From patchwork Mon Mar 2 18:46:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 45308 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8E4EC214B5 for ; Mon, 2 Mar 2015 18:48:07 +0000 (UTC) Received: by lbiw7 with SMTP id w7sf25577130lbi.0 for ; Mon, 02 Mar 2015 10:48:06 -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=84qynwTLEB1CtoRjuBNayHrBK7Vy93qlBzcCrYbYLB0=; b=jqrsrxq+x8i8Q1XTYhEZLX1P4gEXqoDL2egsC70+Dt/GgNAmFJYC7H/lBj1vPeu6bf uFovvZVnd4liO7kKgf4P5zXEa5jdITzNmr1XvHAyYi//JQ82BiuNRB5xAhPHyfu5LZSZ R6+MMMJc0/oBwDxGxABEdPIrAfhtFY5BpuP7gbWLCtFTcl9VBbGZGL6BDWLhUfdjaqgC LKaNMQVNd1NYQEmpXcKFaSCSCgxfUJszDI3JIgRITWKE3NT1wpa9fwD2SgxcFsGI8e1c QAMUklVhzLGuZgdBFyi9oTjyD3RPZP1qM5KBZ/Jg8ADf5OLWqSXFs1O5Kgy8uhSawAUX ovwg== X-Gm-Message-State: ALoCoQkKGBDLBTCCGRQhmx+TScO+zLPtj8WQdHk7d77WeUvOBYc6InibDfEmqMywooQ4Pl4O7EjY X-Received: by 10.112.138.202 with SMTP id qs10mr3946131lbb.24.1425322086566; Mon, 02 Mar 2015 10:48:06 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.132 with SMTP id i4ls448343lab.25.gmail; Mon, 02 Mar 2015 10:48:06 -0800 (PST) X-Received: by 10.112.224.3 with SMTP id qy3mr3070417lbc.36.1425322086274; Mon, 02 Mar 2015 10:48:06 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id dm12si9465797lac.82.2015.03.02.10.48.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 10:48:06 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbiv13 with SMTP id v13so13302723lbi.11 for ; Mon, 02 Mar 2015 10:48:06 -0800 (PST) X-Received: by 10.152.1.135 with SMTP id 7mr7831350lam.41.1425322086177; Mon, 02 Mar 2015 10:48:06 -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.35.133 with SMTP id h5csp90212lbj; Mon, 2 Mar 2015 10:48:05 -0800 (PST) X-Received: by 10.140.233.129 with SMTP id e123mr55073164qhc.23.1425322084796; Mon, 02 Mar 2015 10:48:04 -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 j93si9378025qge.78.2015.03.02.10.48.03 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 02 Mar 2015 10:48:04 -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 1YSVNp-0008HT-LY; Mon, 02 Mar 2015 18:48:01 +0000 Received: from mail-la0-f50.google.com ([209.85.215.50]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YSVNB-0008AE-QB for lng-odp@lists.linaro.org; Mon, 02 Mar 2015 18:47:21 +0000 Received: by labgm9 with SMTP id gm9so32386505lab.2 for ; Mon, 02 Mar 2015 10:47:16 -0800 (PST) X-Received: by 10.152.170.233 with SMTP id ap9mr24783081lac.47.1425322036229; Mon, 02 Mar 2015 10:47:16 -0800 (PST) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id i13sm2696725lab.38.2015.03.02.10.47.15 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Mar 2015 10:47:15 -0800 (PST) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Mon, 2 Mar 2015 20:46:54 +0200 Message-Id: <1425322017-14636-10-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1425322017-14636-1-git-send-email-ciprian.barbu@linaro.org> References: <1425322017-14636-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH NETMAP 09/12] linux-netmap: pktio: keep track of opened netmap interfaces 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.217.171 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 Signed-off-by: Ciprian Barbu --- platform/linux-netmap/include/odp_packet_netmap.h | 11 ++++++++- platform/linux-netmap/odp_packet_netmap.c | 30 ++++++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/platform/linux-netmap/include/odp_packet_netmap.h b/platform/linux-netmap/include/odp_packet_netmap.h index d4895ce..89d1a27 100644 --- a/platform/linux-netmap/include/odp_packet_netmap.h +++ b/platform/linux-netmap/include/odp_packet_netmap.h @@ -22,6 +22,15 @@ #define ODP_NETMAP_RING_HW 0 #define ODP_NETMAP_RING_SW 1 + +/* Since we allow more than one thread to open the same device + * this struct uinquely identifies a device so that proper locking + * can be implemented + */ +typedef struct { + char ifname[IFNAMSIZ]; +} netmap_dev_t; + /** Packet socket using netmap mmaped rings for both Rx and Tx */ typedef struct { odp_buffer_pool_t pool; @@ -35,7 +44,7 @@ typedef struct { struct netmap_ring *txring; odp_queue_t tx_access; /* exclusive access to send packets */ uint32_t if_flags; - char ifname[32]; + netmap_dev_t *nm_dev; } pkt_netmap_t; /** diff --git a/platform/linux-netmap/odp_packet_netmap.c b/platform/linux-netmap/odp_packet_netmap.c index 632ae49..9558440 100644 --- a/platform/linux-netmap/odp_packet_netmap.c +++ b/platform/linux-netmap/odp_packet_netmap.c @@ -60,9 +60,14 @@ static struct nm_desc mmap_desc; /** Used to store the mmap address; subsequent calls to nm_open */ static odp_spinlock_t nm_global_lock; +#define MAX_DEVS 32 +static netmap_dev_t netmap_devs[MAX_DEVS]; +static int nm_dev_cnt; + int odp_netmap_init_global(void) { odp_spinlock_init(&nm_global_lock); + memset(netmap_devs, 0, sizeof(netmap_devs)); return 0; } @@ -81,7 +86,7 @@ static int nm_do_ioctl(pkt_netmap_t * const pkt_nm, unsigned long cmd, } memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, pkt_nm->ifname, sizeof(ifr.ifr_name)); + strncpy(ifr.ifr_name, pkt_nm->nm_dev->ifname, sizeof(ifr.ifr_name)); switch (cmd) { case SIOCSIFFLAGS: @@ -125,7 +130,12 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, odp_packet_t pkt; uint8_t *pkt_buf; uint8_t *l2_hdr; - int ret; + int i, ret; + + if (nm_dev_cnt == MAX_DEVS) { + ODP_ERR("Maximum number of devices reached: %d\n", nm_dev_cnt); + return -1; + } if (pool == ODP_BUFFER_POOL_INVALID) return -1; @@ -146,7 +156,6 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, odph_packet_free(pkt); - strncpy(pkt_nm->ifname, netdev, sizeof(pkt_nm->ifname)); snprintf(ifname, sizeof(ifname), "netmap:%s", netdev); odp_spinlock_lock(&nm_global_lock); @@ -170,6 +179,19 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, mmap_desc.mem = pkt_nm->desc->mem; mmap_desc.memsize = pkt_nm->desc->memsize; } + /* Lookup dev */ + for (i = 0; i < nm_dev_cnt; i++) { + if (!strcmp(netmap_devs[i].ifname, netdev)) { + pkt_nm->nm_dev = &netmap_devs[i]; + break; + } + } + if (i == nm_dev_cnt) { + nm_dev_cnt++; + snprintf(netmap_devs[i].ifname, sizeof(netmap_devs[i].ifname), + "%s", netdev); + pkt_nm->nm_dev = &netmap_devs[i]; + } odp_spinlock_unlock(&nm_global_lock); ODP_DBG("[%04d] mmap addr %p\n", @@ -187,7 +209,7 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, if ((pkt_nm->if_flags & IFF_UP) == 0) { ODP_DBG("[%04d] %s is down, bringing up...\n", odp_thread_id(), - pkt_nm->ifname); + pkt_nm->nm_dev->ifname); pkt_nm->if_flags |= IFF_UP; } if (ETH_PROMISC) {