rtl8366_smi.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Realtek RTL8366 SMI interface driver defines
  3. *
  4. * Copyright (C) 2009-2010 Gabor Juhos <[email protected]>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published
  8. * by the Free Software Foundation.
  9. */
  10. #ifndef _RTL8366_SMI_H
  11. #define _RTL8366_SMI_H
  12. #include <linux/phy.h>
  13. #include <linux/switch.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/reset.h>
  16. struct rtl8366_smi_ops;
  17. struct rtl8366_vlan_ops;
  18. struct mii_bus;
  19. struct dentry;
  20. struct inode;
  21. struct file;
  22. typedef enum rtl8367b_chip_e {
  23. RTL8367B_CHIP_UNKNOWN,
  24. /* Family B */
  25. RTL8367B_CHIP_RTL8367RB,
  26. RTL8367B_CHIP_RTL8367R_VB, /* chip with exception in extif assignment */
  27. /* Family C */
  28. RTL8367B_CHIP_RTL8367RB_VB,
  29. RTL8367B_CHIP_RTL8367S,
  30. /* Family D */
  31. RTL8367B_CHIP_RTL8367S_VB /* chip with exception in extif assignment */
  32. } rtl8367b_chip_t;
  33. struct rtl8366_mib_counter {
  34. unsigned base;
  35. unsigned offset;
  36. unsigned length;
  37. const char *name;
  38. };
  39. struct rtl8366_smi {
  40. struct device *parent;
  41. unsigned int gpio_sda;
  42. unsigned int gpio_sck;
  43. void (*hw_reset)(struct rtl8366_smi *smi, bool active);
  44. unsigned int clk_delay; /* ns */
  45. u8 cmd_read;
  46. u8 cmd_write;
  47. spinlock_t lock;
  48. struct mii_bus *mii_bus;
  49. int mii_irq[PHY_MAX_ADDR];
  50. struct switch_dev sw_dev;
  51. unsigned int cpu_port;
  52. unsigned int num_ports;
  53. unsigned int num_vlan_mc;
  54. unsigned int num_mib_counters;
  55. struct rtl8366_mib_counter *mib_counters;
  56. struct rtl8366_smi_ops *ops;
  57. int vlan_enabled;
  58. int vlan4k_enabled;
  59. char buf[4096];
  60. struct reset_control *reset;
  61. #ifdef CONFIG_RTL8366_SMI_DEBUG_FS
  62. struct dentry *debugfs_root;
  63. u16 dbg_reg;
  64. u8 dbg_vlan_4k_page;
  65. #endif
  66. u32 phy_id;
  67. rtl8367b_chip_t rtl8367b_chip;
  68. struct mii_bus *ext_mbus;
  69. struct rtl8366_vlan_mc *emu_vlanmc;
  70. };
  71. struct rtl8366_vlan_mc {
  72. u16 vid;
  73. u16 untag;
  74. u16 member;
  75. u8 fid;
  76. u8 priority;
  77. };
  78. struct rtl8366_vlan_4k {
  79. u16 vid;
  80. u16 untag;
  81. u16 member;
  82. u8 fid;
  83. };
  84. struct rtl8366_smi_ops {
  85. int (*detect)(struct rtl8366_smi *smi);
  86. int (*reset_chip)(struct rtl8366_smi *smi);
  87. int (*setup)(struct rtl8366_smi *smi);
  88. int (*mii_read)(struct mii_bus *bus, int addr, int reg);
  89. int (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
  90. int (*get_vlan_mc)(struct rtl8366_smi *smi, u32 index,
  91. struct rtl8366_vlan_mc *vlanmc);
  92. int (*set_vlan_mc)(struct rtl8366_smi *smi, u32 index,
  93. const struct rtl8366_vlan_mc *vlanmc);
  94. int (*get_vlan_4k)(struct rtl8366_smi *smi, u32 vid,
  95. struct rtl8366_vlan_4k *vlan4k);
  96. int (*set_vlan_4k)(struct rtl8366_smi *smi,
  97. const struct rtl8366_vlan_4k *vlan4k);
  98. int (*get_mc_index)(struct rtl8366_smi *smi, int port, int *val);
  99. int (*set_mc_index)(struct rtl8366_smi *smi, int port, int index);
  100. int (*get_mib_counter)(struct rtl8366_smi *smi, int counter,
  101. int port, unsigned long long *val);
  102. int (*is_vlan_valid)(struct rtl8366_smi *smi, unsigned vlan);
  103. int (*enable_vlan)(struct rtl8366_smi *smi, int enable);
  104. int (*enable_vlan4k)(struct rtl8366_smi *smi, int enable);
  105. int (*enable_port)(struct rtl8366_smi *smi, int port, int enable);
  106. };
  107. struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent);
  108. int rtl8366_smi_init(struct rtl8366_smi *smi);
  109. void rtl8366_smi_cleanup(struct rtl8366_smi *smi);
  110. int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data);
  111. int rtl8366_smi_write_reg_noack(struct rtl8366_smi *smi, u32 addr, u32 data);
  112. int rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data);
  113. int rtl8366_smi_rmwr(struct rtl8366_smi *smi, u32 addr, u32 mask, u32 data);
  114. #ifdef CONFIG_RTL8366_SMI_DEBUG_FS
  115. int rtl8366_debugfs_open(struct inode *inode, struct file *file);
  116. #endif
  117. static inline struct rtl8366_smi *sw_to_rtl8366_smi(struct switch_dev *sw)
  118. {
  119. return container_of(sw, struct rtl8366_smi, sw_dev);
  120. }
  121. int rtl8366_sw_reset_switch(struct switch_dev *dev);
  122. int rtl8366_sw_get_port_pvid(struct switch_dev *dev, int port, int *val);
  123. int rtl8366_sw_set_port_pvid(struct switch_dev *dev, int port, int val);
  124. int rtl8366_sw_get_port_mib(struct switch_dev *dev,
  125. const struct switch_attr *attr,
  126. struct switch_val *val);
  127. int rtl8366_sw_get_vlan_info(struct switch_dev *dev,
  128. const struct switch_attr *attr,
  129. struct switch_val *val);
  130. int rtl8366_sw_get_vlan_fid(struct switch_dev *dev,
  131. const struct switch_attr *attr,
  132. struct switch_val *val);
  133. int rtl8366_sw_set_vlan_fid(struct switch_dev *dev,
  134. const struct switch_attr *attr,
  135. struct switch_val *val);
  136. int rtl8366_sw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val);
  137. int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val);
  138. int rtl8366_sw_get_vlan_enable(struct switch_dev *dev,
  139. const struct switch_attr *attr,
  140. struct switch_val *val);
  141. int rtl8366_sw_set_vlan_enable(struct switch_dev *dev,
  142. const struct switch_attr *attr,
  143. struct switch_val *val);
  144. int rtl8366_sw_get_port_stats(struct switch_dev *dev, int port,
  145. struct switch_port_stats *stats,
  146. int txb_id, int rxb_id);
  147. struct rtl8366_smi* rtl8366_smi_probe(struct platform_device *pdev);
  148. #endif /* _RTL8366_SMI_H */