Subject: Re: [PATCH v4 net-next 2/3] octeontx2-af: Knobs for NPC default rule counters

From: Jakub Kicinski <[email-masked]>
Date: Sun, 3 Nov 2024 11:53:10 -0800

On Tue, 29 Oct 2024 09:27:38 +0530 Linu Cherian wrote:
> +	struct npc_install_flow_rsp rsp = { 0 };

@rsp is reused in the loop, either it doesn't have to be inited at all,
or it has to be inited before every use

> +	struct npc_mcam *mcam = &rvu->hw->mcam;
> +	struct rvu_npc_mcam_rule *rule;
> +	int blkaddr;
> +
> +	blkaddr = rvu_get_blkaddr(rvu, BLKTYPE_NPC, 0);
> +	if (blkaddr < 0)
> +		return -EINVAL;
> +
> +	mutex_lock(&mcam->lock);
> +	list_for_each_entry(rule, &mcam->mcam_rules, list) {
> +		if (!is_mcam_entry_enabled(rvu, mcam, blkaddr, rule->entry))
> +			continue;
> +		if (!rule->default_rule)
> +			continue;
> +		if (enable && !rule->has_cntr) { /* Alloc and map new counter */
> +			__rvu_mcam_add_counter_to_rule(rvu, rule->owner,
> +						       rule, &rsp);
> +			if (rsp.counter < 0) {
> +				dev_err(rvu->dev, "%s: Err to allocate cntr for default rule (err=%d)\n",
> +					__func__, rsp.counter);
> +				break;

shouldn't you "unwind" in this case? We'll leave the counter enabled
for some rules and disabled for others

> +			}
> +			npc_map_mcam_entry_and_cntr(rvu, mcam, blkaddr,
> +						    rule->entry, rsp.counter);
> +		}
> +
> +		if (enable && rule->has_cntr) /* Reset counter before use */ {
> +			rvu_write64(rvu, blkaddr,
> +				    NPC_AF_MATCH_STATX(rule->cntr), 0x0);
> +			continue;

so setting to enabled while already enabled resets the value?
If so that's neither documented, nor.. usual.

> +		}
> +
> +		if (!enable && rule->has_cntr) /* Free and unmap counter */ {
> +			__rvu_mcam_remove_counter_from_rule(rvu, rule->owner,
> +							    rule);
> +		}

unnecesary parenthesis

> +	}
-- 
pw-bot: cr