xref: /openbsd-src/sys/dev/ic/siopvar_common.h (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1 /*	$OpenBSD: siopvar_common.h,v 1.6 2001/06/25 23:14:40 krw Exp $ */
2 /*	$NetBSD: siopvar_common.h,v 1.10 2001/01/26 21:58:56 bouyer Exp $	*/
3 
4 /*
5  * Copyright (c) 2000 Manuel Bouyer.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by Manuel Bouyer
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
33 
34 /* common struct and routines used by siop and esiop */
35 
36 #ifndef SIOP_DEFAULT_TARGET
37 #define SIOP_DEFAULT_TARGET 7
38 #endif
39 
40 /* tables used by SCRIPT */
41 typedef struct scr_table {
42 	u_int32_t count;
43 	u_int32_t addr;
44 } scr_table_t ;
45 
46 /* Number of scatter/gather entries */
47 #define SIOP_NSG	(MAXPHYS/NBPG + 1)	/* XXX NBPG */
48 
49 /* Number of tags, also number of openings if tags are used */
50 #define SIOP_NTAG 16
51 
52 /* Number of openings if tags are not used */
53 #define SIOP_OPENINGS 2
54 
55 /*
56  * This structure interfaces the SCRIPT with the driver; it describes a full
57  * transfer.
58  */
59 struct siop_xfer_common {
60 	u_int8_t msg_out[16];	    /*  0 */
61 	u_int8_t msg_in[16];	    /* 16 */
62 	u_int32_t status;	    /* 32 */
63 	u_int32_t pad1;		    /* 36 */
64 	u_int32_t id;		    /* 40 */
65 	u_int32_t pad2;		    /* 44 */
66 	scr_table_t t_msgin;	    /* 48 */
67 	scr_table_t t_extmsgin;	    /* 56 */
68 	scr_table_t t_extmsgdata;   /* 64 */
69 	scr_table_t t_msgout;	    /* 72 */
70 	scr_table_t cmd;	    /* 80 */
71 	scr_table_t t_status;	    /* 88 */
72 	scr_table_t data[SIOP_NSG]; /* 96 */
73 } __attribute__((__packed__));
74 
75 /* status can hold the SCSI_* status values, and 2 additional values: */
76 #define SCSI_SIOP_NOCHECK	0xfe	/* don't check the scsi status */
77 #define SCSI_SIOP_NOSTATUS	0xff	/* device didn't report status */
78 
79 /* xfer description of the script: tables and reselect script */
80 struct siop_xfer {
81 	struct siop_xfer_common tables;
82 	/* u_int32_t resel[sizeof(load_dsa) / sizeof(load_dsa[0])]; */
83 	u_int32_t resel[25];
84 } __attribute__((__packed__));
85 
86 /*
87  * This describes a command handled by the SCSI controller.
88  * These are chained in either a free list or a active list.
89  * We have one queue per target.
90  */
91 struct siop_cmd {
92 	TAILQ_ENTRY (siop_cmd) next;
93 	struct siop_softc *siop_sc; /* points back to our adapter */
94 	struct siop_target *siop_target; /* pointer to our target def */
95 	struct scsi_xfer *xs; /* xfer from the upper level */
96 	struct siop_xfer *siop_xfer; /* tables dealing with this xfer */
97 #define siop_tables siop_xfer->tables
98 	struct siop_cbd *siop_cbdp; /* pointer to our siop_cbd */
99 	bus_addr_t	dsa; /* DSA value to load */
100 	bus_dmamap_t	dmamap_cmd;
101 	bus_dmamap_t	dmamap_data;
102 	struct scsi_sense rs_cmd; /* request sense command buffer */
103 	int status;
104 	int flags;
105 	int reselslot; /* the reselect slot used */
106 	int tag;	/* tag used for tagged command queuing */
107 };
108 
109 /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
110 
111 struct siop_cbd {
112 	TAILQ_ENTRY (siop_cbd) next;
113 	struct siop_cmd *cmds;
114 	struct siop_xfer *xfers;
115 	bus_dmamap_t xferdma; /* DMA map for this block of xfers */
116 };
117 
118 /* status defs */
119 #define CMDST_FREE		0 /* cmd slot is free */
120 #define CMDST_READY		1 /* cmd slot is waiting for processing */
121 #define CMDST_ACTIVE		2 /* cmd slot is being processed */
122 #define CMDST_SENSE		3 /* cmd slot is requesting sense */
123 #define CMDST_SENSE_ACTIVE	4 /* request sense active */
124 #define CMDST_SENSE_DONE 	5 /* request sense done */
125 #define CMDST_DONE		6 /* cmd slot has been processed */
126 /* flags defs */
127 #define CMDFL_TIMEOUT	0x0001 /* cmd timed out */
128 #define CMDFL_TAG	0x0002 /* tagged cmd */
129 
130 /* per-tag struct */
131 struct siop_tag {
132 	struct siop_cmd *active; /* active command */
133 	u_int reseloff; /* XXX */
134 };
135 
136 /* per lun struct */
137 struct siop_lun {
138 	struct siop_tag siop_tag[SIOP_NTAG]; /* tag array */
139 	int lun_flags; /* per-lun flags, see below */
140 	u_int reseloff; /* XXX */
141 };
142 
143 #define SIOP_LUNF_FULL 0x01 /* queue full message */
144 
145 /* per-target struct */
146 struct siop_target {
147 	int status;	/* target status, see below */
148 	int flags;	/* target flags, see below */
149 	u_int32_t id;	/* for SELECT FROM
150 			 * 31-24 == SCNTL3
151 			 * 23-16 == SCSI id
152 			 * 15- 8 == SXFER
153 			 *  7- 0 == SCNTL4
154 			 */
155 	struct siop_lun *siop_lun[8]; /* per-lun state */
156 	u_int reseloff; /* XXX */
157 	struct siop_lunsw *lunsw; /* XXX */
158 };
159 
160 /* target status */
161 #define TARST_PROBING	0 /* target is being probed */
162 #define TARST_ASYNC	1 /* target needs sync/wide negotiation */
163 #define TARST_WIDE_NEG	2 /* target is doing wide negotiation */
164 #define TARST_SYNC_NEG	3 /* target is doing sync negotiation */
165 #define TARST_PPR_NEG	4 /* target is doing PPR (Parallel Protocol Request) */
166 #define TARST_OK	5 /* sync/wide agreement is valid */
167 
168 /* target flags */
169 #define TARF_SYNC	0x01 /* target can do sync xfers      */
170 #define TARF_WIDE	0x02 /* target can do wide xfers      */
171 #define TARF_TAG	0x04 /* target can do taggged queuing */
172 #define TARF_PPR	0x08 /* target can do PPR negotiation */
173 
174 #define TARF_ISWIDE	0x10 /* target is using wide xfers    */
175 #define TARF_ISIUS	0x20 /* target is using IUS           */
176 #define TARF_ISDT	0x40 /* target is using DT            */
177 #define TARF_ISQAS	0x80 /* target is using QAS           */
178 
179 struct siop_lunsw {
180 	TAILQ_ENTRY (siop_lunsw) next;
181 	u_int32_t lunsw_off; /* offset of this lun sw, from sc_scriptaddr*/
182 	u_int32_t lunsw_size; /* size of this lun sw */
183 };
184 
185 static __inline__ void siop_table_sync __P((struct siop_cmd *, int));
186 static __inline__ void
187 siop_table_sync(siop_cmd, ops)
188 	struct siop_cmd *siop_cmd;
189 	int ops;
190 {
191 	struct siop_softc *sc = siop_cmd->siop_sc;
192 	bus_dmamap_sync(sc->sc_dmat, siop_cmd->siop_cbdp->xferdma, ops);
193 }
194 
195 void	siop_common_reset __P((struct siop_softc *));
196 void	siop_setuptables __P((struct siop_cmd *));
197 int	siop_modechange __P((struct siop_softc *));
198 
199 int	siop_wdtr_neg __P((struct siop_cmd *));
200 int	siop_sdtr_neg __P((struct siop_cmd *));
201 int     siop_ppr_neg  __P((struct siop_cmd *));
202 void	siop_sdtr_msg __P((struct siop_cmd *, int, int, int));
203 void	siop_wdtr_msg __P((struct siop_cmd *, int, int));
204 void    siop_ppr_msg  __P((struct siop_cmd *, int, int, int));
205 
206 /* actions to take at return of siop_<xxx>_neg() */
207 #define SIOP_NEG_NOP	0x0
208 #define SIOP_NEG_MSGOUT	0x1
209 #define SIOP_NEG_ACK	0x2
210 #define SIOP_NEG_MSGREJ	0x3
211 
212 void	siop_print_info __P((struct siop_softc *, int));
213 void	siop_minphys __P((struct buf *));
214 void 	siop_sdp __P((struct siop_cmd *));
215 void	siop_clearfifo __P((struct siop_softc *));
216 void	siop_resetbus __P((struct siop_softc *));
217 
218 int     siop_period_factor_to_scf __P((struct siop_softc *, int, int));
219 int     siop_scf_to_period_factor __P((struct siop_softc *, int, int));
220 
221 /* XXXX should be  callbacks */
222 void	siop_add_dev __P((struct siop_softc *, int, int));
223 void	siop_del_dev __P((struct siop_softc *, int, int));
224