1 /* $NetBSD: osiopvar.h,v 1.12 2008/03/29 09:11:35 tsutsui Exp $ */
4 * Copyright (c) 2001 Izumi Tsutsui. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Copyright (c) 1990 The Regents of the University of California.
29 * All rights reserved.
31 * This code is derived from software contributed to Berkeley by
32 * Van Jacobson of Lawrence Berkeley Laboratory.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * @(#)siopvar.h 7.1 (Berkeley) 5/8/90
61 #define osiop_read_1(sc, reg) \
62 bus_space_read_1((sc)->sc_bst, (sc)->sc_reg, reg)
63 #define osiop_write_1(sc, reg, val) \
64 bus_space_write_1((sc)->sc_bst, (sc)->sc_reg, reg, val)
66 #define osiop_read_4(sc, reg) \
67 bus_space_read_4((sc)->sc_bst, (sc)->sc_reg, reg)
68 #define osiop_write_4(sc, reg, val) \
69 bus_space_write_4((sc)->sc_bst, (sc)->sc_reg, reg, val)
72 * The largest single request will be MAXPHYS bytes which will require
73 * at most MAXPHYS/NBPG+1 chain elements to describe, i.e. if none of
74 * the buffer pages are physically contiguous (MAXPHYS/NBPG) and the
75 * buffer is not page aligned (+1).
77 /* XXX This should be (MAXPHYS / NBPG + 1), but hardcoded in script */
78 #define OSIOP_NSG (16 + 1)
79 #if MAXPHYS > (PAGE_SIZE * (OSIOP_NSG - 1))
80 #define OSIOP_MAX_XFER (PAGE_SIZE * (OSIOP_NSG - 1))
82 #define OSIOP_MAX_XFER MAXPHYS
86 #define OSIOP_NACB 32 /* XXX (PAGE_SIZE / sizeof(osiop_ds)) is better? */
89 * Data Structure for SCRIPTS program
91 typedef struct buf_table
{
97 uint32_t scsi_addr
; /* 0: SCSI ID & sync */
98 uint32_t pad1
; /* 4: padding */
99 buf_table_t id
; /* 8: Identify message */
100 buf_table_t cmd
; /* 16: SCSI command */
101 buf_table_t status
; /* 24: Status */
102 buf_table_t msg
; /* 32: Message */
103 buf_table_t msgin
; /* 40: Message in */
104 buf_table_t extmsg
; /* 48: Extended message in */
105 buf_table_t synmsg
; /* 56: Sync transfer request */
106 buf_table_t data
[OSIOP_NSG
]; /* 64: DMA S/G buffers */
107 /* (8 * OSIOP_NSG == 136bytes) */
108 uint8_t scsipi_cmd
[16]; /* 200: cmd buf */
109 uint8_t msgout
[8]; /* 216: message out buf */
110 uint8_t msgbuf
[8]; /* 224: message in buf */
111 uint8_t stat
[8]; /* 232: stat buf */
112 uint8_t pad2
[16]; /* 240: padding to 256bytes */
115 /* status can hold the SCSI_* status values, and 2 additional values: */
116 #define SCSI_OSIOP_NOCHECK 0xfe /* don't check the scsi status */
117 #define SCSI_OSIOP_NOSTATUS 0xff /* device didn't report status */
119 #define MSG_INVALID 0xff /* dummy value for message buffer */
121 #define OSIOP_DSOFF(x) offsetof(struct osiop_ds, x)
122 #define OSIOP_DSCMDOFF OSIOP_DSOFF(scsipi_cmd[0])
123 #define OSIOP_DSIDOFF OSIOP_DSOFF(msgout[0])
124 #define OSIOP_DSMSGOFF OSIOP_DSOFF(msgbuf[0])
125 #define OSIOP_DSMSGINOFF OSIOP_DSOFF(msgbuf[1])
126 #define OSIOP_DSEXTMSGOFF OSIOP_DSOFF(msgbuf[2])
127 #define OSIOP_DSSYNMSGOFF OSIOP_DSOFF(msgbuf[3])
128 #define OSIOP_DSSTATOFF OSIOP_DSOFF(stat[0])
131 * ACB. Holds additional information for each SCSI command Comments:
132 * Basicly, we refrain from fiddling with the scsi_xfer struct
133 * (except do the expected updating of return values).
134 * We'll generally update: xs->{flags,resid,error,status} and
135 * occasionally xs->retries.
138 TAILQ_ENTRY(osiop_acb
) chain
;
139 struct scsipi_xfer
*xs
; /* SCSI xfer ctrl block from upper layer */
140 struct osiop_softc
*sc
; /* points back to our adapter */
142 bus_dmamap_t datadma
; /* DMA map for data transfer */
144 struct osiop_ds
*ds
; /* data structure for this acb */
145 bus_size_t dsoffset
; /* offset of data structure for this acb */
147 bus_size_t cmdlen
; /* command length */
148 bus_size_t datalen
; /* transfer data length */
150 void *data
; /* transfer data buffer ptr */
153 bus_addr_t curaddr
; /* current transfer data buffer */
154 bus_size_t curlen
; /* current transfer data length */
156 int status
; /* status of this acb */
158 #define ACB_S_FREE 0 /* cmd slot is free */
159 #define ACB_S_READY 1 /* cmd slot is waiting for processing */
160 #define ACB_S_ACTIVE 2 /* cmd slot is being processed */
161 #define ACB_S_DONE 3 /* cmd slot has been processed */
163 int flags
; /* cmd slot flags */
164 #define ACB_F_TIMEOUT 0x01 /* command timeout */
166 uint8_t intstat
; /* buffer to save sc_flags on disconnect */
170 * Some info about each (possible) target on the SCSI bus. This should
171 * probably have been a "per target+lunit" structure, but we'll leave it at
172 * this for now. Is there a way to reliably hook it up to sc->fordriver??
175 int cmds
; /* number of commands processed */
176 int dconns
; /* number of disconnects */
177 int touts
; /* number of timeouts */
178 int perrs
; /* number of parity errors */
179 int lubusy
; /* What local units/subr. are busy? */
180 int period
; /* Period suggestion */
181 int offset
; /* Offset suggestion */
182 int flags
; /* misc flags per each target */
183 #define TI_NOSYNC 0x01 /* disable sync xfer on this target */
184 #define TI_NODISC 0x02 /* disable disconnect on this target */
185 int state
; /* negotiation state */
186 uint8_t sxfer
; /* value for SXFER reg */
187 uint8_t sbcl
; /* value for SBCL reg */
193 bus_space_tag_t sc_bst
; /* bus space tag */
194 bus_space_handle_t sc_reg
; /* register I/O handle */
196 bus_dma_tag_t sc_dmat
; /* bus dma tag */
197 bus_dmamap_t sc_scrdma
; /* script dma map */
198 bus_dmamap_t sc_dsdma
; /* script data dma map */
200 uint32_t *sc_script
; /* ptr to script memory */
201 struct osiop_ds
*sc_ds
; /* ptr to data structure memory */
203 int sc_id
; /* adapter SCSI id */
204 int sc_active
; /* number of active I/O's */
206 struct osiop_acb
*sc_nexus
; /* current command */
207 struct osiop_acb
*sc_acb
; /* the real command blocks */
209 /* Lists of command blocks */
210 TAILQ_HEAD(acb_list
, osiop_acb
) free_list
,
214 struct scsipi_adapter sc_adapter
;
215 struct scsipi_channel sc_channel
;
217 struct osiop_tinfo sc_tinfo
[OSIOP_NTGT
];
222 #define OSIOP_INTSOFF 0x80 /* Interrupts turned off */
223 #define OSIOP_INTDEFER 0x40 /* MD interrupt has been deferred */
224 #define OSIOP_NODMA 0x02 /* No DMA transfer */
225 #define OSIOP_ALIVE 0x01 /* controller initialized */
227 int sc_cfflags
; /* copy of config flags */
242 /* negotiation states */
243 #define NEG_INIT 0 /* Initial negotiate state */
244 #define NEG_SYNC NEG_INIT /* Negotiate synch transfers */
245 #define NEG_WAITS 1 /* Waiting for synch negotiation response */
246 #define NEG_DONE 2 /* Wide and/or sync negotiation done */
248 void osiop_attach(struct osiop_softc
*);
249 void osiop_intr(struct osiop_softc
*);