From patchwork Mon Feb 17 12:14:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Wallen X-Patchwork-Id: 24763 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f200.google.com (mail-qc0-f200.google.com [209.85.216.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4EB6B202B2 for ; Mon, 17 Feb 2014 12:15:48 +0000 (UTC) Received: by mail-qc0-f200.google.com with SMTP id e9sf29793266qcy.11 for ; Mon, 17 Feb 2014 04:15:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=/xl1OFQH1PHcL+y816gcvsCFbAE8RDWMxwu/rhWnFLE=; b=mf26URnsUBk1HzDqiF+VI4xIE4rbrcWf4cFQA596aa0/ZzywstlYJxpyOs2bammOan 0nHpDSx8zBSHXiSub07q6MvmjHm0burTyKNyjUX4v4koyi1cyB0nI6jy94qOkUEEhGKr iHOt51JHAAcQbWYfqMr8GxkLoe1zc182c2pvTps3OmWm/kHga1qczqbBdNLYsvdMfv8z G8R1/GHUmzCs0n/dPDeT8Y57GsH2k0KTux8XaEbfsjRtMxrqNmU57lKQK7WogVH2hqAR CJeJZqDJuFBqRbfkJ8PEGX3JDZ2Q3B3/MOrDovSeTGJUzcQZf5r6emkhNI37cgrBPiBd Aonw== X-Gm-Message-State: ALoCoQmmfdDv44DnE4so5gM/2Sx+dj7s8elJcGA4+hhR5XrMQVlPPlza+cfmlPThdsDn09QN+Aew X-Received: by 10.236.61.170 with SMTP id w30mr8945358yhc.20.1392639347474; Mon, 17 Feb 2014 04:15:47 -0800 (PST) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.140.90.80 with SMTP id w74ls888403qgd.95.gmail; Mon, 17 Feb 2014 04:15:46 -0800 (PST) X-Received: by 10.140.30.66 with SMTP id c60mr31630149qgc.13.1392639346368; Mon, 17 Feb 2014 04:15:46 -0800 (PST) Received: from mail-qg0-f50.google.com (mail-qg0-f50.google.com [209.85.192.50]) by mx.google.com with ESMTPS id f91si7886566qge.198.2014.02.17.04.15.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 04:15:46 -0800 (PST) Received-SPF: neutral (google.com: 209.85.192.50 is neither permitted nor denied by best guess record for domain of carl.wallen@linaro.org) client-ip=209.85.192.50; Received: by mail-qg0-f50.google.com with SMTP id z60so4825946qgd.9 for ; Mon, 17 Feb 2014 04:15:46 -0800 (PST) X-Received: by 10.140.101.162 with SMTP id u31mr1138482qge.107.1392639346175; Mon, 17 Feb 2014 04:15:46 -0800 (PST) Received: from mcint01.emea.nsn-net.net (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id 3sm44637049qan.15.2014.02.17.04.15.45 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 04:15:45 -0800 (PST) From: Carl Wallen To: lng-odp@linaro.org Cc: Carl Wallen Subject: [lng-odp] [PATCH 4/7] ODP Packet: L2, L3, L4-header access func retval change Date: Mon, 17 Feb 2014 14:14:38 +0200 Message-Id: <1392639281-2753-5-git-send-email-carl.wallen@linaro.org> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1392639281-2753-1-git-send-email-carl.wallen@linaro.org> References: <1392639281-2753-1-git-send-email-carl.wallen@linaro.org> X-Original-Sender: carl.wallen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.192.50 is neither permitted nor denied by best guess record for domain of carl.wallen@linaro.org) smtp.mail=carl.wallen@linaro.org Precedence: list Mailing-list: list lng-odp@linaro.org; contact lng-odp+owners@linaro.org List-ID: X-Google-Group-Id: 474323889996 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , odp_packet_l2/l3/l4_offset() returns ODP_PACKET_OFFSET_INVALID if no known header is found. odp_packet_l2/l3/l4() returns NULL if no known header is found. Signed-off-by: Carl Wallen --- include/odp_packet.h | 46 ++++++++++++++++++++++-------- platform/linux-generic/source/odp_packet.c | 30 +++++++++++++++++-- 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/include/odp_packet.h b/include/odp_packet.h index 4de4db2..0b693d9 100644 --- a/include/odp_packet.h +++ b/include/odp_packet.h @@ -27,6 +27,8 @@ extern "C" { typedef uint32_t odp_packet_t; #define ODP_PACKET_INVALID ODP_BUFFER_INVALID +#define ODP_PACKET_OFFSET_INVALID ((size_t)-1) + /** * Initialize the packet @@ -74,21 +76,41 @@ void odp_packet_set_len(odp_packet_t pkt, size_t len); size_t odp_packet_get_len(odp_packet_t pkt); /** - * Get pointer to the start of the packet buffer + * Get address to the start of the packet buffer * - * The start address of the packet buffer is not necessarily the same as the - * start address of a received frame, e.g. an eth frame may be offset by 2 or 6 + * The address of the packet buffer is not necessarily the same as the start + * address of the received frame, e.g. an eth frame may be offset by 2 or 6 * bytes to ensure 32 or 64-bit alignment of the IP header. - * Use odp_packet_l2(pkt) to get the start address of a received frame. + * Use odp_packet_l2(pkt) to get the start address of a received valid frame + * or odp_packet_start(pkt) to get the start address even if no valid L2 header + * could be found. * * @param pkt Packet handle * * @return Pointer to the start of the packet buffer * - * @see odp_packet_l2() + * @see odp_packet_l2(), odp_packet_start() */ uint8_t *odp_packet_buf_addr(odp_packet_t pkt); +/** + * Get pointer to the start of the received frame + * + * The address of the packet buffer is not necessarily the same as the start + * address of the received frame, e.g. an eth frame may be offset by 2 or 6 + * bytes to ensure 32 or 64-bit alignment of the IP header. + * Use odp_packet_l2(pkt) to get the start address of a received valid eth frame + * + * odp_packet_start() will always return a pointer to the start of the frame, + * even if the frame is unrecognized and no valid L2 header could be found. + * + * @param pkt Packet handle + * + * @return Pointer to the start of the received frame + * + * @see odp_packet_l2(), odp_packet_buf_addr() + */ +uint8_t *odp_packet_start(odp_packet_t pkt); /** * Get pointer to the start of the L2 frame @@ -98,9 +120,9 @@ uint8_t *odp_packet_buf_addr(odp_packet_t pkt); * * @param pkt Packet handle * - * @return Pointer to L2 header + * @return Pointer to L2 header or NULL if not found * - * @see odp_packet_buf_addr() + * @see odp_packet_buf_addr(), odp_packet_start() */ uint8_t *odp_packet_l2(odp_packet_t pkt); @@ -109,7 +131,7 @@ uint8_t *odp_packet_l2(odp_packet_t pkt); * * @param pkt Packet handle * - * @return L2 byte offset + * @return L2 byte offset or ODP_PACKET_OFFSET_INVALID if not found */ size_t odp_packet_l2_offset(odp_packet_t pkt); @@ -127,7 +149,7 @@ void odp_packet_set_l2_offset(odp_packet_t pkt, size_t offset); * * @param pkt Packet handle * - * @return Pointer to L3 packet + * @return Pointer to L3 packet or NULL if not found * */ uint8_t *odp_packet_l3(odp_packet_t pkt); @@ -137,7 +159,7 @@ uint8_t *odp_packet_l3(odp_packet_t pkt); * * @param pkt Packet handle * - * @return L3 byte offset + * @return L3 byte offset or ODP_PACKET_OFFSET_INVALID if not found */ size_t odp_packet_l3_offset(odp_packet_t pkt); @@ -155,7 +177,7 @@ void odp_packet_set_l3_offset(odp_packet_t pkt, size_t offset); * * @param pkt Packet handle * - * @return Pointer to L4 packet + * @return Pointer to L4 packet or NULL if not found * */ uint8_t *odp_packet_l4(odp_packet_t pkt); @@ -165,7 +187,7 @@ uint8_t *odp_packet_l4(odp_packet_t pkt); * * @param pkt Packet handle * - * @return L4 byte offset + * @return L4 byte offset or ODP_PACKET_OFFSET_INVALID if not found */ size_t odp_packet_l4_offset(odp_packet_t pkt); diff --git a/platform/linux-generic/source/odp_packet.c b/platform/linux-generic/source/odp_packet.c index 6ee2c5b..060d82e 100644 --- a/platform/linux-generic/source/odp_packet.c +++ b/platform/linux-generic/source/odp_packet.c @@ -25,6 +25,10 @@ void odp_packet_init(odp_packet_t pkt) start = (uint8_t *)pkt_hdr + start_offset; len = ODP_OFFSETOF(odp_packet_hdr_t, payload) - start_offset; memset(start, 0, len); + + pkt_hdr->l2_offset = (uint32_t) ODP_PACKET_OFFSET_INVALID; + pkt_hdr->l3_offset = (uint32_t) ODP_PACKET_OFFSET_INVALID; + pkt_hdr->l4_offset = (uint32_t) ODP_PACKET_OFFSET_INVALID; } odp_packet_t odp_packet_from_buffer(odp_buffer_t buf) @@ -52,10 +56,20 @@ uint8_t *odp_packet_buf_addr(odp_packet_t pkt) return odp_buffer_addr(odp_buffer_from_packet(pkt)); } +uint8_t *odp_packet_start(odp_packet_t pkt) +{ + return odp_packet_buf_addr(pkt) + odp_packet_hdr(pkt)->frame_offset; +} + uint8_t *odp_packet_l2(odp_packet_t pkt) { - return odp_packet_buf_addr(pkt) + odp_packet_l2_offset(pkt); + const size_t offset = odp_packet_l2_offset(pkt); + + if (odp_unlikely(offset == ODP_PACKET_OFFSET_INVALID)) + return NULL; + + return odp_packet_buf_addr(pkt) + offset; } size_t odp_packet_l2_offset(odp_packet_t pkt) @@ -71,7 +85,12 @@ void odp_packet_set_l2_offset(odp_packet_t pkt, size_t offset) uint8_t *odp_packet_l3(odp_packet_t pkt) { - return odp_packet_buf_addr(pkt) + odp_packet_l3_offset(pkt); + const size_t offset = odp_packet_l3_offset(pkt); + + if (odp_unlikely(offset == ODP_PACKET_OFFSET_INVALID)) + return NULL; + + return odp_packet_buf_addr(pkt) + offset; } size_t odp_packet_l3_offset(odp_packet_t pkt) @@ -87,7 +106,12 @@ void odp_packet_set_l3_offset(odp_packet_t pkt, size_t offset) uint8_t *odp_packet_l4(odp_packet_t pkt) { - return odp_packet_buf_addr(pkt) + odp_packet_l4_offset(pkt); + const size_t offset = odp_packet_l4_offset(pkt); + + if (odp_unlikely(offset == ODP_PACKET_OFFSET_INVALID)) + return NULL; + + return odp_packet_buf_addr(pkt) + offset; } size_t odp_packet_l4_offset(odp_packet_t pkt)