xref: /titanic_41/usr/src/cmd/fcinfo/fcinfo.h (revision ffdae209526a77e75eb659dbd1fad51bf7e2ba98)
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_USER_RAW_FRAME_SIZE	224
123 
124 typedef struct _tgtPortWWNList {
125 	HBA_WWN portWWN;
126 	HBA_UINT32	scsiOSLun;
127 	struct _tgtPortWWNList *next;
128 } tgtPortWWNList;
129 
130 typedef struct _portWWNList {
131 	HBA_WWN	portWWN;
132 	tgtPortWWNList *tgtPortWWN;
133 	struct _portWWNList *next;
134 } portWWNList;
135 
136 /* Discovered ports structure */
137 typedef struct _discoveredDevice {
138 	char	OSDeviceName[MAXPATHLEN];
139 	portWWNList *HBAPortWWN;
140 	char    VID[8];
141 	char    PID[16];
142 	boolean_t   inqSuccess;
143 	uchar_t	dType;
144 	struct  _discoveredDevice *next;
145 } discoveredDevice;
146 
147 /* globals */
148 static char *cmdName;
149 
150 /* print helper functions */
151 void printHBAPortInfo(HBA_PORTATTRIBUTES *port,
152     HBA_ADAPTERATTRIBUTES *attrs, int mode);
153 void printDiscoPortInfo(HBA_PORTATTRIBUTES *discoPort, int scsiTargetType);
154 void printLUNInfo(struct scsi_inquiry *inq, HBA_UINT32 scsiLUN, char *devpath);
155 void printPortStat(fc_rls_acc_t *rls_payload);
156 void printScsiTarget(HBA_WWN);
157 void printStatus(HBA_STATUS status);
158 void printOSDeviceNameInfo(discoveredDevice *devListWalk, boolean_t verbose);
159 uint64_t wwnConversion(uchar_t *wwn);
160 
161 int fc_util_list_hbaport(int wwnCount, char **wwn_argv, cmdOptions_t *options);
162 int fc_util_list_remoteport(int wwnCount, char **argv, cmdOptions_t *options);
163 int fc_util_list_logicalunit(int pathCount, char **argv, cmdOptions_t *options);
164 int fc_util_delete_npivport(int wwnCount, char **argv, cmdOptions_t *options);
165 int fc_util_create_npivport(int wwnCount, char **argv, cmdOptions_t *options);
166 int fc_util_create_portlist();
167 
168 int fcoe_adm_create_port(int objects, char *argv[],
169     cmdOptions_t *options);
170 int fcoe_adm_delete_port(int objects, char *argv[]);
171 int fcoe_adm_list_ports(cmdOptions_t *options);
172 int fcoe_adm_create_portlist(cmdOptions_t *options);
173 
174 
175 #ifdef	__cplusplus
176 }
177 #endif
178 
179 #endif /* _FCINFO_H */
180