From patchwork Thu Feb 19 11:26:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venkatesh Vivekanandan X-Patchwork-Id: 44812 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 204E121554 for ; Thu, 19 Feb 2015 11:31:04 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id c41sf5101325eek.1 for ; Thu, 19 Feb 2015 03:31:03 -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 :mime-version:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=kph5CULTjIwSpGVF21Ge0PnA/Gc7vk2BsTQoWJ24ttQ=; b=U/QV+Di8VvkKFgNv2xGklFv74apqEjAyK84fK8q6tnS38J7XKJFyIJBMWdJYK6lSEb UpTFpu63/pTFzbwtN5546axBGMIC+lQTCgcD0WHOQ4Xf9tHrWhbayL/T58f64HdUH1PR bw9G3sEhecdm6C+jL6rQpMtsMAlHEUSiMsf2eaBNdvqtmyyJNEqBP5j5084GCveN16LE Eoo1+lBv3fFfBvClGKwXAUELkNIG+xgW7Ok0X4ayGkZ2s22HnCRuNeT2GBb8lyKmJMNc rYaipfitQCmwNwEeJeWIbqIPmu7Z+pDUMUjI294/W9UdPHVVFf7lOql3tSAkUdJR71Mj XGfA== X-Gm-Message-State: ALoCoQlHX/xzc6BxYZcU9eRJunP2N4aRPls7nP2NwpxGe7ZDORoNsg4cpcXnPS0Vr7BpcLWycmQ9 X-Received: by 10.194.86.1 with SMTP id l1mr521433wjz.0.1424345463019; Thu, 19 Feb 2015 03:31:03 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.74 with SMTP id q10ls148392laq.43.gmail; Thu, 19 Feb 2015 03:31:02 -0800 (PST) X-Received: by 10.112.235.10 with SMTP id ui10mr3516472lbc.77.1424345462834; Thu, 19 Feb 2015 03:31:02 -0800 (PST) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id k1si17027341laf.21.2015.02.19.03.31.02 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Feb 2015 03:31:02 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by lbvn10 with SMTP id n10so6854844lbv.4 for ; Thu, 19 Feb 2015 03:31:02 -0800 (PST) X-Received: by 10.112.162.167 with SMTP id yb7mr3511780lbb.76.1424345462638; Thu, 19 Feb 2015 03:31:02 -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.35.133 with SMTP id h5csp430153lbj; Thu, 19 Feb 2015 03:31:01 -0800 (PST) X-Received: by 10.140.150.21 with SMTP id 21mr11192440qhw.69.1424345461120; Thu, 19 Feb 2015 03:31:01 -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 w2si10001824qap.18.2015.02.19.03.30.59 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Feb 2015 03:31:01 -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 1YOPJp-0005T5-7V; Thu, 19 Feb 2015 11:30:57 +0000 Received: from mail-gw1-out.broadcom.com ([216.31.210.62]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YOPJk-0005Sc-09 for lng-odp@lists.linaro.org; Thu, 19 Feb 2015 11:30:52 +0000 X-IronPort-AV: E=Sophos;i="5.09,512,1418112000"; d="scan'208";a="57648888" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw1-out.broadcom.com with ESMTP; 19 Feb 2015 05:57:19 -0800 Received: from IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Thu, 19 Feb 2015 03:30:46 -0800 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) with Microsoft SMTP Server id 14.3.174.1; Thu, 19 Feb 2015 03:30:53 -0800 Received: from localhost.localdomain (unknown [10.131.60.56]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 233D040FE6; Thu, 19 Feb 2015 03:29:39 -0800 (PST) From: To: Date: Thu, 19 Feb 2015 16:56:50 +0530 Message-ID: <1424345210-8870-1-git-send-email-venkatesh.vivekanandan@linaro.org> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Topics: patch Subject: [lng-odp] [PATCHv4 DPDK 3/6] New headers 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: , 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: venkatesh.vivekanandan@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.217.172 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 From: Venkatesh Vivekanandan - Added new headers from linux-generic into odp-dpdk Signed-off-by: Venkatesh Vivekanandan --- .../linux-dpdk/include/api/odp_platform_types.h | 78 +++++++++ platform/linux-dpdk/include/odp_buffer_inlines.h | 179 +++++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100644 platform/linux-dpdk/include/api/odp_platform_types.h create mode 100644 platform/linux-dpdk/include/odp_buffer_inlines.h diff --git a/platform/linux-dpdk/include/api/odp_platform_types.h b/platform/linux-dpdk/include/api/odp_platform_types.h new file mode 100644 index 0000000..3bedb5d --- /dev/null +++ b/platform/linux-dpdk/include/api/odp_platform_types.h @@ -0,0 +1,78 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + +/** + * @file + * ODP implementation types + * This file contains all of the implementation-defined types for ODP abstract + * definitions. Having this in one file means that other ODP API files are + * implementation-independent and avoids circular dependencies for files that + * refer to types managed by other components. Included here are typedefs and + * related typed constants that are referenced by other ODP API files. + */ + +#ifndef ODP_IMPL_TYPES_H_ +#define ODP_IMPL_TYPES_H_ + +/** @defgroup odp_platform_types ODP PLATFORM TYPES + * Implementation specific definitions for ODP abstract types. + * @{ + */ + +/** ODP Buffer pool */ +typedef unsigned long odp_buffer_pool_t; + +/** Invalid buffer pool */ +#define ODP_BUFFER_POOL_INVALID (0xffffffff) + +/** ODP buffer */ +typedef unsigned long odp_buffer_t; + +/** Invalid buffer */ +#define ODP_BUFFER_INVALID (0xffffffff) + +/** ODP buffer segment */ +typedef odp_buffer_t odp_buffer_seg_t; + +/** Invalid segment */ +#define ODP_SEGMENT_INVALID ODP_BUFFER_INVALID + +/** ODP packet */ +typedef odp_buffer_t odp_packet_t; + +/** Invalid packet */ +#define ODP_PACKET_INVALID ODP_BUFFER_INVALID + +/** ODP packet segment */ +typedef odp_buffer_t odp_packet_seg_t; + +/** Invalid packet segment */ +#define ODP_PACKET_SEG_INVALID ODP_BUFFER_INVALID + +/** ODP packet IO handle */ +typedef uint32_t odp_pktio_t; + +/** Invalid packet IO handle */ +#define ODP_PKTIO_INVALID 0 + +/** odp_pktio_t value to indicate any port */ +#define ODP_PKTIO_ANY ((odp_pktio_t)~0) + +/** + * ODP shared memory block + */ +typedef uint32_t odp_shm_t; + +/** Invalid shared memory block */ +#define ODP_SHM_INVALID 0 +#define ODP_SHM_NULL ODP_SHM_INVALID /**< Synonym for buffer pool use */ + +/** + * @} + */ + +#endif diff --git a/platform/linux-dpdk/include/odp_buffer_inlines.h b/platform/linux-dpdk/include/odp_buffer_inlines.h new file mode 100644 index 0000000..ebf600b --- /dev/null +++ b/platform/linux-dpdk/include/odp_buffer_inlines.h @@ -0,0 +1,179 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * Inline functions for ODP buffer mgmt routines - implementation internal + */ + +#ifndef ODP_BUFFER_INLINES_H_ +#define ODP_BUFFER_INLINES_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +static inline odp_buffer_t odp_buffer_encode_handle(odp_buffer_hdr_t *hdr) +{ + odp_buffer_bits_t handle; + uint32_t pool_id = pool_handle_to_index(hdr->pool_hdl); + struct pool_entry_s *pool = get_pool_entry(pool_id); + + handle.pool_id = pool_id; + handle.index = ((uint8_t *)hdr - pool->pool_mdata_addr) / + ODP_CACHE_LINE_SIZE; + handle.seg = 0; + + return handle.u32; +} + +static inline odp_buffer_t odp_hdr_to_buf(odp_buffer_hdr_t *hdr) +{ + return hdr->handle.handle; +} + +static inline odp_buffer_hdr_t *odp_buf_to_hdr(odp_buffer_t buf) +{ + return (odp_buffer_hdr_t *)buf; +} + +static inline uint32_t odp_buffer_refcount(odp_buffer_hdr_t *buf) +{ + return odp_atomic_load_u32(&buf->ref_count); +} + +static inline uint32_t odp_buffer_incr_refcount(odp_buffer_hdr_t *buf, + uint32_t val) +{ + return odp_atomic_fetch_add_u32(&buf->ref_count, val) + val; +} + +static inline uint32_t odp_buffer_decr_refcount(odp_buffer_hdr_t *buf, + uint32_t val) +{ + uint32_t tmp; + + tmp = odp_atomic_fetch_sub_u32(&buf->ref_count, val); + + if (tmp < val) { + odp_atomic_fetch_add_u32(&buf->ref_count, val - tmp); + return 0; + } else { + return tmp - val; + } +} + +static inline odp_buffer_hdr_t *validate_buf(odp_buffer_t buf) +{ + odp_buffer_bits_t handle; + odp_buffer_hdr_t *buf_hdr; + handle.u32 = buf; + + /* For buffer handles, segment index must be 0 and pool id in range */ + if (handle.seg != 0 || handle.pool_id >= ODP_CONFIG_BUFFER_POOLS) + return NULL; + + pool_entry_t *pool = odp_pool_to_entry(handle.pool_id); + + /* If pool not created, handle is invalid */ + if (pool->s.pool_shm == ODP_SHM_INVALID) + return NULL; + + uint32_t buf_stride = pool->s.buf_stride / ODP_CACHE_LINE_SIZE; + + /* A valid buffer index must be on stride, and must be in range */ + if ((handle.index % buf_stride != 0) || + ((uint32_t)(handle.index / buf_stride) >= pool->s.params.num_bufs)) + return NULL; + + buf_hdr = (odp_buffer_hdr_t *)(void *) + (pool->s.pool_mdata_addr + + (handle.index * ODP_CACHE_LINE_SIZE)); + + /* Handle is valid, so buffer is valid if it is allocated */ + return buf_hdr->allocator == ODP_FREEBUF ? NULL : buf_hdr; +} + +int odp_buffer_snprint(char *str, uint32_t n, odp_buffer_t buf); + +static inline void *buffer_map(odp_buffer_hdr_t *buf, + uint32_t offset, + uint32_t *seglen, + uint32_t limit) +{ + int seg_index = offset / buf->segsize; + int seg_offset = offset % buf->segsize; + + if (seglen != NULL) { + uint32_t buf_left = limit - offset; + *seglen = buf_left < buf->segsize ? + buf_left : buf->segsize - seg_offset; + } + + return (void *)(seg_offset + (uint8_t *)buf->addr[seg_index]); +} + +static inline odp_buffer_seg_t segment_next(odp_buffer_hdr_t *buf, + odp_buffer_seg_t seg) +{ + odp_buffer_bits_t seghandle; + seghandle.u32 = seg; + + if (seg == ODP_SEGMENT_INVALID || + seghandle.prefix != buf->handle.prefix || + seghandle.seg >= buf->segcount - 1) + return ODP_SEGMENT_INVALID; + else { + seghandle.seg++; + return (odp_buffer_seg_t)seghandle.u32; + } +} + +static inline void *segment_map(odp_buffer_hdr_t *buf, + odp_buffer_seg_t seg, + uint32_t *seglen, + uint32_t limit, + uint32_t hr) +{ + uint32_t seg_offset, buf_left; + odp_buffer_bits_t seghandle; + uint8_t *seg_addr; + seghandle.u32 = seg; + + if (seghandle.prefix != buf->handle.prefix || + seghandle.seg >= buf->segcount) + return NULL; + + seg_addr = (uint8_t *)buf->addr[seghandle.seg]; + seg_offset = seghandle.seg * buf->segsize; + limit += hr; + + /* Can't map this segment if it's nothing but headroom or tailroom */ + if (hr >= seg_offset + buf->segsize || seg_offset > limit) + return NULL; + + /* Adjust address & offset if this segment contains any headroom */ + if (hr > seg_offset) { + seg_addr += hr % buf->segsize; + seg_offset += hr % buf->segsize; + } + + /* Set seglen if caller is asking for it */ + if (seglen != NULL) { + buf_left = limit - seg_offset; + *seglen = buf_left < buf->segsize ? buf_left : buf->segsize; + } + + return (void *)seg_addr; +} + + +#ifdef __cplusplus +} +#endif + +#endif