⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sw.h

📁 网络驱动开发
💻 H
📖 第 1 页 / 共 3 页
字号:
/*++

Copyright (c) 2000 Microsoft Corporation. All rights reserved.

   File:       sw.h
 
               Developed for Toshiba by Elisa Research Inc., CA
               http://www.elisaresearch.com
               (510) 770-4920


Abstract:

Author:

   A. Wang

Environment:

   Kernel mode

Revision History:

   09/23/96    kyleb       Added support for NdisAllocateMemoryWithTag
   01/07/97    awang       Initial of Toshiba ATM 155 Device Driver.
   02/10/97    awang       Moved RECV_SEG_INFO from sar.h

--*/

#ifndef __SW_H
#define __SW_H

#define ABS(x)         (((x) < 0) ? -(x) : (x))

//
//	Macros to read from the adapters memory.
//
#define TBATM155_READ_BUFFER_UCHAR(pDst, pSrc, Length)                     \
{                                                                          \
	UINT	_c;                                                             \
                                                                           \
	for (_c = 0; _c < (Length); _c++)                                       \
	{                                                                       \
		NdisReadRegisterUchar((PUCHAR)(pSrc) + _c, (PUCHAR)(pDst) + _c);    \
	}                                                                       \
}

//
//	This macro is used to convert big-endian to host format.
//
#define TBATM155_SWAP_USHORT(x) (USHORT)((((x) >> 8) & 0xFF)   |   \
                                   (((x) << 8) & 0xFF00))

#define TBATM155_SWAP_ULONG(x)  (ULONG)((((x) >> 24) & 0xFF)   |   \
                               (((x) >> 8) & 0xFF00)           |   \
                               (((x) << 8) & 0xFF0000)         |   \
                               (((x) << 24) & 0xFF000000))

// buffer size passed in NdisMQueryAdapterResources                            
// We should only need three adapter resources (IO, interrupt and memory),
// Some devices get extra resources, so have room for 10 resources 
#define ATM_RESOURCE_BUF_SIZE           (sizeof(NDIS_RESOURCE_LIST) + \
                                        (10 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR)))

//
//	Macros used to allocate and free memory.
//
#define ALLOCATE_MEMORY(_pStatus, _pAddress, _Length, _Tag)    \
{                                                              \
   *(_pStatus) = NdisAllocateMemoryWithTag(                    \
                   (PVOID *)(_pAddress),                       \
                   (UINT)(_Length),                            \
                   (ULONG)(_Tag));                             \
}

#define FREE_MEMORY(_Address, _Length)                         \
{                                                              \
   NdisFreeMemory((PVOID)(_Address), (UINT)(_Length), 0);      \
}

#define ZERO_MEMORY(_Address, _Length)                         \
{                                                              \
   NdisZeroMemory((_Address), (_Length));                      \
}

#define TBATM155_PROTOCOL_RESERVED	(sizeof(MEDIA_SPECIFIC_INFORMATION) + sizeof(ATM_AAL_OOB_INFO))

//
//	Contains allocation information.
//
typedef struct	_ALLOCATION_INFO
{
   PVOID                   VirtualAddress;
   NDIS_PHYSICAL_ADDRESS   PhysicalAddress;
   ULONG                   Size;
}
   ALLOCATION_INFO,
   *PALLOCATION_INFO;



//
//	The following is used to keep track of the receive buffers.
//
typedef struct _RECV_BUFFER_HEADER
{
   ULONG                       Signature;

   //
   //	These are the list pointers used to keep track of free
   //	receive buffers, or of a list of receive buffers that
   //	are being used to receive a packet.
   //
   struct _RECV_BUFFER_HEADER  *Next;
   struct _RECV_BUFFER_HEADER  *Prev;
   struct _RECV_BUFFER_HEADER  *Last;
   
   //
   //	Pointer to the pool this receive buffer came from.
   //
   struct _RECV_BUFFER_POOL    *Pool;
   
   //
   //	Flags that describe the state of the receive buffer.
   //
   ULONG                       Flags;
   
   //
   //	Used for cache coherency.
   //
   PNDIS_BUFFER                FlushBuffer;
   
   //
   //	Used to indicate data in an NDIS_PACKET.
   //
   PNDIS_BUFFER                NdisBuffer;
   
   //
   //	Packet that is associated with this buffer.
   //
   PNDIS_PACKET                Packet;
   
   //
   //	Pointer to the VC that this receive is destined for.
   //
   PVC_BLOCK                   pVc;
   
   //
   //	The posted tags information of this receive buffer.
   //
   USHORT                      TagPosted;

   //
   //	If this buffer was allocated from a pool then there is
   //	only allocation information that describes the aligned
   //	buffer to be used for the receive information.
   //	If the buffer was allocated individually then there is
   //	the aligned allocation information as well as the original
   //	allocation information which is to be used to free the
   //	receive buffer if necessary.
   //
   ALLOCATION_INFO             Alloc[1];
};


#define RECV_BUFFER_HEADER_SIG         0x30303030

//
//	Indices into the ALLOCATION_INFO array...
//
#define RECV_BUFFER_ALIGNED    0
#define RECV_BUFFER_ORIGINAL   1

//
//	This structure is used to keep track of transmit contexts
//
typedef struct _TRANSMIT_CONTEXT
{
   ULONG                       Signature;
   ULONG                       BufferSize;
   ULONG                       DmaAlignment;
   PVC_BLOCK                   pVc;
   PXMIT_SEG_INFO              pTransmitSegInfo;
}TRANSMIT_CONTEXT, *PTRANSMIT_CONTEXT;

#define XMIT_BUFFER_SIG           0x88888888

//
//	This structure is used to keep track of pools of receive
//	buffers.  Receive buffer pools are allocated on a per VC basis.
//	So a buffer pool allocated for VC x is never used for VC y. 
//
struct _RECV_BUFFER_POOL
{
   ULONG                       Signature;

   //
   //	Pointer to the next pool of receive buffers.
   //
   struct _RECV_BUFFER_POOL    *Next;

   //
   //	Back pointer to the owning receive buffer information structure.
   //
   struct _RECV_BUFFER_INFO    *RecvBufferInfo;

   //
   //	Count of buffers allocated to this pool.
   //	This is the same for the packets.
   //
   ULONG                       ReceiveBufferCount;

   //
   //	This is the size of the receive buffer that the adapter can use
   //	to receive into.
   //
   ULONG                       ReceiveBufferSize;

   //
   //	This is the allocated virtual, physical addresses and
   //	the allocated size of the pool.
   //
   ALLOCATION_INFO;

   //
   //	Size of the receive buffer's header.
   //
   ULONG                       ReceiveHeaderSize;
   
   //
   //	Handle for the flush buffers associated with the
   //	pool.
   //
   NDIS_HANDLE                 hFlushBufferPool;
   NDIS_HANDLE                 hNdisBufferPool;

   //
   //	NDIS wrapper handle to a packet pool.
   //
   NDIS_HANDLE                 hNdisPacketPool;

   //
   //	This is a list of buffers that are requested to be returned.
   //  This list is always to be NULL until the pool state is changed
   //  to fRECV_POOL_BEING_FREED.
   //	Once the BuffersFreed count has reached the total count then
   //	this pool can be freed (with consideration for the packets also).
   //	
   PRECV_BUFFER_HEADER         FreeBuffersHead;

   //
   //	Buffers free'd
   //
   ULONG                       BuffersFreed;

   //
   //	Flags describing the buffer pools state.
   //
   ULONG                       Flags;
};


#define RECV_BUFFER_POOL_SIG               0x20202020

//
//	Flag definitions for the receive buffer pool.
//
#define fRECV_POOL_BEING_FREED             0x00000001
#define fRECV_POOL_BLOCK_ALLOC             0x00000002
#define fRECV_POOL_ALLOCATING_BLOCK        0x00000004
#define fRECV_POOL_ALLOCATING_INDIVIDUAL   0x00000008

//
//	Macros used for accessing the receive pool flags
//
#define RECV_POOL_TEST_FLAG(x, f)          (((x)->Flags & (f)) == (f))
#define RECV_POOL_SET_FLAG(x, f)           ((x)->Flags |= (f))
#define RECV_POOL_CLEAR_FLAG(x, f)         ((x)->Flags &= ~(f))

//
//	This structure is used to keep track of multiple pools of receive
//	buffers, guard their access in the case of UBR VCs.
//	It is also used to manage a free list of buffers to be used in
//	the case of a service interrupt.
//
typedef struct _RECV_BUFFER_INFO
{
   ULONG                   Signature;
   
   NDIS_SPIN_LOCK          lock;

   //
   //	Flags for the receive buffer allocation.
   //
   ULONG                   Flags;

   //
   //	Pointer to the owning VC_BLOCK.  If this is NULL then it's
   //	the common UBR receive buffer information.
   //
   PVC_BLOCK               pVc;

   //
   //	This is the amount of information each receive buffer
   //	can hold.
   //
   ULONG                   RecvBufferSize;

   //
   //	Pointer to the list of buffer pools allocated.
   //
   PRECV_BUFFER_POOL       RecvPool;

   //
   //	This is the free list of buffers from all the available pools.
   //
   PRECV_BUFFER_HEADER     FreeBufferListHead;
   PRECV_BUFFER_HEADER     BufferListTail;

   //
   //	Count of available receive buffers in the free list.
   //
   ULONG					FreeReceiveBufferCount;
};

#define RECV_BUFFER_INFO_SIG           0x10101010

//							
//	Flag definitions for the RECV_BUFFER_INFO structure.
//
#define fRECV_INFO_COMPLETE_VC_ACTIVATION      0x00000001

//
//	Macros used for accessing the receive buffer flags
//
#define RECV_INFO_TEST_FLAG(x, f)      (((x)->Flags & (f)) == (f))
#define RECV_INFO_SET_FLAG(x, f)       ((x)->Flags |= (f))
#define RECV_INFO_CLEAR_FLAG(x, f)     ((x)->Flags &= ~(f))


//
// Define that what kind to slot type used in a VC.
//
#define RECV_SMALL_BUFFER      BIT(0)
#define RECV_BIG_BUFFER        BIT(1)


struct _RECV_SEG_INFO
{
   //
   //	Pointer to the owning adapter.
   //	
   PADAPTER_BLOCK			    pAdapter;
   
   //
   //	The size of the segment in ULONGs.
   //
   ULONG					    SegmentSize;
   
   //
   //	Pointer to the entry of Recv state table.
   //
   ULONG                       pEntryOfRecvState;

   TBATM155_RX_STATE_ENTRY     InitRecvState;

   //
   //	Queue of packets that are waiting for the receive complete
   //	interrupt.
   //
   RECV_BUFFER_QUEUE           SegCompleting;

   //
   //	This contains receive pools for buffers and packets.
   //
   PRECV_BUFFER_INFO		    pRecvBufferInfo;

   PRECV_BUFFER_QUEUE          FreeSmallBufQ;
   PRECV_BUFFER_QUEUE          FreeBigBufQ;

   NDIS_SPIN_LOCK			    lock;
};


//
// Number and size of allocated PadTrailer buffers;
//
#define TBATM155_MAX_PADTRAILER_BUFFERS    30


// **********************************************************************
// Allocation Map
//
// This structure holds the mapping parameters of a structure allocated
// in memory for transmission.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -