enetc4_debugfs.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /* Copyright 2025 NXP */
  3. #include <linux/device.h>
  4. #include <linux/debugfs.h>
  5. #include <linux/seq_file.h>
  6. #include <linux/string_choices.h>
  7. #include "enetc_pf.h"
  8. #include "enetc4_debugfs.h"
  9. static void enetc_show_si_mac_hash_filter(struct seq_file *s, int i)
  10. {
  11. struct enetc_si *si = s->private;
  12. struct enetc_hw *hw = &si->hw;
  13. u32 hash_h, hash_l;
  14. hash_l = enetc_port_rd(hw, ENETC4_PSIUMHFR0(i));
  15. hash_h = enetc_port_rd(hw, ENETC4_PSIUMHFR1(i));
  16. seq_printf(s, "SI %d unicast MAC hash filter: 0x%08x%08x\n",
  17. i, hash_h, hash_l);
  18. hash_l = enetc_port_rd(hw, ENETC4_PSIMMHFR0(i));
  19. hash_h = enetc_port_rd(hw, ENETC4_PSIMMHFR1(i));
  20. seq_printf(s, "SI %d multicast MAC hash filter: 0x%08x%08x\n",
  21. i, hash_h, hash_l);
  22. }
  23. static int enetc_mac_filter_show(struct seq_file *s, void *data)
  24. {
  25. struct enetc_si *si = s->private;
  26. struct enetc_hw *hw = &si->hw;
  27. struct maft_entry_data maft;
  28. struct enetc_pf *pf;
  29. int i, err, num_si;
  30. u32 val;
  31. pf = enetc_si_priv(si);
  32. num_si = pf->caps.num_vsi + 1;
  33. val = enetc_port_rd(hw, ENETC4_PSIPMMR);
  34. for (i = 0; i < num_si; i++) {
  35. seq_printf(s, "SI %d Unicast Promiscuous mode: %s\n", i,
  36. str_enabled_disabled(PSIPMMR_SI_MAC_UP(i) & val));
  37. seq_printf(s, "SI %d Multicast Promiscuous mode: %s\n", i,
  38. str_enabled_disabled(PSIPMMR_SI_MAC_MP(i) & val));
  39. }
  40. /* MAC hash filter table */
  41. for (i = 0; i < num_si; i++)
  42. enetc_show_si_mac_hash_filter(s, i);
  43. if (!pf->num_mfe)
  44. return 0;
  45. /* MAC address filter table */
  46. seq_puts(s, "MAC address filter table\n");
  47. for (i = 0; i < pf->num_mfe; i++) {
  48. memset(&maft, 0, sizeof(maft));
  49. err = ntmp_maft_query_entry(&si->ntmp_user, i, &maft);
  50. if (err)
  51. return err;
  52. seq_printf(s, "Entry %d, MAC: %pM, SI bitmap: 0x%04x\n", i,
  53. maft.keye.mac_addr, le16_to_cpu(maft.cfge.si_bitmap));
  54. }
  55. return 0;
  56. }
  57. DEFINE_SHOW_ATTRIBUTE(enetc_mac_filter);
  58. void enetc_create_debugfs(struct enetc_si *si)
  59. {
  60. struct net_device *ndev = si->ndev;
  61. struct dentry *root;
  62. root = debugfs_create_dir(netdev_name(ndev), NULL);
  63. if (IS_ERR(root))
  64. return;
  65. si->debugfs_root = root;
  66. debugfs_create_file("mac_filter", 0444, root, si, &enetc_mac_filter_fops);
  67. }
  68. void enetc_remove_debugfs(struct enetc_si *si)
  69. {
  70. debugfs_remove(si->debugfs_root);
  71. si->debugfs_root = NULL;
  72. }