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 */
RxBufAlloc(TI_HANDLE hOs,TI_UINT32 len,PacketClassTag_e ePacketClassTag)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
55 skb = alloc_skb(alloc_len, GFP_ATOMIC);
56 if (!skb)
57 return NULL;
58 rx_head = (rx_head_t *)skb->head;
59 rx_head->skb = skb;
60 skb_reserve(skb, RX_HEAD_LEN_ALIGNED + WSPI_PAD_BYTES);
61 /*
62 printk("-->> RxBufAlloc(len=%d) skb=0x%x skb->data=0x%x skb->head=0x%x skb->len=%d\n",
63 (int)len, (int)skb, (int)skb->data, (int)skb->head, (int)skb->len);
64 */
65 return skb->data;
66
67 }
68
69 /*--------------------------------------------------------------------------------------*/
70
RxBufFree(TI_HANDLE hOs,void * pBuf)71 inline void RxBufFree(TI_HANDLE hOs, void *pBuf)
72 {
73 unsigned char *pdata = (unsigned char *)((TI_UINT32)pBuf & ~(TI_UINT32)0x3);
74 rx_head_t *rx_head = (rx_head_t *)(pdata - WSPI_PAD_BYTES - RX_HEAD_LEN_ALIGNED);
75 struct sk_buff *skb = rx_head->skb;
76
77 #ifdef TI_DBG
78 if ((TI_UINT32)pBuf & 0x3)
79 {
80 if ((TI_UINT32)pBuf - (TI_UINT32)skb->data != 2)
81 {
82 printk("RxBufFree() address error skb=0x%x skb->data=0x%x pPacket=0x%x !!!\n",(int)skb, (int)skb->data, (int)pBuf);
83 }
84 }
85 else
86 {
87 if ((TI_UINT32)skb->data != (TI_UINT32)pBuf)
88 {
89 printk("RxBufFree() address error skb=0x%x skb->data=0x%x pPacket=0x%x !!!\n",(int)skb, (int)skb->data, (int)pBuf);
90 }
91 }
92 #endif
93 /*
94 printk("-->> RxBufFree() skb=0x%x skb->data=0x%x skb->head=0x%x skb->len=%d\n",
95 (int)skb, (int)skb->data, (int)skb->head, (int)skb->len);
96 */
97 dev_kfree_skb(skb);
98 }
99