Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

454 lines
12 KiB

  1. /*****************************************************************************
  2. ** **
  3. ** COPYRIGHT (C) 2000, 2001 MKNET CORPORATION **
  4. ** DEVELOPED FOR THE MK7100-BASED VFIR PCI CONTROLLER. **
  5. ** **
  6. *****************************************************************************/
  7. /**********************************************************************
  8. Module Name:
  9. MK7COMM.H
  10. Comments:
  11. Include file for the MK7 driver.
  12. **********************************************************************/
  13. #ifndef _MK7COMM_H
  14. #define _MK7COMM_H
  15. //
  16. // IrDA definitions
  17. //
  18. #define MAX_EXTRA_SIR_BOFS 48
  19. #define SIR_BOF_SIZE 1
  20. #define SIR_EOF_SIZE 1
  21. #define ADDR_SIZE 1
  22. #define CONTROL_SIZE 1
  23. #define MAX_I_DATA_SIZE 2048
  24. #define MAX_I_DATA_SIZE_ESC (MAX_I_DATA_SIZE + 40)
  25. #define SIR_FCS_SIZE 2
  26. #define FASTIR_FCS_SIZE 4 // FIR/VFIR
  27. // History:
  28. // B2.1.0 - Was 2; set to 10 to align to 4DW.
  29. // B3.1.0-pre - back to 2
  30. //#define ALIGN_PAD 10 // buffer alignment
  31. #define ALIGN_PAD 2 // buffer alignment
  32. #define DEFAULT_TURNAROUND_usec 1000 // 1000 usec (1 msec)
  33. typedef struct {
  34. enum baudRates tableIndex;
  35. UINT bitsPerSec; // actual bits/sec
  36. UINT ndisCode; // bitmask
  37. } baudRateInfo;
  38. enum baudRates {
  39. // SIR
  40. BAUDRATE_2400 = 0,
  41. BAUDRATE_9600,
  42. BAUDRATE_19200,
  43. BAUDRATE_38400,
  44. BAUDRATE_57600,
  45. BAUDRATE_115200,
  46. // MIR
  47. BAUDRATE_576000,
  48. BAUDRATE_1152000,
  49. // FIR
  50. BAUDRATE_4M,
  51. // VFIR
  52. BAUDRATE_16M,
  53. NUM_BAUDRATES /* must be last */
  54. };
  55. #define DEFAULT_BAUD_RATE 9600
  56. #define MAX_SIR_SPEED 115200
  57. #define MIN_FIR_SPEED 4000000
  58. #define VFIR_SPEED 16000000
  59. //
  60. // End IrDA definitions
  61. //
  62. // TX/RX Ring settings
  63. #define DEF_RING_SIZE 64
  64. #define MIN_RING_SIZE 4
  65. #define MAX_RING_SIZE 64
  66. #define DEF_TXRING_SIZE 4
  67. #define DEF_RXRING_SIZE (DEF_TXRING_SIZE * 2)
  68. #define DEF_EBOFS 24
  69. #define MIN_EBOFS 0
  70. #define MAX_EBOFS 48
  71. #define HW_VER_1_EBOFS 5 // 4.1.0
  72. #define DEF_RCB_CNT DEF_RING_SIZE // !!RCB and TCB cnt must be the same!!
  73. #define DEF_TCB_CNT DEF_RING_SIZE // ALSO SEE MAX_ARRAY_xxx_PACKETS
  74. // Alloc twice as many receive buffers as receive ring size because these buffs
  75. // are pended to upper layer. Don't know when they may be returned.
  76. #define CalRpdSize(x) (x * 2) // Get RPD size given ring size
  77. #define NO_RCB_PENDING 0xFF
  78. #define RX_MODE 0
  79. #define TX_MODE 1
  80. // Set to hw for RX
  81. #define MK7_MAXIMUM_PACKET_SIZE (MAX_EXTRA_SIR_BOFS + \
  82. SIR_BOF_SIZE + \
  83. ADDR_SIZE + \
  84. CONTROL_SIZE + \
  85. MAX_I_DATA_SIZE + \
  86. SIR_FCS_SIZE + \
  87. SIR_EOF_SIZE)
  88. #define MK7_MAXIMUM_PACKET_SIZE_ESC (MAX_EXTRA_SIR_BOFS + \
  89. SIR_BOF_SIZE + \
  90. ADDR_SIZE + \
  91. CONTROL_SIZE + \
  92. MAX_I_DATA_SIZE_ESC + \
  93. SIR_FCS_SIZE + \
  94. SIR_EOF_SIZE)
  95. // For RX memory allocation
  96. //#define RPD_BUFFER_SIZE (MK7_MAXIMUM_PACKET_SIZE + ALIGN_PAD)
  97. #define RPD_BUFFER_SIZE (MK7_MAXIMUM_PACKET_SIZE_ESC + ALIGN_PAD)
  98. // For TX memory allocation
  99. #define COALESCE_BUFFER_SIZE (MK7_MAXIMUM_PACKET_SIZE_ESC + ALIGN_PAD)
  100. // Not used?
  101. #define MAX_TX_PACKETS 4
  102. #define MAX_RX_PACKETS 4
  103. #define SIR_BOF_TYPE UCHAR
  104. #define SIR_EXTRA_BOF_TYPE UCHAR
  105. #define SIR_EXTRA_BOF_SIZE sizeof(SIR_EXTRA_BOF_TYPE)
  106. #define SIR_EOF_TYPE UCHAR
  107. #define SIR_FCS_TYPE USHORT
  108. #define SIR_BOF 0xC0
  109. #define SIR_EXTRA_BOF 0xC0
  110. #define SIR_EOF 0xC1
  111. #define SIR_ESC 0x7D
  112. #define SIR_ESC_COMP 0x20
  113. // When FCS is computed on an IR packet with FCS appended, the result
  114. // should be this constant.
  115. #define GOOD_FCS ((USHORT) ~0xf0b8)
  116. //
  117. // Link list
  118. //
  119. typedef struct _MK7_LIST_ENTRY {
  120. LIST_ENTRY Link;
  121. } MK7_LIST_ENTRY, *PMK7_LIST_ENTRY;
  122. //
  123. // COALESCE -- Consolidate data for TX
  124. //
  125. typedef struct _COALESCE {
  126. MK7_LIST_ENTRY Link;
  127. PVOID OwningTcb;
  128. PUCHAR CoalesceBufferPtr;
  129. ULONG CoalesceBufferPhys;
  130. } COALESCE, *PCOALESCE;
  131. //
  132. // Receive Packet Descriptor (RPD)
  133. //
  134. // Each receive buffer has this control struct.
  135. //
  136. // (We use this mainly because there doesn't seem to be a simple way
  137. // to obtain a buff's phy addr from its virtual addr.)
  138. //
  139. typedef struct _RPD {
  140. MK7_LIST_ENTRY link;
  141. PNDIS_BUFFER ReceiveBuffer; // mapped buffer
  142. PNDIS_PACKET ReceivePacket; // mapped packet
  143. PUCHAR databuff; // virtual data buffer
  144. ULONG databuffphys; // physical data buffer
  145. USHORT status;
  146. UINT FrameLength;
  147. } RPD, *PRPD;
  148. //
  149. // Receive Control Block (RCB)
  150. //
  151. // Points to the corresponding RX Ring entry (RRD).
  152. //
  153. typedef struct _RCB {
  154. MK7_LIST_ENTRY link;
  155. PRRD rrd; // RX ring descriptor - RBD
  156. ULONG rrdphys; // Phy addr of RX ring descriptor
  157. PRPD rpd; // Receive Packet Descriptor
  158. } RCB, *PRCB;
  159. //
  160. // Transmit Control Block (TCB)
  161. //
  162. // Points to the corresponding TX Ring entry (TRD).
  163. //
  164. // NOTE: We have a link field. Chances are we don't need it
  165. // because the TCB (which is the software context for a TRD)
  166. // is indexed. For now we'll have a link field in case it's
  167. // needed.
  168. //
  169. typedef struct _TCB {
  170. MK7_LIST_ENTRY link;
  171. PTRD trd; // TX Ring entry - Transmit Ring Descriptor
  172. ULONG trdPhy;
  173. PUCHAR buff; // virtual data buffer
  174. ULONG buffphy; // physical data buffer
  175. // Stuff you get back from NdisQueryPacket()
  176. PNDIS_PACKET Packet;
  177. UINT PacketLength;
  178. UINT NumPhysDesc;
  179. UINT BufferCount;
  180. PNDIS_BUFFER FirstBuffer;
  181. BOOLEAN changeSpeedAfterThisTcb;
  182. } TCB, *PTCB;
  183. //
  184. // MK7_ADAPTER
  185. //
  186. typedef struct _MK7_ADAPTER
  187. {
  188. #if DBG
  189. UINT Debug;
  190. UINT DbgTest; // different debug/tests to run; 0=none
  191. UINT DbgTestDataCnt;
  192. #define DBG_QUEUE_LEN 4095 //0xfff
  193. UINT DbgIndex;
  194. UCHAR DbgQueue[DBG_QUEUE_LEN];
  195. UINT DbgSendCallCnt;
  196. UINT DbgSentCnt;
  197. UINT DbgSentPktsCnt;
  198. UINT LB; // Loopback debug/test
  199. UINT LBPktLevel; // pass thru 1 out of this many
  200. UINT LBPktCnt;
  201. NDIS_MINIPORT_TIMER MK7DbgTestIntTimer; // for interrupt testing
  202. #endif
  203. // Handle given by NDIS when the Adapter registered itself.
  204. NDIS_HANDLE MK7AdapterHandle;
  205. // 1st pkt queued for TX in deserialized miniport
  206. PNDIS_PACKET FirstTxQueue;
  207. PNDIS_PACKET LastTxQueue;
  208. UINT NumPacketsQueued;
  209. // Save the most recent interrupt events because the reg
  210. // is cleared once it's read.
  211. MK7REG recentInt;
  212. UINT CurrentSpeed; // bits/sec
  213. UINT MaxConnSpeed; // in 100bps increments
  214. UINT AllowedSpeedMask;
  215. baudRateInfo *linkSpeedInfo;
  216. // BOOLEAN haveIndicatedMediaBusy; // 1.0.0
  217. // Keep track of when to change speed.
  218. PNDIS_PACKET changeSpeedAfterThisPkt;
  219. UINT changeSpeedPending;
  220. //#define CHANGESPEED_ON_T 1 // change speed marked on TCB
  221. #define CHANGESPEED_ON_DONE 1 // change speed marked on Q
  222. #define CHANGESPEED_ON_Q 2 // change speed marked on Q
  223. // This info may come from the Registry
  224. UINT RegNumRcb; // # of RCB from the Registry
  225. UINT RegNumTcb; // # of TCB from the Registry
  226. UINT RegNumRpd; // RPD (RX Packet Descriptor) from Registry
  227. UINT RegSpeed; // IrDA speeds
  228. UINT RegExtraBOFs; // Extra BOFs based on 115.2kbps
  229. //******************************
  230. // RXs & TXs
  231. //******************************
  232. // UINT RrdTrdSize; // total RRD & TRD memory size
  233. PUCHAR pRrdTrd; // virtual address - aligned
  234. ULONG pRrdTrdPhysAligned; // physical address - aligned
  235. PUCHAR RxTxUnCached;
  236. NDIS_PHYSICAL_ADDRESS RxTxUnCachedPhys;
  237. UINT RxTxUnCachedSize;
  238. UINT RingSize; // same for both RRD & TRD
  239. //******************************
  240. // RXs
  241. //******************************
  242. UINT NumRcb; // what we actually use
  243. PRCB pRcb; // start of RCB
  244. PUCHAR pRrd; // start of RRD ( = pRrdTrd)
  245. ULONG pRrdPhys; // start of phy RRD ( = pRrdTrdPhysAligned)
  246. PRCB pRcbArray[MAX_RING_SIZE];
  247. UINT nextRxRcbIdx; // index of next RCB to process
  248. UINT rcbPendRpdIdx; // 1st RCB waiting for RPD
  249. UINT rcbPendRpdCnt; // keep cnt to help simplify code logic
  250. UINT rcbUsed; // RYM10-5 needed??
  251. UINT NumRpd; // actually allocated/used
  252. MK7_LIST_ENTRY FreeRpdList; // start of free list
  253. // 4.0.1 BOC
  254. UINT UsedRpdCount; // num of Rpds that not yet return to driver
  255. // 4.0.1 EOC.
  256. NDIS_HANDLE ReceivePacketPool;
  257. NDIS_HANDLE ReceiveBufferPool;
  258. PUCHAR RecvCached; // control structs
  259. UINT RecvCachedSize;
  260. PUCHAR RecvUnCached; // data buffs
  261. UINT RecvUnCachedSize;
  262. NDIS_PHYSICAL_ADDRESS RecvUnCachedPhys;
  263. // 4.1.0 HwVersion
  264. #define HW_VER_1 1
  265. #define HW_VER_2 2
  266. BOOLEAN HwVersion;
  267. //******************************
  268. // TXs
  269. //******************************
  270. UINT NumTcb; // what we actually use
  271. PTCB pTcb; // start of TCB
  272. PUCHAR pTrd; // start of TRD (512 bytes from pRrd)
  273. ULONG pTrdPhys;
  274. PTCB pTcbArray[MAX_RING_SIZE];
  275. UINT nextAvailTcbIdx; // index of next avail in the ring to use for TX
  276. UINT nextReturnTcbIdx; // index of next that'll be returned on completion
  277. UINT tcbUsed;
  278. BOOLEAN writePending; // RYM-2K-1TX
  279. PUCHAR XmitCached; // control structs
  280. UINT XmitCachedSize;
  281. PUCHAR XmitUnCached; // data buffs - coalesce buffs
  282. UINT XmitUnCachedSize;
  283. NDIS_PHYSICAL_ADDRESS XmitUnCachedPhys;
  284. ULONG MaxPhysicalMappings;
  285. // I/O port space (NOT memory mapped I/O)
  286. PUCHAR MappedIoBase;
  287. UINT MappedIoRange;
  288. // Adapter Information Variable (set via Registry entries)
  289. UINT BusNumber; //' BusNumber'
  290. USHORT BusDevice; // PCI Bus/Device #
  291. // timer structure for Async Resets
  292. NDIS_MINIPORT_TIMER MK7AsyncResetTimer; // 1.0.0
  293. NDIS_MINIPORT_TIMER MinTurnaroundTxTimer;
  294. NDIS_MINIPORT_INTERRUPT Interrupt; // interrupt object
  295. NDIS_INTERRUPT_MODE InterruptMode;
  296. NDIS_SPIN_LOCK Lock;
  297. UINT NumMapRegisters;
  298. UINT IOMode;
  299. UINT Wireless;
  300. UINT HangCheck; // 1.0.0
  301. //******************************
  302. // Hardware capabilities
  303. //******************************
  304. // This is a mask of NDIS_IRDA_SPEED_xxx bit values.
  305. UINT supportedSpeedsMask;
  306. // Time (in microseconds) that must transpire between a transmit
  307. //and the next receive.
  308. UINT turnAroundTime_usec;
  309. // Extra BOF (Beginning Of Frame) characters required at the
  310. // start of each received frame.
  311. UINT extraBOFsRequired;
  312. //******************************
  313. // OIDs
  314. //******************************
  315. UINT hardwareStatus; // OID_GEN_HARDWARE_STATUS
  316. BOOLEAN nowReceiving; // OID_IRDA_RECEIVING
  317. BOOLEAN mediaBusy; // OID_IRDA_MEDIA_BUSY
  318. UINT MKBaseSize; // Total port size in bytes
  319. UINT MKBaseIo; // Base I/O address
  320. UINT MKBusType; // 'BusType' (EISA or PCI)
  321. UINT MKInterrupt; // 'InterruptNumber'
  322. USHORT MKSlot; // 'Slot', PCI Slot Number
  323. // This variable should be initialized to false, and set to true
  324. // to prevent re-entrancy in our driver during reset spinlock and unlock
  325. // stuff related to checking our link status
  326. BOOLEAN ResetInProgress;
  327. NDIS_MEDIA_STATE LinkIsActive; // not used right now
  328. // save the status of the Memory Write Invalidate bit in the PCI command word
  329. BOOLEAN MWIEnable;
  330. //
  331. // Put statistics here
  332. //
  333. } MK7_ADAPTER, *PMK7_ADAPTER;
  334. //Given a MiniportContextHandle return the PMK7_ADAPTER it represents.
  335. #define PMK7_ADAPTER_FROM_CONTEXT_HANDLE(Handle) ((PMK7_ADAPTER)(Handle))
  336. //================================================
  337. // Global Variables shared by all driver instances
  338. //================================================
  339. // This constant is used for places where NdisAllocateMemory needs to be
  340. // called and the HighestAcceptableAddress does not matter.
  341. static const NDIS_PHYSICAL_ADDRESS HighestAcceptableMax =
  342. NDIS_PHYSICAL_ADDRESS_CONST(-1,-1);
  343. #endif // _MK7COMM.H