From patchwork Fri Mar 27 17:56:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 46437 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 F2D3521597 for ; Fri, 27 Mar 2015 17:57:35 +0000 (UTC) Received: by wgfh4 with SMTP id h4sf12531359wgf.1 for ; Fri, 27 Mar 2015 10:57:35 -0700 (PDT) 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=00DWGYJCzyZoSPKxxcBQGBBK7s5lM+Dvr8s1MkPqk/w=; b=ZogCGM+AmHi3JZuSzmGaHU474ML/bvpBainQA85P/EXGsTe8d2UX3NQjEzUq3sClEj oCzOuZFkTR9ga5rAWjUmPI/qMeTjybOrqjGZwjotdtJ6Qcm0wkpiehrNlta5wpGG9T18 tK7/uuNoxppM15GVDJClPLLOvGvWwJRWR8OhQmP2YCQlNonlxmX4LPvknGCu8/d0/zrZ xy9BhxFYFvV3G1yYmheQznuJIube679IR8W0BxqmWMoLVggvJgkcAfTxrZZgo8FvQJj+ jzj2lYfFHxWxbyVneZz/Z5CQuE7sdYssUXcNKBopIbmsJp2rMn58c4qRS9xTEdoFbXhp WCdQ== X-Gm-Message-State: ALoCoQmlBEtwmQu7A923dyA4mb/Dinvs/8jZUdwHD4nJEs/TxhC8FKP7150ap1vCyd46syKKiOyv X-Received: by 10.152.88.33 with SMTP id bd1mr4961012lab.2.1427479055188; Fri, 27 Mar 2015 10:57:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.18.165 with SMTP id x5ls426249lad.29.gmail; Fri, 27 Mar 2015 10:57:34 -0700 (PDT) X-Received: by 10.152.27.225 with SMTP id w1mr13472137lag.77.1427479054898; Fri, 27 Mar 2015 10:57:34 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id o3si1849471laf.47.2015.03.27.10.57.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Mar 2015 10:57:34 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by labe2 with SMTP id e2so76278278lab.3 for ; Fri, 27 Mar 2015 10:57:34 -0700 (PDT) X-Received: by 10.152.8.161 with SMTP id s1mr10043452laa.41.1427479054784; Fri, 27 Mar 2015 10:57:34 -0700 (PDT) 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.57.201 with SMTP id k9csp30079lbq; Fri, 27 Mar 2015 10:57:34 -0700 (PDT) X-Received: by 10.140.32.166 with SMTP id h35mr25828617qgh.31.1427479053498; Fri, 27 Mar 2015 10:57:33 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id p88si1214697qga.128.2015.03.27.10.57.12 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 27 Mar 2015 10:57:33 -0700 (PDT) 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 1YbYVK-0008SQ-Uu; Fri, 27 Mar 2015 17:57:10 +0000 Received: from mail-la0-f48.google.com ([209.85.215.48]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YbYV7-0008Rk-Ik for lng-odp@lists.linaro.org; Fri, 27 Mar 2015 17:56:57 +0000 Received: by lahp7 with SMTP id p7so57414228lah.2 for ; Fri, 27 Mar 2015 10:56:51 -0700 (PDT) X-Received: by 10.152.26.201 with SMTP id n9mr18456401lag.29.1427479011661; Fri, 27 Mar 2015 10:56:51 -0700 (PDT) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id m8sm468335laf.14.2015.03.27.10.56.50 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Mar 2015 10:56:50 -0700 (PDT) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Fri, 27 Mar 2015 19:56:40 +0200 Message-Id: <1427479000-25779-3-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1427479000-25779-1-git-send-email-ciprian.barbu@linaro.org> References: <1427479000-25779-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH NETMAP 2/2] linux-netmap: add per interface socket 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: ciprian.barbu@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.215.45 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 This socket will later be useful to implement odp_pktio_mtu and similar Signed-off-by: Ciprian Barbu --- platform/linux-netmap/include/odp_packet_netmap.h | 5 +++++ platform/linux-netmap/odp_packet_io.c | 2 ++ platform/linux-netmap/odp_packet_netmap.c | 23 +++++++++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/platform/linux-netmap/include/odp_packet_netmap.h b/platform/linux-netmap/include/odp_packet_netmap.h index 4b75a6d..d687fa0 100644 --- a/platform/linux-netmap/include/odp_packet_netmap.h +++ b/platform/linux-netmap/include/odp_packet_netmap.h @@ -60,4 +60,9 @@ int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], */ void pkt_netmap_mac_addr(pkt_netmap_t * const pkt_nm, void *mac_addr, int addr_size); + +/** + * Get socket fd associated with this netmap pktio + */ +int pkt_netmap_sockfd(pkt_netmap_t * const pkt_nm); #endif diff --git a/platform/linux-netmap/odp_packet_io.c b/platform/linux-netmap/odp_packet_io.c index 1957ad0..2c3b91b 100644 --- a/platform/linux-netmap/odp_packet_io.c +++ b/platform/linux-netmap/odp_packet_io.c @@ -697,6 +697,8 @@ static int sockfd_from_pktio_entry(pktio_entry_t *entry) return entry->s.pkt_sock.sockfd; case ODP_PKTIO_TYPE_SOCKET_MMAP: return entry->s.pkt_sock_mmap.sockfd; + case ODP_PKTIO_TYPE_NETMAP: + return pkt_netmap_sockfd(&entry->s.pkt_nm); default: ODP_ABORT("Wrong socket type %d\n", entry->s.type); } diff --git a/platform/linux-netmap/odp_packet_netmap.c b/platform/linux-netmap/odp_packet_netmap.c index 11954a2..a4236cf 100644 --- a/platform/linux-netmap/odp_packet_netmap.c +++ b/platform/linux-netmap/odp_packet_netmap.c @@ -51,6 +51,7 @@ typedef struct netmap_dev_t { unsigned char if_mac[ETH_ALEN]; odp_ticketlock_t rx_lock; odp_ticketlock_t tx_lock; + int sockfd; } netmap_dev_t; /** Eth buffer start offset from u32-aligned address to make sure the following @@ -97,13 +98,7 @@ static int nm_do_ioctl(pkt_netmap_t * const pkt_nm, unsigned long cmd, struct ethtool_value eval; struct ifreq ifr; int error; - int fd; - - fd = socket(AF_INET, SOCK_DGRAM, 0); - if (fd < 0) { - ODP_ERR("Error: cannot get device control socket\n"); - return -1; - } + int fd = pkt_nm->nm_dev->sockfd; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, pkt_nm->nm_dev->ifname, sizeof(ifr.ifr_name)); @@ -136,7 +131,6 @@ static int nm_do_ioctl(pkt_netmap_t * const pkt_nm, unsigned long cmd, break; } done: - close(fd); if (error) ODP_ERR("ioctl err %d %lu: %s\n", error, cmd, strerror(errno)); @@ -183,6 +177,7 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, { char ifname[IFNAMSIZ]; int i, ret; + int sockfd; if (nm_dev_cnt == MAX_DEVS) { ODP_ERR("Maximum number of devices reached: %d\n", nm_dev_cnt); @@ -248,6 +243,13 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, odp_thread_id(), pkt_nm->desc->mem); + sockfd = socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) { + ODP_ERR("Error: cannot get device control socket\n"); + return -1; + } + pkt_nm->nm_dev->sockfd = sockfd; + ret = nm_do_ioctl(pkt_nm, SIOCGIFFLAGS, 0); if (ret) return ret; @@ -417,3 +419,8 @@ inline void pkt_netmap_mac_addr(pkt_netmap_t * const pkt_nm, void *mac_addr, memcpy(mac_addr, pkt_nm->nm_dev->if_mac, ETH_ALEN); } + +inline int pkt_netmap_sockfd(pkt_netmap_t * const pkt_nm) +{ + return pkt_nm->nm_dev->sockfd; +}