1981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
2981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * RxBuf.c
3981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
4981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.
5981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * All rights reserved.
6981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
7981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Redistribution and use in source and binary forms, with or without
8981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * modification, are permitted provided that the following conditions
9981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * are met:
10981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
11981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions of source code must retain the above copyright
12981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer.
13981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Redistributions in binary form must reproduce the above copyright
14981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    notice, this list of conditions and the following disclaimer in
15981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    the documentation and/or other materials provided with the
16981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    distribution.
17981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  * Neither the name Texas Instruments nor the names of its
18981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    contributors may be used to endorse or promote products derived
19981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *    from this software without specific prior written permission.
20981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
21981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
33981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
34981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
35981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/** \file  buf.c
36981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  \brief Linux buf implementation.
37981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *
38981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt *  \see
39981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
40981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
41981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "tidef.h"
42981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include "RxBuf_linux.h"
43981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#include <linux/netdevice.h>
44981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*--------------------------------------------------------------------------------------*/
45981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
46981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Allocate BUF Rx packets.
47981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt * Add 16 bytes before the data buffer for WSPI overhead!
48981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt */
4977a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidtvoid *RxBufAlloc(TI_HANDLE hOs, TI_UINT32 len,PacketClassTag_e ePacketClassTag)
50981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
5177a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	TI_UINT32 alloc_len = len + WSPI_PAD_BYTES + PAYLOAD_ALIGN_PAD_BYTES + RX_HEAD_LEN_ALIGNED;
5277a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	struct sk_buff *skb;
5377a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	rx_head_t *rx_head;
54981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
5577a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	skb = alloc_skb(alloc_len, GFP_ATOMIC);
5677a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	if (!skb)
5777a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt		return NULL;
5877a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	rx_head = (rx_head_t *)skb->head;
59981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	rx_head->skb = skb;
6077a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	skb_reserve(skb, RX_HEAD_LEN_ALIGNED + WSPI_PAD_BYTES);
61981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
62981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	printk("-->> RxBufAlloc(len=%d)  skb=0x%x skb->data=0x%x skb->head=0x%x skb->len=%d\n",
63981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		   (int)len, (int)skb, (int)skb->data, (int)skb->head, (int)skb->len);
64981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/
65981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	return skb->data;
66981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
67981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
68981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
69981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*--------------------------------------------------------------------------------------*/
70981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
7177a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidtinline void RxBufFree(TI_HANDLE hOs, void *pBuf)
72981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt{
7377a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	unsigned char  *pdata   = (unsigned char *)((TI_UINT32)pBuf & ~(TI_UINT32)0x3);
74981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	rx_head_t      *rx_head = (rx_head_t *)(pdata -  WSPI_PAD_BYTES - RX_HEAD_LEN_ALIGNED);
75981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	struct sk_buff *skb     = rx_head->skb;
76981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt
77981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#ifdef TI_DBG
7877a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	if ((TI_UINT32)pBuf & 0x3)
7977a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	{
8077a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt		if ((TI_UINT32)pBuf - (TI_UINT32)skb->data != 2)
8177a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt		{
8277a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt			printk("RxBufFree() address error skb=0x%x skb->data=0x%x pPacket=0x%x !!!\n",(int)skb, (int)skb->data, (int)pBuf);
8377a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt		}
8477a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	}
8577a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	else
8677a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	{
8777a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt		if ((TI_UINT32)skb->data != (TI_UINT32)pBuf)
8877a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt		{
8977a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt			printk("RxBufFree() address error skb=0x%x skb->data=0x%x pPacket=0x%x !!!\n",(int)skb, (int)skb->data, (int)pBuf);
9077a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt		}
9177a78b11a0b8e7c1a5b1625e0fddd39ef3a9e224Dmitry Shmidt	}
92981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt#endif
93981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt/*
94981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	printk("-->> RxBufFree()  skb=0x%x skb->data=0x%x skb->head=0x%x skb->len=%d\n",
95981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt		   (int)skb, (int)skb->data, (int)skb->head, (int)skb->len);
96981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt*/
97981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt	dev_kfree_skb(skb);
98981801b95b81e6d1c7a2085967406e86af0f08fcDmitry Shmidt}
99