xref: /illumos-gate/usr/src/uts/intel/io/amr/amrvar.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
1 /*
2  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 /*
6  * Copyright (c) 1999,2000 Michael Smith
7  * Copyright (c) 2000 BSDi
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * Copyright (c) 2002 Eric Moore
32  * Copyright (c) 2002 LSI Logic Corporation
33  * All rights reserved.
34  *
35  * Redistribution and use in source and binary forms, with or without
36  * modification, are permitted provided that the following conditions
37  * are met:
38  * 1. Redistributions of source code must retain the above copyright
39  *    notice, this list of conditions and the following disclaimer.
40  * 2. Redistributions in binary form must reproduce the above copyright
41  *    notice, this list of conditions and the following disclaimer in the
42  *    documentation and/or other materials provided with the distribution.
43  * 3. The party using or redistributing the source code and binary forms
44  *    agrees to the disclaimer below and the terms and conditions set forth
45  *    herein.
46  *
47  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
48  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
51  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57  * SUCH DAMAGE.
58  */
59 
60 #ifndef _AMRVAR_H
61 #define	_AMRVAR_H
62 
63 #ifdef	__cplusplus
64 extern "C" {
65 #endif
66 
67 #define	AMR_DEBUG
68 #ifdef AMR_DEBUG
69 #define	AMRDB_PRINT(fmt) if (amr_debug_var) cmn_err fmt
70 #else
71 #define	AMRDB_PRINT(fmt)
72 #endif
73 
74 #define	AMRDB_PANIC(fmt) cmn_err fmt
75 
76 #define	AMR_PERIODIC_TIMEOUT		60
77 #define	AMR_RETRYCOUNT			10000
78 
79 /* for scsi commands */
80 #ifndef	SD_MODE_SENSE_PAGE3_CODE
81 #define	SD_MODE_SENSE_PAGE3_CODE	0x03
82 #endif
83 
84 #ifndef	SD_MODE_SENSE_PAGE4_CODE
85 #define	SD_MODE_SENSE_PAGE4_CODE	0x04
86 #endif
87 
88 #ifndef	SCMD_SYNCHRONIZE_CACHE
89 #define	SCMD_SYNCHRONIZE_CACHE		0x35
90 #endif
91 
92 #define	AMR_DEFAULT_SECTORS		512
93 #define	AMR_DEFAULT_HEADS		255
94 #define	AMR_DEFAULT_CYLINDERS		63
95 #define	AMR_DEFAULT_ROTATIONS		10000
96 
97 #define	AMR_INQ_ADDITIONAL_LEN		31
98 #define	AMR_INQ_ANSI_VER		2
99 #define	AMR_INQ_RESP_DATA_FORMAT	2
100 
101 #define	AMR_PRODUCT_INFO_SIZE \
102 			sizeof (((struct scsi_inquiry *)(NULL))->inq_pid)
103 #define	AMR_FIRMWARE_VER_SIZE \
104 			sizeof (((struct scsi_inquiry *)(NULL))->inq_revision)
105 
106 #define	AMR_LAST_COOKIE_TAG		0xffffffff
107 
108 /*
109  * Per-logical-drive datastructure
110  */
111 struct amr_logdrive
112 {
113 	uint32_t	al_size;
114 	uint8_t		al_state;
115 	uint8_t		al_properties;
116 };
117 
118 /*
119  * Per-command control structure.
120  */
121 struct amr_command
122 {
123 
124 	struct amr_command	*ac_prev;
125 	struct amr_command	*ac_next;
126 
127 	struct amr_softs	*ac_softs;
128 	uint8_t			ac_slot;
129 
130 	uint8_t			ac_status;
131 	uint32_t		ac_flags;
132 
133 	struct buf		*ac_buf;
134 	uint32_t		cmdlen;
135 	struct scsi_pkt		*pkt;
136 
137 	void			*ac_data;
138 	size_t			ac_length;
139 	uint32_t		ac_dataphys;
140 
141 	ddi_dma_handle_t	sg_dma_handle;
142 	ddi_dma_cookie_t	sg_dma_cookie;
143 	uint_t			sg_dma_cookien;
144 
145 	ddi_dma_handle_t	buffer_dma_handle;
146 	ddi_dma_cookie_t	buffer_dma_cookie;
147 	ddi_acc_handle_t	buffer_acc_handle;
148 	uint_t			num_of_cookie;
149 	uint_t			num_of_win;
150 	uint_t			current_cookie;
151 	uint_t			current_win;
152 	uint32_t		data_transfered;
153 	uint32_t		transfer_size;
154 
155 	struct amr_mailbox	mailbox;
156 	struct amr_sgentry	sgtable[AMR_NSEG];
157 
158 	time_t			ac_timestamp;
159 };
160 
161 /*
162  * ac_flags values in amr_command
163  */
164 #define	AMR_CMD_DATAIN		(1<<0)
165 #define	AMR_CMD_DATAOUT		(1<<1)
166 #define	AMR_CMD_CCB_DATAIN	(1<<2)
167 #define	AMR_CMD_CCB_DATAOUT	(1<<3)
168 #define	AMR_CMD_PRIORITY	(1<<4)
169 #define	AMR_CMD_MAPPED		(1<<5)
170 #define	AMR_CMD_SLEEP		(1<<6)
171 #define	AMR_CMD_BUSY		(1<<7)
172 #define	AMR_CMD_PKT_CONSISTENT	(1<<8)
173 #define	AMR_CMD_PKT_DMA_PARTIAL	(1<<9)
174 #define	AMR_CMD_GOT_SLOT	(1<<10)
175 
176 struct sg_item {
177 	struct amr_sgentry	*sg_table;
178 	ddi_dma_handle_t	sg_handle;
179 	ddi_acc_handle_t	sg_acc_handle;
180 	uint32_t		sg_phyaddr;
181 };
182 
183 struct product_info {
184 	uint8_t			pi_firmware_ver[AMR_FIRMWARE_VER_SIZE+1];
185 	uint8_t			pi_product_name[AMR_PRODUCT_INFO_SIZE+1];
186 };
187 
188 /*
189  * Per-controller-instance data
190  */
191 struct amr_softs
192 {
193 	/* bus attachments */
194 	dev_info_t		*dev_info_p;
195 	ddi_acc_handle_t	pciconfig_handle;
196 	ddi_acc_handle_t	regsmap_handle;
197 	ddi_iblock_cookie_t	iblock_cookiep;
198 
199 	ddi_dma_handle_t	mbox_dma_handle;
200 	ddi_acc_handle_t	mbox_acc_handle;
201 	ddi_dma_cookie_t	mbox_dma_cookie;
202 	uint_t			mbox_dma_cookien;
203 
204 	/* controller limits and features */
205 	uint8_t			maxio; /* maximum number of I/O transactions */
206 	uint8_t			maxdrives; /* max number of logical drives */
207 	uint8_t			maxchan; /* count of SCSI channels */
208 
209 	uint8_t			amr_nlogdrives;
210 
211 	/* connected logical drives */
212 	struct amr_logdrive	logic_drive[AMR_MAXLD];
213 
214 	/* product info of the card */
215 	struct product_info	amr_product_info;
216 
217 	/* controller state */
218 	uint32_t		state;
219 
220 	struct amr_mailbox	*mailbox;
221 	void			*mbox;
222 	uint32_t		mbox_phyaddr;
223 
224 	/* per-controller poll command */
225 	kmutex_t		cmd_mutex;
226 	kcondvar_t		cmd_cv;
227 
228 	uint32_t		amr_busyslots;
229 	struct amr_command	*busycmd[AMR_MAXCMD];
230 	struct sg_item		sg_items[AMR_MAXCMD];
231 	uint32_t		sg_max_count;
232 	struct amr_command	*waiting_q_head;
233 	struct amr_command	*waiting_q_tail;
234 	kmutex_t		queue_mutex;
235 
236 	/* periodic status check */
237 	timeout_id_t		timeout_t;
238 	kmutex_t		periodic_mutex;
239 
240 	scsi_hba_tran_t		*hba_tran;
241 
242 	ddi_taskq_t		*amr_taskq;
243 	uint32_t		amr_interrupts_counter;
244 };
245 
246 /*
247  * state values in amr_softs
248  */
249 #define	AMR_STATE_OPEN			(1<<0)
250 #define	AMR_STATE_SUSPEND		(1<<1)
251 #define	AMR_STATE_CARD_DETECTED		(1<<2)
252 #define	AMR_STATE_BUS_MASTER_ENABLED	(1<<3)
253 #define	AMR_STATE_SOFT_STATE_SETUP	(1<<4)
254 #define	AMR_STATE_PCI_CONFIG_SETUP	(1<<5)
255 #define	AMR_STATE_PCI_MEM_MAPPED	(1<<6)
256 #define	AMR_STATE_KMUTEX_INITED		(1<<7)
257 #define	AMR_STATE_MAILBOX_SETUP		(1<<8)
258 #define	AMR_STATE_SG_TABLES_SETUP	(1<<9)
259 #define	AMR_STATE_INTR_SETUP		(1<<10)
260 #define	AMR_STATE_TASKQ_SETUP		(1<<11)
261 #define	AMR_STATE_TRAN_SETUP		(1<<12)
262 #define	AMR_STATE_TIMEOUT_ENABLED	(1<<13)
263 
264 #ifdef	__cplusplus
265 }
266 #endif
267 
268 #endif /* _AMRVAR_H */
269