siopvar_common.h revision 1.32 1 1.32 perry /* $NetBSD: siopvar_common.h,v 1.32 2005/02/27 00:27:02 perry Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 2000 Manuel Bouyer.
5 1.1 bouyer *
6 1.1 bouyer * Redistribution and use in source and binary forms, with or without
7 1.1 bouyer * modification, are permitted provided that the following conditions
8 1.1 bouyer * are met:
9 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.1 bouyer * notice, this list of conditions and the following disclaimer.
11 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.1 bouyer * documentation and/or other materials provided with the distribution.
14 1.1 bouyer * 3. All advertising materials mentioning features or use of this software
15 1.1 bouyer * must display the following acknowledgement:
16 1.19 bouyer * This product includes software developed by Manuel Bouyer.
17 1.1 bouyer * 4. The name of the author may not be used to endorse or promote products
18 1.1 bouyer * derived from this software without specific prior written permission.
19 1.1 bouyer *
20 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.32 perry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 bouyer *
31 1.1 bouyer */
32 1.16 bouyer
33 1.16 bouyer #include "opt_siop.h"
34 1.1 bouyer
35 1.1 bouyer /* common struct and routines used by siop and esiop */
36 1.1 bouyer
37 1.1 bouyer #ifndef SIOP_DEFAULT_TARGET
38 1.1 bouyer #define SIOP_DEFAULT_TARGET 7
39 1.1 bouyer #endif
40 1.1 bouyer
41 1.1 bouyer /* tables used by SCRIPT */
42 1.1 bouyer typedef struct scr_table {
43 1.1 bouyer u_int32_t count;
44 1.1 bouyer u_int32_t addr;
45 1.30 drochner } __packed scr_table_t;
46 1.1 bouyer
47 1.1 bouyer /* Number of scatter/gather entries */
48 1.24 thorpej #define SIOP_NSG (MAXPHYS/PAGE_SIZE + 1) /* XXX PAGE_SIZE */
49 1.1 bouyer
50 1.1 bouyer /*
51 1.1 bouyer * This structure interfaces the SCRIPT with the driver; it describes a full
52 1.32 perry * transfer.
53 1.14 bouyer * If you change something here, don't forget to update offsets in {s,es}iop.ss
54 1.1 bouyer */
55 1.13 bouyer struct siop_common_xfer {
56 1.17 bouyer u_int8_t msg_out[16]; /* 0 */
57 1.17 bouyer u_int8_t msg_in[16]; /* 16 */
58 1.17 bouyer u_int32_t status; /* 32 */
59 1.17 bouyer u_int32_t pad1; /* 36 */
60 1.17 bouyer u_int32_t id; /* 40 */
61 1.17 bouyer u_int32_t pad2; /* 44 */
62 1.17 bouyer scr_table_t t_msgin; /* 48 */
63 1.17 bouyer scr_table_t t_extmsgin; /* 56 */
64 1.17 bouyer scr_table_t t_extmsgdata; /* 64 */
65 1.17 bouyer scr_table_t t_msgout; /* 72 */
66 1.17 bouyer scr_table_t cmd; /* 80 */
67 1.17 bouyer scr_table_t t_status; /* 88 */
68 1.17 bouyer scr_table_t data[SIOP_NSG]; /* 96 */
69 1.30 drochner } __packed;
70 1.8 bouyer
71 1.25 wiz /* status can hold the SCSI_* status values, and 2 additional values: */
72 1.8 bouyer #define SCSI_SIOP_NOCHECK 0xfe /* don't check the scsi status */
73 1.8 bouyer #define SCSI_SIOP_NOSTATUS 0xff /* device didn't report status */
74 1.1 bouyer
75 1.1 bouyer /*
76 1.25 wiz * This describes a command handled by the SCSI controller
77 1.1 bouyer */
78 1.13 bouyer struct siop_common_cmd {
79 1.13 bouyer struct siop_common_softc *siop_sc; /* points back to our adapter */
80 1.13 bouyer struct siop_common_target *siop_target; /* pointer to our target def */
81 1.1 bouyer struct scsipi_xfer *xs; /* xfer from the upper level */
82 1.13 bouyer struct siop_common_xfer *siop_tables; /* tables for this cmd */
83 1.1 bouyer bus_addr_t dsa; /* DSA value to load */
84 1.1 bouyer bus_dmamap_t dmamap_cmd;
85 1.1 bouyer bus_dmamap_t dmamap_data;
86 1.7 bouyer int status;
87 1.7 bouyer int flags;
88 1.7 bouyer int tag; /* tag used for tagged command queuing */
89 1.28 bouyer int resid; /* valid when CMDFL_RESID is set */
90 1.2 bouyer };
91 1.2 bouyer
92 1.1 bouyer /* status defs */
93 1.1 bouyer #define CMDST_FREE 0 /* cmd slot is free */
94 1.1 bouyer #define CMDST_READY 1 /* cmd slot is waiting for processing */
95 1.1 bouyer #define CMDST_ACTIVE 2 /* cmd slot is being processed */
96 1.11 bouyer #define CMDST_DONE 3 /* cmd slot has been processed */
97 1.1 bouyer /* flags defs */
98 1.1 bouyer #define CMDFL_TIMEOUT 0x0001 /* cmd timed out */
99 1.6 bouyer #define CMDFL_TAG 0x0002 /* tagged cmd */
100 1.28 bouyer #define CMDFL_RESID 0x0004 /* current offset in table is partial */
101 1.6 bouyer
102 1.1 bouyer /* per-target struct */
103 1.13 bouyer struct siop_common_target {
104 1.1 bouyer int status; /* target status, see below */
105 1.1 bouyer int flags; /* target flags, see below */
106 1.1 bouyer u_int32_t id; /* for SELECT FROM */
107 1.11 bouyer int period;
108 1.11 bouyer int offset;
109 1.1 bouyer };
110 1.1 bouyer
111 1.1 bouyer /* target status */
112 1.1 bouyer #define TARST_PROBING 0 /* target is being probed */
113 1.1 bouyer #define TARST_ASYNC 1 /* target needs sync/wide negotiation */
114 1.1 bouyer #define TARST_WIDE_NEG 2 /* target is doing wide negotiation */
115 1.1 bouyer #define TARST_SYNC_NEG 3 /* target is doing sync negotiation */
116 1.18 bouyer #define TARST_PPR_NEG 4 /* target is doing sync negotiation */
117 1.18 bouyer #define TARST_OK 5 /* sync/wide agreement is valid */
118 1.1 bouyer
119 1.1 bouyer /* target flags */
120 1.6 bouyer #define TARF_SYNC 0x01 /* target can do sync */
121 1.6 bouyer #define TARF_WIDE 0x02 /* target can do wide */
122 1.6 bouyer #define TARF_TAG 0x04 /* target can do tags */
123 1.18 bouyer #define TARF_DT 0x08 /* target can do DT clocking */
124 1.18 bouyer #define TARF_ISWIDE 0x10 /* target is wide */
125 1.18 bouyer #define TARF_ISDT 0x20 /* target is doing DT clocking */
126 1.6 bouyer
127 1.13 bouyer /* Driver internal state */
128 1.13 bouyer struct siop_common_softc {
129 1.13 bouyer struct device sc_dev;
130 1.13 bouyer struct scsipi_channel sc_chan;
131 1.13 bouyer struct scsipi_adapter sc_adapt;
132 1.13 bouyer int features; /* chip's features */
133 1.13 bouyer int ram_size;
134 1.13 bouyer int maxburst;
135 1.13 bouyer int maxoff;
136 1.13 bouyer int clock_div; /* async. clock divider (scntl3) */
137 1.13 bouyer int clock_period; /* clock period (ns * 10) */
138 1.18 bouyer int st_minsync; /* min and max sync period, */
139 1.18 bouyer int dt_minsync;
140 1.18 bouyer int st_maxsync; /* as sent in or PPR messages */
141 1.18 bouyer int dt_maxsync;
142 1.21 bouyer int mode; /* current SE/LVD/HVD mode */
143 1.13 bouyer bus_space_tag_t sc_rt; /* bus_space registers tag */
144 1.13 bouyer bus_space_handle_t sc_rh; /* bus_space registers handle */
145 1.25 wiz bus_addr_t sc_raddr; /* register addresses */
146 1.13 bouyer bus_space_tag_t sc_ramt; /* bus_space ram tag */
147 1.13 bouyer bus_space_handle_t sc_ramh; /* bus_space ram handle */
148 1.13 bouyer bus_dma_tag_t sc_dmat; /* bus DMA tag */
149 1.31 perry void (*sc_reset)(struct siop_common_softc*); /* reset callback */
150 1.13 bouyer bus_dmamap_t sc_scriptdma; /* DMA map for script */
151 1.26 wiz bus_addr_t sc_scriptaddr; /* on-board ram or physical address */
152 1.13 bouyer u_int32_t *sc_script; /* script location in memory */
153 1.13 bouyer struct siop_common_target *targets[16]; /* per-target states */
154 1.13 bouyer };
155 1.13 bouyer
156 1.13 bouyer /* features */
157 1.13 bouyer #define SF_BUS_WIDE 0x00000001 /* wide bus */
158 1.23 tsutsui #define SF_BUS_ULTRA 0x00000002 /* Ultra (20MHz) bus */
159 1.23 tsutsui #define SF_BUS_ULTRA2 0x00000004 /* Ultra2 (40MHz) bus */
160 1.23 tsutsui #define SF_BUS_ULTRA3 0x00000008 /* Ultra3 (80MHz) bus */
161 1.15 bouyer #define SF_BUS_DIFF 0x00000010 /* differential bus */
162 1.13 bouyer
163 1.13 bouyer #define SF_CHIP_LED0 0x00000100 /* led on GPIO0 */
164 1.15 bouyer #define SF_CHIP_LEDC 0x00000200 /* led on GPIO0 with hardware control */
165 1.15 bouyer #define SF_CHIP_DBLR 0x00000400 /* clock doubler or quadrupler */
166 1.15 bouyer #define SF_CHIP_QUAD 0x00000800 /* clock quadrupler, with PPL */
167 1.15 bouyer #define SF_CHIP_FIFO 0x00001000 /* large fifo */
168 1.25 wiz #define SF_CHIP_PF 0x00002000 /* Instructions prefetch */
169 1.15 bouyer #define SF_CHIP_RAM 0x00004000 /* on-board RAM */
170 1.15 bouyer #define SF_CHIP_LS 0x00008000 /* load/store instruction */
171 1.15 bouyer #define SF_CHIP_10REGS 0x00010000 /* 10 scratch registers */
172 1.15 bouyer #define SF_CHIP_DFBC 0x00020000 /* Use DFBC register */
173 1.15 bouyer #define SF_CHIP_DT 0x00040000 /* DT clocking */
174 1.20 bouyer #define SF_CHIP_GEBUG 0x00080000 /* SCSI gross error bug */
175 1.27 bouyer #define SF_CHIP_AAIP 0x00100000 /* Always generate AIP regardless of SNCTL4*/
176 1.13 bouyer
177 1.13 bouyer #define SF_PCI_RL 0x01000000 /* PCI read line */
178 1.13 bouyer #define SF_PCI_RM 0x02000000 /* PCI read multiple */
179 1.13 bouyer #define SF_PCI_BOF 0x04000000 /* PCI burst opcode fetch */
180 1.13 bouyer #define SF_PCI_CLS 0x08000000 /* PCI cache line size */
181 1.13 bouyer #define SF_PCI_WRI 0x10000000 /* PCI write and invalidate */
182 1.13 bouyer
183 1.31 perry int siop_common_attach(struct siop_common_softc *);
184 1.31 perry void siop_common_reset(struct siop_common_softc *);
185 1.31 perry void siop_setuptables(struct siop_common_cmd *);
186 1.31 perry int siop_modechange(struct siop_common_softc *);
187 1.31 perry
188 1.31 perry int siop_wdtr_neg(struct siop_common_cmd *);
189 1.31 perry int siop_sdtr_neg(struct siop_common_cmd *);
190 1.31 perry int siop_ppr_neg(struct siop_common_cmd *);
191 1.31 perry void siop_sdtr_msg(struct siop_common_cmd *, int, int, int);
192 1.31 perry void siop_wdtr_msg(struct siop_common_cmd *, int, int);
193 1.31 perry void siop_ppr_msg(struct siop_common_cmd *, int, int, int);
194 1.31 perry void siop_update_xfer_mode(struct siop_common_softc *, int);
195 1.31 perry int siop_iwr(struct siop_common_cmd *);
196 1.29 bouyer /* actions to take at return of siop_wdtr_neg(), siop_sdtr_neg() and siop_iwr */
197 1.1 bouyer #define SIOP_NEG_NOP 0x0
198 1.1 bouyer #define SIOP_NEG_MSGOUT 0x1
199 1.1 bouyer #define SIOP_NEG_ACK 0x2
200 1.1 bouyer
201 1.31 perry void siop_minphys(struct buf *);
202 1.31 perry int siop_ioctl(struct scsipi_channel *, u_long,
203 1.31 perry caddr_t, int, struct proc *);
204 1.31 perry void siop_ma (struct siop_common_cmd *);
205 1.31 perry void siop_sdp(struct siop_common_cmd *, int);
206 1.31 perry void siop_update_resid(struct siop_common_cmd *, int);
207 1.31 perry void siop_clearfifo(struct siop_common_softc *);
208 1.31 perry void siop_resetbus(struct siop_common_softc *);
209