xref: /openbmc/linux/drivers/net/ethernet/mscc/ocelot.h (revision bb8d53fd)
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>
1571e32a20SQuentin Schulz #include <linux/phy.h>
1671e32a20SQuentin Schulz #include <linux/phy/phy.h>
17a556c76aSAlexandre Belloni #include <linux/platform_device.h>
18a556c76aSAlexandre Belloni #include <linux/regmap.h>
19a556c76aSAlexandre Belloni 
20964ee5c8SVladimir Oltean #include <soc/mscc/ocelot_qsys.h>
21a030dfe1SVladimir Oltean #include <soc/mscc/ocelot_sys.h>
22964ee5c8SVladimir Oltean #include <soc/mscc/ocelot_dev.h>
23964ee5c8SVladimir Oltean #include <soc/mscc/ocelot_ana.h>
242b49d128SYangbo Lu #include <soc/mscc/ocelot_ptp.h>
255e256365SVladimir Oltean #include <soc/mscc/ocelot.h>
26a556c76aSAlexandre Belloni #include "ocelot_rew.h"
27a556c76aSAlexandre Belloni #include "ocelot_qs.h"
28a556c76aSAlexandre Belloni 
29a556c76aSAlexandre Belloni #define OCELOT_BUFFER_CELL_SZ 60
30a556c76aSAlexandre Belloni 
31a556c76aSAlexandre Belloni #define OCELOT_STATS_CHECK_DELAY (2 * HZ)
32a556c76aSAlexandre Belloni 
334e3b0468SAntoine Tenart #define OCELOT_PTP_QUEUE_SZ	128
344e3b0468SAntoine Tenart 
35a556c76aSAlexandre Belloni struct frame_info {
36a556c76aSAlexandre Belloni 	u32 len;
37a556c76aSAlexandre Belloni 	u16 port;
38a556c76aSAlexandre Belloni 	u16 vid;
39a556c76aSAlexandre Belloni 	u8 tag_type;
404e3b0468SAntoine Tenart 	u16 rew_op;
414e3b0468SAntoine Tenart 	u32 timestamp;	/* rew_val */
42a556c76aSAlexandre Belloni };
43a556c76aSAlexandre Belloni 
449c90eea3SVladimir Oltean struct ocelot_port_tc {
459c90eea3SVladimir Oltean 	bool block_shared;
469c90eea3SVladimir Oltean 	unsigned long offload_cnt;
479c90eea3SVladimir Oltean 
489c90eea3SVladimir Oltean 	unsigned long police_id;
499c90eea3SVladimir Oltean };
509c90eea3SVladimir Oltean 
51004d44f6SVladimir Oltean struct ocelot_port_private {
52004d44f6SVladimir Oltean 	struct ocelot_port port;
53004d44f6SVladimir Oltean 	struct net_device *dev;
54004d44f6SVladimir Oltean 	struct phy_device *phy;
55004d44f6SVladimir Oltean 	u8 chip_port;
56004d44f6SVladimir Oltean 
5771e32a20SQuentin Schulz 	struct phy *serdes;
582c1d029aSJoergen Andreasen 
592c1d029aSJoergen Andreasen 	struct ocelot_port_tc tc;
604e3b0468SAntoine Tenart };
614e3b0468SAntoine Tenart 
629c90eea3SVladimir Oltean struct ocelot_dump_ctx {
639c90eea3SVladimir Oltean 	struct net_device *dev;
649c90eea3SVladimir Oltean 	struct sk_buff *skb;
659c90eea3SVladimir Oltean 	struct netlink_callback *cb;
669c90eea3SVladimir Oltean 	int idx;
679c90eea3SVladimir Oltean };
689c90eea3SVladimir Oltean 
699c90eea3SVladimir Oltean /* MAC table entry types.
709c90eea3SVladimir Oltean  * ENTRYTYPE_NORMAL is subject to aging.
719c90eea3SVladimir Oltean  * ENTRYTYPE_LOCKED is not subject to aging.
729c90eea3SVladimir Oltean  * ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast.
739c90eea3SVladimir Oltean  * ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast.
749c90eea3SVladimir Oltean  */
759c90eea3SVladimir Oltean enum macaccess_entry_type {
769c90eea3SVladimir Oltean 	ENTRYTYPE_NORMAL = 0,
779c90eea3SVladimir Oltean 	ENTRYTYPE_LOCKED,
789c90eea3SVladimir Oltean 	ENTRYTYPE_MACv4,
799c90eea3SVladimir Oltean 	ENTRYTYPE_MACv6,
809c90eea3SVladimir Oltean };
819c90eea3SVladimir Oltean 
82*bb8d53fdSVladimir Oltean struct ocelot_multicast {
83*bb8d53fdSVladimir Oltean 	struct list_head list;
84*bb8d53fdSVladimir Oltean 	enum macaccess_entry_type entry_type;
85*bb8d53fdSVladimir Oltean 	unsigned char addr[ETH_ALEN];
86*bb8d53fdSVladimir Oltean 	u16 vid;
87*bb8d53fdSVladimir Oltean 	u16 ports;
88*bb8d53fdSVladimir Oltean 	int pgid;
89*bb8d53fdSVladimir Oltean };
90*bb8d53fdSVladimir Oltean 
919c90eea3SVladimir Oltean int ocelot_port_fdb_do_dump(const unsigned char *addr, u16 vid,
929c90eea3SVladimir Oltean 			    bool is_static, void *data);
939c90eea3SVladimir Oltean int ocelot_mact_learn(struct ocelot *ocelot, int port,
949c90eea3SVladimir Oltean 		      const unsigned char mac[ETH_ALEN],
959c90eea3SVladimir Oltean 		      unsigned int vid, enum macaccess_entry_type type);
969c90eea3SVladimir Oltean int ocelot_mact_forget(struct ocelot *ocelot,
979c90eea3SVladimir Oltean 		       const unsigned char mac[ETH_ALEN], unsigned int vid);
989c90eea3SVladimir Oltean int ocelot_port_lag_join(struct ocelot *ocelot, int port,
999c90eea3SVladimir Oltean 			 struct net_device *bond);
1009c90eea3SVladimir Oltean void ocelot_port_lag_leave(struct ocelot *ocelot, int port,
1019c90eea3SVladimir Oltean 			   struct net_device *bond);
102319e4dd1SVladimir Oltean struct net_device *ocelot_port_to_netdev(struct ocelot *ocelot, int port);
103319e4dd1SVladimir Oltean int ocelot_netdev_to_port(struct net_device *dev);
1049c90eea3SVladimir Oltean 
105a556c76aSAlexandre Belloni u32 ocelot_port_readl(struct ocelot_port *port, u32 reg);
106a556c76aSAlexandre Belloni void ocelot_port_writel(struct ocelot_port *port, u32 val, u32 reg);
107a556c76aSAlexandre Belloni 
10891c724cfSVladimir Oltean int ocelot_probe_port(struct ocelot *ocelot, int port, struct regmap *target,
109a556c76aSAlexandre Belloni 		      struct phy_device *phy);
110a556c76aSAlexandre Belloni 
11121468199SVladimir Oltean void ocelot_set_cpu_port(struct ocelot *ocelot, int cpu,
11221468199SVladimir Oltean 			 enum ocelot_tag_prefix injection,
11321468199SVladimir Oltean 			 enum ocelot_tag_prefix extraction);
11421468199SVladimir 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;
118a556c76aSAlexandre Belloni 
119a556c76aSAlexandre Belloni #endif
120