xref: /netbsd-src/sys/dev/ic/siopvar_common.h (revision 9fbd88883c38d0c0fbfcbe66d76fe6b0fab3f9de)
1 /*	$NetBSD: siopvar_common.h,v 1.12 2001/10/22 16:45:28 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 __attribute__((__packed__));
44 
45 /* Number of scatter/gather entries */
46 #define SIOP_NSG	(MAXPHYS/NBPG + 1)	/* XXX NBPG */
47 
48 /* Number of tag */
49 #define SIOP_NTAG 16
50 
51 /*
52  * This structure interfaces the SCRIPT with the driver; it describes a full
53  * transfer.
54  */
55 struct siop_xfer_common {
56 	u_int8_t msg_out[8];	/* 0 */
57 	u_int8_t msg_in[8];	/* 8 */
58 	u_int32_t status;	/* 16 */
59 	u_int32_t pad1;		/* 20 */
60 	u_int32_t id;		/* 24 */
61 	u_int32_t pad2;		/* 28 */
62 	scr_table_t t_msgin;	/* 32 */
63 	scr_table_t t_extmsgin;	/* 40 */
64 	scr_table_t t_extmsgdata; /* 48 */
65 	scr_table_t t_msgout;	/* 56 */
66 	scr_table_t cmd;	/* 64 */
67 	scr_table_t t_status;	/* 72 */
68 	scr_table_t data[SIOP_NSG]; /* 80 */
69 } __attribute__((__packed__));
70 
71 /* status can hold the SCSI_* status values, and 2 additionnal values: */
72 #define SCSI_SIOP_NOCHECK	0xfe	/* don't check the scsi status */
73 #define SCSI_SIOP_NOSTATUS	0xff	/* device didn't report status */
74 
75 /* xfer description of the script: tables and reselect script */
76 struct siop_xfer {
77 	struct siop_xfer_common tables;
78 	/* u_int32_t resel[sizeof(load_dsa) / sizeof(load_dsa[0])]; */
79 	u_int32_t resel[25];
80 } __attribute__((__packed__));
81 
82 /*
83  * This decribes a command handled by the SCSI controller
84  * These are chained in either a free list or a active list
85  * We have one queue per target
86  */
87 struct siop_cmd {
88 	TAILQ_ENTRY (siop_cmd) next;
89 	struct siop_softc *siop_sc; /* points back to our adapter */
90 	struct siop_target *siop_target; /* pointer to our target def */
91 	struct scsipi_xfer *xs; /* xfer from the upper level */
92 	struct siop_xfer *siop_xfer; /* tables dealing with this xfer */
93 #define siop_tables siop_xfer->tables
94 	struct siop_cbd *siop_cbdp; /* pointer to our siop_cbd */
95 	bus_addr_t	dsa; /* DSA value to load */
96 	bus_dmamap_t	dmamap_cmd;
97 	bus_dmamap_t	dmamap_data;
98 	int status;
99 	int flags;
100 	int reselslot; /* the reselect slot used */
101 	int tag;	/* tag used for tagged command queuing */
102 };
103 
104 /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
105 
106 struct siop_cbd {
107 	TAILQ_ENTRY (siop_cbd) next;
108 	struct siop_cmd *cmds;
109 	struct siop_xfer *xfers;
110 	bus_dmamap_t xferdma; /* DMA map for this block of xfers */
111 };
112 
113 /* status defs */
114 #define CMDST_FREE		0 /* cmd slot is free */
115 #define CMDST_READY		1 /* cmd slot is waiting for processing */
116 #define CMDST_ACTIVE		2 /* cmd slot is being processed */
117 #define CMDST_DONE		3 /* cmd slot has been processed */
118 /* flags defs */
119 #define CMDFL_TIMEOUT	0x0001 /* cmd timed out */
120 #define CMDFL_TAG	0x0002 /* tagged cmd */
121 
122 /* per-tag struct */
123 struct siop_tag {
124 	struct siop_cmd *active; /* active command */
125 	u_int reseloff; /* XXX */
126 };
127 
128 /* per lun struct */
129 struct siop_lun {
130 	struct siop_tag siop_tag[SIOP_NTAG]; /* tag array */
131 	int lun_flags; /* per-lun flags, none currently */
132 	u_int reseloff; /* XXX */
133 };
134 
135 /* per-target struct */
136 struct siop_target {
137 	int status;	/* target status, see below */
138 	int flags;	/* target flags, see below */
139 	u_int32_t id;	/* for SELECT FROM */
140 	int period;
141 	int offset;
142 	struct siop_lun *siop_lun[8]; /* per-lun state */
143 	u_int reseloff; /* XXX */
144 	struct siop_lunsw *lunsw; /* XXX */
145 };
146 
147 /* target status */
148 #define TARST_PROBING	0 /* target is being probed */
149 #define TARST_ASYNC	1 /* target needs sync/wide negotiation */
150 #define TARST_WIDE_NEG	2 /* target is doing wide negotiation */
151 #define TARST_SYNC_NEG	3 /* target is doing sync negotiation */
152 #define TARST_OK	4 /* sync/wide agreement is valid */
153 
154 /* target flags */
155 #define TARF_SYNC	0x01 /* target can do sync */
156 #define TARF_WIDE	0x02 /* target can do wide */
157 #define TARF_TAG	0x04 /* target can do tags */
158 #define TARF_ISWIDE	0x08 /* target is wide */
159 
160 struct siop_lunsw {
161 	TAILQ_ENTRY (siop_lunsw) next;
162 	u_int32_t lunsw_off; /* offset of this lun sw, from sc_scriptaddr*/
163 	u_int32_t lunsw_size; /* size of this lun sw */
164 };
165 
166 static __inline__ void siop_table_sync __P((struct siop_cmd *, int));
167 static __inline__ void
168 siop_table_sync(siop_cmd, ops)
169 	struct siop_cmd *siop_cmd;
170 	int ops;
171 {
172 	struct siop_softc *sc  = siop_cmd->siop_sc;
173 	bus_addr_t offset;
174 
175 	offset = siop_cmd->dsa -
176 	    siop_cmd->siop_cbdp->xferdma->dm_segs[0].ds_addr;
177 	bus_dmamap_sync(sc->sc_dmat, siop_cmd->siop_cbdp->xferdma, offset,
178 	    sizeof(struct siop_xfer), ops);
179 }
180 
181 void	siop_common_reset __P((struct siop_softc *));
182 void	siop_setuptables __P((struct siop_cmd *));
183 int	siop_modechange __P((struct siop_softc *));
184 
185 int	siop_wdtr_neg __P((struct siop_cmd *));
186 int	siop_sdtr_neg __P((struct siop_cmd *));
187 void	siop_sdtr_msg __P((struct siop_cmd *, int, int, int));
188 void	siop_wdtr_msg __P((struct siop_cmd *, int, int));
189 void	siop_update_xfer_mode __P((struct siop_softc *, int));
190 /* actions to take at return of siop_wdtr_neg() and siop_sdtr_neg() */
191 #define SIOP_NEG_NOP	0x0
192 #define SIOP_NEG_MSGOUT	0x1
193 #define SIOP_NEG_ACK	0x2
194 
195 void	siop_minphys __P((struct buf *));
196 int	siop_ioctl __P((struct scsipi_channel *, u_long,
197 		caddr_t, int, struct proc *));
198 void 	siop_sdp __P((struct siop_cmd *));
199 void	siop_clearfifo __P((struct siop_softc *));
200 void	siop_resetbus __P((struct siop_softc *));
201 /* XXXX should be  callbacks */
202 void	siop_add_dev __P((struct siop_softc *, int, int));
203 void	siop_del_dev __P((struct siop_softc *, int, int));
204