No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / ic / oosiopvar.h
blob4e69dd177207b2572f68e3c207499b94ca02a6d4
1 /* $NetBSD: oosiopvar.h,v 1.5 2007/12/25 18:33:39 perry Exp $ */
3 /*
4 * Copyright (c) 2001 Shuichiro URATA. All rights reserved.
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. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #define OOSIOP_NTGT 8 /* Max targets */
30 #define OOSIOP_NCB 32 /* Initial command buffers */
31 #define OOSIOP_NSG (MIN(btoc(MAXPHYS) + 1, 32)) /* Max S/G operation */
32 #define OOSIOP_MAX_XFER ctob(OOSIOP_NSG - 1)
34 struct oosiop_xfer {
35 /* script for scatter/gather DMA (move*nsg+jump) */
36 uint32_t datain_scr[(OOSIOP_NSG + 1) * 2];
37 uint32_t dataout_scr[(OOSIOP_NSG + 1) * 2];
39 uint8_t msgin[8];
40 uint8_t msgout[8];
41 uint8_t status;
42 uint8_t pad[7];
43 } __packed;
45 #define SCSI_OOSIOP_NOSTATUS 0xff /* device didn't report status */
47 #define OOSIOP_XFEROFF(x) offsetof(struct oosiop_xfer, x)
48 #define OOSIOP_DINSCROFF OOSIOP_XFEROFF(datain_scr[0])
49 #define OOSIOP_DOUTSCROFF OOSIOP_XFEROFF(dataout_scr[0])
50 #define OOSIOP_MSGINOFF OOSIOP_XFEROFF(msgin[0])
51 #define OOSIOP_MSGOUTOFF OOSIOP_XFEROFF(msgout[0])
53 #define OOSIOP_XFERSCR_SYNC(sc, cb, ops) \
54 bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DINSCROFF, \
55 OOSIOP_MSGINOFF - OOSIOP_DINSCROFF, (ops))
56 #define OOSIOP_DINSCR_SYNC(sc, cb, ops) \
57 bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DINSCROFF, \
58 OOSIOP_DOUTSCROFF - OOSIOP_DINSCROFF, (ops))
59 #define OOSIOP_DOUTSCR_SYNC(sc, cb, ops) \
60 bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_DOUTSCROFF,\
61 OOSIOP_MSGINOFF - OOSIOP_DOUTSCROFF, (ops))
62 #define OOSIOP_XFERMSG_SYNC(sc, cb, ops) \
63 bus_dmamap_sync((sc)->sc_dmat, (cb)->xferdma, OOSIOP_MSGINOFF, \
64 sizeof(struct oosiop_xfer) - OOSIOP_MSGINOFF, (ops))
66 #define OOSIOP_SCRIPT_SYNC(sc, ops) \
67 bus_dmamap_sync((sc)->sc_dmat, (sc)->sc_scrdma, \
68 0, sizeof(oosiop_script), (ops))
70 struct oosiop_cb {
71 TAILQ_ENTRY(oosiop_cb) chain;
73 struct scsipi_xfer *xs; /* SCSI xfer ctrl block from above */
74 int flags;
75 int id; /* target scsi id */
76 int lun; /* target lun */
78 bus_dmamap_t cmddma; /* DMA map for command out */
79 bus_dmamap_t datadma; /* DMA map for data I/O */
80 bus_dmamap_t xferdma; /* DMA map for xfer block */
82 int curdp; /* current data pointer */
83 int savedp; /* saved data pointer */
84 int msgoutlen;
86 struct oosiop_xfer *xfer; /* DMA xfer block */
89 /* oosiop_cb flags */
90 #define CBF_SELTOUT 0x01 /* Selection timeout */
91 #define CBF_TIMEOUT 0x02 /* Command timeout */
93 TAILQ_HEAD(oosiop_cb_queue, oosiop_cb);
95 struct oosiop_target {
96 struct oosiop_cb *nexus;
97 int flags;
98 uint8_t scf; /* synchronous clock divisor */
99 uint8_t sxfer; /* synchronous period and offset */
102 /* target flags */
103 #define TGTF_SYNCNEG 0x01 /* Trigger synchronous negotiation */
104 #define TGTF_WAITSDTR 0x02 /* Waiting SDTR from target */
106 struct oosiop_softc {
107 device_t sc_dev;
109 bus_space_tag_t sc_bst; /* bus space tag */
110 bus_space_handle_t sc_bsh; /* bus space handle */
112 bus_dma_tag_t sc_dmat; /* bus DMA tag */
113 bus_dmamap_t sc_scrdma; /* script DMA map */
115 bus_addr_t sc_scrbase; /* script DMA base address */
116 uint32_t *sc_scr; /* ptr to script memory */
118 int sc_chip; /* 700 or 700-66 */
119 #define OOSIOP_700 0
120 #define OOSIOP_700_66 1
122 int sc_id; /* SCSI ID of this interface */
123 int sc_freq; /* SCLK frequency */
124 int sc_ccf; /* asynchronous divisor (*10) */
125 uint8_t sc_dcntl;
126 uint8_t sc_minperiod;
128 struct oosiop_target sc_tgt[OOSIOP_NTGT];
130 struct scsipi_adapter sc_adapter;
131 struct scsipi_channel sc_channel;
133 /* Lists of command blocks */
134 struct oosiop_cb_queue sc_free_cb;
135 struct oosiop_cb_queue sc_cbq; /* command issue queue */
136 struct oosiop_cb *sc_curcb; /* current command */
137 struct oosiop_cb *sc_lastcb; /* last activated command */
139 bus_addr_t sc_reselbuf; /* msgin buffer for reselection */
140 int sc_resid; /* reselected target id */
142 int sc_active;
143 int sc_nextdsp;
146 #define oosiop_read_1(sc, addr) \
147 bus_space_read_1((sc)->sc_bst, (sc)->sc_bsh, (addr))
148 #define oosiop_write_1(sc, addr, data) \
149 bus_space_write_1((sc)->sc_bst, (sc)->sc_bsh, (addr), (data))
150 /* XXX byte swapping should be handled by MD bus_space(9)? */
151 #define oosiop_read_4(sc, addr) \
152 le32toh(bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (addr)))
153 #define oosiop_write_4(sc, addr, data) \
154 bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (addr), htole32(data))
156 void oosiop_attach(struct oosiop_softc *);
157 int oosiop_intr(struct oosiop_softc *);