xref: /titanic_51/usr/src/uts/sun/sys/scsi/adapters/sfvar.h (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_SCSI_ADAPTERS_SFVAR_H
28 #define	_SYS_SCSI_ADAPTERS_SFVAR_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * FC-AL FCP driver definitions
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * this is to generate unique minor numbers for each minor
42  * node type being created. because of the limitations by SCSA,
43  * we have to use minor number values from 32 to 63 for the HBA
44  * drivers use
45  */
46 #define	SF_BASE_MINOR		32
47 #define	SF_DEVCTL_MINOR		(SF_BASE_MINOR + 1)
48 #define	SF_FC_MINOR		(SF_BASE_MINOR + 2)
49 #define	SF_INST_SHIFT4MINOR	6
50 #define	SF_INST2DEVCTL_MINOR(x)	(((x) << SF_INST_SHIFT4MINOR) | SF_DEVCTL_MINOR)
51 #define	SF_INST2FC_MINOR(x)	(((x) << SF_INST_SHIFT4MINOR) | SF_FC_MINOR)
52 #define	SF_MINOR2INST(x)	((x) >> SF_INST_SHIFT4MINOR)
53 
54 #define	SF_INIT_ITEMS		5
55 #define	SF_MAX_TARGETS		126
56 #define	SF_MAX_LILP_ENTRIES	126
57 
58 #define	SF_NUM_HASH_QUEUES	32
59 #define	SF_HASH(x, y)	((x[0]+x[1]+x[2]+x[3]+x[4]+x[5]+x[6]+x[7]) &\
60 (SF_NUM_HASH_QUEUES-1))
61 
62 
63 /*
64  * sf driver needs to be sanitized for exporting some of its
65  * macros/variables to userland programs.
66  */
67 #ifdef	_KERNEL
68 
69 /*
70  * sf instance structure
71  */
72 
73 struct sf {
74 	struct scsi_hba_tran *sf_tran;
75 	dev_info_t	*sf_dip;
76 	struct sf	*sf_next;
77 	struct sf	*sf_sibling;
78 	kmutex_t	sf_mutex;
79 	kmutex_t	sf_cr_mutex;
80 	uint_t		sf_state;
81 	int64_t		sf_reset_time;	/* reset/lip init time for bus_config */
82 	struct sf_target *sf_targets[SF_MAX_TARGETS];
83 	struct sf_target *sf_wwn_lists[SF_NUM_HASH_QUEUES];
84 	void		*sf_socp;	/* pointer to socal state */
85 	struct fcal_transport *sf_sochandle;
86 	kmutex_t	sf_cmd_mutex;
87 	int		sf_throttle;
88 	int		sf_ncmds;
89 	int		sf_ncmds_exp_avg;
90 	int		sf_device_count;
91 	uint_t		sf_use_lock;
92 	uint_t		sf_timer;
93 	uint_t		sf_online_timer;
94 	int		sf_take_core;
95 	struct kmem_cache *sf_pkt_cache;
96 	struct sf_pkt *sf_pkt_head; /* packet queue */
97 	struct sf_pkt *sf_pkt_tail;
98 	struct sf_els_hdr *sf_els_list;
99 	struct sf_reset_list	*sf_reset_list;
100 	kcondvar_t	sf_cr_cv;
101 	uint_t		sf_cr_pool_cnt;
102 	struct sf_cr_pool *sf_cr_pool; /* list of command/response pools */
103 	uchar_t		sf_al_pa;
104 	uchar_t		sf_busy;
105 	uchar_t		sf_flag;
106 	uchar_t		sf_cr_flag; /* synchronize creation of new cr pools */
107 	uint_t		sf_lip_cnt;
108 	struct scsi_reset_notify_entry  *sf_reset_notify_listf;
109 	struct fcal_lilp_map	*sf_lilp_map;
110 	ddi_dma_handle_t	sf_lilp_dmahandle;
111 	ddi_acc_handle_t	sf_lilp_acchandle;
112 	ddi_dma_cookie_t	sf_lilp_dmacookie;
113 	kstat_t		*sf_ksp;
114 	kmutex_t	sf_hp_daemon_mutex;
115 	kcondvar_t	sf_hp_daemon_cv;
116 	struct sf_hp_elem *sf_hp_elem_head;
117 	struct sf_hp_elem *sf_hp_elem_tail;
118 	/*
119 	 * Event handling
120 	 */
121 	ndi_event_definition_t	*sf_event_defs;
122 	ndi_event_hdl_t		sf_event_hdl;
123 	ndi_event_set_t		sf_events;
124 	struct	sf_stats	sf_stats;
125 	uchar_t		sf_hp_exit;	/* hotplugging thread exit flag */
126 	uchar_t		sf_check_n_close;
127 		/* check if unopened sf is being closed */
128 	kt_did_t	sf_hp_tid;	/* hotplug thread id */
129 };
130 
131 #define	SF_STATE_INIT		0x01
132 #define	SF_STATE_OFFLINE	0x02
133 #define	SF_STATE_ONLINE		0x04
134 #define	SF_STATE_ONLINING	0x08
135 #define	SF_STATE_SUSPENDED	0x10		/* driver has been suspended */
136 
137 #define	SF_EVENT_TAG_INSERT	0
138 #define	SF_EVENT_TAG_REMOVE	1
139 
140 /*
141  * pool of sf command response blocks
142  */
143 
144 struct  sf_cr_pool {
145 	struct	sf_cr_pool	*next;
146 	struct	sf_cr_free_elem *free;
147 	struct	sf		*sf;
148 	caddr_t			cmd_base;	/* start addr of this chunk */
149 	ddi_dma_handle_t	cmd_dma_handle; /* dma mapping for this chunk */
150 	ddi_acc_handle_t	cmd_acc_handle;
151 	caddr_t			rsp_base;
152 	ddi_dma_handle_t	rsp_dma_handle;
153 	ddi_acc_handle_t	rsp_acc_handle;
154 	uint_t			nfree;
155 	uint_t			ntot;
156 };
157 
158 #define	SF_CR_POOL_MAX		32	/* allows 4096 outstanding packets */
159 
160 #define	SF_ELEMS_IN_POOL	128
161 #define	SF_LOG2_ELEMS_IN_POOL	7	/* LOG2 SF_ELEMS_IN_POOL */
162 #define	SF_FREE_CR_EPSILON	64	/* SF_ELEMS_IN_POOL /2 */
163 
164 /*
165  * sf command/response free structure which is overlaid on fcp_cmd
166  */
167 
168 struct  sf_cr_free_elem {
169 	struct		sf_cr_free_elem *next;
170 	caddr_t		rsp;		/* ptr to corresponding rsp */
171 	uint_t		cmd_dmac;	/* dmac_address for cmd */
172 	uint_t		rsp_dmac;	/* dmac_address for rsp */
173 };
174 
175 /*
176  * list of targets for reset delay handling
177  */
178 
179 struct sf_reset_list {
180 	struct sf_reset_list	*next;
181 	struct sf_target	*target;
182 	clock_t			timeout;
183 	uint_t			lip_cnt;
184 };
185 
186 /*
187  * structure used to store hotplug event callback info
188  */
189 
190 struct sf_hp_event {
191 	int (*callback)();
192 	void *arg;
193 };
194 
195 
196 /*
197  * sf per target structure
198  */
199 
200 struct sf_target	{
201 	struct sf_pkt *sft_pkt_head; /* queue of active commands */
202 	struct sf_pkt *sft_pkt_tail;
203 	kmutex_t	sft_mutex;
204 	kcondvar_t	sft_cv;
205 	kmutex_t	sft_pkt_mutex;
206 	dev_info_t	*sft_dip;
207 	uchar_t		sft_node_wwn[FC_WWN_SIZE];
208 	uchar_t		sft_port_wwn[FC_WWN_SIZE];
209 	union {
210 		/* It's easier to shove around an int64 than a byte array */
211 		uchar_t	b[FCP_LUN_SIZE];
212 		int64_t	l;
213 	}		sft_lun;
214 	/* XXXX The RAID LUN field is used to implement FCP Annex C */
215 #ifdef RAID_LUNS
216 	uint_t		sft_raid_lun;
217 #define	SCSA_LUN(t)	(int64_t)(t)->sft_raid_lun
218 #else
219 #define	SCSA_LUN(t)	(t)->sft_lun.l
220 #endif
221 	uchar_t		sft_hard_address;
222 	uchar_t		sft_al_pa;
223 	uchar_t		sft_device_type;
224 	uchar_t		sft_scan_count;
225 	uint_t		sft_alive;
226 	uint_t		sft_state;
227 	uint_t		sft_lip_cnt;
228 	struct scsi_hba_tran *sft_tran;
229 	struct sf_target	*sft_next;
230 	struct sf_target	*sft_next_lun;
231 	struct sf_hp_event sft_insert_ev;
232 	struct sf_hp_event sft_remove_ev;
233 	struct scsi_inquiry	sft_inq;
234 };
235 
236 #define	SF_TARGET_INIT_DONE	0x1
237 #define	SF_TARGET_BUSY		0x2
238 #define	SF_TARGET_OFFLINE	0x4
239 #define	SF_TARGET_MARK		0x8
240 
241 /*
242  * sf packet
243  */
244 
245 #define	PKT2CMD(pkt)		((struct sf_pkt *)pkt->pkt_ha_private)
246 #define	CMD2PKT(cmd)		((cmd)->cmd_pkt)
247 #ifdef	_LP64
248 #define	PKT_PRIV_SIZE		2
249 #define	PKT_PRIV_LEN		16
250 #else /* _ILP32 */
251 #define	PKT_PRIV_SIZE		1
252 #define	PKT_PRIV_LEN		8
253 #endif
254 
255 
256 struct sf_pkt {
257 	struct sf_pkt		*cmd_forw;
258 	struct sf_pkt		*cmd_back;
259 	struct sf_pkt		*cmd_next;
260 	struct scsi_pkt		*cmd_pkt;
261 	fcal_packet_t		*cmd_fp_pkt;
262 	uint_t		cmd_state;
263 	uint_t		cmd_timeout;
264 	char		cmd_scsi_scb[sizeof (struct scsi_arq_status)];
265 	uint32_t	cmd_dmacount;
266 	ddi_dma_handle_t	cmd_dmahandle;  /* dma handle */
267 	ddi_dma_cookie_t	cmd_dmacookie;  /* current dma cookie */
268 	uint_t		cmd_flags;	/* private flags */
269 						/* needs ZEROING */
270 	uint_t		cmd_cdblen;	/* length of cdb */
271 					/* needs to be INITialized */
272 	uint_t		cmd_scblen;	/* length of scb */
273 					/* needs to be INITialized */
274 	uint_t		cmd_privlen;	/* length of tgt private */
275 					/* needs to be INITialized */
276 	struct	sf_cr_pool	*cmd_cr_pool; /* pool to which cmd/rsp belong */
277 	struct fcp_cmd		*cmd_block;
278 	struct fcp_rsp		*cmd_rsp_block;
279 	kmutex_t	cmd_abort_mutex;	/* packet abort mutex */
280 	uint_t		cmd_dmac;
281 	uint_t		cmd_rsp_dmac;
282 	uint64_t		cmd_pkt_private[PKT_PRIV_LEN];
283 			/* default target private area */
284 };
285 
286 #define	SF_STATE_IDLE		0x1
287 #define	SF_STATE_ISSUED		0x2
288 #define	SF_STATE_ABORTING	0x4
289 
290 /*
291  * Define size of extended scsi cmd pkt (ie. includes ARQ)
292  */
293 #define	EXTCMDS_STATUS_SIZE  (sizeof (struct scsi_arq_status))
294 
295 /*
296  * These are the defined flags for this structure.
297  */
298 #define	CFLAG_DMAVALID		0x0010	/* dma mapping valid */
299 #define	CFLAG_DMASEND		0x0020	/* data is going 'out' */
300 #define	CFLAG_CMDIOPB		0x0040	/* this is an 'iopb' packet */
301 #define	CFLAG_CDBEXTERN		0x0100	/* cdb kmem_alloc'd */
302 #define	CFLAG_SCBEXTERN		0x0200	/* scb kmem_alloc'd */
303 #define	CFLAG_FREE		0x0400	/* packet is on free list */
304 #define	CFLAG_PRIVEXTERN	0x1000	/* target private was */
305 					/* kmem_alloc'd */
306 #define	CFLAG_IN_QUEUE		0x2000	/* command in sf queue */
307 
308 struct sf_els_hdr {
309 	struct sf	*sf;
310 	caddr_t		cmd;
311 	caddr_t		rsp;
312 	uchar_t		els_code;
313 	uchar_t		delayed_retry;
314 	ddi_dma_handle_t	cmd_dma_handle;
315 	ddi_dma_handle_t	rsp_dma_handle;
316 	ddi_acc_handle_t	cmd_acc_handle;
317 	ddi_acc_handle_t	rsp_acc_handle;
318 	uint_t		dest_nport_id;
319 	struct	sf_els_hdr	*next;
320 	struct	sf_els_hdr	*prev;
321 	uint_t		size;
322 	uint_t		timeout;
323 	uint_t		retries;
324 	struct fcal_packet	*fpkt;
325 	uint_t		lip_cnt;
326 	uchar_t		port_wwn[FC_WWN_SIZE];
327 	uchar_t		node_wwn[FC_WWN_SIZE];
328 	struct sf_target *target;
329 	ddi_dma_handle_t	data_dma_handle;
330 	ddi_acc_handle_t	data_acc_handle;
331 	caddr_t			data_buf;
332 };
333 
334 union sf_els_cmd {
335 	struct la_els_logi logi;
336 	struct la_els_logo logo;
337 	struct la_els_prli prli;
338 	struct la_els_adisc adisc;
339 	struct fcp_cmd cmd;
340 };
341 
342 union sf_els_rsp {
343 	struct la_els_logi logi;
344 	struct la_els_logo logo;
345 	struct la_els_prli prli;
346 	struct la_els_adisc adisc;
347 	uchar_t rsp[FCP_MAX_RSP_IU_SIZE];
348 };
349 
350 struct sf_hp_elem {
351 	struct sf_hp_elem *next;
352 	dev_info_t	*dip;
353 	int		what;
354 	struct sf_target *target;
355 	struct sf	*sf;
356 };
357 #define	SF_ONLINE	0
358 #define	SF_OFFLINE	1
359 
360 
361 #define	ADDR2SF(ap)	(struct sf *)((ap)->a_hba_tran->tran_hba_private)
362 #define	ADDR2TARGET(ap)	(struct sf_target *)((ap)->a_hba_tran->\
363     tran_tgt_private)
364 #define	SF_ONLINE_TIMEOUT	180
365 #define	SF_OFFLINE_TIMEOUT	45
366 #define	SF_RESET_TIMEOUT	10
367 #define	SF_ELS_TIMEOUT		5
368 #define	SF_INVALID_TIMEOUT	0x7fffffff
369 #define	SF_FCP_TIMEOUT		30
370 #define	SF_BSY_TIMEOUT		10
371 #define	SF_ABORT_TIMEOUT	10000000	/* in usec */
372 #define	SF_POLL_TIMEOUT	60
373 #define	SF_TARGET_RESET_DELAY	250000		/* in usec */
374 
375 #define	SF_DECR_DELTA		5
376 #define	SF_INCR_DELTA		5
377 
378 #define	SF_LO_CMD_DELTA	512
379 #define	SF_HI_CMD_DELTA	256
380 
381 #define	SF_ELS_RETRIES		4
382 #define	SF_BSY_RETRIES		7
383 
384 #define	SF_INIT_WAIT_TIMEOUT	60000000
385 #define		SF_CORE_CMD_TIMEOUT		0x01
386 #define		SF_CORE_BAD_ABORT		0x02
387 #define		SF_CORE_ABORT_TIMEOUT		0x04
388 #define		SF_CORE_ELS_TIMEOUT		0x08
389 #define		SF_CORE_ELS_FAILED		0x10
390 #define		SF_CORE_LILP_FAILED		0x20
391 #define		SF_CORE_OFFLINE_TIMEOUT		0x40
392 #define		SF_CORE_LIP_FAILED		0x80
393 #define		SF_CORE_OFFLINE_TARGET		0x100
394 #define		SF_CORE_INCOMPLETE_DMA		0x200
395 #define		SF_CORE_REPORTLUN_TIMEOUT	0x400
396 #define		SF_CORE_INQUIRY_TIMEOUT		0x800
397 #define		SF_CORE_BAD_DMA			0x1000
398 
399 #define		SF_BAD_DMA_MAGIC	0xdeafbead
400 
401 #define	TRUE		1
402 #define	FALSE		0
403 #define	UNDEFINED	-1
404 
405 
406 /*
407  * The initiator must allocate a minimum of 16 bytes for the response
408  * to the REPORT_LUNS command.  Since there is 8 bytes of overhead and
409  * each LUN is 4 bytes, this means that the minimum size is 2 LUNs.  We
410  * will define the structure that way to prevent any spurious check
411  * conditions.
412  *
413  * There is no maximum size for the response.
414  *
415  * By default we support 256 LUNs for the moment, which means 256*8+16
416  * or 2064 bytes total size.
417  */
418 
419 #define	REPORT_LUNS_MIN_LUNS	2
420 #define	REPORT_LUNS_DEFAULT	256
421 #define	REPORT_LUNS_SIZE	((REPORT_LUNS_DEFAULT)*sizeof (uint32_t) \
422 				+2*sizeof (uint32_t))
423 
424 /*
425  * SCSI Report_Luns Data
426  *
427  * Format of data returned as a result of an REPORT_LUNS command.
428  *
429  */
430 
431 struct scsi_report_luns {
432 	/* Number of bytes of data the target has available to send. */
433 	uint32_t	lun_list_len;
434 	uint32_t	reserved;
435 	uint64_t	lun[REPORT_LUNS_MIN_LUNS];
436 };
437 
438 #endif	/* _KERNEL */
439 
440 #ifdef	__cplusplus
441 }
442 #endif
443 
444 #endif	/* _SYS_SCSI_ADAPTERS_SFVAR_H */
445