From patchwork Thu Nov 20 08:44:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41219 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 5C54E23588 for ; Thu, 20 Nov 2014 08:44:47 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id ex7sf1720627wid.3 for ; Thu, 20 Nov 2014 00:44:46 -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:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=1qKvVcwoEVQ0c4qQcFzn7nweqlo6RiaGhWhiiDxUfM8=; b=D+fGXFCzfMBpavPo1lYSeQU8bnGzpGObuoX1Cs+zt00i1txE5pgRhNu3dcx3j0RTNj Onqk/gHNNWTWU7sTEAn1Cg4TQSqKJTD9g0fPw9IDvDnXJCT4PUex1sRDYxC/71MIplJv lS52IZKMu/9nPXzFOiiUORjqL6ByGoS91g3YPU1y70o34miJSNVMY06kYrW/mwJ/1HWy JTaYWqS2adxsV1I4r4VfWjCNbXXyTDT0M6FWdIumU79rhGNk1f+RpF89TkwZX5nnQIj0 Fyaj44qJAbPUPnyAzYOLmSchWsCuR+QOs9ew+lRRRWF8HJOW+Fq5jCK0eswMFS5Uxnkw 0zLw== X-Gm-Message-State: ALoCoQnAfMneYhVkAnMx1Y2gCAPIUcvVHnwxqGvwLgt/V7zjJHZrfjYGdsO/cFVhVoA+ldtL9/WA X-Received: by 10.112.199.167 with SMTP id jl7mr6482021lbc.5.1416473086555; Thu, 20 Nov 2014 00:44:46 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.197.100 with SMTP id it4ls38327lac.7.gmail; Thu, 20 Nov 2014 00:44:46 -0800 (PST) X-Received: by 10.152.1.130 with SMTP id 2mr723603lam.89.1416473086187; Thu, 20 Nov 2014 00:44:46 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id y2si1499952lbo.100.2014.11.20.00.44.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 00:44:46 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by mail-lb0-f178.google.com with SMTP id f15so425215lbj.37 for ; Thu, 20 Nov 2014 00:44:46 -0800 (PST) X-Received: by 10.152.37.69 with SMTP id w5mr9831970laj.67.1416473086084; Thu, 20 Nov 2014 00:44:46 -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 ew9csp226332lbc; Thu, 20 Nov 2014 00:44:45 -0800 (PST) X-Received: by 10.224.92.81 with SMTP id q17mr57374527qam.66.1416473083584; Thu, 20 Nov 2014 00:44:43 -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 d9si2100233qch.30.2014.11.20.00.44.42 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 20 Nov 2014 00:44:43 -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 1XrNM1-000886-01; Thu, 20 Nov 2014 08:44:41 +0000 Received: from mail-la0-f46.google.com ([209.85.215.46]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XrNLo-00087E-WD for lng-odp@lists.linaro.org; Thu, 20 Nov 2014 08:44:29 +0000 Received: by mail-la0-f46.google.com with SMTP id gd6so2009531lab.19 for ; Thu, 20 Nov 2014 00:44:23 -0800 (PST) X-Received: by 10.152.87.42 with SMTP id u10mr2748983laz.0.1416473063070; Thu, 20 Nov 2014 00:44:23 -0800 (PST) Received: from localhost.localdomain (broadband-46-188-125-135.2com.net. [46.188.125.135]) by mx.google.com with ESMTPSA id ba19sm427858lab.31.2014.11.20.00.44.21 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Nov 2014 00:44:22 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 20 Nov 2014 11:44:12 +0300 Message-Id: <1416473054-10656-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1416473054-10656-1-git-send-email-maxim.uvarov@linaro.org> References: <1416473054-10656-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv5 1/3] pktio: add MTU manipulation functions 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: maxim.uvarov@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.178 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 Implement pktio mtu functions: odp_pktio_mtu() to get mtu value; odp_pktio_set_mtu() to set mtu value. Signed-off-by: Maxim Uvarov Reviewed-by Mike Holmes Reviewed-by: Anders Roxell --- platform/linux-generic/include/api/odp_packet_io.h | 23 ++++++++ .../linux-generic/include/odp_packet_io_internal.h | 4 ++ platform/linux-generic/odp_packet_io.c | 66 ++++++++++++++++++++++ 3 files changed, 93 insertions(+) diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index 47daeda..667395c 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -126,6 +126,29 @@ void odp_pktio_set_input(odp_packet_t pkt, odp_pktio_t id); odp_pktio_t odp_pktio_get_input(odp_packet_t pkt); /** + * Configure the MTU for a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * @param[in] mtu The value of MTU that the interface will be configured to + * use. + * + * @retval 0 on success. + * @retval -1 if specified mtu can not be handled. + * @retval -1 on any other error or illegal input parameters. + */ +int odp_pktio_set_mtu(odp_pktio_t id, int mtu); + +/** + * Return the currently configured MTU value of a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * + * @retval MTU value >0 on success. + * @retval -1 on any error or not existance pktio id. + */ +int odp_pktio_mtu(odp_pktio_t id); + +/** * @} */ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 23633ed..0bc1e21 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -21,6 +21,8 @@ extern "C" { #include #include +#include + /** * Packet IO types */ @@ -38,6 +40,8 @@ struct pktio_entry { odp_pktio_type_t type; /**< pktio type */ pkt_sock_t pkt_sock; /**< using socket API for IO */ pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap API for IO */ + char name[IFNAMSIZ]; /**< name of pktio provided to + pktio_open() */ }; typedef union { diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index f78b7fd..c523350 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -20,6 +20,7 @@ #include #include +#include typedef struct { pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; @@ -203,6 +204,7 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool) return ODP_PKTIO_INVALID; done: + strncpy(pktio_entry->s.name, dev, IFNAMSIZ); unlock_entry(pktio_entry); return id; } @@ -476,3 +478,67 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) queue_enq_multi(qentry, tmp_hdr_tbl, pkts); return nbr; } + +int odp_pktio_set_mtu(odp_pktio_t id, int mtu) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + if (mtu <= 0) { + ODP_DBG("illegal MTU value %d\n", mtu); + return -1; + } + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + if (entry->s.pkt_sock_mmap.sockfd) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); + ifr.ifr_mtu = mtu; + + ret = ioctl(sockfd, SIOCSIFMTU, (caddr_t)&ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCSIFMTU error\n"); + return -1; + } + + return 0; +} + +int odp_pktio_mtu(odp_pktio_t id) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + if (entry->s.pkt_sock_mmap.sockfd) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); + + ret = ioctl(sockfd, SIOCGIFMTU, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCGIFMTU error\n"); + return -1; + } + + return ifr.ifr_mtu; +}