|
root / base / usr / src / lib / libfcoe
libfcoe Plain Text 1328 lines 31.2 KB
   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
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
#
# 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 ../Makefile.lib

# Hammerhead: amd64-only
SUBDIRS = $(MACH64)

all :		TARGET= all
clean :	TARGET= clean
clobber :	TARGET= clobber
install :	TARGET= install
install_h :	TARGET= install_h


HDRS=		libfcoe.h
HDRDIR=         common

.KEEP_STATE:

all clean clobber install: $(SUBDIRS)

install_h: $(ROOTHDRS)

check: $(CHECKHDRS)

$(SUBDIRS): FRC
	@cd $@; pwd; $(MAKE) $(TARGET)

FRC:

include ../Makefile.targ
#
# 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.
#

LIBRARY= libfcoe.a
VERS= .1

OBJECTS= libfcoe.o

include ../../Makefile.lib

LIBS=	$(DYNLIB)

SRCDIR =	../common

INCS +=		-I$(SRCDIR)
INCS +=		-I$(SRC)/uts/common/sys/fcoe

LDLIBS +=	-lc -ldladm -lscf
CSTD=	$(CSTD_GNU99)
CPPFLAGS +=	$(INCS) -D_REENTRANT

.KEEP_STATE:

all: $(LIBS)


include ../../Makefile.targ
#
# 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 ../Makefile.com
include ../../Makefile.lib.64

all: $(LIBS)

install: all $(ROOTLIBS64) $(ROOTLINKS64)
/*
 * 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 <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <libintl.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <syslog.h>
#include <libfcoe.h>
#include <libdllink.h>
#include <fcoeio.h>
#include <libscf.h>
#include <inttypes.h>

#define	FCOE_DEV_PATH	 "/devices/fcoe:admin"

#define	OPEN_FCOE 0
#define	OPEN_EXCL_FCOE O_EXCL

/*
 * Open for fcoe module
 *
 * flag - open flag (OPEN_FCOE, OPEN_EXCL_FCOE)
 * fd - pointer to integer. On success, contains the fcoe file descriptor
 */
static int
openFcoe(int flag, int *fd)
{
	int ret = FCOE_STATUS_ERROR;

	if ((*fd = open(FCOE_DEV_PATH, O_NDELAY | O_RDONLY | flag)) != -1) {
		ret = FCOE_STATUS_OK;
	} else {
		if (errno == EPERM || errno == EACCES) {
			ret = FCOE_STATUS_ERROR_PERM;
		} else {
			ret = FCOE_STATUS_ERROR_OPEN_DEV;
		}
		syslog(LOG_DEBUG, "openFcoe:open failure:%s:errno(%d)",
		    FCOE_DEV_PATH, errno);
	}

	return (ret);
}

static void
WWN2str(char *buf, FCOE_PORT_WWN *wwn)
{
	int j;
	unsigned char *pc = (unsigned char *)&(wwn->wwn[0]);
	buf[0] = '\0';
	for (j = 0; j < 16; j += 2) {
		(void) sprintf(&buf[j], "%02X", (int)*pc++);
	}
}

static int
isWWNZero(FCOE_PORT_WWN portwwn)
{
	int i;
	int size = sizeof (FCOE_PORT_WWN);

	for (i = 0; i < size; i++) {
		if (portwwn.wwn[i] != 0) {
			return (0);
		}
	}
	return (1);
}

/*
 * Initialize scf fcoe service access
 * handle - returned handle
 * service - returned service handle
 */
static int
fcoe_cfg_scf_init(scf_handle_t **handle, scf_service_t **service, int is_target)
{
	scf_scope_t	*scope = NULL;
	int		ret;

	if ((*handle = scf_handle_create(SCF_VERSION)) == NULL) {
		syslog(LOG_ERR, "scf_handle_create failed - %s",
		    scf_strerror(scf_error()));
		ret = FCOE_ERROR;
		goto err;
	}

	if (scf_handle_bind(*handle) == -1) {
		syslog(LOG_ERR, "scf_handle_bind failed - %s",
		    scf_strerror(scf_error()));
		ret = FCOE_ERROR;
		goto err;
	}

	if ((*service = scf_service_create(*handle)) == NULL) {
		syslog(LOG_ERR, "scf_service_create failed - %s",
		    scf_strerror(scf_error()));
		ret = FCOE_ERROR;
		goto err;
	}

	if ((scope = scf_scope_create(*handle)) == NULL) {
		syslog(LOG_ERR, "scf_scope_create failed - %s",
		    scf_strerror(scf_error()));
		ret = FCOE_ERROR;
		goto err;
	}

	if (scf_handle_get_scope(*handle, SCF_SCOPE_LOCAL, scope) == -1) {
		syslog(LOG_ERR, "scf_handle_get_scope failed - %s",
		    scf_strerror(scf_error()));
		ret = FCOE_ERROR;
		goto err;
	}

	if (scf_scope_get_service(scope,
	    is_target ? FCOE_TARGET_SERVICE: FCOE_INITIATOR_SERVICE,
	    *service) == -1) {
		syslog(LOG_ERR, "scf_scope_get_service failed - %s",
		    scf_strerror(scf_error()));
		ret = FCOE_ERROR_SERVICE_NOT_FOUND;
		goto err;
	}

	scf_scope_destroy(scope);

	return (FCOE_SUCCESS);

err:
	if (*handle != NULL) {
		scf_handle_destroy(*handle);
	}
	if (*service != NULL) {
		scf_service_destroy(*service);
		*service = NULL;
	}
	if (scope != NULL) {
		scf_scope_destroy(scope);
	}
	return (ret);
}

static int
fcoe_add_remove_scf_entry(char *mac_name,
    char *pwwn, char *nwwn,
    int is_target, int is_promiscuous, int addRemoveFlag)
{
	scf_handle_t	*handle = NULL;
	scf_service_t	*svc = NULL;
	scf_propertygroup_t	*pg = NULL;
	scf_transaction_t	*tran = NULL;
	scf_transaction_entry_t	*entry = NULL;
	scf_property_t	*prop = NULL;
	scf_value_t	*valueLookup = NULL;
	scf_iter_t	*valueIter = NULL;
	scf_value_t	**valueSet = NULL;
	int	ret = FCOE_SUCCESS;
	boolean_t	createProp = B_FALSE;
	int	lastAlloc = 0;
	char	buf[FCOE_PORT_LIST_LENGTH] = {0};
	char	memberName[FCOE_PORT_LIST_LENGTH] = {0};
	boolean_t	found = B_FALSE;
	int	i = 0;
	int	valueArraySize = 0;
	int	commitRet;
	int portListAlloc = 100;

	(void) snprintf(memberName, FCOE_PORT_LIST_LENGTH,
	    "%s:%s:%s:%d:%d", mac_name, pwwn, nwwn,
	    is_target, is_promiscuous);

	ret = fcoe_cfg_scf_init(&handle, &svc, is_target);
	if (ret != FCOE_SUCCESS) {
		goto out;
	}

	if (((pg = scf_pg_create(handle)) == NULL) ||
	    ((tran = scf_transaction_create(handle)) == NULL) ||
	    ((entry = scf_entry_create(handle)) == NULL) ||
	    ((prop = scf_property_create(handle)) == NULL) ||
	    ((valueIter = scf_iter_create(handle)) == NULL)) {
		ret = FCOE_ERROR;
		goto out;
	}

	/* get property group or create it */
	if (scf_service_get_pg(svc, FCOE_PG_NAME, pg) == -1) {
		if ((scf_error() == SCF_ERROR_NOT_FOUND)) {
			if (scf_service_add_pg(svc, FCOE_PG_NAME,
			    SCF_GROUP_APPLICATION, 0, pg) == -1) {
				syslog(LOG_ERR, "add pg failed - %s",
				    scf_strerror(scf_error()));
				ret = FCOE_ERROR;
			} else {
				createProp = B_TRUE;
			}
		} else {
			syslog(LOG_ERR, "get pg failed - %s",
			    scf_strerror(scf_error()));
			ret = FCOE_ERROR;
		}
		if (ret != FCOE_SUCCESS) {
			goto out;
		}
	}

	/* to make sure property exists */
	if (createProp == B_FALSE) {
		if (scf_pg_get_property(pg, FCOE_PORT_LIST, prop) == -1) {
			if ((scf_error() == SCF_ERROR_NOT_FOUND)) {
				createProp = B_TRUE;
			} else {
				syslog(LOG_ERR, "get property failed - %s",
				    scf_strerror(scf_error()));
				ret = FCOE_ERROR;
				goto out;
			}
		}
	}

	/* Begin the transaction */
	if (scf_transaction_start(tran, pg) == -1) {
		syslog(LOG_ERR, "start transaction failed - %s",
		    scf_strerror(scf_error()));
		ret = FCOE_ERROR;
		goto out;
	}

	valueSet = (scf_value_t **)calloc(1, sizeof (*valueSet)
	    * (lastAlloc = portListAlloc));
	if (valueSet == NULL) {
		ret = FCOE_ERROR_NOMEM;
		goto out;
	}

	if (createProp) {
		if (scf_transaction_property_new(tran, entry, FCOE_PORT_LIST,
		    SCF_TYPE_USTRING) == -1) {
			if (scf_error() == SCF_ERROR_EXISTS) {
				ret = FCOE_ERROR_EXISTS;
			} else {
				syslog(LOG_ERR,
				    "transaction property new failed - %s",
				    scf_strerror(scf_error()));
				ret = FCOE_ERROR;
			}
			goto out;
		}
	} else {
		if (scf_transaction_property_change(tran, entry,
		    FCOE_PORT_LIST, SCF_TYPE_USTRING) == -1) {
			syslog(LOG_ERR,
			    "transaction property change failed - %s",
			    scf_strerror(scf_error()));
			ret = FCOE_ERROR;
			goto out;
		}

		if (scf_pg_get_property(pg, FCOE_PORT_LIST, prop) == -1) {
			syslog(LOG_ERR, "get property failed - %s",
			    scf_strerror(scf_error()));
			ret = FCOE_ERROR;
			goto out;
		}

		valueLookup = scf_value_create(handle);
		if (valueLookup == NULL) {
			syslog(LOG_ERR, "scf value alloc failed - %s",
			    scf_strerror(scf_error()));
			ret = FCOE_ERROR;
			goto out;
		}

		if (scf_iter_property_values(valueIter, prop) == -1) {
			syslog(LOG_ERR, "iter value failed - %s",
			    scf_strerror(scf_error()));
			ret = FCOE_ERROR;
			goto out;
		}

		while (scf_iter_next_value(valueIter, valueLookup) == 1) {
			char *macnameIter = NULL;
			char buftmp[FCOE_PORT_LIST_LENGTH] = {0};

			bzero(buf, sizeof (buf));
			if (scf_value_get_ustring(valueLookup,
			    buf, MAXNAMELEN) == -1) {
				syslog(LOG_ERR, "iter value failed- %s",
				    scf_strerror(scf_error()));
				ret = FCOE_ERROR;
				break;
			}
			(void) strcpy(buftmp, buf);
			macnameIter = strtok(buftmp, ":");
			if (strcmp(macnameIter, mac_name) == 0) {
				if (addRemoveFlag == FCOE_SCF_ADD) {
					ret = FCOE_ERROR_EXISTS;
					break;
				} else {
					found = B_TRUE;
					continue;
				}
			}

			valueSet[i] = scf_value_create(handle);
			if (valueSet[i] == NULL) {
				syslog(LOG_ERR, "scf value alloc failed - %s",
				    scf_strerror(scf_error()));
				ret = FCOE_ERROR;
				break;
			}

			if (scf_value_set_ustring(valueSet[i], buf) == -1) {
				syslog(LOG_ERR, "set value failed 1- %s",
				    scf_strerror(scf_error()));
				ret = FCOE_ERROR;
				break;
			}

			if (scf_entry_add_value(entry, valueSet[i]) == -1) {
				syslog(LOG_ERR, "add value failed - %s",
				    scf_strerror(scf_error()));
				ret = FCOE_ERROR;
				break;
			}

			i++;

			if (i >= lastAlloc) {
				lastAlloc += portListAlloc;
				valueSet = realloc(valueSet,
				    sizeof (*valueSet) * lastAlloc);
				if (valueSet == NULL) {
					ret = FCOE_ERROR;
					break;
				}
			}
		}
	}

	valueArraySize = i;
	if (!found && (addRemoveFlag == FCOE_SCF_REMOVE)) {
		ret = FCOE_ERROR_MEMBER_NOT_FOUND;
	}
	if (ret != FCOE_SUCCESS) {
		goto out;
	}

	if (addRemoveFlag == FCOE_SCF_ADD) {
		/*
		 * Now create the new entry
		 */
		valueSet[i] = scf_value_create(handle);
		if (valueSet[i] == NULL) {
			syslog(LOG_ERR, "scf value alloc failed - %s",
			    scf_strerror(scf_error()));
			ret = FCOE_ERROR;
			goto out;
		} else {
			valueArraySize++;
		}

		/*
		 * Set the new member name
		 */
		if (scf_value_set_ustring(valueSet[i], memberName) == -1) {
			syslog(LOG_ERR, "set value failed 2- %s",
			    scf_strerror(scf_error()));
			ret = FCOE_ERROR;
			goto out;
		}

		/*
		 * Add the new member
		 */
		if (scf_entry_add_value(entry, valueSet[i]) == -1) {
			syslog(LOG_ERR, "add value failed - %s",
			    scf_strerror(scf_error()));
			ret = FCOE_ERROR;
			goto out;
		}
	}

	if ((commitRet = scf_transaction_commit(tran)) != 1) {
		syslog(LOG_ERR, "transaction commit failed - %s",
		    scf_strerror(scf_error()));
		if (commitRet == 0) {
			ret = FCOE_ERROR_BUSY;
		} else {
			ret = FCOE_ERROR;
		}
		goto out;
	}

out:
	/*
	 * Free resources
	 */
	if (handle != NULL) {
		scf_handle_destroy(handle);
	}
	if (svc != NULL) {
		scf_service_destroy(svc);
	}
	if (pg != NULL) {
		scf_pg_destroy(pg);
	}
	if (tran != NULL) {
		scf_transaction_destroy(tran);
	}
	if (entry != NULL) {
		scf_entry_destroy(entry);
	}
	if (prop != NULL) {
		scf_property_destroy(prop);
	}
	if (valueIter != NULL) {
		scf_iter_destroy(valueIter);
	}
	if (valueLookup != NULL) {
		scf_value_destroy(valueLookup);
	}

	/*
	 * Free valueSet scf resources
	 */
	if (valueArraySize > 0) {
		for (i = 0; i < valueArraySize; i++) {
			scf_value_destroy(valueSet[i]);
		}
	}
	/*
	 * Now free the pointer array to the resources
	 */
	if (valueSet != NULL) {
		free(valueSet);
	}

	return (ret);
}

FCOE_STATUS
FCOE_CreatePort(
	const FCOE_UINT8		*macLinkName,
	FCOE_UINT8		portType,
	FCOE_PORT_WWN		pwwn,
	FCOE_PORT_WWN		nwwn,
	FCOE_UINT8		promiscuous)
{
	FCOE_STATUS		status;
	int			fcoe_fd;
	fcoeio_t		fcoeio;
	fcoeio_create_port_param_t	param;
	dladm_handle_t		handle;
	datalink_id_t		linkid;
	datalink_class_t	class;

	bzero(&param, sizeof (fcoeio_create_port_param_t));

	if (macLinkName == NULL) {
		return (FCOE_STATUS_ERROR_INVAL_ARG);
	}

	if (strlen((char *)macLinkName) > MAXLINKNAMELEN-1) {
		return (FCOE_STATUS_ERROR_MAC_LEN);
	}

	if (dladm_open(&handle) != DLADM_STATUS_OK) {
		return (FCOE_STATUS_ERROR);
	}

	if (dladm_name2info(handle, (const char *)macLinkName,
	    &linkid, NULL, &class, NULL) != DLADM_STATUS_OK) {
		dladm_close(handle);
		(void) fcoe_add_remove_scf_entry((char *)macLinkName,
		    "",
		    "",
		    portType,
		    0,
		    FCOE_SCF_REMOVE);
		return (FCOE_STATUS_ERROR_GET_LINKINFO);
	}
	dladm_close(handle);

	if (class != DATALINK_CLASS_PHYS) {
		return (FCOE_STATUS_ERROR_CLASS_UNSUPPORT);
	}

	if (portType != FCOE_PORTTYPE_INITIATOR &&
	    portType != FCOE_PORTTYPE_TARGET) {
		return (FCOE_STATUS_ERROR_INVAL_ARG);
	}

	if (!isWWNZero(pwwn)) {
		param.fcp_pwwn_provided = 1;
		bcopy(pwwn.wwn, param.fcp_pwwn, 8);
	}

	if (!isWWNZero(nwwn)) {
		param.fcp_nwwn_provided = 1;
		bcopy(nwwn.wwn, param.fcp_nwwn, 8);
	}

	if (param.fcp_pwwn_provided == 1 &&
	    param.fcp_nwwn_provided == 1 &&
	    bcmp(&pwwn, &nwwn, 8) == 0) {
		return (FCOE_STATUS_ERROR_WWN_SAME);
	}

	param.fcp_force_promisc = promiscuous;
	param.fcp_mac_linkid = linkid;
	param.fcp_port_type = (fcoe_cli_type_t)portType;

	if ((status = openFcoe(OPEN_FCOE, &fcoe_fd)) != FCOE_STATUS_OK) {
		return (status);
	}

	(void) memset(&fcoeio, 0, sizeof (fcoeio));
	fcoeio.fcoeio_cmd = FCOEIO_CREATE_FCOE_PORT;

	fcoeio.fcoeio_ilen = sizeof (param);
	fcoeio.fcoeio_xfer = FCOEIO_XFER_WRITE;
	fcoeio.fcoeio_ibuf = (uintptr_t)&param;

	if (ioctl(fcoe_fd, FCOEIO_CMD, &fcoeio) != 0) {
		switch (fcoeio.fcoeio_status) {
		case FCOEIOE_INVAL_ARG:
			status = FCOE_STATUS_ERROR_INVAL_ARG;
			break;

		case FCOEIOE_BUSY:
			status = FCOE_STATUS_ERROR_BUSY;
			break;

		case FCOEIOE_ALREADY:
			status = FCOE_STATUS_ERROR_ALREADY;
			break;

		case FCOEIOE_PWWN_CONFLICTED:
			status = FCOE_STATUS_ERROR_PWWN_CONFLICTED;
			break;

		case FCOEIOE_NWWN_CONFLICTED:
			status = FCOE_STATUS_ERROR_NWWN_CONFLICTED;
			break;

		case FCOEIOE_CREATE_MAC:
			status = FCOE_STATUS_ERROR_CREATE_MAC;
			break;

		case FCOEIOE_OPEN_MAC:
			status = FCOE_STATUS_ERROR_OPEN_MAC;
			break;

		case FCOEIOE_CREATE_PORT:
			status = FCOE_STATUS_ERROR_CREATE_PORT;
			break;

		case FCOEIOE_NEED_JUMBO_FRAME:
			status = FCOE_STATUS_ERROR_NEED_JUMBO_FRAME;
			break;

		default:
			status = FCOE_STATUS_ERROR;
		}
	} else {
		char cpwwn[17], cnwwn[17];

		WWN2str(cpwwn, &pwwn);
		WWN2str(cnwwn, &nwwn);

		(void) fcoe_add_remove_scf_entry((char *)macLinkName,
		    cpwwn,
		    cnwwn,
		    portType,
		    promiscuous,
		    FCOE_SCF_ADD);
		status = FCOE_STATUS_OK;
	}
	(void) close(fcoe_fd);
	return (status);
}

FCOE_STATUS
FCOE_DeletePort(const FCOE_UINT8 *macLinkName)
{
	FCOE_STATUS status = FCOE_STATUS_OK;
	int fcoe_fd;
	fcoeio_t	fcoeio;
	dladm_handle_t		handle;
	datalink_id_t		linkid;
	fcoeio_delete_port_param_t fc_del_port;
	uint64_t	is_target = 0;
	int		io_ret = 0;

	if (macLinkName == NULL) {
		return (FCOE_STATUS_ERROR_INVAL_ARG);
	}

	if (strlen((char *)macLinkName) > MAXLINKNAMELEN-1) {
		return (FCOE_STATUS_ERROR_MAC_LEN);
	}
	if (dladm_open(&handle) != DLADM_STATUS_OK) {
		return (FCOE_STATUS_ERROR);
	}

	if (dladm_name2info(handle, (const char *)macLinkName,
	    &linkid, NULL, NULL, NULL) != DLADM_STATUS_OK) {
		dladm_close(handle);
		return (FCOE_STATUS_ERROR_GET_LINKINFO);
	}
	dladm_close(handle);

	if ((status = openFcoe(OPEN_FCOE, &fcoe_fd)) != FCOE_STATUS_OK) {
		return (status);
	}

	fc_del_port.fdp_mac_linkid = linkid;

	(void) memset(&fcoeio, 0, sizeof (fcoeio));
	fcoeio.fcoeio_cmd = FCOEIO_DELETE_FCOE_PORT;

	/* only 4 bytes here, need to change */
	fcoeio.fcoeio_ilen = sizeof (fcoeio_delete_port_param_t);
	fcoeio.fcoeio_olen = sizeof (uint64_t);
	fcoeio.fcoeio_xfer = FCOEIO_XFER_RW;
	fcoeio.fcoeio_ibuf = (uintptr_t)&fc_del_port;
	fcoeio.fcoeio_obuf = (uintptr_t)&is_target;

	io_ret = ioctl(fcoe_fd, FCOEIO_CMD, &fcoeio);
	if (io_ret != 0) {
		switch (fcoeio.fcoeio_status) {
		case FCOEIOE_INVAL_ARG:
			status = FCOE_STATUS_ERROR_INVAL_ARG;
			break;

		case FCOEIOE_BUSY:
			status = FCOE_STATUS_ERROR_BUSY;
			break;

		case FCOEIOE_ALREADY:
			status = FCOE_STATUS_ERROR_ALREADY;
			break;

		case FCOEIOE_MAC_NOT_FOUND:
			status = FCOE_STATUS_ERROR_MAC_NOT_FOUND;
			break;

		case FCOEIOE_OFFLINE_FAILURE:
			status = FCOE_STATUS_ERROR_OFFLINE_DEV;
			break;

		default:
			status = FCOE_STATUS_ERROR;
		}
	} else {
		(void) fcoe_add_remove_scf_entry((char *)macLinkName,
		    "",
		    "",
		    is_target,
		    0,
		    FCOE_SCF_REMOVE);
		status = FCOE_STATUS_OK;
	}

	if (io_ret == FCOEIOE_MAC_NOT_FOUND) {
		(void) fcoe_add_remove_scf_entry((char *)macLinkName,
		    "",
		    "",
		    0,
		    0,
		    FCOE_SCF_REMOVE);
		(void) fcoe_add_remove_scf_entry((char *)macLinkName,
		    "",
		    "",
		    1,
		    0,
		    FCOE_SCF_REMOVE);
	}
	(void) close(fcoe_fd);
	return (status);
}

FCOE_STATUS
FCOE_GetPortList(
	FCOE_UINT32		*port_num,
	FCOE_PORT_ATTRIBUTE	**portlist)
{
	FCOE_STATUS	status = FCOE_STATUS_OK;
	int		fcoe_fd;
	fcoeio_t	fcoeio;
	fcoe_port_list_t	*inportlist = NULL;
	FCOE_PORT_ATTRIBUTE	*outportlist = NULL;
	int		i;
	int		size = 64; /* default first attempt */
	int		retry = 0;
	int		bufsize;
	dladm_handle_t	handle;
	char		mac_name[MAXLINKNAMELEN];

	if (port_num == NULL || portlist == NULL) {
		return (FCOE_STATUS_ERROR_INVAL_ARG);
	}
	*port_num = 0;

	if ((status = openFcoe(OPEN_FCOE, &fcoe_fd)) != FCOE_STATUS_OK) {
		return (status);
	}

	/* Get fcoe port list */
	(void) memset(&fcoeio, 0, sizeof (fcoeio));
	retry = 0;

	do {
		bufsize = sizeof (fcoe_port_instance_t) * (size - 1) +
		    sizeof (fcoe_port_list_t);
		inportlist = (fcoe_port_list_t *)malloc(bufsize);
		fcoeio.fcoeio_cmd = FCOEIO_GET_FCOE_PORT_LIST;
		fcoeio.fcoeio_olen = bufsize;
		fcoeio.fcoeio_xfer = FCOEIO_XFER_READ;
		fcoeio.fcoeio_obuf = (uintptr_t)inportlist;

		if (ioctl(fcoe_fd, FCOEIO_CMD, &fcoeio) != 0) {
			if (fcoeio.fcoeio_status == FCOEIOE_MORE_DATA) {
				size = inportlist->numPorts;
			}
			free(inportlist);
			switch (fcoeio.fcoeio_status) {
			case FCOEIOE_INVAL_ARG:
				status = FCOE_STATUS_ERROR_INVAL_ARG;
				(void) close(fcoe_fd);
				return (status);

			case FCOEIOE_BUSY:
				status = FCOE_STATUS_ERROR_BUSY;
				retry++;
				break;

			case FCOEIOE_MORE_DATA:
				status = FCOE_STATUS_ERROR_MORE_DATA;
				retry++;
				break;

			default:
				status = FCOE_STATUS_ERROR;
				(void) close(fcoe_fd);
				return (status);
			}
		} else {
			status = FCOE_STATUS_OK;
			break;
		}
	} while (retry <= 3 && status != FCOE_STATUS_OK);

	if (status == FCOE_STATUS_OK && inportlist->numPorts > 0) {
		if (dladm_open(&handle) != DLADM_STATUS_OK) {
			handle = NULL;
		}

		outportlist = (PFCOE_PORT_ATTRIBUTE)
		    malloc(sizeof (FCOE_PORT_ATTRIBUTE) * inportlist->numPorts);

		for (i = 0; i < inportlist->numPorts; i++) {
			fcoe_port_instance_t *pi = &inportlist->ports[i];
			FCOE_PORT_ATTRIBUTE *po = &outportlist[i];
			bcopy(pi->fpi_pwwn, &po->port_wwn, 8);

			if (handle == NULL ||
			    dladm_datalink_id2info(handle, pi->fpi_mac_linkid,
			    NULL, NULL, NULL, mac_name, sizeof (mac_name))
			    != DLADM_STATUS_OK) {
				(void) strcpy((char *)po->mac_link_name,
				    "<unknown>");
			} else {
				(void) strcpy((char *)po->mac_link_name,
				    mac_name);
			}
			bcopy(pi->fpi_mac_factory_addr,
			    po->mac_factory_addr, 6);
			bcopy(pi->fpi_mac_current_addr,
			    po->mac_current_addr, 6);
			po->port_type = (FCOE_UINT8)pi->fpi_port_type;
			po->mtu_size = pi->fpi_mtu_size;
			po->mac_promisc = pi->fpi_mac_promisc;
		}

		if (handle != NULL) {
			dladm_close(handle);
		}
		*port_num = inportlist->numPorts;
		*portlist = outportlist;
		free(inportlist);
	} else {
		*port_num = 0;
		*portlist = NULL;
	}
	(void) close(fcoe_fd);
	return (status);
}

FCOE_STATUS FCOE_LoadConfig(
	FCOE_UINT8		portType,
    FCOE_SMF_PORT_LIST **portlist)
{
	scf_handle_t	*handle = NULL;
	scf_service_t	*svc = NULL;
	scf_propertygroup_t	*pg = NULL;
	scf_transaction_t	*tran = NULL;
	scf_transaction_entry_t	*entry = NULL;
	scf_property_t		*prop = NULL;
	scf_value_t	*valueLookup = NULL;
	scf_iter_t	*valueIter = NULL;
	char		buf[FCOE_PORT_LIST_LENGTH] = {0};
	int		commitRet;
	FCOE_UINT32	portIndex;
	int		bufsize, retry;
	int		size = 10; /* default first attempt */
	int		pg_or_prop_not_found = 0;

	commitRet = fcoe_cfg_scf_init(&handle, &svc, portType);
	if (commitRet != FCOE_SUCCESS) {
		goto out;
	}

	if (((pg = scf_pg_create(handle)) == NULL) ||
	    ((tran = scf_transaction_create(handle)) == NULL) ||
	    ((entry = scf_entry_create(handle)) == NULL) ||
	    ((prop = scf_property_create(handle)) == NULL) ||
	    ((valueIter = scf_iter_create(handle)) == NULL)) {
		goto out;
	}

	if (scf_service_get_pg(svc, FCOE_PG_NAME, pg) == -1) {
		pg_or_prop_not_found = 1;
		goto out;
	}

	if (scf_pg_get_property(pg, FCOE_PORT_LIST, prop) == -1) {
		pg_or_prop_not_found = 1;
		goto out;
	}

	valueLookup = scf_value_create(handle);
	if (valueLookup == NULL) {
		syslog(LOG_ERR, "scf value alloc failed - %s",
		    scf_strerror(scf_error()));
		goto out;
	}

	portIndex = 0;

	do {
		if (scf_iter_property_values(valueIter, prop) == -1) {
			syslog(LOG_ERR, "iter value failed - %s",
			    scf_strerror(scf_error()));
			goto out;
		}

		retry = 0;
		bufsize = sizeof (FCOE_SMF_PORT_INSTANCE) * (size - 1) +
		    sizeof (FCOE_SMF_PORT_LIST);
		*portlist = (PFCOE_SMF_PORT_LIST)malloc(bufsize);

		while (scf_iter_next_value(valueIter, valueLookup) == 1) {
			uint8_t *macLinkName = NULL;
			char *remainder = NULL;
			uint64_t	nodeWWN, portWWN;
			int is_target, is_promiscuous;

			bzero(buf, sizeof (buf));
			if (scf_value_get_ustring(valueLookup, buf,
			    MAXNAMELEN) == -1) {
				syslog(LOG_ERR, "iter value failed - %s",
				    scf_strerror(scf_error()));
				break;
			}
			macLinkName = (uint8_t *)strtok(buf, ":");
			remainder = strtok(NULL, "#");
			(void) sscanf(remainder,
			    "%016" PRIx64 ":%016" PRIx64 ":%d:%d",
			    &portWWN, &nodeWWN, &is_target, &is_promiscuous);

			if (portIndex >= size) {
				free(*portlist);
				retry = 1;
				size *= 2;
				break;
			} else {
				PFCOE_SMF_PORT_INSTANCE pi =
				    &(*portlist)->ports[portIndex++];
				(void) strcpy((char *)pi->mac_link_name,
				    (char *)macLinkName);
				pi->port_type = is_target ?
				    FCOE_PORTTYPE_TARGET:
				    FCOE_PORTTYPE_INITIATOR;
				portWWN = htonll(portWWN);
				nodeWWN = htonll(nodeWWN);
				(void) memcpy(&pi->port_pwwn, &portWWN,
				    sizeof (FCOE_PORT_WWN));
				(void) memcpy(&pi->port_nwwn, &nodeWWN,
				    sizeof (FCOE_PORT_WWN));
				pi->mac_promisc = is_promiscuous;
			}
		}

		(*portlist)->port_num = portIndex;
	} while (retry == 1);

	return (FCOE_STATUS_OK);
out:
	/*
	 * Free resources
	 */
	if (handle != NULL) {
		scf_handle_destroy(handle);
	}
	if (svc != NULL) {
		scf_service_destroy(svc);
	}
	if (pg != NULL) {
		scf_pg_destroy(pg);
	}
	if (tran != NULL) {
		scf_transaction_destroy(tran);
	}
	if (entry != NULL) {
		scf_entry_destroy(entry);
	}
	if (prop != NULL) {
		scf_property_destroy(prop);
	}
	if (valueIter != NULL) {
		scf_iter_destroy(valueIter);
	}
	if (valueLookup != NULL) {
		scf_value_destroy(valueLookup);
	}

	if (pg_or_prop_not_found == 1) {
		return (FCOE_STATUS_OK);
	} else {
		return (FCOE_STATUS_ERROR);
	}
}
/*
 * 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.
 */

#ifndef	_LIBFCOE_H
#define	_LIBFCOE_H

#include <time.h>
#include <wchar.h>
#include <sys/param.h>
#include <sys/ethernet.h>
#include <libnvpair.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * FCoE Port Type
 */
#define	FCOE_PORTTYPE_INITIATOR		0
#define	FCOE_PORTTYPE_TARGET		1

#define	FCOE_MAX_MAC_NAME_LEN		32

#define	FCOE_SCF_ADD		0
#define	FCOE_SCF_REMOVE		1

#define	FCOE_SUCCESS			0
#define	FCOE_ERROR			1
#define	FCOE_ERROR_EXISTS		2
#define	FCOE_ERROR_SERVICE_NOT_FOUND	3
#define	FCOE_ERROR_NOMEM		4
#define	FCOE_ERROR_MEMBER_NOT_FOUND	5
#define	FCOE_ERROR_BUSY			6

#define	FCOE_TARGET_SERVICE	"system/fcoe_target"
#define	FCOE_INITIATOR_SERVICE	"system/fcoe_initiator"
#define	FCOE_PG_NAME	"fcoe-port-list-pg"
#define	FCOE_PORT_LIST	"port_list_p"

#define	FCOE_PORT_LIST_LENGTH	255

typedef unsigned char	FCOE_UINT8;
typedef		 char	FCOE_INT8;
typedef unsigned short	FCOE_UINT16;
typedef		 short	FCOE_INT16;
typedef unsigned int	FCOE_UINT32;
typedef		 int	FCOE_INT32;

typedef unsigned int	FCOE_STATUS;

#define	FCOE_STATUS_OK				0
#define	FCOE_STATUS_ERROR			1
#define	FCOE_STATUS_ERROR_INVAL_ARG		2
#define	FCOE_STATUS_ERROR_BUSY			3
#define	FCOE_STATUS_ERROR_ALREADY		4
#define	FCOE_STATUS_ERROR_PERM			5
#define	FCOE_STATUS_ERROR_OPEN_DEV		6
#define	FCOE_STATUS_ERROR_WWN_SAME		7
#define	FCOE_STATUS_ERROR_MAC_LEN		8
#define	FCOE_STATUS_ERROR_PWWN_CONFLICTED	9
#define	FCOE_STATUS_ERROR_NWWN_CONFLICTED	10
#define	FCOE_STATUS_ERROR_NEED_JUMBO_FRAME	11
#define	FCOE_STATUS_ERROR_CREATE_MAC		12
#define	FCOE_STATUS_ERROR_OPEN_MAC		13
#define	FCOE_STATUS_ERROR_CREATE_PORT		14
#define	FCOE_STATUS_ERROR_MAC_NOT_FOUND		15
#define	FCOE_STATUS_ERROR_OFFLINE_DEV		16
#define	FCOE_STATUS_ERROR_MORE_DATA		17
#define	FCOE_STATUS_ERROR_CLASS_UNSUPPORT	18
#define	FCOE_STATUS_ERROR_GET_LINKINFO		19

typedef struct fcoe_port_wwn {
	uchar_t	wwn[8];
} FCOE_PORT_WWN, *PFCOE_PORT_WWN;

typedef struct fcoe_port_attr {
	FCOE_PORT_WWN	port_wwn;
	FCOE_UINT8	mac_link_name[MAXLINKNAMELEN];
	FCOE_UINT8	mac_factory_addr[ETHERADDRL];
	FCOE_UINT8	mac_current_addr[ETHERADDRL];
	FCOE_UINT8	port_type;
	FCOE_UINT32	mtu_size;
	FCOE_UINT8	mac_promisc;
} FCOE_PORT_ATTRIBUTE, *PFCOE_PORT_ATTRIBUTE;

/*
 * FCoE port instance in smf repository
 */
typedef struct fcoe_smf_port_instance {
	FCOE_UINT8	mac_link_name[MAXLINKNAMELEN];
	FCOE_UINT8	port_type;
	FCOE_PORT_WWN	port_pwwn;
	FCOE_PORT_WWN	port_nwwn;
	FCOE_UINT8	mac_promisc;
} FCOE_SMF_PORT_INSTANCE, *PFCOE_SMF_PORT_INSTANCE;

/*
 * FCoE port instance list
 */
typedef struct fcoe_smf_port_list {
	FCOE_UINT32	port_num;
	FCOE_SMF_PORT_INSTANCE	ports[1];
} FCOE_SMF_PORT_LIST, *PFCOE_SMF_PORT_LIST;

/*
 * macLinkName: mac name with maximum lenth 32
 * portType: 0 (Initiator)/ 1(Target)
 * pwwn: Port WWN
 * nwwn: Nodw WWN
 * promiscous: to enable promisc mode for mac interface
 */
FCOE_STATUS FCOE_CreatePort(
	const FCOE_UINT8	*macLinkName,	/* maximum len: 32 */
	FCOE_UINT8	portType,
	FCOE_PORT_WWN	pwwn,
	FCOE_PORT_WWN	nwwn,
	FCOE_UINT8	promiscusous
);

FCOE_STATUS FCOE_DeletePort(
    const FCOE_UINT8	*macLinkName
);

/*
 * Make sure to free the memory pointed by portlist
 */
FCOE_STATUS FCOE_GetPortList(
    FCOE_UINT32		*port_num,
    FCOE_PORT_ATTRIBUTE	**portlist
);

/*
 * Make sure to free the memory pointed by portlist
 */
FCOE_STATUS FCOE_LoadConfig(
    FCOE_UINT8		portType,
    FCOE_SMF_PORT_LIST **portlist
);

#ifdef	__cplusplus
}
#endif

#endif	/* _LIBFCOE_H */
#
# 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 (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
#

#
# MAPFILE HEADER START
#
# WARNING:  STOP NOW.  DO NOT MODIFY THIS FILE.
# Object versioning must comply with the rules detailed in
#
#	usr/src/lib/README.mapfiles
#
# You should not be making modifications here until you've read the most current
# copy of that file. If you need help, contact a gatekeeper for guidance.
#
# MAPFILE HEADER END
#

$mapfile_version 2

SYMBOL_VERSION SUNWprivate {
    global:
	FCOE_CreatePort;
	FCOE_DeletePort;
	FCOE_GetPortList;
	FCOE_LoadConfig;

    local:
	*;
};