b53_priv.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. BCM5395_DEVICE_ID = 0x95,
  46. BCM5397_DEVICE_ID = 0x97,
  47. BCM5398_DEVICE_ID = 0x98,
  48. BCM53115_DEVICE_ID = 0x53115,
  49. BCM53125_DEVICE_ID = 0x53125,
  50. BCM53128_DEVICE_ID = 0x53128,
  51. BCM63XX_DEVICE_ID = 0x6300,
  52. BCM53010_DEVICE_ID = 0x53010,
  53. BCM53011_DEVICE_ID = 0x53011,
  54. BCM53012_DEVICE_ID = 0x53012,
  55. BCM53018_DEVICE_ID = 0x53018,
  56. BCM53019_DEVICE_ID = 0x53019,
  57. BCM58XX_DEVICE_ID = 0x5800,
  58. BCM7445_DEVICE_ID = 0x7445,
  59. BCM7278_DEVICE_ID = 0x7278,
  60. };
  61. #define B53_N_PORTS 9
  62. #define B53_N_PORTS_25 6
  63. struct b53_port {
  64. u16 vlan_ctl_mask;
  65. struct ethtool_eee eee;
  66. };
  67. struct b53_vlan {
  68. u16 members;
  69. u16 untag;
  70. bool valid;
  71. };
  72. struct b53_device {
  73. struct dsa_switch *ds;
  74. struct b53_platform_data *pdata;
  75. const char *name;
  76. struct mutex reg_mutex;
  77. struct mutex stats_mutex;
  78. const struct b53_io_ops *ops;
  79. /* chip specific data */
  80. u32 chip_id;
  81. u8 core_rev;
  82. u8 vta_regs[3];
  83. u8 duplex_reg;
  84. u8 jumbo_pm_reg;
  85. u8 jumbo_size_reg;
  86. int reset_gpio;
  87. u8 num_arl_entries;
  88. /* used ports mask */
  89. u16 enabled_ports;
  90. unsigned int cpu_port;
  91. /* connect specific data */
  92. u8 current_page;
  93. struct device *dev;
  94. /* Master MDIO bus we got probed from */
  95. struct mii_bus *bus;
  96. void *priv;
  97. /* run time configuration */
  98. bool enable_jumbo;
  99. unsigned int num_vlans;
  100. struct b53_vlan *vlans;
  101. unsigned int num_ports;
  102. struct b53_port *ports;
  103. };
  104. #define b53_for_each_port(dev, i) \
  105. for (i = 0; i < B53_N_PORTS; i++) \
  106. if (dev->enabled_ports & BIT(i))
  107. static inline int is5325(struct b53_device *dev)
  108. {
  109. return dev->chip_id == BCM5325_DEVICE_ID;
  110. }
  111. static inline int is5365(struct b53_device *dev)
  112. {
  113. #ifdef CONFIG_BCM47XX
  114. return dev->chip_id == BCM5365_DEVICE_ID;
  115. #else
  116. return 0;
  117. #endif
  118. }
  119. static inline int is5397_98(struct b53_device *dev)
  120. {
  121. return dev->chip_id == BCM5397_DEVICE_ID ||
  122. dev->chip_id == BCM5398_DEVICE_ID;
  123. }
  124. static inline int is539x(struct b53_device *dev)
  125. {
  126. return dev->chip_id == BCM5395_DEVICE_ID ||
  127. dev->chip_id == BCM5397_DEVICE_ID ||
  128. dev->chip_id == BCM5398_DEVICE_ID;
  129. }
  130. static inline int is531x5(struct b53_device *dev)
  131. {
  132. return dev->chip_id == BCM53115_DEVICE_ID ||
  133. dev->chip_id == BCM53125_DEVICE_ID ||
  134. dev->chip_id == BCM53128_DEVICE_ID;
  135. }
  136. static inline int is63xx(struct b53_device *dev)
  137. {
  138. #ifdef CONFIG_BCM63XX
  139. return dev->chip_id == BCM63XX_DEVICE_ID;
  140. #else
  141. return 0;
  142. #endif
  143. }
  144. static inline int is5301x(struct b53_device *dev)
  145. {
  146. return dev->chip_id == BCM53010_DEVICE_ID ||
  147. dev->chip_id == BCM53011_DEVICE_ID ||
  148. dev->chip_id == BCM53012_DEVICE_ID ||
  149. dev->chip_id == BCM53018_DEVICE_ID ||
  150. dev->chip_id == BCM53019_DEVICE_ID;
  151. }
  152. static inline int is58xx(struct b53_device *dev)
  153. {
  154. return dev->chip_id == BCM58XX_DEVICE_ID ||
  155. dev->chip_id == BCM7445_DEVICE_ID ||
  156. dev->chip_id == BCM7278_DEVICE_ID;
  157. }
  158. #define B53_CPU_PORT_25 5
  159. #define B53_CPU_PORT 8
  160. struct b53_device *b53_switch_alloc(struct device *base,
  161. const struct b53_io_ops *ops,
  162. void *priv);
  163. int b53_switch_detect(struct b53_device *dev);
  164. int b53_switch_register(struct b53_device *dev);
  165. static inline void b53_switch_remove(struct b53_device *dev)
  166. {
  167. dsa_unregister_switch(dev->ds);
  168. }
  169. #define b53_build_op(type_op_size, val_type) \
  170. static inline int b53_##type_op_size(struct b53_device *dev, u8 page, \
  171. u8 reg, val_type val) \
  172. { \
  173. int ret; \
  174. \
  175. mutex_lock(&dev->reg_mutex); \
  176. ret = dev->ops->type_op_size(dev, page, reg, val); \
  177. mutex_unlock(&dev->reg_mutex); \
  178. \
  179. return ret; \
  180. }
  181. b53_build_op(read8, u8 *);
  182. b53_build_op(read16, u16 *);
  183. b53_build_op(read32, u32 *);
  184. b53_build_op(read48, u64 *);
  185. b53_build_op(read64, u64 *);
  186. b53_build_op(write8, u8);
  187. b53_build_op(write16, u16);
  188. b53_build_op(write32, u32);
  189. b53_build_op(write48, u64);
  190. b53_build_op(write64, u64);
  191. struct b53_arl_entry {
  192. u8 port;
  193. u8 mac[ETH_ALEN];
  194. u16 vid;
  195. u8 is_valid:1;
  196. u8 is_age:1;
  197. u8 is_static:1;
  198. };
  199. static inline void b53_arl_to_entry(struct b53_arl_entry *ent,
  200. u64 mac_vid, u32 fwd_entry)
  201. {
  202. memset(ent, 0, sizeof(*ent));
  203. ent->port = fwd_entry & ARLTBL_DATA_PORT_ID_MASK;
  204. ent->is_valid = !!(fwd_entry & ARLTBL_VALID);
  205. ent->is_age = !!(fwd_entry & ARLTBL_AGE);
  206. ent->is_static = !!(fwd_entry & ARLTBL_STATIC);
  207. u64_to_ether_addr(mac_vid, ent->mac);
  208. ent->vid = mac_vid >> ARLTBL_VID_S;
  209. }
  210. static inline void b53_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
  211. const struct b53_arl_entry *ent)
  212. {
  213. *mac_vid = ether_addr_to_u64(ent->mac);
  214. *mac_vid |= (u64)(ent->vid & ARLTBL_VID_MASK) << ARLTBL_VID_S;
  215. *fwd_entry = ent->port & ARLTBL_DATA_PORT_ID_MASK;
  216. if (ent->is_valid)
  217. *fwd_entry |= ARLTBL_VALID;
  218. if (ent->is_static)
  219. *fwd_entry |= ARLTBL_STATIC;
  220. if (ent->is_age)
  221. *fwd_entry |= ARLTBL_AGE;
  222. }
  223. #ifdef CONFIG_BCM47XX
  224. #include <linux/bcm47xx_nvram.h>
  225. #include <bcm47xx_board.h>
  226. static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
  227. {
  228. enum bcm47xx_board board = bcm47xx_board_get();
  229. switch (board) {
  230. case BCM47XX_BOARD_LINKSYS_WRT300NV11:
  231. case BCM47XX_BOARD_LINKSYS_WRT310NV1:
  232. return 8;
  233. default:
  234. return bcm47xx_nvram_gpio_pin("robo_reset");
  235. }
  236. }
  237. #else
  238. static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
  239. {
  240. return -ENOENT;
  241. }
  242. #endif
  243. /* Exported functions towards other drivers */
  244. void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port);
  245. int b53_configure_vlan(struct dsa_switch *ds);
  246. void b53_get_strings(struct dsa_switch *ds, int port, uint8_t *data);
  247. void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
  248. int b53_get_sset_count(struct dsa_switch *ds);
  249. int b53_br_join(struct dsa_switch *ds, int port, struct net_device *bridge);
  250. void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *bridge);
  251. void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);
  252. void b53_br_fast_age(struct dsa_switch *ds, int port);
  253. int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering);
  254. int b53_vlan_prepare(struct dsa_switch *ds, int port,
  255. const struct switchdev_obj_port_vlan *vlan,
  256. struct switchdev_trans *trans);
  257. void b53_vlan_add(struct dsa_switch *ds, int port,
  258. const struct switchdev_obj_port_vlan *vlan,
  259. struct switchdev_trans *trans);
  260. int b53_vlan_del(struct dsa_switch *ds, int port,
  261. const struct switchdev_obj_port_vlan *vlan);
  262. int b53_fdb_add(struct dsa_switch *ds, int port,
  263. const unsigned char *addr, u16 vid);
  264. int b53_fdb_del(struct dsa_switch *ds, int port,
  265. const unsigned char *addr, u16 vid);
  266. int b53_fdb_dump(struct dsa_switch *ds, int port,
  267. dsa_fdb_dump_cb_t *cb, void *data);
  268. int b53_mirror_add(struct dsa_switch *ds, int port,
  269. struct dsa_mall_mirror_tc_entry *mirror, bool ingress);
  270. void b53_mirror_del(struct dsa_switch *ds, int port,
  271. struct dsa_mall_mirror_tc_entry *mirror);
  272. int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
  273. void b53_disable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
  274. void b53_brcm_hdr_setup(struct dsa_switch *ds, int port);
  275. void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable);
  276. int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy);
  277. int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
  278. int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
  279. #endif