162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
262306a36Sopenharmony_ci/* Microchip Sparx5 Switch driver
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 2021 Microchip Technology Inc. and its subsidiaries.
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef __SPARX5_MAIN_H__
862306a36Sopenharmony_ci#define __SPARX5_MAIN_H__
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/types.h>
1162306a36Sopenharmony_ci#include <linux/phy/phy.h>
1262306a36Sopenharmony_ci#include <linux/netdevice.h>
1362306a36Sopenharmony_ci#include <linux/phy.h>
1462306a36Sopenharmony_ci#include <linux/if_vlan.h>
1562306a36Sopenharmony_ci#include <linux/bitmap.h>
1662306a36Sopenharmony_ci#include <linux/phylink.h>
1762306a36Sopenharmony_ci#include <linux/net_tstamp.h>
1862306a36Sopenharmony_ci#include <linux/ptp_clock_kernel.h>
1962306a36Sopenharmony_ci#include <linux/hrtimer.h>
2062306a36Sopenharmony_ci#include <linux/debugfs.h>
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci#include "sparx5_main_regs.h"
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci/* Target chip type */
2562306a36Sopenharmony_cienum spx5_target_chiptype {
2662306a36Sopenharmony_ci	SPX5_TARGET_CT_7546    = 0x7546,  /* SparX-5-64  Enterprise */
2762306a36Sopenharmony_ci	SPX5_TARGET_CT_7549    = 0x7549,  /* SparX-5-90  Enterprise */
2862306a36Sopenharmony_ci	SPX5_TARGET_CT_7552    = 0x7552,  /* SparX-5-128 Enterprise */
2962306a36Sopenharmony_ci	SPX5_TARGET_CT_7556    = 0x7556,  /* SparX-5-160 Enterprise */
3062306a36Sopenharmony_ci	SPX5_TARGET_CT_7558    = 0x7558,  /* SparX-5-200 Enterprise */
3162306a36Sopenharmony_ci	SPX5_TARGET_CT_7546TSN = 0x47546, /* SparX-5-64i Industrial */
3262306a36Sopenharmony_ci	SPX5_TARGET_CT_7549TSN = 0x47549, /* SparX-5-90i Industrial */
3362306a36Sopenharmony_ci	SPX5_TARGET_CT_7552TSN = 0x47552, /* SparX-5-128i Industrial */
3462306a36Sopenharmony_ci	SPX5_TARGET_CT_7556TSN = 0x47556, /* SparX-5-160i Industrial */
3562306a36Sopenharmony_ci	SPX5_TARGET_CT_7558TSN = 0x47558, /* SparX-5-200i Industrial */
3662306a36Sopenharmony_ci};
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_cienum sparx5_port_max_tags {
3962306a36Sopenharmony_ci	SPX5_PORT_MAX_TAGS_NONE,  /* No extra tags allowed */
4062306a36Sopenharmony_ci	SPX5_PORT_MAX_TAGS_ONE,   /* Single tag allowed */
4162306a36Sopenharmony_ci	SPX5_PORT_MAX_TAGS_TWO    /* Single and double tag allowed */
4262306a36Sopenharmony_ci};
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_cienum sparx5_vlan_port_type {
4562306a36Sopenharmony_ci	SPX5_VLAN_PORT_TYPE_UNAWARE, /* VLAN unaware port */
4662306a36Sopenharmony_ci	SPX5_VLAN_PORT_TYPE_C,       /* C-port */
4762306a36Sopenharmony_ci	SPX5_VLAN_PORT_TYPE_S,       /* S-port */
4862306a36Sopenharmony_ci	SPX5_VLAN_PORT_TYPE_S_CUSTOM /* S-port using custom type */
4962306a36Sopenharmony_ci};
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci#define SPX5_PORTS             65
5262306a36Sopenharmony_ci#define SPX5_PORT_CPU          (SPX5_PORTS)  /* Next port is CPU port */
5362306a36Sopenharmony_ci#define SPX5_PORT_CPU_0        (SPX5_PORT_CPU + 0) /* CPU Port 65 */
5462306a36Sopenharmony_ci#define SPX5_PORT_CPU_1        (SPX5_PORT_CPU + 1) /* CPU Port 66 */
5562306a36Sopenharmony_ci#define SPX5_PORT_VD0          (SPX5_PORT_CPU + 2) /* VD0/Port 67 used for IPMC */
5662306a36Sopenharmony_ci#define SPX5_PORT_VD1          (SPX5_PORT_CPU + 3) /* VD1/Port 68 used for AFI/OAM */
5762306a36Sopenharmony_ci#define SPX5_PORT_VD2          (SPX5_PORT_CPU + 4) /* VD2/Port 69 used for IPinIP*/
5862306a36Sopenharmony_ci#define SPX5_PORTS_ALL         (SPX5_PORT_CPU + 5) /* Total number of ports */
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define PGID_BASE              SPX5_PORTS /* Starts after port PGIDs */
6162306a36Sopenharmony_ci#define PGID_UC_FLOOD          (PGID_BASE + 0)
6262306a36Sopenharmony_ci#define PGID_MC_FLOOD          (PGID_BASE + 1)
6362306a36Sopenharmony_ci#define PGID_IPV4_MC_DATA      (PGID_BASE + 2)
6462306a36Sopenharmony_ci#define PGID_IPV4_MC_CTRL      (PGID_BASE + 3)
6562306a36Sopenharmony_ci#define PGID_IPV6_MC_DATA      (PGID_BASE + 4)
6662306a36Sopenharmony_ci#define PGID_IPV6_MC_CTRL      (PGID_BASE + 5)
6762306a36Sopenharmony_ci#define PGID_BCAST	       (PGID_BASE + 6)
6862306a36Sopenharmony_ci#define PGID_CPU	       (PGID_BASE + 7)
6962306a36Sopenharmony_ci#define PGID_MCAST_START       (PGID_BASE + 8)
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci#define PGID_TABLE_SIZE	       3290
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci#define IFH_LEN                9 /* 36 bytes */
7462306a36Sopenharmony_ci#define NULL_VID               0
7562306a36Sopenharmony_ci#define SPX5_MACT_PULL_DELAY   (2 * HZ)
7662306a36Sopenharmony_ci#define SPX5_STATS_CHECK_DELAY (1 * HZ)
7762306a36Sopenharmony_ci#define SPX5_PRIOS             8     /* Number of priority queues */
7862306a36Sopenharmony_ci#define SPX5_BUFFER_CELL_SZ    184   /* Cell size  */
7962306a36Sopenharmony_ci#define SPX5_BUFFER_MEMORY     4194280 /* 22795 words * 184 bytes */
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define XTR_QUEUE     0
8262306a36Sopenharmony_ci#define INJ_QUEUE     0
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#define FDMA_DCB_MAX			64
8562306a36Sopenharmony_ci#define FDMA_RX_DCB_MAX_DBS		15
8662306a36Sopenharmony_ci#define FDMA_TX_DCB_MAX_DBS		1
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#define SPARX5_PHC_COUNT		3
8962306a36Sopenharmony_ci#define SPARX5_PHC_PORT			0
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci#define IFH_REW_OP_NOOP			0x0
9262306a36Sopenharmony_ci#define IFH_REW_OP_ONE_STEP_PTP		0x3
9362306a36Sopenharmony_ci#define IFH_REW_OP_TWO_STEP_PTP		0x4
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci#define IFH_PDU_TYPE_NONE		0x0
9662306a36Sopenharmony_ci#define IFH_PDU_TYPE_PTP		0x5
9762306a36Sopenharmony_ci#define IFH_PDU_TYPE_IPV4_UDP_PTP	0x6
9862306a36Sopenharmony_ci#define IFH_PDU_TYPE_IPV6_UDP_PTP	0x7
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_cistruct sparx5;
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_cistruct sparx5_db_hw {
10362306a36Sopenharmony_ci	u64 dataptr;
10462306a36Sopenharmony_ci	u64 status;
10562306a36Sopenharmony_ci};
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_cistruct sparx5_rx_dcb_hw {
10862306a36Sopenharmony_ci	u64 nextptr;
10962306a36Sopenharmony_ci	u64 info;
11062306a36Sopenharmony_ci	struct sparx5_db_hw db[FDMA_RX_DCB_MAX_DBS];
11162306a36Sopenharmony_ci};
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_cistruct sparx5_tx_dcb_hw {
11462306a36Sopenharmony_ci	u64 nextptr;
11562306a36Sopenharmony_ci	u64 info;
11662306a36Sopenharmony_ci	struct sparx5_db_hw db[FDMA_TX_DCB_MAX_DBS];
11762306a36Sopenharmony_ci};
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci/* Frame DMA receive state:
12062306a36Sopenharmony_ci * For each DB, there is a SKB, and the skb data pointer is mapped in
12162306a36Sopenharmony_ci * the DB. Once a frame is received the skb is given to the upper layers
12262306a36Sopenharmony_ci * and a new skb is added to the dcb.
12362306a36Sopenharmony_ci * When the db_index reached FDMA_RX_DCB_MAX_DBS the DB is reused.
12462306a36Sopenharmony_ci */
12562306a36Sopenharmony_cistruct sparx5_rx {
12662306a36Sopenharmony_ci	struct sparx5_rx_dcb_hw *dcb_entries;
12762306a36Sopenharmony_ci	struct sparx5_rx_dcb_hw *last_entry;
12862306a36Sopenharmony_ci	struct sk_buff *skb[FDMA_DCB_MAX][FDMA_RX_DCB_MAX_DBS];
12962306a36Sopenharmony_ci	int db_index;
13062306a36Sopenharmony_ci	int dcb_index;
13162306a36Sopenharmony_ci	dma_addr_t dma;
13262306a36Sopenharmony_ci	struct napi_struct napi;
13362306a36Sopenharmony_ci	u32 channel_id;
13462306a36Sopenharmony_ci	struct net_device *ndev;
13562306a36Sopenharmony_ci	u64 packets;
13662306a36Sopenharmony_ci};
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci/* Frame DMA transmit state:
13962306a36Sopenharmony_ci * DCBs are chained using the DCBs nextptr field.
14062306a36Sopenharmony_ci */
14162306a36Sopenharmony_cistruct sparx5_tx {
14262306a36Sopenharmony_ci	struct sparx5_tx_dcb_hw *curr_entry;
14362306a36Sopenharmony_ci	struct sparx5_tx_dcb_hw *first_entry;
14462306a36Sopenharmony_ci	struct list_head db_list;
14562306a36Sopenharmony_ci	dma_addr_t dma;
14662306a36Sopenharmony_ci	u32 channel_id;
14762306a36Sopenharmony_ci	u64 packets;
14862306a36Sopenharmony_ci	u64 dropped;
14962306a36Sopenharmony_ci};
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_cistruct sparx5_port_config {
15262306a36Sopenharmony_ci	phy_interface_t portmode;
15362306a36Sopenharmony_ci	u32 bandwidth;
15462306a36Sopenharmony_ci	int speed;
15562306a36Sopenharmony_ci	int duplex;
15662306a36Sopenharmony_ci	enum phy_media media;
15762306a36Sopenharmony_ci	bool inband;
15862306a36Sopenharmony_ci	bool power_down;
15962306a36Sopenharmony_ci	bool autoneg;
16062306a36Sopenharmony_ci	bool serdes_reset;
16162306a36Sopenharmony_ci	u32 pause;
16262306a36Sopenharmony_ci	u32 pause_adv;
16362306a36Sopenharmony_ci	phy_interface_t phy_mode;
16462306a36Sopenharmony_ci	u32 sd_sgpio;
16562306a36Sopenharmony_ci};
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_cistruct sparx5_port {
16862306a36Sopenharmony_ci	struct net_device *ndev;
16962306a36Sopenharmony_ci	struct sparx5 *sparx5;
17062306a36Sopenharmony_ci	struct device_node *of_node;
17162306a36Sopenharmony_ci	struct phy *serdes;
17262306a36Sopenharmony_ci	struct sparx5_port_config conf;
17362306a36Sopenharmony_ci	struct phylink_config phylink_config;
17462306a36Sopenharmony_ci	struct phylink *phylink;
17562306a36Sopenharmony_ci	struct phylink_pcs phylink_pcs;
17662306a36Sopenharmony_ci	u16 portno;
17762306a36Sopenharmony_ci	/* Ingress default VLAN (pvid) */
17862306a36Sopenharmony_ci	u16 pvid;
17962306a36Sopenharmony_ci	/* Egress default VLAN (vid) */
18062306a36Sopenharmony_ci	u16 vid;
18162306a36Sopenharmony_ci	bool signd_internal;
18262306a36Sopenharmony_ci	bool signd_active_high;
18362306a36Sopenharmony_ci	bool signd_enable;
18462306a36Sopenharmony_ci	bool flow_control;
18562306a36Sopenharmony_ci	enum sparx5_port_max_tags max_vlan_tags;
18662306a36Sopenharmony_ci	enum sparx5_vlan_port_type vlan_type;
18762306a36Sopenharmony_ci	u32 custom_etype;
18862306a36Sopenharmony_ci	bool vlan_aware;
18962306a36Sopenharmony_ci	struct hrtimer inj_timer;
19062306a36Sopenharmony_ci	/* ptp */
19162306a36Sopenharmony_ci	u8 ptp_cmd;
19262306a36Sopenharmony_ci	u16 ts_id;
19362306a36Sopenharmony_ci	struct sk_buff_head tx_skbs;
19462306a36Sopenharmony_ci	bool is_mrouter;
19562306a36Sopenharmony_ci	struct list_head tc_templates; /* list of TC templates on this port */
19662306a36Sopenharmony_ci};
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_cienum sparx5_core_clockfreq {
19962306a36Sopenharmony_ci	SPX5_CORE_CLOCK_DEFAULT,  /* Defaults to the highest supported frequency */
20062306a36Sopenharmony_ci	SPX5_CORE_CLOCK_250MHZ,   /* 250MHZ core clock frequency */
20162306a36Sopenharmony_ci	SPX5_CORE_CLOCK_500MHZ,   /* 500MHZ core clock frequency */
20262306a36Sopenharmony_ci	SPX5_CORE_CLOCK_625MHZ,   /* 625MHZ core clock frequency */
20362306a36Sopenharmony_ci};
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_cistruct sparx5_phc {
20662306a36Sopenharmony_ci	struct ptp_clock *clock;
20762306a36Sopenharmony_ci	struct ptp_clock_info info;
20862306a36Sopenharmony_ci	struct kernel_hwtstamp_config hwtstamp_config;
20962306a36Sopenharmony_ci	struct sparx5 *sparx5;
21062306a36Sopenharmony_ci	u8 index;
21162306a36Sopenharmony_ci};
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_cistruct sparx5_skb_cb {
21462306a36Sopenharmony_ci	u8 rew_op;
21562306a36Sopenharmony_ci	u8 pdu_type;
21662306a36Sopenharmony_ci	u8 pdu_w16_offset;
21762306a36Sopenharmony_ci	u16 ts_id;
21862306a36Sopenharmony_ci	unsigned long jiffies;
21962306a36Sopenharmony_ci};
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_cistruct sparx5_mdb_entry {
22262306a36Sopenharmony_ci	struct list_head list;
22362306a36Sopenharmony_ci	DECLARE_BITMAP(port_mask, SPX5_PORTS);
22462306a36Sopenharmony_ci	unsigned char addr[ETH_ALEN];
22562306a36Sopenharmony_ci	bool cpu_copy;
22662306a36Sopenharmony_ci	u16 vid;
22762306a36Sopenharmony_ci	u16 pgid_idx;
22862306a36Sopenharmony_ci};
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ci#define SPARX5_PTP_TIMEOUT		msecs_to_jiffies(10)
23162306a36Sopenharmony_ci#define SPARX5_SKB_CB(skb) \
23262306a36Sopenharmony_ci	((struct sparx5_skb_cb *)((skb)->cb))
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_cistruct sparx5 {
23562306a36Sopenharmony_ci	struct platform_device *pdev;
23662306a36Sopenharmony_ci	struct device *dev;
23762306a36Sopenharmony_ci	u32 chip_id;
23862306a36Sopenharmony_ci	enum spx5_target_chiptype target_ct;
23962306a36Sopenharmony_ci	void __iomem *regs[NUM_TARGETS];
24062306a36Sopenharmony_ci	int port_count;
24162306a36Sopenharmony_ci	struct mutex lock; /* MAC reg lock */
24262306a36Sopenharmony_ci	/* port structures are in net device */
24362306a36Sopenharmony_ci	struct sparx5_port *ports[SPX5_PORTS];
24462306a36Sopenharmony_ci	enum sparx5_core_clockfreq coreclock;
24562306a36Sopenharmony_ci	/* Statistics */
24662306a36Sopenharmony_ci	u32 num_stats;
24762306a36Sopenharmony_ci	u32 num_ethtool_stats;
24862306a36Sopenharmony_ci	const char * const *stats_layout;
24962306a36Sopenharmony_ci	u64 *stats;
25062306a36Sopenharmony_ci	/* Workqueue for reading stats */
25162306a36Sopenharmony_ci	struct mutex queue_stats_lock;
25262306a36Sopenharmony_ci	struct delayed_work stats_work;
25362306a36Sopenharmony_ci	struct workqueue_struct *stats_queue;
25462306a36Sopenharmony_ci	/* Notifiers */
25562306a36Sopenharmony_ci	struct notifier_block netdevice_nb;
25662306a36Sopenharmony_ci	struct notifier_block switchdev_nb;
25762306a36Sopenharmony_ci	struct notifier_block switchdev_blocking_nb;
25862306a36Sopenharmony_ci	/* Switch state */
25962306a36Sopenharmony_ci	u8 base_mac[ETH_ALEN];
26062306a36Sopenharmony_ci	/* Associated bridge device (when bridged) */
26162306a36Sopenharmony_ci	struct net_device *hw_bridge_dev;
26262306a36Sopenharmony_ci	/* Bridged interfaces */
26362306a36Sopenharmony_ci	DECLARE_BITMAP(bridge_mask, SPX5_PORTS);
26462306a36Sopenharmony_ci	DECLARE_BITMAP(bridge_fwd_mask, SPX5_PORTS);
26562306a36Sopenharmony_ci	DECLARE_BITMAP(bridge_lrn_mask, SPX5_PORTS);
26662306a36Sopenharmony_ci	DECLARE_BITMAP(vlan_mask[VLAN_N_VID], SPX5_PORTS);
26762306a36Sopenharmony_ci	/* SW MAC table */
26862306a36Sopenharmony_ci	struct list_head mact_entries;
26962306a36Sopenharmony_ci	/* mac table list (mact_entries) mutex */
27062306a36Sopenharmony_ci	struct mutex mact_lock;
27162306a36Sopenharmony_ci	/* SW MDB table */
27262306a36Sopenharmony_ci	struct list_head mdb_entries;
27362306a36Sopenharmony_ci	/* mdb list mutex */
27462306a36Sopenharmony_ci	struct mutex mdb_lock;
27562306a36Sopenharmony_ci	struct delayed_work mact_work;
27662306a36Sopenharmony_ci	struct workqueue_struct *mact_queue;
27762306a36Sopenharmony_ci	/* Board specifics */
27862306a36Sopenharmony_ci	bool sd_sgpio_remapping;
27962306a36Sopenharmony_ci	/* Register based inj/xtr */
28062306a36Sopenharmony_ci	int xtr_irq;
28162306a36Sopenharmony_ci	/* Frame DMA */
28262306a36Sopenharmony_ci	int fdma_irq;
28362306a36Sopenharmony_ci	spinlock_t tx_lock; /* lock for frame transmission */
28462306a36Sopenharmony_ci	struct sparx5_rx rx;
28562306a36Sopenharmony_ci	struct sparx5_tx tx;
28662306a36Sopenharmony_ci	/* PTP */
28762306a36Sopenharmony_ci	bool ptp;
28862306a36Sopenharmony_ci	struct sparx5_phc phc[SPARX5_PHC_COUNT];
28962306a36Sopenharmony_ci	spinlock_t ptp_clock_lock; /* lock for phc */
29062306a36Sopenharmony_ci	spinlock_t ptp_ts_id_lock; /* lock for ts_id */
29162306a36Sopenharmony_ci	struct mutex ptp_lock; /* lock for ptp interface state */
29262306a36Sopenharmony_ci	u16 ptp_skbs;
29362306a36Sopenharmony_ci	int ptp_irq;
29462306a36Sopenharmony_ci	/* VCAP */
29562306a36Sopenharmony_ci	struct vcap_control *vcap_ctrl;
29662306a36Sopenharmony_ci	/* PGID allocation map */
29762306a36Sopenharmony_ci	u8 pgid_map[PGID_TABLE_SIZE];
29862306a36Sopenharmony_ci	/* Common root for debugfs */
29962306a36Sopenharmony_ci	struct dentry *debugfs_root;
30062306a36Sopenharmony_ci};
30162306a36Sopenharmony_ci
30262306a36Sopenharmony_ci/* sparx5_switchdev.c */
30362306a36Sopenharmony_ciint sparx5_register_notifier_blocks(struct sparx5 *sparx5);
30462306a36Sopenharmony_civoid sparx5_unregister_notifier_blocks(struct sparx5 *sparx5);
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_ci/* sparx5_packet.c */
30762306a36Sopenharmony_cistruct frame_info {
30862306a36Sopenharmony_ci	int src_port;
30962306a36Sopenharmony_ci	u32 timestamp;
31062306a36Sopenharmony_ci};
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_civoid sparx5_xtr_flush(struct sparx5 *sparx5, u8 grp);
31362306a36Sopenharmony_civoid sparx5_ifh_parse(u32 *ifh, struct frame_info *info);
31462306a36Sopenharmony_ciirqreturn_t sparx5_xtr_handler(int irq, void *_priv);
31562306a36Sopenharmony_cinetdev_tx_t sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev);
31662306a36Sopenharmony_ciint sparx5_manual_injection_mode(struct sparx5 *sparx5);
31762306a36Sopenharmony_civoid sparx5_port_inj_timer_setup(struct sparx5_port *port);
31862306a36Sopenharmony_ci
31962306a36Sopenharmony_ci/* sparx5_fdma.c */
32062306a36Sopenharmony_ciint sparx5_fdma_start(struct sparx5 *sparx5);
32162306a36Sopenharmony_ciint sparx5_fdma_stop(struct sparx5 *sparx5);
32262306a36Sopenharmony_ciint sparx5_fdma_xmit(struct sparx5 *sparx5, u32 *ifh, struct sk_buff *skb);
32362306a36Sopenharmony_ciirqreturn_t sparx5_fdma_handler(int irq, void *args);
32462306a36Sopenharmony_ci
32562306a36Sopenharmony_ci/* sparx5_mactable.c */
32662306a36Sopenharmony_civoid sparx5_mact_pull_work(struct work_struct *work);
32762306a36Sopenharmony_ciint sparx5_mact_learn(struct sparx5 *sparx5, int port,
32862306a36Sopenharmony_ci		      const unsigned char mac[ETH_ALEN], u16 vid);
32962306a36Sopenharmony_cibool sparx5_mact_getnext(struct sparx5 *sparx5,
33062306a36Sopenharmony_ci			 unsigned char mac[ETH_ALEN], u16 *vid, u32 *pcfg2);
33162306a36Sopenharmony_ciint sparx5_mact_find(struct sparx5 *sparx5,
33262306a36Sopenharmony_ci		     const unsigned char mac[ETH_ALEN], u16 vid, u32 *pcfg2);
33362306a36Sopenharmony_ciint sparx5_mact_forget(struct sparx5 *sparx5,
33462306a36Sopenharmony_ci		       const unsigned char mac[ETH_ALEN], u16 vid);
33562306a36Sopenharmony_ciint sparx5_add_mact_entry(struct sparx5 *sparx5,
33662306a36Sopenharmony_ci			  struct net_device *dev,
33762306a36Sopenharmony_ci			  u16 portno,
33862306a36Sopenharmony_ci			  const unsigned char *addr, u16 vid);
33962306a36Sopenharmony_ciint sparx5_del_mact_entry(struct sparx5 *sparx5,
34062306a36Sopenharmony_ci			  const unsigned char *addr,
34162306a36Sopenharmony_ci			  u16 vid);
34262306a36Sopenharmony_ciint sparx5_mc_sync(struct net_device *dev, const unsigned char *addr);
34362306a36Sopenharmony_ciint sparx5_mc_unsync(struct net_device *dev, const unsigned char *addr);
34462306a36Sopenharmony_civoid sparx5_set_ageing(struct sparx5 *sparx5, int msecs);
34562306a36Sopenharmony_civoid sparx5_mact_init(struct sparx5 *sparx5);
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_ci/* sparx5_vlan.c */
34862306a36Sopenharmony_civoid sparx5_pgid_update_mask(struct sparx5_port *port, int pgid, bool enable);
34962306a36Sopenharmony_civoid sparx5_pgid_clear(struct sparx5 *spx5, int pgid);
35062306a36Sopenharmony_civoid sparx5_pgid_read_mask(struct sparx5 *sparx5, int pgid, u32 portmask[3]);
35162306a36Sopenharmony_civoid sparx5_update_fwd(struct sparx5 *sparx5);
35262306a36Sopenharmony_civoid sparx5_vlan_init(struct sparx5 *sparx5);
35362306a36Sopenharmony_civoid sparx5_vlan_port_setup(struct sparx5 *sparx5, int portno);
35462306a36Sopenharmony_ciint sparx5_vlan_vid_add(struct sparx5_port *port, u16 vid, bool pvid,
35562306a36Sopenharmony_ci			bool untagged);
35662306a36Sopenharmony_ciint sparx5_vlan_vid_del(struct sparx5_port *port, u16 vid);
35762306a36Sopenharmony_civoid sparx5_vlan_port_apply(struct sparx5 *sparx5, struct sparx5_port *port);
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci/* sparx5_calendar.c */
36062306a36Sopenharmony_ciint sparx5_config_auto_calendar(struct sparx5 *sparx5);
36162306a36Sopenharmony_ciint sparx5_config_dsm_calendar(struct sparx5 *sparx5);
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci/* sparx5_ethtool.c */
36462306a36Sopenharmony_civoid sparx5_get_stats64(struct net_device *ndev, struct rtnl_link_stats64 *stats);
36562306a36Sopenharmony_ciint sparx_stats_init(struct sparx5 *sparx5);
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ci/* sparx5_dcb.c */
36862306a36Sopenharmony_ci#ifdef CONFIG_SPARX5_DCB
36962306a36Sopenharmony_ciint sparx5_dcb_init(struct sparx5 *sparx5);
37062306a36Sopenharmony_ci#else
37162306a36Sopenharmony_cistatic inline int sparx5_dcb_init(struct sparx5 *sparx5)
37262306a36Sopenharmony_ci{
37362306a36Sopenharmony_ci	return 0;
37462306a36Sopenharmony_ci}
37562306a36Sopenharmony_ci#endif
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_ci/* sparx5_netdev.c */
37862306a36Sopenharmony_civoid sparx5_set_port_ifh_timestamp(void *ifh_hdr, u64 timestamp);
37962306a36Sopenharmony_civoid sparx5_set_port_ifh_rew_op(void *ifh_hdr, u32 rew_op);
38062306a36Sopenharmony_civoid sparx5_set_port_ifh_pdu_type(void *ifh_hdr, u32 pdu_type);
38162306a36Sopenharmony_civoid sparx5_set_port_ifh_pdu_w16_offset(void *ifh_hdr, u32 pdu_w16_offset);
38262306a36Sopenharmony_civoid sparx5_set_port_ifh(void *ifh_hdr, u16 portno);
38362306a36Sopenharmony_cibool sparx5_netdevice_check(const struct net_device *dev);
38462306a36Sopenharmony_cistruct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno);
38562306a36Sopenharmony_ciint sparx5_register_netdevs(struct sparx5 *sparx5);
38662306a36Sopenharmony_civoid sparx5_destroy_netdevs(struct sparx5 *sparx5);
38762306a36Sopenharmony_civoid sparx5_unregister_netdevs(struct sparx5 *sparx5);
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_ci/* sparx5_ptp.c */
39062306a36Sopenharmony_ciint sparx5_ptp_init(struct sparx5 *sparx5);
39162306a36Sopenharmony_civoid sparx5_ptp_deinit(struct sparx5 *sparx5);
39262306a36Sopenharmony_ciint sparx5_ptp_hwtstamp_set(struct sparx5_port *port,
39362306a36Sopenharmony_ci			    struct kernel_hwtstamp_config *cfg,
39462306a36Sopenharmony_ci			    struct netlink_ext_ack *extack);
39562306a36Sopenharmony_civoid sparx5_ptp_hwtstamp_get(struct sparx5_port *port,
39662306a36Sopenharmony_ci			     struct kernel_hwtstamp_config *cfg);
39762306a36Sopenharmony_civoid sparx5_ptp_rxtstamp(struct sparx5 *sparx5, struct sk_buff *skb,
39862306a36Sopenharmony_ci			 u64 timestamp);
39962306a36Sopenharmony_ciint sparx5_ptp_txtstamp_request(struct sparx5_port *port,
40062306a36Sopenharmony_ci				struct sk_buff *skb);
40162306a36Sopenharmony_civoid sparx5_ptp_txtstamp_release(struct sparx5_port *port,
40262306a36Sopenharmony_ci				 struct sk_buff *skb);
40362306a36Sopenharmony_ciirqreturn_t sparx5_ptp_irq_handler(int irq, void *args);
40462306a36Sopenharmony_ciint sparx5_ptp_gettime64(struct ptp_clock_info *ptp, struct timespec64 *ts);
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci/* sparx5_vcap_impl.c */
40762306a36Sopenharmony_ciint sparx5_vcap_init(struct sparx5 *sparx5);
40862306a36Sopenharmony_civoid sparx5_vcap_destroy(struct sparx5 *sparx5);
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci/* sparx5_pgid.c */
41162306a36Sopenharmony_cienum sparx5_pgid_type {
41262306a36Sopenharmony_ci	SPX5_PGID_FREE,
41362306a36Sopenharmony_ci	SPX5_PGID_RESERVED,
41462306a36Sopenharmony_ci	SPX5_PGID_MULTICAST,
41562306a36Sopenharmony_ci};
41662306a36Sopenharmony_ci
41762306a36Sopenharmony_civoid sparx5_pgid_init(struct sparx5 *spx5);
41862306a36Sopenharmony_ciint sparx5_pgid_alloc_mcast(struct sparx5 *spx5, u16 *idx);
41962306a36Sopenharmony_ciint sparx5_pgid_free(struct sparx5 *spx5, u16 idx);
42062306a36Sopenharmony_ci
42162306a36Sopenharmony_ci/* sparx5_pool.c */
42262306a36Sopenharmony_cistruct sparx5_pool_entry {
42362306a36Sopenharmony_ci	u16 ref_cnt;
42462306a36Sopenharmony_ci	u32 idx; /* tc index */
42562306a36Sopenharmony_ci};
42662306a36Sopenharmony_ci
42762306a36Sopenharmony_ciu32 sparx5_pool_idx_to_id(u32 idx);
42862306a36Sopenharmony_ciint sparx5_pool_put(struct sparx5_pool_entry *pool, int size, u32 id);
42962306a36Sopenharmony_ciint sparx5_pool_get(struct sparx5_pool_entry *pool, int size, u32 *id);
43062306a36Sopenharmony_ciint sparx5_pool_get_with_idx(struct sparx5_pool_entry *pool, int size, u32 idx,
43162306a36Sopenharmony_ci			     u32 *id);
43262306a36Sopenharmony_ci
43362306a36Sopenharmony_ci/* sparx5_sdlb.c */
43462306a36Sopenharmony_ci#define SPX5_SDLB_PUP_TOKEN_DISABLE 0x1FFF
43562306a36Sopenharmony_ci#define SPX5_SDLB_PUP_TOKEN_MAX (SPX5_SDLB_PUP_TOKEN_DISABLE - 1)
43662306a36Sopenharmony_ci#define SPX5_SDLB_GROUP_RATE_MAX 25000000000ULL
43762306a36Sopenharmony_ci#define SPX5_SDLB_2CYCLES_TYPE2_THRES_OFFSET 13
43862306a36Sopenharmony_ci#define SPX5_SDLB_CNT 4096
43962306a36Sopenharmony_ci#define SPX5_SDLB_GROUP_CNT 10
44062306a36Sopenharmony_ci#define SPX5_CLK_PER_100PS_DEFAULT 16
44162306a36Sopenharmony_ci
44262306a36Sopenharmony_cistruct sparx5_sdlb_group {
44362306a36Sopenharmony_ci	u64 max_rate;
44462306a36Sopenharmony_ci	u32 min_burst;
44562306a36Sopenharmony_ci	u32 frame_size;
44662306a36Sopenharmony_ci	u32 pup_interval;
44762306a36Sopenharmony_ci	u32 nsets;
44862306a36Sopenharmony_ci};
44962306a36Sopenharmony_ci
45062306a36Sopenharmony_ciextern struct sparx5_sdlb_group sdlb_groups[SPX5_SDLB_GROUP_CNT];
45162306a36Sopenharmony_ciint sparx5_sdlb_pup_token_get(struct sparx5 *sparx5, u32 pup_interval,
45262306a36Sopenharmony_ci			      u64 rate);
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_ciint sparx5_sdlb_clk_hz_get(struct sparx5 *sparx5);
45562306a36Sopenharmony_ciint sparx5_sdlb_group_get_by_rate(struct sparx5 *sparx5, u32 rate, u32 burst);
45662306a36Sopenharmony_ciint sparx5_sdlb_group_get_by_index(struct sparx5 *sparx5, u32 idx, u32 *group);
45762306a36Sopenharmony_ci
45862306a36Sopenharmony_ciint sparx5_sdlb_group_add(struct sparx5 *sparx5, u32 group, u32 idx);
45962306a36Sopenharmony_ciint sparx5_sdlb_group_del(struct sparx5 *sparx5, u32 group, u32 idx);
46062306a36Sopenharmony_ci
46162306a36Sopenharmony_civoid sparx5_sdlb_group_init(struct sparx5 *sparx5, u64 max_rate, u32 min_burst,
46262306a36Sopenharmony_ci			    u32 frame_size, u32 idx);
46362306a36Sopenharmony_ci
46462306a36Sopenharmony_ci/* sparx5_police.c */
46562306a36Sopenharmony_cienum {
46662306a36Sopenharmony_ci	/* More policer types will be added later */
46762306a36Sopenharmony_ci	SPX5_POL_SERVICE
46862306a36Sopenharmony_ci};
46962306a36Sopenharmony_ci
47062306a36Sopenharmony_cistruct sparx5_policer {
47162306a36Sopenharmony_ci	u32 type;
47262306a36Sopenharmony_ci	u32 idx;
47362306a36Sopenharmony_ci	u64 rate;
47462306a36Sopenharmony_ci	u32 burst;
47562306a36Sopenharmony_ci	u32 group;
47662306a36Sopenharmony_ci	u8 event_mask;
47762306a36Sopenharmony_ci};
47862306a36Sopenharmony_ci
47962306a36Sopenharmony_ciint sparx5_policer_conf_set(struct sparx5 *sparx5, struct sparx5_policer *pol);
48062306a36Sopenharmony_ci
48162306a36Sopenharmony_ci/* sparx5_psfp.c */
48262306a36Sopenharmony_ci#define SPX5_PSFP_GCE_CNT 4
48362306a36Sopenharmony_ci#define SPX5_PSFP_SG_CNT 1024
48462306a36Sopenharmony_ci#define SPX5_PSFP_SG_MIN_CYCLE_TIME_NS (1 * NSEC_PER_USEC)
48562306a36Sopenharmony_ci#define SPX5_PSFP_SG_MAX_CYCLE_TIME_NS ((1 * NSEC_PER_SEC) - 1)
48662306a36Sopenharmony_ci#define SPX5_PSFP_SG_MAX_IPV (SPX5_PRIOS - 1)
48762306a36Sopenharmony_ci#define SPX5_PSFP_SG_OPEN (SPX5_PSFP_SG_CNT - 1)
48862306a36Sopenharmony_ci#define SPX5_PSFP_SG_CYCLE_TIME_DEFAULT 1000000
48962306a36Sopenharmony_ci#define SPX5_PSFP_SF_MAX_SDU 16383
49062306a36Sopenharmony_ci
49162306a36Sopenharmony_cistruct sparx5_psfp_fm {
49262306a36Sopenharmony_ci	struct sparx5_policer pol;
49362306a36Sopenharmony_ci};
49462306a36Sopenharmony_ci
49562306a36Sopenharmony_cistruct sparx5_psfp_gce {
49662306a36Sopenharmony_ci	bool gate_state;            /* StreamGateState */
49762306a36Sopenharmony_ci	u32 interval;               /* TimeInterval */
49862306a36Sopenharmony_ci	u32 ipv;                    /* InternalPriorityValue */
49962306a36Sopenharmony_ci	u32 maxoctets;              /* IntervalOctetMax */
50062306a36Sopenharmony_ci};
50162306a36Sopenharmony_ci
50262306a36Sopenharmony_cistruct sparx5_psfp_sg {
50362306a36Sopenharmony_ci	bool gate_state;            /* PSFPAdminGateStates */
50462306a36Sopenharmony_ci	bool gate_enabled;          /* PSFPGateEnabled */
50562306a36Sopenharmony_ci	u32 ipv;                    /* PSFPAdminIPV */
50662306a36Sopenharmony_ci	struct timespec64 basetime; /* PSFPAdminBaseTime */
50762306a36Sopenharmony_ci	u32 cycletime;              /* PSFPAdminCycleTime */
50862306a36Sopenharmony_ci	u32 cycletimeext;           /* PSFPAdminCycleTimeExtension */
50962306a36Sopenharmony_ci	u32 num_entries;            /* PSFPAdminControlListLength */
51062306a36Sopenharmony_ci	struct sparx5_psfp_gce gce[SPX5_PSFP_GCE_CNT];
51162306a36Sopenharmony_ci};
51262306a36Sopenharmony_ci
51362306a36Sopenharmony_cistruct sparx5_psfp_sf {
51462306a36Sopenharmony_ci	bool sblock_osize_ena;
51562306a36Sopenharmony_ci	bool sblock_osize;
51662306a36Sopenharmony_ci	u32 max_sdu;
51762306a36Sopenharmony_ci	u32 sgid; /* Gate id */
51862306a36Sopenharmony_ci	u32 fmid; /* Flow meter id */
51962306a36Sopenharmony_ci};
52062306a36Sopenharmony_ci
52162306a36Sopenharmony_ciint sparx5_psfp_fm_add(struct sparx5 *sparx5, u32 uidx,
52262306a36Sopenharmony_ci		       struct sparx5_psfp_fm *fm, u32 *id);
52362306a36Sopenharmony_ciint sparx5_psfp_fm_del(struct sparx5 *sparx5, u32 id);
52462306a36Sopenharmony_ci
52562306a36Sopenharmony_ciint sparx5_psfp_sg_add(struct sparx5 *sparx5, u32 uidx,
52662306a36Sopenharmony_ci		       struct sparx5_psfp_sg *sg, u32 *id);
52762306a36Sopenharmony_ciint sparx5_psfp_sg_del(struct sparx5 *sparx5, u32 id);
52862306a36Sopenharmony_ci
52962306a36Sopenharmony_ciint sparx5_psfp_sf_add(struct sparx5 *sparx5, const struct sparx5_psfp_sf *sf,
53062306a36Sopenharmony_ci		       u32 *id);
53162306a36Sopenharmony_ciint sparx5_psfp_sf_del(struct sparx5 *sparx5, u32 id);
53262306a36Sopenharmony_ci
53362306a36Sopenharmony_ciu32 sparx5_psfp_isdx_get_sf(struct sparx5 *sparx5, u32 isdx);
53462306a36Sopenharmony_ciu32 sparx5_psfp_isdx_get_fm(struct sparx5 *sparx5, u32 isdx);
53562306a36Sopenharmony_ciu32 sparx5_psfp_sf_get_sg(struct sparx5 *sparx5, u32 sfid);
53662306a36Sopenharmony_civoid sparx5_isdx_conf_set(struct sparx5 *sparx5, u32 isdx, u32 sfid, u32 fmid);
53762306a36Sopenharmony_ci
53862306a36Sopenharmony_civoid sparx5_psfp_init(struct sparx5 *sparx5);
53962306a36Sopenharmony_ci
54062306a36Sopenharmony_ci/* sparx5_qos.c */
54162306a36Sopenharmony_civoid sparx5_new_base_time(struct sparx5 *sparx5, const u32 cycle_time,
54262306a36Sopenharmony_ci			  const ktime_t org_base_time, ktime_t *new_base_time);
54362306a36Sopenharmony_ci
54462306a36Sopenharmony_ci/* Clock period in picoseconds */
54562306a36Sopenharmony_cistatic inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
54662306a36Sopenharmony_ci{
54762306a36Sopenharmony_ci	switch (cclock) {
54862306a36Sopenharmony_ci	case SPX5_CORE_CLOCK_250MHZ:
54962306a36Sopenharmony_ci		return 4000;
55062306a36Sopenharmony_ci	case SPX5_CORE_CLOCK_500MHZ:
55162306a36Sopenharmony_ci		return 2000;
55262306a36Sopenharmony_ci	case SPX5_CORE_CLOCK_625MHZ:
55362306a36Sopenharmony_ci	default:
55462306a36Sopenharmony_ci		return 1600;
55562306a36Sopenharmony_ci	}
55662306a36Sopenharmony_ci}
55762306a36Sopenharmony_ci
55862306a36Sopenharmony_cistatic inline bool sparx5_is_baser(phy_interface_t interface)
55962306a36Sopenharmony_ci{
56062306a36Sopenharmony_ci	return interface == PHY_INTERFACE_MODE_5GBASER ||
56162306a36Sopenharmony_ci		   interface == PHY_INTERFACE_MODE_10GBASER ||
56262306a36Sopenharmony_ci		   interface == PHY_INTERFACE_MODE_25GBASER;
56362306a36Sopenharmony_ci}
56462306a36Sopenharmony_ci
56562306a36Sopenharmony_ciextern const struct phylink_mac_ops sparx5_phylink_mac_ops;
56662306a36Sopenharmony_ciextern const struct phylink_pcs_ops sparx5_phylink_pcs_ops;
56762306a36Sopenharmony_ciextern const struct ethtool_ops sparx5_ethtool_ops;
56862306a36Sopenharmony_ciextern const struct dcbnl_rtnl_ops sparx5_dcbnl_ops;
56962306a36Sopenharmony_ci
57062306a36Sopenharmony_ci/* Calculate raw offset */
57162306a36Sopenharmony_cistatic inline __pure int spx5_offset(int id, int tinst, int tcnt,
57262306a36Sopenharmony_ci				     int gbase, int ginst,
57362306a36Sopenharmony_ci				     int gcnt, int gwidth,
57462306a36Sopenharmony_ci				     int raddr, int rinst,
57562306a36Sopenharmony_ci				     int rcnt, int rwidth)
57662306a36Sopenharmony_ci{
57762306a36Sopenharmony_ci	WARN_ON((tinst) >= tcnt);
57862306a36Sopenharmony_ci	WARN_ON((ginst) >= gcnt);
57962306a36Sopenharmony_ci	WARN_ON((rinst) >= rcnt);
58062306a36Sopenharmony_ci	return gbase + ((ginst) * gwidth) +
58162306a36Sopenharmony_ci		raddr + ((rinst) * rwidth);
58262306a36Sopenharmony_ci}
58362306a36Sopenharmony_ci
58462306a36Sopenharmony_ci/* Read, Write and modify registers content.
58562306a36Sopenharmony_ci * The register definition macros start at the id
58662306a36Sopenharmony_ci */
58762306a36Sopenharmony_cistatic inline void __iomem *spx5_addr(void __iomem *base[],
58862306a36Sopenharmony_ci				      int id, int tinst, int tcnt,
58962306a36Sopenharmony_ci				      int gbase, int ginst,
59062306a36Sopenharmony_ci				      int gcnt, int gwidth,
59162306a36Sopenharmony_ci				      int raddr, int rinst,
59262306a36Sopenharmony_ci				      int rcnt, int rwidth)
59362306a36Sopenharmony_ci{
59462306a36Sopenharmony_ci	WARN_ON((tinst) >= tcnt);
59562306a36Sopenharmony_ci	WARN_ON((ginst) >= gcnt);
59662306a36Sopenharmony_ci	WARN_ON((rinst) >= rcnt);
59762306a36Sopenharmony_ci	return base[id + (tinst)] +
59862306a36Sopenharmony_ci		gbase + ((ginst) * gwidth) +
59962306a36Sopenharmony_ci		raddr + ((rinst) * rwidth);
60062306a36Sopenharmony_ci}
60162306a36Sopenharmony_ci
60262306a36Sopenharmony_cistatic inline void __iomem *spx5_inst_addr(void __iomem *base,
60362306a36Sopenharmony_ci					   int gbase, int ginst,
60462306a36Sopenharmony_ci					   int gcnt, int gwidth,
60562306a36Sopenharmony_ci					   int raddr, int rinst,
60662306a36Sopenharmony_ci					   int rcnt, int rwidth)
60762306a36Sopenharmony_ci{
60862306a36Sopenharmony_ci	WARN_ON((ginst) >= gcnt);
60962306a36Sopenharmony_ci	WARN_ON((rinst) >= rcnt);
61062306a36Sopenharmony_ci	return base +
61162306a36Sopenharmony_ci		gbase + ((ginst) * gwidth) +
61262306a36Sopenharmony_ci		raddr + ((rinst) * rwidth);
61362306a36Sopenharmony_ci}
61462306a36Sopenharmony_ci
61562306a36Sopenharmony_cistatic inline u32 spx5_rd(struct sparx5 *sparx5, int id, int tinst, int tcnt,
61662306a36Sopenharmony_ci			  int gbase, int ginst, int gcnt, int gwidth,
61762306a36Sopenharmony_ci			  int raddr, int rinst, int rcnt, int rwidth)
61862306a36Sopenharmony_ci{
61962306a36Sopenharmony_ci	return readl(spx5_addr(sparx5->regs, id, tinst, tcnt, gbase, ginst,
62062306a36Sopenharmony_ci			       gcnt, gwidth, raddr, rinst, rcnt, rwidth));
62162306a36Sopenharmony_ci}
62262306a36Sopenharmony_ci
62362306a36Sopenharmony_cistatic inline u32 spx5_inst_rd(void __iomem *iomem, int id, int tinst, int tcnt,
62462306a36Sopenharmony_ci			       int gbase, int ginst, int gcnt, int gwidth,
62562306a36Sopenharmony_ci			       int raddr, int rinst, int rcnt, int rwidth)
62662306a36Sopenharmony_ci{
62762306a36Sopenharmony_ci	return readl(spx5_inst_addr(iomem, gbase, ginst,
62862306a36Sopenharmony_ci				     gcnt, gwidth, raddr, rinst, rcnt, rwidth));
62962306a36Sopenharmony_ci}
63062306a36Sopenharmony_ci
63162306a36Sopenharmony_cistatic inline void spx5_wr(u32 val, struct sparx5 *sparx5,
63262306a36Sopenharmony_ci			   int id, int tinst, int tcnt,
63362306a36Sopenharmony_ci			   int gbase, int ginst, int gcnt, int gwidth,
63462306a36Sopenharmony_ci			   int raddr, int rinst, int rcnt, int rwidth)
63562306a36Sopenharmony_ci{
63662306a36Sopenharmony_ci	writel(val, spx5_addr(sparx5->regs, id, tinst, tcnt,
63762306a36Sopenharmony_ci			      gbase, ginst, gcnt, gwidth,
63862306a36Sopenharmony_ci			      raddr, rinst, rcnt, rwidth));
63962306a36Sopenharmony_ci}
64062306a36Sopenharmony_ci
64162306a36Sopenharmony_cistatic inline void spx5_inst_wr(u32 val, void __iomem *iomem,
64262306a36Sopenharmony_ci				int id, int tinst, int tcnt,
64362306a36Sopenharmony_ci				int gbase, int ginst, int gcnt, int gwidth,
64462306a36Sopenharmony_ci				int raddr, int rinst, int rcnt, int rwidth)
64562306a36Sopenharmony_ci{
64662306a36Sopenharmony_ci	writel(val, spx5_inst_addr(iomem,
64762306a36Sopenharmony_ci				   gbase, ginst, gcnt, gwidth,
64862306a36Sopenharmony_ci				   raddr, rinst, rcnt, rwidth));
64962306a36Sopenharmony_ci}
65062306a36Sopenharmony_ci
65162306a36Sopenharmony_cistatic inline void spx5_rmw(u32 val, u32 mask, struct sparx5 *sparx5,
65262306a36Sopenharmony_ci			    int id, int tinst, int tcnt,
65362306a36Sopenharmony_ci			    int gbase, int ginst, int gcnt, int gwidth,
65462306a36Sopenharmony_ci			    int raddr, int rinst, int rcnt, int rwidth)
65562306a36Sopenharmony_ci{
65662306a36Sopenharmony_ci	u32 nval;
65762306a36Sopenharmony_ci
65862306a36Sopenharmony_ci	nval = readl(spx5_addr(sparx5->regs, id, tinst, tcnt, gbase, ginst,
65962306a36Sopenharmony_ci			       gcnt, gwidth, raddr, rinst, rcnt, rwidth));
66062306a36Sopenharmony_ci	nval = (nval & ~mask) | (val & mask);
66162306a36Sopenharmony_ci	writel(nval, spx5_addr(sparx5->regs, id, tinst, tcnt, gbase, ginst,
66262306a36Sopenharmony_ci			       gcnt, gwidth, raddr, rinst, rcnt, rwidth));
66362306a36Sopenharmony_ci}
66462306a36Sopenharmony_ci
66562306a36Sopenharmony_cistatic inline void spx5_inst_rmw(u32 val, u32 mask, void __iomem *iomem,
66662306a36Sopenharmony_ci				 int id, int tinst, int tcnt,
66762306a36Sopenharmony_ci				 int gbase, int ginst, int gcnt, int gwidth,
66862306a36Sopenharmony_ci				 int raddr, int rinst, int rcnt, int rwidth)
66962306a36Sopenharmony_ci{
67062306a36Sopenharmony_ci	u32 nval;
67162306a36Sopenharmony_ci
67262306a36Sopenharmony_ci	nval = readl(spx5_inst_addr(iomem, gbase, ginst, gcnt, gwidth, raddr,
67362306a36Sopenharmony_ci				    rinst, rcnt, rwidth));
67462306a36Sopenharmony_ci	nval = (nval & ~mask) | (val & mask);
67562306a36Sopenharmony_ci	writel(nval, spx5_inst_addr(iomem, gbase, ginst, gcnt, gwidth, raddr,
67662306a36Sopenharmony_ci				    rinst, rcnt, rwidth));
67762306a36Sopenharmony_ci}
67862306a36Sopenharmony_ci
67962306a36Sopenharmony_cistatic inline void __iomem *spx5_inst_get(struct sparx5 *sparx5, int id, int tinst)
68062306a36Sopenharmony_ci{
68162306a36Sopenharmony_ci	return sparx5->regs[id + tinst];
68262306a36Sopenharmony_ci}
68362306a36Sopenharmony_ci
68462306a36Sopenharmony_cistatic inline void __iomem *spx5_reg_get(struct sparx5 *sparx5,
68562306a36Sopenharmony_ci					 int id, int tinst, int tcnt,
68662306a36Sopenharmony_ci					 int gbase, int ginst, int gcnt, int gwidth,
68762306a36Sopenharmony_ci					 int raddr, int rinst, int rcnt, int rwidth)
68862306a36Sopenharmony_ci{
68962306a36Sopenharmony_ci	return spx5_addr(sparx5->regs, id, tinst, tcnt,
69062306a36Sopenharmony_ci			 gbase, ginst, gcnt, gwidth,
69162306a36Sopenharmony_ci			 raddr, rinst, rcnt, rwidth);
69262306a36Sopenharmony_ci}
69362306a36Sopenharmony_ci
69462306a36Sopenharmony_ci#endif	/* __SPARX5_MAIN_H__ */
695