b53_priv.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * B53 common definitions
  3. *
  4. * Copyright (C) 2011-2013 Jonas Gorski <jogo@openwrt.org>
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef __B53_PRIV_H
  19. #define __B53_PRIV_H
  20. #include <linux/kernel.h>
  21. #include <linux/mutex.h>
  22. #include <linux/phy.h>
  23. #include <linux/etherdevice.h>
  24. #include <net/dsa.h>
  25. #include "b53_regs.h"
  26. struct b53_device;
  27. struct net_device;
  28. struct b53_io_ops {
  29. int (*read8)(struct b53_device *dev, u8 page, u8 reg, u8 *value);
  30. int (*read16)(struct b53_device *dev, u8 page, u8 reg, u16 *value);
  31. int (*read32)(struct b53_device *dev, u8 page, u8 reg, u32 *value);
  32. int (*read48)(struct b53_device *dev, u8 page, u8 reg, u64 *value);
  33. int (*read64)(struct b53_device *dev, u8 page, u8 reg, u64 *value);
  34. int (*write8)(struct b53_device *dev, u8 page, u8 reg, u8 value);
  35. int (*write16)(struct b53_device *dev, u8 page, u8 reg, u16 value);
  36. int (*write32)(struct b53_device *dev, u8 page, u8 reg, u32 value);
  37. int (*write48)(struct b53_device *dev, u8 page, u8 reg, u64 value);
  38. int (*write64)(struct b53_device *dev, u8 page, u8 reg, u64 value);
  39. int (*phy_read16)(struct b53_device *dev, int addr, int reg, u16 *value);
  40. int (*phy_write16)(struct b53_device *dev, int addr, int reg, u16 value);
  41. };
  42. enum {
  43. BCM5325_DEVICE_ID = 0x25,
  44. BCM5365_DEVICE_ID = 0x65,
  45. BCM5389_DEVICE_ID = 0x89,
  46. BCM5395_DEVICE_ID = 0x95,
  47. BCM5397_DEVICE_ID = 0x97,
  48. BCM5398_DEVICE_ID = 0x98,
  49. BCM53115_DEVICE_ID = 0x53115,
  50. BCM53125_DEVICE_ID = 0x53125,
  51. BCM53128_DEVICE_ID = 0x53128,
  52. BCM63XX_DEVICE_ID = 0x6300,
  53. BCM53010_DEVICE_ID = 0x53010,
  54. BCM53011_DEVICE_ID = 0x53011,
  55. BCM53012_DEVICE_ID = 0x53012,
  56. BCM53018_DEVICE_ID = 0x53018,
  57. BCM53019_DEVICE_ID = 0x53019,
  58. BCM58XX_DEVICE_ID = 0x5800,
  59. BCM583XX_DEVICE_ID = 0x58300,
  60. BCM7445_DEVICE_ID = 0x7445,
  61. BCM7278_DEVICE_ID = 0x7278,
  62. };
  63. #define B53_N_PORTS 9
  64. #define B53_N_PORTS_25 6
  65. struct b53_port {
  66. u16 vlan_ctl_mask;
  67. struct ethtool_eee eee;
  68. };
  69. struct b53_vlan {
  70. u16 members;
  71. u16 untag;
  72. bool valid;
  73. };
  74. struct b53_device {
  75. struct dsa_switch *ds;
  76. struct b53_platform_data *pdata;
  77. const char *name;
  78. struct mutex reg_mutex;
  79. struct mutex stats_mutex;
  80. const struct b53_io_ops *ops;
  81. /* chip specific data */
  82. u32 chip_id;
  83. u8 core_rev;
  84. u8 vta_regs[3];
  85. u8 duplex_reg;
  86. u8 jumbo_pm_reg;
  87. u8 jumbo_size_reg;
  88. int reset_gpio;
  89. u8 num_arl_entries;
  90. /* used ports mask */
  91. u16 enabled_ports;
  92. unsigned int cpu_port;
  93. /* connect specific data */
  94. u8 current_page;
  95. struct device *dev;
  96. /* Master MDIO bus we got probed from */
  97. struct mii_bus *bus;
  98. void *priv;
  99. /* run time configuration */
  100. bool enable_jumbo;
  101. unsigned int num_vlans;
  102. struct b53_vlan *vlans;
  103. unsigned int num_ports;
  104. struct b53_port *ports;
  105. };
  106. #define b53_for_each_port(dev, i) \
  107. for (i = 0; i < B53_N_PORTS; i++) \
  108. if (dev->enabled_ports & BIT(i))
  109. static inline int is5325(struct b53_device *dev)
  110. {
  111. return dev->chip_id == BCM5325_DEVICE_ID;
  112. }
  113. static inline int is5365(struct b53_device *dev)
  114. {
  115. #ifdef CONFIG_BCM47XX
  116. return dev->chip_id == BCM5365_DEVICE_ID;
  117. #else
  118. return 0;
  119. #endif
  120. }
  121. static inline int is5397_98(struct b53_device *dev)
  122. {
  123. return dev->chip_id == BCM5397_DEVICE_ID ||
  124. dev->chip_id == BCM5398_DEVICE_ID;
  125. }
  126. static inline int is539x(struct b53_device *dev)
  127. {
  128. return dev->chip_id == BCM5395_DEVICE_ID ||
  129. dev->chip_id == BCM5397_DEVICE_ID ||
  130. dev->chip_id == BCM5398_DEVICE_ID;
  131. }
  132. static inline int is531x5(struct b53_device *dev)
  133. {
  134. return dev->chip_id == BCM53115_DEVICE_ID ||
  135. dev->chip_id == BCM53125_DEVICE_ID ||
  136. dev->chip_id == BCM53128_DEVICE_ID;
  137. }
  138. static inline int is63xx(struct b53_device *dev)
  139. {
  140. #ifdef CONFIG_BCM63XX
  141. return dev->chip_id == BCM63XX_DEVICE_ID;
  142. #else
  143. return 0;
  144. #endif
  145. }
  146. static inline int is5301x(struct b53_device *dev)
  147. {
  148. return dev->chip_id == BCM53010_DEVICE_ID ||
  149. dev->chip_id == BCM53011_DEVICE_ID ||
  150. dev->chip_id == BCM53012_DEVICE_ID ||
  151. dev->chip_id == BCM53018_DEVICE_ID ||
  152. dev->chip_id == BCM53019_DEVICE_ID;
  153. }
  154. static inline int is58xx(struct b53_device *dev)
  155. {
  156. return dev->chip_id == BCM58XX_DEVICE_ID ||
  157. dev->chip_id == BCM583XX_DEVICE_ID ||
  158. dev->chip_id == BCM7445_DEVICE_ID ||
  159. dev->chip_id == BCM7278_DEVICE_ID;
  160. }
  161. #define B53_CPU_PORT_25 5
  162. #define B53_CPU_PORT 8
  163. struct b53_device *b53_switch_alloc(struct device *base,
  164. const struct b53_io_ops *ops,
  165. void *priv);
  166. int b53_switch_detect(struct b53_device *dev);
  167. int b53_switch_register(struct b53_device *dev);
  168. static inline void b53_switch_remove(struct b53_device *dev)
  169. {
  170. dsa_unregister_switch(dev->ds);
  171. }
  172. #define b53_build_op(type_op_size, val_type) \
  173. static inline int b53_##type_op_size(struct b53_device *dev, u8 page, \
  174. u8 reg, val_type val) \
  175. { \
  176. int ret; \
  177. \
  178. mutex_lock(&dev->reg_mutex); \
  179. ret = dev->ops->type_op_size(dev, page, reg, val); \
  180. mutex_unlock(&dev->reg_mutex); \
  181. \
  182. return ret; \
  183. }
  184. b53_build_op(read8, u8 *);
  185. b53_build_op(read16, u16 *);
  186. b53_build_op(read32, u32 *);
  187. b53_build_op(read48, u64 *);
  188. b53_build_op(read64, u64 *);
  189. b53_build_op(write8, u8);
  190. b53_build_op(write16, u16);
  191. b53_build_op(write32, u32);
  192. b53_build_op(write48, u64);
  193. b53_build_op(write64, u64);
  194. struct b53_arl_entry {
  195. u8 port;
  196. u8 mac[ETH_ALEN];
  197. u16 vid;
  198. u8 is_valid:1;
  199. u8 is_age:1;
  200. u8 is_static:1;
  201. };
  202. static inline void b53_arl_to_entry(struct b53_arl_entry *ent,
  203. u64 mac_vid, u32 fwd_entry)
  204. {
  205. memset(ent, 0, sizeof(*ent));
  206. ent->port = fwd_entry & ARLTBL_DATA_PORT_ID_MASK;
  207. ent->is_valid = !!(fwd_entry & ARLTBL_VALID);
  208. ent->is_age = !!(fwd_entry & ARLTBL_AGE);
  209. ent->is_static = !!(fwd_entry & ARLTBL_STATIC);
  210. u64_to_ether_addr(mac_vid, ent->mac);
  211. ent->vid = mac_vid >> ARLTBL_VID_S;
  212. }
  213. static inline void b53_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
  214. const struct b53_arl_entry *ent)
  215. {
  216. *mac_vid = ether_addr_to_u64(ent->mac);
  217. *mac_vid |= (u64)(ent->vid & ARLTBL_VID_MASK) << ARLTBL_VID_S;
  218. *fwd_entry = ent->port & ARLTBL_DATA_PORT_ID_MASK;
  219. if (ent->is_valid)
  220. *fwd_entry |= ARLTBL_VALID;
  221. if (ent->is_static)
  222. *fwd_entry |= ARLTBL_STATIC;
  223. if (ent->is_age)
  224. *fwd_entry |= ARLTBL_AGE;
  225. }
  226. #ifdef CONFIG_BCM47XX
  227. #include <linux/bcm47xx_nvram.h>
  228. #include <bcm47xx_board.h>
  229. static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
  230. {
  231. enum bcm47xx_board board = bcm47xx_board_get();
  232. switch (board) {
  233. case BCM47XX_BOARD_LINKSYS_WRT300NV11:
  234. case BCM47XX_BOARD_LINKSYS_WRT310NV1:
  235. return 8;
  236. default:
  237. return bcm47xx_nvram_gpio_pin("robo_reset");
  238. }
  239. }
  240. #else
  241. static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
  242. {
  243. return -ENOENT;
  244. }
  245. #endif
  246. /* Exported functions towards other drivers */
  247. void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port);
  248. int b53_configure_vlan(struct dsa_switch *ds);
  249. void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
  250. uint8_t *data);
  251. void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
  252. int b53_get_sset_count(struct dsa_switch *ds, int port, int sset);
  253. void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data);
  254. int b53_br_join(struct dsa_switch *ds, int port, struct net_device *bridge);
  255. void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *bridge);
  256. void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);
  257. void b53_br_fast_age(struct dsa_switch *ds, int port);
  258. int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering);
  259. int b53_vlan_prepare(struct dsa_switch *ds, int port,
  260. const struct switchdev_obj_port_vlan *vlan);
  261. void b53_vlan_add(struct dsa_switch *ds, int port,
  262. const struct switchdev_obj_port_vlan *vlan);
  263. int b53_vlan_del(struct dsa_switch *ds, int port,
  264. const struct switchdev_obj_port_vlan *vlan);
  265. int b53_fdb_add(struct dsa_switch *ds, int port,
  266. const unsigned char *addr, u16 vid);
  267. int b53_fdb_del(struct dsa_switch *ds, int port,
  268. const unsigned char *addr, u16 vid);
  269. int b53_fdb_dump(struct dsa_switch *ds, int port,
  270. dsa_fdb_dump_cb_t *cb, void *data);
  271. int b53_mirror_add(struct dsa_switch *ds, int port,
  272. struct dsa_mall_mirror_tc_entry *mirror, bool ingress);
  273. enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port);
  274. void b53_mirror_del(struct dsa_switch *ds, int port,
  275. struct dsa_mall_mirror_tc_entry *mirror);
  276. int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
  277. void b53_disable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
  278. void b53_brcm_hdr_setup(struct dsa_switch *ds, int port);
  279. void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable);
  280. int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy);
  281. int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
  282. int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
  283. #endif