1 /* $OpenBSD: siopvar.h,v 1.10 2003/11/16 20:30:06 avsm Exp $ */
2 /* $NetBSD: siopvar.h,v 1.18 2002/04/23 20:41:15 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 /* structure and definitions for the siop driver */
35
36 /* Number of tag */
37 #define SIOP_NTAG 16
38
39 /*
40 * xfer description of the script: tables and reselect script
41 * In struct siop_common_cmd siop_xfer will point to this.
42 */
43 struct siop_xfer {
44 struct siop_common_xfer siop_tables;
45 /* u_int32_t resel[sizeof(load_dsa) / sizeof(load_dsa[0])]; */
46 /* Add some entries to make size 384 bytes (256+128) */
47 u_int32_t resel[36];
48 } __packed;
49
50 /*
51 * This describes a command handled by the SCSI controller
52 * These are chained in either a free list or an active list
53 * We have one queue per target
54 */
55
56 struct siop_cmd {
57 TAILQ_ENTRY (siop_cmd) next;
58 struct siop_common_cmd cmd_c;
59 struct siop_cbd *siop_cbdp; /* pointer to our siop_cbd */
60 int reselslot;
61 };
62 #define cmd_tables cmd_c.siop_tables
63
64 /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
65 struct siop_cbd {
66 TAILQ_ENTRY (siop_cbd) next;
67 struct siop_cmd *cmds;
68 struct siop_xfer *xfers;
69 bus_dmamap_t xferdma; /* DMA map for this block of xfers */
70 };
71
72 /* per-tag struct */
73 struct siop_tag {
74 struct siop_cmd *active; /* active command */
75 u_int reseloff;
76 };
77
78 /* per lun struct */
79 struct siop_lun {
80 struct siop_tag siop_tag[SIOP_NTAG]; /* tag array */
81 int lun_flags;
82 #define SIOP_LUNF_FULL 0x01 /* queue full message */
83 u_int reseloff;
84 };
85
86 /*
87 * per target struct; siop_common_cmd->target and siop_common_softc->targets[]
88 * will point to this
89 */
90 struct siop_target {
91 struct siop_common_target target_c;
92 struct siop_lun *siop_lun[8]; /* per-lun state */
93 u_int reseloff;
94 struct siop_lunsw *lunsw;
95 };
96
97 struct siop_lunsw {
98 TAILQ_ENTRY (siop_lunsw) next;
99 u_int32_t lunsw_off; /* offset of this lun sw, from sc_scriptaddr*/
100 u_int32_t lunsw_size; /* size of this lun sw */
101 };
102
103 static __inline__ void siop_table_sync(struct siop_cmd *, int);
104 static __inline__ void
siop_table_sync(siop_cmd,ops)105 siop_table_sync(siop_cmd, ops)
106 struct siop_cmd *siop_cmd;
107 int ops;
108 {
109 struct siop_common_softc *sc = siop_cmd->cmd_c.siop_sc;
110 bus_addr_t offset;
111
112 offset = siop_cmd->cmd_c.dsa -
113 siop_cmd->siop_cbdp->xferdma->dm_segs[0].ds_addr;
114 bus_dmamap_sync(sc->sc_dmat, siop_cmd->siop_cbdp->xferdma, offset,
115 sizeof(struct siop_xfer), ops);
116 }
117
118
119 TAILQ_HEAD(cmd_list, siop_cmd);
120 TAILQ_HEAD(cbd_list, siop_cbd);
121 TAILQ_HEAD(lunsw_list, siop_lunsw);
122
123
124 /* Driver internal state */
125 struct siop_softc {
126 struct siop_common_softc sc_c;
127 int sc_currschedslot; /* current scheduler slot */
128 struct cbd_list cmds; /* list of command block descriptors */
129 struct cmd_list free_list; /* cmd descr free list */
130 struct cmd_list urgent_list; /* high priority cmd descr list */
131 struct cmd_list ready_list; /* cmd descr ready list */
132 struct lunsw_list lunsw_list; /* lunsw free list */
133 u_int32_t script_free_lo; /* free ram offset from sc_scriptaddr */
134 u_int32_t script_free_hi; /* free ram offset from sc_scriptaddr */
135 int sc_ntargets; /* number of known targets */
136 u_int32_t sc_flags;
137 };
138
139 /* defs for sc_flags */
140 #define SCF_CHAN_NOSLOT 0x0001 /* channel out of scheduler slot */
141
142 void siop_attach(struct siop_softc *);
143 int siop_intr(void *);
144 void siop_add_dev(struct siop_softc *, int, int);
145 void siop_del_dev(struct siop_softc *, int, int);
146