mtk_debugfs.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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
  4. *
  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.
  9. *
  10. * Copyright (C) 2014-2016 Sean Wang <[email protected]>
  11. * Copyright (C) 2016-2017 John Crispin <[email protected]>
  12. */
  13. #include "mtk_offload.h"
  14. static const char *mtk_foe_entry_state_str[] = {
  15. "INVALID",
  16. "UNBIND",
  17. "BIND",
  18. "FIN"
  19. };
  20. static const char *mtk_foe_packet_type_str[] = {
  21. "IPV4_HNAPT",
  22. "IPV4_HNAT",
  23. "IPV6_1T_ROUTE",
  24. "IPV4_DSLITE",
  25. "IPV6_3T_ROUTE",
  26. "IPV6_5T_ROUTE",
  27. "IPV6_6RD",
  28. };
  29. #define IPV4_HNAPT 0
  30. #define IPV4_HNAT 1
  31. #define IS_IPV4_HNAPT(x) (((x)->bfib1.pkt_type == IPV4_HNAPT) ? 1: 0)
  32. struct mtk_eth *_eth;
  33. #define es(entry) (mtk_foe_entry_state_str[entry->bfib1.state])
  34. //#define ei(entry, end) (MTK_PPE_TBL_SZ - (int)(end - entry))
  35. #define ei(entry, end) (MTK_PPE_ENTRY_CNT - (int)(end - entry))
  36. #define pt(entry) (mtk_foe_packet_type_str[entry->ipv4_hnapt.bfib1.pkt_type])
  37. static int mtk_ppe_debugfs_foe_show(struct seq_file *m, void *private)
  38. {
  39. struct mtk_eth *eth = _eth;
  40. struct mtk_foe_entry *entry, *end;
  41. int i = 0;
  42. entry = eth->foe_table;
  43. end = eth->foe_table + MTK_PPE_ENTRY_CNT;
  44. while (entry < end) {
  45. if (IS_IPV4_HNAPT(entry)) {
  46. __be32 saddr = htonl(entry->ipv4_hnapt.sip);
  47. __be32 daddr = htonl(entry->ipv4_hnapt.dip);
  48. __be32 nsaddr = htonl(entry->ipv4_hnapt.new_sip);
  49. __be32 ndaddr = htonl(entry->ipv4_hnapt.new_dip);
  50. unsigned char h_dest[ETH_ALEN];
  51. unsigned char h_source[ETH_ALEN];
  52. *((u32*) h_source) = swab32(entry->ipv4_hnapt.smac_hi);
  53. *((u16*) &h_source[4]) = swab16(entry->ipv4_hnapt.smac_lo);
  54. *((u32*) h_dest) = swab32(entry->ipv4_hnapt.dmac_hi);
  55. *((u16*) &h_dest[4]) = swab16(entry->ipv4_hnapt.dmac_lo);
  56. seq_printf(m,
  57. "(%x)0x%05x|state=%s|type=%s|"
  58. "%pI4:%d->%pI4:%d=>%pI4:%d->%pI4:%d|%pM=>%pM|"
  59. "etype=0x%04x|info1=0x%x|info2=0x%x|"
  60. "vlan1=%d|vlan2=%d\n",
  61. i,
  62. ei(entry, end), es(entry), pt(entry),
  63. &saddr, entry->ipv4_hnapt.sport,
  64. &daddr, entry->ipv4_hnapt.dport,
  65. &nsaddr, entry->ipv4_hnapt.new_sport,
  66. &ndaddr, entry->ipv4_hnapt.new_dport, h_source,
  67. h_dest, ntohs(entry->ipv4_hnapt.etype),
  68. entry->ipv4_hnapt.info_blk1,
  69. entry->ipv4_hnapt.info_blk2,
  70. entry->ipv4_hnapt.vlan1,
  71. entry->ipv4_hnapt.vlan2);
  72. } else
  73. seq_printf(m, "0x%05x state=%s\n",
  74. ei(entry, end), es(entry));
  75. entry++;
  76. i++;
  77. }
  78. return 0;
  79. }
  80. static int mtk_ppe_debugfs_foe_open(struct inode *inode, struct file *file)
  81. {
  82. return single_open(file, mtk_ppe_debugfs_foe_show, file->private_data);
  83. }
  84. static const struct file_operations mtk_ppe_debugfs_foe_fops = {
  85. .open = mtk_ppe_debugfs_foe_open,
  86. .read = seq_read,
  87. .llseek = seq_lseek,
  88. .release = single_release,
  89. };
  90. int mtk_ppe_debugfs_init(struct mtk_eth *eth)
  91. {
  92. struct dentry *root;
  93. _eth = eth;
  94. root = debugfs_create_dir("mtk_ppe", NULL);
  95. if (!root)
  96. return -ENOMEM;
  97. debugfs_create_file("all_entry", S_IRUGO, root, eth, &mtk_ppe_debugfs_foe_fops);
  98. return 0;
  99. }