Windows NT 4.0 source code leak
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.

555 lines
16 KiB

4 years ago
  1. /****************************************************************************
  2. *
  3. * DRV_ERR.C : Part of the FASTMAC TOOL-KIT (FTK)
  4. *
  5. * THE ERROR EXPLANATION MODULE
  6. *
  7. * Copyright (c) Madge Networks Ltd. 1991-1993
  8. *
  9. * COMPANY CONFIDENTIAL
  10. *
  11. *****************************************************************************
  12. *
  13. * The driver module provides a simple interface to allow the use of
  14. * Fastmac in as general a setting as possible. It handles the downloading
  15. * of the Fastmac code and the initialization of the adapter card. It
  16. * provides simple transmit and receive routines. It is desgined to
  17. * quickly allow the implementation of Fastmac applications. It is not
  18. * designed as the fastest or most memory efficient solution.
  19. *
  20. * The DRV_ERR.C module contains the routine to explain the cause of errors
  21. * when other driver routines fail.
  22. *
  23. ****************************************************************************/
  24. /*---------------------------------------------------------------------------
  25. |
  26. | DEFINITIONS
  27. |
  28. ---------------------------------------------------------------------------*/
  29. #include "ftk_defs.h"
  30. /*---------------------------------------------------------------------------
  31. |
  32. | MODULE ENTRY POINTS
  33. |
  34. ---------------------------------------------------------------------------*/
  35. #include "ftk_intr.h" /* routines internal to FTK */
  36. #include "ftk_extr.h" /* routines provided or used by external FTK user */
  37. /*---------------------------------------------------------------------------
  38. |
  39. | LOCAL VARIABLES
  40. |
  41. ---------------------------------------------------------------------------*/
  42. #include "ftk_tab.h"
  43. /****************************************************************************
  44. *
  45. * driver_explain_error
  46. * ====================
  47. *
  48. * PARAMETERS :
  49. * ============
  50. *
  51. * ADAPTER_HANDLE adapter_handle
  52. *
  53. * This handle identifies the adapter for which the error has occured.
  54. *
  55. * BYTE * returned_error_type
  56. *
  57. * The byte pointed to is filled in with a value representing the type of
  58. * error that has occured. If no error has actually occured it is filled in
  59. * woth the value zero (0).
  60. *
  61. * BYTE * returned_error_value
  62. *
  63. * The byte pointed to is filled in with a value representing the
  64. * particular error of a given type that has occured. If no error has
  65. * actually occured it is filled in with the value zero (0).
  66. *
  67. * char * * returned_error_message
  68. *
  69. * This pointer, on exit, points to a string containing a message
  70. * describing the error that has occured. If no error has actually occured
  71. * then it points to a null message.
  72. *
  73. * BODY :
  74. * ======
  75. *
  76. * The driver_explain_error routine returns details of the most recent
  77. * error to occur using a given adapter.
  78. *
  79. * RETURNS :
  80. * =========
  81. *
  82. * The routine returns a boolean value indicating whether the error is
  83. * fatal or not. If the error is fatal (returns FALSE) then the adapter can
  84. * not be used subsequently except via a call to driver_remove_adapter.
  85. * However, the adapter can, after a call to driver_remove_adapter, be
  86. * initialized again etc.
  87. *
  88. ****************************************************************************/
  89. #ifdef FTK_RES_FUNCTION
  90. #pragma FTK_RES_FUNCTION(driver_explain_error)
  91. #endif
  92. export WBOOLEAN
  93. driver_explain_error(
  94. ADAPTER_HANDLE adapter_handle,
  95. BYTE * returned_error_type,
  96. BYTE * returned_error_value,
  97. char * * returned_error_message
  98. )
  99. {
  100. ERROR_MESSAGE_RECORD * err_msg_record;
  101. char * err_msg_header;
  102. ADAPTER * adapter;
  103. ERROR_RECORD * adapter_error_record;
  104. if (adapter_handle >= MAX_NUMBER_OF_ADAPTERS)
  105. {
  106. /*
  107. * Adapter handle is invalid if greater than max number of adapters.
  108. */
  109. *returned_error_type = ERROR_TYPE_DRIVER;
  110. *returned_error_value = DRIVER_E_01_INVALID_HANDLE;
  111. /*
  112. * Set up returned error msg to point to special string.
  113. * No adapter structure so can not use error message adapter field.
  114. */
  115. #ifdef FTK_NO_ERROR_MESSAGES
  116. *returned_error_message = "";
  117. #else
  118. *returned_error_message = drv_err_msg_1;
  119. #endif
  120. /*
  121. * This is a fatal error.
  122. */
  123. return FALSE;
  124. }
  125. if (adapter_record[adapter_handle] == NULL)
  126. {
  127. /*
  128. * Adapter handle is invalid when no adapter structure for handle.
  129. * Caused by either the adapter handle being invalid or
  130. * the call to sys_alloc_adapter_structure having failed.
  131. * Fill in returned error type and value.
  132. */
  133. *returned_error_type = ERROR_TYPE_DRIVER;
  134. *returned_error_value = DRIVER_E_02_NO_ADAP_STRUCT;
  135. /*
  136. * Set up returned error msg to point to special string.
  137. * No adapter structure so can not use error message adapter field.
  138. */
  139. #ifdef FTK_NO_ERROR_MESSAGES
  140. *returned_error_message = "";
  141. #else
  142. *returned_error_message = drv_err_msg_2;
  143. #endif
  144. /*
  145. * This is a fatal error.
  146. */
  147. return FALSE;
  148. }
  149. /*
  150. * Now know adapter handle is valid. Get pointer to adapter structure.
  151. */
  152. adapter = adapter_record[adapter_handle];
  153. /*
  154. * Get pointer to error record for adapter.
  155. */
  156. adapter_error_record = &adapter->error_record;
  157. /*
  158. * Check for special case when no error has actually occured.
  159. */
  160. if (adapter_error_record->type == ERROR_TYPE_NONE)
  161. {
  162. /*
  163. * Fill in returned error type and value as zero.
  164. */
  165. *returned_error_type = 0;
  166. *returned_error_value = 0;
  167. /*
  168. * Set the returned error message string to be null.
  169. * If no error then adapter error message field must be null.
  170. */
  171. #ifdef FTK_NO_ERROR_MESSAGES
  172. *returned_error_message = "";
  173. #else
  174. *returned_error_message = adapter->error_message.string;
  175. #endif
  176. /*
  177. * This is a non-fatal 'error'.
  178. */
  179. return TRUE;
  180. }
  181. /*
  182. * Now know have genuine error recorded by FTK. Fill in
  183. * returned error type and value.
  184. */
  185. *returned_error_type = adapter_error_record->type;
  186. *returned_error_value = adapter_error_record->value;
  187. #ifdef FTK_NO_ERROR_MESSAGES
  188. *returned_error_message = "";
  189. #else
  190. /*
  191. * All error messages are got from error message tables.
  192. * First get error message header. Note it is known that
  193. * *returned_error_type is valid here.
  194. */
  195. err_msg_header = error_msg_headers_table[(*returned_error_type) - 1];
  196. /*
  197. * Copy error message header to error message in adapter structure.
  198. */
  199. util_string_copy(adapter->error_message.string, err_msg_header);
  200. /*
  201. * Get pointer to correct error message table for rest of message.
  202. */
  203. err_msg_record = list_of_error_msg_tables[(*returned_error_type) - 1];
  204. /*
  205. * Search for required error message within table. Table ends with
  206. * special marked entry. So if error message not found will use
  207. * "Unknown error" message.
  208. */
  209. while (err_msg_record->value != ERR_MSG_UNKNOWN_END_MARKER)
  210. {
  211. if (err_msg_record->value == *returned_error_value)
  212. {
  213. break;
  214. }
  215. err_msg_record++;
  216. }
  217. /*
  218. * Concatenate error message onto end of error header in
  219. * error message field of adapter structure.
  220. */
  221. util_string_concatenate(
  222. adapter->error_message.string,
  223. err_msg_record->err_msg_string
  224. );
  225. /*
  226. * Set up return pointer to error message.
  227. */
  228. *returned_error_message = adapter->error_message.string;
  229. #endif
  230. /*
  231. * Return FALSE for fatal errors.
  232. */
  233. if (macro_fatal_error(*returned_error_type))
  234. {
  235. return FALSE;
  236. }
  237. /*
  238. * Return TRUE for non-fatal errors.
  239. */
  240. return TRUE;
  241. }
  242. /****************************************************************************
  243. *
  244. * driver_check_version
  245. * ====================
  246. *
  247. * PARAMETERS :
  248. * ============
  249. *
  250. * UINT * returned_version_number
  251. *
  252. * The returned version number is zero (0) if the version numbers of all
  253. * the FTK modules do not match correctly. If they do, then the returned
  254. * version number is the real version number mutiplied by 100 (eg. 1.01
  255. * becomes 101).
  256. *
  257. *
  258. * BODY :
  259. * ======
  260. *
  261. * The driver_check_version routine checks the version number consistency
  262. * of the FTK by looking at all the different code modules and header
  263. * files.
  264. *
  265. * RETURNS :
  266. * =========
  267. *
  268. * The routine returns TRUE if the version numbers are consistent.
  269. * Otherwise, it returns FALSE.
  270. *
  271. ****************************************************************************/
  272. /*
  273. * Marker at end of version number array.
  274. */
  275. #define VERSION_NUMBERS_END_MARK 0xFFFF
  276. /*
  277. * Version number array containing version numbers of ALL header files.
  278. */
  279. local UINT version_number[] =
  280. {
  281. FTK_VERSION_NUMBER_FTK_ADAP_H,
  282. FTK_VERSION_NUMBER_FTK_AT_H,
  283. FTK_VERSION_NUMBER_FTK_CARD_H,
  284. FTK_VERSION_NUMBER_FTK_DOWN_H,
  285. FTK_VERSION_NUMBER_FTK_EISA_H,
  286. FTK_VERSION_NUMBER_FTK_PCI_H,
  287. FTK_VERSION_NUMBER_FTK_PCMC_H,
  288. FTK_VERSION_NUMBER_FTK_PNP_H,
  289. FTK_VERSION_NUMBER_FTK_ERR_H,
  290. FTK_VERSION_NUMBER_FTK_FM_H,
  291. FTK_VERSION_NUMBER_FTK_INIT_H,
  292. FTK_VERSION_NUMBER_FTK_MACR_H,
  293. FTK_VERSION_NUMBER_FTK_MC_H,
  294. FTK_VERSION_NUMBER_FTK_SRB_H,
  295. FTK_VERSION_NUMBER_FTK_TAB_H,
  296. FTK_VERSION_NUMBER_FTK_USER_H,
  297. FTK_VERSION_NUMBER_DRV_ERR_H,
  298. FTK_VERSION_NUMBER_DRV_INIT_H,
  299. FTK_VERSION_NUMBER_DRV_IRQ_H,
  300. FTK_VERSION_NUMBER_DRV_MISC_H,
  301. FTK_VERSION_NUMBER_DRV_SRB_H,
  302. FTK_VERSION_NUMBER_DRV_RXTX_H,
  303. FTK_VERSION_NUMBER_HWI_GEN_H,
  304. FTK_VERSION_NUMBER_HWI_AT_H,
  305. FTK_VERSION_NUMBER_HWI_EISA_H,
  306. FTK_VERSION_NUMBER_HWI_MC_H,
  307. FTK_VERSION_NUMBER_HWI_PCI_H,
  308. FTK_VERSION_NUMBER_HWI_PCMC_H,
  309. FTK_VERSION_NUMBER_HWI_PNP_H,
  310. FTK_VERSION_NUMBER_SYS_ALLO_H,
  311. FTK_VERSION_NUMBER_SYS_BUFF_H,
  312. FTK_VERSION_NUMBER_SYS_DMA_H,
  313. FTK_VERSION_NUMBER_SYS_IRQ_H,
  314. FTK_VERSION_NUMBER_SYS_MEM_H,
  315. FTK_VERSION_NUMBER_SYS_TIME_H,
  316. FTK_VERSION_NUMBER_SYS_PCI_H,
  317. FTK_VERSION_NUMBER_SYS_CS_H,
  318. FTK_VERSION_NUMBER_USER_H,
  319. FTK_VERSION_NUMBER_UTIL_H,
  320. VERSION_NUMBERS_END_MARK};
  321. #ifdef FTK_RES_FUNCTION
  322. #pragma FTK_RES_FUNCTION(driver_check_version)
  323. #endif
  324. export WBOOLEAN
  325. driver_check_version(
  326. UINT * returned_version_number
  327. )
  328. {
  329. UINT i;
  330. /*
  331. * Check for consistent version number.
  332. */
  333. i = 0;
  334. while (version_number[i+1] != VERSION_NUMBERS_END_MARK)
  335. {
  336. if (version_number[i] != version_number[i + 1])
  337. {
  338. /*
  339. * Inconsistent version numbers so return failure.
  340. */
  341. *returned_version_number = 0;
  342. return FALSE;
  343. }
  344. i++;
  345. }
  346. /*
  347. * Version numbers are consistent so return version number and success.
  348. */
  349. *returned_version_number = version_number[0];
  350. return TRUE;
  351. }
  352. /****************************************************************************
  353. *
  354. * driver_check_adapter
  355. * ====================
  356. *
  357. * The driver_check_adapter routine is called at the beginning of every
  358. * driver routine, except driver_remove_adapter and driver_prepare_adapter,
  359. * in order to check the validity of the adapter handle. It also checks
  360. * that the adapter is in the correct operative state, and that the SRB
  361. * associated with the adapter is in the correct state (if any particular
  362. * state is required).
  363. *
  364. ****************************************************************************/
  365. #ifdef FTK_RES_FUNCTION
  366. #pragma FTK_RES_FUNCTION(driver_check_adapter)
  367. #endif
  368. export WBOOLEAN
  369. driver_check_adapter(
  370. ADAPTER_HANDLE adapter_handle,
  371. UINT required_adapter_status,
  372. UINT required_srb_status
  373. )
  374. {
  375. ADAPTER * adapter;
  376. /*
  377. * Adapter handle is invalid if greater than max number of adapter.
  378. * Can not set up error record but see driver_explain_error.
  379. */
  380. if (adapter_handle >= MAX_NUMBER_OF_ADAPTERS)
  381. {
  382. return FALSE;
  383. }
  384. /*
  385. * Adapter handle is invalid when no adapter structure for handle.
  386. * Can not set up error record but see driver_explain_error.
  387. */
  388. if (adapter_record[adapter_handle] == NULL)
  389. {
  390. return FALSE;
  391. }
  392. /*
  393. * Get pointer to adapter structure.
  394. */
  395. adapter = adapter_record[adapter_handle];
  396. /*
  397. * If fatal error already exists for adapter then fail. Do not not
  398. * change error code in this case. Fatal errors are - driver, hwi,
  399. * init, bring-up, adapter, auto_open.
  400. */
  401. if (macro_fatal_error(adapter->error_record.type))
  402. {
  403. return FALSE;
  404. }
  405. /*
  406. * Check if status of adapter is that required.
  407. */
  408. if (adapter->adapter_status != required_adapter_status)
  409. {
  410. if (required_adapter_status == ADAPTER_PREPARED_FOR_START)
  411. {
  412. /*
  413. * Required adapter status is ADAPTER_PREPARED_FOR_START.
  414. * Fill in error record and fail.
  415. */
  416. adapter->error_record.type = ERROR_TYPE_DRIVER;
  417. adapter->error_record.value = DRIVER_E_07_NOT_PREPARED;
  418. return FALSE;
  419. }
  420. else
  421. {
  422. /*
  423. * Required adapter status is ADAPTER_RUNNING.
  424. * Fill in error record and fail.
  425. */
  426. adapter->error_record.type = ERROR_TYPE_DRIVER;
  427. adapter->error_record.value = DRIVER_E_08_NOT_RUNNING;
  428. return FALSE;
  429. }
  430. }
  431. /*
  432. * Check if status of SRB is that required. Only do if particular
  433. * state is needed.
  434. */
  435. if ((required_srb_status != SRB_ANY_STATE) &&
  436. (adapter->srb_status != required_srb_status))
  437. {
  438. if (required_srb_status == SRB_FREE)
  439. {
  440. /*
  441. * Required srb status is SRB_FREE fill in error record
  442. * and fail.
  443. */
  444. adapter->error_record.type = ERROR_TYPE_DRIVER;
  445. adapter->error_record.value = DRIVER_E_09_SRB_NOT_FREE;
  446. return FALSE;
  447. }
  448. else
  449. {
  450. /*
  451. * Never require srb status to be SRB_NOT_FREE.
  452. */
  453. }
  454. }
  455. /*
  456. * Adapter handle and status are okay so complete successfully.
  457. */
  458. return TRUE;
  459. }
  460. /******** End of DRV_ERR.C *************************************************/