xref: /netbsd-src/sys/dev/ic/esiopvar.h (revision 8ac07aec990b9d2e483062509d0a9fa5b4f57cf2)
1 /*	$NetBSD: esiopvar.h,v 1.16 2007/12/25 18:33:38 perry Exp $	*/
2 
3 /*
4  * Copyright (c) 2002 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 /* structure and definitions for the siop driver */
34 
35 /* Number of tag */
36 #define ESIOP_NTAG 256
37 
38 /*
39  * description of a command scheduler slot. The script uses a ring of
40  * A_ncmd_slots of this.
41  */
42 struct esiop_slot {
43 	u_int32_t dsa; /* DSA of the xfer. The first 2 bits holds flags */
44 } __packed;
45 
46 #define CMD_SLOTSIZE (sizeof(struct esiop_slot) / sizeof(u_int32_t))
47 
48 /*
49  * xfer description of the script: tables and reselect script
50  * In struct siop_common_cmd siop_xfer will point to this.
51  * If you change this don't forget to update o_cmd_* and cmd_slot_size in script
52  */
53 struct esiop_xfer {
54 	struct siop_common_xfer siop_tables;
55 	u_int32_t tlq; /* target/lun/tag loaded in scratchC by script */
56 	u_int32_t saved_offset;/* contains scratchA if script saved an offset */
57 } __packed;
58 
59 #define ESIOP_XFER(cmd, m) (((struct esiop_xfer *)((cmd)->cmd_tables))->m)
60 
61 /*
62  * This describes a command handled by the SCSI controller
63  * These are chained in either a free list or a active list
64  * We have one queue per target
65  */
66 
67 struct esiop_cmd {
68 	TAILQ_ENTRY (esiop_cmd) next;
69 	struct siop_common_cmd cmd_c;
70 	struct esiop_cbd *esiop_cbdp; /* pointer to our siop_cbd */
71 };
72 #define cmd_tables cmd_c.siop_tables
73 
74 /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
75 struct esiop_cbd {
76 	TAILQ_ENTRY (esiop_cbd) next;
77 	struct esiop_cmd *cmds;
78 	struct esiop_xfer *xfers;
79 	bus_dmamap_t xferdma; /* DMA map for this block of xfers */
80 };
81 
82 TAILQ_HEAD(cmd_list, esiop_cmd);
83 TAILQ_HEAD(cbd_list, esiop_cbd);
84 
85 /* DSA table descriptor for tags. Free tables are in a list */
86 struct esiop_dsatbl {
87 	TAILQ_ENTRY (esiop_dsatbl) next;
88 	u_int32_t *tbl; /* the table itself */
89 	u_int32_t tbl_dsa; /* DSA of base of this table */
90 	bus_addr_t tbl_offset; /* offset of this table in the map */
91 	struct esiop_dsatblblk *tblblk; /* pointer back to our block */
92 };
93 
94 /* DSA table block descriptor. */
95 struct esiop_dsatblblk {
96 	TAILQ_ENTRY (esiop_dsatblblk) next;
97 	bus_dmamap_t blkmap; /* DMA map of this block */
98 };
99 
100 TAILQ_HEAD(tbl_list, esiop_dsatbl);
101 TAILQ_HEAD(tblblk_list, esiop_dsatblblk);
102 
103 /* Number of table per block */
104 #define ESIOP_NTPB ((PAGE_SIZE) / (sizeof(u_int32_t) * ESIOP_NTAG))
105 
106 /* per lun struct */
107 struct esiop_lun {
108 	struct esiop_cmd *active; /* active non-tagged command */
109 	struct esiop_cmd *tactive[ESIOP_NTAG]; /* active tagged commands */
110 	int lun_flags; /* per-lun flags */
111 	struct esiop_dsatbl *lun_tagtbl; /* the tag DSA table */
112 };
113 
114 /*
115  * per target struct; siop_common_cmd->target and siop_common_softc->targets[]
116  * will point to this
117  */
118 struct esiop_target {
119 	struct siop_common_target target_c;
120 	struct esiop_lun *esiop_lun[8]; /* per-lun state */
121 	u_int32_t lun_table_offset; /* pointer to our DSA table */
122 };
123 
124 static __inline void esiop_table_sync(struct esiop_cmd *, int);
125 static __inline void
126 esiop_table_sync(esiop_cmd, ops)
127 	struct esiop_cmd *esiop_cmd;
128 	int ops;
129 {
130 	struct siop_common_softc *sc  = esiop_cmd->cmd_c.siop_sc;
131 	bus_addr_t offset;
132 
133 	offset = esiop_cmd->cmd_c.dsa -
134 	    esiop_cmd->esiop_cbdp->xferdma->dm_segs[0].ds_addr;
135 	bus_dmamap_sync(sc->sc_dmat, esiop_cmd->esiop_cbdp->xferdma, offset,
136 	    sizeof(struct esiop_xfer), ops);
137 }
138 
139 
140 
141 /* Driver internal state */
142 struct esiop_softc {
143 	struct siop_common_softc sc_c;
144 	u_int32_t sc_semoffset;		/* semaphore */
145 	u_int32_t sc_shedoffset;	/* base of scheduler ring */
146 	int sc_currschedslot;		/* current scheduler slot */
147 	struct cbd_list cmds;		/* list of command block descriptors */
148 	struct cmd_list free_list;	/* cmd descr free list */
149 	struct tbl_list free_tagtbl;	/* list of free tag DSA tables */
150 	struct tblblk_list tag_tblblk;	/* tag DSA table blocks */
151 	u_int32_t sc_flags;
152 	u_int32_t sc_free_offset;	/* pointer to free RAM */
153 	u_int32_t sc_target_table_offset;/* pointer to target DSA table */
154 	int sc_currdoneslot;		/* current done slot */
155 	bus_dmamap_t sc_done_map;	/* dma map for done ring (shared) */
156 	bus_addr_t sc_done_offset; 	/* offset of ring in sc_done_map */
157 	u_int32_t *sc_done_slot;	/* The done ring itself */
158 };
159 
160 /* defs for sc_flags */
161 #define SCF_CHAN_NOSLOT	0x0001		/* channel out of scheduler slot */
162 #define SCF_CHAN_ADAPTREQ 0x0002	/* esiop_scsipi_request() is running */
163 
164 void    esiop_attach(struct esiop_softc *);
165 int	esiop_intr(void *);
166 void	esiop_add_dev(struct esiop_softc *, int, int);
167 void	esiop_del_dev(struct esiop_softc *, int, int);
168