b53_priv.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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/phylink.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. int (*irq_enable)(struct b53_device *dev, int port);
  42. void (*irq_disable)(struct b53_device *dev, int port);
  43. void (*phylink_get_caps)(struct b53_device *dev, int port,
  44. struct phylink_config *config);
  45. struct phylink_pcs *(*phylink_mac_select_pcs)(struct b53_device *dev,
  46. int port,
  47. phy_interface_t interface);
  48. u8 (*serdes_map_lane)(struct b53_device *dev, int port);
  49. void (*serdes_link_set)(struct b53_device *dev, int port,
  50. unsigned int mode, phy_interface_t interface,
  51. bool link_up);
  52. };
  53. #define B53_INVALID_LANE 0xff
  54. enum {
  55. BCM4908_DEVICE_ID = 0x4908,
  56. BCM5325_DEVICE_ID = 0x25,
  57. BCM5365_DEVICE_ID = 0x65,
  58. BCM5389_DEVICE_ID = 0x89,
  59. BCM5395_DEVICE_ID = 0x95,
  60. BCM5397_DEVICE_ID = 0x97,
  61. BCM5398_DEVICE_ID = 0x98,
  62. BCM53115_DEVICE_ID = 0x53115,
  63. BCM53125_DEVICE_ID = 0x53125,
  64. BCM53128_DEVICE_ID = 0x53128,
  65. BCM63XX_DEVICE_ID = 0x6300,
  66. BCM63268_DEVICE_ID = 0x63268,
  67. BCM53010_DEVICE_ID = 0x53010,
  68. BCM53011_DEVICE_ID = 0x53011,
  69. BCM53012_DEVICE_ID = 0x53012,
  70. BCM53018_DEVICE_ID = 0x53018,
  71. BCM53019_DEVICE_ID = 0x53019,
  72. BCM58XX_DEVICE_ID = 0x5800,
  73. BCM583XX_DEVICE_ID = 0x58300,
  74. BCM7445_DEVICE_ID = 0x7445,
  75. BCM7278_DEVICE_ID = 0x7278,
  76. BCM53134_DEVICE_ID = 0x5075,
  77. };
  78. struct b53_pcs {
  79. struct phylink_pcs pcs;
  80. struct b53_device *dev;
  81. u8 lane;
  82. };
  83. #define B53_N_PORTS 9
  84. #define B53_N_PORTS_25 6
  85. #define B53_N_PCS 2
  86. struct b53_port {
  87. u16 vlan_ctl_mask;
  88. u16 pvid;
  89. struct ethtool_keee eee;
  90. };
  91. struct b53_vlan {
  92. u16 members;
  93. u16 untag;
  94. bool valid;
  95. };
  96. struct b53_device {
  97. struct dsa_switch *ds;
  98. struct b53_platform_data *pdata;
  99. const char *name;
  100. struct mutex reg_mutex;
  101. struct mutex stats_mutex;
  102. struct mutex arl_mutex;
  103. const struct b53_io_ops *ops;
  104. /* chip specific data */
  105. u32 chip_id;
  106. u8 core_rev;
  107. u8 vta_regs[3];
  108. u8 duplex_reg;
  109. u8 jumbo_pm_reg;
  110. u8 jumbo_size_reg;
  111. int reset_gpio;
  112. u8 num_arl_bins;
  113. u16 num_arl_buckets;
  114. enum dsa_tag_protocol tag_protocol;
  115. /* used ports mask */
  116. u16 enabled_ports;
  117. unsigned int imp_port;
  118. /* connect specific data */
  119. u8 current_page;
  120. struct device *dev;
  121. u8 serdes_lane;
  122. /* Master MDIO bus we got probed from */
  123. struct mii_bus *bus;
  124. void *priv;
  125. /* run time configuration */
  126. bool enable_jumbo;
  127. unsigned int num_vlans;
  128. struct b53_vlan *vlans;
  129. bool vlan_enabled;
  130. bool vlan_filtering;
  131. unsigned int num_ports;
  132. struct b53_port *ports;
  133. struct b53_pcs pcs[B53_N_PCS];
  134. };
  135. #define b53_for_each_port(dev, i) \
  136. for (i = 0; i < B53_N_PORTS; i++) \
  137. if (dev->enabled_ports & BIT(i))
  138. static inline int is5325(struct b53_device *dev)
  139. {
  140. return dev->chip_id == BCM5325_DEVICE_ID;
  141. }
  142. static inline int is5365(struct b53_device *dev)
  143. {
  144. #ifdef CONFIG_BCM47XX
  145. return dev->chip_id == BCM5365_DEVICE_ID;
  146. #else
  147. return 0;
  148. #endif
  149. }
  150. static inline int is5397_98(struct b53_device *dev)
  151. {
  152. return dev->chip_id == BCM5397_DEVICE_ID ||
  153. dev->chip_id == BCM5398_DEVICE_ID;
  154. }
  155. static inline int is539x(struct b53_device *dev)
  156. {
  157. return dev->chip_id == BCM5395_DEVICE_ID ||
  158. dev->chip_id == BCM5397_DEVICE_ID ||
  159. dev->chip_id == BCM5398_DEVICE_ID;
  160. }
  161. static inline int is531x5(struct b53_device *dev)
  162. {
  163. return dev->chip_id == BCM53115_DEVICE_ID ||
  164. dev->chip_id == BCM53125_DEVICE_ID ||
  165. dev->chip_id == BCM53128_DEVICE_ID ||
  166. dev->chip_id == BCM53134_DEVICE_ID;
  167. }
  168. static inline int is63xx(struct b53_device *dev)
  169. {
  170. return dev->chip_id == BCM63XX_DEVICE_ID ||
  171. dev->chip_id == BCM63268_DEVICE_ID;
  172. }
  173. static inline int is63268(struct b53_device *dev)
  174. {
  175. return dev->chip_id == BCM63268_DEVICE_ID;
  176. }
  177. static inline int is5301x(struct b53_device *dev)
  178. {
  179. return dev->chip_id == BCM53010_DEVICE_ID ||
  180. dev->chip_id == BCM53011_DEVICE_ID ||
  181. dev->chip_id == BCM53012_DEVICE_ID ||
  182. dev->chip_id == BCM53018_DEVICE_ID ||
  183. dev->chip_id == BCM53019_DEVICE_ID;
  184. }
  185. static inline int is58xx(struct b53_device *dev)
  186. {
  187. return dev->chip_id == BCM58XX_DEVICE_ID ||
  188. dev->chip_id == BCM583XX_DEVICE_ID ||
  189. dev->chip_id == BCM7445_DEVICE_ID ||
  190. dev->chip_id == BCM7278_DEVICE_ID ||
  191. dev->chip_id == BCM53134_DEVICE_ID;
  192. }
  193. #define B53_63XX_RGMII0 4
  194. #define B53_CPU_PORT_25 5
  195. #define B53_CPU_PORT 8
  196. static inline unsigned int b53_max_arl_entries(struct b53_device *dev)
  197. {
  198. return dev->num_arl_buckets * dev->num_arl_bins;
  199. }
  200. struct b53_device *b53_switch_alloc(struct device *base,
  201. const struct b53_io_ops *ops,
  202. void *priv);
  203. int b53_switch_detect(struct b53_device *dev);
  204. int b53_switch_register(struct b53_device *dev);
  205. static inline void b53_switch_remove(struct b53_device *dev)
  206. {
  207. dsa_unregister_switch(dev->ds);
  208. }
  209. static inline void b53_switch_shutdown(struct b53_device *dev)
  210. {
  211. dsa_switch_shutdown(dev->ds);
  212. }
  213. #define b53_build_op(type_op_size, val_type) \
  214. static inline int b53_##type_op_size(struct b53_device *dev, u8 page, \
  215. u8 reg, val_type val) \
  216. { \
  217. int ret; \
  218. \
  219. mutex_lock(&dev->reg_mutex); \
  220. ret = dev->ops->type_op_size(dev, page, reg, val); \
  221. mutex_unlock(&dev->reg_mutex); \
  222. \
  223. return ret; \
  224. }
  225. b53_build_op(read8, u8 *);
  226. b53_build_op(read16, u16 *);
  227. b53_build_op(read32, u32 *);
  228. b53_build_op(read48, u64 *);
  229. b53_build_op(read64, u64 *);
  230. b53_build_op(write8, u8);
  231. b53_build_op(write16, u16);
  232. b53_build_op(write32, u32);
  233. b53_build_op(write48, u64);
  234. b53_build_op(write64, u64);
  235. struct b53_arl_entry {
  236. u16 port;
  237. u8 mac[ETH_ALEN];
  238. u16 vid;
  239. u8 is_valid:1;
  240. u8 is_age:1;
  241. u8 is_static:1;
  242. };
  243. static inline void b53_arl_to_entry(struct b53_arl_entry *ent,
  244. u64 mac_vid, u32 fwd_entry)
  245. {
  246. memset(ent, 0, sizeof(*ent));
  247. ent->port = fwd_entry & ARLTBL_DATA_PORT_ID_MASK;
  248. ent->is_valid = !!(fwd_entry & ARLTBL_VALID);
  249. ent->is_age = !!(fwd_entry & ARLTBL_AGE);
  250. ent->is_static = !!(fwd_entry & ARLTBL_STATIC);
  251. u64_to_ether_addr(mac_vid, ent->mac);
  252. ent->vid = mac_vid >> ARLTBL_VID_S;
  253. }
  254. static inline void b53_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
  255. const struct b53_arl_entry *ent)
  256. {
  257. *mac_vid = ether_addr_to_u64(ent->mac);
  258. *mac_vid |= (u64)(ent->vid & ARLTBL_VID_MASK) << ARLTBL_VID_S;
  259. *fwd_entry = ent->port & ARLTBL_DATA_PORT_ID_MASK;
  260. if (ent->is_valid)
  261. *fwd_entry |= ARLTBL_VALID;
  262. if (ent->is_static)
  263. *fwd_entry |= ARLTBL_STATIC;
  264. if (ent->is_age)
  265. *fwd_entry |= ARLTBL_AGE;
  266. }
  267. #ifdef CONFIG_BCM47XX
  268. #include <linux/bcm47xx_nvram.h>
  269. #include <bcm47xx_board.h>
  270. static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
  271. {
  272. enum bcm47xx_board board = bcm47xx_board_get();
  273. switch (board) {
  274. case BCM47XX_BOARD_LINKSYS_WRT300NV11:
  275. case BCM47XX_BOARD_LINKSYS_WRT310NV1:
  276. return 8;
  277. default:
  278. return bcm47xx_nvram_gpio_pin("robo_reset");
  279. }
  280. }
  281. #else
  282. static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
  283. {
  284. return -ENOENT;
  285. }
  286. #endif
  287. /* Exported functions towards other drivers */
  288. void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port);
  289. int b53_configure_vlan(struct dsa_switch *ds);
  290. void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
  291. uint8_t *data);
  292. void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
  293. int b53_get_sset_count(struct dsa_switch *ds, int port, int sset);
  294. void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data);
  295. int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
  296. bool *tx_fwd_offload, struct netlink_ext_ack *extack);
  297. void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge);
  298. void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);
  299. void b53_br_fast_age(struct dsa_switch *ds, int port);
  300. int b53_br_flags_pre(struct dsa_switch *ds, int port,
  301. struct switchdev_brport_flags flags,
  302. struct netlink_ext_ack *extack);
  303. int b53_br_flags(struct dsa_switch *ds, int port,
  304. struct switchdev_brport_flags flags,
  305. struct netlink_ext_ack *extack);
  306. int b53_setup_devlink_resources(struct dsa_switch *ds);
  307. void b53_port_event(struct dsa_switch *ds, int port);
  308. int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering,
  309. struct netlink_ext_ack *extack);
  310. int b53_vlan_add(struct dsa_switch *ds, int port,
  311. const struct switchdev_obj_port_vlan *vlan,
  312. struct netlink_ext_ack *extack);
  313. int b53_vlan_del(struct dsa_switch *ds, int port,
  314. const struct switchdev_obj_port_vlan *vlan);
  315. int b53_fdb_add(struct dsa_switch *ds, int port,
  316. const unsigned char *addr, u16 vid,
  317. struct dsa_db db);
  318. int b53_fdb_del(struct dsa_switch *ds, int port,
  319. const unsigned char *addr, u16 vid,
  320. struct dsa_db db);
  321. int b53_fdb_dump(struct dsa_switch *ds, int port,
  322. dsa_fdb_dump_cb_t *cb, void *data);
  323. int b53_mdb_add(struct dsa_switch *ds, int port,
  324. const struct switchdev_obj_port_mdb *mdb,
  325. struct dsa_db db);
  326. int b53_mdb_del(struct dsa_switch *ds, int port,
  327. const struct switchdev_obj_port_mdb *mdb,
  328. struct dsa_db db);
  329. int b53_mirror_add(struct dsa_switch *ds, int port,
  330. struct dsa_mall_mirror_tc_entry *mirror, bool ingress,
  331. struct netlink_ext_ack *extack);
  332. enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port,
  333. enum dsa_tag_protocol mprot);
  334. void b53_mirror_del(struct dsa_switch *ds, int port,
  335. struct dsa_mall_mirror_tc_entry *mirror);
  336. int b53_setup_port(struct dsa_switch *ds, int port);
  337. int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
  338. void b53_disable_port(struct dsa_switch *ds, int port);
  339. void b53_brcm_hdr_setup(struct dsa_switch *ds, int port);
  340. int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy);
  341. bool b53_support_eee(struct dsa_switch *ds, int port);
  342. int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_keee *e);
  343. int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_keee *e);
  344. #endif