#ifndef PHSTBNETDEV_LINUX_INTERNAL_H    /* Multi-include protection.   <FILENAME>_H */
#define PHSTBNETDEV_LINUX_INTERNAL_H

/*****************************************************************************/
/* Copyright (c) 2008 NXP B.V.                                               */
/*                                                                           */
/* This program is free software; you can redistribute it and/or modify      */
/* it under the terms of the GNU General Public License as published by      */
/* the Free Software Foundation, using version 2 of the License.             */
/*                                                                           */
/* This program is distributed in the hope that it will be useful,           */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the              */
/* GNU General Public License for more details.                              */
/*                                                                           */
/* You should have received a copy of the GNU General Public License         */
/* along with this program; if not, write to the Free Software               */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307       */
/* USA.                                                                      */
/*                                                                           */
/*****************************************************************************/
/**
    @file   phStbNetDev_Linux_Internal.h
    @brief  Linux internal header file for this component.

@b  Component:  phStbNetDev

*//*

Rev Date        Author      Comments
--------------------------------------------------------------------------------
  1 20070710   batelaan    Initial
  2 20070919   batelaan    Portability fix.
  3 20070925   batelaan    Further portability improvement.
3.1.1 20080422 batelaan    Update file header
  4 20080407   neill       Use spin_[un]lock rather than spin_[un]lock_bh
  4 20080417   batelaan    Add PH_STBNETDEV_POOL_LOCAL_LOCK_CHECK
  5 20080419   batelaan    Use spin_[un]lock, to lock correctly.
  6 20080423   batelaan    Merge 3.1.1
--------------------------------------------------------------------------------
    For consistency and standardisation retain the Section Separators.
*/

/*******************
* INCLUDE FILES    *
********************/

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/errno.h>

#include <phStbNetDev_Mailbox.h>
#include <linux/init.h>
#include <linux/moduleparam.h>

#include <linux/sched.h>
#include <linux/kernel.h> /* printk() */
#include <linux/slab.h> /* kmalloc() */
#include <linux/types.h>  /* size_t */
#include <linux/interrupt.h>
#include <asm/io.h>
#include <linux/cache.h> /* L1_CACHE_ALIGN */
#include <linux/kthread.h>

#include <linux/in.h>
#include <linux/netdevice.h>   /* struct device, and other headers */
#include <linux/etherdevice.h> /* eth_type_trans */
#include <linux/ip.h>          /* struct iphdr */
#include <linux/tcp.h>         /* struct tcphdr */
#include <linux/skbuff.h>


/**************************************************************************
* EXPORTED MACROS                          PH_STBTEMPLATE_<_WORD>+        *
***************************************************************************/

#define ERRPREFIX KERN_ERR "**ERROR: "
/* If defined then we check if the pool local lock macros work.
    @see PH_STBNETDEV_POOL_LOCAL_LOCK PH_STBNETDEV_POOL_LOCAL_UNLOCK */
#define PH_STBNETDEV_POOL_LOCAL_LOCK_CHECK

#ifdef PH_STBNETDEV_POOL_LOCAL_LOCK_CHECK
extern int gphStbNetDev_LocalLockFlag;
#define PH_STBNETDEV_POOL_LOCAL_LOCK_ENTRY_CHECK do { \
    if (gphStbNetDev_LocalLockFlag++ != 0) { \
        MSG_PRINT((KERN_ERR "StbNetDev: entry lockFlag=%d\n", gphStbNetDev_LocalLockFlag)); \
    } \
} while (0)
#define PH_STBNETDEV_POOL_LOCAL_LOCK_EXIT_CHECK do { \
    if (gphStbNetDev_LocalLockFlag-- != 1) { \
        MSG_PRINT((KERN_ERR "StbNetDev: exit lockFlag=%d\n", gphStbNetDev_LocalLockFlag)); \
    } \
} while (0)
#else
#define PH_STBNETDEV_POOL_LOCAL_LOCK_ENTRY_CHECK do { \
} while (0)
#define PH_STBNETDEV_POOL_LOCAL_LOCK_EXIT_CHECK do { \
} while (0)
#endif /* PH_STBNETDEV_POOL_LOCAL_LOCK_CHECK */

#define PH_STBNETDEV_POOL_LOCAL_LOCK   do { \
    spin_lock_bh(&gphStbNetDev_PoolLock); \
    PH_STBNETDEV_POOL_LOCAL_LOCK_ENTRY_CHECK; \
} while (0)

#define PH_STBNETDEV_POOL_LOCAL_UNLOCK   do { \
    PH_STBNETDEV_POOL_LOCAL_LOCK_EXIT_CHECK; \
    spin_unlock_bh(&gphStbNetDev_PoolLock); \
} while (0)

/** True if device transmit queue is (temporarily) stopped.
    This may occur because we run out of free packets in the pool
    to use for transmission.
    @param dev IN A ::pphStbNetDev_Device_t
    @return Any boolean type.
    @see phStbNetDev_GetFreeBuffer()
    @see phStbNetDev_PutFreeBuffer()
*/
#define PH_STBNETDEV_DEVICE_QUEUE_STOPPED(dev) netif_queue_stopped(dev)

/** Stop the device transmit queue (temporarily).
    This will be called when we run out of free packets in the pool
    to use for transmission.
    Opposite of #PH_STBNETDEV_DEVICE_WAKE_QUEUE.
    @param dev IN A ::pphStbNetDev_Device_t
    @return Ignored.
    @see phStbNetDev_GetFreeBuffer()
*/
#define PH_STBNETDEV_DEVICE_STOP_QUEUE(dev) netif_stop_queue(dev)

/** Wake the device transmit queue.
    This will be called when we again have one or more free packets in the pool
    to use for transmission.
    Opposite of #PH_STBNETDEV_DEVICE_STOP_QUEUE.
    @param dev IN A ::pphStbNetDev_Device_t
    @return Ignored.
    @see phStbNetDev_PutFreeBuffer()
*/
#define PH_STBNETDEV_DEVICE_WAKE_QUEUE(dev) netif_wake_queue(dev)

/*********************************************************************
* EXPORTED TYPEDEFS                      [p]phStbTemplate_<Word>+_t  *
**********************************************************************/

/** Handle to the abstracted (opaque) network device instance. */
typedef struct net_device * pphStbNetDev_Device_t;

/**************************************************************************
* EXPORTED DATA                     g[k|p|kp|pk|kpk]phStbTemplate_<Word>+ *
***************************************************************************/

/** Lock to control access by current CPU to the pool.
    @see PH_STBNETDEV_POOL_LOCAL_LOCK
    @see PH_STBNETDEV_POOL_LOCAL_UNLOCK
*/
extern spinlock_t gphStbNetDev_PoolLock;

/****************************************************************************
* EXPORTED FUNCTION PROTOTYPES phStbTemplate[_<Word>+] *
*****************************************************************************/

#ifdef __cplusplus
extern "C"
{
#endif

/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

/******************************************************************************/
#ifdef __cplusplus
}
#endif

#endif /* PHSTBNETDEV_LINUX_INTERNAL_H      Do not add any thing below this line */
