From patchwork Thu Nov 13 12:18:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 40744 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C039F24493 for ; Thu, 13 Nov 2014 12:18:40 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id b6sf2556652lbj.0 for ; Thu, 13 Nov 2014 04:18:39 -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=em2qabc6okxGGAa8s1NjDMlLuw7wSHahcJOjvzggSK8=; b=hTtlNxOBhTyYiIeWghxy/bqQUAenN4ozCayr5+KTfGGG19sLwH6LB4IKgeddb5pXd8 3S7CiboFVbGYSEVPA9gV7L6QY8aqc/zJiCIrLktM+QYjyDay5LlJ1vFlXbJjPFz6icSV SDE/HYTQnMgvn4kd/RSVSUqSCyO/HDNBMU0nzQNQGPSRuNG1h6+kSF6Ptt5yscyGzM3e WdYuyMSr+tNO7+bXEVeiGW8tBaqvJP3Py65TJJSneVtEqPLFSGwlCS3c8i0KLMTkxDkW ukE7j/+bJKuDSt9xXCndF22UEVrP7H8B2y9p9qBdBFzFYR8K48e4MdXkipGPhuMaHHyN 8lWQ== X-Gm-Message-State: ALoCoQlGcRo5b1HB01461VZsCwFE2XmFJgLGPR6Moobeu4QjkX3dDrAVcCHS8yDP3sbb/dXtIfgJ X-Received: by 10.112.146.104 with SMTP id tb8mr269722lbb.22.1415881119665; Thu, 13 Nov 2014 04:18:39 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.6.12 with SMTP id cq12ls93272lad.42.gmail; Thu, 13 Nov 2014 04:18:39 -0800 (PST) X-Received: by 10.152.22.74 with SMTP id b10mr2158423laf.16.1415881119358; Thu, 13 Nov 2014 04:18:39 -0800 (PST) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id k1si38257660lah.55.2014.11.13.04.18.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Nov 2014 04:18:39 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by mail-lb0-f169.google.com with SMTP id 10so11067182lbg.0 for ; Thu, 13 Nov 2014 04:18:39 -0800 (PST) X-Received: by 10.152.37.69 with SMTP id w5mr2029592laj.67.1415881119265; Thu, 13 Nov 2014 04:18:39 -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 ew9csp579510lbc; Thu, 13 Nov 2014 04:18:38 -0800 (PST) X-Received: by 10.224.46.5 with SMTP id h5mr2900237qaf.26.1415881117638; Thu, 13 Nov 2014 04:18:37 -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 v4si46257356qcz.24.2014.11.13.04.18.36 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 13 Nov 2014 04:18:37 -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 1XotMC-0001Ty-2a; Thu, 13 Nov 2014 12:18:36 +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 1XotM0-0001Tc-44 for lng-odp@lists.linaro.org; Thu, 13 Nov 2014 12:18:24 +0000 Received: by mail-la0-f45.google.com with SMTP id pn19so12970227lab.4 for ; Thu, 13 Nov 2014 04:18:18 -0800 (PST) X-Received: by 10.112.234.201 with SMTP id ug9mr2197742lbc.14.1415881098172; Thu, 13 Nov 2014 04:18:18 -0800 (PST) Received: from localhost.localdomain (broadband-46-188-125-147.2com.net. [46.188.125.147]) by mx.google.com with ESMTPSA id j6sm7450270lbs.9.2014.11.13.04.18.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 13 Nov 2014 04:18:17 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 13 Nov 2014 15:18:05 +0300 Message-Id: <1415881086-13088-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1415881086-13088-1-git-send-email-maxim.uvarov@linaro.org> References: <1415881086-13088-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv3 1/2] 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.169 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..90d525b 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -135,6 +135,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..651815d 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 != 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; +}