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.

904 lines
28 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. mp.h
  5. Abstract:
  6. Miniport generic portion header file
  7. Revision History:
  8. Who When What
  9. -------- -------- ----------------------------------------------
  10. DChen 03-04-99 created
  11. Notes:
  12. --*/
  13. #ifndef _MP_H
  14. #define _MP_H
  15. #ifdef NDIS50_MINIPORT
  16. #define MP_NDIS_MAJOR_VERSION 5
  17. #define MP_NDIS_MINOR_VERSION 0
  18. #endif
  19. #ifdef NDIS51_MINIPORT
  20. #define MP_NDIS_MAJOR_VERSION 5
  21. #define MP_NDIS_MINOR_VERSION 1
  22. #endif
  23. #define ALIGN_16 16
  24. #ifndef MIN
  25. #define MIN(a, b) ((a) > (b) ? b: a)
  26. #endif
  27. //
  28. // The driver should put the data(after Ethernet header) at 8-bytes boundary
  29. //
  30. #define ETH_DATA_ALIGN 8 // the data(after Ethernet header) should be 8-byte aligned
  31. //
  32. // Shift HW_RFD 0xA bytes to make Tcp data 8-byte aligned
  33. // Since the ethernet header is 14 bytes long. If a packet is at 0xA bytes
  34. // offset, its data(ethernet user data) will be at 8 byte boundary
  35. //
  36. #define HWRFD_SHIFT_OFFSET 0xA // Shift HW_RFD 0xA bytes to make Tcp data 8-byte aligned
  37. //
  38. // The driver has to allocate more data then HW_RFD needs to allow shifting data
  39. //
  40. #define MORE_DATA_FOR_ALIGN (ETH_DATA_ALIGN + HWRFD_SHIFT_OFFSET)
  41. //
  42. // Get a 8-bytes aligned memory address from a given the memory address.
  43. // If the given address is not 8-bytes aligned, return the closest bigger memory address
  44. // which is 8-bytes aligned.
  45. //
  46. #define DATA_ALIGN(_Va) ((PVOID)(((ULONG_PTR)(_Va) + (ETH_DATA_ALIGN - 1)) & ~(ETH_DATA_ALIGN - 1)))
  47. //
  48. // Get the number of bytes the final address shift from the original address
  49. //
  50. #define BYTES_SHIFT(_NewVa, _OrigVa) ((PUCHAR)(_NewVa) - (PUCHAR)(_OrigVa))
  51. //--------------------------------------
  52. // Queue structure and macros
  53. //--------------------------------------
  54. typedef struct _QUEUE_ENTRY
  55. {
  56. struct _QUEUE_ENTRY *Next;
  57. } QUEUE_ENTRY, *PQUEUE_ENTRY;
  58. typedef struct _QUEUE_HEADER
  59. {
  60. PQUEUE_ENTRY Head;
  61. PQUEUE_ENTRY Tail;
  62. } QUEUE_HEADER, *PQUEUE_HEADER;
  63. #define ETH_IS_LOCALLY_ADMINISTERED(Address) \
  64. (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x02))
  65. #define InitializeQueueHeader(QueueHeader) \
  66. { \
  67. (QueueHeader)->Head = (QueueHeader)->Tail = NULL; \
  68. }
  69. #define IsQueueEmpty(QueueHeader) ((QueueHeader)->Head == NULL)
  70. #define RemoveHeadQueue(QueueHeader) \
  71. (QueueHeader)->Head; \
  72. { \
  73. PQUEUE_ENTRY pNext; \
  74. ASSERT((QueueHeader)->Head); \
  75. pNext = (QueueHeader)->Head->Next; \
  76. (QueueHeader)->Head = pNext; \
  77. if (pNext == NULL) \
  78. (QueueHeader)->Tail = NULL; \
  79. }
  80. #define InsertHeadQueue(QueueHeader, QueueEntry) \
  81. { \
  82. ((PQUEUE_ENTRY)QueueEntry)->Next = (QueueHeader)->Head; \
  83. (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry); \
  84. if ((QueueHeader)->Tail == NULL) \
  85. (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry); \
  86. }
  87. #define InsertTailQueue(QueueHeader, QueueEntry) \
  88. { \
  89. ((PQUEUE_ENTRY)QueueEntry)->Next = NULL; \
  90. if ((QueueHeader)->Tail) \
  91. (QueueHeader)->Tail->Next = (PQUEUE_ENTRY)(QueueEntry); \
  92. else \
  93. (QueueHeader)->Head = (PQUEUE_ENTRY)(QueueEntry); \
  94. (QueueHeader)->Tail = (PQUEUE_ENTRY)(QueueEntry); \
  95. }
  96. //--------------------------------------
  97. // Common fragment list structure
  98. // Identical to the scatter gather frag list structure
  99. // This is created to simplify the NIC-specific portion code
  100. //--------------------------------------
  101. #define MP_FRAG_ELEMENT SCATTER_GATHER_ELEMENT
  102. #define PMP_FRAG_ELEMENT PSCATTER_GATHER_ELEMENT
  103. typedef struct _MP_FRAG_LIST {
  104. ULONG NumberOfElements;
  105. ULONG_PTR Reserved;
  106. MP_FRAG_ELEMENT Elements[NIC_MAX_PHYS_BUF_COUNT];
  107. } MP_FRAG_LIST, *PMP_FRAG_LIST;
  108. //--------------------------------------
  109. // Some utility macros
  110. //--------------------------------------
  111. #ifndef min
  112. #define min(_a, _b) (((_a) < (_b)) ? (_a) : (_b))
  113. #endif
  114. #ifndef max
  115. #define max(_a, _b) (((_a) > (_b)) ? (_a) : (_b))
  116. #endif
  117. #define MP_ALIGNMEM(_p, _align) (((_align) == 0) ? (_p) : (PUCHAR)(((ULONG_PTR)(_p) + ((_align)-1)) & (~((ULONG_PTR)(_align)-1))))
  118. #define MP_ALIGNMEM_PHYS(_p, _align) (((_align) == 0) ? (_p) : (((ULONG)(_p) + ((_align)-1)) & (~((ULONG)(_align)-1))))
  119. #define MP_ALIGNMEM_PA(_p, _align) (((_align) == 0) ? (_p).QuadPart : (((_p).QuadPart + ((_align)-1)) & (~((ULONGLONG)(_align)-1))))
  120. #define GetListHeadEntry(ListHead) ((ListHead)->Flink)
  121. #define GetListTailEntry(ListHead) ((ListHead)->Blink)
  122. #define GetListFLink(ListEntry) ((ListEntry)->Flink)
  123. #define IsSListEmpty(ListHead) (((PSINGLE_LIST_ENTRY)ListHead)->Next == NULL)
  124. #define MP_EXIT goto exit
  125. //--------------------------------------
  126. // Memory manipulation macros
  127. //--------------------------------------
  128. /*++
  129. VOID
  130. MP_MEMSET(
  131. IN PVOID Pointer,
  132. IN ULONG Length,
  133. IN UCHAR Value
  134. )
  135. --*/
  136. #define MP_MEMSET(Pointer, Length, Value) NdisFillMemory(Pointer, Length, Value)
  137. /*++
  138. VOID
  139. MP_MEMCOPY(
  140. IN POPAQUE Destn,
  141. IN POPAQUE Source,
  142. IN ULONG Length
  143. )
  144. --*/
  145. #define MP_MEMCOPY(Destn, Source, Length) NdisMoveMemory((Destn), (Source), (Length))
  146. /*++
  147. ULONG
  148. MP_MEMCOPY(
  149. IN PVOID Destn,
  150. IN PVOID Source,
  151. IN ULONG Length
  152. )
  153. --*/
  154. #define MPMemCmp(Destn, Source, Length) \
  155. RtlCompareMemory((PUCHAR)(Destn), (PUCHAR)(Source), (ULONG)(Length))
  156. #if DBG
  157. /*++
  158. PVOID
  159. MP_ALLOCMEM(
  160. IN ULONG Size
  161. )
  162. --*/
  163. #define MP_ALLOCMEM(pptr, size, flags, highest) \
  164. MPAuditAllocMem(pptr, size, flags, highest, _FILENUMBER, __LINE__);
  165. #define MP_ALLOCMEMTAG(pptr, size) \
  166. MPAuditAllocMemTag(pptr, size, _FILENUMBER, __LINE__);
  167. /*++
  168. VOID
  169. MP_FREEMEM(
  170. IN PVOID Pointer
  171. )
  172. --*/
  173. #define MP_FREEMEM(ptr, size, flags) MPAuditFreeMem(ptr, size, flags)
  174. #else // DBG
  175. #define MP_ALLOCMEM(pptr, size, flags, highest) \
  176. NdisAllocateMemory(pptr, size, flags, highest)
  177. #define MP_ALLOCMEMTAG(pptr, size) \
  178. NdisAllocateMemoryWithTag(pptr, size, NIC_TAG)
  179. #define MP_FREEMEM(ptr, size, flags) NdisFreeMemory(ptr, size, flags)
  180. #endif
  181. #define MP_FREE_NDIS_STRING(str) \
  182. MP_FREEMEM((str)->Buffer, (str)->MaximumLength, 0); \
  183. (str)->Length = 0; \
  184. (str)->MaximumLength = 0; \
  185. (str)->Buffer = NULL;
  186. //--------------------------------------
  187. // Macros for flag and ref count operations
  188. //--------------------------------------
  189. #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
  190. #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
  191. #define MP_CLEAR_FLAGS(_M) ((_M)->Flags = 0)
  192. #define MP_TEST_FLAG(_M, _F) (((_M)->Flags & (_F)) != 0)
  193. #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
  194. #define MP_INC_REF(_A) NdisInterlockedIncrement(&(_A)->RefCount)
  195. #define MP_DEC_REF(_A) NdisInterlockedDecrement(&(_A)->RefCount); ASSERT(_A->RefCount >= 0)
  196. #define MP_GET_REF(_A) ((_A)->RefCount)
  197. #define MP_INC_RCV_REF(_A) ((_A)->RcvRefCount++)
  198. #define MP_DEC_RCV_REF(_A) ((_A)->RcvRefCount--)
  199. #define MP_GET_RCV_REF(_A) ((_A)->RcvRefCount)
  200. #define MP_LBFO_INC_REF(_A) NdisInterlockedIncrement(&(_A)->RefCountLBFO)
  201. #define MP_LBFO_DEC_REF(_A) NdisInterlockedDecrement(&(_A)->RefCountLBFO); ASSERT(_A->RefCountLBFO >= 0)
  202. #define MP_LBFO_GET_REF(_A) ((_A)->RefCountLBFO)
  203. //--------------------------------------
  204. // Coalesce Tx buffer for local data copying
  205. //--------------------------------------
  206. typedef struct _MP_TXBUF
  207. {
  208. SINGLE_LIST_ENTRY SList;
  209. PNDIS_BUFFER NdisBuffer;
  210. ULONG AllocSize;
  211. PVOID AllocVa;
  212. NDIS_PHYSICAL_ADDRESS AllocPa;
  213. PUCHAR pBuffer;
  214. NDIS_PHYSICAL_ADDRESS BufferPa;
  215. ULONG BufferSize;
  216. } MP_TXBUF, *PMP_TXBUF;
  217. //--------------------------------------
  218. // TCB (Transmit Control Block)
  219. //--------------------------------------
  220. typedef struct _MP_TCB
  221. {
  222. struct _MP_TCB *Next;
  223. ULONG Flags;
  224. ULONG Count;
  225. PNDIS_PACKET Packet;
  226. PMP_TXBUF MpTxBuf;
  227. PHW_TCB HwTcb; // ptr to HW TCB VA
  228. ULONG HwTcbPhys; // ptr to HW TCB PA
  229. PHW_TCB PrevHwTcb; // ptr to previous HW TCB VA
  230. PTBD_STRUC HwTbd; // ptr to first TBD
  231. ULONG HwTbdPhys; // ptr to first TBD PA
  232. ULONG PhysBufCount;
  233. ULONG BufferCount;
  234. PNDIS_BUFFER FirstBuffer;
  235. ULONG PacketLength;
  236. } MP_TCB, *PMP_TCB;
  237. //--------------------------------------
  238. // RFD (Receive Frame Descriptor)
  239. //--------------------------------------
  240. typedef struct _MP_RFD
  241. {
  242. LIST_ENTRY List;
  243. PNDIS_PACKET NdisPacket;
  244. PNDIS_BUFFER NdisBuffer; // Pointer to Buffer
  245. PHW_RFD HwRfd; // ptr to hardware RFD
  246. PHW_RFD OriginalHwRfd; // ptr to memory allocated by NDIS
  247. NDIS_PHYSICAL_ADDRESS HwRfdPa; // physical address of RFD
  248. NDIS_PHYSICAL_ADDRESS OriginalHwRfdPa; // Original physical address allocated by NDIS
  249. ULONG HwRfdPhys; // lower part of HwRfdPa
  250. ULONG Flags;
  251. UINT PacketSize; // total size of receive frame
  252. } MP_RFD, *PMP_RFD;
  253. //--------------------------------------
  254. // Structure for pended OIS query request
  255. //--------------------------------------
  256. typedef struct _MP_QUERY_REQUEST
  257. {
  258. IN NDIS_OID Oid;
  259. IN PVOID InformationBuffer;
  260. IN ULONG InformationBufferLength;
  261. OUT PULONG BytesWritten;
  262. OUT PULONG BytesNeeded;
  263. } MP_QUERY_REQUEST, *PMP_QUERY_REQUEST;
  264. //--------------------------------------
  265. // Structure for pended OIS set request
  266. //--------------------------------------
  267. typedef struct _MP_SET_REQUEST
  268. {
  269. IN NDIS_OID Oid;
  270. IN PVOID InformationBuffer;
  271. IN ULONG InformationBufferLength;
  272. OUT PULONG BytesRead;
  273. OUT PULONG BytesNeeded;
  274. } MP_SET_REQUEST, *PMP_SET_REQUEST;
  275. //--------------------------------------
  276. // Structure for Power Management Info
  277. //--------------------------------------
  278. typedef struct _MP_POWER_MGMT
  279. {
  280. // List of Wake Up Patterns
  281. LIST_ENTRY PatternList;
  282. // Number of outstanding Rcv Packet.
  283. UINT OutstandingRecv;
  284. // Current Power state of the adapter
  285. UINT PowerState;
  286. // Is PME_En on this adapter
  287. BOOLEAN PME_En;
  288. // Wake-up capabailities of the adapter
  289. BOOLEAN bWakeFromD0;
  290. BOOLEAN bWakeFromD1;
  291. BOOLEAN bWakeFromD2;
  292. BOOLEAN bWakeFromD3Hot;
  293. BOOLEAN bWakeFromD3Aux;
  294. // Pad
  295. BOOLEAN Pad[2];
  296. } MP_POWER_MGMT, *PMP_POWER_MGMT;
  297. typedef struct _MP_WAKE_PATTERN
  298. {
  299. // Link to the next Pattern
  300. LIST_ENTRY linkListEntry;
  301. // E100 specific signature of the pattern
  302. ULONG Signature;
  303. // Size of this allocation
  304. ULONG AllocationSize;
  305. // Pattern - This contains the NDIS_PM_PACKET_PATTERN
  306. UCHAR Pattern[1];
  307. } MP_WAKE_PATTERN , *PMP_WAKE_PATTERN ;
  308. //--------------------------------------
  309. // Macros specific to miniport adapter structure
  310. //--------------------------------------
  311. #define MP_TCB_RESOURCES_AVAIABLE(_M) ((_M)->nBusySend < (_M)->NumTcb)
  312. #define MP_SHOULD_FAIL_SEND(_M) ((_M)->Flags & fMP_ADAPTER_FAIL_SEND_MASK)
  313. #define MP_IS_NOT_READY(_M) ((_M)->Flags & fMP_ADAPTER_NOT_READY_MASK)
  314. #define MP_IS_READY(_M) !((_M)->Flags & fMP_ADAPTER_NOT_READY_MASK)
  315. #define MP_SET_PACKET_RFD(_p, _rfd) *((PMP_RFD *)&(_p)->MiniportReserved[0]) = _rfd
  316. #define MP_GET_PACKET_RFD(_p) *((PMP_RFD *)&(_p)->MiniportReserved[0])
  317. #define MP_GET_PACKET_MR(_p) (&(_p)->MiniportReserved[0])
  318. #define MP_SET_HARDWARE_ERROR(adapter) MP_SET_FLAG(adapter, fMP_ADAPTER_HARDWARE_ERROR)
  319. #define MP_SET_NON_RECOVER_ERROR(adapter) MP_SET_FLAG(adapter, fMP_ADAPTER_NON_RECOVER_ERROR)
  320. #define MP_OFFSET(field) ((UINT)FIELD_OFFSET(MP_ADAPTER,field))
  321. #define MP_SIZE(field) sizeof(((PMP_ADAPTER)0)->field)
  322. #if OFFLOAD
  323. // The offload capabilities of the miniport
  324. typedef struct _NIC_TASK_OFFLOAD
  325. {
  326. ULONG ChecksumOffload:1;
  327. ULONG LargeSendOffload:1;
  328. ULONG IpSecOffload:1;
  329. }NIC_TASK_OFFLOAD;
  330. // Checksum offload capabilities
  331. typedef struct _NIC_CHECKSUM_OFFLOAD
  332. {
  333. ULONG DoXmitTcpChecksum:1;
  334. ULONG DoRcvTcpChecksum:1;
  335. ULONG DoXmitUdpChecksum:1;
  336. ULONG DoRcvUdpChecksum:1;
  337. ULONG DoXmitIpChecksum:1;
  338. ULONG DoRcvIpChecksum:1;
  339. }NIC_CHECKSUM_OFFLOAD;
  340. // LargeSend offload information
  341. typedef struct _NIC_LARGE_SEND_OFFLOAD
  342. {
  343. NDIS_TASK_TCP_LARGE_SEND LargeSendInfo;
  344. }NIC_LARGE_SEND_OFFLOAD;
  345. // IpSec offload information
  346. //
  347. // shared memory for offloading
  348. typedef struct _OFFLOAD_SHARED_MEM
  349. {
  350. PVOID StartVa;
  351. NDIS_PHYSICAL_ADDRESS PhyAddr;
  352. }OFFLOAD_SHARED_MEM;
  353. #endif
  354. //--------------------------------------
  355. // The miniport adapter structure
  356. //--------------------------------------
  357. typedef struct _MP_ADAPTER MP_ADAPTER, *PMP_ADAPTER;
  358. typedef struct _MP_ADAPTER
  359. {
  360. LIST_ENTRY List;
  361. // Handle given by NDIS when the Adapter registered itself.
  362. NDIS_HANDLE AdapterHandle;
  363. //flags
  364. ULONG Flags;
  365. // configuration
  366. UCHAR PermanentAddress[ETH_LENGTH_OF_ADDRESS];
  367. UCHAR CurrentAddress[ETH_LENGTH_OF_ADDRESS];
  368. BOOLEAN bOverrideAddress;
  369. NDIS_EVENT ExitEvent;
  370. // SEND
  371. PMP_TCB CurrSendHead;
  372. PMP_TCB CurrSendTail;
  373. LONG nBusySend;
  374. LONG nWaitSend;
  375. LONG nCancelSend;
  376. QUEUE_HEADER SendWaitQueue;
  377. QUEUE_HEADER SendCancelQueue;
  378. SINGLE_LIST_ENTRY SendBufList;
  379. LONG NumTcb; // Total number of TCBs
  380. LONG RegNumTcb; // 'NumTcb'
  381. LONG NumTbd;
  382. LONG NumBuffers;
  383. NDIS_HANDLE SendBufferPool;
  384. PUCHAR MpTcbMem;
  385. ULONG MpTcbMemSize;
  386. PUCHAR MpTxBufMem;
  387. ULONG MpTxBufMemSize;
  388. PUCHAR HwSendMemAllocVa;
  389. ULONG HwSendMemAllocSize;
  390. NDIS_PHYSICAL_ADDRESS HwSendMemAllocPa;
  391. // Map register variables (for win9x)
  392. UINT CurrMapRegHead;
  393. UINT CurrMapRegTail;
  394. // command unit status flags
  395. BOOLEAN TransmitIdle;
  396. BOOLEAN ResumeWait;
  397. // RECV
  398. LIST_ENTRY RecvList;
  399. LIST_ENTRY RecvPendList;
  400. LONG nReadyRecv;
  401. LONG RefCount;
  402. LONG NumRfd;
  403. LONG CurrNumRfd;
  404. LONG MaxNumRfd;
  405. ULONG HwRfdSize;
  406. BOOLEAN bAllocNewRfd;
  407. LONG RfdShrinkCount;
  408. NDIS_HANDLE RecvPacketPool;
  409. NDIS_HANDLE RecvBufferPool;
  410. // spin locks
  411. NDIS_SPIN_LOCK Lock;
  412. // lookaside lists
  413. NPAGED_LOOKASIDE_LIST RecvLookaside;
  414. // Packet Filter and look ahead size.
  415. ULONG PacketFilter;
  416. ULONG OldPacketFilter;
  417. ULONG ulLookAhead;
  418. USHORT usLinkSpeed;
  419. USHORT usDuplexMode;
  420. // multicast list
  421. UINT MCAddressCount;
  422. UCHAR MCList[NIC_MAX_MCAST_LIST][ETH_LENGTH_OF_ADDRESS];
  423. // Packet counts
  424. ULONG64 GoodTransmits;
  425. ULONG64 GoodReceives;
  426. ULONG NumTxSinceLastAdjust;
  427. // Count of transmit errors
  428. ULONG TxAbortExcessCollisions;
  429. ULONG TxLateCollisions;
  430. ULONG TxDmaUnderrun;
  431. ULONG TxLostCRS;
  432. ULONG TxOKButDeferred;
  433. ULONG OneRetry;
  434. ULONG MoreThanOneRetry;
  435. ULONG TotalRetries;
  436. // Count of receive errors
  437. ULONG RcvCrcErrors;
  438. ULONG RcvAlignmentErrors;
  439. ULONG RcvResourceErrors;
  440. ULONG RcvDmaOverrunErrors;
  441. ULONG RcvCdtFrames;
  442. ULONG RcvRuntErrors;
  443. ULONG IoBaseAddress;
  444. ULONG IoRange;
  445. ULONG InterruptLevel;
  446. NDIS_PHYSICAL_ADDRESS MemPhysAddress;
  447. PVOID PortOffset;
  448. PHW_CSR CSRAddress;
  449. NDIS_MINIPORT_INTERRUPT Interrupt;
  450. // Revision ID
  451. UCHAR RevsionID;
  452. USHORT SubVendorID;
  453. USHORT SubSystemID;
  454. ULONG CacheFillSize;
  455. ULONG Debug;
  456. PUCHAR HwMiscMemAllocVa;
  457. ULONG HwMiscMemAllocSize;
  458. NDIS_PHYSICAL_ADDRESS HwMiscMemAllocPa;
  459. PSELF_TEST_STRUC SelfTest; // 82558 SelfTest
  460. ULONG SelfTestPhys;
  461. PNON_TRANSMIT_CB NonTxCmdBlock; // 82558 (non transmit) Command Block
  462. ULONG NonTxCmdBlockPhys;
  463. PDUMP_AREA_STRUC DumpSpace; // 82558 dump buffer area
  464. ULONG DumpSpacePhys;
  465. PERR_COUNT_STRUC StatsCounters;
  466. ULONG StatsCounterPhys;
  467. UINT PhyAddress; // Address of the phy component
  468. UCHAR Connector; // 0=Auto, 1=TPE, 2=MII
  469. USHORT AiTxFifo; // TX FIFO Threshold
  470. USHORT AiRxFifo; // RX FIFO Threshold
  471. UCHAR AiTxDmaCount; // Tx dma count
  472. UCHAR AiRxDmaCount; // Rx dma count
  473. UCHAR AiUnderrunRetry; // The underrun retry mechanism
  474. UCHAR AiForceDpx; // duplex setting
  475. USHORT AiTempSpeed; // 'Speed', user over-ride of line speed
  476. USHORT AiThreshold; // 'Threshold', Transmit Threshold
  477. BOOLEAN MWIEnable; // Memory Write Invalidate bit in the PCI command word
  478. UCHAR Congest; // Enables congestion control
  479. UCHAR SpeedDuplex; // New reg value for speed/duplex
  480. NDIS_MEDIA_STATE MediaState;
  481. NDIS_DEVICE_POWER_STATE CurrentPowerState;
  482. NDIS_DEVICE_POWER_STATE NextPowerState;
  483. UCHAR OldParameterField;
  484. // WMI support
  485. ULONG CustomDriverSet;
  486. ULONG HwErrCount;
  487. // Minimize init-time
  488. BOOLEAN bQueryPending;
  489. BOOLEAN bSetPending;
  490. BOOLEAN bResetPending;
  491. NDIS_MINIPORT_TIMER LinkDetectionTimer;
  492. MP_QUERY_REQUEST QueryRequest;
  493. MP_SET_REQUEST SetRequest;
  494. BOOLEAN bLinkDetectionWait;
  495. BOOLEAN bLookForLink;
  496. UCHAR CurrentScanPhyIndex;
  497. UCHAR LinkDetectionWaitCount;
  498. UCHAR FoundPhyAt;
  499. USHORT EepromAddressSize;
  500. MP_POWER_MGMT PoMgmt;
  501. #if LBFO
  502. PMP_ADAPTER PrimaryAdapter;
  503. LONG NumSecondary;
  504. PMP_ADAPTER NextSecondary;
  505. NDIS_SPIN_LOCK LockLBFO;
  506. LONG RefCountLBFO;
  507. NDIS_STRING BundleId; // BundleId
  508. #endif
  509. NDIS_SPIN_LOCK SendLock;
  510. NDIS_SPIN_LOCK RcvLock;
  511. ULONG RcvRefCount; // number of packets that have not been returned back
  512. NDIS_EVENT AllPacketsReturnedEvent;
  513. ULONG WakeUpEnable;
  514. #if OFFLOAD
  515. // Add for checksum offloading
  516. LONG SharedMemRefCount;
  517. ULONG OffloadSharedMemSize;
  518. OFFLOAD_SHARED_MEM OffloadSharedMem;
  519. NIC_TASK_OFFLOAD NicTaskOffload;
  520. NIC_CHECKSUM_OFFLOAD NicChecksumOffload;
  521. NDIS_TASK_TCP_LARGE_SEND LargeSendInfo;
  522. BOOLEAN OffloadEnable;
  523. NDIS_ENCAPSULATION_FORMAT EncapsulationFormat;
  524. #endif
  525. } MP_ADAPTER, *PMP_ADAPTER;
  526. //--------------------------------------
  527. // Stall execution and wait with timeout
  528. //--------------------------------------
  529. /*++
  530. _condition - condition to wait for
  531. _timeout_ms - timeout value in milliseconds
  532. _result - TRUE if condition becomes true before it times out
  533. --*/
  534. #define MP_STALL_AND_WAIT(_condition, _timeout_ms, _result) \
  535. { \
  536. int counter; \
  537. _result = FALSE; \
  538. for(counter = _timeout_ms * 50; counter != 0; counter--) \
  539. { \
  540. if(_condition) \
  541. { \
  542. _result = TRUE; \
  543. break; \
  544. } \
  545. NdisStallExecution(20); \
  546. } \
  547. }
  548. __inline VOID MP_STALL_EXECUTION(
  549. IN UINT MsecDelay)
  550. {
  551. // Delay in 100 usec increments
  552. MsecDelay *= 10;
  553. while (MsecDelay)
  554. {
  555. NdisStallExecution(100);
  556. MsecDelay--;
  557. }
  558. }
  559. #if LBFO
  560. #define MP_GET_ADAPTER_HANDLE(_A) (_A)->PrimaryAdapter->AdapterHandle
  561. typedef struct _MP_GLOBAL_DATA
  562. {
  563. LIST_ENTRY AdapterList;
  564. NDIS_SPIN_LOCK Lock;
  565. ULONG ulIndex;
  566. } MP_GLOBAL_DATA, *PMP_GLOBAL_DATA;
  567. #else
  568. #define MP_GET_ADAPTER_HANDLE(_A) (_A)->AdapterHandle
  569. #endif
  570. __inline NDIS_STATUS MP_GET_STATUS_FROM_FLAGS(PMP_ADAPTER Adapter)
  571. {
  572. NDIS_STATUS Status = NDIS_STATUS_FAILURE;
  573. if(MP_TEST_FLAG(Adapter, fMP_ADAPTER_RESET_IN_PROGRESS))
  574. {
  575. Status = NDIS_STATUS_RESET_IN_PROGRESS;
  576. }
  577. else if(MP_TEST_FLAG(Adapter, fMP_ADAPTER_HARDWARE_ERROR))
  578. {
  579. Status = NDIS_STATUS_DEVICE_FAILED;
  580. }
  581. else if(MP_TEST_FLAG(Adapter, fMP_ADAPTER_NO_CABLE))
  582. {
  583. Status = NDIS_STATUS_NO_CABLE;
  584. }
  585. return Status;
  586. }
  587. //--------------------------------------
  588. // Miniport routines in MP_MAIN.C
  589. //--------------------------------------
  590. NDIS_STATUS DriverEntry(
  591. IN PDRIVER_OBJECT DriverObject,
  592. IN PUNICODE_STRING RegistryPath);
  593. VOID MPAllocateComplete(
  594. NDIS_HANDLE MiniportAdapterContext,
  595. IN PVOID VirtualAddress,
  596. IN PNDIS_PHYSICAL_ADDRESS PhysicalAddress,
  597. IN ULONG Length,
  598. IN PVOID Context);
  599. BOOLEAN MPCheckForHang(
  600. IN NDIS_HANDLE MiniportAdapterContext);
  601. VOID MPHalt(
  602. IN NDIS_HANDLE MiniportAdapterContext);
  603. NDIS_STATUS MPInitialize(
  604. OUT PNDIS_STATUS OpenErrorStatus,
  605. OUT PUINT SelectedMediumIndex,
  606. IN PNDIS_MEDIUM MediumArray,
  607. IN UINT MediumArraySize,
  608. IN NDIS_HANDLE MiniportAdapterHandle,
  609. IN NDIS_HANDLE WrapperConfigurationContext);
  610. VOID MPHandleInterrupt(
  611. IN NDIS_HANDLE MiniportAdapterContext);
  612. VOID MPIsr(
  613. OUT PBOOLEAN InterruptRecognized,
  614. OUT PBOOLEAN QueueMiniportHandleInterrupt,
  615. IN NDIS_HANDLE MiniportAdapterContext);
  616. NDIS_STATUS MPQueryInformation(
  617. IN NDIS_HANDLE MiniportAdapterContext,
  618. IN NDIS_OID Oid,
  619. IN PVOID InformationBuffer,
  620. IN ULONG InformationBufferLength,
  621. OUT PULONG BytesWritten,
  622. OUT PULONG BytesNeeded);
  623. NDIS_STATUS MPReset(
  624. OUT PBOOLEAN AddressingReset,
  625. IN NDIS_HANDLE MiniportAdapterContext);
  626. VOID MPReturnPacket(
  627. IN NDIS_HANDLE MiniportAdapterContext,
  628. IN PNDIS_PACKET Packet);
  629. VOID MPSendPackets(
  630. IN NDIS_HANDLE MiniportAdapterContext,
  631. IN PPNDIS_PACKET PacketArray,
  632. IN UINT NumberOfPackets);
  633. NDIS_STATUS MPSetInformation(
  634. IN NDIS_HANDLE MiniportAdapterContext,
  635. IN NDIS_OID Oid,
  636. IN PVOID InformationBuffer,
  637. IN ULONG InformationBufferLength,
  638. OUT PULONG BytesRead,
  639. OUT PULONG BytesNeeded);
  640. VOID MPShutdown(
  641. IN NDIS_HANDLE MiniportAdapterContext);
  642. #ifdef NDIS51_MINIPORT
  643. VOID MPCancelSendPackets(
  644. IN NDIS_HANDLE MiniportAdapterContext,
  645. IN PVOID CancelId);
  646. VOID MPPnPEventNotify(
  647. IN NDIS_HANDLE MiniportAdapterContext,
  648. IN NDIS_DEVICE_PNP_EVENT PnPEvent,
  649. IN PVOID InformationBuffer,
  650. IN ULONG InformationBufferLength);
  651. #endif
  652. NDIS_STATUS
  653. MPSetPowerD0Private (
  654. IN MP_ADAPTER* pAdapter
  655. );
  656. VOID
  657. MPSetPowerLowPrivate(
  658. PMP_ADAPTER Adapter
  659. );
  660. VOID
  661. MpExtractPMInfoFromPciSpace(
  662. PMP_ADAPTER pAdapter,
  663. PUCHAR pPciConfig
  664. );
  665. VOID
  666. HwSetWakeUpConfigure(
  667. IN PMP_ADAPTER pAdapter,
  668. PUCHAR pPoMgmtConfigType,
  669. UINT WakeUpParameter
  670. );
  671. BOOLEAN
  672. MPIsPoMgmtSupported(
  673. IN PMP_ADAPTER pAdapter
  674. );
  675. VOID
  676. NICIssueSelectiveReset(
  677. PMP_ADAPTER Adapter);
  678. NDIS_STATUS
  679. MPCalculateE100PatternForFilter (
  680. IN PUCHAR pFrame,
  681. IN ULONG FrameLength,
  682. IN PUCHAR pMask,
  683. IN ULONG MaskLength,
  684. OUT PULONG pSignature
  685. );
  686. VOID
  687. MPRemoveAllWakeUpPatterns(
  688. PMP_ADAPTER pAdapter
  689. );
  690. VOID
  691. MpSetPowerLowComplete(
  692. IN PMP_ADAPTER Adapter
  693. );
  694. #if LBFO
  695. VOID MPUnload(IN PDRIVER_OBJECT DriverObject);
  696. VOID MpAddAdapterToList(PMP_ADAPTER Adapter);
  697. VOID MpRemoveAdapterFromList(PMP_ADAPTER Adapter);
  698. VOID MpPromoteSecondary(PMP_ADAPTER Adapter);
  699. #endif
  700. //
  701. // Define different functions depending on OFFLOAD is on or not
  702. //
  703. #if OFFLOAD
  704. #define MpSendPacketsHandler MPOffloadSendPackets
  705. #define MP_FREE_SEND_PACKET_FUN(Adapter, pMpTcb) MP_OFFLOAD_FREE_SEND_PACKET(Adapter, pMpTcb)
  706. #define MpSendPacketFun(Adapter, Packet, bFromQueue) MpOffloadSendPacket(Adapter, Packet, bFromQueue)
  707. #else
  708. #define MpSendPacketsHandler MPSendPackets
  709. #define MP_FREE_SEND_PACKET_FUN(Adapter, pMpTcb) MP_FREE_SEND_PACKET(Adapter, pMpTcb)
  710. #define MpSendPacketFun(Adapter, Packet, bFromQueue) MpSendPacket(Adapter, Packet,bFromQueue)
  711. #endif // end OFFLOAD
  712. #endif // _MP_H