sbicvar.h revision 1.2 1 1.2 agc /* $NetBSD: sbicvar.h,v 1.2 2003/08/07 16:26:30 agc Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.1 reinoud * Copyright (c) 1990 The Regents of the University of California.
5 1.1 reinoud * All rights reserved.
6 1.1 reinoud *
7 1.1 reinoud * This code is derived from software contributed to Berkeley by
8 1.1 reinoud * Van Jacobson of Lawrence Berkeley Laboratory.
9 1.1 reinoud *
10 1.1 reinoud * Redistribution and use in source and binary forms, with or without
11 1.1 reinoud * modification, are permitted provided that the following conditions
12 1.1 reinoud * are met:
13 1.1 reinoud * 1. Redistributions of source code must retain the above copyright
14 1.1 reinoud * notice, this list of conditions and the following disclaimer.
15 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 reinoud * notice, this list of conditions and the following disclaimer in the
17 1.1 reinoud * documentation and/or other materials provided with the distribution.
18 1.2 agc * 3. Neither the name of the University nor the names of its contributors
19 1.1 reinoud * may be used to endorse or promote products derived from this software
20 1.1 reinoud * without specific prior written permission.
21 1.1 reinoud *
22 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 reinoud * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 reinoud * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 reinoud * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 reinoud * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 reinoud * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 reinoud * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 reinoud * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 reinoud * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 reinoud * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 reinoud * SUCH DAMAGE.
33 1.1 reinoud *
34 1.1 reinoud * @(#)scsivar.h 7.1 (Berkeley) 5/8/90
35 1.1 reinoud */
36 1.1 reinoud
37 1.1 reinoud #ifndef _SBICVAR_H_
38 1.1 reinoud #define _SBICVAR_H_
39 1.1 reinoud #include <sys/malloc.h>
40 1.1 reinoud #include <sys/callout.h>
41 1.1 reinoud
42 1.1 reinoud /*
43 1.1 reinoud * ACB. Holds additional information for each SCSI command Comments: We
44 1.1 reinoud * need a separate scsi command block because we may need to overwrite it
45 1.1 reinoud * with a request sense command. Basicly, we refrain from fiddling with
46 1.1 reinoud * the scsi_xfer struct (except do the expected updating of return values).
47 1.1 reinoud * We'll generally update: xs->{flags,resid,error,sense,status} and
48 1.1 reinoud * occasionally xs->retries.
49 1.1 reinoud */
50 1.1 reinoud struct sbic_acb {
51 1.1 reinoud TAILQ_ENTRY(sbic_acb) chain;
52 1.1 reinoud struct scsipi_xfer *xs; /* SCSI xfer ctrl block from above */
53 1.1 reinoud int flags; /* Status */
54 1.1 reinoud #define ACB_FREE 0x00
55 1.1 reinoud #define ACB_ACTIVE 0x01
56 1.1 reinoud #define ACB_DONE 0x02
57 1.1 reinoud #define ACB_DATAIN 0x04 /* DMA direction flag */
58 1.1 reinoud #define ACB_DMA 0x08 /* ACB using DMA this time */
59 1.1 reinoud struct scsi_generic cmd; /* SCSI command block */
60 1.1 reinoud int clen;
61 1.1 reinoud bus_dmamap_t dmamap_xfer; /* Handle for dma */
62 1.1 reinoud u_char *data; /* Data buffer... */
63 1.1 reinoud int datalen; /* ... and its length. */
64 1.1 reinoud int offset;
65 1.1 reinoud u_long sc_tcnt; /* number of bytes for this DMA */
66 1.1 reinoud };
67 1.1 reinoud
68 1.1 reinoud /*
69 1.1 reinoud * Some info about each (possible) target on the SCSI bus. This should
70 1.1 reinoud * probably have been a "per target+lunit" structure, but we'll leave it at
71 1.1 reinoud * this for now. Is there a way to reliably hook it up to sc->fordriver??
72 1.1 reinoud */
73 1.1 reinoud struct sbic_tinfo {
74 1.1 reinoud int cmds; /* #commands processed */
75 1.1 reinoud int dconns; /* #disconnects */
76 1.1 reinoud int touts; /* #timeouts */
77 1.1 reinoud int perrs; /* #parity errors */
78 1.1 reinoud u_char* bounce; /* Bounce buffer for this device */
79 1.1 reinoud ushort lubusy; /* What local units/subr. are busy? */
80 1.1 reinoud u_char flags;
81 1.1 reinoud u_char period; /* Period suggestion */
82 1.1 reinoud u_char offset; /* Offset suggestion */
83 1.1 reinoud } tinfo_t;
84 1.1 reinoud
85 1.1 reinoud struct sbic_softc {
86 1.1 reinoud struct device sc_dev;
87 1.1 reinoud /* struct isr sc_isr;*/
88 1.1 reinoud struct callout sc_timo_ch;
89 1.1 reinoud struct target_sync {
90 1.1 reinoud u_char state;
91 1.1 reinoud u_char period;
92 1.1 reinoud u_char offset;
93 1.1 reinoud } sc_sync[8];
94 1.1 reinoud u_char target; /* Currently active target */
95 1.1 reinoud u_char lun;
96 1.1 reinoud struct scsipi_channel sc_channel;
97 1.1 reinoud struct scsipi_adapter sc_adapter;
98 1.1 reinoud sbic_regmap sc_sbicp; /* Handle for the SBIC */
99 1.1 reinoud
100 1.1 reinoud volatile void *sc_cregs; /* driver specific regs */
101 1.1 reinoud
102 1.1 reinoud /* Lists of command blocks */
103 1.1 reinoud TAILQ_HEAD(acb_list, sbic_acb) free_list,
104 1.1 reinoud ready_list,
105 1.1 reinoud nexus_list;
106 1.1 reinoud
107 1.1 reinoud struct sbic_acb *sc_nexus; /* current command */
108 1.1 reinoud struct sbic_acb sc_acb[8]; /* the real command blocks */
109 1.1 reinoud struct sbic_tinfo sc_tinfo[8];
110 1.1 reinoud
111 1.1 reinoud u_char sc_flags;
112 1.1 reinoud u_char sc_scsiaddr;
113 1.1 reinoud u_char sc_stat[2];
114 1.1 reinoud u_char sc_msg[7];
115 1.1 reinoud u_long sc_clkfreq;
116 1.1 reinoud
117 1.1 reinoud int sc_dmaflags; /* Target-specific busdma flags */
118 1.1 reinoud void *sc_dmah; /* Interface specific dma handle */
119 1.1 reinoud bus_dma_tag_t sc_dmat; /* Tag for dma accesses */
120 1.1 reinoud int sc_max_dmalen; /* Maximum DMA segment length */
121 1.1 reinoud int sc_dmamode; /* Machine-specific DMA mode for
122 1.1 reinoud the SBIC chip */
123 1.1 reinoud
124 1.1 reinoud u_short sc_dmatimo; /* dma timeout */
125 1.1 reinoud int (*sc_dmaok) (void *, bus_dma_tag_t, struct sbic_acb *);
126 1.1 reinoud int (*sc_dmasetup) (void *, bus_dma_tag_t, struct sbic_acb *, int);
127 1.1 reinoud int (*sc_dmanext) (void *, bus_dma_tag_t, struct sbic_acb *, int);
128 1.1 reinoud void (*sc_dmastop) (void *, bus_dma_tag_t, struct sbic_acb *);
129 1.1 reinoud void (*sc_dmafinish) (void *, bus_dma_tag_t, struct sbic_acb *);
130 1.1 reinoud void (*sc_enintr) (struct sbic_softc *);
131 1.1 reinoud };
132 1.1 reinoud
133 1.1 reinoud /* sc_flags */
134 1.1 reinoud #define SBICF_ALIVE 0x01 /* controller initialized */
135 1.1 reinoud #define SBICF_SELECTED 0x02 /* bus is in selected state. */
136 1.1 reinoud #define SBICF_ICMD 0x04 /* Immediate command in execution */
137 1.1 reinoud #define SBICF_BADDMA 0x08 /* controller can only DMA to ztwobus space */
138 1.1 reinoud #define SBICF_NODMA 0x10 /* Don't use DMA */
139 1.1 reinoud #define SBICF_INTR 0x20 /* SBICF interrupt expected */
140 1.1 reinoud #define SBICF_INDMA 0x40 /* not used yet, DMA I/O in progress */
141 1.1 reinoud
142 1.1 reinoud /* sync states */
143 1.1 reinoud #define SYNC_START 0 /* no sync handshake started */
144 1.1 reinoud #define SYNC_SENT 1 /* we sent sync request, no answer yet */
145 1.1 reinoud #define SYNC_DONE 2 /* target accepted our (or inferior) settings,
146 1.1 reinoud or it rejected the request and we stay
147 1.1 reinoud async */
148 1.1 reinoud #ifdef DEBUG
149 1.1 reinoud #define DDB_FOLLOW 0x04
150 1.1 reinoud #define DDB_IO 0x08
151 1.1 reinoud #endif
152 1.1 reinoud extern u_char sbic_inhibit_sync[8];
153 1.1 reinoud extern int sbic_no_dma;
154 1.1 reinoud extern int sbic_clock_override;
155 1.1 reinoud
156 1.1 reinoud #define PHASE_MASK 0x07 /* mask for psns/pctl phase */
157 1.1 reinoud #define DATA_OUT_PHASE 0x00
158 1.1 reinoud #define DATA_IN_PHASE 0x01
159 1.1 reinoud #define CMD_PHASE 0x02
160 1.1 reinoud #define STATUS_PHASE 0x03
161 1.1 reinoud #define BUS_FREE_PHASE 0x04
162 1.1 reinoud #define ARB_SEL_PHASE 0x05 /* Fuji chip combines arbitration with sel. */
163 1.1 reinoud #define MESG_OUT_PHASE 0x06
164 1.1 reinoud #define MESG_IN_PHASE 0x07
165 1.1 reinoud
166 1.1 reinoud #define MSG_CMD_COMPLETE 0x00
167 1.1 reinoud #define MSG_EXT_MESSAGE 0x01
168 1.1 reinoud #define MSG_SAVE_DATA_PTR 0x02
169 1.1 reinoud #define MSG_RESTORE_PTR 0x03
170 1.1 reinoud #define MSG_DISCONNECT 0x04
171 1.1 reinoud #define MSG_INIT_DETECT_ERROR 0x05
172 1.1 reinoud #define MSG_ABORT 0x06
173 1.1 reinoud #define MSG_REJECT 0x07
174 1.1 reinoud #define MSG_NOOP 0x08
175 1.1 reinoud #define MSG_PARITY_ERROR 0x09
176 1.1 reinoud #define MSG_BUS_DEVICE_RESET 0x0C
177 1.1 reinoud #define MSG_IDENTIFY 0x80
178 1.1 reinoud #define MSG_IDENTIFY_DR 0xc0 /* (disconnect/reconnect allowed) */
179 1.1 reinoud #define MSG_SYNC_REQ 0x01
180 1.1 reinoud
181 1.1 reinoud #define MSG_ISIDENTIFY(x) (x&MSG_IDENTIFY)
182 1.1 reinoud #define IFY_TRN 0x20
183 1.1 reinoud #define IFY_LUNTRN(x) (x&0x07)
184 1.1 reinoud #define IFY_LUN(x) (!(x&0x20))
185 1.1 reinoud
186 1.1 reinoud /* Check if high bit set */
187 1.1 reinoud
188 1.1 reinoud #define STS_CHECKCOND 0x02 /* Check Condition (ie., read sense) */
189 1.1 reinoud #define STS_CONDMET 0x04 /* Condition Met (ie., search worked) */
190 1.1 reinoud #define STS_BUSY 0x08
191 1.1 reinoud #define STS_INTERMED 0x10 /* Intermediate status sent */
192 1.1 reinoud #define STS_EXT 0x80 /* Extended status valid */
193 1.1 reinoud
194 1.1 reinoud
195 1.1 reinoud /* States returned by our state machine */
196 1.1 reinoud
197 1.1 reinoud #define SBIC_STATE_ERROR -1
198 1.1 reinoud #define SBIC_STATE_DONE 0
199 1.1 reinoud #define SBIC_STATE_RUNNING 1
200 1.1 reinoud #define SBIC_STATE_DISCONNECT 2
201 1.1 reinoud
202 1.1 reinoud /*
203 1.1 reinoud * XXXX
204 1.1 reinoud */
205 1.1 reinoud struct scsi_fmt_cdb {
206 1.1 reinoud int len; /* cdb length (in bytes) */
207 1.1 reinoud u_char cdb[28]; /* cdb to use on next read/write */
208 1.1 reinoud };
209 1.1 reinoud
210 1.1 reinoud struct buf;
211 1.1 reinoud struct scsipi_xfer;
212 1.1 reinoud
213 1.1 reinoud void sbic_minphys (struct buf *bp);
214 1.1 reinoud void sbic_scsi_request (struct scsipi_channel *,
215 1.1 reinoud scsipi_adapter_req_t, void *);
216 1.1 reinoud int sbicinit (struct sbic_softc *dev);
217 1.1 reinoud int sbicintr (struct sbic_softc *);
218 1.1 reinoud void sbic_dump (struct sbic_softc *dev);
219 1.1 reinoud
220 1.1 reinoud #endif /* _SBICVAR_H_ */
221