ramips: mt7621: improve hnat driver support

This commit is contained in:
MeIsReallyBa 2022-05-28 17:16:19 +08:00 committed by AmadeusGhost
parent 590517f040
commit 9cd22dd829
5 changed files with 34 additions and 18 deletions

View File

@ -1027,7 +1027,7 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
nr_frags = skb_shinfo(skb)->nr_frags; nr_frags = skb_shinfo(skb)->nr_frags;
qid = skb->mark & (MTK_QDMA_TX_MASK); qid = mac->id;
#if defined(CONFIG_MEDIATEK_NETSYS_V2) #if defined(CONFIG_MEDIATEK_NETSYS_V2)
if(!qid && mac->id) if(!qid && mac->id)
@ -1180,9 +1180,6 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
txd_pdma->txd2 |= TX_DMA_LS1; txd_pdma->txd2 |= TX_DMA_LS1;
} }
netdev_sent_queue(dev, skb->len);
skb_tx_timestamp(skb);
ring->next_free = mtk_qdma_phys_to_virt(ring, txd->txd2); ring->next_free = mtk_qdma_phys_to_virt(ring, txd->txd2);
atomic_sub(n_desc, &ring->free_count); atomic_sub(n_desc, &ring->free_count);
@ -1408,6 +1405,9 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
0 : RX_DMA_GET_SPORT(trxd.rxd4) - 1; 0 : RX_DMA_GET_SPORT(trxd.rxd4) - 1;
} }
if (mac == 4)
mac = 0;
if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT || if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
!eth->netdev[mac])) !eth->netdev[mac]))
goto release_desc; goto release_desc;
@ -1642,7 +1642,6 @@ static int mtk_poll_tx(struct mtk_eth *eth, int budget)
for (i = 0; i < MTK_MAC_COUNT; i++) { for (i = 0; i < MTK_MAC_COUNT; i++) {
if (!eth->netdev[i] || !done[i]) if (!eth->netdev[i] || !done[i])
continue; continue;
netdev_completed_queue(eth->netdev[i], done[i], bytes[i]);
total += done[i]; total += done[i];
} }
@ -1809,6 +1808,7 @@ static int mtk_tx_alloc(struct mtk_eth *eth)
mtk_w32(eth, ring->last_free_ptr, MTK_QTX_DRX_PTR); mtk_w32(eth, ring->last_free_ptr, MTK_QTX_DRX_PTR);
mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES, mtk_w32(eth, (QDMA_RES_THRES << 8) | QDMA_RES_THRES,
MTK_QTX_CFG(0)); MTK_QTX_CFG(0));
mtk_w32(eth, BIT(31), MTK_QTX_SCH(0));
} else { } else {
mtk_w32(eth, ring->phys_pdma, MT7628_TX_BASE_PTR0); mtk_w32(eth, ring->phys_pdma, MT7628_TX_BASE_PTR0);
mtk_w32(eth, MTK_DMA_SIZE, MT7628_TX_MAX_CNT0); mtk_w32(eth, MTK_DMA_SIZE, MT7628_TX_MAX_CNT0);

View File

@ -308,7 +308,7 @@ static int hnat_hw_init(u32 ppe_id)
/* enable FOE */ /* enable FOE */
cr_set_bits(hnat_priv->ppe_base[ppe_id] + PPE_FLOW_CFG, cr_set_bits(hnat_priv->ppe_base[ppe_id] + PPE_FLOW_CFG,
BIT_IPV4_NAT_EN | BIT_IPV4_NAPT_EN | BIT_TCP_IP4F_NAT_EN | BIT_IPV4_NAT_EN | BIT_IPV4_NAPT_EN |
BIT_IPV4_NAT_FRAG_EN | BIT_IPV4_HASH_GREK | BIT_IPV4_NAT_FRAG_EN | BIT_IPV4_HASH_GREK |
BIT_IPV4_DSL_EN | BIT_IPV6_6RD_EN | BIT_IPV4_DSL_EN | BIT_IPV6_6RD_EN |
BIT_IPV6_3T_ROUTE_EN | BIT_IPV6_5T_ROUTE_EN); BIT_IPV6_3T_ROUTE_EN | BIT_IPV6_5T_ROUTE_EN);
@ -855,7 +855,7 @@ static int hnat_remove(struct platform_device *pdev)
static const struct mtk_hnat_data hnat_data_v1 = { static const struct mtk_hnat_data hnat_data_v1 = {
.num_of_sch = 2, .num_of_sch = 2,
.whnat = false, .whnat = true,
.per_flow_accounting = false, .per_flow_accounting = false,
.mcast = false, .mcast = false,
.version = MTK_HNAT_V1, .version = MTK_HNAT_V1,

View File

@ -596,9 +596,9 @@ struct foe_entry {
/* If user wants to change default FOE entry number, both DEF_ETRY_NUM and /* If user wants to change default FOE entry number, both DEF_ETRY_NUM and
* DEF_ETRY_NUM_CFG need to be modified. * DEF_ETRY_NUM_CFG need to be modified.
*/ */
#define DEF_ETRY_NUM 8192 #define DEF_ETRY_NUM 16384
/* feasible values : 32768, 16384, 8192, 4096, 2048, 1024 */ /* feasible values : 32768, 16384, 8192, 4096, 2048, 1024 */
#define DEF_ETRY_NUM_CFG TABLE_8K #define DEF_ETRY_NUM_CFG TABLE_16K
/* corresponding values : TABLE_32K, TABLE_16K, TABLE_8K, TABLE_4K, TABLE_2K, /* corresponding values : TABLE_32K, TABLE_16K, TABLE_8K, TABLE_4K, TABLE_2K,
* TABLE_1K * TABLE_1K
*/ */
@ -740,6 +740,7 @@ enum FoeIpAct {
#define BIT_FUC_FOE BIT(2) #define BIT_FUC_FOE BIT(2)
#define BIT_FMC_FOE BIT(1) #define BIT_FMC_FOE BIT(1)
#define BIT_FBC_FOE BIT(0) #define BIT_FBC_FOE BIT(0)
#define BIT_TCP_IP4F_NAT_EN BIT(6)
#define BIT_UDP_IP4F_NAT_EN BIT(7) /*Enable IPv4 fragment + UDP packet NAT*/ #define BIT_UDP_IP4F_NAT_EN BIT(7) /*Enable IPv4 fragment + UDP packet NAT*/
#define BIT_IPV6_3T_ROUTE_EN BIT(8) #define BIT_IPV6_3T_ROUTE_EN BIT(8)
#define BIT_IPV6_5T_ROUTE_EN BIT(9) #define BIT_IPV6_5T_ROUTE_EN BIT(9)

View File

@ -393,9 +393,7 @@ unsigned int do_hnat_ext_to_ge(struct sk_buff *skb, const struct net_device *in,
} }
/*set where we come from*/ /*set where we come from*/
skb->vlan_proto = htons(ETH_P_8021Q); __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), in->ifindex & VLAN_VID_MASK);
skb->vlan_tci =
(VLAN_CFI_MASK | (in->ifindex & VLAN_VID_MASK));
trace_printk( trace_printk(
"%s: vlan_prot=0x%x, vlan_tci=%x, in->name=%s, skb->dev->name=%s\n", "%s: vlan_prot=0x%x, vlan_tci=%x, in->name=%s, skb->dev->name=%s\n",
__func__, ntohs(skb->vlan_proto), skb->vlan_tci, __func__, ntohs(skb->vlan_proto), skb->vlan_tci,
@ -426,6 +424,7 @@ unsigned int do_hnat_ext_to_ge2(struct sk_buff *skb, const char *func)
skb->dev = dev; skb->dev = dev;
skb->vlan_proto = 0; skb->vlan_proto = 0;
skb->vlan_tci = 0; skb->vlan_tci = 0;
__vlan_hwaccel_clear_tag(skb);
if (ntohs(eth->h_proto) == ETH_P_8021Q) { if (ntohs(eth->h_proto) == ETH_P_8021Q) {
skb = skb_vlan_untag(skb); skb = skb_vlan_untag(skb);
@ -456,6 +455,7 @@ unsigned int do_hnat_ext_to_ge2(struct sk_buff *skb, const char *func)
set_from_mape(skb); set_from_mape(skb);
skb->vlan_proto = 0; skb->vlan_proto = 0;
skb->vlan_tci = 0; skb->vlan_tci = 0;
__vlan_hwaccel_clear_tag(skb);
fix_skb_packet_type(skb, skb->dev, eth_hdr(skb)); fix_skb_packet_type(skb, skb->dev, eth_hdr(skb));
entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)]; entry = &hnat_priv->foe_table_cpu[skb_hnat_ppe(skb)][skb_hnat_entry(skb)];
entry->bfib1.pkt_type = IPV4_HNAPT; entry->bfib1.pkt_type = IPV4_HNAPT;
@ -650,9 +650,7 @@ unsigned int do_hnat_mape_w2l_fast(struct sk_buff *skb, const struct net_device
eth->h_proto = htons(ETH_P_IP); eth->h_proto = htons(ETH_P_IP);
set_to_ppe(skb); set_to_ppe(skb);
skb->vlan_proto = htons(ETH_P_8021Q); __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), in->ifindex & VLAN_VID_MASK);
skb->vlan_tci =
(VLAN_CFI_MASK | (in->ifindex & VLAN_VID_MASK));
if (!hnat_priv->g_ppdev) if (!hnat_priv->g_ppdev)
hnat_priv->g_ppdev = dev_get_by_name(&init_net, hnat_priv->ppd); hnat_priv->g_ppdev = dev_get_by_name(&init_net, hnat_priv->ppd);
@ -744,7 +742,7 @@ static unsigned int is_ppe_support_type(struct sk_buff *skb)
struct iphdr _iphdr; struct iphdr _iphdr;
eth = eth_hdr(skb); eth = eth_hdr(skb);
if (!is_magic_tag_valid(skb) || !IS_SPACE_AVAILABLE_HEAD(skb) || if (!IS_SPACE_AVAILABLE_HEAD(skb) ||
is_broadcast_ether_addr(eth->h_dest)) is_broadcast_ether_addr(eth->h_dest))
return 0; return 0;
@ -802,6 +800,8 @@ mtk_hnat_ipv6_nf_pre_routing(void *priv, struct sk_buff *skb,
/* packets from external devices -> xxx ,step 1 , learning stage & bound stage*/ /* packets from external devices -> xxx ,step 1 , learning stage & bound stage*/
if (do_ext2ge_fast_try(state->in, skb)) { if (do_ext2ge_fast_try(state->in, skb)) {
if (unlikely(IS_BR(state->in)))
return NF_ACCEPT;
if (!do_hnat_ext_to_ge(skb, state->in, __func__)) if (!do_hnat_ext_to_ge(skb, state->in, __func__))
return NF_STOLEN; return NF_STOLEN;
if (!skb) if (!skb)
@ -861,6 +861,8 @@ mtk_hnat_ipv4_nf_pre_routing(void *priv, struct sk_buff *skb,
/* packets from external devices -> xxx ,step 1 , learning stage & bound stage*/ /* packets from external devices -> xxx ,step 1 , learning stage & bound stage*/
if (do_ext2ge_fast_try(state->in, skb)) { if (do_ext2ge_fast_try(state->in, skb)) {
if (unlikely(IS_BR(state->in)))
return NF_ACCEPT;
if (!do_hnat_ext_to_ge(skb, state->in, __func__)) if (!do_hnat_ext_to_ge(skb, state->in, __func__))
return NF_STOLEN; return NF_STOLEN;
if (!skb) if (!skb)
@ -922,6 +924,8 @@ mtk_hnat_br_nf_local_in(void *priv, struct sk_buff *skb,
/* packets from external devices -> xxx ,step 1 , learning stage & bound stage*/ /* packets from external devices -> xxx ,step 1 , learning stage & bound stage*/
if ((skb_hnat_iface(skb) == FOE_MAGIC_EXT) && !is_from_extge(skb) && if ((skb_hnat_iface(skb) == FOE_MAGIC_EXT) && !is_from_extge(skb) &&
!is_multicast_ether_addr(eth_hdr(skb)->h_dest)) { !is_multicast_ether_addr(eth_hdr(skb)->h_dest)) {
if (unlikely(IS_BR(state->in)))
return NF_ACCEPT;
if (!hnat_priv->g_ppdev) if (!hnat_priv->g_ppdev)
hnat_priv->g_ppdev = dev_get_by_name(&init_net, hnat_priv->ppd); hnat_priv->g_ppdev = dev_get_by_name(&init_net, hnat_priv->ppd);
@ -1999,7 +2003,8 @@ static unsigned int mtk_hnat_nf_post_routing(
{ {
struct foe_entry *entry; struct foe_entry *entry;
struct flow_offload_hw_path hw_path = { .dev = (struct net_device*)out, struct flow_offload_hw_path hw_path = { .dev = (struct net_device*)out,
.virt_dev = (struct net_device*)out }; .virt_dev = (struct net_device*)out,
.flags = FLOW_OFFLOAD_PATH_ETHERNET };
const struct net_device *arp_dev = out; const struct net_device *arp_dev = out;
if (skb_hnat_alg(skb) || unlikely(!is_magic_tag_valid(skb) || if (skb_hnat_alg(skb) || unlikely(!is_magic_tag_valid(skb) ||

View File

@ -11,9 +11,19 @@ start() {
return return
fi fi
for irq in $(grep "mt76..e" /proc/interrupts | cut -d: -f1 | sed 's, *,,') for irq in $(grep -E "mt|ra" /proc/interrupts | cut -d: -f1 | sed 's, *,,')
do do
echo "$mask" > "/proc/irq/$irq/smp_affinity" echo "$mask" > "/proc/irq/$irq/smp_affinity"
[ $mask = 4 ] && mask=8 [ $mask = 4 ] && mask=8
done done
echo "6" > "/sys/class/net/eth0/queues/rx-0/rps_cpus"
echo "6" > "/sys/class/net/ra0/queues/rx-0/rps_cpus"
echo "6" > "/sys/class/net/rai0/queues/rx-0/rps_cpus"
echo "6" > "/sys/class/net/rax0/queues/rx-0/rps_cpus"
echo "6" > "/sys/class/net/apcli0/queues/rx-0/rps_cpus"
echo "6" > "/sys/class/net/apclix0/queues/rx-0/rps_cpus"
echo "6" > "/sys/class/net/apclii0/queues/rx-0/rps_cpus"
echo "8" > "/proc/irq/23/smp_affinity"
echo "8" > "/proc/irq/24/smp_affinity"
} }