spbx/roms/srcs/images/ethernet/gianfar_eth/hook.h

331 lines
8.5 KiB
C

#ifndef HOOK_H
#define HOOK_H
#include <net/sock.h>
#include <linux/kfifo.h>
#include <linux/etherdevice.h>
#include "mpic_timer.h"
#define EN_SIP_SWITCH (1)
#define MAX_RTP_CH (1000)
#define MAX_SIP_CH (400)
#define UMB_MAX_GETH 3
enum
{
IP_TX_OK_FLAGS = 0x0000,
IP_SEND_FLAGS = 0x0001,
IP_CSUM_FLAGS = 0x0010,
IP_SENDING_FLAGS = 0x0100
};
struct rtp_tx_buf_t
{
uint16_t status;
uint16_t len;
uint8_t fcb[8]; // used to fcb
uint8_t data[512]; //156 + 4 == 160
};
struct rtp_rx_buf_t
{
uint16_t status;
uint16_t len;
char* data;
void* skb;
};
typedef struct __RTP_CH_DETAILS__
{
struct rtp_tx_buf_t* current_ktx;
struct rtp_tx_buf_t* current_utx;
struct rtp_rx_buf_t* current_krx;
struct rtp_rx_buf_t* current_urx;
void* netdev; //for out route device
struct sock* sk;
struct rtp_tx_buf_t tx[2];
struct rtp_rx_buf_t rx[3];
atomic_t hold;
} RTP_CH_DETAILS, *PRTP_CH_DETAILS; //160*2 + 4*7 + 3*12 = 384
typedef struct __RTP_CH_DGBS__
{
uint32_t uRecBytes;
uint32_t uSendBytes;
uint32_t uUDPRecPackages;
uint32_t uLostPackages;
uint32_t uSendSeqLost;
uint32_t uRecvSeqLost;
uint32_t uBufStatus;
} RTP_CH_DBGS, PRTP_CH_DBGS;
typedef struct __CPU_TIMER_DBG__
{
unsigned int uRTPSendTime;
unsigned int uIRQTime;
unsigned int uRTPNetTime;
unsigned int uIRQHookTime;
unsigned int uRTPSendCnt;
unsigned int uIRQCnt;
unsigned int uRTPNetCnt;
unsigned int uIRQHookCnt;
} CPU_TIMER_DBG, *PCPU_TIMER_DBG;
enum
{
SKB_BUFF_TYPE = 0,
RTP_BUFF_TYPE = 1,
} ;
enum
{
IRQ_STOP = 0x00000001,
};
#define TIMER_EXPIRES (HZ/1000)
struct ipstack_hook_t
{
//struct sk_buff_head qtx[UMB_MAX_GETH];
struct sk_buff_head qtx;
uint8_t* kmap_addr;
uint8_t* kmap_end;
uint32_t kmap_len;
uintptr_t kmap_phy;
atomic_t hold;
int (*hook_init)(struct gfar_private*);
int (*hook_exit)(struct gfar_private*);
int (*xmit_filter)(struct sk_buff*);
int (*backlog)(struct sk_buff*);
int (*hook_xmit)(void* data, int tx_type, struct net_device* dev);
int (*backlog_xmit)(struct gfar_private*, int len);
int (*gptimer_init)(int);
int (*gptimer_exit)(void);
PRTP_CH_DETAILS(*get_grtp)(struct gfar_private*);
int (*is_rtp_kbuf)(void*, int);
int (*do_sock_send)(void*);
int (*do_sock_recv)(struct sk_buff* skb);
// RTP content
PRTP_CH_DETAILS pRtpChDetails;
unsigned short rtpBasePort;
unsigned short rtpPortStep;
unsigned short rtpMaxCh;
unsigned short rtpCfgCh;
unsigned short rtpPortIndex[MAX_RTP_CH];
unsigned int linkIPAddr[MAX_RTP_CH];
unsigned int sendIndex[MAX_RTP_CH];
unsigned int recvIndex[MAX_RTP_CH];
// count cpu used
CPU_TIMER_DBG maxTime;
CPU_TIMER_DBG avgTime;
CPU_TIMER_DBG minTime;
// debug proc used
RTP_CH_DBGS rtpChDbgs[MAX_RTP_CH];
};
#ifdef EN_SIP_SWITCH
#define MAX_CH_SUBPORT (3)
typedef enum __ETH_INTERFACE__
{
ETH_INTERFACE_0 = 0,
ETH_INTERFACE_1 = 1,
ETH_INTERFACE_2 = 2,
} ETH_INTERFACE;
typedef enum __CH_TYPE__
{
CH_TYPE_UNKNOWN = -1,
CH_TYPE_UMB = 0,
CH_TYPE_SIP = 1,
CH_TYPE_TC = 2,
} CH_TYPE;
typedef enum __CH_STATUS__
{
CH_STATUS_UNKONWN = -1,
CH_STATUS_CONFIGUREED = 0,
CH_STATUS_IDLE = 1,
CH_STATUS_LINKED = 2,
} CH_STATUS;
typedef enum __PORT_TYPE__
{
PORT_TYPE_UNKNOWN = -1,
PORT_TYPE_RECA = 0,
PORT_TYPE_RECB = 1,
PORT_TYPE_SS = 2,
PORT_TYPE_IPR = 5,
PORT_TYPE_B2B = 6,
PORT_TYPE_T38 = 7,
PORT_TYPE_SIPRTP = 8,
} PORT_TYPE;
typedef struct __IP_ADDR_INFO__
{
// ETH_INTERFACE ethId;
char ethAddr[ETH_ALEN];
__be16 ipPort;
__be32 ipAddr;
} IP_ADDR_INFO, *PIP_ADDR_INFO;
#pragma pack(1)
typedef struct __PACKAGE_HEAD__
{
struct ethhdr ethHead;
struct iphdr ipHead;
struct udphdr udpHead;
} __attribute__((packed))
PACKAGE_HEAD, *PPACKAGE_HEAD;
typedef struct __PACKAGE_INFO__
{
unsigned int isUpdate;
PACKAGE_HEAD headValue;
} PACKAGE_INFO, *PPACKAGE_INFO;
typedef struct __CH_LINK_INFO__
{
int linkCh;
__be16 stunTags;
int usdTarget;
IP_ADDR_INFO dstTarget;
IP_ADDR_INFO inTarget;
PACKAGE_INFO toRTPCh;
PACKAGE_INFO fromRTPCh;
} CH_LINK_INFO, *PCH_LINK_INFO;
typedef struct __CH_PORT_INFO__
{
PORT_TYPE portType;
CH_STATUS chStatus;
__be16 ipPort;
CH_LINK_INFO chLinkInfo;
} CH_PORT_INFO, *PCH_PORT_INFO;
typedef enum __RFC2833_STATUS__
{
RFC2833_SEND_IDLE = 0,
RFC2833_SEND_BEGING,
RFC2833_SENDING,
RFC2833_RECV_IDLE,
RFC2833_RECVING,
RFC2833_RECV_UPLOAD,
RFC2833_RECV_LOCK,
} RFC2833_STATUS;
#define MAX_DTMF_SEND_BUF (32)
#define MAX_DTMF_RECV_BUF (64)
typedef struct __RFC2833_INFO__
{
unsigned int timeStamps;
unsigned int synIdentifier;
unsigned short seqNumber;
char dtmfValue;
char refCount;
char payloadType;
RFC2833_STATUS refStatus;
} RFC2833_INFO, *PRFC2833_INFO;
typedef struct __RFC2833_DTFM_RECV__
{
char recvBuf[MAX_DTMF_RECV_BUF];
} RFC2833_DTFM_RECV, *PRFC2833_DTFM_RECV;
typedef struct __CH_DTMF_INFO__
{
unsigned int refSendMask;
unsigned int curSendIndex;
__be32 srcIp;
__be16 srcPort;
char drvRfc2833ChkVal;
char nicRfc2833ChkVal;
RFC2833_INFO dtmfSendBuf;
RFC2833_INFO dtmfRecvBuf[MAX_DTMF_RECV_BUF];
} CH_DTMF_INFO, *PCH_DTMF_INFO;
typedef struct __SIP_CH_DBG__
{
unsigned int cnt_eth0_recv;
unsigned int cnt_eth0_2_ethx;
unsigned int mask_eth0_2_ethx;
unsigned int cnt_ethx_recv;
unsigned int cnt_ethx_2_eth0;
unsigned int mask_ethx_2_eth0;
unsigned short eth0_seq_index;
unsigned short ethx_seq_index;
unsigned int eth0_seq_error;
unsigned int ethx_seq_error;
unsigned int eth0_drop_src;
unsigned int ethx_drop_src;
unsigned int ethx_rfc2833_error;
unsigned int ethx_rfc2833_recv;
unsigned int ethx_rfc2833_rcv_lost;
unsigned int ethx_rfc2833_snd_lost;
unsigned int drv_rcv_rfc2833_recv;
unsigned int drv_rcv_rfc2833_error;
} SIP_CH_DBG, *PSIP_CH_DBG;
typedef struct __SIP_CH_DETIAL__
{
int chId;
ETH_INTERFACE sipETHId;
CH_PORT_INFO portIPR;
CH_PORT_INFO portB2B;
CH_PORT_INFO portT38;
CH_PORT_INFO portRTP;
CH_DTMF_INFO rfc2833DTMF;
SIP_CH_DBG sipDebug;
struct kfifo dtmfSendFifo;
struct kfifo dtmfRecvFifo;
} SIP_CH_DETIAL, *PSIP_CH_DETIAL;
typedef struct __SIP_CH_INFO__
{
int iTotalCh;
int iPortStep;
int iPortBase;
int iRTPPortBase;
PSIP_CH_DETIAL pSipChDetial;
} SIP_CH_INFO, *PSIP_CH_INFO;
#endif
extern struct ipstack_hook_t* ipstack_hook_get(int ucc_num);
extern int register_irq_poll(void * (*hooks)(int, void* obj), void* data, unsigned int);
extern int unregister_irq_poll(int idx, void * (*hooks)(int, void* obj));
extern int unregister_mpic_timer_irq(int idx);
extern int register_mpic_timer_irq(PMIPC_TIMER_RUNTIME phooks, void* data);
extern int unregister_ext_timer_irq(int idx);
extern int register_ext_timer_irq(PMIPC_TIMER_RUNTIME phooks, void* data);
extern int mpic_tm_get_current(void);
extern int mrs_irq_init(void);
extern void mrs_irq_exit(void);
extern int config_eth_ipaddr(unsigned int ethId, __be32 ipaddr, __be32 gwaddr, __be32 gwmask);
extern int eth_unlink(unsigned int chId, int portType);
extern int sip_recv_dtmf(unsigned int sipCh);
extern int eth_sip_link(unsigned int sipCh,
__be32 dst_ipAddr,
__be16 dst_ipPort,
__be16 stun_tags);
extern int eth_link(unsigned int chId, PORT_TYPE portType,
__be32 dst_ipAddr,
__be16 dst_ipPort);
extern int config_sip_ch(unsigned int maxSIPCh,
unsigned int portBase,
unsigned int portStep,
unsigned int rtpPortBase);
extern int config_sip_port(unsigned int chId,
unsigned int ethId,
unsigned short chPort,
unsigned short sipChPort);
#endif