From patchwork Mon Apr 25 14:20:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 66587 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1067193qge; Mon, 25 Apr 2016 07:23:38 -0700 (PDT) X-Received: by 10.140.168.193 with SMTP id o184mr8735605qho.9.1461594218588; Mon, 25 Apr 2016 07:23:38 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 6si10668759qkp.25.2016.04.25.07.23.38; Mon, 25 Apr 2016 07:23:38 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 4452761935; Mon, 25 Apr 2016 14:23:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id ED45361887; Mon, 25 Apr 2016 14:22:43 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 396706186F; Mon, 25 Apr 2016 14:22:32 +0000 (UTC) Received: from mail-pf0-f180.google.com (mail-pf0-f180.google.com [209.85.192.180]) by lists.linaro.org (Postfix) with ESMTPS id 29DBD6186F for ; Mon, 25 Apr 2016 14:21:30 +0000 (UTC) Received: by mail-pf0-f180.google.com with SMTP id 206so18014622pfu.0 for ; Mon, 25 Apr 2016 07:21:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dkt2QUuQOHNiRURbB7CVwWcQVdt19wBFxC6rd+0s4lM=; b=D5X5rbrxAhB6AD9+XVldzGaFk7athr1gdZbG1AC7NRoMHJILrrNPvvZ7GQPG77tKPN i2m9Ksj1qJHU73Os5Jpl7xTopL/sy8Uk03UKzJ6r5d2c8n4LnKnTVKUlfyVevoQXHAQr kUVricYp7fYRsQblhN8GvQp5sXNheeIePb+Gm+WSpuSjZGrdp8g/cr68ClRFHGxpiUe2 peapyEO9lwhykLlKPur3v5QG2LMMY5m3BOZEXp7NZMpkNXJgnDDBDjtAYxB4wpHxxDiq wtmtyIVXbrKqjnnvnNdxwjpfUBO9eyhrzdtGMOeEwgZw4zn+kWL14Jw15Kebw2HDaN25 SdrQ== X-Gm-Message-State: AOPr4FVP2tMW6NzIXqsI/Gt5JzdUXnbSgCQ753FA45e4+xOQWTQSlJ3l/L+d4ODU9V+TMM8eBns= X-Received: by 10.98.17.9 with SMTP id z9mr32169777pfi.40.1461594089499; Mon, 25 Apr 2016 07:21:29 -0700 (PDT) Received: from localhost.localdomain ([106.206.145.44]) by smtp.gmail.com with ESMTPSA id q26sm29251069pfi.57.2016.04.25.07.21.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Apr 2016 07:21:28 -0700 (PDT) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Mon, 25 Apr 2016 19:50:57 +0530 Message-Id: <1461594059-23824-2-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461594059-23824-1-git-send-email-bala.manoharan@linaro.org> References: <1461594059-23824-1-git-send-email-bala.manoharan@linaro.org> X-Topics: Classification Cc: petri.savolainen@nokia.com Subject: [lng-odp] [API-NEXTv3 2/4] linux-generic: classification: Implements capability and PMR range X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" Implements classification capability and PMR range functionality feature. Signed-off-by: Balasubramanian Manoharan Reviewed-by: Bill Fischofer --- .../include/odp_classification_datamodel.h | 19 ++++- .../include/odp_classification_inlines.h | 24 +++--- platform/linux-generic/odp_classification.c | 92 +++++++++++++--------- 3 files changed, 82 insertions(+), 53 deletions(-) diff --git a/platform/linux-generic/include/odp_classification_datamodel.h b/platform/linux-generic/include/odp_classification_datamodel.h index 63f3ec6..dc2190d 100644 --- a/platform/linux-generic/include/odp_classification_datamodel.h +++ b/platform/linux-generic/include/odp_classification_datamodel.h @@ -52,9 +52,22 @@ Stores the Term and Value mapping for a PMR. The maximum size of value currently supported in 64 bits **/ typedef struct pmr_term_value { - odp_pmr_term_t term; /* PMR Term */ - uint64_t val; /**< Value to be matched */ - uint64_t mask; /**< Masked set of bits to be matched */ + odp_cls_pmr_term_t term; /* PMR Term */ + odp_bool_t range_term; /* True if range, false if match */ + union { + struct { + /** Value to be matched */ + uint64_t value; + /** Masked set of bits to be matched */ + uint64_t mask; + } match; + struct { + /** Start value of the range */ + uint64_t val_start; + /** End value of the range */ + uint64_t val_end; + } range; + }; uint32_t offset; /**< Offset if term == ODP_PMR_CUSTOM_FRAME */ uint32_t val_sz; /**< Size of the value to be matched */ } pmr_term_value_t; diff --git a/platform/linux-generic/include/odp_classification_inlines.h b/platform/linux-generic/include/odp_classification_inlines.h index bac5b48..b8b04ce 100644 --- a/platform/linux-generic/include/odp_classification_inlines.h +++ b/platform/linux-generic/include/odp_classification_inlines.h @@ -34,8 +34,8 @@ These following functions return 1 on success and 0 on failure static inline int verify_pmr_packet_len(odp_packet_hdr_t *pkt_hdr, pmr_term_value_t *term_value) { - if (term_value->val == (packet_len(pkt_hdr) & - term_value->mask)) + if (term_value->match.value == (packet_len(pkt_hdr) & + term_value->match.mask)) return 1; return 0; @@ -51,7 +51,7 @@ static inline int verify_pmr_ip_proto(const uint8_t *pkt_addr, return 0; ip = (const odph_ipv4hdr_t *)(pkt_addr + pkt_hdr->l3_offset); proto = ip->proto; - if (term_value->val == (proto & term_value->mask)) + if (term_value->match.value == (proto & term_value->match.mask)) return 1; return 0; @@ -67,7 +67,7 @@ static inline int verify_pmr_ipv4_saddr(const uint8_t *pkt_addr, return 0; ip = (const odph_ipv4hdr_t *)(pkt_addr + pkt_hdr->l3_offset); ipaddr = odp_be_to_cpu_32(ip->src_addr); - if (term_value->val == (ipaddr & term_value->mask)) + if (term_value->match.value == (ipaddr & term_value->match.mask)) return 1; return 0; @@ -83,7 +83,7 @@ static inline int verify_pmr_ipv4_daddr(const uint8_t *pkt_addr, return 0; ip = (const odph_ipv4hdr_t *)(pkt_addr + pkt_hdr->l3_offset); ipaddr = odp_be_to_cpu_32(ip->dst_addr); - if (term_value->val == (ipaddr & term_value->mask)) + if (term_value->match.value == (ipaddr & term_value->match.mask)) return 1; return 0; @@ -99,7 +99,7 @@ static inline int verify_pmr_tcp_sport(const uint8_t *pkt_addr, return 0; tcp = (const odph_tcphdr_t *)(pkt_addr + pkt_hdr->l4_offset); sport = odp_be_to_cpu_16(tcp->src_port); - if (term_value->val == (sport & term_value->mask)) + if (term_value->match.value == (sport & term_value->match.mask)) return 1; return 0; @@ -115,7 +115,7 @@ static inline int verify_pmr_tcp_dport(const uint8_t *pkt_addr, return 0; tcp = (const odph_tcphdr_t *)(pkt_addr + pkt_hdr->l4_offset); dport = odp_be_to_cpu_16(tcp->dst_port); - if (term_value->val == (dport & term_value->mask)) + if (term_value->match.value == (dport & term_value->match.mask)) return 1; return 0; @@ -131,7 +131,7 @@ static inline int verify_pmr_udp_dport(const uint8_t *pkt_addr, return 0; udp = (const odph_udphdr_t *)(pkt_addr + pkt_hdr->l4_offset); dport = odp_be_to_cpu_16(udp->dst_port); - if (term_value->val == (dport & term_value->mask)) + if (term_value->match.value == (dport & term_value->match.mask)) return 1; return 0; @@ -148,7 +148,7 @@ static inline int verify_pmr_udp_sport(const uint8_t *pkt_addr, return 0; udp = (const odph_udphdr_t *)(pkt_addr + pkt_hdr->l4_offset); sport = odp_be_to_cpu_16(udp->src_port); - if (term_value->val == (sport & term_value->mask)) + if (term_value->match.value == (sport & term_value->match.mask)) return 1; return 0; @@ -174,7 +174,7 @@ static inline int verify_pmr_dmac(const uint8_t *pkt_addr, if (dmac_be != dmac) dmac = dmac >> (64 - (ODPH_ETHADDR_LEN * 8)); - if (term_value->val == (dmac & term_value->mask)) + if (term_value->match.value == (dmac & term_value->match.mask)) return 1; return 0; } @@ -234,7 +234,7 @@ static inline int verify_pmr_ipsec_spi(const uint8_t *pkt_addr, return 0; } - if (term_value->val == (spi & term_value->mask)) + if (term_value->match.value == (spi & term_value->match.mask)) return 1; return 0; @@ -262,7 +262,7 @@ static inline int verify_pmr_custom_frame(const uint8_t *pkt_addr, return 0; memcpy(&val, pkt_addr + offset, val_sz); - if (term_value->val == (val & term_value->mask)) + if (term_value->match.value == (val & term_value->match.mask)) return 1; return 0; diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c index f5e4673..5e4bce5 100644 --- a/platform/linux-generic/odp_classification.c +++ b/platform/linux-generic/odp_classification.c @@ -124,6 +124,34 @@ void odp_cls_cos_param_init(odp_cls_cos_param_t *param) param->drop_policy = ODP_COS_DROP_NEVER; } +void odp_cls_pmr_param_init(odp_pmr_param_t *param) +{ + memset(param, 0, sizeof(odp_pmr_param_t)); +} + +int odp_cls_capability(odp_cls_capability_t *capability) +{ + unsigned count = 0; + + for (int i = 0; i < ODP_PMR_MAX_ENTRY; i++) + if (!pmr_tbl->pmr[i].s.valid) + count++; + + capability->max_pmr_terms = ODP_PMR_MAX_ENTRY; + capability->available_pmr_terms = count; + capability->max_cos = ODP_COS_MAX_ENTRY; + capability->pmr_range_supported = false; + capability->supported_terms.all_bits = 0; + capability->supported_terms.bit.ip_proto = 1; + capability->supported_terms.bit.udp_dport = 1; + capability->supported_terms.bit.udp_sport = 1; + capability->supported_terms.bit.tcp_dport = 1; + capability->supported_terms.bit.tcp_sport = 1; + capability->supported_terms.bit.sip_addr = 1; + capability->supported_terms.bit.dip_addr = 1; + return 0; +} + odp_cos_t odp_cls_cos_create(const char *name, odp_cls_cos_param_t *param) { int i, j; @@ -409,17 +437,28 @@ int odp_cos_with_l3_qos(odp_pktio_t pktio_in, return 0; } -static void odp_pmr_create_term(pmr_term_value_t *value, - const odp_pmr_match_t *match) +static int odp_pmr_create_term(pmr_term_value_t *value, + const odp_pmr_param_t *param) { - value->term = match->term; - value->offset = match->offset; - value->val_sz = match->val_sz; - value->val = 0; - value->mask = 0; - memcpy(&value->val, match->val, match->val_sz); - memcpy(&value->mask, match->mask, match->val_sz); - value->val &= value->mask; + value->term = param->term; + value->range_term = param->range_term; + if (!value->range_term) { + value->match.value = 0; + value->match.mask = 0; + memcpy(&value->match.value, param->match.value, param->val_sz); + memcpy(&value->match.mask, param->match.mask, param->val_sz); + value->match.value &= value->match.mask; + } else { + value->range.val_start = 0; + value->range.val_end = 0; + memcpy(&value->range.val_start, param->range.val_start, + param->val_sz); + memcpy(&value->range.val_end, param->range.val_end, + param->val_sz); + } + value->offset = param->offset; + value->val_sz = param->val_sz; + return 0; } int odp_cls_pmr_destroy(odp_pmr_t pmr_id) @@ -452,33 +491,7 @@ no_rule: return 0; } -unsigned long long odp_pmr_terms_cap(void) -{ - unsigned long long term_cap = 0; - - term_cap |= (1 << ODP_PMR_LEN); - term_cap |= (1 << ODP_PMR_IPPROTO); - term_cap |= (1 << ODP_PMR_UDP_DPORT); - term_cap |= (1 << ODP_PMR_TCP_DPORT); - term_cap |= (1 << ODP_PMR_UDP_SPORT); - term_cap |= (1 << ODP_PMR_TCP_SPORT); - term_cap |= (1 << ODP_PMR_SIP_ADDR); - term_cap |= (1 << ODP_PMR_DIP_ADDR); - return term_cap; -} - -unsigned odp_pmr_terms_avail(void) -{ - unsigned count = 0; - int i; - - for (i = 0; i < ODP_PMR_MAX_ENTRY; i++) - if (!pmr_tbl->pmr[i].s.valid) - count++; - return count; -} - -odp_pmr_t odp_cls_pmr_create(const odp_pmr_match_t *terms, int num_terms, +odp_pmr_t odp_cls_pmr_create(const odp_pmr_param_t *terms, int num_terms, odp_cos_t src_cos, odp_cos_t dst_cos) { pmr_t *pmr; @@ -512,10 +525,13 @@ odp_pmr_t odp_cls_pmr_create(const odp_pmr_match_t *terms, int num_terms, val_sz = terms[i].val_sz; if (val_sz > ODP_PMR_TERM_BYTES_MAX) { pmr->s.valid = 0; + return ODP_PMR_INVAL; + } + if (0 > odp_pmr_create_term(&pmr->s.pmr_term_value[i], + &terms[i])) { UNLOCK(&pmr->s.lock); return ODP_PMR_INVAL; } - odp_pmr_create_term(&pmr->s.pmr_term_value[i], &terms[i]); } loc = odp_atomic_fetch_inc_u32(&cos_src->s.num_rule);