/****************************************************************************************
 *   dda_ti_dsl.h
 *   
 *   2003 (c) Texas Instruments Inc.
 *
 *   8/15/2006 MK      CQ10847: Fixed available_tx_bufs allocation for all channels.
 *   8/15/2006 MK      CQ10844: Added DDA_dsldk_proc_version proc entry to display DSLDK
 *                     version.
 *   9/21/2006 EP      CQ10932: Generated Doxygen-compliant DDC API.
 *   9/25/2006 AV      Added the OAM channel queue definitions.
 *   10/9/2006 AV      Added the separate tx and rx interrupt line definitions for data 
 *                     and OAM modes. Adding definitions for tasklet mode.
 *   02/14/2007 EP     Clean up psp trace.
****************************************************************************************/
#ifndef _DDA_ATM_H_
#define _DDA_ATM_H_

//AV_26
#include <linux/init.h>
#include <linux/module.h>
//bk DSP FW Location wird als parameter angegeben 
#include <linux/moduleparam.h>
extern char *firmware_load_file;
//end bk 
#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <linux/errno.h>
#include <linux/in.h>
#include <linux/ioport.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/atmdev.h>
#include <linux/time.h>
#include <linux/skbuff.h>
#include <linux/proc_fs.h>
#include <linux/ctype.h>
#include <asm/irq.h>            /* For NR_IRQS only. */
#include <asm/bitops.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/semaphore.h>
#include <asm/mips-boards/prom.h>
#include <ti_linux_porting.h>
#include <linux/vmalloc.h>
#include <linux/file.h>
#include <linux/sysctl.h>

//AV_26
#if 0
#ifdef CONFIG_MODVERSIONS
#include <linux/modversions.h>
#endif
#endif

#undef TIATM_INST_SUPP     /* Enable Instrumentation code. Disabled by default */

#ifdef TIATM_INST_SUPP
#include <linux/psp_trace.h>
#endif


#include "version.h"
#include "ddc_dsl_api.h"
#include "ddc_dsl_callback.h"

//AV_26 Changing for 8.1_B&F to use the new symbol
#ifdef CONFIG_MIPS_AVALANCHE_STATIC_SKB
#define TI_STATIC_ALLOCATIONS
/* Till we can figure out where this is exported. */
extern struct sk_buff *ti_alloc_skb(unsigned int size,int gfp_mask);
#endif



/* Start */
#ifndef INIT_USE_ONLY
#define INIT_USE_ONLY __init
#endif

/*** Definition ***/

#define DEV_DSLMOD       1
#define MAX_STR_SIZE     256
#define DSL_MOD_SIZE     256

#define ATM_REG_OK 1
#define ATM_REG_FAILED 0

#define UR8_DEF_OAM_RXQ  3
#define UR8_DEF_OAM_TXQ  3

/*** Data Structure ***/

/**
 *  \brief  DSL generic read/write parameters
 */
typedef struct dsl_read_write {
  int action;           /**< TBD */
  int offsetnum;        /**< TBD */
  int offset[8];        /**< TBD */
  unsigned int data;    /**< TBD */
} dsl_read_write_t;

/**
 * \
 */
typedef struct _DDA_atm_private
{
  struct _DDA_atm_private     *next;                /* next device */
  struct atm_dev              *dev;                 /* ATM device */
  struct net_device_stats     *stats;               /* Used to report Tx/Rx frames from ifconfig */
  #ifdef AR7_SAR
  int                         sar_irq;
  #endif
  #ifdef UR8_SAR
  int                         sar_tx_irq;
  int                         sar_rx_irq;
  int                         sar_oam_tx_irq;
  int                         sar_oam_rx_irq;
  #endif
  int                         dsl_irq;

  char*                       name;                 /* device name */
  char*                       proc_name;            /* board name under /proc/atm */
  atomic_t                    available_tx_bufs[MAX_DMA_CHAN + 1];    /* Available tx buffs */
  unsigned int                connection_cell_rate; /* cell rate */

  /* spin lock for netifqueue */
  spinlock_t                   netifqueueLock;
  int                          netifqueueLockFlag;
  int                          xmitStop; /* temp fix for SAR problem */
  int                          EnableQoS;
  DDC_DslPriv                  *dslPriv;
  unsigned int                 Oam_txq;
  unsigned int                 Oam_rxq;

#ifdef TI_DSL_TASKLET_MODE
  struct tasklet_struct tx_tasklet;     /**< Tasklet structure if processing packets in tasklets */
  struct tasklet_struct rx_tasklet;     /**< Tasklet structure if processing rx packets in tasklets */
#endif

} DDA_atm_private_t, Tn7AtmPrivate, DDA_DslPriv;

/**
 * TX flush struct
 */
typedef struct tx_flush {
  struct atm_vcc *vcc;
  int            queue;
  int            skip_num;
} tx_flush_t;

extern Tn7AtmPrivate *Local_priv;

/* Temporary fix till the Base PSP doesn't export the following in a header file. */
extern int avalanche_request_pacing(int irq_nr, unsigned int blk_num, unsigned int pace_val);

/* Check if the release.h is mapped into the include folder. */
#ifdef CONFIG_HAS_RELEASE_H_FILE
#include <linux/release.h>
#endif /* CONFIG_HAS_RELEASE_H_FILE */

/* LED support for 8.1 */
#ifdef BASE_PSP_8X
#define __NO__VOICE_PATCH__ /* Not required anymore. */

#if defined (CONFIG_MIPS_AVALANCHE_COLORED_LED)
#include <asm/mach-avalanche/generic/led_manager.h>

/* LED handles */
extern void *hnd_LED_0;

#define MOD_ADSL          1
#define DEF_ADSL_IDLE     1
#define DEF_ADSL_TRAINING 2
#define DEF_ADSL_SYNC     3
#define DEF_ADSL_ACTIVITY 4

#define LED_NUM_1 0
#define LED_NUM_2 1

/* Only one is supported at a time. */
#ifdef CONFIG_LED_MODULE
#undef CONFIG_LED_MODULE
#endif

#endif /*defined (CONFIG_MIPS_AVALANCHE_COLORED_LED)*/

#define TN7DSL_LED_ACTION(module_handle, module_name, state_id) led_manager_led_action(module_handle, state_id)

#endif /* BASE_PSP_8X */

/* Base PSP 7.4 support */
#if ((PSP_VERSION_MAJOR == 7) && (PSP_VERSION_MINOR == 4))
#define __NO__VOICE_PATCH__ /* Not required anymore. */

#if defined (CONFIG_MIPS_AVALANCHE_COLORED_LED)
#include <asm/avalanche/generic/led_manager.h>

/* LED handles */
extern void *hnd_LED_0;

#define MOD_ADSL          1
#define DEF_ADSL_IDLE     1
#define DEF_ADSL_TRAINING 2
#define DEF_ADSL_SYNC     3
#define DEF_ADSL_ACTIVITY 4

#define LED_NUM_1 0
#define LED_NUM_2 1

#endif /*defined (CONFIG_MIPS_AVALANCHE_COLORED_LED)*/

/* So as to not cause any confusion. */
#ifdef BASE_PSP_7X
#undef BASE_PSP_7X
#endif /*BASE_PSP_7X*/

#define TN7DSL_LED_ACTION(module_handle, module_name, state_id) led_manager_led_action(module_handle, state_id)

#endif /*((PSP_VERSION_MAJOR == 7) && (PSP_VERSION_MINOR == 4)) */

#ifdef CONFIG_LED_MODULE
#ifndef BASE_PSP_7X

#define MOD_ADSL            1
#define DEF_ADSL_IDLE       1
#define DEF_ADSL_TRAINING   2
#define DEF_ADSL_SYNC       3
#define DEF_ADSL_TXACTIVITY 6
#define DEF_ADSL_RXACTIVITY 7

#else
/* BASE_PSP_7X is defined */
#define MOD_ADSL 1
#define DEF_ADSL_IDLE     1
#define DEF_ADSL_TRAINING 2
#define DEF_ADSL_SYNC     3
#define DEF_ADSL_ACTIVITY 4

typedef struct led_reg{
    unsigned int param;
    void (*init)(unsigned long param);
    void (*onfunc)(unsigned long param);
    void (*offfunc)(unsigned long param);
}led_reg_t;

#endif /* BASE_PSP_7X */

/* For LED wrapper functions */
extern void register_led_drv(int led_num,led_reg_t *led);
extern void deregister_led_drv( int led_num);
extern void led_operation(int mod,int state_id);

/* LED handles */
extern void *hnd_LED_0;


#define TN7DSL_LED_ACTION(module_handle, module_name, state_id) led_operation(module_name, state_id)

#define LED_NUM_1 3
#define LED_NUM_2 4
#endif /* CONFIG_LED_MODULE */

/* No LED support */
#if !defined (CONFIG_MIPS_AVALANCHE_COLORED_LED) && !defined (CONFIG_LED_MODULE)
#define TN7DSL_LED_ACTION(module_handle, module_name, state_id)
#endif


/* proc entries */
int DDA_dsldk_proc_version (char* , char **, off_t , int ,int *, void *);
int DDA_atm_proc_channels  (char* , char **, off_t , int ,int *, void *);
int DDA_sar_proc_sar_stat  (char* , char **, off_t , int ,int *, void *);
int DDA_sar_proc_oam_ping  (char* , char **, off_t , int ,int *, void *);
int DDA_sar_proc_pvc_table (char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_snr0      (char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_snr1      (char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_snr2      (char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_eoc       (char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_bit_allocation(char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_train_mode_export(char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_SNRpsds    (char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_QLNpsds    (char* , char **, off_t , int ,int *, void *);
int DDA_atm_proc_private   (char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_modem      (char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_stats      (char* , char **, off_t , int ,int *, void *);

#ifdef ADV_DIAG_STATS //CQ10275
int DDA_dsl_proc_adv_stats1(char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_adv_stats2(char* , char **, off_t , int ,int *, void *);
int DDA_dsl_proc_adv_stats3(char* , char **, off_t , int ,int *, void *);
#endif

int DDA_atm_proc_qos_read(char* , char **, off_t , int ,int *, void *);
int DDA_atm_proc_qos_write(struct file *, const char * , unsigned long , void *);
int DDA_dsl_proc_write_stats(struct file *, const char * , unsigned long , void *);

/* Sysctl */
int dslmod_sysctl (ctl_table * ctl, int write, struct file *filp, void *buffer, size_t *lenp, loff_t *ppos);

/* Interrupt Handlers */
irqreturn_t DDA_atm_dsl_irq (int irq, void *voiddev, struct pt_regs *regs);
irqreturn_t DDA_atm_sar_irq (int irq, void *voiddev, struct pt_regs *regs);
void DDA_atm_free_rx_skb (void *skb, void *pmem);
void *DDA_atm_allocate_rx_skb (void *os_dev, void **os_receive_info, unsigned int size, void *vcc);

int os_atoi(const char *pStr);
int os_atoh(const char *pStr);

int DDA_atm_send_complete (void *skb1);
void DDA_sar_critical_on(void);
void DDA_sar_critical_off(void);

void * DDA_atm_memcpy(void * dst, void const * src, size_t len);
int DDA_atm_memcmp(void * dst, void const * src, size_t len);

int DDA_atm_ioctl (struct atm_dev *dev, unsigned int cmd, void *arg);
int DDA_atm_send (struct atm_vcc *vcc, struct sk_buff *skb);
int DDA_atm_change_qos(struct atm_vcc *vcc, struct atm_qos *qos, int flags);

int DDA_printf(const char *fmt, ...);

#ifdef TI_DSL_TASKLET_MODE
extern void cpsar_handle_rx_tasklet (unsigned long data);
extern void cpsar_handle_tx_tasklet (unsigned long data);
#endif

#endif  /*_DDA_ATM_H_*/
