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.

1605 lines
49 KiB

4 years ago
  1. //**********************************************************************
  2. //**********************************************************************
  3. //
  4. // File Name: INIT.C
  5. //
  6. // Program Name: NetFlex NDIS 3.0 Miniport Driver
  7. //
  8. // Companion Files: None
  9. //
  10. // Function: This module contains the NetFlex Miniport Driver
  11. // interface routines called by the Wrapper and the
  12. // configuration manager.
  13. //
  14. // (c) Compaq Computer Corporation, 1992,1993,1994
  15. //
  16. // This file is licensed by Compaq Computer Corporation to Microsoft
  17. // Corporation pursuant to the letter of August 20, 1992 from
  18. // Gary Stimac to Mark Baber.
  19. //
  20. // History:
  21. //
  22. // 04/15/94 Robert Van Cleve - Converted from NDIS Mac Driver
  23. //
  24. //**********************************************************************
  25. //**********************************************************************
  26. //-------------------------------------
  27. // Include all general companion files
  28. //-------------------------------------
  29. #include <ndis.h>
  30. #include "tmsstrct.h"
  31. #include "macstrct.h"
  32. #include "adapter.h"
  33. #include "protos.h"
  34. //-----------------
  35. // Variables
  36. //-----------------
  37. MAC macgbls = {0};
  38. USHORT gbl_addingdualport = 0;
  39. USHORT gbl_portnumbertoadd = 0;
  40. USHORT RxIntRatio = 1;
  41. #ifdef XMIT_INTS
  42. USHORT TxIntRatio = 1;
  43. #endif
  44. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  45. //
  46. // Routine Name: DriverEntry
  47. //
  48. // Description: This routine is the initialization entry
  49. // point into the driver. In this routine,
  50. // the driver registers itself with the wrapper
  51. // and initializes the global variables for the
  52. // driver.
  53. //
  54. // Input: DriverObject Pointer to the driver object
  55. // assigned to the MAC driver.
  56. //
  57. // Output: Returns NDIS_STATUS_SUCCESS for a successful
  58. // completion and returns an error code if an
  59. // error is encountered.
  60. //
  61. // Called_By: OS
  62. //
  63. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  64. #pragma NDIS_INIT_FUNCTION(DriverEntry)
  65. NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
  66. IN PUNICODE_STRING RegistryPath)
  67. {
  68. NDIS_STATUS Status;
  69. //
  70. // The characteristics table
  71. //
  72. NDIS_MINIPORT_CHARACTERISTICS NetFlexChar;
  73. DebugPrint(1,("NetFlex: Dynamic Ratio Version\n"));
  74. #ifdef XMIT_INTS
  75. DebugPrint(1,("NetFlex: with Transmit Interrupts\n"));
  76. #endif
  77. //
  78. // Indicate that we are in initialization mode.
  79. //
  80. macgbls.Initializing = TRUE;
  81. //
  82. // Initialize the Wrapper
  83. //
  84. NdisMInitializeWrapper(
  85. &macgbls.mac_wrapper,
  86. DriverObject,
  87. RegistryPath,
  88. NULL);
  89. //
  90. // Store the driver object. We will need this for Unloading
  91. // the driver.
  92. macgbls.mac_object = DriverObject;
  93. //
  94. // Initialize the Miniport characteristics for the call to
  95. // NdisMRegisterMiniport.
  96. //
  97. NetFlexChar.MajorNdisVersion = NETFLEX_MAJ_VER;
  98. NetFlexChar.MinorNdisVersion = NETFLEX_MIN_VER;
  99. NetFlexChar.CheckForHangHandler = NetFlexCheckForHang;
  100. NetFlexChar.DisableInterruptHandler = NetFlexDisableInterrupt;
  101. NetFlexChar.EnableInterruptHandler = NetFlexEnableInterrupt;
  102. NetFlexChar.HaltHandler = NetFlexHalt;
  103. NetFlexChar.HandleInterruptHandler = NetFlexHandleInterrupt;
  104. NetFlexChar.InitializeHandler = NetFlexInitialize;
  105. NetFlexChar.ISRHandler = NetFlexISR;
  106. NetFlexChar.QueryInformationHandler = NetFlexQueryInformation;
  107. NetFlexChar.ReconfigureHandler = NULL;
  108. NetFlexChar.ResetHandler = NetFlexResetDispatch;
  109. NetFlexChar.SendHandler = NetFlexSend;
  110. NetFlexChar.SetInformationHandler = NetFlexSetInformation;
  111. NetFlexChar.TransferDataHandler = NetFlexTransferData;
  112. NetFlexChar.ReturnPacketHandler = NULL;
  113. NetFlexChar.SendPacketsHandler = NULL;
  114. NetFlexChar.AllocateCompleteHandler = NULL;
  115. //
  116. // Register this driver with NDIS
  117. //
  118. Status = NdisMRegisterMiniport( macgbls.mac_wrapper,
  119. &NetFlexChar,
  120. sizeof(NetFlexChar) );
  121. //
  122. // Set to non-initializing mode
  123. //
  124. macgbls.Initializing = FALSE;
  125. if (Status == NDIS_STATUS_SUCCESS)
  126. {
  127. return STATUS_SUCCESS;
  128. }
  129. //
  130. // We can only get here if something went wrong with registering
  131. // the driver or *ALL* of the adapters.
  132. //
  133. if ((macgbls.mac_adapters == NULL) &&
  134. (macgbls.mac_wrapper != NULL))
  135. {
  136. NdisTerminateWrapper(macgbls.mac_wrapper, NULL);
  137. }
  138. return STATUS_UNSUCCESSFUL;
  139. }
  140. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  141. //
  142. // Routine Name: NetFlexInitialize
  143. //
  144. // Description: See NDIS 3.0 Miniport spec.
  145. // Called to initialize each adapter
  146. //
  147. // Input: See NDIS 3.0 Miniport spec.
  148. //
  149. // Output: NDIS_STATUS_SUCCESS or NDIS_STATUS_PENDING
  150. //
  151. // Called_By: NDIS Miniport Wrapper
  152. //
  153. //----------------------------------------------------------------
  154. NDIS_STATUS
  155. NetFlexInitialize(
  156. OUT PNDIS_STATUS OpenErrorStatus,
  157. OUT PUINT SelectedMediumIndex,
  158. IN PNDIS_MEDIUM MediumArray,
  159. IN UINT MediumArraySize,
  160. IN NDIS_HANDLE MiniportAdapterHandle,
  161. IN NDIS_HANDLE ConfigurationHandle
  162. )
  163. {
  164. NDIS_STATUS status;
  165. PACB acb = NULL;
  166. PACB FirstHeadsAcb = NULL;
  167. USHORT baseaddr;
  168. UINT slot,i;
  169. NDIS_STRING portnumber = NDIS_STRING_CONST("PortNumber");
  170. NDIS_HANDLE ConfigHandle = NULL;
  171. NDIS_EISA_FUNCTION_INFORMATION EisaData;
  172. PNDIS_CONFIGURATION_PARAMETER cfgp;
  173. DebugPrint(2,("NetFlex: NetFlexInitialize\n"));
  174. //
  175. // Make sure we still have the wrapper, this is needed if an adapter
  176. // fails to open and there isn't any already opened, the halt routine
  177. // will remove the wrapper, and thus all adapters fail. I don't know
  178. // if this means that I should remove the code from the halt routine
  179. // or if I need to come up with aditional logic...
  180. //
  181. if (macgbls.mac_wrapper == NULL)
  182. {
  183. DebugPrint(0,("NetFlex: Don't have a handle to the Wrapper!\n"));
  184. status = NDIS_STATUS_FAILURE;
  185. goto ConfigError;
  186. }
  187. //
  188. // Check if we have a configuration handle before proceeding.
  189. //
  190. if (ConfigurationHandle == NULL)
  191. {
  192. DebugPrint(0,("NetFlex: Adapter not set up properly - no config handle\n"));
  193. status = NDIS_STATUS_FAILURE;
  194. goto ConfigError;
  195. }
  196. //
  197. // Open the configuration handle
  198. //
  199. NdisOpenConfiguration( &status,
  200. &ConfigHandle,
  201. ConfigurationHandle );
  202. if (status != NDIS_STATUS_SUCCESS)
  203. {
  204. DebugPrint(0,("NetFlex: Adapter not set up properly - couldn't open config\n"));
  205. status = NDIS_STATUS_FAILURE;
  206. ConfigHandle = NULL;
  207. goto ConfigError;
  208. }
  209. //
  210. // Find out what slot number the adapter associated with
  211. // this name is in.
  212. //
  213. NdisReadEisaSlotInformation( &status,
  214. ConfigurationHandle,
  215. &slot,
  216. &EisaData );
  217. if (status != NDIS_STATUS_SUCCESS)
  218. {
  219. DebugPrint(0,("NetFlex: Slot number not set up\n"));
  220. status = NDIS_ERROR_CODE_ADAPTER_NOT_FOUND;
  221. goto ConfigError;
  222. }
  223. baseaddr = slot * 0x1000;
  224. NdisReadConfiguration( &status,
  225. &cfgp,
  226. ConfigHandle,
  227. &portnumber,
  228. NdisParameterInteger);
  229. //
  230. // If we didn't read a portnumber, that means we're adding a
  231. // non-dual port card - NETFLX, MAPLE, CPQTOK
  232. //
  233. if (status != NDIS_STATUS_SUCCESS)
  234. {
  235. gbl_portnumbertoadd = 0;
  236. gbl_addingdualport = FALSE;
  237. }
  238. else
  239. {
  240. gbl_portnumbertoadd = (USHORT)cfgp->ParameterData.IntegerData;
  241. if (gbl_portnumbertoadd == PORT0)
  242. gbl_addingdualport = FALSE;
  243. else
  244. gbl_addingdualport = TRUE;
  245. }
  246. //
  247. // See if this adapter has been added. If so return an error.
  248. // The very first time we are called, acb should be NULL.
  249. //
  250. if (macgbls.DownloadCode == NULL)
  251. {
  252. // On Initial Init, We need to get the global stuff...
  253. //
  254. status = NetFlexInitGlobals();
  255. if (status != NDIS_STATUS_SUCCESS)
  256. {
  257. goto ConfigError;
  258. }
  259. }
  260. else
  261. {
  262. acb = macgbls.mac_adapters;
  263. while (acb)
  264. {
  265. if ( acb->acb_baseaddr == baseaddr)
  266. {
  267. //
  268. // If the card has the same slot and we're adding a dual port
  269. // then go to the next acb, otherwise it is an error.
  270. //
  271. if ( gbl_addingdualport )
  272. {
  273. FirstHeadsAcb = acb;
  274. acb = acb->acb_next;
  275. }
  276. else
  277. {
  278. DebugPrint(0,("NetFlex: Adapter already added\n"));
  279. status = NDIS_STATUS_FAILURE;
  280. goto ConfigError;
  281. }
  282. }
  283. else
  284. {
  285. acb = acb->acb_next;
  286. }
  287. }
  288. }
  289. //
  290. // Allocate adapter control block and register adapter.
  291. //
  292. status = NetFlexRegisterAdapter( &acb,
  293. FirstHeadsAcb,
  294. ConfigHandle,
  295. baseaddr,
  296. MiniportAdapterHandle
  297. );
  298. if (status != NDIS_STATUS_SUCCESS)
  299. {
  300. goto ConfigError;
  301. }
  302. //
  303. // Search for the medium type supported matches adapter configuration
  304. //
  305. for (i = 0; i < MediumArraySize; i++)
  306. {
  307. if (MediumArray[i] == acb->acb_gen_objs.media_type_in_use)
  308. {
  309. *SelectedMediumIndex = i;
  310. break;
  311. }
  312. }
  313. //
  314. // If supported medium not found. Return an error.
  315. //
  316. if (i == MediumArraySize)
  317. {
  318. DebugPrint(0,("NetFlex: No supported media found!\n"));
  319. status = NDIS_STATUS_UNSUPPORTED_MEDIA;
  320. goto ConfigError;
  321. }
  322. //
  323. // Now, initialize the board and the data structures.
  324. // glb_ErrorCode will be set if there was an error.
  325. //
  326. status = NetFlexBoardInitandReg(acb,&EisaData);
  327. if (status != NDIS_STATUS_SUCCESS)
  328. {
  329. DebugPrint(0,("NF(%d): Board Init and Reg Failed\n",acb->anum));
  330. goto ConfigError;
  331. }
  332. ConfigError:
  333. //
  334. // Were there any errors?
  335. //
  336. if (status != NDIS_STATUS_SUCCESS)
  337. {
  338. //
  339. // if we allocated an acb, we need to get rid of it...
  340. //
  341. if (acb != NULL)
  342. {
  343. //
  344. // Since there was an acb, the error data and section code will be in
  345. // the acb instead of the globals.
  346. //
  347. NetFlexDeregisterAdapter(acb);
  348. }
  349. DebugPrint(0, ("NF: NetFlexInitialize Failed!\n"));
  350. }
  351. if (ConfigHandle != NULL)
  352. {
  353. NdisCloseConfiguration(ConfigHandle);
  354. }
  355. return status;
  356. }
  357. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  358. //
  359. // Routine Name: NetFlexRegisterAdapter
  360. //
  361. // Description: This routine allocates memory for the adapter
  362. // control block and registers with the wrapper.
  363. //
  364. // Input: acbp - pointer to adapter control block
  365. //
  366. //
  367. // Output: Returns NDIS_STATUS_SUCCESS for a successful
  368. // completion. Otherwise, an error code is
  369. // returned.
  370. //
  371. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  372. NDIS_STATUS
  373. NetFlexRegisterAdapter(
  374. PACB *acbp,
  375. PACB FirstHeadsAcb,
  376. NDIS_HANDLE ConfigHandle,
  377. USHORT baseaddr,
  378. NDIS_HANDLE MiniportAdapterHandle
  379. )
  380. {
  381. PACB acb;
  382. USHORT cpqid, boardid, reg_value;
  383. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  384. //
  385. // Allocate the Memory for the adapter's acb.
  386. //
  387. NdisAllocateMemory( (PVOID *)&acb,
  388. (UINT) (sizeof (ACB)),
  389. (UINT) 0,
  390. NetFlexHighestAddress );
  391. //
  392. // If we did not get the memory, flag any error.
  393. //
  394. if (acb == NULL)
  395. {
  396. return(NDIS_STATUS_RESOURCES);
  397. }
  398. //
  399. // Zero out the memory. Save configuration handle.
  400. //
  401. NdisZeroMemory(acb, sizeof (ACB));
  402. acb->acb_state = AS_REGISTERING;
  403. acb->acb_baseaddr = baseaddr;
  404. //
  405. // Indicate that we are initializing the adapter.
  406. //
  407. acb->AdapterInitializing = TRUE;
  408. //
  409. // link in this acb
  410. //
  411. *acbp = acb;
  412. macgbls.mac_numadpts++;
  413. #if (DBG || DBGPRINT)
  414. acb->anum = macgbls.mac_numadpts;
  415. #endif
  416. //
  417. // save reference to our Miniport Handle
  418. //
  419. acb->acb_handle = MiniportAdapterHandle;
  420. //
  421. // Initialize reset timer
  422. //
  423. NdisMInitializeTimer(
  424. &acb->ResetTimer,
  425. acb->acb_handle,
  426. (PVOID) NetFlexResetHandler,
  427. (PVOID) acb );
  428. //
  429. // Initialize DPC timer
  430. //
  431. NdisMInitializeTimer(
  432. &acb->DpcTimer,
  433. acb->acb_handle,
  434. (PVOID) NetFlexDeferredTimer,
  435. (PVOID) acb );
  436. //
  437. // Set the attributes for this adapter
  438. //
  439. NdisMSetAttributes( MiniportAdapterHandle,
  440. (NDIS_HANDLE) acb,
  441. TRUE,
  442. NdisInterfaceEisa );
  443. //
  444. // Register our shutdown handler.
  445. //
  446. NdisMRegisterAdapterShutdownHandler(
  447. MiniportAdapterHandle, // wrapper miniport handle.
  448. acb, // shutdown context.
  449. NetFlexShutdown // shutdown handler.
  450. );
  451. //
  452. // Reserve this adapters IO ports, if they haven't allready been added by the first
  453. // head...
  454. //
  455. if (gbl_addingdualport)
  456. {
  457. if (FirstHeadsAcb == NULL)
  458. {
  459. // This is the first instance of a head on a dual port board,
  460. // so register all the io ports for both heads.
  461. acb->FirstHeadsAcb = acb;
  462. //
  463. // grab ports z000 - z02f
  464. //
  465. Status = NdisMRegisterIoPortRange( (PVOID *)&acb->BasePorts,
  466. MiniportAdapterHandle,
  467. baseaddr,
  468. NUM_DUALHEAD_CFG_PORTS );
  469. if (Status == NDIS_STATUS_SUCCESS)
  470. {
  471. // Save the master base port addresses
  472. //
  473. acb->MasterBasePorts = acb->BasePorts;
  474. // grab zc80 - zc85
  475. //
  476. Status = NdisMRegisterIoPortRange( (PVOID *)&acb->ConfigPorts,
  477. MiniportAdapterHandle,
  478. baseaddr + CFG_PORT_OFFSET,
  479. NUM_CFG_PORTS );
  480. if (Status == NDIS_STATUS_SUCCESS)
  481. {
  482. // grab zc63 - zc67
  483. //
  484. Status = NdisMRegisterIoPortRange( (PVOID *)&acb->ExtConfigPorts,
  485. MiniportAdapterHandle,
  486. baseaddr + EXTCFG_PORT_OFFSET,
  487. NUM_EXTCFG_PORTS );
  488. }
  489. }
  490. }
  491. else
  492. {
  493. // Get the pointers to the other head's ports, which are already mapped.
  494. //
  495. acb->FirstHeadsAcb = FirstHeadsAcb;
  496. acb->BasePorts = FirstHeadsAcb->MasterBasePorts;
  497. acb->ConfigPorts = FirstHeadsAcb->ConfigPorts;
  498. acb->ExtConfigPorts = FirstHeadsAcb->ExtConfigPorts;
  499. acb->MasterBasePorts= FirstHeadsAcb->MasterBasePorts;
  500. Status = NDIS_STATUS_SUCCESS;
  501. }
  502. }
  503. else
  504. {
  505. // grab ports z000 - z01f
  506. //
  507. Status = NdisMRegisterIoPortRange( (PVOID *)&acb->BasePorts,
  508. MiniportAdapterHandle,
  509. baseaddr,
  510. NUM_BASE_PORTS );
  511. if (Status == NDIS_STATUS_SUCCESS)
  512. {
  513. // grab zc80 - zc85
  514. //
  515. Status = NdisMRegisterIoPortRange( (PVOID *)&acb->ConfigPorts,
  516. MiniportAdapterHandle,
  517. baseaddr + CFG_PORT_OFFSET,
  518. NUM_CFG_PORTS );
  519. if (Status == NDIS_STATUS_SUCCESS)
  520. {
  521. // grab zc63 - zc67
  522. //
  523. Status = NdisMRegisterIoPortRange( (PVOID *)&acb->ExtConfigPorts,
  524. MiniportAdapterHandle,
  525. baseaddr + EXTCFG_PORT_OFFSET,
  526. NUM_EXTCFG_PORTS );
  527. }
  528. }
  529. }
  530. //
  531. // If the registration fails, free up the memory we allocated
  532. // for the acb.
  533. //
  534. if (Status != NDIS_STATUS_SUCCESS)
  535. {
  536. DebugPrint(0,("NF: Registration FAILED for slot#%d\n",(baseaddr / 1000)));
  537. goto HandleRegisterError;
  538. }
  539. //
  540. // Read in the company product id.
  541. //
  542. NdisRawReadPortUshort( acb->ConfigPorts, (PUSHORT) &cpqid);
  543. //
  544. // Read in the board product id.
  545. //
  546. NdisRawReadPortUshort( acb->ConfigPorts + 2, (PUSHORT) &boardid);
  547. //
  548. // Does it have a Compaq id?
  549. //
  550. // NETFLEX_ID covers NetFlex and NetFlex-2
  551. // CPQTOK_ID covers DualSpeed and 16/4 Token-Ring
  552. if ( !( (cpqid == COMPAQ_ID) &&
  553. ( ((boardid & NETFLEX_REVMASK) == NETFLEX_ID) ||
  554. ((boardid & NETFLEX_REVMASK) == CPQTOK_ID) ||
  555. ((boardid & NETFLEX_REVMASK) == RODAN_ID) ||
  556. ((boardid & NETFLEX_REVMASK) == BONSAI_ID)
  557. ) ) )
  558. {
  559. //
  560. // Not a Compaq id.
  561. //
  562. DebugPrint(0,("NF(%d): No Compaq adapter found\n",acb->anum));
  563. Status = NDIS_STATUS_ADAPTER_NOT_FOUND;
  564. goto HandleRegisterError;
  565. }
  566. //
  567. // Make sure this is our board.
  568. //
  569. NdisRawReadPortUshort( acb->ConfigPorts + CFG_REGISTER, &reg_value);
  570. if (!(reg_value & CFG_ENABLE))
  571. {
  572. DebugPrint(0,("NF(%d): Adapter is not enabled\n",acb->anum));
  573. DebugPrint(0,("NF(%d): Board Test Failed\n",acb->anum));
  574. Status = NDIS_STATUS_ADAPTER_NOT_FOUND;
  575. goto HandleRegisterError;
  576. }
  577. //
  578. // Check to see if it's a card with FPA or a dual port adapter
  579. //
  580. if ( (boardid == MAPLE_ID) ||
  581. (boardid == DURANGO_ID) )
  582. {
  583. DebugPrint(1,("NF(%d): We're adding a card using FPA ! \n",acb->anum));
  584. acb->acb_usefpa = TRUE;
  585. }
  586. else if ( ((boardid & NETFLEX_REVMASK) == BONSAI_ID) ||
  587. ((boardid & NETFLEX_REVMASK) == RODAN_ID ) )
  588. {
  589. acb->acb_usefpa = TRUE;
  590. acb->acb_dualport = TRUE;
  591. acb->acb_portnumber = gbl_portnumbertoadd;
  592. DebugPrint(1,("NF(%d): We're adding BONSAI or RODAN port #%d\n",acb->anum,acb->acb_portnumber));
  593. }
  594. //
  595. // Set up the Config register location and the extended sif address
  596. // register location.
  597. //
  598. acb->AdapterConfigPort = acb->ConfigPorts + CFG_REGISTER;
  599. if (acb->acb_dualport && (acb->acb_portnumber == PORT2) )
  600. {
  601. //
  602. // Align the ports right for the head #2's ports
  603. //
  604. acb->BasePorts = acb->FirstHeadsAcb->BasePorts + DUALHEAD_CFG_PORT_OFFSET;
  605. if ((boardid & NETFLEX_REVMASK) == RODAN_ID)
  606. {
  607. acb->AdapterConfigPort = acb->MasterBasePorts + CFG_REGRODAN;
  608. }
  609. }
  610. acb->SifDataPort = acb->BasePorts + SIF_DATA_OFF; /* SIF data register */
  611. acb->SifDIncPort = acb->BasePorts + SIF_DINC_OFF; /* SIF data autoincrment reg */
  612. acb->SifAddrPort = acb->BasePorts + SIF_ADDR_OFF; /* SIF address register */
  613. acb->SifIntPort = acb->BasePorts + SIF_INT_OFF; /* SIF interrupt register */
  614. acb->SifActlPort = acb->BasePorts + SIF_ACTL_OFF; /* SIF ACTL register */
  615. acb->SifAddrxPort = acb->BasePorts + SIF_ACTL_EXT_OFF;/* SIF SIF extended address reg */
  616. //
  617. // Save the Board ID
  618. //
  619. acb->acb_boardid = boardid;
  620. //
  621. // Do a reset to the adapter
  622. //
  623. NdisRawWritePortUshort(acb->SifActlPort, 0xEE);
  624. //
  625. // Wait 15 milliseconds to let the reset take place.
  626. //
  627. NdisStallExecution((UINT)15000); // Wait 15 milliseconds
  628. //
  629. // Get the Network type and speed from the eisa config info.
  630. //
  631. NetFlexSetupNetType(acb);
  632. //
  633. // Read configuration parameters from the registry if there are any
  634. //
  635. Status = NetFlexReadConfigurationParameters(acb,ConfigHandle);
  636. if (Status != NDIS_STATUS_SUCCESS)
  637. {
  638. DebugPrint(0,("NF(%d): NetFlexReadConfigurationParameters Failed\n",acb->anum));
  639. Status = NDIS_STATUS_RESOURCES;
  640. goto HandleRegisterError;
  641. }
  642. HandleRegisterError:
  643. if (Status != NDIS_STATUS_SUCCESS)
  644. {
  645. if (acb!=NULL)
  646. {
  647. if (acb->acb_parms != NULL)
  648. {
  649. NdisFreeMemory( (PVOID) acb->acb_parms, (UINT) sizeof(PNETFLEX_PARMS), (UINT) 0);
  650. }
  651. *acbp = NULL;
  652. NdisFreeMemory( (PVOID) acb, (UINT) sizeof(ACB), (UINT) 0);
  653. }
  654. }
  655. return(Status);
  656. }
  657. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  658. //
  659. // Routine Name: NetFlexReadConfigurationParameters
  660. //
  661. // Description: This routine reads configuration parameters
  662. // set by the user in the registry if exist.
  663. //
  664. // Input: acb - Adapter Context
  665. // ConfigHandle
  666. //
  667. // Output: Returns NDIS_STATUS_SUCCESS for a successful
  668. // completion. Otherwise, an error code is
  669. // returned.
  670. //
  671. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  672. NDIS_STATUS
  673. NetFlexReadConfigurationParameters(
  674. PACB acb,
  675. NDIS_HANDLE ConfigHandle
  676. )
  677. {
  678. NDIS_STATUS status;
  679. PNETFLEX_PARMS pParms = NULL;
  680. ULONG length;
  681. PVOID NetworkAddress;
  682. BOOLEAN WriteError;
  683. PNDIS_CONFIGURATION_PARAMETER cfgp;
  684. ULONG netspeed = acb->acb_gen_objs.link_speed;
  685. NDIS_STRING maxreceives = NDIS_STRING_CONST("MAXRECEIVES");
  686. NDIS_STRING productid = NDIS_STRING_CONST("PRODUCTID");
  687. NDIS_STRING earlyrelease = NDIS_STRING_CONST("EARLYRELEASE");
  688. NDIS_STRING maxtransmits = NDIS_STRING_CONST("MAXTRANSMITS");
  689. NDIS_STRING maxframesz = NDIS_STRING_CONST("MAXFRAMESIZE");
  690. NDIS_STRING maxmulticast = NDIS_STRING_CONST("MAXMULTICAST");
  691. NDIS_STRING maxinternalreqs = NDIS_STRING_CONST("MAXINTERNALREQS");
  692. NDIS_STRING maxinternalbufs = NDIS_STRING_CONST("MAXINTERNALBUFS");
  693. NDIS_STRING maxtxbuf = NDIS_STRING_CONST("MAXTXBUF");
  694. NDIS_STRING mintxbuf = NDIS_STRING_CONST("MINTXBUF");
  695. NDIS_STRING extremecheckforhang = NDIS_STRING_CONST("ExtremeCheckForHang");
  696. #ifdef XMIT_INTS
  697. NDIS_STRING xmitintratio = NDIS_STRING_CONST("TXINTRATIO");
  698. #endif
  699. NDIS_STRING rcvintratio = NDIS_STRING_CONST("RXINTRATIO");
  700. //
  701. // Allocate the Memory for the adapter's parms structure.
  702. //
  703. NdisAllocateMemory( (PVOID *)&pParms,
  704. (UINT) (sizeof (NETFLEX_PARMS)),
  705. (UINT) 0,
  706. NetFlexHighestAddress );
  707. //
  708. // If we did not get the memory, flag any error.
  709. //
  710. if (pParms == NULL)
  711. {
  712. return(NDIS_STATUS_RESOURCES);
  713. }
  714. NdisMoveMemory(pParms, &NetFlex_Defaults, sizeof(NETFLEX_PARMS));
  715. //
  716. // See if the user has specified the maximum number of internal
  717. // transmit buffers
  718. //
  719. NdisReadConfiguration( &status,
  720. &cfgp,
  721. ConfigHandle,
  722. &maxinternalbufs,
  723. NdisParameterInteger);
  724. if (status == NDIS_STATUS_SUCCESS)
  725. {
  726. if ( (cfgp->ParameterData.IntegerData <= MAX_INTERNALBUFS) &&
  727. (cfgp->ParameterData.IntegerData >= MIN_INTERNALBUFS) )
  728. {
  729. pParms->utd_maxinternalbufs = (USHORT)cfgp->ParameterData.IntegerData;
  730. }
  731. else
  732. {
  733. // The parameter is out of range.
  734. DebugPrint(0,("NF(%d): MAXINTERNALBUFS parameter is out of range, using default\n",acb->anum));
  735. NdisWriteErrorLogEntry( acb->acb_handle,
  736. EVENT_NDIS_MAXINTERNALBUFS_ERROR,
  737. 2,
  738. (ULONG)cfgp->ParameterData.IntegerData,
  739. (ULONG)pParms->utd_maxinternalbufs);
  740. }
  741. }
  742. //
  743. // Read the network specific information from the registry
  744. //
  745. if (acb->acb_gen_objs.media_type_in_use == NdisMedium802_5)
  746. {
  747. // TokenRing
  748. //
  749. //
  750. // See if early token release has been selected.
  751. //
  752. if (netspeed == 16)
  753. {
  754. // Default to early token release.
  755. //
  756. pParms->utd_open.OPEN_Options |= SWAPS(OOPTS_ETR);
  757. NdisReadConfiguration( &status,
  758. &cfgp,
  759. ConfigHandle,
  760. &earlyrelease,
  761. NdisParameterInteger );
  762. if (status == NDIS_STATUS_SUCCESS)
  763. {
  764. if ( cfgp->ParameterData.IntegerData == 0)
  765. {
  766. // The user does not want early token release.
  767. //
  768. pParms->utd_open.OPEN_Options &= SWAPS((~OOPTS_ETR));
  769. }
  770. }
  771. }
  772. //
  773. // Set the framehold bit so that we can allow promiscuous mode
  774. // to be set later on. We don't necessarily have to set
  775. // promiscuous mode but if we do, this is a requirement.
  776. //
  777. pParms->utd_open.OPEN_Options |= SWAPS(OOPTS_FHOLD);
  778. //
  779. // Set MaxTransmits
  780. //
  781. pParms->utd_numsmallbufs = pParms->utd_maxtrans = DF_XMITS_TR;
  782. //
  783. // See if the user has specified the maximum number of transmit
  784. // lists supported.
  785. //
  786. NdisReadConfiguration( &status,
  787. &cfgp,
  788. ConfigHandle,
  789. &maxtransmits,
  790. NdisParameterInteger);
  791. if (status == NDIS_STATUS_SUCCESS)
  792. {
  793. if ( (cfgp->ParameterData.IntegerData <= MAX_XMITS_TR) &&
  794. (cfgp->ParameterData.IntegerData >= MIN_XMITS) )
  795. {
  796. pParms->utd_numsmallbufs = pParms->utd_maxtrans = (USHORT)cfgp->ParameterData.IntegerData;
  797. }
  798. else
  799. {
  800. // The parameter is out of range.
  801. DebugPrint(0,("NF(%d): MAXTRANSMITS parameter is out of range, using default\n",acb->anum));
  802. NdisWriteErrorLogEntry( acb->acb_handle,
  803. EVENT_NDIS_MAXTRANSMITS_ERROR,
  804. 2,
  805. (ULONG)cfgp->ParameterData.IntegerData,
  806. (ULONG)pParms->utd_maxtrans);
  807. }
  808. }
  809. //
  810. // See if the user has specified the maximum frame size.
  811. //
  812. pParms->utd_maxframesz = DF_FRAMESIZE_TR;
  813. WriteError = FALSE;
  814. NdisReadConfiguration( &status,
  815. &cfgp,
  816. ConfigHandle,
  817. &maxframesz,
  818. NdisParameterInteger);
  819. if (status == NDIS_STATUS_SUCCESS)
  820. {
  821. if (cfgp->ParameterData.IntegerData < MIN_FRAMESIZE)
  822. {
  823. pParms->utd_maxframesz = MIN_FRAMESIZE;
  824. WriteError = TRUE;
  825. }
  826. else if (netspeed == 16)
  827. {
  828. // 16 Mb
  829. //
  830. if (cfgp->ParameterData.IntegerData > MAX_FRAMESIZE_TR16)
  831. {
  832. pParms->utd_maxframesz = MAX_FRAMESIZE_TR16;
  833. WriteError = TRUE;
  834. }
  835. else
  836. {
  837. pParms->utd_maxframesz = (USHORT)cfgp->ParameterData.IntegerData;
  838. }
  839. }
  840. //
  841. // 4Mb
  842. //
  843. else if (cfgp->ParameterData.IntegerData > MAX_FRAMESIZE_TR4)
  844. {
  845. pParms->utd_maxframesz = MAX_FRAMESIZE_TR4;
  846. WriteError = TRUE;
  847. }
  848. else
  849. {
  850. pParms->utd_maxframesz = (USHORT)cfgp->ParameterData.IntegerData;
  851. }
  852. if (WriteError)
  853. {
  854. // The parameter is out of range.
  855. NdisWriteErrorLogEntry( acb->acb_handle,
  856. EVENT_NDIS_MAXFRAMESIZE_ERROR,
  857. 2,
  858. (ULONG)cfgp->ParameterData.IntegerData,
  859. (ULONG)pParms->utd_maxframesz);
  860. DebugPrint(0,("NF(%d): MaxFrameSize parameter is out of range, using default\n",acb->anum));
  861. }
  862. }
  863. //
  864. // See if the user has specified the maximum number of Receive
  865. // lists supported.
  866. //
  867. pParms->utd_maxrcvs = DF_RCVS_TR;
  868. NdisReadConfiguration( &status,
  869. &cfgp,
  870. ConfigHandle,
  871. &maxreceives,
  872. NdisParameterInteger);
  873. if (status == NDIS_STATUS_SUCCESS)
  874. {
  875. if ( (cfgp->ParameterData.IntegerData <= MAX_RCVS_TR) &&
  876. (cfgp->ParameterData.IntegerData >= MIN_RCVS) )
  877. {
  878. pParms->utd_maxrcvs = (USHORT)cfgp->ParameterData.IntegerData;
  879. }
  880. else
  881. {
  882. // The parameter is out of range.
  883. NdisWriteErrorLogEntry( acb->acb_handle,
  884. EVENT_NDIS_MAXRECEIVES_ERROR,
  885. 2,
  886. (ULONG)cfgp->ParameterData.IntegerData,
  887. (ULONG)pParms->utd_maxrcvs);
  888. DebugPrint(0,("NF(%d): MAXReceives parameter is out of range, using default\n",acb->anum));
  889. }
  890. }
  891. //
  892. // Adjust Number of Lists based on size of Max TR Frame Size
  893. //
  894. //
  895. // For every frame size which is greater than a multiple of 4096,
  896. // decrease number of transmits, Receives, and internal buffers.
  897. //
  898. if (pParms->utd_maxframesz > DF_FRAMESIZE_TR)
  899. {
  900. if (pParms->utd_maxframesz < ( (DF_FRAMESIZE_TR*2)+2) )
  901. {
  902. pParms->utd_maxtrans = MAX_XMITS_TR-2; /* 6 xmits, 30 mapregs */
  903. pParms->utd_maxrcvs = MAX_XMITS_TR-2;
  904. pParms->utd_maxinternalbufs = pParms->utd_maxtrans / 2;
  905. }
  906. else
  907. {
  908. pParms->utd_maxtrans = MAX_XMITS_TR-4; /* 4 xmits, 25 mapregs */
  909. pParms->utd_maxrcvs = MAX_XMITS_TR-4;
  910. pParms->utd_maxinternalbufs = pParms->utd_maxtrans / 2;
  911. }
  912. }
  913. }
  914. else
  915. {
  916. // Ethernet
  917. //
  918. //
  919. // Set the framehold bit so that we can allow promiscuous mode
  920. // to be set later on. We don't necessarily have to set
  921. // promiscuous mode but if we do, this is a requirement.
  922. //
  923. pParms->utd_open.OPEN_Options |= SWAPS(OOPTS_REQ + OOPTS_FHOLD);
  924. pParms->utd_maxframesz = DF_FRAMESIZE_ETH;
  925. //
  926. // See if the user has specified the maximum number of multicast
  927. // addresses supported.
  928. //
  929. pParms->utd_maxmulticast = DF_MULTICASTS;
  930. NdisReadConfiguration( &status,
  931. &cfgp,
  932. ConfigHandle,
  933. &maxmulticast,
  934. NdisParameterInteger);
  935. if (status == NDIS_STATUS_SUCCESS)
  936. {
  937. if ( (cfgp->ParameterData.IntegerData <= MAX_MULTICASTS) &&
  938. (cfgp->ParameterData.IntegerData >= MIN_MULTICASTS) )
  939. {
  940. pParms->utd_maxmulticast = (USHORT)cfgp->ParameterData.IntegerData;
  941. }
  942. else
  943. {
  944. // The parameter is out of range.
  945. DebugPrint(0,("NF(%d): MAXMULTICAST Parameter is out of range, using default\n",acb->anum));
  946. NdisWriteErrorLogEntry( acb->acb_handle,
  947. EVENT_NDIS_MAXMULTICAST_ERROR,
  948. 2,
  949. (ULONG)cfgp->ParameterData.IntegerData,
  950. (ULONG)pParms->utd_maxmulticast);
  951. }
  952. }
  953. //
  954. // See if the user has specified the maximum number of transmit lists.
  955. //
  956. pParms->utd_numsmallbufs = pParms->utd_maxtrans = DF_XMITS_ETH;
  957. NdisReadConfiguration( &status,
  958. &cfgp,
  959. ConfigHandle,
  960. &maxtransmits,
  961. NdisParameterInteger);
  962. if (status == NDIS_STATUS_SUCCESS)
  963. {
  964. if ( (cfgp->ParameterData.IntegerData <= MAX_XMITS_ETH) &&
  965. (cfgp->ParameterData.IntegerData >= MIN_XMITS) )
  966. {
  967. pParms->utd_numsmallbufs = pParms->utd_maxtrans = (USHORT)cfgp->ParameterData.IntegerData;
  968. }
  969. else
  970. {
  971. // The parameter is out of range.
  972. DebugPrint(0,("NF(%d): MAXTRANSMITS parameter is out of range, using default\n",acb->anum));
  973. NdisWriteErrorLogEntry( acb->acb_handle,
  974. EVENT_NDIS_MAXTRANSMITS_ERROR,
  975. 2,
  976. (ULONG)cfgp->ParameterData.IntegerData,
  977. (ULONG)pParms->utd_maxtrans);
  978. }
  979. }
  980. //
  981. // See if the user has specified the maximum frame size.
  982. //
  983. WriteError = FALSE;
  984. pParms->utd_maxframesz = MAX_FRAMESIZE_ETH;
  985. NdisReadConfiguration( &status,
  986. &cfgp,
  987. ConfigHandle,
  988. &maxframesz,
  989. NdisParameterInteger);
  990. if (status == NDIS_STATUS_SUCCESS)
  991. {
  992. if (cfgp->ParameterData.IntegerData < MIN_FRAMESIZE)
  993. {
  994. pParms->utd_maxframesz = MIN_FRAMESIZE;
  995. WriteError = TRUE;
  996. }
  997. else if (cfgp->ParameterData.IntegerData > MAX_FRAMESIZE_ETH)
  998. {
  999. pParms->utd_maxframesz = MAX_FRAMESIZE_ETH;
  1000. WriteError = TRUE;
  1001. }
  1002. else
  1003. {
  1004. pParms->utd_maxframesz = (USHORT)cfgp->ParameterData.IntegerData;
  1005. }
  1006. if (WriteError)
  1007. {
  1008. // The parameter is out of range.
  1009. NdisWriteErrorLogEntry( acb->acb_handle,
  1010. EVENT_NDIS_MAXFRAMESIZE_ERROR,
  1011. 2,
  1012. (ULONG)cfgp->ParameterData.IntegerData,
  1013. (ULONG)pParms->utd_maxframesz);
  1014. DebugPrint(0,("NF(%d): MaxFrameSize parameter is out of range, using default\n",acb->anum));
  1015. }
  1016. }
  1017. //
  1018. // See if the user has specified the maximum number of Receive
  1019. // lists supported.
  1020. //
  1021. pParms->utd_maxrcvs = DF_RCVS_ETH;
  1022. NdisReadConfiguration( &status,
  1023. &cfgp,
  1024. ConfigHandle,
  1025. &maxreceives,
  1026. NdisParameterInteger);
  1027. if (status == NDIS_STATUS_SUCCESS)
  1028. {
  1029. if ( (cfgp->ParameterData.IntegerData <= MAX_RCVS_ETH) &&
  1030. (cfgp->ParameterData.IntegerData >= MIN_RCVS) )
  1031. {
  1032. pParms->utd_maxrcvs = (USHORT)cfgp->ParameterData.IntegerData;
  1033. }
  1034. else
  1035. {
  1036. // The parameter is out of range.
  1037. NdisWriteErrorLogEntry( acb->acb_handle,
  1038. EVENT_NDIS_MAXRECEIVES_ERROR,
  1039. (ULONG)cfgp->ParameterData.IntegerData,
  1040. (ULONG)pParms->utd_maxrcvs);
  1041. DebugPrint(0,("NF(%d): MAXReceives parameter is out of range, using default\n",acb->anum));
  1042. }
  1043. }
  1044. }
  1045. DebugPrint(1,("NF(%d): MaxFrameSize = %d\n",acb->anum,pParms->utd_maxframesz));
  1046. DebugPrint(1,("NF(%d): MaxTransmits = %d\n",acb->anum,pParms->utd_maxtrans));
  1047. DebugPrint(1,("NF(%d): MaxReceives = %d\n",acb->anum,pParms->utd_maxrcvs));
  1048. //
  1049. // Common Configuration settings for both Ethernet and TokenRing
  1050. //
  1051. //
  1052. // See if the user has specified extreme checking for adapter hang.
  1053. //
  1054. NdisReadConfiguration(&status,
  1055. &cfgp,
  1056. ConfigHandle,
  1057. &extremecheckforhang,
  1058. NdisParameterInteger);
  1059. if ((NDIS_STATUS_SUCCESS == status) &&
  1060. (cfgp->ParameterData.IntegerData != 0))
  1061. {
  1062. //
  1063. // They want the extreme checking to see if this adapter is
  1064. // hung.
  1065. //
  1066. pParms->utd_extremecheckforhang = TRUE;
  1067. }
  1068. //
  1069. // See if the user has specified the maximum number of adapter transmit buffers.
  1070. //
  1071. NdisReadConfiguration( &status,
  1072. &cfgp,
  1073. ConfigHandle,
  1074. &maxtxbuf,
  1075. NdisParameterInteger);
  1076. //
  1077. // Set default Transmist_Buffer_Maximum_Count based on the max frame size * 2 tx lists
  1078. //
  1079. pParms->utd_open.OPEN_Xbufmax = ((pParms->utd_maxframesz / 1024) + 1 ) * 2;
  1080. if (status == NDIS_STATUS_SUCCESS)
  1081. {
  1082. // Make Sure the value doesn't preclude us from transmiting a max frame size
  1083. //
  1084. if (cfgp->ParameterData.IntegerData > (UINT) (pParms->utd_maxframesz / 1024))
  1085. {
  1086. pParms->utd_open.OPEN_Xbufmax = (UCHAR)cfgp->ParameterData.IntegerData;
  1087. }
  1088. else
  1089. {
  1090. // The parameter is out of range.
  1091. DebugPrint(0,("NF(%d): MaxTXBuf parameter is out of range, using default\n",acb->anum));
  1092. }
  1093. }
  1094. DebugPrint(1,("NF(%d): MaxTXBuf = 0x%x\n",acb->anum,pParms->utd_open.OPEN_Xbufmax));
  1095. //
  1096. // See if the user has specified the minimum number of adapter transmit buffers.
  1097. //
  1098. NdisReadConfiguration( &status,
  1099. &cfgp,
  1100. ConfigHandle,
  1101. &mintxbuf,
  1102. NdisParameterInteger);
  1103. //
  1104. // Set default Transmist_Buffer_Minimum_Count based on the max
  1105. //
  1106. pParms->utd_open.OPEN_Xbufmin = pParms->utd_open.OPEN_Xbufmax;
  1107. if (status == NDIS_STATUS_SUCCESS)
  1108. {
  1109. if ((cfgp->ParameterData.IntegerData >= 0) &&
  1110. (cfgp->ParameterData.IntegerData <= pParms->utd_open.OPEN_Xbufmax) )
  1111. {
  1112. pParms->utd_open.OPEN_Xbufmin = (UCHAR)cfgp->ParameterData.IntegerData;
  1113. }
  1114. else
  1115. {
  1116. // The parameter is out of range.
  1117. DebugPrint(0,("NF(%d): MinTXBuf parameter is out of range, using default\n",acb->anum));
  1118. }
  1119. }
  1120. DebugPrint(1,("NF(%d): MinTXBuf = 0x%x\n",acb->anum,pParms->utd_open.OPEN_Xbufmin));
  1121. //
  1122. // See if the user has specified the maximum number of internal
  1123. // requests supported.
  1124. //
  1125. NdisReadConfiguration( &status,
  1126. &cfgp,
  1127. ConfigHandle,
  1128. &maxinternalreqs,
  1129. NdisParameterInteger);
  1130. if (status == NDIS_STATUS_SUCCESS)
  1131. {
  1132. if ( (cfgp->ParameterData.IntegerData <= MAX_INTERNALREQS) &&
  1133. (cfgp->ParameterData.IntegerData >= MIN_INTERNALREQS) )
  1134. {
  1135. pParms->utd_maxinternalreqs = (USHORT)cfgp->ParameterData.IntegerData;
  1136. }
  1137. else
  1138. {
  1139. // The parameter is out of range.
  1140. DebugPrint(0,("NF(%d): MAXINTERNALREQS parameter is out of range, using default\n",acb->anum));
  1141. }
  1142. }
  1143. //
  1144. // See if the user has specified the node address
  1145. //
  1146. NdisReadNetworkAddress( &status,
  1147. &NetworkAddress,
  1148. &length,
  1149. ConfigHandle );
  1150. if ((length == NET_ADDR_SIZE) && (status == NDIS_STATUS_SUCCESS))
  1151. {
  1152. NdisMoveMemory((PUCHAR)pParms->utd_open.OPEN_NodeAddr,
  1153. (PUCHAR)NetworkAddress,
  1154. NET_ADDR_SIZE);
  1155. }
  1156. else
  1157. {
  1158. DebugPrint(1,("NF(%d): Error in NdisReadNetworkAddress or none specified\n",acb->anum));
  1159. }
  1160. //
  1161. // See if the user has specified the product id
  1162. //
  1163. NdisReadConfiguration( &status,
  1164. &cfgp,
  1165. ConfigHandle,
  1166. &productid,NdisParameterString );
  1167. if (status == NDIS_STATUS_SUCCESS)
  1168. {
  1169. status = NetFlexAsciiToHex( &(cfgp->ParameterData.StringData),
  1170. (PUCHAR)pParms->utd_open.OPEN_ProdID,
  1171. (USHORT)(18) );
  1172. if (status != NDIS_STATUS_SUCCESS)
  1173. {
  1174. // The parameter is out of range.
  1175. DebugPrint(1,("NF(%d): PRODUCTID parameter is invalid, using default\n",acb->anum));
  1176. NdisWriteErrorLogEntry( acb->acb_handle,
  1177. EVENT_NDIS_PRODUCTID_ERROR,
  1178. 0);
  1179. }
  1180. }
  1181. //
  1182. // See if we need to open in Full Duplex
  1183. //
  1184. if (acb->FullDuplexEnabled)
  1185. {
  1186. //
  1187. // Allocate the xmit spin lock.
  1188. //
  1189. NdisAllocateSpinLock(&acb->XmitLock);
  1190. pParms->utd_open.OPEN_Options |= SWAPS(OOPTS_FULLDUP);
  1191. }
  1192. acb->acb_parms = pParms;
  1193. #ifdef XMIT_INTS
  1194. //
  1195. // See if the user has specified the xmit_int_ratio
  1196. //
  1197. acb->XmitIntRatio = TxIntRatio;
  1198. NdisReadConfiguration( &status,
  1199. &cfgp,
  1200. ConfigHandle,
  1201. &xmitintratio,
  1202. NdisParameterInteger);
  1203. if (status == NDIS_STATUS_SUCCESS) {
  1204. acb->XmitIntRatio = (USHORT)cfgp->ParameterData.IntegerData;
  1205. }
  1206. DebugPrint(1,("NF(%d): TxIntRatio = 1:%d\n",acb->anum,acb->XmitIntRatio));
  1207. #endif
  1208. //
  1209. // See if the user has specified the rcv_int_ratio
  1210. //
  1211. acb->RcvIntRatio = RxIntRatio;
  1212. NdisReadConfiguration( &status,
  1213. &cfgp,
  1214. ConfigHandle,
  1215. &rcvintratio,
  1216. NdisParameterInteger);
  1217. if (status == NDIS_STATUS_SUCCESS)
  1218. {
  1219. acb->RcvIntRatio = (USHORT)cfgp->ParameterData.IntegerData;
  1220. }
  1221. DebugPrint(1,("NF(%d): Rx Int Ratio = 1:%d\n",acb->anum,acb->RcvIntRatio));
  1222. return NDIS_STATUS_SUCCESS;
  1223. }
  1224. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1225. //
  1226. // Routine Name: NetFlexBoardInitandReg
  1227. //
  1228. // Description: This routine initiailizes the board, downloads
  1229. // the mac code, and registers the adapter with
  1230. // the wrapper.
  1231. //
  1232. // Input: acbp - Pointer to an acb ptr.
  1233. // pParms - Settable parameters
  1234. //
  1235. // Output: acbp - Pointer to allocated acb
  1236. // Returns NDIS_STATUS_SUCCESS for a successful
  1237. // completion. Otherwise, an error code is
  1238. // returned.
  1239. //
  1240. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1241. NDIS_STATUS
  1242. NetFlexBoardInitandReg(
  1243. PACB acb,
  1244. PNDIS_EISA_FUNCTION_INFORMATION EisaData
  1245. )
  1246. {
  1247. UINT int_vector;
  1248. NDIS_INTERRUPT_MODE int_mode;
  1249. NDIS_STATUS status;
  1250. UINT i=0;
  1251. //
  1252. // Initialize the fields of the acb.
  1253. //
  1254. if ((status = NetFlexInitializeAcb(acb)) != NDIS_STATUS_SUCCESS)
  1255. {
  1256. // Failed, get out now...
  1257. //
  1258. return status;
  1259. }
  1260. //
  1261. // Get EISA Config Data so we can set the interrupt data
  1262. //
  1263. int_vector = EisaData->EisaIrq[0].ConfigurationByte.Interrupt;
  1264. if (!int_vector)
  1265. {
  1266. return NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION;
  1267. }
  1268. if (gbl_addingdualport)
  1269. {
  1270. // Dualport boards share the same interupt between heads
  1271. //
  1272. acb->InterruptsShared = TRUE;
  1273. }
  1274. else
  1275. {
  1276. acb->InterruptsShared = EisaData->EisaIrq[0].ConfigurationByte.Shared;
  1277. }
  1278. int_mode = EisaData->EisaIrq[0].ConfigurationByte.LevelTriggered ? NdisInterruptLevelSensitive : NdisInterruptLatched;
  1279. //
  1280. // Add this acb to the global list
  1281. //
  1282. acb->acb_next = macgbls.mac_adapters;
  1283. macgbls.mac_adapters = acb;
  1284. //
  1285. // Initialize the interrupt.
  1286. //
  1287. status = NdisMRegisterInterrupt( &acb->acb_interrupt,
  1288. acb->acb_handle,
  1289. int_vector,
  1290. int_vector,
  1291. FALSE, // TRUE,
  1292. acb->InterruptsShared,
  1293. int_mode );
  1294. if (status != NDIS_STATUS_SUCCESS)
  1295. {
  1296. DebugPrint(0,("NF(%d): Initialization of the Interrupt FAILED\n",acb->anum));
  1297. NetFlexDequeue_OnePtrQ( (PVOID *)&macgbls.mac_adapters,
  1298. (PVOID)acb);
  1299. return status;
  1300. }
  1301. //
  1302. // Ok, we're set, so reset the adapter and open'er up!
  1303. // Try three times...
  1304. //
  1305. do
  1306. {
  1307. status = NetFlexAdapterReset(acb,HARD_RESET);
  1308. if (status == NDIS_STATUS_SUCCESS)
  1309. {
  1310. //
  1311. // Send the Open Command
  1312. //
  1313. status = NetFlexOpenAdapter(acb);
  1314. }
  1315. } while ((++i < 3) && (status != NDIS_STATUS_SUCCESS));
  1316. if (status != NDIS_STATUS_SUCCESS)
  1317. {
  1318. // Something failed, so get out.
  1319. //
  1320. return status;
  1321. }
  1322. //
  1323. // Get the Burned In Address
  1324. //
  1325. NetFlexGetBIA(acb);
  1326. //
  1327. // Set the Default DPC timer
  1328. //
  1329. NdisMSetTimer(&acb->DpcTimer, 10);
  1330. //
  1331. // Indidicate that we're done with initializing this adapter.
  1332. //
  1333. acb->AdapterInitializing = FALSE;
  1334. return NDIS_STATUS_SUCCESS;
  1335. }
  1336. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1337. //
  1338. // Routine Name: NetFlexInitGlobals
  1339. //
  1340. // Description: This routine initializes the global
  1341. // variables and downloads the mac download
  1342. // code into our map buffer area.
  1343. //
  1344. // Input: None.
  1345. //
  1346. // Output: Status = SUCCESS .
  1347. //
  1348. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  1349. NDIS_STATUS
  1350. NetFlexInitGlobals(
  1351. )
  1352. {
  1353. NDIS_STRING maccode = NDIS_STRING_CONST("NETFLX.BIN");
  1354. UINT length;
  1355. NDIS_STATUS status;
  1356. PUSHORT MappedBuffer;
  1357. NDIS_HANDLE mac_filehandle;
  1358. //
  1359. // Open the file containing the MAC download code.
  1360. //
  1361. NdisOpenFile( &status,
  1362. &mac_filehandle,
  1363. &length,
  1364. &maccode,
  1365. NetFlexHighestAddress);
  1366. if (status != NDIS_STATUS_SUCCESS)
  1367. {
  1368. DebugPrint(0,("NF: Download file could not be opened\n"));
  1369. return status;
  1370. }
  1371. //
  1372. // Allocate the buffer.
  1373. //
  1374. NdisAllocateMemory( (PVOID *)&macgbls.DownloadCode,
  1375. length,
  1376. FALSE,
  1377. NetFlexHighestAddress);
  1378. if (macgbls.DownloadCode == NULL)
  1379. {
  1380. status = NDIS_STATUS_FAILURE;
  1381. }
  1382. else
  1383. {
  1384. // Store the length
  1385. //
  1386. macgbls.DownloadLength = length;
  1387. //
  1388. // Get a mapping to the opened download file.
  1389. //
  1390. NdisMapFile( &status,
  1391. (PVOID *)&MappedBuffer,
  1392. mac_filehandle);
  1393. if (status != NDIS_STATUS_SUCCESS)
  1394. {
  1395. DebugPrint(0,("NF: Download file could not be mapped\n"));
  1396. }
  1397. else
  1398. {
  1399. // Copy the download code into the shared memory space
  1400. //
  1401. NdisMoveMemory(macgbls.DownloadCode,MappedBuffer,length);
  1402. NdisUnmapFile(mac_filehandle);
  1403. }
  1404. //
  1405. // Done with the file
  1406. NdisCloseFile(mac_filehandle);
  1407. }
  1408. return status;
  1409. }