126b3f3ccSNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
2c7cd6c5aSSunil Goutham /* Marvell RVU Admin Function driver
37a37245eSSunil Goutham *
4c7cd6c5aSSunil Goutham * Copyright (C) 2018 Marvell.
57a37245eSSunil Goutham */
67a37245eSSunil Goutham
77a37245eSSunil Goutham #ifndef COMMON_H
87a37245eSSunil Goutham #define COMMON_H
97a37245eSSunil Goutham
107a37245eSSunil Goutham #include "rvu_struct.h"
117a37245eSSunil Goutham
127a37245eSSunil Goutham #define OTX2_ALIGN 128 /* Align to cacheline */
137a37245eSSunil Goutham
147a37245eSSunil Goutham #define Q_SIZE_16 0ULL /* 16 entries */
157a37245eSSunil Goutham #define Q_SIZE_64 1ULL /* 64 entries */
167a37245eSSunil Goutham #define Q_SIZE_256 2ULL
177a37245eSSunil Goutham #define Q_SIZE_1K 3ULL
187a37245eSSunil Goutham #define Q_SIZE_4K 4ULL
197a37245eSSunil Goutham #define Q_SIZE_16K 5ULL
207a37245eSSunil Goutham #define Q_SIZE_64K 6ULL
217a37245eSSunil Goutham #define Q_SIZE_256K 7ULL
227a37245eSSunil Goutham #define Q_SIZE_1M 8ULL /* Million entries */
237a37245eSSunil Goutham #define Q_SIZE_MIN Q_SIZE_16
247a37245eSSunil Goutham #define Q_SIZE_MAX Q_SIZE_1M
257a37245eSSunil Goutham
267a37245eSSunil Goutham #define Q_COUNT(x) (16ULL << (2 * x))
277a37245eSSunil Goutham #define Q_SIZE(x, n) ((ilog2(x) - (n)) / 2)
287a37245eSSunil Goutham
297a37245eSSunil Goutham /* Admin queue info */
307a37245eSSunil Goutham
317a37245eSSunil Goutham /* Since we intend to add only one instruction at a time,
327a37245eSSunil Goutham * keep queue size to it's minimum.
337a37245eSSunil Goutham */
347a37245eSSunil Goutham #define AQ_SIZE Q_SIZE_16
357a37245eSSunil Goutham /* HW head & tail pointer mask */
367a37245eSSunil Goutham #define AQ_PTR_MASK 0xFFFFF
377a37245eSSunil Goutham
387a37245eSSunil Goutham struct qmem {
397a37245eSSunil Goutham void *base;
407a37245eSSunil Goutham dma_addr_t iova;
417a37245eSSunil Goutham int alloc_sz;
4239341520SEric Dumazet u16 entry_sz;
437a37245eSSunil Goutham u8 align;
447a37245eSSunil Goutham u32 qsize;
457a37245eSSunil Goutham };
467a37245eSSunil Goutham
qmem_alloc(struct device * dev,struct qmem ** q,int qsize,int entry_sz)477a37245eSSunil Goutham static inline int qmem_alloc(struct device *dev, struct qmem **q,
487a37245eSSunil Goutham int qsize, int entry_sz)
497a37245eSSunil Goutham {
507a37245eSSunil Goutham struct qmem *qmem;
517a37245eSSunil Goutham int aligned_addr;
527a37245eSSunil Goutham
537a37245eSSunil Goutham if (!qsize)
547a37245eSSunil Goutham return -EINVAL;
557a37245eSSunil Goutham
567a37245eSSunil Goutham *q = devm_kzalloc(dev, sizeof(*qmem), GFP_KERNEL);
577a37245eSSunil Goutham if (!*q)
587a37245eSSunil Goutham return -ENOMEM;
597a37245eSSunil Goutham qmem = *q;
607a37245eSSunil Goutham
617a37245eSSunil Goutham qmem->entry_sz = entry_sz;
627a37245eSSunil Goutham qmem->alloc_sz = (qsize * entry_sz) + OTX2_ALIGN;
6373d33dbcSGeetha sowjanya qmem->base = dma_alloc_attrs(dev, qmem->alloc_sz, &qmem->iova,
6473d33dbcSGeetha sowjanya GFP_KERNEL, DMA_ATTR_FORCE_CONTIGUOUS);
657a37245eSSunil Goutham if (!qmem->base)
667a37245eSSunil Goutham return -ENOMEM;
677a37245eSSunil Goutham
687a37245eSSunil Goutham qmem->qsize = qsize;
697a37245eSSunil Goutham
707a37245eSSunil Goutham aligned_addr = ALIGN((u64)qmem->iova, OTX2_ALIGN);
717a37245eSSunil Goutham qmem->align = (aligned_addr - qmem->iova);
727a37245eSSunil Goutham qmem->base += qmem->align;
737a37245eSSunil Goutham qmem->iova += qmem->align;
747a37245eSSunil Goutham return 0;
757a37245eSSunil Goutham }
767a37245eSSunil Goutham
qmem_free(struct device * dev,struct qmem * qmem)777a37245eSSunil Goutham static inline void qmem_free(struct device *dev, struct qmem *qmem)
787a37245eSSunil Goutham {
797a37245eSSunil Goutham if (!qmem)
807a37245eSSunil Goutham return;
817a37245eSSunil Goutham
827a37245eSSunil Goutham if (qmem->base)
8373d33dbcSGeetha sowjanya dma_free_attrs(dev, qmem->alloc_sz,
847a37245eSSunil Goutham qmem->base - qmem->align,
8573d33dbcSGeetha sowjanya qmem->iova - qmem->align,
8673d33dbcSGeetha sowjanya DMA_ATTR_FORCE_CONTIGUOUS);
877a37245eSSunil Goutham devm_kfree(dev, qmem);
887a37245eSSunil Goutham }
897a37245eSSunil Goutham
907a37245eSSunil Goutham struct admin_queue {
917a37245eSSunil Goutham struct qmem *inst;
927a37245eSSunil Goutham struct qmem *res;
937a37245eSSunil Goutham spinlock_t lock; /* Serialize inst enqueue from PFs */
947a37245eSSunil Goutham };
957a37245eSSunil Goutham
963fa4c323SSunil Goutham /* NPA aura count */
973fa4c323SSunil Goutham enum npa_aura_sz {
983fa4c323SSunil Goutham NPA_AURA_SZ_0,
993fa4c323SSunil Goutham NPA_AURA_SZ_128,
1003fa4c323SSunil Goutham NPA_AURA_SZ_256,
1013fa4c323SSunil Goutham NPA_AURA_SZ_512,
1023fa4c323SSunil Goutham NPA_AURA_SZ_1K,
1033fa4c323SSunil Goutham NPA_AURA_SZ_2K,
1043fa4c323SSunil Goutham NPA_AURA_SZ_4K,
1053fa4c323SSunil Goutham NPA_AURA_SZ_8K,
1063fa4c323SSunil Goutham NPA_AURA_SZ_16K,
1073fa4c323SSunil Goutham NPA_AURA_SZ_32K,
1083fa4c323SSunil Goutham NPA_AURA_SZ_64K,
1093fa4c323SSunil Goutham NPA_AURA_SZ_128K,
1103fa4c323SSunil Goutham NPA_AURA_SZ_256K,
1113fa4c323SSunil Goutham NPA_AURA_SZ_512K,
1123fa4c323SSunil Goutham NPA_AURA_SZ_1M,
1133fa4c323SSunil Goutham NPA_AURA_SZ_MAX,
1143fa4c323SSunil Goutham };
1153fa4c323SSunil Goutham
1163fa4c323SSunil Goutham #define NPA_AURA_COUNT(x) (1ULL << ((x) + 6))
1173fa4c323SSunil Goutham
1184a3581cdSSunil Goutham /* NPA AQ result structure for init/read/write of aura HW contexts */
1194a3581cdSSunil Goutham struct npa_aq_aura_res {
1204a3581cdSSunil Goutham struct npa_aq_res_s res;
1214a3581cdSSunil Goutham struct npa_aura_s aura_ctx;
1224a3581cdSSunil Goutham struct npa_aura_s ctx_mask;
1234a3581cdSSunil Goutham };
1244a3581cdSSunil Goutham
1254a3581cdSSunil Goutham /* NPA AQ result structure for init/read/write of pool HW contexts */
1264a3581cdSSunil Goutham struct npa_aq_pool_res {
1274a3581cdSSunil Goutham struct npa_aq_res_s res;
1284a3581cdSSunil Goutham struct npa_pool_s pool_ctx;
1294a3581cdSSunil Goutham struct npa_pool_s ctx_mask;
1304a3581cdSSunil Goutham };
131cb30711aSSunil Goutham
132709a4f0cSSunil Goutham /* NIX Transmit schedulers */
133709a4f0cSSunil Goutham enum nix_scheduler {
134709a4f0cSSunil Goutham NIX_TXSCH_LVL_SMQ = 0x0,
135709a4f0cSSunil Goutham NIX_TXSCH_LVL_MDQ = 0x0,
136709a4f0cSSunil Goutham NIX_TXSCH_LVL_TL4 = 0x1,
137709a4f0cSSunil Goutham NIX_TXSCH_LVL_TL3 = 0x2,
138709a4f0cSSunil Goutham NIX_TXSCH_LVL_TL2 = 0x3,
139709a4f0cSSunil Goutham NIX_TXSCH_LVL_TL1 = 0x4,
140709a4f0cSSunil Goutham NIX_TXSCH_LVL_CNT = 0x5,
141709a4f0cSSunil Goutham };
142709a4f0cSSunil Goutham
143caa2da34SSunil Goutham #define TXSCH_RR_QTM_MAX ((1 << 24) - 1)
144caa2da34SSunil Goutham #define TXSCH_TL1_DFLT_RR_QTM TXSCH_RR_QTM_MAX
1455e6808b4SNaveen Mamindlapalli #define TXSCH_TL1_DFLT_RR_PRIO (0x7ull)
14676660df2SSunil Goutham #define CN10K_MAX_DWRR_WEIGHT 16384 /* Weight is 14bit on CN10K */
14726dda7daSNithin Dabilpuram
148*bbba125eSSunil Goutham /* Don't change the order as on CN10K (except CN10KB)
149*bbba125eSSunil Goutham * SMQX_CFG[SDP] value should be 1 for SDP flows.
150*bbba125eSSunil Goutham */
151*bbba125eSSunil Goutham #define SMQ_LINK_TYPE_RPM 0
152*bbba125eSSunil Goutham #define SMQ_LINK_TYPE_SDP 1
153*bbba125eSSunil Goutham #define SMQ_LINK_TYPE_LBK 2
154*bbba125eSSunil Goutham
1559b7dd87aSSunil Goutham /* Min/Max packet sizes, excluding FCS */
1569b7dd87aSSunil Goutham #define NIC_HW_MIN_FRS 40
1579b7dd87aSSunil Goutham #define NIC_HW_MAX_FRS 9212
1589b7dd87aSSunil Goutham #define SDP_HW_MAX_FRS 65535
1596e54e1c5SHariprasad Kelam #define CN10K_LMAC_LINK_MAX_FRS 16380 /* 16k - FCS */
1606e54e1c5SHariprasad Kelam #define CN10K_LBK_LINK_MAX_FRS 65535 /* 64k */
1619b7dd87aSSunil Goutham
162fefefd99SSunil Goutham /* NIX RX action operation*/
163fefefd99SSunil Goutham #define NIX_RX_ACTIONOP_DROP (0x0ull)
164fefefd99SSunil Goutham #define NIX_RX_ACTIONOP_UCAST (0x1ull)
165fefefd99SSunil Goutham #define NIX_RX_ACTIONOP_UCAST_IPSEC (0x2ull)
166fefefd99SSunil Goutham #define NIX_RX_ACTIONOP_MCAST (0x3ull)
167fefefd99SSunil Goutham #define NIX_RX_ACTIONOP_RSS (0x4ull)
16855307fcbSSubbaraya Sundeep /* Use the RX action set in the default unicast entry */
16955307fcbSSubbaraya Sundeep #define NIX_RX_ACTION_DEFAULT (0xfull)
170fefefd99SSunil Goutham
171fefefd99SSunil Goutham /* NIX TX action operation*/
172fefefd99SSunil Goutham #define NIX_TX_ACTIONOP_DROP (0x0ull)
173fefefd99SSunil Goutham #define NIX_TX_ACTIONOP_UCAST_DEFAULT (0x1ull)
174fefefd99SSunil Goutham #define NIX_TX_ACTIONOP_UCAST_CHAN (0x2ull)
175fefefd99SSunil Goutham #define NIX_TX_ACTIONOP_MCAST (0x3ull)
176fefefd99SSunil Goutham #define NIX_TX_ACTIONOP_DROP_VIOL (0x5ull)
177fefefd99SSunil Goutham
178fefefd99SSunil Goutham #define NPC_MCAM_KEY_X1 0
179fefefd99SSunil Goutham #define NPC_MCAM_KEY_X2 1
180fefefd99SSunil Goutham #define NPC_MCAM_KEY_X4 2
181fefefd99SSunil Goutham
1821c1935c9SSubbaraya Sundeep #define NIX_INTFX_RX(a) (0x0ull | (a) << 1)
1831c1935c9SSubbaraya Sundeep #define NIX_INTFX_TX(a) (0x1ull | (a) << 1)
1841c1935c9SSubbaraya Sundeep
1851c1935c9SSubbaraya Sundeep /* Default interfaces are NIX0_RX and NIX0_TX */
1861c1935c9SSubbaraya Sundeep #define NIX_INTF_RX NIX_INTFX_RX(0)
1871c1935c9SSubbaraya Sundeep #define NIX_INTF_TX NIX_INTFX_TX(0)
188fefefd99SSunil Goutham
18994d942c5SGeetha sowjanya #define NIX_INTF_TYPE_CGX 0
19094d942c5SGeetha sowjanya #define NIX_INTF_TYPE_LBK 1
191fe1939bbSRadha Mohan Chintakuntla #define NIX_INTF_TYPE_SDP 2
19294d942c5SGeetha sowjanya
19394d942c5SGeetha sowjanya #define MAX_LMAC_PKIND 12
19494d942c5SGeetha sowjanya #define NIX_LINK_CGX_LMAC(a, b) (0 + 4 * (a) + (b))
1958bb991c5STomasz Duszynski #define NIX_LINK_LBK(a) (12 + (a))
196f5721f76SStanislaw Kardach #define NIX_CHAN_CGX_LMAC_CHX(a, b, c) (0x800 + 0x100 * (a) + 0x10 * (b) + (c))
1978bb991c5STomasz Duszynski #define NIX_CHAN_LBK_CHX(a, b) (0 + 0x100 * (a) + (b))
198242da439SSubbaraya Sundeep #define NIX_CHAN_SDP_CH_START (0x700ull)
199fe1939bbSRadha Mohan Chintakuntla #define NIX_CHAN_SDP_CHX(a) (NIX_CHAN_SDP_CH_START + (a))
200fe1939bbSRadha Mohan Chintakuntla #define NIX_CHAN_SDP_NUM_CHANS 256
2014b5a3ab1SSrujana Challa #define NIX_CHAN_CPT_CH_START (0x800ull)
202242da439SSubbaraya Sundeep
203967db352SNaveen Mamindlapalli /* The mask is to extract lower 10-bits of channel number
204967db352SNaveen Mamindlapalli * which CPT will pass to X2P.
205967db352SNaveen Mamindlapalli */
206967db352SNaveen Mamindlapalli #define NIX_CHAN_CPT_X2P_MASK (0x3ffull)
207967db352SNaveen Mamindlapalli
20859360e98SSunil Goutham /* NIX LSO format indices.
20959360e98SSunil Goutham * As of now TSO is the only one using, so statically assigning indices.
21059360e98SSunil Goutham */
21159360e98SSunil Goutham #define NIX_LSO_FORMAT_IDX_TSOV4 0
21259360e98SSunil Goutham #define NIX_LSO_FORMAT_IDX_TSOV6 1
21359360e98SSunil Goutham
214cb30711aSSunil Goutham /* RSS info */
215cb30711aSSunil Goutham #define MAX_RSS_GROUPS 8
216cb30711aSSunil Goutham /* Group 0 has to be used in default pkt forwarding MCAM entries
217cb30711aSSunil Goutham * reserved for NIXLFs. Groups 1-7 can be used for RSS for ntuple
218cb30711aSSunil Goutham * filters.
219cb30711aSSunil Goutham */
220cb30711aSSunil Goutham #define DEFAULT_RSS_CONTEXT_GROUP 0
221cb30711aSSunil Goutham #define MAX_RSS_INDIR_TBL_SIZE 256 /* 1 << Max adder bits */
222cb30711aSSunil Goutham
223c5a797e0SPrakash Brahmajyosyula /* NDC info */
224c5a797e0SPrakash Brahmajyosyula enum ndc_idx_e {
225c5a797e0SPrakash Brahmajyosyula NIX0_RX = 0x0,
226c5a797e0SPrakash Brahmajyosyula NIX0_TX = 0x1,
227c5a797e0SPrakash Brahmajyosyula NPA0_U = 0x2,
2280f3ce484SRakesh Babu NIX1_RX = 0x4,
2290f3ce484SRakesh Babu NIX1_TX = 0x5,
230c5a797e0SPrakash Brahmajyosyula };
231c5a797e0SPrakash Brahmajyosyula
232c5a797e0SPrakash Brahmajyosyula enum ndc_ctype_e {
233c5a797e0SPrakash Brahmajyosyula CACHING = 0x0,
234c5a797e0SPrakash Brahmajyosyula BYPASS = 0x1,
235c5a797e0SPrakash Brahmajyosyula };
236c5a797e0SPrakash Brahmajyosyula
237c5a797e0SPrakash Brahmajyosyula #define NDC_MAX_PORT 6
238c5a797e0SPrakash Brahmajyosyula #define NDC_READ_TRANS 0
239c5a797e0SPrakash Brahmajyosyula #define NDC_WRITE_TRANS 1
240c5a797e0SPrakash Brahmajyosyula
2417a37245eSSunil Goutham #endif /* COMMON_H */
242