From patchwork Thu Apr 21 06:19:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 66306 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2860154qge; Wed, 20 Apr 2016 23:20:24 -0700 (PDT) X-Received: by 10.55.18.206 with SMTP id 75mr4200748qks.89.1461219624386; Wed, 20 Apr 2016 23:20:24 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b2si623930qka.220.2016.04.20.23.20.23; Wed, 20 Apr 2016 23:20:24 -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 C839A68A77; Thu, 21 Apr 2016 06:20:23 +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=-0.5 required=5.0 tests=BAYES_00, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_WEB, 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 1DA4268572; Thu, 21 Apr 2016 06:20:10 +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 63171684AC; Thu, 21 Apr 2016 06:20:05 +0000 (UTC) Received: from mail-pf0-f172.google.com (mail-pf0-f172.google.com [209.85.192.172]) by lists.linaro.org (Postfix) with ESMTPS id 0CF1E68572 for ; Thu, 21 Apr 2016 06:19:26 +0000 (UTC) Received: by mail-pf0-f172.google.com with SMTP id e128so26492557pfe.3 for ; Wed, 20 Apr 2016 23:19:26 -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=/OV+05SZUiMD6AZEDv0qXakcwKKN4GzwDJftGvX7Y6A=; b=A/ClxihrDRC3wtYc7VG8nBIWwI3ZLyLbAsUZjuW9deUF0Z2MZqWP2j6rg8dBbey42/ 1fi+tYa729E14QvLOlhJKtx6ghQQ3W44tstQZ9q5C4wDa98DflMuZRZP9yW8ZAduLOsc 5bszXszNIsGpVjtk0brYBU7KNOLTDQRiiFlhOtb9DUQhlif46a3lqb36edtXaN4sWaGK N3SjC5BTLW9A89EoxObTzJMT+p56smRZaAH5azZIKPi7D7LXNM46TEFb5aDtnmJrfvN/ RYZEudtFU7NKiakfEymYrZ6OkLGpRaS25e62+x/gleBSMuVOfA1cwgyaxjqvmUu8DYLM RyvQ== X-Gm-Message-State: AOPr4FUho3hJj0DQvc5LcxI87sBkH2ZcWEdP9M7esQ5VOiyw6HDZZMeA/kQiTa821axKw0aUkhQ= X-Received: by 10.98.76.22 with SMTP id z22mr18029144pfa.78.1461219565280; Wed, 20 Apr 2016 23:19:25 -0700 (PDT) Received: from localhost.localdomain ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id v189sm1722577pfb.85.2016.04.20.23.19.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Apr 2016 23:19:24 -0700 (PDT) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Thu, 21 Apr 2016 11:49:03 +0530 Message-Id: <1461219545-14545-2-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461219545-14545-1-git-send-email-bala.manoharan@linaro.org> References: <1461219545-14545-1-git-send-email-bala.manoharan@linaro.org> X-Topics: Classification Cc: petri.savolainen@nokia.com Subject: [lng-odp] [API-NEXT 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 | 17 +++- .../include/odp_classification_inlines.h | 24 +++--- platform/linux-generic/odp_classification.c | 92 +++++++++++++--------- 3 files changed, 81 insertions(+), 52 deletions(-) diff --git a/platform/linux-generic/include/odp_classification_datamodel.h b/platform/linux-generic/include/odp_classification_datamodel.h index 63f3ec6..7a1dd5c 100644 --- a/platform/linux-generic/include/odp_classification_datamodel.h +++ b/platform/linux-generic/include/odp_classification_datamodel.h @@ -53,8 +53,21 @@ 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_bool_t range_term; + 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..c991fd9 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->pmr_terms.all_bits = 0; + capability->pmr_terms.proto.ip_proto = 1; + capability->pmr_terms.proto.udp_dport = 1; + capability->pmr_terms.proto.udp_sport = 1; + capability->pmr_terms.proto.tcp_dport = 1; + capability->pmr_terms.proto.tcp_sport = 1; + capability->pmr_terms.proto.sip_addr = 1; + capability->pmr_terms.proto.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);