From patchwork Tue Nov 11 04:03:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bill Fischofer X-Patchwork-Id: 40553 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CA663244B6 for ; Tue, 11 Nov 2014 04:09:02 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id h11sf164424wiw.11 for ; Mon, 10 Nov 2014 20:09:02 -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:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=8pOSLRk8IXjj8xNyJc5L5UMROsRU0uhM5VewhfgsEkQ=; b=PgXxxCu2DGlr1vRzSqDpmdE503UnFY9tK9/2RMCjeYINtrUwnCaewKfNtVZDNZJAkj NM7vWbRZwDy8/FZWUThdwTHeePerAqMPhxxEYiommVlB+3IfziuBKGdiaWd90yF3//N9 w1Q98s+koQ0g+GRBdlID/0AMBkMKVX1hhWHHDqFUWeVGy2UdhURA5Xi96J9uLfSROIBC vSgu/weo5Z4zAQ1a+Qj96zvO05a77twDqobS1E7LyyVM6moqlhVkelNtIr7cfZf/JSxA fF6wSS54uxS+B1GnKqCf7GKzR2CjmYjoCMBMPngeq75358+vRwI+TKzAPLCdUDjlOAvt Bjvw== X-Gm-Message-State: ALoCoQkwc9RM4MI25Cb2TRrlJuY91iPZQv0s50DYC0FvJzWgU+ahPuhxo9q+VQ1VWdqq5K909HZi X-Received: by 10.180.100.100 with SMTP id ex4mr4814133wib.2.1415678942052; Mon, 10 Nov 2014 20:09:02 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.4 with SMTP id i4ls537154laf.59.gmail; Mon, 10 Nov 2014 20:09:01 -0800 (PST) X-Received: by 10.112.25.73 with SMTP id a9mr34440296lbg.10.1415678941764; Mon, 10 Nov 2014 20:09:01 -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 d5si29813183laf.110.2014.11.10.20.09.01 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Nov 2014 20:09:01 -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 pv20so8966379lab.11 for ; Mon, 10 Nov 2014 20:09:01 -0800 (PST) X-Received: by 10.152.234.136 with SMTP id ue8mr33719315lac.21.1415678941638; Mon, 10 Nov 2014 20:09:01 -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.184.201 with SMTP id ew9csp200068lbc; Mon, 10 Nov 2014 20:09:00 -0800 (PST) X-Received: by 10.224.3.134 with SMTP id 6mr50153738qan.87.1415678940470; Mon, 10 Nov 2014 20:09:00 -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 mf6si34870138qcb.28.2014.11.10.20.08.59 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 10 Nov 2014 20:09:00 -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 1Xo2lH-0003XW-0c; Tue, 11 Nov 2014 04:08:59 +0000 Received: from mail-ob0-f179.google.com ([209.85.214.179]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xo2gJ-00038r-W5 for lng-odp@lists.linaro.org; Tue, 11 Nov 2014 04:03:52 +0000 Received: by mail-ob0-f179.google.com with SMTP id m8so6880012obr.10 for ; Mon, 10 Nov 2014 20:03:46 -0800 (PST) X-Received: by 10.60.78.106 with SMTP id a10mr30247091oex.21.1415678626720; Mon, 10 Nov 2014 20:03:46 -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 ln10sm7905136obc.24.2014.11.10.20.03.45 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Nov 2014 20:03:46 -0800 (PST) From: Bill Fischofer To: lng-odp@lists.linaro.org Date: Mon, 10 Nov 2014 22:03:12 -0600 Message-Id: <1415678595-31405-8-git-send-email-bill.fischofer@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415678595-31405-1-git-send-email-bill.fischofer@linaro.org> References: <1415678595-31405-1-git-send-email-bill.fischofer@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH ODP v1.0 Buffer/Packet APIs 6/9] Modifications to helper files for v1.0 buffer/packet API 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 --- helper/include/odph_ip.h | 47 +++++++++++++++------ helper/include/odph_packet.h | 97 -------------------------------------------- helper/include/odph_tcp.h | 61 ++++++++++++++++++++++++++++ helper/include/odph_udp.h | 11 +++-- 4 files changed, 101 insertions(+), 115 deletions(-) delete mode 100644 helper/include/odph_packet.h create mode 100644 helper/include/odph_tcp.h diff --git a/helper/include/odph_ip.h b/helper/include/odph_ip.h index 2c83c0f..2dab164 100644 --- a/helper/include/odph_ip.h +++ b/helper/include/odph_ip.h @@ -79,10 +79,12 @@ static inline int odph_ipv4_csum_valid(odp_packet_t pkt) odph_ipv4hdr_t ip; uint16be_t chksum; - if (!odp_packet_l3_offset(pkt)) + if (!odp_packet_inflag_ipv4(pkt)) return 0; - memcpy(&ip, odp_packet_l3(pkt), sizeof(odph_ipv4hdr_t)); + odp_packet_copy_to_memory(&ip, pkt, odp_packet_l3_offset(pkt), + sizeof(odph_ipv4hdr_t)); + w = (uint16_t *)(void *)&ip; chksum = ip.chksum; ip.chksum = 0x0; @@ -105,12 +107,13 @@ static inline uint16sum_t odph_ipv4_csum_update(odp_packet_t pkt) { uint16_t *w; odph_ipv4hdr_t *ip; + size_t seglen; int nleft = sizeof(odph_ipv4hdr_t); - if (!odp_packet_l3_offset(pkt)) + if (!odp_packet_inflag_ipv4(pkt)) return 0; - ip = (odph_ipv4hdr_t *)odp_packet_l3(pkt); + ip = (odph_ipv4hdr_t *)odp_packet_l3_map(pkt, &seglen); w = (uint16_t *)(void *)ip; ip->chksum = odp_chksum(w, nleft); return ip->chksum; @@ -126,7 +129,14 @@ static inline uint16sum_t odph_ipv4_csum_update(odp_packet_t pkt) * IPv6 header */ typedef struct ODP_PACKED { - uint32be_t ver_tc_flow; /**< Version / Traffic class / Flow label */ + union { + uint32be_t ver_tc_flow; /**< Version / TC / Flow label */ + struct { + uint32be_t ver:4; /**< Version (must be 6) */ + uint32be_t tc:8; /**< Traffic class */ + uint32be_t flow:20; /**< Flow label */ + }; + }; uint16be_t payload_len; /**< Payload length */ uint8_t next_hdr; /**< Next header */ uint8_t hop_limit; /**< Hop limit */ @@ -137,16 +147,29 @@ typedef struct ODP_PACKED { /** @internal Compile time assert */ ODP_STATIC_ASSERT(sizeof(odph_ipv6hdr_t) == ODPH_IPV6HDR_LEN, "ODPH_IPV6HDR_T__SIZE_ERROR"); +/** + * IPv6 Header extensions + */ +typedef struct ODP_PACKED { + uint8_t next_hdr; /**< Protocol of next header */ + uint8_t ext_len; /**< Length of this extention in 8 byte units, + not counting first 8 bytes, so 0 = 8 bytes + 1 = 16 bytes, etc. */ + uint8_t filler[6]; /**< Fill out first 8 byte segment */ +} odph_ipv6hdr_ext_t; + /** @name * IP protocol values (IPv4:'proto' or IPv6:'next_hdr') * @{*/ -#define ODPH_IPPROTO_ICMP 0x01 /**< Internet Control Message Protocol (1) */ -#define ODPH_IPPROTO_TCP 0x06 /**< Transmission Control Protocol (6) */ -#define ODPH_IPPROTO_UDP 0x11 /**< User Datagram Protocol (17) */ -#define ODPH_IPPROTO_SCTP 0x84 /**< Stream Control Transmission Protocol (132) */ -#define ODPH_IPPROTO_FRAG 0x2C /**< Fragment (44) */ -#define ODPH_IPPROTO_AH 0x33 /**< Authentication Header (51) */ -#define ODPH_IPPROTO_ESP 0x32 /**< Encapsulating Security Payload (50) */ +#define ODPH_IPPROTO_HOPOPTS 0x00 /**< IPv6 hop-by-hop options */ +#define ODPH_IPPROTO_ICMP 0x01 /**< Internet Control Message Protocol (1) */ +#define ODPH_IPPROTO_TCP 0x06 /**< Transmission Control Protocol (6) */ +#define ODPH_IPPROTO_UDP 0x11 /**< User Datagram Protocol (17) */ +#define ODPH_IPPROTO_ROUTE 0x2B /**< IPv6 Routing header (43) */ +#define ODPH_IPPROTO_FRAG 0x2C /**< IPv6 Fragment (44) */ +#define ODPH_IPPROTO_AH 0x33 /**< Authentication Header (51) */ +#define ODPH_IPPROTO_ESP 0x32 /**< Encapsulating Security Payload (50) */ +#define ODPH_IPPROTO_INVALID 0xFF /**< Reserved invalid by IANA */ /**@}*/ #ifdef __cplusplus diff --git a/helper/include/odph_packet.h b/helper/include/odph_packet.h deleted file mode 100644 index 3d53593..0000000 --- a/helper/include/odph_packet.h +++ /dev/null @@ -1,97 +0,0 @@ -/* Copyright (c) 2014, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - - -/** - * @file - * - * Optional ODP packet helper functions - */ - -#ifndef ODPH_PACKET_HELPER_H_ -#define ODPH_PACKET_HELPER_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/** - * Helper: Tests if packet is valid - * - * Allows for more thorough checking than "if (pkt == ODP_PACKET_INVALID)" - * - * @param pkt Packet handle - * - * @return 1 if valid, otherwise 0 - */ -static inline int odph_packet_is_valid(odp_packet_t pkt) -{ - odp_buffer_t buf = odp_packet_to_buffer(pkt); - - return odp_buffer_is_valid(buf); -} - -/** - * Helper: Allocate and initialize a packet buffer from a packet pool - * - * @param pool_id Pool handle - * - * @note The pool must have been created with 'buf_type=ODP_BUFFER_TYPE_PACKET' - * - * @return Packet handle or ODP_PACKET_INVALID - */ -static inline odp_packet_t odph_packet_alloc(odp_buffer_pool_t pool_id) -{ - odp_packet_t pkt; - odp_buffer_t buf; - - buf = odp_buffer_alloc(pool_id); - if (odp_unlikely(!odp_buffer_is_valid(buf))) - return ODP_PACKET_INVALID; - - pkt = odp_packet_from_buffer(buf); - odp_packet_init(pkt); - - return pkt; -} - -/** - * Helper: Free a packet buffer back into the packet pool - * - * @param pkt Packet handle - */ -static inline void odph_packet_free(odp_packet_t pkt) -{ - odp_buffer_t buf = odp_packet_to_buffer(pkt); - - odp_buffer_free(buf); -} - -/** - * Helper: Packet buffer maximum data size - * - * @note odp_packet_buf_size(pkt) != odp_packet_get_len(pkt), the former returns - * the max length of the buffer, the latter the size of a received packet. - * - * @param pkt Packet handle - * - * @return Packet buffer maximum data size - */ -static inline size_t odph_packet_buf_size(odp_packet_t pkt) -{ - odp_buffer_t buf = odp_packet_to_buffer(pkt); - - return odp_buffer_size(buf); -} - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/helper/include/odph_tcp.h b/helper/include/odph_tcp.h new file mode 100644 index 0000000..4c5912b --- /dev/null +++ b/helper/include/odph_tcp.h @@ -0,0 +1,61 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + +/** + * @file + * + * ODP TCP header + */ + +#ifndef ODPH_TCP_H_ +#define ODPH_TCP_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/** UDP header length */ +#define ODPH_TCPHDR_LEN 8 + +/** TCP header */ +typedef struct ODP_PACKED { + uint16be_t src_port; /**< Source port */ + uint16be_t dst_port; /**< Destinatino port */ + uint32be_t seq_no; /**< Sequence number */ + uint32be_t ack_no; /**< Acknowledgment number */ + union { + uint32be_t flags_and_window; + struct { + uint32be_t rsvd1:8; + uint32be_t flags:8; /**< TCP flags as a byte */ + uint32be_t rsvd2:16; + }; + struct { + uint32be_t hl:4; /**< Hdr len, in words */ + uint32be_t rsvd3:6; /**< Reserved */ + uint32be_t urg:1; /**< ACK */ + uint32be_t ack:1; + uint32be_t psh:1; + uint32be_t rst:1; + uint32be_t syn:1; + uint32be_t fin:1; + uint32be_t window:16; /**< Window size */ + }; + }; + uint16be_t cksm; /**< Checksum */ + uint16be_t urgptr; /**< Urgent pointer */ +} odph_tcphdr_t; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/helper/include/odph_udp.h b/helper/include/odph_udp.h index b2eaf03..bd0fb68 100644 --- a/helper/include/odph_udp.h +++ b/helper/include/odph_udp.h @@ -57,15 +57,14 @@ static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt) odph_udphdr_t *udph; odph_ipv4hdr_t *iph; uint16_t udplen; + size_t l3_seglen, l4_seglen; - if (!odp_packet_l3_offset(pkt)) + if (odp_packet_l3_protocol(pkt) != 0x800 || + odp_packet_l4_protocol(pkt) != ODPH_IPPROTO_UDP) return 0; - if (!odp_packet_l4_offset(pkt)) - return 0; - - iph = (odph_ipv4hdr_t *)odp_packet_l3(pkt); - udph = (odph_udphdr_t *)odp_packet_l4(pkt); + iph = (odph_ipv4hdr_t *)odp_packet_l3_map(pkt, &l3_seglen); + udph = (odph_udphdr_t *)odp_packet_l4_map(pkt, &l4_seglen); udplen = odp_be_to_cpu_16(udph->length); /* the source ip */