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.

495 lines
17 KiB

  1. /*
  2. (C) Copyright 1999
  3. All rights reserved.
  4. Portions of this software are:
  5. (C) Copyright 1995 TriplePoint, Inc. -- http://www.TriplePoint.com
  6. License to use this software is granted under the same terms
  7. outlined in the Microsoft Windows Device Driver Development Kit.
  8. (C) Copyright 1992 Microsoft Corp. -- http://www.Microsoft.com
  9. License to use this software is granted under the terms outlined in
  10. the Microsoft Windows Device Driver Development Kit.
  11. @doc INTERNAL Card Card_h
  12. @module Card.h |
  13. This module defines the hardware specific structures and values used to
  14. control the network interface card.
  15. @head3 Contents |
  16. @index class,mfunc,func,msg,mdata,struct,enum | Card_h
  17. @end
  18. */
  19. /* @doc EXTERNAL INTERNAL
  20. @topic 4.2 Card Overview |
  21. This section describes the interfaces defined in <f Card\.h>.
  22. This module isolates most the vendor specific hardware access interfaces.
  23. It will require signficant changes to accomodate your hardware device.
  24. You should try to isolate your changes to the <t CARD_OBJECT> rather then
  25. the <t MINIPORT_ADAPTER_OBJECT>. This will make it eaiser to reuse the
  26. upper portions of the driver should your hardware change in the future.
  27. The driver assumes one <t CARD_OBJECT> per physical ISDN card. The card
  28. object is always available via the <t MINIPORT_ADAPTER_OBJECT> which is
  29. available in nearly every interface the driver supports. Each
  30. <t CARD_OBJECT> contains one or more <t PORT_OBJECT>s depending on how
  31. many physical ISDN lines your card supports.
  32. You should add all your physical card related data to the <t CARD_OBJECT>.
  33. You can also add any card related registry parameters to this structure,
  34. and the <f g_CardParameters> table.
  35. */
  36. #ifndef _CARD_H
  37. #define _CARD_H
  38. #define CARD_OBJECT_TYPE ((ULONG)'C')+\
  39. ((ULONG)'A'<<8)+\
  40. ((ULONG)'R'<<16)+\
  41. ((ULONG)'D'<<24)
  42. /*
  43. // TODO - These values will normally come from the NIC or the installer.
  44. */
  45. #define MAX_ADAPTERS 8
  46. #define CARD_NUM_PORTS 1
  47. //#define CARD_MIN_IOPORT_SIZE 256
  48. // TODO - How many I/O ports does the card have? (undefined if none)
  49. //#define CARD_MIN_MEMORY_SIZE 256
  50. // TODO - How much memory does the card have? (undefined if none)
  51. #define CARD_IS_BUS_MASTER FALSE
  52. // TODO - Is the card a bus master device? (TRUE or FALSE)
  53. #if (CARD_IS_BUS_MASTER)
  54. # define CARD_MAP_REGISTERS_NEEDED NUM_DEV_PER_ADAP
  55. // TODO - How many map registers needed to transmit data to card.
  56. #endif
  57. //#define CARD_REQUEST_ISR TRUE
  58. // TODO - How do you want to handle interrupts from the card?
  59. // TRUE if you want to always use MiniportISR().
  60. // FALSE if you want to use MiniportDisable() and MiniportEnable().
  61. // Undefined if your card does not generate interrupts.
  62. #if defined(CARD_REQUEST_ISR)
  63. #define CARD_INTERRUPT_SHARED TRUE
  64. // TODO - Is your interrupt shared? (TRUE or FALSE).
  65. #define CARD_INTERRUPT_MODE NdisInterruptLevelSensitive
  66. // TODO - Is your interrupt latched or level sensitve?
  67. #endif // defined(CARD_REQUEST_ISR)
  68. /*
  69. // Maximum packet size allowed by the adapter -- must be restricted to
  70. // 1500 bytes at this point, and must also allow for frames at least 32
  71. // bytes longer.
  72. */
  73. #define NDISWAN_EXTRA_SIZE 32
  74. #define CARD_MIN_PACKET_SIZE ( 480 + NDISWAN_EXTRA_SIZE)
  75. #define CARD_MAX_PACKET_SIZE (2016 + NDISWAN_EXTRA_SIZE)
  76. #define CARD_DEFAULT_PACKET_SIZE (1504 + NDISWAN_EXTRA_SIZE)
  77. /*
  78. // The WAN miniport must indicate the entire packet when it is received.
  79. */
  80. #define CARD_MAX_LOOKAHEAD (pAdapter->pCard->BufferSize)
  81. /*
  82. // Number of digits allowed in a phone number (not including spaces).
  83. */
  84. #define CARD_MAX_DIAL_DIGITS 32
  85. #define NULL_BUFFER_POOL ((NDIS_HANDLE) -1)
  86. /* @doc INTERNAL Card Card_h CARD_RESOURCES
  87. @struct CARD_RESOURCES |
  88. This structure contains the data associated with the hardware resources
  89. required to configure the NIC. These values are isolated from the rest
  90. of the <t CARD_OBJECT> because they depend on the underlying hardware.
  91. @comm
  92. The contents of this structure depends on compile time flags and should
  93. only include information about the resource actually used by the NIC.
  94. This structure is filled in by <f CardFindNIC> and is used to configure
  95. and allocate resources from NDIS when <f CardInitialize> is called.
  96. */
  97. typedef struct CARD_RESOURCES
  98. {
  99. NDIS_INTERFACE_TYPE BusInterfaceType; // @field
  100. // This value is used to tell NDIS what type of adapter this is.
  101. // This is usually the same as the registry parameter BusType, but
  102. // may be different in the case of a bridged adapter.
  103. BOOLEAN Master; // @field
  104. // This is TRUE if the adapter is capable of bus master transfers.
  105. // Use the <t CARD_IS_BUS_MASTER> defininition to set this value
  106. // so the other bus master values will be included if needed.
  107. // See <f NdisMAllocateMapRegisters> for more details on the bus
  108. // master parameters.
  109. #if (CARD_IS_BUS_MASTER)
  110. BOOLEAN Dma32BitAddresses; // @field
  111. // This is TRUE if the bus master device uses 32-bit addresses.
  112. // Almost always TRUE for today's devices.
  113. ULONG PhysicalMapRegistersNeeded; // @field
  114. // This should be set to the maximum number of outstanding DMA
  115. // transfers that can be active at one time. One for each physical
  116. // buffer segment.
  117. ULONG MaximumPhysicalMapping; // @field
  118. // This should be set to the maximum number of contigous bytes that
  119. // can make up a single DMA transfer.
  120. ULONG DmaChannel; // @field
  121. // This should only be set if your adapter is an ISA bus master and
  122. // requires the use of one of the host DMA channels.
  123. #endif // (CARD_IS_BUS_MASTER)
  124. #if defined(CARD_MIN_MEMORY_SIZE)
  125. ULONG MemoryLength; // @field
  126. // The number of bytes of memory the NIC has on board.
  127. // Use the <t CARD_MIN_MEMORY_SIZE> defininition to set the minimum value
  128. // so the other NIC based memory values will be included if needed.
  129. NDIS_PHYSICAL_ADDRESS MemoryPhysicalAddress; // @field
  130. // System physical address assigned to the NIC's on board memory.
  131. #endif // CARD_MIN_MEMORY_SIZE
  132. #if defined(CARD_MIN_IOPORT_SIZE)
  133. ULONG IoPortLength; // @field
  134. // The number of bytes of I/O ports the NIC has on board.
  135. // Use the <t CARD_MIN_IOPORT_SIZE> defininition to set the minimum value
  136. // so the other NIC based memory values will be included if needed.
  137. NDIS_PHYSICAL_ADDRESS IoPortPhysicalAddress; // @field
  138. // System physical address assigned to the NIC's on board I/O ports.
  139. #endif // CARD_MIN_IOPORT_SIZE
  140. #if defined(CARD_REQUEST_ISR)
  141. ULONG InterruptVector; // @field
  142. // System interrupt vector assigned to the NIC's interrupt request line.
  143. ULONG InterruptLevel; // @field
  144. // System interrupt level assigned to the NIC's interrupt request line.
  145. ULONG InterruptMode; // @field
  146. // Set this value to NdisInterruptLevelSensitive or NdisInterruptLatched.
  147. // Use the <t CARD_INTERRUPT_MODE> defininition to set this value.
  148. BOOLEAN InterruptShared; // @field
  149. // Set TRUE if you want to allow the NIC's <f InterruptVector> to be
  150. // shared with other drivers in the system.
  151. // Use the <t CARD_INTERRUPT_SHARED> defininition to set this value.
  152. #endif // defined(CARD_REQUEST_ISR)
  153. } CARD_RESOURCES;
  154. #if !defined(CARD_REQUEST_ISR)
  155. /* @doc INTERNAL Card Card_h CARD_EVENT_CODE
  156. @enum CARD_EVENT_CODE |
  157. This enumeration defines the events generated by the card.
  158. */
  159. typedef enum CARD_EVENT_CODE
  160. {
  161. CARD_EVENT_NULL, // @emem
  162. // Not used for anything.
  163. CARD_EVENT_RING, // @emem
  164. // Indicates that a call is incoming on the given BChannel.
  165. CARD_EVENT_CONNECT, // @emem
  166. // Indicates that a call is connected on the given BChannel.
  167. CARD_EVENT_DISCONNECT, // @emem
  168. // Indicates that a call is disconnected on the given BChannel.
  169. CARD_EVENT_RECEIVE, // @emem
  170. // Indicates that a packet is incoming on the given BChannel.
  171. CARD_EVENT_TRANSMIT_COMPLETE // @emem
  172. // Indicates that the transmit is complete on the given BChannel.
  173. } CARD_EVENT_CODE;
  174. /* @doc INTERNAL Card Card_h CARD_EVENT_OBJECT
  175. @struct CARD_EVENT_OBJECT |
  176. This structure is used to keep track of events passed between the
  177. callee and caller. Each <t CARD_OBJECT> keeps a list of these events.
  178. */
  179. typedef struct CARD_EVENT_OBJECT
  180. {
  181. LIST_ENTRY Queue; // @field
  182. // Used to place the buffer on one of the receive lists.
  183. CARD_EVENT_CODE ulEventCode; // @field
  184. // Reason for event notification.
  185. PVOID pSendingObject; // @field
  186. // Interface object that is notifying. See <t BCHANNEL_OBJECT> or
  187. // <t DCHANNEL_OBJECT>,
  188. PVOID pReceivingObject; // @field
  189. // Interface object that is notifying. See <t BCHANNEL_OBJECT> or
  190. // <t DCHANNEL_OBJECT>,
  191. PNDIS_PACKET pNdisPacket; // @field
  192. // A pointer to the associated NDIS packet structure <t NDIS_PACKET>.
  193. } CARD_EVENT_OBJECT, *PCARD_EVENT_OBJECT;
  194. #endif // !defined(CARD_REQUEST_ISR)
  195. /* @doc INTERNAL Card Card_h CARD_OBJECT
  196. @struct CARD_OBJECT |
  197. This structure contains the data associated with the Network Interface
  198. Card (NIC). This object is responsible for managing all the hardware
  199. specific components of the NIC.
  200. @comm
  201. The <t MINIPORT_ADAPTER_OBJECT> manages the interface between NDIS and
  202. the driver, and then passes off the hardware specific interface to this
  203. object. There is one <t CARD_OBJECT> for each <t MINIPORT_ADAPTER_OBJECT>.
  204. One of these objects is created each time that our <f MiniportInitialize>
  205. routine is called. The NDIS wrapper calls this routine once for each of
  206. NIC installed and enabled in the system. In the case of a hot swappable
  207. NIC (e.g. PCMCIA) the adapter might come and go several times during a
  208. single Windows session.
  209. */
  210. typedef struct CARD_OBJECT
  211. {
  212. ULONG ObjectType; // @field
  213. // Four characters used to identify this type of object 'CARD'.
  214. ULONG ObjectID; // @field
  215. // Instance number used to identify a specific object instance.
  216. PMINIPORT_ADAPTER_OBJECT pAdapter; // @field
  217. // A pointer to the <t MINIPORT_ADAPTER_OBJECT> instance.
  218. CARD_RESOURCES ResourceInformation; // @field
  219. // Contains adapter specific resource requirements and settings.
  220. // See <t CARD_RESOURCES>.
  221. ULONG InterruptStatus; // @field
  222. // Bits indicating which interrupts need to be processed.
  223. NDIS_MINIPORT_INTERRUPT Interrupt; // @field
  224. // Miniport interrupt object used by NDIS.
  225. USHORT ReceiveBuffersPerLink; // @field
  226. // Maximum number of receive buffers per channel, registry parameter.
  227. USHORT TransmitBuffersPerLink; // @field
  228. // Maximum number of transmit buffers per channel, registry parameter.
  229. USHORT BufferSize; // @field
  230. // The maxmimum packet size. The NDISWAN spec says this must be 1500+32,
  231. // but everything seems to work okay if it is set smaller.
  232. ULONG NumChannels; // @field
  233. // Number of communication channels configured on the NIC.
  234. ULONG NumPorts; // @field
  235. // Number of <t PORT_OBJECT>'s allocated in <p pPortArray>.
  236. PPORT_OBJECT * pPortArray; // @field
  237. // An array of <t PORT_OBJECT>'s created by <f PortCreate>.
  238. // One entry for each port on NIC.
  239. #if defined(PCI_BUS)
  240. ULONG PciSlotNumber; // @field
  241. // PCI slot number for this adapter (FunctionNumber * 32) + DeviceNumber.
  242. #endif // PCI_BUS
  243. #if defined(CARD_MIN_MEMORY_SIZE)
  244. PCHAR pMemoryVirtualAddress; // @field
  245. // Virtual adress of NIC memory area.
  246. #endif // CARD_MIN_MEMORY_SIZE
  247. #if defined(CARD_MIN_IOPORT_SIZE)
  248. PCHAR pIoPortVirtualAddress; // @field
  249. // Virtual adress of NIC I/O port area.
  250. #endif // CARD_MIN_IOPORT_SIZE
  251. #if (CARD_IS_BUS_MASTER)
  252. ULONG MapRegisterIndex; // @field
  253. // Next map register index to be used for DMA transfer.
  254. long MapRegistersInUse; // @field
  255. // Number of map registers currently in use.
  256. #endif // (CARD_IS_BUS_MASTER)
  257. NDIS_HANDLE PacketPoolHandle; // @field
  258. // Internal message packet pool.
  259. NDIS_HANDLE BufferPoolHandle; // @field
  260. // Internal message buffer pool.
  261. PUCHAR MessagesVirtualAddress; // @field
  262. // Pointer to the message buffer area used for incoming packets.
  263. LIST_ENTRY MessageBufferList; // @field
  264. // List of available message buffers.
  265. NDIS_SPIN_LOCK MessageBufferLock; // @field
  266. // Spin lock used to protect <p MessageBufferList>.
  267. ULONG NumMessageBuffers; // @field
  268. // Number of message buffers to allocate for <p MessageBufferList>.
  269. ULONG TODO; // @field
  270. // Add your data members here.
  271. ULONG NumDChannels; // @field
  272. // The sample driver uses this registry value to determine the number
  273. // of ports to simulate.
  274. #if defined(SAMPLE_DRIVER)
  275. LIST_ENTRY EventList; // @field
  276. // Events waiting to be processed. See <t CARD_EVENT_OBJECT>.
  277. # define MAX_EVENTS 32
  278. CARD_EVENT_OBJECT EventArray[MAX_EVENTS]; // @field
  279. // Card event allocation array.
  280. ULONG NextEvent; // @field
  281. // Index into EventArray.
  282. #endif // SAMPLE_DRIVER
  283. } CARD_OBJECT;
  284. #define GET_ADAPTER_FROM_CARD(pCard) (pCard->pAdapter)
  285. #define GET_QUEUE_FROM_PACKET(pNdisPacket)\
  286. ((PLIST_ENTRY) pNdisPacket->MiniportReservedEx)
  287. #define GET_PACKET_FROM_QUEUE(pList)\
  288. CONTAINING_RECORD(pList, NDIS_PACKET, MiniportReservedEx)
  289. /*
  290. Object Interface Prototypes
  291. */
  292. NDIS_STATUS CardCreate(
  293. OUT PCARD_OBJECT * ppCard,
  294. IN PMINIPORT_ADAPTER_OBJECT pAdapter
  295. );
  296. void CardDestroy(
  297. IN PCARD_OBJECT pCard
  298. );
  299. NDIS_STATUS CardInitialize(
  300. IN PCARD_OBJECT pCard
  301. );
  302. ULONG CardNumChannels(
  303. IN PCARD_OBJECT pCard
  304. );
  305. ULONG CardNumPorts(
  306. IN PCARD_OBJECT pCard
  307. );
  308. void CardInterruptHandler(
  309. IN PCARD_OBJECT pCard
  310. );
  311. BOOLEAN CardTransmitPacket(
  312. IN PCARD_OBJECT pCard,
  313. IN PBCHANNEL_OBJECT pBChannel,
  314. IN PNDIS_PACKET pNdisPacket
  315. );
  316. USHORT CardCleanPhoneNumber(
  317. OUT PUCHAR Dst,
  318. IN PUSHORT Src,
  319. IN USHORT Length
  320. );
  321. NDIS_STATUS CardReset(
  322. IN PCARD_OBJECT pCard
  323. );
  324. #if defined(SAMPLE_DRIVER)
  325. PBCHANNEL_OBJECT GET_BCHANNEL_FROM_PHONE_NUMBER(
  326. IN PUCHAR pDialString
  327. );
  328. VOID CardNotifyEvent(
  329. IN PCARD_OBJECT pCard,
  330. IN PCARD_EVENT_OBJECT pEvent
  331. );
  332. PCARD_EVENT_OBJECT CardEventAllocate(
  333. IN PCARD_OBJECT pCard
  334. );
  335. VOID CardEventRelease(
  336. IN PCARD_OBJECT pCard,
  337. IN PCARD_EVENT_OBJECT pEvent
  338. );
  339. #endif // SAMPLE_DRIVER
  340. #endif // _CARD_H