ocelot.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
  2. /*
  3. * Microsemi Ocelot Switch driver
  4. *
  5. * Copyright (c) 2017 Microsemi Corporation
  6. */
  7. #ifndef _MSCC_OCELOT_H_
  8. #define _MSCC_OCELOT_H_
  9. #include <linux/bitops.h>
  10. #include <linux/etherdevice.h>
  11. #include <linux/if_vlan.h>
  12. #include <linux/net_tstamp.h>
  13. #include <linux/phylink.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/regmap.h>
  16. #include <soc/mscc/ocelot_qsys.h>
  17. #include <soc/mscc/ocelot_sys.h>
  18. #include <soc/mscc/ocelot_dev.h>
  19. #include <soc/mscc/ocelot_ana.h>
  20. #include <soc/mscc/ocelot_ptp.h>
  21. #include <soc/mscc/ocelot_vcap.h>
  22. #include <soc/mscc/ocelot.h>
  23. #include "ocelot_rew.h"
  24. #include "ocelot_qs.h"
  25. #define OCELOT_STANDALONE_PVID 0
  26. #define OCELOT_BUFFER_CELL_SZ 60
  27. #define OCELOT_STATS_CHECK_DELAY (2 * HZ)
  28. #define OCELOT_PTP_QUEUE_SZ 128
  29. #define OCELOT_JUMBO_MTU 9000
  30. struct ocelot_port_tc {
  31. bool block_shared;
  32. unsigned long offload_cnt;
  33. unsigned long ingress_mirred_id;
  34. unsigned long egress_mirred_id;
  35. unsigned long police_id;
  36. };
  37. struct ocelot_port_private {
  38. struct ocelot_port port;
  39. struct net_device *dev;
  40. struct phylink *phylink;
  41. struct phylink_config phylink_config;
  42. struct ocelot_port_tc tc;
  43. };
  44. /* A (PGID) port mask structure, encoding the 2^ocelot->num_phys_ports
  45. * possibilities of egress port masks for L2 multicast traffic.
  46. * For a switch with 9 user ports, there are 512 possible port masks, but the
  47. * hardware only has 46 individual PGIDs that it can forward multicast traffic
  48. * to. So we need a structure that maps the limited PGID indices to the port
  49. * destinations requested by the user for L2 multicast.
  50. */
  51. struct ocelot_pgid {
  52. unsigned long ports;
  53. int index;
  54. refcount_t refcount;
  55. struct list_head list;
  56. };
  57. struct ocelot_multicast {
  58. struct list_head list;
  59. enum macaccess_entry_type entry_type;
  60. unsigned char addr[ETH_ALEN];
  61. u16 vid;
  62. u16 ports;
  63. struct ocelot_pgid *pgid;
  64. };
  65. static inline void ocelot_reg_to_target_addr(struct ocelot *ocelot,
  66. enum ocelot_reg reg,
  67. enum ocelot_target *target,
  68. u32 *addr)
  69. {
  70. *target = reg >> TARGET_OFFSET;
  71. *addr = ocelot->map[*target][reg & REG_MASK];
  72. }
  73. int ocelot_bridge_num_find(struct ocelot *ocelot,
  74. const struct net_device *bridge);
  75. int ocelot_mact_learn(struct ocelot *ocelot, int port,
  76. const unsigned char mac[ETH_ALEN],
  77. unsigned int vid, enum macaccess_entry_type type);
  78. int ocelot_mact_forget(struct ocelot *ocelot,
  79. const unsigned char mac[ETH_ALEN], unsigned int vid);
  80. struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port);
  81. int ocelot_netdev_to_port(struct net_device *dev);
  82. int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target,
  83. struct device_node *portnp);
  84. void ocelot_release_port(struct ocelot_port *ocelot_port);
  85. int ocelot_port_devlink_init(struct ocelot *ocelot, int port,
  86. enum devlink_port_flavour flavour);
  87. void ocelot_port_devlink_teardown(struct ocelot *ocelot, int port);
  88. int ocelot_trap_add(struct ocelot *ocelot, int port,
  89. unsigned long cookie, bool take_ts,
  90. void (*populate)(struct ocelot_vcap_filter *f));
  91. int ocelot_trap_del(struct ocelot *ocelot, int port, unsigned long cookie);
  92. struct ocelot_mirror *ocelot_mirror_get(struct ocelot *ocelot, int to,
  93. struct netlink_ext_ack *extack);
  94. void ocelot_mirror_put(struct ocelot *ocelot);
  95. int ocelot_stats_init(struct ocelot *ocelot);
  96. void ocelot_stats_deinit(struct ocelot *ocelot);
  97. int ocelot_mm_init(struct ocelot *ocelot);
  98. void ocelot_port_change_fp(struct ocelot *ocelot, int port,
  99. unsigned long preemptible_tcs);
  100. void ocelot_port_update_active_preemptible_tcs(struct ocelot *ocelot, int port);
  101. extern struct notifier_block ocelot_netdevice_nb;
  102. extern struct notifier_block ocelot_switchdev_nb;
  103. extern struct notifier_block ocelot_switchdev_blocking_nb;
  104. extern const struct devlink_ops ocelot_devlink_ops;
  105. #endif