From patchwork Sat Jan 31 16:14:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 44084 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f198.google.com (mail-we0-f198.google.com [74.125.82.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2A5252359E for ; Sat, 31 Jan 2015 16:15:02 +0000 (UTC) Received: by mail-we0-f198.google.com with SMTP id q59sf13410973wes.1 for ; Sat, 31 Jan 2015 08:15:01 -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=eVSyGN0/pWV0hIDcazTWGEO/a9SWehwA7LS4LeVIMJoPsn+OJakYwTvkAtdBxJne6s /c4MvW8vRDxndnfFx7b8zS6cimdoDno7vmWMi+HE2d7QBn776HRRb1ol6DCcNN5VvrhX 2x8tia6eN9/jvyeFBcQcXmy1Wdq1KYOl7e6uoqRJ/AphsjmnXeVviRNsDYB5XCai295R T3wKg5dJATtm74TFGWsRmY5Idyfmo59a/MIK+uFRE1aXXdpXgggI/WEgehkD9YLveX01 WekWOT4Rf2qsNLL6Zvw3GGgdzo/5pczHDMEXdYoFeg23raWslJLkr0HuVVnXn1FoXdUM D71g== X-Gm-Message-State: ALoCoQnUE8NolC+FnUbVg8Pm449p+bK5KMad0wcVrCfWUHZnKm0e3dYCFuNe18wUA/K9CRC6nnek X-Received: by 10.112.133.98 with SMTP id pb2mr1472362lbb.2.1422720901216; Sat, 31 Jan 2015 08:15:01 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.243.39 with SMTP id wv7ls1079lac.66.gmail; Sat, 31 Jan 2015 08:15:01 -0800 (PST) X-Received: by 10.112.199.69 with SMTP id ji5mr11472932lbc.45.1422720901067; Sat, 31 Jan 2015 08:15:01 -0800 (PST) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id e2si12670540lbc.31.2015.01.31.08.15.00 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 31 Jan 2015 08:15:00 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id gf13so29427494lab.8 for ; Sat, 31 Jan 2015 08:15:00 -0800 (PST) X-Received: by 10.112.41.234 with SMTP id i10mr11644164lbl.25.1422720900868; Sat, 31 Jan 2015 08:15:00 -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 h5csp351886lbj; Sat, 31 Jan 2015 08:14:59 -0800 (PST) X-Received: by 10.224.54.131 with SMTP id q3mr23901060qag.102.1422720899375; Sat, 31 Jan 2015 08:14:59 -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 p95si18389595qgp.18.2015.01.31.08.14.58 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sat, 31 Jan 2015 08:14:59 -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 1YHahD-00056y-Uq; Sat, 31 Jan 2015 16:14:55 +0000 Received: from mail-ob0-f181.google.com ([209.85.214.181]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YHah0-00055f-Qm for lng-odp@lists.linaro.org; Sat, 31 Jan 2015 16:14:42 +0000 Received: by mail-ob0-f181.google.com with SMTP id vb8so7445179obc.12 for ; Sat, 31 Jan 2015 08:14:37 -0800 (PST) X-Received: by 10.202.180.70 with SMTP id d67mr6487103oif.119.1422720877607; Sat, 31 Jan 2015 08:14:37 -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 ur1sm6921411obc.3.2015.01.31.08.14.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 31 Jan 2015 08:14:36 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Sat, 31 Jan 2015 10:14:20 -0600 Message-Id: <1422720866-22194-4-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1422720866-22194-1-git-send-email-bill.fischofer@linaro.org> References: <1422720866-22194-1-git-send-email-bill.fischofer@linaro.org> X-Topics: Classification patch Subject: [lng-odp] [PATCHv2 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.49 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++) {