1 /* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License as published by
3 * the Free Software Foundation; version 2 of the License
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
10 * Copyright (C) 2014-2016 Sean Wang <sean.wang@mediatek.com>
11 * Copyright (C) 2016-2017 John Crispin <blogic@openwrt.org>
14 #include "mtk_offload.h"
16 static const char *mtk_foe_entry_state_str[] = {
23 static const char *mtk_foe_packet_type_str[] = {
35 #define IS_IPV4_HNAPT(x) (((x)->bfib1.pkt_type == IPV4_HNAPT) ? 1: 0)
37 #define es(entry) (mtk_foe_entry_state_str[entry->bfib1.state])
38 //#define ei(entry, end) (MTK_PPE_TBL_SZ - (int)(end - entry))
39 #define ei(entry, end) (MTK_PPE_ENTRY_CNT - (int)(end - entry))
40 #define pt(entry) (mtk_foe_packet_type_str[entry->ipv4_hnapt.bfib1.pkt_type])
42 static int mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private)
44 struct mtk_eth *eth = _eth;
45 struct mtk_foe_entry *entry, *end;
48 entry = eth->foe_table;
49 end = eth->foe_table + MTK_PPE_ENTRY_CNT;
52 if (IS_IPV4_HNAPT(entry)) {
53 __be32 saddr = htonl(entry->ipv4_hnapt.sip);
54 __be32 daddr = htonl(entry->ipv4_hnapt.dip);
55 __be32 nsaddr = htonl(entry->ipv4_hnapt.new_sip);
56 __be32 ndaddr = htonl(entry->ipv4_hnapt.new_dip);
57 unsigned char h_dest[ETH_ALEN];
58 unsigned char h_source[ETH_ALEN];
60 *((u32*) h_source) = swab32(entry->ipv4_hnapt.smac_hi);
61 *((u16*) &h_source[4]) = swab16(entry->ipv4_hnapt.smac_lo);
62 *((u32*) h_dest) = swab32(entry->ipv4_hnapt.dmac_hi);
63 *((u16*) &h_dest[4]) = swab16(entry->ipv4_hnapt.dmac_lo);
65 "(%x)0x%05x|state=%s|type=%s|"
66 "%pI4:%d->%pI4:%d=>%pI4:%d->%pI4:%d|%pM=>%pM|"
67 "etype=0x%04x|info1=0x%x|info2=0x%x|"
68 "vlan1=%d|vlan2=%d\n",
70 ei(entry, end), es(entry), pt(entry),
71 &saddr, entry->ipv4_hnapt.sport,
72 &daddr, entry->ipv4_hnapt.dport,
73 &nsaddr, entry->ipv4_hnapt.new_sport,
74 &ndaddr, entry->ipv4_hnapt.new_dport, h_source,
75 h_dest, ntohs(entry->ipv4_hnapt.etype),
76 entry->ipv4_hnapt.info_blk1,
77 entry->ipv4_hnapt.info_blk2,
78 entry->ipv4_hnapt.vlan1,
79 entry->ipv4_hnapt.vlan2);
81 seq_printf(m, "0x%05x state=%s\n",
82 ei(entry, end), es(entry));
90 static int mtk_ppe_debugfs_foe_open(struct inode *inode, struct file *file)
92 return single_open(file, mtk_ppe_debugfs_foe_show, file->private_data);
95 static const struct file_operations mtk_ppe_debugfs_foe_fops = {
96 .open = mtk_ppe_debugfs_foe_open,
99 .release = single_release,
102 int mtk_ppe_debugfs_init(struct mtk_eth *eth)
108 root = debugfs_create_dir("mtk_ppe", NULL);
112 debugfs_create_file("all_entry", S_IRUGO, root, eth, &mtk_ppe_debugfs_foe_fops);