-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvlib.c
1850 lines (1604 loc) · 54.9 KB
/
vlib.c
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
// SPDX-License-Identifier: EPL-1.0
/*
* Copyright IBM Corp. 2003,2010
*
* Authors: Andreas Herrmann
* Stefan Voelkel
* Sven Schuetz <[email protected]>
*
* File: vlib.c
*
* Description:
* This file contains the implementations of most HBA API library
* functions.
*
*/
/**
* @file vlib.c
* @brief Implementations of most HBA API functions (all except event handling
* functions).
* @note We only include vlib.h which in turn should include all other
* necessary header files.
*
* This file contains the implementations of most HBA API library
* functions. Implementations of event handling HBA API routines
* can be found in files vlib_events.c and vlib_callbacks.c.
* @see vlib_events.c vlib_callbacks.c
*/
#include "vlib.h"
/*
* GLOBAL VARIABLES
*/
struct vlib_data vlib_data;
/*
* STATIC FUNCTION DECLARATIONS
*/
/**
* @brief Internal function to report the attributes of the libary.
*/
static HBA_UINT32 _GetVendorLibraryAttributes(HBA_LIBRARYATTRIBUTES *);
/*
* LIBRARY CONTROL FUNCTIONS
*/
/** @ingroup SupportedHBAAPIs
* @brief Return the version of the HBA API specification with which this
* library is compliant.
* @return
* - 2 (compliant to FC-HBA)
* @note No check if library is loaded has to be performed.
*/
HBA_UINT32 HBA_GetVersion(void)
{
return HBAAPI_LIBRARY_VERSION;
}
/** @ingroup InitAndFini
* @brief Initialization function of this library.
*/
void _initvlib(void)
{
char *env;
pthread_mutexattr_t mutexattr;
pthread_mutexattr_init(&mutexattr);
#ifdef HBAAPI_BACKTRACE
pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_ERRORCHECK_NP);
#endif
memset(&vlib_data, 0, sizeof(vlib_data));
env = getenv(VLIB_ENV_LOG_LEVEL);
if (env != NULL)
vlib_data.loglevel = atoi(env);
vlib_data.errfp = stderr;
env = getenv(VLIB_ENV_LOG_FILE);
if (env != NULL) {
vlib_data.errfp = fopen(env, "a");
if (NULL == vlib_data.errfp) {
vlib_data.errfp = stderr;
VLIB_PERROR(errno, "WARNING: fopen() failed for log "
"file '%s'", env);
}
}
/* start logging */
if (vlib_data.loglevel > 0) {
char timestr[32];
time_t t;
t = time(NULL);
memset(×tr, 0, 32);
strftime(timestr, 32, "%b %d %T", localtime(&t));
VLIB_LOG("libzfcphbaapi.so loaded at %s\n", timestr);
}
pthread_mutex_init(&vlib_data.mutex, &mutexattr);
}
/** @ingroup InitAndFini
* @brief Finalization function of this library.
*/
void _finivlib(void)
{
if (vlib_data.errfp != stderr)
fclose(vlib_data.errfp);
pthread_mutex_destroy(&vlib_data.mutex);
}
/** @ingroup SupportedHBAAPIs
* @brief Perform initialization of library.
* @return
* - HBA_STATUS_ERROR_ALREADY_LOADED if this function was already called
* before.
* - HBA_STATUS_ERROR if initialization fails.
* - HBA_STATUS_OK on success.
* @par Locks:
* lock/unlock of vlib_data.mutex
* @note This function tries to open the zfcp_hbaapi char device.
*/
HBA_STATUS HBA_LoadLibrary(void)
{
HBA_STATUS status;
int ret;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
if (vlib_data.isLoaded) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR;
}
status = sysfs_createAndReadConfigAdapter();
if (status != HBA_STATUS_OK) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
vlib_data.isLoaded = 1;
start_event_thread();
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
/** @ingroup SupportedHBAAPIs
* @brief Free system resources that library has used.
* @return
* - HBA_STATUS_ERROR_NOT_LOADED if HBA_LoadLibrary was not called before.
* - HBA_STATUS_ERROR if HBA_FreeLibrary is already running.
* - HBA_STATUS_OK on success.
* @par Locks:
* lock/unlock of vlib_data.mutex
* @note This function tries to close the zfcp_hbaapi char device.
*/
HBA_STATUS HBA_FreeLibrary(void)
{
void *res;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
if (!vlib_data.isLoaded) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR;
}
if (vlib_data.unloading) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR;
}
vlib_data.unloading = 1;
if (pthread_cancel(vlib_data.id) != 0) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR;
}
if (pthread_join(vlib_data.id, &res) != 0) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR;
}
if (res != PTHREAD_CANCELED) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR;
}
closeAllAdapters();
vlib_data.isLoaded = 0;
vlib_data.unloading = 0;
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_OK;
}
#ifdef HBAAPI_VENDOR_LIB /* compile as vendor specific library */
/** @ingroup SupportedHBAAPIs
* @brief Register the functionality of FC-MI with the wrapper library.
* @param pHBAInfo entry points of HBA API phase 1 library functions
* @return HBA_STATUS_OK
* @note This function is only defined if this library was built as a
* vendor specific library.
*/
HBA_STATUS HBA_RegisterLibrary(HBA_ENTRYPOINTS *pHBAInfo)
{
memset(pHBAInfo, 0, sizeof(*pHBAInfo));
pHBAInfo->GetVersionHandler = HBA_GetVersion;
pHBAInfo->LoadLibraryHandler = HBA_LoadLibrary;
pHBAInfo->FreeLibraryHandler = HBA_FreeLibrary;
pHBAInfo->GetNumberOfAdaptersHandler = HBA_GetNumberOfAdapters;
pHBAInfo->GetAdapterNameHandler = HBA_GetAdapterName;
pHBAInfo->OpenAdapterHandler = HBA_OpenAdapter;
pHBAInfo->CloseAdapterHandler = HBA_CloseAdapter;
pHBAInfo->GetAdapterAttributesHandler = HBA_GetAdapterAttributes;
pHBAInfo->GetAdapterPortAttributesHandler =
HBA_GetAdapterPortAttributes;
pHBAInfo->GetPortStatisticsHandler = HBA_GetPortStatistics;
pHBAInfo->GetDiscoveredPortAttributesHandler =
HBA_GetDiscoveredPortAttributes;
pHBAInfo->GetPortAttributesByWWNHandler = HBA_GetPortAttributesByWWN;
pHBAInfo->SendCTPassThruHandler = HBA_SendCTPassThru;
pHBAInfo->RefreshInformationHandler = HBA_RefreshInformation;
pHBAInfo->ResetStatisticsHandler = HBA_ResetStatistics;
pHBAInfo->GetFcpTargetMappingHandler = HBA_GetFcpTargetMapping;
pHBAInfo->GetFcpPersistentBindingHandler = HBA_GetFcpPersistentBinding;
pHBAInfo->GetEventBufferHandler = HBA_GetEventBuffer;
pHBAInfo->SetRNIDMgmtInfoHandler = HBA_SetRNIDMgmtInfo;
pHBAInfo->GetRNIDMgmtInfoHandler = HBA_GetRNIDMgmtInfo;
pHBAInfo->SendRNIDHandler = HBA_SendRNID;
pHBAInfo->ScsiInquiryHandler = HBA_SendScsiInquiry;
pHBAInfo->ReportLUNsHandler = HBA_SendReportLUNs;
pHBAInfo->ReadCapacityHandler = HBA_SendReadCapacity;
return HBA_STATUS_OK;
}
/** @ingroup SupportedHBAAPIs
* @brief Register the functionality of HBA API phase 2 with the wrapper
* library.
* @param pHBAInfo entry points of HBA API phase 2 library functions
* @return HBA_STATUS_OK on success
* @note This function is only defined if this library was built as a
* vendor specific library.
*/
HBA_STATUS HBA_RegisterLibraryV2(HBA_ENTRYPOINTSV2 *pHBAInfo)
{
memset(pHBAInfo, 0, sizeof(*pHBAInfo));
pHBAInfo->GetVersionHandler = HBA_GetVersion;
pHBAInfo->LoadLibraryHandler = HBA_LoadLibrary;
pHBAInfo->FreeLibraryHandler = HBA_FreeLibrary;
pHBAInfo->GetNumberOfAdaptersHandler = HBA_GetNumberOfAdapters;
pHBAInfo->GetAdapterNameHandler = HBA_GetAdapterName;
pHBAInfo->OpenAdapterHandler = HBA_OpenAdapter;
pHBAInfo->CloseAdapterHandler = HBA_CloseAdapter;
pHBAInfo->GetAdapterAttributesHandler = HBA_GetAdapterAttributes;
pHBAInfo->GetAdapterPortAttributesHandler =
HBA_GetAdapterPortAttributes;
pHBAInfo->GetPortStatisticsHandler = HBA_GetPortStatistics;
pHBAInfo->GetDiscoveredPortAttributesHandler =
HBA_GetDiscoveredPortAttributes;
pHBAInfo->GetPortAttributesByWWNHandler = HBA_GetPortAttributesByWWN;
pHBAInfo->SendCTPassThruHandler = HBA_SendCTPassThru;
pHBAInfo->RefreshInformationHandler = HBA_RefreshInformation;
pHBAInfo->ResetStatisticsHandler = HBA_ResetStatistics;
pHBAInfo->GetFcpTargetMappingHandler = HBA_GetFcpTargetMapping;
pHBAInfo->GetFcpPersistentBindingHandler = HBA_GetFcpPersistentBinding;
pHBAInfo->GetEventBufferHandler = HBA_GetEventBuffer;
pHBAInfo->SetRNIDMgmtInfoHandler = HBA_SetRNIDMgmtInfo;
pHBAInfo->GetRNIDMgmtInfoHandler = HBA_GetRNIDMgmtInfo;
pHBAInfo->SendRNIDHandler = HBA_SendRNID;
pHBAInfo->ScsiInquiryHandler = HBA_SendScsiInquiry;
pHBAInfo->ReportLUNsHandler = HBA_SendReportLUNs;
pHBAInfo->ReadCapacityHandler = HBA_SendReadCapacity;
pHBAInfo->OpenAdapterByWWNHandler = HBA_OpenAdapterByWWN;
pHBAInfo->GetFcpTargetMappingV2Handler = HBA_GetFcpTargetMappingV2;
pHBAInfo->SendCTPassThruV2Handler = HBA_SendCTPassThruV2;
pHBAInfo->RefreshAdapterConfigurationHandler =
HBA_RefreshAdapterConfiguration;
pHBAInfo->GetBindingCapabilityHandler = HBA_GetBindingCapability;
pHBAInfo->GetBindingSupportHandler = HBA_GetBindingSupport;
pHBAInfo->SetBindingSupportHandler = HBA_SetBindingSupport;
pHBAInfo->SetPersistentBindingV2Handler = HBA_SetPersistentBindingV2;
pHBAInfo->GetPersistentBindingV2Handler = HBA_GetPersistentBindingV2;
pHBAInfo->RemovePersistentBindingHandler = HBA_RemovePersistentBinding;
pHBAInfo->RemoveAllPersistentBindingsHandler =
HBA_RemoveAllPersistentBindings;
pHBAInfo->SendRNIDV2Handler = HBA_SendRNIDV2;
pHBAInfo->ScsiInquiryV2Handler = HBA_ScsiInquiryV2;
pHBAInfo->ScsiReportLUNsV2Handler = HBA_ScsiReportLUNsV2;
pHBAInfo->ScsiReadCapacityV2Handler = HBA_ScsiReadCapacityV2;
pHBAInfo->GetVendorLibraryAttributesHandler =
_GetVendorLibraryAttributes;
pHBAInfo->RemoveCallbackHandler = HBA_RemoveCallback;
pHBAInfo->RegisterForAdapterAddEventsHandler =
HBA_RegisterForAdapterAddEvents;
pHBAInfo->RegisterForAdapterEventsHandler =
HBA_RegisterForAdapterEvents;
pHBAInfo->RegisterForAdapterPortEventsHandler =
HBA_RegisterForAdapterPortEvents;
pHBAInfo->RegisterForAdapterPortStatEventsHandler =
HBA_RegisterForAdapterPortStatEvents;
pHBAInfo->RegisterForTargetEventsHandler = HBA_RegisterForTargetEvents;
pHBAInfo->RegisterForLinkEventsHandler = HBA_RegisterForLinkEvents;
pHBAInfo->SendRPLHandler = HBA_SendRPL;
pHBAInfo->SendRPSHandler = HBA_SendRPS;
pHBAInfo->SendSRLHandler = HBA_SendSRL;
pHBAInfo->SendLIRRHandler = HBA_SendLIRR;
pHBAInfo->GetFC4StatisticsHandler = HBA_GetFC4Statistics;
pHBAInfo->GetFCPStatisticsHandler = HBA_GetFCPStatistics;
pHBAInfo->SendRLSHandler = HBA_SendRLS;
return HBA_STATUS_OK;
}
#endif /* HBAAPI_VENDOR_LIB */
#ifndef HBAAPI_VENDOR_LIB
/** @ingroup SupportedHBAAPIs
* @brief Return attributes of the OS specific HBA API library.
* @param attributes used to return library attributes
* @return
* - 2 (compliant to FC-HBA)
* @note This function is not defined if the library is built as a
* vendor specific library.
* @see _GetVendorLibraryAttributes()
*/
HBA_UINT32 HBA_GetWrapperLibraryAttributes(HBA_LIBRARYATTRIBUTES *attributes)
{
return _GetVendorLibraryAttributes(attributes);
}
/** @ingroup SupportedHBAAPIs
* @brief Return attributes of the vendor specific HBA API library.
* @param adapter_index not used
* @param attributes used to return library attributes
* @return
* - 2 (compliant to FC-HBA)
* @note This function is not defined if the library is built as a
* vendor specific library.
* @note The index of the HBA is ignored, because it is of use only for a
* wrapper library.
* @see _GetVendorLibraryAttributes()
*/
HBA_UINT32 HBA_GetVendorLibraryAttributes(HBA_UINT32 adapter_index,
HBA_LIBRARYATTRIBUTES *attributes)
{
return _GetVendorLibraryAttributes(attributes);
}
#endif
/**
* @param attributes used to return library attributes
* @return
* - 2 (compliant to FC-HBA)
*/
static HBA_UINT32 _GetVendorLibraryAttributes(HBA_LIBRARYATTRIBUTES *attributes)
{
memset(attributes, 0, sizeof(*attributes));
attributes->final = HBAAPI_LIBRARY_FINAL;
#ifndef VLIBPATH
# error "VLIBPATH not set"
#endif
strncpy(attributes->LibPath, VLIBPATH, 256);
strncpy(attributes->VName, "IBM Corp.", 256);
strncpy(attributes->VVersion, HBAAPI_LIBRARY_REVISION, 256);
strptime(__DATE__ " " __TIME__ , "%b %d %Y %T",
&attributes->build_date);
return HBAAPI_LIBRARY_VERSION;
}
/** @ingroup SupportedHBAAPIs
* @brief Return number of adapters.
* @return
* - 0 on error or if no adapters are configured
* - number of adapters on success
* @par Locks:
* lock/unlock of vlib_data.mutex
*/
HBA_UINT32 HBA_GetNumberOfAdapters(void)
{
HBA_UINT32 num;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
if (HBA_STATUS_OK != revalidateRepository())
num = 0;
else
num = vlib_data.adapters.used;
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return num;
}
/** @ingroup SupportedHBAAPIs
* @brief Refresh information of an adapter.
* @param handle of the adapter for which information should be refreshed.
* @par Locks:
* lock/unlock of vlib_data.mutex
*/
void HBA_RefreshInformation(HBA_HANDLE handle)
{
HBA_STATUS status;
struct vlib_adapter *adapter;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
adapter = getAdapterByHandle(handle, &status);
if (NULL == adapter) {
VLIB_LOG("ERROR: invalid adapter handle or "
"adapter unavailable\n");
} else {
updateAdapter(adapter);
}
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return;
}
#ifdef HBAAPI_VENDOR_LIB /* compile as vendor specific library */
/** @ingroup SupportedHBAAPIs
* @brief According to a discussion with Bob Nixon (editor of FC-HBA) this
* function has no effect in an HBA specific library.
*/
void HBA_RefreshAdapterConfiguration(void)
{
return;
}
#else
/** @ingroup SupportedHBAAPIs
* @brief Refresh information about configured adapters.
* @par Locks:
* lock/unlock of vlib_data.mutex
* @note We do not report HBA_STATUS_ERROR_STALE_DATA, because we use
* semistatic tables internally. We just make use of
* HBA_STATUS_ERROR_UNAVAILABLE (e.g. if an adapter is removed).
*/
void HBA_RefreshAdapterConfiguration(void)
{
VLIB_MUTEX_LOCK(&vlib_data.mutex);
revalidateRepository();
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
}
#endif
/** @ingroup SupportedHBAAPIs
* @brief According to FC-HBA this function is obsolete.
*
* This function has no effect.
*/
void HBA_ResetStatistics(HBA_HANDLE handle, HBA_UINT32 portindex)
{
return;
}
/*
* ADAPTER and PORT INFORMATION FUNCTIONS
*/
/** @ingroup SupportedHBAAPIs
* @brief Return name that identifies an adapter.
* @param adapterindex index of the HBA
* @param pAdaptername used to return the ASCII string
* @return
* - HBA_STATUS_NOT_LOADED if library is not loaded
* - HBA_STATUS_ERROR_ILLEGAL_INDEX if index is invalid
* - HBA_STATUS_ERROR if any other internal error occurs
* - HBA_STATUS_OK on success
* @par Locks:
* lock/unlock of vlib_data.mutex
* @see revalidateRepository()
*/
HBA_STATUS HBA_GetAdapterName(HBA_UINT32 adapterindex, char *pAdaptername)
{
HBA_STATUS status;
struct vlib_adapter *adapter;
*pAdaptername = '\0';
VLIB_MUTEX_LOCK(&vlib_data.mutex);
status = revalidateRepository();
if (HBA_STATUS_OK != status) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
adapter = getAdapterByIndex(adapterindex);
if (NULL == adapter) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR_ILLEGAL_INDEX;
}
if (adapter->isInvalid) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR_UNAVAILABLE;
}
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
snprintf(pAdaptername, VLIB_ADAPTERNAME_LEN, "%s%u",
VLIB_ADAPTERNAME_PREFIX, adapterindex);
return HBA_STATUS_OK;
}
/** @ingroup SupportedHBAAPIs
* @brief Open an adapter.
* @param pAdaptername name of adapter to be opened (name was obtained by
* previous call to HBA_GetAdapterName())
* @return
* - ::VLIB_INVALID_HANDLE on error
* - handle on success
* @par Locks:
* lock/unlock of vlib_data.mutex
* @note Possible (theoretical) overflow of index values.
*/
HBA_HANDLE HBA_OpenAdapter(char *pAdaptername)
{
HBA_STATUS status;
HBA_HANDLE handle;
int index;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
status = revalidateRepository();
if (HBA_STATUS_OK != status) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return VLIB_INVALID_HANDLE;
}
index = findIndexByName(pAdaptername);
if (-1 == index) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return VLIB_INVALID_HANDLE;
}
handle = openAdapterByIndex(index);
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return handle;
}
/** @ingroup UnSupportedHBAAPIs
* @return HBA_STATUS_ERROR_NOT_SUPPORTED
* @note This function is currently not supported.
*/
HBA_STATUS HBA_OpenAdapterByWWN(HBA_HANDLE *pHandle, HBA_WWN wwn)
{
/* note: wwn is either node name or port name of adapter */
return HBA_STATUS_ERROR_NOT_SUPPORTED;
}
/** @ingroup SupportedHBAAPIs
* @brief Close an open adapter.
* @param handle of adapter to be closed
* @par Locks:
* lock/unlock of vlib_data.mutex
*
* The adapter handle is invalidated and the information about the
* ports and units of this adapter is deleted.
*/
void HBA_CloseAdapter(HBA_HANDLE handle)
{
HBA_STATUS status;
struct vlib_adapter *adapter;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
adapter = getAdapterByHandle(handle, &status);
if (NULL == adapter) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return;
}
doCloseAdapter(adapter);
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return;
}
/** @ingroup SupportedHBAAPIs
* @brief Return attributes for an adapter.
* @param handle of an opened adapter
* @param pAdapterattributes pointer to return atributes
* @return
* - HBA_STATUS_NOT_LOADED if library is not loaded
* - HBA_STATUS_ERROR_INVALID_HANDLE if handle is invalid
* - HBA_STATUS_ERROR_UNAVAILABLE if adapter is unavailable
* - HBA_STATUS_ERROR if any other internal error occurs
* - HBA_STATUS_OK on success.
* @par Locks:
* lock/unlock of vlib_data.mutex
* @note ZFCP HBA API does not set the adapter attributes OptionROMVersion
* and NodeSymbolicName.
*/
HBA_STATUS HBA_GetAdapterAttributes(HBA_HANDLE handle,
HBA_ADAPTERATTRIBUTES *pAdapterattributes)
{
HBA_STATUS status;
int ret;
struct vlib_adapter *adapter;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
status = revalidateRepository();
if (HBA_STATUS_OK != status) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
adapter = getAdapterByHandle(handle, &status);
if (NULL == adapter) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
status = sysfs_getAdapterAttributes(&pAdapterattributes, adapter);
return status;
}
/** @ingroup SupportedHBAAPIs
* @brief Return attributes for an adapter port.
* @param handle to an opened adapter
* @param portindex index of adapter port
* @param pPortattributes pointer to return atributes
* @return
* - HBA_STATUS_NOT_LOADED if library is not loaded
* - HBA_STATUS_ERROR_INVALID_HANDLE if handle is invalid
* - HBA_STATUS_ERROR_UNAVAILABLE if adapter is unavailable
* - HBA_STATUS_ERROR_ILLEGAL_INDEX if portindex is invalid
* - HBA_STATUS_ERROR if any other internal error occurs
* - HBA_STATUS_OK on success.
* @par Locks:
* lock/unlock of vlib_data.mutex
* @note Parameter portindex _must_ be 0, since we have only one local port on
* our adapters.
* @note Additionally this function triggers creation of port configuration for
* this adapter (see revalidatePorts()).
* @note ZFCP HBA API does not set the port attributes FabricName,
* OSDeviceName and PortSymbolicName for an adapter port.
*/
HBA_STATUS HBA_GetAdapterPortAttributes(HBA_HANDLE handle,
HBA_UINT32 portindex,
HBA_PORTATTRIBUTES *pPortattributes)
{
HBA_STATUS status;
struct vlib_adapter *adapter;
int ret;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
status = revalidateRepository();
if (HBA_STATUS_OK != status) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
adapter = getAdapterByHandle(handle, &status);
if (NULL == adapter) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
if (portindex != 0) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR_ILLEGAL_INDEX;
}
if (revalidatePorts(adapter) < 0) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR;
}
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
status = sysfs_getAdapterPortAttributes(&pPortattributes, adapter);
return status;
}
/** @ingroup SupportedHBAAPIs
* @brief Return attributes of an discovered port.
* @param handle to an opened adapter
* @param portindex index of adapter port
* @param discoveredportindex index of adapter port
* @param pPortattributes pointer to return atributes
* @return
* - HBA_STATUS_NOT_LOADED if library is not loaded
* - HBA_STATUS_ERROR_INVALID_HANDLE if handle is invalid
* - HBA_STATUS_ERROR_UNAVAILABLE if adapter is unavailable
* - HBA_STATUS_ERROR_ILLEGAL_INDEX if portindex or discoveredindex
* is invalid
* - HBA_STATUS_ERROR if any other internal error occurs
* - HBA_STATUS_OK on success.
* @par Locks:
* lock/unlock of vlib_data.mutex
* @note Parameter portindex _must_ be 0, since we have only one local port on
* our adapters.
* @note For discovered ports ZFCP HBA API does not set the port attributes
* OSDeviceName, PortMaxFrameSize and PortSupportedFc4Types.
* PortSupportedSpeed, PortSpeed, and PortState are set to values
* indicating unknwon. NumberofDiscoveredPorts is 0.
* Most other values are determined using a GA_NXT request on the Name
* Server Directory Service.
* @note For PortSupportedFc4Types and PortActive Fc4Types we do not follow
* FC-HBA Rev 10. We do not store them "little-endian" but "big-endian" as
* it is suggested by Editors Note 1.
*/
HBA_STATUS HBA_GetDiscoveredPortAttributes(HBA_HANDLE handle,
HBA_UINT32 portindex,
HBA_UINT32 discoveredportindex,
HBA_PORTATTRIBUTES *pPortattributes)
{
HBA_STATUS status;
int ret;
struct vlib_adapter *adapter;
struct vlib_port *port;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
status = revalidateRepository();
if (HBA_STATUS_OK != status) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
adapter = getAdapterByHandle(handle, &status);
if (NULL == adapter) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
if (portindex != 0) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR_ILLEGAL_INDEX;
}
port = getPortByIndex(adapter, discoveredportindex);
if (NULL == port) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR_ILLEGAL_INDEX;
}
if (port->isInvalid) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR_UNAVAILABLE;
}
status = sysfs_getDiscoveredPortAttributes(&pPortattributes, port);
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
/** @ingroup UnSupportedHBAAPIs
* @return HBA_STATUS_ERROR_NOT_SUPPORTED
* @note This function is currently not supported.
*/
HBA_STATUS HBA_GetPortAttributesByWWN(HBA_HANDLE handle, HBA_WWN PortWWN,
HBA_PORTATTRIBUTES *pPortattributes)
{
return HBA_STATUS_ERROR_NOT_SUPPORTED;
}
/** @ingroup SupportedHBAAPIs
* @brief Return statistics of an adapter port
* @param handle to an opened adapter
* @param portindex index of adapter port
* @param pPortstatistics pointer to return statistics
* @return
* - HBA_STATUS_NOT_LOADED if library is not loaded
* - HBA_STATUS_ERROR_INVALID_HANDLE if handle is invalid
* - HBA_STATUS_ERROR_UNAVAILABLE if adapter is unavailable
* - HBA_STATUS_ERROR_ILLEGAL_INDEX if portindex is invalid
* - HBA_STATUS_ERROR if any other internal error occurs
* - HBA_STATUS_OK on success.
* @par Locks:
* lock/unlock of vlib_data.mutex
* @note Parameter portindex _must_ be 0, since we have only one local port on
* our adapters.
*/
HBA_STATUS HBA_GetPortStatistics(HBA_HANDLE handle, HBA_UINT32 portindex,
HBA_PORTSTATISTICS *pPortstatistics)
{
HBA_STATUS status;
struct vlib_adapter *adapter;
int ret;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
status = revalidateRepository();
if (HBA_STATUS_OK != status) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
adapter = getAdapterByHandle(handle, &status);
if (NULL == adapter) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
if (portindex != 0) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR_ILLEGAL_INDEX;
}
status = sysfs_getPortStatistics(&pPortstatistics, adapter);
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
/** @ingroup UnSupportedHBAAPIs
* @return HBA_STATUS_ERROR_NOT_SUPPORTED
* @note This function is currently not supported.
*/
HBA_STATUS HBA_GetFC4Statistics(HBA_HANDLE handle, HBA_WWN hbaPortWWN,
HBA_UINT8 FC4type,
HBA_FC4STATISTICS *statistics)
{
return HBA_STATUS_ERROR_NOT_SUPPORTED;
}
/*
* FCP INFORMATION FUNCTIONS
*/
/** @ingroup UnSupportedHBAAPIs
* @return HBA_STATUS_ERROR_NOT_SUPPORTED
* @note This function is currently not supported.
*/
HBA_STATUS HBA_GetBindingCapability(HBA_HANDLE handle, HBA_WWN hbaPortWWN,
HBA_BIND_CAPABILITY *pFlags)
{
return HBA_STATUS_ERROR_NOT_SUPPORTED;
}
/** @ingroup UnSupportedHBAAPIs
* @return HBA_STATUS_ERROR_NOT_SUPPORTED
* @note This function is currently not supported.
*/
HBA_STATUS HBA_GetBindingSupport(HBA_HANDLE handle, HBA_WWN hbaPortWWN,
HBA_BIND_CAPABILITY *pFlags)
{
return HBA_STATUS_ERROR_NOT_SUPPORTED;
}
/** @ingroup UnSupportedHBAAPIs
* @return HBA_STATUS_ERROR_NOT_SUPPORTED
* @note This function is currently not supported.
*/
HBA_STATUS HBA_SetBindingSupport(HBA_HANDLE handle, HBA_WWN hbaPortWWN,
HBA_BIND_CAPABILITY flags)
{
return HBA_STATUS_ERROR_NOT_SUPPORTED;
}
/** @ingroup SupportedHBAAPIs
* @brief Retrieve mappings between OS SCSI targets/units and FCP targets/units.
* @param handle to an opened adapter
* @param *pMapping pointer to return target mappings
* @return
* - HBA_STATUS_NOT_LOADED if library is not loaded
* - HBA_STATUS_ERROR_INVALID_HANDLE if handle is invalid
* - HBA_STATUS_ERROR_UNAVAILABLE if adapter is unavailable
* - HBA_STATUS_ERROR_MORE_DATA if there is not enough space in pMapping
* to return complete mapping information
* - HBA_STATUS_ERROR if any other internal error occurs
* - HBA_STATUS_OK on success.
* @par Locks:
* lock/unlock of vlib_data.mutex
* @note An OSDeviceName is not provided for target mappings.
* @note Additionally this function triggers creation of unit configuration for
* this adapter (see revalidateUnits()).
*/
HBA_STATUS HBA_GetFcpTargetMapping(HBA_HANDLE handle,
HBA_FCPTARGETMAPPING *pMapping)
{
unsigned int i, j;
struct vlib_adapter *adapter;
struct vlib_port *port;
struct vlib_unit *unit;
HBA_UINT32 total, free;
HBA_STATUS status;
HBA_FCPSCSIENTRY *entry;
VLIB_MUTEX_LOCK(&vlib_data.mutex);
status = revalidateRepository();
if (HBA_STATUS_OK != status) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
adapter = getAdapterByHandle(handle, &status);
if (NULL == adapter) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return status;
}
if (revalidatePorts(adapter) < 0) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR;
}
port = getPortByIndex(adapter, 0);
if (NULL == port) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR;
}
free = pMapping->NumberOfEntries;
entry = pMapping->entry;
total = 0;
for (i = 0; i < adapter->ports.used; ++i, ++port) {
if (port->isInvalid)
continue;
if (revalidateUnits(port) < 0) {
VLIB_MUTEX_UNLOCK(&vlib_data.mutex);
return HBA_STATUS_ERROR;
}
unit = getUnitByIndex(port, 0);
if (NULL == unit)
continue;
for (j = 0; j < port->units.used; ++j, ++unit) {
if (unit->isInvalid)
continue;
++total;
if (0 == free)
/* although there is no space to return further
mappings, we still have to determine the
total number of mappings which must be
returned in the NumberOfEntries field */
continue;
strcpy(entry->ScsiId.OSDeviceName, "");
entry->ScsiId.ScsiBusNumber = unit->channel;
entry->ScsiId.ScsiTargetNumber = unit->target;
entry->ScsiId.ScsiOSLun = unit->lun;
snprintf(entry->ScsiId.OSDeviceName,
sizeof(entry->ScsiId.OSDeviceName),
"/dev/bsg/%d:%d:%d:%d",
adapter->ident.host,
unit->channel,
unit->target,
unit->lun);
entry->FcpId.FcId = vlib_FCID_to_hbaFCID(port->did);
vlib_wwn_to_HBA_WWN(port->wwnn,
&entry->FcpId.NodeWWN);
vlib_wwn_to_HBA_WWN(port->wwpn,
&entry->FcpId.PortWWN);
entry->FcpId.FcpLun = unit->fcLun;
++entry;
--free;
}
}