xref: /titanic_44/usr/src/lib/storage/libg_fc/common/hdrs/gfc.h (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  *	Generic Fibre Channel Library definitions
28  */
29 
30 /*
31  * I18N message number ranges
32  *  This file: 19500 - 19999
33  *  Shared common messages: 1 - 1999
34  */
35 
36 #ifndef	_GFC_H
37 #define	_GFC_H
38 
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Put your include files here
46  */
47 #include 	<sys/types.h>
48 #include 	<sys/fibre-channel/fcio.h>
49 #include	<sys/sunmdi.h>
50 #include	<sys/scsi/generic/inquiry.h>
51 /*
52  * sys/fc4/fcio.h includes sys/fc4/fcal_linkapp.h.  The following #define
53  * keeps from actually including the contents of sys/fc4/fcal_linkapp.h
54  * since that file contains the same structure definitions as sys/fc4/fcio.h.
55  */
56 #define		_SYS_FC4_FCAL_LINKAPP_H
57 #include	<sys/fc4/fcio.h>
58 
59 
60 /* Defines */
61 #define		WWN_S_LEN	17 	/* NULL terminated string */
62 #define		WWN_SIZE	8
63 #define		MAX_HBA_PORT	256
64 
65 /* Constants used by g_wwn_in_dev_list() */
66 #define		MATCH_NODE_WWN	0
67 #define		MATCH_PORT_WWN	1
68 
69 /*
70  * The masks defined below are for the Fibre channel transport and FCAs.
71  * Mask names starting with FC4 are for the non-fabric fibre channel driver
72  * stack and those starting with FC are for the fabric fibre channel driver
73  * stack.
74  *
75  * The transport values are represented in the low order 16 bits and FCA
76  * values represented in the high order 16 bits.
77  *
78  * The notation used is as shown below :
79  * (starting from the low order byte)
80  * Byte 1 - holds the non-fabric FC transport driver defines
81  * Byte 2 - holds the fabric FC transport driver defines
82  * Byte 3 - holds the non-fabric FC FCA defines
83  * Byte 4 - holds the fabric FC FCA defines
84  */
85 /* Recognized Transport categories */
86 #define	FC4_SF_XPORT	0x00000001
87 #define	FC4_IFP_XPORT	0x00000002
88 #define	FC_GEN_XPORT	0x00000100
89 
90 /* Transport masks */
91 #define	FC4_XPORT_MASK	0x000000FF
92 #define	FC_XPORT_MASK	0x0000FF00
93 #define	XPORT_MASK	(FC_XPORT_MASK | FC4_XPORT_MASK)
94 
95 /* Recognized Fibre Channel Adapters */
96 #define	FC4_SOCAL_FCA	0x00010000
97 #define	FC4_PCI_FCA	0x00020000
98 #define	FC_PCI_FCA	0x02000000
99 
100 /* FCA masks */
101 #define	FC4_FCA_MASK	0x00FF0000
102 #define	FC_FCA_MASK	0xFF000000
103 #define	FCA_MASK	(FC_FCA_MASK | FC4_FCA_MASK)
104 
105 /*
106  * Disk ports
107  */
108 #define	PORT_B			0x00
109 #define	PORT_A			0x01
110 #define	FC_PORT_A		0x00
111 #define	FC_PORT_B		0x01
112 #define	PORT_A_B		0x02
113 
114 /* Constants used by g_set_port_state() */
115 #define	PORT_OFFLINE	0
116 #define	PORT_ONLINE	1
117 
118 /* Constants used by g_loopback_mode() */
119 #define	NO_LPBACK		0x00
120 #define	EXT_LPBACK		0x01
121 #define	INT_LPBACK		0x02
122 
123 /* Constants for port state */
124 #define	PORT_CONNECTED		0x00
125 #define	PORT_NOTCONNECTED	0x01
126 
127 /* Extended pathinfo node states */
128 #define	MDI_PATHINFO_STATE_TRANSIENT			0x00010000
129 #define	MDI_PATHINFO_STATE_USER_DISABLE			0x00100000
130 #define	MDI_PATHINFO_STATE_DRV_DISABLE			0x00200000
131 #define	MDI_PATHINFO_STATE_DRV_DISABLE_TRANSIENT	0x00400000
132 #define	MDI_PATHINFO_STATE_MASK				0x0000FFFF
133 #define	MDI_PATHINFO_EXT_STATE_MASK			0xFFF00000
134 
135 /*
136  * Error inq dtype for g_get_dev_list partial failure.
137  * choose E0 since Solaris has #define DTYPE_MASK 0x1F.
138  */
139 #define	GFC_ERR_INQ_DTYPE	(0xFF & ~DTYPE_MASK)
140 
141 /* Exported Variables */
142 extern uchar_t g_switch_to_alpa[];
143 extern uchar_t g_sf_alpa_to_switch[];
144 
145 
146 /* Exported Structures */
147 
148 /*	Device Map	*/
149 typedef struct	al_rls {
150 	char			driver_path[MAXNAMELEN];
151 	uint_t			al_ha;
152 	struct rls_payload	payload;
153 	struct al_rls		*next;
154 } AL_rls;
155 
156 
157 /* Multi path list */
158 struct	dlist	{
159 	char	*dev_path;
160 	char	*logical_path;
161 	struct	dlist *multipath;
162 	struct	dlist *next;
163 	struct	dlist *prev;
164 };
165 
166 
167 /* Individual drive state */
168 typedef struct g_disk_state_struct {
169 	uint_t		num_blocks;		 /* Capacity */
170 	char		physical_path[MAXNAMELEN];	/* First one found */
171 	struct dlist	*multipath_list;
172 	char		node_wwn_s[WWN_S_LEN];	 /* NULL terminated str */
173 	int		persistent_reserv_flag;
174 	int		persistent_active, persistent_registered;
175 	int		d_state_flags[2];	 /* Disk state */
176 	int		port_a_valid;		 /* If disk state is valid */
177 	int		port_b_valid;		 /* If disk state is valid */
178 	char		port_a_wwn_s[WWN_S_LEN]; /* NULL terminated string */
179 	char		port_b_wwn_s[WWN_S_LEN]; /* NULL terminated string */
180 } G_disk_state;
181 
182 
183 typedef	struct hotplug_disk_list {
184 	struct dlist		*seslist;
185 	struct dlist		*dlhead;
186 	char			box_name[33];
187 	char			dev_name[MAXPATHLEN];
188 	char			node_wwn_s[17];
189 	int			tid;
190 	int			slot;
191 	int			f_flag; /* Front flag */
192 	int			dev_type;
193 	int			dev_location; /* device in A5000 or not */
194 	int			busy_flag;
195 	int			reserve_flag;
196 	struct hotplug_disk_list	*next;
197 	struct hotplug_disk_list	*prev;
198 } Hotplug_Devlist;
199 
200 typedef struct l_inquiry_inq_2 {
201 	uchar_t inq_2_reladdr	: 1,	/* relative addressing */
202 		inq_wbus32	: 1,	/* 32 bit wide data xfers */
203 		inq_wbus16	: 1,	/* 16 bit wide data xfers */
204 		inq_sync	: 1,	/* synchronous data xfers */
205 		inq_linked	: 1,	/* linked commands */
206 		inq_res1	: 1,	/* reserved */
207 		inq_cmdque	: 1,	/* command queueing */
208 		inq_sftre	: 1;	/* Soft Reset option */
209 } L_inq_2;
210 typedef struct l_inquiry_inq_3 {
211 	uchar_t inq_3_reladdr	: 1,	/* relative addressing */
212 		inq_SIP_2	: 3,	/* Interlocked Protocol */
213 		inq_3_linked	: 1,	/* linked commands */
214 		inq_trandis	: 1,	/* Transfer Disable */
215 		inq_3_cmdque	: 1,	/* command queueing */
216 		inq_SIP_3	: 1;	/* Interlocked Protocol */
217 } L_inq_3;
218 
219 typedef struct l_inquiry_struct {
220 	/*
221 	 * byte 0
222 	 *
223 	 * Bits 7-5 are the Peripheral Device Qualifier
224 	 * Bits 4-0 are the Peripheral Device Type
225 	 *
226 	 */
227 	uchar_t	inq_dtype;
228 	/* byte 1 */
229 	uchar_t	inq_rmb		: 1,	/* removable media */
230 		inq_qual	: 7;	/* device type qualifier */
231 
232 	/* byte 2 */
233 	uchar_t	inq_iso		: 2,	/* ISO version */
234 		inq_ecma	: 3,	/* ECMA version */
235 		inq_ansi	: 3;	/* ANSI version */
236 
237 	/* byte 3 */
238 #define	inq_aerc inq_aenc	/* SCSI-3 */
239 	uchar_t	inq_aenc	: 1,	/* async event notification cap. */
240 		inq_trmiop	: 1,	/* supports TERMINATE I/O PROC msg */
241 		inq_normaca	: 1,	/* Normal ACA Supported */
242 				: 1,	/* reserved */
243 		inq_rdf		: 4;	/* response data format */
244 
245 	/* bytes 4-7 */
246 	uchar_t	inq_len;		/* additional length */
247 	uchar_t			: 8;	/* reserved */
248 	uchar_t			: 2,	/* reserved */
249 		inq_port	: 1,	/* Only defined when dual_p set */
250 		inq_dual_p	: 1,	/* Dual Port */
251 		inq_mchngr	: 1,	/* Medium Changer */
252 		inq_SIP_1	: 3;	/* Interlocked Protocol */
253 
254 	union {
255 		L_inq_2 inq_2;
256 		L_inq_3 inq_3;
257 	} ui;
258 
259 
260 	/* bytes 8-35 */
261 
262 	uchar_t	inq_vid[8];		/* vendor ID */
263 
264 	uchar_t	inq_pid[16];		/* product ID */
265 
266 	uchar_t	inq_revision[4];	/* product revision level */
267 
268 	/*
269 	 * Bytes 36-55 are vendor-specific parameter bytes
270 	 */
271 
272 	/* SSA specific definitions */
273 	/* bytes 36 - 39 */
274 #define	inq_ven_specific_1 inq_firmware_rev
275 	uchar_t	inq_firmware_rev[4];	/* firmware revision level */
276 
277 	/* bytes 40 - 51 */
278 	uchar_t	inq_serial[12];		/* serial number, not used any more */
279 
280 	/* bytes 52-53 */
281 	uchar_t	inq_res2[2];
282 
283 	/* byte 54, 55 */
284 	uchar_t	inq_ssa_ports;		/* number of ports */
285 	uchar_t	inq_ssa_tgts;		/* number of targets */
286 
287 	/*
288 	 * Bytes 56-95 are reserved.
289 	 */
290 	uchar_t	inq_res3[40];
291 	/*
292 	 * 96 to 'n' are vendor-specific parameter bytes
293 	 */
294 	uchar_t	inq_box_name[32];
295 	uchar_t	inq_avu[256];
296 } L_inquiry;
297 
298 
299 typedef struct wwn_list_struct {
300 	char	*logical_path;
301 	char	*physical_path;
302 	char	node_wwn_s[WWN_S_LEN];	/* NULL terminated string */
303 	uchar_t	w_node_wwn[WWN_SIZE];
304 	char	port_wwn_s[WWN_S_LEN];	/* NULL terminated string */
305 	uchar_t	device_type;	/* disk or tape (Peripheral Device Type) */
306 	struct	wwn_list_struct	*wwn_prev;
307 	struct	wwn_list_struct	*wwn_next;
308 } WWN_list;
309 
310 
311 /* HBA port list */
312 typedef struct portlist {
313 	int hbacnt;
314 	char *physpath[MAX_HBA_PORT];
315 } portlist_t;
316 /* union for capturing sf and fp strucures */
317 typedef union gfc_port_dev_u {
318 	sf_al_addr_pair_t	priv_port; /* private loop */
319 	fc_port_dev_t		pub_port;  /* fabric/public loop */
320 } gfc_port_dev_ut;
321 
322 
323 /* FC device sturcure with topology */
324 typedef struct gfc_port_dev_info {
325 	uint32_t	port_topology;
326 	gfc_port_dev_ut gfc_port_dev;
327 } gfc_port_dev_info_t;
328 
329 
330 /* strucure for FC map */
331 typedef struct gfc_map {
332 	int	count;
333 	gfc_port_dev_info_t	*dev_addr;
334 	gfc_port_dev_info_t	hba_addr;
335 } gfc_map_t;
336 
337 /* g_dev_map_init related declaration */
338 
339 typedef void *gfc_dev_t; /* opaque type for map device */
340 typedef void *gfc_prop_t; /* opaque type for map device property */
341 
342 #define	MAP_FORMAT_STANDARD	0
343 #define	MAP_FORMAT_LILP		0x00000001
344 #define	MAP_XPORT_PROP_ONLY	0x00000010
345 
346 /* property name for g_dev_prop_lookup */
347 #define	PORT_WWN_PROP "port-wwn"
348 #define	NODE_WWN_PROP "node-wwn"
349 #define	INQ_DTYPE_PROP "inq-dtype"
350 #define	PORT_ADDR_PROP "port-addr"
351 #define	HARD_ADDR_PROP "hard-addr"
352 
353 /* property type for g_dev_prop_next */
354 #define	GFC_PROP_TYPE_BOOLEAN	0
355 #define	GFC_PROP_TYPE_INT	1
356 #define	GFC_PROP_TYPE_STRING	2
357 #define	GFC_PROP_TYPE_BYTES	3
358 #define	GFC_PROP_TYPE_UNKNOWN	4
359 
360 typedef struct mp_pathinfo {
361 	mdi_pathinfo_state_t path_state;
362 	char	path_class[MAXNAMELEN];
363 	char	path_hba[MAXPATHLEN];
364 	char	path_dev[MAXPATHLEN];
365 	char	path_addr[MAXNAMELEN];
366 } mp_pathinfo_t;
367 
368 /* structure for mpxio pathlist */
369 typedef struct mp_pathlist {
370 	uint_t		path_count;
371 	mp_pathinfo_t	*path_info;
372 } mp_pathlist_t;
373 
374 /*
375  * Prototypes of Exported functions which are defined in libg_fc
376  * They are all CONTRACT PRIVATE
377  */
378 
379 #if defined(__STDC__)
380 
381 extern int	g_dev_start(char *, int);
382 extern int	g_dev_stop(char *, struct wwn_list_struct *, int);
383 extern int	g_force_lip(char *, int);
384 extern int	g_forcelip_all(struct hotplug_disk_list *);
385 extern void	g_free_multipath(struct dlist *);
386 extern void	g_free_wwn_list(struct wwn_list_struct **);
387 extern int	g_get_dev_map(char *, gfc_map_t *, int);
388 extern int	g_get_lilp_map(char *, gfc_map_t *, int);
389 extern int	g_get_inq_dtype(char *, la_wwn_t, uchar_t *);
390 extern int	g_get_dev_list(char *, fc_port_dev_t **, int *);
391 extern int	g_wwn_in_dev_list(char *, la_wwn_t, int);
392 extern char 	*g_get_dev_or_bus_phys_name(char *);
393 extern char 	*g_get_errString(int);
394 extern int	g_get_inquiry(char *, L_inquiry *);
395 extern int	g_get_serial_number(char *, uchar_t *, size_t *);
396 extern int	g_get_limited_map(char *, struct lilpmap *, int);
397 extern int	g_get_multipath(char *, struct dlist **,
398 		struct wwn_list_struct *, int);
399 extern int	g_get_nexus_path(char *, char **);
400 extern char 	*g_get_physical_name_from_link(char *);
401 extern char 	*g_get_physical_name(char *);
402 extern int	g_get_wwn(char *, uchar_t *, uchar_t *, int *, int);
403 extern int	g_get_wwn_list(struct wwn_list_struct **, int);
404 extern int	g_i18n_catopen(void);
405 extern int	g_offline_drive(struct dlist *, int);
406 extern void	g_online_drive(struct dlist *, int);
407 extern int	g_rdls(char *, struct al_rls **, int);
408 extern uint_t	g_get_path_type(char *);
409 extern int	g_get_host_params(char *, fc_port_dev_t *, int);
410 extern int	g_port_offline(char *);
411 extern int	g_port_online(char *);
412 extern int	g_get_port_path(char *, portlist_t *);
413 extern void	g_free_portlist(portlist_t *);
414 extern int	g_loopback_mode(char *, int);
415 extern int	g_get_port_state(char *, int *, int);
416 extern int	g_get_fca_port_topology(char *, uint32_t *, int);
417 extern int	g_dev_login(char *, la_wwn_t);
418 extern int	g_dev_logout(char *, la_wwn_t);
419 extern int	g_get_pathlist(char *, struct mp_pathlist *);
420 extern int	g_failover(char *, char *);
421 
422 /* g_dev_map_init related routines. */
423 extern gfc_dev_t	g_dev_map_init(char *, int *, int);
424 extern void		g_dev_map_fini(gfc_dev_t);
425 extern int		g_get_map_topology(gfc_dev_t, uint_t *);
426 extern gfc_dev_t	g_get_first_dev(gfc_dev_t, int *);
427 extern gfc_dev_t	g_get_next_dev(gfc_dev_t, int *);
428 extern int	g_dev_prop_lookup_bytes(gfc_dev_t, const char *, int *,
429 		uchar_t **);
430 extern int g_dev_prop_lookup_ints(gfc_dev_t, const char *, int **);
431 extern int g_dev_prop_lookup_strings(gfc_dev_t, const char *, char **);
432 extern gfc_prop_t g_get_first_dev_prop(gfc_dev_t, int *);
433 extern gfc_prop_t g_get_next_dev_prop(gfc_prop_t, int *);
434 extern char *g_get_dev_prop_name(gfc_prop_t, int *);
435 extern int g_get_dev_prop_type(gfc_prop_t, int *);
436 extern int g_get_dev_prop_bytes(gfc_prop_t, int *, uchar_t **);
437 extern int g_get_dev_prop_ints(gfc_prop_t, int **);
438 extern int g_get_dev_prop_strings(gfc_prop_t, char **);
439 extern int g_stms_path_disable(char *, char *);
440 extern int g_stms_path_enable(char *, char *);
441 extern int g_stms_path_disable_all(char *);
442 extern int g_stms_path_enable_all(char *);
443 extern int g_stms_get_path_state(char *, char *, int *, int *);
444 
445 
446 #else /* __STDC__ */
447 
448 extern int	g_dev_start();
449 extern int	g_dev_stop();
450 extern int	g_force_lip();
451 extern int	g_forcelip_all();
452 extern void	g_free_multipath();
453 extern void	g_free_wwn_list();
454 extern int	g_get_inq_dtype();
455 extern int	g_get_dev_list();
456 extern int	g_wwn_in_dev_list();
457 extern int	g_get_dev_map();
458 extern int	g_get_lilp_map();
459 extern char 	*g_get_dev_or_bus_phys_name();
460 extern char 	*g_get_errString();
461 extern int	g_get_inquiry();
462 extern int	g_get_serial_number();
463 extern int	g_get_limited_map();
464 extern int	g_get_multipath();
465 extern int	g_get_nexus_path();
466 extern int	g_get_wwn_list();
467 extern int	g_offline_drive();
468 extern void	g_online_drive();
469 extern char 	*g_get_physical_name();
470 extern char 	*g_get_physical_name_from_link();
471 extern int	g_get_wwn();
472 extern int	g_i18n_catopen();
473 extern int	g_rdls();
474 extern uint_t	g_get_path_type();
475 extern int	g_get_host_params();
476 extern int	g_port_offline();
477 extern int	g_port_online();
478 extern int	g_get_port_path();
479 extern void	g_free_portlist();
480 extern int	g_loopback_mode();
481 extern int	g_get_port_state();
482 extern int	g_get_fca_port_topology();
483 extern int	g_dev_login();
484 extern int	g_dev_logout();
485 extern int	g_get_pathlist();
486 extern int	g_failover();
487 
488 /* g_dev_map_init related routines. */
489 extern gfc_dev_t	g_dev_map_init();
490 extern void		g_dev_map_fini();
491 extern int		g_get_map_topology();
492 extern gfc_dev_t	g_get_first_dev();
493 extern gfc_dev_t	g_get_next_dev();
494 extern int	g_dev_prop_lookup_bytes();
495 extern int g_dev_prop_lookup_ints();
496 extern int g_dev_prop_lookup_strings();
497 extern gfc_prop_t g_get_first_dev_prop();
498 extern gfc_prop_t g_get_next_dev_prop();
499 extern char *g_get_dev_prop_name();
500 extern int g_get_dev_prop_type();
501 extern int g_get_dev_prop_bytes();
502 extern int g_get_dev_prop_ints();
503 extern int g_get_dev_prop_strings();
504 extern int g_stms_path_disable();
505 extern int g_stms_path_enable();
506 extern int g_stms_path_disable_all();
507 extern int g_stms_path_enable_all();
508 extern int g_stms_get_path_state();
509 
510 #endif /* __STDC__ */
511 
512 #ifdef	__cplusplus
513 }
514 #endif
515 
516 #endif /* _GFC_H */
517