1a556c76aSAlexandre Belloni /* SPDX-License-Identifier: (GPL-2.0 OR MIT) */ 2a556c76aSAlexandre Belloni /* 3a556c76aSAlexandre Belloni * Microsemi Ocelot Switch driver 4a556c76aSAlexandre Belloni * 5a556c76aSAlexandre Belloni * Copyright (c) 2017 Microsemi Corporation 6a556c76aSAlexandre Belloni */ 7a556c76aSAlexandre Belloni 8a556c76aSAlexandre Belloni #ifndef _MSCC_OCELOT_H_ 9a556c76aSAlexandre Belloni #define _MSCC_OCELOT_H_ 10a556c76aSAlexandre Belloni 11a556c76aSAlexandre Belloni #include <linux/bitops.h> 12a556c76aSAlexandre Belloni #include <linux/etherdevice.h> 13a556c76aSAlexandre Belloni #include <linux/if_vlan.h> 144e3b0468SAntoine Tenart #include <linux/net_tstamp.h> 15e6e12df6SVladimir Oltean #include <linux/phylink.h> 16a556c76aSAlexandre Belloni #include <linux/platform_device.h> 17a556c76aSAlexandre Belloni #include <linux/regmap.h> 18a556c76aSAlexandre Belloni 19964ee5c8SVladimir Oltean #include <soc/mscc/ocelot_qsys.h> 20a030dfe1SVladimir Oltean #include <soc/mscc/ocelot_sys.h> 21964ee5c8SVladimir Oltean #include <soc/mscc/ocelot_dev.h> 22964ee5c8SVladimir Oltean #include <soc/mscc/ocelot_ana.h> 232b49d128SYangbo Lu #include <soc/mscc/ocelot_ptp.h> 24b9bace6eSVladimir Oltean #include <soc/mscc/ocelot_vcap.h> 255e256365SVladimir Oltean #include <soc/mscc/ocelot.h> 26a556c76aSAlexandre Belloni #include "ocelot_rew.h" 27a556c76aSAlexandre Belloni #include "ocelot_qs.h" 28a556c76aSAlexandre Belloni 2954c31984SVladimir Oltean #define OCELOT_STANDALONE_PVID 0 30a556c76aSAlexandre Belloni #define OCELOT_BUFFER_CELL_SZ 60 31a556c76aSAlexandre Belloni 32a556c76aSAlexandre Belloni #define OCELOT_STATS_CHECK_DELAY (2 * HZ) 33a556c76aSAlexandre Belloni 344e3b0468SAntoine Tenart #define OCELOT_PTP_QUEUE_SZ 128 354e3b0468SAntoine Tenart 36de5841e1SClément Léger #define OCELOT_JUMBO_MTU 9000 37de5841e1SClément Léger 389c90eea3SVladimir Oltean struct ocelot_port_tc { 399c90eea3SVladimir Oltean bool block_shared; 409c90eea3SVladimir Oltean unsigned long offload_cnt; 41*ccb6ed42SVladimir Oltean unsigned long ingress_mirred_id; 42*ccb6ed42SVladimir Oltean unsigned long egress_mirred_id; 439c90eea3SVladimir Oltean unsigned long police_id; 449c90eea3SVladimir Oltean }; 459c90eea3SVladimir Oltean 46004d44f6SVladimir Oltean struct ocelot_port_private { 47004d44f6SVladimir Oltean struct ocelot_port port; 48004d44f6SVladimir Oltean struct net_device *dev; 49e6e12df6SVladimir Oltean struct phylink *phylink; 50e6e12df6SVladimir Oltean struct phylink_config phylink_config; 51004d44f6SVladimir Oltean u8 chip_port; 522c1d029aSJoergen Andreasen struct ocelot_port_tc tc; 534e3b0468SAntoine Tenart }; 544e3b0468SAntoine Tenart 559c90eea3SVladimir Oltean struct ocelot_dump_ctx { 569c90eea3SVladimir Oltean struct net_device *dev; 579c90eea3SVladimir Oltean struct sk_buff *skb; 589c90eea3SVladimir Oltean struct netlink_callback *cb; 599c90eea3SVladimir Oltean int idx; 609c90eea3SVladimir Oltean }; 619c90eea3SVladimir Oltean 62e5d1f896SVladimir Oltean /* A (PGID) port mask structure, encoding the 2^ocelot->num_phys_ports 63e5d1f896SVladimir Oltean * possibilities of egress port masks for L2 multicast traffic. 64e5d1f896SVladimir Oltean * For a switch with 9 user ports, there are 512 possible port masks, but the 65e5d1f896SVladimir Oltean * hardware only has 46 individual PGIDs that it can forward multicast traffic 66e5d1f896SVladimir Oltean * to. So we need a structure that maps the limited PGID indices to the port 67e5d1f896SVladimir Oltean * destinations requested by the user for L2 multicast. 68e5d1f896SVladimir Oltean */ 69e5d1f896SVladimir Oltean struct ocelot_pgid { 70e5d1f896SVladimir Oltean unsigned long ports; 71e5d1f896SVladimir Oltean int index; 72e5d1f896SVladimir Oltean refcount_t refcount; 73e5d1f896SVladimir Oltean struct list_head list; 74e5d1f896SVladimir Oltean }; 75e5d1f896SVladimir Oltean 76bb8d53fdSVladimir Oltean struct ocelot_multicast { 77bb8d53fdSVladimir Oltean struct list_head list; 78bb8d53fdSVladimir Oltean enum macaccess_entry_type entry_type; 79bb8d53fdSVladimir Oltean unsigned char addr[ETH_ALEN]; 80bb8d53fdSVladimir Oltean u16 vid; 81bb8d53fdSVladimir Oltean u16 ports; 82e5d1f896SVladimir Oltean struct ocelot_pgid *pgid; 83bb8d53fdSVladimir Oltean }; 84bb8d53fdSVladimir Oltean 8554c31984SVladimir Oltean int ocelot_bridge_num_find(struct ocelot *ocelot, 8654c31984SVladimir Oltean const struct net_device *bridge); 8754c31984SVladimir Oltean 889c90eea3SVladimir Oltean int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid, 899c90eea3SVladimir Oltean bool is_static, void *data); 909c90eea3SVladimir Oltean int ocelot_mact_learn(struct ocelot *ocelot, int port, 919c90eea3SVladimir Oltean const unsigned char mac[ETH_ALEN], 929c90eea3SVladimir Oltean unsigned int vid, enum macaccess_entry_type type); 939c90eea3SVladimir Oltean int ocelot_mact_forget(struct ocelot *ocelot, 949c90eea3SVladimir Oltean const unsigned char mac[ETH_ALEN], unsigned int vid); 95319e4dd1SVladimir Oltean struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port); 96319e4dd1SVladimir Oltean int ocelot_netdev_to_port(struct net_device *dev); 979c90eea3SVladimir Oltean 98a556c76aSAlexandre Belloni u32 ocelot_port_readl(struct ocelot_port *port, u32 reg); 99a556c76aSAlexandre Belloni void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg); 100a556c76aSAlexandre Belloni 10191c724cfSVladimir Oltean int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target, 102e6e12df6SVladimir Oltean struct device_node *portnp); 103e0c16233SDan Carpenter void ocelot_release_port(struct ocelot_port *ocelot_port); 1046c30384eSVladimir Oltean int ocelot_devlink_init(struct ocelot *ocelot); 1056c30384eSVladimir Oltean void ocelot_devlink_teardown(struct ocelot *ocelot); 1066c30384eSVladimir Oltean int ocelot_port_devlink_init(struct ocelot *ocelot, int port, 1076c30384eSVladimir Oltean enum devlink_port_flavour flavour); 1086c30384eSVladimir Oltean void ocelot_port_devlink_teardown(struct ocelot *ocelot, int port); 109a556c76aSAlexandre Belloni 1109d75b881SVladimir Oltean int ocelot_trap_add(struct ocelot *ocelot, int port, 1119d75b881SVladimir Oltean unsigned long cookie, bool take_ts, 112b9bace6eSVladimir Oltean void (*populate)(struct ocelot_vcap_filter *f)); 113b9bace6eSVladimir Oltean int ocelot_trap_del(struct ocelot *ocelot, int port, unsigned long cookie); 114b9bace6eSVladimir Oltean 115a556c76aSAlexandre Belloni extern struct notifier_block ocelot_netdevice_nb; 11656da64bcSFlorian Fainelli extern struct notifier_block ocelot_switchdev_nb; 1170e332c85SPetr Machata extern struct notifier_block ocelot_switchdev_blocking_nb; 1186c30384eSVladimir Oltean extern const struct devlink_ops ocelot_devlink_ops; 119a556c76aSAlexandre Belloni 120a556c76aSAlexandre Belloni #endif 121