xref: /titanic_41/usr/src/cmd/fcinfo/fcinfo.h (revision 8475e04352e630e4bd0f59a283286ee2475a14ce)
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 #ifndef _FCINFO_H
27 #define	_FCINFO_H
28 
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <libintl.h>
38 #include <hbaapi.h>
39 #include <hbaapi-sun.h>
40 #include <unistd.h>
41 #include <sys/scsi/scsi.h>
42 #include <sys/fibre-channel/fcio.h>
43 #include <sys/types.h>
44 #include <netinet/in.h>
45 #include <inttypes.h>
46 #include <cmdparse.h>
47 
48 #ifdef _BIG_ENDIAN
49 #define	htonll(x)   (x)
50 #define	ntohll(x)   (x)
51 #else
52 #define	htonll(x)   ((((unsigned long long)htonl(x)) << 32) + htonl(x >> 32))
53 #define	ntohll(x)   ((((unsigned long long)ntohl(x)) << 32) + ntohl(x >> 32))
54 #endif
55 
56 /* DEFINES */
57 
58 /* SCSI TARGET TYPES */
59 #define	SCSI_TARGET_TYPE_UNKNOWN    0
60 #define	SCSI_TARGET_TYPE_NO	    1
61 #define	SCSI_TARGET_TYPE_YES	    2
62 
63 #define	DEFAULT_LUN_COUNT	    1024
64 #define	LUN_SIZE		    8
65 #define	LUN_HEADER_SIZE		    8
66 #define	LUN_LENGTH		    LUN_SIZE + LUN_HEADER_SIZE
67 #define	DEFAULT_LUN_LENGTH	    DEFAULT_LUN_COUNT	* \
68 				    LUN_SIZE		+ \
69 				    LUN_HEADER_SIZE
70 
71 #define	HBA_MAX_RETRIES		20
72 #define	PORT_LIST_ALLOC		100
73 #define	NPIV_PORT_LIST_LENGTH	255
74 
75 #define	NPIV_ADD		0
76 #define	NPIV_REMOVE		1
77 
78 #define	NPIV_SUCCESS			0
79 #define	NPIV_ERROR			1
80 #define	NPIV_ERROR_NOT_FOUND		2
81 #define	NPIV_ERROR_EXISTS		3
82 #define	NPIV_ERROR_SERVICE_NOT_FOUND	4
83 #define	NPIV_ERROR_NOMEM		5
84 #define	NPIV_ERROR_MEMBER_NOT_FOUND	6
85 #define	NPIV_ERROR_BUSY			7
86 
87 #define	NPIV_SERVICE	"network/npiv_config"
88 #define	NPIV_PG_NAME	"npiv-port-list"
89 #define	NPIV_PORT_LIST	"port_list"
90 
91 /* flags that are needed to be passed into processHBA */
92 #define	PRINT_LINKSTAT	    0x00000001	/* print link statistics information */
93 #define	PRINT_SCSI_TARGET   0x00000010	/* print Scsi target information */
94 #define	PRINT_INITIATOR	    0x00000100	/* print intiator port information */
95 #define	PRINT_TARGET	    0x00001000	/* print target port information */
96 
97 /* flags for Adpater/port mode */
98 #define	INITIATOR_MODE	    0x00000001
99 #define	TARGET_MODE	    0x00000010
100 
101 typedef struct _tgtPortWWNList {
102 	HBA_WWN portWWN;
103 	HBA_UINT32	scsiOSLun;
104 	struct _tgtPortWWNList *next;
105 } tgtPortWWNList;
106 
107 typedef struct _portWWNList {
108 	HBA_WWN	portWWN;
109 	tgtPortWWNList *tgtPortWWN;
110 	struct _portWWNList *next;
111 } portWWNList;
112 
113 /* Discovered ports structure */
114 typedef struct _discoveredDevice {
115 	char	OSDeviceName[MAXPATHLEN];
116 	portWWNList *HBAPortWWN;
117 	char    VID[8];
118 	char    PID[16];
119 	boolean_t   inqSuccess;
120 	uchar_t	dType;
121 	struct  _discoveredDevice *next;
122 } discoveredDevice;
123 
124 /* globals */
125 static char *cmdName;
126 
127 /* print helper functions */
128 void printHBAPortInfo(HBA_PORTATTRIBUTES *port,
129     HBA_ADAPTERATTRIBUTES *attrs, int mode);
130 void printDiscoPortInfo(HBA_PORTATTRIBUTES *discoPort, int scsiTargetType);
131 void printLUNInfo(struct scsi_inquiry *inq, HBA_UINT32 scsiLUN, char *devpath);
132 void printPortStat(fc_rls_acc_t *rls_payload);
133 void printScsiTarget(HBA_WWN);
134 void printStatus(HBA_STATUS status);
135 void printOSDeviceNameInfo(discoveredDevice *devListWalk, boolean_t verbose);
136 uint64_t wwnConversion(uchar_t *wwn);
137 
138 int fc_util_list_hbaport(int wwnCount, char **wwn_argv, cmdOptions_t *options);
139 int fc_util_list_remoteport(int wwnCount, char **argv, cmdOptions_t *options);
140 int fc_util_list_logicalunit(int pathCount, char **argv, cmdOptions_t *options);
141 int fc_util_delete_npivport(int wwnCount, char **argv, cmdOptions_t *options);
142 int fc_util_create_npivport(int wwnCount, char **argv, cmdOptions_t *options);
143 int fc_util_create_portlist();
144 
145 #ifdef	__cplusplus
146 }
147 #endif
148 
149 #endif /* _FCINFO_H */
150