xref: /openbmc/linux/drivers/net/dsa/ocelot/felix.h (revision d47a97bd)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright 2019 NXP
3  */
4 #ifndef _MSCC_FELIX_H
5 #define _MSCC_FELIX_H
6 
7 #define ocelot_to_felix(o)		container_of((o), struct felix, ocelot)
8 #define FELIX_MAC_QUIRKS		OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION
9 
10 #define OCELOT_PORT_MODE_NONE		0
11 #define OCELOT_PORT_MODE_INTERNAL	BIT(0)
12 #define OCELOT_PORT_MODE_SGMII		BIT(1)
13 #define OCELOT_PORT_MODE_QSGMII		BIT(2)
14 #define OCELOT_PORT_MODE_2500BASEX	BIT(3)
15 #define OCELOT_PORT_MODE_USXGMII	BIT(4)
16 #define OCELOT_PORT_MODE_1000BASEX	BIT(5)
17 
18 /* Platform-specific information */
19 struct felix_info {
20 	/* Hardcoded resources provided by the hardware instantiation. */
21 	const struct resource		*resources;
22 	size_t				num_resources;
23 	/* Names of the mandatory resources that will be requested during
24 	 * probe. Must have TARGET_MAX elements, since it is indexed by target.
25 	 */
26 	const char *const		*resource_names;
27 	const struct reg_field		*regfields;
28 	const u32 *const		*map;
29 	const struct ocelot_ops		*ops;
30 	const u32			*port_modes;
31 	int				num_mact_rows;
32 	int				num_ports;
33 	int				num_tx_queues;
34 	struct vcap_props		*vcap;
35 	u16				vcap_pol_base;
36 	u16				vcap_pol_max;
37 	u16				vcap_pol_base2;
38 	u16				vcap_pol_max2;
39 	const struct ptp_clock_info	*ptp_caps;
40 	unsigned long			quirks;
41 
42 	/* Some Ocelot switches are integrated into the SoC without the
43 	 * extraction IRQ line connected to the ARM GIC. By enabling this
44 	 * workaround, the few packets that are delivered to the CPU port
45 	 * module (currently only PTP) are copied not only to the hardware CPU
46 	 * port module, but also to the 802.1Q Ethernet CPU port, and polling
47 	 * the extraction registers is triggered once the DSA tagger sees a PTP
48 	 * frame. The Ethernet frame is only used as a notification: it is
49 	 * dropped, and the original frame is extracted over MMIO and annotated
50 	 * with the RX timestamp.
51 	 */
52 	bool				quirk_no_xtr_irq;
53 
54 	int	(*mdio_bus_alloc)(struct ocelot *ocelot);
55 	void	(*mdio_bus_free)(struct ocelot *ocelot);
56 	int	(*port_setup_tc)(struct dsa_switch *ds, int port,
57 				 enum tc_setup_type type, void *type_data);
58 	void	(*tas_guard_bands_update)(struct ocelot *ocelot, int port);
59 	void	(*port_sched_speed_set)(struct ocelot *ocelot, int port,
60 					u32 speed);
61 };
62 
63 /* Methods for initializing the hardware resources specific to a tagging
64  * protocol (like the NPI port, for "ocelot" or "seville", or the VCAP TCAMs,
65  * for "ocelot-8021q").
66  * It is important that the resources configured here do not have side effects
67  * for the other tagging protocols. If that is the case, their configuration
68  * needs to go to felix_tag_proto_setup_shared().
69  */
70 struct felix_tag_proto_ops {
71 	int (*setup)(struct dsa_switch *ds);
72 	void (*teardown)(struct dsa_switch *ds);
73 	unsigned long (*get_host_fwd_mask)(struct dsa_switch *ds);
74 	int (*change_master)(struct dsa_switch *ds, int port,
75 			     struct net_device *master,
76 			     struct netlink_ext_ack *extack);
77 };
78 
79 extern const struct dsa_switch_ops felix_switch_ops;
80 
81 /* DSA glue / front-end for struct ocelot */
82 struct felix {
83 	struct dsa_switch		*ds;
84 	const struct felix_info		*info;
85 	struct ocelot			ocelot;
86 	struct mii_bus			*imdio;
87 	struct phylink_pcs		**pcs;
88 	resource_size_t			switch_base;
89 	enum dsa_tag_protocol		tag_proto;
90 	const struct felix_tag_proto_ops *tag_proto_ops;
91 	struct kthread_worker		*xmit_worker;
92 	unsigned long			host_flood_uc_mask;
93 	unsigned long			host_flood_mc_mask;
94 };
95 
96 struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port);
97 int felix_netdev_to_port(struct net_device *dev);
98 
99 #endif
100