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