162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Copyright 2019 NXP
362306a36Sopenharmony_ci */
462306a36Sopenharmony_ci#ifndef _MSCC_FELIX_H
562306a36Sopenharmony_ci#define _MSCC_FELIX_H
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#define ocelot_to_felix(o)		container_of((o), struct felix, ocelot)
862306a36Sopenharmony_ci#define FELIX_MAC_QUIRKS		OCELOT_QUIRK_PCS_PERFORMS_RATE_ADAPTATION
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#define OCELOT_PORT_MODE_NONE		0
1162306a36Sopenharmony_ci#define OCELOT_PORT_MODE_INTERNAL	BIT(0)
1262306a36Sopenharmony_ci#define OCELOT_PORT_MODE_SGMII		BIT(1)
1362306a36Sopenharmony_ci#define OCELOT_PORT_MODE_QSGMII		BIT(2)
1462306a36Sopenharmony_ci#define OCELOT_PORT_MODE_2500BASEX	BIT(3)
1562306a36Sopenharmony_ci#define OCELOT_PORT_MODE_USXGMII	BIT(4)
1662306a36Sopenharmony_ci#define OCELOT_PORT_MODE_1000BASEX	BIT(5)
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistruct device_node;
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/* Platform-specific information */
2162306a36Sopenharmony_cistruct felix_info {
2262306a36Sopenharmony_ci	/* Hardcoded resources provided by the hardware instantiation. */
2362306a36Sopenharmony_ci	const struct resource		*resources;
2462306a36Sopenharmony_ci	size_t				num_resources;
2562306a36Sopenharmony_ci	/* Names of the mandatory resources that will be requested during
2662306a36Sopenharmony_ci	 * probe. Must have TARGET_MAX elements, since it is indexed by target.
2762306a36Sopenharmony_ci	 */
2862306a36Sopenharmony_ci	const char *const		*resource_names;
2962306a36Sopenharmony_ci	const struct reg_field		*regfields;
3062306a36Sopenharmony_ci	const u32 *const		*map;
3162306a36Sopenharmony_ci	const struct ocelot_ops		*ops;
3262306a36Sopenharmony_ci	const u32			*port_modes;
3362306a36Sopenharmony_ci	int				num_mact_rows;
3462306a36Sopenharmony_ci	int				num_ports;
3562306a36Sopenharmony_ci	int				num_tx_queues;
3662306a36Sopenharmony_ci	struct vcap_props		*vcap;
3762306a36Sopenharmony_ci	u16				vcap_pol_base;
3862306a36Sopenharmony_ci	u16				vcap_pol_max;
3962306a36Sopenharmony_ci	u16				vcap_pol_base2;
4062306a36Sopenharmony_ci	u16				vcap_pol_max2;
4162306a36Sopenharmony_ci	const struct ptp_clock_info	*ptp_caps;
4262306a36Sopenharmony_ci	unsigned long			quirks;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci	/* Some Ocelot switches are integrated into the SoC without the
4562306a36Sopenharmony_ci	 * extraction IRQ line connected to the ARM GIC. By enabling this
4662306a36Sopenharmony_ci	 * workaround, the few packets that are delivered to the CPU port
4762306a36Sopenharmony_ci	 * module (currently only PTP) are copied not only to the hardware CPU
4862306a36Sopenharmony_ci	 * port module, but also to the 802.1Q Ethernet CPU port, and polling
4962306a36Sopenharmony_ci	 * the extraction registers is triggered once the DSA tagger sees a PTP
5062306a36Sopenharmony_ci	 * frame. The Ethernet frame is only used as a notification: it is
5162306a36Sopenharmony_ci	 * dropped, and the original frame is extracted over MMIO and annotated
5262306a36Sopenharmony_ci	 * with the RX timestamp.
5362306a36Sopenharmony_ci	 */
5462306a36Sopenharmony_ci	bool				quirk_no_xtr_irq;
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci	int	(*mdio_bus_alloc)(struct ocelot *ocelot);
5762306a36Sopenharmony_ci	void	(*mdio_bus_free)(struct ocelot *ocelot);
5862306a36Sopenharmony_ci	int	(*port_setup_tc)(struct dsa_switch *ds, int port,
5962306a36Sopenharmony_ci				 enum tc_setup_type type, void *type_data);
6062306a36Sopenharmony_ci	void	(*port_sched_speed_set)(struct ocelot *ocelot, int port,
6162306a36Sopenharmony_ci					u32 speed);
6262306a36Sopenharmony_ci	void	(*phylink_mac_config)(struct ocelot *ocelot, int port,
6362306a36Sopenharmony_ci				      unsigned int mode,
6462306a36Sopenharmony_ci				      const struct phylink_link_state *state);
6562306a36Sopenharmony_ci	int	(*configure_serdes)(struct ocelot *ocelot, int port,
6662306a36Sopenharmony_ci				    struct device_node *portnp);
6762306a36Sopenharmony_ci};
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/* Methods for initializing the hardware resources specific to a tagging
7062306a36Sopenharmony_ci * protocol (like the NPI port, for "ocelot" or "seville", or the VCAP TCAMs,
7162306a36Sopenharmony_ci * for "ocelot-8021q").
7262306a36Sopenharmony_ci * It is important that the resources configured here do not have side effects
7362306a36Sopenharmony_ci * for the other tagging protocols. If that is the case, their configuration
7462306a36Sopenharmony_ci * needs to go to felix_tag_proto_setup_shared().
7562306a36Sopenharmony_ci */
7662306a36Sopenharmony_cistruct felix_tag_proto_ops {
7762306a36Sopenharmony_ci	int (*setup)(struct dsa_switch *ds);
7862306a36Sopenharmony_ci	void (*teardown)(struct dsa_switch *ds);
7962306a36Sopenharmony_ci	unsigned long (*get_host_fwd_mask)(struct dsa_switch *ds);
8062306a36Sopenharmony_ci	int (*change_master)(struct dsa_switch *ds, int port,
8162306a36Sopenharmony_ci			     struct net_device *master,
8262306a36Sopenharmony_ci			     struct netlink_ext_ack *extack);
8362306a36Sopenharmony_ci};
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ciextern const struct dsa_switch_ops felix_switch_ops;
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci/* DSA glue / front-end for struct ocelot */
8862306a36Sopenharmony_cistruct felix {
8962306a36Sopenharmony_ci	struct dsa_switch		*ds;
9062306a36Sopenharmony_ci	const struct felix_info		*info;
9162306a36Sopenharmony_ci	struct ocelot			ocelot;
9262306a36Sopenharmony_ci	struct mii_bus			*imdio;
9362306a36Sopenharmony_ci	struct phylink_pcs		**pcs;
9462306a36Sopenharmony_ci	resource_size_t			switch_base;
9562306a36Sopenharmony_ci	enum dsa_tag_protocol		tag_proto;
9662306a36Sopenharmony_ci	const struct felix_tag_proto_ops *tag_proto_ops;
9762306a36Sopenharmony_ci	struct kthread_worker		*xmit_worker;
9862306a36Sopenharmony_ci	unsigned long			host_flood_uc_mask;
9962306a36Sopenharmony_ci	unsigned long			host_flood_mc_mask;
10062306a36Sopenharmony_ci};
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_cistruct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port);
10362306a36Sopenharmony_ciint felix_netdev_to_port(struct net_device *dev);
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci#endif
106