xref: /openbmc/linux/drivers/net/ethernet/mscc/ocelot.h (revision 49e62a04)
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;
41ccb6ed42SVladimir Oltean 	unsigned long ingress_mirred_id;
42ccb6ed42SVladimir 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;
512c1d029aSJoergen Andreasen 	struct ocelot_port_tc tc;
524e3b0468SAntoine Tenart };
534e3b0468SAntoine Tenart 
54e5d1f896SVladimir Oltean /* A (PGID) port mask structure, encoding the 2^ocelot->num_phys_ports
55e5d1f896SVladimir Oltean  * possibilities of egress port masks for L2 multicast traffic.
56e5d1f896SVladimir Oltean  * For a switch with 9 user ports, there are 512 possible port masks, but the
57e5d1f896SVladimir Oltean  * hardware only has 46 individual PGIDs that it can forward multicast traffic
58e5d1f896SVladimir Oltean  * to. So we need a structure that maps the limited PGID indices to the port
59e5d1f896SVladimir Oltean  * destinations requested by the user for L2 multicast.
60e5d1f896SVladimir Oltean  */
61e5d1f896SVladimir Oltean struct ocelot_pgid {
62e5d1f896SVladimir Oltean 	unsigned long ports;
63e5d1f896SVladimir Oltean 	int index;
64e5d1f896SVladimir Oltean 	refcount_t refcount;
65e5d1f896SVladimir Oltean 	struct list_head list;
66e5d1f896SVladimir Oltean };
67e5d1f896SVladimir Oltean 
68bb8d53fdSVladimir Oltean struct ocelot_multicast {
69bb8d53fdSVladimir Oltean 	struct list_head list;
70bb8d53fdSVladimir Oltean 	enum macaccess_entry_type entry_type;
71bb8d53fdSVladimir Oltean 	unsigned char addr[ETH_ALEN];
72bb8d53fdSVladimir Oltean 	u16 vid;
73bb8d53fdSVladimir Oltean 	u16 ports;
74e5d1f896SVladimir Oltean 	struct ocelot_pgid *pgid;
75bb8d53fdSVladimir Oltean };
76bb8d53fdSVladimir Oltean 
ocelot_reg_to_target_addr(struct ocelot * ocelot,enum ocelot_reg reg,enum ocelot_target * target,u32 * addr)7740cd07cbSVladimir Oltean static inline void ocelot_reg_to_target_addr(struct ocelot *ocelot,
7840cd07cbSVladimir Oltean 					     enum ocelot_reg reg,
7940cd07cbSVladimir Oltean 					     enum ocelot_target *target,
8040cd07cbSVladimir Oltean 					     u32 *addr)
8140cd07cbSVladimir Oltean {
8240cd07cbSVladimir Oltean 	*target = reg >> TARGET_OFFSET;
8340cd07cbSVladimir Oltean 	*addr = ocelot->map[*target][reg & REG_MASK];
8440cd07cbSVladimir Oltean }
8540cd07cbSVladimir Oltean 
8654c31984SVladimir Oltean int ocelot_bridge_num_find(struct ocelot *ocelot,
8754c31984SVladimir Oltean 			   const struct net_device *bridge);
8854c31984SVladimir Oltean 
899c90eea3SVladimir Oltean int ocelot_mact_learn(struct ocelot *ocelot, int port,
909c90eea3SVladimir Oltean 		      const unsigned char mac[ETH_ALEN],
919c90eea3SVladimir Oltean 		      unsigned int vid, enum macaccess_entry_type type);
929c90eea3SVladimir Oltean int ocelot_mact_forget(struct ocelot *ocelot,
939c90eea3SVladimir Oltean 		       const unsigned char mac[ETH_ALEN], unsigned int vid);
94319e4dd1SVladimir Oltean struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port);
95319e4dd1SVladimir Oltean int ocelot_netdev_to_port(struct net_device *dev);
969c90eea3SVladimir Oltean 
9791c724cfSVladimir Oltean int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target,
98e6e12df6SVladimir Oltean 		      struct device_node *portnp);
99e0c16233SDan Carpenter void ocelot_release_port(struct ocelot_port *ocelot_port);
1006c30384eSVladimir Oltean int ocelot_port_devlink_init(struct ocelot *ocelot, int port,
1016c30384eSVladimir Oltean 			     enum devlink_port_flavour flavour);
1026c30384eSVladimir Oltean void ocelot_port_devlink_teardown(struct ocelot *ocelot, int port);
103a556c76aSAlexandre Belloni 
1049d75b881SVladimir Oltean int ocelot_trap_add(struct ocelot *ocelot, int port,
1059d75b881SVladimir Oltean 		    unsigned long cookie, bool take_ts,
106b9bace6eSVladimir Oltean 		    void (*populate)(struct ocelot_vcap_filter *f));
107b9bace6eSVladimir Oltean int ocelot_trap_del(struct ocelot *ocelot, int port, unsigned long cookie);
108b9bace6eSVladimir Oltean 
109f2a0e216SVladimir Oltean struct ocelot_mirror *ocelot_mirror_get(struct ocelot *ocelot, int to,
110f2a0e216SVladimir Oltean 					struct netlink_ext_ack *extack);
111f2a0e216SVladimir Oltean void ocelot_mirror_put(struct ocelot *ocelot);
112f2a0e216SVladimir Oltean 
113fe90104cSVladimir Oltean int ocelot_stats_init(struct ocelot *ocelot);
114fe90104cSVladimir Oltean void ocelot_stats_deinit(struct ocelot *ocelot);
115fe90104cSVladimir Oltean 
1166505b680SVladimir Oltean int ocelot_mm_init(struct ocelot *ocelot);
117*403ffc2cSVladimir Oltean void ocelot_port_change_fp(struct ocelot *ocelot, int port,
118*403ffc2cSVladimir Oltean 			   unsigned long preemptible_tcs);
119*403ffc2cSVladimir Oltean void ocelot_port_update_active_preemptible_tcs(struct ocelot *ocelot, int port);
1206505b680SVladimir Oltean 
121a556c76aSAlexandre Belloni extern struct notifier_block ocelot_netdevice_nb;
12256da64bcSFlorian Fainelli extern struct notifier_block ocelot_switchdev_nb;
1230e332c85SPetr Machata extern struct notifier_block ocelot_switchdev_blocking_nb;
1246c30384eSVladimir Oltean extern const struct devlink_ops ocelot_devlink_ops;
125a556c76aSAlexandre Belloni 
126a556c76aSAlexandre Belloni #endif
127