Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

493 lines
11 KiB

  1. //***************************************************************************
  2. //
  3. // getdata.c
  4. //
  5. // Module: Windows HBA API implmentation
  6. //
  7. // Purpose: Contains routines for getting and setting data
  8. //
  9. // Copyright (c) 2001 Microsoft Corporation
  10. //
  11. //***************************************************************************
  12. #include "hbaapip.h"
  13. HBA_STATUS HBA_GetAdapterAttributesX(
  14. HBA_HANDLE HbaHandle,
  15. HBA_ADAPTERATTRIBUTES *HbaAdapterAttributes,
  16. BOOLEAN IsAnsi
  17. )
  18. {
  19. HANDLE Handle;
  20. PADAPTER_HANDLE HandleData;
  21. ULONG Status;
  22. HBA_STATUS HbaStatus = HBA_STATUS_ERROR;
  23. PWNODE_SINGLE_INSTANCE Buffer;
  24. PUCHAR Data;
  25. ULONG DataLength;
  26. PHBA_ADAPTERATTRIBUTES HbaAdapterAttributesA;
  27. HandleData = GetDataByHandle(HbaHandle);
  28. if (HandleData != NULL)
  29. {
  30. Status = WmiOpenBlock((LPGUID)&MSFC_FCAdapterHBAAttributes_GUID,
  31. GENERIC_READ,
  32. &Handle);
  33. if (Status == ERROR_SUCCESS)
  34. {
  35. //
  36. // Validate adapter name by querying for that adapter name as a
  37. // WMI instance name
  38. //
  39. Status = QuerySingleInstance(Handle,
  40. HandleData->InstanceName,
  41. &Buffer);
  42. if (Status == ERROR_SUCCESS)
  43. {
  44. Status = ParseSingleInstance(Buffer,
  45. NULL,
  46. &Data,
  47. &DataLength);
  48. if (Status == ERROR_SUCCESS)
  49. {
  50. //
  51. // Skip over AdapterId as it is not needed for HBA
  52. //
  53. Data += sizeof(ULONGLONG);
  54. //
  55. // Get the HBA status returned from the miniport.
  56. // If the miniport returns HBA_STATUS_OK then all
  57. // data is filled in the data block. If any other
  58. // HBA status is returned then the miniport is
  59. // reporting an error and we want to return that
  60. // HBA error code to the caller
  61. //
  62. HbaStatus = *(HBA_STATUS *)Data;
  63. Data += sizeof(HBA_STATUS);
  64. if (HbaStatus == HBA_STATUS_OK)
  65. {
  66. //
  67. // We have got our adapter attributes, so copy them
  68. // over to the output buffer
  69. //
  70. if (IsAnsi)
  71. {
  72. HbaAdapterAttributesA = HbaAdapterAttributes;
  73. GetDataFromDataBlock(HbaAdapterAttributesA,
  74. NodeWWN,
  75. HBA_WWN,
  76. Data);
  77. GetDataFromDataBlock(HbaAdapterAttributesA,
  78. VendorSpecificID,
  79. HBA_UINT32,
  80. Data);
  81. GetDataFromDataBlock(HbaAdapterAttributesA,
  82. NumberOfPorts,
  83. HBA_UINT32,
  84. Data);
  85. CopyString(&HbaAdapterAttributesA->Manufacturer,
  86. &Data,
  87. 64,
  88. IsAnsi);
  89. CopyString(&HbaAdapterAttributesA->SerialNumber,
  90. &Data,
  91. 64,
  92. IsAnsi);
  93. CopyString(&HbaAdapterAttributesA->Model,
  94. &Data,
  95. 256,
  96. IsAnsi);
  97. CopyString(&HbaAdapterAttributesA->ModelDescription,
  98. &Data,
  99. 256,
  100. IsAnsi);
  101. CopyString(&HbaAdapterAttributesA->NodeSymbolicName,
  102. &Data,
  103. 256,
  104. IsAnsi);
  105. CopyString(&HbaAdapterAttributesA->HardwareVersion,
  106. &Data,
  107. 256,
  108. IsAnsi);
  109. CopyString(&HbaAdapterAttributesA->DriverVersion,
  110. &Data,
  111. 256,
  112. IsAnsi);
  113. CopyString(&HbaAdapterAttributesA->OptionROMVersion,
  114. &Data,
  115. 256,
  116. IsAnsi);
  117. CopyString(&HbaAdapterAttributesA->FirmwareVersion,
  118. &Data,
  119. 256,
  120. IsAnsi);
  121. CopyString(&HbaAdapterAttributesA->DriverName,
  122. &Data,
  123. 256,
  124. IsAnsi);
  125. } else {
  126. GetDataFromDataBlock(HbaAdapterAttributes,
  127. NodeWWN,
  128. HBA_WWN,
  129. Data);
  130. GetDataFromDataBlock(HbaAdapterAttributes,
  131. VendorSpecificID,
  132. HBA_UINT32,
  133. Data);
  134. GetDataFromDataBlock(HbaAdapterAttributes,
  135. NumberOfPorts,
  136. HBA_UINT32,
  137. Data);
  138. CopyString(&HbaAdapterAttributes->Manufacturer,
  139. &Data,
  140. 64,
  141. IsAnsi);
  142. CopyString(&HbaAdapterAttributes->SerialNumber,
  143. &Data,
  144. 64,
  145. IsAnsi);
  146. CopyString(&HbaAdapterAttributes->Model,
  147. &Data,
  148. 256,
  149. IsAnsi);
  150. CopyString(&HbaAdapterAttributes->ModelDescription,
  151. &Data,
  152. 256,
  153. IsAnsi);
  154. CopyString(&HbaAdapterAttributes->NodeSymbolicName,
  155. &Data,
  156. 256,
  157. IsAnsi);
  158. CopyString(&HbaAdapterAttributes->HardwareVersion,
  159. &Data,
  160. 256,
  161. IsAnsi);
  162. CopyString(&HbaAdapterAttributes->DriverVersion,
  163. &Data,
  164. 256,
  165. IsAnsi);
  166. CopyString(&HbaAdapterAttributes->OptionROMVersion,
  167. &Data,
  168. 256,
  169. IsAnsi);
  170. CopyString(&HbaAdapterAttributes->FirmwareVersion,
  171. &Data,
  172. 256,
  173. IsAnsi);
  174. CopyString(&HbaAdapterAttributes->DriverName,
  175. &Data,
  176. 256,
  177. IsAnsi);
  178. }
  179. }
  180. }
  181. FreeMemory(Buffer);
  182. }
  183. WmiCloseBlock(Handle);
  184. }
  185. } else {
  186. HbaStatus = HBA_STATUS_ERROR_INVALID_HANDLE;
  187. }
  188. return(HbaStatus);
  189. }
  190. HBA_STATUS HBA_API HBA_GetAdapterAttributes(
  191. HBA_HANDLE HbaHandle,
  192. HBA_ADAPTERATTRIBUTES *HbaAdapterAttributes
  193. )
  194. {
  195. return(HBA_GetAdapterAttributesX(HbaHandle,
  196. HbaAdapterAttributes,
  197. TRUE));
  198. }
  199. HBA_STATUS HBA_GetAdapterPortAttributesX(
  200. HBA_HANDLE HbaHandle,
  201. HBA_UINT32 PortIndex,
  202. HBA_PORTATTRIBUTES *PortAttributes,
  203. BOOLEAN IsAnsi
  204. )
  205. {
  206. HANDLE Handle;
  207. PADAPTER_HANDLE HandleData;
  208. ULONG Status;
  209. HBA_STATUS HbaStatus = HBA_STATUS_ERROR;
  210. PWNODE_SINGLE_INSTANCE Buffer;
  211. PUCHAR Data;
  212. ULONG DataLength;
  213. PWCHAR InstanceName;
  214. HandleData = GetDataByHandle(HbaHandle);
  215. if (HandleData != NULL)
  216. {
  217. Status = WmiOpenBlock((LPGUID)&MSFC_FibrePortHBAAttributes_GUID,
  218. GENERIC_READ,
  219. &Handle);
  220. if (Status == ERROR_SUCCESS)
  221. {
  222. InstanceName = CreatePortInstanceNameW(HandleData->InstanceName,
  223. PortIndex);
  224. if (InstanceName != NULL)
  225. {
  226. Status = QuerySingleInstance(Handle,
  227. InstanceName,
  228. &Buffer);
  229. if (Status == ERROR_SUCCESS)
  230. {
  231. Status = ParseSingleInstance(Buffer,
  232. NULL,
  233. &Data,
  234. &DataLength);
  235. if (Status == ERROR_SUCCESS)
  236. {
  237. //
  238. // Skip over AdapterId as it is not needed for HBA
  239. //
  240. Data += sizeof(ULONGLONG);
  241. //
  242. // Get the HBA status returned from the miniport.
  243. // If the miniport returns HBA_STATUS_OK then all
  244. // data is filled in the data block. If any other
  245. // HBA status is returned then the miniport is
  246. // reporting an error and we want to return that
  247. // HBA error code to the caller
  248. //
  249. HbaStatus = *(HBA_STATUS *)Data;
  250. Data += sizeof(HBA_STATUS);
  251. if (HbaStatus == HBA_STATUS_OK)
  252. {
  253. CopyPortAttributes(PortAttributes,
  254. Data,
  255. IsAnsi);
  256. }
  257. }
  258. FreeMemory(Buffer);
  259. }
  260. FreeMemory(InstanceName);
  261. }
  262. WmiCloseBlock(Handle);
  263. }
  264. } else {
  265. HbaStatus = HBA_STATUS_ERROR_INVALID_HANDLE;
  266. }
  267. return(HbaStatus);
  268. }
  269. HBA_STATUS HBA_API HBA_GetAdapterPortAttributes(
  270. HBA_HANDLE HbaHandle,
  271. HBA_UINT32 PortIndex,
  272. HBA_PORTATTRIBUTES *PortAttributes
  273. )
  274. {
  275. return(HBA_GetAdapterPortAttributesX(HbaHandle,
  276. PortIndex,
  277. PortAttributes,
  278. TRUE));
  279. }
  280. HBA_STATUS HBA_API HBA_GetPortStatistics(
  281. HBA_HANDLE HbaHandle,
  282. HBA_UINT32 PortIndex,
  283. HBA_PORTSTATISTICS *HbaPortStatistics
  284. )
  285. {
  286. HANDLE Handle;
  287. PADAPTER_HANDLE HandleData;
  288. ULONG Status;
  289. HBA_STATUS HbaStatus = HBA_STATUS_ERROR;
  290. PUCHAR Data;
  291. ULONG DataLength;
  292. PWCHAR InstanceName;
  293. PWNODE_SINGLE_INSTANCE Buffer;
  294. HandleData = GetDataByHandle(HbaHandle);
  295. if (HandleData != NULL)
  296. {
  297. Status = WmiOpenBlock((LPGUID)&MSFC_FibrePortHBAStatistics_GUID,
  298. GENERIC_READ,
  299. &Handle);
  300. if (Status == ERROR_SUCCESS)
  301. {
  302. InstanceName = CreatePortInstanceNameW(HandleData->InstanceName,
  303. PortIndex);
  304. if (InstanceName != NULL)
  305. {
  306. Status = QuerySingleInstance(Handle,
  307. InstanceName,
  308. &Buffer);
  309. if (Status == ERROR_SUCCESS)
  310. {
  311. Status = ParseSingleInstance(Buffer,
  312. NULL,
  313. &Data,
  314. &DataLength);
  315. if (Status == ERROR_SUCCESS)
  316. {
  317. //
  318. // Skip over AdapterId as it is not needed for HBA
  319. //
  320. Data += sizeof(ULONGLONG);
  321. //
  322. // Get the HBA status returned from the miniport.
  323. // If the miniport returns HBA_STATUS_OK then all
  324. // data is filled in the data block. If any other
  325. // HBA status is returned then the miniport is
  326. // reporting an error and we want to return that
  327. // HBA error code to the caller
  328. //
  329. HbaStatus = *(HBA_STATUS *)Data;
  330. Data += sizeof(HBA_STATUS);
  331. //
  332. // Since the data block goes from ULONG to
  333. // ULONGLONG, we need to account for 4 bytes of
  334. // padding
  335. //
  336. Data += 4;
  337. if (HbaStatus == HBA_STATUS_OK)
  338. {
  339. //
  340. // We have got our port statistics, so copy them
  341. // over to the output buffer
  342. //
  343. GetDataFromDataBlock(HbaPortStatistics,
  344. SecondsSinceLastReset,
  345. HBA_INT64,
  346. Data);
  347. GetDataFromDataBlock(HbaPortStatistics,
  348. TxFrames,
  349. HBA_INT64,
  350. Data);
  351. GetDataFromDataBlock(HbaPortStatistics,
  352. TxWords,
  353. HBA_INT64,
  354. Data);
  355. GetDataFromDataBlock(HbaPortStatistics,
  356. RxFrames,
  357. HBA_INT64,
  358. Data);
  359. GetDataFromDataBlock(HbaPortStatistics,
  360. RxWords,
  361. HBA_INT64,
  362. Data);
  363. GetDataFromDataBlock(HbaPortStatistics,
  364. LIPCount,
  365. HBA_INT64,
  366. Data);
  367. GetDataFromDataBlock(HbaPortStatistics,
  368. NOSCount,
  369. HBA_INT64,
  370. Data);
  371. GetDataFromDataBlock(HbaPortStatistics,
  372. ErrorFrames,
  373. HBA_INT64,
  374. Data);
  375. GetDataFromDataBlock(HbaPortStatistics,
  376. DumpedFrames,
  377. HBA_INT64,
  378. Data);
  379. GetDataFromDataBlock(HbaPortStatistics,
  380. LinkFailureCount,
  381. HBA_INT64,
  382. Data);
  383. GetDataFromDataBlock(HbaPortStatistics,
  384. LossOfSyncCount,
  385. HBA_INT64,
  386. Data);
  387. GetDataFromDataBlock(HbaPortStatistics,
  388. LossOfSignalCount,
  389. HBA_INT64,
  390. Data);
  391. GetDataFromDataBlock(HbaPortStatistics,
  392. PrimitiveSeqProtocolErrCount,
  393. HBA_INT64,
  394. Data);
  395. GetDataFromDataBlock(HbaPortStatistics,
  396. InvalidTxWordCount,
  397. HBA_INT64,
  398. Data);
  399. GetDataFromDataBlock(HbaPortStatistics,
  400. InvalidCRCCount,
  401. HBA_INT64,
  402. Data);
  403. }
  404. }
  405. FreeMemory(Buffer);
  406. }
  407. FreeMemory(InstanceName);
  408. }
  409. WmiCloseBlock(Handle);
  410. }
  411. } else {
  412. HbaStatus = HBA_STATUS_ERROR_INVALID_HANDLE;
  413. }
  414. return(HbaStatus);
  415. }