From patchwork Sun Feb 1 00:16:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 44106 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3C6B12359E for ; Sun, 1 Feb 2015 00:17:23 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id x12sf13569128wgg.0 for ; Sat, 31 Jan 2015 16:17:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=YNgS2dgjI1WpdAvOgpE1Uco979n2JmjOANDlQBLaY+I=; b=gV67NbqtZRD6CuTz4Rgyfoe8ku1L5F8q+4Uyp1PNq5LrVO+7GWcnBZOZMAWdirmURr 7BQC//lCi/23zmnFQPNGQ0PDr6R6fPHnZviJT1B+owKNiDBZHvtHx458ykiRNXOEw8AZ 8H1DvFvlo1ZBK114HZdboBRakhbn89gTWerllKN1A1IWRzImrryuEhYq8nKz/VkIo/Wn h4sVcLI4EV53gAeEPTqGqwg0Ct6pbkvrXf2/2sRhcf8Tnt+u+yevxAhdmdvmMMgBr0pX MpIJNpXyqHX5ZOA9EOO4I9YZxOMFyD1NT6obHUdMf4aoK0tYk12SwTGE1qoyfBMEk+h6 37YQ== X-Gm-Message-State: ALoCoQkc7sp1pQzi2xO+qYge1JiPglDnkD10Hy6y+spiFHUTIJGomzc1WvFj0v8j9ViRoCDIETFM X-Received: by 10.152.121.65 with SMTP id li1mr1591196lab.0.1422749841805; Sat, 31 Jan 2015 16:17:21 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.129 with SMTP id d1ls243399laf.18.gmail; Sat, 31 Jan 2015 16:17:21 -0800 (PST) X-Received: by 10.152.45.4 with SMTP id i4mr12963856lam.74.1422749841514; Sat, 31 Jan 2015 16:17:21 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id y3si13344182laj.127.2015.01.31.16.17.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Jan 2015 16:17:21 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id hz20so31139028lab.6 for ; Sat, 31 Jan 2015 16:17:21 -0800 (PST) X-Received: by 10.112.170.36 with SMTP id aj4mr12742692lbc.3.1422749841397; Sat, 31 Jan 2015 16:17:21 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp507658lbj; Sat, 31 Jan 2015 16:17:20 -0800 (PST) X-Received: by 10.140.83.69 with SMTP id i63mr25423868qgd.97.1422749840001; Sat, 31 Jan 2015 16:17:20 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id p1si19946095qaa.13.2015.01.31.16.17.18 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 31 Jan 2015 16:17:19 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YHiE1-0002Jw-2A; Sun, 01 Feb 2015 00:17:17 +0000 Received: from mail-oi0-f49.google.com ([209.85.218.49]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YHiDm-0002ID-QJ for lng-odp@lists.linaro.org; Sun, 01 Feb 2015 00:17:02 +0000 Received: by mail-oi0-f49.google.com with SMTP id a3so39632042oib.8 for ; Sat, 31 Jan 2015 16:16:57 -0800 (PST) X-Received: by 10.182.84.225 with SMTP id c1mr7880394obz.68.1422749817533; Sat, 31 Jan 2015 16:16:57 -0800 (PST) Received: from localhost.localdomain (cpe-24-28-70-239.austin.res.rr.com. [24.28.70.239]) by mx.google.com with ESMTPSA id xr17sm5945905oeb.12.2015.01.31.16.16.56 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 31 Jan 2015 16:16:57 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sat, 31 Jan 2015 18:16:34 -0600 Message-Id: <1422749807-20228-4-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422749807-20228-1-git-send-email-bill.fischofer@linaro.org> References: <1422749807-20228-1-git-send-email-bill.fischofer@linaro.org> X-Topics: Classification patch Subject: [lng-odp] [PATCHv4 03/10] linux-generic: classification: add strong typing support X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: bill.fischofer@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Bill Fischofer --- include/odp/api/classification.h | 44 ++++++++++++++++--- .../include/odp/plat/classification_types.h | 34 ++++++++++++--- platform/linux-generic/odp_classification.c | 51 +++++++++++++--------- .../classification/odp_classification_basic.c | 2 +- 4 files changed, 99 insertions(+), 32 deletions(-) diff --git a/include/odp/api/classification.h b/include/odp/api/classification.h index 5c6636f..55e4ba0 100644 --- a/include/odp/api/classification.h +++ b/include/odp/api/classification.h @@ -172,11 +172,6 @@ int odp_cos_with_l3_qos(odp_pktio_t pktio_in, */ /** - * Macro for Invalid PMR. - */ -#define ODP_PMR_INVAL ((odp_pmr_t)~0) - -/** * Packet Matching Rule field enumeration * for fields that may be used to calculate * the PMR, if present in a packet. @@ -391,6 +386,45 @@ int odp_pktio_pmr_match_set_cos(odp_pmr_set_t pmr_set_id, odp_pktio_t src_pktio, odp_cos_t dst_cos); /** + * Get printable value for an odp_cos_t + * + * @param hdl odp_cos_t handle to be printed + * @return uint64_t value that can be used to print/display this + * handle + * + * @note This routine is intended to be used for diagnostic purposes + * to enable applications to generate a printable value that represents + * an odp_cos_t handle. + */ +uint64_t odp_cos_t_print(odp_cos_t hdl); + +/** + * Get printable value for an odp_pmr_t + * + * @param hdl odp_pmr_t handle to be printed + * @return uint64_t value that can be used to print/display this + * handle + * + * @note This routine is intended to be used for diagnostic purposes + * to enable applications to generate a printable value that represents + * an odp_pmr_t handle. + */ +uint64_t odp_pmr_t_print(odp_pmr_t hdl); + +/** + * Get printable value for an odp_pmr_set_t + * + * @param hdl odp_pmr_set_t handle to be printed + * @return uint64_t value that can be used to print/display this + * handle + * + * @note This routine is intended to be used for diagnostic purposes + * to enable applications to generate a printable value that represents + * an odp_pmr_set_t handle. + */ +uint64_t odp_pmr_set_t_print(odp_pmr_set_t hdl); + +/** * @} */ diff --git a/platform/linux-generic/include/odp/plat/classification_types.h b/platform/linux-generic/include/odp/plat/classification_types.h index 07d640e..ed000db 100644 --- a/platform/linux-generic/include/odp/plat/classification_types.h +++ b/platform/linux-generic/include/odp/plat/classification_types.h @@ -17,19 +17,43 @@ extern "C" { #endif +#include + /** @addtogroup odp_classification * @{ */ -typedef uint32_t odp_cos_t; -typedef uint32_t odp_flowsig_t; +typedef odp_handle_t odp_cos_t; +typedef odp_handle_t odp_flowsig_t; -#define ODP_COS_INVALID ((odp_cos_t)~0) +#define ODP_COS_INVALID _odp_cast_scalar(odp_cos_t, ~0) #define ODP_COS_NAME_LEN 32 typedef uint16_t odp_cos_flow_set_t; -typedef uint32_t odp_pmr_t; -typedef uint32_t odp_pmr_set_t; + +typedef odp_handle_t odp_pmr_t; +#define ODP_PMR_INVAL _odp_cast_scalar(odp_pmr_t, ~0) + +typedef odp_handle_t odp_pmr_set_t; +#define ODP_PMR_SET_INVAL _odp_cast_scalar(odp_pmr_set_t, ~0) + +/** Get printable format of odp_cos_t */ +static inline uint64_t odp_cos_t_print(odp_cos_t hdl) +{ + return _odp_pri(hdl); +} + +/** Get printable format of odp_pmr_t */ +static inline uint64_t odp_pmr_t_print(odp_pmr_t hdl) +{ + return _odp_pri(hdl); +} + +/** Get printable format of odp_pmr_set_t */ +static inline uint64_t odp_pmr_set_t_print(odp_pmr_set_t hdl) +{ + return _odp_pri(hdl); +} /** * @} diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c index 78597ef..9459586 100644 --- a/platform/linux-generic/odp_classification.c +++ b/platform/linux-generic/odp_classification.c @@ -32,17 +32,17 @@ static pmr_tbl_t *pmr_tbl; cos_t *get_cos_entry_internal(odp_cos_t cos_id) { - return &(cos_tbl->cos_entry[cos_id]); + return &(cos_tbl->cos_entry[_odp_typeval(cos_id)]); } pmr_set_t *get_pmr_set_entry_internal(odp_pmr_set_t pmr_set_id) { - return &(pmr_set_tbl->pmr_set[pmr_set_id]); + return &(pmr_set_tbl->pmr_set[_odp_typeval(pmr_set_id)]); } pmr_t *get_pmr_entry_internal(odp_pmr_t pmr_id) { - return &(pmr_tbl->pmr[pmr_id]); + return &(pmr_tbl->pmr[_odp_typeval(pmr_id)]); } int odp_classification_init_global(void) @@ -68,7 +68,8 @@ int odp_classification_init_global(void) memset(cos_tbl, 0, sizeof(cos_tbl_t)); for (i = 0; i < ODP_COS_MAX_ENTRY; i++) { /* init locks */ - cos_t *cos = get_cos_entry_internal(i); + cos_t *cos = + get_cos_entry_internal(_odp_cast_scalar(odp_cos_t, i)); LOCK_INIT(&cos->s.lock); } @@ -88,7 +89,8 @@ int odp_classification_init_global(void) memset(pmr_tbl, 0, sizeof(pmr_tbl_t)); for (i = 0; i < ODP_PMR_MAX_ENTRY; i++) { /* init locks */ - pmr_t *pmr = get_pmr_entry_internal(i); + pmr_t *pmr = + get_pmr_entry_internal(_odp_cast_scalar(odp_pmr_t, i)); LOCK_INIT(&pmr->s.lock); } @@ -108,7 +110,9 @@ int odp_classification_init_global(void) memset(pmr_set_tbl, 0, sizeof(pmr_set_tbl_t)); for (i = 0; i < ODP_PMRSET_MAX_ENTRY; i++) { /* init locks */ - pmr_set_t *pmr = get_pmr_set_entry_internal(i); + pmr_set_t *pmr = + get_pmr_set_entry_internal + (_odp_cast_scalar(odp_pmr_set_t, i)); LOCK_INIT(&pmr->s.pmr.s.lock); } @@ -142,7 +146,7 @@ odp_cos_t odp_cos_create(const char *name) cos_tbl->cos_entry[i].s.headroom = 0; cos_tbl->cos_entry[i].s.valid = 1; UNLOCK(&cos_tbl->cos_entry[i].s.lock); - return (odp_cos_t)i; + return _odp_cast_scalar(odp_cos_t, i); } UNLOCK(&cos_tbl->cos_entry[i].s.lock); } @@ -162,12 +166,13 @@ odp_pmr_set_t alloc_pmr_set(pmr_t **pmr) *pmr = (pmr_t *)&pmr_set_tbl->pmr_set[i]; odp_atomic_init_u32(&pmr_set_tbl->pmr_set[i] .s.pmr.s.count, 0); - return (odp_pmr_set_t)i; /* return as locked */ + /* return as locked */ + return _odp_cast_scalar(odp_pmr_set_t, i); } UNLOCK(&pmr_set_tbl->pmr_set[i].s.pmr.s.lock); } ODP_ERR("ODP_PMRSET_MAX_ENTRY reached"); - return ODP_PMR_INVAL; + return ODP_PMR_SET_INVAL; } odp_pmr_t alloc_pmr(pmr_t **pmr) @@ -181,7 +186,8 @@ odp_pmr_t alloc_pmr(pmr_t **pmr) odp_atomic_init_u32(&pmr_tbl->pmr[i].s.count, 0); pmr_tbl->pmr[i].s.num_pmr = 0; *pmr = &pmr_tbl->pmr[i]; - return (odp_pmr_t)i; /* return as locked */ + /* return as locked */ + return _odp_cast_scalar(odp_pmr_t, i); } UNLOCK(&pmr_tbl->pmr[i].s.lock); } @@ -192,30 +198,33 @@ odp_pmr_t alloc_pmr(pmr_t **pmr) cos_t *get_cos_entry(odp_cos_t cos_id) { - if (cos_id >= ODP_COS_MAX_ENTRY || cos_id == ODP_COS_INVALID) + if (_odp_typeval(cos_id) >= ODP_COS_MAX_ENTRY || + cos_id == ODP_COS_INVALID) return NULL; - if (cos_tbl->cos_entry[cos_id].s.valid == 0) + if (cos_tbl->cos_entry[_odp_typeval(cos_id)].s.valid == 0) return NULL; - return &(cos_tbl->cos_entry[cos_id]); + return &(cos_tbl->cos_entry[_odp_typeval(cos_id)]); } pmr_set_t *get_pmr_set_entry(odp_pmr_set_t pmr_set_id) { - if (pmr_set_id >= ODP_PMRSET_MAX_ENTRY || pmr_set_id == ODP_PMR_INVAL) + if (_odp_typeval(pmr_set_id) >= ODP_PMRSET_MAX_ENTRY || + pmr_set_id == ODP_PMR_SET_INVAL) return NULL; - if (pmr_set_tbl->pmr_set[pmr_set_id].s.pmr.s.valid == 0) + if (pmr_set_tbl->pmr_set[_odp_typeval(pmr_set_id)].s.pmr.s.valid == 0) return NULL; - return &(pmr_set_tbl->pmr_set[pmr_set_id]); + return &(pmr_set_tbl->pmr_set[_odp_typeval(pmr_set_id)]); } pmr_t *get_pmr_entry(odp_pmr_t pmr_id) { - if (pmr_id >= ODP_PMR_MAX_ENTRY || pmr_id == ODP_PMR_INVAL) + if (_odp_typeval(pmr_id) >= ODP_PMR_MAX_ENTRY || + pmr_id == ODP_PMR_INVAL) return NULL; - if (pmr_tbl->pmr[pmr_id].s.valid == 0) + if (pmr_tbl->pmr[_odp_typeval(pmr_id)].s.valid == 0) return NULL; - return &(pmr_tbl->pmr[pmr_id]); + return &(pmr_tbl->pmr[_odp_typeval(pmr_id)]); } int odp_cos_destroy(odp_cos_t cos_id) @@ -544,7 +553,7 @@ int odp_pmr_match_set_create(int num_terms, odp_pmr_match_t *terms, { pmr_t *pmr; int i; - uint32_t id; + odp_pmr_set_t id; int val_sz; int count = 0; @@ -555,7 +564,7 @@ int odp_pmr_match_set_create(int num_terms, odp_pmr_match_t *terms, id = alloc_pmr_set(&pmr); /*if alloc_pmr_set is successful it returns with the acquired lock*/ - if (id == ODP_PMR_INVAL) { + if (id == ODP_PMR_SET_INVAL) { *pmr_set_id = id; return -1; } diff --git a/test/validation/classification/odp_classification_basic.c b/test/validation/classification/odp_classification_basic.c index 844b66e..ac2fe8e 100644 --- a/test/validation/classification/odp_classification_basic.c +++ b/test/validation/classification/odp_classification_basic.c @@ -146,7 +146,7 @@ static void classification_pmr_match_set_destroy(void) uint16_t mask = 0xffff; int i; - retval = odp_pmr_match_set_destroy(ODP_PMR_INVAL); + retval = odp_pmr_match_set_destroy(ODP_PMR_SET_INVAL); CU_ASSERT(retval < 0); for (i = 0; i < PMR_SET_NUM; i++) {