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.
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.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
38 static const char *FCOE_DRIVER_PATH
= "/devices/fcoe:admin";
49 if (strlen(wwn
) != 16) {
53 for (index
= 0; index
< 16; index
++) {
54 if (isxdigit(wwn
[index
])) {
62 static uint64_t wwnconvert(uchar_t
*wwn
)
65 memcpy(&tmp
, wwn
, sizeof (uint64_t));
70 * prints out all the HBA port information
73 printFCOEPortInfo(FCOE_PORT_ATTRIBUTE
*attr
)
79 fprintf(stdout
, gettext("HBA Port WWN: %016llx\n"),
80 wwnconvert((unsigned char *)&attr
->port_wwn
));
82 fprintf(stdout
, gettext("\tPort Type: %s\n"),
83 (attr
->port_type
== 0) ? "Initiator" : "Target");
85 fprintf(stdout
, gettext("\tMAC Name: %s\n"), attr
->mac_link_name
);
87 fprintf(stdout
, gettext("\tMTU Size: %d\n"), attr
->mtu_size
);
89 fprintf(stdout
, gettext("\tPrimary MAC Address: "));
90 for (i
= 0; i
< 6; i
++) {
91 fprintf(stdout
, gettext("%02x"), attr
->mac_factory_addr
[i
]);
93 fprintf(stdout
, gettext("\n\tCurrent MAC Address: "));
94 for (i
= 0; i
< 6; i
++) {
95 fprintf(stdout
, gettext("%02x"), attr
->mac_current_addr
[i
]);
97 fprintf(stdout
, gettext("\n\tPromiscuous Mode: %s\n"),
98 attr
->mac_promisc
== 1 ? "On" : "Off");
103 fcoe_adm_create_port(int objects
, char *argv
[],
104 cmdOptions_t
*options
)
106 FCOE_STATUS status
= FCOE_STATUS_OK
;
107 uint64_t nodeWWN
, portWWN
;
108 FCOE_PORT_WWN pwwn
, nwwn
;
109 FCOE_UINT8 macLinkName
[FCOE_MAX_MAC_NAME_LEN
];
110 FCOE_UINT8 promiscuous
= 0;
111 int createini
= 0, createtgt
= 0;
113 /* check the mac name operand */
114 assert(objects
== 1);
116 strcpy((char *)macLinkName
, argv
[0]);
120 for (; options
->optval
; options
++) {
121 switch (options
->optval
) {
130 if (!isValidWWN(options
->optarg
)) {
132 gettext("Error: Invalid Port WWN\n"));
135 sscanf(options
->optarg
, "%016llx", &portWWN
);
136 portWWN
= htonll(portWWN
);
137 memcpy(&pwwn
, &portWWN
, sizeof (portWWN
));
141 if (!isValidWWN(options
->optarg
)) {
143 gettext("Error: Invalid Node WWN\n"));
146 sscanf(options
->optarg
, "%016llx", &nodeWWN
);
147 nodeWWN
= htonll(nodeWWN
);
148 memcpy(&nwwn
, &nodeWWN
, sizeof (nodeWWN
));
155 fprintf(stderr
, gettext("Error: Illegal option: %c\n"),
161 if (createini
== 1 && createtgt
== 1) {
162 fprintf(stderr
, "Error: Option -i and -t should "
163 "not be both specified\n");
166 status
= FCOE_CreatePort(macLinkName
,
167 createtgt
== 1 ? FCOE_PORTTYPE_TARGET
:
168 FCOE_PORTTYPE_INITIATOR
, pwwn
, nwwn
, promiscuous
);
170 if (status
!= FCOE_STATUS_OK
) {
172 case FCOE_STATUS_ERROR_BUSY
:
174 gettext("Error: fcoe driver is busy\n"));
177 case FCOE_STATUS_ERROR_ALREADY
:
179 gettext("Error: Existing FCoE port "
180 "found on the specified MAC link\n"));
183 case FCOE_STATUS_ERROR_PERM
:
185 gettext("Error: Not enough permission to "
186 "open fcoe device\n"));
189 case FCOE_STATUS_ERROR_OPEN_DEV
:
191 gettext("Error: Failed to open fcoe device\n"));
194 case FCOE_STATUS_ERROR_WWN_SAME
:
196 gettext("Error: Port WWN is same as Node "
200 case FCOE_STATUS_ERROR_MAC_LEN
:
202 gettext("Error: MAC name exceeds maximum "
206 case FCOE_STATUS_ERROR_PWWN_CONFLICTED
:
208 gettext("Error: The specified Port WWN "
209 "is already in use\n"));
212 case FCOE_STATUS_ERROR_NWWN_CONFLICTED
:
214 gettext("Error: The specified Node WWN "
215 "is already in use\n"));
218 case FCOE_STATUS_ERROR_NEED_JUMBO_FRAME
:
220 gettext("Error: MTU size of the specified "
221 "MAC link needs to be increased to 2500 "
225 case FCOE_STATUS_ERROR_CREATE_MAC
:
227 gettext("Error: Out of memory\n"));
231 case FCOE_STATUS_ERROR_OPEN_MAC
:
233 gettext("Error: Failed to open the "
234 "specified MAC link\n"));
237 case FCOE_STATUS_ERROR_CREATE_PORT
:
239 gettext("Error: Failed to create FCoE "
240 "port on the specified MAC link\n"));
243 case FCOE_STATUS_ERROR_CLASS_UNSUPPORT
:
245 gettext("Error: Link class other than physical "
246 "link is not supported\n"));
249 case FCOE_STATUS_ERROR_GET_LINKINFO
:
251 gettext("Error: Failed to get link information "
252 "for %s\n"), macLinkName
);
255 case FCOE_STATUS_ERROR
:
258 gettext("Error: Due to reason code %d\n"), status
);
267 fcoe_adm_delete_port(int objects
, char *argv
[])
270 FCOE_UINT8
*macLinkName
;
271 FCOE_UINT32 port_num
;
272 FCOE_PORT_ATTRIBUTE
*portlist
= NULL
;
275 /* check the mac name operand */
276 assert(objects
== 1);
278 macLinkName
= (FCOE_UINT8
*) argv
[0];
280 status
= FCOE_DeletePort(macLinkName
);
281 if (status
!= FCOE_STATUS_OK
) {
283 case FCOE_STATUS_ERROR_BUSY
:
285 gettext("Error: fcoe driver is busy\n"));
288 case FCOE_STATUS_ERROR_ALREADY
:
290 gettext("Error: FCoE port not found on the "
291 "specified MAC link\n"));
294 case FCOE_STATUS_ERROR_PERM
:
296 gettext("Error: Not enough permission to "
297 "open fcoe device\n"));
300 case FCOE_STATUS_ERROR_MAC_LEN
:
302 gettext("Failed: MAC name exceeds maximum "
306 case FCOE_STATUS_ERROR_OPEN_DEV
:
308 gettext("Error: Failed to open fcoe device\n"));
311 case FCOE_STATUS_ERROR_MAC_NOT_FOUND
:
313 gettext("Error: FCoE port not found on the "
314 "specified MAC link\n"));
317 case FCOE_STATUS_ERROR_OFFLINE_DEV
:
318 status
= FCOE_GetPortList(&port_num
, &portlist
);
319 if (status
!= FCOE_STATUS_OK
|| port_num
== 0) {
321 gettext("Error: FCoE port not found on the "
322 "specified MAC link\n"));
325 for (i
= 0; i
< port_num
; i
++) {
327 (char *)portlist
[i
].mac_link_name
,
328 (char *)macLinkName
) == 0) {
329 if (portlist
[i
].port_type
==
330 FCOE_PORTTYPE_TARGET
) {
332 gettext("Error: Please use "
333 "stmfadm to offline the "
334 "FCoE target first\n"));
337 gettext("Error: Failed to "
338 "delete FCoE port because "
339 "unable to offline the "
348 gettext("Error: FCoE port not found on the "
349 "specified MAC link\n"));
353 case FCOE_STATUS_ERROR_GET_LINKINFO
:
355 gettext("Error: Failed to get link information "
356 "for %s\n"), macLinkName
);
359 case FCOE_STATUS_ERROR
:
362 gettext("Error: Due to reason code %d\n"), status
);
371 fcoe_adm_list_ports(cmdOptions_t
*options
)
374 int showini
= 0, showtgt
= 0;
375 FCOE_UINT32 port_num
;
376 FCOE_PORT_ATTRIBUTE
*portlist
= NULL
;
380 for (; options
->optval
; options
++) {
381 switch (options
->optval
) {
391 fprintf(stderr
, gettext("Error: Illegal option: %c\n"),
396 if (showini
== 0 && showtgt
== 0) {
401 status
= FCOE_GetPortList(&port_num
, &portlist
);
403 if (status
!= FCOE_STATUS_OK
) {
405 case FCOE_STATUS_ERROR_BUSY
:
407 gettext("Error: fcoe driver is busy\n"));
410 case FCOE_STATUS_ERROR_PERM
:
412 gettext("Error: Not enough permission to "
413 "open fcoe device\n"));
416 case FCOE_STATUS_ERROR_OPEN_DEV
:
418 gettext("Error: Failed to open fcoe device\n"));
421 case FCOE_STATUS_ERROR_INVAL_ARG
:
423 gettext("Error: Invalid argument\n"));
426 case FCOE_STATUS_ERROR_MORE_DATA
:
428 gettext("Error: More data\n"));
431 case FCOE_STATUS_ERROR
:
434 gettext("Error: Due to reason code %d\n"), status
);
439 fprintf(stdout
, gettext("No FCoE Ports Found!\n"));
441 for (i
= 0; i
< port_num
; i
++) {
442 if ((portlist
[i
].port_type
==
443 FCOE_PORTTYPE_INITIATOR
&&
444 showini
== 1) || (showtgt
== 1 &&
445 portlist
[i
].port_type
==
446 FCOE_PORTTYPE_TARGET
)) {
447 printFCOEPortInfo(&portlist
[i
]);
454 if (portlist
!= NULL
) {