mediatek: add hwnat module
[openwrt/staging/blogic.git] / target / linux / mediatek / patches-4.9 / 0310-hwnat.patch
1 Index: linux-4.9.29/drivers/net/ethernet/mediatek/mtk_eth_soc.c
2 ===================================================================
3 --- linux-4.9.29.orig/drivers/net/ethernet/mediatek/mtk_eth_soc.c
4 +++ linux-4.9.29/drivers/net/ethernet/mediatek/mtk_eth_soc.c
5 @@ -23,6 +23,10 @@
6 #include <linux/reset.h>
7 #include <linux/tcp.h>
8
9 +#if defined(CONFIG_NET_MEDIATEK_HNAT) || defined(CONFIG_NET_MEDIATEK_HNAT_MODULE)
10 +#include "mtk_hnat/nf_hnat_mtk.h"
11 +#endif
12 +
13 #include "mtk_eth_soc.h"
14
15 static int mtk_msg_level = -1;
16 @@ -649,6 +653,11 @@ static int mtk_tx_map(struct sk_buff *sk
17 return -ENOMEM;
18
19 /* set the forward port */
20 +#if defined(CONFIG_NET_MEDIATEK_HNAT) || defined(CONFIG_NET_MEDIATEK_HNAT_MODULE)
21 + if (HNAT_SKB_CB2(skb)->magic == 0x78681415)
22 + fport |= 0x4 << TX_DMA_FPORT_SHIFT;
23 + else
24 +#endif
25 fport = (mac->id + 1) << TX_DMA_FPORT_SHIFT;
26 txd4 |= fport;
27
28 @@ -945,9 +954,8 @@ static int mtk_poll_rx(struct napi_struc
29 break;
30
31 /* find out which mac the packet come from. values start at 1 */
32 - mac = (trxd.rxd4 >> RX_DMA_FPORT_SHIFT) &
33 - RX_DMA_FPORT_MASK;
34 - mac--;
35 + mac = (trxd.rxd4 >> 22) & 0x1;
36 + mac = (mac + 1) % 2;
37
38 netdev = eth->netdev[mac];
39
40 @@ -971,6 +979,9 @@ static int mtk_poll_rx(struct napi_struc
41 }
42
43 /* receive data */
44 + if (mac < 0 || mac > 2)
45 + goto skip;
46 +
47 skb = build_skb(data, ring->frag_size);
48 if (unlikely(!skb)) {
49 skb_free_frag(new_data);
50 @@ -994,9 +1005,14 @@ static int mtk_poll_rx(struct napi_struc
51 RX_DMA_VID(trxd.rxd3))
52 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q),
53 RX_DMA_VID(trxd.rxd3));
54 +#if defined(CONFIG_NET_MEDIATEK_HNAT) || defined(CONFIG_NET_MEDIATEK_HNAT_MODULE)
55 + *(u32 *)(skb->head) = trxd.rxd4;
56 + skb_hnat_alg(skb) = 0;
57 +#endif
58 skb_record_rx_queue(skb, 0);
59 napi_gro_receive(napi, skb);
60
61 +skip:
62 ring->data[idx] = new_data;
63 rxd->rxd1 = (unsigned int)dma_addr;
64
65 @@ -1883,18 +1899,14 @@ static int mtk_hw_init(struct mtk_eth *e
66 val = mtk_r32(eth, MTK_CDMQ_IG_CTRL);
67 mtk_w32(eth, val | MTK_CDMQ_STAG_EN, MTK_CDMQ_IG_CTRL);
68
69 - /* Indicates CDM to parse the MTK special tag from CPU
70 - * which also is working out for untag packets.
71 - */
72 - val = mtk_r32(eth, MTK_CDMQ_IG_CTRL);
73 - mtk_w32(eth, val | MTK_CDMQ_STAG_EN, MTK_CDMQ_IG_CTRL);
74 -
75 /* Enable RX VLan Offloading */
76 if (MTK_HW_FEATURES & NETIF_F_HW_VLAN_CTAG_RX)
77 mtk_w32(eth, 1, MTK_CDMP_EG_CTRL);
78 else
79 mtk_w32(eth, 0, MTK_CDMP_EG_CTRL);
80
81 + mtk_w32(eth, 0x81000001, MTK_CDMP_IG_CTRL);
82 +
83 /* disable delay and normal interrupt */
84 #ifdef MTK_IRQ_DLY
85 mtk_w32(eth, 0x84048404, MTK_PDMA_DELAY_INT);
86 @@ -1924,6 +1936,9 @@ static int mtk_hw_init(struct mtk_eth *e
87 /* Enable RX checksum */
88 val |= MTK_GDMA_ICS_EN | MTK_GDMA_TCS_EN | MTK_GDMA_UCS_EN;
89
90 + if (!i)
91 + val |= BIT(24);
92 +
93 /* setup the mac dma */
94 mtk_w32(eth, val, MTK_GDMA_FWD_CFG(i));
95 }
96 Index: linux-4.9.29/drivers/net/ethernet/mediatek/mtk_eth_soc.h
97 ===================================================================
98 --- linux-4.9.29.orig/drivers/net/ethernet/mediatek/mtk_eth_soc.h
99 +++ linux-4.9.29/drivers/net/ethernet/mediatek/mtk_eth_soc.h
100 @@ -78,6 +78,9 @@
101 #define MTK_CDMQ_IG_CTRL 0x1400
102 #define MTK_CDMQ_STAG_EN BIT(0)
103
104 +/* CDMP Ingress Control Register */
105 +#define MTK_CDMP_IG_CTRL 0x400
106 +
107 /* CDMP Exgress Control Register */
108 #define MTK_CDMP_EG_CTRL 0x404
109
110 @@ -87,6 +90,9 @@
111 #define MTK_GDMA_TCS_EN BIT(21)
112 #define MTK_GDMA_UCS_EN BIT(20)
113
114 +/* GDMA Ingress Control Register */
115 +#define MTK_GDMA1_IG_CTRL(x) (0x500 + (x * 0x1000))
116 +
117 /* Unicast Filter MAC Address Register - Low */
118 #define MTK_GDMA_MAC_ADRL(x) (0x508 + (x * 0x1000))
119
120 Index: linux-4.9.29/net/netfilter/nf_conntrack_proto_tcp.c
121 ===================================================================
122 --- linux-4.9.29.orig/net/netfilter/nf_conntrack_proto_tcp.c
123 +++ linux-4.9.29/net/netfilter/nf_conntrack_proto_tcp.c
124 @@ -11,6 +11,7 @@
125 #include <linux/types.h>
126 #include <linux/timer.h>
127 #include <linux/module.h>
128 +#include <linux/inetdevice.h>
129 #include <linux/in.h>
130 #include <linux/tcp.h>
131 #include <linux/spinlock.h>
132 @@ -19,6 +20,7 @@
133 #include <net/ip6_checksum.h>
134 #include <asm/unaligned.h>
135
136 +#include <net/ip.h>
137 #include <net/tcp.h>
138
139 #include <linux/netfilter.h>
140 @@ -53,6 +55,11 @@ static int nf_ct_tcp_max_retrans __read_
141 /* FIXME: Examine ipfilter's timeouts and conntrack transitions more
142 closely. They're more complex. --RR */
143
144 +#ifndef IPV4_DEVCONF_DFLT
145 + #define IPV4_DEVCONF_DFLT(net, attr) \
146 + IPV4_DEVCONF((*net->ipv4.devconf_dflt), attr)
147 +#endif
148 +
149 static const char *const tcp_conntrack_names[] = {
150 "NONE",
151 "SYN_SENT",
152 @@ -519,6 +526,18 @@ static bool tcp_in_window(const struct n
153 if (nf_ct_tcp_no_window_check)
154 return true;
155
156 + if (net) {
157 + if ((net->ipv4.devconf_all && net->ipv4.devconf_dflt && net->ipv6.devconf_all) &&
158 + net->ipv6.devconf_dflt) {
159 + if ((IPV4_DEVCONF_DFLT(net, FORWARDING) ||
160 + IPV4_DEVCONF_ALL(net, FORWARDING)) ||
161 + (net->ipv6.devconf_all->forwarding ||
162 + net->ipv6.devconf_dflt->forwarding)) {
163 + return true;
164 + }
165 + }
166 + }
167 +
168 /*
169 * Get the required data from the packet.
170 */