From patchwork Tue Feb 3 04:44:52 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 44195 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 590A52034D for ; Tue, 3 Feb 2015 04:46:16 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id x12sf18714969wgg.0 for ; Mon, 02 Feb 2015 20:46:15 -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=2cauu6JGIKwKYt10vwLq8+iv9qlz1Z1zmz7+s6qC1wU=; b=E1mSgMCFYnOXwSrrE5kCQI+6njwqNxoQFOhW3W9lFnQ2WrteGL75GFrB04VODEZhKB gSHsmPPXVJlPHQvuBHW1fDUzeoexjtbHvMTnT5E6UXd9mTg9HC6TXfArHRFz+Wj1/tgn 4Yanw9owM5i7YOakiRkxtsfcF731dh4IumQS22XyCcmkJa6ZR6096p7tHgU0KwQeipOF jA5+4AhtvAHx5PE31IDtYTIKNC/i0LS1Lp+TFusE4EFvug0xCUXhRjHmyBZWm36To6ce MfkbDr2JNPNQ1CYvj4an8GqIRRczIHo+7cMRNctgW7d4J6GBEZkTNzd9g9Vqoe2zloWz 5AzA== X-Gm-Message-State: ALoCoQn+9o0F6o16EKWR0rG3j91zrRPeN6TEDh2nMhdDpw/TC+2/lVVbS47WyMpe/RTcQyc0nE6N X-Received: by 10.194.201.10 with SMTP id jw10mr2795084wjc.3.1422938775682; Mon, 02 Feb 2015 20:46:15 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.165 with SMTP id m5ls410958lag.104.gmail; Mon, 02 Feb 2015 20:46:15 -0800 (PST) X-Received: by 10.112.142.201 with SMTP id ry9mr22933149lbb.4.1422938775320; Mon, 02 Feb 2015 20:46:15 -0800 (PST) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id qr3si7946492lbb.127.2015.02.02.20.46.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Feb 2015 20:46:15 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by mail-la0-f48.google.com with SMTP id pv20so47781242lab.7 for ; Mon, 02 Feb 2015 20:46:15 -0800 (PST) X-Received: by 10.112.135.196 with SMTP id pu4mr22701265lbb.41.1422938775195; Mon, 02 Feb 2015 20:46:15 -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 h5csp1712467lbj; Mon, 2 Feb 2015 20:46:14 -0800 (PST) X-Received: by 10.140.94.6 with SMTP id f6mr293622qge.38.1422938773483; Mon, 02 Feb 2015 20:46:13 -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 i7si22211958qcn.2.2015.02.02.20.46.12 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 02 Feb 2015 20:46:13 -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 1YIVNK-00068T-HR; Tue, 03 Feb 2015 04:46:10 +0000 Received: from mail-oi0-f53.google.com ([209.85.218.53]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YIVMl-00060h-2D for lng-odp@lists.linaro.org; Tue, 03 Feb 2015 04:45:35 +0000 Received: by mail-oi0-f53.google.com with SMTP id i138so47476635oig.12 for ; Mon, 02 Feb 2015 20:45:29 -0800 (PST) X-Received: by 10.202.209.151 with SMTP id i145mr13338262oig.108.1422938729800; Mon, 02 Feb 2015 20:45:29 -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 vs5sm10277537oeb.14.2015.02.02.20.45.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Feb 2015 20:45:28 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 2 Feb 2015 22:44:52 -0600 Message-Id: <1422938699-12877-13-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422938699-12877-1-git-send-email-bill.fischofer@linaro.org> References: <1422938699-12877-1-git-send-email-bill.fischofer@linaro.org> X-Topics: Classification patch Subject: [lng-odp] [PATCHv5 12/19] 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.48 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 | 34 ++++++++++++--- platform/linux-generic/odp_classification.c | 51 +++++++++++++--------- .../classification/odp_classification_basic.c | 2 +- 4 files changed, 60 insertions(+), 32 deletions(-) diff --git a/include/odp/api/classification.h b/include/odp/api/classification.h index 3479754..6e38a2c 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..042d8c8 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_to_u64(odp_cos_t hdl) +{ + return _odp_pri(hdl); +} + +/** Get printable format of odp_pmr_t */ +static inline uint64_t odp_pmr_to_u64(odp_pmr_t hdl) +{ + return _odp_pri(hdl); +} + +/** Get printable format of odp_pmr_set_t */ +static inline uint64_t odp_pmr_set_to_u64(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++) {