diff options
Diffstat (limited to 'target/linux/realtek/files/include/net/rtl')
23 files changed, 5225 insertions, 0 deletions
diff --git a/target/linux/realtek/files/include/net/rtl/fastpath/fast_br.h b/target/linux/realtek/files/include/net/rtl/fastpath/fast_br.h new file mode 100644 index 000000000..c49472c2b --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/fastpath/fast_br.h @@ -0,0 +1,41 @@ +#ifndef FAST_BR_H
+#define FAST_BR_H
+
+#include <linux/netdevice.h>
+
+#define RTL_FAST_BR_HEAD_SIZE 1
+#define RTL_FAST_BR_HASH_SIZE 4
+#define RTL_FAST_BR_ENTRY_NUM 16
+#define RTL_FAST_BR_SALT 3
+#define RTL_FAST_BR_ENTRY_TIME_OUT 180*HZ
+
+#define RTL_FAST_BR_SUCCESS 0
+#define RTL_FAST_BR_FAILED -1
+#define RTL_FAST_BR_ENTRY_EXPIRED 1
+#define RTL_FAST_BR_ENTRY_NOT_EXPIRED 0
+
+#define ERR_RTL_FAST_BR_ENTRY_EXIST -1000
+#define ERR_RTL_FAST_BR_ENTRY_NOT_EXIST -1001
+#define ERR_RTL_FAST_BR_NO_BUFFER -1002
+
+
+
+typedef struct _fast_br_head
+{
+ struct hlist_head fast_br_hash[RTL_FAST_BR_HASH_SIZE];
+
+}fast_br_head;
+
+typedef struct _fast_br_cache_entry
+{
+ struct hlist_node hlist;
+ struct net_device *to_dev;
+ unsigned long ageing_timer;
+ unsigned char mac_addr[6];
+ unsigned int valid;
+}fast_br_cache_entry;
+
+int rtl_add_fast_br_entry(fast_br_cache_entry *entry);
+int rtl_fast_br_forwarding(struct sk_buff *skb);
+#endif
+
diff --git a/target/linux/realtek/files/include/net/rtl/fastpath/fastpath_core.h b/target/linux/realtek/files/include/net/rtl/fastpath/fastpath_core.h new file mode 100644 index 000000000..9d02db024 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/fastpath/fastpath_core.h @@ -0,0 +1,790 @@ +#ifndef __FASTPATH_CORE_H__ +#define __FASTPATH_CORE_H__ + +#include <linux/module.h> +#include <linux/proc_fs.h> +#include <linux/in.h> +#include <linux/ip.h> +#include <linux/udp.h> +#include <linux/tcp.h> +#include <linux/netdevice.h> +#include <linux/netfilter.h> +#include <linux/netfilter_ipv4.h> +#include <net/dst.h> + +#if defined(CONFIG_RTL_HW_QOS_SUPPORT) +#include <net/rtl/rtl865x_nat.h> +#endif + +//#include <net/netfilter/nf_conntrack.h> +//#include <net/route.h> + + +/* + Virtual Rome Driver API & System (Light Rome Driver Simulator) +*/ + +#if defined (__IRAM_GEN) +#undef __IRAM_GEN +#define __IRAM_GEN +#endif + +//#define ipaddr_t __u32 +//#define uint8 __u8 +//#define uint16 __u16 +//#define uint32 __u32 +//typedef unsigned long long __uint64; + +#if 0 +#define DEBUGP_API printk +#else +#define DEBUGP_API(format, args...) +#endif + +#if 0 +#define DEBUGP_PKT printk +#else +#define DEBUGP_PKT(format, args...) +#endif + +#if 0 +#define DEBUGP_SYS printk +#else +#define DEBUGP_SYS(format, args...) +#endif + +//#define DEBUG_PROCFILE /* Create ProcFile for debug */ + +//define this macro to improve qos +#define IMPROVE_QOS 1 + +//#define RTL_FP_CHECK_SPI_ENABLED 1 +#if !defined(RTL_FP_CHECK_SPI_ENABLED) +#define CONFIG_UDP_FRAG_CACHE 1 //enable fragmentation cache ,mark_add +#endif + +#if defined(CONFIG_UDP_FRAG_CACHE) +#define MAX_UDP_FRAG_ENTRY 64 //kernel => 64 frag queue!! +#endif + +#if 1 +/***********************************cary:refine filter.c**********************************/ +#define FASTPATH_FILTER 1 +/***********************************************************************************/ +#define CUSTOM_RSP_PACKET +#define DOS_FILTER +#define URL_FILTER + +//#define URL_CONTENT_AUTHENTICATION + +#define ACTION_ALLOW 1 +#define ACTION_DENY 0 +#define WEEK_ALL_DAY 1<<7 +#define TIME_ALL_TIME 1<<0 +#define FAST_PPTP +#define FAST_L2TP +#endif +//#define DEL_NAPT_TBL +#define DEL_ROUTE_TBL //sync from rtl865x --2010.02.09 +#define NO_ARP_USED // 2008.01.09, Forrest Lin. Use kernel route cache already. +#define INVALID_PATH_BY_FIN + + +#if defined(FAST_L2TP) +#if 0 + #define DEBUGP printk +#else + #define DEBUGP(fmt, args...) {} +#endif + +#ifdef URL_CONTENT_AUTHENTICATION +#define RTL_UNAUTH_BUFFER_SIZE 8 +#define RTL_URL_CONTENT_READED 0x1 + +typedef struct _unAuth_skb_s +{ + struct list_head list; + int id; /*skb->iphdr.id*/ + uint32 saddr; + uint32 daddr; + uint32 flag; /*whether the url content is readed by application....*/ + struct sk_buff *skb; +} unAuth_skb_t; + +int rtl_urlContent_auth(struct sk_buff *skb); +#endif + + +#define control_message 0x8000 +#define connect_control 0xc +#define stop_control 0x4 +#define call_reply 0xb + +struct l2tp_info +{ + struct net_device *wan_dev; + struct net_device *ppp0_dev; + unsigned long last_xmit; + __u32 daddr; + __u32 saddr; + __u16 tid; /* Tunnel ID */ + __u16 cid; /* Caller ID */ + unsigned char mac_header[ETH_HLEN]; + __u16 valid; + + +}; + +struct l2tp_ext_hdr +{ + __u16 source; + __u16 dest; + __u16 len; + __u16 checksum; + __u16 type; + __u16 tid; + __u16 cid; + __u16 addr_control; + __u16 protocol; +}; + +struct avp_info +{ + __u16 length; + __u16 vendorid; + __u16 attr; + __u16 mss_type; +}; + +struct l2tp_header +{ + __u16 ver; /* Version and friends */ + __u16 length; /* Optional Length */ + __u16 tid; /* Tunnel ID */ + __u16 cid; /* Caller ID */ + __u16 Ns; /* Optional next sent */ + __u16 Nr; /* Optional next received */ +}; +extern void (*l2tp_tx_id_hook)(struct sk_buff *skb); + +#endif + + +#if defined(FAST_PPTP) + +#if 0 + #define FAST_PPTP_PRINT printk +#else + #define FAST_PPTP_PRINT(fmt, args...) {} +#endif + +/* +struct pptp_info { + struct net_device *wan_dev; + unsigned int tx_seqno; + unsigned int rx_seqno; + __u32 saddr; + __u32 daddr; + __u16 callID; + __u16 peer_callID; + __u16 tx_ipID; + __u16 ipID; + struct net_device *ppp0_dev; + struct net_device *lan_dev; + unsigned char mac_header[ETH_HLEN]; + unsigned int tx_seqno_daemon; + unsigned int rx_seqno_daemon; + int ppp_hdr_len; + unsigned char ppp_hdr[4]; +}; +*/ + +extern int fast_pptp_fw; + + +/* following define are imported from kerenl */ +#define SC_COMP_RUN 0x00001000 /* compressor has been inited */ +enum NPmode { + NPMODE_PASS, /* pass the packet through */ + NPMODE_DROP, /* silently drop the packet */ + NPMODE_ERROR, /* return an error */ + NPMODE_QUEUE /* save it up for later. */ +}; + +#define NUM_NP 6 /* Number of NPs. */ +struct ppp_file { + enum { + INTERFACE=1, CHANNEL + } kind; + struct sk_buff_head xq; /* pppd transmit queue */ + struct sk_buff_head rq; /* receive queue for pppd */ + wait_queue_head_t rwait; /* for poll on reading /dev/ppp */ + atomic_t refcnt; /* # refs (incl /dev/ppp attached) */ + int hdrlen; /* space to leave for headers */ + int index; /* interface unit / channel number */ + int dead; /* unit/channel has been shut down */ +}; + +//To sync with drivers/net/ppp_generic.c +struct ppp { + struct ppp_file file; /* stuff for read/write/poll 0 */ + struct file *owner; /* file that owns this unit 48 */ + struct list_head channels; /* list of attached channels 4c */ + int n_channels; /* how many channels are attached 54 */ + spinlock_t rlock; /* lock for receive side 58 */ + spinlock_t wlock; /* lock for transmit side 5c */ + int mru; /* max receive unit 60 */ +#if defined(CONFIG_PPP_MPPE_MPPC) + int mru_alloc; /* MAX(1500,MRU) for dev_alloc_skb() */ +#endif + unsigned int flags; /* control bits 64 */ + unsigned int xstate; /* transmit state bits 68 */ + unsigned int rstate; /* receive state bits 6c */ + int debug; /* debug flags 70 */ + struct slcompress *vj; /* state for VJ header compression */ + enum NPmode npmode[NUM_NP]; /* what to do with each net proto 78 */ + struct sk_buff *xmit_pending; /* a packet ready to go out 88 */ + struct compressor *xcomp; /* transmit packet compressor 8c */ + void *xc_state; /* its internal state 90 */ + struct compressor *rcomp; /* receive decompressor 94 */ + void *rc_state; /* its internal state 98 */ + unsigned long last_xmit; /* jiffies when last pkt sent 9c */ + unsigned long last_recv; /* jiffies when last pkt rcvd a0 */ + struct net_device *dev; /* network interface device a4 */ + int closing; /* is device closing down? a8 */ +#ifdef CONFIG_PPP_MULTILINK + int nxchan; /* next channel to send something on */ + u32 nxseq; /* next sequence number to send */ + int mrru; /* MP: max reconst. receive unit */ + u32 nextseq; /* MP: seq no of next packet */ + u32 minseq; /* MP: min of most recent seqnos */ + struct sk_buff_head mrq; /* MP: receive reconstruction queue */ +#endif /* CONFIG_PPP_MULTILINK */ + struct net_device_stats stats; /* statistics */ +#ifdef CONFIG_PPP_FILTER + struct sock_filter *pass_filter; /* filter for packets to pass */ + struct sock_filter *active_filter;/* filter for pkts to reset idle */ + unsigned pass_len, active_len; +#endif /* CONFIG_PPP_FILTER */ + struct net *ppp_net; /* the net we belong to */ +}; + +extern void (*sync_tx_pptp_gre_seqno_hook)(struct sk_buff *skb); +#endif +#if defined(CUSTOM_RSP_PACKET) +void register_customRspHook(int *_cusRsp401_func,int *_cusRspTCPFinAck_func,int *_cusRspTCPEndAck_func); +void unregister_customRspHook(void); +void register_customRspStr(char *_str); +void unregister_customRspStr(void); + int GenerateHTTP401(struct sk_buff *skb); +#endif +#ifdef DOS_FILTER + extern int filter_enter(struct sk_buff *skb); + extern int __init filter_init(void); + extern void __exit filter_exit(void); + extern void filter_addconnect(ipaddr_t ipaddr); + extern void filter_delconnect(ipaddr_t ipaddr); +#endif + +#ifdef FAST_PPTP + extern void fast_pptp_filter(struct sk_buff *skb); + extern void fast_pptp_sync_rx_seq(struct sk_buff *skb); + extern int __init fast_pptp_init(void); + extern void __exit fast_pptp_exit(void); + extern int fast_pptp_to_lan(struct sk_buff **pskb); + extern int Check_GRE_rx_net_device(struct sk_buff *skb); + extern int pptp_tcp_finished; +#endif + +#ifdef FAST_L2TP + extern int __init fast_l2tp_init(void); + extern void __exit fast_l2tp_exit(void); + extern int fast_l2tp_to_wan(struct sk_buff *skb); + extern void fast_l2tp_rx(struct sk_buff *skb); + extern void l2tp_tx_id(struct sk_buff *skb); + extern int fast_l2tp_fw; +#endif + + + +/* ---------------------------------------------------------------------------------------------------- */ + +#define IFNAME_LEN_MAX 16 +#define MAC_ADDR_LEN_MAX 18 +#if !defined(NO_ARP_USED) +#define ARP_TABLE_LIST_MAX 32 +#define ARP_TABLE_ENTRY_MAX 128 +#endif + +#define ROUTE_TABLE_LIST_MAX 16 +#define ROUTE_TABLE_ENTRY_MAX 64 + +#if !defined(CONFIG_RTL8186_KB_N) +#if defined(CONFIG_RTL_8198) || defined(CONFIG_RTL_92D_SUPPORT) +#define NAPT_TABLE_LIST_MAX 4096 +#define NAPT_TABLE_ENTRY_MAX 4096 +#define PATH_TABLE_LIST_MAX 4096 +#else +#define NAPT_TABLE_LIST_MAX 1024 +#define NAPT_TABLE_ENTRY_MAX 1024 +#define PATH_TABLE_LIST_MAX 1024 +#endif +#endif + +#define PATH_TABLE_ENTRY_MAX (NAPT_TABLE_ENTRY_MAX<<1) + +#if defined(CONFIG_RTL_FAST_FILTER) +#define NF_DROP 0 +#define NF_FASTPATH 1 +#define NF_LINUX 2 +#define NF_MARK 3 +#define NF_REPEAT 4 +#define NF_OMIT 5 +#endif + +#if 0 +#define ETHER_ADDR_LEN 6 +typedef struct ether_addr_s { + uint8 octet[ETHER_ADDR_LEN]; +} ether_addr_t; +#endif + +/* ########### API #################################################################################### */ +enum LR_RESULT +{ + /* Common error code */ + LR_SUCCESS = 0, /* Function Success */ + LR_FAILED = -1, /* General Failure, not recommended to use */ + LR_ERROR_PARAMETER = -2, /* The given parameter error */ + LR_EXIST = -3, /* The entry you want to add has been existed, add failed */ + LR_NONEXIST = -4, /* The specified entry is not found */ + + LR_NOBUFFER = -1000, /* Out of Entry Space */ + LR_INVAPARAM = -1001, /* Invalid parameters */ + LR_NOTFOUND = -1002, /* Entry not found */ + LR_DUPENTRY = -1003, /* Duplicate entry found */ +}; + +#if 0 +enum IF_FLAGS +{ + IF_NONE, + IF_INTERNAL = (0<<1), /* This is an internal interface. */ + IF_EXTERNAL = (1<<1), /* This is an external interface. */ +}; + +enum FDB_FLAGS +{ + FDB_NONE = 0, +}; +#endif + +enum ARP_FLAGS +{ + ARP_NONE = 0, +}; + +enum RT_FLAGS +{ + RT_NONE = 0, +}; + +enum SE_TYPE +{ + SE_PPPOE = 1, + SE_PPTP = 2, + SE_L2TP = 3, +}; +enum SE_FLAGS +{ + SE_NONE = 0, +}; + +enum NP_PROTOCOL +{ + NP_UDP = 1, + NP_TCP = 2, +}; +enum NP_FLAGS +{ + NP_NONE = 0, +}; + +typedef struct _rtl_fp_napt_entry +{ + enum NP_PROTOCOL protocol; + ipaddr_t intIp; + uint32 intPort; + ipaddr_t extIp; + uint32 extPort; + ipaddr_t remIp; + uint32 remPort; +}rtl_fp_napt_entry; + +/* ---------------------------------------------------------------------------------------------------- */ +#if 0 +enum LR_RESULT rtk_addInterface( uint8* ifname, ipaddr_t ipAddr, ether_addr_t* gmac, uint32 mtu, enum IF_FLAGS flags ); +enum LR_RESULT rtk_configInterface( uint8* ifname, uint32 vlanId, uint32 fid, uint32 mbr, uint32 untag, enum IF_FLAGS flags ); +enum LR_RESULT rtk_delInterface( uint8* ifname ); +enum LR_RESULT rtk_addFdbEntry( uint32 vid, uint32 fid, ether_addr_t* mac, uint32 portmask, enum FDB_FLAGS flags ); +enum LR_RESULT rtk_delFdbEntry( uint32 vid, uint32 fid, ether_addr_t* mac ); +#endif +enum LR_RESULT rtk_addArp( ipaddr_t ip, ether_addr_t* mac, enum ARP_FLAGS flags ); +enum LR_RESULT rtk_modifyArp( ipaddr_t ip, ether_addr_t* mac, enum ARP_FLAGS flags ); +enum LR_RESULT rtk_delArp( ipaddr_t ip ); +enum LR_RESULT rtk_addRoute( ipaddr_t ip, ipaddr_t mask, ipaddr_t gateway, uint8* ifname, enum RT_FLAGS flags ); +enum LR_RESULT rtk_modifyRoute( ipaddr_t ip, ipaddr_t mask, ipaddr_t gateway, uint8* ifname, enum RT_FLAGS flags ); +enum LR_RESULT rtk_delRoute( ipaddr_t ip, ipaddr_t mask ); +enum LR_RESULT rtk_addSession( uint8* ifname, enum SE_TYPE seType, uint32 sessionId, enum SE_FLAGS flags ); +enum LR_RESULT rtk_delSession( uint8* ifname ); + +enum LR_RESULT rtk_addNaptConnection(rtl_fp_napt_entry *fpNaptEntry, +#if defined(IMPROVE_QOS) + struct sk_buff *pskb, struct nf_conn *ct, +#endif + enum NP_FLAGS flags); +enum LR_RESULT rtk_delNaptConnection( rtl_fp_napt_entry *fpNaptEntry); +#if defined(IMPROVE_QOS) +enum LR_RESULT rtk_idleNaptConnection(rtl_fp_napt_entry *fpNaptEntry, uint32 interval); +#else +enum LR_RESULT rtk_idleNaptConnection(rtl_fp_napt_entry *fpNaptEntry, uint32 interval, unsigned long *lastUsed); +#endif +#if defined(CONFIG_BRIDGE) +int32 rtl_br_fdb_time_update(void *br, void *fdb, const unsigned char *addr); +#endif +int32 rtl_fp_dev_queue_xmit_check(struct sk_buff *skb, struct net_device *dev); +int32 rtl_fp_dev_hard_start_xmit_check(struct sk_buff *skb, struct net_device *dev, struct netdev_queue *txq); + +#if defined(IMPROVE_QOS) || defined(CONFIG_RTL_HW_QOS_SUPPORT) +//To query hardware address based on IP through arp table of dev +int arp_req_get_ha(__be32 queryIP, struct net_device *dev, unsigned char * resHwAddr); +#endif + +#if defined(CONFIG_RTL_HW_QOS_SUPPORT) +int32 rtl_qosGetSkbMarkByNaptEntry(rtl865x_napt_entry *naptEntry, rtl865x_qos_mark *qosMark, struct sk_buff *pskb); +#endif +int fast_path_before_nat_check(struct sk_buff *skb, struct iphdr *iph, uint32 iphProtocol); + +#if defined(CONFIG_PROC_FS) +int fastpath_dump_napt_entry_num(char *page, int len); +#endif + +/* [MARCO FUNCTION] ========================================================================= */ +#define MAC2STR(addr) \ + ((unsigned char *)&addr)[0], \ + ((unsigned char *)&addr)[1], \ + ((unsigned char *)&addr)[2], \ + ((unsigned char *)&addr)[3], \ + ((unsigned char *)&addr)[4], \ + ((unsigned char *)&addr)[5] + +#define FASTPATH_MAC2STR(mac, hbuffer) \ + do { \ + int j,k; \ + const char hexbuf[] = "0123456789ABCDEF"; \ + for (k=0,j=0;k<MAC_ADDR_LEN_MAX && j<6;j++) { \ + hbuffer[k++]=hexbuf[(mac->octet[j]>>4)&15 ]; \ + hbuffer[k++]=hexbuf[mac->octet[j]&15 ]; \ + hbuffer[k++]=':'; \ + } \ + hbuffer[--k]=0; \ + } while(0) /* Mac Address to String */ +#if 0 +#define FASTPATH_ADJUST_CHKSUM_NAT(ip_mod, ip_org, chksum) \ + do { \ + s32 accumulate = 0; \ + if (((ip_mod) != 0) && ((ip_org) != 0)){ \ + accumulate = ((ip_org) & 0xffff); \ + accumulate += (( (ip_org) >> 16 ) & 0xffff); \ + accumulate -= ((ip_mod) & 0xffff); \ + accumulate -= (( (ip_mod) >> 16 ) & 0xffff); \ + } \ + accumulate += ntohs(chksum); \ + if (accumulate < 0) { \ + accumulate = -accumulate; \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) ~accumulate); \ + } else { \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) accumulate); \ + } \ + }while(0) /* Checksum adjustment */ + +#define FASTPATH_ADJUST_CHKSUM_NPT(port_mod, port_org, chksum) \ + do { \ + s32 accumulate = 0; \ + if (((port_mod) != 0) && ((port_org) != 0)){ \ + accumulate += (port_org); \ + accumulate -= (port_mod); \ + } \ + accumulate += ntohs(chksum); \ + if (accumulate < 0) { \ + accumulate = -accumulate; \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) ~accumulate); \ + } else { \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) accumulate); \ + } \ + }while(0) /* Checksum adjustment */ + + +#define FASTPATH_ADJUST_CHKSUM_NAPT(ip_mod, ip_org, port_mod, port_org, chksum) \ + do { \ + s32 accumulate = 0; \ + if (((ip_mod) != 0) && ((ip_org) != 0)){ \ + accumulate = ((ip_org) & 0xffff); \ + accumulate += (( (ip_org) >> 16 ) & 0xffff); \ + accumulate -= ((ip_mod) & 0xffff); \ + accumulate -= (( (ip_mod) >> 16 ) & 0xffff); \ + } \ + if (((port_mod) != 0) && ((port_org) != 0)){ \ + accumulate += (port_org); \ + accumulate -= (port_mod); \ + } \ + accumulate += ntohs(chksum); \ + if (accumulate < 0) { \ + accumulate = -accumulate; \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) ~accumulate); \ + } else { \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) accumulate); \ + } \ + }while(0) /* Checksum adjustment */ +#else + +#define FASTPATH_ADJUST_CHKSUM_NAT(ip_mod, ip_org, chksum) \ + do { \ + s32 accumulate = 0; \ + accumulate = ((ip_org) & 0xffff); \ + accumulate += (( (ip_org) >> 16 ) & 0xffff); \ + accumulate -= ((ip_mod) & 0xffff); \ + accumulate -= (( (ip_mod) >> 16 ) & 0xffff); \ + accumulate += ntohs(chksum); \ + if (accumulate < 0) { \ + accumulate = -accumulate; \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) ~accumulate); \ + } else { \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) accumulate); \ + } \ + }while(0) /* Checksum adjustment */ + +#define FASTPATH_ADJUST_CHKSUM_NPT(port_mod, port_org, chksum) \ + do { \ + s32 accumulate = 0; \ + accumulate += (port_org); \ + accumulate -= (port_mod); \ + accumulate += ntohs(chksum); \ + if (accumulate < 0) { \ + accumulate = -accumulate; \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) ~accumulate); \ + } else { \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) accumulate); \ + } \ + }while(0) /* Checksum adjustment */ + + +#define FASTPATH_ADJUST_CHKSUM_NAPT(ip_mod, ip_org, port_mod, port_org, chksum) \ + do { \ + s32 accumulate = 0; \ + accumulate = ((ip_org) & 0xffff); \ + accumulate += (( (ip_org) >> 16 ) & 0xffff); \ + accumulate -= ((ip_mod) & 0xffff); \ + accumulate -= (( (ip_mod) >> 16 ) & 0xffff); \ + accumulate += (port_org); \ + accumulate -= (port_mod); \ + accumulate += ntohs(chksum); \ + if (accumulate < 0) { \ + accumulate = -accumulate; \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) ~accumulate); \ + } else { \ + accumulate = (accumulate >> 16) + (accumulate & 0xffff); \ + accumulate += accumulate >> 16; \ + chksum = htons((uint16) accumulate); \ + } \ + }while(0) /* Checksum adjustment */ + +#endif +/* ---------------------------------------------------------------------------------------------------- */ +#ifdef DEBUG_PROCFILE +void init_fastpath_debug_proc(void); +void remove_fastpath_debug_proc(void); +#endif +#ifndef NO_ARP_USED +int init_table_arp(int arp_tbl_list_max, int arp_tbl_entry_max); +#endif +#ifndef DEL_ROUTE_TBL +int init_table_route(int route_tbl_list_max, int route_tbl_entry_max); +#endif +#ifndef DEL_NAPT_TBL +int init_table_napt(int napt_tbl_list_max, int napt_tbl_entry_max); +#endif +int init_table_path(int path_tbl_list_max, int path_tbl_entry_max); +int udp_fragCache_init(int udp_frag_entry_max); +void fastpath_set_qos_mark(struct sk_buff *skb, unsigned int preRouteMark, unsigned int postRouteMark); +int fast_path_pre_process_check(struct iphdr *iph, struct tcphdr *tcphupuh, struct sk_buff *skb); +int fast_path_post_process_xmit_check(struct iphdr *iph, struct tcphdr *tcphupuh, struct sk_buff *skb); +int fast_path_post_process_return_check(struct iphdr *iph, struct tcphdr *tcphupuh, struct sk_buff *skb); +int ip_finish_output3(struct sk_buff *skb); +__IRAM_GEN int enter_fast_path(struct sk_buff *skb); +uint8 *FastPath_Route(ipaddr_t dIp); +int FastPath_Enter(struct sk_buff **skb); +extern int Get_fast_pptp_fw(void); +#ifdef CONFIG_FAST_PATH_MODULE +extern int (*fast_path_hook)(struct sk_buff **pskb) ; +extern enum LR_RESULT (*FastPath_hook1)( ipaddr_t ip, ipaddr_t mask ); +extern enum LR_RESULT (*FastPath_hook2)( ipaddr_t ip, ipaddr_t mask, ipaddr_t gateway, uint8* ifname, enum RT_FLAGS flags ); +extern int (*fast_path_hook)(struct sk_buff **pskb) ; +extern enum LR_RESULT (*FastPath_hook3)( ipaddr_t ip, ipaddr_t mask, ipaddr_t gateway, uint8* ifname, enum RT_FLAGS flags ); +extern enum LR_RESULT (*FastPath_hook4)( rtl_fp_napt_entry *fpNaptEntry); +extern enum LR_RESULT (*FastPath_hook5)( ipaddr_t ip, ether_addr_t* mac, enum ARP_FLAGS flags ); +enum LR_RESULT (*FastPath_hook6)( rtl_fp_napt_entry *fpNaptEntry, +#if defined(IMPROVE_QOS) + struct sk_buff *pskb, struct nf_conn *ct, +#endif + enum NP_FLAGS flags); +extern enum LR_RESULT (*FastPath_hook7)( ipaddr_t ip ); +extern enum LR_RESULT (*FastPath_hook8)( ipaddr_t ip, ether_addr_t* mac, enum ARP_FLAGS flags ); +extern int (*FastPath_hook9)( void ); +extern int (*FastPath_hook10)(struct sk_buff *skb); +extern enum LR_RESULT (*FastPath_hook11)(rtl_fp_napt_entry *fpNaptEntry, uint32 interval); + +extern int fast_pptp_to_wan(struct sk_buff *skb); +#endif + +/* ---------------------------------------------------------------------------------------------------- */ +#if defined(FASTPATH_FILTER) +#define RTL_FILTER_CONTENT_MAXNUM 40 +#define RTL_TABLE_FILTER_ENTRY_COUNT 10 +#define IP_RANGE_TABLE 1 +#define MAC_TABLE 2 +#define URL_KEY_TABLE 3 +#define SCHEDULT_TABLE 4 +#define CONTENT_FILTER 5 + +typedef struct _rlt_filter_table_head +{ + struct list_head filter_table; + struct list_head filter_items; + uint32 flag; +}rlt_filter_table_head; + +//ip range table +#define RTL_IP_RANGE_FILTER_ENTRY_COUNT 20 +typedef struct _filter_ipRange_fastpath +{ + struct list_head list; + uint32 addr_start; /*ipaddr start*/ + uint32 addr_end; /*address end*/ + uint32 flag; /*0 bit: default action[0:block,1:forward];1 bit: src ip or dest ip[0:src, 1:dest];2 bit: refer both direction*/ + /*bit 9: valid 1; invalid 0*/ +}rtl_ipRange_fastpath; + +//url and keyword +#define RTL_URL_FILTER_CONTENT_MAXNUM_FASTPATH 40 +typedef struct _url_table_head_entry_fastpath +{ + struct list_head list; + uint32 flag; + int (*func)(struct sk_buff *skb); +}url_table_head_entry_fastpath; + +typedef struct _url_table_unit_entry_fastpath +{ + struct list_head list; + char url_content[RTL_URL_FILTER_CONTENT_MAXNUM_FASTPATH]; +}url_table_unit_entry_fastpath; + +typedef struct _url_entry_fastpath +{ + struct list_head list; + char url_content[RTL_URL_FILTER_CONTENT_MAXNUM_FASTPATH]; + uint32 flag; +}rtl_url_entry_fastpath; + +typedef struct _rtl_mac_entry_fastpath +{ + struct list_head list; + char mac[ETHER_ADDR_LEN]; + uint8 flag; +}rtl_mac_entry_fastpath; + +typedef struct _rtl_sch_entry_fastpath +{ + struct list_head list; + uint32 weekMask; /*bit0: sunday, bit 1: monday, .... bit 6 saturday, bit7: (1: all days, monday~sunday)*/ + uint32 startTime; /*minutes, ex. 5:21 = 5*60+21 minutes*/ + uint32 endTime; /*minutes*/ + uint8 allTimeFlag;/*if alltime(00:00~23:59:59), please set this flag...*/ + uint8 flag; /* bit0( 0: deny, 1: allow), bit1( 1:block all http packet), bit2(0:default deny; 1: default allow)*/ +}rtl_sch_entry_fastpath; + +typedef struct _filter_table_info +{ + uint32 type; //type + int (*func)(struct sk_buff *skb, void *data); +}filter_table_info; + +typedef struct _filter_table_list +{ + struct list_head table_list; + struct list_head item_list; + uint32 type; //type + uint32 flag; + uint32 num; + int (*func)(struct sk_buff *skb, void *data); +}filter_table_list; + +typedef struct _filter_item_entry +{ + struct list_head item_list; + struct list_head rule_list; + uint32 relation_flag; //bit0: is the first condition? 1;0 + //bit1: have next condition? 1:0 [next table condition] + //bit2: have "and" logic condition?1:0 + //bit3: default action: 1 block;0 forward + //bit4~7: the index of "and" logic rule + //bit8: all match flag 1: all, 0: not all + //bit9: NULL flag, 1:NULL, 0: not NULL + uint32 index; + uint32 flag; + char data[RTL_FILTER_CONTENT_MAXNUM]; +}filter_item_entry; + +typedef struct _rtl_mac_info +{ + char mac[ETHER_ADDR_LEN]; +}rtl_mac_info; + +extern filter_table_list table_list_head; + +#define RTL_FP_FLT_TBL_INIT_VALUE 1 +#define RTL_FP_FLT_TBL_EMPTY (table_list_head.num==RTL_FP_FLT_TBL_INIT_VALUE) +#define RTL_FP_FLT_TBL_NOT_INIT (table_list_head.num<RTL_FP_FLT_TBL_INIT_VALUE) +#endif + +#define RTL_FASTPATH_PPP0_DEV_NAME "ppp0" + +#if defined(CONFIG_RTL_NF_CONNTRACK_GARBAGE_NEW) +void rtl_fp_mark_invalid(struct nf_conn *ct); +#endif + +#endif /* __FASTPATH_CORE_H__ */ + diff --git a/target/linux/realtek/files/include/net/rtl/features/rtl_features.h b/target/linux/realtek/files/include/net/rtl/features/rtl_features.h new file mode 100644 index 000000000..45b2c7466 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/features/rtl_features.h @@ -0,0 +1,187 @@ +#ifndef RTL_FEATURES_H
+#define RTL_FEATURES_H 1
+
+extern int rtl_nf_conntrack_threshold;
+
+#if defined(CONFIG_RTL_IPTABLES_FAST_PATH) || defined(CONFIG_RTL_HARDWARE_NAT) || defined(CONFIG_RTL_NF_CONNTRACK_GARBAGE_NEW)
+#define IS_CLASSD_ADDR(__ipv4addr__) ((((uint32)(__ipv4addr__)) & 0xf0000000) == 0xe0000000)
+#define IS_ALLZERO_ADDR(__ipv4addr__) ((((uint32)(__ipv4addr__)) & 0xffffffff) == 0)
+#define IS_BROADCAST_ADDR(__ipv4addr__) ((((uint32)(__ipv4addr__)) & 0xffffffff) == 0xffffffff)
+#endif
+
+#if defined(CONFIG_RTL_NF_CONNTRACK_GARBAGE_NEW) +struct tcp_state_hash_head
+{ + enum tcp_conntrack state; + + struct list_head* state_hash; +}; +struct udp_state_hash_head +{ + uint8_t state; + struct list_head* state_hash; +}; + +#define UDP_UNREPLY (TCP_CONNTRACK_MAX+1) +#define UDP_ASSURED (TCP_CONNTRACK_MAX+2) + +struct DROP_PRORITY{ + u_int8_t state; + u_int16_t threshold; +}; + +extern struct tcp_state_hash_head Tcp_State_Hash_Head[]; +extern struct udp_state_hash_head Udp_State_Hash_Head[];
+extern struct DROP_PRORITY drop_priority[];
+ +enum { + PROT_ICMP, + PROT_TCP, + PROT_UDP, + PROT_MAX +}; +#endif
+
+#if defined(CONFIG_RTL_NF_CONNTRACK_GARBAGE_NEW)
+#if defined(CONFIG_PROC_FS)
+extern unsigned long rtl_gc_overflow_timout;
+void gc_overflow_timout_proc_init(void);
+#endif
+void clean_from_lists(struct nf_conn *ct, struct net *net);
+void rtl_death_action(struct nf_conn *ct);
+int drop_one_conntrack(const struct nf_conntrack_tuple *orig,const struct nf_conntrack_tuple *repl);
+int32 rtl_nf_conn_GC_init(void);
+int32 rtl_connGC_addList(struct sk_buff *skb, struct nf_conn *ct);
+#endif
+
+#if defined(CONFIG_RTL_IPTABLES_FAST_PATH)
+int rtl_fpTimer_update(struct nf_conn *ct);
+#endif
+
+void rtl_fpAddConnCache(struct nf_conn *ct, struct sk_buff *skb);
+
+#if defined(CONFIG_RTL_LOCAL_PUBLIC) || defined(CONFIG_RTL_MULTIPLE_WAN) || (defined(CONFIG_NET_SCHED)&&defined(CONFIG_RTL_IPTABLES_FAST_PATH)) || defined(CONFIG_RTL_HW_QOS_SUPPORT) +extern struct net_device *rtl865x_getWanDev(void ); +extern struct net_device *rtl865x_getLanDev(void ); +#endif +
+#if defined (CONFIG_RTL_LOCAL_PUBLIC) || defined(CONFIG_RTL_HW_QOS_SUPPORT)
+extern int rtl865x_attainDevType(unsigned char *devName, unsigned int *isLanDev, unsigned int *isWanDev); +#endif
+
+#if defined(CONFIG_RTL_IPTABLES_FAST_PATH) || defined(CONFIG_RTL_HARDWARE_NAT) +/*2007-12-19*/ +extern int tcp_get_timeouts_by_state(u_int8_t state);
+extern unsigned int nf_ct_udp_timeout; +extern unsigned int nf_ct_udp_timeout_stream;
+void rtl_check_for_acc(struct nf_conn *ct, unsigned long expires);
+void rtl_delConnCache(struct nf_conn *ct);
+int32 rtl_connCache_timer_update(struct nf_conn *ct);
+#endif
+
+#if defined(CONFIG_RTL_HARDWARE_NAT)
+int rtl865x_handle_nat(struct nf_conn *ct, int act, struct sk_buff *skb);
+int rtl_hwnat_timer_update(struct nf_conn *ct);
+#endif
+
+#if defined(IMPROVE_QOS) && (defined(CONFIG_RTL_IPTABLES_FAST_PATH) || defined(CONFIG_RTL_HARDWARE_NAT))
+void rtl_addConnCache(struct nf_conn *ct, struct sk_buff *skb);
+#endif
+
+#if defined(CONFIG_RTL_819X)
+int32 rtl_nat_init(void);
+#endif
+
+#if defined(CONFIG_NET_SCHED)
+extern int gQosEnabled;
+int32 rtl_qos_init(void);
+int32 rtl_qos_cleanup(void);
+#endif
+
+#if defined(CONFIG_RTL_FAST_BRIDGE)
+int32 rtl_fb_add_br_entry(skb)
+#endif
+
+//#define CONFIG_HARDWARE_NAT_DEBUG
+
+#if defined(CONFIG_RTL_HARDWARE_NAT)
+#define RTL_MULTIPLE_WAN_NUM 2
+
+typedef struct _rtl_masq_if_struct +{ + unsigned int valid; + unsigned int ipAddr; + //struct ipt_entry *masq_entry; + char ifName[IFNAMSIZ]; +}rtl_masq_if;
+
+rtl_masq_if *rtl_get_masq_info_by_devName(const char* name); +#endif +
+#if defined(CONFIG_RTL_HARDWARE_NAT )
+/*2007-12-19*/
+int32 syn_asic_arp(struct neighbour *n, int add);
+
+#if defined(CONFIG_RTL_MULTIPLE_WAN)
+int32 rtl_get_ps_arp_mapping(u32 ip,void *arp_entry);
+#endif
+#endif
+
+#if defined(FAST_PATH_SPI_ENABLED)
+extern struct nf_conntrack_l4proto **nf_ct_protos[PF_MAX];
+extern unsigned int + rtl_nf_conntrack_in(struct net *net, unsigned int dataoff, unsigned int hooknum, struct sk_buff *skb);
+#endif
+
+#if defined(CONFIG_RTL_HARDWARE_NAT)
+int rtl_flush_extern_ip(void);
+int rtl_init_masq_info(void);
+int rtl_check_for_extern_ip(const char *name,
+ unsigned int valid_hooks, struct xt_table_info *newinfo,
+ void *entry0, unsigned int size,
+ unsigned int number, const unsigned int *hook_entries,
+ const unsigned int *underflows);
+#endif
+
+#if defined(CONFIG_RTL_HARDWARE_NAT) +int rtl865x_handle_nat(struct nf_conn *ct, int act, struct sk_buff *skb);
+int32 rtl_update_ip_tables(char *name, unsigned long event, struct in_ifaddr *ina);
+int32 rtl_fn_insert(struct fib_table *tb, struct fib_config *cfg, struct fib_info *fi);
+int32 rtl_fn_delete(struct fib_table *tb, struct fib_config *cfg);
+int32 rtl_fn_flush(int fz_order, int idx, u32 tb_id, u32 fn_key);
+int32 rtl_ip_vs_conn_expire_check(struct ip_vs_conn *cp);
+int32 rtl_ip_vs_conn_expire_check_delete(struct ip_vs_conn *cp);
+int32 rtl_tcp_state_transition_check(struct ip_vs_conn *cp, int direction, const struct sk_buff *skb, struct ip_vs_protocol *pp);
+int32 rtl_udp_state_transition_check(struct ip_vs_conn *cp, int direction, const struct sk_buff *skb, struct ip_vs_protocol *pp);
+#endif
+
+#if defined(CONFIG_RTL_NF_CONNTRACK_GARBAGE_NEW) +extern int rtl_newGC_session_status_flags; +extern unsigned long rtl_newGC_session_status_time; +
+#if (HZ==100) +#define RTL_FP_SESSION_LEVEL3_INTERVAL (1) +#define RTL_FP_SESSION_LEVEL1_INTERVAL (200) /* 2 second */
+#elif (HZ==1000) +#define RTL_FP_SESSION_LEVEL3_INTERVAL (10) +#define RTL_FP_SESSION_LEVEL1_INTERVAL (2000) /* 2 second */
+#else +#error "Please adjust the parameter according to the HZ" +#endif + +#if defined(CONFIG_RTL_8198)
+#define RTL_FP_SESSION_LEVEL3_ALLOW_COUNT (40)
+#else
+#define RTL_FP_SESSION_LEVEL3_ALLOW_COUNT (16)
+#endif
+#define RTL_FP_SESSION_LEVEL1_RX_WEIGHT (8) + +#define RTL_FP_SESSION_LEVEL_IDLE 0 +#define RTL_FP_SESSION_LEVEL1 1 +#define RTL_FP_SESSION_LEVEL2 2 +#define RTL_FP_SESSION_LEVEL3 3 +//void rtl_fp_mark_invalid(struct nf_conn *ct); +//enum LR_RESULT rtk_refreshOSConnectionTimer(void); +#endif +
+#endif /* RTL_FEATURES_H */
diff --git a/target/linux/realtek/files/include/net/rtl/features/rtl_ps_hooks.h b/target/linux/realtek/files/include/net/rtl/features/rtl_ps_hooks.h new file mode 100644 index 000000000..6af1b865d --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/features/rtl_ps_hooks.h @@ -0,0 +1,144 @@ +#ifndef RTL_PS_HOOKS_H +#define RTL_PS_HOOKS_H 1 + +#include <linux/netfilter_ipv4.h> +#include <linux/netfilter/nf_conntrack_common.h> +#include <linux/netfilter/nf_conntrack_tcp.h> + +#include <net/rtl/rtl_types.h> +#include <net/ip_fib.h> +#include <net/ip_vs.h> + +#include <net/netfilter/nf_conntrack.h> +#include <net/netfilter/nf_conntrack_core.h> +#include <net/netfilter/nf_conntrack_helper.h> + +#include <net/rtl/features/rtl_features.h> +#if defined(CONFIG_RTL_FASTBRIDGE) +#include <net/rtl/features/fast_bridge.h> +#endif + +#define RTL_PS_HOOKS_CONTINUE 0 /* keep the process flow */ +#define RTL_PS_HOOKS_BREAK 1 /* should break from caller's loops */ +#define RTL_PS_HOOKS_RETURN 2 /* should immediately return from the caller function */ +#define RTL_PS_HOOKS_DROP 3 + +typedef struct { + struct net *net; + struct nf_conn *ct; + struct sk_buff *skb; + struct nf_conntrack_l3proto *l3proto; + struct nf_conntrack_l4proto *l4proto; + u_int8_t protonum; + u_int8_t pf; + unsigned int hooknum; + enum ip_conntrack_info ctinfo; + enum tcp_conntrack new_state; + enum tcp_conntrack old_state; +} rtl_nf_conntrack_inso_s; + +int32 rtl_nf_conntrack_in_hooks(rtl_nf_conntrack_inso_s *info); +int32 rtl_nf_conntrack_death_by_timeout_hooks(rtl_nf_conntrack_inso_s *info); +int32 rtl_nf_conntrack_destroy_hooks(rtl_nf_conntrack_inso_s *info); +int32 rtl_nf_conntrack_confirm_hooks(rtl_nf_conntrack_inso_s *info); +int32 rtl_nf_init_conntrack_hooks(rtl_nf_conntrack_inso_s *info); +int32 rtl_nf_conntrack_init_hooks(void); +int32 rtl_tcp_packet_hooks(rtl_nf_conntrack_inso_s *info); +int32 rtl_nf_nat_packet_hooks(rtl_nf_conntrack_inso_s *info); +int32 rtl_nat_init_hooks(void); +int32 rtl_nat_cleanup_hooks(void); + +int32 rtl_fn_hash_insert_hooks(struct fib_table *tb, struct fib_config *cfg, struct fib_info *fi); +int32 rtl_fn_hash_delete_hooks(struct fib_table *tb, struct fib_config *cfg); +int32 rtl_fn_flush_list_hooks(int fz_order, int idx, u32 tb_id, u32 fn_key); +int32 rtl_fn_hash_replace_hooks(struct fib_table *tb, struct fib_config *cfg, struct fib_info *fi); + +int32 rtl_dev_queue_xmit_hooks(struct sk_buff *skb, struct net_device *dev); +int32 rtl_dev_hard_start_xmit_hooks(struct sk_buff *skb, struct net_device *dev, struct netdev_queue *txq); +int32 rtl_netif_receive_skb_hooks(struct sk_buff **pskb); + +int32 rtl_br_dev_queue_push_xmit_before_xmit_hooks(struct sk_buff *skb); + +#ifdef CONFIG_NET_SCHED +extern int gQosEnabled; +#endif +int32 rtl_neigh_forced_gc_hooks(struct neigh_table *tbl, struct neighbour *n); +int32 rtl_neigh_flush_dev_hooks(struct neigh_table *tbl, struct net_device *dev, struct neighbour *n); +int32 rtl_neigh_destroy_hooks(struct neighbour *n); +int32 rtl_neigh_connect_hooks(struct neighbour *neigh); +int32 rtl_neigh_timer_handler_pre_update_hooks(struct neighbour *neigh, unsigned state); +int32 rtl_neigh_timer_handler_during_update_hooks(struct neighbour *neigh, unsigned state); +int32 rtl_neigh_timer_handler_post_update_hooks(struct neighbour *neigh, unsigned state); +int32 rtl___neigh_event_send_pre_hooks(struct neighbour *neigh, struct sk_buff *skb); +int32 rtl___neigh_event_send_post_hooks(struct neighbour *neigh, struct sk_buff *skb); +int32 rtl_neigh_update_hooks(struct neighbour *n, const u8 *lladdr, uint8 old); +int32 rtl_neigh_update_post_hooks(struct neighbour *n, const u8 *lladdr, uint8 old); +int32 rtl_neigh_periodic_timer_hooks(struct neighbour *n, unsigned int refresh); +int32 rtl_neigh_init_hooks(void); +#if defined(CONFIG_BRIDGE) +int32 rtl___br_fdb_get_timeout_hooks(struct net_bridge *br, struct net_bridge_fdb_entry *fdb, const unsigned char *addr); +#endif +int32 rtl_translate_table_hooks(const char *name, + unsigned int valid_hooks, + struct xt_table_info *newinfo, + void *entry0, + unsigned int size, + unsigned int number, + const unsigned int *hook_entries, + const unsigned int *underflows); + +int32 rtl_ip_tables_init_hooks(void); + +int32 rtl_masq_device_event_hooks(struct notifier_block *this, struct net_device *dev, unsigned long event); +int32 rtl_masq_inet_event_hooks(struct notifier_block *this, unsigned long event, void *ptr); + +#if defined(CONFIG_IP_VS) +int32 rtl_ip_vs_conn_expire_hooks1(struct ip_vs_conn *cp); +int32 rtl_ip_vs_conn_expire_hooks2(struct ip_vs_conn *cp); +#endif + +#if defined(CONFIG_IP_VS_PROTO_TCP) +int32 rtl_tcp_state_transition_hooks(struct ip_vs_conn *cp, int direction, const struct sk_buff *skb, struct ip_vs_protocol *pp); +#endif + +#if defined(CONFIG_IP_VS_PROTO_UDP) +int32 rtl_udp_state_transition_hooks(struct ip_vs_conn *cp, int direction, const struct sk_buff *skb, struct ip_vs_protocol *pp); +#endif + +#ifdef CONFIG_PROC_FS +int rtl_ct_seq_show_hooks(struct seq_file *s, struct nf_conn *ct); +#endif +#if 0 +int rtl_get_unique_tuple_hooks(struct nf_conntrack_tuple *tuple, + const struct nf_conntrack_tuple *orig_tuple, + const struct nf_nat_range *range, + struct nf_conn *ct, + enum nf_nat_manip_type maniptype, + struct nf_nat_protocol *proto); + +#endif + +int32 rtl_dst_alloc_gc_pre_check_hooks(struct dst_ops * ops); +int32 rtl_dst_alloc_gc_post_check1_hooks(struct dst_ops * ops); +int32 rtl_dst_alloc_gc_post_check2_hooks(struct dst_ops * ops, struct dst_entry * dst); + +#if defined(CONFIG_RTL_NF_CONNTRACK_GARBAGE_NEW) +int32 clean_from_lists_hooks(struct nf_conn *ct, struct net *net); +int32 __nf_ct_refresh_acct_proto_hooks(struct nf_conn *ct, + enum ip_conntrack_info ctinfo, + const struct sk_buff *skb, + int do_acct, + int *event); +int32 __drop_one_conntrack_process_hooks1(struct nf_conn* ct, int dropPrioIdx, int factor, int checkFlags, int tcpUdpState); +int32 __drop_one_conntrack_process_hooks2(struct nf_conn* ct, int dropPrioIdx, int factor, int checkFlags, int tcpUdpState); +int32 rtl_nf_conn_GC_init_hooks(void); +#endif + +#if defined(CONFIG_BRIDGE) +int32 rtl_fdb_delete_hooks(struct net_bridge_fdb_entry *f); +int32 rtl_br_fdb_cleanup_hooks(struct net_bridge *br, struct net_bridge_fdb_entry *f); +#endif + +#endif + + diff --git a/target/linux/realtek/files/include/net/rtl/rtk_stp.h b/target/linux/realtek/files/include/net/rtl/rtk_stp.h new file mode 100644 index 000000000..c671a7c20 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtk_stp.h @@ -0,0 +1,39 @@ +/*
+ * Headler file of Realtek STP
+ *
+ * $Id: rtk_stp.h,v 1.3 2009/06/01 07:00:27 davidhsu Exp $
+ */
+
+#ifndef _RTK_STP_H
+#define _RTK_STP_H
+#include "rtl_types.h"
+
+#ifdef CONFIG_RTK_MESH
+#define MAX_RE865X_STP_PORT 7
+#define WLAN_MESH_PSEUDO_IF_INDEX 6
+#define WLAN_MESH_IF_NAME "wlan0-msh0"
+#else
+#define MAX_RE865X_STP_PORT 6
+#endif
+
+#define MAX_RE865X_ETH_STP_PORT 5
+#define WLAN_PSEUDO_IF_INDEX 5
+#define WLAN_IF_NAME "wlan0"
+
+#define NO_MAPPING -1
+
+#define MAX_RTL_STP_PORT_WH 5
+
+#define RTL8651_PORTSTA_DISABLED 0x00 +#define RTL8651_PORTSTA_BLOCKING 0x01 +#define RTL8651_PORTSTA_LISTENING 0x02 +#define RTL8651_PORTSTA_LEARNING 0x03 +#define RTL8651_PORTSTA_FORWARDING 0x04
+
+extern int8 STP_PortDev_Mapping[MAX_RE865X_STP_PORT];
+
+int32 rtl865x_setSpanningEnable(int8 spanningTreeEnabled);
+int32 rtl865x_setMulticastSpanningTreePortState(uint32 port, uint32 portState);
+int32 rtl865x_setSpanningTreePortState(uint32 port, uint32 portState);
+
+#endif // _RTK_STP_H
diff --git a/target/linux/realtek/files/include/net/rtl/rtk_vlan.h b/target/linux/realtek/files/include/net/rtl/rtk_vlan.h new file mode 100644 index 000000000..71764b61f --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtk_vlan.h @@ -0,0 +1,38 @@ +/*
+ * Headler file of Realtek VLAN
+ *
+ * $Id: rtk_vlan.h,v 1.3 2009/06/01 07:00:27 davidhsu Exp $
+ */
+
+#ifndef _RTK_VLAN_H
+#define _RTK_VLAN_H
+#include "rtl_types.h"
+
+struct vlan_info {
+ int global_vlan; // 0/1 - global vlan disable/enable
+ int is_lan; // 1: eth-lan/wlan port, 0: wan port
+ int vlan; // 0/1: disable/enable vlan
+ int tag; // 0/1: disable/enable tagging
+ int id; // 1~4090: vlan id
+ int pri; // 0~7: priority;
+ int cfi; // 0/1: cfi
+};
+
+struct _vlan_tag {
+ unsigned short tpid; // protocol id
+ unsigned short pci; // priority:3, cfi:1, id:12
+};
+
+struct vlan_tag {
+ union
+ {
+ unsigned long v;
+ struct _vlan_tag f;
+ };
+};
+
+#if defined(CONFIG_RTL_HW_STP)
+uint32 rtl865x_getVlanPortMask(uint32 vid);
+#endif
+
+#endif // _RTK_VLAN_H
diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_arp_api.h b/target/linux/realtek/files/include/net/rtl/rtl865x_arp_api.h new file mode 100644 index 000000000..73ed95a2b --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_arp_api.h @@ -0,0 +1,27 @@ +#ifndef RTL865X_ARP_API_H +#define RTL865X_ARP_API_H + +#define RTL865X_ARPTBL_SIZE 512 + +typedef struct rtl865x_arpMapping_entry_s +{ + ipaddr_t ip; + ether_addr_t mac; +}rtl865x_arpMapping_entry_t; + + +struct rtl865x_arp_table { + uint8 allocBitmap[64]; + rtl865x_arpMapping_entry_t mappings[512]; +}; + +/*for linux protocol stack sync*/ +int32 rtl865x_addArp(ipaddr_t ip, ether_addr_t * mac); +int32 rtl865x_delArp(ipaddr_t ip); +uint32 rtl865x_arpSync( ipaddr_t ip, uint32 refresh ); +int32 rtl865x_getArpMapping(ipaddr_t ip, rtl865x_arpMapping_entry_t * arp_mapping); +#if defined(CONFIG_RTL_MULTIPLE_WAN) +int32 rtl_set_callback_for_ps_arp(int (*call_back_fn)(u32 ip,rtl865x_arpMapping_entry_t *entry)); +#endif + +#endif diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_fdb_api.h b/target/linux/realtek/files/include/net/rtl/rtl865x_fdb_api.h new file mode 100644 index 000000000..b2fb2390a --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_fdb_api.h @@ -0,0 +1,43 @@ + +#ifndef RTL865X_FDB_API_H +#define RTL865X_FDB_API_H + +#define RTL_LAN_FID 0 +#if defined (CONFIG_RTL_IVL_SUPPORT) +#define RTL_WAN_FID 1 +#else +#define RTL_WAN_FID 0 +#endif + +#define FDB_STATIC 0x01 /* flag for FDB: process static entry only */ +#define FDB_DYNAMIC 0x02 /* flag for FDB: process dynamic entry only */ + +void update_hw_l2table(const char *srcName,const unsigned char *addr); +int32 rtl_get_hw_fdb_age(uint32 fid,ether_addr_t *mac, uint32 flags); +int32 rtl865x_addAuthFDBEntry(const unsigned char *addr, int32 auth, int32 port); +int32 rtl865x_setRestrictPortNum(int32 port, uint8 isEnable, int32 number); +int32 rtl865x_check_authfdbentry_Byport(int32 port_num, const unsigned char *macAddr); +int32 rtl865x_enableLanPortNumRestrict(uint8 isEnable); + +#if defined(CONFIG_RTL865X_LANPORT_RESTRICTION) +#define LAN_RESTRICT_PORT_NUMBER 9 + +typedef struct _lan_restrict_info +{ + int16 port_num; + int16 enable; + int32 max_num; + int32 curr_num; +}lan_restrict_info; + +extern lan_restrict_info lan_restrict_tbl[LAN_RESTRICT_PORT_NUMBER]; + +int32 rtl_check_fdb_entry_check_exist(uint32 fid, ether_addr_t *mac, uint32 flags); +int32 rtl_check_fdb_entry_check_srcBlock(uint32 fid, ether_addr_t *mac, int32 *SrcBlk); +int32 lanrestrict_callbackFn_for_add_fdb(void *param); +int32 lanrestrict_callbackFn_for_del_fdb(void *param); +int32 lanrestrict_unRegister_event(void); +int32 lanrestrict_register_event(void); +#endif /* defined(CONFIG_RTL865X_LANPORT_RESTRICTION) */ + +#endif diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_igmpsnooping.h b/target/linux/realtek/files/include/net/rtl/rtl865x_igmpsnooping.h new file mode 100644 index 000000000..9b5fcf7f9 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_igmpsnooping.h @@ -0,0 +1,151 @@ +/* +* Copyright c Realsil Semiconductor Corporation, 2006 +* All rights reserved. +* +* Program : igmp snooping function +* Abstract : +* Author :qinjunjie +* Email:qinjunjie1980@hotmail.com +* +*/ + +#ifndef RTL865X_IGMP_SNOOPING_H +#define RTL865X_IGMP_SNOOPING_H + +/* multicast configuration*/ +struct rtl_mCastSnoopingGlobalConfig +{ + uint32 maxGroupNum; + uint32 maxClientNum; + uint32 maxSourceNum; + uint32 hashTableSize; + + uint32 groupMemberAgingTime; + uint32 lastMemberAgingTime; + uint32 querierPresentInterval; + + uint32 dvmrpRouterAgingTime; + uint32 mospfRouterAgingTime; + uint32 pimRouterAgingTime; +}; + +struct rtl_mCastSnoopingLocalConfig +{ + uint8 enableSourceList; + uint8 enableFastLeave; + uint8 gatewayMac[6]; + uint32 gatewayIpv4Addr; + uint32 gatewayIpv6Addr[4]; + //uint32 unknownMcastFloodMap; + uint32 ipv4UnknownMcastFloodMap; + uint32 ipv6UnknownMcastFloodMap; + uint32 staticRouterPortMask; +}; + + struct rtl_mCastTimerParameters + { + uint32 disableExpire; + uint32 groupMemberAgingTime; + uint32 lastMemberAgingTime; + uint32 querierPresentInterval; + + uint32 dvmrpRouterAgingTime; /*DVMRP multicast router aging time*/ + uint32 mospfRouterAgingTime; /*MOSPF multicast router aging time*/ + uint32 pimRouterAgingTime; /*PIM-DM multicast router aging time*/ + +}; + +#define IP_VERSION4 4 +#define IP_VERSION6 6 + +struct rtl_multicastDataInfo +{ + uint32 ipVersion; + uint32 sourceIp[4]; + uint32 groupAddr[4]; + +}; + +struct rtl_multicastFwdInfo +{ + uint8 unknownMCast; + uint8 reservedMCast; + uint16 cpuFlag; + uint32 fwdPortMask; + +}; + +struct rtl_groupInfo +{ + uint32 ownerMask; +}; + +typedef struct rtl_multicastDeviceInfo_s +{ + char devName[32]; + uint32 vlanId; + uint32 portMask; + uint32 swPortMask; +}rtl_multicastDeviceInfo_t; + + +typedef struct rtl_multicastEventContext_s +{ + char devName[16]; + uint32 moduleIndex; + uint32 ipVersion; + uint32 groupAddr[4]; + uint32 sourceAddr[4]; + uint32 portMask; +}rtl_multicastEventContext_t; + + +typedef struct rtl_igmpPortInfo_s +{ + uint32 linkPortMask; +}rtl_igmpPortInfo_t; + +/****************************************************** + Function called in the system initialization +******************************************************/ + +int32 rtl_initMulticastSnooping(struct rtl_mCastSnoopingGlobalConfig mCastSnoopingGlobalConfig); +int32 rtl_exitMulticastSnooping(void); +void rtl_setMulticastParameters(struct rtl_mCastTimerParameters mCastTimerParameters); + +int32 rtl_registerIgmpSnoopingModule(uint32 *moduleIndex); + +int32 rtl_setIgmpSnoopingModuleDevInfo(uint32 moduleIndex,rtl_multicastDeviceInfo_t *devInfo); +int32 rtl_getIgmpSnoopingModuleDevInfo(uint32 moduleIndex,rtl_multicastDeviceInfo_t *devInfo); + +int32 rtl_getDeviceIgmpSnoopingModuleIndex(rtl_multicastDeviceInfo_t *devInfo,uint32 *moduleIndex); + +int32 rtl_unregisterIgmpSnoopingModule(uint32 moduleIndex); + +int32 rtl_configIgmpSnoopingModule(uint32 moduleIndex, struct rtl_mCastSnoopingLocalConfig *multicastSnoopingConfig); + +int32 rtl_igmpMldProcess(uint32 moduleIndex, uint8 * macFrame, uint32 portNum, uint32 *fwdPortMask); + +int32 rtl_getMulticastDataFwdInfo(uint32 moduleIndex, struct rtl_multicastDataInfo * multicastDataInfo, struct rtl_multicastFwdInfo *multicastFwdInfo); + +int32 rtl_maintainMulticastSnoopingTimerList(uint32 currentSystemTime); + + +#ifdef CONFIG_PROC_FS +int igmp_show(struct seq_file *s, void *v); +int igmp_write(struct file *file, const char __user *buffer, size_t count, loff_t *data); +#endif + +int32 rtl_getGroupInfo(uint32 groupAddr, struct rtl_groupInfo *groupInfo); +int32 rtl_flushAllIgmpRecord(void); +int32 rtl_delIgmpRecordByMacAddr(uint8 *macAddr); + +int32 rtl_addSpecialMCast(uint32 moduleIndex, uint32 ipVersion, uint32 *groupAddr, uint32 fwdPortMask); +int32 rtl_delSpecialMCast(uint32 moduleIndex, uint32 ipVersion, uint32 *groupAddr); + +int32 rtl_setIpv4UnknownMCastFloodMap(uint32 moduleIndex,uint32 unknownMCastFloodMap); +int32 rtl_getIpv4UnknownMCastFloodMap(uint32 moduleIndex,uint32 *unknownMCastFloodMap); +int32 rtl_setIpv6UnknownMCastFloodMap(uint32 moduleIndex,uint32 unknownMCastFloodMap); +int32 rtl_getIpv6UnknownMCastFloodMap(uint32 moduleIndex,uint32 *unknownMCastFloodMap); +#endif + diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_igmpsnooping_glue.h b/target/linux/realtek/files/include/net/rtl/rtl865x_igmpsnooping_glue.h new file mode 100644 index 000000000..c648df3f2 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_igmpsnooping_glue.h @@ -0,0 +1,113 @@ +/* +* Copyright c Realsil Semiconductor Corporation, 2006 +* All rights reserved. +* +* Program : IGMP glue file +* Abstract : +* Author :qinjunjie +* Email:qinjunjie1980@hotmail.com +* +*/ + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef SUCCESS +#define SUCCESS 0 +#endif + +#ifndef FAILED +#define FAILED -1 +#endif + + +#if 0 +#ifndef _RTL_TYPES_H +typedef unsigned int uint32; +typedef int int32; +typedef unsigned short uint16; +typedef short int16; +typedef unsigned char uint8; +typedef char int8; +#endif +#else +#include "rtl_types.h" +#endif + +#ifndef RTL_MULTICAST_SNOOPING_GLUE +#define RTL_MULTICAST_SNOOPING_GLUE + + +#define swapl32(x)\ + ((((x) & 0xff000000U) >> 24) | \ + (((x) & 0x00ff0000U) >> 8) | \ + (((x) & 0x0000ff00U) << 8) | \ + (((x) & 0x000000ffU) << 24)) +#define swaps16(x) \ + ((((x) & 0xff00) >> 8) | \ + (((x) & 0x00ff) << 8)) + +#ifdef _LITTLE_ENDIAN + +#ifndef ntohs + #define ntohs(x) (swaps16(x)) +#endif + +#ifndef ntohl + #define ntohl(x) (swapl32(x)) +#endif + +#ifndef htons + #define htons(x) (swaps16(x)) +#endif + +#ifndef htonl + #define htonl(x) (swapl32(x)) +#endif + +#else + +#ifndef ntohs + #define ntohs(x) (x) +#endif + +#ifndef ntohl + #define ntohl(x) (x) +#endif + +#ifndef htons + #define htons(x) (x) +#endif + +#ifndef htonl + #define htonl(x) (x) +#endif + +#endif + +#ifdef __KERNEL__ + #define rtl_gluePrintf printk +#else + #define rtl_gluePrintf printf +#endif + + +void *rtl_glueMalloc(uint32 NBYTES); +void rtl_glueFree(void *memblock); + +void rtl_glueMutexLock(void); +void rtl_glueMutexUnlock(void); + +#endif + + + diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_ip_api.h b/target/linux/realtek/files/include/net/rtl/rtl865x_ip_api.h new file mode 100644 index 000000000..b0aaed8c2 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_ip_api.h @@ -0,0 +1,11 @@ +#ifndef RTL865X_IP_API_H +#define RTL865X_IP_API_H + +#define IP_TYPE_NAPT 0x00 +#define IP_TYPE_NAT 0x01 +#define IP_TYPE_LOCALSERVER 0x02 +#define IP_TYPE_RESERVED 0x03 + +int32 rtl865x_addIp(ipaddr_t intIp, ipaddr_t extIp, uint32 ip_type); +int32 rtl865x_delIp(ipaddr_t extIp); +#endif diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_localPublic.h b/target/linux/realtek/files/include/net/rtl/rtl865x_localPublic.h new file mode 100644 index 000000000..8d638ada8 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_localPublic.h @@ -0,0 +1,117 @@ +#ifndef RTL865X_LOCAL_PUBLIC_H
+#define RTL865X_LOCAL_PUBLIC_H
+
+#if defined(CONFIG_RTL_HW_QOS_SUPPORT)
+#include <common/rtl865x_netif.h>
+#endif
+
+#define FROM_LOCAL_PUBLIC 1
+#define TO_LOCAL_PUBLIC 2
+#define RX_LAN_PACKET 1
+#define RX_WAN_PACKET 2
+#define TX_LAN_PACKET 3
+#define TX_WAN_PACKET 4
+
+#define MAX_HW_LOCAL_PUBLIC_NUM 2
+#define DEF_LOCAL_PUBLIC_NUM 32
+#define MAX_LOCAL_PUBLIC_NUM 32
+
+#define LOCAL_PUBLIC_VLAN_START 3198
+#define LOCAL_PUBLIC_VLAN_END 4094
+#define MCAST_NETIF_VLAN_ID 3197
+
+struct rtl865x_localPublic
+{
+ unsigned int ipAddr;
+ unsigned int netMask;
+ unsigned int defGateway;
+ unsigned int hw;
+ unsigned int inAsic;
+
+ unsigned char port;
+ unsigned char mac[6];
+ unsigned char dev[16];
+
+ unsigned char lpNetif[16];
+ unsigned int lpVid;
+ unsigned char defGwMac[6];
+
+ //must at the tail...
+ struct
+ {
+ struct rtl865x_localPublic *tqe_next;
+ struct rtl865x_localPublic**tqe_prev;
+ }next;
+
+};
+
+#if defined(CONFIG_RTL_PUBLIC_SSID)
+struct rtl865x_public_ssid_entry
+{
+ struct list_head list;
+ unsigned int public_addr;
+ unsigned int flags;
+};
+#endif
+
+struct rtl865x_pktInfo
+{
+ /*input parameter*/
+ unsigned char *data;
+ unsigned char port;
+ unsigned char action;
+ unsigned char dev[16];
+
+ /*output parameter*/
+ unsigned char *arpHdr;
+ unsigned char *ipHdr;
+ unsigned char fromLocalPublic;
+ unsigned char toLocalPublic;
+ unsigned int srcIp;
+ unsigned int dstIp;
+};
+
+struct rtl865x_localPublicPara
+{
+ unsigned int maxEntryNum;
+};
+
+struct rtl865x_interface_info
+{
+ unsigned char ifname[16];
+ unsigned char isWan;
+ unsigned short if_type;
+ unsigned short vid;
+ unsigned short fid;
+ unsigned int memPort;
+ unsigned int untagSet;
+ unsigned int mtu;
+};
+
+int rtl865x_initLocalPublic(struct rtl865x_localPublicPara* para);
+
+int rtl865x_reInitLocalPublic(void);
+
+int rtl865x_addLocalPublic(struct rtl865x_localPublic* newEntry);
+
+int rtl865x_delLocalPublic(struct rtl865x_localPublic* delEntry);
+
+int rtl865x_checkLocalPublic(struct rtl865x_pktInfo *pktInfo);
+
+int rtl865x_isLocalPublicIp(unsigned int ipAddr);
+
+int rtl865x_getLocalPublicInfo(unsigned int ipAddr, struct rtl865x_localPublic *localPublicInfo);
+
+int rtl865x_localPublicEnabled(void);
+int rtl865x_getLocalPublicMac(unsigned int ip, unsigned char mac[]);
+int rtl865x_getAllLocalPublic(struct rtl865x_localPublic localPublicArray[], int arraySize);
+#if defined(CONFIG_RTL_HW_QOS_SUPPORT)
+int rtl_checkLocalPublicNetifIngressRule(rtl865x_AclRule_t *rule);
+#endif
+#if defined(CONFIG_RTL_PUBLIC_SSID)
+int rtl865x_is_public_ssid_entry(unsigned int ipAddr);
+int rtl865x_from_public_ssid_device(unsigned char *name);
+#endif
+
+int rtl865x_setMCastSrcMac(unsigned char *srcMac);
+#endif
diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_multicast.h b/target/linux/realtek/files/include/net/rtl/rtl865x_multicast.h new file mode 100644 index 000000000..2b55ad5b8 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_multicast.h @@ -0,0 +1,360 @@ +#ifndef RTL865X_MULTICAST_H
+#define RTL865X_MULTICAST_H
+
+#define RTL865X_NETWORK_INTERFACE_DATA_STRUCTURE
+
+#define RTL865X_MULTICAST_TABLE_AGE 35
+#define RTL865X_MULTICAST_TABLE_ASIC_FULL_AGE 35
+#define RTL865X_MULTICAST_TABLE_ASIC_AGE 10 /* we would always write this value into ASIC */
+#define RTL865X_MULTICAST_SWAP_THRESHOLD 400
+#define SINGLE_BITMASK_ISSET(x) ((x & (x - 1)) == 0) /* chenyl: only 1 bit is set in vlanMask */
+
+
+/*================================================
+ * Multicast Data Structure
+ *================================================*/
+#define TBLDRV_MULTICAST_DATA_STRUCTURE
+
+/* mcast entry flag */
+#define RTL865X_MULTICAST_PPPOEPATCH_CPUBIT 0x01
+#define RTL865X_MULTICAST_EXTIP_SET 0x02
+#define RTL865X_MULTICAST_UPLOADONLY 0x04
+
+#define MAX_MCAST_FWD_DESCRIPTOR_CNT 256
+#define MAX_MCAST_TABLE_ENTRY_CNT 128
+
+ +/* + * List definitions. + */ +#define MC_LIST_HEAD(name, type) \
+struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define MC_LIST_HEAD_INITIALIZER(head) \
+ { NULL } + +#define MC_LIST_ENTRY(type) \
+struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ + +#define MC_LIST_EMPTY(head) ((head)->lh_first == NULL)
+ +#define MC_LIST_FIRST(head) ((head)->lh_first)
+ +#define MC_LIST_FOREACH(var, head, field) \
+ for((var) = (head)->lh_first; (var); (var) = (var)->field.le_next) + +#define MC_LIST_INIT(head) do { \
+ (head)->lh_first = NULL; \ +} while (0) + +#define MC_LIST_INSERT_AFTER(listelm, elm, field) do { \
+ if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ +} while (0) + +#define MC_LIST_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ +} while (0) + +#define MC_LIST_INSERT_HEAD(head, elm, field) do { \
+ if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ +} while (0) + +#define MC_LIST_NEXT(elm, field) ((elm)->field.le_next)
+ +#define MC_LIST_REMOVE(elm, field) do { \
+ if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \
+ if ((elm)->field.le_prev != NULL) \
+ *(elm)->field.le_prev = (elm)->field.le_next; \
+} while (0) +
+
+
+ +/* + * Counting Tail queue definitions. + */ +#define CTAILQ_HEAD(name, type) \ +struct name {\ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ + int tqh_count;\ +} + +#define CTAILQ_HEAD_INITIALIZER(head) \ + { 0, NULL, &(head).tqh_first } + +#define CTAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ +} + +/* + * Counting Tail queue functions. + */ +#define CTAILQ_EMPTY(head) ((head)->tqh_first == NULL) + +#define CTAILQ_FOREACH(var, head, field) \ + for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field)) + +#define CTAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define CTAILQ_FIRST(head) ((head)->tqh_first) +#define CTAILQ_TOTAL(head) ((head)->tqh_count) +#define CTAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + +#define CTAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define CTAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#define CTAILQ_INIT(head) do { \ + (head)->tqh_count=0;\ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (0) + +#define CTAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ + (head)->tqh_count++;\ +} while (0) + +#define CTAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_count++;\ +} while (0) + +#define CTAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ + (head)->tqh_count++; \ +} while (0) + +#define CTAILQ_INSERT_BEFORE(head, listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ + (head)->tqh_count++;\ +} while (0) + +#define CTAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + (head)->tqh_count--;\ +} while (0) +
+#define ETHERNET_DEVICE_TYPE 0
+#define WIRELESS_DEVICE_TYPE 1
+#define VIRTUAL_DEVICE_TYPE 2
+typedef struct rtl865x_mcast_fwd_descriptor_s{
+ char netifName[16];
+ unsigned int descPortMask;
+ char toCpu;
+ unsigned int vid;
+ unsigned int fwdPortMask;
+ MC_LIST_ENTRY(rtl865x_mcast_fwd_descriptor_s) next;
+
+}rtl865x_mcast_fwd_descriptor_t;
+
+typedef MC_LIST_HEAD(mcast_fwd_descriptor_head_s, rtl865x_mcast_fwd_descriptor_s) mcast_fwd_descriptor_head_t;
+
+/* + * Tail queue definitions. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ +} + +/* + * Tail queue functions. + */ +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) + +#define TAILQ_FOREACH(var, head, field) \ + for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define TAILQ_FIRST(head) ((head)->tqh_first) + +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#define TAILQ_INIT(head) do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ +} while (0) +
+typedef struct rtl865x_tblDrv_mCast_s {
+ unsigned int sip;
+ unsigned int dip;
+ unsigned short svid;
+ unsigned short port;
+ unsigned int mbr;
+ unsigned short age;
+ unsigned short cpu;
+ unsigned int extIp;
+ /*above field is for asic table usage*/
+ mcast_fwd_descriptor_head_t fwdDescChain;
+ unsigned int count;
+ unsigned int maxPPS;
+ unsigned char cpuHold;
+ unsigned char flag;
+ unsigned char inAsic;
+ unsigned char unKnownMCast;
+#if defined(CONFIG_RTL8196C_REVISION_B) || defined (CONFIG_RTL8198_REVISION_B)
+ unsigned short liveTime;
+#endif
+ TAILQ_ENTRY(rtl865x_tblDrv_mCast_s) nextMCast;
+
+} rtl865x_tblDrv_mCast_t;
+
+struct rtl865x_multicastTable{
+
+ struct freeList_s {
+
+ TAILQ_HEAD( _FreeMultiCastEntry, rtl865x_tblDrv_mCast_s) freeMultiCast;
+ } freeList;
+
+ struct inuseList_s {
+ TAILQ_HEAD( _InuseMCast, rtl865x_tblDrv_mCast_s) *mCastTbl;
+ }inuseList;
+
+};
+
+typedef struct rtl865x_mCastConfig_s{
+ unsigned int externalPortMask;
+
+}rtl865x_mCastConfig_t;
+
+int rtl865x_initMulticast(rtl865x_mCastConfig_t * mCastConfig);
+int rtl865x_reinitMulticast(void);
+
+int rtl865x_addMulticastExternalPort(unsigned int extPort);
+int rtl865x_delMulticastExternalPort(unsigned int extPort);
+
+int rtl865x_setMulticastExternalPortMask(unsigned int extPortMask);
+int rtl865x_getMulticastExternalPortMask(void);
+
+int rtl865x_addMulticastExternalPortMask(unsigned int extPortMask);
+int rtl865x_delMulticastExternalPortMask(unsigned int extPortMask);
+
+rtl865x_tblDrv_mCast_t *rtl865x_findMCastEntry(unsigned int mAddr, unsigned int sip, unsigned short svid, unsigned short sport);
+
+int rtl865x_addMulticastEntry(unsigned int mAddr, unsigned int sip, unsigned short svid, unsigned short sport,
+ rtl865x_mcast_fwd_descriptor_t * newFwdDescChain,
+ int flushOldChain, unsigned int extIp, char cpuHold, unsigned char flag);
+
+int rtl865x_delMulticastEntry(unsigned int mcast_addr);
+
+int rtl865x_genVirtualMCastFwdDescriptor(unsigned int forceToCpu, unsigned int fwdPortMask, rtl865x_mcast_fwd_descriptor_t *fwdDescriptor);
+int rtl865x_blockMulticastFlow(unsigned int srcVlanId, unsigned int srcPort,unsigned int srcIpAddr, unsigned int destIpAddr);
+
+#endif
+
diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_multipleWan_api.h b/target/linux/realtek/files/include/net/rtl/rtl865x_multipleWan_api.h new file mode 100644 index 000000000..c4c79ee92 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_multipleWan_api.h @@ -0,0 +1,260 @@ +/* +* Copyright c Realtek Semiconductor Corporation, 2010 +* All rights reserved. +* +* Program : multiple wan device driver header file +* Abstract : +* Author : hyking (hyking_liu@realsil.com.cn) +*/ + +#ifndef RTL865X_MULTIPLEWAN_API_H +#define RTL865X_MULTIPLEWAN_API_H +#include "rtl_types.h" + +#define RTL_ADVRT_MAC 0x00 +#define RTL_ADVRT_DSTFILTER_IPRANGE 0x01 +#define RTL_ADVRT_IP 0x02 +#define RTL_ADVRT_ICMP 0x04 +#define RTL_ADVRT_IGMP 0x05 +#define RTL_ADVRT_TCP 0x06 +#define RTL_ADVRT_UDP 0x07 +#define RTL_ADVRT_SRCFILTER 0x08 +#define RTL_ADVRT_DSTFILTER 0x09 +#define RTL_ADVRT_IP_RANGE 0x0A +#define RTL_ADVRT_SRCFILTER_IPRANGE 0x0B +#define RTL_ADVRT_ICMP_IPRANGE 0x0C +#define RTL_ADVRT_IGMP_IPRANGE 0x0D +#define RTL_ADVRT_TCP_IPRANGE 0x0E +#define RTL_ADVRT_UDP_IPRANGE 0x0F + + +typedef struct _rtl_advRoute_entry +{ + union + { + /* MAC rule */ + struct { + ether_addr_t _dstMac, _dstMacMask; + ether_addr_t _srcMac, _srcMacMask; + uint16 _typeLen, _typeLenMask; + } MAC; + + /* IP Group rule */ + struct + { + ipaddr_t _srcIpAddr, _srcIpAddrMask; + ipaddr_t _dstIpAddr, _dstIpAddrMask; + uint8 _tos, _tosMask; + union + { + /* IP rle */ + struct + { + uint8 _proto, _protoMask, _flagMask;// flag & flagMask only last 3-bit is meaning ful + uint32 _FOP:1, _FOM:1, _httpFilter:1, _httpFilterM:1, _identSrcDstIp:1, _identSrcDstIpM:1; + union + { + uint8 _flag; + struct + { + uint8 pend1:5, + pend2:1, + _DF:1, //don't fragment flag + _MF:1; //more fragments flag + } s; + } un; + } ip; + + /* ICMP rule */ + struct + { + uint8 _type, _typeMask, _code, _codeMask; + } icmp; + + /* IGMP rule */ + struct + { + uint8 _type, _typeMask; + } igmp; + + /* TCP rule */ + struct + { + uint8 _flagMask; + uint16 _srcPortUpperBound, _srcPortLowerBound; + uint16 _dstPortUpperBound, _dstPortLowerBound; + union + { + uint8 _flag; + struct + { + uint8 _pend:2, + _urg:1, //urgent bit + _ack:1, //ack bit + _psh:1, //push bit + _rst:1, //reset bit + _syn:1, //sync bit + _fin:1; //fin bit + }s; + }un; + }tcp; + + /* UDP rule */ + struct + { + uint16 _srcPortUpperBound, _srcPortLowerBound; + uint16 _dstPortUpperBound, _dstPortLowerBound; + }udp; + }is; + }L3L4; + + /* Source filter rule */ + struct + { + ether_addr_t _srcMac, _srcMacMask; + uint16 _srcPort, _srcPortMask; + uint16 _srcVlanIdx, _srcVlanIdxMask; + ipaddr_t _srcIpAddr, _srcIpAddrMask; + uint16 _srcPortUpperBound, _srcPortLowerBound; + uint32 _ignoreL4:1, //L2 rule + _ignoreL3L4:1; //L3 rule + } SRCFILTER; + + /* Destination filter rule */ + struct + { + ether_addr_t _dstMac, _dstMacMask; + uint16 _vlanIdx, _vlanIdxMask; + ipaddr_t _dstIpAddr, _dstIpAddrMask; + uint16 _dstPortUpperBound, _dstPortLowerBound; + uint32 _ignoreL4:1, //L3 rule + _ignoreL3L4:1; //L2 rule + } DSTFILTER; +#if defined(CONFIG_RTL_QOS_8021P_SUPPORT) + struct { + uint8 vlanTagPri; + } VLANTAG; +#endif + }un_ty; + + + uint32 valid_:1, + ruleType_:5, + pktOpApp_:3; + + ipaddr_t extIp; /*which ip address is used when napt*/ + ipaddr_t nexthop; /* next hop IP address */ + char outIfName[16]; /*out interface name, it should the netif name in driver*/ +}rtl_advRoute_entry_t; + +/* MAC ACL rule Definition */ +#define advrt_dstMac_ un_ty.MAC._dstMac +#define advrt_dstMacMask_ un_ty.MAC._dstMacMask +#define advrt_srcMac_ un_ty.MAC._srcMac +#define advrt_srcMacMask_ un_ty.MAC._srcMacMask +#define advrt_typeLen_ un_ty.MAC._typeLen +#define advrt_typeLenMask_ un_ty.MAC._typeLenMask + +/* Common IP ACL Rule Definition */ +#define advrt_srcIpAddr_ un_ty.L3L4._srcIpAddr +#define advrt_srcIpAddrMask_ un_ty.L3L4._srcIpAddrMask +#define advrt_srcIpAddrUB_ un_ty.L3L4._srcIpAddr +#define advrt_srcIpAddrLB_ un_ty.L3L4._srcIpAddrMask +#define advrt_dstIpAddr_ un_ty.L3L4._dstIpAddr +#define advrt_dstIpAddrMask_ un_ty.L3L4._dstIpAddrMask +#define advrt_dstIpAddrUB_ un_ty.L3L4._dstIpAddr +#define advrt_dstIpAddrLB_ un_ty.L3L4._dstIpAddrMask +#define advrt_tos_ un_ty.L3L4._tos +#define advrt_tosMask_ un_ty.L3L4._tosMask +/* IP Rrange */ +/*Hyking:Asic use Addr to srore Upper address + and use Mask to store Lower address +*/ +#define advrt_srcIpAddrStart_ un_ty.L3L4._srcIpAddrMask +#define advrt_srcIpAddrEnd_ un_ty.L3L4._srcIpAddr +#define advrt_dstIpAddrStart_ un_ty.L3L4._dstIpAddrMask +#define advrt_dstIpAddrEnd_ un_ty.L3L4._dstIpAddr + +/* IP ACL Rule Definition */ +#define advrt_ipProto_ un_ty.L3L4.is.ip._proto +#define advrt_ipProtoMask_ un_ty.L3L4.is.ip._protoMask +#define advrt_ipFlagMask_ un_ty.L3L4.is.ip._flagMask +#define advrt_ipFOP_ un_ty.L3L4.is.ip._FOP +#define advrt_ipFOM_ un_ty.L3L4.is.ip._FOM +#define advrt_ipHttpFilter_ un_ty.L3L4.is.ip._httpFilter +#define advrt_ipHttpFilterM_ un_ty.L3L4.is.ip._httpFilterM +#define advrt_ipIdentSrcDstIp_ un_ty.L3L4.is.ip._identSrcDstIp +#define advrt_ipIdentSrcDstIpM_ un_ty.L3L4.is.ip._identSrcDstIpM +#define advrt_ipFlag_ un_ty.L3L4.is.ip.un._flag +#define advrt_ipDF_ un_ty.L3L4.is.ip.un.s._DF +#define advrt_ipMF_ un_ty.L3L4.is.ip.un.s._MF + +/* ICMP ACL Rule Definition */ +#define advrt_icmpType_ un_ty.L3L4.is.icmp._type +#define advrt_icmpTypeMask_ un_ty.L3L4.is.icmp._typeMask +#define advrt_icmpCode_ un_ty.L3L4.is.icmp._code +#define advrt_icmpCodeMask_ un_ty.L3L4.is.icmp._codeMask + +/* IGMP ACL Rule Definition */ +#define advrt_igmpType_ un_ty.L3L4.is.igmp._type +#define advrt_igmpTypeMask_ un_ty.L3L4.is.igmp._typeMask + +/* TCP ACL Rule Definition */ +#define advrt_tcpSrcPortUB_ un_ty.L3L4.is.tcp._srcPortUpperBound +#define advrt_tcpSrcPortLB_ un_ty.L3L4.is.tcp._srcPortLowerBound +#define advrt_tcpDstPortUB_ un_ty.L3L4.is.tcp._dstPortUpperBound +#define advrt_tcpDstPortLB_ un_ty.L3L4.is.tcp._dstPortLowerBound +#define advrt_tcpFlagMask_ un_ty.L3L4.is.tcp._flagMask +#define advrt_tcpFlag_ un_ty.L3L4.is.tcp.un._flag +#define advrt_tcpURG_ un_ty.L3L4.is.tcp.un.s._urg +#define advrt_tcpACK_ un_ty.L3L4.is.tcp.un.s._ack +#define advrt_tcpPSH_ un_ty.L3L4.is.tcp.un.s._psh +#define advrt_tcpRST_ un_ty.L3L4.is.tcp.un.s._rst +#define advrt_tcpSYN_ un_ty.L3L4.is.tcp.un.s._syn +#define advrt_tcpFIN_ un_ty.L3L4.is.tcp.un.s._fin + +/* UDP ACL Rule Definition */ +#define advrt_udpSrcPortUB_ un_ty.L3L4.is.udp._srcPortUpperBound +#define advrt_udpSrcPortLB_ un_ty.L3L4.is.udp._srcPortLowerBound +#define advrt_udpDstPortUB_ un_ty.L3L4.is.udp._dstPortUpperBound +#define advrt_udpDstPortLB_ un_ty.L3L4.is.udp._dstPortLowerBound + +/* Source Filter ACL Rule Definition */ +#define advrt_srcFilterMac_ un_ty.SRCFILTER._srcMac +#define advrt_srcFilterMacMask_ un_ty.SRCFILTER._srcMacMask +#define advrt_srcFilterPort_ un_ty.SRCFILTER._srcPort +#define advrt_srcFilterPortMask_ un_ty.SRCFILTER._srcPortMask +#define advrt_srcFilterVlanIdx_ un_ty.SRCFILTER._srcVlanIdx +#define advrt_srcFilterVlanId_ un_ty.SRCFILTER._srcVlanIdx +#define advrt_srcFilterVlanIdxMask_ un_ty.SRCFILTER._srcVlanIdxMask +#define advrt_srcFilterVlanIdMask_ un_ty.SRCFILTER._srcVlanIdxMask +#define advrt_srcFilterIpAddr_ un_ty.SRCFILTER._srcIpAddr +#define advrt_srcFilterIpAddrMask_ un_ty.SRCFILTER._srcIpAddrMask +#define advrt_srcFilterIpAddrUB_ un_ty.SRCFILTER._srcIpAddr +#define advrt_srcFilterIpAddrLB_ un_ty.SRCFILTER._srcIpAddrMask +#define advrt_srcFilterPortUpperBound_ un_ty.SRCFILTER._srcPortUpperBound +#define advrt_srcFilterPortLowerBound_ un_ty.SRCFILTER._srcPortLowerBound +#define advrt_srcFilterIgnoreL3L4_ un_ty.SRCFILTER._ignoreL3L4 +#define advrt_srcFilterIgnoreL4_ un_ty.SRCFILTER._ignoreL4 + +/* Destination Filter ACL Rule Definition */ +#define advrt_dstFilterMac_ un_ty.DSTFILTER._dstMac +#define advrt_dstFilterMacMask_ un_ty.DSTFILTER._dstMacMask +#define advrt_dstFilterVlanIdx_ un_ty.DSTFILTER._vlanIdx +#define advrt_dstFilterVlanIdxMask_ un_ty.DSTFILTER._vlanIdxMask +#define advrt_dstFilterVlanId_ un_ty.DSTFILTER._vlanIdx +#define advrt_dstFilterVlanIdMask_ un_ty.DSTFILTER._vlanIdxMask +#define advrt_dstFilterIpAddr_ un_ty.DSTFILTER._dstIpAddr +#define advrt_dstFilterIpAddrMask_ un_ty.DSTFILTER._dstIpAddrMask +#define advrt_dstFilterPortUpperBound_ un_ty.DSTFILTER._dstPortUpperBound +#define advrt_dstFilterIpAddrUB_ un_ty.DSTFILTER._dstIpAddr +#define advrt_dstFilterIpAddrLB_ un_ty.DSTFILTER._dstIpAddrMask +#define advrt_dstFilterPortLowerBound_ un_ty.DSTFILTER._dstPortLowerBound +#define advrt_dstFilterIgnoreL3L4_ un_ty.DSTFILTER._ignoreL3L4 +#define advrt_dstFilterIgnoreL4_ un_ty.DSTFILTER._ignoreL4 +#if defined(CONFIG_RTL_QOS_8021P_SUPPORT) +#define advrt_vlanTagPri_ un_ty.VLANTAG.vlanTagPri +#endif + + +#endif diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_nat.h b/target/linux/realtek/files/include/net/rtl/rtl865x_nat.h new file mode 100644 index 000000000..1471a8fee --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_nat.h @@ -0,0 +1,122 @@ +#ifndef RTL865X_NAT_H +#define RTL865X_NAT_H + +#define FLAG_QOS_ENABLE 1 + +/* NAT timeout value */ +#define TCP_TIMEOUT 120 /* 120 secs */ +#define UDP_TIMEOUT 90 /* 90 secs */ +#define TCP_OVERRIDE_ELASPED_THRESHOLD 60 /* 60 secs */ +#define UDP_OVERRIDE_ELASPED_THRESHOLD 30 /* 30 secs */ + +#define TCP_CLOSED_FLOW 8 + +#define RTL865X_PROTOCOL_UDP 0 +#define RTL865X_PROTOCOL_TCP 1 + +#define NAT_INBOUND 0x00000001 +#define NAT_OUTBOUND 0x00000002 +#define NAT_PRI_PROCESSED 0x00000004 +#define NAT_PRI_HALF_PROCESSED 0x00000008 + +#define NAT_PRE_RESERVED 0x00000100 +#define RESERVE_EXPIRE_TIME 3 /*uinit:seconds*/ + +#define NAT_INUSE(_n_) ( ((_n_)->flags&(NAT_INBOUND|NAT_OUTBOUND)) ) +#define SET_NAT_FLAGS(_n_, _v_) ((_n_)->flags |= (_v_)) +#define CLR_NAT_FLAGS(_n_, _v_) ((_n_)->flags &= (~(_v_))) +#define NAT_INVALID(_n_) ( ((_n_)->flags=0) ) + +#define MAX_EXTPORT_TRY_CNT 8 + +#define RTL_NAPT_ACCELERATION_FAIL -1 +#define RTL_NAPT_FULL_ACCELERATION 0 +#define RTL_NAPT_OUTBOUND_ACCELERATION 1 +#define RTL_NAPT_INBOUND_ACCELERATION 2 + +#define CONFIG_RTL_INBOUND_COLLISION_AVOIDANCE +#define CONFIG_RTL_HALF_NAPT_ACCELERATION + +typedef struct _rtl865x_napt_entry +{ + uint32 protocol; //RTL865X_PROTOCOL_UDP or RTL865X_PROTOCOL_TCP + ipaddr_t intIp; + uint32 intPort; + ipaddr_t extIp; + uint32 extPort; + ipaddr_t remIp; + uint32 remPort; +}rtl865x_napt_entry; + +typedef struct _rtl865x_priority +{ + int32 uplinkPrio; + int32 downlinkPrio; +}rtl865x_priority; + +typedef struct _rtl865x_qos_mark +{ + int32 uplinkMark; + int32 downlinkMark; +}rtl865x_qos_mark; + +int32 rtl865x_nat_init(void); +int32 rtl865x_nat_reinit(void); +/* +@func enum RTL_RESULT | rtl865x_addNaptConnection | Add a NAPT Flow +@parm enum RTL_NP_PROTOCOL | protocol | The protocol to add +@parm ipaddr_t | intIp | Internal IP address +@parm uint32 | intPort | Internal Port +@parm ipaddr_t | extIp | External IP address +@parm uint32 | extPort | External Port +@parm ipaddr_t | remIp | Remote IP address +@parm uint32 | remPort | Remote Port +@parm enum RTL_NP_FLAGS | flags | reserved for future used +@rvalue RTL_SUCCESS | Add success (can be ASIC-accelerated) +@rvalue RTL_SUCCESS | Add success (cannot be ASIC-accelerated) +@rvalue RTL_ERROR_PARAMETER | Error parameter is given +@rvalue RTL_EXIST | Add an existed flow +@rvalue RTL_FAILED | General failure +@comm + Add a NAPT Flow Entry to L4 TCP/UDP NAPT Table(1024-Entry) +@devnote + Insert into ip_nat_setup_info() function in file net/ipv4/netfilter/ip_nat_core.c +*/ +int32 rtl865x_addNaptConnection(rtl865x_napt_entry *naptEntry, rtl865x_priority *prio); +/* +@func enum RTL_RESULT | rtl865x_delNaptConnection | Delete a NAPT Flow +@parm enum RTL_NP_PROTOCOL | protocol | The protocol to delete +@parm ipaddr_t | intIp | Internal IP address +@parm uint32 | intPort | Internal Port +@parm ipaddr_t | extIp | External IP address +@parm uint32 | extPort | External Port +@parm ipaddr_t | remIp | Remote IP address +@parm uint32 | remPort | Remote Port +@rvalue RTL_SUCCESS | Delete success +@rvalue RTL_NONEXIST | Delete a non-existed flow +@rvalue RTL_FAILED | General failure +@comm + Delete a NAPT Flow Entry of L4 TCP/UDP NAPT Table(1024-Entry) +@devnote + Insert into ip_nat_cleanup_conntrack() function in file net/ipv4/netfilter/ip_nat_core.c +*/ +int32 rtl865x_delNaptConnection(rtl865x_napt_entry *naptEntry); + +int32 rtl865x_naptSync(rtl865x_napt_entry *naptEntry, uint32 refresh); + +#if defined (CONFIG_RTL_INBOUND_COLLISION_AVOIDANCE) +int rtl865x_optimizeExtPort(unsigned short origDelta, unsigned int rangeSize, unsigned short *newDelta); + +int rtl865x_getAsicNaptHashScore(rtl865x_napt_entry *naptEntry, + uint32 *naptHashScore); + +int32 rtl865x_preReserveConn(rtl865x_napt_entry *naptEntry); + +#endif +#if defined(CONFIG_RTL_HARDWARE_NAT) +int32 rtl_nat_expire_interval_update(int proto, int32 interval); +int32 rtl865x_nat_reinit(void); +#endif + +#endif + diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_netif.h b/target/linux/realtek/files/include/net/rtl/rtl865x_netif.h new file mode 100644 index 000000000..e2c0c956e --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_netif.h @@ -0,0 +1,527 @@ +/* +* Copyright c Realtek Semiconductor Corporation, 2008 +* All rights reserved. +* +* Program : network interface driver header file +* Abstract : +* Author : hyking (hyking_liu@realsil.com.cn) +*/ + +#ifndef RTL865X_NETIF_H +#define RTL865X_NETIF_H +#include "rtl_types.h" + +#define IF_NONE 0 +#define IF_ETHER 1 +#define IF_PPPOE 2 +#define IF_PPTP 3 +#define IF_L2TP 4 + +#define RTL865X_ACL_IPV6_USED -30000 +#define RTL865X_ACL_QOS_USED2 -20002 /* dummy queue for iptable 2 acl translate */ +#define RTL865X_ACL_QOS_USED1 -20000 /* for default queue */ +#define RTL865X_ACL_QOS_USED0 -20001 /* for user add queue */ +#define RTL865X_ACL_MULTIWAN_USED -15000 /*for multiwan*/ + +#define RTL865X_ACL_USER_USED 0 + +#if 1 //def CONFIG_RTL_LAYERED_DRIVER_ACL +typedef struct _rtl865x_AclRule_s +{ + union + { + /* MAC ACL rule */ + struct { + ether_addr_t _dstMac, _dstMacMask; + ether_addr_t _srcMac, _srcMacMask; + uint16 _typeLen, _typeLenMask; + } MAC; + + /* IP Group ACL rule */ + struct + { + ipaddr_t _srcIpAddr, _srcIpAddrMask; + ipaddr_t _dstIpAddr, _dstIpAddrMask; + uint8 _tos, _tosMask; + union + { + /* IP ACL rle */ + struct + { + uint8 _proto, _protoMask, _flagMask;// flag & flagMask only last 3-bit is meaning ful + uint32 _FOP:1, _FOM:1, _httpFilter:1, _httpFilterM:1, _identSrcDstIp:1, _identSrcDstIpM:1; + union + { + uint8 _flag; + struct + { + uint8 pend1:5, + pend2:1, + _DF:1, //don't fragment flag + _MF:1; //more fragments flag + } s; + } un; + } ip; + + /* ICMP ACL rule */ + struct + { + uint8 _type, _typeMask, _code, _codeMask; + } icmp; + + /* IGMP ACL rule */ + struct + { + uint8 _type, _typeMask; + } igmp; + + /* TCP ACL rule */ + struct + { + uint8 _flagMask; + uint16 _srcPortUpperBound, _srcPortLowerBound; + uint16 _dstPortUpperBound, _dstPortLowerBound; + union + { + uint8 _flag; + struct + { + uint8 _pend:2, + _urg:1, //urgent bit + _ack:1, //ack bit + _psh:1, //push bit + _rst:1, //reset bit + _syn:1, //sync bit + _fin:1; //fin bit + }s; + }un; + }tcp; + + /* UDP ACL rule */ + struct + { + uint16 _srcPortUpperBound, _srcPortLowerBound; + uint16 _dstPortUpperBound, _dstPortLowerBound; + }udp; + }is; + }L3L4; + + /* Source filter ACL rule */ + struct + { + ether_addr_t _srcMac, _srcMacMask; + uint16 _srcPort, _srcPortMask; + uint16 _srcVlanIdx, _srcVlanIdxMask; + ipaddr_t _srcIpAddr, _srcIpAddrMask; + uint16 _srcPortUpperBound, _srcPortLowerBound; + uint32 _ignoreL4:1, //L2 rule + _ignoreL3L4:1; //L3 rule + } SRCFILTER; + + /* Destination filter ACL rule */ + struct + { + ether_addr_t _dstMac, _dstMacMask; + uint16 _vlanIdx, _vlanIdxMask; + ipaddr_t _dstIpAddr, _dstIpAddrMask; + uint16 _dstPortUpperBound, _dstPortLowerBound; + uint32 _ignoreL4:1, //L3 rule + _ignoreL3L4:1; //L2 rule + } DSTFILTER; +#if defined(CONFIG_RTL_QOS_8021P_SUPPORT) + struct { + uint8 vlanTagPri; + } VLANTAG; +#endif + }un_ty; + + + uint32 ruleType_:5, + actionType_:4, + pktOpApp_:3, + priority_:3, + direction_:2, +#if defined(CONFIG_RTL_HW_QOS_SUPPORT) + upDown_:1,//0: uplink acl rule for hw qos; 1: downlink acl rule for hw qos +#endif + nexthopIdx_:5, /* Index of nexthop table (NOT L2 table) */ /* used as network interface index for 865xC qos system */ + ratelimtIdx_:4; /* Index of rate limit table */ /* used as outputQueue index for 865xC qos system */ + + + uint32 netifIdx_:3, /*for redirect*/ + pppoeIdx_:3, /*for redirect*/ + L2Idx_:10, /* Index of L2 table */ + inv_flag:8, /*mainly for iptables-->acl rule, when iptables rule has invert netif flag, this acl rule is added to other netifs*/ + aclIdx:7; /* aisc entry idx */ + + struct _rtl865x_AclRule_s *pre,*next; + +}rtl865x_AclRule_t; + + +/* MAC ACL rule Definition */ +#define dstMac_ un_ty.MAC._dstMac +#define dstMacMask_ un_ty.MAC._dstMacMask +#define srcMac_ un_ty.MAC._srcMac +#define srcMacMask_ un_ty.MAC._srcMacMask +#define typeLen_ un_ty.MAC._typeLen +#define typeLenMask_ un_ty.MAC._typeLenMask + +/* Common IP ACL Rule Definition */ +#define srcIpAddr_ un_ty.L3L4._srcIpAddr +#define srcIpAddrMask_ un_ty.L3L4._srcIpAddrMask +#define srcIpAddrUB_ un_ty.L3L4._srcIpAddr +#define srcIpAddrLB_ un_ty.L3L4._srcIpAddrMask +#define dstIpAddr_ un_ty.L3L4._dstIpAddr +#define dstIpAddrMask_ un_ty.L3L4._dstIpAddrMask +#define dstIpAddrUB_ un_ty.L3L4._dstIpAddr +#define dstIpAddrLB_ un_ty.L3L4._dstIpAddrMask +#define tos_ un_ty.L3L4._tos +#define tosMask_ un_ty.L3L4._tosMask +/* IP Rrange */ +/*Hyking:Asic use Addr to srore Upper address + and use Mask to store Lower address +*/ +#define srcIpAddrStart_ un_ty.L3L4._srcIpAddrMask +#define srcIpAddrEnd_ un_ty.L3L4._srcIpAddr +#define dstIpAddrStart_ un_ty.L3L4._dstIpAddrMask +#define dstIpAddrEnd_ un_ty.L3L4._dstIpAddr + +/* IP ACL Rule Definition */ +#define ipProto_ un_ty.L3L4.is.ip._proto +#define ipProtoMask_ un_ty.L3L4.is.ip._protoMask +#define ipFlagMask_ un_ty.L3L4.is.ip._flagMask +#define ipFOP_ un_ty.L3L4.is.ip._FOP +#define ipFOM_ un_ty.L3L4.is.ip._FOM +#define ipHttpFilter_ un_ty.L3L4.is.ip._httpFilter +#define ipHttpFilterM_ un_ty.L3L4.is.ip._httpFilterM +#define ipIdentSrcDstIp_ un_ty.L3L4.is.ip._identSrcDstIp +#define ipIdentSrcDstIpM_ un_ty.L3L4.is.ip._identSrcDstIpM +#define ipFlag_ un_ty.L3L4.is.ip.un._flag +#define ipDF_ un_ty.L3L4.is.ip.un.s._DF +#define ipMF_ un_ty.L3L4.is.ip.un.s._MF + +/* ICMP ACL Rule Definition */ +#define icmpType_ un_ty.L3L4.is.icmp._type +#define icmpTypeMask_ un_ty.L3L4.is.icmp._typeMask +#define icmpCode_ un_ty.L3L4.is.icmp._code +#define icmpCodeMask_ un_ty.L3L4.is.icmp._codeMask + +/* IGMP ACL Rule Definition */ +#define igmpType_ un_ty.L3L4.is.igmp._type +#define igmpTypeMask_ un_ty.L3L4.is.igmp._typeMask + +/* TCP ACL Rule Definition */ +#define tcpSrcPortUB_ un_ty.L3L4.is.tcp._srcPortUpperBound +#define tcpSrcPortLB_ un_ty.L3L4.is.tcp._srcPortLowerBound +#define tcpDstPortUB_ un_ty.L3L4.is.tcp._dstPortUpperBound +#define tcpDstPortLB_ un_ty.L3L4.is.tcp._dstPortLowerBound +#define tcpFlagMask_ un_ty.L3L4.is.tcp._flagMask +#define tcpFlag_ un_ty.L3L4.is.tcp.un._flag +#define tcpURG_ un_ty.L3L4.is.tcp.un.s._urg +#define tcpACK_ un_ty.L3L4.is.tcp.un.s._ack +#define tcpPSH_ un_ty.L3L4.is.tcp.un.s._psh +#define tcpRST_ un_ty.L3L4.is.tcp.un.s._rst +#define tcpSYN_ un_ty.L3L4.is.tcp.un.s._syn +#define tcpFIN_ un_ty.L3L4.is.tcp.un.s._fin + +/* UDP ACL Rule Definition */ +#define udpSrcPortUB_ un_ty.L3L4.is.udp._srcPortUpperBound +#define udpSrcPortLB_ un_ty.L3L4.is.udp._srcPortLowerBound +#define udpDstPortUB_ un_ty.L3L4.is.udp._dstPortUpperBound +#define udpDstPortLB_ un_ty.L3L4.is.udp._dstPortLowerBound + +/* Source Filter ACL Rule Definition */ +#define srcFilterMac_ un_ty.SRCFILTER._srcMac +#define srcFilterMacMask_ un_ty.SRCFILTER._srcMacMask +#define srcFilterPort_ un_ty.SRCFILTER._srcPort +#define srcFilterPortMask_ un_ty.SRCFILTER._srcPortMask +#define srcFilterVlanIdx_ un_ty.SRCFILTER._srcVlanIdx +#define srcFilterVlanId_ un_ty.SRCFILTER._srcVlanIdx +#define srcFilterVlanIdxMask_ un_ty.SRCFILTER._srcVlanIdxMask +#define srcFilterVlanIdMask_ un_ty.SRCFILTER._srcVlanIdxMask +#define srcFilterIpAddr_ un_ty.SRCFILTER._srcIpAddr +#define srcFilterIpAddrMask_ un_ty.SRCFILTER._srcIpAddrMask +#define srcFilterIpAddrUB_ un_ty.SRCFILTER._srcIpAddr +#define srcFilterIpAddrLB_ un_ty.SRCFILTER._srcIpAddrMask +#define srcFilterPortUpperBound_ un_ty.SRCFILTER._srcPortUpperBound +#define srcFilterPortLowerBound_ un_ty.SRCFILTER._srcPortLowerBound +#define srcFilterIgnoreL3L4_ un_ty.SRCFILTER._ignoreL3L4 +#define srcFilterIgnoreL4_ un_ty.SRCFILTER._ignoreL4 + +/* Destination Filter ACL Rule Definition */ +#define dstFilterMac_ un_ty.DSTFILTER._dstMac +#define dstFilterMacMask_ un_ty.DSTFILTER._dstMacMask +#define dstFilterVlanIdx_ un_ty.DSTFILTER._vlanIdx +#define dstFilterVlanIdxMask_ un_ty.DSTFILTER._vlanIdxMask +#define dstFilterVlanId_ un_ty.DSTFILTER._vlanIdx +#define dstFilterVlanIdMask_ un_ty.DSTFILTER._vlanIdxMask +#define dstFilterIpAddr_ un_ty.DSTFILTER._dstIpAddr +#define dstFilterIpAddrMask_ un_ty.DSTFILTER._dstIpAddrMask +#define dstFilterPortUpperBound_ un_ty.DSTFILTER._dstPortUpperBound +#define dstFilterIpAddrUB_ un_ty.DSTFILTER._dstIpAddr +#define dstFilterIpAddrLB_ un_ty.DSTFILTER._dstIpAddrMask +#define dstFilterPortLowerBound_ un_ty.DSTFILTER._dstPortLowerBound +#define dstFilterIgnoreL3L4_ un_ty.DSTFILTER._ignoreL3L4 +#define dstFilterIgnoreL4_ un_ty.DSTFILTER._ignoreL4 +#if defined(CONFIG_RTL_QOS_8021P_SUPPORT) +#define vlanTagPri_ un_ty.VLANTAG.vlanTagPri +#endif +#endif //CONFIG_RTL_LAYERED_DRIVER_ACL + +/* ACL Rule Action type Definition */ +#define RTL865X_ACL_PERMIT 0x00 +#define RTL865X_ACL_REDIRECT_ETHER 0x01 +#define RTL865X_ACL_DROP 0x02 +#define RTL865X_ACL_TOCPU 0x03 +#define RTL865X_ACL_LEGACY_DROP 0x04 +#define RTL865X_ACL_DROPCPU_LOG 0x05 +#define RTL865X_ACL_MIRROR 0x06 +#define RTL865X_ACL_REDIRECT_PPPOE 0x07 +#define RTL865X_ACL_DEFAULT_REDIRECT 0x08 +#define RTL865X_ACL_MIRROR_KEEP_MATCH 0x09 +#define RTL865X_ACL_DROP_RATE_EXCEED_PPS 0x0a +#define RTL865X_ACL_LOG_RATE_EXCEED_PPS 0x0b +#define RTL865X_ACL_DROP_RATE_EXCEED_BPS 0x0c +#define RTL865X_ACL_LOG_RATE_EXCEED_BPS 0x0d +#define RTL865X_ACL_PRIORITY 0x0e + +/* ACL Rule type Definition */ +#define RTL865X_ACL_MAC 0x00 +#define RTL865X_ACL_DSTFILTER_IPRANGE 0x01 +#define RTL865X_ACL_IP 0x02 +#define RTL865X_ACL_ICMP 0x04 +#define RTL865X_ACL_IGMP 0x05 +#define RTL865X_ACL_TCP 0x06 +#define RTL865X_ACL_UDP 0x07 +#define RTL865X_ACL_SRCFILTER 0x08 +#define RTL865X_ACL_DSTFILTER 0x09 +#define RTL865X_ACL_IP_RANGE 0x0A +#define RTL865X_ACL_SRCFILTER_IPRANGE 0x0B +#define RTL865X_ACL_ICMP_IPRANGE 0x0C +#define RTL865X_ACL_IGMP_IPRANGE 0x0D +#define RTL865X_ACL_TCP_IPRANGE 0x0E +#define RTL865X_ACL_UDP_IPRANGE 0x0F + +#if defined(CONFIG_RTL_QOS_8021P_SUPPORT) +/* dummy acl type for qos */ +#define RTL865X_ACL_802D1P 0x1f +#endif + +/* For PktOpApp */ +#define RTL865X_ACL_ONLY_L2 1 /* Only for L2 switch */ +#define RTL865X_ACL_ONLY_L3 2 /* Only for L3 routing (including IP multicast) */ +#define RTL865X_ACL_L2_AND_L3 3 /* Only for L2 switch and L3 routing (including IP multicast) */ +#define RTL865X_ACL_ONLY_L4 4 /* Only for L4 translation packets */ +#define RTL865X_ACL_L3_AND_L4 6 /* Only for L3 routing and L4 translation packets (including IP multicast) */ +#define RTL865X_ACL_ALL_LAYER 7 /* No operation. Don't apply this rule. */ + +#define RTL865X_ACL_MAX_NUMBER 125 +//#define RTL865X_ACL_MAX_NUMBER 64 +#define RTL865X_ACL_RESERVED_NUMBER 3 + +#define RTL865X_ACLTBL_ALL_TO_CPU 127 // This rule is always "To CPU" +#define RTL865X_ACLTBL_DROP_ALL 126 //This rule is always "Drop" +#define RTL865X_ACLTBL_PERMIT_ALL 125 // This rule is always "Permit" + +#define MAX_IFNAMESIZE 16 +#define NETIF_NUMBER 8 + +/*invert flag*/ +#define RTL865X_INVERT_IN_NETIF 0x01 +#define RTL865X_INVERT_OUT_NETIF 0x02 + +/*ingress or egress flag*/ +#define RTL865X_ACL_INGRESS 0 /*ingress acl*/ +#define RTL865X_ACL_EGRESS 1 /*egress acl*/ + +#define RTL_DEV_NAME_NUM(name,num) name#num + +#define RTL_BR_NAME "br0" +#define RTL_WLAN_NAME "wlan" +//flowing name in driver DO NOT duplicate +#if defined(CONFIG_BRIDGE) +#define RTL_DRV_LAN_NETIF_NAME "br0" +#else +#define RTL_DRV_LAN_NETIF_NAME "eth0" +#endif + +#define RTL_DRV_WAN0_NETIF_NAME "eth1" +#if defined(CONFIG_RTL_MULTIPLE_WAN) +#define RTL_DRV_WAN1_NETIF_NAME "eth6" +#endif +#define RTL_DRV_PPP_NETIF_NAME "ppp0" + +#define RTL_DRV_LAN_P0_NETIF_NAME RTL_DRV_LAN_NETIF_NAME +#define RTL_DRV_LAN_P1_NETIF_NAME "eth2" +#define RTL_DRV_LAN_P2_NETIF_NAME "eth3" +#define RTL_DRV_LAN_P3_NETIF_NAME "eth4" +#define RTL_DRV_LAN_P4_NETIF_NAME RTL_DRV_WAN0_NETIF_NAME +#define RTL_DRV_LAN_P5_NETIF_NAME "eth5" + +/************************************ +* const variable defination +*************************************/ +#define RTL_WANVLANID 8 +#define RTL_LANVLANID 9 +#if defined(CONFIG_RTL_MULTIPLE_WAN) +#define RTL_WAN_1_VLANID 369 +#endif +#if defined(CONFIG_RTL8196_RTL8366) + #define RTL_WANPORT_MASK 0x1C1 + #define RTL_LANPORT_MASK 0x1C1 + #define RTL8366RB_GMIIPORT 0x20 + #define RTL8366RB_LANPORT 0xCf + #define RTL8366RB_WANPORT 0x10 +#elif defined(CONFIG_RTL_819X) && (defined(CONFIG_RTK_VLAN_SUPPORT) || defined (CONFIG_RTL_MULTI_LAN_DEV)) +#if defined (CONFIG_POCKET_ROUTER_SUPPORT) + #define RTL_WANPORT_MASK 0x10 + #define RTL_LANPORT_MASK 0x10 +#elif defined(CONFIG_RTL_PUBLIC_SSID) + #define RTL_WANPORT_MASK 0x110 //port 4/port 8 + #define RTL_LANPORT_MASK 0x10f +#elif defined(CONFIG_8198_PORT5_RGMII) + #define RTL_WANPORT_MASK 0x10 + #define RTL_LANPORT_MASK 0x12f +#else + #if defined (CONFIG_RTL_8196C_iNIC) + #define RTL_WANPORT_MASK 0x01 + #define RTL_LANPORT_MASK 0x110 //mark_inic , only port4 connect to MII + #elif defined (CONFIG_RTK_INBAND_HOST_HACK) + #if defined (CONFIG_8198_PORT5_GMII) + #define RTL_WANPORT_MASK 0x120 //port5 ,hack port,eth1 + #define RTL_LANPORT_MASK 0x11f // 0~4 port eth0 + #else + #define RTL_WANPORT_MASK 0x110 //port4(port0 in some board) is eth1 + #define RTL_LANPORT_MASK 0x12f // 0 1 2 3 5 port are eth0 + #endif + #elif defined (CONFIG_8198_PORT5_GMII) + #define RTL_WANPORT_MASK 0x10 //port0 + #define RTL_LANPORT_MASK 0x12f //all port eth0 + #else + #define RTL_WANPORT_MASK 0x10 + #define RTL_LANPORT_MASK 0x10f + #endif +#endif + #define RTL_LANPORT_MASK_1 0x8 //port 0 + #define RTL_LANPORT_MASK_2 0x4 //port 1 + #define RTL_LANPORT_MASK_3 0x2 //port 2 + #define RTL_LANPORT_MASK_4 0x1 //port 3 + #ifdef CONFIG_8198_PORT5_GMII + #define RTL_LANPORT_MASK_5 0x20 //port 5 + #endif +#elif defined(CONFIG_RTL_8198_NFBI_BOARD) + #define RTL_WANPORT_MASK 0x1e0 //port 5, port 6,port 7,port 8 + #define RTL_LANPORT_MASK 0x1df //port 0~4 , port 6~8 , need port4 ?? +#elif defined(CONFIG_8198_PORT5_GMII) + #define RTL_WANPORT_MASK 0x110 + #define RTL_LANPORT_MASK 0x1ef +#elif defined (CONFIG_POCKET_ROUTER_SUPPORT) + #define RTL_WANPORT_MASK 0x10 + #define RTL_LANPORT_MASK 0x10 +#elif defined(CONFIG_RTL_PUBLIC_SSID) + #define RTL_WANPORT_MASK 0x110 //port 4/port 8 +#elif defined(CONFIG_RTL8186_KB_N) || defined(CONFIG_RTL_819X) /* defined(CONFIG_RTL8196_RTL8366) */ + #ifdef CONFIG_RTL_8196C_iNIC + #define RTL_WANPORT_MASK 0x01 + #define RTL_LANPORT_MASK 0x110 //mark_inic , only port4 connect to MII + #else + #define RTL_WANPORT_MASK 0x10 + #define RTL_LANPORT_MASK 0x10f + #endif +#else + #define RTL_WANPORT_MASK 0x01 + #define RTL_LANPORT_MASK 0x11e /* port1/2/3/4/cpu port(port 8) */ + #if defined(CONFIG_RTK_VLAN_SUPPORT) || defined (CONFIG_RTL_MULTI_LAN_DEV) + #define RTL_LANPORT_MASK_1 0x2 //port 1 + #define RTL_LANPORT_MASK_2 0x4 //port 2 + #define RTL_LANPORT_MASK_3 0x8 //port 3 + #define RTL_LANPORT_MASK_4 0x10 //port 4 + #endif +#endif /* defined(CONFIG_RTL8186_KB_N) || defined(CONFIG_RTL_819X) */ + +#if defined(CONFIG_RTK_VLAN_SUPPORT) || defined (CONFIG_RTL_MULTI_LAN_DEV) +#if defined(CONFIG_8198_PORT5_GMII) + #define ETH_INTF_NUM 6 +#else + #define ETH_INTF_NUM 5 +#endif +#else +#define ETH_INTF_NUM 2 +#endif + +typedef struct rtl865x_netif_s +{ + uint16 vid; /*netif->vid*/ + uint16 mtu; /*netif's MTU*/ + uint32 if_type:5; /*interface type, 0:ether,1:pppoe....*/ + ether_addr_t macAddr; + uint32 is_wan:1, /*wan interface?*/ + dmz:1, /*DMZ/routing lan*/ + is_slave:1; /*is slave interface?*/ + uint8 name[MAX_IFNAMESIZE]; + uint16 enableRoute; +#if defined (CONFIG_RTL_LOCAL_PUBLIC) + uint16 forMacBasedMCast; +#endif +}rtl865x_netif_t; + +/*internal...*/ +int32 _rtl865x_getAclFromAsic(int32 index, rtl865x_AclRule_t *rule); + +int32 rtl865x_init_acl(void); +int32 rtl865x_reinit_acl(void); +int32 rtl865x_add_acl(rtl865x_AclRule_t *rule, char *netifName, int32 chainNo); +int32 rtl865x_del_acl(rtl865x_AclRule_t *rule, char *netifName, int32 chainNo); +int32 rtl865x_regist_aclChain(char *netifName, int32 priority, uint32 flag); +int32 rtl865x_unRegist_aclChain(char *netifName, int32 priority, uint32 flag); +int32 rtl865x_flush_allAcl_fromChain(char *netifName, int32 priority, uint32 flag); +int32 rtl865x_show_allAclChains(void); +rtl865x_AclRule_t* rtl865x_matched_layer4_aclChain(char *netifName,int32 priority, uint32 flag, rtl865x_AclRule_t *match); +rtl865x_AclRule_t* rtl865x_matched_layer2_aclChain(char *netifName,int32 priority, uint32 flag, rtl865x_AclRule_t *match); +//int32 rtl865x_add_def_permit_acl(void); +//int32 rtl865x_del_def_permit_acl(void); + +#if defined(CONFIG_RTK_VLAN_SUPPORT) +int32 rtl865x_enable_acl(uint32 enable); +#endif +int rtl865x_add_pattern_acl_for_contentFilter(rtl865x_AclRule_t *rule,char *netifName); +int rtl865x_del_pattern_acl_for_contentFilter(rtl865x_AclRule_t *rule,char *netifName); + + +#ifdef RTL_LAYERED_DRIVER_DEBUG +int32 rtl865x_acl_test(int32 testNo); +#endif + +int32 rtl865x_deReferNetif(char *ifName); +int32 rtl865x_referNetif(char *ifName); +int32 rtl865x_setNetifMtu(rtl865x_netif_t *netif); +int32 rtl865x_setNetifMac(rtl865x_netif_t *netif); +int32 rtl865x_setNetifVid(char *name, uint16 vid); +int32 rtl865x_setNetifType(char *name, uint32 ifType); +int32 rtl865x_addNetif(rtl865x_netif_t *netif); +int32 rtl865x_delNetif(char *ifName); +int32 rtl865x_initNetifTable(void); +int32 rtl865x_reinitNetifTable(void); +int32 rtl865x_attachMasterNetif(char *slave, char *master); +int32 rtl865x_detachMasterNetif(char *slave); + +int32 rtl865x_setPortToNetif(char *name,uint32 port); + +#if defined (CONFIG_RTL_HARDWARE_MULTICAST) +int32 rtl865x_getNetifVid(char *name, uint32 *vid); +int32 rtl865x_getNetifType(char *name,uint32 *type); +uint32 rtl865x_getExternalPortMask(void); +#endif + +#if defined (CONFIG_RTL_LOCAL_PUBLIC) +//int32 rtl865x_getNetifFid(char *name, uint16 *fid); +int32 rtl865x_addVirtualNetif(rtl865x_netif_t *netif); +int32 rtl865x_delVirtualNetif(char *ifName); +#endif + +int32 rtl865x_setDefACLForAllNetif(uint8 start_ingressAclIdx, uint8 end_ingressAclIdx,uint8 start_egressAclIdx,uint8 end_egressAclIdx); +int32 rtl865x_reConfigDefaultAcl(char *ifName); +int32 rtl865x_config_callback_for_get_drv_netifName(int (*fun)(const char *psName,char *netifName)); +#endif + diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_outputQueue.h b/target/linux/realtek/files/include/net/rtl/rtl865x_outputQueue.h new file mode 100644 index 000000000..ed70fc4a9 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_outputQueue.h @@ -0,0 +1,165 @@ +#ifndef RTL865X_OUTPUTQUEUE_H +#define RTL865X_OUTPUTQUEUE_H +#include <linux/if.h> + +#if !defined(CONFIG_RTL_LAYERED_ASIC_DRIVER) +#define RTL865XC_MNQUEUE_OUTPUTQUEUE 1 +#define RTL865XC_QOS_OUTPUTQUEUE 1 + +typedef struct rtl865xC_outputQueuePara_s { + + uint32 ifg; /* default: Bandwidth Control Include/exclude Preamble & IFG */ + uint32 gap; /* default: Per Queue Physical Length Gap = 20 */ + uint32 drop; /* default: Descriptor Run Out Threshold = 500 */ + + uint32 systemSBFCOFF; /*System shared buffer flow control turn off threshold*/ + uint32 systemSBFCON; /*System shared buffer flow control turn on threshold*/ + + uint32 systemFCOFF; /* system flow control turn off threshold */ + uint32 systemFCON; /* system flow control turn on threshold */ + + uint32 portFCOFF; /* port base flow control turn off threshold */ + uint32 portFCON; /* port base flow control turn on threshold */ + + uint32 queueDescFCOFF; /* Queue-Descriptor=Based Flow Control turn off Threshold */ + uint32 queueDescFCON; /* Queue-Descriptor=Based Flow Control turn on Threshold */ + + uint32 queuePktFCOFF; /* Queue-Packet=Based Flow Control turn off Threshold */ + uint32 queuePktFCON; /* Queue-Packet=Based Flow Control turn on Threshold */ +} rtl865xC_outputQueuePara_t; +#endif + +#define MAX_QOS_RULE_NUM 10 +#define MAX_MARK_NUM_PER_DEV 5 // Note: not include the default mark(0) and should be <= (hw queue number - 1(for default)) +#define IPPROTO_ANY 256 +#define IPPROTO_BOTH 257 + +#define QOS_DEF_QUEUE 0x4 +#define QOS_VALID_MASK 0x2 +#define QOS_TYPE_MASK 0x1 +#define QOS_TYPE_STR 0x0 /*0x0|QOS_VALID_MASK*/ +#define QOS_TYPE_WFQ 0x1 /*0x1|QOS_VALID_MASK*/ + +#define EGRESS_BANDWIDTH_GRANULARITY 0x10000 /* 64*1024 */ +#define EGRESS_BANDWIDTH_GRANULARITY_BITMASK 0xffff +#define EGRESS_BANDWIDTH_GRANULARITY_BITLEN 16 + +#define INGRESS_BANDWIDTH_GRANULARITY_BITLEN 14 + +#define EGRESS_WFQ_MAX_RATIO 0x80 + +#if 0 +#define QOS_DEBUGP printk +#else +#define QOS_DEBUGP(format, args...) +#endif + +#if 0 +#define QOS_RULE_DEBUGP printk +#else +#define QOS_RULE_DEBUGP(format, args...) +#endif + +/* priority decision array index */ +enum PriDecIdx +{ + PORT_BASE = 0, + D1P_BASE, + DSCP_BASE, + ACL_BASE, + NAT_BASE, + PRI_TYPE_NUM, +}; + +typedef unsigned int bwu; + +typedef struct { + /* classify */ + unsigned int protocol; + ipaddr_t local_ip_start; + ipaddr_t local_ip_end; + ipaddr_t remote_ip_start; + ipaddr_t remote_ip_end; + unsigned short lo_port_start; + unsigned short lo_port_end; + unsigned short re_port_start; + unsigned short re_port_end; + + /* tc */ + uint32 mark; + unsigned char prio; + unsigned char rate; +} rtl865x_qos_entry_t, *rtl865x_qos_entry_p; + +typedef struct { + uint8 dscpRemark; + uint8 vlanPriRemark; + uint16 flags; + + char ifname[IFNAMSIZ]; + uint32 queueId; /* identify outputQueue */ + uint32 handle; + + bwu ceil; + bwu burst; + bwu bandwidth; /* average bandwidth, unit kbps */ +} rtl865x_qos_t, *rtl865x_qos_p; + +typedef rtl865x_qos_entry_t QOS_T; +typedef rtl865x_qos_entry_p QOS_Tp; + +typedef struct _rtl865x_qos_rule_t{ + char inIfname[IFNAMSIZ]; + char outIfname[IFNAMSIZ]; + rtl865x_AclRule_t *rule; + uint32 mark; + uint32 handle; + struct _rtl865x_qos_rule_t *next; +} rtl865x_qos_rule_t, *rtl865x_qos_rule_p; + +typedef struct { + uint32 mark; /* mark==0 means entry not used */ + uint32 priority; +} rtl_qos_mark_info_t, *rtl_qos_mark_info_p; + +int32 rtl865x_qosSetBandwidth(uint8 *netIfName, uint32 bps); +int32 rtl865x_qosFlushBandwidth(uint8 *netIfName); +int32 rtl865x_qosGetPriorityByHandle(uint8 *priority, uint32 handle); +int32 rtl865x_qosProcessQueue(uint8 *netIfName, rtl865x_qos_t *qosInfo); +int32 rtl865x_setRule2HandleMapping(uint32 ifIdx, uint32 idx, uint32 handle); +int32 rtl865x_qosAddMarkRule(rtl865x_qos_rule_t *rule); +int32 rtl865x_qosFlushMarkRule(void); +int32 rtl865x_qosCheckNaptPriority(rtl865x_AclRule_t *qosRule); +int32 rtl865x_closeQos(uint8 *netIfName); +int32 rtl865x_registerQosCompFunc(int8 (*p_cmpFunc)(rtl865x_qos_t *entry1, rtl865x_qos_t *entry2)); +int __init rtl865x_initOutputQueue(uint8 **netIfName); +void __exit rtl865x_exitOutputQueue(void); +int32 rtl865x_qosArrangeRuleByNetif(void); +#if defined(CONFIG_RTL_PROC_DEBUG) +int32 rtl865x_show_allQosAcl(void); +#endif +extern int32 rtl865x_qosArrangeRuleByNetif(void); +int32 rtl_qosGetPriorityByMark(uint8 *netIfName, int32 mark); + +int32 rtl_qosGetPriorityByVid(int32 vid, int32 mark); +int32 rtl_qosSetPriorityByMark(uint8 *netIfName, int32 mark, int32 handler, int32 enable); + +extern u8 netIfNameArray[NETIF_NUMBER][IFNAMSIZ]; +extern rtl865x_qos_rule_t *rtl865x_qosRuleHead; + +#if defined(CONFIG_RTK_QOS_FOR_CABLE_MODEM) +void rtl_initQosForCableModem(void); +#endif + +#if defined (CONFIG_RTL_HW_QOS_SUPPORT) && defined(CONFIG_RTL_QOS_PATCH) +#define DEF_QUEUE_NUM 1 +#define MAX_QOS_PATCH_QUEUE_NUM 2 +void rtl865x_reinitOutputQueuePatchForQoS(uint32 qosEnabled); +#endif + +#if defined (CONFIG_RTL_HW_QOS_SUPPORT) // sync from voip customer for multiple ppp +int32 rtl865x_qosFlushMarkRuleByDev(uint8 *netIfName); +int32 rtl865x_qosRearrangeRule(void); +#endif + +#endif diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_ppp.h b/target/linux/realtek/files/include/net/rtl/rtl865x_ppp.h new file mode 100644 index 000000000..e66b56175 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_ppp.h @@ -0,0 +1,30 @@ +/* +* Copyright c Realtek Semiconductor Corporation, 2008 +* All rights reserved. +* +* Program : ppoe table driver +* Abstract : +* Author : hyking (hyking_liu@realsil.com.cn) +*/ +#ifndef RTL865X_PPP_H +#define RTL865X_PPP_H + +#if !defined(REDUCE_MEMORY_SIZE_FOR_16M) +#define REDUCE_MEMORY_SIZE_FOR_16M +#endif + +#if defined(REDUCE_MEMORY_SIZE_FOR_16M) +#define PPP_NUMBER 2 +#else +#define PPP_NUMBER 8 +#endif +#define SESSION_TYPE_PPPOE 0x00 +#define SESSION_TYPE_PPTP 0x01 +#define SESSION_TYPE_L2TP 0x02 + +int32 rtl865x_delPpp(uint32 sessionId); +int32 rtl865x_delPppbyIfName(char *name); +int32 rtl865x_addPpp(uint8 *ifname, ether_addr_t *mac, uint32 sessionId, int32 type); + +#endif + diff --git a/target/linux/realtek/files/include/net/rtl/rtl865x_route_api.h b/target/linux/realtek/files/include/net/rtl/rtl865x_route_api.h new file mode 100644 index 000000000..a7a01dd76 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl865x_route_api.h @@ -0,0 +1,21 @@ + +/* + * * Copyright c Realtek Semiconductor Corporation, 2008 + * * All rights reserved. + * * + * * Program : route table driver + * * Abstract : + * * Author : hyking (hyking_liu@realsil.com.cn) + * */ +#ifndef RTL865X_ROUTE_API_H +#define RTL865X_ROUTE_API_H + +#define RT_ASIC_ENTRY_NUM 8 +#define RT_DRV_ENTRY_NUM 8 + +#define RT_MAX_ARP_SIZE 256 + +int32 rtl865x_addRoute(ipaddr_t ipAddr, ipaddr_t ipMask, ipaddr_t nextHop, int8 * ifName,ipaddr_t srcIp); +int32 rtl865x_delRoute(ipaddr_t ipAddr, ipaddr_t ipMask); + +#endif diff --git a/target/linux/realtek/files/include/net/rtl/rtl_glue.h b/target/linux/realtek/files/include/net/rtl/rtl_glue.h new file mode 100644 index 000000000..0460ef851 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl_glue.h @@ -0,0 +1,252 @@ +/* +* -------------------------------------------------------------------- +* Copyright c Realtek Semiconductor Corporation, 2002 +* All rights reserved. +* +* Program : rtl_glue.h +* Abstract :Header of porting layer +* Author : Edward Jin-Ru Chen +* +* $Id: rtl_glue.h,v 1.3 2008/04/11 10:12:38 bo_zhao Exp $ +* $Log: rtl_glue.h,v $ +* Revision 1.3 2008/04/11 10:12:38 bo_zhao +* *: swap nic drive to 8186 style +* +* Revision 1.2 2008/01/18 02:50:16 alva_zhang +* *: refine function define to pass the gcc-3.4 compiling +* +* Revision 1.1 2007/12/21 10:29:52 davidhsu +* +: support nic driver +* +* Revision 1.35 2007/07/03 05:53:51 qy_wang +* *:add rtl8316s model core +* +* Revision 1.34 2007/06/07 05:35:30 chenyl +* +: add new function "rtlglue_clearDCache" to clear D-cache without +* writing back to external memory. ( Only for Processor with this function ) +* +* Revision 1.33 2007/06/01 09:20:52 michaelhuang +* -: removed the rtl867x compiler flag. +* +* Revision 1.32 2007/04/09 14:14:01 michaelhuang +* +: added rtlglue_read() function +* +* Revision 1.31 2007/03/02 13:31:59 chenyl +* *: enable range based D-cache flush function. +* +* Revision 1.30 2007/01/09 02:36:08 michaelhuang +* *: Prepare implement test module for RTL8672 +* +* Revision 1.29 2006/12/21 06:57:00 yjlou +* -: remove the following usages: +* printk +* printfByPolling +* +* Revision 1.28 2006/11/28 02:15:14 hyking_liu +* *: Mofify function related with usrDefineTunnel +* +* Revision 1.27 2006/11/21 12:28:35 chenyl +* *: rearrange some code +* *: bug fix - Src VLAN decision +* *: bug fix - D-cache invalidation for FAST extension device forwarding +* *: bug fix - m_unused1 and ph_reserved are needed for FAST extension device forwarding +* +* Revision 1.26 2006/10/26 02:15:32 qy_wang +* *:remove the inculed file net_device.h in rtl8651_layer2fwd.c +* +* Revision 1.25 2006/10/25 07:10:15 qy_wang +* +:add a function to block extension device when link up +* +* Revision 1.24 2006/08/31 15:44:48 chenyl +* *: add some declarations of external APIs +* +* Revision 1.23 2006/07/13 15:55:49 chenyl +* *: modify code for RTL865XC driver compilation. +* *: dos2unix process +* +* Revision 1.22 2006/06/20 05:53:22 brian_bin +* +: brian_bin move open, write, close declaration into __RTL_GLUE__ define brace +* +* Revision 1.21 2006/01/12 08:32:37 brian_bin +* +: brian_bin add kernel system call of file operations +* +* Revision 1.20 2006/01/02 02:52:14 chenyl +* +: VLAN-tag support extension port forwarding and software Rome Driver forwarding. +* +* Revision 1.19 2005/09/16 11:34:48 tony +* *: bug fixed: support kernel space swNic model code for RTL865XC. +* +* Revision 1.18 2005/09/06 02:36:38 yjlou +* +: add random and time glue functions. +* +* Revision 1.17 2005/07/20 15:29:38 yjlou +* +: porting Model Code to Linux Kernel: check RTL865X_MODEL_KERNEL. +* +* Revision 1.16 2005/07/01 09:34:41 yjlou +* *: porting swNic2.c into model code. +* +* Revision 1.15 2005/06/19 05:41:19 yjlou +* *: merge ASIC driver into model code. +* +* Revision 1.14 2005/06/07 15:00:57 chenyl +* *: modify mutex Lock / Unlock code to check the balance of Lock/Unlock function call +* +* Revision 1.13 2004/11/29 07:35:44 chenyl +* *: fix bug : multiple-PPPoE MTU setting bug +* *: fix bug : Never add second session's ip into ASIC in multiple-PPPoE WAN type. +* *: fix bug : Tunekey abnormal behavior when multiple-PPPoE Dial-on-demand Dynamically turn ON/OFF +* *: in forwarding engine Init function, the parameter == 0xffffffff means user want to set as default value +* *: add Mutex-Lock/Unlock checking in testing code +* +* Revision 1.12 2004/11/05 09:54:08 yjlou +* +: support more precise timeUpdate() function. +* +: add EVENT_TRIGGER_TIMEUPDATE==2 +* *: modify #ifdef EVENT_TRIGGER_TIMEUPDATE +* +* Revision 1.11 2004/07/27 10:47:08 cfliu +* -: Remove RTL865x external loopback port related code for PPTP/L2TP/WLAN +* +* Revision 1.10 2004/06/23 08:11:55 yjlou +* *: change the declaration of rtlglue_getmstime() +* +* Revision 1.9 2004/05/03 14:56:18 cfliu +* Add 8650B extension port support. +* Revise all WLAN/extport related code. +* +* Revision 1.8 2004/05/03 02:53:03 chenyl +* *: swNic_getRingSize -> rtlglue_getRingSize and move it from swNic2.c to rtl_glue.c +* *: set default upstream ip to 0 if we config interface to dhcp +* +* Revision 1.7 2004/04/30 08:58:08 chenyl +* +: ip multicast/igmp proxy +* +* Revision 1.6 2004/04/08 12:11:20 cfliu +* Change extension port API.....define rtlglue_extDeviceSend() +* +* Revision 1.5 2004/03/31 09:37:01 cfliu +* Add WDS support +* +* Revision 1.4 2004/03/19 13:13:35 cfliu +* Reorganize ROME driver local header files. Put all private data structures into different .h file corrsponding to its layering +* Rename printf, printk, malloc, free with rtlglue_XXX prefix +* +* Revision 1.1 2004/03/10 11:42:36 cfliu +* Move rtl_glue.* from rtl865x/ +* +* Revision 1.2 2004/03/03 10:40:38 yjlou +* *: commit for mergence the difference in rtl86xx_tbl/ since 2004/02/26. +* +* Revision 1.1 2004/02/25 14:26:33 chhuang +* *** empty log message *** +* +* Revision 1.2 2004/02/25 14:24:52 chhuang +* *** empty log message *** +* +* Revision 1.7 2004/02/24 04:15:43 cfliu +* add API for WLAN acceleration +* +* Revision 1.6 2004/02/18 13:54:37 chhuang +* *** empty log message *** +* +* Revision 1.5 2003/12/26 09:27:50 orlando +* add rtl_glue.h +* +* Revision 1.3 2003/09/30 06:07:50 orlando +* check in RTL8651BLDRV_V20_20030930 +* +* Revision 1.4 2003/06/10 05:33:30 cfliu +* Remove rtl8651_tblDrvFwdSend registration. +* Add rtlglue_drvSend to replace rtl8651_tblDrvFwdSend function pointer +* +* Revision 1.3 2003/06/09 04:48:43 cfliu +* add 3 OS dependent glue functions to support mbuf external cluster allocation. +* Rewrite all help messages using Autoduck's syntax so documentation could generated automatically. +* +* Revision 1.2 2003/05/23 07:47:06 cfliu +* Extract porting function and fix compile warning. +* +* Revision 1.1 2003/05/23 04:55:25 jzchen +* Add rtl glue to solve porting issue +* +*/ + +#ifndef RTL_GLUE_H +#define RTL_GLUE_H + +/* @doc RTLGLUE_API + + @module rtl_glue.h - Glue interface for Realtek 8651 Home gateway controller driver | + This guide documents the glue interface for porting 8651 driver to targeted operating system + @normal Chun-Feng Liu (cfliu@realtek.com.tw) <date> + + Copyright <cp>2003 Realtek<tm> Semiconductor Cooperation, All Rights Reserved. + + @head3 List of Symbols | + Here is the list of all functions and variables in this module. + + @index | RTLGLUE_API +*/ +#include <linux/semaphore.h> +#include <linux/spinlock.h> + +#define RTL_DECLARE_MUTEX(name) DECLARE_MUTEX(name) + +//int rtl_down_interruptible(struct semaphore * sem); +//void rtl_up(struct semaphore * sem); +// +#ifndef RTL865X_DEBUG +#define assert(expr) do {} while (0) +#else +#define assert(expr) \ + if(!(expr)) { \ + printk( "\033[33;41m%s:%d: assert(%s)\033[m\n", \ + __FILE__,__LINE__,#expr); \ + } +#endif + +#define RTL_BUG(cause) \ + do { printk(" [= !! BUG !! =] at %s line %d\n\t=> Cause: \ + %s\n\t=>-- system Halt\n", __FUNCTION__, __LINE__, cause); while(1);} while (0) + +#define TBL_MEM_ALLOC(tbl, type, size) \ + { \ + (tbl) = (type *)kmalloc((size) * sizeof(type),GFP_ATOMIC); \ + if(!(tbl)){\ + printk("MEM alloc failed at line %d\n", __LINE__);\ + while(1);\ + return FAILED;\ + }\ + } + +#ifndef bzero + #define bzero( p, s ) memset( p, 0, s ) +#endif + +#define RTL_NIC_LOCK_INIT(__rtl_lock__) spin_lock_init(&__rtl_lock__) +#define RTL_NIC_LOCK(__rtl_lock__) spin_lock(&__rtl_lock__) +#define RTL_NIC_UNLOCK(__rtl_lock__) spin_unlock(&__rtl_lock__) + +static inline int rtl_down_interruptible(struct semaphore * sem) +{ + return down_interruptible(sem); +} + +static inline void rtl_up(struct semaphore * sem) +{ + up(sem); +} + +static inline void *rtl_malloc(size_t NBYTES) +{ + if(NBYTES==0) return NULL; + return (void *)kmalloc(NBYTES,GFP_ATOMIC); +} + +static inline void rtl_free(void *APTR) +{ + kfree(APTR); +} + +void memDump (void *start, uint32 size, int8 * strHeader); + +#endif diff --git a/target/linux/realtek/files/include/net/rtl/rtl_nic.h b/target/linux/realtek/files/include/net/rtl/rtl_nic.h new file mode 100644 index 000000000..c911b7de9 --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl_nic.h @@ -0,0 +1,274 @@ +#ifndef RTL_NIC_H +#define RTL_NIC_H + +#ifdef CONFIG_RTL_STP +#include <net/rtl/rtk_stp.h> +#endif + +#include "rtl865x_netif.h" +/************************************ +* feature enable/disable +*************************************/ +#define RX_TASKLET 1 +#define TX_TASKLET 1 +#define LINK_TASKLET 1 +#define RTL819X_PRIV_IOCTL_ENABLE 1 /* mark_add */ +#define CONFIG_RTL_PHY_PATCH 1 +#define RTK_QUE 1 +#if defined(CONFIG_NET_WIRELESS_AGN) || defined (CONFIG_RTL8192SE) || defined(CONFIG_RTL8192CD) || defined(CONFIG_RTL8192CD_MODULE) +#define BR_SHORTCUT 1 +#endif +/* +*#define CONFIG_RTL_MULTI_LAN_DEV 1 +*/ + +#if defined(CONFIG_POCKET_AP_SUPPORT) +#define CONFIG_POCKET_ROUTER_SUPPORT +#endif + +#if defined(CONFIG_RTL_ETH_PRIV_SKB) + #if defined(CONFIG_RTL_819X) + #define MAX_ETH_SKB_NUM (\ + NUM_RX_PKTHDR_DESC \ + + NUM_RX_PKTHDR_DESC1 \ + + NUM_RX_PKTHDR_DESC2 \ + + NUM_RX_PKTHDR_DESC3 \ + + NUM_RX_PKTHDR_DESC4 \ + + NUM_RX_PKTHDR_DESC5 \ + + MAX_PRE_ALLOC_RX_SKB + 128) + #else + #define MAX_ETH_SKB_NUM (\ + NUM_RX_PKTHDR_DESC \ + + NUM_RX_PKTHDR_DESC1 \ + + NUM_RX_PKTHDR_DESC2 \ + + NUM_RX_PKTHDR_DESC3 \ + + NUM_RX_PKTHDR_DESC4 \ + + NUM_RX_PKTHDR_DESC5 \ + + MAX_PRE_ALLOC_RX_SKB + 256) + #endif +#define ETH_SKB_BUF_SIZE (SKB_DATA_ALIGN(CROSS_LAN_MBUF_LEN+sizeof(struct skb_shared_info)+160+NET_SKB_PAD)) +#define ETH_MAGIC_CODE "819X" +#define ETH_MAGIC_LEN 4 +#endif + +struct re865x_priv +{ + u16 ready; + u16 addIF; + u16 devnum; + u32 sec_count; + u32 sec; +#if defined(CONFIG_RTK_VLAN_SUPPORT) || defined (CONFIG_RTL_MULTI_LAN_DEV) + struct net_device *dev[ETH_INTF_NUM]; +#else + struct net_device *dev[ETH_INTF_NUM]; +#endif +#ifdef CONFIG_RTL_STP + struct net_device *stp_port[MAX_RE865X_STP_PORT]; +#endif +#if defined(CONFIG_RTL_CUSTOM_PASSTHRU) + struct net_device *pdev; +#endif + //spinlock_t lock; + void *regs; + struct tasklet_struct rx_tasklet; + struct timer_list timer; /* Media monitoring timer. */ + unsigned long linkchg; +}; + +struct dev_priv { + u32 id; /* VLAN id, not vlan index */ + u32 portmask; /* member port mask */ + u32 portnum; /* number of member ports */ + u32 netinit; + struct net_device *dev; + struct net_device *dev_prev; + struct net_device *dev_next; +#ifdef RX_TASKLET + struct tasklet_struct rx_dsr_tasklet; +#endif + +#ifdef TX_TASKLET + struct tasklet_struct tx_dsr_tasklet; +#endif + + struct tasklet_struct link_dsr_tasklet; + +#if defined(CONFIG_RTK_VLAN_SUPPORT) + struct vlan_info vlan_setting; +#endif + +#ifdef CP_VLAN_TAG_USED + struct vlan_group *vlgrp; +#endif + spinlock_t lock; + u32 msg_enable; + u32 opened; + u32 irq_owner; //record which dev request IRQ + struct net_device_stats net_stats; +#if defined(DYNAMIC_ADJUST_TASKLET) || defined(CONFIG_RTL8186_TR) || defined(BR_SHORTCUT) || defined(CONFIG_RTL8196C_REVISION_B) || defined(CONFIG_RTL_8198) + struct timer_list expire_timer; +#endif + +#ifdef CONFIG_RTL8196C_GREEN_ETHERNET + struct timer_list expire_timer2; +#endif +}; + +typedef struct __rtlInterruptRxData +{ + #if defined (CONFIG_RTK_VOIP_QOS) && !defined (CONFIG_RTK_VOIP_ETHERNET_DSP_IS_HOST) + unsigned long voip_rx_start_time; + int voip_rx_cnt; + #endif +} rtlInterruptRxData; + +/* define return value */ +#define RTL_RX_PROCESS_RETURN_SUCCESS 0 +#define RTL_RX_PROCESS_RETURN_CONTINUE -1 +#define RTL_RX_PROCESS_RETURN_BREAK -2 + + +#if defined (CONFIG_RTL_UNKOWN_UNICAST_CONTROL) +#define RTL_MAC_RECORD_NUM 4 /* Must be 2's orders */ +#define RTL_MAC_THRESHOLD 128 /* threshold for block unkown unicast */ +#define RTL_MAC_TIMEOUT 10*HZ /* unkown unicast restriction time */ +#define RTL_MAC_REFILL_TOKEN 25000 /* per second refill token number */ +typedef struct __rtlMacRecord +{ + uint8 enable; + uint8 cnt; + uint8 mac[ETHER_ADDR_LEN]; + struct timer_list timer; +} rtlMacRecord; +#endif + +#if defined(RTL819X_PRIV_IOCTL_ENABLE) +#define RTL819X_IOCTL_READ_PORT_STATUS (SIOCDEVPRIVATE + 0x01) +#define RTL819X_IOCTL_READ_PORT_STATS (SIOCDEVPRIVATE + 0x02) + +struct lan_port_status { + unsigned char link; + unsigned char speed; + unsigned char duplex; + unsigned char nway; +}; + +struct port_statistics { + unsigned int rx_bytes; + unsigned int rx_unipkts; + unsigned int rx_mulpkts; + unsigned int rx_bropkts; + unsigned int rx_discard; + unsigned int rx_error; + unsigned int tx_bytes; + unsigned int tx_unipkts; + unsigned int tx_mulpkts; + unsigned int tx_bropkts; + unsigned int tx_discard; + unsigned int tx_error; +}; +#endif + +#if defined(CONFIG_RTK_VLAN_SUPPORT) || defined (CONFIG_RTL_MULTI_LAN_DEV) +#define RTL_LANVLANID_1 9 +#define RTL_LANVLANID_2 10 +#define RTL_LANVLANID_3 11 +#define RTL_LANVLANID_4 12 +#define RTL_LANVLANID_5 13 +#endif +#define RTL_PPTPL2TP_VLANID 999 + +//flowing name in protocol stack DO NOT duplicate +#define RTL_PS_BR0_DEV_NAME RTL_BR_NAME +#define RTL_PS_ETH_NAME "eth" +#define RTL_PS_WLAN_NAME RTL_WLAN_NAME +#define RTL_PS_PPP_NAME "ppp" +#define RTL_PS_LAN_P0_DEV_NAME RTL_DEV_NAME_NUM(RTL_PS_ETH_NAME,0) +#define RTL_PS_WAN0_DEV_NAME RTL_DEV_NAME_NUM(RTL_PS_ETH_NAME,1) +#define RTL_PS_PPP0_DEV_NAME RTL_DEV_NAME_NUM(RTL_PS_PPP_NAME,0) +#define RTL_PS_PPP1_DEV_NAME RTL_DEV_NAME_NUM(RTL_PS_PPP_NAME,1) +#define RTL_PS_WLAN0_DEV_NAME RTL_DEV_NAME_NUM(RTL_PS_WLAN_NAME,0) +#define RTL_PS_WLAN1_DEV_NAME RTL_DEV_NAME_NUM(RTL_PS_WLAN_NAME,1) + +#if defined(CONFIG_RTL_MULTIPLE_WAN) +#define RTL_MULTIWAN_ADD 1 +#define RTL_MULTIWAN_DEL 2 +//#define RTL_PS_WAN1_DEV_NAME RTL_DEV_NAME_NUM(RTL_PS_ETH_NAME,2) +#endif + +#if defined(CONFIG_RTL_PUBLIC_SSID) +#define RTL_LAN_DEVICE_NAME "br0" +#define RTL_GW_WAN_DEVICE_NAME "br1" +#define RTL_WISP_WAN_DEVICE_NAME "wlan0" +#define RTL_BR_WAN_DEVICE_NAME "br0" +#endif + +//Used by fastpath mac-based qos under IMPROVE_QOS +#define QOS_LAN_DEV_NAME RTL_PS_BR0_DEV_NAME + +#ifdef CONFIG_RTL_LAYERED_DRIVER +struct rtl865x_vlanConfig { + uint8 ifname[IFNAMSIZ]; + uint8 isWan; + uint16 if_type; + uint16 vid; + uint16 fid; + uint32 memPort; + uint32 untagSet; + uint32 mtu; + ether_addr_t mac; + uint8 is_slave; +}; +#define RTL865X_CONFIG_END { "", 0, 0, 0, 0, 0, 0, 0, {{0}}, 0 } + +#define GATEWAY_MODE 0 +#define BRIDGE_MODE 1 +#define WISP_MODE 2 +//#define MULTIPLE_VLAN_BRIDGE_MODE 3 +//#define MULTIPLE_VLAN_WISP_MODE 4 +#define CONFIG_CHECK(expr) do {\ + if(((int32)expr)!=SUCCESS){\ + rtlglue_printf("Error >>> %s:%d failed !\n", __FUNCTION__,__LINE__);\ + return FAILED;\ + }\ +}while(0) + +#define INIT_CHECK(expr) do {\ + if(((int32)expr)!=SUCCESS){\ + rtlglue_printf("Error >>> %s:%d failed !\n", __FUNCTION__,__LINE__);\ + return FAILED;\ + }\ +}while(0) +#endif + +typedef struct _ps_drv_netif_mapping_s +{ + uint32 valid:1, //entry enable? + flags; //reserverd + struct net_device *ps_netif; //linux ps network interface + char drvName[MAX_IFNAMESIZE];//netif name in driver + +}ps_drv_netif_mapping_t; + +int32 rtl865x_changeOpMode(int mode); + +#if defined(CONFIG_RTL_ETH_PRIV_SKB) +__MIPS16 __IRAM_FWD int is_rtl865x_eth_priv_buf(unsigned char *head); +void free_rtl865x_eth_priv_buf(unsigned char *head); +#endif + +ps_drv_netif_mapping_t* rtl_get_ps_drv_netif_mapping_by_psdev(struct net_device *dev); +int rtl_add_ps_drv_netif_mapping(struct net_device *dev, const char *name); +int rtl_del_ps_drv_netif_mapping(struct net_device *dev); + +#if defined(CONFIG_RTK_VLAN_SUPPORT) && defined(CONFIG_RTK_VLAN_FOR_CABLE_MODEM) +extern struct net_device* get_dev_by_vid(int vid); +#endif +extern __MIPS16 struct net_device *get_shortcut_dev(unsigned char *da); +#define CONFIG_RTL_NIC_HWSTATS + +int32 rtl865x_changeOpMode(int mode); +int rtl865x_reChangeOpMode (void); + +#endif diff --git a/target/linux/realtek/files/include/net/rtl/rtl_queue.h b/target/linux/realtek/files/include/net/rtl/rtl_queue.h new file mode 100644 index 000000000..d5f9f174b --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl_queue.h @@ -0,0 +1,940 @@ + +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + * $FreeBSD: src/sys/sys/queue.h,v 1.32.2.4 2001/03/31 03:33:39 hsu Exp $ + */ + +#ifndef _RTL_QUEUE_H_ +#define _RTL_QUEUE_H_ + +////#include <machine/ansi.h> /* for __offsetof */ + +/* + * This file defines five types of data structures: singly-linked lists, + * singly-linked tail queues, lists, tail queues, and circular queues. + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A singly-linked tail queue is headed by a pair of pointers, one to the + * head of the list and the other to the tail of the list. The elements are + * singly linked for minimum space and pointer manipulation overhead at the + * expense of O(n) removal for arbitrary elements. New elements can be added + * to the list after an existing element, at the head of the list, or at the + * end of the list. Elements being removed from the head of the tail queue + * should use the explicit macro for this purpose for optimum efficiency. + * A singly-linked tail queue may only be traversed in the forward direction. + * Singly-linked tail queues are ideal for applications with large datasets + * and few or no removals or for implementing a FIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * A circle queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or after + * an existing element, at the head of the list, or at the end of the list. + * A circle queue may be traversed in either direction, but has a more + * complex end of list detection. + * + * For details on the use of these macros, see the queue(3) manual page. + * + * + * SLIST LIST STAILQ TAILQ CIRCLEQ + * _HEAD + + + + + + * _ENTRY + + + + + + * _INIT + + + + + + * _EMPTY + + + + + + * _FIRST + + + + + + * _NEXT + + + + + + * _PREV - - - + + + * _LAST - - + + + + * _FOREACH + + + + + + * _FOREACH_REVERSE - - - + + + * _INSERT_HEAD + + + + + + * _INSERT_BEFORE - + - + + + * _INSERT_AFTER + + + + + + * _INSERT_TAIL - - + + + + * _REMOVE_HEAD + - + - - + * _REMOVE + + + + + + * + */ + +#ifndef __offsetof +#define __offsetof(type, field) ((unsigned long)(&((type *)0)->field)) +#endif + +/* + * Singly-linked List definitions. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#define SLIST_EMPTY(head) ((head)->slh_first == NULL) + +#define SLIST_FIRST(head) ((head)->slh_first) + +#define SLIST_FOREACH(var, head, field) \ + for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next) + +#define SLIST_INIT(head) { \ + (head)->slh_first = NULL; \ +} + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ +} while (0) + +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ +} while (0) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + if ((head)->slh_first == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = (head)->slh_first; \ + while( curelm->field.sle_next != (elm) ) \ + curelm = curelm->field.sle_next; \ + curelm->field.sle_next = \ + curelm->field.sle_next->field.sle_next; \ + } \ +} while (0) + +/* + * Counting Singly-linked List definitions. + */ +#define CSLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ + int slh_count;\ +} + +#define CSLIST_HEAD_INITIALIZER(head) \ + {0, NULL } + +#define CSLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#define CSLIST_EMPTY(head) ((head)->slh_first == NULL) +#define CSLIST_FIRST(head) ((head)->slh_first) +#define CSLIST_TOTAL(head) ((head)->slh_count) +#define CSLIST_FOREACH(var, head, field) \ + for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next) + +#define CSLIST_INIT(head) { \ + (head)->slh_count=0;\ + (head)->slh_first = NULL; \ +} + +#define CSLIST_INSERT_AFTER(head, slistelm, elm, field) do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ + (head)->slh_count++;\ +} while (0) + +#define CSLIST_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ + (head)->slh_count++;\ +} while (0) + +#define CSLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define CSLIST_REMOVE_HEAD(head, field) do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ + (head)->slh_count--;\ +} while (0) + +#define CSLIST_REMOVE(head, elm, type, field) do { \ + if ((head)->slh_first == (elm)) { \ + CSLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = (head)->slh_first; \ + while( curelm->field.sle_next != (elm) ) \ + curelm = curelm->field.sle_next; \ + curelm->field.sle_next = curelm->field.sle_next->field.sle_next;\ + (head)->slh_count--;\ + }\ +} while (0) + +/* + * Singly-linked Tail queue definitions. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first;/* first element */ \ + struct type **stqh_last;/* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) + +#define STAILQ_INIT(head) do { \ + (head)->stqh_first = NULL; \ + (head)->stqh_last = &(head)->stqh_first; \ +} while (0) + +#define STAILQ_FIRST(head) ((head)->stqh_first) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY(head) ? \ + NULL : \ + ((struct type *) \ + ((int8 *)((head)->stqh_last) - __offsetof(struct type, field)))) + +#define STAILQ_FOREACH(var, head, field) \ + for((var) = (head)->stqh_first; (var); (var) = (var)->field.stqe_next) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \ + (head)->stqh_last = &(elm)->field.stqe_next; \ + (head)->stqh_first = (elm); \ +} while (0) + +/*if the header->stqh_first == NULL,we should modify it*/ +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + if((head)->stqh_first == NULL) \ + STAILQ_INSERT_HEAD(head, elm, field); \ + else { \ + (elm)->field.stqe_next = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &(elm)->field.stqe_next; \ + } \ +} while (0) + +#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ + if (((elm)->field.stqe_next = (tqelm)->field.stqe_next) == NULL)\ + (head)->stqh_last = &(elm)->field.stqe_next; \ + (tqelm)->field.stqe_next = (elm); \ +} while (0) + +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if (((head)->stqh_first = \ + (head)->stqh_first->field.stqe_next) == NULL) \ + (head)->stqh_last = &(head)->stqh_first; \ +} while (0) + +#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \ + if (((head)->stqh_first = (elm)->field.stqe_next) == NULL) \ + (head)->stqh_last = &(head)->stqh_first; \ +} while (0) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + if ((head)->stqh_first == (elm)) { \ + STAILQ_REMOVE_HEAD(head, field); \ + } \ + else { \ + struct type *curelm = (head)->stqh_first; \ + while( curelm->field.stqe_next != (elm) ) \ + curelm = curelm->field.stqe_next; \ + if((curelm->field.stqe_next = \ + curelm->field.stqe_next->field.stqe_next) == NULL) \ + (head)->stqh_last = &(curelm)->field.stqe_next; \ + } \ +} while (0) + + +/* + * Counting Singly-linked Tail queue definitions. + */ +#define CSTAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first;/* first element */ \ + struct type **stqh_last;/* addr of last next element */ \ + int stqh_count;\ +} + +#define CSTAILQ_HEAD_INITIALIZER(head) \ + { 0, NULL, &(head).stqh_first } + +#define CSTAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +/* + * Counting Singly-linked Tail queue functions. + */ +#define CSTAILQ_EMPTY(head) ((head)->stqh_first == NULL) + +#define CSTAILQ_INIT(head) do { \ + (head)->stqh_count=0;\ + (head)->stqh_first = NULL; \ + (head)->stqh_last = &(head)->stqh_first; \ +} while (0) + +#define CSTAILQ_FIRST(head) ((head)->stqh_first) +#define CSTAILQ_TOTAL(head) ((head)->stqh_count) +#define CSTAILQ_LAST(head, type, field) \ + (CSTAILQ_EMPTY(head) ? \ + NULL : \ + ((struct type *) \ + ((int8 *)((head)->stqh_last) - __offsetof(struct type, field)))) + +#define CSTAILQ_FOREACH(var, head, field) \ + for((var) = (head)->stqh_first; (var); (var) = (var)->field.stqe_next) + +#define CSTAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \ + (head)->stqh_last = &(elm)->field.stqe_next; \ + (head)->stqh_first = (elm); \ + (head)->stqh_count++;\ +} while (0) + +#define CSTAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.stqe_next = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &(elm)->field.stqe_next; \ + (head)->stqh_count++;\ +} while (0) + +#define CSTAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ + if (((elm)->field.stqe_next = (tqelm)->field.stqe_next) == NULL)\ + (head)->stqh_last = &(elm)->field.stqe_next; \ + (tqelm)->field.stqe_next = (elm); \ + (head)->stqh_count++;\ +} while (0) + +#define CSTAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define CSTAILQ_REMOVE_HEAD(head, field) do { \ + if (((head)->stqh_first = \ + (head)->stqh_first->field.stqe_next) == NULL) \ + (head)->stqh_last = &(head)->stqh_first; \ + (head)->stqh_count--;\ +} while (0) + +#define CSTAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \ + if (((head)->stqh_first = (elm)->field.stqe_next) == NULL) \ + (head)->stqh_last = &(head)->stqh_first; \ + (head)->stqh_count--;\ +} while (0) + +#define CSTAILQ_REMOVE(head, elm, type, field) do { \ + if ((head)->stqh_first == (elm)) { \ + CSTAILQ_REMOVE_HEAD(head, field); \ + } \ + else { \ + struct type *curelm = (head)->stqh_first; \ + while( curelm->field.stqe_next != (elm) ) \ + curelm = curelm->field.stqe_next; \ + if((curelm->field.stqe_next = \ + curelm->field.stqe_next->field.stqe_next) == NULL) \ + (head)->stqh_last = &(curelm)->field.stqe_next; \ + (head)->stqh_count--;\ + } \ +} while (0) + +#if !(defined(__linux__) || defined(LIST_HEAD)) + +/* + * List definitions. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ + +#define LIST_EMPTY(head) ((head)->lh_first == NULL) + +#define LIST_FIRST(head) ((head)->lh_first) + +#define LIST_FOREACH(var, head, field) \ + for((var) = (head)->lh_first; (var); (var) = (var)->field.le_next) + +#define LIST_INIT(head) do { \ + (head)->lh_first = NULL; \ +} while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ +} while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ +} while (0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ +} while (0) + +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_REMOVE(elm, field) do { \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ +} while (0) + +#endif /* __linux__ */ + +/* + * Counting List definitions. + */ +#define CLIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ + int lh_count;\ +} + +#define CLIST_HEAD_INITIALIZER(head) \ + { 0, NULL } + +#define CLIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * Counting List functions. + */ + +#define CLIST_EMPTY(head) ((head)->lh_first == NULL) +#define CLIST_TOTAL(head) ((head)->lh_count) +#define CLIST_FIRST(head) ((head)->lh_first) + +#define CLIST_FOREACH(var, head, field) \ + for((var) = (head)->lh_first; (var); (var) = (var)->field.le_next) + +#define CLIST_INIT(head) do { \ + (head)->lh_count=0;\ + (head)->lh_first = NULL; \ +} while (0) + +#define CLIST_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ + (head)->lh_count++;\ +} while (0) + +#define CLIST_INSERT_BEFORE(head, listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ + (head)->lh_count++;\ +} while (0) + +#define CLIST_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ + (head)->lh_count++;\ +} while (0) + +#define CLIST_NEXT(elm, field) ((elm)->field.le_next) + +#define CLIST_REMOVE(head, elm, field) do { \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ + (head)->lh_count--;\ +} while (0) + + +/* + * Tail queue definitions. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ +} + +/* + * Tail queue functions. + */ +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) + +#define TAILQ_FOREACH(var, head, field) \ + for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define TAILQ_FIRST(head) ((head)->tqh_first) + +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#define TAILQ_INIT(head) do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ +} while (0) + +#define TAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ +} while (0) + +/* + * Counting Tail queue definitions. + */ +#define CTAILQ_HEAD(name, type) \ +struct name {\ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ + int tqh_count;\ +} + +#define CTAILQ_HEAD_INITIALIZER(head) \ + { 0, NULL, &(head).tqh_first } + +#define CTAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ +} + +/* + * Counting Tail queue functions. + */ +#define CTAILQ_EMPTY(head) ((head)->tqh_first == NULL) + +#define CTAILQ_FOREACH(var, head, field) \ + for (var = TAILQ_FIRST(head); var; var = TAILQ_NEXT(var, field)) + +#define CTAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define CTAILQ_FIRST(head) ((head)->tqh_first) +#define CTAILQ_TOTAL(head) ((head)->tqh_count) +#define CTAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + +#define CTAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define CTAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#define CTAILQ_INIT(head) do { \ + (head)->tqh_count=0;\ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ +} while (0) + +#define CTAILQ_INSERT_HEAD(head, elm, field) do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ + (head)->tqh_count++;\ +} while (0) + +#define CTAILQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_count++;\ +} while (0) + +#define CTAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ + (head)->tqh_count++; \ +} while (0) + +#define CTAILQ_INSERT_BEFORE(head, listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ + (head)->tqh_count++;\ +} while (0) + +#define CTAILQ_REMOVE(head, elm, field) do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + (head)->tqh_count--;\ +} while (0) + + + +/* + * Circular queue definitions. + */ +#define CIRCLEQ_HEAD(name, type) \ +struct name { \ + struct type *cqh_first; /* first element */ \ + struct type *cqh_last; /* last element */ \ +} + +#define CIRCLEQ_ENTRY(type) \ +struct { \ + struct type *cqe_next; /* next element */ \ + struct type *cqe_prev; /* previous element */ \ +} + +/* + * Circular queue functions. + */ +#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head)) + +#define CIRCLEQ_FIRST(head) ((head)->cqh_first) + +#define CIRCLEQ_FOREACH(var, head, field) \ + for((var) = (head)->cqh_first; \ + (var) != (void *)(head); \ + (var) = (var)->field.cqe_next) + +#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ + for((var) = (head)->cqh_last; \ + (var) != (void *)(head); \ + (var) = (var)->field.cqe_prev) + +#define CIRCLEQ_INIT(head) do { \ + (head)->cqh_first = (void *)(head); \ + (head)->cqh_last = (void *)(head); \ +} while (0) + +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + (elm)->field.cqe_next = (listelm)->field.cqe_next; \ + (elm)->field.cqe_prev = (listelm); \ + if ((listelm)->field.cqe_next == (void *)(head)) \ + (head)->cqh_last = (elm); \ + else \ + (listelm)->field.cqe_next->field.cqe_prev = (elm); \ + (listelm)->field.cqe_next = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \ + (elm)->field.cqe_next = (listelm); \ + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ + if ((listelm)->field.cqe_prev == (void *)(head)) \ + (head)->cqh_first = (elm); \ + else \ + (listelm)->field.cqe_prev->field.cqe_next = (elm); \ + (listelm)->field.cqe_prev = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.cqe_next = (head)->cqh_first; \ + (elm)->field.cqe_prev = (void *)(head); \ + if ((head)->cqh_last == (void *)(head)) \ + (head)->cqh_last = (elm); \ + else \ + (head)->cqh_first->field.cqe_prev = (elm); \ + (head)->cqh_first = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.cqe_next = (void *)(head); \ + (elm)->field.cqe_prev = (head)->cqh_last; \ + if ((head)->cqh_first == (void *)(head)) \ + (head)->cqh_first = (elm); \ + else \ + (head)->cqh_last->field.cqe_next = (elm); \ + (head)->cqh_last = (elm); \ +} while (0) + +#define CIRCLEQ_LAST(head) ((head)->cqh_last) + +#define CIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next) + +#define CIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev) + +#define CIRCLEQ_REMOVE(head, elm, field) do { \ + if ((elm)->field.cqe_next == (void *)(head)) \ + (head)->cqh_last = (elm)->field.cqe_prev; \ + else \ + (elm)->field.cqe_next->field.cqe_prev = \ + (elm)->field.cqe_prev; \ + if ((elm)->field.cqe_prev == (void *)(head)) \ + (head)->cqh_first = (elm)->field.cqe_next; \ + else \ + (elm)->field.cqe_prev->field.cqe_next = \ + (elm)->field.cqe_next; \ +} while (0) + +/* + * Counting Circular queue definitions. + */ +#define CCIRCLEQ_HEAD(name, type) \ +struct name { \ + struct type *cqh_first; /* first element */ \ + struct type *cqh_last; /* last element */ \ +} + +#define CCIRCLEQ_ENTRY(type) \ +struct { \ + int cqe_count;\ + struct type *cqe_next; /* next element */ \ + struct type *cqe_prev; /* previous element */ \ +} + +/* + * Counting Circular queue functions. + */ +#define CCIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head)) +#define CCIRCLEQ_FIRST(head) ((head)->cqh_first) +#define CCIRCLEQ_TOTAL(head) ((head))->cqh_count) +#define CCIRCLEQ_FOREACH(var, head, field) \ + for((var) = (head)->cqh_first; \ + (var) != (void *)(head); \ + (var) = (var)->field.cqe_next) + +#define CCIRCLEQ_FOREACH_REVERSE(var, head, field) \ + for((var) = (head)->cqh_last; \ + (var) != (void *)(head); \ + (var) = (var)->field.cqe_prev) + +#define CCIRCLEQ_INIT(head) do { \ + (head)->cqh_count=0;\ + (head)->cqh_first = (void *)(head); \ + (head)->cqh_last = (void *)(head); \ +} while (0) + +#define CCIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + (elm)->field.cqe_next = (listelm)->field.cqe_next; \ + (elm)->field.cqe_prev = (listelm); \ + if ((listelm)->field.cqe_next == (void *)(head)) \ + (head)->cqh_last = (elm); \ + else \ + (listelm)->field.cqe_next->field.cqe_prev = (elm); \ + (listelm)->field.cqe_next = (elm); \ + (head)->cqh_count++;\ +} while (0) + +#define CCIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \ + (elm)->field.cqe_next = (listelm); \ + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ + if ((listelm)->field.cqe_prev == (void *)(head)) \ + (head)->cqh_first = (elm); \ + else \ + (listelm)->field.cqe_prev->field.cqe_next = (elm); \ + (listelm)->field.cqe_prev = (elm); \ + (head)->cqh_count++;\ +} while (0) + +#define CCIRCLEQ_INSERT_HEAD(head, elm, field) do { \ + (elm)->field.cqe_next = (head)->cqh_first; \ + (elm)->field.cqe_prev = (void *)(head); \ + if ((head)->cqh_last == (void *)(head)) \ + (head)->cqh_last = (elm); \ + else \ + (head)->cqh_first->field.cqe_prev = (elm); \ + (head)->cqh_first = (elm); \ + (head)->cqh_count++;\ +} while (0) + +#define CCIRCLEQ_INSERT_TAIL(head, elm, field) do { \ + (elm)->field.cqe_next = (void *)(head); \ + (elm)->field.cqe_prev = (head)->cqh_last; \ + if ((head)->cqh_first == (void *)(head)) \ + (head)->cqh_first = (elm); \ + else \ + (head)->cqh_last->field.cqe_next = (elm); \ + (head)->cqh_last = (elm); \ + (head)->cqh_count++;\ +} while (0) + +#define CCIRCLEQ_LAST(head) ((head)->cqh_last) + +#define CCIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next) + +#define CCIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev) + +#define CCIRCLEQ_REMOVE(head, elm, field) do { \ + if ((elm)->field.cqe_next == (void *)(head)) \ + (head)->cqh_last = (elm)->field.cqe_prev; \ + else \ + (elm)->field.cqe_next->field.cqe_prev = \ + (elm)->field.cqe_prev; \ + if ((elm)->field.cqe_prev == (void *)(head)) \ + (head)->cqh_first = (elm)->field.cqe_next; \ + else \ + (elm)->field.cqe_prev->field.cqe_next = \ + (elm)->field.cqe_next; \ + (head)->cqh_count--;\ +} while (0) +#endif /* !_RTL_QUEUE_H_ */ diff --git a/target/linux/realtek/files/include/net/rtl/rtl_types.h b/target/linux/realtek/files/include/net/rtl/rtl_types.h new file mode 100644 index 000000000..cdd29436e --- /dev/null +++ b/target/linux/realtek/files/include/net/rtl/rtl_types.h @@ -0,0 +1,573 @@ +/* +* Copyright c Realtek Semiconductor Corporation, 2002 +* All rights reserved. +* +* Program : The header file of realtek type definition +* Abstract : +* Author : +* $Id: rtl_types.h,v 1.2 2008-01-18 07:53:11 hyking_liu Exp $ +* $Log: not supported by cvs2svn $ +* Revision 1.1 2007/12/21 10:29:52 davidhsu +* +: support nic driver +* +* Revision 1.27 2007/07/27 09:31:23 chenyl +* +: Add macro for MIPS16-enabled function declaration. +* +* Revision 1.26 2007/07/24 08:37:02 chenyl +* *: For MIPS16 related macros +* +* Revision 1.25 2007/06/25 13:08:43 alva_zhang +* -: remove suitable header file rtl_config.h +* +* Revision 1.24 2007/06/25 05:42:30 alva_zhang +* *: reopen including rtl_config.h +* +* Revision 1.23 2007/06/25 02:29:27 alva_zhang +* -: diable include rtl_config.h temporarily +* +* Revision 1.22 2007/06/23 09:11:00 alva_zhang +* +: add rtl_config.h which includes the MAcro indicate the usage of SDK +* +* Revision 1.21 2007/05/15 03:36:56 michaelhuang +* *: fixed compatibility for Linux Kernel 2.6 +* +* Revision 1.20 2007/04/04 15:48:54 chenyl +* +: cleshell commend for asic register configuration : mmtu ( multicast mtu ) +* +* Revision 1.19 2006/08/29 13:00:00 chenyl +* *: New SWNIC driver for RTL865xC +* *: some rearrange in re_core.c for Bootstrap sequence being more readable. +* +* Revision 1.18 2006/02/27 07:47:06 ympan +* +: No change by ympan +* +* Revision 1.17 2005/09/27 05:59:44 chenyl +* *: modify IRAM / DRAM layout: +* IRAM/DRAM-FWD : external used, swNic ... blahblah +* IRAM/DRAM-L2-FWD : fwdengine internal used, L2 and below (ex. preprocess, postprocess) +* IRAM/DRAM-L34-FWD : fwdengine internal used, L3/L4 process only (ex. Routing, decision table...etc). +* +* => If L34 is used, we strongly suggest L2 must be used, too. +* +* Revision 1.16 2005/08/23 14:38:26 chenyl +* +: apply prioirty IRAM/DRAM usage +* +* Revision 1.15 2005/08/22 07:33:55 chenyl +* *: don't set DRAM/IRAM for other OSs yet. +* +* Revision 1.14 2005/08/18 09:14:08 chenyl +* *: add code to porting to other OSs +* +* Revision 1.13 2005/08/18 06:29:29 chenyl +* +: always define the rtlglue_printf in rtl_types.h +* +* Revision 1.12 2005/07/01 09:34:41 yjlou +* *: porting swNic2.c into model code. +* +* Revision 1.11 2005/06/19 05:29:37 yjlou +* *: use 'unsigned int' to replace 'size_t' +* *: define spinlock_t when RTL865X_MODEL_USER defined. +* +* Revision 1.10 2005/06/10 05:32:22 yjlou +* +: Porting CLE Shell to Linux user space for model test. +* See RTL865X_MODEL_USER compile flags. +* +* Revision 1.9 2005/01/10 03:21:43 yjlou +* *: always define __IRAM and __DRAM +* +* Revision 1.8 2004/07/23 13:42:45 tony +* *: remove all warning messages +* +* Revision 1.7 2004/07/05 08:25:32 chenyl +* +: define __IRAM, __DRAM for module test +* +* Revision 1.6 2004/07/04 15:04:55 cfliu +* +: add IRAM and DRAM +* +* Revision 1.5 2004/04/20 03:44:03 tony +* if disable define "RTL865X_OVER_KERNEL" and "RTL865X_OVER_LINUX", __KERNEL__ and __linux__ will be undefined. +* +* Revision 1.4 2004/03/19 13:13:35 cfliu +* Reorganize ROME driver local header files. Put all private data structures into different .h file corrsponding to its layering +* Rename printf, printk, malloc, free with rtlglue_XXX prefix +* +* Revision 1.3 2004/03/05 07:44:27 cfliu +* fix header file problem for ctype.h +* +* Revision 1.2 2004/03/03 10:40:38 yjlou +* *: commit for mergence the difference in rtl86xx_tbl/ since 2004/02/26. +* +* Revision 1.1 2004/02/25 14:26:33 chhuang +* *** empty log message *** +* +* Revision 1.3 2004/02/25 14:24:52 chhuang +* *** empty log message *** +* +* Revision 1.8 2003/12/10 06:30:12 tony +* add linux/config.h, disable define CONFIG_RTL865X_NICDRV2 in mbuf.c by default +* +* Revision 1.7 2003/12/03 14:25:43 cfliu +* change SIZE_T to _SIZE_T. Linux kernel seems to recognize _SIZE_T +* +* Revision 1.6 2003/10/01 12:29:02 tony +* #define DEBUG_P(args...) while(0); +* +* Revision 1.5 2003/10/01 10:31:47 tony +* solve all the compiler warnning messages in the board.c +* +* Revision 1.4 2003/09/30 06:07:50 orlando +* check in RTL8651BLDRV_V20_20030930 +* +* Revision 1.30 2003/07/21 06:27:49 cfliu +* no message +* +* Revision 1.29 2003/04/30 15:32:30 cfliu +* move macros to types.h +* +* Revision 1.28 2003/03/13 10:29:22 cfliu +* Remove unused symbols +* +* Revision 1.27 2003/03/06 05:00:04 cfliu +* Move '#pragma ghs inlineprologue' to rtl_depend.h since it is compiler dependent +* +* Revision 1.26 2003/03/06 03:41:46 danwu +* Prevent compiler from generating internal sub-routine call code at the +* function prologue and epilogue automatically +* +* Revision 1.25 2003/03/03 09:16:35 hiwu +* remove ip4a +* +* Revision 1.24 2003/02/18 10:04:06 jzchen +* Add ether_addr_t to compatable with protocol stack's ether_addr +* +* Revision 1.23 2003/01/21 05:59:51 cfliu +* add min, max, SETBITS, CLEARBITS, etc. +* +* Revision 1.22 2002/11/25 07:31:30 cfliu +* Remove _POSIX_SOURCE since it is cygwin specific +* +* Revision 1.21 2002/09/30 11:51:49 jzchen +* Add ASSERT_ISR for not print inside ISR +* +* Revision 1.20 2002/09/18 01:43:24 jzchen +* Add type limit definition +* +* Revision 1.19 2002/09/16 00:14:34 elvis +* remove struct posix_handle_t (change the handle type from +* structure to uint32) +* +* Revision 1.18 2002/08/20 01:40:40 danwu +* Add definitions of ipaddr_t & macaddr_t. +* +* Revision 1.17 2002/07/30 04:36:30 danwu +* Add ASSERT_CSP. +* +* Revision 1.16 2002/07/19 06:47:30 cfliu +* Add _POSIX_SOURCE symbol +* +* Revision 1.15 2002/07/05 02:10:39 elvis +* Add new types for OSK +* +* Revision 1.14 2002/07/03 12:36:21 orlando +* <rtl_depend.h> will use type definitions. Has to be moved to +* be after the type declaration lines. +* +* Revision 1.13 2002/07/03 09:19:00 cfliu +* Removed all standard header files from source code. They would be included by <core/types.h>-><rtl_depend.h> +* +* Revision 1.12 2002/07/03 09:16:48 cfliu +* Removed all standard header files from source code. They would be included by <core/types.h>-><rtl_depend.h> +* +* Revision 1.11 2002/07/03 07:14:47 orlando +* Add "struct posix_handle_t_", used by POSIX module. +* +* Revision 1.9 2002/06/21 03:15:36 cfliu +* Add time.h for struct timeval +* +* Revision 1.8 2002/06/14 01:58:03 cfliu +* Move sa_family_t to socket +* +* Revision 1.7 2002/06/13 09:37:42 cfliu +* Move byte order conversion routines to socket +* +* Revision 1.6 2002/05/23 04:24:37 hiwu +* change memaddr_t to calladdr_t +* +* Revision 1.5 2002/05/13 10:15:16 hiwu +* add new type definition +* +* Revision 1.4 2002/05/09 05:21:51 cfliu +* Add parenthesis around swaps16, swapl32 +* +* Revision 1.3 2002/04/30 03:07:34 orlando +* Remove UIxx_T definitions to conform with new +* naming conventions. +* +* Revision 1.2 2002/04/29 10:10:32 hiwu +* add NTOHS macro +* +* Revision 1.1.1.1 2002/04/26 08:53:53 orlando +* Initial source tree creation. +* +* Revision 1.9 2002/04/25 03:59:05 cfliu +* no message +* +* Revision 1.8 2002/04/08 08:08:04 hiwu +* initial version +* +*/ + + +#ifndef _RTL_TYPES_H +#define _RTL_TYPES_H + +#define RTL_LAYERED_DRIVER_DEBUG 0 + +#if 0 +#ifndef RTL865X_OVER_KERNEL + #undef __KERNEL__ +#endif + +#ifndef RTL865X_OVER_LINUX + #undef __linux__ +#endif +#endif + +/* + * Internal names for basic integral types. Omit the typedef if + * not possible for a machine/compiler combination. + */ +#ifdef __linux__ +#ifdef __KERNEL__ +#include <linux/version.h> +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) +#include <linux/config.h> +#endif +#include <linux/ctype.h> +#include <linux/module.h> +#include <linux/string.h> +#endif /*__KERNEL__*/ +#endif /*__linux__*/ + +/* =============================================================================== + IRAM / DRAM definition + =============================================================================== */ +#undef __DRAM_GEN +#undef __DRAM_FWD +#undef __DRAM_L2_FWD +#undef __DRAM_L34_FWD +#undef __DRAM_EXTDEV +#undef __DRAM_AIRGO +#undef __DRAM_RTKWLAN +#undef __DRAM_CRYPTO +#undef __DRAM_VOIP +#undef __DRAM_TX +#undef __DRAM + +#undef __IRAM_GEN +#undef __IRAM_FWD +#undef __IRAM_L2_FWD +#undef __IRAM_L34_FWD +#undef __IRAM_EXTDEV +#undef __IRAM_AIRGO +#undef __IRAM_RTKWLAN +#undef __IRAM_CRYPTO +#undef __IRAM_VOIP +#undef __IRAM_TX +#undef __IRAM + +#if defined(__linux__)&&defined(__KERNEL__)&&defined(CONFIG_RTL_819X) + #define __DRAM_GEN __attribute__ ((section(".dram-gen"))) + #define __DRAM_FWD __attribute__ ((section(".dram-fwd"))) + #define __DRAM_L2_FWD __attribute__ ((section(".dram-l2-fwd"))) + #define __DRAM_L34_FWD __attribute__ ((section(".dram-l34-fwd"))) + #define __DRAM_EXTDEV __attribute__ ((section(".dram-extdev"))) + #define __DRAM_AIRGO __attribute__ ((section(".dram-airgo"))) + #define __DRAM_RTKWLAN __attribute__ ((section(".dram-rtkwlan"))) + #define __DRAM_CRYPTO __attribute__ ((section(".dram-crypto"))) + #define __DRAM_VOIP __attribute__ ((section(".dram-voip"))) + #define __DRAM_TX __attribute__ ((section(".dram-tx"))) + #define __DRAM __attribute__ ((section(".dram"))) + + #define __IRAM_GEN __attribute__ ((section(".iram-gen"))) + #define __IRAM_FWD __attribute__ ((section(".iram-fwd"))) + #define __IRAM_L2_FWD __attribute__ ((section(".iram-l2-fwd"))) + #define __IRAM_L34_FWD __attribute__ ((section(".iram-l34-fwd"))) + #define __IRAM_EXTDEV __attribute__ ((section(".iram-extdev"))) + #define __IRAM_AIRGO __attribute__ ((section(".iram-airgo"))) + #define __IRAM_RTKWLAN __attribute__ ((section(".iram-rtkwlan"))) + #define __IRAM_CRYPTO __attribute__ ((section(".iram-crypto"))) + #define __IRAM_VOIP __attribute__ ((section(".iram-voip"))) + #define __IRAM_TX __attribute__ ((section(".iram-tx"))) + #define __IRAM __attribute__ ((section(".iram"))) +#else + #define __DRAM_GEN + #define __DRAM_FWD + #define __DRAM_L2_FWD + #define __DRAM_L34_FWD + #define __DRAM_EXTDEV + #define __DRAM_AIRGO + #define __DRAM_RTKWLAN + #define __DRAM_CRYPTO + #define __DRAM_VOIP + #define __DRAM_TX + #define __DRAM + + #define __IRAM_GEN + #define __IRAM_FWD + #define __IRAM_L2_FWD + #define __IRAM_L34_FWD + #define __IRAM_EXTDEV + #define __IRAM_AIRGO + #define __IRAM_RTKWLAN + #define __IRAM_CRYPTO + #define __IRAM_VOIP + #define __IRAM_TX + #define __IRAM +#endif + +#if defined(CONFIG_RTL_DYNAMIC_IRAM_MAPPING_FOR_WAPI) + #define __IRAM_GEN_WAPI __attribute__ ((section(".iram-gen-wapi"))) + #define __IRAM_FWD_WAPI __attribute__ ((section(".iram-fwd-wapi"))) + #define __IRAM_L2_FWD_WAPI __attribute__ ((section(".iram-l2-fwd-wapi"))) + #define __IRAM_L34_FWD_WAPI __attribute__ ((section(".iram-l34-fwd-wapi"))) + #define __IRAM_RTKWLAN_WAPI __attribute__ ((section(".iram-rtkwlan-wapi"))) + #define __IRAM_TX_WAPI __attribute__ ((section(".iram-tx-wapi"))) + + #define FUNCTION_CHECK(x) do \ + { \ + if((x)==NULL) \ + printk("---%s %s(%d) function is NULL!!\n",__FILE__,__FUNCTION__,__LINE__); \ + } while(0) +#endif + + +/* =============================================================================== + Additional GCC attribute + =============================================================================== */ + +#undef __NOMIPS16 +#undef __MIPS16 + +#if defined(__linux__)&&defined(__KERNEL__)&&defined(CONFIG_RTL_819X) && !defined(CONFIG_RTL_8196C) + #define __NOMIPS16 __attribute__((nomips16)) /* Inidcate to prevent from MIPS16 */ + #define __MIPS16 __attribute__((mips16)) /* Inidcate to use MIPS16 */ +#else + #define __NOMIPS16 + #define __MIPS16 +#endif + +/* =============================================================================== + print macro + =============================================================================== */ +#if defined(__linux__)&&defined(__KERNEL__) + + #define rtlglue_printf printk + +#else /* defined(__linux__)&&defined(__KERNEL__) */ + +#ifdef RTL865X_TEST + #include <ctype.h> +#endif /* RTL865X_TEST */ + +#define rtlglue_printf printf + +#endif /* defined(__linux__)&&defined(__KERNEL__) */ + +/* =============================================================================== + Type definition + =============================================================================== */ +#if 1 +typedef unsigned long long uint64; +typedef long long int64; +typedef unsigned int uint32; + +#ifdef int32 +#undef int32 +#endif +typedef int int32; + +typedef unsigned short uint16; +typedef short int16; +typedef unsigned char uint8; +typedef char int8; + +#else +typedef __u64 uint64; +typedef __s64 int64; +typedef __u32 uint32; +#ifndef int32 +typedef __s32 int32; +#endif +typedef __u16 uint16; +typedef __s16 int16; +typedef __u8 uint8; +typedef __s8 int8; +#endif + +typedef uint32 memaddr; +typedef uint32 ipaddr_t; +typedef struct { + uint16 mac47_32; + uint16 mac31_16; + uint16 mac15_0; +} macaddr_t; + +#define ETHER_ADDR_LEN 6 +typedef struct ether_addr_s { + uint8 octet[ETHER_ADDR_LEN]; +} ether_addr_t; + +#define RX_OFFSET 2 +#define MBUF_LEN 1700 +#define CROSS_LAN_MBUF_LEN (MBUF_LEN+RX_OFFSET+10) + +#if defined(CONFIG_RTL_819X) + #if defined(CONFIG_RTL_ETH_PRIV_SKB) + #define DELAY_REFILL_ETH_RX_BUF 1 + #endif +#endif + +/* + CN SD6 Mantis issue #1085: NIC RX can't work correctly after runout. + this bug still happened in RTL8196B + */ + +#ifndef NULL +#define NULL 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#ifndef SUCCESS +#define SUCCESS 0 +#endif +#ifndef FAILED +#define FAILED -1 +#endif + + + +#define DEBUG_P(args...) while(0); +#ifndef OK +#define OK 0 +#endif +#ifndef NOT_OK +#define NOT_OK 1 +#endif + +#ifndef CLEARBITS +#define CLEARBITS(a,b) ((a) &= ~(b)) +#endif + +#ifndef SETBITS +#define SETBITS(a,b) ((a) |= (b)) +#endif + +#ifndef ISSET +#define ISSET(a,b) (((a) & (b))!=0) +#endif + +#ifndef ISCLEARED +#define ISCLEARED(a,b) (((a) & (b))==0) +#endif + +#ifndef max +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif /* max */ + +#ifndef min +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif /* min */ + +//round down x to multiple of y. Ex: ROUNDDOWN(20, 7)=14 +#ifndef ROUNDDOWN +#define ROUNDDOWN(x, y) (((x)/(y))*(y)) +#endif + +//round up x to multiple of y. Ex: ROUNDUP(11, 7) = 14 +#ifndef ROUNDUP +#define ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ +#endif + +#ifndef ROUNDUP2 +#define ROUNDUP2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ +#endif + +#ifndef ROUNDUP4 +#define ROUNDUP4(x) ((1+(((x)-1)>>2))<<2) +#endif + +#ifndef IS4BYTEALIGNED +#define IS4BYTEALIGNED(x) ((((x) & 0x3)==0)? 1 : 0) +#endif + +#ifndef __offsetof +#define __offsetof(type, field) ((unsigned long)(&((type *)0)->field)) +#endif + +#ifndef offsetof +#define offsetof(type, field) __offsetof(type, field) +#endif + +#ifndef RTL_PROC_CHECK +#define RTL_PROC_CHECK(expr, success) \ + do {\ + int __retval; \ + if ((__retval = (expr)) != (success))\ + {\ + rtlglue_printf("ERROR >>> [%s]:[%d] failed -- return value: %d\n", __FUNCTION__,__LINE__, __retval);\ + return __retval; \ + }\ + }while(0) +#endif + +#ifndef RTL_STREAM_SAME +#define RTL_STREAM_SAME(s1, s2) \ + ((strlen(s1) == strlen(s2)) && (strcmp(s1, s2) == 0)) +#endif + +#define ASSERT_ISR(x) if(!(x)) {while(1);} +#define RTL_STATIC_INLINE static __inline__ + +#define ASSERT_CSP(x) if (!(x)) {rtlglue_printf("\nAssert Fail: %s %d", __FILE__, __LINE__); while(1);} + + +#if defined(RTL865X_TEST)||defined(RTL865X_MODEL_USER) +#define UNCACHE_MASK 0 +#define UNCACHE(addr) (addr) +#define CACHED(addr) ((uint32)(addr)) +#else +#define UNCACHE_MASK 0x20000000 +#define UNCACHE(addr) ((UNCACHE_MASK)|(uint32)(addr)) +#define CACHED(addr) ((uint32)(addr) & ~(UNCACHE_MASK)) +#endif + +#if defined(CONFIG_RTL_PROC_DEBUG) +#define RTL865X_DRIVER_DEBUG_FLAG /*flag for debug*/ +#else +#undef RTL865X_DRIVER_DEBUG_FLAG /*flag for debug*/ +#endif + +/* asic configuration */ +#define RTL8651_OUTPUTQUEUE_SIZE 6 +#define TOTAL_VLAN_PRIORITY_NUM 8 +#define RTL8651_RATELIMITTBL_SIZE 32 + +#if defined(CONFIG_RTL_8196C) +#define CONFIG_RTL8196C_ETH_IOT 1 +#ifdef CONFIG_RTL_WTDOG +#define CONFIG_RTL_8196C_ESD 1 +#endif +#endif + +#if defined(CONFIG_RTL_8198) && defined(CONFIG_RTL_WTDOG) +#define CONFIG_RTL_8198_ESD 1 +#endif + +#endif + |