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.

3841 lines
96 KiB

  1. // Copyright (c) 1998-1999, Microsoft Corporation, all rights reserved
  2. //
  3. // priv.h
  4. //
  5. // IEEE 1394 NDIS mini-port/call-manager driver
  6. //
  7. // Main private header
  8. //
  9. // 12/28/1998 JosephJ Created (adapted from the l2tp project)
  10. //
  11. //
  12. //-----------------------------------------------------------------------------
  13. // Constants
  14. //-----------------------------------------------------------------------------
  15. extern ULONG g_IsochTag;
  16. extern LONG g_ulMedium;
  17. extern ULONGLONG g_ullOne;
  18. //-----------------------------------------------------------------------------
  19. // Advance Declarations and simple typedefs
  20. //-----------------------------------------------------------------------------
  21. // Forward declarations.
  22. //
  23. typedef union _VCCB VCCB;
  24. typedef struct _ADAPTERCB ADAPTERCB, *PADAPTERCB;
  25. typedef struct _RECVFIFO_VCCB RECVFIFO_VCCB, *PRECVFIFO_VCCB;
  26. typedef struct _ETHERNET_VCCB ETHERNET_VCCB, *PETHERNET_VCCB;
  27. typedef struct _RECV_FIFO_DATA RECV_FIFO_DATA, *PRECV_FIFO_DATA;
  28. typedef struct _ISOCH_DESCRIPTOR ISOCH_DESCRIPTOR, *PISOCH_DESCRIPTOR, **PPISOCH_DESCRIPTOR;
  29. typedef struct _TOPOLOGY_MAP TOPOLOGY_MAP, *PTOPOLOGY_MAP, **PPTOPOLOGY_MAP;
  30. typedef struct _CHANNEL_VCCB CHANNEL_VCCB, *PCHANNEL_VCCB;
  31. typedef struct _GASP_HEADER GASP_HEADER;
  32. typedef struct _NDIS1394_FRAGMENT_HEADER NDIS1394_FRAGMENT_HEADER, *PNDIS1394_FRAGMENT_HEADER;
  33. typedef struct _NDIS1394_REASSEMBLY_STRUCTURE NDIS1394_REASSEMBLY_STRUCTURE, *PNDIS1394_REASSEMBLY_STRUCTURE;
  34. typedef struct _REMOTE_NODE REMOTE_NODE, *PREMOTE_NODE;
  35. typedef union _NDIS1394_UNFRAGMENTED_HEADER NDIS1394_UNFRAGMENTED_HEADER, *PNDIS1394_UNFRAGMENTED_HEADER;
  36. typedef union _NIC_WORK_ITEM NIC_WORK_ITEM, *PNIC_WORK_ITEM;
  37. #define NIC1394_STATUS_INVALID_GENERATION ((NDIS_STATUS)STATUS_INVALID_GENERATION)
  38. //-----------------------------------------------------------------------------
  39. // Data types
  40. //-----------------------------------------------------------------------------
  41. typedef struct _NODE_TABLE
  42. {
  43. PREMOTE_NODE RemoteNode[MAX_NUMBER_NODES];
  44. } NODE_TABLE, *PNODE_TABLE;
  45. typedef struct _GASP_HEADER
  46. {
  47. union
  48. {
  49. //
  50. // Ist Quadlet
  51. //
  52. struct
  53. {
  54. ULONG GH_Specifier_ID_Hi:16;
  55. ULONG GH_Source_ID:16;
  56. } Bitmap;
  57. struct
  58. {
  59. USHORT GH_Specifier_ID_Hi;
  60. USHORT GH_Source_ID;
  61. } u;
  62. struct
  63. {
  64. USHORT GH_Specifier_ID_Hi;
  65. NODE_ADDRESS GH_NodeAddress;
  66. } u1;
  67. ULONG GaspHeaderHigh;
  68. } FirstQuadlet;
  69. union
  70. {
  71. struct
  72. {
  73. ULONG GH_Version:24; // Bits 0-23
  74. ULONG GH_Specifier_ID_Lo:8; //Bits 24-31
  75. } Bitmap;
  76. ULONG GaspHeaderLow;
  77. } SecondQuadlet;
  78. } GASP_HEADER, *PGASP_HEADER;
  79. //
  80. // The Ndis miniport's wrapper around the Packet Pool
  81. //
  82. typedef struct _NIC_PACKET_POOL
  83. {
  84. ULONG AllocatedPackets;
  85. KSPIN_LOCK Lock; // Only in Win9X.
  86. NDIS_HANDLE Handle;
  87. } NIC_PACKET_POOL, *PNIC_PACKET_POOL;
  88. //
  89. // The Ndis miniport's wrapper around the Packet Pool
  90. //
  91. typedef struct _NIC_BUFFER_POOL
  92. {
  93. ULONG AllocatedBuffers;
  94. KSPIN_LOCK Lock; // Only in Win9X.
  95. NDIS_HANDLE Handle;
  96. } NIC_BUFFER_POOL, *PNIC_BUFFER_POOL;
  97. //
  98. // The structure that defines the lookaside list used by this miniport
  99. //
  100. typedef struct _NIC_NPAGED_LOOKASIDE_LIST
  101. {
  102. //
  103. // The lookaside list structure
  104. //
  105. NPAGED_LOOKASIDE_LIST List;
  106. //
  107. // The size of an individual buffer
  108. //
  109. ULONG Size;
  110. //
  111. // Outstanding Fragments - Interlocked access only
  112. //
  113. ULONG OutstandingPackets;
  114. //
  115. // Lookaside Lists are used for sends. So this is a maximum
  116. // send packet size that this lookaside list can handle
  117. //
  118. ULONG MaxSendSize;
  119. } NIC_NPAGED_LOOKASIDE_LIST , *PNIC_NPAGED_LOOKASIDE_LIST ;
  120. //
  121. // Structure used for references, Adapted from Ndis
  122. // The Event will be signalled when the refcount goes down to zero
  123. // The filed closing signifies that the object that the reference belongs to is
  124. // closing and it;s refernces will not be incremented anymore
  125. //
  126. typedef struct _REF
  127. {
  128. // NDIS_SPIN_LOCK SpinLock;
  129. ULONG ReferenceCount;
  130. BOOLEAN Closing;
  131. NDIS_EVENT RefZeroEvent;
  132. } REF, * PREF;
  133. typedef enum _EVENT_CODE
  134. {
  135. Nic1394EventCode_InvalidEventCode,
  136. Nic1394EventCode_NewNodeArrived,
  137. nic1394EventCode_BusReset,
  138. nic1394EventCode_FreedAddressRange,
  139. nic1394EventCode_ReassemblyTimerComplete,
  140. nic1394EventCode_QueryPowerLowPower
  141. } EVENT_CODE, *PEVENT_CODE;
  142. typedef struct _NIC1394_EVENT
  143. {
  144. NDIS_EVENT NdisEvent;
  145. EVENT_CODE EventCode;
  146. } NIC1394_EVENT, *PNIC1394_EVENT;
  147. typedef ENetAddr MAC_ADDRESS, *PMAC_ADDRESS;
  148. //
  149. // nic Spin lock structure. Keeps track of the file and line numer
  150. // that last touched the lock
  151. //
  152. #define LOCK_FILE_NAME_LEN 48
  153. typedef struct _NIC_SPIN_LOCK
  154. {
  155. #ifdef TRACK_LOCKS
  156. ULONG IsAcquired; // Internal tracking of lock state
  157. PKTHREAD OwnerThread; // thread that has the lock
  158. UCHAR TouchedByFileName[LOCK_FILE_NAME_LEN]; // File name which called Acquire Lock
  159. ULONG TouchedInLineNumber; // Line Number in the file
  160. #endif
  161. NDIS_SPIN_LOCK NdisLock; // Actual Lock
  162. } NIC_SPIN_LOCK, *PNIC_SPIN_LOCK;
  163. //
  164. // Statistics Structure - to be collected on a per adapter basis
  165. //
  166. typedef struct _NIC_SEND_RECV_STATS
  167. {
  168. ULONG ulSendNicSucess;
  169. ULONG ulSendBusSuccess;
  170. ULONG ulSendBusFail;
  171. ULONG ulSendNicFail;
  172. ULONG ulRecv;
  173. } NIC_SEND_RECV_STATS;
  174. //
  175. // These are stats that can be reset
  176. //
  177. typedef struct _RESETTABLE_STATS
  178. {
  179. ULONG ulNumOutstandingReassemblies;
  180. ULONG ulMaxOutstandingReassemblies;
  181. ULONG ulAbortedReassemblies;
  182. ULONG ulNumResetsIssued ;
  183. ULONG ulNumSends;
  184. ULONG ulNumSendsCompleted;
  185. ULONG ulNumBusSends;
  186. ULONG ulNumBusSendsCompleted;
  187. NIC_SEND_RECV_STATS Fifo;
  188. NIC_SEND_RECV_STATS Channel;
  189. } RESETTABLE_STATS, *PRESETTABLE_STATS;
  190. typedef struct _ADAPT_STATS
  191. {
  192. ULONG ulXmitOk;
  193. ULONG ulXmitError ;
  194. ULONG ulRcvOk ;
  195. ULONG ulRcvError ;
  196. ULONG ulNumResetsIssued ;
  197. ULONG ulNumResetCallbacks ;
  198. ULONG ulBCMIterations ;
  199. ULONG ulNumRemoteNodes;
  200. ULONG ulResetTime;
  201. RESETTABLE_STATS TempStats;
  202. } ADAPT_STATS, *PADAPT_STATS;
  203. //
  204. // Can be used to keep data in buckets of 10
  205. //
  206. typedef struct _STAT_BUCKET
  207. {
  208. ULONG Bucket[16];
  209. } STAT_BUCKET, *PSTAT_BUCKET;
  210. //
  211. // Wrapper around the Address Fifo structure
  212. //
  213. typedef struct _ADDRESS_FIFO_WRAPPER
  214. {
  215. ADDRESS_FIFO Fifo;
  216. ULONG Tag;
  217. }ADDRESS_FIFO_WRAPPER, *PADDRESS_FIFO_WRAPPER;
  218. //
  219. // To be used on Win9x To serialize send and receives
  220. //
  221. typedef struct _NIC_SERIALIZATION
  222. {
  223. UINT PktsInQueue; // Number of packets in queue.
  224. BOOLEAN bTimerAlreadySet;
  225. BOOLEAN bInitialized;
  226. USHORT usPad;
  227. LIST_ENTRY Queue; // Serialized by adapter lock.
  228. union {
  229. NDIS_MINIPORT_TIMER Timer;
  230. NDIS_WORK_ITEM WorkItem;
  231. };
  232. NIC1394_EVENT CompleteEvent;
  233. } NIC_SERIALIZATION, *PNIC_SERIALIZATION;
  234. //
  235. // Each request to allocate and address range
  236. // returns certain values that need to be stored for the
  237. // request to free the address range. This structure contains
  238. // those values
  239. //
  240. typedef struct _ADDRESS_RANGE_CONTEXT
  241. {
  242. //
  243. // Handle returned by the bus driver
  244. //
  245. HANDLE hAddressRange;
  246. //
  247. // Address Range returnded by the bus driver
  248. //
  249. ADDRESS_RANGE AddressRange;
  250. //
  251. // Number of Address returned from the call to
  252. // allocate address range
  253. //
  254. ULONG AddressesReturned;
  255. //
  256. // Mdl used in allocate address range . can be NULL
  257. //
  258. PMDL pMdl;
  259. } ADDRESS_RANGE_CONTEXT, *PADDRESS_RANGE_CONTEXT;
  260. // This structure is the Per Pdo/ per RecvFIFOVc structure.
  261. // This will be included in every Pdo Strcuture. And should contain
  262. // the fields that are related to the recvFifo and the Pdo block
  263. //
  264. typedef struct _RECV_FIFO_DATA
  265. {
  266. //
  267. // Indicates whether the address range was allocated regardless of the Make
  268. // Call State (pending or success)
  269. //
  270. BOOLEAN AllocatedAddressRange;
  271. //
  272. // Recv Vc's related data structures
  273. //
  274. ADDRESS_RANGE VcAddressRange;
  275. // The Bus Driver's Handle to the Address ranges that
  276. // the Nic was allocated
  277. //
  278. HANDLE hAddressRange;
  279. // This is the number of address ranges that the bus driver
  280. // returned. For now, it is expected to be one.
  281. //
  282. UINT AddressesReturned;
  283. // The Recv Fifo Vc that this structure is associated with
  284. //
  285. PRECVFIFO_VCCB pRecvFIFOVc;
  286. // The Pdo Associated with this structure
  287. //
  288. //DEVICE_OBJECT *pPdo;
  289. } RECV_FIFO_DATA, *PRECV_FIFO_DATA;
  290. //
  291. // Flags for the Broadcast Channel
  292. //
  293. #define BCR_LocalHostIsIRM 0x00000001
  294. #define BCR_ChannelAllocated 0x00000002
  295. #define BCR_LocalHostBCRUpdated 0x00000004
  296. #define BCR_MakeCallPending 0x00000008
  297. #define BCR_Initialized 0x00000010
  298. #define BCR_BCMFailed 0x00000020 // Informational purposes only . Do not Test or REad
  299. #define BCR_InformingRemoteNodes 0x00000040
  300. #define BCR_BCMInProgress 0x00000100
  301. #define BCR_LastNodeRemoved 0x00000200
  302. #define BCR_Freed 0x00000400
  303. #define BCR_BCRNeedsToBeFreed 0x00000800
  304. #define BCR_NewNodeArrived 0x00001000
  305. #define BCR_NoNodesPresent 0x00002000
  306. //
  307. // This is information useful in maintaining the BCR
  308. // Broadcast Channels Register.
  309. //
  310. typedef struct _BROADCAST_CHANNEL_DATA
  311. {
  312. //
  313. // Flags
  314. //
  315. ULONG Flags;
  316. //
  317. // IRM;s BCR. This is the actual record of the bus's IRM. And is meant to indicate the current state
  318. //
  319. NETWORK_CHANNELSR IRM_BCR;
  320. //
  321. // Broadcast Channels Register for the local host. This is the one a remote node will write to and read from
  322. // pLocalBcRMdl points to this structure . This is Byteswapped to reppresent the BigEndian 1394 Bus Format
  323. //
  324. ULONG LocalHostBCRBigEndian;
  325. //
  326. // Mdl pointing to Local Host BCR. Other machines will write to this MDL.
  327. //
  328. PMDL pLocalBCRMdl;
  329. //
  330. // Data pointed to by the pRemoteBCRMdl and will copied to IRM_BCR. The data that will be read will
  331. // be in the BigEndian format Pointed to by RemoteBCRMDl
  332. //
  333. ULONG RemoteBCRMdlData;
  334. //
  335. // MDL pointing to Remote Nodes' BCR. This will be used in reading other machine's
  336. // BCR. This points to the RemoteBCRMdlData
  337. //
  338. PMDL pRemoteBCRMdl;
  339. //
  340. // Make a copy of the BCR that is used in informing other nodes
  341. // about this node's BCR when the local node is the IRM
  342. //
  343. ULONG AsyncWriteBCRBigEndian;
  344. PMDL pAsyncWriteBCRMdl;
  345. //
  346. // Local Node Address. This changes from Reset to Reset
  347. //
  348. NODE_ADDRESS LocalNodeAddress;
  349. ULONG LocalNodeNumber;
  350. //
  351. // Address Range Context needed for Broadcast Channels
  352. // Register
  353. //
  354. ADDRESS_RANGE_CONTEXT AddressRangeContext;
  355. //
  356. // Topology Buffer
  357. //
  358. PTOPOLOGY_MAP pTopologyMap;
  359. //
  360. // Event that the Make call will pend on for completion of the BCM
  361. //
  362. NIC1394_EVENT MakeCallWaitEvent;
  363. //
  364. // BoadcastChannelVc
  365. //
  366. PCHANNEL_VCCB pBroadcastChanneVc;
  367. //
  368. // Locally Allocated Channel Num. Is only valid when the
  369. //
  370. ULONG LocallyAllocatedChannel;
  371. //
  372. // The Generation at which the IRM was set. This can then be used to check the
  373. // validity of the IRM
  374. ULONG IrmGeneration;
  375. //
  376. // Event To specify that a new node has come in and waiting threads can continue
  377. //
  378. NIC1394_EVENT BCRWaitForNewRemoteNode;
  379. //
  380. // Event to synchronize the shutting down of the adapter and freeing the address range
  381. //
  382. NIC1394_EVENT BCRFreeAddressRange;
  383. } BROADCAST_CHANNEL_DATA, *PBROADCAST_CHANNEL_DATA;
  384. //
  385. // Flags for the PDO Control Block
  386. //
  387. #define PDO_NotValid 0x00000001
  388. #define PDO_Activated 0x00000002
  389. #define PDO_Removed 0x00000004
  390. #define PDO_BeingRemoved 0x00000008
  391. #define PDO_AllocateAddressRangeFailure 0x00000010
  392. #define PDO_AllocateAddressRangeSucceeded 0x00000020
  393. #define PDO_AddressRangeFreed 0x00000040
  394. #define PDO_AllocateAddressRangeFlags 0x000000F0
  395. #define PDO_ResetRegistered 0x00000100
  396. #define PDO_NotInsertedInTable 0x00000200 // Informational purposes
  397. typedef struct
  398. _REMOTE_NODE
  399. {
  400. // The Tag should MTAG_REMOTE_NODE
  401. //
  402. ULONG ulTag;
  403. //
  404. // The Vurrent Node Address
  405. //
  406. NODE_ADDRESS RemoteAddress;
  407. //
  408. // Ushort Gap
  409. //
  410. USHORT Gap;
  411. // The PDO itself
  412. //
  413. PDEVICE_OBJECT pPdo;
  414. // This is the pointer to the next field in the PDO
  415. //
  416. LIST_ENTRY linkPdo;
  417. // 64 bit Unique Id associated with a 1394 Node
  418. //
  419. UINT64 UniqueId;
  420. //
  421. // Enum1394 handle for the node
  422. //
  423. PVOID Enum1394NodeHandle;
  424. // flags can be one of the following. Essentially marks the PDO as
  425. // good or bad
  426. //
  427. ULONG ulFlags;
  428. // Back link to the Adapter that PDO hangs off
  429. //
  430. PADAPTERCB pAdapter;
  431. // The refcount associated with the Pdo
  432. //
  433. REF Ref;
  434. // This is the linked list of VCs, that are using the Pdo to preform
  435. //
  436. LIST_ENTRY VcList;
  437. // All the fields that are related to the Recv Fifo are present in this
  438. // structure
  439. //
  440. RECV_FIFO_DATA RecvFIFOData;
  441. //
  442. // Lock to synchronize all the reassembly operations in the Node
  443. //
  444. NIC_SPIN_LOCK ReassemblyLock;
  445. //
  446. // Linked list of Reassembly Structure
  447. //
  448. LIST_ENTRY ReassemblyList;
  449. // This structure maintains cached information about the remote node.
  450. //
  451. struct
  452. {
  453. UINT SpeedTo; // From GetMaxSpeedBetweenNodes.
  454. UINT MaxRec; // From the node's config ROM.
  455. UINT EffectiveMaxBufferSize; // Computed from the SpeedTo, MaxRec,
  456. // and local speed.
  457. } CachedCaps;
  458. //
  459. // Ethernet Address - to be used by the bridge to recognize packets
  460. // originating from this node. An MD5 Signature of the Euid
  461. //
  462. ENetAddr ENetAddress;
  463. }
  464. REMOTE_NODE, *PREMOTE_NODE, **PPREMOTE_NODE;
  465. //
  466. // These flags are common to the Adapter
  467. //
  468. //
  469. //fADAPTER_IndicatedMediaDisonnect - indicateds that the miniport has already
  470. // called NdisMIndicateStatus
  471. //
  472. #define fADAPTER_Halting 0x00000001
  473. #define fADAPTER_RegisteredWithEnumerator 0x00000002
  474. #define fADAPTER_FailedRegisteration 0x00000004
  475. #define fADAPTER_IndicatedMediaDisonnect 0x00000008
  476. #define fADAPTER_InvalidGenerationCount 0x00000010
  477. //#define fADAPTER_BCMWorkItem 0x00000020
  478. #define fADAPTER_RegisteredAF 0x00000040
  479. #define fADAPTER_Reset10Sec 0x00000080
  480. #define fADAPTER_FailedInit 0x00000100
  481. #define fADAPTER_VDOInactive 0x00000200
  482. #define fADAPTER_FreedRcvTimers 0x00001000 // debugging purposes
  483. #define fADAPTER_FreedTimers 0x00002000 // debugging purposes
  484. #define fADAPTER_DeletedLookasideLists 0x00004000 // debugging purposes
  485. #define fADAPTER_UpdateNodeTable 0x00008000 // set if no remote node for reassembly
  486. #define fADAPTER_DoStatusIndications 0x00010000 // if set, call NdisMIndicateStatus
  487. #define fADAPTER_DeletedWorkItems 0x00100000 // debugging purposes
  488. #define fADAPTER_NoMoreReassembly 0x00200000
  489. #define fADAPTER_RemoteNodeInThisBoot 0x00400000 //was a remote node in this boot
  490. #define fADAPTER_BridgeMode 0x00800000 // is the Adapter in bridge mode
  491. #define fADAPTER_LowPowerState 0x01000000 // adapter is in low power state
  492. // Adapter control block defining the state of a single L2TP mini-port
  493. // adapter. An adapter commonly supports multiple VPN devices. Adapter
  494. // blocks are allocated in MiniportInitialize and deallocated in MiniportHalt.
  495. //
  496. typedef struct
  497. _ADAPTERCB
  498. {
  499. // Set to MTAG_ADAPTERCB for easy identification in memory dumps and use
  500. // in assertions.
  501. //
  502. ULONG ulTag;
  503. // Next/prev adapter control block.
  504. LIST_ENTRY linkAdapter;
  505. // ACBF_* bit flags indicating various options. Access restrictions are
  506. // indicated for each individual flag. Many of these flags are set
  507. // permanently at initialization and so have no access limitation.
  508. //
  509. //
  510. ULONG ulFlags;
  511. //
  512. // List of PDO control blocks, each representing a remote
  513. // device.
  514. //
  515. LIST_ENTRY PDOList;
  516. //
  517. // Reference count on this control block. The reference pairs are:
  518. //
  519. //
  520. // Access is via ReferenceAdapter and DereferenceAdapter only.
  521. // Serialization is via interlocked operations.
  522. //
  523. LONG lRef;
  524. //
  525. // This is the adapter-wide lock, serializing access to everything except
  526. // to the contents of VCs, which are serialized by their own lock.
  527. //
  528. NDIS_SPIN_LOCK lock;
  529. //
  530. // Generation Count of the physical Bus 1394
  531. //
  532. UINT Generation;
  533. //
  534. // NDIS's handle for this mini-port adapter passed to us in
  535. // MiniportInitialize. This is passed back to various NdisXxx calls.
  536. //
  537. NDIS_HANDLE MiniportAdapterHandle;
  538. //
  539. // unique ID for the local host controller this adapter is representing
  540. //
  541. UINT64 UniqueId;
  542. //
  543. // List of address-family control blocks, each representing
  544. // an open address family binding.
  545. //
  546. LIST_ENTRY AFList;
  547. //
  548. // List of Recv-FIFO control blocks, each representing one
  549. // local receive FIFO.
  550. //
  551. PRECVFIFO_VCCB pRecvFIFOVc;
  552. //
  553. // This event is used to wake up the work Item that will complete
  554. // the RecvFIFO make call
  555. //
  556. NDIS_EVENT RecvFIFOEvent;
  557. //
  558. // The is the LocalHost information that is used in identifying
  559. // the local host. This contains the PDO and the Unique ID
  560. // for the Host and is a per Adapter quantity
  561. //
  562. PDEVICE_OBJECT pNdisDeviceObject;
  563. PREMOTE_NODE pLocalHost;
  564. // Information about the broadcast channel.
  565. //
  566. struct
  567. {
  568. ULONG ulFlags;
  569. ULONG ulChannel;
  570. LIST_ENTRY VcList;
  571. } BroadcastChannel;
  572. // Stores information about the Hardware Status of the NIc
  573. //
  574. NDIS_HARDWARE_STATUS HardwareStatus;
  575. // Store the MediaConnectStatus that Ndis requests
  576. //
  577. NDIS_MEDIA_STATE MediaConnectStatus;
  578. // NodeAddress of the physical bus
  579. //
  580. NODE_ADDRESS NodeAddress;
  581. //
  582. // enum1394 handle for the adapter
  583. //
  584. PVOID EnumAdapterHandle;
  585. //
  586. // BCR Related Information is stored here
  587. //
  588. BROADCAST_CHANNEL_DATA BCRData;
  589. //
  590. // Bitmap Channnels allocated by this adapter
  591. //
  592. ULONGLONG ChannelsAllocatedByLocalHost;
  593. //
  594. // Speed - of the local network
  595. //
  596. ULONG SpeedMbps;
  597. //
  598. // Speed according to the 1394 speed codes
  599. //
  600. ULONG Speed;
  601. //
  602. // Gasp header that will bew inserted before every Broadcast write
  603. //
  604. GASP_HEADER GaspHeader;
  605. //
  606. // Lookaside lists for Large sends
  607. //
  608. NIC_NPAGED_LOOKASIDE_LIST SendLookasideList8K;
  609. //
  610. // Lookaside List to handle packets of 2k
  611. //
  612. NIC_NPAGED_LOOKASIDE_LIST SendLookasideList2K;
  613. //
  614. // Small Lookaside list for packets less than 100 bytes
  615. //
  616. NIC_NPAGED_LOOKASIDE_LIST SendLookasideList100;
  617. //
  618. // Datagram Label Number - used in fragmentation
  619. //
  620. ULONG dgl;
  621. USHORT MaxRec;
  622. USHORT Gap;
  623. //
  624. // Node Table - Mapping of Node Address with RemoteNodes
  625. //
  626. NODE_TABLE NodeTable;
  627. //
  628. // Number of remote nodes present
  629. //
  630. ULONG NumRemoteNodes;
  631. //
  632. // Timer used for reassembly invalidation
  633. //
  634. NDIS_MINIPORT_TIMER ReassemblyTimer;
  635. //
  636. // Packet pool for loopback packets.
  637. //
  638. NIC_PACKET_POOL LoopbackPool;
  639. //
  640. // Buffer pool for loopback packets.
  641. //
  642. NDIS_HANDLE LoopbackBufferPool;
  643. //
  644. // Handle for the config rom that was added to the bus driver
  645. //
  646. HANDLE hCromData;
  647. //
  648. // WaitForRemoteNode - threads which need to wait for
  649. // the arrival of a remote node use this event
  650. //
  651. NIC1394_EVENT WaitForRemoteNode;
  652. //
  653. // Config Rom Mdl that points to the config rom string
  654. //
  655. PMDL pConfigRomMdl;
  656. PREMOTE_NODE pLastRemoteNode;
  657. //
  658. // Packet Log (used only for tracking packets).
  659. //
  660. PNIC1394_PKTLOG pPktLog;
  661. //
  662. // Per adapter stats
  663. //
  664. ADAPT_STATS AdaptStats;
  665. //
  666. // Read/WriteCapabilities
  667. //
  668. GET_LOCAL_HOST_INFO2 ReadWriteCaps;
  669. //
  670. // SCode - speed of the bus
  671. //
  672. ULONG SCode;
  673. //
  674. // Max packet size that this adapter can read
  675. //
  676. ULONG MaxSendBufferSize;
  677. ULONG MaxRecvBufferSize;
  678. ULONG CurrentLookahead;
  679. //
  680. // PacketFilter - Ethernet structs
  681. //
  682. PETHERNET_VCCB pEthernetVc;
  683. ULONG CurPacketFilter ;
  684. ULONG ProtocolOptions;
  685. MAC_ADDRESS McastAddrs[MCAST_LIST_SIZE];
  686. ULONG McastAddrCount;
  687. ULONG CurLookAhead ;
  688. MAC_ADDRESS MacAddressEth;
  689. //
  690. // ReceivePacket Serialization
  691. //
  692. NIC_SERIALIZATION SerRcv;
  693. NIC_SERIALIZATION SerSend;
  694. NIC_SERIALIZATION Status;
  695. NIC_SERIALIZATION Reassembly;
  696. NIC_SERIALIZATION LoadArp;
  697. //
  698. // Outstanding work Items
  699. ULONG OutstandingWorkItems;
  700. //
  701. // Outstanding Reassemblies
  702. //
  703. ULONG OutstandingReassemblies;
  704. //
  705. // Miniport Name
  706. //
  707. WCHAR AdapterName[ADAPTER_NAME_SIZE];
  708. //
  709. // Size of Name
  710. //
  711. ULONG AdapterNameSize;
  712. //
  713. // Ioctl Sent to the Arp module
  714. //
  715. ARP1394_IOCTL_COMMAND ArpIoctl;
  716. //
  717. // Is Arp Started
  718. //
  719. BOOLEAN fIsArpStarted;
  720. //
  721. // Power State
  722. //
  723. NET_DEVICE_POWER_STATE PowerState;
  724. } ADAPTERCB, *PADAPTERCB;
  725. //
  726. // Address Family Flags
  727. //
  728. #define ACBF_Allocated 0x00000001
  729. #define ACBF_Initialized 0x00000002
  730. #define ACBF_ClosePending 0x00000100
  731. #define ACBF_CloseComplete 0x00000200
  732. // Address family control block, describing the state of an ndis address family.
  733. // Each block may have zero or more VCs associated with it.
  734. //
  735. typedef struct
  736. _AFCB
  737. {
  738. // Set to MTAG_AFCB for easy identification in memory dumps and use in
  739. // assertions.
  740. //
  741. ULONG ulTag;
  742. // ACBF_* bit flags indicating various options. Access restrictions are
  743. // indicated for each individual flag. Many of these flags are set
  744. // permanently at initialization and so have no access limitation.
  745. //
  746. //
  747. ULONG ulFlags;
  748. // Reference count on this control block. The reference pairs are:
  749. //
  750. // (a) A reference is added when this block is linked to the adapter's
  751. // list of af blocks, and removed when it is unlinked.
  752. //
  753. // (a) A reference is added when a call on a VCCB is created
  754. // removed when it is deleted.
  755. //
  756. // Access is via ReferenceTunnel and DereferenceTunnel only which use
  757. // 'ADAPTERCB.lockTunnels' for protection.
  758. //
  759. LONG lRef;
  760. // Links to the prev/next AFCB in the owning adapter's AF list.
  761. // Access to the list links is protected by 'ADAPTERCB.lock'.
  762. //
  763. LIST_ENTRY linkAFCB;
  764. // List of all VCs associated with this address family.
  765. // Access is protected by the adapter lock.
  766. //
  767. LIST_ENTRY AFVCList;
  768. // Back pointer to owning adapter's control block.
  769. //
  770. PADAPTERCB pAdapter;
  771. // NDIS's handle for our Address Family as passed to our CmOpenAfHandler
  772. // or NULL if none.
  773. //
  774. NDIS_HANDLE NdisAfHandle;
  775. }
  776. AFCB, *PAFCB;
  777. // Call statistics block.
  778. //
  779. typedef struct
  780. _CALLSTATS
  781. {
  782. // System time call reached established state. When the block is being
  783. // used for cumulative statistics of multiple calls, this is the number of
  784. // calls instead.
  785. //
  786. LONGLONG llCallUp;
  787. // Duration in seconds of now idle call.
  788. //
  789. ULONG ulSeconds;
  790. // Total data bytes received and sent.
  791. //
  792. ULONG ulDataBytesRecd;
  793. ULONG ulDataBytesSent;
  794. // Number of received packets indicated up.
  795. //
  796. ULONG ulRecdDataPackets;
  797. // TODO: add more stats if required.
  798. ULONG ulSentPkts;
  799. //
  800. // NDis Packet failures
  801. //
  802. ULONG ulSendFailures;
  803. //
  804. // Bus AsyncWrite or Stream failires
  805. //
  806. ULONG ulBusSendFailures;
  807. ULONG ulBusSendSuccess;
  808. }
  809. CALLSTATS;
  810. typedef
  811. NDIS_STATUS
  812. (*PFN_INITVCHANDLER) (
  813. VCCB *pVc
  814. );
  815. typedef
  816. NDIS_STATUS
  817. (*PFN_SENDPACKETHANDLER) (
  818. VCCB *pVc,
  819. NDIS_PACKET * pPacket
  820. );
  821. typedef
  822. NDIS_STATUS
  823. (*PFN_CLOSECALLHANDLER) (
  824. VCCB *pVc
  825. );
  826. typedef
  827. VOID
  828. (*PFN_RETURNHANDLER) (
  829. VCCB *pVc,
  830. PNDIS_PACKET *pPacket
  831. );
  832. // Table of vc-type-specific handler functions.
  833. //
  834. typedef struct _VC_HANDLERS
  835. {
  836. PFN_INITVCHANDLER MakeCallHandler;
  837. PFN_CLOSECALLHANDLER CloseCallHandler;
  838. PFN_SENDPACKETHANDLER SendPackets;
  839. } VC_HANDLERS;
  840. typedef enum _NIC1394_VC_TYPE
  841. {
  842. NIC1394_Invalid_Type,
  843. NIC1394_SendRecvChannel,
  844. NIC1394_RecvFIFO,
  845. NIC1394_SendFIFO,
  846. NIC1394_MultiChannel,
  847. NIC1394_Ethernet,
  848. NIC1394_SendChannel,
  849. NIC1394_RecvChannel,
  850. Nic1394_NoMoreVcTypes
  851. } NIC1394_VC_TYPE, *PNIC1394_VC_TYPE;
  852. // Virtual circuit control block header defining the state of a single VC that
  853. // is common to all the different types of VCs.
  854. //
  855. typedef struct
  856. _VCHDR
  857. {
  858. // Set to MTAG_VCCB_* for easy identification in memory dumps and use in
  859. // assertions.
  860. //
  861. ULONG ulTag;
  862. // The Pdo Block that will be used to perform all the operations for this Vc
  863. //
  864. //
  865. PREMOTE_NODE pRemoteNode;
  866. //
  867. // pLocalHostVdo - local host's VDO that will be used for all channel and
  868. // recv fifo allocations
  869. //
  870. PDEVICE_OBJECT pLocalHostVDO;
  871. // Links to the prev/next VCCB in the owning AF's control block.
  872. // Access is protected by 'ADAPTERCB.lock'.
  873. //
  874. LIST_ENTRY linkAFVcs;
  875. // The VCType and Destination of the call that has been set up on the VC
  876. // The VCType can be either Isoch or Async, Sends or Recieve. Each type
  877. // of VC has an address associated with it
  878. NIC1394_VC_TYPE VcType;
  879. // This stores the generation of the physical adapter. And should match the value
  880. // kept in the adapter block
  881. PUINT pGeneration;
  882. // VCBF_* bit flags indicating various options and states. Access is via
  883. // the interlocked ReadFlags/SetFlags/ClearFlags routines.
  884. //
  885. // VCBF_IndicateReceivedTime: Set if MakeCall caller sets the
  886. // MediaParameters.Flags RECEIVE_TIME_INDICATION flag requesting the
  887. // TimeReceived field of the NDIS packet be filled with a timestamp.
  888. //
  889. // VCBF_CallClosableByClient: Set when a call is in a state where
  890. // NicCmCloseCall requests to initiate clean-up should be accepted.
  891. // This may be set when VCBF_CallClosableByPeer is not, which means we
  892. // have indicated an incoming close to client and are waiting for him
  893. // to do a client close in response (in that weird CoNDIS way). The
  894. // flag is protected by 'lockV'.
  895. //
  896. // VCBF_VcCreated: Set when the VC has been created successfully. This is
  897. // the "creation" that occurs with the client, not the mini-port.
  898. // VCBF_VcActivated: Set when the VC has been activated successfully.
  899. // VCBM_VcState: Bit mask including each of the above 3 NDIS state flags.
  900. //
  901. // VCBF_VcDeleted: Set when the DeleteVC handler has been called on this
  902. // VC. This guards against NDPROXY double-deleting VCs which it has
  903. // been known to do.
  904. //
  905. // The pending bits below are mutually exclusive (except ClientClose which
  906. // may occur after but simultaneous with ClientOpen), and so require lock
  907. // protection by 'lockV':
  908. //
  909. // VCBF_ClientOpenPending: Set when client attempts to establish a call,
  910. // and the result is not yet known.
  911. // VCBF_ClientClosePending: Set when client attempts to close an
  912. // established call and the result is not yet known. Access is
  913. // protected by 'lockV'.
  914. // VCBM_Pending: Bit mask that includes each of the 4 pending flags.
  915. //
  916. // VCBF_ClientCloseCompletion: Set when client close completion is in
  917. // progress.
  918. //
  919. // VCBF_WaitCloseCall: Set when the client is expected to call our call
  920. // manager's CloseCall handler. This is strictly a debug aid.
  921. //
  922. // VCBF_FreedResources - VC This is a channel VC and because the last
  923. // node in the network was being removed, its resources have been freed
  924. ULONG ulFlags;
  925. #define VCBF_IndicateTimeReceived 0x00000001
  926. #define VCBF_CallClosableByClient 0x00000002
  927. #define VCBF_VcCreated 0x00000100
  928. #define VCBF_VcActivated 0x00000200
  929. #define VCBF_VcDispatchedCloseCall 0x00000400
  930. #define VCBF_MakeCallPending 0x00002000
  931. #define VCBF_CloseCallPending 0x00008000
  932. #define VCBF_VcDeleted 0x00010000
  933. #define VCBF_MakeCallFailed 0x00020000
  934. #define VCBF_CloseCallCompleted 0x00040000
  935. #define VCBF_WaitCloseCall 0x00200000
  936. #define VCBF_NewPdoIsActivatingFifo 0x01000000
  937. #define VCBF_PdoIsBeingRemoved 0x02000000
  938. #define VCBF_NeedsToAllocateChannel 0x04000000
  939. #define VCBF_GenerationWorkItem 0x10000000
  940. #define VCBF_AllocatedChannel 0x20000000
  941. #define VCBF_BroadcastVc 0x40000000
  942. #define VCBF_FreedResources 0x80000000
  943. #define VCBM_VcState 0x00000700
  944. #define VCBM_Pending 0x0000F000
  945. #define VCBM_NoActiveCall 0x000F0000
  946. #define VCBM_PdoFlags 0x0F000000
  947. // Back pointer to owning address family control block.
  948. //
  949. AFCB* pAF;
  950. // Reference count on the active call.
  951. // References may only be added
  952. // when the VCCB_VcActivated flag is set, and this is enforced by
  953. // ReferenceCall. The reference pairs are:
  954. //
  955. // (a) A reference is added when a VC is activated and removed when it is
  956. // de-activated.
  957. //
  958. // (b) A reference is added when the send handler accepts a packet.
  959. //
  960. // The field is accessed only by the ReferenceCall and DereferenceCall
  961. // routines, which protect the field with 'lock'.
  962. //
  963. REF CallRef;
  964. // Reference count on this VC control block. The reference pairs are:
  965. //
  966. // (a) NicCoCreateVc adds a reference that is removed by NicCoDeleteVc.
  967. // This covers all clients that learn of the VCCB via NDIS.
  968. //
  969. // The field is accessed only by the ReferenceVc and DereferenceVc
  970. // routines, which protect with Interlocked routines.
  971. //
  972. LONG lRef;
  973. //
  974. // This is a copy the parameters that are passed to the VC in
  975. // a Make Call. Each VC needs to keep a copy. This is stored here
  976. //
  977. NIC1394_MEDIA_PARAMETERS Nic1394MediaParams;
  978. // NDIS BOOKKEEPING ------------------------------------------------------
  979. // NDIS's handle for this VC passed to us in MiniportCoCreateVcHandler.
  980. // This is passed back to NDIS in various NdisXxx calls.
  981. //
  982. NDIS_HANDLE NdisVcHandle;
  983. // This linked list is used to designate all the VCs that are using a single PdoCb
  984. // The head of this list resides in a REMOTE_NODE. So that when a Pdo goes away, we can go and
  985. // close all the Vcs that are dependent on it. No RecvFIFO included
  986. LIST_ENTRY SinglePdoVcLink;
  987. // CALL SETUP ------------------------------------------------------------
  988. // Address of the call parameters passed down in CmMakeCall. This field
  989. // will only be valid until the NdisMCmMakeCallComplete notification for
  990. // the associated call is made, at which time it is reset to NULL. Access
  991. // is via Interlocked routines.
  992. //
  993. PCO_CALL_PARAMETERS pCallParameters;
  994. UINT MTU;
  995. // This is the initialize handler used to initialize the Vc
  996. // Each Vc has its own specific initialize handler so that all the
  997. // data structures that specific to it, can be filled
  998. //
  999. VC_HANDLERS VcHandlers;
  1000. // STATISTICS ------------------------------------------------------------
  1001. // Statistics for the current call. Access is protected by 'lock'.
  1002. //
  1003. CALLSTATS stats;
  1004. // This is a pointer to the lock in the adapater
  1005. // structure.
  1006. PNDIS_SPIN_LOCK plock;
  1007. //
  1008. // MaxPayload that this VC will send in a single IRP
  1009. // To be used in Lookaside lists
  1010. //
  1011. ULONG MaxPayload;
  1012. }
  1013. VCHDR;
  1014. //
  1015. // Virtual circuit control block defining the state of a single SendFIFO VC.
  1016. //
  1017. typedef struct
  1018. _SENDFIFO_VCCB
  1019. {
  1020. // Common header for all types of VCs
  1021. //
  1022. VCHDR Hdr;
  1023. // Prev/next in the list of SendFIFO VCs for a particular destination
  1024. // PDO
  1025. //
  1026. LIST_ENTRY SendFIFOLink;
  1027. // SendFIFO-specific VC Info
  1028. //
  1029. NIC1394_FIFO_ADDRESS FifoAddress;
  1030. // Shortcuts to the Values we were passed in the Make call
  1031. // that activated the VC
  1032. //
  1033. // UINT MaxSendBlockSize;
  1034. UINT MaxSendSpeed;
  1035. } SENDFIFO_VCCB, *PSENDFIFO_VCCB;
  1036. // Virtual circuit control block defining the state of a single RecvFIFO VC.
  1037. //
  1038. typedef struct
  1039. _RECVFIFO_VCCB
  1040. {
  1041. // Common header for all types of VCs
  1042. //
  1043. VCHDR Hdr;
  1044. // Prev/next in the list of RecvFIFO VCs for a particular Recv FIFO
  1045. // address.
  1046. //
  1047. LIST_ENTRY RecvFIFOLink;
  1048. // Packet Pool Handle
  1049. //
  1050. NIC_PACKET_POOL PacketPool;
  1051. //NDIS_HANDLE PacketPoolHandle;
  1052. // Slist Header. All buffers are posted here, using Interlocked routines
  1053. //
  1054. SLIST_HEADER FifoSListHead;
  1055. // Slist Spin lock that protects the Slist
  1056. //
  1057. KSPIN_LOCK FifoSListSpinLock;
  1058. //
  1059. // Num Fifo Elements allocated
  1060. //
  1061. ULONG NumAllocatedFifos;
  1062. // Num of Fifo that have been indicated to the miniport
  1063. // Count of Fifo that the Nic has not returned to the bus driver
  1064. //
  1065. ULONG NumIndicatedFifos;
  1066. // This is the address range that is returned in the allocate
  1067. // address irb. Will be changed to a pointer or an array
  1068. //
  1069. ADDRESS_RANGE VcAddressRange;
  1070. // This is the number of address ranges that the bus driver
  1071. // returned. For now, it is expected to be one.
  1072. //
  1073. UINT AddressesReturned;
  1074. //
  1075. // Handle to the address range
  1076. //
  1077. HANDLE hAddressRange;
  1078. //
  1079. // Buffer pool
  1080. //
  1081. NIC_BUFFER_POOL BufferPool;
  1082. //NIC_WORK_ITEM FifoWorkItem;
  1083. BOOLEAN FifoWorkItemInProgress ;
  1084. UINT NumOfFifosInSlistInCloseCall;
  1085. #if FIFO_WRAPPER
  1086. PADDRESS_FIFO pFifoTable[NUM_RECV_FIFO_BUFFERS];
  1087. #endif
  1088. } RECVFIFO_VCCB, *PRECVFIFO_VCCB;
  1089. // Virtual circuit control block defining the state of a single CHANNEL VC.
  1090. //
  1091. typedef struct
  1092. _CHANNEL_VCCB
  1093. {
  1094. // Common header for all types of VCs
  1095. //
  1096. VCHDR Hdr;
  1097. // Prev/next in the list of channel VCs for a particular destination
  1098. // channel
  1099. //
  1100. LIST_ENTRY ChannelLink;
  1101. // Channel-specific VC Info
  1102. //
  1103. UINT Channel;
  1104. // The speed at which this Channel will stream data
  1105. //
  1106. UINT Speed;
  1107. // Indicates the Sy field in packets that will indicated up
  1108. //
  1109. ULONG ulSynch;
  1110. // the Tag used in submitting asyncstream irps
  1111. //
  1112. ULONG ulTag;
  1113. // MaxBytesPerFrameRequested and available
  1114. //
  1115. ULONG MaxBytesPerFrameRequested;
  1116. ULONG BytesPerFrameAvailable;
  1117. // Handle to the Resources allocated
  1118. //
  1119. HANDLE hResource;
  1120. // Speeds Requested and speed returned
  1121. //
  1122. ULONG SpeedRequested;
  1123. ULONG SpeedSelected;
  1124. // Maximum Buffer Size
  1125. //
  1126. ULONG MaxBufferSize;
  1127. // Num of descriptors that were attached to the resources
  1128. //
  1129. ULONG NumDescriptors;
  1130. // Pointer to an array of isochDescriptors used in AttachBuffers
  1131. //
  1132. PISOCH_DESCRIPTOR pIsochDescriptor;
  1133. // PacketPool Handle
  1134. //
  1135. NIC_PACKET_POOL PacketPool;
  1136. //NDIS_HANDLE hPacketPoolHandle;
  1137. //
  1138. // Temporary
  1139. //
  1140. UINT PacketLength;
  1141. //
  1142. // Number of Isoch Descriptors that the Bus driver has indicated to the miniport
  1143. //
  1144. ULONG NumIndicatedIsochDesc;
  1145. //
  1146. // Event to signal that the last of the Isoch descriptors have
  1147. // been returned to the bus driver. Only set when Vc is closing (after IsochStop)
  1148. //
  1149. NDIS_EVENT LastDescReturned;
  1150. //
  1151. // Channel Map used in Multichannel Vcs
  1152. //
  1153. ULARGE_INTEGER uliChannelMap;
  1154. } CHANNEL_VCCB, *PCHANNEL_VCCB;
  1155. typedef struct
  1156. _ETHERNET_VCCB
  1157. {
  1158. // Common header for all types of VCs
  1159. //
  1160. VCHDR Hdr;
  1161. NIC_PACKET_POOL PacketPool;
  1162. } ETHERNET_VCCB, *PETHERNET_VCCB;
  1163. // The following union has enough space to hold any of the type-specific
  1164. // VC control blocks.
  1165. //
  1166. typedef union _VCCB
  1167. {
  1168. VCHDR Hdr;
  1169. CHANNEL_VCCB ChannelVc;
  1170. SENDFIFO_VCCB SendFIFOVc;
  1171. RECVFIFO_VCCB RecvFIFOVc;
  1172. ETHERNET_VCCB EthernetVc;
  1173. } VCCB, *PVCCB;
  1174. // The next structure is used when sending a packet, to store context
  1175. // information in an NdisPacket. These are pointers to the Vc and the Irb
  1176. // and are stored in the MiniportWrapperReserved field of the NdisPacket
  1177. // and has a limit of 2 PVOIDs
  1178. //
  1179. typedef union _PKT_CONTEXT
  1180. {
  1181. struct
  1182. {
  1183. PVCCB pVc;
  1184. PVOID pLookasideListBuffer;
  1185. } AsyncWrite;
  1186. struct
  1187. {
  1188. PVCCB pVc;
  1189. PVOID pLookasideListBuffer;
  1190. } AsyncStream;
  1191. //
  1192. // For receives make sure the first element is the Vc or we will break;
  1193. //
  1194. struct
  1195. {
  1196. PRECVFIFO_VCCB pRecvFIFOVc;
  1197. PADDRESS_FIFO pIndicatedFifo;
  1198. } AllocateAddressRange;
  1199. struct
  1200. {
  1201. PCHANNEL_VCCB pChannelVc;
  1202. PISOCH_DESCRIPTOR pIsochDescriptor;
  1203. } IsochListen;
  1204. struct
  1205. {
  1206. //
  1207. // First DWORD is the Vc
  1208. //
  1209. PVCCB pVc;
  1210. //
  1211. // Second is the isoch descriptor or Fifo
  1212. //
  1213. union
  1214. {
  1215. PISOCH_DESCRIPTOR pIsochDescriptor; // channels use isoch desc
  1216. PADDRESS_FIFO pIndicatedFifo; // fifo use AddressFifo
  1217. PVOID pCommon; // to be used in the common code path
  1218. } IndicatedStruct;
  1219. } Receive;
  1220. struct
  1221. {
  1222. PNDIS_PACKET pOrigPacket;
  1223. } EthernetSend;
  1224. } PKT_CONTEXT,*PPKT_CONTEXT,**PPPKT_CONTEXT;
  1225. typedef struct _NDIS1394_FRAGMENT_HEADER
  1226. {
  1227. union
  1228. {
  1229. struct
  1230. {
  1231. ULONG FH_fragment_offset:12;
  1232. ULONG FH_rsv_0:4;
  1233. ULONG FH_buffersize:12;
  1234. ULONG FH_rsv_1:2;
  1235. ULONG FH_lf:2;
  1236. } FirstQuadlet;
  1237. struct
  1238. {
  1239. ULONG FH_EtherType:16;
  1240. ULONG FH_buffersize:12;
  1241. ULONG FH_rsv_1:2;
  1242. ULONG FH_lf:2;
  1243. } FirstQuadlet_FirstFragment;
  1244. ULONG FH_High;
  1245. } u;
  1246. union
  1247. {
  1248. struct
  1249. {
  1250. ULONG FH_rsv:16;
  1251. ULONG FH_dgl:16;
  1252. } SecondQuadlet;
  1253. ULONG FH_Low;
  1254. } u1;
  1255. } NDIS1394_FRAGMENT_HEADER, *PNDIS1394_FRAGMENT_HEADER;
  1256. #define LOOKASIDE_HEADER_No_More_Framgents 1
  1257. #define LOOKASIDE_HEADER_SendPacketFrees 2
  1258. #define LOOKASIDE_HEADER_SendCompleteFrees 4
  1259. //
  1260. // This structure is used with the above flags to maintain state within the lookaside buffer
  1261. //
  1262. typedef union _LOOKASIDE_BUFFER_STATE
  1263. {
  1264. struct
  1265. {
  1266. USHORT Refcount;
  1267. USHORT Flags;
  1268. } u;
  1269. LONG FlagRefcount;
  1270. } LOOKASIDE_BUFFER_STATE, *PLOOKASIDE_BUFFER_STATE;
  1271. typedef enum _BUS_OPERATION
  1272. {
  1273. InvalidOperation,
  1274. AsyncWrite,
  1275. AsyncStream,
  1276. AddressRange,
  1277. IsochReceive
  1278. } BUS_OPERATION, *PBUS_OPERATION;
  1279. //
  1280. // This will be used as a local variable
  1281. // during a send operation and will
  1282. // keep all the state information
  1283. // regarding fragmentation
  1284. //
  1285. typedef struct _FRAGMENTATION_STRUCTURE
  1286. {
  1287. //
  1288. // Start of the buffer that will be used in the send.
  1289. // Usually from a lookaside list
  1290. //
  1291. PVOID pLookasideListBuffer;
  1292. //
  1293. // Fragment Length
  1294. //
  1295. ULONG FragmentLength ;
  1296. //
  1297. // Start of the this fragment to be used
  1298. //
  1299. PVOID pStartFragment;
  1300. //
  1301. // Specified if an async write or an asyncstream operation is occurring
  1302. //
  1303. BUS_OPERATION AsyncOp;
  1304. //
  1305. // LookasideBuffer associated with the fragmentation
  1306. //
  1307. PVOID pLookasideBuffer;
  1308. //
  1309. // Start of the next fragment
  1310. //
  1311. // PVOID pStartNextFragment;
  1312. //
  1313. // Length of each fragment
  1314. //
  1315. ULONG MaxFragmentLength;
  1316. //
  1317. // NumFragments that will be generated
  1318. //
  1319. ULONG NumFragmentsNeeded ;
  1320. //
  1321. // Current NdisBuffer which is being fragmented
  1322. //
  1323. PNDIS_BUFFER pCurrNdisBuffer;
  1324. //
  1325. // Length that needs to be copied in CurrNdisBuffer
  1326. //
  1327. ULONG NdisBufferLengthRemaining;
  1328. //
  1329. // Point to which copying has occurred in the pCurrNdisBuffer
  1330. //
  1331. PVOID pSourceAddressInNdisBuffer;
  1332. //
  1333. // UnFragment Header from this NdisPacket
  1334. //
  1335. NDIS1394_UNFRAGMENTED_HEADER UnfragmentedHeader;
  1336. //
  1337. // Fragmented Header to be used by all the fragments
  1338. // generated by this NdisPackets
  1339. //
  1340. NDIS1394_FRAGMENT_HEADER FragmentationHeader;
  1341. //
  1342. // Status of the lf field in the fragment header. Also serves as an
  1343. // implicit flag about the state of the fragmentation
  1344. //
  1345. NDIS1394_FRAGMENT_LF lf;
  1346. //
  1347. // Length of the Ip Datagram, to be used as the buffersize in fragment header
  1348. //
  1349. USHORT IPDatagramLength;
  1350. //
  1351. // An AsyncStream will have a gasp header as well . So the starting
  1352. // offset can either be either 8 or 16. Only applicable for fragmentation code path
  1353. //
  1354. ULONG TxHeaderSize;
  1355. //
  1356. // Pointer to the lookaside list that this buffer was allocated from
  1357. //
  1358. PNIC_NPAGED_LOOKASIDE_LIST pLookasideList;
  1359. //
  1360. // Adapter - local host
  1361. //
  1362. PADAPTERCB pAdapter;
  1363. //
  1364. // Pointer to the IRB to be used in the current fragment
  1365. //
  1366. PIRB pCurrentIrb;
  1367. //
  1368. // Current Fragment Number
  1369. //
  1370. ULONG CurrFragmentNum;
  1371. PVOID pStartOfFirstFragment;
  1372. }FRAGMENTATION_STRUCTURE, *PFRAGMENTATION_STRUCTURE;
  1373. typedef struct _LOOKASIDE_BUFFER_HEADER
  1374. {
  1375. //
  1376. // Refcount
  1377. //
  1378. ULONG OutstandingFragments;
  1379. //
  1380. // NumOfFragments generated by the NdisPacket So Far
  1381. //
  1382. ULONG FragmentsGenerated;
  1383. //
  1384. // Will this Buffer contain fragments
  1385. //
  1386. BOOLEAN IsFragmented;
  1387. //
  1388. // Pointer to the NdisPacket whose data is being transmitted
  1389. // by the lookaside buffer
  1390. //
  1391. PNDIS_PACKET pNdisPacket;
  1392. //
  1393. // pVc Pointer to the Vc on which the packet was indicated
  1394. // Used to complete the packet
  1395. //
  1396. PVCCB pVc;
  1397. //
  1398. // Pointer to the lookaside list that this buffer was allocated from
  1399. //
  1400. PNIC_NPAGED_LOOKASIDE_LIST pLookasideList;
  1401. //
  1402. // Bus Op AsyncStream or AsyncWrite.
  1403. // AsyncWrite reference the RemoteNode. AsuncWrite does not
  1404. //
  1405. BUS_OPERATION AsyncOp;
  1406. //
  1407. // Start of Data
  1408. //
  1409. PVOID pStartOfData;
  1410. } LOOKASIDE_BUFFER_HEADER, *PLOOKASIDE_BUFFER_HEADER;
  1411. typedef enum _ENUM_LOOKASIDE_LIST
  1412. {
  1413. NoLookasideList,
  1414. SendLookasideList100,
  1415. SendLookasideList2K,
  1416. SendLookasideList8K
  1417. } ENUM_LOOKASIDE_LIST, *PENUM_LOOKASIDE_LIST;
  1418. //
  1419. // Unfragmented Buffer
  1420. //
  1421. typedef struct _UNFRAGMENTED_BUFFER
  1422. {
  1423. LOOKASIDE_BUFFER_HEADER Header;
  1424. IRB Irb;
  1425. UCHAR Data [1];
  1426. } UNFRAGMENTED_BUFFER, *PUNFRAGMENTED_BUFFER;
  1427. #define PAYLOAD_100 100
  1428. //
  1429. // A simple packet with no fragmentation . This will primarily be used for the IP Acks and ARP req
  1430. //
  1431. typedef struct _PAYLOAD_100_LOOKASIDE_BUFFER
  1432. {
  1433. LOOKASIDE_BUFFER_HEADER Header;
  1434. IRB Irb;
  1435. UCHAR Data [PAYLOAD_100 + sizeof (GASP_HEADER)];
  1436. } PAYLOAD_100_LOOKASIDE_BUFFER;
  1437. //
  1438. // This lookaside will handle packets upto 2K.
  1439. //
  1440. // Calculate the theoretical maximum number of fragments that can occur for a
  1441. // a 2K Packet
  1442. //
  1443. #define PAYLOAD_2K ASYNC_PAYLOAD_400_RATE
  1444. #define NUM_FRAGMENT_2K ((PAYLOAD_2K/ASYNC_PAYLOAD_100_RATE) +1)
  1445. typedef struct _PAYLOAD_2K_LOOKASIDE_BUFFER
  1446. {
  1447. LOOKASIDE_BUFFER_HEADER Header;
  1448. //
  1449. // There can be a maximum of 2048 bytes in 1 Async Packet fragment
  1450. // on ASYNC_PAYLOAD_400 so this will cater to
  1451. // that, but it will be prepared for the worst
  1452. //
  1453. //
  1454. IRB Irb[NUM_FRAGMENT_2K];
  1455. //
  1456. // We get a data size large enough to handle 2048 bytes of data chopped up
  1457. // into the max num of fragments and leave room for header (fragmentation and Gasp)
  1458. // To access we'll just use simple pointer arithmetic
  1459. //
  1460. UCHAR Data[PAYLOAD_2K+ (NUM_FRAGMENT_2K *(sizeof (GASP_HEADER)+sizeof (NDIS1394_FRAGMENT_HEADER)))];
  1461. } PAYLOAD_2K_LOOKASIDE_BUFFER, *PPAYLOAD_2K_LOOKASIDE_BUFFER;
  1462. //
  1463. // This is to handle large packets > 2K .For now I have chosen an arbitrary large amount
  1464. // of 8K
  1465. //
  1466. #define PAYLOAD_8K ASYNC_PAYLOAD_400_RATE *4
  1467. #define NUM_FRAGMENT_8K (PAYLOAD_8K /ASYNC_PAYLOAD_100_RATE +1)
  1468. typedef struct _PAYLOAD_8K_LOOKASIDE_BUFFER
  1469. {
  1470. //
  1471. // The same comments as the 2K_Lookaside Header apply here
  1472. //
  1473. LOOKASIDE_BUFFER_HEADER Header;
  1474. IRB Irb[NUM_FRAGMENT_8K ];
  1475. UCHAR Data[PAYLOAD_8K + (NUM_FRAGMENT_8K*(sizeof (GASP_HEADER)+sizeof (NDIS1394_FRAGMENT_HEADER)))];
  1476. }PAYLOAD_8K_LOOKASIDE_BUFFER, *PPAYLOAD_8K_LOOKASIDE_BUFFER;
  1477. //
  1478. // The 1394 fragment that is passed down can have a gasp header, fragmentation header,
  1479. // unfragmented header. Define Types to format these headers so that we can make
  1480. // compiler do the pointer arithmetic for us.
  1481. //
  1482. typedef union _PACKET_FORMAT
  1483. {
  1484. struct
  1485. {
  1486. GASP_HEADER GaspHeader;
  1487. NDIS1394_FRAGMENT_HEADER FragmentHeader;
  1488. UCHAR Data[1];
  1489. } AsyncStreamFragmented;
  1490. struct
  1491. {
  1492. GASP_HEADER GaspHeader;
  1493. NDIS1394_UNFRAGMENTED_HEADER NonFragmentedHeader;
  1494. UCHAR Data[1];
  1495. } AsyncStreamNonFragmented;
  1496. struct
  1497. {
  1498. NDIS1394_FRAGMENT_HEADER FragmentHeader;
  1499. UCHAR Data[1];
  1500. } AsyncWriteFragmented;
  1501. struct
  1502. {
  1503. NDIS1394_UNFRAGMENTED_HEADER NonFragmentedHeader;
  1504. UCHAR Data[1];
  1505. }AsyncWriteNonFragmented;
  1506. struct
  1507. {
  1508. //
  1509. // Isoch receive header has a prefix, isoch header, gasp header
  1510. //
  1511. ULONG Prefix;
  1512. ISOCH_HEADER IsochHeader;
  1513. GASP_HEADER GaspHeader;
  1514. NDIS1394_UNFRAGMENTED_HEADER NonFragmentedHeader;
  1515. UCHAR Data[1];
  1516. } IsochReceiveNonFragmented;
  1517. struct
  1518. {
  1519. //
  1520. // Isoch receive header has a prefix, isoch header, gasp header
  1521. //
  1522. ULONG Prefix;
  1523. ISOCH_HEADER IsochHeader;
  1524. GASP_HEADER GaspHeader;
  1525. NDIS1394_FRAGMENT_HEADER FragmentHeader;
  1526. UCHAR Data[1];
  1527. }IsochReceiveFragmented;
  1528. }PACKET_FORMAT, DATA_FORMAT, *PPACKET_FORMAT, *PDATA_FORMAT;
  1529. //
  1530. // Used as an Info Struct for Out of Order Reassembly
  1531. //
  1532. typedef struct _REASSEMBLY_CURRENT_INFO
  1533. {
  1534. PMDL pCurrMdl;
  1535. PNDIS_BUFFER pCurrNdisBuffer;
  1536. PADDRESS_FIFO pCurrFifo;
  1537. PISOCH_DESCRIPTOR pCurrIsoch;
  1538. } REASSEMBLY_CURRENT_INFO, *PREASSEMBLY_CURRENT_INFO ;
  1539. typedef enum _REASSEMBLY_INSERT_TYPE
  1540. {
  1541. Unacceptable,
  1542. InsertAsFirst,
  1543. InsertInMiddle,
  1544. InsertAtEnd
  1545. }REASSEMBLY_INSERT_TYPE, *PREASSEMBLY_INSERT_TYPE;
  1546. //
  1547. // This is used as a descriptor for indicated fragments that are waiting for reassembly
  1548. //
  1549. typedef struct _FRAGMENT_DESCRIPTOR
  1550. {
  1551. ULONG Offset; // Offset of the incoming fragment
  1552. ULONG IPLength; // Length of the fragment
  1553. PNDIS_BUFFER pNdisBuffer; // NdisBufferpointing to actual data
  1554. PMDL pMdl; // Mdl that belongs to the bus
  1555. NDIS1394_FRAGMENT_HEADER FragHeader; // Fragment header of the Descriptor
  1556. union
  1557. {
  1558. PADDRESS_FIFO pFifo;
  1559. PISOCH_DESCRIPTOR pIsoch;
  1560. PVOID pCommon;
  1561. PSINGLE_LIST_ENTRY pListEntry;
  1562. }IndicatedStructure;
  1563. } FRAGMENT_DESCRIPTOR, *PFRAGMENT_DESCRIPTOR;
  1564. //
  1565. // Reassembly structure : An instance of the reassembly is created for
  1566. // every packet that is being reassembled. It contains all the relevant
  1567. // bookkeeping information
  1568. //
  1569. // This needs to be allocated from a lookaside list
  1570. // Each PDO will contain a list of all outstanding packets that are being reassembled/
  1571. //
  1572. //
  1573. // REASSEMBLY_NOT_TOUCHED - Each reassembly structure will be marked as Not touched
  1574. // in the timer routine. If the flag is not cleared by the next
  1575. // invocation of the timer, this structure will be freed
  1576. // REASSMEBLY_FREED - The structure is about to be thrown away.
  1577. #define REASSEMBLY_NOT_TOUCHED 1
  1578. #define REASSEMBLY_FREED 2
  1579. #define REASSEMBLY_ABORTED 4
  1580. typedef struct _NDIS1394_REASSEMBLY_STRUCTURE
  1581. {
  1582. //
  1583. // Reference Count - Interlocked access only
  1584. //
  1585. ULONG Ref;
  1586. //
  1587. // Next Reassembly Structure
  1588. //
  1589. LIST_ENTRY ReassemblyListEntry;
  1590. //
  1591. // Tag - used for memory validatation
  1592. //
  1593. ULONG Tag;
  1594. //
  1595. // Receive Operation
  1596. //
  1597. BUS_OPERATION ReceiveOp;
  1598. //
  1599. // Dgl - Datagram label. Unique for every reassembly structure gernerated by this local host
  1600. //
  1601. USHORT Dgl;
  1602. //
  1603. // Ether type of the reassembled packet . Populated in the first fragment
  1604. //
  1605. USHORT EtherType;
  1606. //
  1607. // pRemoteNode -> RemoteNode + Dgl are unique for each reassembly structure
  1608. //
  1609. PREMOTE_NODE pRemoteNode;
  1610. //
  1611. // Flags pertaining to the reassembly
  1612. //
  1613. ULONG Flags;
  1614. //
  1615. // ExpectedFragmentOffset is computed by the LAST Fragment's Offset +
  1616. // length of fragment. Does not account for gaps in the reassembled packet.
  1617. //
  1618. ULONG ExpectedFragmentOffset; // Last is based on offset, not time of indication
  1619. //
  1620. // Buffer Size - total length of the datagram being reassembled
  1621. //
  1622. ULONG BufferSize;
  1623. //
  1624. // Bytes Received So far
  1625. //
  1626. ULONG BytesRecvSoFar;
  1627. //
  1628. // Head NdisBuffer
  1629. //
  1630. PNDIS_BUFFER pHeadNdisBuffer;
  1631. //
  1632. // LastNdisBuffer that was appended to the packet
  1633. //
  1634. PNDIS_BUFFER pTailNdisBuffer;
  1635. //
  1636. // Mdl chain Head - pointing to the actual indicated fragment
  1637. //
  1638. PMDL pHeadMdl;
  1639. //
  1640. //Mdl Chain Tail - pointing to the last Mdl in the list
  1641. //
  1642. PMDL pTailMdl ;
  1643. //
  1644. // Packet that is being reassembled
  1645. //
  1646. PNDIS_PACKET pNdisPacket;
  1647. //
  1648. // NumOfFragmentsSoFar;
  1649. //
  1650. ULONG NumOfFragmentsSoFar;
  1651. //
  1652. // Pointer to the head of the MDL chain that the 1394 bus
  1653. // driver is indicating up. Will be used to return the buffers to
  1654. // the BusDriver
  1655. //
  1656. union
  1657. {
  1658. PADDRESS_FIFO pAddressFifo;
  1659. PISOCH_DESCRIPTOR pIsochDescriptor;
  1660. PVOID pCommon;
  1661. } Head;
  1662. //
  1663. // Last - Last Mdl that was appended to this packet in the reassembly structure
  1664. //
  1665. union
  1666. {
  1667. PADDRESS_FIFO pAddressFifo;
  1668. PISOCH_DESCRIPTOR pIsochDescriptor;
  1669. PVOID pCommon;
  1670. } Tail;
  1671. //
  1672. // Flag to signal if any out of order fragments were received. Default FALSE
  1673. //
  1674. BOOLEAN OutOfOrder;
  1675. //
  1676. // Flag to indicate if all fragments are completed . Default False
  1677. //
  1678. BOOLEAN fReassemblyComplete;
  1679. //
  1680. // Vc that this packet is being assembled for
  1681. //
  1682. PVCCB pVc;
  1683. //
  1684. // MaxIndex in the Fragment Table.
  1685. // At all times, MaxOffset points to an first empty element in the array
  1686. //
  1687. ULONG MaxOffsetTableIndex;
  1688. //
  1689. // FragmentOffset Table
  1690. //
  1691. FRAGMENT_DESCRIPTOR FragTable[MAX_ALLOWED_FRAGMENTS];
  1692. } NDIS1394_REASSEMBLY_STRUCTURE, *PDIS1394_REASSEMBLY_STRUCTURE, *PPDIS1394_REASSEMBLY_STRUCTURE;
  1693. //
  1694. // This structure is local to each Isoch descriptor or fifo that is indicated up
  1695. // to the nic1394 miniport. It stores all the local information extracted
  1696. // from the GASP header and Isoch Header
  1697. //
  1698. typedef struct
  1699. {
  1700. BUS_OPERATION RecvOp; // Fifo or Isoch Receive
  1701. PDATA_FORMAT p1394Data; // Start of 1394 pkt
  1702. ULONG Length1394; // Length of the 1394 data
  1703. PVOID pEncapHeader; // Points to start of frag/defrag encap header
  1704. ULONG DataLength; // length of the packet, from the EncapHeader
  1705. BOOLEAN fGasp; // Has GASP header
  1706. NDIS1394_UNFRAGMENTED_HEADER UnfragHeader; // Unfragmented header
  1707. NDIS1394_FRAGMENT_HEADER FragmentHeader; // Fragment Header
  1708. PGASP_HEADER pGaspHeader; // Gasp Header
  1709. PVOID pIndicatedData; // Data indicated up, includes the isoch header, unfrag headers
  1710. PMDL pMdl;
  1711. //
  1712. // Following information from the fragmented/unfragmented header...
  1713. //
  1714. BOOLEAN fFragmented; // Is fragmented
  1715. BOOLEAN fFirstFragment; // Is the First fragment
  1716. ULONG BufferSize;
  1717. ULONG FragmentOffset;
  1718. USHORT Dgl; // Dgl
  1719. ULONG lf; // Lf - Fragmented or not
  1720. ULONG EtherType; // Ethertype
  1721. PNDIS_BUFFER pNdisBuffer; // Ndis buffer - used to indicate data up.
  1722. PVOID pNdisBufferData; // Points to the start of the data that the Ndis Buffer points to
  1723. //
  1724. // Sender specific information here
  1725. //
  1726. USHORT SourceID;
  1727. PREMOTE_NODE pRemoteNode;
  1728. //
  1729. // Vc Specific Information here
  1730. //
  1731. PVCCB pVc;
  1732. PNIC_PACKET_POOL pPacketPool;
  1733. //
  1734. // Indication data
  1735. //
  1736. union
  1737. {
  1738. PADDRESS_FIFO pFifoContext;
  1739. PISOCH_DESCRIPTOR pIsochContext;
  1740. PVOID pCommon; // to be used in the common code path
  1741. }NdisPktContext;
  1742. } NIC_RECV_DATA_INFO, *PNIC_RECV_DATA_INFO;
  1743. //
  1744. // Fragment Header as defined in the IP/1394 spec. Each packet greater than the MaxPayload
  1745. // will be split up into fragments and this header will be attached.
  1746. //
  1747. #define FRAGMENT_HEADER_LF_UNFRAGMENTED 0
  1748. #define FRAGMENT_HEADER_LF_FIRST_FRAGMENT 1
  1749. #define FRAGMENT_HEADER_LF_LAST_FRAGMENT 2
  1750. #define FRAGMENT_HEADER_LF_INTERIOR_FRAGMENT 3
  1751. typedef struct _INDICATE_RSVD
  1752. {
  1753. PNDIS_PACKET pPacket;
  1754. PVCCB pVc;
  1755. PADAPTERCB pAdapter;
  1756. LIST_ENTRY Link;
  1757. ULONG Tag;
  1758. } INDICATE_RSVD, *PINDICATE_RSVD;
  1759. typedef struct _RSVD
  1760. {
  1761. UCHAR Mandatory[PROTOCOL_RESERVED_SIZE_IN_PACKET]; // mandatory ndis requirement
  1762. INDICATE_RSVD IndicateRsvd; // to be used as extra context
  1763. #ifdef USE_RECV_TIMER
  1764. NDIS_MINIPORT_TIMER RcvIndicateTimer; // Used as a timer for win9x. All rcv Indicates are done here
  1765. #endif
  1766. } RSVD, *PRSVD;
  1767. //
  1768. // Used only in Win9x as a context for the send timer routine
  1769. //
  1770. typedef struct _NDIS_SEND_CONTEXT
  1771. {
  1772. LIST_ENTRY Link;
  1773. PVCCB pVc;
  1774. }NDIS_SEND_CONTEXT, *PNDIS_SEND_CONTEXT;
  1775. typedef struct _NDIS_STATUS_CONTEXT
  1776. {
  1777. LIST_ENTRY Link;
  1778. IN NDIS_STATUS GeneralStatus;
  1779. IN PVOID StatusBuffer;
  1780. IN UINT StatusBufferSize;
  1781. }NDIS_STATUS_CONTEXT, *PNDIS_STATUS_CONTEXT;
  1782. //
  1783. // This is the Irb structure used by the Bus Driver.
  1784. // There is extra room allocated at the end for the miniport's Context
  1785. //
  1786. typedef struct _NDIS1394_IRB
  1787. {
  1788. //
  1789. // Original Irb used by the bus driver
  1790. //
  1791. IRB Irb;
  1792. //
  1793. // Adapter - local host -optional
  1794. //
  1795. PADAPTERCB pAdapter;
  1796. //
  1797. // remote node to which the Irp was sent - optional
  1798. //
  1799. PREMOTE_NODE pRemoteNode;
  1800. //
  1801. // VC for which the Irp was sent. - optional
  1802. //
  1803. PVCCB pVc;
  1804. //
  1805. // Context if any - optinal
  1806. //
  1807. PVOID Context;
  1808. }NDIS1394_IRB, *PNDIS1394_IRB;
  1809. #pragma pack (push, 1)
  1810. typedef ULONG IP_ADDRESS;
  1811. //* Structure of an Ethernet header (taken from ip\arpdef.h).
  1812. typedef struct ENetHeader {
  1813. ENetAddr eh_daddr;
  1814. ENetAddr eh_saddr;
  1815. USHORT eh_type;
  1816. } ENetHeader;
  1817. // Structure of an Ethernet ARP packet.
  1818. //
  1819. typedef struct {
  1820. ENetHeader header;
  1821. USHORT hardware_type;
  1822. USHORT protocol_type;
  1823. UCHAR hw_addr_len;
  1824. UCHAR IP_addr_len;
  1825. USHORT opcode; // Opcode.
  1826. ENetAddr sender_hw_address;
  1827. IP_ADDRESS sender_IP_address;
  1828. ENetAddr target_hw_address;
  1829. IP_ADDRESS target_IP_address;
  1830. } ETH_ARP_PKT, *PETH_ARP_PKT;
  1831. #pragma pack (pop)
  1832. // These are ethernet arp specific constants
  1833. //
  1834. #define ARP_ETH_ETYPE_IP 0x800
  1835. #define ARP_ETH_ETYPE_ARP 0x806
  1836. #define ARP_ETH_REQUEST 1
  1837. #define ARP_ETH_RESPONSE 2
  1838. #define ARP_ETH_HW_ENET 1
  1839. #define ARP_ETH_HW_802 6
  1840. typedef enum _ARP_ACTION {
  1841. LoadArp = 1,
  1842. UnloadArp ,
  1843. UnloadArpNoRequest,
  1844. BindArp
  1845. }ARP_ACTION , *PARP_ACTION;
  1846. typedef struct _ARP_INFO{
  1847. //
  1848. // List entry to handle serialization of requests to ARP
  1849. //
  1850. LIST_ENTRY Link;
  1851. //
  1852. // Action to be done by the Arp module
  1853. //
  1854. ARP_ACTION Action;
  1855. //
  1856. // Request to be compeleted - optional
  1857. //
  1858. PNDIS_REQUEST pRequest;
  1859. } ARP_INFO, *PARP_INFO;
  1860. //-----------------------------------------------------------------------------
  1861. // Macros/inlines
  1862. //-----------------------------------------------------------------------------
  1863. // These basics are not in the DDK headers for some reason.
  1864. //
  1865. #define min( a, b ) (((a) < (b)) ? (a) : (b))
  1866. #define max( a, b ) (((a) > (b)) ? (a) : (b))
  1867. #define InsertBefore( pNewL, pL ) \
  1868. { \
  1869. (pNewL)->Flink = (pL); \
  1870. (pNewL)->Blink = (pL)->Blink; \
  1871. (pNewL)->Flink->Blink = (pNewL); \
  1872. (pNewL)->Blink->Flink = (pNewL); \
  1873. }
  1874. #define InsertAfter( pNewL, pL ) \
  1875. { \
  1876. (pNewL)->Flink = (pL)->Flink; \
  1877. (pNewL)->Blink = (pL); \
  1878. (pNewL)->Flink->Blink = (pNewL); \
  1879. (pNewL)->Blink->Flink = (pNewL); \
  1880. }
  1881. // Winsock-ish host/network byte order converters for short and long integers.
  1882. //
  1883. #if (defined(_M_IX86) && (_MSC_FULL_VER > 13009037)) || ((defined(_M_AMD64) || defined(_M_IA64)) && (_MSC_FULL_VER > 13009175))
  1884. #define htons(x) _byteswap_ushort((USHORT)(x))
  1885. #define htonl(x) _byteswap_ulong((ULONG)(x))
  1886. #else
  1887. #define htons( a ) ((((a) & 0xFF00) >> 8) |\
  1888. (((a) & 0x00FF) << 8))
  1889. #define htonl( a ) ((((a) & 0xFF000000) >> 24) | \
  1890. (((a) & 0x00FF0000) >> 8) | \
  1891. (((a) & 0x0000FF00) << 8) | \
  1892. (((a) & 0x000000FF) << 24))
  1893. #endif
  1894. #define ntohs( a ) htons(a)
  1895. #define ntohl( a ) htonl(a)
  1896. // Place in a TRACE argument list to correspond with a format of "%d.%d.%d.%d"
  1897. // to print network byte-ordered IP address 'x' in human readable form.
  1898. //
  1899. #define IPADDRTRACE( x ) ((x) & 0x000000FF), \
  1900. (((x) >> 8) & 0x000000FF), \
  1901. (((x) >> 16) & 0x000000FF), \
  1902. (((x) >> 24) & 0x000000FF)
  1903. // Place in a TRACE argument list to correspond with a format of "%d" to print
  1904. // a percentage of two integers, or an average of two integers, or those
  1905. // values rounded.
  1906. //
  1907. #define PCTTRACE( n, d ) ((d) ? (((n) * 100) / (d)) : 0)
  1908. #define AVGTRACE( t, c ) ((c) ? ((t) / (c)) : 0)
  1909. #define PCTRNDTRACE( n, d ) ((d) ? (((((n) * 1000) / (d)) + 5) / 10) : 0)
  1910. #define AVGRNDTRACE( t, c ) ((c) ? (((((t) * 10) / (c)) + 5) / 10) : 0)
  1911. // All memory allocations and frees are done with these ALLOC_*/FREE_*
  1912. // macros/inlines to allow memory management scheme changes without global
  1913. // editing. For example, might choose to lump several lookaside lists of
  1914. // nearly equal sized items into a single list for efficiency.
  1915. //
  1916. // NdisFreeMemory requires the length of the allocation as an argument. NT
  1917. // currently doesn't use this for non-paged memory, but according to JameelH,
  1918. // Windows95 does. These inlines stash the length at the beginning of the
  1919. // allocation, providing the traditional malloc/free interface. The
  1920. // stash-area is a ULONGLONG so that all allocated blocks remain ULONGLONG
  1921. // aligned as they would be otherwise, preventing problems on Alphas.
  1922. //
  1923. __inline
  1924. VOID*
  1925. ALLOC_NONPAGED(
  1926. IN ULONG ulBufLength,
  1927. IN ULONG ulTag )
  1928. {
  1929. CHAR* pBuf;
  1930. NdisAllocateMemoryWithTag(
  1931. &pBuf, (UINT )(ulBufLength + MEMORY_ALLOCATION_ALIGNMENT), ulTag );
  1932. if (!pBuf)
  1933. {
  1934. return NULL;
  1935. }
  1936. ((ULONG* )pBuf)[ 0 ] = ulBufLength;
  1937. ((ULONG* )pBuf)[ 1 ] = ulTag;
  1938. return (pBuf + MEMORY_ALLOCATION_ALIGNMENT);
  1939. }
  1940. __inline
  1941. VOID
  1942. FREE_NONPAGED(
  1943. IN VOID* pBuf )
  1944. {
  1945. ULONG ulBufLen;
  1946. ulBufLen = *((ULONG* )(((CHAR* )pBuf) - MEMORY_ALLOCATION_ALIGNMENT));
  1947. NdisFreeMemory(
  1948. ((CHAR* )pBuf) - MEMORY_ALLOCATION_ALIGNMENT,
  1949. (UINT )(ulBufLen + MEMORY_ALLOCATION_ALIGNMENT),
  1950. 0 );
  1951. }
  1952. #define ALLOC_NDIS_WORK_ITEM( pA ) \
  1953. NdisAllocateFromNPagedLookasideList( &(pA)->llistWorkItems )
  1954. #define FREE_NDIS_WORK_ITEM( pA, pNwi ) \
  1955. NdisFreeToNPagedLookasideList( &(pA)->llistWorkItems, (pNwi) )
  1956. #define ALLOC_TIMERQITEM( pA ) \
  1957. NdisAllocateFromNPagedLookasideList( &(pA)->llistTimerQItems )
  1958. #define FREE_TIMERQITEM( pA, pTqi ) \
  1959. NdisFreeToNPagedLookasideList( &(pA)->llistTimerQItems, (pTqi) )
  1960. #define ALLOC_TUNNELCB( pA ) \
  1961. ALLOC_NONPAGED( sizeof(TUNNELCB), MTAG_TUNNELCB )
  1962. #define FREE_TUNNELCB( pA, pT ) \
  1963. FREE_NONPAGED( pT )
  1964. #define ALLOC_VCCB( pA ) \
  1965. ALLOC_NONPAGED( sizeof(VCCB), MTAG_VCCB )
  1966. #define FREE_VCCB( pA, pV ) \
  1967. FREE_NONPAGED( pV )
  1968. #define ALLOC_TIMERQ( pA ) \
  1969. ALLOC_NONPAGED( sizeof(TIMERQ), MTAG_TIMERQ )
  1970. #define FREE_TIMERQ( pA, pTq ) \
  1971. FREE_NONPAGED( pTq )
  1972. //
  1973. // Log packet macro
  1974. //
  1975. #ifdef PKT_LOG
  1976. #define NIC1394_ALLOC_PKTLOG(_pAdapter) \
  1977. nic1394AllocPktLog(_pAdapter)
  1978. #define NIC1394_DEALLOC_PKTLOG(_pAdapter) \
  1979. Nic1394DeallocPktLog(_pAdapter)
  1980. #define NIC1394_LOG_PKT(_pAdapter, _Flags, _SourceID, _DestID, _pvData, _cbData)\
  1981. (((_pAdapter)->pPktLog) ? \
  1982. Nic1394LogPkt( \
  1983. (_pAdapter)->pPktLog, \
  1984. (_Flags), \
  1985. (_SourceID), \
  1986. (_DestID), \
  1987. (_pvData), \
  1988. (_cbData) \
  1989. ) \
  1990. : 0)
  1991. #else
  1992. #define NIC1394_ALLOC_PKTLOG(_pAdapter)
  1993. #define NIC1394_DEALLOC_PKTLOG(_pAdapter)
  1994. #define NIC1394_LOG_PKT(_pAdapter, _Flags, _SourceID, _DestID, _pvData, _cbData)
  1995. #endif
  1996. #define NIC1394_LOGFLAGS_RECV_CHANNEL 0x00000001
  1997. #define NIC1394_LOGFLAGS_SEND_FIFO 0x00000010
  1998. #define NIC1394_LOGFLAGS_SEND_CHANNEL 0x00000011
  1999. #define NIC1394_LOGFLAGS_RECV_FIFO 0x00000100
  2000. #define NIC1394_LOGFLAGS_BCM_FAILED 0x00001000
  2001. #define NIC1394_LOGFLAGS_BCM_IS_IRM_TIMEOUT 0x00002000
  2002. #define NIC1394_LOGFLAGS_BCM_NOT_IRM_TIMEOUT 0x00004000
  2003. #define NIC1394_LOGFLAGS_BCM_IRM_NOT_FOUND 0x00008000
  2004. #if 0
  2005. //
  2006. // To get the MaxRec we extract the 0xf000 nibble
  2007. //
  2008. #define GET_MAXREC_FROM_BUSCAPS(_pBus, _pMaxRec) \
  2009. { \
  2010. ULONG _LitEnd = SWAPBYTES_ULONG(_pBus); \
  2011. _LitEnd = _LitEnd & 0xf000; \
  2012. _LitEnd = _LitEnd >> 12; \
  2013. *(_pBusRec) = _LitEnd; \
  2014. }
  2015. #endif
  2016. //
  2017. // To get the MaxRec we extract the 0xf000 nibble
  2018. //
  2019. #define GET_MAXREC_FROM_BUSCAPS(_Bus) (((_Bus) & 0xf00000) >> 20);
  2020. //-----------------------------------------------------------------------------
  2021. // F L A G S & L O C K S
  2022. //-----------------------------------------------------------------------------
  2023. //
  2024. // These macros are just present to make accessing the VC's flags easier
  2025. // and concentrate the implementations at one place
  2026. //
  2027. #define VC_TEST_FLAG(_V, _F) ((nicReadFlags(&(_V)->Hdr.ulFlags) & (_F))!= 0)
  2028. #define VC_SET_FLAG(_V, _F) (nicSetFlags(&(_V)->Hdr.ulFlags, (_F)))
  2029. #define VC_CLEAR_FLAGS(_V, _F) (nicClearFlags(&(_V)->Hdr.ulFlags , (_F)))
  2030. #define VC_TEST_FLAGS(_V, _F) ((nicReadFlags(&(_V)->Hdr.ulFlags) & (_F)) == (_F))
  2031. #define VC_READ_FLAGS(_V) ((nicReadFlags(&(_V)->Hdr.ulFlags)
  2032. #define VC_ACTIVE(_V) (((_V)->Hdr.ulFlags & (VCBF_CloseCallPending | VCBF_VcDeleted | VCBF_VcActivated |VCBF_MakeCallPending )) == VCBF_VcActivated)
  2033. #define REMOTE_NODE_TEST_FLAG(_P, _F ) ((nicReadFlags(&(_P)->ulFlags) & (_F))!= 0)
  2034. #define REMOTE_NODE_SET_FLAG(_P, _F) (nicSetFlags(&(_P)->ulFlags, (_F)))
  2035. #define REMOTE_NODE_CLEAR_FLAGS(_P, _F) (nicClearFlags(&(_P)->ulFlags , (_F)))
  2036. #define REMOTE_NODE_TEST_FLAGS(_P, _F) ((nicReadFlags(&(_P)->ulFlags) & (_F)) == (_F))
  2037. #define REMOTE_NODE_READ_FLAGS(_P) ((nicReadFlags(&(_P)->ulFlags)
  2038. #define REMOTE_NODE_ACTIVE(_P) (((_P)->ulFlags & (PDO_Activated | PDO_BeingRemoved)) == PDO_Activated)
  2039. #define ADAPTER_TEST_FLAG(_A, _F) ((nicReadFlags(&(_A)->ulFlags) & (_F))!= 0)
  2040. #define ADAPTER_SET_FLAG(_A, _F) (nicSetFlags(&(_A)->ulFlags, (_F)))
  2041. #define ADAPTER_CLEAR_FLAG(_A, _F) (nicClearFlags(&(_A)->ulFlags , (_F)))
  2042. #define ADAPTER_TEST_FLAGS(_A, _F) ((nicReadFlags(&(_A)->ulFlags) & (_F)) == (_F))
  2043. #define ADAPTER_READ_FLAGS(_A) ((nicReadFlags(&(_A)->ulFlags)
  2044. #define ADAPTER_ACTIVE(_A) ((((_A)->ulFlags) & fADAPTER_VDOInactive) != fADAPTER_VDOInactive)
  2045. #define BCR_TEST_FLAG(_A, _F) ((nicReadFlags(&(_A)->BCRData.Flags) & (_F))!= 0)
  2046. #define BCR_SET_FLAG(_A, _F) (nicSetFlags(&(_A)->BCRData.Flags, (_F)))
  2047. #define BCR_CLEAR_FLAG(_A, _F) (nicClearFlags(&(_A)->BCRData.Flags , (_F)))
  2048. #define BCR_CLEAR_ALL_FLAGS(_A) ((_A)->BCRData.Flags = 0)
  2049. #define BCR_TEST_FLAGS(_A, _F) ((nicReadFlags(&(_A)->BCRData.Flags) & (_F)) != 0)
  2050. #define BCR_READ_FLAGS(_A) ((nicReadFlags(&(_A)->BCRData.Flags)
  2051. #define BCR_IS_VALID(_B) ((_B)->NC_One == 1 && (_B)->NC_Valid ==1)
  2052. #define IS_A_BCR(_B) ((_B)->NC_One == 1 )
  2053. #define LOOKASIDE_HEADER_SET_FLAG(_H, _F) (nicSetFlags(&(_H)->State.u.Flags, (_F)))
  2054. #define LOOKASIDE_HEADER_TEST_FLAG(_H, _F) ((nicReadFlags(&(_H)->State.u.Flags) & (_F))!= 0)
  2055. #define REASSEMBLY_ACTIVE(_R) (((_R)->Flags & (REASSEMBLY_ABORTED | REASSEMBLY_FREED)) == 0)
  2056. #define REASSEMBLY_TEST_FLAG(_R,_F) ((nicReadFlags(&(_R)->Flags) & (_F))!= 0)
  2057. #define REASSEMBLY_SET_FLAG(_R,_F) (nicSetFlags(&(_R)->Flags, (_F)))
  2058. #define REASSEMBLY_CLEAR_FLAG(_R,_F) (nicClearFlags(&(_R)->Flags , (_F)))
  2059. #define NIC_GET_SYSTEM_ADDRESS_FOR_MDL(_M) MmGetSystemAddressForMdl(_M)
  2060. #define NIC_GET_BYTE_COUNT_FOR_MDL(_M) MmGetMdlByteCount(_M)
  2061. #define nicNdisBufferVirtualAddress(_N) NdisBufferVirtualAddress(_N)
  2062. #define nicNdisBufferLength(_N) NdisBufferLength(_N)
  2063. //
  2064. // These macros are used to assert that the IRQL level remains the same
  2065. // at the beginning and end of a function
  2066. //
  2067. #if DBG
  2068. #define STORE_CURRENT_IRQL UCHAR OldIrql = KeGetCurrentIrql();
  2069. #define MATCH_IRQL ASSERT (OldIrql == KeGetCurrentIrql() );
  2070. #else
  2071. #define STORE_CURRENT_IRQL
  2072. #define MATCH_IRQL
  2073. #endif // if DBG
  2074. //
  2075. // Macros used to access the Reference Structure (not used yet)
  2076. //
  2077. #define NIC_INCREMENT_REF (_R) nicReferenceRef (_R);
  2078. #define NIC_DEREFERENCE_REF (_R) nicDereferenceRef (_R)
  2079. #define nicInitializeCallRef(_pV) nicInitializeRef (&(_pV)->Hdr.CallRef);
  2080. #define nicCloseCallRef(_pV) nicCloseRef (&(_pV)->Hdr.CallRef);
  2081. //
  2082. // Macros used to acquire and release lock by the data structures (Vc, AF, Adapter)
  2083. // Right now, they all point to the same lock (i.e.) the lock in the Adapter structure
  2084. //
  2085. #define VC_ACQUIRE_LOCK(_pVc) NdisAcquireSpinLock (_pVc->Hdr.plock);
  2086. #define VC_RELEASE_LOCK(_pVc) NdisReleaseSpinLock (_pVc->Hdr.plock);
  2087. #define AF_ACQUIRE_LOCK(_pAF) NdisAcquireSpinLock (&_pAF->pAdapter->lock);
  2088. #define AF_RELEASE_LOCK(_pAF) NdisReleaseSpinLock (&_pAF->pAdapter->lock);
  2089. #define ADAPTER_ACQUIRE_LOCK(_pA) NdisAcquireSpinLock (&_pA->lock);
  2090. #define ADAPTER_RELEASE_LOCK(_pA) NdisReleaseSpinLock (&_pA->lock);
  2091. #define REMOTE_NODE_ACQUIRE_LOCK(_pP) NdisAcquireSpinLock (&_pP->pAdapter->lock);
  2092. #define REMOTE_NODE_RELEASE_LOCK(_pP) NdisReleaseSpinLock (&_pP->pAdapter->lock);
  2093. #define REASSEMBLY_ACQUIRE_LOCK(_R) REMOTE_NODE_REASSEMBLY_ACQUIRE_LOCK(_R->pRemoteNode);
  2094. #define REASSEMBLY_RELEASE_LOCK(_R) REMOTE_NODE_REASSEMBLY_RELEASE_LOCK(_R->pRemoteNode);
  2095. #ifdef TRACK_LOCKS
  2096. #define REMOTE_NODE_REASSEMBLY_ACQUIRE_LOCK(_Remote) \
  2097. nicAcquireSpinLock (&_Remote->ReassemblyLock , __FILE__ , __LINE__);
  2098. #define REMOTE_NODE_REASSEMBLY_RELEASE_LOCK(_Remote) \
  2099. nicReleaseSpinLock (&_Remote->ReassemblyLock , __FILE__ , __LINE__);
  2100. #else
  2101. #define REMOTE_NODE_REASSEMBLY_ACQUIRE_LOCK(_Remote) NdisAcquireSpinLock (&_Remote->ReassemblyLock.NdisLock);
  2102. #define REMOTE_NODE_REASSEMBLY_RELEASE_LOCK(_Remote) NdisReleaseSpinLock (&_Remote->ReassemblyLock.NdisLock);
  2103. #endif
  2104. #define REASSEMBLY_APPEND_FRAG_DESC(_pR, _Off, _Len) \
  2105. _pR->FragTable[_pR->MaxOffsetTableIndex].Offset =_Off; \
  2106. _pR->FragTable[_pR->MaxOffsetTableIndex].IPLength = _Len; \
  2107. _pR->MaxOffsetTableIndex++;
  2108. //-----------------------------------------------------------------------------
  2109. // S T A T S & F A I L U R E M A C R O S
  2110. //-----------------------------------------------------------------------------
  2111. // Used to distinguish stats collected that are collected in the various code paths
  2112. typedef enum
  2113. {
  2114. ChannelCodePath,
  2115. FifoCodePath,
  2116. ReceiveCodePath,
  2117. NoMoreCodePaths
  2118. };
  2119. #if TRACK_FAILURE
  2120. extern ULONG BusFailure;
  2121. extern ULONG MallocFailure;
  2122. extern ULONG IsochOverwrite;
  2123. extern ULONG MaxIndicatedFifos;
  2124. #define nicInitTrackFailure() BusFailure = 0;MallocFailure= 0;
  2125. #define nicIncrementBusFailure() NdisInterlockedIncrement(&BusFailure);
  2126. #define nicIncrementMallocFailure() NdisInterlockedIncrement(&MallocFailure);
  2127. #define nicIsochOverwritten() NdisInterlockedIncrement(&IsochOverwrite);
  2128. #define nicStatsRecordNumIndicatedFifos(_Num) \
  2129. { \
  2130. ULONG _N_ = (_Num); \
  2131. ASSERT((_N_) <= 100); \
  2132. MaxIndicatedFifos = max((_N_), MaxIndicatedFifos); \
  2133. }
  2134. #define nicIncChannelSendMdl() NdisInterlockedIncrement(&MdlsAllocated[ChannelCodePath]);
  2135. #define nicIncFifoSendMdl() NdisInterlockedIncrement(&MdlsAllocated[FifoCodePath]);
  2136. #define nicDecChannelSendMdl() NdisInterlockedIncrement(&MdlsFreed[ChannelCodePath]);
  2137. #define nicDecFifoSendMdl() NdisInterlockedIncrement(&MdlsFreed[FifoCodePath]);
  2138. #define nicIncChannelRecvBuffer() NdisInterlockedIncrement(&NdisBufferAllocated[ChannelCodePath]);
  2139. #define nicIncFifoRecvBuffer() NdisInterlockedIncrement(&NdisBufferAllocated[FifoCodePath]);
  2140. #define nicDecChannelRecvBuffer() NdisInterlockedIncrement(&NdisBufferFreed[ChannelCodePath]);
  2141. #define nicDecFifoRecvBuffer() NdisInterlockedIncrement(&NdisBufferFreed[FifoCodePath]);
  2142. #define nicIncRecvBuffer(_bisFifo) \
  2143. { \
  2144. if (_bisFifo) \
  2145. { nicIncFifoRecvBuffer(); } \
  2146. else \
  2147. { nicIncChannelRecvBuffer();} \
  2148. }
  2149. #define nicDecRecvBuffer(_bisFifo) \
  2150. { \
  2151. if (_bisFifo) \
  2152. { nicDecFifoRecvBuffer(); } \
  2153. else \
  2154. { nicDecChannelRecvBuffer(); }\
  2155. }
  2156. #else
  2157. #define nicInitTrackFailure()
  2158. #define nicIncrementBusFailure()
  2159. #define nicIncrementMallocFailure()
  2160. #define nicIsochOverwritten()
  2161. #define nicStatsRecordNumIndicatedFifos(_Num)
  2162. #define nicIncChannelSendMdl()
  2163. #define nicIncFifoSendMdl()
  2164. #define nicDecChannelSendMdl()
  2165. #define nicDecFifoSendMdl()
  2166. #define nicFreeMdlRecordStat()
  2167. #endif
  2168. #if QUEUED_PACKETS_STATS
  2169. extern ULONG RcvTimerCount;
  2170. extern ULONG SendTimerCount;
  2171. #define nicInitQueueStats() \
  2172. NdisZeroMemory (&SendStats, sizeof(SendStats) ); \
  2173. NdisZeroMemory (&RcvStats, sizeof(RcvStats) ); \
  2174. nicMaxRcv = 0; \
  2175. nicMaxSend = 0;
  2176. #define nicSetCountInHistogram(_PktsInQueue, _Stats) NdisInterlockedIncrement (&(_Stats.Bucket [ (_PktsInQueue/10) ] ) );
  2177. #define nicIncrementRcvTimerCount() NdisInterlockedIncrement(&RcvTimerCount);
  2178. #define nicIncrementSendTimerCount() NdisInterlockedIncrement(&SendTimerCount);
  2179. #define nicSetMax(_nicMax, _PktsInQueue) _nicMax = max(_nicMax, _PktsInQueue);
  2180. #else
  2181. #define nicInitQueueStats()
  2182. #define nicSetCountInHistogram(_PktsInQueue, _Stats)
  2183. #define nicSetMax(_nicMax, _PktsInQueue)
  2184. #define nicIncrementRcvTimerCount()
  2185. #define nicIncrementSendTimerCount()
  2186. #endif
  2187. //
  2188. // Isoch descriptor macros - Used in the send/recv code path
  2189. //
  2190. typedef enum
  2191. {
  2192. IsochNext,
  2193. IsochTag,
  2194. IsochChannelVc,
  2195. MaxIsochContextIndex
  2196. } IsochContextIndex;
  2197. //
  2198. // The following structure is used to add more contexts to a work item.
  2199. // NOTE: the Adapter is passed in as the context always.
  2200. //
  2201. typedef union _NIC_WORK_ITEM
  2202. {
  2203. NDIS_WORK_ITEM NdisWorkItem;
  2204. struct{
  2205. NDIS_WORK_ITEM NdisWorkItem;
  2206. PNDIS_REQUEST pNdisRequest;
  2207. VCCB* pVc;
  2208. } RequestInfo;
  2209. struct{
  2210. NDIS_WORK_ITEM NdisWorkItem;
  2211. ULONG Start;
  2212. PNDIS_REQUEST pNdisRequest;
  2213. } StartArpInfo;
  2214. struct {
  2215. NDIS_WORK_ITEM NdisWorkItem;
  2216. } Fifo;
  2217. } NIC_WORK_ITEM, *PNIC_WORK_ITEM;
  2218. #define STORE_CHANNELVC_IN_DESCRIPTOR(_pI,_pVc) (_pI)->DeviceReserved[IsochChannelVc] =(ULONG_PTR) _pVc
  2219. #define GET_CHANNELVC_FROM_DESCRIPTOR(_pI) (_pI)->DeviceReserved[IsochChannelVc]
  2220. #define MARK_ISOCH_DESCRIPTOR_INDICATED(_pI) \
  2221. (_pI)->DeviceReserved[IsochTag] = (ULONG)NIC1394_TAG_INDICATED; \
  2222. (_pI)->DeviceReserved[IsochNext] = 0;
  2223. #define MARK_ISOCH_DESCRIPTOR_IN_REASSEMBLY(_pI) \
  2224. (_pI)->DeviceReserved[IsochTag] = (ULONG)NIC1394_TAG_REASSEMBLY;
  2225. #define CLEAR_DESCRIPTOR_OF_NDIS_TAG(_pI) \
  2226. (_pI)->DeviceReserved[IsochTag] = 0;
  2227. #define APPEND_ISOCH_DESCRIPTOR(_Old, _New) \
  2228. (_Old)->DeviceReserved[IsochNext] = (ULONG_PTR)&((_New)->DeviceReserved[IsochNext]);
  2229. #define NEXT_ISOCH_DESCRIPTOR(_pI) (_pI)->DeviceReserved[IsochNext]
  2230. #define CLEAR_DESCRIPTOR_NEXT(_pI) (_pI)->DeviceReserved[IsochNext] = 0;
  2231. #define GET_MDL_FROM_IRB(_pM, _pI, _Op) \
  2232. if (_Op==AsyncWrite) \
  2233. { \
  2234. _pM = _pI->u.AsyncWrite.Mdl; \
  2235. } \
  2236. else \
  2237. { \
  2238. ASSERT (_Op == AsyncStream); \
  2239. _pM = _pI->u.AsyncStream.Mdl ; \
  2240. }
  2241. //
  2242. // Macros used to walk a doubly linked list. Only macros that are not defined in ndis.h
  2243. // The List Next macro will work on Single and Doubly linked list as Flink is a common
  2244. // field name in both
  2245. //
  2246. /*
  2247. PLIST_ENTRY
  2248. ListNext (
  2249. IN PLIST_ENTRY
  2250. );
  2251. PSINGLE_LIST_ENTRY
  2252. ListNext (
  2253. IN PSINGLE_LIST_ENTRY
  2254. );
  2255. */
  2256. #define ListNext(_pL) (_pL)->Flink
  2257. /*
  2258. PLIST_ENTRY
  2259. ListPrev (
  2260. IN LIST_ENTRY *
  2261. );
  2262. */
  2263. #define ListPrev(_pL) (_pL)->Blink
  2264. #define OnlyElementInList(_pL) (_pL->Flink == _pL->Blink ? TRUE : FALSE)
  2265. #define BREAK(_TM_Mode, _String) \
  2266. { \
  2267. TRACE( TL_A, _TM_Mode, ( _String ) ); \
  2268. break; \
  2269. }
  2270. // USHORT
  2271. // SWAPBYTES_USHORT(USHORT Val )
  2272. //
  2273. #define SWAPBYTES_USHORT(Val) \
  2274. ((((Val) & 0xff) << 8) | (((Val) & 0xff00) >> 8))
  2275. // ULONG
  2276. // SWAPBYTES_ULONG(ULONG Val )
  2277. //
  2278. #define SWAPBYTES_ULONG(Val) \
  2279. ((((Val) & 0x000000ff) << 24) | \
  2280. (((Val) & 0x0000ff00) << 8) | \
  2281. (((Val) & 0x00ff0000) >> 8) | \
  2282. (((Val) & 0xff000000) >> 24) )
  2283. //
  2284. // nicRemoveEntry List
  2285. // Just add a check to make sure that we are actually pointing to a valid next
  2286. //
  2287. #define nicRemoveEntryList(_L) \
  2288. { \
  2289. ASSERT ((_L)->Flink != (_L)); \
  2290. RemoveEntryList (_L); \
  2291. }
  2292. //#define nicFreeToNPagedLookasideList(_L, _E) NdisFreeToNPagedLookasideList(_L, _E)
  2293. //#define nicDeleteLookasideList(_L) NdisDeleteNPagedLookasideList(_L)
  2294. //
  2295. // Timing Query Routines
  2296. //
  2297. #define nicQueryTickCount() \
  2298. LARGE_INTEGER TickStart; \
  2299. KeQueryTickCount(&TickStart);
  2300. #define nicPrintElapsedTicks(_s) \
  2301. { \
  2302. LARGE_INTEGER TickEnd, TickDiff; \
  2303. ULONG Increment = KeQueryTimeIncrement() ; \
  2304. KeQueryTickCount(&TickEnd); \
  2305. TickDiff.QuadPart = TickEnd.QuadPart - TickStart.QuadPart; \
  2306. TickDiff.QuadPart = (TickDiff.QuadPart * Increment); \
  2307. DbgPrint (_s); \
  2308. DbgPrint(" TickStart %x %x, Time End %x %x Time Diff %x %x Increment %x\n",TickStart.HighPart , TickStart.LowPart , TickEnd.HighPart, TickEnd.LowPart, TickDiff.HighPart, TickDiff.LowPart, Increment); \
  2309. }
  2310. #define nicEntryTimeStamp() \
  2311. UINT EntryMilliSec; \
  2312. EntryMilliSec= nicGetSystemTimeMilliSeconds();
  2313. #if DO_TIMESTAMPS
  2314. void
  2315. nicTimeStamp(
  2316. char *szFormatString,
  2317. UINT Val
  2318. );
  2319. #define TIMESTAMP(_FormatString) nicTimeStamp("TIMESTAMP %lu:%lu.%lu nic1394 " _FormatString "\n" , 0)
  2320. #define TIMESTAMP1(_FormatString, _Val) nicTimeStamp( "TIMESTAMP %lu:%lu.%lu ARP1394 " _FormatString "\n" , (_Val))
  2321. #else // !DO_TIMESTAMPS
  2322. #define TIMESTAMP(_FormatString)
  2323. #define TIMESTAMP1(_FormatString, _Val)
  2324. #endif // !DO_TIMESTAMPS
  2325. #if ENTRY_EXIT_TIME
  2326. #define TIMESTAMP_ENTRY(_String) TIMESTAMP(_String)
  2327. #define TIMESTAMP_EXIT(_String) TIMESTAMP(_String)
  2328. #else
  2329. #define TIMESTAMP_ENTRY(s);
  2330. #define TIMESTAMP_EXIT(s);
  2331. #endif
  2332. #if INIT_HALT_TIME
  2333. #define TIMESTAMP_INITIALIZE() TIMESTAMP("==>InitializeHandler");
  2334. #define TIMESTAMP_HALT() TIMESTAMP("<==Halt");
  2335. #else
  2336. #define TIMESTAMP_INITIALIZE()
  2337. #define TIMESTAMP_HALT()
  2338. #endif
  2339. //-----------------------------------------------------------------------------
  2340. // S T A T I S T I C M A C R O S
  2341. //-----------------------------------------------------------------------------
  2342. //
  2343. // Reasembly counts
  2344. //
  2345. #define nicReassemblyStarted(_pAdapter) \
  2346. { \
  2347. NdisInterlockedIncrement( &(_pAdapter->AdaptStats.TempStats.ulNumOutstandingReassemblies)); \
  2348. NdisInterlockedIncrement ( &(_pAdapter->Reassembly.PktsInQueue)); \
  2349. NdisInterlockedIncrement ( &(_pAdapter->OutstandingReassemblies));\
  2350. }
  2351. #define nicReassemblyCompleted(_A) \
  2352. { \
  2353. NdisInterlockedDecrement(&(_A->AdaptStats.TempStats.ulNumOutstandingReassemblies));\
  2354. NdisInterlockedDecrement(&(_A->Reassembly.PktsInQueue));\
  2355. NdisInterlockedDecrement ( &(_A->OutstandingReassemblies));\
  2356. }
  2357. #define nicReassemblyAborted(_A) \
  2358. { \
  2359. NdisInterlockedDecrement ( &(_A->OutstandingReassemblies)); \
  2360. NdisInterlockedIncrement (&(_A->AdaptStats.TempStats.ulAbortedReassemblies)); \
  2361. }
  2362. //
  2363. // Top level stat collection macros
  2364. //
  2365. #define nicIncrementRcvVcPktCount(_Vc, _Pkt) \
  2366. { \
  2367. if ((_Vc)->Hdr.VcType == NIC1394_RecvFIFO) \
  2368. { \
  2369. nicIncrementFifoRcvPktCount(_Vc, _Pkt); \
  2370. } \
  2371. else \
  2372. { \
  2373. nicIncrementChannelRcvPktCount(_Vc, _Pkt); \
  2374. } \
  2375. }
  2376. #define nicIncrementVcSendPktCount(_Vc, _Pkt) \
  2377. { \
  2378. if ((_Vc)->Hdr.VcType == NIC1394_SendFIFO) \
  2379. { \
  2380. nicIncrementFifoSendPktCount(_Vc, _Pkt); \
  2381. } \
  2382. else \
  2383. { \
  2384. nicIncrementChannelSendPktCount(_Vc, _Pkt); \
  2385. } \
  2386. }
  2387. #define nicIncrementVcSendFailures(_Vc, _Pkt) \
  2388. { \
  2389. if ((_Vc)->Hdr.VcType == NIC1394_SendFIFO) \
  2390. { \
  2391. nicIncrementFifoSendFailures(_Vc, _Pkt); \
  2392. } \
  2393. else \
  2394. { \
  2395. nicIncrementChannelSendFailures(_Vc, _Pkt); \
  2396. } \
  2397. }
  2398. #define nicIncrementVcBusSendFailures(_Vc, _Pkt) \
  2399. { \
  2400. if ((_Vc)->Hdr.VcType == NIC1394_SendFIFO) \
  2401. { \
  2402. nicIncrementFifoBusSendFailures(_Vc, _Pkt); \
  2403. } \
  2404. else \
  2405. { \
  2406. nicIncrementChannelBusSendFailures(_Vc, _Pkt); \
  2407. } \
  2408. }
  2409. #define nicIncrementVcBusSendSucess(_Vc, _Pkt) \
  2410. { \
  2411. if ((_Vc)->Hdr.VcType == NIC1394_SendFIFO) \
  2412. { \
  2413. nicIncrementFifoBusSendSucess(_Vc, _Pkt); \
  2414. } \
  2415. else \
  2416. { \
  2417. nicIncrementChannelBusSendSucess(_Vc, _Pkt); \
  2418. } \
  2419. }
  2420. //
  2421. // Fifo counts
  2422. //
  2423. #define nicIncrementFifoSendPktCount(_Vc, _Pkt) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.Fifo.ulSendNicSucess));
  2424. #define nicIncrementFifoSendFailures(_Vc, _Pkt) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.Fifo.ulSendNicFail));
  2425. #define nicIncrementFifoBusSendFailures(_Vc,_Pkt) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.Fifo.ulSendBusFail));
  2426. #define nicIncrementFifoBusSendSucess(_Vc,_Pkt) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.Fifo.ulSendBusSuccess));
  2427. #define nicIncrementFifoRcvPktCount(_Vc, _Pkt) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.Fifo.ulRecv));
  2428. //
  2429. // Channel Counts
  2430. //
  2431. #define nicIncrementChannelSendPktCount(_Vc, _Pkt) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.Channel.ulSendNicSucess));
  2432. #define nicIncrementChannelSendFailures(_Vc, _Pkt) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.Channel.ulSendNicFail));
  2433. #define nicIncrementChannelBusSendFailures(_Vc,_Pkt) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.Channel.ulSendBusFail));
  2434. #define nicIncrementChannelBusSendSucess(_Vc, _Pkt) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.Channel.ulSendBusSuccess));
  2435. #define nicIncrementChannelRcvPktCount(_Vc, _Pkt) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.Channel.ulRecv));
  2436. //
  2437. // Generic counts
  2438. //
  2439. #define nicIncrementSendCompletes(_Vc) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.ulNumSendsCompleted )); \
  2440. NdisInterlockedIncrement(&NicSendCompletes);
  2441. #define nicIncrementSends(_Vc) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.ulNumSends)); \
  2442. NdisInterlockedIncrement (&NicSends);
  2443. #define nicIncrementBusSends(_Vc) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.ulNumBusSends)); \
  2444. NdisInterlockedIncrement (&BusSends);
  2445. #define nicIncrementBusSendCompletes(_Vc) NdisInterlockedIncrement(&((_Vc)->Hdr.pAF->pAdapter->AdaptStats.TempStats.ulNumBusSendsCompleted )); \
  2446. NdisInterlockedIncrement(&BusSendCompletes);
  2447. #if FIFO_WRAPPER
  2448. #define nicSetTagInFifoWrapper(_pF, _Tag) \
  2449. { \
  2450. ((PADDRESS_FIFO_WRAPPER)(_pF))->Tag = _Tag; \
  2451. \
  2452. }
  2453. #else
  2454. #define nicSetTagInFifoWrapper(_pF, _Tag)
  2455. #endif
  2456. //-----------------------------------------------------------------------------
  2457. // N I C E R R O R C O D E S
  2458. //-----------------------------------------------------------------------------
  2459. #define NIC_ERROR_CODE_INVALID_UNIQUE_ID_0 0xbad0000
  2460. #define NIC_ERROR_CODE_INVALID_UNIQUE_ID_FF 0xbadffff
  2461. //-----------------------------------------------------------------------------
  2462. // R E M O T E N O D E F U N C T I O N S
  2463. //-----------------------------------------------------------------------------
  2464. #if 0
  2465. VOID
  2466. NicMpNotifyHandler(
  2467. IN PDEVICE_OBJECT RemoteNodePhysicalDeviceObject,
  2468. IN PDEVICE_OBJECT LocalHostPhysicalDeviceObject,
  2469. IN ULONG UniqueId0,
  2470. IN ULONG UniqueId1,
  2471. IN NDIS1394ENUM_NOTIFY_CODE NotificationCode
  2472. );
  2473. #endif
  2474. NDIS_STATUS
  2475. NicInitializeRemoteNode(
  2476. OUT REMOTE_NODE **ppRemoteNode,
  2477. IN PDEVICE_OBJECT p1394DeviceObject,
  2478. IN UINT64 UniqueId
  2479. );
  2480. NTSTATUS
  2481. nicAddRemoteNode(
  2482. IN PVOID Nic1394AdapterContext, // Nic1394 handle for the local host adapter
  2483. IN PVOID Enum1394NodeHandle, // Enum1394 handle for the remote node
  2484. IN PDEVICE_OBJECT RemoteNodePhysicalDeviceObject, // physical device object for the remote node
  2485. IN ULONG UniqueId0, // unique ID Low for the remote node
  2486. IN ULONG UniqueId1, // unique ID High for the remote node
  2487. OUT PVOID * pNic1394NodeContext // Nic1394 context for the remote node
  2488. );
  2489. NTSTATUS
  2490. nicRemoveRemoteNode(
  2491. IN PVOID Nic1394NodeContext // Nic1394 context for the remote node
  2492. );
  2493. NDIS_STATUS
  2494. nicFindRemoteNodeFromAdapter(
  2495. IN PADAPTERCB pAdapter,
  2496. IN PDEVICE_OBJECT pRemotePdo,
  2497. IN UINT64 UniqueId,
  2498. IN OUT REMOTE_NODE ** ppRemoteNode
  2499. );
  2500. NDIS_STATUS
  2501. nicGetLocalHostPdoBlock (
  2502. IN PVCCB pVc,
  2503. IN OUT REMOTE_NODE **ppRemoteNode
  2504. );
  2505. NDIS_STATUS
  2506. nicRemoteNodeRemoveVcCleanUp (
  2507. IN PREMOTE_NODE pRemoteNode
  2508. );
  2509. UINT
  2510. nicNumOfActiveRemoteNodes(
  2511. IN PADAPTERCB pAdapter
  2512. );
  2513. BOOLEAN
  2514. nicReferenceRemoteNode (
  2515. IN REMOTE_NODE *pRemoteNode,
  2516. IN PCHAR pDebugPrint
  2517. );
  2518. BOOLEAN
  2519. nicDereferenceRemoteNode (
  2520. IN REMOTE_NODE *pRemoteNode,
  2521. IN CHAR DebugPrint[50]
  2522. );
  2523. VOID
  2524. nicInitalizeRefRemoteNode(
  2525. IN REMOTE_NODE *pRemoteNode
  2526. );
  2527. BOOLEAN
  2528. nicCloseRefRemoteNode(
  2529. IN REMOTE_NODE *pRemoteNode
  2530. );
  2531. //-----------------------------------------------------------------------------
  2532. // U T I L I T Y F U N C T I O N S
  2533. //-----------------------------------------------------------------------------
  2534. VOID
  2535. nicCallCleanUp(
  2536. IN VCCB* pVc
  2537. );
  2538. VOID
  2539. nicClearFlags(
  2540. IN OUT ULONG* pulFlags,
  2541. IN ULONG ulMask
  2542. );
  2543. BOOLEAN
  2544. nicCloseRef(
  2545. IN PREF RefP
  2546. );
  2547. VOID
  2548. nicReferenceAdapter(
  2549. IN ADAPTERCB* pAdapter ,
  2550. IN PCHAR pDebugPrint
  2551. );
  2552. BOOLEAN
  2553. nicDereferenceCall(
  2554. IN VCCB* pVc,
  2555. IN PCHAR pDebugPrint
  2556. );
  2557. BOOLEAN
  2558. nicDereferenceRef(
  2559. IN PREF RefP
  2560. );
  2561. VOID
  2562. nicDereferenceAdapter(
  2563. IN PADAPTERCB pAdapter,
  2564. IN PCHAR pDebugPrint
  2565. );
  2566. VOID
  2567. nicDereferenceVc(
  2568. IN VCCB* pVc
  2569. );
  2570. NDIS_STATUS
  2571. nicExecuteWork(
  2572. IN ADAPTERCB* pAdapter,
  2573. IN NDIS_PROC pProc,
  2574. IN PVOID pContext,
  2575. IN ULONG ulArg1,
  2576. IN ULONG ulArg2,
  2577. IN ULONG ulArg3,
  2578. IN ULONG ulArg4
  2579. );
  2580. VOID
  2581. nicInitializeRef(
  2582. IN PREF RefP
  2583. );
  2584. ULONG
  2585. nicReadFlags(
  2586. IN ULONG* pulFlags
  2587. );
  2588. VOID
  2589. nicReferenceAdapter(
  2590. IN ADAPTERCB* pAdapter,
  2591. IN PCHAR pDebugPrint
  2592. );
  2593. BOOLEAN
  2594. nicReferenceCall(
  2595. IN VCCB* pVc,
  2596. IN PCHAR pDebugPrint
  2597. );
  2598. BOOLEAN
  2599. nicReferenceRef(
  2600. IN PREF RefP
  2601. );
  2602. VOID
  2603. nicReferenceVc(
  2604. IN VCCB* pVc
  2605. );
  2606. NDIS_STATUS
  2607. nicScheduleWork(
  2608. IN ADAPTERCB* pAdapter,
  2609. IN NDIS_PROC pProc,
  2610. IN PVOID pContext
  2611. );
  2612. VOID
  2613. nicSetFlags(
  2614. IN OUT ULONG* pulFlags,
  2615. IN ULONG ulMask
  2616. );
  2617. CHAR*
  2618. nicStrDup(
  2619. IN CHAR* psz
  2620. );
  2621. CHAR*
  2622. nicStrDupNdisString(
  2623. IN NDIS_STRING* pNdisString
  2624. );
  2625. CHAR*
  2626. nicStrDupSized(
  2627. IN CHAR* psz,
  2628. IN ULONG ulLength,
  2629. IN ULONG ulExtra
  2630. );
  2631. VOID
  2632. nicUpdateGlobalCallStats(
  2633. IN VCCB *pVc
  2634. );
  2635. NDIS_STATUS
  2636. NtStatusToNdisStatus (
  2637. NTSTATUS NtStatus
  2638. );
  2639. VOID
  2640. PrintNdisPacket (
  2641. ULONG TM_Comp,
  2642. PNDIS_PACKET pMyPacket
  2643. );
  2644. VOID
  2645. nicAllocatePacket(
  2646. OUT PNDIS_STATUS pNdisStatus,
  2647. OUT PNDIS_PACKET *ppNdisPacket,
  2648. IN PNIC_PACKET_POOL pPacketPool
  2649. );
  2650. VOID
  2651. nicFreePacket(
  2652. IN PNDIS_PACKET pNdisPacket,
  2653. IN PNIC_PACKET_POOL pPacketPool
  2654. );
  2655. VOID
  2656. nicFreePacketPool (
  2657. IN PNIC_PACKET_POOL pPacketPool
  2658. );
  2659. VOID
  2660. nicAcquireSpinLock (
  2661. IN PNIC_SPIN_LOCK pNicSpinLock,
  2662. IN PUCHAR FileName,
  2663. IN UINT LineNumber
  2664. );
  2665. VOID
  2666. nicReleaseSpinLock (
  2667. IN PNIC_SPIN_LOCK pNicSpinLock,
  2668. IN PUCHAR FileName,
  2669. IN UINT LineNumber
  2670. );
  2671. VOID
  2672. nicInitializeNicSpinLock (
  2673. IN PNIC_SPIN_LOCK pNicSpinLock
  2674. );
  2675. VOID
  2676. nicFreeNicSpinLock (
  2677. IN PNIC_SPIN_LOCK pNicSpinLock
  2678. );
  2679. VOID
  2680. nic1394DeallocPktLog(
  2681. IN ADAPTERCB* pAdapter
  2682. );
  2683. VOID
  2684. nic1394AllocPktLog(
  2685. IN ADAPTERCB* pAdapter
  2686. );
  2687. VOID
  2688. Nic1394LogPkt (
  2689. PNIC1394_PKTLOG pPktLog,
  2690. ULONG Flags,
  2691. ULONG SourceID,
  2692. ULONG DestID,
  2693. PVOID pvData,
  2694. ULONG cbData
  2695. );
  2696. VOID
  2697. Nic1394InitPktLog(
  2698. PNIC1394_PKTLOG pPktLog
  2699. );
  2700. ULONG
  2701. SwapBytesUlong(
  2702. IN ULONG Val
  2703. );
  2704. VOID
  2705. nicUpdatePacketState (
  2706. IN PNDIS_PACKET pPacket,
  2707. IN ULONG Tag
  2708. );
  2709. UINT
  2710. nicGetSystemTime(
  2711. VOID
  2712. );
  2713. UINT
  2714. nicGetSystemTimeMilliSeconds(
  2715. VOID
  2716. );
  2717. VOID
  2718. nicGetFakeMacAddress(
  2719. UINT64 *Euid,
  2720. MAC_ADDRESS *MacAddr
  2721. );
  2722. VOID
  2723. nicWriteErrorLog (
  2724. IN PADAPTERCB pAdapter,
  2725. IN NDIS_ERROR_CODE ErrorCode,
  2726. IN ULONG ErrorValue
  2727. );
  2728. //-----------------------------------------------------------------------------
  2729. // S E R I A L I Z E S E N D / R E C E I V E F U N C T I O N S
  2730. //-----------------------------------------------------------------------------
  2731. NDIS_STATUS
  2732. nicInitSerializedReceiveStruct(
  2733. PADAPTERCB pAdapter
  2734. );
  2735. VOID
  2736. nicDeInitSerializedReceiveStruct(
  2737. PADAPTERCB pAdapter
  2738. );
  2739. NDIS_STATUS
  2740. nicQueueReceivedPacket(
  2741. PNDIS_PACKET pPacket,
  2742. PVCCB pVc,
  2743. PADAPTERCB pAdapter
  2744. );
  2745. NDIS_STATUS
  2746. nicInitSerializedSendStruct(
  2747. PADAPTERCB pAdapter
  2748. );
  2749. VOID
  2750. nicDeInitSerializedSendStruct(
  2751. PADAPTERCB pAdapter
  2752. );
  2753. NDIS_STATUS
  2754. nicQueueSendPacket(
  2755. PNDIS_PACKET pPacket,
  2756. PVCCB pVc
  2757. );
  2758. //-----------------------------------------------------------------------------
  2759. // G L O B A L V A R I A B L E S
  2760. //-----------------------------------------------------------------------------
  2761. UINT NumChannels;
  2762. //-----------------------------------------------------------------------------
  2763. // E N U M E R A T O R F U N C T I O N S
  2764. //-----------------------------------------------------------------------------
  2765. extern ENUM1394_REGISTER_DRIVER_HANDLER NdisEnum1394RegisterDriver;
  2766. extern ENUM1394_DEREGISTER_DRIVER_HANDLER NdisEnum1394DeregisterDriver;
  2767. extern ENUM1394_REGISTER_ADAPTER_HANDLER NdisEnum1394RegisterAdapter;
  2768. extern ENUM1394_DEREGISTER_ADAPTER_HANDLER NdisEnum1394DeregisterAdapter;
  2769. extern NIC1394_CHARACTERISTICS Nic1394Characteristics;
  2770. NTSTATUS
  2771. NicRegisterEnum1394(
  2772. IN PNDISENUM1394_CHARACTERISTICS NdisEnum1394Characteristcis
  2773. );
  2774. VOID
  2775. NicDeregisterEnum1394(
  2776. VOID
  2777. );
  2778. VOID
  2779. Nic1394Callback(
  2780. PVOID CallBackContext,
  2781. PVOID Source,
  2782. PVOID Characteristics
  2783. );
  2784. VOID
  2785. Nic1394RegisterAdapters(
  2786. VOID
  2787. );
  2788. NTSTATUS
  2789. Nic1394BusRequest(
  2790. PDEVICE_OBJECT DeviceObject,
  2791. PIRB Irb
  2792. );
  2793. NTSTATUS
  2794. Nic1394PassIrpDownTheStack(
  2795. IN PIRP pIrp,
  2796. IN PDEVICE_OBJECT pNextDeviceObject
  2797. );
  2798. NTSTATUS
  2799. Nic1394IrpCompletion(
  2800. IN PDEVICE_OBJECT DeviceObject,
  2801. IN PIRP Irp,
  2802. IN PVOID Context
  2803. );
  2804. VOID
  2805. nicDumpMdl (
  2806. IN PMDL pMdl,
  2807. IN ULONG LengthToPrint,
  2808. IN CHAR *str
  2809. );
  2810. VOID
  2811. nicDumpPkt (
  2812. IN PNDIS_PACKET pPacket,
  2813. CHAR * str
  2814. );
  2815. VOID
  2816. nicCheckForEthArps (
  2817. IN PNDIS_PACKET pPkt
  2818. );
  2819. VOID
  2820. nicGetMacAddressFromEuid (
  2821. UINT64 *pEuid,
  2822. MAC_ADDRESS *pMacAddr
  2823. );
  2824. VOID
  2825. nicInitializeLoadArpStruct(
  2826. PADAPTERCB pAdapter
  2827. );
  2828. extern PCALLBACK_OBJECT Nic1394CallbackObject;
  2829. extern PVOID Nic1394CallbackRegisterationHandle;
  2830. //-----------------------------------------------------------------------------
  2831. // S T A T I S T I C B U C K E T S
  2832. //-----------------------------------------------------------------------------
  2833. extern STAT_BUCKET SendStats;
  2834. extern STAT_BUCKET RcvStats;
  2835. extern ULONG nicMaxRcv;
  2836. extern ULONG nicMaxSend;
  2837. extern ULONG SendTimer; // In ms
  2838. extern ULONG RcvTimer; // In ms