From patchwork Tue Apr 26 04:48:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 66663 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1402463qge; Mon, 25 Apr 2016 21:50:28 -0700 (PDT) X-Received: by 10.140.153.129 with SMTP id 123mr384254qhz.71.1461646228099; Mon, 25 Apr 2016 21:50:28 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z2si416144qkb.21.2016.04.25.21.50.27; Mon, 25 Apr 2016 21:50:28 -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 B9F88616A4; Tue, 26 Apr 2016 04:50:27 +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 A0EBB6167A; Tue, 26 Apr 2016 04:49:49 +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 F3A1B61674; Tue, 26 Apr 2016 04:49:45 +0000 (UTC) Received: from mail-pa0-f48.google.com (mail-pa0-f48.google.com [209.85.220.48]) by lists.linaro.org (Postfix) with ESMTPS id 2966F6167A for ; Tue, 26 Apr 2016 04:49:05 +0000 (UTC) Received: by mail-pa0-f48.google.com with SMTP id iv1so1903015pac.2 for ; Mon, 25 Apr 2016 21:49:05 -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=2Y4GEcxhe/mSTTHg+wyD3MlXU53M8jIb7suJQlxS6fo=; b=ln/AP0BunCVnNj3hpFvFaFNO0rbW8BsFm1qHOc1E7OFW1PA4mzFT63oqsBHXlAqBL+ wleB+V/91VDYJw8qqSmnb5X2MX+XnoTKRcUdS5M8JhizocbJp6HwyEgbzQeMr1NZDE53 HWd8kVaUuEy5/4U79o+Ghi3444NG3f6oYDRI8QGrzDbaAuGJopFpq+1pSAYvJM0QRBqx o43SFd0jPy6a63isj2LmnqriO4aNIa9ocKhCUy51/u0OKiijr9nd67mfZFJmeZl3nvvj 66awJ6ee/hRioe+3LI740ga53odnZ1FS6F8z/Y6w8621Ph0vmGKmA8yMACQdbEwUtiZU z6bA== X-Gm-Message-State: AOPr4FU4YsqoNv4d/IFzUiwT9C/MXzWhOjKX9f7T+Q7wQnH7P395803E9ul1eB3kPgjC7zmTC2A= X-Received: by 10.66.121.197 with SMTP id lm5mr654516pab.143.1461646144494; Mon, 25 Apr 2016 21:49:04 -0700 (PDT) Received: from localhost.localdomain ([122.166.219.57]) by smtp.gmail.com with ESMTPSA id 194sm973922pfv.8.2016.04.25.21.49.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Apr 2016 21:49:03 -0700 (PDT) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Tue, 26 Apr 2016 10:18:36 +0530 Message-Id: <1461646118-27600-2-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461646118-27600-1-git-send-email-bala.manoharan@linaro.org> References: <1461646118-27600-1-git-send-email-bala.manoharan@linaro.org> X-Topics: Classification Subject: [lng-odp] [API-NEXTv4 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 --- .../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);