xref: /illumos-gate/usr/src/cmd/luxadm/common.h (revision fcf3ce44)
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  * PHOTON CONFIGURATION MANAGER
28  * Common definitions
29  */
30 
31 /*
32  * I18N message number ranges
33  *  This file: 12500 - 12999
34  *  Shared common messages: 1 - 1999
35  */
36 
37 #ifndef	_COMMON_H
38 #define	_COMMON_H
39 
40 
41 
42 
43 /*
44  * Include any headers you depend on.
45  */
46 #include <sys/types.h>
47 #include <sys/scsi/adapters/scsi_vhci.h>
48 
49 #ifdef	__cplusplus
50 extern "C" {
51 #endif
52 
53 /*#ifdef _BIG_ENDIAN
54 #define	htonll(x)   (x)
55 #define	ntohll(x)   (x)
56 #else
57 #define	htonll(x)   ((((unsigned long long)htonl(x)) << 32) + htonl(x >> 32))
58 #define	ntohll(x)   ((((unsigned long long)ntohl(x)) << 32) + ntohl(x >> 32))
59 #endif*/
60 
61 
62 extern	char	*p_error_msg_ptr;
63 
64 #ifdef __x86
65 #include <nl_types.h>
66 extern nl_catd l_catd;
67 #define	L_SET1			1   /* catalog set number */
68 #define	MSGSTR(Num, Str)	catgets(l_catd, L_SET1, Num, Str)
69 #endif
70 
71 
72 /* Defines */
73 #define	USEAGE()	{(void) fprintf(stderr,  MSGSTR(12500, \
74 			"Usage: %s [-v] subcommand [option...]" \
75 			" {enclosure[,dev]... | pathname...}\n"), \
76 			whoami); \
77 			(void) fflush(stderr); }
78 
79 #define	E_USEAGE()	{(void) fprintf(stderr,  MSGSTR(12501, \
80 			"Usage: %s [-v] -e subcommand [option...]" \
81 			" {enclosure[,dev]... | pathname...}\n"), \
82 			whoami); \
83 			(void) fflush(stderr); }
84 
85 #define	VERBPRINT	 if (Options & PVERBOSE) (void) printf
86 
87 #define	L_ERR_PRINT	\
88 			if (p_error_msg_ptr == NULL) {  \
89 				perror(MSGSTR(12502, "Error"));	 \
90 			} else {	\
91 	(void) fprintf(stderr, MSGSTR(12503, "Error: %s"), p_error_msg_ptr); \
92 			} \
93 			p_error_msg_ptr = NULL;
94 
95 #define	P_ERR_PRINT	 if (p_error_msg_ptr == NULL) {  \
96 					perror(whoami);	 \
97 			} else {	\
98 	(void) fprintf(stderr, MSGSTR(12504, "Error: %s"), p_error_msg_ptr); \
99 			} \
100 			p_error_msg_ptr = NULL;
101 
102 
103 /* Display extended mode page information. */
104 #ifndef	MODEPAGE_CACHING
105 #undef	MODEPAGE_CACHING
106 #define	MODEPAGE_CACHING	0x08
107 #endif
108 
109 
110 /* Primary commands */
111 #define	ENCLOSURE_NAMES 100
112 #define	DISPLAY	 101
113 #define	DOWNLOAD	102
114 #define	FAST_WRITE	400	 /* SSA */
115 #define	FAILOVER	500
116 #define	FC_UPDATE	401	 /* SSA */
117 #define	FCAL_UPDATE	103	 /* Update the Fcode on Sbus soc card */
118 #define	FCODE_UPDATE	117	 /* Update the Fcode on all cards */
119 #define	QLGC_UPDATE	116	 /* Update the Fcode on PCI card(s) */
120 #define	INQUIRY		105
121 #define	LED		107
122 #define	LED_ON		108
123 #define	LED_OFF		109
124 #define	LED_BLINK	110
125 #define	NVRAM_DATA	402	 /* SSA */
126 #define	POWER_OFF	403	 /* SSA */
127 #define	POWER_ON	111
128 #define	PASSWORD	112
129 #define	PURGE		404	 /* SSA */
130 #define	PERF_STATISTICS 405	 /* SSA */
131 #define	PROBE		113
132 #define	RELEASE		210
133 #define	RESERVE		211
134 #define	START		213
135 #define	STOP		214
136 #define	SYNC_CACHE	406	 /* SSA */
137 #define	SET_BOOT_DEV	115	 /* Set the boot-device variable in nvram */
138 #define	INSERT_DEVICE	106	/* Hot plug */
139 #define	REMOVE_DEVICE	114	/* hot plug */
140 
141 /* Device hotplugging */
142 #define	REPLACE_DEVICE	150
143 #define	DEV_ONLINE	155
144 #define	DEV_OFFLINE	156
145 #define	DEV_GETSTATE	157
146 #define	DEV_RESET	158
147 #define	BUS_QUIESCE	160
148 #define	BUS_UNQUIESCE	161
149 #define	BUS_GETSTATE	162
150 #define	BUS_RESET	163
151 #define	BUS_RESETALL	164
152 
153 #define	SKIP		111
154 #define	QUIT		222
155 
156 #define	L_LED_STATUS	0x00
157 #define	L_LED_RQST_IDENTIFY	0x01
158 #define	L_LED_ON	0x02
159 #define	L_LED_OFF	0x04
160 
161 
162 /* Enclosure Specific */
163 #define	ALARM		407	 /* SSA */
164 #define	ALARM_OFF	408	 /* SSA */
165 #define	ALARM_ON	409	 /* SSA */
166 #define	ALARM_SET	410	 /* SSA */
167 #define	ENV_DISPLAY	411	 /* SSA */
168 
169 /* Expert commands */
170 #define	RDLS		215
171 #define	P_BYPASS	218
172 #define	P_ENABLE	219
173 #define	BYPASS		220
174 #define	ENABLE		221
175 #define	FORCELIP	222
176 #define	LUX_P_OFFLINE	223
177 #define	LUX_P_ONLINE	224
178 #define	EXT_LOOPBACK	225
179 #define	INT_LOOPBACK	226
180 #define	NO_LOOPBACK	227
181 #define	CREATE_FAB	228
182 
183 /* Undocumented commands */
184 #define	DUMP		300
185 #define	CHECK_FILE	301	/* Undocumented - Check download file */
186 #define	DUMP_MAP	302	/* Dump map of loop */
187 #define	VERSION		303	/* undocumented */
188 #define	AU		304	/* undocumented */
189 #define	PORT		305	/* undocumented */
190 
191 /* Undocumented diagnostic subcommands */
192 #define	SYSDUMP	 350
193 
194 
195 /* SSA - for adm_download */
196 /* #define	SSAFIRMWARE_FILE	"/usr/lib/firmware/ssa/ssafirmware" */
197 
198 /*	Global variables	*/
199 extern char	*whoami;
200 extern int	Options;
201 extern const	int OPTION_A;
202 extern const	int OPTION_B;
203 extern const	int OPTION_C;
204 extern const	int OPTION_D;
205 extern const	int OPTION_E;
206 extern const	int OPTION_F;
207 extern const	int OPTION_L;
208 extern const	int OPTION_P;
209 extern const	int OPTION_R;
210 extern const	int OPTION_T;
211 extern const	int OPTION_V;
212 extern const	int OPTION_Z;
213 extern const	int OPTION_Y;
214 extern const	int OPTION_CAPF;
215 extern const	int PVERBOSE;
216 extern const	int SAVE;
217 extern const	int EXPERT;
218 
219 #define		TARGET_ID(box_id, f_r, slot)	\
220 		((box_id | ((f_r == 'f' ? 0 : 1) << 4)) | (slot + 2))
221 
222 #define		NEWER(time1, time2) 	(time1.tv_sec > time2.tv_sec)
223 
224 /* used to set the behavior of get_slash_devices_from_osDevName. */
225 #define		STANDARD_DEVNAME_HANDLING	1
226 #define		NOT_IGNORE_DANGLING_LINK	2
227 
228 #include <hbaapi.h>
229 #ifndef __x86
230 #include <sys/scsi/generic/mode.h>
231 #include <sys/scsi/generic/sense.h>
232 #include <sys/scsi/impl/uscsi.h>
233 #include <g_state.h>
234 #include <stgcom.h>
235 #include <l_common.h>
236 #else
237 typedef struct l_inquiry_inq_2 {
238 #if defined(_BIT_FIELDS_HTOL)
239 	uchar_t inq_2_reladdr	: 1,	/* relative addressing */
240 		inq_wbus32	: 1,	/* 32 bit wide data xfers */
241 		inq_wbus16	: 1,	/* 16 bit wide data xfers */
242 		inq_sync	: 1,	/* synchronous data xfers */
243 		inq_linked	: 1,	/* linked commands */
244 		inq_res1	: 1,	/* reserved */
245 		inq_cmdque	: 1,	/* command queueing */
246 		inq_sftre	: 1;	/* Soft Reset option */
247 #else
248 	uchar_t inq_sftre	: 1,	/* Soft Reset option */
249 		inq_cmdque	: 1,	/* command queueing */
250 		inq_res1	: 1,	/* reserved */
251 		inq_linked	: 1,	/* linked commands */
252 		inq_sync	: 1,	/* synchronous data xfers */
253 		inq_wbus16	: 1,	/* 16 bit wide data xfers */
254 		inq_wbus32	: 1,	/* 32 bit wide data xfers */
255 		inq_2_reladdr	: 1;	/* relative addressing */
256 #endif /* _BIT_FIELDS_HTOL */
257 } L_inq_2;
258 
259 typedef struct l_inquiry_inq_3 {
260 #if defined(_BIT_FIELDS_HTOL)
261 	uchar_t inq_3_reladdr	: 1,	/* relative addressing */
262 		inq_SIP_2	: 3,	/* Interlocked Protocol */
263 		inq_3_linked	: 1,	/* linked commands */
264 		inq_trandis	: 1,	/* Transfer Disable */
265 		inq_3_cmdque	: 1,	/* command queueing */
266 		inq_SIP_3	: 1;	/* Interlocked Protocol */
267 #else
268 	uchar_t inq_SIP_3	: 1,	/* Interlocked Protocol */
269 		inq_3_cmdque	: 1,	/* command queueing */
270 		inq_trandis	: 1,	/* Transfer Disable */
271 		inq_3_linked	: 1,	/* linked commands */
272 		inq_SIP_2	: 3,	/* Interlocked Protocol */
273 		inq_3_reladdr	: 1;	/* relative addressing */
274 #endif /* _BIT_FIELDS_HTOL */
275 } L_inq_3;
276 
277 typedef struct l_inquiry_struct {
278 	/*
279 	 * byte 0
280 	 *
281 	 * Bits 7-5 are the Peripheral Device Qualifier
282 	 * Bits 4-0 are the Peripheral Device Type
283 	 *
284 	 */
285 	uchar_t	inq_dtype;
286 	/* byte 1 */
287 #if defined(_BIT_FIELDS_HTOL)
288 	uchar_t	inq_rmb		: 1,	/* removable media */
289 		inq_qual	: 7;	/* device type qualifier */
290 #else
291 	uchar_t	inq_qual	: 7,	/* device type qualifier */
292 		inq_rmb		: 1; 	/* removable media */
293 #endif /* _BIT_FIELDS_HTOL */
294 
295 	/* byte 2 */
296 #if defined(_BIT_FIELDS_HTOL)
297 	uchar_t	inq_iso		: 2,	/* ISO version */
298 		inq_ecma	: 3,	/* ECMA version */
299 		inq_ansi	: 3;	/* ANSI version */
300 #else
301 	uchar_t	inq_ansi	: 3,	/* ANSI version */
302 		inq_ecma	: 3,	/* ECMA version */
303 		inq_iso		: 2;	/* ISO version */
304 #endif /* _BIT_FIELDS_HTOL */
305 
306 	/* byte 3 */
307 #define	inq_aerc inq_aenc	/* SCSI-3 */
308 #if defined(_BIT_FIELDS_HTOL)
309 	uchar_t	inq_aenc	: 1,	/* async event notification cap. */
310 		inq_trmiop	: 1,	/* supports TERMINATE I/O PROC msg */
311 		inq_normaca	: 1,	/* Normal ACA Supported */
312 				: 1,	/* reserved */
313 		inq_rdf		: 4;	/* response data format */
314 #else
315 	uchar_t	inq_rdf		: 4,	/* response data format */
316 				: 1,	/* reserved */
317 		inq_normaca	: 1,	/* Normal ACA Supported */
318 		inq_trmiop	: 1,	/* supports TERMINATE I/O PROC msg */
319 		inq_aenc	: 1;	/* async event notification cap. */
320 #endif /* _BIT_FIELDS_HTOL */
321 
322 	/* bytes 4-7 */
323 	uchar_t	inq_len;		/* additional length */
324 	uchar_t			: 8;	/* reserved */
325 #if defined(_BIT_FIELDS_HTOL)
326 	uchar_t			: 2,	/* reserved */
327 		inq_port	: 1,	/* Only defined when dual_p set */
328 		inq_dual_p	: 1,	/* Dual Port */
329 		inq_mchngr	: 1,	/* Medium Changer */
330 		inq_SIP_1	: 3;	/* Interlocked Protocol */
331 #else
332 	uchar_t	inq_SIP_1	: 3,	/* Interlocked Protocol */
333 		inq_mchngr	: 1,	/* Medium Changer */
334 		inq_dual_p	: 1,	/* Dual Port */
335 		inq_port	: 1,	/* Only defined when dual_p set */
336 				: 2;	/* reserved */
337 #endif /* _BIT_FIELDS_HTOL */
338 
339 	union {
340 		L_inq_2 inq_2;
341 		L_inq_3 inq_3;
342 	} ui;
343 
344 
345 	/* bytes 8-35 */
346 
347 	uchar_t	inq_vid[8];		/* vendor ID */
348 
349 	uchar_t	inq_pid[16];		/* product ID */
350 
351 	uchar_t	inq_revision[4];	/* product revision level */
352 
353 	/*
354 	 * Bytes 36-55 are vendor-specific parameter bytes
355 	 */
356 
357 	/* SSA specific definitions */
358 	/* bytes 36 - 39 */
359 #define	inq_ven_specific_1 inq_firmware_rev
360 	uchar_t	inq_firmware_rev[4];	/* firmware revision level */
361 
362 	/* bytes 40 - 51 */
363 	uchar_t	inq_serial[12];		/* serial number, not used any more */
364 
365 	/* bytes 52-53 */
366 	uchar_t	inq_res2[2];
367 
368 	/* byte 54, 55 */
369 	uchar_t	inq_ssa_ports;		/* number of ports */
370 	uchar_t	inq_ssa_tgts;		/* number of targets */
371 
372 	/*
373 	 * Bytes 56-95 are reserved.
374 	 */
375 	uchar_t	inq_res3[40];
376 	/*
377 	 * 96 to 'n' are vendor-specific parameter bytes
378 	 */
379 	uchar_t	inq_box_name[32];
380 	uchar_t	inq_avu[256];
381 } L_inquiry;
382 #define	HEX_ONLY	0	/* Print Hex only */
383 #define	HEX_ASCII	1	/* Print Hex and Ascii */
384 #define	WWN_SIZE	8	/* # of bytes to dump per line */
385 
386 /* NOTE: These command op codes are not defined in commands.h */
387 #define	SCMD_SYNC_CACHE		    0x35
388 #define	SCMD_LOG_SENSE		    0x4d
389 #define	SCMD_PERS_RESERV_IN	    0x5e
390 #define	SCMD_PERS_RESERV_OUT	    0x5f
391 
392 typedef struct rls_payload {
393 	uint_t  rls_portno;
394 	uint_t  rls_linkfail;
395 	uint_t  rls_syncfail;
396 	uint_t  rls_sigfail;
397 	uint_t  rls_primitiverr;
398 	uint_t  rls_invalidword;
399 	uint_t  rls_invalidcrc;
400 } rls_payload_t;
401 
402 typedef struct l_inquiry00_struct {
403 #if defined(_BIT_FIELDS_LTOH)
404 uchar_t		qual    :3,
405 		dtype   :5;
406 #else
407 uchar_t		dtype	:5,
408 		qual	:3;
409 #endif	/* _BIT_FIELDS_LTOH */
410 uchar_t		page_code;
411 uchar_t		reserved;
412 uchar_t		len;
413 uchar_t		page_list[251];
414 } L_inquiry00;
415 
416 #define	MIN(a, b) (a < b ? a : b)
417 #define	ER_DPRINTF	if (getenv("_LUX_ER_DEBUG") != NULL) (void) printf
418 #define	O_DPRINTF	if (getenv("_LUX_O_DEBUG") != NULL) (void) printf
419 #define	P_DPRINTF	if (getenv("_LUX_P_DEBUG") != NULL) (void) printf
420 #define	R_DPRINTF	if (getenv("_LUX_R_DEBUG") != NULL) (void) printf
421 #define	I_DPRINTF	if (getenv("_LUX_I_DEBUG") != NULL) (void) printf
422 #define	S_DPRINTF	if (getenv("_LUX_S_DEBUG") != NULL) (void) printf
423 #define	RETRY_FCIO_IOCTL    360
424 #define	WAIT_FCIO_IOCTL	    250000 /* 1/4 of a second */
425 
426 #endif /* __x86 */
427 
428 
429 int adm_display_config(char **argv);
430 void adm_download(char **argv, char *file_name);
431 void up_encl_name(char **argv, int argc);
432 void adm_failover(char **argv);
433 void pho_probe();
434 void non_encl_probe();
435 void adm_led(char **argv, int led_action);
436 void up_password(char **argv);
437 int adm_start(char **argv);
438 int adm_stop(char **argv);
439 int adm_power_off(char **argv, int off_flag);
440 int adm_forcelip(char **argv);
441 void adm_bypass_enable(char **argv, int bypass_flag);
442 int adm_port_offline_online(char *argv[], int flag);
443 void display_link_status(char **argv);
444 int read_repos_file(char *repos_filename);
445 int adm_check_file(char **argv, int flag);
446 void dump(char **argv);
447 void dump_map(char **argv);
448 int adm_port_loopback(char *portpath, int flag);
449 int adm_inquiry(char **argv);
450 int adm_display_port(int verbose);
451 
452 int adm_reserve(char *path);
453 int adm_release(char *path);
454 void i18n_catopen();
455 void dump_hex_data(char *, uchar_t *, int, int);
456 void print_errString(int, char *);
457 void	print_chars(uchar_t *, int, int);
458 void	print_inq_data(char *, char *, L_inquiry, uchar_t *, size_t);
459 void print_fabric_dtype_prop(uchar_t *hba_port_wwn, uchar_t *port_wwn,
460 	uchar_t dtype_prop);
461 void print_private_loop_dtype_prop(uchar_t *hba_port_wwn, uchar_t *port_wwn,
462 	uchar_t dtype_prop);
463 char *get_errString(int errornum);
464 int cmp_raw_wwn(uchar_t *wwn_1, uchar_t *wwn_2);
465 
466 /* routines in fchba*.c files */
467 int fchba_display_port(int verbose);
468 int fchba_display_config(char **argv, int option_t_input, int argc);
469 char *get_slash_devices_from_osDevName(char *osDevName, int flag);
470 int get_scsi_vhci_pathinfo(char *dev_path, sv_iocdata_t *ioc,
471 		int *path_count);
472 int get_mode_page(char *path, uchar_t **pg_buf);
473 int scsi_mode_sense_cmd(int fd, uchar_t *buf_ptr, int buf_len, uchar_t pc,
474 	uchar_t page_code);
475 int scsi_release(char *path);
476 int scsi_reserve(char *path);
477 int is_path(char *arg);
478 int is_wwn(char *arg);
479 int loadLibrary();
480 uint32_t getNumberOfAdapters();
481 int getAdapterAttrs(HBA_HANDLE handle,
482 	char *name, HBA_ADAPTERATTRIBUTES *attrs);
483 int getAdapterPortAttrs(HBA_HANDLE handle, char *name, int portIndex,
484 	HBA_PORTATTRIBUTES *attrs);
485 HBA_STATUS fetch_mappings(HBA_HANDLE handle, HBA_WWN pwwn,
486     HBA_FCPTARGETMAPPINGV2 **map);
487 int match_mappings(char *compare, HBA_FCPTARGETMAPPINGV2 *map);
488 uint64_t wwnConversion(uchar_t *wwn);
489 
490 
491 #ifdef	__cplusplus
492 }
493 #endif
494 
495 #endif	/* _COMMON_H */
496