📄 ga.c
字号:
pMem = kmalloc (pAddrStruct->BufSize + Alignment -1, GFP_KERNEL | GFP_DMA | GFP_ATOMIC); if(pMem == NULL) {#ifdef FAILURE_MESSAGES printk("\nAllocation of contiguous memory failed");#endif return FAILURE; } NsmZeroMemory(pMem, pAddrStruct->BufSize + Alignment - 1); AlignedMem = ((UINT) pMem) + (Alignment -1); pAddrStruct->pCookie = pMem; AlignedMem &= ~(Alignment -1); pAddrStruct->VirtAddr = (UCHAR *)AlignedMem;#ifdef ASSERTION if(AlignedMem & (Alignment-1)) NsmDbgMsg1("ASSERTION FAILED: In NsmMallocContiguous, the allocated memory is not %d byte aligned\n",Alignment);#endif pAddrStruct->PhysAddr = (UCHAR *)virt_to_bus ((VOID *)AlignedMem); return SUCCESS; }/*******************************************************************************f** Name: NsmFreeContiguous** Description: This is called by HSM to free a contiguous chunk of memory ** Parameters: pNsm: Pointer to the NsmContext** pAddrstruct: Pointer to the Addrstruct structure, where the * virtual and physical addresses are put** Cached: Cached/Non-Cached memory** Return Value: None**f*******************************************************************************/ void NsmFreeContiguous(VOID *pNsm, AddrStruct *pAddrStruct, UINT Cached){ kfree(pAddrStruct->pCookie); pAddrStruct->VirtAddr = 0; pAddrStruct->PhysAddr = 0; pAddrStruct->pCookie = 0;}/*******************************************************************************f** Name: NsmAllocatePacket** Description: This is called by HSM to allocate an sk_buff with a data * buffer associated with it.** Parameters: pNsm: Pointer to the NsmContext structure** pRcb: Pointer to the HsmRCB, to which the allocated * packet is to be linked to** pAddr: Pointer to the Addrstruct structure, where the * virtual and physical addresses are put** Return Value: SUCCESS or FAILURE**f*******************************************************************************/UCHAR NsmAllocatePacket(VOID *pNsm, struct _HsmRCB *pRcb, AddrStruct *pAddr){ struct sk_buff *skb; skb = alloc_skb(pAddr->BufSize, GFP_KERNEL | GFP_DMA | GFP_ATOMIC); if(skb == NULL) {#ifdef FAILURE_MESSAGES printk("Allocation of the sk_buff failed\n");#endif return FAILURE; } skb->dev = ((NsmContext *)pNsm)->dev; NsmZeroMemory(skb->data, pAddr->BufSize); pAddr->pCookie = (VOID *)skb; pAddr->PhysAddr = (UCHAR *)virt_to_bus(skb->data); pRcb->pDataBuf = pAddr->VirtAddr = skb->data;#ifdef ASSERTION if(((UINT)skb->data) & 7) NsmDbgMsg("ASSERTION FAILED : In NsmAllocatePacket, the allocated memory is not 8 byte aligned\n");#endif pRcb->pOsCtrlBlk = (VOID *)skb; return SUCCESS;}/*******************************************************************************f** Name: NsmDeAllocatePacket** Description: This is called by HSM to deallocate the sk_buff structure * and consequently the data buffer associated with it, within* an HsmRCB** Parameters: pNsm: Pointer to the NsmContext** Addr: Pointer to the AddrStruct** pRcb: Pointer to the HsmRCB, to which the allocated * packet is to be linked to** Return Value: None**f*******************************************************************************/void NsmDeAllocatePacket(VOID *pNsm, AddrStruct *Addr, HsmRCB *pRcb){ kfree_skb(pRcb->pOsCtrlBlk); pRcb->pOsCtrlBlk = NULL; pRcb->pDataBuf = NULL;}/* Utility routines *//*******************************************************************************f** Name: CreatePacketstruct** Description: This creates a packet struct and encapsulates the data in * the sk_buff in to the Pktstruct** Parameters: skb: Pointer to the sk_buff, from which the data to be sent * down is taken to be encapsulated in to the Pktstruct data * structure. * * pPkt: Pointer to the Pktstruct structure, into which the * data to be sent down is put** Return Value: None**f*******************************************************************************/void CreatePacketStruct(struct sk_buff *skb, PktStruct *pPkt){ /* Set the pointer to the physical memory for this fragment in the packet structure */ pPkt->PktArray[0].FragArray[0].pFrag = (UCHAR *)virt_to_bus(skb->data); /* Update the length field of the fragment */ pPkt->PktArray[0].FragArray[0].FragLen = skb->len; /* Put the number of fragments within the packet in the NumOfFrags field within the packet struct */ pPkt->PktArray[0].NumFrags = 1; /* Make the pOsCtrlBlk point to the skb */ pPkt->PktArray[0].pOSCtrlBlk = skb; pPkt->PktArray[0].ChkSum = 0; pPkt->PktCount = 1;}/*******************************************************************************f** Name: CreatePacketInfo** Description: This creates a packet info structure and encapsulates * the data in the sk_buff in to the PktInfo structure** Parameters: skb: Pointer to the sk_buff, from which the data to be sent * down is taken to be encapsulated in to the PktInfo data * structure. * * pPkt: Pointer to the PktInfo structure, into which the * data to be sent down is put** Return Value: None**f*******************************************************************************/VOID CreatePacketInfo(struct sk_buff *skb, PktInfo *pPkt){ /* Set the pointer to the physical memory for this fragment in the packet structure */ pPkt->FragArray[0].pFrag = (UCHAR *)virt_to_phys(skb->data); /* Update the length field of the fragment */ pPkt->FragArray[0].FragLen = skb->len; /* Put the number of fragments within the packet in the NumOfFrags field within the packet struct */ pPkt->NumFrags = 1; /* Make the pOsCtrlBlk point to the skb */ pPkt->pOSCtrlBlk = skb; pPkt->ChkSum = 0; }/*******************************************************************************f** Name: IsBrdCastOrMultiCast** Description: This is used to check whether a particular address is a * broadcast or multicast address address** Parameters: dev: Pointer to the device structure** DestMac: Pointer to the destination MAC address** Return Value: SUCCESS or FAILURE**f*******************************************************************************/UCHAR IsBrdCastOrMultiCast(struct device *dev, UCHAR *DestMac){ struct dev_mc_list *mc_list; /* Check for broadcast address */ if ((DestMac[0]==0xff) && (DestMac[1]==0xff) && (DestMac[2]==0xff) && (DestMac[3]==0xff) && (DestMac[4]==0xff) && (DestMac[5]==0xff)) return SUCCESS; /* Check for multicast address */ if(DestMac[0]==0x01) { mc_list = dev->mc_list; while(mc_list) { if(CMP_ETH_ADDR(mc_list->dmi_addr, (UCHAR *)DestMac, MAC_ADDR_LEN)) return SUCCESS; mc_list = mc_list->next; } return FAILURE; } else return FAILURE; }/*******************************************************************************f** Name: ChangeMtu** Description: This changes the MTU size in the device structure to the new * value specified by NewMtu** Parameters: dev: Pointer to the device structure** NewMtu: The new MTU size which needs to be set in the device * structure** Return Value: EINVAL or OK**f*******************************************************************************/STATIC int ChangeMtu(struct device *dev, int NewMtu){ /* Check for the accepatable range of MTU sizes */ if( (NewMtu < 68) || (NewMtu > 65280) ) return -EINVAL; /* Set the mtu field in the device structure to the NewMtu if it is falling within the acceptable range */ dev->mtu = NewMtu; return (0);} /*******************************************************************************f** Name: CMP_ETH_ADDR** Description: This is used to compare two ethernet ( MAC ) addresses* * Parameters: SrcMac: Address of source ** DstMac: Address of destination * * Len: Number of bytes to be compared* * Return Value: 0 or 1 **f*******************************************************************************/inline UCHAR CMP_ETH_ADDR(UCHAR *SrcMac,UCHAR *DestMac, UINT Len){ UINT i = 0; while(i<Len) { if(DestMac[i]!=SrcMac[i]) break; i++; } if(i == Len) return 1; else return 0;} /*******************************************************************************f** Name: NsmCreateLock** Description: Allocates the data structure for a lock and intialises it** Parameters: None** Return Value: Pointer to the LockId**f*******************************************************************************/inline VOID *NsmCreateLock(){ VOID *LockId = kmalloc(sizeof(spinlock_t), GFP_KERNEL); if(LockId == NULL) return NULL; spin_lock_init((spinlock_t *)LockId); return LockId;}/*******************************************************************************f** Name: NsmAcquireLock** Description: Acquires a lock which has been initialized early on** Parameters: pAdapter: Pointer to the AdapterContext ** LockId: Pointer to the data structure allocated for the lock ** Return Value: None**f*******************************************************************************/inline VOID NsmAcquireLock(AdapterContext *pAdapter,VOID *LockId){ spin_lock((spinlock_t *)LockId);}/*******************************************************************************f** Name: NsmReleaseLock** Description: Release a lock which has been acquired early on** Parameters: pAdapter: Pointer to the AdapterContext ** LockId: Pointer to the data structure allocated for the lock ** Return Value: None**f*******************************************************************************/inline VOID NsmReleaseLock(AdapterContext *pAdapter, VOID *LockId){ spin_unlock((spinlock_t *)LockId);}/*******************************************************************************f** Name: NsmMalloc** Description: Allocates kernel memory of the specified size** Parameters: size: Size of the memory that needs to be allocated** Return Value: Pointer to the memory that is allocated**f*******************************************************************************/inline VOID *NsmMalloc(UINT size){ VOID *ptr = kmalloc(size, GFP_KERNEL); if(ptr == NULL) return NULL; NsmZeroMemory(ptr,size); return ptr;}/*******************************************************************************f** Name: PrintContents** Description: Prints the contents of kernel memory locations in the range* specified ** Parameters: start: Start address ** len: Length of the range ** Return Value: None**f*******************************************************************************/inline VOID PrintContents(UCHAR *start, UINT len){ UCHAR *ptr = start; UINT i; printk("The contents of the location :\n"); for(i=0;i<len;i++) { printk(": %x :" ,*ptr); ptr++; }}/*void NsmIndicateLinkStatus(AdapterContext *pAdapter) { NsmContext *pNsm = (NsmContext *)(pAdapter->pNsmContext); if(!(pNsm->status & NSM_OPEN)) return; if((pAdapter)->AdapterStatus & LINK_UP) { printk("\nLINK_UP"); ((NsmContext *)((pAdapter)->pNsmContext))->dev->flags |= IFF_UP; } else { printk("\nLINK_DOWN"); ((NsmContext *)((pAdapter)->pNsmContext))->dev->flags &= ~IFF_UP; } }*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -