1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "fcinfo.h"
#include <libintl.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
#include <ctype.h>
#include <sys/list.h>
#include <stddef.h>
#include <strings.h>
#include <libfcoe.h>
#include <syslog.h>
static const char *FCOE_DRIVER_PATH = "/devices/fcoe:admin";
static int
isValidWWN(char *wwn)
{
int index;
if (wwn == NULL) {
return (0);
}
if (strlen(wwn) != 16) {
return (0);
}
for (index = 0; index < 16; index++) {
if (isxdigit(wwn[index])) {
continue;
}
return (0);
}
return (1);
}
static uint64_t wwnconvert(uchar_t *wwn)
{
uint64_t tmp;
memcpy(&tmp, wwn, sizeof (uint64_t));
return (ntohll(tmp));
}
/*
* prints out all the HBA port information
*/
void
printFCOEPortInfo(FCOE_PORT_ATTRIBUTE *attr)
{
int i;
if (attr == NULL) {
return;
}
fprintf(stdout, gettext("HBA Port WWN: %016llx\n"),
wwnconvert((unsigned char *)&attr->port_wwn));
fprintf(stdout, gettext("\tPort Type: %s\n"),
(attr->port_type == 0) ? "Initiator" : "Target");
fprintf(stdout, gettext("\tMAC Name: %s\n"), attr->mac_link_name);
fprintf(stdout, gettext("\tMTU Size: %d\n"), attr->mtu_size);
fprintf(stdout, gettext("\tPrimary MAC Address: "));
for (i = 0; i < 6; i++) {
fprintf(stdout, gettext("%02x"), attr->mac_factory_addr[i]);
}
fprintf(stdout, gettext("\n\tCurrent MAC Address: "));
for (i = 0; i < 6; i++) {
fprintf(stdout, gettext("%02x"), attr->mac_current_addr[i]);
}
fprintf(stdout, gettext("\n\tPromiscuous Mode: %s\n"),
attr->mac_promisc == 1 ? "On" : "Off");
}
int
fcoe_adm_create_port(int objects, char *argv[],
cmdOptions_t *options)
{
FCOE_STATUS status = FCOE_STATUS_OK;
uint64_t nodeWWN, portWWN;
FCOE_PORT_WWN pwwn, nwwn;
FCOE_UINT8 macLinkName[FCOE_MAX_MAC_NAME_LEN];
FCOE_UINT8 promiscuous = 0;
int createini = 0, createtgt = 0;
/* check the mac name operand */
assert(objects == 1);
strcpy((char *)macLinkName, argv[0]);
bzero(&pwwn, 8);
bzero(&nwwn, 8);
for (; options->optval; options++) {
switch (options->optval) {
case 'i':
createini = 1;
break;
case 't':
createtgt = 1;
break;
case 'p':
if (!isValidWWN(options->optarg)) {
fprintf(stderr,
gettext("Error: Invalid Port WWN\n"));
return (1);
}
sscanf(options->optarg, "%016llx", &portWWN);
portWWN = htonll(portWWN);
memcpy(&pwwn, &portWWN, sizeof (portWWN));
break;
case 'n':
if (!isValidWWN(options->optarg)) {
fprintf(stderr,
gettext("Error: Invalid Node WWN\n"));
return (1);
}
sscanf(options->optarg, "%016llx", &nodeWWN);
nodeWWN = htonll(nodeWWN);
memcpy(&nwwn, &nodeWWN, sizeof (nodeWWN));
break;
case 'f':
promiscuous = 1;
break;
default:
fprintf(stderr, gettext("Error: Illegal option: %c\n"),
options->optval);
return (1);
}
}
if (createini == 1 && createtgt == 1) {
fprintf(stderr, "Error: Option -i and -t should "
"not be both specified\n");
return (1);
}
status = FCOE_CreatePort(macLinkName,
createtgt == 1 ? FCOE_PORTTYPE_TARGET :
FCOE_PORTTYPE_INITIATOR, pwwn, nwwn, promiscuous);
if (status != FCOE_STATUS_OK) {
switch (status) {
case FCOE_STATUS_ERROR_BUSY:
fprintf(stderr,
gettext("Error: fcoe driver is busy\n"));
break;
case FCOE_STATUS_ERROR_ALREADY:
fprintf(stderr,
gettext("Error: Existing FCoE port "
"found on the specified MAC link\n"));
break;
case FCOE_STATUS_ERROR_PERM:
fprintf(stderr,
gettext("Error: Not enough permission to "
"open fcoe device\n"));
break;
case FCOE_STATUS_ERROR_OPEN_DEV:
fprintf(stderr,
gettext("Error: Failed to open fcoe device\n"));
break;
case FCOE_STATUS_ERROR_WWN_SAME:
fprintf(stderr,
gettext("Error: Port WWN is same as Node "
"WWN\n"));
break;
case FCOE_STATUS_ERROR_MAC_LEN:
fprintf(stderr,
gettext("Error: MAC name exceeds maximum "
"length\n"));
break;
case FCOE_STATUS_ERROR_PWWN_CONFLICTED:
fprintf(stderr,
gettext("Error: The specified Port WWN "
"is already in use\n"));
break;
case FCOE_STATUS_ERROR_NWWN_CONFLICTED:
fprintf(stderr,
gettext("Error: The specified Node WWN "
"is already in use\n"));
break;
case FCOE_STATUS_ERROR_NEED_JUMBO_FRAME:
fprintf(stderr,
gettext("Error: MTU size of the specified "
"MAC link needs to be increased to 2500 "
"or above\n"));
break;
case FCOE_STATUS_ERROR_CREATE_MAC:
fprintf(stderr,
gettext("Error: Out of memory\n"));
break;
case FCOE_STATUS_ERROR_OPEN_MAC:
fprintf(stderr,
gettext("Error: Failed to open the "
"specified MAC link\n"));
break;
case FCOE_STATUS_ERROR_CREATE_PORT:
fprintf(stderr,
gettext("Error: Failed to create FCoE "
"port on the specified MAC link\n"));
break;
case FCOE_STATUS_ERROR_CLASS_UNSUPPORT:
fprintf(stderr,
gettext("Error: Link class other than physical "
"link is not supported\n"));
break;
case FCOE_STATUS_ERROR_GET_LINKINFO:
fprintf(stderr,
gettext("Error: Failed to get link information "
"for %s\n"), macLinkName);
break;
case FCOE_STATUS_ERROR:
default:
fprintf(stderr,
gettext("Error: Due to reason code %d\n"), status);
}
return (1);
} else {
return (0);
}
}
int
fcoe_adm_delete_port(int objects, char *argv[])
{
FCOE_STATUS status;
FCOE_UINT8 *macLinkName;
FCOE_UINT32 port_num;
FCOE_PORT_ATTRIBUTE *portlist = NULL;
int i;
/* check the mac name operand */
assert(objects == 1);
macLinkName = (FCOE_UINT8 *) argv[0];
status = FCOE_DeletePort(macLinkName);
if (status != FCOE_STATUS_OK) {
switch (status) {
case FCOE_STATUS_ERROR_BUSY:
fprintf(stderr,
gettext("Error: fcoe driver is busy\n"));
break;
case FCOE_STATUS_ERROR_ALREADY:
fprintf(stderr,
gettext("Error: FCoE port not found on the "
"specified MAC link\n"));
break;
case FCOE_STATUS_ERROR_PERM:
fprintf(stderr,
gettext("Error: Not enough permission to "
"open fcoe device\n"));
break;
case FCOE_STATUS_ERROR_MAC_LEN:
fprintf(stderr,
gettext("Failed: MAC name exceeds maximum "
"length 32\n"));
break;
case FCOE_STATUS_ERROR_OPEN_DEV:
fprintf(stderr,
gettext("Error: Failed to open fcoe device\n"));
break;
case FCOE_STATUS_ERROR_MAC_NOT_FOUND:
fprintf(stderr,
gettext("Error: FCoE port not found on the "
"specified MAC link\n"));
break;
case FCOE_STATUS_ERROR_OFFLINE_DEV:
status = FCOE_GetPortList(&port_num, &portlist);
if (status != FCOE_STATUS_OK || port_num == 0) {
fprintf(stderr,
gettext("Error: FCoE port not found on the "
"specified MAC link\n"));
break;
}
for (i = 0; i < port_num; i++) {
if (strcmp(
(char *)portlist[i].mac_link_name,
(char *)macLinkName) == 0) {
if (portlist[i].port_type ==
FCOE_PORTTYPE_TARGET) {
fprintf(stderr,
gettext("Error: Please use "
"stmfadm to offline the "
"FCoE target first\n"));
} else {
fprintf(stderr,
gettext("Error: Failed to "
"delete FCoE port because "
"unable to offline the "
"device\n"));
}
break;
}
}
free(portlist);
if (i == port_num) {
fprintf(stderr,
gettext("Error: FCoE port not found on the "
"specified MAC link\n"));
}
break;
case FCOE_STATUS_ERROR_GET_LINKINFO:
fprintf(stderr,
gettext("Error: Failed to get link information "
"for %s\n"), macLinkName);
break;
case FCOE_STATUS_ERROR:
default:
fprintf(stderr,
gettext("Error: Due to reason code %d\n"), status);
}
return (1);
} else {
return (0);
}
}
int
fcoe_adm_list_ports(cmdOptions_t *options)
{
FCOE_STATUS status;
int showini = 0, showtgt = 0;
FCOE_UINT32 port_num;
FCOE_PORT_ATTRIBUTE *portlist = NULL;
int i;
int ret;
for (; options->optval; options++) {
switch (options->optval) {
case 'i':
showini = 1;
break;
case 't':
showtgt = 1;
break;
default:
fprintf(stderr, gettext("Error: Illegal option: %c\n"),
options->optval);
return (1);
}
}
if (showini == 0 && showtgt == 0) {
showini = 1;
showtgt = 1;
}
status = FCOE_GetPortList(&port_num, &portlist);
if (status != FCOE_STATUS_OK) {
switch (status) {
case FCOE_STATUS_ERROR_BUSY:
fprintf(stderr,
gettext("Error: fcoe driver is busy\n"));
break;
case FCOE_STATUS_ERROR_PERM:
fprintf(stderr,
gettext("Error: Not enough permission to "
"open fcoe device\n"));
break;
case FCOE_STATUS_ERROR_OPEN_DEV:
fprintf(stderr,
gettext("Error: Failed to open fcoe device\n"));
break;
case FCOE_STATUS_ERROR_INVAL_ARG:
fprintf(stderr,
gettext("Error: Invalid argument\n"));
break;
case FCOE_STATUS_ERROR_MORE_DATA:
fprintf(stderr,
gettext("Error: More data\n"));
break;
case FCOE_STATUS_ERROR:
default:
fprintf(stderr,
gettext("Error: Due to reason code %d\n"), status);
}
ret = 1;
} else {
if (port_num == 0) {
fprintf(stdout, gettext("No FCoE Ports Found!\n"));
} else {
for (i = 0; i < port_num; i++) {
if ((portlist[i].port_type ==
FCOE_PORTTYPE_INITIATOR &&
showini == 1) || (showtgt == 1 &&
portlist[i].port_type ==
FCOE_PORTTYPE_TARGET)) {
printFCOEPortInfo(&portlist[i]);
}
}
}
ret = 0;
}
if (portlist != NULL) {
free(portlist);
}
return (ret);
}
|