-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhbasample.c
369 lines (322 loc) · 10.2 KB
/
hbasample.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
/*************************************************************************
* Description
* hbasample.c - Implements a sample HBA API compliant vendor library
* defining the entry points for the DLL application
*
* License:
* The contents of this file are subject to the SNIA Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* /http://www.snia.org/English/Resources/Code/OpenSource.html
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is SNIA HBA API Sample Vendor Specific Library
*
* The Initial Developer of the Original Code is:
* Benjamin F. Kuo, Troika Networks, Inc. ([email protected])
*
* Contributor(s):
* Tuan Lam, QLogic Corp. ([email protected])
* Dan Willie, Emulex Corp. ([email protected])
* Dixon Hutchinson, Legato Systems, Inc. ([email protected])
*
*************************************************************************
*/
#ifdef WIN32
#include <windows.h>
#endif
#include <time.h>
#include "hbaapi.h"
#include "vendorhbaapi.h"
#include "hbasample.h"
/* Begin implementation */
#ifdef WIN32
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif
/*
* Two functions are exported. They both are used to register entry points.
* Remember, this is a Rev2 Vendor specific library, but we might be
* called by either a Rev2 or a Rev1. The Rev1 callers will call
* HBA_RegisterLibrary. The Rev2 callers SHOULD call HBA_RegisterLibaryV2.
* The size of the structure referenced in the Rev2 call is larger then in
* the Rev1 call and the Rev1 sturcture is duplicated at the beginning of the
* Rev2 structure
*/
/*
* Rev1 Code will call this function and only get the Rev1 registration.
* This prevents overrunning the data structure.
*/
HBASAMPLE_API HBA_STATUS
HBA_RegisterLibrary(HBA_ENTRYPOINTS *entrypoints ) {
entrypoints->GetVersionHandler = Sample_GetVersion;
entrypoints->LoadLibraryHandler = Sample_LoadLibrary;
entrypoints->FreeLibraryHandler = Sample_FreeLibrary;
entrypoints->GetNumberOfAdaptersHandler = Sample_GetNumberOfAdapters;
entrypoints->GetAdapterNameHandler = Sample_GetAdapterName;
entrypoints->OpenAdapterHandler = Sample_OpenAdapter;
entrypoints->OpenAdapterByWWNHandler = Sample_OpenAdapterByWWN;
entrypoints->CloseAdapterHandler = Sample_CloseAdapter;
entrypoints->GetAdapterAttributesHandler = Sample_GetAdapterAttributes;
entrypoints->GetAdapterPortAttributesHandler = Sample_GetAdapterPortAttributes;
entrypoints->GetPortStatisticsHandler = Sample_GetPortStatistics;
entrypoints->GetDiscoveredPortAttributesHandler =
Sample_GetDiscoveredPortAttributes;
entrypoints->GetPortAttributesByWWNHandler = Sample_GetPortAttributesByWWN;
entrypoints->RefreshInformationHandler = Sample_RefreshInformation;
entrypoints->RegisterForAdapterEventsHandler = Sample_RegisterForAdapterEvents;
/* There are a lot more entry points to register, however this is just
* busy work. You get the idea. */
return 0;
}
/*
* Here is were Rev2 callers will try first (all done by the wrapper library),
* If the machine has not Rev2 vendor library, then obviosly, this function
* will not be found.
*/
HBASAMPLE_API HBA_STATUS
HBA_RegisterLibraryV2(HBA_ENTRYPOINTSV2 *entrypoints) {
/* have the old function do the Rev1 part */
(void) HBA_RegisterLibrary((HBA_ENTRYPOINTS *)entrypoints);
entrypoints->SendCTPassThruV2Handler = Sample_SendCTPassThruV2;
/* so on and so forth */
return 0
}
void
Sample_RemoveCallback() {
}
HBA_STATUS Sample_LoadLibrary() {
/* Vendor specific intialization ...*/
return HBA_STATUS_OK;
}
HBA_STATUS Sample_FreeLibrary() {
/* Free up all resources any call to this library allocated */
return HBA_STATUS_OK;
}
HBA_UINT32 Sample_GetVersion()
{
return HBA_LIBVERSION;
}
HBA_UINT32 Sample_GetNumberOfAdapters()
{
return 1;
}
HBA_STATUS Sample_GetAdapterName(HBA_UINT32 adapterindex, char *adaptername)
{
if (adapterindex > 1) {
return HBA_STATUS_ERROR_ILLEGAL_INDEX;
} else {
strcpy(adaptername, "org.snia.sample-1");
return HBA_STATUS_OK;
}
}
HBA_HANDLE
Sample_OpenAdapter(char* adaptername ){
/*
* WARNING WARNING, Danger Will Robinson,
* The wrapper library will mask the return of this function to
* the lower 16 bits. Think of this function as returning
* UINT16
*/
HBA_HANDLE temp;
temp = 0;
if (strcmp(adaptername, "sample-adapter-1") == 0) {
}
return temp;
}
HBA_STATUS
Sample_OpenAdapterByWWN(HBA_HANDLE handle, HBA_WWN wwn){
/*
* WARNING WARNING, Danger Will Robinson,
* The wrapper library will mask the handle of this function to
* the lower 16 bits. Think of this HBA_HANDLE as UINT16
*/
HBA_HANDLE temp;
HBA_WWN twwn = {1,2,3,4,5,6,7,8};
if (memcmp(wwn, twwn) == 0) {
return HBA_STATUS_OK;
}
return HBA_STATUS_ERROR_ILLEGAL_WWN;
}
void Sample_CloseAdapter(
HBA_HANDLE handle
)
{
}
HBA_STATUS Sample_GetAdapterAttributes(
HBA_HANDLE handle,
PHBA_ADAPTERATTRIBUTES hbaattributes
)
{
strcpy(hbaattributes->Manufacturer, "Emulex");
strcpy(hbaattributes->SerialNumber, "A12345");
strcpy(hbaattributes->Model, "QLA2200");
strcpy(hbaattributes->ModelDescription, "Agilent TachLite");
hbaattributes->NodeWWN.wwn[0] = 0x01;
hbaattributes->NodeWWN.wwn[1] = 0x02;
hbaattributes->NodeWWN.wwn[2] = 0x03;
hbaattributes->NodeWWN.wwn[3] = 0x04;
hbaattributes->NodeWWN.wwn[4] = 0x05;
hbaattributes->NodeWWN.wwn[5] = 0x06;
hbaattributes->NodeWWN.wwn[6] = 0x07;
hbaattributes->NodeWWN.wwn[7] = 0x08;
strcpy(hbaattributes->NodeSymbolicName, "HBA API Sample Driver");
strcpy(hbaattributes->HardwareVersion, "Hardware Version");
strcpy(hbaattributes->DriverVersion, "Driver Version");
strcpy(hbaattributes->OptionROMVersion, "Option ROM Version");
strcpy(hbaattributes->FirmwareVersion, "Firmware Version");
hbaattributes->VendorSpecificID = 0;
hbaattributes->NumberOfPorts = 1;
return HBA_STATUS_OK;
}
HBA_STATUS Sample_GetAdapterPortAttributes(
HBA_HANDLE handle,
HBA_UINT32 portindex,
HBA_PORTATTRIBUTES *portattributes
)
{
if (portindex == 1) {
/* WWN corresponding to 0001020304050708 */
portattributes->NodeWWN.wwn[0] = 0x01;
portattributes->NodeWWN.wwn[1] = 0x02;
portattributes->NodeWWN.wwn[2] = 0x03;
portattributes->NodeWWN.wwn[3] = 0x04;
portattributes->NodeWWN.wwn[4] = 0x05;
portattributes->NodeWWN.wwn[5] = 0x06;
portattributes->NodeWWN.wwn[6] = 0x07;
portattributes->NodeWWN.wwn[7] = 0x08;
portattributes->PortWWN.wwn[0] = 0x01;
portattributes->PortWWN.wwn[1] = 0x02;
portattributes->PortWWN.wwn[2] = 0x03;
portattributes->PortWWN.wwn[3] = 0x04;
portattributes->PortWWN.wwn[4] = 0x05;
portattributes->PortWWN.wwn[5] = 0x06;
portattributes->PortWWN.wwn[6] = 0x07;
portattributes->PortWWN.wwn[7] = 0x08;
portattributes->PortFcId = 0x00;
portattributes->PortType = HBA_PORTTYPE_UNKNOWN;
portattributes->PortState = HBA_PORTSTATE_ONLINE;
portattributes->PortSupportedClassofService = 0x00;
portattributes->PortSupportedFc4Types.bits[0] = 0x00;
portattributes->PortActiveFc4Types.bits[0] = 0x00;
strcpy(portattributes->OSDeviceName, "DeviceName");
portattributes->PortSpeed = HBA_PORTSPEED_1GBIT;
portattributes->NumberofDiscoveredPorts = 0;
return HBA_STATUS_OK;
} else {
return HBA_STATUS_ERROR_ILLEGAL_INDEX;
}
}
HBA_STATUS Sample_GetPortStatistics(
HBA_HANDLE handle,
HBA_UINT32 portindex,
HBA_PORTSTATISTICS *portstatistics
)
{
portstatistics->TxFrames = 0;
portstatistics->RxFrames = 0;
portstatistics->TxWords = 0;
portstatistics->RxWords = 0;
portstatistics->LIPCount = 0;
portstatistics->NOSCount = 0;
portstatistics->ErrorFrames = 0;
portstatistics->DumpedFrames = 0;
portstatistics->LinkFailureCount = 0;
portstatistics->LossOfSyncCount = 0;
portstatistics->LossOfSignalCount = 0;
portstatistics->PrimitiveSeqProtocolErrCount = 0;
portstatistics->InvalidTxWordCount = 0;
portstatistics->InvalidCRCCount = 0;
return HBA_STATUS_OK;
}
HBA_STATUS Sample_GetDiscoveredPortAttributes(
HBA_HANDLE handle,
HBA_UINT32 portindex,
HBA_UINT32 discoveredportindex,
HBA_PORTATTRIBUTES *portattributes
)
{
/* since this is a virtual driver with no discovered ports
always return an error */
return HBA_STATUS_ERROR_ILLEGAL_INDEX;
}
HBA_STATUS Sample_GetPortAttributesByWWN(
HBA_HANDLE handle,
HBA_WWN PortWWN,
HBA_PORTATTRIBUTES *portattributes
)
{
return HBA_STATUS_ERROR_NOT_SUPPORTED;
}
void Sample_RefreshInformation(HBA_HANDLE handle)
{
}
static void *eventhandlerdata;
HBA_STATUS Sample_RegisterForAdapterEvents(
(void (*callback)(
void *data,
HBA_WWN PortWWN,
HBA_UINT32 eventType),
void *userData,
HBA_HANDLE handle,
HBA_CALLBACKHANDLE *callbackHandle)
{
ptr = calloc();
ptr->userdata = userData;
ptr->callbackfunc = callback;
/* store away a pointer to this data,
* the low level event handler (event below)
* will magically find this data when the
* event is delivery is necessary
*/
eventhandlerdata = ptr;
/* give the caller something to remember this registion by */
/* this can be used later to deregister the call back */
*callbackHandle = ptr;
}
void
event()
{
HBA_UINT64 port = 0x12345678;
HBA_WWN PortWWN;
ptr = eventhandlerdata;
memcpy(&PortWWN, &port, 8);
(*ptr->callvackfunc)(ptr->userdata, PortWWN, HBA_EVENT_ADAPTER_CHANGE);
}
/*
* REV 2 functions
*/
HBA_STATUS Sample_HBAOpenAdapterByWWN(HBA_HANDLE *phandle, HBA_WWN wwn) {
/* find out if it is a WWN to one of our hba's */
/* if it is, open it */
if(1 == 2) {
*phandle = "123";
return(HBA_STATUS_OK);
} else {
return(HBA_STATUS_ERROR_ILLEGAL_WWN);
}
}
HBA_STATUS Sample_HBA_GetFcpTargetMapping(
HBA_HANDLE handle,
HBA_FCPTARGETMAPPING
*pmapping
)
{
}