rtl8366_smi.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Realtek RTL8366 SMI interface driver defines
  3. *
  4. * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
  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. struct rtl8366_smi_ops;
  16. struct rtl8366_vlan_ops;
  17. struct mii_bus;
  18. struct dentry;
  19. struct inode;
  20. struct file;
  21. struct rtl8366_mib_counter {
  22. unsigned base;
  23. unsigned offset;
  24. unsigned length;
  25. const char *name;
  26. };
  27. struct rtl8366_smi {
  28. struct device *parent;
  29. unsigned int gpio_sda;
  30. unsigned int gpio_sck;
  31. void (*hw_reset)(bool active);
  32. unsigned int clk_delay; /* ns */
  33. u8 cmd_read;
  34. u8 cmd_write;
  35. spinlock_t lock;
  36. struct mii_bus *mii_bus;
  37. int mii_irq[PHY_MAX_ADDR];
  38. struct switch_dev sw_dev;
  39. unsigned int cpu_port;
  40. unsigned int num_ports;
  41. unsigned int num_vlan_mc;
  42. unsigned int num_mib_counters;
  43. struct rtl8366_mib_counter *mib_counters;
  44. struct rtl8366_smi_ops *ops;
  45. int vlan_enabled;
  46. int vlan4k_enabled;
  47. char buf[4096];
  48. #ifdef CONFIG_RTL8366_SMI_DEBUG_FS
  49. struct dentry *debugfs_root;
  50. u16 dbg_reg;
  51. u8 dbg_vlan_4k_page;
  52. #endif
  53. };
  54. struct rtl8366_vlan_mc {
  55. u16 vid;
  56. u16 untag;
  57. u16 member;
  58. u8 fid;
  59. u8 priority;
  60. };
  61. struct rtl8366_vlan_4k {
  62. u16 vid;
  63. u16 untag;
  64. u16 member;
  65. u8 fid;
  66. };
  67. struct rtl8366_smi_ops {
  68. int (*detect)(struct rtl8366_smi *smi);
  69. int (*reset_chip)(struct rtl8366_smi *smi);
  70. int (*setup)(struct rtl8366_smi *smi);
  71. int (*mii_read)(struct mii_bus *bus, int addr, int reg);
  72. int (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
  73. int (*get_vlan_mc)(struct rtl8366_smi *smi, u32 index,
  74. struct rtl8366_vlan_mc *vlanmc);
  75. int (*set_vlan_mc)(struct rtl8366_smi *smi, u32 index,
  76. const struct rtl8366_vlan_mc *vlanmc);
  77. int (*get_vlan_4k)(struct rtl8366_smi *smi, u32 vid,
  78. struct rtl8366_vlan_4k *vlan4k);
  79. int (*set_vlan_4k)(struct rtl8366_smi *smi,
  80. const struct rtl8366_vlan_4k *vlan4k);
  81. int (*get_mc_index)(struct rtl8366_smi *smi, int port, int *val);
  82. int (*set_mc_index)(struct rtl8366_smi *smi, int port, int index);
  83. int (*get_mib_counter)(struct rtl8366_smi *smi, int counter,
  84. int port, unsigned long long *val);
  85. int (*is_vlan_valid)(struct rtl8366_smi *smi, unsigned vlan);
  86. int (*enable_vlan)(struct rtl8366_smi *smi, int enable);
  87. int (*enable_vlan4k)(struct rtl8366_smi *smi, int enable);
  88. int (*enable_port)(struct rtl8366_smi *smi, int port, int enable);
  89. };
  90. struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent);
  91. int rtl8366_smi_init(struct rtl8366_smi *smi);
  92. void rtl8366_smi_cleanup(struct rtl8366_smi *smi);
  93. int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data);
  94. int rtl8366_smi_write_reg_noack(struct rtl8366_smi *smi, u32 addr, u32 data);
  95. int rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data);
  96. int rtl8366_smi_rmwr(struct rtl8366_smi *smi, u32 addr, u32 mask, u32 data);
  97. int rtl8366_reset_vlan(struct rtl8366_smi *smi);
  98. int rtl8366_enable_vlan(struct rtl8366_smi *smi, int enable);
  99. int rtl8366_enable_all_ports(struct rtl8366_smi *smi, int enable);
  100. #ifdef CONFIG_RTL8366_SMI_DEBUG_FS
  101. int rtl8366_debugfs_open(struct inode *inode, struct file *file);
  102. #endif
  103. static inline struct rtl8366_smi *sw_to_rtl8366_smi(struct switch_dev *sw)
  104. {
  105. return container_of(sw, struct rtl8366_smi, sw_dev);
  106. }
  107. int rtl8366_sw_reset_switch(struct switch_dev *dev);
  108. int rtl8366_sw_get_port_pvid(struct switch_dev *dev, int port, int *val);
  109. int rtl8366_sw_set_port_pvid(struct switch_dev *dev, int port, int val);
  110. int rtl8366_sw_get_port_mib(struct switch_dev *dev,
  111. const struct switch_attr *attr,
  112. struct switch_val *val);
  113. int rtl8366_sw_get_vlan_info(struct switch_dev *dev,
  114. const struct switch_attr *attr,
  115. struct switch_val *val);
  116. int rtl8366_sw_get_vlan_fid(struct switch_dev *dev,
  117. const struct switch_attr *attr,
  118. struct switch_val *val);
  119. int rtl8366_sw_set_vlan_fid(struct switch_dev *dev,
  120. const struct switch_attr *attr,
  121. struct switch_val *val);
  122. int rtl8366_sw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val);
  123. int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val);
  124. int rtl8366_sw_get_vlan_enable(struct switch_dev *dev,
  125. const struct switch_attr *attr,
  126. struct switch_val *val);
  127. int rtl8366_sw_set_vlan_enable(struct switch_dev *dev,
  128. const struct switch_attr *attr,
  129. struct switch_val *val);
  130. struct rtl8366_smi* rtl8366_smi_probe(struct platform_device *pdev);
  131. #endif /* _RTL8366_SMI_H */