DPDK logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2019-2021 Broadcom
 * All rights reserved.
 */

#include <string.h>
#include <rte_common.h>

#include "tf_tcam.h"
#include "tf_common.h"
#include "tf_util.h"
#include "tf_rm.h"
#include "tf_device.h"
#include "tfp.h"
#include "tf_session.h"
#include "tf_msg.h"
#include "tf_shadow_tcam.h"

struct tf;

/**
 * TCAM Shadow DBs
 */
static void *shadow_tcam_db[TF_DIR_MAX];

/**
 * Shadow init flag, set on bind and cleared on unbind
 */
static uint8_t shadow_init;

int
tf_tcam_bind(struct tf *tfp,
	     struct tf_tcam_cfg_parms *parms)
{
	int rc;
	int db_rc[TF_DIR_MAX] = { 0 };
	int i, d;
	struct tf_rm_alloc_info info;
	struct tf_rm_free_db_parms fparms;
	struct tf_rm_create_db_parms db_cfg;
	struct tf_tcam_resources *tcam_cnt;
	struct tf_rm_get_alloc_info_parms ainfo;
	struct tf_shadow_tcam_free_db_parms fshadow;
	struct tf_shadow_tcam_cfg_parms shadow_cfg;
	struct tf_shadow_tcam_create_db_parms shadow_cdb;
	uint16_t num_slices = 1;
	struct tf_session *tfs;
	struct tf_dev_info *dev;
	struct tcam_rm_db *tcam_db;
	struct tfp_calloc_parms cparms;

	TF_CHECK_PARMS2(tfp, parms);

	/* Retrieve the session information */
	rc = tf_session_get_session_internal(tfp, &tfs);
	if (rc)
		return rc;

	/* Retrieve the device information */
	rc = tf_session_get_device(tfs, &dev);
	if (rc)
		return rc;

	if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
		rc = -EOPNOTSUPP;
		TFP_DRV_LOG(ERR,
			    "Operation not supported, rc:%s\n",
			    strerror(-rc));
		return rc;
	}

	rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
						  TF_TCAM_TBL_TYPE_WC_TCAM,
						  0,
						  &num_slices);
	if (rc)
		return rc;

	tcam_cnt = parms->resources->tcam_cnt;
	if ((tcam_cnt[TF_DIR_RX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] % num_slices) ||
	    (tcam_cnt[TF_DIR_TX].cnt[TF_TCAM_TBL_TYPE_WC_TCAM] % num_slices)) {
		TFP_DRV_LOG(ERR,
			    "Requested num of WC TCAM entries has to be multiple %d\n",
			    num_slices);
		return -EINVAL;
	}

	memset(&db_cfg, 0, sizeof(db_cfg));
	cparms.nitems = 1;
	cparms.size = sizeof(struct tcam_rm_db);
	cparms.alignment = 0;
	if (tfp_calloc(&cparms) != 0) {
		TFP_DRV_LOG(ERR, "tcam_rm_db alloc error %s\n",
			    strerror(ENOMEM));
		return -ENOMEM;
	}

	tcam_db = cparms.mem_va;
	for (i = 0; i < TF_DIR_MAX; i++)
		tcam_db->tcam_db[i] = NULL;
	tf_session_set_db(tfp, TF_MODULE_TYPE_TCAM, tcam_db);

	db_cfg.module = TF_MODULE_TYPE_TCAM;
	db_cfg.num_elements = parms->num_elements;
	db_cfg.cfg = parms->cfg;

	for (d = 0; d < TF_DIR_MAX; d++) {
		db_cfg.dir = d;
		db_cfg.alloc_cnt = parms->resources->tcam_cnt[d].cnt;
		db_cfg.rm_db = (void *)&tcam_db->tcam_db[d];
		if (tf_session_is_shared_session(tfs) &&
			(!tf_session_is_shared_session_creator(tfs)))
			db_rc[d] = tf_rm_create_db_no_reservation(tfp, &db_cfg);
		else
			db_rc[d] = tf_rm_create_db(tfp, &db_cfg);
	}

	/* No db created */
	if (db_rc[TF_DIR_RX] && db_rc[TF_DIR_TX]) {
		TFP_DRV_LOG(ERR, "No TCAM DB created\n");
		return db_rc[TF_DIR_RX];
	}

	/* check if reserved resource for WC is multiple of num_slices */
	for (d = 0; d < TF_DIR_MAX; d++) {
		if (!tcam_db->tcam_db[d])
			continue;

		memset(&info, 0, sizeof(info));
		ainfo.rm_db = tcam_db->tcam_db[d];
		ainfo.subtype = TF_TCAM_TBL_TYPE_WC_TCAM;
		ainfo.info = &info;
		rc = tf_rm_get_info(&ainfo);
		if (rc)
			goto error;

		if (info.entry.start % num_slices != 0 ||
		    info.entry.stride % num_slices != 0) {
			TFP_DRV_LOG(ERR,
				    "%s: TCAM reserved resource is not multiple of %d\n",
				    tf_dir_2_str(d),
				    num_slices);
			rc = -EINVAL;
			goto error;
		}
	}

	/* Initialize the TCAM manager. */
	if (parms->shadow_copy) {
		for (d = 0; d < TF_DIR_MAX; d++) {
			memset(&shadow_cfg, 0, sizeof(shadow_cfg));
			memset(&shadow_cdb, 0, sizeof(shadow_cdb));
			/* Get the base addresses of the tcams for tcam mgr */
			for (i = 0; i < TF_TCAM_TBL_TYPE_MAX; i++) {
				memset(&info, 0, sizeof(info));

				if (!parms->resources->tcam_cnt[d].cnt[i])
					continue;
				ainfo.rm_db = tcam_db->tcam_db[d];
				ainfo.subtype = i;
				ainfo.info = &info;
				rc = tf_rm_get_info(&ainfo);
				if (rc)
					goto error;

				shadow_cfg.base_addr[i] = info.entry.start;
			}

			/* Create the shadow db */
			shadow_cfg.alloc_cnt =
				parms->resources->tcam_cnt[d].cnt;
			shadow_cfg.num_entries = parms->num_elements;

			shadow_cdb.shadow_db = &shadow_tcam_db[d];
			shadow_cdb.cfg = &shadow_cfg;
			rc = tf_shadow_tcam_create_db(&shadow_cdb);
			if (rc) {
				TFP_DRV_LOG(ERR,
					    "TCAM MGR DB creation failed "
					    "rc=%d\n", rc);
				goto error;
			}
		}
		shadow_init = 1;
	}

	TFP_DRV_LOG(INFO,
		    "TCAM - initialized\n");

	return 0;
error:
	for (i = 0; i < TF_DIR_MAX; i++) {
		memset(&fparms, 0, sizeof(fparms));
		fparms.dir = i;
		fparms.rm_db = tcam_db->tcam_db[i];
		/* Ignoring return here since we are in the error case */
		(void)tf_rm_free_db(tfp, &fparms);

		if (parms->shadow_copy) {
			fshadow.shadow_db = shadow_tcam_db[i];
			tf_shadow_tcam_free_db(&fshadow);
			shadow_tcam_db[i] = NULL;
		}

		tcam_db->tcam_db[i] = NULL;
		tf_session_set_db(tfp, TF_MODULE_TYPE_TCAM, NULL);
	}

	shadow_init = 0;

	return rc;
}

int
tf_tcam_unbind(struct tf *tfp)
{
	int rc;
	int i;
	struct tf_rm_free_db_parms fparms;
	struct tcam_rm_db *tcam_db;
	void *tcam_db_ptr = NULL;
	struct tf_shadow_tcam_free_db_parms fshadow;
	TF_CHECK_PARMS1(tfp);

	rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
	if (rc) {
		return 0;
	}
	tcam_db = (struct tcam_rm_db *)tcam_db_ptr;

	for (i = 0; i < TF_DIR_MAX; i++) {
		if (tcam_db->tcam_db[i] == NULL)
			continue;
		memset(&fparms, 0, sizeof(fparms));
		fparms.dir = i;
		fparms.rm_db = tcam_db->tcam_db[i];
		rc = tf_rm_free_db(tfp, &fparms);
		if (rc)
			return rc;

		tcam_db->tcam_db[i] = NULL;

		if (shadow_init) {
			memset(&fshadow, 0, sizeof(fshadow));

			fshadow.shadow_db = shadow_tcam_db[i];
			tf_shadow_tcam_free_db(&fshadow);
			shadow_tcam_db[i] = NULL;
		}
	}

	shadow_init = 0;

	return 0;
}

int
tf_tcam_alloc(struct tf *tfp,
	      struct tf_tcam_alloc_parms *parms)
{
	int rc, i;
	struct tf_session *tfs;
	struct tf_dev_info *dev;
	struct tf_rm_allocate_parms aparms;
	uint16_t num_slices = 1;
	uint32_t index;
	struct tcam_rm_db *tcam_db;
	void *tcam_db_ptr = NULL;

	TF_CHECK_PARMS2(tfp, parms);

	/* Retrieve the session information */
	rc = tf_session_get_session_internal(tfp, &tfs);
	if (rc)
		return rc;

	/* Retrieve the device information */
	rc = tf_session_get_device(tfs, &dev);
	if (rc)
		return rc;

	if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
		rc = -EOPNOTSUPP;
		TFP_DRV_LOG(ERR,
			    "%s: Operation not supported, rc:%s\n",
			    tf_dir_2_str(parms->dir),
			    strerror(-rc));
		return rc;
	}

	/* Need to retrieve number of slices based on the key_size */
	rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
						  parms->type,
						  parms->key_size,
						  &num_slices);
	if (rc)
		return rc;

	rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
	if (rc) {
		TFP_DRV_LOG(ERR,
			    "Failed to get tcam_db from session, rc:%s\n",
			    strerror(-rc));
		return rc;
	}
	tcam_db = (struct tcam_rm_db *)tcam_db_ptr;

	/*
	 * For WC TCAM, number of slices could be 4, 2, 1 based on
	 * the key_size. For other TCAM, it is always 1
	 */
	for (i = 0; i < num_slices; i++) {
		memset(&aparms, 0, sizeof(aparms));
		aparms.rm_db = tcam_db->tcam_db[parms->dir];
		aparms.subtype = parms->type;
		aparms.priority = parms->priority;
		aparms.index = &index;
		rc = tf_rm_allocate(&aparms);
		if (rc) {
			TFP_DRV_LOG(ERR,
				    "%s: Failed tcam, type:%d\n",
				    tf_dir_2_str(parms->dir),
				    parms->type);
			return rc;
		}

		/* return the start index of each row */
		if (i == 0)
			parms->idx = index;
	}

	return 0;
}

int
tf_tcam_free(struct tf *tfp,
	     struct tf_tcam_free_parms *parms)
{
	int rc;
	struct tf_session *tfs;
	struct tf_dev_info *dev;
	struct tf_rm_is_allocated_parms aparms;
	struct tf_rm_free_parms fparms;
	struct tf_rm_get_hcapi_parms hparms;
	uint16_t num_slices = 1;
	int allocated = 0;
	struct tf_shadow_tcam_remove_parms shparms;
	int i;
	struct tcam_rm_db *tcam_db;
	void *tcam_db_ptr = NULL;

	TF_CHECK_PARMS2(tfp, parms);

	/* Retrieve the session information */
	rc = tf_session_get_session_internal(tfp, &tfs);
	if (rc)
		return rc;

	/* Retrieve the device information */
	rc = tf_session_get_device(tfs, &dev);
	if (rc)
		return rc;

	if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
		rc = -EOPNOTSUPP;
		TFP_DRV_LOG(ERR,
			    "%s: Operation not supported, rc:%s\n",
			    tf_dir_2_str(parms->dir),
			    strerror(-rc));
		return rc;
	}

	/* Need to retrieve row size etc */
	rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
						  parms->type,
						  0,
						  &num_slices);
	if (rc)
		return rc;

	if (parms->idx % num_slices) {
		TFP_DRV_LOG(ERR,
			    "%s: TCAM reserved resource is not multiple of %d\n",
			    tf_dir_2_str(parms->dir),
			    num_slices);
		return -EINVAL;
	}

	rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
	if (rc) {
		TFP_DRV_LOG(ERR,
			    "Failed to get em_ext_db from session, rc:%s\n",
			    strerror(-rc));
		return rc;
	}
	tcam_db = (struct tcam_rm_db *)tcam_db_ptr;

	/* Check if element is in use */
	memset(&aparms, 0, sizeof(aparms));
	aparms.rm_db = tcam_db->tcam_db[parms->dir];
	aparms.subtype = parms->type;
	aparms.index = parms->idx;
	aparms.allocated = &allocated;
	rc = tf_rm_is_allocated(&aparms);
	if (rc)
		return rc;

	if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
		TFP_DRV_LOG(ERR,
			    "%s: Entry already free, type:%d, index:%d\n",
			    tf_dir_2_str(parms->dir),
			    parms->type,
			    parms->idx);
		return -EINVAL;
	}

	/*
	 * The Shadow mgmt, if enabled, determines if the entry needs
	 * to be deleted.
	 */
	if (shadow_init) {
		shparms.shadow_db = shadow_tcam_db[parms->dir];
		shparms.fparms = parms;
		rc = tf_shadow_tcam_remove(&shparms);
		if (rc) {
			/*
			 * Should not get here, log it and let the entry be
			 * deleted.
			 */
			TFP_DRV_LOG(ERR, "%s: Shadow free fail, "
				    "type:%d index:%d deleting the entry.\n",
				    tf_dir_2_str(parms->dir),
				    parms->type,
				    parms->idx);
		} else {
			/*
			 * If the entry still has references, just return the
			 * ref count to the caller.  No need to remove entry
			 * from rm or hw
			 */
			if (parms->ref_cnt >= 1)
				return rc;
		}
	}

	for (i = 0; i < num_slices; i++) {
		/* Free requested element */
		memset(&fparms, 0, sizeof(fparms));
		fparms.rm_db = tcam_db->tcam_db[parms->dir];
		fparms.subtype = parms->type;
		fparms.index = parms->idx + i;
		rc = tf_rm_free(&fparms);
		if (rc) {
			TFP_DRV_LOG(ERR,
				    "%s: Free failed, type:%d, index:%d\n",
				    tf_dir_2_str(parms->dir),
				    parms->type,
				    parms->idx);
			return rc;
		}
	}

	/* Convert TF type to HCAPI RM type */
	memset(&hparms, 0, sizeof(hparms));

	hparms.rm_db = tcam_db->tcam_db[parms->dir];
	hparms.subtype = parms->type;
	hparms.hcapi_type = &parms->hcapi_type;

	rc = tf_rm_get_hcapi_type(&hparms);
	if (rc)
		return rc;

	rc = tf_msg_tcam_entry_free(tfp, dev, parms);
	if (rc) {
		/* Log error */
		TFP_DRV_LOG(ERR,
			    "%s: %s: Entry %d free failed, rc:%s\n",
			    tf_dir_2_str(parms->dir),
			    tf_tcam_tbl_2_str(parms->type),
			    parms->idx,
			    strerror(-rc));
		return rc;
	}

	return 0;
}

int
tf_tcam_alloc_search(struct tf *tfp,
		     struct tf_tcam_alloc_search_parms *parms)
{
	struct tf_shadow_tcam_search_parms sparms;
	struct tf_shadow_tcam_bind_index_parms bparms;
	struct tf_tcam_free_parms fparms;
	struct tf_tcam_alloc_parms aparms;
	uint16_t num_slice_per_row = 1;
	struct tf_session *tfs;
	struct tf_dev_info *dev;
	int rc;

	TF_CHECK_PARMS2(tfp, parms);

	if (!shadow_init || !shadow_tcam_db[parms->dir]) {
		TFP_DRV_LOG(ERR, "%s: TCAM Shadow not initialized for %s\n",
			    tf_dir_2_str(parms->dir),
			    tf_tcam_tbl_2_str(parms->type));
		return -EINVAL;
	}

	/* Retrieve the session information */
	rc = tf_session_get_session_internal(tfp, &tfs);
	if (rc)
		return rc;

	/* Retrieve the device information */
	rc = tf_session_get_device(tfs, &dev);
	if (rc)
		return rc;

	if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
		rc = -EOPNOTSUPP;
		TFP_DRV_LOG(ERR,
			    "%s: Operation not supported, rc:%s\n",
			    tf_dir_2_str(parms->dir),
			    strerror(-rc));
		return rc;
	}

	/* Need to retrieve row size etc */
	rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
						  parms->type,
						  parms->key_size,
						  &num_slice_per_row);
	if (rc)
		return rc;

	/*
	 * Prep the shadow search, reusing the parms from original search
	 * instead of copying them.  Shadow will update output in there.
	 */
	memset(&sparms, 0, sizeof(sparms));
	sparms.sparms = parms;
	sparms.shadow_db = shadow_tcam_db[parms->dir];

	rc = tf_shadow_tcam_search(&sparms);
	if (rc)
		return rc;

	/*
	 * The app didn't request us to alloc the entry, so return now.
	 * The hit should have been updated in the original search parm.
	 */
	if (!parms->alloc || parms->search_status != MISS)
		return rc;

	/* Caller desires an allocate on miss */
	if (dev->ops->tf_dev_alloc_tcam == NULL) {
		rc = -EOPNOTSUPP;
		TFP_DRV_LOG(ERR,
			    "%s: Operation not supported, rc:%s\n",
			    tf_dir_2_str(parms->dir),
			    strerror(-rc));
		return rc;
	}
	memset(&aparms, 0, sizeof(aparms));
	aparms.dir = parms->dir;
	aparms.type = parms->type;
	aparms.key_size = parms->key_size;
	aparms.priority = parms->priority;
	rc = dev->ops->tf_dev_alloc_tcam(tfp, &aparms);
	if (rc)
		return rc;

	/* Successful allocation, attempt to add it to the shadow */
	memset(&bparms, 0, sizeof(bparms));
	bparms.dir = parms->dir;
	bparms.shadow_db = shadow_tcam_db[parms->dir];
	bparms.type = parms->type;
	bparms.key = parms->key;
	bparms.mask = parms->mask;
	bparms.key_size = parms->key_size;
	bparms.idx = aparms.idx;
	bparms.hb_handle = sparms.hb_handle;
	rc = tf_shadow_tcam_bind_index(&bparms);
	if (rc) {
		/* Error binding entry, need to free the allocated idx */
		if (dev->ops->tf_dev_free_tcam == NULL) {
			rc = -EOPNOTSUPP;
			TFP_DRV_LOG(ERR,
				    "%s: Operation not supported, rc:%s\n",
				    tf_dir_2_str(parms->dir),
				    strerror(-rc));
			return rc;
		}

		fparms.dir = parms->dir;
		fparms.type = parms->type;
		fparms.idx = aparms.idx;
		rc = dev->ops->tf_dev_free_tcam(tfp, &fparms);
		if (rc)
			return rc;
	}

	/* Add the allocated index to output and done */
	parms->idx = aparms.idx;

	return 0;
}

int
tf_tcam_set(struct tf *tfp __rte_unused,
	    struct tf_tcam_set_parms *parms __rte_unused)
{
	int rc;
	struct tf_session *tfs;
	struct tf_dev_info *dev;
	struct tf_rm_is_allocated_parms aparms;
	struct tf_rm_get_hcapi_parms hparms;
	struct tf_shadow_tcam_insert_parms iparms;
	uint16_t num_slice_per_row = 1;
	int allocated = 0;
	struct tcam_rm_db *tcam_db;
	void *tcam_db_ptr = NULL;

	TF_CHECK_PARMS2(tfp, parms);

	/* Retrieve the session information */
	rc = tf_session_get_session_internal(tfp, &tfs);
	if (rc)
		return rc;

	/* Retrieve the device information */
	rc = tf_session_get_device(tfs, &dev);
	if (rc)
		return rc;

	if (dev->ops->tf_dev_get_tcam_slice_info == NULL) {
		rc = -EOPNOTSUPP;
		TFP_DRV_LOG(ERR,
			    "%s: Operation not supported, rc:%s\n",
			    tf_dir_2_str(parms->dir),
			    strerror(-rc));
		return rc;
	}

	/* Need to retrieve row size etc */
	rc = dev->ops->tf_dev_get_tcam_slice_info(tfp,
						  parms->type,
						  parms->key_size,
						  &num_slice_per_row);
	if (rc)
		return rc;

	rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
	if (rc) {
		TFP_DRV_LOG(ERR,
			    "Failed to get em_ext_db from session, rc:%s\n",
			    strerror(-rc));
		return rc;
	}
	tcam_db = (struct tcam_rm_db *)tcam_db_ptr;

	/* Check if element is in use */
	memset(&aparms, 0, sizeof(aparms));

	aparms.rm_db = tcam_db->tcam_db[parms->dir];
	aparms.subtype = parms->type;
	aparms.index = parms->idx;
	aparms.allocated = &allocated;
	rc = tf_rm_is_allocated(&aparms);
	if (rc)
		return rc;

	if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
		TFP_DRV_LOG(ERR,
			    "%s: Entry is not allocated, type:%d, index:%d\n",
			    tf_dir_2_str(parms->dir),
			    parms->type,
			    parms->idx);
		return -EINVAL;
	}

	/* Convert TF type to HCAPI RM type */
	memset(&hparms, 0, sizeof(hparms));

	hparms.rm_db = tcam_db->tcam_db[parms->dir];
	hparms.subtype = parms->type;
	hparms.hcapi_type = &parms->hcapi_type;

	rc = tf_rm_get_hcapi_type(&hparms);
	if (rc)
		return rc;

	rc = tf_msg_tcam_entry_set(tfp, dev, parms);
	if (rc) {
		/* Log error */
		TFP_DRV_LOG(ERR,
			    "%s: %s: Entry %d set failed, rc:%s",
			    tf_dir_2_str(parms->dir),
			    tf_tcam_tbl_2_str(parms->type),
			    parms->idx,
			    strerror(-rc));
		return rc;
	}

	/* Successfully added to hw, now for shadow if enabled. */
	if (!shadow_init || !shadow_tcam_db[parms->dir])
		return 0;

	iparms.shadow_db = shadow_tcam_db[parms->dir];
	iparms.sparms = parms;
	rc = tf_shadow_tcam_insert(&iparms);
	if (rc) {
		TFP_DRV_LOG(ERR,
			    "%s: %s: Entry %d set failed, rc:%s",
			    tf_dir_2_str(parms->dir),
			    tf_tcam_tbl_2_str(parms->type),
			    parms->idx,
			    strerror(-rc));
		return rc;
	}

	return 0;
}

int
tf_tcam_get(struct tf *tfp __rte_unused,
	    struct tf_tcam_get_parms *parms)
{
	int rc;
	struct tf_session *tfs;
	struct tf_dev_info *dev;
	struct tf_rm_is_allocated_parms aparms;
	struct tf_rm_get_hcapi_parms hparms;
	int allocated = 0;
	struct tcam_rm_db *tcam_db;
	void *tcam_db_ptr = NULL;

	TF_CHECK_PARMS2(tfp, parms);

	/* Retrieve the session information */
	rc = tf_session_get_session_internal(tfp, &tfs);
	if (rc)
		return rc;

	/* Retrieve the device information */
	rc = tf_session_get_device(tfs, &dev);
	if (rc)
		return rc;

	rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
	if (rc) {
		TFP_DRV_LOG(ERR,
			    "Failed to get em_ext_db from session, rc:%s\n",
			    strerror(-rc));
		return rc;
	}
	tcam_db = (struct tcam_rm_db *)tcam_db_ptr;

	/* Check if element is in use */
	memset(&aparms, 0, sizeof(aparms));

	aparms.rm_db = tcam_db->tcam_db[parms->dir];
	aparms.subtype = parms->type;
	aparms.index = parms->idx;
	aparms.allocated = &allocated;
	rc = tf_rm_is_allocated(&aparms);
	if (rc)
		return rc;

	if (allocated != TF_RM_ALLOCATED_ENTRY_IN_USE) {
		TFP_DRV_LOG(ERR,
			    "%s: Entry is not allocated, type:%d, index:%d\n",
			    tf_dir_2_str(parms->dir),
			    parms->type,
			    parms->idx);
		return -EINVAL;
	}

	/* Convert TF type to HCAPI RM type */
	memset(&hparms, 0, sizeof(hparms));

	hparms.rm_db = tcam_db->tcam_db[parms->dir];
	hparms.subtype = parms->type;
	hparms.hcapi_type = &parms->hcapi_type;

	rc = tf_rm_get_hcapi_type(&hparms);
	if (rc)
		return rc;

	rc = tf_msg_tcam_entry_get(tfp, dev, parms);
	if (rc) {
		/* Log error */
		TFP_DRV_LOG(ERR,
			    "%s: %s: Entry %d set failed, rc:%s",
			    tf_dir_2_str(parms->dir),
			    tf_tcam_tbl_2_str(parms->type),
			    parms->idx,
			    strerror(-rc));
		return rc;
	}

	return 0;
}

int
tf_tcam_get_resc_info(struct tf *tfp,
		      struct tf_tcam_resource_info *tcam)
{
	int rc;
	int d;
	struct tf_resource_info *dinfo;
	struct tf_rm_get_alloc_info_parms ainfo;
	void *tcam_db_ptr = NULL;
	struct tcam_rm_db *tcam_db;

	TF_CHECK_PARMS2(tfp, tcam);

	rc = tf_session_get_db(tfp, TF_MODULE_TYPE_TCAM, &tcam_db_ptr);
	if (rc == -ENOMEM)
		return 0;  /* db doesn't exist */
	else if (rc)
		return rc; /* error getting db */

	tcam_db = (struct tcam_rm_db *)tcam_db_ptr;

	/* check if reserved resource for WC is multiple of num_slices */
	for (d = 0; d < TF_DIR_MAX; d++) {
		ainfo.rm_db = tcam_db->tcam_db[d];

		if (!ainfo.rm_db)
			continue;

		dinfo = tcam[d].info;

		ainfo.info = (struct tf_rm_alloc_info *)dinfo;
		ainfo.subtype = 0;
		rc = tf_rm_get_all_info(&ainfo, TF_TCAM_TBL_TYPE_MAX);
		if (rc && rc != -ENOTSUP)
			return rc;
	}

	return 0;
}