1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Marvell RVU Admin Function driver
4 * Copyright (C) 2022 Marvell.
8 #ifndef __RVU_NPC_HASH_H
9 #define __RVU_NPC_HASH_H
11 #define RVU_NPC_HASH_SECRET_KEY0 0xa9d5af4c9fbc76b1
12 #define RVU_NPC_HASH_SECRET_KEY1 0xa9d5af4c9fbc87b4
13 #define RVU_NPC_HASH_SECRET_KEY2 0x5954c9e7
15 #define NPC_MAX_HASH 2
16 #define NPC_MAX_HASH_MASK 2
18 #define KEX_LD_CFG_USE_HASH(use_hash, bytesm1, hdr_ofs, ena, flags_ena, key_ofs) \
19 ((use_hash) << 20 | ((bytesm1) << 16) | ((hdr_ofs) << 8) | \
20 ((ena) << 7) | ((flags_ena) << 6) | ((key_ofs) & 0x3F))
21 #define KEX_LD_CFG_HASH(hdr_ofs, bytesm1, lt_en, lid_en, lid, ltype_match, ltype_mask) \
22 (((hdr_ofs) << 32) | ((bytesm1) << 16) | \
23 ((lt_en) << 12) | ((lid_en) << 11) | ((lid) << 8) | \
24 ((ltype_match) << 4) | ((ltype_mask) & 0xF))
26 #define SET_KEX_LD_HASH(intf, ld, cfg) \
27 rvu_write64(rvu, blkaddr, \
28 NPC_AF_INTFX_HASHX_CFG(intf, ld), cfg)
30 #define SET_KEX_LD_HASH_MASK(intf, ld, mask_idx, cfg) \
31 rvu_write64(rvu, blkaddr, \
32 NPC_AF_INTFX_HASHX_MASKX(intf, ld, mask_idx), cfg)
34 #define SET_KEX_LD_HASH_CTRL(intf, ld, cfg) \
35 rvu_write64(rvu, blkaddr, \
36 NPC_AF_INTFX_HASHX_RESULT_CTRL(intf, ld), cfg)
38 struct npc_mcam_kex_hash {
39 /* NPC_AF_INTF(0..1)_LID(0..7)_LT(0..15)_LD(0..1)_CFG */
40 bool lid_lt_ld_hash_en[NPC_MAX_INTF][NPC_MAX_LID][NPC_MAX_LT][NPC_MAX_LD];
41 /* NPC_AF_INTF(0..1)_HASH(0..1)_CFG */
42 u64 hash[NPC_MAX_INTF][NPC_MAX_HASH];
43 /* NPC_AF_INTF(0..1)_HASH(0..1)_MASK(0..1) */
44 u64 hash_mask[NPC_MAX_INTF][NPC_MAX_HASH][NPC_MAX_HASH_MASK];
45 /* NPC_AF_INTF(0..1)_HASH(0..1)_RESULT_CTRL */
46 u64 hash_ctrl[NPC_MAX_INTF][NPC_MAX_HASH];
49 void npc_update_field_hash(struct rvu *rvu, u8 intf,
50 struct mcam_entry *entry,
54 struct flow_msg *mask,
55 struct flow_msg *opkt,
56 struct flow_msg *omask);
57 void npc_config_secret_key(struct rvu *rvu, int blkaddr);
58 void npc_program_mkex_hash(struct rvu *rvu, int blkaddr);
59 u32 npc_field_hash_calc(u64 *ldata, struct npc_mcam_kex_hash *mkex_hash,
60 u64 *secret_key, u8 intf, u8 hash_idx);
62 static struct npc_mcam_kex_hash npc_mkex_hash_default __maybe_unused = {
63 .lid_lt_ld_hash_en = {
85 KEX_LD_CFG_HASH(0x8ULL, 0xf, 0x1, 0x1, NPC_LID_LC, NPC_LT_LC_IP6, 0xf),
86 KEX_LD_CFG_HASH(0x18ULL, 0xf, 0x1, 0x1, NPC_LID_LC, NPC_LT_LC_IP6, 0xf),
90 KEX_LD_CFG_HASH(0x8ULL, 0xf, 0x1, 0x1, NPC_LID_LC, NPC_LT_LC_IP6, 0xf),
91 KEX_LD_CFG_HASH(0x18ULL, 0xf, 0x1, 0x1, NPC_LID_LC, NPC_LT_LC_IP6, 0xf),
121 [0] = GENMASK_ULL(63, 32), /* MSB 32 bit is mask and LSB 32 bit is offset. */
122 [1] = GENMASK_ULL(63, 32), /* MSB 32 bit is mask and LSB 32 bit is offset. */
126 [0] = GENMASK_ULL(63, 32), /* MSB 32 bit is mask and LSB 32 bit is offset. */
127 [1] = GENMASK_ULL(63, 32), /* MSB 32 bit is mask and LSB 32 bit is offset. */
132 enum npc_exact_opc_type {
137 struct npc_exact_table_entry {
138 struct list_head list;
139 struct list_head glist;
140 u32 seq_id; /* Sequence number of entry */
141 u32 index; /* Mem table or cam table index */
143 /* Mcam index. This is valid only if "cmd" field is false */
144 enum npc_exact_opc_type opc_type;
152 bool cmd; /* Is added by ethtool command ? */
155 struct npc_exact_table {
156 struct mutex lock; /* entries update lock */
157 unsigned long *id_bmap;
163 u64 mask; // Masks before hash calculation.
164 u16 hash_mask; // 11 bits for hash mask
165 u16 hash_offset; // 11 bits offset
172 #define NPC_EXACT_TBL_MAX_WAYS 4
174 struct list_head lhead_mem_tbl_entry[NPC_EXACT_TBL_MAX_WAYS];
175 int mem_tbl_entry_cnt;
177 struct list_head lhead_cam_tbl_entry;
178 int cam_tbl_entry_cnt;
180 struct list_head lhead_gbl;
183 bool rvu_npc_exact_has_match_table(struct rvu *rvu);
184 int rvu_npc_exact_del_table_entry_by_id(struct rvu *rvu, u32 seq_id);
185 u32 rvu_npc_exact_get_max_entries(struct rvu *rvu);
186 int rvu_npc_exact_init(struct rvu *rvu);
188 bool rvu_npc_exact_can_disable_feature(struct rvu *rvu);
189 void rvu_npc_exact_disable_feature(struct rvu *rvu);
190 void rvu_npc_exact_reset(struct rvu *rvu, u16 pcifunc);
192 #endif /* RVU_NPC_HASH_H */