162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Marvell RVU Admin Function driver 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (C) 2018 Marvell. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef COMMON_H 862306a36Sopenharmony_ci#define COMMON_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include "rvu_struct.h" 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#define OTX2_ALIGN 128 /* Align to cacheline */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define Q_SIZE_16 0ULL /* 16 entries */ 1562306a36Sopenharmony_ci#define Q_SIZE_64 1ULL /* 64 entries */ 1662306a36Sopenharmony_ci#define Q_SIZE_256 2ULL 1762306a36Sopenharmony_ci#define Q_SIZE_1K 3ULL 1862306a36Sopenharmony_ci#define Q_SIZE_4K 4ULL 1962306a36Sopenharmony_ci#define Q_SIZE_16K 5ULL 2062306a36Sopenharmony_ci#define Q_SIZE_64K 6ULL 2162306a36Sopenharmony_ci#define Q_SIZE_256K 7ULL 2262306a36Sopenharmony_ci#define Q_SIZE_1M 8ULL /* Million entries */ 2362306a36Sopenharmony_ci#define Q_SIZE_MIN Q_SIZE_16 2462306a36Sopenharmony_ci#define Q_SIZE_MAX Q_SIZE_1M 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#define Q_COUNT(x) (16ULL << (2 * x)) 2762306a36Sopenharmony_ci#define Q_SIZE(x, n) ((ilog2(x) - (n)) / 2) 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* Admin queue info */ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci/* Since we intend to add only one instruction at a time, 3262306a36Sopenharmony_ci * keep queue size to it's minimum. 3362306a36Sopenharmony_ci */ 3462306a36Sopenharmony_ci#define AQ_SIZE Q_SIZE_16 3562306a36Sopenharmony_ci/* HW head & tail pointer mask */ 3662306a36Sopenharmony_ci#define AQ_PTR_MASK 0xFFFFF 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_cistruct qmem { 3962306a36Sopenharmony_ci void *base; 4062306a36Sopenharmony_ci dma_addr_t iova; 4162306a36Sopenharmony_ci int alloc_sz; 4262306a36Sopenharmony_ci u16 entry_sz; 4362306a36Sopenharmony_ci u8 align; 4462306a36Sopenharmony_ci u32 qsize; 4562306a36Sopenharmony_ci}; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_cistatic inline int qmem_alloc(struct device *dev, struct qmem **q, 4862306a36Sopenharmony_ci int qsize, int entry_sz) 4962306a36Sopenharmony_ci{ 5062306a36Sopenharmony_ci struct qmem *qmem; 5162306a36Sopenharmony_ci int aligned_addr; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci if (!qsize) 5462306a36Sopenharmony_ci return -EINVAL; 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci *q = devm_kzalloc(dev, sizeof(*qmem), GFP_KERNEL); 5762306a36Sopenharmony_ci if (!*q) 5862306a36Sopenharmony_ci return -ENOMEM; 5962306a36Sopenharmony_ci qmem = *q; 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci qmem->entry_sz = entry_sz; 6262306a36Sopenharmony_ci qmem->alloc_sz = (qsize * entry_sz) + OTX2_ALIGN; 6362306a36Sopenharmony_ci qmem->base = dma_alloc_attrs(dev, qmem->alloc_sz, &qmem->iova, 6462306a36Sopenharmony_ci GFP_KERNEL, DMA_ATTR_FORCE_CONTIGUOUS); 6562306a36Sopenharmony_ci if (!qmem->base) 6662306a36Sopenharmony_ci return -ENOMEM; 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci qmem->qsize = qsize; 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci aligned_addr = ALIGN((u64)qmem->iova, OTX2_ALIGN); 7162306a36Sopenharmony_ci qmem->align = (aligned_addr - qmem->iova); 7262306a36Sopenharmony_ci qmem->base += qmem->align; 7362306a36Sopenharmony_ci qmem->iova += qmem->align; 7462306a36Sopenharmony_ci return 0; 7562306a36Sopenharmony_ci} 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_cistatic inline void qmem_free(struct device *dev, struct qmem *qmem) 7862306a36Sopenharmony_ci{ 7962306a36Sopenharmony_ci if (!qmem) 8062306a36Sopenharmony_ci return; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci if (qmem->base) 8362306a36Sopenharmony_ci dma_free_attrs(dev, qmem->alloc_sz, 8462306a36Sopenharmony_ci qmem->base - qmem->align, 8562306a36Sopenharmony_ci qmem->iova - qmem->align, 8662306a36Sopenharmony_ci DMA_ATTR_FORCE_CONTIGUOUS); 8762306a36Sopenharmony_ci devm_kfree(dev, qmem); 8862306a36Sopenharmony_ci} 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_cistruct admin_queue { 9162306a36Sopenharmony_ci struct qmem *inst; 9262306a36Sopenharmony_ci struct qmem *res; 9362306a36Sopenharmony_ci spinlock_t lock; /* Serialize inst enqueue from PFs */ 9462306a36Sopenharmony_ci}; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci/* NPA aura count */ 9762306a36Sopenharmony_cienum npa_aura_sz { 9862306a36Sopenharmony_ci NPA_AURA_SZ_0, 9962306a36Sopenharmony_ci NPA_AURA_SZ_128, 10062306a36Sopenharmony_ci NPA_AURA_SZ_256, 10162306a36Sopenharmony_ci NPA_AURA_SZ_512, 10262306a36Sopenharmony_ci NPA_AURA_SZ_1K, 10362306a36Sopenharmony_ci NPA_AURA_SZ_2K, 10462306a36Sopenharmony_ci NPA_AURA_SZ_4K, 10562306a36Sopenharmony_ci NPA_AURA_SZ_8K, 10662306a36Sopenharmony_ci NPA_AURA_SZ_16K, 10762306a36Sopenharmony_ci NPA_AURA_SZ_32K, 10862306a36Sopenharmony_ci NPA_AURA_SZ_64K, 10962306a36Sopenharmony_ci NPA_AURA_SZ_128K, 11062306a36Sopenharmony_ci NPA_AURA_SZ_256K, 11162306a36Sopenharmony_ci NPA_AURA_SZ_512K, 11262306a36Sopenharmony_ci NPA_AURA_SZ_1M, 11362306a36Sopenharmony_ci NPA_AURA_SZ_MAX, 11462306a36Sopenharmony_ci}; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci#define NPA_AURA_COUNT(x) (1ULL << ((x) + 6)) 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci/* NPA AQ result structure for init/read/write of aura HW contexts */ 11962306a36Sopenharmony_cistruct npa_aq_aura_res { 12062306a36Sopenharmony_ci struct npa_aq_res_s res; 12162306a36Sopenharmony_ci struct npa_aura_s aura_ctx; 12262306a36Sopenharmony_ci struct npa_aura_s ctx_mask; 12362306a36Sopenharmony_ci}; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci/* NPA AQ result structure for init/read/write of pool HW contexts */ 12662306a36Sopenharmony_cistruct npa_aq_pool_res { 12762306a36Sopenharmony_ci struct npa_aq_res_s res; 12862306a36Sopenharmony_ci struct npa_pool_s pool_ctx; 12962306a36Sopenharmony_ci struct npa_pool_s ctx_mask; 13062306a36Sopenharmony_ci}; 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci/* NIX Transmit schedulers */ 13362306a36Sopenharmony_cienum nix_scheduler { 13462306a36Sopenharmony_ci NIX_TXSCH_LVL_SMQ = 0x0, 13562306a36Sopenharmony_ci NIX_TXSCH_LVL_MDQ = 0x0, 13662306a36Sopenharmony_ci NIX_TXSCH_LVL_TL4 = 0x1, 13762306a36Sopenharmony_ci NIX_TXSCH_LVL_TL3 = 0x2, 13862306a36Sopenharmony_ci NIX_TXSCH_LVL_TL2 = 0x3, 13962306a36Sopenharmony_ci NIX_TXSCH_LVL_TL1 = 0x4, 14062306a36Sopenharmony_ci NIX_TXSCH_LVL_CNT = 0x5, 14162306a36Sopenharmony_ci}; 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci#define TXSCH_RR_QTM_MAX ((1 << 24) - 1) 14462306a36Sopenharmony_ci#define TXSCH_TL1_DFLT_RR_QTM TXSCH_RR_QTM_MAX 14562306a36Sopenharmony_ci#define TXSCH_TL1_DFLT_RR_PRIO (0x7ull) 14662306a36Sopenharmony_ci#define CN10K_MAX_DWRR_WEIGHT 16384 /* Weight is 14bit on CN10K */ 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci/* Don't change the order as on CN10K (except CN10KB) 14962306a36Sopenharmony_ci * SMQX_CFG[SDP] value should be 1 for SDP flows. 15062306a36Sopenharmony_ci */ 15162306a36Sopenharmony_ci#define SMQ_LINK_TYPE_RPM 0 15262306a36Sopenharmony_ci#define SMQ_LINK_TYPE_SDP 1 15362306a36Sopenharmony_ci#define SMQ_LINK_TYPE_LBK 2 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci/* Min/Max packet sizes, excluding FCS */ 15662306a36Sopenharmony_ci#define NIC_HW_MIN_FRS 40 15762306a36Sopenharmony_ci#define NIC_HW_MAX_FRS 9212 15862306a36Sopenharmony_ci#define SDP_HW_MAX_FRS 65535 15962306a36Sopenharmony_ci#define CN10K_LMAC_LINK_MAX_FRS 16380 /* 16k - FCS */ 16062306a36Sopenharmony_ci#define CN10K_LBK_LINK_MAX_FRS 65535 /* 64k */ 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci/* NIX RX action operation*/ 16362306a36Sopenharmony_ci#define NIX_RX_ACTIONOP_DROP (0x0ull) 16462306a36Sopenharmony_ci#define NIX_RX_ACTIONOP_UCAST (0x1ull) 16562306a36Sopenharmony_ci#define NIX_RX_ACTIONOP_UCAST_IPSEC (0x2ull) 16662306a36Sopenharmony_ci#define NIX_RX_ACTIONOP_MCAST (0x3ull) 16762306a36Sopenharmony_ci#define NIX_RX_ACTIONOP_RSS (0x4ull) 16862306a36Sopenharmony_ci/* Use the RX action set in the default unicast entry */ 16962306a36Sopenharmony_ci#define NIX_RX_ACTION_DEFAULT (0xfull) 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci/* NIX TX action operation*/ 17262306a36Sopenharmony_ci#define NIX_TX_ACTIONOP_DROP (0x0ull) 17362306a36Sopenharmony_ci#define NIX_TX_ACTIONOP_UCAST_DEFAULT (0x1ull) 17462306a36Sopenharmony_ci#define NIX_TX_ACTIONOP_UCAST_CHAN (0x2ull) 17562306a36Sopenharmony_ci#define NIX_TX_ACTIONOP_MCAST (0x3ull) 17662306a36Sopenharmony_ci#define NIX_TX_ACTIONOP_DROP_VIOL (0x5ull) 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci#define NPC_MCAM_KEY_X1 0 17962306a36Sopenharmony_ci#define NPC_MCAM_KEY_X2 1 18062306a36Sopenharmony_ci#define NPC_MCAM_KEY_X4 2 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci#define NIX_INTFX_RX(a) (0x0ull | (a) << 1) 18362306a36Sopenharmony_ci#define NIX_INTFX_TX(a) (0x1ull | (a) << 1) 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci/* Default interfaces are NIX0_RX and NIX0_TX */ 18662306a36Sopenharmony_ci#define NIX_INTF_RX NIX_INTFX_RX(0) 18762306a36Sopenharmony_ci#define NIX_INTF_TX NIX_INTFX_TX(0) 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci#define NIX_INTF_TYPE_CGX 0 19062306a36Sopenharmony_ci#define NIX_INTF_TYPE_LBK 1 19162306a36Sopenharmony_ci#define NIX_INTF_TYPE_SDP 2 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci#define MAX_LMAC_PKIND 12 19462306a36Sopenharmony_ci#define NIX_LINK_CGX_LMAC(a, b) (0 + 4 * (a) + (b)) 19562306a36Sopenharmony_ci#define NIX_LINK_LBK(a) (12 + (a)) 19662306a36Sopenharmony_ci#define NIX_CHAN_CGX_LMAC_CHX(a, b, c) (0x800 + 0x100 * (a) + 0x10 * (b) + (c)) 19762306a36Sopenharmony_ci#define NIX_CHAN_LBK_CHX(a, b) (0 + 0x100 * (a) + (b)) 19862306a36Sopenharmony_ci#define NIX_CHAN_SDP_CH_START (0x700ull) 19962306a36Sopenharmony_ci#define NIX_CHAN_SDP_CHX(a) (NIX_CHAN_SDP_CH_START + (a)) 20062306a36Sopenharmony_ci#define NIX_CHAN_SDP_NUM_CHANS 256 20162306a36Sopenharmony_ci#define NIX_CHAN_CPT_CH_START (0x800ull) 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci/* The mask is to extract lower 10-bits of channel number 20462306a36Sopenharmony_ci * which CPT will pass to X2P. 20562306a36Sopenharmony_ci */ 20662306a36Sopenharmony_ci#define NIX_CHAN_CPT_X2P_MASK (0x3ffull) 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci/* NIX LSO format indices. 20962306a36Sopenharmony_ci * As of now TSO is the only one using, so statically assigning indices. 21062306a36Sopenharmony_ci */ 21162306a36Sopenharmony_ci#define NIX_LSO_FORMAT_IDX_TSOV4 0 21262306a36Sopenharmony_ci#define NIX_LSO_FORMAT_IDX_TSOV6 1 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci/* RSS info */ 21562306a36Sopenharmony_ci#define MAX_RSS_GROUPS 8 21662306a36Sopenharmony_ci/* Group 0 has to be used in default pkt forwarding MCAM entries 21762306a36Sopenharmony_ci * reserved for NIXLFs. Groups 1-7 can be used for RSS for ntuple 21862306a36Sopenharmony_ci * filters. 21962306a36Sopenharmony_ci */ 22062306a36Sopenharmony_ci#define DEFAULT_RSS_CONTEXT_GROUP 0 22162306a36Sopenharmony_ci#define MAX_RSS_INDIR_TBL_SIZE 256 /* 1 << Max adder bits */ 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci/* NDC info */ 22462306a36Sopenharmony_cienum ndc_idx_e { 22562306a36Sopenharmony_ci NIX0_RX = 0x0, 22662306a36Sopenharmony_ci NIX0_TX = 0x1, 22762306a36Sopenharmony_ci NPA0_U = 0x2, 22862306a36Sopenharmony_ci NIX1_RX = 0x4, 22962306a36Sopenharmony_ci NIX1_TX = 0x5, 23062306a36Sopenharmony_ci}; 23162306a36Sopenharmony_ci 23262306a36Sopenharmony_cienum ndc_ctype_e { 23362306a36Sopenharmony_ci CACHING = 0x0, 23462306a36Sopenharmony_ci BYPASS = 0x1, 23562306a36Sopenharmony_ci}; 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ci#define NDC_MAX_PORT 6 23862306a36Sopenharmony_ci#define NDC_READ_TRANS 0 23962306a36Sopenharmony_ci#define NDC_WRITE_TRANS 1 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci#endif /* COMMON_H */ 242