rtl8366_smi.h 4.3 KB

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