aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/include/odp_classification_internal.h
blob: bc0a12f8fd76aac2be619988c0ed67ef76228958 (plain)
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
/* Copyright (c) 2014-2018, Linaro Limited
 * Copyright (c) 2021, Nokia
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

/**
 * @file
 *
 * ODP Classification Internal
 * Describes the classification internal Functions
 */

#ifndef __ODP_CLASSIFICATION_INTERNAL_H_
#define __ODP_CLASSIFICATION_INTERNAL_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <odp/api/atomic.h>
#include <odp/api/classification.h>
#include <odp/api/hints.h>
#include <odp/api/queue.h>
#include <odp_packet_internal.h>
#include <odp/api/packet_io.h>
#include <odp_packet_io_internal.h>
#include <odp_classification_datamodel.h>

extern cls_global_t *_odp_cls_global;

static inline cos_t *_odp_cos_entry_from_idx(uint32_t ndx)
{
	return &_odp_cls_global->cos_tbl.cos_entry[ndx];
}

static inline int _odp_cos_queue_idx(const cos_t *cos, odp_queue_t queue)
{
	uint32_t i, tbl_idx;
	int queue_idx = -1;

	if (cos->s.num_queue == 1) {
		if (odp_unlikely(cos->s.queue != queue))
			return -1;
		return 0;
	}

	tbl_idx = cos->s.index * CLS_COS_QUEUE_MAX;
	for (i = 0; i < cos->s.num_queue; i++) {
		if (_odp_cls_global->queue_grp_tbl.s.queue[tbl_idx + i] == queue) {
			queue_idx = i;
			break;
		}
	}
	return queue_idx;
}

static inline void _odp_cos_queue_stats_add(cos_t *cos, odp_queue_t queue,
					    uint64_t packets, uint64_t discards)
{
	int queue_idx = _odp_cos_queue_idx(cos, queue);

	if (odp_unlikely(queue_idx < 0)) {
		ODP_ERR("Queue not attached to the CoS\n");
		return;
	}

	if (packets)
		odp_atomic_add_u64(&cos->s.stats[queue_idx].packets, packets);
	if (discards)
		odp_atomic_add_u64(&cos->s.stats[queue_idx].discards, discards);
}

/** Classification Internal function **/

/**
@internal

Packet Classifier

Start function for Packet Classifier
This function calls Classifier module internal functions for a given packet and
selects destination queue and packet pool based on selected PMR and CoS.
**/
int _odp_cls_classify_packet(pktio_entry_t *entry, const uint8_t *base,
			     uint16_t pkt_len, uint32_t seg_len, odp_pool_t *pool,
			     odp_packet_hdr_t *pkt_hdr, odp_bool_t parse);

/**
Packet IO classifier init

This function does initialization of classifier object associated with pktio.
This function should be called during pktio initialization.
**/
int _odp_pktio_classifier_init(pktio_entry_t *pktio);

#ifdef __cplusplus
}
#endif
#endif