siopvar_common.h revision 1.6 1 /* $NetBSD: siopvar_common.h,v 1.6 2000/10/18 17:06:52 bouyer Exp $ */
2
3 /*
4 * Copyright (c) 2000 Manuel Bouyer.
5 *
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. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Manuel Bouyer
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33 /* common struct and routines used by siop and esiop */
34
35 #ifndef SIOP_DEFAULT_TARGET
36 #define SIOP_DEFAULT_TARGET 7
37 #endif
38
39 /* tables used by SCRIPT */
40 typedef struct scr_table {
41 u_int32_t count;
42 u_int32_t addr;
43 } scr_table_t ;
44
45 /* Number of scatter/gather entries */
46 #define SIOP_NSG (MAXPHYS/NBPG + 1)
47
48 /*
49 * This structure interfaces the SCRIPT with the driver; it describes a full
50 * transfer.
51 */
52 struct siop_xfer_common {
53 u_int8_t msg_out[8]; /* 0 */
54 u_int8_t msg_in[8]; /* 8 */
55 int status; /* 16 */
56 u_int32_t pad1; /* 20 */
57 u_int32_t id; /* 24 */
58 u_int32_t pad2; /* 28 */
59 scr_table_t t_msgin; /* 32 */
60 scr_table_t t_extmsgin; /* 40 */
61 scr_table_t t_extmsgdata; /* 48 */
62 scr_table_t t_msgtag; /* 56 */
63 scr_table_t t_msgout; /* 64 */
64 scr_table_t cmd; /* 72 */
65 scr_table_t t_status; /* 80 */
66 scr_table_t data[SIOP_NSG]; /* 88 */
67 } __attribute__((__packed__));
68
69 /* xfer description of the script: tables and reselect script */
70 struct siop_xfer {
71 struct siop_xfer_common tables;
72 /* u_int32_t resel[sizeof(load_dsa) / sizeof(load_dsa[0])]; */
73 u_int32_t resel[14];
74 } __attribute__((__packed__));
75
76 /*
77 * This decribes a command handled by the SCSI controller
78 * These are chained in either a free list or a active list
79 * We have one queue per target
80 */
81 struct siop_cmd {
82 TAILQ_ENTRY (siop_cmd) next;
83 struct siop_softc *siop_sc; /* points back to our adapter */
84 struct siop_target *siop_target; /* pointer to our target def */
85 struct scsipi_xfer *xs; /* xfer from the upper level */
86 struct siop_xfer *siop_xfer; /* tables dealing with this xfer */
87 #define siop_tables siop_xfer->tables
88 struct siop_cbd *siop_cbdp; /* pointer to our siop_cbd */
89 bus_addr_t dsa; /* DSA value to load */
90 bus_dmamap_t dmamap_cmd;
91 bus_dmamap_t dmamap_data;
92 struct scsipi_sense rs_cmd; /* request sense command buffer */
93 int status;
94 int flags;
95 int reselslot; /* the reselect slot used */
96 };
97
98 /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
99
100 struct siop_cbd {
101 TAILQ_ENTRY (siop_cbd) next;
102 struct siop_cmd *cmds;
103 struct siop_xfer *xfers;
104 bus_dmamap_t xferdma; /* DMA map for this block of xfers */
105 };
106
107 /* status defs */
108 #define CMDST_FREE 0 /* cmd slot is free */
109 #define CMDST_READY 1 /* cmd slot is waiting for processing */
110 #define CMDST_ACTIVE 2 /* cmd slot is being processed */
111 #define CMDST_SENSE 3 /* cmd slot is being requesting sense */
112 #define CMDST_SENSE_ACTIVE 4 /* request sense active */
113 #define CMDST_SENSE_DONE 5 /* request sense done */
114 #define CMDST_DONE 6 /* cmd slot has been processed */
115 /* flags defs */
116 #define CMDFL_TIMEOUT 0x0001 /* cmd timed out */
117 #define CMDFL_TAG 0x0002 /* tagged cmd */
118
119 /* per lun struct */
120 struct siop_lun {
121 struct siop_cmd *active; /* active command */
122 int reseloff; /* XXX tmp */
123 };
124
125 /* per-target struct */
126 struct siop_target {
127 int status; /* target status, see below */
128 int flags; /* target flags, see below */
129 u_int32_t id; /* for SELECT FROM */
130 struct siop_lun siop_lun[8]; /* per-lun state, XXX should be dynamic */
131 int reseloff; /* XXX tmp */
132 struct siop_lunsw *lunsw; /* XXX tmp */
133 };
134
135 /* target status */
136 #define TARST_PROBING 0 /* target is being probed */
137 #define TARST_ASYNC 1 /* target needs sync/wide negotiation */
138 #define TARST_WIDE_NEG 2 /* target is doing wide negotiation */
139 #define TARST_SYNC_NEG 3 /* target is doing sync negotiation */
140 #define TARST_OK 4 /* sync/wide agreement is valid */
141
142 /* target flags */
143 #define TARF_SYNC 0x01 /* target can do sync */
144 #define TARF_WIDE 0x02 /* target can do wide */
145 #define TARF_TAG 0x04 /* target can do tags */
146 #define TARF_ISWIDE 0x08 /* target is wide */
147
148 struct siop_lunsw {
149 TAILQ_ENTRY (siop_lunsw) next;
150 u_int32_t lunsw_off; /* offset of this lun sw, from sc_scriptaddr*/
151 };
152
153 void siop_common_reset __P((struct siop_softc *));
154 int siop_modechange __P((struct siop_softc *));
155
156 int siop_wdtr_neg __P((struct siop_cmd *siop_cmd));
157 int siop_sdtr_neg __P((struct siop_cmd *siop_cmd));
158 /* actions to take at return of siop_wdtr_neg() and siop_sdtr_neg() */
159 #define SIOP_NEG_NOP 0x0
160 #define SIOP_NEG_MSGOUT 0x1
161 #define SIOP_NEG_ACK 0x2
162
163 void siop_minphys __P((struct buf *));
164 int siop_ioctl __P((struct scsipi_link *, u_long,
165 caddr_t, int, struct proc *));
166 void siop_sdp __P((struct siop_cmd *));
167 void siop_clearfifo __P((struct siop_softc *));
168 void siop_resetbus __P((struct siop_softc *));
169