Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PATCH v6] api: cls: add pmr/cos create/destroy multi functions #1912

Merged
merged 10 commits into from
Oct 20, 2023
78 changes: 77 additions & 1 deletion include/odp/api/spec/classification.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) 2014-2018 Linaro Limited
* Copyright (c) 2021-2022 Nokia
* Copyright (c) 2021-2023 Nokia
*/

/**
Expand Down Expand Up @@ -739,6 +739,30 @@ int odp_cls_capability(odp_cls_capability_t *capability);
odp_cos_t odp_cls_cos_create(const char *name,
const odp_cls_cos_param_t *param);

/**
* Create multiple class-of-services
*
* Otherwise like odp_cls_cos_create(), but creates multiple CoSes with a
* single call. The output CoS handles are written in the same order as input
* parameters. A single odp_cls_cos_create_multi() call is equivalent to calling
* odp_cls_cos_create() 'num' times in row.
*
* Each parameter array must contain 'num' elements with the exception that
* 'name' array may also be NULL.
*
* @param name Array of CoS name pointers or NULL. NULL is also valid
* CoS name pointer value.
* @param param Array of CoS parameters
* @param[out] cos Array of CoS handles for output
* @param num Number of CoSes to create
*
* @return Number of CoSes actually created (0 ... num)
* @retval <0 on failure
*/
int odp_cls_cos_create_multi(const char *name[],
const odp_cls_cos_param_t param[],
odp_cos_t cos[], int num);

/**
* Queue hash result
* Returns the queue within a CoS in which a particular packet will be enqueued
Expand Down Expand Up @@ -770,6 +794,20 @@ odp_queue_t odp_cls_hash_result(odp_cos_t cos, odp_packet_t packet);
*/
int odp_cos_destroy(odp_cos_t cos);

/**
* Destroy multiple class-of-services
*
* Otherwise like odp_cos_destroy(), but destroys multiple CoSes with a single
* call.
*
* @param cos Array of CoS handles
* @param num Number of CoSes to destroy
*
* @retval Number of CoSes actually destroyed (1 ... num)
* @retval <0 on failure
*/
int odp_cos_destroy_multi(odp_cos_t cos[], int num);

/**
* Assign a queue for a class-of-service
*
Expand Down Expand Up @@ -988,6 +1026,30 @@ odp_pmr_t odp_cls_pmr_create(const odp_pmr_param_t *terms, int num_terms,
*/
odp_pmr_t odp_cls_pmr_create_opt(const odp_pmr_create_opt_t *opt,
odp_cos_t src_cos, odp_cos_t dst_cos);

/**
* Create multiple packet matching rules
*
* Otherwise like odp_cls_pmr_create_opt(), but creates multiple rules with a
* single call. The output PMR handles are written in the same order as input
* parameters. A single odp_cls_pmr_create_multi() call is equivalent to calling
* odp_cls_pmr_create_opt() 'num' times in row.
*
* Each parameter array must contain 'num' elements.
*
* @param opt Array of PMR create options
* @param src_cos Array of source CoS handles
* @param dst_cos Array of destination CoS handles
* @param[out] pmr Array of PMR handles for output
* @param num Number of packet matching rules to create
*
* @return Number of PMRs actually created (0 ... num)
* @retval <0 on failure
*/
int odp_cls_pmr_create_multi(const odp_pmr_create_opt_t opt[],
odp_cos_t src_cos[], odp_cos_t dst_cos[],
odp_pmr_t pmr[], int num);

/**
* Function to destroy a packet match rule
*
Expand All @@ -1007,6 +1069,20 @@ odp_pmr_t odp_cls_pmr_create_opt(const odp_pmr_create_opt_t *opt,
*/
int odp_cls_pmr_destroy(odp_pmr_t pmr);

/**
* Destroy multiple packet matching rules
*
* Otherwise like odp_cls_pmr_destroy(), but destroys multiple PMRs with a
* single call.
*
* @param pmr Array of PMR handles
* @param num Number of PMRs to destroy
*
* @retval Number of PMRs actually destroyed (1 ... num)
* @retval <0 on failure
*/
int odp_cls_pmr_destroy_multi(odp_pmr_t pmr[], int num);

/**
* Assigns a packet pool for a specific class of service
*
Expand Down
87 changes: 82 additions & 5 deletions platform/linux-generic/odp_classification.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
/* Copyright (c) 2014-2018, Linaro Limited
* Copyright (c) 2019-2022, Nokia
* Copyright (c) 2019-2023, Nokia
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <odp/api/classification.h>
#include <odp/api/align.h>
#include <odp/api/queue.h>
#include <odp/api/debug.h>
#include <odp/api/hints.h>
#include <odp/api/packet_io.h>
#include <odp/api/pool.h>
#include <odp/api/queue.h>
#include <odp/api/shared_memory.h>
#include <odp/api/spinlock.h>

#include <odp_init_internal.h>
#include <odp_debug_internal.h>
#include <odp_packet_internal.h>
#include <odp/api/packet_io.h>
#include <odp_packet_io_internal.h>
#include <odp_classification_datamodel.h>
#include <odp_classification_internal.h>
#include <odp/api/shared_memory.h>
#include <protocols/eth.h>
#include <protocols/ip.h>
#include <protocols/ipsec.h>
Expand All @@ -28,7 +31,6 @@
#include <errno.h>
#include <stdbool.h>
#include <inttypes.h>
#include <odp/api/spinlock.h>

/* Debug level for per packet classification operations */
#define CLS_DBG 3
Expand Down Expand Up @@ -362,6 +364,26 @@ odp_cos_t odp_cls_cos_create(const char *name, const odp_cls_cos_param_t *param_
return ODP_COS_INVALID;
}

int odp_cls_cos_create_multi(const char *name[], const odp_cls_cos_param_t param[],
odp_cos_t cos[], int num)
{
int i;

_ODP_ASSERT(param != NULL);
_ODP_ASSERT(cos != NULL);

for (i = 0; i < num; i++) {
const char *cur_name = name != NULL ? name[i] : NULL;
odp_cos_t new_cos = odp_cls_cos_create(cur_name, &param[i]);

if (odp_unlikely(new_cos == ODP_COS_INVALID))
return (i == 0) ? -1 : i;

cos[i] = new_cos;
}
return i;
}

/*
* Allocate an odp_pmr_t Handle
*/
Expand Down Expand Up @@ -426,6 +448,23 @@ int odp_cos_destroy(odp_cos_t cos_id)
return 0;
}

int odp_cos_destroy_multi(odp_cos_t cos[], int num)
{
int i;

_ODP_ASSERT(cos != NULL);
_ODP_ASSERT(num > 0);

for (i = 0; i < num; i++) {
int ret = odp_cos_destroy(cos[i]);

if (ret)
return (i == 0) ? ret : i;
}

return i;
}

int odp_cos_queue_set(odp_cos_t cos_id, odp_queue_t queue_id)
{
cos_t *cos = get_cos_entry(cos_id);
Expand Down Expand Up @@ -785,6 +824,23 @@ int odp_cls_pmr_destroy(odp_pmr_t pmr_id)
return 0;
}

int odp_cls_pmr_destroy_multi(odp_pmr_t pmr[], int num)
{
int i;

_ODP_ASSERT(pmr != NULL);
_ODP_ASSERT(num > 0);

for (i = 0; i < num; i++) {
int ret = odp_cls_pmr_destroy(pmr[i]);

if (ret)
return (i == 0) ? ret : i;
}

return i;
}

static odp_pmr_t cls_pmr_create(const odp_pmr_param_t *terms, int num_terms, uint16_t mark,
odp_cos_t src_cos, odp_cos_t dst_cos)
{
Expand Down Expand Up @@ -855,6 +911,27 @@ odp_pmr_t odp_cls_pmr_create_opt(const odp_pmr_create_opt_t *opt,
return cls_pmr_create(opt->terms, opt->num_terms, opt->mark, src_cos, dst_cos);
}

int odp_cls_pmr_create_multi(const odp_pmr_create_opt_t opt[], odp_cos_t src_cos[],
odp_cos_t dst_cos[], odp_pmr_t pmr[], int num)
{
int i;

_ODP_ASSERT(opt != NULL);
_ODP_ASSERT(src_cos != NULL);
_ODP_ASSERT(dst_cos != NULL);
_ODP_ASSERT(pmr != NULL);

for (i = 0; i < num; i++) {
odp_pmr_t new_pmr = odp_cls_pmr_create_opt(&opt[i], src_cos[i], dst_cos[i]);

if (odp_unlikely(new_pmr == ODP_PMR_INVALID))
return (i == 0) ? -1 : i;

pmr[i] = new_pmr;
}
return i;
}

int odp_cls_cos_pool_set(odp_cos_t cos_id, odp_pool_t pool)
{
cos_t *cos;
Expand Down
Loading