rtl8366_smi.h 4.7 KB

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