From patchwork Wed Dec 30 10:18:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 59073 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2760147lbb; Wed, 30 Dec 2015 02:18:56 -0800 (PST) X-Received: by 10.140.159.131 with SMTP id f125mr87135511qhf.72.1451470736064; Wed, 30 Dec 2015 02:18:56 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id g189si74720833qhd.50.2015.12.30.02.18.55; Wed, 30 Dec 2015 02:18:56 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id A64F26179D; Wed, 30 Dec 2015 10:18:55 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=g5jTpYEJ; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id ECCFA61796; Wed, 30 Dec 2015 10:18:27 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 25E8861794; Wed, 30 Dec 2015 10:18:23 +0000 (UTC) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com [209.85.217.178]) by lists.linaro.org (Postfix) with ESMTPS id E30EF61789 for ; Wed, 30 Dec 2015 10:18:21 +0000 (UTC) Received: by mail-lb0-f178.google.com with SMTP id sv6so106775592lbb.0 for ; Wed, 30 Dec 2015 02:18:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bu4roSiZxTtA0yNqZH8Dlv76ARkJK4/9AlE3jL8F9T8=; b=g5jTpYEJJ01jJoPHkJsBPwd3CYLb8Y4UKPYezzEsrNMHv/2CdXlfhRRMqXlylOPYcd KN0iWTSRdf8Ris6E/xUuPTVf4W9j1Z0WY/Zm5Rp9AgNqz8ruUnEbHQFi98qIRj4XruBd vc4pxi7RR4MHnDYqWJc3SIR2ztrpmQKMFcrkY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bu4roSiZxTtA0yNqZH8Dlv76ARkJK4/9AlE3jL8F9T8=; b=KGe529FD7XJPfJXyj98QEPCuBBrPYVXvuG82JrmvapbGbrZzs6uSzcXTUZgF6aCpYB bsyheEOpIYOUd0Eh1mtJgZDFpATzmAUOcrBlx+vS4PnxGGBpJjro1N7DsRZS/mHCYGUf Dep+nenTsB0IMV4ib+7Nk8amsMcyMzt+ytuj33FuzzLe6yw+Fq4atsaN/W5nEwRTvjfB 5hVjVq4xkQtuf5j6eddZ3XNiE7VO6l+sB/BO/X1418uYG7T6vNHGXwyO0Fz0RcGYEENu J0wviopJ+4f92IyvAXgHR4vUt/4+wVLgBQ+ys+3qXzNPzIrnOY/7pT/oaEJz6VSWWnzl S6UA== X-Gm-Message-State: ALoCoQmai30ngZlqZG8P4iVgyv6k23vg6Kzjhlgy3DvuRGdEHiixnERBBB6AVvDaeglW7jlW51Fo03MyiWLtxID29XZJ62ewSg== X-Received: by 10.112.200.40 with SMTP id jp8mr23166212lbc.104.1451470700853; Wed, 30 Dec 2015 02:18:20 -0800 (PST) Received: from localhost.localdomain (ppp91-76-173-134.pppoe.mtu-net.ru. [91.76.173.134]) by smtp.gmail.com with ESMTPSA id eb3sm6209001lbc.31.2015.12.30.02.18.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Dec 2015 02:18:20 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 30 Dec 2015 13:18:13 +0300 Message-Id: <1451470694-15707-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451470694-15707-1-git-send-email-maxim.uvarov@linaro.org> References: <1451470694-15707-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [NEXT PATCHv3 1/2] linux-generic: pktio: implement odp_pktio_link_status() X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" Signed-off-by: Maxim Uvarov --- .../linux-generic/include/odp_packet_io_internal.h | 1 + platform/linux-generic/include/odp_packet_socket.h | 5 +++++ platform/linux-generic/odp_packet_io.c | 26 ++++++++++++++++++++++ platform/linux-generic/pktio/socket.c | 24 ++++++++++++++++++++ platform/linux-generic/pktio/socket_mmap.c | 7 ++++++ 5 files changed, 63 insertions(+) diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index e15c6af..4fd3c87 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -137,6 +137,7 @@ typedef struct pktio_if_ops { int (*promisc_mode_set)(pktio_entry_t *pktio_entry, int enable); int (*promisc_mode_get)(pktio_entry_t *pktio_entry); int (*mac_get)(pktio_entry_t *pktio_entry, void *mac_addr); + int (*link_status)(pktio_entry_t *pktio_entry); int (*capability)(pktio_entry_t *pktio_entry, odp_pktio_capability_t *capa); int (*input_queues_config)(pktio_entry_t *pktio_entry, diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h index 66c258f..ec202db 100644 --- a/platform/linux-generic/include/odp_packet_socket.h +++ b/platform/linux-generic/include/odp_packet_socket.h @@ -118,6 +118,11 @@ int promisc_mode_set_fd(int fd, const char *name, int enable); int promisc_mode_get_fd(int fd, const char *name); /** + * Return link status of a packet socket (up/down) + */ +int link_status_fd(int fd, const char *name); + +/** * Get enabled RSS hash protocols of a packet socket * * @param fd Socket file descriptor diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index a235798..95b8904 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -821,6 +821,32 @@ int odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, int addr_size) return ret; } +int odp_pktio_link_status(odp_pktio_t id) +{ + pktio_entry_t *entry; + int ret = -1; + + entry = get_pktio_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + lock_entry(entry); + + if (odp_unlikely(is_free(entry))) { + unlock_entry(entry); + ODP_DBG("already freed pktio\n"); + return -1; + } + + if (entry->s.ops->link_status) + ret = entry->s.ops->link_status(entry); + unlock_entry(entry); + + return ret; +} + void odp_pktio_param_init(odp_pktio_param_t *params) { memset(params, 0, sizeof(odp_pktio_param_t)); diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index ae5a2d6..343f89e 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -195,6 +195,23 @@ int promisc_mode_get_fd(int fd, const char *name) return !!(ifr.ifr_flags & IFF_PROMISC); } +int link_status_fd(int fd, const char *name) +{ + struct ifreq ifr; + int ret; + + snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", name); + ret = ioctl(fd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + __odp_errno = errno; + ODP_DBG("ioctl(SIOCGIFFLAGS): %s: \"%s\".\n", strerror(errno), + ifr.ifr_name); + return -1; + } + + return !!(ifr.ifr_flags & IFF_RUNNING); +} + /** * Get enabled hash options of a packet socket * @@ -767,6 +784,12 @@ static int sock_promisc_mode_get(pktio_entry_t *pktio_entry) pktio_entry->s.name); } +static int sock_link_status(pktio_entry_t *pktio_entry) +{ + return link_status_fd(pktio_entry->s.pkt_sock.sockfd, + pktio_entry->s.name); +} + const pktio_if_ops_t sock_mmsg_pktio_ops = { .name = "socket", .init = NULL, @@ -781,6 +804,7 @@ const pktio_if_ops_t sock_mmsg_pktio_ops = { .promisc_mode_set = sock_promisc_mode_set, .promisc_mode_get = sock_promisc_mode_get, .mac_get = sock_mac_addr_get, + .link_status = sock_link_status, .capability = NULL, .input_queues_config = NULL, .output_queues_config = NULL, diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index 628848a..b8f2665 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -554,6 +554,12 @@ static int sock_mmap_promisc_mode_get(pktio_entry_t *pktio_entry) pktio_entry->s.name); } +static int sock_mmap_link_status(pktio_entry_t *pktio_entry) +{ + return link_status_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + pktio_entry->s.name); +} + const pktio_if_ops_t sock_mmap_pktio_ops = { .name = "socket_mmap", .init = NULL, @@ -568,6 +574,7 @@ const pktio_if_ops_t sock_mmap_pktio_ops = { .promisc_mode_set = sock_mmap_promisc_mode_set, .promisc_mode_get = sock_mmap_promisc_mode_get, .mac_get = sock_mmap_mac_addr_get, + .link_status = sock_mmap_link_status, .capability = NULL, .input_queues_config = NULL, .output_queues_config = NULL,