siopvar_common.h revision 1.13 1 1.13 bouyer /* $NetBSD: siopvar_common.h,v 1.13 2002/04/20 00:15:54 bouyer 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.1 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.1 bouyer * 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.1 bouyer
33 1.1 bouyer /* common struct and routines used by siop and esiop */
34 1.1 bouyer
35 1.1 bouyer #ifndef SIOP_DEFAULT_TARGET
36 1.1 bouyer #define SIOP_DEFAULT_TARGET 7
37 1.1 bouyer #endif
38 1.1 bouyer
39 1.1 bouyer /* tables used by SCRIPT */
40 1.1 bouyer typedef struct scr_table {
41 1.1 bouyer u_int32_t count;
42 1.1 bouyer u_int32_t addr;
43 1.12 bouyer } scr_table_t __attribute__((__packed__));
44 1.1 bouyer
45 1.1 bouyer /* Number of scatter/gather entries */
46 1.9 thorpej #define SIOP_NSG (MAXPHYS/NBPG + 1) /* XXX NBPG */
47 1.1 bouyer
48 1.1 bouyer /*
49 1.1 bouyer * This structure interfaces the SCRIPT with the driver; it describes a full
50 1.6 bouyer * transfer.
51 1.1 bouyer */
52 1.13 bouyer struct siop_common_xfer {
53 1.1 bouyer u_int8_t msg_out[8]; /* 0 */
54 1.1 bouyer u_int8_t msg_in[8]; /* 8 */
55 1.8 bouyer u_int32_t status; /* 16 */
56 1.1 bouyer u_int32_t pad1; /* 20 */
57 1.1 bouyer u_int32_t id; /* 24 */
58 1.1 bouyer u_int32_t pad2; /* 28 */
59 1.1 bouyer scr_table_t t_msgin; /* 32 */
60 1.1 bouyer scr_table_t t_extmsgin; /* 40 */
61 1.1 bouyer scr_table_t t_extmsgdata; /* 48 */
62 1.7 bouyer scr_table_t t_msgout; /* 56 */
63 1.7 bouyer scr_table_t cmd; /* 64 */
64 1.7 bouyer scr_table_t t_status; /* 72 */
65 1.7 bouyer scr_table_t data[SIOP_NSG]; /* 80 */
66 1.1 bouyer } __attribute__((__packed__));
67 1.8 bouyer
68 1.8 bouyer /* status can hold the SCSI_* status values, and 2 additionnal values: */
69 1.8 bouyer #define SCSI_SIOP_NOCHECK 0xfe /* don't check the scsi status */
70 1.8 bouyer #define SCSI_SIOP_NOSTATUS 0xff /* device didn't report status */
71 1.1 bouyer
72 1.1 bouyer /*
73 1.1 bouyer * This decribes a command handled by the SCSI controller
74 1.1 bouyer */
75 1.13 bouyer struct siop_common_cmd {
76 1.13 bouyer struct siop_common_softc *siop_sc; /* points back to our adapter */
77 1.13 bouyer struct siop_common_target *siop_target; /* pointer to our target def */
78 1.1 bouyer struct scsipi_xfer *xs; /* xfer from the upper level */
79 1.13 bouyer struct siop_common_xfer *siop_tables; /* tables for this cmd */
80 1.1 bouyer bus_addr_t dsa; /* DSA value to load */
81 1.1 bouyer bus_dmamap_t dmamap_cmd;
82 1.1 bouyer bus_dmamap_t dmamap_data;
83 1.7 bouyer int status;
84 1.7 bouyer int flags;
85 1.7 bouyer int tag; /* tag used for tagged command queuing */
86 1.2 bouyer };
87 1.2 bouyer
88 1.1 bouyer /* status defs */
89 1.1 bouyer #define CMDST_FREE 0 /* cmd slot is free */
90 1.1 bouyer #define CMDST_READY 1 /* cmd slot is waiting for processing */
91 1.1 bouyer #define CMDST_ACTIVE 2 /* cmd slot is being processed */
92 1.11 bouyer #define CMDST_DONE 3 /* cmd slot has been processed */
93 1.1 bouyer /* flags defs */
94 1.1 bouyer #define CMDFL_TIMEOUT 0x0001 /* cmd timed out */
95 1.6 bouyer #define CMDFL_TAG 0x0002 /* tagged cmd */
96 1.6 bouyer
97 1.1 bouyer /* per-target struct */
98 1.13 bouyer struct siop_common_target {
99 1.1 bouyer int status; /* target status, see below */
100 1.1 bouyer int flags; /* target flags, see below */
101 1.1 bouyer u_int32_t id; /* for SELECT FROM */
102 1.11 bouyer int period;
103 1.11 bouyer int offset;
104 1.1 bouyer };
105 1.1 bouyer
106 1.1 bouyer /* target status */
107 1.1 bouyer #define TARST_PROBING 0 /* target is being probed */
108 1.1 bouyer #define TARST_ASYNC 1 /* target needs sync/wide negotiation */
109 1.1 bouyer #define TARST_WIDE_NEG 2 /* target is doing wide negotiation */
110 1.1 bouyer #define TARST_SYNC_NEG 3 /* target is doing sync negotiation */
111 1.1 bouyer #define TARST_OK 4 /* sync/wide agreement is valid */
112 1.1 bouyer
113 1.1 bouyer /* target flags */
114 1.6 bouyer #define TARF_SYNC 0x01 /* target can do sync */
115 1.6 bouyer #define TARF_WIDE 0x02 /* target can do wide */
116 1.6 bouyer #define TARF_TAG 0x04 /* target can do tags */
117 1.6 bouyer #define TARF_ISWIDE 0x08 /* target is wide */
118 1.6 bouyer
119 1.13 bouyer /* Driver internal state */
120 1.13 bouyer struct siop_common_softc {
121 1.13 bouyer struct device sc_dev;
122 1.13 bouyer struct scsipi_channel sc_chan;
123 1.13 bouyer struct scsipi_adapter sc_adapt;
124 1.13 bouyer int features; /* chip's features */
125 1.13 bouyer int ram_size;
126 1.13 bouyer int maxburst;
127 1.13 bouyer int maxoff;
128 1.13 bouyer int clock_div; /* async. clock divider (scntl3) */
129 1.13 bouyer int clock_period; /* clock period (ns * 10) */
130 1.13 bouyer int minsync; /* min and max sync period, */
131 1.13 bouyer int maxsync; /* as sent in SDTR message */
132 1.13 bouyer bus_space_tag_t sc_rt; /* bus_space registers tag */
133 1.13 bouyer bus_space_handle_t sc_rh; /* bus_space registers handle */
134 1.13 bouyer bus_addr_t sc_raddr; /* register adresses */
135 1.13 bouyer bus_space_tag_t sc_ramt; /* bus_space ram tag */
136 1.13 bouyer bus_space_handle_t sc_ramh; /* bus_space ram handle */
137 1.13 bouyer bus_dma_tag_t sc_dmat; /* bus DMA tag */
138 1.13 bouyer void (*sc_reset) __P((struct siop_common_softc*)); /* reset callback */
139 1.13 bouyer bus_dmamap_t sc_scriptdma; /* DMA map for script */
140 1.13 bouyer bus_addr_t sc_scriptaddr; /* on-board ram or physical adress */
141 1.13 bouyer u_int32_t *sc_script; /* script location in memory */
142 1.13 bouyer struct siop_common_target *targets[16]; /* per-target states */
143 1.13 bouyer };
144 1.13 bouyer
145 1.13 bouyer /* features */
146 1.13 bouyer #define SF_BUS_WIDE 0x00000001 /* wide bus */
147 1.13 bouyer #define SF_BUS_ULTRA 0x00000002 /* Ultra (20Mhz) bus */
148 1.13 bouyer #define SF_BUS_ULTRA2 0x00000004 /* Ultra2 (40Mhz) bus */
149 1.13 bouyer #define SF_BUS_DIFF 0x00000008 /* differential bus */
150 1.13 bouyer
151 1.13 bouyer #define SF_CHIP_LED0 0x00000100 /* led on GPIO0 */
152 1.13 bouyer #define SF_CHIP_DBLR 0x00000200 /* clock doubler or quadrupler */
153 1.13 bouyer #define SF_CHIP_QUAD 0x00000400 /* clock quadrupler, with PPL */
154 1.13 bouyer #define SF_CHIP_FIFO 0x00000800 /* large fifo */
155 1.13 bouyer #define SF_CHIP_PF 0x00001000 /* Intructions prefetch */
156 1.13 bouyer #define SF_CHIP_RAM 0x00002000 /* on-board RAM */
157 1.13 bouyer #define SF_CHIP_LS 0x00004000 /* load/store instruction */
158 1.13 bouyer #define SF_CHIP_10REGS 0x00008000 /* 10 scratch registers */
159 1.13 bouyer #define SF_CHIP_DFBC 0x00010000 /* Use DFBC register */
160 1.13 bouyer
161 1.13 bouyer #define SF_PCI_RL 0x01000000 /* PCI read line */
162 1.13 bouyer #define SF_PCI_RM 0x02000000 /* PCI read multiple */
163 1.13 bouyer #define SF_PCI_BOF 0x04000000 /* PCI burst opcode fetch */
164 1.13 bouyer #define SF_PCI_CLS 0x08000000 /* PCI cache line size */
165 1.13 bouyer #define SF_PCI_WRI 0x10000000 /* PCI write and invalidate */
166 1.13 bouyer
167 1.13 bouyer void siop_common_reset __P((struct siop_common_softc *));
168 1.13 bouyer void siop_setuptables __P((struct siop_common_cmd *));
169 1.13 bouyer int siop_modechange __P((struct siop_common_softc *));
170 1.13 bouyer
171 1.13 bouyer int siop_wdtr_neg __P((struct siop_common_cmd *));
172 1.13 bouyer int siop_sdtr_neg __P((struct siop_common_cmd *));
173 1.13 bouyer void siop_sdtr_msg __P((struct siop_common_cmd *, int, int, int));
174 1.13 bouyer void siop_wdtr_msg __P((struct siop_common_cmd *, int, int));
175 1.13 bouyer void siop_update_xfer_mode __P((struct siop_common_softc *, int));
176 1.1 bouyer /* actions to take at return of siop_wdtr_neg() and siop_sdtr_neg() */
177 1.1 bouyer #define SIOP_NEG_NOP 0x0
178 1.1 bouyer #define SIOP_NEG_MSGOUT 0x1
179 1.1 bouyer #define SIOP_NEG_ACK 0x2
180 1.1 bouyer
181 1.1 bouyer void siop_minphys __P((struct buf *));
182 1.11 bouyer int siop_ioctl __P((struct scsipi_channel *, u_long,
183 1.1 bouyer caddr_t, int, struct proc *));
184 1.13 bouyer void siop_sdp __P((struct siop_common_cmd *));
185 1.13 bouyer void siop_clearfifo __P((struct siop_common_softc *));
186 1.13 bouyer void siop_resetbus __P((struct siop_common_softc *));
187