From patchwork Fri Jan 30 04:27:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 44011 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C7BD424128 for ; Fri, 30 Jan 2015 04:28:24 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id r20sf608161wiv.2 for ; Thu, 29 Jan 2015 20:28:24 -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=FX+wYTbFVS0uEtk+CL3UnWC4hK8hBh29Uvo/O/PBnqI=; b=gYE923RSf4DIEgFDcRMzDJWK/Gef73IpwoCWdvbRdXe/0Qwzs+d/zvaRxbsmralLDE n3ZwL+W/iVV1yU+mtMDDDE6iRMrGlCOaGrjp+cfk/EhpnFx6wPu2sveSjj/pwSSF5hEY +Px8hUtOqi4R8l8+ImTBMM5uzPKju2t8mopUjphZvxztBnMOGzzoexVaIm/Y3j7VevX8 2a9Os08mptNhcuq0ImZkKaEkTuE5qr1YGEJBSz9byFB2qL5WyF53wNPXxo0GH2AgUrZz FPCce4/YFLd1XLoDUby5RP8ZiIEJgTd/nhtu48fKvK6LdBwOyn0lNSZRwA4u1Ugw0saG jzjw== X-Gm-Message-State: ALoCoQmZfbaDHJZcJvG2M70CFiGBzK7BiF8Y2EWgnVT7A/nsSH9uAKVz+povQGbZQH/D2x614SRf X-Received: by 10.194.204.201 with SMTP id la9mr524851wjc.6.1422592104126; Thu, 29 Jan 2015 20:28:24 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.45.6 with SMTP id i6ls376391lam.10.gmail; Thu, 29 Jan 2015 20:28:23 -0800 (PST) X-Received: by 10.112.30.135 with SMTP id s7mr4452460lbh.63.1422592103894; Thu, 29 Jan 2015 20:28:23 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id xq4si9286201lbb.20.2015.01.29.20.28.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 Jan 2015 20:28:23 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by mail-la0-f46.google.com with SMTP id s18so21800233lam.5 for ; Thu, 29 Jan 2015 20:28:23 -0800 (PST) X-Received: by 10.152.116.43 with SMTP id jt11mr4529164lab.69.1422592103270; Thu, 29 Jan 2015 20:28:23 -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 h5csp159166lbj; Thu, 29 Jan 2015 20:28:22 -0800 (PST) X-Received: by 10.229.99.134 with SMTP id u6mr8931580qcn.10.1422592101899; Thu, 29 Jan 2015 20:28:21 -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 8si12883645qgi.114.2015.01.29.20.28.20 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 29 Jan 2015 20:28:21 -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 1YH3Bq-0007OQ-LE; Fri, 30 Jan 2015 04:28:18 +0000 Received: from mail-oi0-f42.google.com ([209.85.218.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YH3Bc-0007Lk-FJ for lng-odp@lists.linaro.org; Fri, 30 Jan 2015 04:28:04 +0000 Received: by mail-oi0-f42.google.com with SMTP id i138so32971917oig.1 for ; Thu, 29 Jan 2015 20:27:59 -0800 (PST) X-Received: by 10.182.33.138 with SMTP id r10mr2615654obi.67.1422592079201; Thu, 29 Jan 2015 20:27:59 -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 x21sm4737369oix.24.2015.01.29.20.27.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jan 2015 20:27:58 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Thu, 29 Jan 2015 22:27:39 -0600 Message-Id: <1422592065-15875-4-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422592065-15875-1-git-send-email-bill.fischofer@linaro.org> References: <1422592065-15875-1-git-send-email-bill.fischofer@linaro.org> X-Topics: Classification patch Subject: [lng-odp] [patch 3/9] 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.46 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 | 5 --- .../include/odp/plat/classification_types.h | 16 ++++--- platform/linux-generic/odp_classification.c | 51 +++++++++++++--------- .../classification/odp_classification_basic.c | 2 +- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/include/odp/api/classification.h b/include/odp/api/classification.h index 5c6636f..f21e02f 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. diff --git a/platform/linux-generic/include/odp/plat/classification_types.h b/platform/linux-generic/include/odp/plat/classification_types.h index 07d640e..7f81ed2 100644 --- a/platform/linux-generic/include/odp/plat/classification_types.h +++ b/platform/linux-generic/include/odp/plat/classification_types.h @@ -17,19 +17,25 @@ 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) /** * @} 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++) {