From patchwork Fri Nov 14 09:30:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 40802 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 506E6240ED for ; Fri, 14 Nov 2014 09:31:32 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id a1sf375948wgh.7 for ; Fri, 14 Nov 2014 01:31:31 -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=NWHakJpTwGqbihD5b2RAFuACUKq11WOTa8AXbsAhCY4=; b=lw1RYK8LHaFf5isH0hbSGuIHhnkOIhzKsHPBvKILxXlPGzrOJ7ynZ7ISiR9+1F2JP7 EeHYRswRNJaU46OqadhVIUFdr6CIe2M8rVDR/gpBHhqIXFNiuZTTgsziNPLFaHolbXc9 qa/1bgXNp/cs6JrmZnAkeUd/SFGGXchU3VMnEghcXSFQnE61SHUPO0BrHd5uRTY+oKOh p00F18CTu0+hwrWil7i6AUYrSUR3qDYMDvtVqOnsYkZ59wZaCQs6C/WZokD/6FAKjIuE 7/UDY3em2tCJnAasHofBOVPGKEGu1kezd0uSgPhZtiD+BMNzv4q9hC/KF2rbi6quEy3y 3teg== X-Gm-Message-State: ALoCoQl1q6JvdszzQN/HyJRprWmvANfDgxPm0mXKRWXR04UYQ1qdnucBrPq13LrHFRoBGEOOAhKv X-Received: by 10.180.100.100 with SMTP id ex4mr864512wib.2.1415957491614; Fri, 14 Nov 2014 01:31:31 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.169 with SMTP id 9ls949944lan.109.gmail; Fri, 14 Nov 2014 01:31:31 -0800 (PST) X-Received: by 10.112.150.102 with SMTP id uh6mr7360177lbb.50.1415957491371; Fri, 14 Nov 2014 01:31:31 -0800 (PST) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id 6si40899459lav.119.2014.11.14.01.31.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Nov 2014 01:31:31 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id w7so3871560lbi.1 for ; Fri, 14 Nov 2014 01:31:31 -0800 (PST) X-Received: by 10.112.12.35 with SMTP id v3mr1117496lbb.80.1415957491264; Fri, 14 Nov 2014 01:31:31 -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 ew9csp735993lbc; Fri, 14 Nov 2014 01:31:30 -0800 (PST) X-Received: by 10.224.7.200 with SMTP id e8mr9984104qae.77.1415957489456; Fri, 14 Nov 2014 01:31:29 -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 z13si40838317qaz.122.2014.11.14.01.31.28 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 14 Nov 2014 01:31:29 -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 1XpDDz-0003nJ-Cb; Fri, 14 Nov 2014 09:31:27 +0000 Received: from mail-la0-f45.google.com ([209.85.215.45]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XpDDn-0003mH-Rf for lng-odp@lists.linaro.org; Fri, 14 Nov 2014 09:31:15 +0000 Received: by mail-la0-f45.google.com with SMTP id pn19so14554839lab.4 for ; Fri, 14 Nov 2014 01:31:10 -0800 (PST) X-Received: by 10.112.148.130 with SMTP id ts2mr7254012lbb.43.1415957469508; Fri, 14 Nov 2014 01:31:09 -0800 (PST) Received: from localhost.localdomain (broadband-46-188-125-121.2com.net. [46.188.125.121]) by mx.google.com with ESMTPSA id x3sm1676435laj.34.2014.11.14.01.31.07 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Nov 2014 01:31:08 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 14 Nov 2014 12:30:57 +0300 Message-Id: <1415957459-11458-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1415957459-11458-1-git-send-email-maxim.uvarov@linaro.org> References: <1415957459-11458-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 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.170 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 --- 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 360636d..e5cf320 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -136,6 +136,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 f35193f..f0e361a 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) 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) { + 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) { + ODP_DBG("ioctl SIOCGIFMTU error\n"); + return -1; + } + + return ifr.ifr_mtu; +}