xref: /titanic_44/usr/src/cmd/fcinfo/fcinfo.h (revision 0a1ad920531b37f01f4aa8084737026621c76bdb)
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 2009 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 #include <locale.h>
48 
49 #ifdef _BIG_ENDIAN
50 #define	htonll(x)   (x)
51 #define	ntohll(x)   (x)
52 #else
53 #define	htonll(x)   ((((unsigned long long)htonl(x)) << 32) + htonl(x >> 32))
54 #define	ntohll(x)   ((((unsigned long long)ntohl(x)) << 32) + ntohl(x >> 32))
55 #endif
56 
57 /* DEFINES */
58 
59 /* SCSI TARGET TYPES */
60 #define	SCSI_TARGET_TYPE_UNKNOWN    0
61 #define	SCSI_TARGET_TYPE_NO	    1
62 #define	SCSI_TARGET_TYPE_YES	    2
63 
64 #define	DEFAULT_LUN_COUNT	    1024
65 #define	LUN_SIZE		    8
66 #define	LUN_HEADER_SIZE		    8
67 #define	LUN_LENGTH		    LUN_SIZE + LUN_HEADER_SIZE
68 #define	DEFAULT_LUN_LENGTH	    DEFAULT_LUN_COUNT	* \
69 				    LUN_SIZE		+ \
70 				    LUN_HEADER_SIZE
71 
72 #define	HBA_MAX_RETRIES		20
73 #define	PORT_LIST_ALLOC		100
74 #define	NPIV_PORT_LIST_LENGTH	255
75 
76 #define	NPIV_ADD		0
77 #define	NPIV_REMOVE		1
78 
79 #define	NPIV_SUCCESS			0
80 #define	NPIV_ERROR			1
81 #define	NPIV_ERROR_NOT_FOUND		2
82 #define	NPIV_ERROR_EXISTS		3
83 #define	NPIV_ERROR_SERVICE_NOT_FOUND	4
84 #define	NPIV_ERROR_NOMEM		5
85 #define	NPIV_ERROR_MEMBER_NOT_FOUND	6
86 #define	NPIV_ERROR_BUSY			7
87 
88 #define	NPIV_SERVICE	"network/npiv_config"
89 #define	NPIV_PG_NAME	"npiv-port-list"
90 #define	NPIV_PORT_LIST	"port_list"
91 
92 #define	FCOE_SCF_ADD		0
93 #define	FCOE_SCF_REMOVE		1
94 
95 #define	FCOE_SUCCESS			0
96 #define	FCOE_ERROR			1
97 #define	FCOE_ERROR_NOT_FOUND		2
98 #define	FCOE_ERROR_EXISTS		3
99 #define	FCOE_ERROR_SERVICE_NOT_FOUND	4
100 #define	FCOE_ERROR_NOMEM		5
101 #define	FCOE_ERROR_MEMBER_NOT_FOUND	6
102 #define	FCOE_ERROR_BUSY			7
103 
104 #define	FCOE_PORT_LIST_LENGTH	255
105 
106 #define	FCOE_SERVICE	"network/fcoe_config"
107 #define	FCOE_PG_NAME	"fcoe-port-list-pg"
108 #define	FCOE_PORT_LIST	"port_list_p"
109 
110 /* flags that are needed to be passed into processHBA */
111 #define	PRINT_LINKSTAT	    0x00000001	/* print link statistics information */
112 #define	PRINT_SCSI_TARGET   0x00000010	/* print Scsi target information */
113 #define	PRINT_INITIATOR	    0x00000100	/* print intiator port information */
114 #define	PRINT_TARGET	    0x00001000	/* print target port information */
115 #define	PRINT_FCOE	    0x00010000	/* print fcoe port information */
116 
117 /* flags for Adpater/port mode */
118 #define	INITIATOR_MODE	    0x00000001
119 #define	TARGET_MODE	    0x00000010
120 
121 /* FCOE */
122 #define	FCOE_MAX_MAC_NAME_LEN		32
123 #define	FCOE_USER_RAW_FRAME_SIZE	224
124 
125 typedef struct _tgtPortWWNList {
126 	HBA_WWN portWWN;
127 	HBA_UINT32	scsiOSLun;
128 	struct _tgtPortWWNList *next;
129 } tgtPortWWNList;
130 
131 typedef struct _portWWNList {
132 	HBA_WWN	portWWN;
133 	tgtPortWWNList *tgtPortWWN;
134 	struct _portWWNList *next;
135 } portWWNList;
136 
137 /* Discovered ports structure */
138 typedef struct _discoveredDevice {
139 	char	OSDeviceName[MAXPATHLEN];
140 	portWWNList *HBAPortWWN;
141 	char    VID[8];
142 	char    PID[16];
143 	boolean_t   inqSuccess;
144 	uchar_t	dType;
145 	struct  _discoveredDevice *next;
146 } discoveredDevice;
147 
148 /* globals */
149 static char *cmdName;
150 
151 /* print helper functions */
152 void printHBAPortInfo(HBA_PORTATTRIBUTES *port,
153     HBA_ADAPTERATTRIBUTES *attrs, int mode);
154 void printDiscoPortInfo(HBA_PORTATTRIBUTES *discoPort, int scsiTargetType);
155 void printLUNInfo(struct scsi_inquiry *inq, HBA_UINT32 scsiLUN, char *devpath);
156 void printPortStat(fc_rls_acc_t *rls_payload);
157 void printScsiTarget(HBA_WWN);
158 void printStatus(HBA_STATUS status);
159 void printOSDeviceNameInfo(discoveredDevice *devListWalk, boolean_t verbose);
160 uint64_t wwnConversion(uchar_t *wwn);
161 
162 int fc_util_list_hbaport(int wwnCount, char **wwn_argv, cmdOptions_t *options);
163 int fc_util_list_remoteport(int wwnCount, char **argv, cmdOptions_t *options);
164 int fc_util_list_logicalunit(int pathCount, char **argv, cmdOptions_t *options);
165 int fc_util_delete_npivport(int wwnCount, char **argv, cmdOptions_t *options);
166 int fc_util_create_npivport(int wwnCount, char **argv, cmdOptions_t *options);
167 int fc_util_create_portlist();
168 
169 int fcoe_adm_create_port(int objects, char *argv[],
170     cmdOptions_t *options);
171 int fcoe_adm_delete_port(int objects, char *argv[]);
172 int fcoe_adm_list_ports(cmdOptions_t *options);
173 int fcoe_adm_create_portlist(cmdOptions_t *options);
174 
175 
176 #ifdef	__cplusplus
177 }
178 #endif
179 
180 #endif /* _FCINFO_H */
181