xref: /dpdk/drivers/common/cnxk/roc_npc_aging.c (revision 118ba4e3f2a39e6fc10075c680310f4cdabc1bd7)
1357f5ebcSAnkur Dwivedi /* SPDX-License-Identifier: BSD-3-Clause
2357f5ebcSAnkur Dwivedi  * Copyright(C) 2023 Marvell.
3357f5ebcSAnkur Dwivedi  */
4357f5ebcSAnkur Dwivedi 
5357f5ebcSAnkur Dwivedi #include "roc_api.h"
6357f5ebcSAnkur Dwivedi #include "roc_priv.h"
7357f5ebcSAnkur Dwivedi 
8357f5ebcSAnkur Dwivedi int
9357f5ebcSAnkur Dwivedi npc_aged_flows_bitmap_alloc(struct roc_npc *roc_npc)
10357f5ebcSAnkur Dwivedi {
11357f5ebcSAnkur Dwivedi 	struct roc_npc_flow_age *flow_age;
12357f5ebcSAnkur Dwivedi 	uint8_t *age_mem = NULL;
13357f5ebcSAnkur Dwivedi 	uint32_t bmap_sz;
14357f5ebcSAnkur Dwivedi 	int rc = 0;
15357f5ebcSAnkur Dwivedi 
16357f5ebcSAnkur Dwivedi 	bmap_sz = plt_bitmap_get_memory_footprint(MCAM_ARR_ELEM_SZ *
17357f5ebcSAnkur Dwivedi 						  MCAM_ARR_SIZE);
18357f5ebcSAnkur Dwivedi 	age_mem = plt_zmalloc(bmap_sz, 0);
19357f5ebcSAnkur Dwivedi 	if (age_mem == NULL) {
20357f5ebcSAnkur Dwivedi 		plt_err("Bmap alloc failed");
21357f5ebcSAnkur Dwivedi 		rc = NPC_ERR_NO_MEM;
22357f5ebcSAnkur Dwivedi 		goto done;
23357f5ebcSAnkur Dwivedi 	}
24357f5ebcSAnkur Dwivedi 
25357f5ebcSAnkur Dwivedi 	flow_age = &roc_npc->flow_age;
26357f5ebcSAnkur Dwivedi 	flow_age->age_mem = age_mem;
27357f5ebcSAnkur Dwivedi 	flow_age->aged_flows = plt_bitmap_init(MCAM_ARR_ELEM_SZ * MCAM_ARR_SIZE,
28357f5ebcSAnkur Dwivedi 					       age_mem, bmap_sz);
29357f5ebcSAnkur Dwivedi 	if (!flow_age->aged_flows) {
30357f5ebcSAnkur Dwivedi 		plt_err("Bitmap init failed");
31357f5ebcSAnkur Dwivedi 		plt_free(age_mem);
32357f5ebcSAnkur Dwivedi 		rc = NPC_ERR_NO_MEM;
33357f5ebcSAnkur Dwivedi 		goto done;
34357f5ebcSAnkur Dwivedi 	}
35357f5ebcSAnkur Dwivedi 
36357f5ebcSAnkur Dwivedi done:
37357f5ebcSAnkur Dwivedi 	return rc;
38357f5ebcSAnkur Dwivedi }
39357f5ebcSAnkur Dwivedi 
40357f5ebcSAnkur Dwivedi void
41357f5ebcSAnkur Dwivedi npc_aged_flows_bitmap_free(struct roc_npc *roc_npc)
42357f5ebcSAnkur Dwivedi {
43357f5ebcSAnkur Dwivedi 	struct roc_npc_flow_age *flow_age;
44357f5ebcSAnkur Dwivedi 
45357f5ebcSAnkur Dwivedi 	flow_age = &roc_npc->flow_age;
46357f5ebcSAnkur Dwivedi 	plt_bitmap_free(flow_age->aged_flows);
47357f5ebcSAnkur Dwivedi 	if (flow_age->age_mem)
48357f5ebcSAnkur Dwivedi 		plt_free(roc_npc->flow_age.age_mem);
49357f5ebcSAnkur Dwivedi }
50357f5ebcSAnkur Dwivedi 
51357f5ebcSAnkur Dwivedi static void
52357f5ebcSAnkur Dwivedi check_timeout_cycles(struct roc_npc *roc_npc, uint32_t mcam_id)
53357f5ebcSAnkur Dwivedi {
54357f5ebcSAnkur Dwivedi 	struct npc *npc = roc_npc_to_npc_priv(roc_npc);
55357f5ebcSAnkur Dwivedi 	struct npc_age_flow_list_head *list;
56357f5ebcSAnkur Dwivedi 	struct npc_age_flow_entry *fl_iter;
57357f5ebcSAnkur Dwivedi 	struct roc_npc_flow_age *flow_age;
58357f5ebcSAnkur Dwivedi 
59357f5ebcSAnkur Dwivedi 	flow_age = &roc_npc->flow_age;
60357f5ebcSAnkur Dwivedi 	list = &npc->age_flow_list;
61357f5ebcSAnkur Dwivedi 	TAILQ_FOREACH(fl_iter, list, next) {
62357f5ebcSAnkur Dwivedi 		if (fl_iter->flow->mcam_id == mcam_id &&
63a4477550SAnkur Dwivedi 		    fl_iter->flow->timeout_cycles < plt_tsc_cycles()) {
64357f5ebcSAnkur Dwivedi 			/* update bitmap */
65357f5ebcSAnkur Dwivedi 			plt_bitmap_set(flow_age->aged_flows, mcam_id);
66357f5ebcSAnkur Dwivedi 			if (flow_age->aged_flows_cnt == 0) {
67357f5ebcSAnkur Dwivedi 				flow_age->start_id = mcam_id;
68357f5ebcSAnkur Dwivedi 				flow_age->end_id = mcam_id;
69357f5ebcSAnkur Dwivedi 			}
70357f5ebcSAnkur Dwivedi 			if (flow_age->start_id > mcam_id)
71357f5ebcSAnkur Dwivedi 				flow_age->start_id = mcam_id;
72357f5ebcSAnkur Dwivedi 			else if (flow_age->end_id < mcam_id)
73357f5ebcSAnkur Dwivedi 				flow_age->end_id = mcam_id;
74357f5ebcSAnkur Dwivedi 			flow_age->aged_flows_cnt += 1;
75357f5ebcSAnkur Dwivedi 			break;
76357f5ebcSAnkur Dwivedi 		}
77357f5ebcSAnkur Dwivedi 	}
78357f5ebcSAnkur Dwivedi }
79357f5ebcSAnkur Dwivedi 
80357f5ebcSAnkur Dwivedi static void
81357f5ebcSAnkur Dwivedi update_timeout_cycles(struct roc_npc *roc_npc, uint32_t mcam_id)
82357f5ebcSAnkur Dwivedi {
83357f5ebcSAnkur Dwivedi 	struct npc *npc = roc_npc_to_npc_priv(roc_npc);
84357f5ebcSAnkur Dwivedi 	struct npc_age_flow_list_head *list;
85357f5ebcSAnkur Dwivedi 	struct npc_age_flow_entry *fl_iter;
86357f5ebcSAnkur Dwivedi 
87357f5ebcSAnkur Dwivedi 	list = &npc->age_flow_list;
88357f5ebcSAnkur Dwivedi 	TAILQ_FOREACH(fl_iter, list, next) {
89357f5ebcSAnkur Dwivedi 		if (fl_iter->flow->mcam_id == mcam_id) {
90a4477550SAnkur Dwivedi 			fl_iter->flow->timeout_cycles = plt_tsc_cycles() +
91a4477550SAnkur Dwivedi 				fl_iter->flow->timeout * plt_tsc_hz();
92357f5ebcSAnkur Dwivedi 			break;
93357f5ebcSAnkur Dwivedi 		}
94357f5ebcSAnkur Dwivedi 	}
95357f5ebcSAnkur Dwivedi }
96357f5ebcSAnkur Dwivedi 
97357f5ebcSAnkur Dwivedi static int
98357f5ebcSAnkur Dwivedi npc_mcam_get_hit_status(struct npc *npc, uint64_t *mcam_ids, uint16_t start_id,
99357f5ebcSAnkur Dwivedi 			uint16_t end_id, uint64_t *hit_status, bool clear)
100357f5ebcSAnkur Dwivedi {
101357f5ebcSAnkur Dwivedi 	struct npc_mcam_get_hit_status_req *req;
102357f5ebcSAnkur Dwivedi 	struct npc_mcam_get_hit_status_rsp *rsp;
103357f5ebcSAnkur Dwivedi 	struct mbox *mbox = mbox_get(npc->mbox);
104357f5ebcSAnkur Dwivedi 	uint8_t idx_start;
105357f5ebcSAnkur Dwivedi 	uint8_t idx_end;
106357f5ebcSAnkur Dwivedi 	int rc;
107357f5ebcSAnkur Dwivedi 	int i;
108357f5ebcSAnkur Dwivedi 
109357f5ebcSAnkur Dwivedi 	req = mbox_alloc_msg_npc_mcam_get_hit_status(mbox);
110357f5ebcSAnkur Dwivedi 	if (req == NULL)
111357f5ebcSAnkur Dwivedi 		return -ENOSPC;
112357f5ebcSAnkur Dwivedi 
113357f5ebcSAnkur Dwivedi 	idx_start = start_id / MCAM_ARR_ELEM_SZ;
114357f5ebcSAnkur Dwivedi 	idx_end = end_id / MCAM_ARR_ELEM_SZ;
115357f5ebcSAnkur Dwivedi 
116357f5ebcSAnkur Dwivedi 	for (i = idx_start; i <= idx_end; i++)
117357f5ebcSAnkur Dwivedi 		req->mcam_ids[i] = mcam_ids[i];
118357f5ebcSAnkur Dwivedi 
119357f5ebcSAnkur Dwivedi 	req->range_valid_mcam_ids_start = start_id;
120357f5ebcSAnkur Dwivedi 	req->range_valid_mcam_ids_end = end_id;
121357f5ebcSAnkur Dwivedi 	req->clear = clear;
122357f5ebcSAnkur Dwivedi 
123357f5ebcSAnkur Dwivedi 	rc = mbox_process_msg(mbox, (void *)&rsp);
124357f5ebcSAnkur Dwivedi 	if (rc)
125357f5ebcSAnkur Dwivedi 		goto exit;
126357f5ebcSAnkur Dwivedi 
127357f5ebcSAnkur Dwivedi 	for (i = idx_start; i <= idx_end; i++)
128357f5ebcSAnkur Dwivedi 		hit_status[i] = rsp->mcam_hit_status[i];
129357f5ebcSAnkur Dwivedi 
130357f5ebcSAnkur Dwivedi 	rc = 0;
131357f5ebcSAnkur Dwivedi exit:
132357f5ebcSAnkur Dwivedi 	mbox_put(mbox);
133357f5ebcSAnkur Dwivedi 	return rc;
134357f5ebcSAnkur Dwivedi }
135357f5ebcSAnkur Dwivedi 
136a4878294SKiran Kumar K static void
137a4878294SKiran Kumar K npc_age_wait_until(struct roc_npc_flow_age *flow_age)
138a4878294SKiran Kumar K {
139a4878294SKiran Kumar K #define NPC_AGE_WAIT_TIMEOUT_MS 1000
140a4878294SKiran Kumar K #define NPC_AGE_WAIT_TIMEOUT_US (NPC_AGE_WAIT_TIMEOUT_MS * NPC_AGE_WAIT_TIMEOUT_MS)
141a4878294SKiran Kumar K 	uint64_t timeout = 0;
142a4878294SKiran Kumar K 	uint64_t sleep = 10 * NPC_AGE_WAIT_TIMEOUT_MS;
143a4878294SKiran Kumar K 
144a4878294SKiran Kumar K 	do {
145a4878294SKiran Kumar K 		plt_delay_us(sleep);
146a4878294SKiran Kumar K 		timeout += sleep;
147a4878294SKiran Kumar K 	} while (!flow_age->aged_flows_get_thread_exit &&
148*118ba4e3SAnkur Dwivedi 		 (timeout < ((uint64_t)flow_age->aging_poll_freq * NPC_AGE_WAIT_TIMEOUT_US)));
149a4878294SKiran Kumar K }
150a4878294SKiran Kumar K 
151357f5ebcSAnkur Dwivedi uint32_t
152357f5ebcSAnkur Dwivedi npc_aged_flows_get(void *args)
153357f5ebcSAnkur Dwivedi {
154357f5ebcSAnkur Dwivedi 	uint64_t hit_status[MCAM_ARR_SIZE] = {0};
155357f5ebcSAnkur Dwivedi 	uint64_t mcam_ids[MCAM_ARR_SIZE] = {0};
156357f5ebcSAnkur Dwivedi 	struct npc_age_flow_list_head *list;
157357f5ebcSAnkur Dwivedi 	struct npc_age_flow_entry *fl_iter;
158357f5ebcSAnkur Dwivedi 	struct roc_npc *roc_npc = args;
159357f5ebcSAnkur Dwivedi 	struct npc *npc = roc_npc_to_npc_priv(roc_npc);
160357f5ebcSAnkur Dwivedi 	struct roc_npc_flow_age *flow_age;
161357f5ebcSAnkur Dwivedi 	bool aging_enabled;
162357f5ebcSAnkur Dwivedi 	uint32_t start_id;
163357f5ebcSAnkur Dwivedi 	uint32_t end_id;
164357f5ebcSAnkur Dwivedi 	uint32_t mcam_id;
165357f5ebcSAnkur Dwivedi 	uint32_t idx;
166357f5ebcSAnkur Dwivedi 	uint32_t i;
167357f5ebcSAnkur Dwivedi 	int rc;
168357f5ebcSAnkur Dwivedi 
169357f5ebcSAnkur Dwivedi 	flow_age = &roc_npc->flow_age;
170357f5ebcSAnkur Dwivedi 	list = &npc->age_flow_list;
171357f5ebcSAnkur Dwivedi 	while (!flow_age->aged_flows_get_thread_exit) {
172357f5ebcSAnkur Dwivedi 		start_id = 0;
173357f5ebcSAnkur Dwivedi 		end_id = 0;
174357f5ebcSAnkur Dwivedi 		aging_enabled = false;
175357f5ebcSAnkur Dwivedi 		memset(mcam_ids, 0, sizeof(mcam_ids));
176357f5ebcSAnkur Dwivedi 		TAILQ_FOREACH(fl_iter, list, next) {
177357f5ebcSAnkur Dwivedi 			mcam_id = fl_iter->flow->mcam_id;
178357f5ebcSAnkur Dwivedi 			idx = mcam_id / MCAM_ARR_ELEM_SZ;
179357f5ebcSAnkur Dwivedi 			mcam_ids[idx] |= BIT_ULL(mcam_id % MCAM_ARR_ELEM_SZ);
180357f5ebcSAnkur Dwivedi 
181357f5ebcSAnkur Dwivedi 			if (!aging_enabled) {
182357f5ebcSAnkur Dwivedi 				start_id = mcam_id;
183357f5ebcSAnkur Dwivedi 				end_id = mcam_id;
184357f5ebcSAnkur Dwivedi 				aging_enabled = true;
185357f5ebcSAnkur Dwivedi 			}
186357f5ebcSAnkur Dwivedi 
187357f5ebcSAnkur Dwivedi 			if (mcam_id < start_id)
188357f5ebcSAnkur Dwivedi 				start_id = mcam_id;
189357f5ebcSAnkur Dwivedi 			else if (mcam_id > end_id)
190357f5ebcSAnkur Dwivedi 				end_id = mcam_id;
191357f5ebcSAnkur Dwivedi 		}
192357f5ebcSAnkur Dwivedi 
193357f5ebcSAnkur Dwivedi 		if (!aging_enabled)
194357f5ebcSAnkur Dwivedi 			goto lbl_sleep;
195357f5ebcSAnkur Dwivedi 
196357f5ebcSAnkur Dwivedi 		rc = npc_mcam_get_hit_status(npc, mcam_ids, start_id, end_id,
197357f5ebcSAnkur Dwivedi 					     hit_status, true);
198357f5ebcSAnkur Dwivedi 		if (rc)
199357f5ebcSAnkur Dwivedi 			return 0;
200357f5ebcSAnkur Dwivedi 
201357f5ebcSAnkur Dwivedi 		plt_seqcount_write_begin(&flow_age->seq_cnt);
202357f5ebcSAnkur Dwivedi 		flow_age->aged_flows_cnt = 0;
203357f5ebcSAnkur Dwivedi 		for (i = start_id; i <= end_id; i++) {
204357f5ebcSAnkur Dwivedi 			idx = i / MCAM_ARR_ELEM_SZ;
205357f5ebcSAnkur Dwivedi 			if (mcam_ids[idx] & BIT_ULL(i % MCAM_ARR_ELEM_SZ)) {
206357f5ebcSAnkur Dwivedi 				if (!(hit_status[idx] & BIT_ULL(i % MCAM_ARR_ELEM_SZ)))
207357f5ebcSAnkur Dwivedi 					check_timeout_cycles(roc_npc, i);
208357f5ebcSAnkur Dwivedi 				else
209357f5ebcSAnkur Dwivedi 					update_timeout_cycles(roc_npc, i);
210357f5ebcSAnkur Dwivedi 			}
211357f5ebcSAnkur Dwivedi 		}
212357f5ebcSAnkur Dwivedi 		plt_seqcount_write_end(&flow_age->seq_cnt);
213357f5ebcSAnkur Dwivedi 
214357f5ebcSAnkur Dwivedi lbl_sleep:
215a4878294SKiran Kumar K 		npc_age_wait_until(flow_age);
216357f5ebcSAnkur Dwivedi 	}
217357f5ebcSAnkur Dwivedi 
218357f5ebcSAnkur Dwivedi 	return 0;
219357f5ebcSAnkur Dwivedi }
220357f5ebcSAnkur Dwivedi 
221357f5ebcSAnkur Dwivedi void
222357f5ebcSAnkur Dwivedi npc_age_flow_list_entry_add(struct roc_npc *roc_npc, struct roc_npc_flow *flow)
223357f5ebcSAnkur Dwivedi {
224357f5ebcSAnkur Dwivedi 	struct npc *npc = roc_npc_to_npc_priv(roc_npc);
225357f5ebcSAnkur Dwivedi 	struct npc_age_flow_entry *age_fl_iter;
226357f5ebcSAnkur Dwivedi 	struct npc_age_flow_entry *new_entry;
227357f5ebcSAnkur Dwivedi 
228357f5ebcSAnkur Dwivedi 	new_entry = plt_zmalloc(sizeof(*new_entry), 0);
229a4477550SAnkur Dwivedi 	if (new_entry == NULL) {
230a4477550SAnkur Dwivedi 		plt_err("flow entry alloc failed");
231a4477550SAnkur Dwivedi 		return;
232a4477550SAnkur Dwivedi 	}
233a4477550SAnkur Dwivedi 
234357f5ebcSAnkur Dwivedi 	new_entry->flow = flow;
235357f5ebcSAnkur Dwivedi 	roc_npc->flow_age.age_flow_refcnt++;
236357f5ebcSAnkur Dwivedi 	/* List in ascending order of mcam entries */
237357f5ebcSAnkur Dwivedi 	TAILQ_FOREACH(age_fl_iter, &npc->age_flow_list, next) {
238357f5ebcSAnkur Dwivedi 		if (age_fl_iter->flow->mcam_id > flow->mcam_id) {
239357f5ebcSAnkur Dwivedi 			TAILQ_INSERT_BEFORE(age_fl_iter, new_entry, next);
240357f5ebcSAnkur Dwivedi 			return;
241357f5ebcSAnkur Dwivedi 		}
242357f5ebcSAnkur Dwivedi 	}
243357f5ebcSAnkur Dwivedi 	TAILQ_INSERT_TAIL(&npc->age_flow_list, new_entry, next);
244357f5ebcSAnkur Dwivedi }
245357f5ebcSAnkur Dwivedi 
246357f5ebcSAnkur Dwivedi void
247357f5ebcSAnkur Dwivedi npc_age_flow_list_entry_delete(struct roc_npc *roc_npc,
248357f5ebcSAnkur Dwivedi 			       struct roc_npc_flow *flow)
249357f5ebcSAnkur Dwivedi {
250357f5ebcSAnkur Dwivedi 	struct npc *npc = roc_npc_to_npc_priv(roc_npc);
251357f5ebcSAnkur Dwivedi 	struct npc_age_flow_list_head *list;
2524ebef525SSatheesh Paul 	struct roc_npc_flow_age *flow_age;
253357f5ebcSAnkur Dwivedi 	struct npc_age_flow_entry *curr;
254357f5ebcSAnkur Dwivedi 
2554ebef525SSatheesh Paul 	flow_age = &roc_npc->flow_age;
2564ebef525SSatheesh Paul 
257357f5ebcSAnkur Dwivedi 	list = &npc->age_flow_list;
258357f5ebcSAnkur Dwivedi 	curr = TAILQ_FIRST(list);
259357f5ebcSAnkur Dwivedi 
260357f5ebcSAnkur Dwivedi 	if (!curr)
261357f5ebcSAnkur Dwivedi 		return;
262357f5ebcSAnkur Dwivedi 
263357f5ebcSAnkur Dwivedi 	while (curr) {
264357f5ebcSAnkur Dwivedi 		if (flow->mcam_id == curr->flow->mcam_id) {
2654ebef525SSatheesh Paul 			plt_bitmap_clear(flow_age->aged_flows, flow->mcam_id);
266357f5ebcSAnkur Dwivedi 			TAILQ_REMOVE(list, curr, next);
267357f5ebcSAnkur Dwivedi 			plt_free(curr);
268357f5ebcSAnkur Dwivedi 			break;
269357f5ebcSAnkur Dwivedi 		}
270357f5ebcSAnkur Dwivedi 		curr = TAILQ_NEXT(curr, next);
271357f5ebcSAnkur Dwivedi 	}
272357f5ebcSAnkur Dwivedi 	roc_npc->flow_age.age_flow_refcnt--;
273357f5ebcSAnkur Dwivedi }
274357f5ebcSAnkur Dwivedi 
275357f5ebcSAnkur Dwivedi int
276357f5ebcSAnkur Dwivedi npc_aging_ctrl_thread_create(struct roc_npc *roc_npc,
277357f5ebcSAnkur Dwivedi 			     const struct roc_npc_action_age *age,
278357f5ebcSAnkur Dwivedi 			     struct roc_npc_flow *flow)
279357f5ebcSAnkur Dwivedi {
280357f5ebcSAnkur Dwivedi 	struct roc_npc_flow_age *flow_age;
281357f5ebcSAnkur Dwivedi 	int errcode = 0;
282357f5ebcSAnkur Dwivedi 
283357f5ebcSAnkur Dwivedi 	flow_age = &roc_npc->flow_age;
284357f5ebcSAnkur Dwivedi 	if (age->timeout < flow_age->aging_poll_freq) {
285357f5ebcSAnkur Dwivedi 		plt_err("Age timeout should be greater or equal to %u seconds",
286357f5ebcSAnkur Dwivedi 			flow_age->aging_poll_freq);
287357f5ebcSAnkur Dwivedi 		errcode = NPC_ERR_ACTION_NOTSUP;
288357f5ebcSAnkur Dwivedi 		goto done;
289357f5ebcSAnkur Dwivedi 	}
290357f5ebcSAnkur Dwivedi 
291357f5ebcSAnkur Dwivedi 	flow->age_context = age->context == NULL ? flow : age->context;
292357f5ebcSAnkur Dwivedi 	flow->timeout = age->timeout;
293a4477550SAnkur Dwivedi 	flow->timeout_cycles = plt_tsc_cycles() + age->timeout * plt_tsc_hz();
294c436ab84SAnkur Dwivedi 	flow->has_age_action = true;
295357f5ebcSAnkur Dwivedi 
296357f5ebcSAnkur Dwivedi 	if (flow_age->age_flow_refcnt == 0) {
2973ddc923bSAnkur Dwivedi 		errcode = npc_aged_flows_bitmap_alloc(roc_npc);
2983ddc923bSAnkur Dwivedi 		if (errcode != 0)
2993ddc923bSAnkur Dwivedi 			goto done;
3003ddc923bSAnkur Dwivedi 
301357f5ebcSAnkur Dwivedi 		flow_age->aged_flows_get_thread_exit = false;
302357f5ebcSAnkur Dwivedi 		if (plt_thread_create_control(&flow_age->aged_flows_poll_thread,
303357f5ebcSAnkur Dwivedi 					   "Aged Flows Get Ctrl Thread",
304357f5ebcSAnkur Dwivedi 					   npc_aged_flows_get, roc_npc) != 0) {
305357f5ebcSAnkur Dwivedi 			plt_err("Failed to create thread for age flows");
3063ddc923bSAnkur Dwivedi 			npc_aged_flows_bitmap_free(roc_npc);
307357f5ebcSAnkur Dwivedi 			errcode = NPC_ERR_ACTION_NOTSUP;
308357f5ebcSAnkur Dwivedi 			goto done;
309357f5ebcSAnkur Dwivedi 		}
310357f5ebcSAnkur Dwivedi 	}
311357f5ebcSAnkur Dwivedi done:
312357f5ebcSAnkur Dwivedi 	return errcode;
313357f5ebcSAnkur Dwivedi }
314357f5ebcSAnkur Dwivedi 
315357f5ebcSAnkur Dwivedi void
316357f5ebcSAnkur Dwivedi npc_aging_ctrl_thread_destroy(struct roc_npc *roc_npc)
317357f5ebcSAnkur Dwivedi {
318357f5ebcSAnkur Dwivedi 	struct roc_npc_flow_age *flow_age;
319357f5ebcSAnkur Dwivedi 
320357f5ebcSAnkur Dwivedi 	flow_age = &roc_npc->flow_age;
32185e9542dSSatheesh Paul 	if (plt_thread_is_valid(flow_age->aged_flows_poll_thread)) {
322357f5ebcSAnkur Dwivedi 		flow_age->aged_flows_get_thread_exit = true;
323357f5ebcSAnkur Dwivedi 		plt_thread_join(flow_age->aged_flows_poll_thread, NULL);
324357f5ebcSAnkur Dwivedi 		npc_aged_flows_bitmap_free(roc_npc);
325357f5ebcSAnkur Dwivedi 	}
32685e9542dSSatheesh Paul }
327357f5ebcSAnkur Dwivedi 
328357f5ebcSAnkur Dwivedi void *
329357f5ebcSAnkur Dwivedi roc_npc_aged_flow_ctx_get(struct roc_npc *roc_npc, uint32_t mcam_id)
330357f5ebcSAnkur Dwivedi {
331357f5ebcSAnkur Dwivedi 	struct npc *npc = roc_npc_to_npc_priv(roc_npc);
332357f5ebcSAnkur Dwivedi 	struct npc_age_flow_list_head *list;
333357f5ebcSAnkur Dwivedi 	struct npc_age_flow_entry *fl_iter;
334357f5ebcSAnkur Dwivedi 
335357f5ebcSAnkur Dwivedi 	list = &npc->age_flow_list;
336357f5ebcSAnkur Dwivedi 
337357f5ebcSAnkur Dwivedi 	TAILQ_FOREACH(fl_iter, list, next) {
338357f5ebcSAnkur Dwivedi 		if (fl_iter->flow->mcam_id == mcam_id)
339357f5ebcSAnkur Dwivedi 			return fl_iter->flow->age_context;
340357f5ebcSAnkur Dwivedi 	}
341357f5ebcSAnkur Dwivedi 
342357f5ebcSAnkur Dwivedi 	return NULL;
343357f5ebcSAnkur Dwivedi }
344