b53_priv.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. * B53 common definitions
  3. *
  4. * Copyright (C) 2011-2013 Jonas Gorski <[email protected]>
  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. BCM53010_DEVICE_ID = 0x53010,
  67. BCM53011_DEVICE_ID = 0x53011,
  68. BCM53012_DEVICE_ID = 0x53012,
  69. BCM53018_DEVICE_ID = 0x53018,
  70. BCM53019_DEVICE_ID = 0x53019,
  71. BCM58XX_DEVICE_ID = 0x5800,
  72. BCM583XX_DEVICE_ID = 0x58300,
  73. BCM7445_DEVICE_ID = 0x7445,
  74. BCM7278_DEVICE_ID = 0x7278,
  75. };
  76. struct b53_pcs {
  77. struct phylink_pcs pcs;
  78. struct b53_device *dev;
  79. u8 lane;
  80. };
  81. #define B53_N_PORTS 9
  82. #define B53_N_PORTS_25 6
  83. #define B53_N_PCS 2
  84. struct b53_port {
  85. u16 vlan_ctl_mask;
  86. struct ethtool_eee eee;
  87. };
  88. struct b53_vlan {
  89. u16 members;
  90. u16 untag;
  91. bool valid;
  92. };
  93. struct b53_device {
  94. struct dsa_switch *ds;
  95. struct b53_platform_data *pdata;
  96. const char *name;
  97. struct mutex reg_mutex;
  98. struct mutex stats_mutex;
  99. struct mutex arl_mutex;
  100. const struct b53_io_ops *ops;
  101. /* chip specific data */
  102. u32 chip_id;
  103. u8 core_rev;
  104. u8 vta_regs[3];
  105. u8 duplex_reg;
  106. u8 jumbo_pm_reg;
  107. u8 jumbo_size_reg;
  108. int reset_gpio;
  109. u8 num_arl_bins;
  110. u16 num_arl_buckets;
  111. enum dsa_tag_protocol tag_protocol;
  112. /* used ports mask */
  113. u16 enabled_ports;
  114. unsigned int imp_port;
  115. /* connect specific data */
  116. u8 current_page;
  117. struct device *dev;
  118. u8 serdes_lane;
  119. /* Master MDIO bus we got probed from */
  120. struct mii_bus *bus;
  121. void *priv;
  122. /* run time configuration */
  123. bool enable_jumbo;
  124. unsigned int num_vlans;
  125. struct b53_vlan *vlans;
  126. bool vlan_enabled;
  127. unsigned int num_ports;
  128. struct b53_port *ports;
  129. struct b53_pcs pcs[B53_N_PCS];
  130. };
  131. #define b53_for_each_port(dev, i) \
  132. for (i = 0; i < B53_N_PORTS; i++) \
  133. if (dev->enabled_ports & BIT(i))
  134. static inline int is5325(struct b53_device *dev)
  135. {
  136. return dev->chip_id == BCM5325_DEVICE_ID;
  137. }
  138. static inline int is5365(struct b53_device *dev)
  139. {
  140. #ifdef CONFIG_BCM47XX
  141. return dev->chip_id == BCM5365_DEVICE_ID;
  142. #else
  143. return 0;
  144. #endif
  145. }
  146. static inline int is5397_98(struct b53_device *dev)
  147. {
  148. return dev->chip_id == BCM5397_DEVICE_ID ||
  149. dev->chip_id == BCM5398_DEVICE_ID;
  150. }
  151. static inline int is539x(struct b53_device *dev)
  152. {
  153. return dev->chip_id == BCM5395_DEVICE_ID ||
  154. dev->chip_id == BCM5397_DEVICE_ID ||
  155. dev->chip_id == BCM5398_DEVICE_ID;
  156. }
  157. static inline int is531x5(struct b53_device *dev)
  158. {
  159. return dev->chip_id == BCM53115_DEVICE_ID ||
  160. dev->chip_id == BCM53125_DEVICE_ID ||
  161. dev->chip_id == BCM53128_DEVICE_ID;
  162. }
  163. static inline int is63xx(struct b53_device *dev)
  164. {
  165. return dev->chip_id == BCM63XX_DEVICE_ID;
  166. }
  167. static inline int is5301x(struct b53_device *dev)
  168. {
  169. return dev->chip_id == BCM53010_DEVICE_ID ||
  170. dev->chip_id == BCM53011_DEVICE_ID ||
  171. dev->chip_id == BCM53012_DEVICE_ID ||
  172. dev->chip_id == BCM53018_DEVICE_ID ||
  173. dev->chip_id == BCM53019_DEVICE_ID;
  174. }
  175. static inline int is58xx(struct b53_device *dev)
  176. {
  177. return dev->chip_id == BCM58XX_DEVICE_ID ||
  178. dev->chip_id == BCM583XX_DEVICE_ID ||
  179. dev->chip_id == BCM7445_DEVICE_ID ||
  180. dev->chip_id == BCM7278_DEVICE_ID;
  181. }
  182. #define B53_CPU_PORT_25 5
  183. #define B53_CPU_PORT 8
  184. static inline unsigned int b53_max_arl_entries(struct b53_device *dev)
  185. {
  186. return dev->num_arl_buckets * dev->num_arl_bins;
  187. }
  188. struct b53_device *b53_switch_alloc(struct device *base,
  189. const struct b53_io_ops *ops,
  190. void *priv);
  191. int b53_switch_detect(struct b53_device *dev);
  192. int b53_switch_register(struct b53_device *dev);
  193. static inline void b53_switch_remove(struct b53_device *dev)
  194. {
  195. dsa_unregister_switch(dev->ds);
  196. }
  197. static inline void b53_switch_shutdown(struct b53_device *dev)
  198. {
  199. dsa_switch_shutdown(dev->ds);
  200. }
  201. #define b53_build_op(type_op_size, val_type) \
  202. static inline int b53_##type_op_size(struct b53_device *dev, u8 page, \
  203. u8 reg, val_type val) \
  204. { \
  205. int ret; \
  206. \
  207. mutex_lock(&dev->reg_mutex); \
  208. ret = dev->ops->type_op_size(dev, page, reg, val); \
  209. mutex_unlock(&dev->reg_mutex); \
  210. \
  211. return ret; \
  212. }
  213. b53_build_op(read8, u8 *);
  214. b53_build_op(read16, u16 *);
  215. b53_build_op(read32, u32 *);
  216. b53_build_op(read48, u64 *);
  217. b53_build_op(read64, u64 *);
  218. b53_build_op(write8, u8);
  219. b53_build_op(write16, u16);
  220. b53_build_op(write32, u32);
  221. b53_build_op(write48, u64);
  222. b53_build_op(write64, u64);
  223. struct b53_arl_entry {
  224. u16 port;
  225. u8 mac[ETH_ALEN];
  226. u16 vid;
  227. u8 is_valid:1;
  228. u8 is_age:1;
  229. u8 is_static:1;
  230. };
  231. static inline void b53_arl_to_entry(struct b53_arl_entry *ent,
  232. u64 mac_vid, u32 fwd_entry)
  233. {
  234. memset(ent, 0, sizeof(*ent));
  235. ent->port = fwd_entry & ARLTBL_DATA_PORT_ID_MASK;
  236. ent->is_valid = !!(fwd_entry & ARLTBL_VALID);
  237. ent->is_age = !!(fwd_entry & ARLTBL_AGE);
  238. ent->is_static = !!(fwd_entry & ARLTBL_STATIC);
  239. u64_to_ether_addr(mac_vid, ent->mac);
  240. ent->vid = mac_vid >> ARLTBL_VID_S;
  241. }
  242. static inline void b53_arl_from_entry(u64 *mac_vid, u32 *fwd_entry,
  243. const struct b53_arl_entry *ent)
  244. {
  245. *mac_vid = ether_addr_to_u64(ent->mac);
  246. *mac_vid |= (u64)(ent->vid & ARLTBL_VID_MASK) << ARLTBL_VID_S;
  247. *fwd_entry = ent->port & ARLTBL_DATA_PORT_ID_MASK;
  248. if (ent->is_valid)
  249. *fwd_entry |= ARLTBL_VALID;
  250. if (ent->is_static)
  251. *fwd_entry |= ARLTBL_STATIC;
  252. if (ent->is_age)
  253. *fwd_entry |= ARLTBL_AGE;
  254. }
  255. #ifdef CONFIG_BCM47XX
  256. #include <linux/bcm47xx_nvram.h>
  257. #include <bcm47xx_board.h>
  258. static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
  259. {
  260. enum bcm47xx_board board = bcm47xx_board_get();
  261. switch (board) {
  262. case BCM47XX_BOARD_LINKSYS_WRT300NV11:
  263. case BCM47XX_BOARD_LINKSYS_WRT310NV1:
  264. return 8;
  265. default:
  266. return bcm47xx_nvram_gpio_pin("robo_reset");
  267. }
  268. }
  269. #else
  270. static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
  271. {
  272. return -ENOENT;
  273. }
  274. #endif
  275. /* Exported functions towards other drivers */
  276. void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port);
  277. int b53_configure_vlan(struct dsa_switch *ds);
  278. void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
  279. uint8_t *data);
  280. void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
  281. int b53_get_sset_count(struct dsa_switch *ds, int port, int sset);
  282. void b53_get_ethtool_phy_stats(struct dsa_switch *ds, int port, uint64_t *data);
  283. int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
  284. bool *tx_fwd_offload, struct netlink_ext_ack *extack);
  285. void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge);
  286. void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);
  287. void b53_br_fast_age(struct dsa_switch *ds, int port);
  288. int b53_br_flags_pre(struct dsa_switch *ds, int port,
  289. struct switchdev_brport_flags flags,
  290. struct netlink_ext_ack *extack);
  291. int b53_br_flags(struct dsa_switch *ds, int port,
  292. struct switchdev_brport_flags flags,
  293. struct netlink_ext_ack *extack);
  294. int b53_setup_devlink_resources(struct dsa_switch *ds);
  295. void b53_port_event(struct dsa_switch *ds, int port);
  296. void b53_phylink_mac_config(struct dsa_switch *ds, int port,
  297. unsigned int mode,
  298. const struct phylink_link_state *state);
  299. void b53_phylink_mac_link_down(struct dsa_switch *ds, int port,
  300. unsigned int mode,
  301. phy_interface_t interface);
  302. void b53_phylink_mac_link_up(struct dsa_switch *ds, int port,
  303. unsigned int mode,
  304. phy_interface_t interface,
  305. struct phy_device *phydev,
  306. int speed, int duplex,
  307. bool tx_pause, bool rx_pause);
  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_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
  337. void b53_disable_port(struct dsa_switch *ds, int port);
  338. void b53_brcm_hdr_setup(struct dsa_switch *ds, int port);
  339. void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable);
  340. int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy);
  341. int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
  342. int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e);
  343. #endif