| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include <linux/bitfield.h> |
| 9 |
#include <linux/module.h> |
| 10 |
#include <linux/pci.h> |
| 11 |
#include <linux/firmware.h> |
| 12 |
#include <linux/stddef.h> |
| 13 |
#include <linux/debugfs.h> |
| 14 |
|
| 15 |
#include "rvu_struct.h" |
| 16 |
#include "rvu_reg.h" |
| 17 |
#include "rvu.h" |
| 18 |
#include "npc.h" |
| 19 |
#include "cgx.h" |
| 20 |
#include "rvu_npc_fs.h" |
| 21 |
#include "rvu_npc_hash.h" |
| 22 |
|
| 23 |
static u64 rvu_npc_wide_extract(const u64 input[], size_t start_bit, |
| 24 |
size_t width_bits) |
| 25 |
{ |
| 26 |
const u64 mask = ~(u64)((~(__uint128_t)0) << width_bits); |
| 27 |
const size_t msb = start_bit + width_bits - 1; |
| 28 |
const size_t lword = start_bit >> 6; |
| 29 |
const size_t uword = msb >> 6; |
| 30 |
size_t lbits; |
| 31 |
u64 hi, lo; |
| 32 |
|
| 33 |
if (lword == uword) |
| 34 |
return (input[lword] >> (start_bit & 63)) & mask; |
| 35 |
|
| 36 |
lbits = 64 - (start_bit & 63); |
| 37 |
hi = input[uword]; |
| 38 |
lo = (input[lword] >> (start_bit & 63)); |
| 39 |
return ((hi << lbits) | lo) & mask; |
| 40 |
} |
| 41 |
|
| 42 |
static void rvu_npc_lshift_key(u64 *key, size_t key_bit_len) |
| 43 |
{ |
| 44 |
u64 prev_orig_word = 0; |
| 45 |
u64 cur_orig_word = 0; |
| 46 |
size_t extra = key_bit_len % 64; |
| 47 |
size_t max_idx = key_bit_len / 64; |
| 48 |
size_t i; |
| 49 |
|
| 50 |
if (extra) |
| 51 |
max_idx++; |
| 52 |
|
| 53 |
for (i = 0; i < max_idx; i++) { |
| 54 |
cur_orig_word = key[i]; |
| 55 |
key[i] = key[i] << 1; |
| 56 |
key[i] |= ((prev_orig_word >> 63) & 0x1); |
| 57 |
prev_orig_word = cur_orig_word; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
static u32 rvu_npc_toeplitz_hash(const u64 *data, u64 *key, size_t data_bit_len, |
| 62 |
size_t key_bit_len) |
| 63 |
{ |
| 64 |
u32 hash_out = 0; |
| 65 |
u64 temp_data = 0; |
| 66 |
int i; |
| 67 |
|
| 68 |
for (i = data_bit_len - 1; i >= 0; i--) { |
| 69 |
temp_data = (data[i / 64]); |
| 70 |
temp_data = temp_data >> (i % 64); |
| 71 |
temp_data &= 0x1; |
| 72 |
if (temp_data) |
| 73 |
hash_out ^= (u32)(rvu_npc_wide_extract(key, key_bit_len - 32, 32)); |
| 74 |
|
| 75 |
rvu_npc_lshift_key(key, key_bit_len); |
| 76 |
} |
| 77 |
|
| 78 |
return hash_out; |
| 79 |
} |
| 80 |
|
| 81 |
u32 npc_field_hash_calc(u64 *ldata, struct npc_get_field_hash_info_rsp rsp, |
| 82 |
u8 intf, u8 hash_idx) |
| 83 |
{ |
| 84 |
u64 hash_key[3]; |
| 85 |
u64 data_padded[2]; |
| 86 |
u32 field_hash; |
| 87 |
|
| 88 |
hash_key[0] = rsp.secret_key[1] << 31; |
| 89 |
hash_key[0] |= rsp.secret_key[2]; |
| 90 |
hash_key[1] = rsp.secret_key[1] >> 33; |
| 91 |
hash_key[1] |= rsp.secret_key[0] << 31; |
| 92 |
hash_key[2] = rsp.secret_key[0] >> 33; |
| 93 |
|
| 94 |
data_padded[0] = rsp.hash_mask[intf][hash_idx][0] & ldata[0]; |
| 95 |
data_padded[1] = rsp.hash_mask[intf][hash_idx][1] & ldata[1]; |
| 96 |
field_hash = rvu_npc_toeplitz_hash(data_padded, hash_key, 128, 159); |
| 97 |
|
| 98 |
field_hash &= FIELD_GET(GENMASK(63, 32), rsp.hash_ctrl[intf][hash_idx]); |
| 99 |
field_hash += FIELD_GET(GENMASK(31, 0), rsp.hash_ctrl[intf][hash_idx]); |
| 100 |
return field_hash; |
| 101 |
} |
| 102 |
|
| 103 |
static u64 npc_update_use_hash(struct rvu *rvu, int blkaddr, |
| 104 |
u8 intf, int lid, int lt, int ld) |
| 105 |
{ |
| 106 |
u8 hdr, key; |
| 107 |
u64 cfg; |
| 108 |
|
| 109 |
cfg = rvu_read64(rvu, blkaddr, NPC_AF_INTFX_LIDX_LTX_LDX_CFG(intf, lid, lt, ld)); |
| 110 |
hdr = FIELD_GET(NPC_HDR_OFFSET, cfg); |
| 111 |
key = FIELD_GET(NPC_KEY_OFFSET, cfg); |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
cfg = KEX_LD_CFG_USE_HASH(0x1, 0x03, |
| 117 |
hdr, 0x1, 0x0, key); |
| 118 |
|
| 119 |
return cfg; |
| 120 |
} |
| 121 |
|
| 122 |
static void npc_program_mkex_hash_rx(struct rvu *rvu, int blkaddr, |
| 123 |
u8 intf) |
| 124 |
{ |
| 125 |
struct npc_mcam_kex_hash *mkex_hash = rvu->kpu.mkex_hash; |
| 126 |
int lid, lt, ld, hash_cnt = 0; |
| 127 |
|
| 128 |
if (is_cn20k(rvu->pdev)) |
| 129 |
return; |
| 130 |
|
| 131 |
if (is_npc_intf_tx(intf)) |
| 132 |
return; |
| 133 |
|
| 134 |
|
| 135 |
for (lid = 0; lid < NPC_MAX_LID; lid++) { |
| 136 |
for (lt = 0; lt < NPC_MAX_LT; lt++) { |
| 137 |
for (ld = 0; ld < NPC_MAX_LD; ld++) { |
| 138 |
if (mkex_hash->lid_lt_ld_hash_en[intf][lid][lt][ld]) { |
| 139 |
u64 cfg; |
| 140 |
|
| 141 |
if (hash_cnt == NPC_MAX_HASH) |
| 142 |
return; |
| 143 |
|
| 144 |
cfg = npc_update_use_hash(rvu, blkaddr, |
| 145 |
intf, lid, lt, ld); |
| 146 |
|
| 147 |
SET_KEX_LD(intf, lid, lt, ld, cfg); |
| 148 |
|
| 149 |
SET_KEX_LD_HASH(intf, ld, |
| 150 |
mkex_hash->hash[intf][ld]); |
| 151 |
SET_KEX_LD_HASH_MASK(intf, ld, 0, |
| 152 |
mkex_hash->hash_mask[intf][ld][0]); |
| 153 |
SET_KEX_LD_HASH_MASK(intf, ld, 1, |
| 154 |
mkex_hash->hash_mask[intf][ld][1]); |
| 155 |
SET_KEX_LD_HASH_CTRL(intf, ld, |
| 156 |
mkex_hash->hash_ctrl[intf][ld]); |
| 157 |
|
| 158 |
hash_cnt++; |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
static void npc_program_mkex_hash_tx(struct rvu *rvu, int blkaddr, |
| 166 |
u8 intf) |
| 167 |
{ |
| 168 |
struct npc_mcam_kex_hash *mkex_hash = rvu->kpu.mkex_hash; |
| 169 |
int lid, lt, ld, hash_cnt = 0; |
| 170 |
|
| 171 |
if (is_cn20k(rvu->pdev)) |
| 172 |
return; |
| 173 |
|
| 174 |
if (is_npc_intf_rx(intf)) |
| 175 |
return; |
| 176 |
|
| 177 |
|
| 178 |
for (lid = 0; lid < NPC_MAX_LID; lid++) { |
| 179 |
for (lt = 0; lt < NPC_MAX_LT; lt++) { |
| 180 |
for (ld = 0; ld < NPC_MAX_LD; ld++) |
| 181 |
if (mkex_hash->lid_lt_ld_hash_en[intf][lid][lt][ld]) { |
| 182 |
u64 cfg; |
| 183 |
|
| 184 |
if (hash_cnt == NPC_MAX_HASH) |
| 185 |
return; |
| 186 |
|
| 187 |
cfg = npc_update_use_hash(rvu, blkaddr, |
| 188 |
intf, lid, lt, ld); |
| 189 |
|
| 190 |
SET_KEX_LD(intf, lid, lt, ld, cfg); |
| 191 |
|
| 192 |
SET_KEX_LD_HASH(intf, ld, |
| 193 |
mkex_hash->hash[intf][ld]); |
| 194 |
SET_KEX_LD_HASH_MASK(intf, ld, 0, |
| 195 |
mkex_hash->hash_mask[intf][ld][0]); |
| 196 |
SET_KEX_LD_HASH_MASK(intf, ld, 1, |
| 197 |
mkex_hash->hash_mask[intf][ld][1]); |
| 198 |
SET_KEX_LD_HASH_CTRL(intf, ld, |
| 199 |
mkex_hash->hash_ctrl[intf][ld]); |
| 200 |
hash_cnt++; |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
void npc_config_secret_key(struct rvu *rvu, int blkaddr) |
| 207 |
{ |
| 208 |
struct hw_cap *hwcap = &rvu->hw->cap; |
| 209 |
struct rvu_hwinfo *hw = rvu->hw; |
| 210 |
u8 intf; |
| 211 |
|
| 212 |
if (!hwcap->npc_hash_extract) |
| 213 |
return; |
| 214 |
|
| 215 |
for (intf = 0; intf < hw->npc_intfs; intf++) { |
| 216 |
rvu_write64(rvu, blkaddr, NPC_AF_INTFX_SECRET_KEY0(intf), |
| 217 |
RVU_NPC_HASH_SECRET_KEY0); |
| 218 |
rvu_write64(rvu, blkaddr, NPC_AF_INTFX_SECRET_KEY1(intf), |
| 219 |
RVU_NPC_HASH_SECRET_KEY1); |
| 220 |
rvu_write64(rvu, blkaddr, NPC_AF_INTFX_SECRET_KEY2(intf), |
| 221 |
RVU_NPC_HASH_SECRET_KEY2); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
void npc_program_mkex_hash(struct rvu *rvu, int blkaddr) |
| 226 |
{ |
| 227 |
struct npc_mcam_kex_hash *mh = rvu->kpu.mkex_hash; |
| 228 |
struct hw_cap *hwcap = &rvu->hw->cap; |
| 229 |
u8 intf, ld, hdr_offset, byte_len; |
| 230 |
struct rvu_hwinfo *hw = rvu->hw; |
| 231 |
u64 cfg; |
| 232 |
|
| 233 |
if (is_cn20k(rvu->pdev)) |
| 234 |
return; |
| 235 |
|
| 236 |
|
| 237 |
if (!hwcap->npc_hash_extract) |
| 238 |
return; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
for (intf = 0; intf < hw->npc_intfs; intf++) { |
| 255 |
for (ld = 0; ld < NPC_MAX_LD; ld++) { |
| 256 |
cfg = rvu_read64(rvu, blkaddr, |
| 257 |
NPC_AF_INTFX_LIDX_LTX_LDX_CFG(intf, |
| 258 |
NPC_LID_LC, |
| 259 |
NPC_LT_LC_IP6, |
| 260 |
ld)); |
| 261 |
hdr_offset = FIELD_GET(NPC_HDR_OFFSET, cfg); |
| 262 |
byte_len = FIELD_GET(NPC_BYTESM, cfg); |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
if ((hdr_offset == 8 || hdr_offset == 24) && byte_len == 3) |
| 273 |
mh->lid_lt_ld_hash_en[intf][NPC_LID_LC][NPC_LT_LC_IP6][ld] = true; |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
for (intf = 0; intf < hw->npc_intfs; intf++) { |
| 279 |
npc_program_mkex_hash_rx(rvu, blkaddr, intf); |
| 280 |
npc_program_mkex_hash_tx(rvu, blkaddr, intf); |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
void npc_update_field_hash(struct rvu *rvu, u8 intf, |
| 285 |
struct mcam_entry_mdata *mdata, |
| 286 |
int blkaddr, |
| 287 |
u64 features, |
| 288 |
struct flow_msg *pkt, |
| 289 |
struct flow_msg *mask, |
| 290 |
struct flow_msg *opkt, |
| 291 |
struct flow_msg *omask) |
| 292 |
{ |
| 293 |
struct npc_mcam_kex_hash *mkex_hash = rvu->kpu.mkex_hash; |
| 294 |
struct npc_get_field_hash_info_req req; |
| 295 |
struct npc_get_field_hash_info_rsp rsp; |
| 296 |
u8 hash_idx, lid, ltype, ltype_mask; |
| 297 |
u64 ldata[2], cfg; |
| 298 |
u32 field_hash; |
| 299 |
bool en; |
| 300 |
|
| 301 |
if (is_cn20k(rvu->pdev)) |
| 302 |
return; |
| 303 |
|
| 304 |
if (!rvu->hw->cap.npc_hash_extract) { |
| 305 |
dev_dbg(rvu->dev, "%s: Field hash extract feature is not supported\n", __func__); |
| 306 |
return; |
| 307 |
} |
| 308 |
|
| 309 |
req.intf = intf; |
| 310 |
rvu_mbox_handler_npc_get_field_hash_info(rvu, &req, &rsp); |
| 311 |
|
| 312 |
for (hash_idx = 0; hash_idx < NPC_MAX_HASH; hash_idx++) { |
| 313 |
cfg = rvu_read64(rvu, blkaddr, NPC_AF_INTFX_HASHX_CFG(intf, hash_idx)); |
| 314 |
en = !!(cfg & BIT_ULL(11)) && (cfg & BIT_ULL(12)); |
| 315 |
if (!en) |
| 316 |
continue; |
| 317 |
|
| 318 |
lid = (cfg & GENMASK_ULL(10, 8)) >> 8; |
| 319 |
ltype = (cfg & GENMASK_ULL(7, 4)) >> 4; |
| 320 |
ltype_mask = cfg & GENMASK_ULL(3, 0); |
| 321 |
|
| 322 |
if (!mkex_hash->lid_lt_ld_hash_en[intf][lid][ltype][hash_idx]) |
| 323 |
continue; |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
if ((ltype & ltype_mask) != NPC_LT_LC_IP6) |
| 330 |
continue; |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
if ((features & BIT_ULL(NPC_SIP_IPV6)) && !hash_idx) { |
| 336 |
u32 src_ip[IPV6_WORDS]; |
| 337 |
|
| 338 |
be32_to_cpu_array(src_ip, pkt->ip6src, IPV6_WORDS); |
| 339 |
ldata[1] = (u64)src_ip[0] << 32 | src_ip[1]; |
| 340 |
ldata[0] = (u64)src_ip[2] << 32 | src_ip[3]; |
| 341 |
field_hash = npc_field_hash_calc(ldata, rsp, intf, |
| 342 |
hash_idx); |
| 343 |
npc_update_entry(rvu, NPC_SIP_IPV6, mdata, field_hash, |
| 344 |
0, GENMASK(31, 0), 0, intf); |
| 345 |
memcpy(&opkt->ip6src, &pkt->ip6src, |
| 346 |
sizeof(pkt->ip6src)); |
| 347 |
memcpy(&omask->ip6src, &mask->ip6src, |
| 348 |
sizeof(mask->ip6src)); |
| 349 |
continue; |
| 350 |
} |
| 351 |
|
| 352 |
if ((features & BIT_ULL(NPC_DIP_IPV6)) && hash_idx) { |
| 353 |
u32 dst_ip[IPV6_WORDS]; |
| 354 |
|
| 355 |
be32_to_cpu_array(dst_ip, pkt->ip6dst, IPV6_WORDS); |
| 356 |
ldata[1] = (u64)dst_ip[0] << 32 | dst_ip[1]; |
| 357 |
ldata[0] = (u64)dst_ip[2] << 32 | dst_ip[3]; |
| 358 |
field_hash = npc_field_hash_calc(ldata, rsp, intf, |
| 359 |
hash_idx); |
| 360 |
npc_update_entry(rvu, NPC_DIP_IPV6, mdata, |
| 361 |
field_hash, 0, GENMASK(31, 0), |
| 362 |
0, intf); |
| 363 |
memcpy(&opkt->ip6dst, &pkt->ip6dst, |
| 364 |
sizeof(pkt->ip6dst)); |
| 365 |
memcpy(&omask->ip6dst, &mask->ip6dst, |
| 366 |
sizeof(mask->ip6dst)); |
| 367 |
continue; |
| 368 |
} |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
int rvu_mbox_handler_npc_get_field_hash_info(struct rvu *rvu, |
| 373 |
struct npc_get_field_hash_info_req *req, |
| 374 |
struct npc_get_field_hash_info_rsp *rsp) |
| 375 |
{ |
| 376 |
u64 *secret_key = rsp->secret_key; |
| 377 |
u8 intf = req->intf; |
| 378 |
int i, j, blkaddr; |
| 379 |
|
| 380 |
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); |
| 381 |
if (blkaddr < 0) { |
| 382 |
dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__); |
| 383 |
return -EINVAL; |
| 384 |
} |
| 385 |
|
| 386 |
secret_key[0] = rvu_read64(rvu, blkaddr, NPC_AF_INTFX_SECRET_KEY0(intf)); |
| 387 |
secret_key[1] = rvu_read64(rvu, blkaddr, NPC_AF_INTFX_SECRET_KEY1(intf)); |
| 388 |
secret_key[2] = rvu_read64(rvu, blkaddr, NPC_AF_INTFX_SECRET_KEY2(intf)); |
| 389 |
|
| 390 |
for (i = 0; i < NPC_MAX_HASH; i++) { |
| 391 |
for (j = 0; j < NPC_MAX_HASH_MASK; j++) { |
| 392 |
rsp->hash_mask[NIX_INTF_RX][i][j] = |
| 393 |
GET_KEX_LD_HASH_MASK(NIX_INTF_RX, i, j); |
| 394 |
rsp->hash_mask[NIX_INTF_TX][i][j] = |
| 395 |
GET_KEX_LD_HASH_MASK(NIX_INTF_TX, i, j); |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
for (i = 0; i < NPC_MAX_INTF; i++) |
| 400 |
for (j = 0; j < NPC_MAX_HASH; j++) |
| 401 |
rsp->hash_ctrl[i][j] = GET_KEX_LD_HASH_CTRL(i, j); |
| 402 |
|
| 403 |
return 0; |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
static u64 rvu_exact_prepare_mdata(u8 *mac, u16 chan, u16 ctype, u64 mask) |
| 415 |
{ |
| 416 |
u64 ldata = ether_addr_to_u64(mac); |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
ldata |= ((u64)chan << 48); |
| 422 |
ldata |= ((u64)ctype << 60); |
| 423 |
ldata &= mask; |
| 424 |
ldata = ldata << 2; |
| 425 |
|
| 426 |
return ldata; |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
static u32 rvu_exact_calculate_hash(struct rvu *rvu, u16 chan, u16 ctype, u8 *mac, |
| 440 |
u64 mask, u32 table_depth) |
| 441 |
{ |
| 442 |
struct npc_exact_table *table = rvu->hw->table; |
| 443 |
u64 hash_key[2]; |
| 444 |
u64 key_in[2]; |
| 445 |
u64 ldata; |
| 446 |
u32 hash; |
| 447 |
|
| 448 |
key_in[0] = RVU_NPC_HASH_SECRET_KEY0; |
| 449 |
key_in[1] = RVU_NPC_HASH_SECRET_KEY2; |
| 450 |
|
| 451 |
hash_key[0] = key_in[0] << 31; |
| 452 |
hash_key[0] |= key_in[1]; |
| 453 |
hash_key[1] = key_in[0] >> 33; |
| 454 |
|
| 455 |
ldata = rvu_exact_prepare_mdata(mac, chan, ctype, mask); |
| 456 |
|
| 457 |
dev_dbg(rvu->dev, "%s: ldata=0x%llx hash_key0=0x%llx hash_key2=0x%llx\n", __func__, |
| 458 |
ldata, hash_key[1], hash_key[0]); |
| 459 |
hash = rvu_npc_toeplitz_hash(&ldata, (u64 *)hash_key, 64, 95); |
| 460 |
|
| 461 |
hash &= table->mem_table.hash_mask; |
| 462 |
hash += table->mem_table.hash_offset; |
| 463 |
dev_dbg(rvu->dev, "%s: hash=%x\n", __func__, hash); |
| 464 |
|
| 465 |
return hash; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
static int rvu_npc_exact_alloc_mem_table_entry(struct rvu *rvu, u8 *way, |
| 479 |
u32 *index, unsigned int hash) |
| 480 |
{ |
| 481 |
struct npc_exact_table *table; |
| 482 |
int depth, i; |
| 483 |
|
| 484 |
table = rvu->hw->table; |
| 485 |
depth = table->mem_table.depth; |
| 486 |
|
| 487 |
|
| 488 |
mutex_lock(&table->lock); |
| 489 |
for (i = 0; i < table->mem_table.ways; i++) { |
| 490 |
if (test_bit(hash + i * depth, table->mem_table.bmap)) |
| 491 |
continue; |
| 492 |
|
| 493 |
set_bit(hash + i * depth, table->mem_table.bmap); |
| 494 |
mutex_unlock(&table->lock); |
| 495 |
|
| 496 |
dev_dbg(rvu->dev, "%s: mem table entry alloc success (way=%d index=%d)\n", |
| 497 |
__func__, i, hash); |
| 498 |
|
| 499 |
*way = i; |
| 500 |
*index = hash; |
| 501 |
return 0; |
| 502 |
} |
| 503 |
mutex_unlock(&table->lock); |
| 504 |
|
| 505 |
dev_dbg(rvu->dev, "%s: No space in 4 way exact way, weight=%u\n", __func__, |
| 506 |
bitmap_weight(table->mem_table.bmap, table->mem_table.depth)); |
| 507 |
return -ENOSPC; |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
static void rvu_npc_exact_free_id(struct rvu *rvu, u32 seq_id) |
| 516 |
{ |
| 517 |
struct npc_exact_table *table; |
| 518 |
|
| 519 |
table = rvu->hw->table; |
| 520 |
mutex_lock(&table->lock); |
| 521 |
clear_bit(seq_id, table->id_bmap); |
| 522 |
mutex_unlock(&table->lock); |
| 523 |
dev_dbg(rvu->dev, "%s: freed id %d\n", __func__, seq_id); |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
static bool rvu_npc_exact_alloc_id(struct rvu *rvu, u32 *seq_id) |
| 533 |
{ |
| 534 |
struct npc_exact_table *table; |
| 535 |
u32 idx; |
| 536 |
|
| 537 |
table = rvu->hw->table; |
| 538 |
|
| 539 |
mutex_lock(&table->lock); |
| 540 |
idx = find_first_zero_bit(table->id_bmap, table->tot_ids); |
| 541 |
if (idx == table->tot_ids) { |
| 542 |
mutex_unlock(&table->lock); |
| 543 |
dev_err(rvu->dev, "%s: No space in id bitmap (%d)\n", |
| 544 |
__func__, table->tot_ids); |
| 545 |
|
| 546 |
return false; |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
set_bit(idx, table->id_bmap); |
| 551 |
mutex_unlock(&table->lock); |
| 552 |
|
| 553 |
*seq_id = idx; |
| 554 |
dev_dbg(rvu->dev, "%s: Allocated id (%d)\n", __func__, *seq_id); |
| 555 |
|
| 556 |
return true; |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
static int rvu_npc_exact_alloc_cam_table_entry(struct rvu *rvu, int *index) |
| 566 |
{ |
| 567 |
struct npc_exact_table *table; |
| 568 |
u32 idx; |
| 569 |
|
| 570 |
table = rvu->hw->table; |
| 571 |
|
| 572 |
mutex_lock(&table->lock); |
| 573 |
idx = find_first_zero_bit(table->cam_table.bmap, table->cam_table.depth); |
| 574 |
if (idx == table->cam_table.depth) { |
| 575 |
mutex_unlock(&table->lock); |
| 576 |
dev_info(rvu->dev, "%s: No space in exact cam table, weight=%u\n", __func__, |
| 577 |
bitmap_weight(table->cam_table.bmap, table->cam_table.depth)); |
| 578 |
return -ENOSPC; |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
set_bit(idx, table->cam_table.bmap); |
| 583 |
mutex_unlock(&table->lock); |
| 584 |
|
| 585 |
*index = idx; |
| 586 |
dev_dbg(rvu->dev, "%s: cam table entry alloc success (index=%d)\n", |
| 587 |
__func__, idx); |
| 588 |
return 0; |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
static u64 rvu_exact_prepare_table_entry(struct rvu *rvu, bool enable, |
| 601 |
u8 ctype, u16 chan, u8 *mac_addr) |
| 602 |
|
| 603 |
{ |
| 604 |
u64 ldata = ether_addr_to_u64(mac_addr); |
| 605 |
|
| 606 |
|
| 607 |
u64 mdata = FIELD_PREP(GENMASK_ULL(63, 63), enable ? 1 : 0); |
| 608 |
|
| 609 |
|
| 610 |
mdata |= FIELD_PREP(GENMASK_ULL(61, 60), ctype); |
| 611 |
|
| 612 |
|
| 613 |
mdata |= FIELD_PREP(GENMASK_ULL(59, 48), chan); |
| 614 |
|
| 615 |
|
| 616 |
mdata |= FIELD_PREP(GENMASK_ULL(47, 0), ldata); |
| 617 |
|
| 618 |
return mdata; |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
static void rvu_exact_config_secret_key(struct rvu *rvu) |
| 626 |
{ |
| 627 |
int blkaddr; |
| 628 |
|
| 629 |
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); |
| 630 |
rvu_write64(rvu, blkaddr, NPC_AF_INTFX_EXACT_SECRET0(NIX_INTF_RX), |
| 631 |
RVU_NPC_HASH_SECRET_KEY0); |
| 632 |
|
| 633 |
rvu_write64(rvu, blkaddr, NPC_AF_INTFX_EXACT_SECRET1(NIX_INTF_RX), |
| 634 |
RVU_NPC_HASH_SECRET_KEY1); |
| 635 |
|
| 636 |
rvu_write64(rvu, blkaddr, NPC_AF_INTFX_EXACT_SECRET2(NIX_INTF_RX), |
| 637 |
RVU_NPC_HASH_SECRET_KEY2); |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
static void rvu_exact_config_search_key(struct rvu *rvu) |
| 645 |
{ |
| 646 |
int blkaddr; |
| 647 |
u64 reg_val; |
| 648 |
|
| 649 |
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); |
| 650 |
|
| 651 |
|
| 652 |
reg_val = FIELD_PREP(GENMASK_ULL(39, 32), 0); |
| 653 |
|
| 654 |
|
| 655 |
reg_val |= FIELD_PREP(GENMASK_ULL(18, 16), ETH_ALEN - 1); |
| 656 |
|
| 657 |
|
| 658 |
reg_val |= FIELD_PREP(GENMASK_ULL(11, 11), 1); |
| 659 |
reg_val |= FIELD_PREP(GENMASK_ULL(10, 8), NPC_LID_LA); |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
reg_val |= FIELD_PREP(GENMASK_ULL(12, 12), 0); |
| 665 |
|
| 666 |
|
| 667 |
reg_val |= FIELD_PREP(GENMASK_ULL(7, 4), 0); |
| 668 |
|
| 669 |
|
| 670 |
reg_val |= FIELD_PREP(GENMASK_ULL(3, 0), 0); |
| 671 |
|
| 672 |
rvu_write64(rvu, blkaddr, NPC_AF_INTFX_EXACT_CFG(NIX_INTF_RX), reg_val); |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
static void rvu_exact_config_result_ctrl(struct rvu *rvu, uint32_t depth) |
| 683 |
{ |
| 684 |
int blkaddr; |
| 685 |
u64 reg = 0; |
| 686 |
|
| 687 |
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); |
| 688 |
|
| 689 |
|
| 690 |
rvu->hw->table->mem_table.hash_mask = (depth - 1); |
| 691 |
reg |= FIELD_PREP(GENMASK_ULL(42, 32), (depth - 1)); |
| 692 |
|
| 693 |
|
| 694 |
rvu->hw->table->mem_table.hash_offset = 0; |
| 695 |
reg |= FIELD_PREP(GENMASK_ULL(10, 0), 0); |
| 696 |
|
| 697 |
|
| 698 |
rvu_write64(rvu, blkaddr, NPC_AF_INTFX_EXACT_RESULT_CTL(NIX_INTF_RX), reg); |
| 699 |
|
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
static void rvu_exact_config_table_mask(struct rvu *rvu) |
| 707 |
{ |
| 708 |
int blkaddr; |
| 709 |
u64 mask = 0; |
| 710 |
|
| 711 |
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); |
| 712 |
|
| 713 |
|
| 714 |
mask |= FIELD_PREP(GENMASK_ULL(61, 60), 0); |
| 715 |
|
| 716 |
|
| 717 |
mask |= GENMASK_ULL(59, 48); |
| 718 |
|
| 719 |
|
| 720 |
mask |= GENMASK_ULL(47, 0); |
| 721 |
|
| 722 |
|
| 723 |
rvu->hw->table->mem_table.mask = mask; |
| 724 |
|
| 725 |
|
| 726 |
rvu_write64(rvu, blkaddr, NPC_AF_INTFX_EXACT_MASK(NIX_INTF_RX), mask); |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
u32 rvu_npc_exact_get_max_entries(struct rvu *rvu) |
| 735 |
{ |
| 736 |
struct npc_exact_table *table; |
| 737 |
|
| 738 |
table = rvu->hw->table; |
| 739 |
return table->tot_ids; |
| 740 |
} |
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
bool rvu_npc_exact_has_match_table(struct rvu *rvu) |
| 748 |
{ |
| 749 |
return rvu->hw->cap.npc_exact_match_enabled; |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
static struct npc_exact_table_entry * |
| 761 |
__rvu_npc_exact_find_entry_by_seq_id(struct rvu *rvu, u32 seq_id) |
| 762 |
{ |
| 763 |
struct npc_exact_table *table = rvu->hw->table; |
| 764 |
struct npc_exact_table_entry *entry = NULL; |
| 765 |
struct list_head *lhead; |
| 766 |
|
| 767 |
lhead = &table->lhead_gbl; |
| 768 |
|
| 769 |
|
| 770 |
list_for_each_entry(entry, lhead, glist) { |
| 771 |
if (entry->seq_id != seq_id) |
| 772 |
continue; |
| 773 |
|
| 774 |
return entry; |
| 775 |
} |
| 776 |
|
| 777 |
return NULL; |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
static int rvu_npc_exact_add_to_list(struct rvu *rvu, enum npc_exact_opc_type opc_type, u8 ways, |
| 798 |
u32 index, u8 cgx_id, u8 lmac_id, u8 *mac_addr, u16 chan, |
| 799 |
u8 ctype, u32 *seq_id, bool cmd, u32 mcam_idx, u16 pcifunc) |
| 800 |
{ |
| 801 |
struct npc_exact_table_entry *entry, *tmp, *iter; |
| 802 |
struct npc_exact_table *table = rvu->hw->table; |
| 803 |
struct list_head *lhead, *pprev; |
| 804 |
|
| 805 |
WARN_ON(ways >= NPC_EXACT_TBL_MAX_WAYS); |
| 806 |
|
| 807 |
if (!rvu_npc_exact_alloc_id(rvu, seq_id)) { |
| 808 |
dev_err(rvu->dev, "%s: Generate seq id failed\n", __func__); |
| 809 |
return -EFAULT; |
| 810 |
} |
| 811 |
|
| 812 |
entry = kmalloc_obj(*entry); |
| 813 |
if (!entry) { |
| 814 |
rvu_npc_exact_free_id(rvu, *seq_id); |
| 815 |
dev_err(rvu->dev, "%s: Memory allocation failed\n", __func__); |
| 816 |
return -ENOMEM; |
| 817 |
} |
| 818 |
|
| 819 |
mutex_lock(&table->lock); |
| 820 |
switch (opc_type) { |
| 821 |
case NPC_EXACT_OPC_CAM: |
| 822 |
lhead = &table->lhead_cam_tbl_entry; |
| 823 |
table->cam_tbl_entry_cnt++; |
| 824 |
break; |
| 825 |
|
| 826 |
case NPC_EXACT_OPC_MEM: |
| 827 |
lhead = &table->lhead_mem_tbl_entry[ways]; |
| 828 |
table->mem_tbl_entry_cnt++; |
| 829 |
break; |
| 830 |
|
| 831 |
default: |
| 832 |
mutex_unlock(&table->lock); |
| 833 |
kfree(entry); |
| 834 |
rvu_npc_exact_free_id(rvu, *seq_id); |
| 835 |
|
| 836 |
dev_err(rvu->dev, "%s: Unknown opc type%d\n", __func__, opc_type); |
| 837 |
return -EINVAL; |
| 838 |
} |
| 839 |
|
| 840 |
|
| 841 |
INIT_LIST_HEAD(&entry->glist); |
| 842 |
list_add_tail(&entry->glist, &table->lhead_gbl); |
| 843 |
INIT_LIST_HEAD(&entry->list); |
| 844 |
entry->index = index; |
| 845 |
entry->ways = ways; |
| 846 |
entry->opc_type = opc_type; |
| 847 |
|
| 848 |
entry->pcifunc = pcifunc; |
| 849 |
|
| 850 |
ether_addr_copy(entry->mac, mac_addr); |
| 851 |
entry->chan = chan; |
| 852 |
entry->ctype = ctype; |
| 853 |
entry->cgx_id = cgx_id; |
| 854 |
entry->lmac_id = lmac_id; |
| 855 |
|
| 856 |
entry->seq_id = *seq_id; |
| 857 |
|
| 858 |
entry->mcam_idx = mcam_idx; |
| 859 |
entry->cmd = cmd; |
| 860 |
|
| 861 |
pprev = lhead; |
| 862 |
|
| 863 |
|
| 864 |
list_for_each_entry_safe(iter, tmp, lhead, list) { |
| 865 |
if (index < iter->index) |
| 866 |
break; |
| 867 |
|
| 868 |
pprev = &iter->list; |
| 869 |
} |
| 870 |
|
| 871 |
|
| 872 |
list_add(&entry->list, pprev); |
| 873 |
mutex_unlock(&table->lock); |
| 874 |
return 0; |
| 875 |
} |
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
static void rvu_npc_exact_mem_table_write(struct rvu *rvu, int blkaddr, u8 ways, |
| 886 |
u32 index, u64 mdata) |
| 887 |
{ |
| 888 |
rvu_write64(rvu, blkaddr, NPC_AF_EXACT_MEM_ENTRY(ways, index), mdata); |
| 889 |
} |
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
static void rvu_npc_exact_cam_table_write(struct rvu *rvu, int blkaddr, |
| 899 |
u32 index, u64 mdata) |
| 900 |
{ |
| 901 |
rvu_write64(rvu, blkaddr, NPC_AF_EXACT_CAM_ENTRY(index), mdata); |
| 902 |
} |
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
static int rvu_npc_exact_dealloc_table_entry(struct rvu *rvu, enum npc_exact_opc_type opc_type, |
| 913 |
u8 ways, u32 index) |
| 914 |
{ |
| 915 |
int blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); |
| 916 |
struct npc_exact_table *table; |
| 917 |
u8 null_dmac[6] = { 0 }; |
| 918 |
int depth; |
| 919 |
|
| 920 |
|
| 921 |
u64 null_mdata = rvu_exact_prepare_table_entry(rvu, false, 0, 0, null_dmac); |
| 922 |
|
| 923 |
table = rvu->hw->table; |
| 924 |
depth = table->mem_table.depth; |
| 925 |
|
| 926 |
mutex_lock(&table->lock); |
| 927 |
|
| 928 |
switch (opc_type) { |
| 929 |
case NPC_EXACT_OPC_CAM: |
| 930 |
|
| 931 |
|
| 932 |
if (!test_bit(index, table->cam_table.bmap)) { |
| 933 |
mutex_unlock(&table->lock); |
| 934 |
dev_err(rvu->dev, "%s: Trying to free an unused entry ways=%d index=%d\n", |
| 935 |
__func__, ways, index); |
| 936 |
return -EINVAL; |
| 937 |
} |
| 938 |
|
| 939 |
rvu_npc_exact_cam_table_write(rvu, blkaddr, index, null_mdata); |
| 940 |
clear_bit(index, table->cam_table.bmap); |
| 941 |
break; |
| 942 |
|
| 943 |
case NPC_EXACT_OPC_MEM: |
| 944 |
|
| 945 |
|
| 946 |
if (!test_bit(index + ways * depth, table->mem_table.bmap)) { |
| 947 |
mutex_unlock(&table->lock); |
| 948 |
dev_err(rvu->dev, "%s: Trying to free an unused entry index=%d\n", |
| 949 |
__func__, index); |
| 950 |
return -EINVAL; |
| 951 |
} |
| 952 |
|
| 953 |
rvu_npc_exact_mem_table_write(rvu, blkaddr, ways, index, null_mdata); |
| 954 |
clear_bit(index + ways * depth, table->mem_table.bmap); |
| 955 |
break; |
| 956 |
|
| 957 |
default: |
| 958 |
mutex_unlock(&table->lock); |
| 959 |
dev_err(rvu->dev, "%s: invalid opc type %d", __func__, opc_type); |
| 960 |
return -ENOSPC; |
| 961 |
} |
| 962 |
|
| 963 |
mutex_unlock(&table->lock); |
| 964 |
|
| 965 |
dev_dbg(rvu->dev, "%s: Successfully deleted entry (index=%d, ways=%d opc_type=%d\n", |
| 966 |
__func__, index, ways, opc_type); |
| 967 |
|
| 968 |
return 0; |
| 969 |
} |
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
static int rvu_npc_exact_alloc_table_entry(struct rvu *rvu, char *mac, u16 chan, u8 ctype, |
| 987 |
u32 *index, u8 *ways, enum npc_exact_opc_type *opc_type) |
| 988 |
{ |
| 989 |
struct npc_exact_table *table; |
| 990 |
unsigned int hash; |
| 991 |
int err; |
| 992 |
|
| 993 |
table = rvu->hw->table; |
| 994 |
|
| 995 |
|
| 996 |
hash = rvu_exact_calculate_hash(rvu, chan, ctype, mac, table->mem_table.mask, |
| 997 |
table->mem_table.depth); |
| 998 |
err = rvu_npc_exact_alloc_mem_table_entry(rvu, ways, index, hash); |
| 999 |
if (!err) { |
| 1000 |
*opc_type = NPC_EXACT_OPC_MEM; |
| 1001 |
dev_dbg(rvu->dev, "%s: inserted in 4 ways hash table ways=%d, index=%d\n", |
| 1002 |
__func__, *ways, *index); |
| 1003 |
return 0; |
| 1004 |
} |
| 1005 |
|
| 1006 |
dev_dbg(rvu->dev, "%s: failed to insert in 4 ways hash table\n", __func__); |
| 1007 |
|
| 1008 |
|
| 1009 |
*ways = 0; |
| 1010 |
err = rvu_npc_exact_alloc_cam_table_entry(rvu, index); |
| 1011 |
if (!err) { |
| 1012 |
*opc_type = NPC_EXACT_OPC_CAM; |
| 1013 |
dev_dbg(rvu->dev, "%s: inserted in fully associative hash table index=%u\n", |
| 1014 |
__func__, *index); |
| 1015 |
return 0; |
| 1016 |
} |
| 1017 |
|
| 1018 |
dev_err(rvu->dev, "%s: failed to insert in fully associative hash table\n", __func__); |
| 1019 |
return -ENOSPC; |
| 1020 |
} |
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
static bool rvu_npc_exact_save_drop_rule_chan_and_mask(struct rvu *rvu, int drop_mcam_idx, |
| 1032 |
u64 chan_val, u64 chan_mask, u16 pcifunc) |
| 1033 |
{ |
| 1034 |
struct npc_exact_table *table; |
| 1035 |
int i; |
| 1036 |
|
| 1037 |
table = rvu->hw->table; |
| 1038 |
|
| 1039 |
for (i = 0; i < NPC_MCAM_DROP_RULE_MAX; i++) { |
| 1040 |
if (!table->drop_rule_map[i].valid) |
| 1041 |
break; |
| 1042 |
|
| 1043 |
if (table->drop_rule_map[i].chan_val != (u16)chan_val) |
| 1044 |
continue; |
| 1045 |
|
| 1046 |
if (table->drop_rule_map[i].chan_mask != (u16)chan_mask) |
| 1047 |
continue; |
| 1048 |
|
| 1049 |
return false; |
| 1050 |
} |
| 1051 |
|
| 1052 |
if (i == NPC_MCAM_DROP_RULE_MAX) |
| 1053 |
return false; |
| 1054 |
|
| 1055 |
table->drop_rule_map[i].drop_rule_idx = drop_mcam_idx; |
| 1056 |
table->drop_rule_map[i].chan_val = (u16)chan_val; |
| 1057 |
table->drop_rule_map[i].chan_mask = (u16)chan_mask; |
| 1058 |
table->drop_rule_map[i].pcifunc = pcifunc; |
| 1059 |
table->drop_rule_map[i].valid = true; |
| 1060 |
return true; |
| 1061 |
} |
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
static bool rvu_npc_exact_calc_drop_rule_chan_and_mask(struct rvu *rvu, u8 intf_type, |
| 1074 |
u8 cgx_id, u8 lmac_id, |
| 1075 |
u64 *val, u64 *mask) |
| 1076 |
{ |
| 1077 |
u16 chan_val, chan_mask; |
| 1078 |
|
| 1079 |
|
| 1080 |
if (intf_type != NIX_INTF_TYPE_CGX) |
| 1081 |
return false; |
| 1082 |
|
| 1083 |
chan_val = rvu_nix_chan_cgx(rvu, cgx_id, lmac_id, 0); |
| 1084 |
chan_mask = 0xfff; |
| 1085 |
|
| 1086 |
if (val) |
| 1087 |
*val = chan_val; |
| 1088 |
|
| 1089 |
if (mask) |
| 1090 |
*mask = chan_mask; |
| 1091 |
|
| 1092 |
return true; |
| 1093 |
} |
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
u16 rvu_npc_exact_drop_rule_to_pcifunc(struct rvu *rvu, u32 drop_rule_idx) |
| 1105 |
{ |
| 1106 |
struct npc_exact_table *table; |
| 1107 |
int i; |
| 1108 |
|
| 1109 |
table = rvu->hw->table; |
| 1110 |
|
| 1111 |
for (i = 0; i < NPC_MCAM_DROP_RULE_MAX; i++) { |
| 1112 |
if (!table->drop_rule_map[i].valid) |
| 1113 |
break; |
| 1114 |
|
| 1115 |
if (table->drop_rule_map[i].drop_rule_idx != drop_rule_idx) |
| 1116 |
continue; |
| 1117 |
|
| 1118 |
return table->drop_rule_map[i].pcifunc; |
| 1119 |
} |
| 1120 |
|
| 1121 |
dev_err(rvu->dev, "%s: drop mcam rule index (%d) >= NPC_MCAM_DROP_RULE_MAX\n", |
| 1122 |
__func__, drop_rule_idx); |
| 1123 |
return -1; |
| 1124 |
} |
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
static bool rvu_npc_exact_get_drop_rule_info(struct rvu *rvu, u8 intf_type, u8 cgx_id, |
| 1139 |
u8 lmac_id, u32 *drop_mcam_idx, u64 *val, |
| 1140 |
u64 *mask, u16 *pcifunc) |
| 1141 |
{ |
| 1142 |
struct npc_exact_table *table; |
| 1143 |
u64 chan_val, chan_mask; |
| 1144 |
bool rc; |
| 1145 |
int i; |
| 1146 |
|
| 1147 |
table = rvu->hw->table; |
| 1148 |
|
| 1149 |
if (intf_type != NIX_INTF_TYPE_CGX) { |
| 1150 |
dev_err(rvu->dev, "%s: No drop rule for LBK/SDP mode\n", __func__); |
| 1151 |
return false; |
| 1152 |
} |
| 1153 |
|
| 1154 |
rc = rvu_npc_exact_calc_drop_rule_chan_and_mask(rvu, intf_type, cgx_id, |
| 1155 |
lmac_id, &chan_val, &chan_mask); |
| 1156 |
if (!rc) |
| 1157 |
return false; |
| 1158 |
|
| 1159 |
for (i = 0; i < NPC_MCAM_DROP_RULE_MAX; i++) { |
| 1160 |
if (!table->drop_rule_map[i].valid) |
| 1161 |
break; |
| 1162 |
|
| 1163 |
if (table->drop_rule_map[i].chan_val != (u16)chan_val) |
| 1164 |
continue; |
| 1165 |
|
| 1166 |
if (val) |
| 1167 |
*val = table->drop_rule_map[i].chan_val; |
| 1168 |
if (mask) |
| 1169 |
*mask = table->drop_rule_map[i].chan_mask; |
| 1170 |
if (pcifunc) |
| 1171 |
*pcifunc = table->drop_rule_map[i].pcifunc; |
| 1172 |
|
| 1173 |
*drop_mcam_idx = i; |
| 1174 |
return true; |
| 1175 |
} |
| 1176 |
|
| 1177 |
if (i == NPC_MCAM_DROP_RULE_MAX) { |
| 1178 |
dev_err(rvu->dev, "%s: drop mcam rule index (%d) >= NPC_MCAM_DROP_RULE_MAX\n", |
| 1179 |
__func__, *drop_mcam_idx); |
| 1180 |
return false; |
| 1181 |
} |
| 1182 |
|
| 1183 |
dev_err(rvu->dev, "%s: Could not retrieve for cgx=%d, lmac=%d\n", |
| 1184 |
__func__, cgx_id, lmac_id); |
| 1185 |
return false; |
| 1186 |
} |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
static u16 __rvu_npc_exact_cmd_rules_cnt_update(struct rvu *rvu, int drop_mcam_idx, |
| 1201 |
int val, bool *enable_or_disable_cam) |
| 1202 |
{ |
| 1203 |
struct npc_exact_table *table; |
| 1204 |
u16 *cnt, old_cnt; |
| 1205 |
bool promisc; |
| 1206 |
|
| 1207 |
table = rvu->hw->table; |
| 1208 |
promisc = table->promisc_mode[drop_mcam_idx]; |
| 1209 |
|
| 1210 |
cnt = &table->cnt_cmd_rules[drop_mcam_idx]; |
| 1211 |
old_cnt = *cnt; |
| 1212 |
|
| 1213 |
*cnt += val; |
| 1214 |
|
| 1215 |
if (!enable_or_disable_cam) |
| 1216 |
goto done; |
| 1217 |
|
| 1218 |
*enable_or_disable_cam = false; |
| 1219 |
|
| 1220 |
if (promisc) |
| 1221 |
goto done; |
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
if (!*cnt && val < 0) { |
| 1227 |
*enable_or_disable_cam = true; |
| 1228 |
goto done; |
| 1229 |
} |
| 1230 |
|
| 1231 |
|
| 1232 |
if (!old_cnt && val > 0) { |
| 1233 |
*enable_or_disable_cam = true; |
| 1234 |
goto done; |
| 1235 |
} |
| 1236 |
|
| 1237 |
done: |
| 1238 |
return *cnt; |
| 1239 |
} |
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
static int rvu_npc_exact_del_table_entry_by_id(struct rvu *rvu, u32 seq_id) |
| 1251 |
{ |
| 1252 |
struct npc_exact_table_entry *entry = NULL; |
| 1253 |
struct npc_exact_table *table; |
| 1254 |
bool disable_cam = false; |
| 1255 |
u32 drop_mcam_idx = -1; |
| 1256 |
int *cnt; |
| 1257 |
bool rc; |
| 1258 |
|
| 1259 |
table = rvu->hw->table; |
| 1260 |
|
| 1261 |
mutex_lock(&table->lock); |
| 1262 |
|
| 1263 |
|
| 1264 |
entry = __rvu_npc_exact_find_entry_by_seq_id(rvu, seq_id); |
| 1265 |
if (!entry) { |
| 1266 |
dev_dbg(rvu->dev, "%s: failed to find entry for id=%d\n", __func__, seq_id); |
| 1267 |
mutex_unlock(&table->lock); |
| 1268 |
return -ENODATA; |
| 1269 |
} |
| 1270 |
|
| 1271 |
cnt = (entry->opc_type == NPC_EXACT_OPC_CAM) ? &table->cam_tbl_entry_cnt : |
| 1272 |
&table->mem_tbl_entry_cnt; |
| 1273 |
|
| 1274 |
|
| 1275 |
list_del_init(&entry->list); |
| 1276 |
list_del_init(&entry->glist); |
| 1277 |
|
| 1278 |
(*cnt)--; |
| 1279 |
|
| 1280 |
rc = rvu_npc_exact_get_drop_rule_info(rvu, NIX_INTF_TYPE_CGX, entry->cgx_id, |
| 1281 |
entry->lmac_id, &drop_mcam_idx, NULL, NULL, NULL); |
| 1282 |
if (!rc) { |
| 1283 |
dev_dbg(rvu->dev, "%s: failed to retrieve drop info for id=0x%x\n", |
| 1284 |
__func__, seq_id); |
| 1285 |
mutex_unlock(&table->lock); |
| 1286 |
return -ENODATA; |
| 1287 |
} |
| 1288 |
|
| 1289 |
if (entry->cmd) |
| 1290 |
__rvu_npc_exact_cmd_rules_cnt_update(rvu, drop_mcam_idx, -1, &disable_cam); |
| 1291 |
|
| 1292 |
|
| 1293 |
if (disable_cam) { |
| 1294 |
rvu_npc_enable_mcam_by_entry_index(rvu, drop_mcam_idx, NIX_INTF_RX, false); |
| 1295 |
dev_dbg(rvu->dev, "%s: Disabling mcam idx %d\n", |
| 1296 |
__func__, drop_mcam_idx); |
| 1297 |
} |
| 1298 |
|
| 1299 |
mutex_unlock(&table->lock); |
| 1300 |
|
| 1301 |
rvu_npc_exact_dealloc_table_entry(rvu, entry->opc_type, entry->ways, entry->index); |
| 1302 |
|
| 1303 |
rvu_npc_exact_free_id(rvu, seq_id); |
| 1304 |
|
| 1305 |
dev_dbg(rvu->dev, "%s: delete entry success for id=0x%x, mca=%pM\n", |
| 1306 |
__func__, seq_id, entry->mac); |
| 1307 |
kfree(entry); |
| 1308 |
|
| 1309 |
return 0; |
| 1310 |
} |
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
static int rvu_npc_exact_add_table_entry(struct rvu *rvu, u8 cgx_id, u8 lmac_id, u8 *mac, |
| 1330 |
u16 chan, u8 ctype, u32 *seq_id, bool cmd, |
| 1331 |
u32 mcam_idx, u16 pcifunc) |
| 1332 |
{ |
| 1333 |
int blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); |
| 1334 |
enum npc_exact_opc_type opc_type; |
| 1335 |
bool enable_cam = false; |
| 1336 |
u32 drop_mcam_idx; |
| 1337 |
u32 index; |
| 1338 |
u64 mdata; |
| 1339 |
bool rc; |
| 1340 |
int err; |
| 1341 |
u8 ways; |
| 1342 |
|
| 1343 |
ctype = 0; |
| 1344 |
|
| 1345 |
err = rvu_npc_exact_alloc_table_entry(rvu, mac, chan, ctype, &index, &ways, &opc_type); |
| 1346 |
if (err) { |
| 1347 |
dev_err(rvu->dev, "%s: Could not alloc in exact match table\n", __func__); |
| 1348 |
return err; |
| 1349 |
} |
| 1350 |
|
| 1351 |
|
| 1352 |
mdata = rvu_exact_prepare_table_entry(rvu, true, ctype, chan, mac); |
| 1353 |
|
| 1354 |
if (opc_type == NPC_EXACT_OPC_CAM) |
| 1355 |
rvu_npc_exact_cam_table_write(rvu, blkaddr, index, mdata); |
| 1356 |
else |
| 1357 |
rvu_npc_exact_mem_table_write(rvu, blkaddr, ways, index, mdata); |
| 1358 |
|
| 1359 |
|
| 1360 |
err = rvu_npc_exact_add_to_list(rvu, opc_type, ways, index, cgx_id, lmac_id, |
| 1361 |
mac, chan, ctype, seq_id, cmd, mcam_idx, pcifunc); |
| 1362 |
if (err) { |
| 1363 |
rvu_npc_exact_dealloc_table_entry(rvu, opc_type, ways, index); |
| 1364 |
dev_err(rvu->dev, "%s: could not add to exact match table\n", __func__); |
| 1365 |
return err; |
| 1366 |
} |
| 1367 |
|
| 1368 |
rc = rvu_npc_exact_get_drop_rule_info(rvu, NIX_INTF_TYPE_CGX, cgx_id, lmac_id, |
| 1369 |
&drop_mcam_idx, NULL, NULL, NULL); |
| 1370 |
if (!rc) { |
| 1371 |
rvu_npc_exact_dealloc_table_entry(rvu, opc_type, ways, index); |
| 1372 |
dev_dbg(rvu->dev, "%s: failed to get drop rule info cgx=%d lmac=%d\n", |
| 1373 |
__func__, cgx_id, lmac_id); |
| 1374 |
return -EINVAL; |
| 1375 |
} |
| 1376 |
|
| 1377 |
if (cmd) |
| 1378 |
__rvu_npc_exact_cmd_rules_cnt_update(rvu, drop_mcam_idx, 1, &enable_cam); |
| 1379 |
|
| 1380 |
|
| 1381 |
if (enable_cam) { |
| 1382 |
rvu_npc_enable_mcam_by_entry_index(rvu, drop_mcam_idx, NIX_INTF_RX, true); |
| 1383 |
dev_dbg(rvu->dev, "%s: Enabling mcam idx %d\n", |
| 1384 |
__func__, drop_mcam_idx); |
| 1385 |
} |
| 1386 |
|
| 1387 |
dev_dbg(rvu->dev, |
| 1388 |
"%s: Successfully added entry (index=%d, dmac=%pM, ways=%d opc_type=%d\n", |
| 1389 |
__func__, index, mac, ways, opc_type); |
| 1390 |
|
| 1391 |
return 0; |
| 1392 |
} |
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
static int rvu_npc_exact_update_table_entry(struct rvu *rvu, u8 cgx_id, u8 lmac_id, |
| 1408 |
u8 *old_mac, u8 *new_mac, u32 *seq_id) |
| 1409 |
{ |
| 1410 |
int blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); |
| 1411 |
struct npc_exact_table_entry *entry; |
| 1412 |
struct npc_exact_table *table; |
| 1413 |
u32 hash_index; |
| 1414 |
u64 mdata; |
| 1415 |
|
| 1416 |
table = rvu->hw->table; |
| 1417 |
|
| 1418 |
mutex_lock(&table->lock); |
| 1419 |
|
| 1420 |
|
| 1421 |
entry = __rvu_npc_exact_find_entry_by_seq_id(rvu, *seq_id); |
| 1422 |
if (!entry) { |
| 1423 |
mutex_unlock(&table->lock); |
| 1424 |
dev_dbg(rvu->dev, |
| 1425 |
"%s: failed to find entry for cgx_id=%d lmac_id=%d old_mac=%pM\n", |
| 1426 |
__func__, cgx_id, lmac_id, old_mac); |
| 1427 |
return -ENODATA; |
| 1428 |
} |
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
if (entry->opc_type == NPC_EXACT_OPC_MEM) { |
| 1434 |
hash_index = rvu_exact_calculate_hash(rvu, entry->chan, entry->ctype, |
| 1435 |
new_mac, table->mem_table.mask, |
| 1436 |
table->mem_table.depth); |
| 1437 |
if (hash_index != entry->index) { |
| 1438 |
dev_dbg(rvu->dev, |
| 1439 |
"%s: Update failed due to index mismatch(new=0x%x, old=%x)\n", |
| 1440 |
__func__, hash_index, entry->index); |
| 1441 |
mutex_unlock(&table->lock); |
| 1442 |
return -EINVAL; |
| 1443 |
} |
| 1444 |
} |
| 1445 |
|
| 1446 |
mdata = rvu_exact_prepare_table_entry(rvu, true, entry->ctype, entry->chan, new_mac); |
| 1447 |
|
| 1448 |
if (entry->opc_type == NPC_EXACT_OPC_MEM) |
| 1449 |
rvu_npc_exact_mem_table_write(rvu, blkaddr, entry->ways, entry->index, mdata); |
| 1450 |
else |
| 1451 |
rvu_npc_exact_cam_table_write(rvu, blkaddr, entry->index, mdata); |
| 1452 |
|
| 1453 |
|
| 1454 |
ether_addr_copy(entry->mac, new_mac); |
| 1455 |
*seq_id = entry->seq_id; |
| 1456 |
|
| 1457 |
dev_dbg(rvu->dev, |
| 1458 |
"%s: Successfully updated entry (index=%d, dmac=%pM, ways=%d opc_type=%d\n", |
| 1459 |
__func__, entry->index, entry->mac, entry->ways, entry->opc_type); |
| 1460 |
|
| 1461 |
dev_dbg(rvu->dev, "%s: Successfully updated entry (old mac=%pM new_mac=%pM\n", |
| 1462 |
__func__, old_mac, new_mac); |
| 1463 |
|
| 1464 |
mutex_unlock(&table->lock); |
| 1465 |
return 0; |
| 1466 |
} |
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
int rvu_npc_exact_promisc_disable(struct rvu *rvu, u16 pcifunc) |
| 1479 |
{ |
| 1480 |
struct npc_exact_table *table; |
| 1481 |
int pf = rvu_get_pf(rvu->pdev, pcifunc); |
| 1482 |
u8 cgx_id, lmac_id; |
| 1483 |
u32 drop_mcam_idx; |
| 1484 |
bool *promisc; |
| 1485 |
bool rc; |
| 1486 |
|
| 1487 |
table = rvu->hw->table; |
| 1488 |
|
| 1489 |
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); |
| 1490 |
rc = rvu_npc_exact_get_drop_rule_info(rvu, NIX_INTF_TYPE_CGX, cgx_id, lmac_id, |
| 1491 |
&drop_mcam_idx, NULL, NULL, NULL); |
| 1492 |
if (!rc) { |
| 1493 |
dev_dbg(rvu->dev, "%s: failed to get drop rule info cgx=%d lmac=%d\n", |
| 1494 |
__func__, cgx_id, lmac_id); |
| 1495 |
return -EINVAL; |
| 1496 |
} |
| 1497 |
|
| 1498 |
mutex_lock(&table->lock); |
| 1499 |
promisc = &table->promisc_mode[drop_mcam_idx]; |
| 1500 |
|
| 1501 |
if (!*promisc) { |
| 1502 |
mutex_unlock(&table->lock); |
| 1503 |
dev_dbg(rvu->dev, "%s: Err Already promisc mode disabled (cgx=%d lmac=%d)\n", |
| 1504 |
__func__, cgx_id, lmac_id); |
| 1505 |
return LMAC_AF_ERR_INVALID_PARAM; |
| 1506 |
} |
| 1507 |
*promisc = false; |
| 1508 |
mutex_unlock(&table->lock); |
| 1509 |
|
| 1510 |
|
| 1511 |
rvu_npc_enable_mcam_by_entry_index(rvu, drop_mcam_idx, NIX_INTF_RX, |
| 1512 |
true); |
| 1513 |
|
| 1514 |
dev_dbg(rvu->dev, "%s: disabled promisc mode (cgx=%d lmac=%d)\n", |
| 1515 |
__func__, cgx_id, lmac_id); |
| 1516 |
return 0; |
| 1517 |
} |
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
int rvu_npc_exact_promisc_enable(struct rvu *rvu, u16 pcifunc) |
| 1526 |
{ |
| 1527 |
struct npc_exact_table *table; |
| 1528 |
int pf = rvu_get_pf(rvu->pdev, pcifunc); |
| 1529 |
u8 cgx_id, lmac_id; |
| 1530 |
u32 drop_mcam_idx; |
| 1531 |
bool *promisc; |
| 1532 |
bool rc; |
| 1533 |
|
| 1534 |
table = rvu->hw->table; |
| 1535 |
|
| 1536 |
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); |
| 1537 |
rc = rvu_npc_exact_get_drop_rule_info(rvu, NIX_INTF_TYPE_CGX, cgx_id, lmac_id, |
| 1538 |
&drop_mcam_idx, NULL, NULL, NULL); |
| 1539 |
if (!rc) { |
| 1540 |
dev_dbg(rvu->dev, "%s: failed to get drop rule info cgx=%d lmac=%d\n", |
| 1541 |
__func__, cgx_id, lmac_id); |
| 1542 |
return -EINVAL; |
| 1543 |
} |
| 1544 |
|
| 1545 |
mutex_lock(&table->lock); |
| 1546 |
promisc = &table->promisc_mode[drop_mcam_idx]; |
| 1547 |
|
| 1548 |
if (*promisc) { |
| 1549 |
mutex_unlock(&table->lock); |
| 1550 |
dev_dbg(rvu->dev, "%s: Already in promisc mode (cgx=%d lmac=%d)\n", |
| 1551 |
__func__, cgx_id, lmac_id); |
| 1552 |
return LMAC_AF_ERR_INVALID_PARAM; |
| 1553 |
} |
| 1554 |
*promisc = true; |
| 1555 |
mutex_unlock(&table->lock); |
| 1556 |
|
| 1557 |
|
| 1558 |
rvu_npc_enable_mcam_by_entry_index(rvu, drop_mcam_idx, NIX_INTF_RX, |
| 1559 |
false); |
| 1560 |
|
| 1561 |
dev_dbg(rvu->dev, "%s: Enabled promisc mode (cgx=%d lmac=%d)\n", |
| 1562 |
__func__, cgx_id, lmac_id); |
| 1563 |
return 0; |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
int rvu_npc_exact_mac_addr_reset(struct rvu *rvu, struct cgx_mac_addr_reset_req *req, |
| 1574 |
struct msg_rsp *rsp) |
| 1575 |
{ |
| 1576 |
int pf = rvu_get_pf(rvu->pdev, req->hdr.pcifunc); |
| 1577 |
u32 seq_id = req->index; |
| 1578 |
struct rvu_pfvf *pfvf; |
| 1579 |
u8 cgx_id, lmac_id; |
| 1580 |
int rc; |
| 1581 |
|
| 1582 |
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); |
| 1583 |
|
| 1584 |
pfvf = rvu_get_pfvf(rvu, req->hdr.pcifunc); |
| 1585 |
|
| 1586 |
rc = rvu_npc_exact_del_table_entry_by_id(rvu, seq_id); |
| 1587 |
if (rc) { |
| 1588 |
|
| 1589 |
dev_err(rvu->dev, "%s MAC (%pM) del PF=%d failed\n", __func__, pfvf->mac_addr, pf); |
| 1590 |
return 0; |
| 1591 |
} |
| 1592 |
|
| 1593 |
dev_dbg(rvu->dev, "%s MAC (%pM) del PF=%d success (seq_id=%u)\n", |
| 1594 |
__func__, pfvf->mac_addr, pf, seq_id); |
| 1595 |
return 0; |
| 1596 |
} |
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
int rvu_npc_exact_mac_addr_update(struct rvu *rvu, |
| 1606 |
struct cgx_mac_addr_update_req *req, |
| 1607 |
struct cgx_mac_addr_update_rsp *rsp) |
| 1608 |
{ |
| 1609 |
int pf = rvu_get_pf(rvu->pdev, req->hdr.pcifunc); |
| 1610 |
struct npc_exact_table_entry *entry; |
| 1611 |
struct npc_exact_table *table; |
| 1612 |
struct rvu_pfvf *pfvf; |
| 1613 |
u32 seq_id, mcam_idx; |
| 1614 |
u8 old_mac[ETH_ALEN]; |
| 1615 |
u8 cgx_id, lmac_id; |
| 1616 |
int rc; |
| 1617 |
|
| 1618 |
if (!is_cgx_config_permitted(rvu, req->hdr.pcifunc)) |
| 1619 |
return LMAC_AF_ERR_PERM_DENIED; |
| 1620 |
|
| 1621 |
dev_dbg(rvu->dev, "%s: Update request for seq_id=%d, mac=%pM\n", |
| 1622 |
__func__, req->index, req->mac_addr); |
| 1623 |
|
| 1624 |
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); |
| 1625 |
|
| 1626 |
pfvf = rvu_get_pfvf(rvu, req->hdr.pcifunc); |
| 1627 |
|
| 1628 |
table = rvu->hw->table; |
| 1629 |
|
| 1630 |
mutex_lock(&table->lock); |
| 1631 |
|
| 1632 |
|
| 1633 |
entry = __rvu_npc_exact_find_entry_by_seq_id(rvu, req->index); |
| 1634 |
if (!entry) { |
| 1635 |
dev_err(rvu->dev, "%s: failed to find entry for id=0x%x\n", __func__, req->index); |
| 1636 |
mutex_unlock(&table->lock); |
| 1637 |
return LMAC_AF_ERR_EXACT_MATCH_TBL_LOOK_UP_FAILED; |
| 1638 |
} |
| 1639 |
ether_addr_copy(old_mac, entry->mac); |
| 1640 |
seq_id = entry->seq_id; |
| 1641 |
mcam_idx = entry->mcam_idx; |
| 1642 |
mutex_unlock(&table->lock); |
| 1643 |
|
| 1644 |
rc = rvu_npc_exact_update_table_entry(rvu, cgx_id, lmac_id, old_mac, |
| 1645 |
req->mac_addr, &seq_id); |
| 1646 |
if (!rc) { |
| 1647 |
rsp->index = seq_id; |
| 1648 |
dev_dbg(rvu->dev, "%s mac:%pM (pfvf:%pM default:%pM) update to PF=%d success\n", |
| 1649 |
__func__, req->mac_addr, pfvf->mac_addr, pfvf->default_mac, pf); |
| 1650 |
ether_addr_copy(pfvf->mac_addr, req->mac_addr); |
| 1651 |
return 0; |
| 1652 |
} |
| 1653 |
|
| 1654 |
|
| 1655 |
rc = rvu_npc_exact_del_table_entry_by_id(rvu, req->index); |
| 1656 |
if (rc) { |
| 1657 |
|
| 1658 |
dev_dbg(rvu->dev, "%s MAC (%pM) del PF=%d failed\n", __func__, |
| 1659 |
pfvf->mac_addr, pf); |
| 1660 |
} |
| 1661 |
|
| 1662 |
rc = rvu_npc_exact_add_table_entry(rvu, cgx_id, lmac_id, req->mac_addr, |
| 1663 |
pfvf->rx_chan_base, 0, &seq_id, true, |
| 1664 |
mcam_idx, req->hdr.pcifunc); |
| 1665 |
if (rc) { |
| 1666 |
dev_err(rvu->dev, "%s MAC (%pM) add PF=%d failed\n", __func__, |
| 1667 |
req->mac_addr, pf); |
| 1668 |
return LMAC_AF_ERR_EXACT_MATCH_TBL_ADD_FAILED; |
| 1669 |
} |
| 1670 |
|
| 1671 |
rsp->index = seq_id; |
| 1672 |
dev_dbg(rvu->dev, |
| 1673 |
"%s MAC (new:%pM, old=%pM default:%pM) del and add to PF=%d success (seq_id=%u)\n", |
| 1674 |
__func__, req->mac_addr, pfvf->mac_addr, pfvf->default_mac, pf, seq_id); |
| 1675 |
|
| 1676 |
ether_addr_copy(pfvf->mac_addr, req->mac_addr); |
| 1677 |
return 0; |
| 1678 |
} |
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
int rvu_npc_exact_mac_addr_add(struct rvu *rvu, |
| 1688 |
struct cgx_mac_addr_add_req *req, |
| 1689 |
struct cgx_mac_addr_add_rsp *rsp) |
| 1690 |
{ |
| 1691 |
int pf = rvu_get_pf(rvu->pdev, req->hdr.pcifunc); |
| 1692 |
struct rvu_pfvf *pfvf; |
| 1693 |
u8 cgx_id, lmac_id; |
| 1694 |
int rc = 0; |
| 1695 |
u32 seq_id; |
| 1696 |
|
| 1697 |
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); |
| 1698 |
pfvf = rvu_get_pfvf(rvu, req->hdr.pcifunc); |
| 1699 |
|
| 1700 |
rc = rvu_npc_exact_add_table_entry(rvu, cgx_id, lmac_id, req->mac_addr, |
| 1701 |
pfvf->rx_chan_base, 0, &seq_id, |
| 1702 |
true, -1, req->hdr.pcifunc); |
| 1703 |
|
| 1704 |
if (!rc) { |
| 1705 |
rsp->index = seq_id; |
| 1706 |
dev_dbg(rvu->dev, "%s MAC (%pM) add to PF=%d success (seq_id=%u)\n", |
| 1707 |
__func__, req->mac_addr, pf, seq_id); |
| 1708 |
return 0; |
| 1709 |
} |
| 1710 |
|
| 1711 |
dev_err(rvu->dev, "%s MAC (%pM) add to PF=%d failed\n", __func__, |
| 1712 |
req->mac_addr, pf); |
| 1713 |
return LMAC_AF_ERR_EXACT_MATCH_TBL_ADD_FAILED; |
| 1714 |
} |
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
int rvu_npc_exact_mac_addr_del(struct rvu *rvu, |
| 1724 |
struct cgx_mac_addr_del_req *req, |
| 1725 |
struct msg_rsp *rsp) |
| 1726 |
{ |
| 1727 |
int pf = rvu_get_pf(rvu->pdev, req->hdr.pcifunc); |
| 1728 |
int rc; |
| 1729 |
|
| 1730 |
rc = rvu_npc_exact_del_table_entry_by_id(rvu, req->index); |
| 1731 |
if (!rc) { |
| 1732 |
dev_dbg(rvu->dev, "%s del to PF=%d success (seq_id=%u)\n", |
| 1733 |
__func__, pf, req->index); |
| 1734 |
return 0; |
| 1735 |
} |
| 1736 |
|
| 1737 |
dev_err(rvu->dev, "%s del to PF=%d failed (seq_id=%u)\n", |
| 1738 |
__func__, pf, req->index); |
| 1739 |
return LMAC_AF_ERR_EXACT_MATCH_TBL_DEL_FAILED; |
| 1740 |
} |
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
int rvu_npc_exact_mac_addr_set(struct rvu *rvu, struct cgx_mac_addr_set_or_get *req, |
| 1750 |
struct cgx_mac_addr_set_or_get *rsp) |
| 1751 |
{ |
| 1752 |
int pf = rvu_get_pf(rvu->pdev, req->hdr.pcifunc); |
| 1753 |
u32 seq_id = req->index; |
| 1754 |
struct rvu_pfvf *pfvf; |
| 1755 |
u8 cgx_id, lmac_id; |
| 1756 |
u32 mcam_idx = -1; |
| 1757 |
int rc, nixlf; |
| 1758 |
|
| 1759 |
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[pf], &cgx_id, &lmac_id); |
| 1760 |
|
| 1761 |
pfvf = &rvu->pf[pf]; |
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
rc = rvu_npc_exact_update_table_entry(rvu, cgx_id, lmac_id, pfvf->mac_addr, |
| 1767 |
req->mac_addr, &seq_id); |
| 1768 |
if (!rc) { |
| 1769 |
rsp->index = seq_id; |
| 1770 |
ether_addr_copy(pfvf->mac_addr, req->mac_addr); |
| 1771 |
ether_addr_copy(rsp->mac_addr, req->mac_addr); |
| 1772 |
dev_dbg(rvu->dev, "%s MAC (%pM) update to PF=%d success\n", |
| 1773 |
__func__, req->mac_addr, pf); |
| 1774 |
return 0; |
| 1775 |
} |
| 1776 |
|
| 1777 |
|
| 1778 |
rc = rvu_npc_exact_del_table_entry_by_id(rvu, req->index); |
| 1779 |
if (rc) { |
| 1780 |
dev_dbg(rvu->dev, "%s MAC (%pM) del PF=%d failed\n", |
| 1781 |
__func__, pfvf->mac_addr, pf); |
| 1782 |
} |
| 1783 |
|
| 1784 |
|
| 1785 |
rc = nix_get_nixlf(rvu, req->hdr.pcifunc, &nixlf, NULL); |
| 1786 |
if (!rc) { |
| 1787 |
mcam_idx = npc_get_nixlf_mcam_index(&rvu->hw->mcam, req->hdr.pcifunc, |
| 1788 |
nixlf, NIXLF_UCAST_ENTRY); |
| 1789 |
} |
| 1790 |
|
| 1791 |
rc = rvu_npc_exact_add_table_entry(rvu, cgx_id, lmac_id, req->mac_addr, |
| 1792 |
pfvf->rx_chan_base, 0, &seq_id, |
| 1793 |
true, mcam_idx, req->hdr.pcifunc); |
| 1794 |
if (rc) { |
| 1795 |
dev_err(rvu->dev, "%s MAC (%pM) add PF=%d failed\n", |
| 1796 |
__func__, req->mac_addr, pf); |
| 1797 |
return LMAC_AF_ERR_EXACT_MATCH_TBL_ADD_FAILED; |
| 1798 |
} |
| 1799 |
|
| 1800 |
rsp->index = seq_id; |
| 1801 |
ether_addr_copy(rsp->mac_addr, req->mac_addr); |
| 1802 |
ether_addr_copy(pfvf->mac_addr, req->mac_addr); |
| 1803 |
dev_dbg(rvu->dev, |
| 1804 |
"%s MAC (%pM) del and add to PF=%d success (seq_id=%u)\n", |
| 1805 |
__func__, req->mac_addr, pf, seq_id); |
| 1806 |
return 0; |
| 1807 |
} |
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
bool rvu_npc_exact_can_disable_feature(struct rvu *rvu) |
| 1815 |
{ |
| 1816 |
struct npc_exact_table *table = rvu->hw->table; |
| 1817 |
bool empty; |
| 1818 |
|
| 1819 |
if (!rvu->hw->cap.npc_exact_match_enabled) |
| 1820 |
return false; |
| 1821 |
|
| 1822 |
mutex_lock(&table->lock); |
| 1823 |
empty = list_empty(&table->lhead_gbl); |
| 1824 |
mutex_unlock(&table->lock); |
| 1825 |
|
| 1826 |
return empty; |
| 1827 |
} |
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
void rvu_npc_exact_disable_feature(struct rvu *rvu) |
| 1834 |
{ |
| 1835 |
rvu->hw->cap.npc_exact_match_enabled = false; |
| 1836 |
} |
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
void rvu_npc_exact_reset(struct rvu *rvu, u16 pcifunc) |
| 1844 |
{ |
| 1845 |
struct npc_exact_table *table = rvu->hw->table; |
| 1846 |
struct npc_exact_table_entry *tmp, *iter; |
| 1847 |
u32 seq_id; |
| 1848 |
|
| 1849 |
mutex_lock(&table->lock); |
| 1850 |
list_for_each_entry_safe(iter, tmp, &table->lhead_gbl, glist) { |
| 1851 |
if (pcifunc != iter->pcifunc) |
| 1852 |
continue; |
| 1853 |
|
| 1854 |
seq_id = iter->seq_id; |
| 1855 |
dev_dbg(rvu->dev, "%s: resetting pcifun=%d seq_id=%u\n", __func__, |
| 1856 |
pcifunc, seq_id); |
| 1857 |
|
| 1858 |
mutex_unlock(&table->lock); |
| 1859 |
rvu_npc_exact_del_table_entry_by_id(rvu, seq_id); |
| 1860 |
mutex_lock(&table->lock); |
| 1861 |
} |
| 1862 |
mutex_unlock(&table->lock); |
| 1863 |
} |
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
int rvu_npc_exact_init(struct rvu *rvu) |
| 1874 |
{ |
| 1875 |
u64 bcast_mcast_val, bcast_mcast_mask; |
| 1876 |
struct npc_exact_table *table; |
| 1877 |
u64 exact_val, exact_mask; |
| 1878 |
u64 chan_val, chan_mask; |
| 1879 |
u8 cgx_id, lmac_id; |
| 1880 |
u32 *drop_mcam_idx; |
| 1881 |
u16 max_lmac_cnt; |
| 1882 |
u64 npc_const3; |
| 1883 |
int table_size; |
| 1884 |
int blkaddr; |
| 1885 |
u16 pcifunc; |
| 1886 |
int err, i; |
| 1887 |
u64 cfg; |
| 1888 |
bool rc; |
| 1889 |
|
| 1890 |
if (is_cn20k(rvu->pdev)) |
| 1891 |
return 0; |
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0); |
| 1897 |
if (blkaddr < 0) { |
| 1898 |
dev_err(rvu->dev, "%s: NPC block not implemented\n", __func__); |
| 1899 |
return -EINVAL; |
| 1900 |
} |
| 1901 |
|
| 1902 |
|
| 1903 |
npc_const3 = rvu_read64(rvu, blkaddr, NPC_AF_CONST3); |
| 1904 |
if (!(npc_const3 & BIT_ULL(62))) |
| 1905 |
return 0; |
| 1906 |
|
| 1907 |
|
| 1908 |
cfg = rvu_read64(rvu, blkaddr, NPC_AF_INTFX_KEX_CFG(NIX_INTF_RX)); |
| 1909 |
if (!(cfg & NPC_EXACT_NIBBLE_HIT)) |
| 1910 |
return 0; |
| 1911 |
|
| 1912 |
|
| 1913 |
rvu->hw->cap.npc_exact_match_enabled = true; |
| 1914 |
|
| 1915 |
table = kzalloc_obj(*table); |
| 1916 |
if (!table) |
| 1917 |
return -ENOMEM; |
| 1918 |
|
| 1919 |
dev_dbg(rvu->dev, "%s: Memory allocation for table success\n", __func__); |
| 1920 |
rvu->hw->table = table; |
| 1921 |
|
| 1922 |
|
| 1923 |
table->mem_table.ways = FIELD_GET(GENMASK_ULL(19, 16), npc_const3); |
| 1924 |
table->mem_table.depth = FIELD_GET(GENMASK_ULL(15, 0), npc_const3); |
| 1925 |
table->cam_table.depth = FIELD_GET(GENMASK_ULL(31, 24), npc_const3); |
| 1926 |
|
| 1927 |
dev_dbg(rvu->dev, "%s: NPC exact match 4way_2k table(ways=%d, depth=%d)\n", |
| 1928 |
__func__, table->mem_table.ways, table->cam_table.depth); |
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
if ((table->mem_table.depth & (table->mem_table.depth - 1)) != 0) { |
| 1934 |
dev_err(rvu->dev, |
| 1935 |
"%s: NPC exact match 4way_2k table depth(%d) is not square of 2\n", |
| 1936 |
__func__, table->mem_table.depth); |
| 1937 |
return -EINVAL; |
| 1938 |
} |
| 1939 |
|
| 1940 |
table_size = table->mem_table.depth * table->mem_table.ways; |
| 1941 |
|
| 1942 |
|
| 1943 |
table->mem_table.bmap = devm_bitmap_zalloc(rvu->dev, table_size, |
| 1944 |
GFP_KERNEL); |
| 1945 |
if (!table->mem_table.bmap) |
| 1946 |
return -ENOMEM; |
| 1947 |
|
| 1948 |
dev_dbg(rvu->dev, "%s: Allocated bitmap for 4way 2K entry table\n", __func__); |
| 1949 |
|
| 1950 |
|
| 1951 |
table->cam_table.bmap = devm_bitmap_zalloc(rvu->dev, 32, GFP_KERNEL); |
| 1952 |
|
| 1953 |
if (!table->cam_table.bmap) |
| 1954 |
return -ENOMEM; |
| 1955 |
|
| 1956 |
dev_dbg(rvu->dev, "%s: Allocated bitmap for 32 entry cam\n", __func__); |
| 1957 |
|
| 1958 |
table->tot_ids = table_size + table->cam_table.depth; |
| 1959 |
table->id_bmap = devm_bitmap_zalloc(rvu->dev, table->tot_ids, |
| 1960 |
GFP_KERNEL); |
| 1961 |
|
| 1962 |
if (!table->id_bmap) |
| 1963 |
return -ENOMEM; |
| 1964 |
|
| 1965 |
dev_dbg(rvu->dev, "%s: Allocated bitmap for id map (total=%d)\n", |
| 1966 |
__func__, table->tot_ids); |
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
for (i = 0; i < NPC_EXACT_TBL_MAX_WAYS; i++) |
| 1973 |
INIT_LIST_HEAD(&table->lhead_mem_tbl_entry[i]); |
| 1974 |
|
| 1975 |
INIT_LIST_HEAD(&table->lhead_cam_tbl_entry); |
| 1976 |
INIT_LIST_HEAD(&table->lhead_gbl); |
| 1977 |
|
| 1978 |
mutex_init(&table->lock); |
| 1979 |
|
| 1980 |
rvu_exact_config_secret_key(rvu); |
| 1981 |
rvu_exact_config_search_key(rvu); |
| 1982 |
|
| 1983 |
rvu_exact_config_table_mask(rvu); |
| 1984 |
rvu_exact_config_result_ctrl(rvu, table->mem_table.depth); |
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
exact_val = !NPC_EXACT_RESULT_HIT; |
| 1990 |
exact_mask = NPC_EXACT_RESULT_HIT; |
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
bcast_mcast_val = 0b0000; |
| 1996 |
bcast_mcast_mask = 0b0011; |
| 1997 |
|
| 1998 |
|
| 1999 |
drop_mcam_idx = &table->num_drop_rules; |
| 2000 |
|
| 2001 |
max_lmac_cnt = rvu->cgx_cnt_max * rvu->hw->lmac_per_cgx + |
| 2002 |
PF_CGXMAP_BASE; |
| 2003 |
|
| 2004 |
for (i = PF_CGXMAP_BASE; i < max_lmac_cnt; i++) { |
| 2005 |
if (rvu->pf2cgxlmac_map[i] == 0xFF) |
| 2006 |
continue; |
| 2007 |
|
| 2008 |
rvu_get_cgx_lmac_id(rvu->pf2cgxlmac_map[i], &cgx_id, &lmac_id); |
| 2009 |
|
| 2010 |
rc = rvu_npc_exact_calc_drop_rule_chan_and_mask(rvu, NIX_INTF_TYPE_CGX, cgx_id, |
| 2011 |
lmac_id, &chan_val, &chan_mask); |
| 2012 |
if (!rc) { |
| 2013 |
dev_err(rvu->dev, |
| 2014 |
"%s: failed, info chan_val=0x%llx chan_mask=0x%llx rule_id=%d\n", |
| 2015 |
__func__, chan_val, chan_mask, *drop_mcam_idx); |
| 2016 |
return -EINVAL; |
| 2017 |
} |
| 2018 |
|
| 2019 |
|
| 2020 |
pcifunc = RVU_PFFUNC(rvu->pdev, i, 0); |
| 2021 |
|
| 2022 |
dev_dbg(rvu->dev, |
| 2023 |
"%s:Drop rule cgx=%d lmac=%d chan(val=0x%llx, mask=0x%llx\n", |
| 2024 |
__func__, cgx_id, lmac_id, chan_val, chan_mask); |
| 2025 |
|
| 2026 |
rc = rvu_npc_exact_save_drop_rule_chan_and_mask(rvu, table->num_drop_rules, |
| 2027 |
chan_val, chan_mask, pcifunc); |
| 2028 |
if (!rc) { |
| 2029 |
dev_err(rvu->dev, |
| 2030 |
"%s: failed to set drop info for cgx=%d, lmac=%d, chan=%llx\n", |
| 2031 |
__func__, cgx_id, lmac_id, chan_val); |
| 2032 |
return -EINVAL; |
| 2033 |
} |
| 2034 |
|
| 2035 |
err = npc_install_mcam_drop_rule(rvu, *drop_mcam_idx, |
| 2036 |
&table->counter_idx[*drop_mcam_idx], |
| 2037 |
chan_val, chan_mask, |
| 2038 |
exact_val, exact_mask, |
| 2039 |
bcast_mcast_val, bcast_mcast_mask); |
| 2040 |
if (err) { |
| 2041 |
dev_err(rvu->dev, |
| 2042 |
"failed to configure drop rule (cgx=%d lmac=%d)\n", |
| 2043 |
cgx_id, lmac_id); |
| 2044 |
return err; |
| 2045 |
} |
| 2046 |
|
| 2047 |
(*drop_mcam_idx)++; |
| 2048 |
} |
| 2049 |
|
| 2050 |
dev_info(rvu->dev, "initialized exact match table successfully\n"); |
| 2051 |
return 0; |
| 2052 |
} |