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