162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/* Marvell OcteonTx2 CGX driver
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 2018 Marvell.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef CGX_H
962306a36Sopenharmony_ci#define CGX_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include "mbox.h"
1262306a36Sopenharmony_ci#include "cgx_fw_if.h"
1362306a36Sopenharmony_ci#include "rpm.h"
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci /* PCI device IDs */
1662306a36Sopenharmony_ci#define	PCI_DEVID_OCTEONTX2_CGX		0xA059
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/* PCI BAR nos */
1962306a36Sopenharmony_ci#define PCI_CFG_REG_BAR_NUM		0
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#define CGX_ID_MASK			0xF
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/* Registers */
2462306a36Sopenharmony_ci#define CGXX_CMRX_CFG			0x00
2562306a36Sopenharmony_ci#define CMR_P2X_SEL_MASK		GENMASK_ULL(61, 59)
2662306a36Sopenharmony_ci#define CMR_P2X_SEL_SHIFT		59ULL
2762306a36Sopenharmony_ci#define CMR_P2X_SEL_NIX0		1ULL
2862306a36Sopenharmony_ci#define CMR_P2X_SEL_NIX1		2ULL
2962306a36Sopenharmony_ci#define DATA_PKT_TX_EN			BIT_ULL(53)
3062306a36Sopenharmony_ci#define DATA_PKT_RX_EN			BIT_ULL(54)
3162306a36Sopenharmony_ci#define CGX_LMAC_TYPE_SHIFT		40
3262306a36Sopenharmony_ci#define CGX_LMAC_TYPE_MASK		0xF
3362306a36Sopenharmony_ci#define CGXX_CMRX_INT			0x040
3462306a36Sopenharmony_ci#define FW_CGX_INT			BIT_ULL(1)
3562306a36Sopenharmony_ci#define CGXX_CMRX_INT_ENA_W1S		0x058
3662306a36Sopenharmony_ci#define CGXX_CMRX_RX_ID_MAP		0x060
3762306a36Sopenharmony_ci#define CGXX_CMRX_RX_STAT0		0x070
3862306a36Sopenharmony_ci#define CGXX_CMRX_RX_LOGL_XON		0x100
3962306a36Sopenharmony_ci#define CGXX_CMRX_RX_LMACS		0x128
4062306a36Sopenharmony_ci#define CGXX_CMRX_RX_DMAC_CTL0		(0x1F8 + mac_ops->csr_offset)
4162306a36Sopenharmony_ci#define CGX_DMAC_CTL0_CAM_ENABLE	BIT_ULL(3)
4262306a36Sopenharmony_ci#define CGX_DMAC_CAM_ACCEPT		BIT_ULL(3)
4362306a36Sopenharmony_ci#define CGX_DMAC_MCAST_MODE_CAM		BIT_ULL(2)
4462306a36Sopenharmony_ci#define CGX_DMAC_MCAST_MODE		BIT_ULL(1)
4562306a36Sopenharmony_ci#define CGX_DMAC_BCAST_MODE		BIT_ULL(0)
4662306a36Sopenharmony_ci#define CGXX_CMRX_RX_DMAC_CAM0		(0x200 + mac_ops->csr_offset)
4762306a36Sopenharmony_ci#define CGX_DMAC_CAM_ADDR_ENABLE	BIT_ULL(48)
4862306a36Sopenharmony_ci#define CGX_DMAC_CAM_ENTRY_LMACID	GENMASK_ULL(50, 49)
4962306a36Sopenharmony_ci#define CGXX_CMRX_RX_DMAC_CAM1		0x400
5062306a36Sopenharmony_ci#define CGX_RX_DMAC_ADR_MASK		GENMASK_ULL(47, 0)
5162306a36Sopenharmony_ci#define CGXX_CMRX_TX_STAT0		0x700
5262306a36Sopenharmony_ci#define CGXX_SCRATCH0_REG		0x1050
5362306a36Sopenharmony_ci#define CGXX_SCRATCH1_REG		0x1058
5462306a36Sopenharmony_ci#define CGX_CONST			0x2000
5562306a36Sopenharmony_ci#define CGX_CONST_RXFIFO_SIZE	        GENMASK_ULL(55, 32)
5662306a36Sopenharmony_ci#define CGX_CONST_MAX_LMACS	        GENMASK_ULL(31, 24)
5762306a36Sopenharmony_ci#define CGXX_SPUX_CONTROL1		0x10000
5862306a36Sopenharmony_ci#define CGXX_SPUX_LNX_FEC_CORR_BLOCKS	0x10700
5962306a36Sopenharmony_ci#define CGXX_SPUX_LNX_FEC_UNCORR_BLOCKS	0x10800
6062306a36Sopenharmony_ci#define CGXX_SPUX_RSFEC_CORR		0x10088
6162306a36Sopenharmony_ci#define CGXX_SPUX_RSFEC_UNCORR		0x10090
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define CGXX_SPUX_CONTROL1_LBK		BIT_ULL(14)
6462306a36Sopenharmony_ci#define CGXX_GMP_PCS_MRX_CTL		0x30000
6562306a36Sopenharmony_ci#define CGXX_GMP_PCS_MRX_CTL_LBK	BIT_ULL(14)
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#define CGXX_SMUX_RX_FRM_CTL		0x20020
6862306a36Sopenharmony_ci#define CGX_SMUX_RX_FRM_CTL_CTL_BCK	BIT_ULL(3)
6962306a36Sopenharmony_ci#define CGX_SMUX_RX_FRM_CTL_PTP_MODE	BIT_ULL(12)
7062306a36Sopenharmony_ci#define CGXX_GMP_GMI_RXX_FRM_CTL	0x38028
7162306a36Sopenharmony_ci#define CGX_GMP_GMI_RXX_FRM_CTL_CTL_BCK	BIT_ULL(3)
7262306a36Sopenharmony_ci#define CGX_GMP_GMI_RXX_FRM_CTL_PTP_MODE BIT_ULL(12)
7362306a36Sopenharmony_ci#define CGXX_SMUX_TX_CTL		0x20178
7462306a36Sopenharmony_ci#define CGXX_SMUX_TX_PAUSE_PKT_TIME	0x20110
7562306a36Sopenharmony_ci#define CGXX_SMUX_TX_PAUSE_PKT_INTERVAL	0x20120
7662306a36Sopenharmony_ci#define CGXX_SMUX_SMAC                        0x20108
7762306a36Sopenharmony_ci#define CGXX_SMUX_CBFC_CTL                    0x20218
7862306a36Sopenharmony_ci#define CGXX_SMUX_CBFC_CTL_RX_EN             BIT_ULL(0)
7962306a36Sopenharmony_ci#define CGXX_SMUX_CBFC_CTL_TX_EN             BIT_ULL(1)
8062306a36Sopenharmony_ci#define CGXX_SMUX_CBFC_CTL_DRP_EN            BIT_ULL(2)
8162306a36Sopenharmony_ci#define CGXX_SMUX_CBFC_CTL_BCK_EN            BIT_ULL(3)
8262306a36Sopenharmony_ci#define CGX_PFC_CLASS_MASK		     GENMASK_ULL(47, 32)
8362306a36Sopenharmony_ci#define CGXX_GMP_GMI_TX_PAUSE_PKT_TIME	0x38230
8462306a36Sopenharmony_ci#define CGXX_GMP_GMI_TX_PAUSE_PKT_INTERVAL	0x38248
8562306a36Sopenharmony_ci#define CGX_SMUX_TX_CTL_L2P_BP_CONV	BIT_ULL(7)
8662306a36Sopenharmony_ci#define CGXX_CMR_RX_OVR_BP		0x130
8762306a36Sopenharmony_ci#define CGX_CMR_RX_OVR_BP_EN(X)		BIT_ULL(((X) + 8))
8862306a36Sopenharmony_ci#define CGX_CMR_RX_OVR_BP_BP(X)		BIT_ULL(((X) + 4))
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci#define CGX_COMMAND_REG			CGXX_SCRATCH1_REG
9162306a36Sopenharmony_ci#define CGX_EVENT_REG			CGXX_SCRATCH0_REG
9262306a36Sopenharmony_ci#define CGX_CMD_TIMEOUT			5000 /* msecs */
9362306a36Sopenharmony_ci#define DEFAULT_PAUSE_TIME		0x7FF
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci#define CGX_LMAC_FWI			0
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_cienum  cgx_nix_stat_type {
9862306a36Sopenharmony_ci	NIX_STATS_RX,
9962306a36Sopenharmony_ci	NIX_STATS_TX,
10062306a36Sopenharmony_ci};
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_cienum LMAC_TYPE {
10362306a36Sopenharmony_ci	LMAC_MODE_SGMII		= 0,
10462306a36Sopenharmony_ci	LMAC_MODE_XAUI		= 1,
10562306a36Sopenharmony_ci	LMAC_MODE_RXAUI		= 2,
10662306a36Sopenharmony_ci	LMAC_MODE_10G_R		= 3,
10762306a36Sopenharmony_ci	LMAC_MODE_40G_R		= 4,
10862306a36Sopenharmony_ci	LMAC_MODE_QSGMII	= 6,
10962306a36Sopenharmony_ci	LMAC_MODE_25G_R		= 7,
11062306a36Sopenharmony_ci	LMAC_MODE_50G_R		= 8,
11162306a36Sopenharmony_ci	LMAC_MODE_100G_R	= 9,
11262306a36Sopenharmony_ci	LMAC_MODE_USXGMII	= 10,
11362306a36Sopenharmony_ci	LMAC_MODE_USGMII	= 11,
11462306a36Sopenharmony_ci	LMAC_MODE_MAX,
11562306a36Sopenharmony_ci};
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_cistruct cgx_link_event {
11862306a36Sopenharmony_ci	struct cgx_link_user_info link_uinfo;
11962306a36Sopenharmony_ci	u8 cgx_id;
12062306a36Sopenharmony_ci	u8 lmac_id;
12162306a36Sopenharmony_ci};
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci/**
12462306a36Sopenharmony_ci * struct cgx_event_cb
12562306a36Sopenharmony_ci * @notify_link_chg:	callback for link change notification
12662306a36Sopenharmony_ci * @data:	data passed to callback function
12762306a36Sopenharmony_ci */
12862306a36Sopenharmony_cistruct cgx_event_cb {
12962306a36Sopenharmony_ci	int (*notify_link_chg)(struct cgx_link_event *event, void *data);
13062306a36Sopenharmony_ci	void *data;
13162306a36Sopenharmony_ci};
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ciextern struct pci_driver cgx_driver;
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ciint cgx_get_cgxcnt_max(void);
13662306a36Sopenharmony_ciint cgx_get_cgxid(void *cgxd);
13762306a36Sopenharmony_ciint cgx_get_lmac_cnt(void *cgxd);
13862306a36Sopenharmony_civoid *cgx_get_pdata(int cgx_id);
13962306a36Sopenharmony_ciint cgx_set_pkind(void *cgxd, u8 lmac_id, int pkind);
14062306a36Sopenharmony_ciint cgx_lmac_evh_register(struct cgx_event_cb *cb, void *cgxd, int lmac_id);
14162306a36Sopenharmony_ciint cgx_lmac_evh_unregister(void *cgxd, int lmac_id);
14262306a36Sopenharmony_ciint cgx_get_tx_stats(void *cgxd, int lmac_id, int idx, u64 *tx_stat);
14362306a36Sopenharmony_ciint cgx_get_rx_stats(void *cgxd, int lmac_id, int idx, u64 *rx_stat);
14462306a36Sopenharmony_ciint cgx_lmac_rx_tx_enable(void *cgxd, int lmac_id, bool enable);
14562306a36Sopenharmony_ciint cgx_lmac_tx_enable(void *cgxd, int lmac_id, bool enable);
14662306a36Sopenharmony_ciint cgx_lmac_addr_set(u8 cgx_id, u8 lmac_id, u8 *mac_addr);
14762306a36Sopenharmony_ciint cgx_lmac_addr_reset(u8 cgx_id, u8 lmac_id);
14862306a36Sopenharmony_ciu64 cgx_lmac_addr_get(u8 cgx_id, u8 lmac_id);
14962306a36Sopenharmony_ciint cgx_lmac_addr_add(u8 cgx_id, u8 lmac_id, u8 *mac_addr);
15062306a36Sopenharmony_ciint cgx_lmac_addr_del(u8 cgx_id, u8 lmac_id, u8 index);
15162306a36Sopenharmony_ciint cgx_lmac_addr_max_entries_get(u8 cgx_id, u8 lmac_id);
15262306a36Sopenharmony_civoid cgx_lmac_promisc_config(int cgx_id, int lmac_id, bool enable);
15362306a36Sopenharmony_civoid cgx_lmac_enadis_rx_pause_fwding(void *cgxd, int lmac_id, bool enable);
15462306a36Sopenharmony_ciint cgx_lmac_internal_loopback(void *cgxd, int lmac_id, bool enable);
15562306a36Sopenharmony_ciint cgx_get_link_info(void *cgxd, int lmac_id,
15662306a36Sopenharmony_ci		      struct cgx_link_user_info *linfo);
15762306a36Sopenharmony_ciint cgx_lmac_linkup_start(void *cgxd);
15862306a36Sopenharmony_ciint cgx_get_fwdata_base(u64 *base);
15962306a36Sopenharmony_ciint cgx_lmac_get_pause_frm(void *cgxd, int lmac_id,
16062306a36Sopenharmony_ci			   u8 *tx_pause, u8 *rx_pause);
16162306a36Sopenharmony_ciint cgx_lmac_set_pause_frm(void *cgxd, int lmac_id,
16262306a36Sopenharmony_ci			   u8 tx_pause, u8 rx_pause);
16362306a36Sopenharmony_civoid cgx_lmac_ptp_config(void *cgxd, int lmac_id, bool enable);
16462306a36Sopenharmony_ciu8 cgx_lmac_get_p2x(int cgx_id, int lmac_id);
16562306a36Sopenharmony_ciint cgx_set_fec(u64 fec, int cgx_id, int lmac_id);
16662306a36Sopenharmony_ciint cgx_get_fec_stats(void *cgxd, int lmac_id, struct cgx_fec_stats_rsp *rsp);
16762306a36Sopenharmony_ciint cgx_get_phy_fec_stats(void *cgxd, int lmac_id);
16862306a36Sopenharmony_ciint cgx_set_link_mode(void *cgxd, struct cgx_set_link_mode_args args,
16962306a36Sopenharmony_ci		      int cgx_id, int lmac_id);
17062306a36Sopenharmony_ciu64 cgx_features_get(void *cgxd);
17162306a36Sopenharmony_cistruct mac_ops *get_mac_ops(void *cgxd);
17262306a36Sopenharmony_ciint cgx_get_nr_lmacs(void *cgxd);
17362306a36Sopenharmony_ciu8 cgx_get_lmacid(void *cgxd, u8 lmac_index);
17462306a36Sopenharmony_ciunsigned long cgx_get_lmac_bmap(void *cgxd);
17562306a36Sopenharmony_civoid cgx_lmac_write(int cgx_id, int lmac_id, u64 offset, u64 val);
17662306a36Sopenharmony_ciu64 cgx_lmac_read(int cgx_id, int lmac_id, u64 offset);
17762306a36Sopenharmony_ciint cgx_lmac_addr_update(u8 cgx_id, u8 lmac_id, u8 *mac_addr, u8 index);
17862306a36Sopenharmony_ciu64 cgx_read_dmac_ctrl(void *cgxd, int lmac_id);
17962306a36Sopenharmony_ciu64 cgx_read_dmac_entry(void *cgxd, int index);
18062306a36Sopenharmony_ciint cgx_lmac_pfc_config(void *cgxd, int lmac_id, u8 tx_pause, u8 rx_pause,
18162306a36Sopenharmony_ci			u16 pfc_en);
18262306a36Sopenharmony_ciint cgx_lmac_get_pfc_frm_cfg(void *cgxd, int lmac_id, u8 *tx_pause,
18362306a36Sopenharmony_ci			     u8 *rx_pause);
18462306a36Sopenharmony_ciint verify_lmac_fc_cfg(void *cgxd, int lmac_id, u8 tx_pause, u8 rx_pause,
18562306a36Sopenharmony_ci		       int pfvf_idx);
18662306a36Sopenharmony_ciint cgx_lmac_reset(void *cgxd, int lmac_id, u8 pf_req_flr);
18762306a36Sopenharmony_ci#endif /* CGX_H */
188