18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*  Marvell OcteonTx2 RVU Admin Function driver
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2018 Marvell International Ltd.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
78c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License version 2 as
88c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef COMMON_H
128c2ecf20Sopenharmony_ci#define COMMON_H
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include "rvu_struct.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#define OTX2_ALIGN			128  /* Align to cacheline */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define Q_SIZE_16		0ULL /* 16 entries */
198c2ecf20Sopenharmony_ci#define Q_SIZE_64		1ULL /* 64 entries */
208c2ecf20Sopenharmony_ci#define Q_SIZE_256		2ULL
218c2ecf20Sopenharmony_ci#define Q_SIZE_1K		3ULL
228c2ecf20Sopenharmony_ci#define Q_SIZE_4K		4ULL
238c2ecf20Sopenharmony_ci#define Q_SIZE_16K		5ULL
248c2ecf20Sopenharmony_ci#define Q_SIZE_64K		6ULL
258c2ecf20Sopenharmony_ci#define Q_SIZE_256K		7ULL
268c2ecf20Sopenharmony_ci#define Q_SIZE_1M		8ULL /* Million entries */
278c2ecf20Sopenharmony_ci#define Q_SIZE_MIN		Q_SIZE_16
288c2ecf20Sopenharmony_ci#define Q_SIZE_MAX		Q_SIZE_1M
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define Q_COUNT(x)		(16ULL << (2 * x))
318c2ecf20Sopenharmony_ci#define Q_SIZE(x, n)		((ilog2(x) - (n)) / 2)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/* Admin queue info */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/* Since we intend to add only one instruction at a time,
368c2ecf20Sopenharmony_ci * keep queue size to it's minimum.
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_ci#define AQ_SIZE			Q_SIZE_16
398c2ecf20Sopenharmony_ci/* HW head & tail pointer mask */
408c2ecf20Sopenharmony_ci#define AQ_PTR_MASK		0xFFFFF
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct qmem {
438c2ecf20Sopenharmony_ci	void            *base;
448c2ecf20Sopenharmony_ci	dma_addr_t	iova;
458c2ecf20Sopenharmony_ci	int		alloc_sz;
468c2ecf20Sopenharmony_ci	u16		entry_sz;
478c2ecf20Sopenharmony_ci	u8		align;
488c2ecf20Sopenharmony_ci	u32		qsize;
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic inline int qmem_alloc(struct device *dev, struct qmem **q,
528c2ecf20Sopenharmony_ci			     int qsize, int entry_sz)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	struct qmem *qmem;
558c2ecf20Sopenharmony_ci	int aligned_addr;
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	if (!qsize)
588c2ecf20Sopenharmony_ci		return -EINVAL;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	*q = devm_kzalloc(dev, sizeof(*qmem), GFP_KERNEL);
618c2ecf20Sopenharmony_ci	if (!*q)
628c2ecf20Sopenharmony_ci		return -ENOMEM;
638c2ecf20Sopenharmony_ci	qmem = *q;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	qmem->entry_sz = entry_sz;
668c2ecf20Sopenharmony_ci	qmem->alloc_sz = (qsize * entry_sz) + OTX2_ALIGN;
678c2ecf20Sopenharmony_ci	qmem->base = dma_alloc_coherent(dev, qmem->alloc_sz,
688c2ecf20Sopenharmony_ci					 &qmem->iova, GFP_KERNEL);
698c2ecf20Sopenharmony_ci	if (!qmem->base)
708c2ecf20Sopenharmony_ci		return -ENOMEM;
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	qmem->qsize = qsize;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	aligned_addr = ALIGN((u64)qmem->iova, OTX2_ALIGN);
758c2ecf20Sopenharmony_ci	qmem->align = (aligned_addr - qmem->iova);
768c2ecf20Sopenharmony_ci	qmem->base += qmem->align;
778c2ecf20Sopenharmony_ci	qmem->iova += qmem->align;
788c2ecf20Sopenharmony_ci	return 0;
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistatic inline void qmem_free(struct device *dev, struct qmem *qmem)
828c2ecf20Sopenharmony_ci{
838c2ecf20Sopenharmony_ci	if (!qmem)
848c2ecf20Sopenharmony_ci		return;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	if (qmem->base)
878c2ecf20Sopenharmony_ci		dma_free_coherent(dev, qmem->alloc_sz,
888c2ecf20Sopenharmony_ci				  qmem->base - qmem->align,
898c2ecf20Sopenharmony_ci				  qmem->iova - qmem->align);
908c2ecf20Sopenharmony_ci	devm_kfree(dev, qmem);
918c2ecf20Sopenharmony_ci}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistruct admin_queue {
948c2ecf20Sopenharmony_ci	struct qmem	*inst;
958c2ecf20Sopenharmony_ci	struct qmem	*res;
968c2ecf20Sopenharmony_ci	spinlock_t	lock; /* Serialize inst enqueue from PFs */
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci/* NPA aura count */
1008c2ecf20Sopenharmony_cienum npa_aura_sz {
1018c2ecf20Sopenharmony_ci	NPA_AURA_SZ_0,
1028c2ecf20Sopenharmony_ci	NPA_AURA_SZ_128,
1038c2ecf20Sopenharmony_ci	NPA_AURA_SZ_256,
1048c2ecf20Sopenharmony_ci	NPA_AURA_SZ_512,
1058c2ecf20Sopenharmony_ci	NPA_AURA_SZ_1K,
1068c2ecf20Sopenharmony_ci	NPA_AURA_SZ_2K,
1078c2ecf20Sopenharmony_ci	NPA_AURA_SZ_4K,
1088c2ecf20Sopenharmony_ci	NPA_AURA_SZ_8K,
1098c2ecf20Sopenharmony_ci	NPA_AURA_SZ_16K,
1108c2ecf20Sopenharmony_ci	NPA_AURA_SZ_32K,
1118c2ecf20Sopenharmony_ci	NPA_AURA_SZ_64K,
1128c2ecf20Sopenharmony_ci	NPA_AURA_SZ_128K,
1138c2ecf20Sopenharmony_ci	NPA_AURA_SZ_256K,
1148c2ecf20Sopenharmony_ci	NPA_AURA_SZ_512K,
1158c2ecf20Sopenharmony_ci	NPA_AURA_SZ_1M,
1168c2ecf20Sopenharmony_ci	NPA_AURA_SZ_MAX,
1178c2ecf20Sopenharmony_ci};
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci#define NPA_AURA_COUNT(x)	(1ULL << ((x) + 6))
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci/* NPA AQ result structure for init/read/write of aura HW contexts */
1228c2ecf20Sopenharmony_cistruct npa_aq_aura_res {
1238c2ecf20Sopenharmony_ci	struct	npa_aq_res_s	res;
1248c2ecf20Sopenharmony_ci	struct	npa_aura_s	aura_ctx;
1258c2ecf20Sopenharmony_ci	struct	npa_aura_s	ctx_mask;
1268c2ecf20Sopenharmony_ci};
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci/* NPA AQ result structure for init/read/write of pool HW contexts */
1298c2ecf20Sopenharmony_cistruct npa_aq_pool_res {
1308c2ecf20Sopenharmony_ci	struct	npa_aq_res_s	res;
1318c2ecf20Sopenharmony_ci	struct	npa_pool_s	pool_ctx;
1328c2ecf20Sopenharmony_ci	struct	npa_pool_s	ctx_mask;
1338c2ecf20Sopenharmony_ci};
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci/* NIX Transmit schedulers */
1368c2ecf20Sopenharmony_cienum nix_scheduler {
1378c2ecf20Sopenharmony_ci	NIX_TXSCH_LVL_SMQ = 0x0,
1388c2ecf20Sopenharmony_ci	NIX_TXSCH_LVL_MDQ = 0x0,
1398c2ecf20Sopenharmony_ci	NIX_TXSCH_LVL_TL4 = 0x1,
1408c2ecf20Sopenharmony_ci	NIX_TXSCH_LVL_TL3 = 0x2,
1418c2ecf20Sopenharmony_ci	NIX_TXSCH_LVL_TL2 = 0x3,
1428c2ecf20Sopenharmony_ci	NIX_TXSCH_LVL_TL1 = 0x4,
1438c2ecf20Sopenharmony_ci	NIX_TXSCH_LVL_CNT = 0x5,
1448c2ecf20Sopenharmony_ci};
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci#define TXSCH_RR_QTM_MAX		((1 << 24) - 1)
1478c2ecf20Sopenharmony_ci#define TXSCH_TL1_DFLT_RR_QTM		TXSCH_RR_QTM_MAX
1488c2ecf20Sopenharmony_ci#define TXSCH_TL1_DFLT_RR_PRIO		(0x1ull)
1498c2ecf20Sopenharmony_ci#define MAX_SCHED_WEIGHT		0xFF
1508c2ecf20Sopenharmony_ci#define DFLT_RR_WEIGHT			71
1518c2ecf20Sopenharmony_ci#define DFLT_RR_QTM	((DFLT_RR_WEIGHT * TXSCH_RR_QTM_MAX) \
1528c2ecf20Sopenharmony_ci			 / MAX_SCHED_WEIGHT)
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* Min/Max packet sizes, excluding FCS */
1558c2ecf20Sopenharmony_ci#define	NIC_HW_MIN_FRS			40
1568c2ecf20Sopenharmony_ci#define	NIC_HW_MAX_FRS			9212
1578c2ecf20Sopenharmony_ci#define	SDP_HW_MAX_FRS			65535
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci/* NIX RX action operation*/
1608c2ecf20Sopenharmony_ci#define NIX_RX_ACTIONOP_DROP		(0x0ull)
1618c2ecf20Sopenharmony_ci#define NIX_RX_ACTIONOP_UCAST		(0x1ull)
1628c2ecf20Sopenharmony_ci#define NIX_RX_ACTIONOP_UCAST_IPSEC	(0x2ull)
1638c2ecf20Sopenharmony_ci#define NIX_RX_ACTIONOP_MCAST		(0x3ull)
1648c2ecf20Sopenharmony_ci#define NIX_RX_ACTIONOP_RSS		(0x4ull)
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/* NIX TX action operation*/
1678c2ecf20Sopenharmony_ci#define NIX_TX_ACTIONOP_DROP		(0x0ull)
1688c2ecf20Sopenharmony_ci#define NIX_TX_ACTIONOP_UCAST_DEFAULT	(0x1ull)
1698c2ecf20Sopenharmony_ci#define NIX_TX_ACTIONOP_UCAST_CHAN	(0x2ull)
1708c2ecf20Sopenharmony_ci#define NIX_TX_ACTIONOP_MCAST		(0x3ull)
1718c2ecf20Sopenharmony_ci#define NIX_TX_ACTIONOP_DROP_VIOL	(0x5ull)
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#define NPC_MCAM_KEY_X1			0
1748c2ecf20Sopenharmony_ci#define NPC_MCAM_KEY_X2			1
1758c2ecf20Sopenharmony_ci#define NPC_MCAM_KEY_X4			2
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci#define NIX_INTF_RX			0
1788c2ecf20Sopenharmony_ci#define NIX_INTF_TX			1
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci#define NIX_INTF_TYPE_CGX		0
1818c2ecf20Sopenharmony_ci#define NIX_INTF_TYPE_LBK		1
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci#define MAX_LMAC_PKIND			12
1848c2ecf20Sopenharmony_ci#define NIX_LINK_CGX_LMAC(a, b)		(0 + 4 * (a) + (b))
1858c2ecf20Sopenharmony_ci#define NIX_LINK_LBK(a)			(12 + (a))
1868c2ecf20Sopenharmony_ci#define NIX_CHAN_CGX_LMAC_CHX(a, b, c)	(0x800 + 0x100 * (a) + 0x10 * (b) + (c))
1878c2ecf20Sopenharmony_ci#define NIX_CHAN_LBK_CHX(a, b)		(0 + 0x100 * (a) + (b))
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci/* NIX LSO format indices.
1908c2ecf20Sopenharmony_ci * As of now TSO is the only one using, so statically assigning indices.
1918c2ecf20Sopenharmony_ci */
1928c2ecf20Sopenharmony_ci#define NIX_LSO_FORMAT_IDX_TSOV4	0
1938c2ecf20Sopenharmony_ci#define NIX_LSO_FORMAT_IDX_TSOV6	1
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/* RSS info */
1968c2ecf20Sopenharmony_ci#define MAX_RSS_GROUPS			8
1978c2ecf20Sopenharmony_ci/* Group 0 has to be used in default pkt forwarding MCAM entries
1988c2ecf20Sopenharmony_ci * reserved for NIXLFs. Groups 1-7 can be used for RSS for ntuple
1998c2ecf20Sopenharmony_ci * filters.
2008c2ecf20Sopenharmony_ci */
2018c2ecf20Sopenharmony_ci#define DEFAULT_RSS_CONTEXT_GROUP	0
2028c2ecf20Sopenharmony_ci#define MAX_RSS_INDIR_TBL_SIZE		256 /* 1 << Max adder bits */
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/* NDC info */
2058c2ecf20Sopenharmony_cienum ndc_idx_e {
2068c2ecf20Sopenharmony_ci	NIX0_RX = 0x0,
2078c2ecf20Sopenharmony_ci	NIX0_TX = 0x1,
2088c2ecf20Sopenharmony_ci	NPA0_U  = 0x2,
2098c2ecf20Sopenharmony_ci};
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cienum ndc_ctype_e {
2128c2ecf20Sopenharmony_ci	CACHING = 0x0,
2138c2ecf20Sopenharmony_ci	BYPASS = 0x1,
2148c2ecf20Sopenharmony_ci};
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci#define NDC_MAX_PORT 6
2178c2ecf20Sopenharmony_ci#define NDC_READ_TRANS 0
2188c2ecf20Sopenharmony_ci#define NDC_WRITE_TRANS 1
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci#endif /* COMMON_H */
221