1/* $NetBSD: aic6360var.h,v 1.16 2009/09/22 13:18:28 tsutsui Exp $ */
2
3/*
4 * Copyright (c) 1994, 1995, 1996 Charles M. Hannum. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Charles M. Hannum.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * Copyright (c) 1994 Jarle Greipsland
21 * All rights reserved.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. The name of the author may not be used to endorse or promote products
32 * derived from this software without specific prior written permission.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
35 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
38 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44 * POSSIBILITY OF SUCH DAMAGE.
45 */
46
47#ifndef _DEV_IC_AIC6360VAR_H_
48#define _DEV_IC_AIC6360VAR_H_
49
50/*
51 * Acknowledgements: Many of the algorithms used in this driver are
52 * inspired by the work of Julian Elischer (julian@tfs.com) and
53 * Charles Hannum (mycroft@duality.gnu.ai.mit.edu). Thanks a million!
54 */
55
56typedef u_long physaddr;
57typedef u_long physlen;
58
59struct aic_dma_seg {
60 physaddr seg_addr;
61 physlen seg_len;
62};
63
64#define AIC_NSEG 16
65
66/*
67 * ACB. Holds additional information for each SCSI command Comments: We
68 * need a separate scsi command block because we may need to overwrite it
69 * with a request sense command. Basicly, we refrain from fiddling with
70 * the scsipi_xfer struct (except do the expected updating of return values).
71 * We'll generally update: xs->{flags,resid,error,sense,status} and
72 * occasionally xs->retries.
73 */
74struct aic_acb {
75 struct scsipi_generic scsipi_cmd;
76 int scsipi_cmd_length;
77 u_char *data_addr; /* Saved data pointer */
78 int data_length; /* Residue */
79
80 u_char target_stat; /* SCSI status byte */
81
82#ifdef notdef
83 struct aic_dma_seg dma[AIC_NSEG]; /* Physical addresses+len */
84#endif
85
86 TAILQ_ENTRY(aic_acb) chain;
87 struct scsipi_xfer *xs; /* SCSI xfer ctrl block from above */
88 int flags;
89#define ACB_ALLOC 0x01
90#define ACB_NEXUS 0x02
91#define ACB_SENSE 0x04
92#define ACB_ABORT 0x40
93#define ACB_RESET 0x80
94 int timeout;
95};
96
97/*
98 * Some info about each (possible) target on the SCSI bus. This should
99 * probably have been a "per target+lunit" structure, but we'll leave it at
100 * this for now.
101 */
102struct aic_tinfo {
103 int cmds; /* #commands processed */
104 int dconns; /* #disconnects */
105 int touts; /* #timeouts */
106 int perrs; /* #parity errors */
107 int senses; /* #request sense commands sent */
108 ushort lubusy; /* What local units/subr. are busy? */
109 u_char flags;
110#define DO_SYNC 0x01 /* (Re)Negotiate synchronous options */
111#define DO_WIDE 0x02 /* (Re)Negotiate wide options */
112 u_char period; /* Period suggestion */
113 u_char offset; /* Offset suggestion */
114 u_char width; /* Width suggestion */
115};
116
117struct aic_softc {
118 device_t sc_dev;
119
120 bus_space_tag_t sc_iot;
121 bus_space_handle_t sc_ioh;
122
123 struct scsipi_adapter sc_adapter;
124 struct scsipi_channel sc_channel;
125
126 TAILQ_HEAD(, aic_acb) free_list, ready_list, nexus_list;
127 struct aic_acb *sc_nexus; /* current command */
128 struct aic_acb sc_acb[8];
129 struct aic_tinfo sc_tinfo[8];
130
131 /* Data about the current nexus (updated for every cmd switch) */
132 u_char *sc_dp; /* Current data pointer */
133 size_t sc_dleft; /* Data bytes left to transfer */
134 u_char *sc_cp; /* Current command pointer */
135 size_t sc_cleft; /* Command bytes left to transfer */
136
137 /* Adapter state */
138 u_char sc_phase; /* Current bus phase */
139 u_char sc_prevphase; /* Previous bus phase */
140 u_char sc_state; /* State applicable to the adapter */
141#define AIC_INIT 0
142#define AIC_IDLE 1
143#define AIC_SELECTING 2 /* SCSI command is arbiting */
144#define AIC_RESELECTED 3 /* Has been reselected */
145#define AIC_CONNECTED 4 /* Actively using the SCSI bus */
146#define AIC_DISCONNECT 5 /* MSG_DISCONNECT received */
147#define AIC_CMDCOMPLETE 6 /* MSG_CMDCOMPLETE received */
148#define AIC_CLEANING 7
149 u_char sc_flags;
150#define AIC_DROP_MSGIN 0x01 /* Discard all msgs (parity err detected) */
151#define AIC_ABORTING 0x02 /* Bailing out */
152#define AIC_DOINGDMA 0x04 /* The FIFO data path is active! */
153 u_char sc_selid; /* Reselection ID */
154 device_t sc_child;/* Our child */
155
156 /* Message stuff */
157 u_char sc_msgpriq; /* Messages we want to send */
158 u_char sc_msgoutq; /* Messages sent during last MESSAGE OUT */
159 u_char sc_lastmsg; /* Message last transmitted */
160 u_char sc_currmsg; /* Message currently ready to transmit */
161#define SEND_DEV_RESET 0x01
162#define SEND_PARITY_ERROR 0x02
163#define SEND_INIT_DET_ERR 0x04
164#define SEND_REJECT 0x08
165#define SEND_IDENTIFY 0x10
166#define SEND_ABORT 0x20
167#define SEND_SDTR 0x40
168#define SEND_WDTR 0x80
169#define AIC_MAX_MSG_LEN 8
170 u_char sc_omess[AIC_MAX_MSG_LEN];
171 u_char *sc_omp; /* Outgoing message pointer */
172 u_char sc_imess[AIC_MAX_MSG_LEN];
173 u_char *sc_imp; /* Incoming message pointer */
174
175 /* Hardware stuff */
176 int sc_initiator; /* Our scsi id */
177 int sc_freq; /* Clock frequency in MHz */
178 int sc_minsync; /* Minimum sync period / 4 */
179 int sc_maxsync; /* Maximum sync period / 4 */
180};
181
182#if AIC_DEBUG
183#define AIC_SHOWACBS 0x01
184#define AIC_SHOWINTS 0x02
185#define AIC_SHOWCMDS 0x04
186#define AIC_SHOWMISC 0x08
187#define AIC_SHOWTRACE 0x10
188#define AIC_SHOWSTART 0x20
189#define AIC_DOBREAK 0x40
190extern int aic_debug; /* AIC_SHOWSTART|AIC_SHOWMISC|AIC_SHOWTRACE; */
191#define AIC_PRINT(b, s) do { \
192 if ((aic_debug & (b)) != 0) \
193 printf s; \
194 } while (/* CONSTCOND */ 0)
195#define AIC_BREAK() do { \
196 if ((aic_debug & AIC_DOBREAK) != 0) \
197 Debugger(); \
198 } while (/* CONSTCOND */ 0)
199#define AIC_ASSERT(x) do { \
200 if (! (x)) { \
201 printf("%s at line %d: assertion failed\n", \
202 device_xname(sc->sc_dev), __LINE__); \
203 Debugger(); \
204 } } while (/* CONSTCOND */ 0)
205#else
206#define AIC_PRINT(b, s) /* NOTHING */
207#define AIC_BREAK() /* NOTHING */
208#define AIC_ASSERT(x) /* NOTHING */
209#endif
210
211#define AIC_ACBS(s) AIC_PRINT(AIC_SHOWACBS, s)
212#define AIC_INTS(s) AIC_PRINT(AIC_SHOWINTS, s)
213#define AIC_CMDS(s) AIC_PRINT(AIC_SHOWCMDS, s)
214#define AIC_MISC(s) AIC_PRINT(AIC_SHOWMISC, s)
215#define AIC_TRACE(s) AIC_PRINT(AIC_SHOWTRACE, s)
216#define AIC_START(s) AIC_PRINT(AIC_SHOWSTART, s)
217
218#define AIC_ISA_IOSIZE 0x20 /* XXX */
219
220void aicattach(struct aic_softc *);
221int aic_activate(device_t, enum devact);
222int aic_detach(device_t, int);
223int aicintr(void *);
224int aic_find(bus_space_tag_t, bus_space_handle_t);
225void aic_init(struct aic_softc *, int);
226
227#endif /* _DEV_IC_AIC6360VAR_H_ */
228