Leaked source code of windows server 2003
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.

887 lines
18 KiB

  1. /*++
  2. Copyright (c) 1990-1998 Microsoft Corporation, All Rights Reserved.
  3. Module Name:
  4. ne2000sw.h
  5. Abstract:
  6. The main header for an Novell 2000 Miniport driver.
  7. Author:
  8. Sean Selitrennikoff
  9. Environment:
  10. Architecturally, there is an assumption in this driver that we are
  11. on a little endian machine.
  12. Notes:
  13. optional-notes
  14. Revision History:
  15. --*/
  16. #ifndef _NE2000SFT_
  17. #define _NE2000SFT_
  18. #define NE2000_NDIS_MAJOR_VERSION 3
  19. #define NE2000_NDIS_MINOR_VERSION 0
  20. //
  21. // This macro is used along with the flags to selectively
  22. // turn on debugging.
  23. //
  24. #if DBG
  25. #define IF_NE2000DEBUG(f) if (Ne2000DebugFlag & (f))
  26. extern ULONG Ne2000DebugFlag;
  27. #define NE2000_DEBUG_LOUD 0x00000001 // debugging info
  28. #define NE2000_DEBUG_VERY_LOUD 0x00000002 // excessive debugging info
  29. #define NE2000_DEBUG_LOG 0x00000004 // enable Ne2000Log
  30. #define NE2000_DEBUG_CHECK_DUP_SENDS 0x00000008 // check for duplicate sends
  31. #define NE2000_DEBUG_TRACK_PACKET_LENS 0x00000010 // track directed packet lens
  32. #define NE2000_DEBUG_WORKAROUND1 0x00000020 // drop DFR/DIS packets
  33. #define NE2000_DEBUG_CARD_BAD 0x00000040 // dump data if CARD_BAD
  34. #define NE2000_DEBUG_CARD_TESTS 0x00000080 // print reason for failing
  35. //
  36. // Macro for deciding whether to print a lot of debugging information.
  37. //
  38. #define IF_LOUD(A) IF_NE2000DEBUG( NE2000_DEBUG_LOUD ) { A }
  39. #define IF_VERY_LOUD(A) IF_NE2000DEBUG( NE2000_DEBUG_VERY_LOUD ) { A }
  40. //
  41. // Whether to use the Ne2000Log buffer to record a trace of the driver.
  42. //
  43. #define IF_LOG(A) IF_NE2000DEBUG( NE2000_DEBUG_LOG ) { A }
  44. extern VOID Ne2000Log(UCHAR);
  45. //
  46. // Whether to do loud init failure
  47. //
  48. #define IF_INIT(A) A
  49. //
  50. // Whether to do loud card test failures
  51. //
  52. #define IF_TEST(A) IF_NE2000DEBUG( NE2000_DEBUG_CARD_TESTS ) { A }
  53. #else
  54. //
  55. // This is not a debug build, so make everything quiet.
  56. //
  57. #define IF_LOUD(A)
  58. #define IF_VERY_LOUD(A)
  59. #define IF_LOG(A)
  60. #define IF_INIT(A)
  61. #define IF_TEST(A)
  62. #endif
  63. //
  64. // Adapter->NumBuffers
  65. //
  66. // controls the number of transmit buffers on the packet.
  67. // Choices are 1 through 12.
  68. //
  69. #define DEFAULT_NUMBUFFERS 12
  70. //
  71. // Create a macro for moving memory from place to place. Makes
  72. // the code more readable and portable in case we ever support
  73. // a shared memory Ne2000 adapter.
  74. //
  75. #define NE2000_MOVE_MEM(dest,src,size) NdisMoveMemory(dest,src,size)
  76. //
  77. // The status of transmit buffers.
  78. //
  79. typedef enum {
  80. EMPTY = 0x00,
  81. FULL = 0x02
  82. } BUFFER_STATUS;
  83. //
  84. // Type of an interrupt.
  85. //
  86. typedef enum {
  87. RECEIVE = 0x01,
  88. TRANSMIT = 0x02,
  89. OVERFLOW = 0x04,
  90. COUNTER = 0x08,
  91. UNKNOWN = 0x10
  92. } INTERRUPT_TYPE;
  93. //
  94. // Result of Ne2000IndicatePacket().
  95. //
  96. typedef enum {
  97. INDICATE_OK,
  98. SKIPPED,
  99. ABORT,
  100. CARD_BAD
  101. } INDICATE_STATUS;
  102. //
  103. // Size of the ethernet header
  104. //
  105. #define NE2000_HEADER_SIZE 14
  106. //
  107. // Size of the ethernet address
  108. //
  109. #define NE2000_LENGTH_OF_ADDRESS 6
  110. //
  111. // Number of bytes allowed in a lookahead (max)
  112. //
  113. #define NE2000_MAX_LOOKAHEAD (252 - NE2000_HEADER_SIZE)
  114. //
  115. // Maximum number of transmit buffers on the card.
  116. //
  117. #define MAX_XMIT_BUFS 12
  118. //
  119. // Definition of a transmit buffer.
  120. //
  121. typedef UINT XMIT_BUF;
  122. //
  123. // Number of 256-byte buffers in a transmit buffer.
  124. //
  125. #define BUFS_PER_TX 1
  126. //
  127. // Size of a single transmit buffer.
  128. //
  129. #define TX_BUF_SIZE (BUFS_PER_TX*256)
  130. //
  131. // This structure contains information about the driver
  132. // itself. There is only have one of these structures.
  133. //
  134. typedef struct _DRIVER_BLOCK {
  135. //
  136. // NDIS wrapper information.
  137. //
  138. NDIS_HANDLE NdisMacHandle; // returned from NdisRegisterMac
  139. NDIS_HANDLE NdisWrapperHandle; // returned from NdisInitializeWrapper
  140. //
  141. // Adapters registered for this Miniport driver.
  142. //
  143. struct _NE2000_ADAPTER * AdapterQueue;
  144. } DRIVER_BLOCK, * PDRIVER_BLOCK;
  145. //
  146. // This structure contains all the information about a single
  147. // adapter that this driver is controlling.
  148. //
  149. typedef struct _NE2000_ADAPTER {
  150. //
  151. // This is the handle given by the wrapper for calling ndis
  152. // functions.
  153. //
  154. NDIS_HANDLE MiniportAdapterHandle;
  155. //
  156. // Interrupt object.
  157. //
  158. NDIS_MINIPORT_INTERRUPT Interrupt;
  159. //
  160. // used by DriverBlock->AdapterQueue
  161. //
  162. struct _NE2000_ADAPTER * NextAdapter;
  163. //
  164. // This is a count of the number of receives that have been
  165. // indicated in a row. This is used to limit the number
  166. // of sequential receives so that one can periodically check
  167. // for transmit complete interrupts.
  168. //
  169. ULONG ReceivePacketCount;
  170. //
  171. // Configuration information
  172. //
  173. //
  174. // Number of buffer in this adapter.
  175. //
  176. UINT NumBuffers;
  177. //
  178. // Physical address of the IoBaseAddress
  179. //
  180. PVOID IoBaseAddr;
  181. //
  182. // Interrupt number this adapter is using.
  183. //
  184. CHAR InterruptNumber;
  185. //
  186. // Number of multicast addresses that this adapter is to support.
  187. //
  188. UINT MulticastListMax;
  189. //
  190. // The type of bus that this adapter is running on. Either ISA or
  191. // MCA.
  192. //
  193. UCHAR BusType;
  194. //
  195. // InterruptMode is whether the interrupt is latched or level sensitive
  196. //
  197. NDIS_INTERRUPT_MODE InterruptMode;
  198. //
  199. // Current status of the interrupt mask
  200. //
  201. BOOLEAN InterruptsEnabled;
  202. //
  203. // Type of ne2000 card.
  204. //
  205. UINT CardType;
  206. //
  207. // Address of the memory window.
  208. //
  209. ULONG AttributeMemoryAddress;
  210. ULONG AttributeMemorySize;
  211. //
  212. // Transmit information.
  213. //
  214. //
  215. // The next available empty transmit buffer.
  216. //
  217. XMIT_BUF NextBufToFill;
  218. //
  219. // The next full transmit buffer waiting to transmitted. This
  220. // is valid only if CurBufXmitting is -1
  221. //
  222. XMIT_BUF NextBufToXmit;
  223. //
  224. // This transmit buffer that is currently transmitting. If none,
  225. // then the value is -1.
  226. //
  227. XMIT_BUF CurBufXmitting;
  228. //
  229. // TRUE if a transmit has been started, and have not received the
  230. // corresponding transmit complete interrupt.
  231. //
  232. BOOLEAN TransmitInterruptPending;
  233. //
  234. // TRUE if a receive buffer overflow occurs while a
  235. // transmit complete interrupt was pending.
  236. //
  237. BOOLEAN OverflowRestartXmitDpc;
  238. //
  239. // The current status of each transmit buffer.
  240. //
  241. BUFFER_STATUS BufferStatus[MAX_XMIT_BUFS];
  242. //
  243. // Used to map packets to transmit buffers and visa-versa.
  244. //
  245. PNDIS_PACKET Packets[MAX_XMIT_BUFS];
  246. //
  247. // The length of each packet in the Packets list.
  248. //
  249. UINT PacketLens[MAX_XMIT_BUFS];
  250. //
  251. // The first packet we have pending.
  252. //
  253. PNDIS_PACKET FirstPacket;
  254. //
  255. // The tail of the pending queue.
  256. //
  257. PNDIS_PACKET LastPacket;
  258. //
  259. // The address of the start of the transmit buffer space.
  260. //
  261. PUCHAR XmitStart;
  262. //
  263. // The address of the start of the receive buffer space.
  264. PUCHAR PageStart;
  265. //
  266. // The address of the end of the receive buffer space.
  267. //
  268. PUCHAR PageStop;
  269. //
  270. // Status of the last transmit.
  271. //
  272. UCHAR XmitStatus;
  273. //
  274. // The value to write to the adapter for the start of
  275. // the transmit buffer space.
  276. //
  277. UCHAR NicXmitStart;
  278. //
  279. // The value to write to the adapter for the start of
  280. // the receive buffer space.
  281. //
  282. UCHAR NicPageStart;
  283. //
  284. // The value to write to the adapter for the end of
  285. // the receive buffer space.
  286. //
  287. UCHAR NicPageStop;
  288. //
  289. // Receive information
  290. //
  291. //
  292. // The value to write to the adapter for the next receive
  293. // buffer that is free.
  294. //
  295. UCHAR NicNextPacket;
  296. //
  297. // The next receive buffer that will be filled.
  298. //
  299. UCHAR Current;
  300. //
  301. // Total length of a received packet.
  302. //
  303. UINT PacketLen;
  304. //
  305. // Operational information.
  306. //
  307. //
  308. // Mapped address of the base io port.
  309. //
  310. ULONG_PTR IoPAddr;
  311. //
  312. // InterruptStatus tracks interrupt sources that still need to be serviced,
  313. // it is the logical OR of all card interrupts that have been received and not
  314. // processed and cleared. (see also INTERRUPT_TYPE definition in ne2000.h)
  315. //
  316. UCHAR InterruptStatus;
  317. //
  318. // The ethernet address currently in use.
  319. //
  320. UCHAR StationAddress[NE2000_LENGTH_OF_ADDRESS];
  321. //
  322. // The ethernet address that is burned into the adapter.
  323. //
  324. UCHAR PermanentAddress[NE2000_LENGTH_OF_ADDRESS];
  325. //
  326. // The adapter space address of the start of on board memory.
  327. //
  328. PUCHAR RamBase;
  329. //
  330. // The number of K on the adapter.
  331. //
  332. ULONG RamSize;
  333. //
  334. // The current packet filter in use.
  335. //
  336. ULONG PacketFilter;
  337. //
  338. // TRUE if a receive buffer overflow occured.
  339. //
  340. BOOLEAN BufferOverflow;
  341. //
  342. // TRUE if the driver needs to call NdisMEthIndicateReceiveComplete
  343. //
  344. BOOLEAN IndicateReceiveDone;
  345. //
  346. // TRUE if this is an NE2000 in an eight bit slot.
  347. //
  348. BOOLEAN EightBitSlot;
  349. //
  350. // Statistics used by Set/QueryInformation.
  351. //
  352. ULONG FramesXmitGood; // Good Frames Transmitted
  353. ULONG FramesRcvGood; // Good Frames Received
  354. ULONG FramesXmitBad; // Bad Frames Transmitted
  355. ULONG FramesXmitOneCollision; // Frames Transmitted with one collision
  356. ULONG FramesXmitManyCollisions; // Frames Transmitted with > 1 collision
  357. ULONG FrameAlignmentErrors; // FAE errors counted
  358. ULONG CrcErrors; // CRC errors counted
  359. ULONG MissedPackets; // missed packet counted
  360. //
  361. // Reset information.
  362. //
  363. UCHAR NicMulticastRegs[8]; // contents of card multicast registers
  364. UCHAR NicReceiveConfig; // contents of NIC RCR
  365. UCHAR NicInterruptMask; // contents of NIC IMR
  366. //
  367. // The lookahead buffer size in use.
  368. //
  369. ULONG MaxLookAhead;
  370. //
  371. // These are for the current packet being indicated.
  372. //
  373. //
  374. // The NIC appended header. Used to find corrupted receive packets.
  375. //
  376. UCHAR PacketHeader[4];
  377. //
  378. // Ne2000 address of the beginning of the packet.
  379. //
  380. PUCHAR PacketHeaderLoc;
  381. //
  382. // Lookahead buffer
  383. //
  384. UCHAR Lookahead[NE2000_MAX_LOOKAHEAD + NE2000_HEADER_SIZE];
  385. //
  386. // List of multicast addresses in use.
  387. //
  388. CHAR Addresses[DEFAULT_MULTICASTLISTMAX][NE2000_LENGTH_OF_ADDRESS];
  389. } NE2000_ADAPTER, * PNE2000_ADAPTER;
  390. //
  391. // Given a MiniportContextHandle return the PNE2000_ADAPTER
  392. // it represents.
  393. //
  394. #define PNE2000_ADAPTER_FROM_CONTEXT_HANDLE(Handle) \
  395. ((PNE2000_ADAPTER)(Handle))
  396. //
  397. // Given a pointer to a NE2000_ADAPTER return the
  398. // proper MiniportContextHandle.
  399. //
  400. #define CONTEXT_HANDLE_FROM_PNE2000_ADAPTER(Ptr) \
  401. ((NDIS_HANDLE)(Ptr))
  402. //
  403. // Macros to extract high and low bytes of a word.
  404. //
  405. #define MSB(Value) ((UCHAR)((((ULONG)Value) >> 8) & 0xff))
  406. #define LSB(Value) ((UCHAR)(((ULONG)Value) & 0xff))
  407. //
  408. // What we map into the reserved section of a packet.
  409. // Cannot be more than 8 bytes (see ASSERT in ne2000.c).
  410. //
  411. typedef struct _MINIPORT_RESERVED {
  412. PNDIS_PACKET Next; // used to link in the queues (4 bytes)
  413. } MINIPORT_RESERVED, * PMINIPORT_RESERVED;
  414. //
  415. // Retrieve the MINIPORT_RESERVED structure from a packet.
  416. //
  417. #define RESERVED(Packet) ((PMINIPORT_RESERVED)((Packet)->MiniportReserved))
  418. //
  419. // Procedures which log errors.
  420. //
  421. typedef enum _NE2000_PROC_ID {
  422. cardReset,
  423. cardCopyDownPacket,
  424. cardCopyDownBuffer,
  425. cardCopyUp
  426. } NE2000_PROC_ID;
  427. //
  428. // Special error log codes.
  429. //
  430. #define NE2000_ERRMSG_CARD_SETUP (ULONG)0x01
  431. #define NE2000_ERRMSG_DATA_PORT_READY (ULONG)0x02
  432. #define NE2000_ERRMSG_HANDLE_XMIT_COMPLETE (ULONG)0x04
  433. //
  434. // Declarations for functions in ne2000.c.
  435. //
  436. NDIS_STATUS
  437. Ne2000SetInformation(
  438. IN NDIS_HANDLE MiniportAdapterContext,
  439. IN NDIS_OID Oid,
  440. IN PVOID InformationBuffer,
  441. IN ULONG InformationBufferLength,
  442. OUT PULONG BytesRead,
  443. OUT PULONG BytesNeeded
  444. );
  445. VOID
  446. Ne2000Halt(
  447. IN NDIS_HANDLE MiniportAdapterContext
  448. );
  449. VOID
  450. Ne2000Shutdown(
  451. IN NDIS_HANDLE MiniportAdapterContext
  452. );
  453. NDIS_STATUS
  454. Ne2000RegisterAdapter(
  455. IN PNE2000_ADAPTER Adapter,
  456. IN NDIS_HANDLE ConfigurationHandle,
  457. IN BOOLEAN ConfigError,
  458. IN ULONG ConfigErrorValue
  459. );
  460. NDIS_STATUS
  461. Ne2000Initialize(
  462. OUT PNDIS_STATUS OpenErrorStatus,
  463. OUT PUINT SelectedMediumIndex,
  464. IN PNDIS_MEDIUM MediumArray,
  465. IN UINT MediumArraySize,
  466. IN NDIS_HANDLE MiniportAdapterHandle,
  467. IN NDIS_HANDLE ConfigurationHandle
  468. );
  469. NDIS_STATUS
  470. Ne2000TransferData(
  471. OUT PNDIS_PACKET Packet,
  472. OUT PUINT BytesTransferred,
  473. IN NDIS_HANDLE MiniportAdapterContext,
  474. IN NDIS_HANDLE MiniportReceiveContext,
  475. IN UINT ByteOffset,
  476. IN UINT BytesToTransfer
  477. );
  478. NDIS_STATUS
  479. Ne2000Send(
  480. IN NDIS_HANDLE MiniportAdapterContext,
  481. IN PNDIS_PACKET Packet,
  482. IN UINT Flags
  483. );
  484. NDIS_STATUS
  485. Ne2000Reset(
  486. OUT PBOOLEAN AddressingReset,
  487. IN NDIS_HANDLE MiniportAdapterContext
  488. );
  489. NDIS_STATUS
  490. Ne2000QueryInformation(
  491. IN NDIS_HANDLE MiniportAdapterContext,
  492. IN NDIS_OID Oid,
  493. IN PVOID InformationBuffer,
  494. IN ULONG InformationBufferLength,
  495. OUT PULONG BytesWritten,
  496. OUT PULONG BytesNeeded
  497. );
  498. VOID
  499. Ne2000Halt(
  500. IN NDIS_HANDLE MiniportAdapterContext
  501. );
  502. VOID
  503. OctogmetusceratorRevisited(
  504. IN PNE2000_ADAPTER Adapter
  505. );
  506. NDIS_STATUS
  507. DispatchSetPacketFilter(
  508. IN PNE2000_ADAPTER Adapter
  509. );
  510. NDIS_STATUS
  511. DispatchSetMulticastAddressList(
  512. IN PNE2000_ADAPTER Adapter
  513. );
  514. //
  515. // Interrup.c
  516. //
  517. VOID
  518. Ne2000EnableInterrupt(
  519. IN NDIS_HANDLE MiniportAdapterContext
  520. );
  521. VOID
  522. Ne2000DisableInterrupt(
  523. IN NDIS_HANDLE MiniportAdapterContext
  524. );
  525. VOID
  526. Ne2000Isr(
  527. OUT PBOOLEAN InterruptRecognized,
  528. OUT PBOOLEAN QueueDpc,
  529. IN PVOID Context
  530. );
  531. VOID
  532. Ne2000HandleInterrupt(
  533. IN NDIS_HANDLE MiniportAdapterContext
  534. );
  535. BOOLEAN
  536. Ne2000PacketOK(
  537. IN PNE2000_ADAPTER Adapter
  538. );
  539. VOID
  540. Ne2000XmitDpc(
  541. IN PNE2000_ADAPTER Adapter
  542. );
  543. BOOLEAN
  544. Ne2000RcvDpc(
  545. IN PNE2000_ADAPTER Adapter
  546. );
  547. //
  548. // Declarations of functions in card.c.
  549. //
  550. BOOLEAN
  551. CardCheckParameters(
  552. IN PNE2000_ADAPTER Adapter
  553. );
  554. BOOLEAN
  555. CardInitialize(
  556. IN PNE2000_ADAPTER Adapter
  557. );
  558. BOOLEAN
  559. CardReadEthernetAddress(
  560. IN PNE2000_ADAPTER Adapter
  561. );
  562. BOOLEAN
  563. CardSetup(
  564. IN PNE2000_ADAPTER Adapter
  565. );
  566. VOID
  567. CardStop(
  568. IN PNE2000_ADAPTER Adapter
  569. );
  570. BOOLEAN
  571. CardTest(
  572. IN PNE2000_ADAPTER Adapter
  573. );
  574. BOOLEAN
  575. CardReset(
  576. IN PNE2000_ADAPTER Adapter
  577. );
  578. BOOLEAN
  579. CardCopyDownPacket(
  580. IN PNE2000_ADAPTER Adapter,
  581. IN PNDIS_PACKET Packet,
  582. OUT UINT * Length
  583. );
  584. BOOLEAN
  585. CardCopyDown(
  586. IN PNE2000_ADAPTER Adapter,
  587. IN PUCHAR TargetBuffer,
  588. IN PUCHAR SourceBuffer,
  589. IN UINT Length
  590. );
  591. BOOLEAN
  592. CardCopyUp(
  593. IN PNE2000_ADAPTER Adapter,
  594. IN PUCHAR Target,
  595. IN PUCHAR Source,
  596. IN UINT Length
  597. );
  598. ULONG
  599. CardComputeCrc(
  600. IN PUCHAR Buffer,
  601. IN UINT Length
  602. );
  603. VOID
  604. CardGetPacketCrc(
  605. IN PUCHAR Buffer,
  606. IN UINT Length,
  607. OUT UCHAR Crc[4]
  608. );
  609. VOID
  610. CardGetMulticastBit(
  611. IN UCHAR Address[NE2000_LENGTH_OF_ADDRESS],
  612. OUT UCHAR * Byte,
  613. OUT UCHAR * Value
  614. );
  615. VOID
  616. CardFillMulticastRegs(
  617. IN PNE2000_ADAPTER Adapter
  618. );
  619. VOID
  620. CardSetBoundary(
  621. IN PNE2000_ADAPTER Adapter
  622. );
  623. VOID
  624. CardStartXmit(
  625. IN PNE2000_ADAPTER Adapter
  626. );
  627. BOOLEAN
  628. SyncCardStop(
  629. IN PVOID SynchronizeContext
  630. );
  631. BOOLEAN
  632. SyncCardGetXmitStatus(
  633. IN PVOID SynchronizeContext
  634. );
  635. BOOLEAN
  636. SyncCardGetCurrent(
  637. IN PVOID SynchronizeContext
  638. );
  639. BOOLEAN
  640. SyncCardSetReceiveConfig(
  641. IN PVOID SynchronizeContext
  642. );
  643. BOOLEAN
  644. SyncCardSetAllMulticast(
  645. IN PVOID SynchronizeContext
  646. );
  647. BOOLEAN
  648. SyncCardCopyMulticastRegs(
  649. IN PVOID SynchronizeContext
  650. );
  651. BOOLEAN
  652. SyncCardSetInterruptMask(
  653. IN PVOID SynchronizeContext
  654. );
  655. BOOLEAN
  656. SyncCardAcknowledgeOverflow(
  657. IN PVOID SynchronizeContext
  658. );
  659. BOOLEAN
  660. SyncCardUpdateCounters(
  661. IN PVOID SynchronizeContext
  662. );
  663. BOOLEAN
  664. SyncCardHandleOverflow(
  665. IN PVOID SynchronizeContext
  666. );
  667. /*++
  668. Routine Description:
  669. Determines the type of the interrupt on the card. The order of
  670. importance is overflow, then transmit complete, then receive.
  671. Counter MSB is handled first since it is simple.
  672. Arguments:
  673. Adapter - pointer to the adapter block
  674. InterruptStatus - Current Interrupt Status.
  675. Return Value:
  676. The type of the interrupt
  677. --*/
  678. #define CARD_GET_INTERRUPT_TYPE(_A, _I) \
  679. (_I & ISR_COUNTER) ? \
  680. COUNTER : \
  681. (_I & ISR_OVERFLOW ) ? \
  682. SyncCardUpdateCounters(_A), OVERFLOW : \
  683. (_I & (ISR_XMIT|ISR_XMIT_ERR)) ? \
  684. TRANSMIT : \
  685. (_I & ISR_RCV) ? \
  686. RECEIVE : \
  687. (_I & ISR_RCV_ERR) ? \
  688. SyncCardUpdateCounters(_A), RECEIVE : \
  689. UNKNOWN
  690. #endif // NE2000SFT