siopvar.h revision 1.18 1 1.18 bouyer /* $NetBSD: siopvar.h,v 1.18 2002/04/23 20:41:15 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.18 bouyer * This product includes software developed by Manuel Bouyer.
17 1.3 bouyer * 4. The name of the author may not be used to endorse or promote products
18 1.3 bouyer * derived from this software without specific prior written permission.
19 1.1 bouyer *
20 1.5 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.5 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.5 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.5 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.5 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.5 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.5 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.5 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.5 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.5 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 /* structure and definitions for the siop driver */
34 1.1 bouyer
35 1.17 bouyer /* Number of tag */
36 1.17 bouyer #define SIOP_NTAG 16
37 1.17 bouyer
38 1.17 bouyer /*
39 1.17 bouyer * xfer description of the script: tables and reselect script
40 1.17 bouyer * In struct siop_common_cmd siop_xfer will point to this.
41 1.17 bouyer */
42 1.17 bouyer struct siop_xfer {
43 1.17 bouyer struct siop_common_xfer siop_tables;
44 1.17 bouyer /* u_int32_t resel[sizeof(load_dsa) / sizeof(load_dsa[0])]; */
45 1.17 bouyer u_int32_t resel[25];
46 1.17 bouyer } __attribute__((__packed__));
47 1.17 bouyer
48 1.17 bouyer /*
49 1.17 bouyer * This decribes a command handled by the SCSI controller
50 1.17 bouyer * These are chained in either a free list or a active list
51 1.17 bouyer * We have one queue per target
52 1.17 bouyer */
53 1.17 bouyer
54 1.17 bouyer struct siop_cmd {
55 1.17 bouyer TAILQ_ENTRY (siop_cmd) next;
56 1.17 bouyer struct siop_common_cmd cmd_c;
57 1.17 bouyer struct siop_cbd *siop_cbdp; /* pointer to our siop_cbd */
58 1.17 bouyer int reselslot;
59 1.17 bouyer };
60 1.17 bouyer #define cmd_tables cmd_c.siop_tables
61 1.17 bouyer
62 1.17 bouyer /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
63 1.17 bouyer struct siop_cbd {
64 1.17 bouyer TAILQ_ENTRY (siop_cbd) next;
65 1.17 bouyer struct siop_cmd *cmds;
66 1.17 bouyer struct siop_xfer *xfers;
67 1.17 bouyer bus_dmamap_t xferdma; /* DMA map for this block of xfers */
68 1.17 bouyer };
69 1.17 bouyer
70 1.17 bouyer /* per-tag struct */
71 1.17 bouyer struct siop_tag {
72 1.17 bouyer struct siop_cmd *active; /* active command */
73 1.17 bouyer u_int reseloff;
74 1.17 bouyer };
75 1.17 bouyer
76 1.17 bouyer /* per lun struct */
77 1.17 bouyer struct siop_lun {
78 1.17 bouyer struct siop_tag siop_tag[SIOP_NTAG]; /* tag array */
79 1.17 bouyer int lun_flags; /* per-lun flags, none currently */
80 1.17 bouyer u_int reseloff;
81 1.17 bouyer };
82 1.17 bouyer
83 1.17 bouyer /*
84 1.17 bouyer * per target struct; siop_common_cmd->target and siop_common_softc->targets[]
85 1.17 bouyer * will point to this
86 1.17 bouyer */
87 1.17 bouyer struct siop_target {
88 1.17 bouyer struct siop_common_target target_c;
89 1.17 bouyer struct siop_lun *siop_lun[8]; /* per-lun state */
90 1.17 bouyer u_int reseloff;
91 1.17 bouyer struct siop_lunsw *lunsw;
92 1.17 bouyer };
93 1.17 bouyer
94 1.17 bouyer struct siop_lunsw {
95 1.17 bouyer TAILQ_ENTRY (siop_lunsw) next;
96 1.17 bouyer u_int32_t lunsw_off; /* offset of this lun sw, from sc_scriptaddr*/
97 1.17 bouyer u_int32_t lunsw_size; /* size of this lun sw */
98 1.17 bouyer };
99 1.17 bouyer
100 1.17 bouyer static __inline__ void siop_table_sync __P((struct siop_cmd *, int));
101 1.17 bouyer static __inline__ void
102 1.17 bouyer siop_table_sync(siop_cmd, ops)
103 1.17 bouyer struct siop_cmd *siop_cmd;
104 1.17 bouyer int ops;
105 1.17 bouyer {
106 1.17 bouyer struct siop_common_softc *sc = siop_cmd->cmd_c.siop_sc;
107 1.17 bouyer bus_addr_t offset;
108 1.17 bouyer
109 1.17 bouyer offset = siop_cmd->cmd_c.dsa -
110 1.17 bouyer siop_cmd->siop_cbdp->xferdma->dm_segs[0].ds_addr;
111 1.17 bouyer bus_dmamap_sync(sc->sc_dmat, siop_cmd->siop_cbdp->xferdma, offset,
112 1.17 bouyer sizeof(struct siop_xfer), ops);
113 1.17 bouyer }
114 1.17 bouyer
115 1.17 bouyer
116 1.1 bouyer TAILQ_HEAD(cmd_list, siop_cmd);
117 1.6 bouyer TAILQ_HEAD(cbd_list, siop_cbd);
118 1.11 bouyer TAILQ_HEAD(lunsw_list, siop_lunsw);
119 1.1 bouyer
120 1.17 bouyer
121 1.1 bouyer /* Driver internal state */
122 1.1 bouyer struct siop_softc {
123 1.17 bouyer struct siop_common_softc sc_c;
124 1.10 bouyer int sc_currschedslot; /* current scheduler slot */
125 1.6 bouyer struct cbd_list cmds; /* list of command block descriptors */
126 1.1 bouyer struct cmd_list free_list; /* cmd descr free list */
127 1.11 bouyer struct lunsw_list lunsw_list; /* lunsw free list */
128 1.12 bouyer u_int32_t script_free_lo; /* free ram offset from sc_scriptaddr */
129 1.12 bouyer u_int32_t script_free_hi; /* free ram offset from sc_scriptaddr */
130 1.12 bouyer int sc_ntargets; /* number of known targets */
131 1.1 bouyer u_int32_t sc_flags;
132 1.1 bouyer };
133 1.17 bouyer
134 1.1 bouyer /* defs for sc_flags */
135 1.16 bouyer #define SCF_CHAN_NOSLOT 0x0001 /* channel out of sheduler slot */
136 1.1 bouyer
137 1.1 bouyer void siop_attach __P((struct siop_softc *));
138 1.1 bouyer int siop_intr __P((void *));
139 1.17 bouyer void siop_add_dev __P((struct siop_softc *, int, int));
140 1.17 bouyer void siop_del_dev __P((struct siop_softc *, int, int));
141