esiopvar.h revision 1.21 1 1.21 msaitoh /* $NetBSD: esiopvar.h,v 1.21 2012/08/24 09:01:22 msaitoh Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 2002 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 *
15 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.12 perry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 bouyer *
26 1.1 bouyer */
27 1.1 bouyer
28 1.1 bouyer /* structure and definitions for the siop driver */
29 1.1 bouyer
30 1.1 bouyer /* Number of tag */
31 1.1 bouyer #define ESIOP_NTAG 256
32 1.1 bouyer
33 1.1 bouyer /*
34 1.2 bouyer * description of a command scheduler slot. The script uses a ring of
35 1.2 bouyer * A_ncmd_slots of this.
36 1.2 bouyer */
37 1.2 bouyer struct esiop_slot {
38 1.19 tsutsui uint32_t dsa; /* DSA of the xfer. The first 2 bits holds flags */
39 1.16 perry } __packed;
40 1.2 bouyer
41 1.19 tsutsui #define CMD_SLOTSIZE (sizeof(struct esiop_slot) / sizeof(uint32_t))
42 1.4 bouyer
43 1.2 bouyer /*
44 1.1 bouyer * xfer description of the script: tables and reselect script
45 1.1 bouyer * In struct siop_common_cmd siop_xfer will point to this.
46 1.4 bouyer * If you change this don't forget to update o_cmd_* and cmd_slot_size in script
47 1.1 bouyer */
48 1.1 bouyer struct esiop_xfer {
49 1.1 bouyer struct siop_common_xfer siop_tables;
50 1.19 tsutsui uint32_t tlq; /* target/lun/tag loaded in scratchC by script */
51 1.19 tsutsui uint32_t saved_offset;/* contains scratchA if script saved an offset */
52 1.16 perry } __packed;
53 1.1 bouyer
54 1.13 bouyer #define ESIOP_XFER(cmd, m) (((struct esiop_xfer *)((cmd)->cmd_tables))->m)
55 1.13 bouyer
56 1.1 bouyer /*
57 1.8 wiz * This describes a command handled by the SCSI controller
58 1.21 msaitoh * These are chained in either a free list or an active list
59 1.1 bouyer * We have one queue per target
60 1.1 bouyer */
61 1.1 bouyer
62 1.1 bouyer struct esiop_cmd {
63 1.1 bouyer TAILQ_ENTRY (esiop_cmd) next;
64 1.1 bouyer struct siop_common_cmd cmd_c;
65 1.1 bouyer struct esiop_cbd *esiop_cbdp; /* pointer to our siop_cbd */
66 1.1 bouyer };
67 1.1 bouyer #define cmd_tables cmd_c.siop_tables
68 1.1 bouyer
69 1.1 bouyer /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
70 1.1 bouyer struct esiop_cbd {
71 1.1 bouyer TAILQ_ENTRY (esiop_cbd) next;
72 1.1 bouyer struct esiop_cmd *cmds;
73 1.1 bouyer struct esiop_xfer *xfers;
74 1.1 bouyer bus_dmamap_t xferdma; /* DMA map for this block of xfers */
75 1.1 bouyer };
76 1.1 bouyer
77 1.2 bouyer TAILQ_HEAD(cmd_list, esiop_cmd);
78 1.2 bouyer TAILQ_HEAD(cbd_list, esiop_cbd);
79 1.2 bouyer
80 1.2 bouyer /* DSA table descriptor for tags. Free tables are in a list */
81 1.2 bouyer struct esiop_dsatbl {
82 1.2 bouyer TAILQ_ENTRY (esiop_dsatbl) next;
83 1.19 tsutsui uint32_t *tbl; /* the table itself */
84 1.19 tsutsui uint32_t tbl_dsa; /* DSA of base of this table */
85 1.2 bouyer bus_addr_t tbl_offset; /* offset of this table in the map */
86 1.2 bouyer struct esiop_dsatblblk *tblblk; /* pointer back to our block */
87 1.2 bouyer };
88 1.2 bouyer
89 1.2 bouyer /* DSA table block descriptor. */
90 1.2 bouyer struct esiop_dsatblblk {
91 1.2 bouyer TAILQ_ENTRY (esiop_dsatblblk) next;
92 1.2 bouyer bus_dmamap_t blkmap; /* DMA map of this block */
93 1.2 bouyer };
94 1.2 bouyer
95 1.2 bouyer TAILQ_HEAD(tbl_list, esiop_dsatbl);
96 1.2 bouyer TAILQ_HEAD(tblblk_list, esiop_dsatblblk);
97 1.2 bouyer
98 1.2 bouyer /* Number of table per block */
99 1.19 tsutsui #define ESIOP_NTPB ((PAGE_SIZE) / (sizeof(uint32_t) * ESIOP_NTAG))
100 1.2 bouyer
101 1.1 bouyer /* per lun struct */
102 1.1 bouyer struct esiop_lun {
103 1.2 bouyer struct esiop_cmd *active; /* active non-tagged command */
104 1.2 bouyer struct esiop_cmd *tactive[ESIOP_NTAG]; /* active tagged commands */
105 1.2 bouyer int lun_flags; /* per-lun flags */
106 1.2 bouyer struct esiop_dsatbl *lun_tagtbl; /* the tag DSA table */
107 1.1 bouyer };
108 1.1 bouyer
109 1.1 bouyer /*
110 1.1 bouyer * per target struct; siop_common_cmd->target and siop_common_softc->targets[]
111 1.1 bouyer * will point to this
112 1.1 bouyer */
113 1.1 bouyer struct esiop_target {
114 1.1 bouyer struct siop_common_target target_c;
115 1.1 bouyer struct esiop_lun *esiop_lun[8]; /* per-lun state */
116 1.19 tsutsui uint32_t lun_table_offset; /* pointer to our DSA table */
117 1.1 bouyer };
118 1.1 bouyer
119 1.15 perry static __inline void esiop_table_sync(struct esiop_cmd *, int);
120 1.15 perry static __inline void
121 1.17 cegger esiop_table_sync(struct esiop_cmd *esiop_cmd, int ops)
122 1.1 bouyer {
123 1.1 bouyer struct siop_common_softc *sc = esiop_cmd->cmd_c.siop_sc;
124 1.1 bouyer bus_addr_t offset;
125 1.1 bouyer
126 1.1 bouyer offset = esiop_cmd->cmd_c.dsa -
127 1.1 bouyer esiop_cmd->esiop_cbdp->xferdma->dm_segs[0].ds_addr;
128 1.1 bouyer bus_dmamap_sync(sc->sc_dmat, esiop_cmd->esiop_cbdp->xferdma, offset,
129 1.1 bouyer sizeof(struct esiop_xfer), ops);
130 1.1 bouyer }
131 1.1 bouyer
132 1.1 bouyer
133 1.1 bouyer
134 1.1 bouyer /* Driver internal state */
135 1.1 bouyer struct esiop_softc {
136 1.1 bouyer struct siop_common_softc sc_c;
137 1.19 tsutsui uint32_t sc_semoffset; /* semaphore */
138 1.19 tsutsui uint32_t sc_shedoffset; /* base of scheduler ring */
139 1.1 bouyer int sc_currschedslot; /* current scheduler slot */
140 1.1 bouyer struct cbd_list cmds; /* list of command block descriptors */
141 1.1 bouyer struct cmd_list free_list; /* cmd descr free list */
142 1.2 bouyer struct tbl_list free_tagtbl; /* list of free tag DSA tables */
143 1.2 bouyer struct tblblk_list tag_tblblk; /* tag DSA table blocks */
144 1.19 tsutsui uint32_t sc_flags;
145 1.19 tsutsui uint32_t sc_free_offset; /* pointer to free RAM */
146 1.19 tsutsui uint32_t sc_target_table_offset;/* pointer to target DSA table */
147 1.6 bouyer int sc_currdoneslot; /* current done slot */
148 1.6 bouyer bus_dmamap_t sc_done_map; /* dma map for done ring (shared) */
149 1.18 tsutsui bus_addr_t sc_done_offset; /* offset of ring in sc_done_map */
150 1.19 tsutsui uint32_t *sc_done_slot; /* The done ring itself */
151 1.1 bouyer };
152 1.1 bouyer
153 1.1 bouyer /* defs for sc_flags */
154 1.8 wiz #define SCF_CHAN_NOSLOT 0x0001 /* channel out of scheduler slot */
155 1.7 bouyer #define SCF_CHAN_ADAPTREQ 0x0002 /* esiop_scsipi_request() is running */
156 1.1 bouyer
157 1.11 perry void esiop_attach(struct esiop_softc *);
158 1.11 perry int esiop_intr(void *);
159 1.11 perry void esiop_add_dev(struct esiop_softc *, int, int);
160 1.11 perry void esiop_del_dev(struct esiop_softc *, int, int);
161