1 /* 2 * RxBuf.c 3 * 4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name Texas Instruments nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 35 /** \file buf.c 36 * \brief Linux buf implementation. 37 * 38 * \see 39 */ 40 41 #include "tidef.h" 42 #include "RxBuf_linux.h" 43 #include <linux/netdevice.h> 44 /*--------------------------------------------------------------------------------------*/ 45 /* 46 * Allocate BUF Rx packets. 47 * Add 16 bytes before the data buffer for WSPI overhead! 48 */ 49 void *RxBufAlloc(TI_HANDLE hOs, TI_UINT32 len,PacketClassTag_e ePacketClassTag) 50 { 51 TI_UINT32 alloc_len = len + WSPI_PAD_BYTES + PAYLOAD_ALIGN_PAD_BYTES + RX_HEAD_LEN_ALIGNED; 52 struct sk_buff *skb; 53 rx_head_t *rx_head; 54 gfp_t flags = (in_atomic()) ? GFP_ATOMIC : GFP_KERNEL; 55 56 skb = alloc_skb(alloc_len, flags); 57 if (!skb) 58 { 59 return NULL; 60 } 61 rx_head = (rx_head_t *)skb->head; 62 rx_head->skb = skb; 63 skb_reserve(skb, RX_HEAD_LEN_ALIGNED + WSPI_PAD_BYTES); 64 /* 65 printk("-->> RxBufAlloc(len=%d) skb=0x%x skb->data=0x%x skb->head=0x%x skb->len=%d\n", 66 (int)len, (int)skb, (int)skb->data, (int)skb->head, (int)skb->len); 67 */ 68 return skb->data; 69 70 } 71 72 /*--------------------------------------------------------------------------------------*/ 73 74 inline void RxBufFree(TI_HANDLE hOs, void *pBuf) 75 { 76 unsigned char *pdata = (unsigned char *)((TI_UINT32)pBuf & ~(TI_UINT32)0x3); 77 rx_head_t *rx_head = (rx_head_t *)(pdata - WSPI_PAD_BYTES - RX_HEAD_LEN_ALIGNED); 78 struct sk_buff *skb = rx_head->skb; 79 80 #ifdef TI_DBG 81 if ((TI_UINT32)pBuf & 0x3) 82 { 83 if ((TI_UINT32)pBuf - (TI_UINT32)skb->data != 2) 84 { 85 printk("RxBufFree() address error skb=0x%x skb->data=0x%x pPacket=0x%x !!!\n",(int)skb, (int)skb->data, (int)pBuf); 86 } 87 } 88 else 89 { 90 if ((TI_UINT32)skb->data != (TI_UINT32)pBuf) 91 { 92 printk("RxBufFree() address error skb=0x%x skb->data=0x%x pPacket=0x%x !!!\n",(int)skb, (int)skb->data, (int)pBuf); 93 } 94 } 95 #endif 96 /* 97 printk("-->> RxBufFree() skb=0x%x skb->data=0x%x skb->head=0x%x skb->len=%d\n", 98 (int)skb, (int)skb->data, (int)skb->head, (int)skb->len); 99 */ 100 dev_kfree_skb(skb); 101 } 102