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.

1982 lines
43 KiB

  1. /*++
  2. Copyright (c) 1990-1998 Microsoft Corporation, All Rights Reserved.
  3. Module Name:
  4. ne2000.c
  5. Abstract:
  6. This is the main file for the Novel 2000 Ethernet controller.
  7. This driver conforms to the NDIS 3.0 miniport interface.
  8. Author:
  9. Sean Selitrennikoff (Dec 1993)
  10. Environment:
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. //
  15. // On debug builds tell the compiler to keep the symbols for
  16. // internal functions, otw throw them out.
  17. //
  18. #if DBG
  19. #define STATIC
  20. #else
  21. #define STATIC static
  22. #endif
  23. //
  24. // Debugging definitions
  25. //
  26. #if DBG
  27. //
  28. // Default debug mode
  29. //
  30. ULONG Ne2000DebugFlag = NE2000_DEBUG_LOG;
  31. //
  32. // Debug tracing defintions
  33. //
  34. #define NE2000_LOG_SIZE 256
  35. UCHAR Ne2000LogBuffer[NE2000_LOG_SIZE]={0};
  36. UINT Ne2000LogLoc = 0;
  37. extern
  38. VOID
  39. Ne2000Log(UCHAR c) {
  40. Ne2000LogBuffer[Ne2000LogLoc++] = c;
  41. Ne2000LogBuffer[(Ne2000LogLoc + 4) % NE2000_LOG_SIZE] = '\0';
  42. if (Ne2000LogLoc >= NE2000_LOG_SIZE)
  43. Ne2000LogLoc = 0;
  44. }
  45. #endif
  46. //
  47. // The global Miniport driver block.
  48. //
  49. DRIVER_BLOCK Ne2000MiniportBlock={0};
  50. //
  51. // List of supported OID for this driver.
  52. //
  53. STATIC UINT Ne2000SupportedOids[] = {
  54. OID_GEN_SUPPORTED_LIST,
  55. OID_GEN_HARDWARE_STATUS,
  56. OID_GEN_MEDIA_SUPPORTED,
  57. OID_GEN_MEDIA_IN_USE,
  58. OID_GEN_MAXIMUM_LOOKAHEAD,
  59. OID_GEN_MAXIMUM_FRAME_SIZE,
  60. OID_GEN_MAXIMUM_TOTAL_SIZE,
  61. OID_GEN_MAC_OPTIONS,
  62. OID_GEN_PROTOCOL_OPTIONS,
  63. OID_GEN_LINK_SPEED,
  64. OID_GEN_TRANSMIT_BUFFER_SPACE,
  65. OID_GEN_RECEIVE_BUFFER_SPACE,
  66. OID_GEN_TRANSMIT_BLOCK_SIZE,
  67. OID_GEN_RECEIVE_BLOCK_SIZE,
  68. OID_GEN_VENDOR_DESCRIPTION,
  69. OID_GEN_VENDOR_ID,
  70. OID_GEN_DRIVER_VERSION,
  71. OID_GEN_CURRENT_PACKET_FILTER,
  72. OID_GEN_CURRENT_LOOKAHEAD,
  73. OID_GEN_XMIT_OK,
  74. OID_GEN_RCV_OK,
  75. OID_GEN_XMIT_ERROR,
  76. OID_GEN_RCV_ERROR,
  77. OID_GEN_RCV_NO_BUFFER,
  78. OID_802_3_PERMANENT_ADDRESS,
  79. OID_802_3_CURRENT_ADDRESS,
  80. OID_802_3_MULTICAST_LIST,
  81. OID_802_3_MAXIMUM_LIST_SIZE,
  82. OID_802_3_RCV_ERROR_ALIGNMENT,
  83. OID_802_3_XMIT_ONE_COLLISION,
  84. OID_802_3_XMIT_MORE_COLLISIONS
  85. };
  86. //
  87. // Determines whether failing the initial card test will prevent
  88. // the adapter from being registered.
  89. //
  90. #ifdef CARD_TEST
  91. BOOLEAN InitialCardTest = TRUE;
  92. #else // CARD_TEST
  93. BOOLEAN InitialCardTest = FALSE;
  94. #endif // CARD_TEST
  95. NTSTATUS
  96. DriverEntry(
  97. IN PDRIVER_OBJECT DriverObject,
  98. IN PUNICODE_STRING RegistryPath
  99. );
  100. #pragma NDIS_INIT_FUNCTION(DriverEntry)
  101. NTSTATUS
  102. DriverEntry(
  103. IN PDRIVER_OBJECT DriverObject,
  104. IN PUNICODE_STRING RegistryPath
  105. )
  106. /*++
  107. Routine Description:
  108. This is the primary initialization routine for the NE2000 driver.
  109. It is simply responsible for the intializing the wrapper and registering
  110. the Miniport driver. It then calls a system and architecture specific
  111. routine that will initialize and register each adapter.
  112. Arguments:
  113. DriverObject - Pointer to driver object created by the system.
  114. RegistryPath - Path to the parameters for this driver in the registry.
  115. Return Value:
  116. The status of the operation.
  117. --*/
  118. {
  119. //
  120. // Receives the status of the NdisMRegisterMiniport operation.
  121. //
  122. NDIS_STATUS Status;
  123. //
  124. // Characteristics table for this driver.
  125. //
  126. NDIS_MINIPORT_CHARACTERISTICS NE2000Char;
  127. //
  128. // Pointer to the global information for this driver
  129. //
  130. PDRIVER_BLOCK NewDriver = &Ne2000MiniportBlock;
  131. //
  132. // Handle for referring to the wrapper about this driver.
  133. //
  134. NDIS_HANDLE NdisWrapperHandle;
  135. //
  136. // Initialize the wrapper.
  137. //
  138. NdisMInitializeWrapper(
  139. &NdisWrapperHandle,
  140. DriverObject,
  141. RegistryPath,
  142. NULL
  143. );
  144. //
  145. // Save the global information about this driver.
  146. //
  147. NewDriver->NdisWrapperHandle = NdisWrapperHandle;
  148. NewDriver->AdapterQueue = (PNE2000_ADAPTER)NULL;
  149. //
  150. // Initialize the Miniport characteristics for the call to
  151. // NdisMRegisterMiniport.
  152. //
  153. NE2000Char.MajorNdisVersion = NE2000_NDIS_MAJOR_VERSION;
  154. NE2000Char.MinorNdisVersion = NE2000_NDIS_MINOR_VERSION;
  155. NE2000Char.CheckForHangHandler = NULL;
  156. NE2000Char.DisableInterruptHandler = Ne2000DisableInterrupt;
  157. NE2000Char.EnableInterruptHandler = Ne2000EnableInterrupt;
  158. NE2000Char.HaltHandler = Ne2000Halt;
  159. NE2000Char.HandleInterruptHandler = Ne2000HandleInterrupt;
  160. NE2000Char.InitializeHandler = Ne2000Initialize;
  161. NE2000Char.ISRHandler = Ne2000Isr;
  162. NE2000Char.QueryInformationHandler = Ne2000QueryInformation;
  163. NE2000Char.ReconfigureHandler = NULL;
  164. NE2000Char.ResetHandler = Ne2000Reset;
  165. NE2000Char.SendHandler = Ne2000Send;
  166. NE2000Char.SetInformationHandler = Ne2000SetInformation;
  167. NE2000Char.TransferDataHandler = Ne2000TransferData;
  168. Status = NdisMRegisterMiniport(
  169. NdisWrapperHandle,
  170. &NE2000Char,
  171. sizeof(NE2000Char)
  172. );
  173. if (Status == NDIS_STATUS_SUCCESS) {
  174. return STATUS_SUCCESS;
  175. }
  176. return STATUS_UNSUCCESSFUL;
  177. }
  178. #pragma NDIS_PAGEABLE_FUNCTION(Ne2000Initialize)
  179. extern
  180. NDIS_STATUS
  181. Ne2000Initialize(
  182. OUT PNDIS_STATUS OpenErrorStatus,
  183. OUT PUINT SelectedMediumIndex,
  184. IN PNDIS_MEDIUM MediumArray,
  185. IN UINT MediumArraySize,
  186. IN NDIS_HANDLE MiniportAdapterHandle,
  187. IN NDIS_HANDLE ConfigurationHandle
  188. )
  189. /*++
  190. Routine Description:
  191. Ne2000Initialize starts an adapter and registers resources with the
  192. wrapper.
  193. Arguments:
  194. OpenErrorStatus - Extra status bytes for opening token ring adapters.
  195. SelectedMediumIndex - Index of the media type chosen by the driver.
  196. MediumArray - Array of media types for the driver to chose from.
  197. MediumArraySize - Number of entries in the array.
  198. MiniportAdapterHandle - Handle for passing to the wrapper when
  199. referring to this adapter.
  200. ConfigurationHandle - A handle to pass to NdisOpenConfiguration.
  201. Return Value:
  202. NDIS_STATUS_SUCCESS
  203. NDIS_STATUS_PENDING
  204. --*/
  205. {
  206. //
  207. // Pointer to our newly allocated adapter.
  208. //
  209. PNE2000_ADAPTER Adapter;
  210. //
  211. // The handle for reading from the registry.
  212. //
  213. NDIS_HANDLE ConfigHandle;
  214. //
  215. // The value read from the registry.
  216. //
  217. PNDIS_CONFIGURATION_PARAMETER ReturnedValue;
  218. //
  219. // String names of all the parameters that will be read.
  220. //
  221. NDIS_STRING IOAddressStr = NDIS_STRING_CONST("IoBaseAddress");
  222. NDIS_STRING InterruptStr = NDIS_STRING_CONST("InterruptNumber");
  223. NDIS_STRING MaxMulticastListStr = NDIS_STRING_CONST("MaximumMulticastList");
  224. NDIS_STRING NetworkAddressStr = NDIS_STRING_CONST("NetworkAddress");
  225. NDIS_STRING BusTypeStr = NDIS_STRING_CONST("BusType");
  226. NDIS_STRING CardTypeStr = NDIS_STRING_CONST("CardType");
  227. //
  228. // TRUE if there is a configuration error.
  229. //
  230. BOOLEAN ConfigError = FALSE;
  231. //
  232. // A special value to log concerning the error.
  233. //
  234. ULONG ConfigErrorValue = 0;
  235. //
  236. // The slot number the adapter is located in, used for
  237. // Microchannel adapters.
  238. //
  239. UINT SlotNumber = 0;
  240. //
  241. // TRUE if it is unnecessary to read the Io Base Address
  242. // and Interrupt from the registry. Used for Microchannel
  243. // adapters, which get this information from the slot
  244. // information.
  245. //
  246. BOOLEAN SkipIobaseAndInterrupt = FALSE;
  247. //
  248. // The network address the adapter should use instead of the
  249. // the default burned in address.
  250. //
  251. PVOID NetAddress;
  252. //
  253. // The number of bytes in the address. It should be
  254. // NE2000_LENGTH_OF_ADDRESS
  255. //
  256. ULONG Length;
  257. //
  258. // These are used when calling Ne2000RegisterAdapter.
  259. //
  260. //
  261. // The physical address of the base I/O port.
  262. //
  263. PVOID IoBaseAddr;
  264. //
  265. // The interrupt number to use.
  266. //
  267. CCHAR InterruptNumber;
  268. //
  269. // The number of multicast address to be supported.
  270. //
  271. UINT MaxMulticastList;
  272. //
  273. // Temporary looping variable.
  274. //
  275. ULONG i;
  276. //
  277. // Status of Ndis calls.
  278. //
  279. NDIS_STATUS Status;
  280. NDIS_MCA_POS_DATA McaData;
  281. //
  282. // Search for the medium type (802.3) in the given array.
  283. //
  284. for (i = 0; i < MediumArraySize; i++){
  285. if (MediumArray[i] == NdisMedium802_3){
  286. break;
  287. }
  288. }
  289. if (i == MediumArraySize){
  290. return( NDIS_STATUS_UNSUPPORTED_MEDIA );
  291. }
  292. *SelectedMediumIndex = i;
  293. //
  294. // Set default values.
  295. //
  296. IoBaseAddr = DEFAULT_IOBASEADDR;
  297. InterruptNumber = DEFAULT_INTERRUPTNUMBER;
  298. MaxMulticastList = DEFAULT_MULTICASTLISTMAX;
  299. //
  300. // Allocate memory for the adapter block now.
  301. //
  302. Status = NdisAllocateMemoryWithTag( (PVOID *)&Adapter,
  303. sizeof(NE2000_ADAPTER),
  304. 'k2EN'
  305. );
  306. if (Status != NDIS_STATUS_SUCCESS) {
  307. return Status;
  308. }
  309. //
  310. // Clear out the adapter block, which sets all default values to FALSE,
  311. // or NULL.
  312. //
  313. NdisZeroMemory (Adapter, sizeof(NE2000_ADAPTER));
  314. //
  315. // Open the configuration space.
  316. //
  317. NdisOpenConfiguration(
  318. &Status,
  319. &ConfigHandle,
  320. ConfigurationHandle
  321. );
  322. if (Status != NDIS_STATUS_SUCCESS) {
  323. NdisFreeMemory(Adapter, sizeof(NE2000_ADAPTER), 0);
  324. return Status;
  325. }
  326. //
  327. // Read in the card type.
  328. //
  329. Adapter->CardType = NE2000_ISA;
  330. NdisReadConfiguration(
  331. &Status,
  332. &ReturnedValue,
  333. ConfigHandle,
  334. &CardTypeStr,
  335. NdisParameterHexInteger
  336. );
  337. if (Status == NDIS_STATUS_SUCCESS)
  338. Adapter->CardType = (UINT)ReturnedValue->ParameterData.IntegerData;
  339. //
  340. // Read net address
  341. //
  342. NdisReadNetworkAddress(
  343. &Status,
  344. &NetAddress,
  345. &Length,
  346. ConfigHandle
  347. );
  348. if ((Length == NE2000_LENGTH_OF_ADDRESS) && (Status == NDIS_STATUS_SUCCESS)) {
  349. //
  350. // Save the address that should be used.
  351. //
  352. NdisMoveMemory(
  353. Adapter->StationAddress,
  354. NetAddress,
  355. NE2000_LENGTH_OF_ADDRESS
  356. );
  357. }
  358. //
  359. // Disallow multiple adapters in the same MP machine because of hardware
  360. // problems this results in random packet corruption.
  361. //
  362. if ((NdisSystemProcessorCount() > 1) && (Ne2000MiniportBlock.AdapterQueue != NULL)) {
  363. ConfigError = TRUE;
  364. ConfigErrorValue = (ULONG)NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION;
  365. goto RegisterAdapter;
  366. return NDIS_STATUS_FAILURE;
  367. }
  368. //
  369. // Read Bus Type (for NE2/AE2 support)
  370. //
  371. Adapter->BusType = NdisInterfaceIsa;
  372. NdisReadConfiguration(
  373. &Status,
  374. &ReturnedValue,
  375. ConfigHandle,
  376. &BusTypeStr,
  377. NdisParameterHexInteger
  378. );
  379. if (Status == NDIS_STATUS_SUCCESS) {
  380. Adapter->BusType = (UCHAR)ReturnedValue->ParameterData.IntegerData;
  381. }
  382. if (!SkipIobaseAndInterrupt) {
  383. //
  384. // Read I/O Address
  385. //
  386. NdisReadConfiguration(
  387. &Status,
  388. &ReturnedValue,
  389. ConfigHandle,
  390. &IOAddressStr,
  391. NdisParameterHexInteger
  392. );
  393. if (Status == NDIS_STATUS_SUCCESS) {
  394. IoBaseAddr = UlongToPtr(ReturnedValue->ParameterData.IntegerData);
  395. }
  396. if (Adapter->BusType != NdisInterfacePcMcia)
  397. {
  398. //
  399. // Check that the value is valid.
  400. //
  401. if ((IoBaseAddr < (PVOID)MIN_IOBASEADDR) ||
  402. (IoBaseAddr > (PVOID)MAX_IOBASEADDR)) {
  403. ConfigError = TRUE;
  404. ConfigErrorValue = PtrToUlong(IoBaseAddr);
  405. goto RegisterAdapter;
  406. }
  407. }
  408. //
  409. // Read interrupt number
  410. //
  411. NdisReadConfiguration(
  412. &Status,
  413. &ReturnedValue,
  414. ConfigHandle,
  415. &InterruptStr,
  416. NdisParameterHexInteger
  417. );
  418. if (Status == NDIS_STATUS_SUCCESS) {
  419. InterruptNumber = (CCHAR)(ReturnedValue->ParameterData.IntegerData);
  420. }
  421. //
  422. // Verify that the value is valid.
  423. //
  424. if ((InterruptNumber < MIN_IRQ) ||
  425. (InterruptNumber > MAX_IRQ)) {
  426. ConfigError = TRUE;
  427. ConfigErrorValue = (ULONG)InterruptNumber;
  428. goto RegisterAdapter;
  429. }
  430. //
  431. // If the adapter is a pcmcia card then get the memory window
  432. // address for later use.
  433. //
  434. if (NE2000_PCMCIA == Adapter->CardType)
  435. {
  436. #if 0
  437. NDIS_STRING AttributeMemoryAddrStr =
  438. NDIS_STRING_CONST("MemoryMappedBaseAddress");
  439. NDIS_STRING AttributeMemorySizeStr =
  440. NDIS_STRING_CONST("PCCARDAttributeMemorySize");
  441. //
  442. // Read the attribute memory address.
  443. //
  444. Adapter->AttributeMemoryAddress = 0xd4000;
  445. NdisReadConfiguration(
  446. &Status,
  447. &ReturnedValue,
  448. ConfigHandle,
  449. &AttributeMemoryAddrStr,
  450. NdisParameterHexInteger
  451. );
  452. if (NDIS_STATUS_SUCCESS == Status)
  453. {
  454. Adapter->AttributeMemoryAddress =
  455. (ULONG)ReturnedValue->ParameterData.IntegerData;
  456. }
  457. //
  458. // Read the size of the attribute memory range.
  459. //
  460. Adapter->AttributeMemorySize = 0x1000;
  461. NdisReadConfiguration(
  462. &Status,
  463. &ReturnedValue,
  464. ConfigHandle,
  465. &AttributeMemorySizeStr,
  466. NdisParameterHexInteger
  467. );
  468. if (NDIS_STATUS_SUCCESS == Status)
  469. {
  470. Adapter->AttributeMemorySize =
  471. (ULONG)ReturnedValue->ParameterData.IntegerData;
  472. }
  473. #endif
  474. }
  475. }
  476. //
  477. // Read MaxMulticastList
  478. //
  479. NdisReadConfiguration(
  480. &Status,
  481. &ReturnedValue,
  482. ConfigHandle,
  483. &MaxMulticastListStr,
  484. NdisParameterInteger
  485. );
  486. if (Status == NDIS_STATUS_SUCCESS) {
  487. MaxMulticastList = ReturnedValue->ParameterData.IntegerData;
  488. if (ReturnedValue->ParameterData.IntegerData <= DEFAULT_MULTICASTLISTMAX)
  489. MaxMulticastList = ReturnedValue->ParameterData.IntegerData;
  490. }
  491. RegisterAdapter:
  492. //
  493. // Now to use this information and register with the wrapper
  494. // and initialize the adapter.
  495. //
  496. //
  497. // First close the configuration space.
  498. //
  499. NdisCloseConfiguration(ConfigHandle);
  500. IF_LOUD( DbgPrint(
  501. "Registering adapter # buffers %ld\n"
  502. "Card type: 0x%x\n"
  503. "I/O base addr 0x%lx\n"
  504. "interrupt number %ld\n"
  505. "max multicast %ld\nattribute memory address 0x%X\n"
  506. "attribute memory size 0x%X\n"
  507. "CardType: %d\n",
  508. DEFAULT_NUMBUFFERS,
  509. Adapter->CardType,
  510. IoBaseAddr,
  511. InterruptNumber,
  512. DEFAULT_MULTICASTLISTMAX,
  513. Adapter->AttributeMemoryAddress,
  514. Adapter->AttributeMemorySize,
  515. Adapter->CardType );)
  516. //
  517. // Set up the parameters.
  518. //
  519. Adapter->NumBuffers = DEFAULT_NUMBUFFERS;
  520. Adapter->IoBaseAddr = IoBaseAddr;
  521. Adapter->InterruptNumber = InterruptNumber;
  522. Adapter->MulticastListMax = MaxMulticastList;
  523. Adapter->MiniportAdapterHandle = MiniportAdapterHandle;
  524. Adapter->MaxLookAhead = NE2000_MAX_LOOKAHEAD;
  525. //
  526. // Now do the work.
  527. //
  528. if (Ne2000RegisterAdapter(Adapter,
  529. ConfigurationHandle,
  530. ConfigError,
  531. ConfigErrorValue
  532. ) != NDIS_STATUS_SUCCESS) {
  533. //
  534. // Ne2000RegisterAdapter failed.
  535. //
  536. NdisFreeMemory(Adapter, sizeof(NE2000_ADAPTER), 0);
  537. return NDIS_STATUS_FAILURE;
  538. }
  539. IF_LOUD( DbgPrint( "Ne2000RegisterAdapter succeeded\n" );)
  540. return NDIS_STATUS_SUCCESS;
  541. }
  542. #pragma NDIS_PAGEABLE_FUNCTION(Ne2000RegisterAdapter)
  543. NDIS_STATUS
  544. Ne2000RegisterAdapter(
  545. IN PNE2000_ADAPTER Adapter,
  546. IN NDIS_HANDLE ConfigurationHandle,
  547. IN BOOLEAN ConfigError,
  548. IN ULONG ConfigErrorValue
  549. )
  550. /*++
  551. Routine Description:
  552. Called when a new adapter should be registered. It allocates space for
  553. the adapter, initializes the adapter's block, registers resources
  554. with the wrapper and initializes the physical adapter.
  555. Arguments:
  556. Adapter - The adapter structure.
  557. ConfigurationHandle - Handle passed to Ne2000Initialize.
  558. ConfigError - Was there an error during configuration reading.
  559. ConfigErrorValue - Value to log if there is an error.
  560. Return Value:
  561. Indicates the success or failure of the registration.
  562. --*/
  563. {
  564. //
  565. // Temporary looping variable.
  566. //
  567. UINT i;
  568. //
  569. // General purpose return from NDIS calls
  570. //
  571. NDIS_STATUS status;
  572. //
  573. // check that NumBuffers <= MAX_XMIT_BUFS
  574. //
  575. if (Adapter->NumBuffers > MAX_XMIT_BUFS)
  576. return(NDIS_STATUS_RESOURCES);
  577. //
  578. // Check for a configuration error
  579. //
  580. if (ConfigError)
  581. {
  582. //
  583. // Log Error and exit.
  584. //
  585. NdisWriteErrorLogEntry(
  586. Adapter->MiniportAdapterHandle,
  587. NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION,
  588. 1,
  589. ConfigErrorValue
  590. );
  591. return(NDIS_STATUS_FAILURE);
  592. }
  593. //
  594. // Inform the wrapper of the physical attributes of this adapter.
  595. //
  596. NdisMSetAttributes(
  597. Adapter->MiniportAdapterHandle,
  598. (NDIS_HANDLE)Adapter,
  599. FALSE,
  600. Adapter->BusType
  601. );
  602. //
  603. // Register the port addresses.
  604. //
  605. status = NdisMRegisterIoPortRange(
  606. (PVOID *)(&(Adapter->IoPAddr)),
  607. Adapter->MiniportAdapterHandle,
  608. PtrToUint(Adapter->IoBaseAddr),
  609. 0x20
  610. );
  611. if (status != NDIS_STATUS_SUCCESS)
  612. return(status);
  613. if (NE2000_ISA == Adapter->CardType)
  614. {
  615. //
  616. // Check that the IoBaseAddress seems to be correct.
  617. //
  618. IF_VERY_LOUD( DbgPrint("Checking Parameters\n"); )
  619. if (!CardCheckParameters(Adapter))
  620. {
  621. //
  622. // The card does not seem to be there, fail silently.
  623. //
  624. IF_VERY_LOUD( DbgPrint(" -- Failed\n"); )
  625. NdisWriteErrorLogEntry(
  626. Adapter->MiniportAdapterHandle,
  627. NDIS_ERROR_CODE_ADAPTER_NOT_FOUND,
  628. 0
  629. );
  630. status = NDIS_STATUS_ADAPTER_NOT_FOUND;
  631. goto fail2;
  632. }
  633. IF_VERY_LOUD( DbgPrint(" -- Success\n"); )
  634. }
  635. //
  636. // Initialize the card.
  637. //
  638. IF_VERY_LOUD( DbgPrint("CardInitialize\n"); )
  639. if (!CardInitialize(Adapter))
  640. {
  641. //
  642. // Card seems to have failed.
  643. //
  644. IF_VERY_LOUD( DbgPrint(" -- Failed\n"); )
  645. NdisWriteErrorLogEntry(
  646. Adapter->MiniportAdapterHandle,
  647. NDIS_ERROR_CODE_ADAPTER_NOT_FOUND,
  648. 0
  649. );
  650. status = NDIS_STATUS_ADAPTER_NOT_FOUND;
  651. goto fail2;
  652. }
  653. IF_VERY_LOUD( DbgPrint(" -- Success\n"); )
  654. //
  655. //
  656. // For programmed I/O, we will refer to transmit/receive memory in
  657. // terms of offsets in the card's 64K address space.
  658. //
  659. Adapter->XmitStart = Adapter->RamBase;
  660. //
  661. // For the NicXXX fields, always use the addressing system
  662. // containing the MSB only).
  663. //
  664. Adapter->NicXmitStart = (UCHAR)((PtrToUlong(Adapter->XmitStart)) >> 8);
  665. //
  666. // The start of the receive space.
  667. //
  668. Adapter->PageStart = Adapter->XmitStart +
  669. (Adapter->NumBuffers * TX_BUF_SIZE);
  670. Adapter->NicPageStart = Adapter->NicXmitStart +
  671. (UCHAR)(Adapter->NumBuffers * BUFS_PER_TX);
  672. ASSERT(Adapter->PageStart < (Adapter->RamBase + Adapter->RamSize));
  673. //
  674. // The end of the receive space.
  675. //
  676. Adapter->PageStop = Adapter->XmitStart + Adapter->RamSize;
  677. Adapter->NicPageStop = Adapter->NicXmitStart + (UCHAR)(Adapter->RamSize >> 8);
  678. ASSERT(Adapter->PageStop <= (Adapter->RamBase + Adapter->RamSize));
  679. IF_LOUD( DbgPrint("Xmit Start (0x%x, 0x%x) : Rcv Start (0x%x, 0x%x) : Rcv End (0x%x, 0x%x)\n",
  680. Adapter->XmitStart,
  681. Adapter->NicXmitStart,
  682. Adapter->PageStart,
  683. Adapter->NicPageStart,
  684. (ULONG_PTR)Adapter->PageStop,
  685. Adapter->NicPageStop
  686. );
  687. )
  688. //
  689. // Initialize the receive variables.
  690. //
  691. Adapter->NicReceiveConfig = RCR_REJECT_ERR;
  692. //
  693. // Initialize the transmit buffer control.
  694. //
  695. Adapter->CurBufXmitting = (XMIT_BUF)-1;
  696. //
  697. // Initialize the transmit buffer states.
  698. //
  699. for (i = 0; i < Adapter->NumBuffers; i++)
  700. Adapter->BufferStatus[i] = EMPTY;
  701. //
  702. // Read the Ethernet address off of the PROM.
  703. //
  704. if (!CardReadEthernetAddress(Adapter))
  705. {
  706. IF_LOUD(DbgPrint("Could not read the ethernet address\n");)
  707. NdisWriteErrorLogEntry(
  708. Adapter->MiniportAdapterHandle,
  709. NDIS_ERROR_CODE_ADAPTER_NOT_FOUND,
  710. 0
  711. );
  712. status = NDIS_STATUS_ADAPTER_NOT_FOUND;
  713. goto fail2;
  714. }
  715. //
  716. // Now initialize the NIC and Gate Array registers.
  717. //
  718. Adapter->NicInterruptMask = IMR_RCV | IMR_XMIT | IMR_XMIT_ERR | IMR_OVERFLOW;
  719. //
  720. // Link us on to the chain of adapters for this driver.
  721. //
  722. Adapter->NextAdapter = Ne2000MiniportBlock.AdapterQueue;
  723. Ne2000MiniportBlock.AdapterQueue = Adapter;
  724. //
  725. // Setup the card based on the initialization information
  726. //
  727. IF_VERY_LOUD( DbgPrint("Setup\n"); )
  728. if (!CardSetup(Adapter))
  729. {
  730. //
  731. // The NIC could not be written to.
  732. //
  733. NdisWriteErrorLogEntry(
  734. Adapter->MiniportAdapterHandle,
  735. NDIS_ERROR_CODE_ADAPTER_NOT_FOUND,
  736. 0
  737. );
  738. IF_VERY_LOUD( DbgPrint(" -- Failed\n"); )
  739. status = NDIS_STATUS_ADAPTER_NOT_FOUND;
  740. goto fail3;
  741. }
  742. IF_VERY_LOUD( DbgPrint(" -- Success\n"); )
  743. //
  744. // Initialize the interrupt.
  745. //
  746. Adapter->InterruptMode = NdisInterruptLatched;
  747. status = NdisMRegisterInterrupt(
  748. &Adapter->Interrupt,
  749. Adapter->MiniportAdapterHandle,
  750. Adapter->InterruptNumber,
  751. Adapter->InterruptNumber,
  752. FALSE,
  753. FALSE,
  754. Adapter->InterruptMode
  755. );
  756. if (status != NDIS_STATUS_SUCCESS)
  757. {
  758. //
  759. // Maybe it is a level interrupt
  760. //
  761. Adapter->InterruptMode = NdisInterruptLevelSensitive;
  762. Adapter->InterruptsEnabled = TRUE;
  763. status = NdisMRegisterInterrupt(
  764. &Adapter->Interrupt,
  765. Adapter->MiniportAdapterHandle,
  766. Adapter->InterruptNumber,
  767. Adapter->InterruptNumber,
  768. TRUE,
  769. TRUE,
  770. Adapter->InterruptMode
  771. );
  772. if (status != NDIS_STATUS_SUCCESS)
  773. {
  774. NdisWriteErrorLogEntry(
  775. Adapter->MiniportAdapterHandle,
  776. NDIS_ERROR_CODE_INTERRUPT_CONNECT,
  777. 0
  778. );
  779. goto fail3;
  780. }
  781. }
  782. IF_LOUD( DbgPrint("Interrupt Connected\n");)
  783. //
  784. // Start up the adapter.
  785. //
  786. CardStart(Adapter);
  787. //
  788. // Initialization completed successfully. Register a shutdown handler.
  789. //
  790. NdisMRegisterAdapterShutdownHandler(
  791. Adapter->MiniportAdapterHandle,
  792. (PVOID)Adapter,
  793. Ne2000Shutdown
  794. );
  795. IF_LOUD( DbgPrint(" [ Ne2000 ] : OK\n");)
  796. return(NDIS_STATUS_SUCCESS);
  797. //
  798. // Code to unwind what has already been set up when a part of
  799. // initialization fails, which is jumped into at various
  800. // points based on where the failure occured. Jumping to
  801. // a higher-numbered failure point will execute the code
  802. // for that block and all lower-numbered ones.
  803. //
  804. fail3:
  805. //
  806. // Take us out of the AdapterQueue.
  807. //
  808. if (Ne2000MiniportBlock.AdapterQueue == Adapter)
  809. {
  810. Ne2000MiniportBlock.AdapterQueue = Adapter->NextAdapter;
  811. }
  812. else
  813. {
  814. PNE2000_ADAPTER TmpAdapter = Ne2000MiniportBlock.AdapterQueue;
  815. while (TmpAdapter->NextAdapter != Adapter)
  816. {
  817. TmpAdapter = TmpAdapter->NextAdapter;
  818. }
  819. TmpAdapter->NextAdapter = TmpAdapter->NextAdapter->NextAdapter;
  820. }
  821. //
  822. // We already enabled the interrupt on the card, so
  823. // turn it off.
  824. //
  825. NdisRawWritePortUchar(Adapter->IoPAddr+NIC_COMMAND, CR_STOP);
  826. fail2:
  827. NdisMDeregisterIoPortRange(
  828. Adapter->MiniportAdapterHandle,
  829. PtrToUint(Adapter->IoBaseAddr),
  830. 0x20,
  831. (PVOID)Adapter->IoPAddr
  832. );
  833. return(status);
  834. }
  835. extern
  836. VOID
  837. Ne2000Halt(
  838. IN NDIS_HANDLE MiniportAdapterContext
  839. )
  840. /*++
  841. Routine Description:
  842. NE2000Halt removes an adapter that was previously initialized.
  843. Arguments:
  844. MiniportAdapterContext - The context value that the Miniport returned
  845. from Ne2000Initialize; actually as pointer to an NE2000_ADAPTER.
  846. Return Value:
  847. None.
  848. --*/
  849. {
  850. PNE2000_ADAPTER Adapter;
  851. Adapter = PNE2000_ADAPTER_FROM_CONTEXT_HANDLE(MiniportAdapterContext);
  852. //
  853. // Shut down the chip.
  854. //
  855. CardStop(Adapter);
  856. //
  857. // Deregister the adapter shutdown handler.
  858. //
  859. NdisMDeregisterAdapterShutdownHandler(Adapter->MiniportAdapterHandle);
  860. //
  861. // Disconnect the interrupt line.
  862. //
  863. NdisMDeregisterInterrupt(&Adapter->Interrupt);
  864. //
  865. // Pause, waiting for any DPC stuff to clear.
  866. //
  867. NdisStallExecution(250000);
  868. NdisMDeregisterIoPortRange(Adapter->MiniportAdapterHandle,
  869. PtrToUint(Adapter->IoBaseAddr),
  870. 0x20,
  871. (PVOID)Adapter->IoPAddr
  872. );
  873. //
  874. // Remove the adapter from the global queue of adapters.
  875. //
  876. if (Ne2000MiniportBlock.AdapterQueue == Adapter) {
  877. Ne2000MiniportBlock.AdapterQueue = Adapter->NextAdapter;
  878. } else {
  879. PNE2000_ADAPTER TmpAdapter = Ne2000MiniportBlock.AdapterQueue;
  880. while (TmpAdapter->NextAdapter != Adapter) {
  881. TmpAdapter = TmpAdapter->NextAdapter;
  882. }
  883. TmpAdapter->NextAdapter = TmpAdapter->NextAdapter->NextAdapter;
  884. }
  885. //
  886. // Free up the memory
  887. //
  888. NdisFreeMemory(Adapter, sizeof(NE2000_ADAPTER), 0);
  889. return;
  890. }
  891. VOID
  892. Ne2000Shutdown(
  893. IN NDIS_HANDLE MiniportAdapterContext
  894. )
  895. /*++
  896. Routine Description:
  897. This is called by NDIS when the system is shutting down or restarting
  898. on an unrecoverable error. Do the minimum set of operations to make the
  899. card silent.
  900. Arguments:
  901. MiniportAdapterContext - pointer to our adapter structure
  902. Return Value:
  903. None.
  904. --*/
  905. {
  906. //
  907. // Pointer to the adapter structure.
  908. //
  909. PNE2000_ADAPTER Adapter = (PNE2000_ADAPTER)MiniportAdapterContext;
  910. (VOID)SyncCardStop(Adapter);
  911. }
  912. NDIS_STATUS
  913. Ne2000Reset(
  914. OUT PBOOLEAN AddressingReset,
  915. IN NDIS_HANDLE MiniportAdapterContext
  916. )
  917. /*++
  918. Routine Description:
  919. The NE2000Reset request instructs the Miniport to issue a hardware reset
  920. to the network adapter. The driver also resets its software state. See
  921. the description of NdisMReset for a detailed description of this request.
  922. Arguments:
  923. AddressingReset - Does the adapter need the addressing information reloaded.
  924. MiniportAdapterContext - Pointer to the adapter structure.
  925. Return Value:
  926. The function value is the status of the operation.
  927. --*/
  928. {
  929. //
  930. // Pointer to the adapter structure.
  931. //
  932. PNE2000_ADAPTER Adapter = (PNE2000_ADAPTER)MiniportAdapterContext;
  933. //
  934. // Temporary looping variable
  935. //
  936. UINT i;
  937. //
  938. // Clear the values for transmits, they will be reset these for after
  939. // the reset is completed.
  940. //
  941. Adapter->NextBufToFill = 0;
  942. Adapter->NextBufToXmit = 0;
  943. Adapter->CurBufXmitting = (XMIT_BUF)-1;
  944. Adapter->FirstPacket = NULL;
  945. Adapter->LastPacket = NULL;
  946. for (i=0; i<Adapter->NumBuffers; i++) {
  947. Adapter->BufferStatus[i] = EMPTY;
  948. }
  949. //
  950. // Physically reset the card.
  951. //
  952. Adapter->NicInterruptMask = IMR_RCV | IMR_XMIT | IMR_XMIT_ERR | IMR_OVERFLOW;
  953. return (CardReset(Adapter) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE);
  954. }
  955. NDIS_STATUS
  956. Ne2000QueryInformation(
  957. IN NDIS_HANDLE MiniportAdapterContext,
  958. IN NDIS_OID Oid,
  959. IN PVOID InformationBuffer,
  960. IN ULONG InformationBufferLength,
  961. OUT PULONG BytesWritten,
  962. OUT PULONG BytesNeeded
  963. )
  964. /*++
  965. Routine Description:
  966. The NE2000QueryInformation process a Query request for
  967. NDIS_OIDs that are specific about the Driver.
  968. Arguments:
  969. MiniportAdapterContext - a pointer to the adapter.
  970. Oid - the NDIS_OID to process.
  971. InformationBuffer - a pointer into the
  972. NdisRequest->InformationBuffer into which store the result of the query.
  973. InformationBufferLength - a pointer to the number of bytes left in the
  974. InformationBuffer.
  975. BytesWritten - a pointer to the number of bytes written into the
  976. InformationBuffer.
  977. BytesNeeded - If there is not enough room in the information buffer
  978. then this will contain the number of bytes needed to complete the
  979. request.
  980. Return Value:
  981. The function value is the status of the operation.
  982. --*/
  983. {
  984. //
  985. // Pointer to the adapter structure.
  986. //
  987. PNE2000_ADAPTER Adapter = (PNE2000_ADAPTER)MiniportAdapterContext;
  988. //
  989. // General Algorithm:
  990. //
  991. // Switch(Request)
  992. // Get requested information
  993. // Store results in a common variable.
  994. // default:
  995. // Try protocol query information
  996. // If that fails, fail query.
  997. //
  998. // Copy result in common variable to result buffer.
  999. // Finish processing
  1000. UINT BytesLeft = InformationBufferLength;
  1001. PUCHAR InfoBuffer = (PUCHAR)(InformationBuffer);
  1002. NDIS_STATUS StatusToReturn = NDIS_STATUS_SUCCESS;
  1003. NDIS_HARDWARE_STATUS HardwareStatus = NdisHardwareStatusReady;
  1004. NDIS_MEDIUM Medium = NdisMedium802_3;
  1005. //
  1006. // This variable holds result of query
  1007. //
  1008. ULONG GenericULong;
  1009. USHORT GenericUShort;
  1010. UCHAR GenericArray[6];
  1011. UINT MoveBytes = sizeof(ULONG);
  1012. PVOID MoveSource = (PVOID)(&GenericULong);
  1013. //
  1014. // Make sure that int is 4 bytes. Else GenericULong must change
  1015. // to something of size 4.
  1016. //
  1017. ASSERT(sizeof(ULONG) == 4);
  1018. //
  1019. // Switch on request type
  1020. //
  1021. switch (Oid) {
  1022. case OID_GEN_MAC_OPTIONS:
  1023. GenericULong = (ULONG)(NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
  1024. NDIS_MAC_OPTION_RECEIVE_SERIALIZED |
  1025. NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |
  1026. NDIS_MAC_OPTION_NO_LOOPBACK
  1027. );
  1028. break;
  1029. case OID_GEN_SUPPORTED_LIST:
  1030. MoveSource = (PVOID)(Ne2000SupportedOids);
  1031. MoveBytes = sizeof(Ne2000SupportedOids);
  1032. break;
  1033. case OID_GEN_HARDWARE_STATUS:
  1034. HardwareStatus = NdisHardwareStatusReady;
  1035. MoveSource = (PVOID)(&HardwareStatus);
  1036. MoveBytes = sizeof(NDIS_HARDWARE_STATUS);
  1037. break;
  1038. case OID_GEN_MEDIA_SUPPORTED:
  1039. case OID_GEN_MEDIA_IN_USE:
  1040. MoveSource = (PVOID) (&Medium);
  1041. MoveBytes = sizeof(NDIS_MEDIUM);
  1042. break;
  1043. case OID_GEN_MAXIMUM_LOOKAHEAD:
  1044. GenericULong = NE2000_MAX_LOOKAHEAD;
  1045. break;
  1046. case OID_GEN_MAXIMUM_FRAME_SIZE:
  1047. GenericULong = (ULONG)(1514 - NE2000_HEADER_SIZE);
  1048. break;
  1049. case OID_GEN_MAXIMUM_TOTAL_SIZE:
  1050. GenericULong = (ULONG)(1514);
  1051. break;
  1052. case OID_GEN_LINK_SPEED:
  1053. GenericULong = (ULONG)(100000);
  1054. break;
  1055. case OID_GEN_TRANSMIT_BUFFER_SPACE:
  1056. GenericULong = (ULONG)(Adapter->NumBuffers * TX_BUF_SIZE);
  1057. break;
  1058. case OID_GEN_RECEIVE_BUFFER_SPACE:
  1059. GenericULong = (ULONG)(0x2000 - (Adapter->NumBuffers * TX_BUF_SIZE));
  1060. break;
  1061. case OID_GEN_TRANSMIT_BLOCK_SIZE:
  1062. GenericULong = (ULONG)(TX_BUF_SIZE);
  1063. break;
  1064. case OID_GEN_RECEIVE_BLOCK_SIZE:
  1065. GenericULong = (ULONG)(256);
  1066. break;
  1067. #ifdef NE2000
  1068. case OID_GEN_VENDOR_ID:
  1069. NdisMoveMemory(
  1070. (PVOID)&GenericULong,
  1071. Adapter->PermanentAddress,
  1072. 3
  1073. );
  1074. GenericULong &= 0xFFFFFF00;
  1075. MoveSource = (PVOID)(&GenericULong);
  1076. MoveBytes = sizeof(GenericULong);
  1077. break;
  1078. case OID_GEN_VENDOR_DESCRIPTION:
  1079. MoveSource = (PVOID)"Novell 2000 Adapter.";
  1080. MoveBytes = 21;
  1081. break;
  1082. #else
  1083. case OID_GEN_VENDOR_ID:
  1084. NdisMoveMemory(
  1085. (PVOID)&GenericULong,
  1086. Adapter->PermanentAddress,
  1087. 3
  1088. );
  1089. GenericULong &= 0xFFFFFF00;
  1090. GenericULong |= 0x01;
  1091. MoveSource = (PVOID)(&GenericULong);
  1092. MoveBytes = sizeof(GenericULong);
  1093. break;
  1094. case OID_GEN_VENDOR_DESCRIPTION:
  1095. MoveSource = (PVOID)"Novell 1000 Adapter.";
  1096. MoveBytes = 21;
  1097. break;
  1098. #endif
  1099. case OID_GEN_DRIVER_VERSION:
  1100. GenericUShort = ((USHORT)NE2000_NDIS_MAJOR_VERSION << 8) |
  1101. NE2000_NDIS_MINOR_VERSION;
  1102. MoveSource = (PVOID)(&GenericUShort);
  1103. MoveBytes = sizeof(GenericUShort);
  1104. break;
  1105. case OID_GEN_CURRENT_LOOKAHEAD:
  1106. GenericULong = (ULONG)(Adapter->MaxLookAhead);
  1107. break;
  1108. case OID_802_3_PERMANENT_ADDRESS:
  1109. NE2000_MOVE_MEM((PCHAR)GenericArray,
  1110. Adapter->PermanentAddress,
  1111. NE2000_LENGTH_OF_ADDRESS);
  1112. MoveSource = (PVOID)(GenericArray);
  1113. MoveBytes = sizeof(Adapter->PermanentAddress);
  1114. break;
  1115. case OID_802_3_CURRENT_ADDRESS:
  1116. NE2000_MOVE_MEM((PCHAR)GenericArray,
  1117. Adapter->StationAddress,
  1118. NE2000_LENGTH_OF_ADDRESS);
  1119. MoveSource = (PVOID)(GenericArray);
  1120. MoveBytes = sizeof(Adapter->StationAddress);
  1121. break;
  1122. case OID_802_3_MAXIMUM_LIST_SIZE:
  1123. GenericULong = (ULONG) (Adapter->MulticastListMax);
  1124. break;
  1125. case OID_GEN_XMIT_OK:
  1126. GenericULong = (UINT)(Adapter->FramesXmitGood);
  1127. break;
  1128. case OID_GEN_RCV_OK:
  1129. GenericULong = (UINT)(Adapter->FramesRcvGood);
  1130. break;
  1131. case OID_GEN_XMIT_ERROR:
  1132. GenericULong = (UINT)(Adapter->FramesXmitBad);
  1133. break;
  1134. case OID_GEN_RCV_ERROR:
  1135. GenericULong = (UINT)(Adapter->CrcErrors);
  1136. break;
  1137. case OID_GEN_RCV_NO_BUFFER:
  1138. GenericULong = (UINT)(Adapter->MissedPackets);
  1139. break;
  1140. case OID_802_3_RCV_ERROR_ALIGNMENT:
  1141. GenericULong = (UINT)(Adapter->FrameAlignmentErrors);
  1142. break;
  1143. case OID_802_3_XMIT_ONE_COLLISION:
  1144. GenericULong = (UINT)(Adapter->FramesXmitOneCollision);
  1145. break;
  1146. case OID_802_3_XMIT_MORE_COLLISIONS:
  1147. GenericULong = (UINT)(Adapter->FramesXmitManyCollisions);
  1148. break;
  1149. default:
  1150. StatusToReturn = NDIS_STATUS_INVALID_OID;
  1151. break;
  1152. }
  1153. if (StatusToReturn == NDIS_STATUS_SUCCESS) {
  1154. if (MoveBytes > BytesLeft) {
  1155. //
  1156. // Not enough room in InformationBuffer. Punt
  1157. //
  1158. *BytesNeeded = MoveBytes;
  1159. StatusToReturn = NDIS_STATUS_INVALID_LENGTH;
  1160. } else {
  1161. //
  1162. // Store result.
  1163. //
  1164. NE2000_MOVE_MEM(InfoBuffer, MoveSource, MoveBytes);
  1165. (*BytesWritten) = MoveBytes;
  1166. }
  1167. }
  1168. return StatusToReturn;
  1169. }
  1170. extern
  1171. NDIS_STATUS
  1172. Ne2000SetInformation(
  1173. IN NDIS_HANDLE MiniportAdapterContext,
  1174. IN NDIS_OID Oid,
  1175. IN PVOID InformationBuffer,
  1176. IN ULONG InformationBufferLength,
  1177. OUT PULONG BytesRead,
  1178. OUT PULONG BytesNeeded
  1179. )
  1180. /*++
  1181. Routine Description:
  1182. NE2000SetInformation handles a set operation for a
  1183. single OID.
  1184. Arguments:
  1185. MiniportAdapterContext - Context registered with the wrapper, really
  1186. a pointer to the adapter.
  1187. Oid - The OID of the set.
  1188. InformationBuffer - Holds the data to be set.
  1189. InformationBufferLength - The length of InformationBuffer.
  1190. BytesRead - If the call is successful, returns the number
  1191. of bytes read from InformationBuffer.
  1192. BytesNeeded - If there is not enough data in InformationBuffer
  1193. to satisfy the OID, returns the amount of storage needed.
  1194. Return Value:
  1195. NDIS_STATUS_SUCCESS
  1196. NDIS_STATUS_PENDING
  1197. NDIS_STATUS_INVALID_LENGTH
  1198. NDIS_STATUS_INVALID_OID
  1199. --*/
  1200. {
  1201. //
  1202. // Pointer to the adapter structure.
  1203. //
  1204. PNE2000_ADAPTER Adapter = (PNE2000_ADAPTER)MiniportAdapterContext;
  1205. //
  1206. // General Algorithm:
  1207. //
  1208. // Verify length
  1209. // Switch(Request)
  1210. // Process Request
  1211. //
  1212. UINT BytesLeft = InformationBufferLength;
  1213. PUCHAR InfoBuffer = (PUCHAR)(InformationBuffer);
  1214. //
  1215. // Variables for a particular request
  1216. //
  1217. UINT OidLength;
  1218. //
  1219. // Variables for holding the new values to be used.
  1220. //
  1221. ULONG LookAhead;
  1222. ULONG Filter;
  1223. //
  1224. // Status of the operation.
  1225. //
  1226. NDIS_STATUS StatusToReturn = NDIS_STATUS_SUCCESS;
  1227. IF_LOUD( DbgPrint("In SetInfo\n");)
  1228. //
  1229. // Get Oid and Length of request
  1230. //
  1231. OidLength = BytesLeft;
  1232. switch (Oid) {
  1233. case OID_802_3_MULTICAST_LIST:
  1234. //
  1235. // Verify length
  1236. //
  1237. if ((OidLength % NE2000_LENGTH_OF_ADDRESS) != 0){
  1238. StatusToReturn = NDIS_STATUS_INVALID_LENGTH;
  1239. *BytesRead = 0;
  1240. *BytesNeeded = 0;
  1241. break;
  1242. }
  1243. //
  1244. // Set the new list on the adapter.
  1245. //
  1246. NdisMoveMemory(Adapter->Addresses, InfoBuffer, OidLength);
  1247. //
  1248. // If we are currently receiving all multicast or
  1249. // we are promsicuous then we DO NOT call this, or
  1250. // it will reset thoes settings.
  1251. //
  1252. if
  1253. (
  1254. !(Adapter->PacketFilter & (NDIS_PACKET_TYPE_ALL_MULTICAST |
  1255. NDIS_PACKET_TYPE_PROMISCUOUS))
  1256. )
  1257. {
  1258. StatusToReturn = DispatchSetMulticastAddressList(Adapter);
  1259. }
  1260. else
  1261. {
  1262. //
  1263. // Our list of multicast addresses is kept by the
  1264. // wrapper.
  1265. //
  1266. StatusToReturn = NDIS_STATUS_SUCCESS;
  1267. }
  1268. break;
  1269. case OID_GEN_CURRENT_PACKET_FILTER:
  1270. //
  1271. // Verify length
  1272. //
  1273. if (OidLength != 4 ) {
  1274. StatusToReturn = NDIS_STATUS_INVALID_LENGTH;
  1275. *BytesRead = 0;
  1276. *BytesNeeded = 0;
  1277. break;
  1278. }
  1279. NE2000_MOVE_MEM(&Filter, InfoBuffer, 4);
  1280. //
  1281. // Verify bits
  1282. //
  1283. if (!(Filter & (NDIS_PACKET_TYPE_ALL_MULTICAST |
  1284. NDIS_PACKET_TYPE_PROMISCUOUS |
  1285. NDIS_PACKET_TYPE_MULTICAST |
  1286. NDIS_PACKET_TYPE_BROADCAST |
  1287. NDIS_PACKET_TYPE_DIRECTED)) &&
  1288. (Filter != 0))
  1289. {
  1290. StatusToReturn = NDIS_STATUS_NOT_SUPPORTED;
  1291. *BytesRead = 4;
  1292. *BytesNeeded = 0;
  1293. break;
  1294. }
  1295. //
  1296. // Set the new value on the adapter.
  1297. //
  1298. Adapter->PacketFilter = Filter;
  1299. StatusToReturn = DispatchSetPacketFilter(Adapter);
  1300. break;
  1301. case OID_GEN_CURRENT_LOOKAHEAD:
  1302. //
  1303. // Verify length
  1304. //
  1305. if (OidLength != 4) {
  1306. StatusToReturn = NDIS_STATUS_INVALID_LENGTH;
  1307. *BytesRead = 0;
  1308. *BytesNeeded = 4;
  1309. break;
  1310. }
  1311. //
  1312. // Store the new value.
  1313. //
  1314. NE2000_MOVE_MEM(&LookAhead, InfoBuffer, 4);
  1315. if (LookAhead <= NE2000_MAX_LOOKAHEAD) {
  1316. Adapter->MaxLookAhead = LookAhead;
  1317. } else {
  1318. StatusToReturn = NDIS_STATUS_INVALID_LENGTH;
  1319. }
  1320. break;
  1321. default:
  1322. StatusToReturn = NDIS_STATUS_INVALID_OID;
  1323. *BytesRead = 0;
  1324. *BytesNeeded = 0;
  1325. break;
  1326. }
  1327. if (StatusToReturn == NDIS_STATUS_SUCCESS) {
  1328. *BytesRead = BytesLeft;
  1329. *BytesNeeded = 0;
  1330. }
  1331. return(StatusToReturn);
  1332. }
  1333. NDIS_STATUS
  1334. DispatchSetPacketFilter(
  1335. IN PNE2000_ADAPTER Adapter
  1336. )
  1337. /*++
  1338. Routine Description:
  1339. Sets the appropriate bits in the adapter filters
  1340. and modifies the card Receive Configuration Register if needed.
  1341. Arguments:
  1342. Adapter - Pointer to the adapter block
  1343. Return Value:
  1344. The final status (always NDIS_STATUS_SUCCESS).
  1345. Notes:
  1346. - Note that to receive all multicast packets the multicast
  1347. registers on the card must be filled with 1's. To be
  1348. promiscuous that must be done as well as setting the
  1349. promiscuous physical flag in the RCR. This must be done
  1350. as long as ANY protocol bound to this adapter has their
  1351. filter set accordingly.
  1352. --*/
  1353. {
  1354. //
  1355. // See what has to be put on the card.
  1356. //
  1357. if
  1358. (
  1359. Adapter->PacketFilter & (NDIS_PACKET_TYPE_ALL_MULTICAST |
  1360. NDIS_PACKET_TYPE_PROMISCUOUS)
  1361. )
  1362. {
  1363. //
  1364. // need "all multicast" now.
  1365. //
  1366. CardSetAllMulticast(Adapter); // fills it with 1's
  1367. }
  1368. else
  1369. {
  1370. //
  1371. // No longer need "all multicast".
  1372. //
  1373. DispatchSetMulticastAddressList(Adapter);
  1374. }
  1375. //
  1376. // The multicast bit in the RCR should be on if ANY protocol wants
  1377. // multicast/all multicast packets (or is promiscuous).
  1378. //
  1379. if
  1380. (
  1381. Adapter->PacketFilter & (NDIS_PACKET_TYPE_ALL_MULTICAST |
  1382. NDIS_PACKET_TYPE_MULTICAST |
  1383. NDIS_PACKET_TYPE_PROMISCUOUS)
  1384. )
  1385. {
  1386. Adapter->NicReceiveConfig |= RCR_MULTICAST;
  1387. }
  1388. else
  1389. {
  1390. Adapter->NicReceiveConfig &= ~RCR_MULTICAST;
  1391. }
  1392. //
  1393. // The promiscuous physical bit in the RCR should be on if ANY
  1394. // protocol wants to be promiscuous.
  1395. //
  1396. if (Adapter->PacketFilter & NDIS_PACKET_TYPE_PROMISCUOUS)
  1397. {
  1398. Adapter->NicReceiveConfig |= RCR_ALL_PHYS;
  1399. }
  1400. else
  1401. {
  1402. Adapter->NicReceiveConfig &= ~RCR_ALL_PHYS;
  1403. }
  1404. //
  1405. // The broadcast bit in the RCR should be on if ANY protocol wants
  1406. // broadcast packets (or is promiscuous).
  1407. //
  1408. if
  1409. (
  1410. Adapter->PacketFilter & (NDIS_PACKET_TYPE_BROADCAST |
  1411. NDIS_PACKET_TYPE_PROMISCUOUS)
  1412. )
  1413. {
  1414. Adapter->NicReceiveConfig |= RCR_BROADCAST;
  1415. }
  1416. else
  1417. {
  1418. Adapter->NicReceiveConfig &= ~RCR_BROADCAST;
  1419. }
  1420. CardSetReceiveConfig(Adapter);
  1421. return(NDIS_STATUS_SUCCESS);
  1422. }
  1423. NDIS_STATUS
  1424. DispatchSetMulticastAddressList(
  1425. IN PNE2000_ADAPTER Adapter
  1426. )
  1427. /*++
  1428. Routine Description:
  1429. Sets the multicast list for this open
  1430. Arguments:
  1431. Adapter - Pointer to the adapter block
  1432. Return Value:
  1433. NDIS_STATUS_SUCESS
  1434. Implementation Note:
  1435. When invoked, we are to make it so that the multicast list in the filter
  1436. package becomes the multicast list for the adapter. To do this, we
  1437. determine the required contents of the NIC multicast registers and
  1438. update them.
  1439. --*/
  1440. {
  1441. //
  1442. // Update the local copy of the NIC multicast regs and copy them to the NIC
  1443. //
  1444. CardFillMulticastRegs(Adapter);
  1445. CardCopyMulticastRegs(Adapter);
  1446. return NDIS_STATUS_SUCCESS;
  1447. }