xref: /openbsd/sys/dev/ic/siopvar.h (revision 4bdff4be)
1 /*	$OpenBSD: siopvar.h,v 1.17 2011/09/23 10:40:06 miod Exp $ */
2 /*	$NetBSD: siopvar.h,v 1.22 2005/11/18 23:10:32 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  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 /* structure and definitions for the siop driver */
30 
31 /* Number of tag */
32 #define SIOP_NTAG 16
33 
34 /*
35  * wrap up the bus_dma api.
36  */
37 struct siop_dmamem {
38 	bus_dmamap_t		sdm_map;
39 	bus_dma_segment_t	sdm_seg;
40 	size_t			sdm_size;
41 	caddr_t			sdm_kva;
42 };
43 #define SIOP_DMA_MAP(_sdm)	((_sdm)->sdm_map)
44 #define SIOP_DMA_DVA(_sdm)	((_sdm)->sdm_map->dm_segs[0].ds_addr)
45 #define SIOP_DMA_KVA(_sdm)	((void *)(_sdm)->sdm_kva)
46 
47 /*
48  * xfer description of the script: tables and reselect script
49  * In struct siop_common_cmd siop_xfer will point to this.
50  */
51 struct siop_xfer {
52 	struct siop_common_xfer siop_tables;
53 	/* u_int32_t resel[sizeof(load_dsa) / sizeof(load_dsa[0])]; */
54 	/* Add some entries to make size 384 bytes (244+140) */
55 	u_int32_t resel[35];
56 } __packed;
57 
58 /*
59  * This describes a command handled by the SCSI controller
60  * These are chained in either a free list or an active list
61  * We have one queue per target
62  */
63 
64 struct siop_cmd {
65 	TAILQ_ENTRY (siop_cmd) next;
66 	struct siop_common_cmd cmd_c;
67 	struct siop_cbd *siop_cbdp; /* pointer to our siop_cbd */
68 	int reselslot;
69 	u_int32_t saved_offset; /* offset in table after disc without sdp */
70 };
71 #define cmd_tables cmd_c.siop_tables
72 
73 /* command block descriptors: an array of siop_cmd, siop_xfer, and sense */
74 struct siop_cbd {
75 	TAILQ_ENTRY (siop_cbd) next;
76 	struct siop_cmd *cmds;
77 	struct siop_dmamem *xfers;
78 	struct siop_dmamem *sense;
79 };
80 
81 /* per-tag struct */
82 struct siop_tag {
83 	struct siop_cmd *active; /* active command */
84 	u_int reseloff;
85 };
86 
87 /* per lun struct */
88 struct siop_lun {
89 	struct siop_tag siop_tag[SIOP_NTAG]; /* tag array */
90 	int lun_flags;
91 #define SIOP_LUNF_FULL 0x01 /* queue full message */
92 	u_int reseloff;
93 };
94 
95 /*
96  * per target struct; siop_common_cmd->target and siop_common_softc->targets[]
97  * will point to this
98  */
99 struct siop_target {
100 	struct siop_common_target target_c;
101 	struct siop_lun *siop_lun[8]; /* per-lun state */
102 	u_int reseloff;
103 	struct siop_lunsw *lunsw;
104 };
105 
106 struct siop_lunsw {
107 	TAILQ_ENTRY (siop_lunsw) next;
108 	u_int32_t lunsw_off; /* offset of this lun sw, from sc_scriptaddr*/
109 	u_int32_t lunsw_size; /* size of this lun sw */
110 };
111 
112 
113 TAILQ_HEAD(cmd_list, siop_cmd);
114 TAILQ_HEAD(cbd_list, siop_cbd);
115 TAILQ_HEAD(lunsw_list, siop_lunsw);
116 
117 
118 /* Driver internal state */
119 struct siop_softc {
120 	struct siop_common_softc sc_c;
121 	int sc_currschedslot;		/* current scheduler slot */
122 	struct cbd_list cmds;		/* list of command block descriptors */
123 	struct cmd_list free_list;	/* cmd descr free list */
124 	struct cmd_list urgent_list;	/* high priority cmd descr list */
125 	struct cmd_list ready_list;	/* cmd descr ready list */
126 	struct scsi_iopool iopool;	/* cmd pool */
127 	struct lunsw_list lunsw_list;	/* lunsw free list */
128 	u_int32_t script_free_lo;	/* free ram offset from sc_scriptaddr */
129 	u_int32_t script_free_hi;	/* free ram offset from sc_scriptaddr */
130 	int sc_ntargets;		/* number of known targets */
131 	u_int32_t sc_flags;
132 };
133 
134 /* defs for sc_flags */
135 #define SCF_CHAN_NOSLOT	0x0001		/* channel out of scheduler slot */
136 
137 void    siop_attach(struct siop_softc *);
138 int	siop_intr(void *);
139 void	siop_add_dev(struct siop_softc *, int, int);
140 void	siop_del_dev(struct siop_softc *, int, int);
141