From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id D76C6A052E; Mon, 9 Mar 2020 09:47:03 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 42A661C020; Mon, 9 Mar 2020 09:47:03 +0100 (CET) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by dpdk.org (Postfix) with ESMTP id B9E981C000 for ; Mon, 9 Mar 2020 09:47:01 +0100 (CET) Received: by mail-wr1-f65.google.com with SMTP id r7so9937630wro.2 for ; Mon, 09 Mar 2020 01:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mime-version:content-disposition :content-transfer-encoding:user-agent; bh=gbHP4Bj1KCOiK3xsO0KQ3OkegBTswDE8DUi3mXbMD+k=; b=LKZq0z9NRBu6dQ18stGlNctXhAofDRdi9xLWewu3IkVRMeHdBjIZVD82MfXmTWb0Z0 iS34hrPjzrAWomyIbLLMjzRySMXXSVkK+8khH+R6fy/a4L7A6B2SD3pdevPMwCGrBiRt i9tWSWN3SveTFa+LTOc6m4ujLx07/UQJBEHBKCKm9gdCSkHUO791hmpbv93sPi6CMtWe CqgpqA2eR3FjwUNCoEjWy2favpQ8NvqFBSzoX5FVSzXhFx9BdC6baZKVM7ANM6IRQGM1 fYQwKeBDcPPtT1gTpWnEQeNBoQhsbl8ebIxUc2awpgzz9pVwVgO4mqsNkXI6OAHuAgeY jcdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:content-transfer-encoding:user-agent; bh=gbHP4Bj1KCOiK3xsO0KQ3OkegBTswDE8DUi3mXbMD+k=; b=YJVYoVYAf80I2G5ytbYE0NDR8tFYQKJJoPLP75i/LE5TGVONaHvd1Iu48NEE6opAx1 IQybkijtWtWA/sWp+OTzoiN7LwJ28uoLGrx6GngjkFx0ehkNvt3CD+R14rwMtO8fetBe d3re99qJ5c5xhbmWgankaIWCGSjxPDOPUxD4P0vlnSVyCyfPWEGCq5oIgjXrTYdunxYf 4LnM6rbitn2yD/wwFHoTWCss22cPhFGE/InE1qzTTpxYT9VTKdiafpViNkivPpTyusNp PWSzagKZvIgfYsvUUzoBrFZVMlTvJz8DVEBOMzXrLRJSRzAkNSLbyPJGoW/7g46TEodR 7zqg== X-Gm-Message-State: ANhLgQ3dD6516q68BBH5ECjMigTr9eWZ5mmjwSzwptaGMJ/bIobUlV0H NgM8ONwsVi2X871kLndjWR+Suku+ X-Google-Smtp-Source: ADFU+vvvXtP2luAH56MGX+Sqn9QbG2P9V4kcs9Z76Z1KZXcWX5VvkXcNTny/GjZv/VFFlyA8pljWdQ== X-Received: by 2002:a5d:54ce:: with SMTP id x14mr19402969wrv.353.1583743621040; Mon, 09 Mar 2020 01:47:01 -0700 (PDT) Received: from vbox (81.89.53.154.host.vnet.sk. [81.89.53.154]) by smtp.gmail.com with ESMTPSA id z16sm59103660wrp.33.2020.03.09.01.47.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Mar 2020 01:47:00 -0700 (PDT) Date: Mon, 9 Mar 2020 11:46:59 +0100 From: =?iso-8859-1?Q?J=FAlius?= Milan To: dev@dpdk.org, jgrajcia@cisco.com, ferruh.yigit@intel.com Message-ID: <20200309104659.GA17684@vbox> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.9.4 (2018-02-28) Subject: [dpdk-dev] [PATCH v2 1/2] net/memif: enable loopback X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" With this patch it is possible to connect 2 DPDK memifs into loopback, i.e. when they have the same id and different roles, as for example: "--vdev=net_memif0,role=master,id=0" "--vdev=net_memif1,role=slave,id=0" Signed-off-by: Július Milan --- drivers/net/memif/memif_socket.c | 30 ++++++++++++++---------------- drivers/net/memif/rte_eth_memif.c | 1 + drivers/net/memif/rte_eth_memif.h | 1 + 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/net/memif/memif_socket.c b/drivers/net/memif/memif_socket.c index ad5e30b96..553f8b004 100644 --- a/drivers/net/memif/memif_socket.c +++ b/drivers/net/memif/memif_socket.c @@ -203,7 +203,7 @@ memif_msg_receive_init(struct memif_control_channel *cc, memif_msg_t *msg) dev = elt->dev; pmd = dev->data->dev_private; if (((pmd->flags & ETH_MEMIF_FLAG_DISABLED) == 0) && - pmd->id == i->id) { + (pmd->id == i->id) && (pmd->role == MEMIF_ROLE_MASTER)) { /* assign control channel to device */ cc->dev = dev; pmd->cc = cc; @@ -528,6 +528,7 @@ memif_disconnect(struct rte_eth_dev *dev) pmd->flags &= ~ETH_MEMIF_FLAG_CONNECTING; pmd->flags &= ~ETH_MEMIF_FLAG_CONNECTED; + rte_spinlock_lock(&pmd->cc_lock); if (pmd->cc != NULL) { /* Clear control message queue (except disconnect message if any). */ for (elt = TAILQ_FIRST(&pmd->cc->msg_queue); elt != NULL; elt = next) { @@ -570,6 +571,7 @@ memif_disconnect(struct rte_eth_dev *dev) "Failed to unregister control channel callback."); } } + rte_spinlock_unlock(&pmd->cc_lock); /* unconfig interrupts */ for (i = 0; i < pmd->cfg.num_s2m_rings; i++) { @@ -612,7 +614,8 @@ memif_disconnect(struct rte_eth_dev *dev) /* reset connection configuration */ memset(&pmd->run, 0, sizeof(pmd->run)); - MIF_LOG(DEBUG, "Disconnected."); + MIF_LOG(DEBUG, "Disconnected, id: %d, role: %s.", pmd->id, + (pmd->role == MEMIF_ROLE_MASTER) ? "master" : "slave"); } static int @@ -642,8 +645,12 @@ memif_msg_receive(struct memif_control_channel *cc) size = recvmsg(cc->intr_handle.fd, &mh, 0); if (size != sizeof(memif_msg_t)) { - MIF_LOG(DEBUG, "Invalid message size."); - memif_msg_enq_disconnect(cc, "Invalid message size", 0); + MIF_LOG(DEBUG, "Invalid message size = %zu", size); + if (size > 0) + /* 0 means end-of-file, negative size means error, + * don't send further disconnect message in such cases. + */ + memif_msg_enq_disconnect(cc, "Invalid message size", 0); return -1; } MIF_LOG(DEBUG, "Received msg type: %u.", msg.type); @@ -965,20 +972,11 @@ memif_socket_init(struct rte_eth_dev *dev, const char *socket_filename) } pmd->socket_filename = socket->filename; - if (socket->listener != 0 && pmd->role == MEMIF_ROLE_SLAVE) { - MIF_LOG(ERR, "Socket is a listener."); - return -1; - } else if ((socket->listener == 0) && (pmd->role == MEMIF_ROLE_MASTER)) { - MIF_LOG(ERR, "Socket is not a listener."); - return -1; - } - TAILQ_FOREACH(elt, &socket->dev_queue, next) { tmp_pmd = elt->dev->data->dev_private; - if (tmp_pmd->id == pmd->id) { - MIF_LOG(ERR, "Memif device with id %d already " - "exists on socket %s", - pmd->id, socket->filename); + if (tmp_pmd->id == pmd->id && tmp_pmd->role == pmd->role) { + MIF_LOG(ERR, "Two interfaces with the same id (%d) can " + "not have the same role.", pmd->id); return -1; } } diff --git a/drivers/net/memif/rte_eth_memif.c b/drivers/net/memif/rte_eth_memif.c index 27c0f0924..81d71c53a 100644 --- a/drivers/net/memif/rte_eth_memif.c +++ b/drivers/net/memif/rte_eth_memif.c @@ -1491,6 +1491,7 @@ memif_create(struct rte_vdev_device *vdev, enum memif_role_t role, pmd->cfg.num_m2s_rings = 0; pmd->cfg.pkt_buffer_size = pkt_buffer_size; + rte_spinlock_init(&pmd->cc_lock); data = eth_dev->data; data->dev_private = pmd; diff --git a/drivers/net/memif/rte_eth_memif.h b/drivers/net/memif/rte_eth_memif.h index 0d2566392..6f45b7072 100644 --- a/drivers/net/memif/rte_eth_memif.h +++ b/drivers/net/memif/rte_eth_memif.h @@ -94,6 +94,7 @@ struct pmd_internals { char secret[ETH_MEMIF_SECRET_SIZE]; /**< secret (optional security parameter) */ struct memif_control_channel *cc; /**< control channel */ + rte_spinlock_t cc_lock; /**< control channel lock */ /* remote info */ char remote_name[RTE_DEV_NAME_MAX_LEN]; /**< remote app name */ -- 2.17.1