realtek.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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_H
  8. #define _REALTEK_H
  9. #include <linux/phy.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/gpio/consumer.h>
  12. #include <net/dsa.h>
  13. #include <linux/reset.h>
  14. #define REALTEK_HW_STOP_DELAY 25 /* msecs */
  15. #define REALTEK_HW_START_DELAY 100 /* msecs */
  16. struct phylink_mac_ops;
  17. struct realtek_ops;
  18. struct dentry;
  19. struct inode;
  20. struct file;
  21. struct rtl8366_mib_counter {
  22. unsigned int base;
  23. unsigned int offset;
  24. unsigned int length;
  25. const char *name;
  26. };
  27. /*
  28. * struct rtl8366_vlan_mc - Virtual LAN member configuration
  29. */
  30. struct rtl8366_vlan_mc {
  31. u16 vid;
  32. u16 untag;
  33. u16 member;
  34. u8 fid;
  35. u8 priority;
  36. };
  37. struct rtl8366_vlan_4k {
  38. u16 vid;
  39. u16 untag;
  40. u16 member;
  41. u8 fid;
  42. };
  43. struct realtek_priv {
  44. struct device *dev;
  45. struct reset_control *reset_ctl;
  46. struct gpio_desc *reset;
  47. struct gpio_desc *mdc;
  48. struct gpio_desc *mdio;
  49. struct regmap *map;
  50. struct regmap *map_nolock;
  51. struct mutex map_lock;
  52. struct mii_bus *user_mii_bus;
  53. struct mii_bus *bus;
  54. int mdio_addr;
  55. const struct realtek_variant *variant;
  56. spinlock_t lock; /* Locks around command writes */
  57. struct dsa_switch ds;
  58. struct irq_domain *irqdomain;
  59. bool leds_disabled;
  60. unsigned int cpu_port;
  61. unsigned int num_ports;
  62. unsigned int num_vlan_mc;
  63. unsigned int num_mib_counters;
  64. struct rtl8366_mib_counter *mib_counters;
  65. const struct realtek_ops *ops;
  66. int (*write_reg_noack)(void *ctx, u32 addr, u32 data);
  67. int vlan_enabled;
  68. int vlan4k_enabled;
  69. char buf[4096];
  70. void *chip_data; /* Per-chip extra variant data */
  71. };
  72. /*
  73. * struct realtek_ops - vtable for the per-SMI-chiptype operations
  74. * @detect: detects the chiptype
  75. */
  76. struct realtek_ops {
  77. int (*detect)(struct realtek_priv *priv);
  78. int (*reset_chip)(struct realtek_priv *priv);
  79. int (*setup)(struct realtek_priv *priv);
  80. int (*get_mib_counter)(struct realtek_priv *priv,
  81. int port,
  82. struct rtl8366_mib_counter *mib,
  83. u64 *mibvalue);
  84. int (*get_vlan_mc)(struct realtek_priv *priv, u32 index,
  85. struct rtl8366_vlan_mc *vlanmc);
  86. int (*set_vlan_mc)(struct realtek_priv *priv, u32 index,
  87. const struct rtl8366_vlan_mc *vlanmc);
  88. int (*get_vlan_4k)(struct realtek_priv *priv, u32 vid,
  89. struct rtl8366_vlan_4k *vlan4k);
  90. int (*set_vlan_4k)(struct realtek_priv *priv,
  91. const struct rtl8366_vlan_4k *vlan4k);
  92. int (*get_mc_index)(struct realtek_priv *priv, int port, int *val);
  93. int (*set_mc_index)(struct realtek_priv *priv, int port, int index);
  94. bool (*is_vlan_valid)(struct realtek_priv *priv, unsigned int vlan);
  95. int (*enable_vlan)(struct realtek_priv *priv, bool enable);
  96. int (*enable_vlan4k)(struct realtek_priv *priv, bool enable);
  97. int (*enable_port)(struct realtek_priv *priv, int port, bool enable);
  98. int (*phy_read)(struct realtek_priv *priv, int phy, int regnum);
  99. int (*phy_write)(struct realtek_priv *priv, int phy, int regnum,
  100. u16 val);
  101. };
  102. struct realtek_variant {
  103. const struct dsa_switch_ops *ds_ops;
  104. const struct realtek_ops *ops;
  105. const struct phylink_mac_ops *phylink_mac_ops;
  106. unsigned int clk_delay;
  107. u8 cmd_read;
  108. u8 cmd_write;
  109. size_t chip_data_sz;
  110. };
  111. /* RTL8366 library helpers */
  112. int rtl8366_mc_is_used(struct realtek_priv *priv, int mc_index, int *used);
  113. int rtl8366_set_vlan(struct realtek_priv *priv, int vid, u32 member,
  114. u32 untag, u32 fid);
  115. int rtl8366_set_pvid(struct realtek_priv *priv, unsigned int port,
  116. unsigned int vid);
  117. int rtl8366_enable_vlan4k(struct realtek_priv *priv, bool enable);
  118. int rtl8366_enable_vlan(struct realtek_priv *priv, bool enable);
  119. int rtl8366_reset_vlan(struct realtek_priv *priv);
  120. int rtl8366_vlan_add(struct dsa_switch *ds, int port,
  121. const struct switchdev_obj_port_vlan *vlan,
  122. struct netlink_ext_ack *extack);
  123. int rtl8366_vlan_del(struct dsa_switch *ds, int port,
  124. const struct switchdev_obj_port_vlan *vlan);
  125. void rtl8366_get_strings(struct dsa_switch *ds, int port, u32 stringset,
  126. uint8_t *data);
  127. int rtl8366_get_sset_count(struct dsa_switch *ds, int port, int sset);
  128. void rtl8366_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
  129. extern const struct realtek_variant rtl8366rb_variant;
  130. extern const struct realtek_variant rtl8365mb_variant;
  131. #endif /* _REALTEK_H */