From patchwork Sat Jan 31 20:50:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 44097 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f72.google.com (mail-ee0-f72.google.com [74.125.83.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5F67C2359E for ; Sat, 31 Jan 2015 20:51:24 +0000 (UTC) Received: by mail-ee0-f72.google.com with SMTP id e49sf13534658eek.3 for ; Sat, 31 Jan 2015 12:51:23 -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=Bry5WxpmJghniFTWR2LZJUIa6INwQsW7n5e/y+sjXGiyC77zCYtW0YR6I+8XVldJhg k+EHQsFAhcdAwUKk7lvbeRFTvbGn+2czDiNPLy1JLy3YK8pEnlmJkdydnyeeC6y/8DbI 22IaPgCZpwffIWlu0ft6Irsi7B3ItY+SL0NiE9yWUg5u4boLfxtJ2xEE6yQdHb1LZ8K2 0Z/F8seWzyMIAI3w8XHu05odxUOzwRHi2OjBqQJWsPbO8NnY+vWgxwYhIiEbL3oinhtV t+4YARPP9ccFDj17W2mxG3f/XvcHEggZfmSsehsGJvvcq7768+LJYuUXYh2JAbefPRlH InPA== X-Gm-Message-State: ALoCoQnYnoM2OpJ/nd1DAyltT02krQKvcd2e0TcGX3IR2OkeCA7G2+OCxgyIvmoZz2J1m7+drPXu X-Received: by 10.152.43.166 with SMTP id x6mr1524991lal.3.1422737483529; Sat, 31 Jan 2015 12:51:23 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.6 with SMTP id 6ls551209lai.30.gmail; Sat, 31 Jan 2015 12:51:23 -0800 (PST) X-Received: by 10.152.179.236 with SMTP id dj12mr12468215lac.60.1422737483307; Sat, 31 Jan 2015 12:51:23 -0800 (PST) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id k5si13157456lak.12.2015.01.31.12.51.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Jan 2015 12:51:22 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id ge10so30643259lab.11 for ; Sat, 31 Jan 2015 12:51:22 -0800 (PST) X-Received: by 10.152.6.132 with SMTP id b4mr12455295laa.59.1422737482836; Sat, 31 Jan 2015 12:51:22 -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 h5csp450279lbj; Sat, 31 Jan 2015 12:51:21 -0800 (PST) X-Received: by 10.224.63.70 with SMTP id a6mr26446642qai.42.1422737481265; Sat, 31 Jan 2015 12:51: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 g6si19331852qgf.0.2015.01.31.12.51.20 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 31 Jan 2015 12:51: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 1YHf0g-0000vI-JH; Sat, 31 Jan 2015 20:51:18 +0000 Received: from mail-ob0-f180.google.com ([209.85.214.180]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YHf0S-0000tv-C2 for lng-odp@lists.linaro.org; Sat, 31 Jan 2015 20:51:04 +0000 Received: by mail-ob0-f180.google.com with SMTP id vb8so11274663obc.11 for ; Sat, 31 Jan 2015 12:50:59 -0800 (PST) X-Received: by 10.202.210.86 with SMTP id j83mr7198099oig.131.1422737459108; Sat, 31 Jan 2015 12:50: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 uv10sm7202439obc.27.2015.01.31.12.50.58 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 31 Jan 2015 12:50:58 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sat, 31 Jan 2015 14:50:43 -0600 Message-Id: <1422737449-11540-4-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422737449-11540-1-git-send-email-bill.fischofer@linaro.org> References: <1422737449-11540-1-git-send-email-bill.fischofer@linaro.org> X-Topics: Classification patch Subject: [lng-odp] [PATCHv3 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.52 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++) {