rtl8366_smi.h 4.6 KB

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