realtek-smi-core.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /* Realtek SMI interface driver defines
  3. *
  4. * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
  5. * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  6. */
  7. #ifndef _REALTEK_SMI_H
  8. #define _REALTEK_SMI_H
  9. #include <linux/phy.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/gpio/consumer.h>
  12. #include <net/dsa.h>
  13. struct realtek_smi_ops;
  14. struct dentry;
  15. struct inode;
  16. struct file;
  17. struct rtl8366_mib_counter {
  18. unsigned int base;
  19. unsigned int offset;
  20. unsigned int length;
  21. const char *name;
  22. };
  23. /**
  24. * struct rtl8366_vlan_mc - Virtual LAN member configuration
  25. */
  26. struct rtl8366_vlan_mc {
  27. u16 vid;
  28. u16 untag;
  29. u16 member;
  30. u8 fid;
  31. u8 priority;
  32. };
  33. struct rtl8366_vlan_4k {
  34. u16 vid;
  35. u16 untag;
  36. u16 member;
  37. u8 fid;
  38. };
  39. struct realtek_smi {
  40. struct device *dev;
  41. struct gpio_desc *reset;
  42. struct gpio_desc *mdc;
  43. struct gpio_desc *mdio;
  44. struct regmap *map;
  45. struct mii_bus *slave_mii_bus;
  46. unsigned int clk_delay;
  47. u8 cmd_read;
  48. u8 cmd_write;
  49. spinlock_t lock; /* Locks around command writes */
  50. struct dsa_switch *ds;
  51. struct irq_domain *irqdomain;
  52. bool leds_disabled;
  53. unsigned int cpu_port;
  54. unsigned int num_ports;
  55. unsigned int num_vlan_mc;
  56. unsigned int num_mib_counters;
  57. struct rtl8366_mib_counter *mib_counters;
  58. const struct realtek_smi_ops *ops;
  59. int vlan_enabled;
  60. int vlan4k_enabled;
  61. char buf[4096];
  62. };
  63. /**
  64. * struct realtek_smi_ops - vtable for the per-SMI-chiptype operations
  65. * @detect: detects the chiptype
  66. */
  67. struct realtek_smi_ops {
  68. int (*detect)(struct realtek_smi *smi);
  69. int (*reset_chip)(struct realtek_smi *smi);
  70. int (*setup)(struct realtek_smi *smi);
  71. void (*cleanup)(struct realtek_smi *smi);
  72. int (*get_mib_counter)(struct realtek_smi *smi,
  73. int port,
  74. struct rtl8366_mib_counter *mib,
  75. u64 *mibvalue);
  76. int (*get_vlan_mc)(struct realtek_smi *smi, u32 index,
  77. struct rtl8366_vlan_mc *vlanmc);
  78. int (*set_vlan_mc)(struct realtek_smi *smi, u32 index,
  79. const struct rtl8366_vlan_mc *vlanmc);
  80. int (*get_vlan_4k)(struct realtek_smi *smi, u32 vid,
  81. struct rtl8366_vlan_4k *vlan4k);
  82. int (*set_vlan_4k)(struct realtek_smi *smi,
  83. const struct rtl8366_vlan_4k *vlan4k);
  84. int (*get_mc_index)(struct realtek_smi *smi, int port, int *val);
  85. int (*set_mc_index)(struct realtek_smi *smi, int port, int index);
  86. bool (*is_vlan_valid)(struct realtek_smi *smi, unsigned int vlan);
  87. int (*enable_vlan)(struct realtek_smi *smi, bool enable);
  88. int (*enable_vlan4k)(struct realtek_smi *smi, bool enable);
  89. int (*enable_port)(struct realtek_smi *smi, int port, bool enable);
  90. int (*phy_read)(struct realtek_smi *smi, int phy, int regnum);
  91. int (*phy_write)(struct realtek_smi *smi, int phy, int regnum,
  92. u16 val);
  93. };
  94. struct realtek_smi_variant {
  95. const struct dsa_switch_ops *ds_ops;
  96. const struct realtek_smi_ops *ops;
  97. unsigned int clk_delay;
  98. u8 cmd_read;
  99. u8 cmd_write;
  100. };
  101. /* SMI core calls */
  102. int realtek_smi_write_reg_noack(struct realtek_smi *smi, u32 addr,
  103. u32 data);
  104. int realtek_smi_setup_mdio(struct realtek_smi *smi);
  105. /* RTL8366 library helpers */
  106. int rtl8366_mc_is_used(struct realtek_smi *smi, int mc_index, int *used);
  107. int rtl8366_set_vlan(struct realtek_smi *smi, int vid, u32 member,
  108. u32 untag, u32 fid);
  109. int rtl8366_set_pvid(struct realtek_smi *smi, unsigned int port,
  110. unsigned int vid);
  111. int rtl8366_enable_vlan4k(struct realtek_smi *smi, bool enable);
  112. int rtl8366_enable_vlan(struct realtek_smi *smi, bool enable);
  113. int rtl8366_reset_vlan(struct realtek_smi *smi);
  114. int rtl8366_init_vlan(struct realtek_smi *smi);
  115. int rtl8366_vlan_filtering(struct dsa_switch *ds, int port,
  116. bool vlan_filtering);
  117. int rtl8366_vlan_prepare(struct dsa_switch *ds, int port,
  118. const struct switchdev_obj_port_vlan *vlan);
  119. void rtl8366_vlan_add(struct dsa_switch *ds, int port,
  120. const struct switchdev_obj_port_vlan *vlan);
  121. int rtl8366_vlan_del(struct dsa_switch *ds, int port,
  122. const struct switchdev_obj_port_vlan *vlan);
  123. void rtl8366_get_strings(struct dsa_switch *ds, int port, u32 stringset,
  124. uint8_t *data);
  125. int rtl8366_get_sset_count(struct dsa_switch *ds, int port, int sset);
  126. void rtl8366_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
  127. extern const struct realtek_smi_variant rtl8366rb_variant;
  128. #endif /* _REALTEK_SMI_H */