From patchwork Fri Jan 8 20:29:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 59402 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp756482lbb; Fri, 8 Jan 2016 11:50:08 -0800 (PST) X-Received: by 10.140.81.112 with SMTP id e103mr141912874qgd.99.1452282608111; Fri, 08 Jan 2016 11:50:08 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 2si110071198qgi.13.2016.01.08.11.50.07; Fri, 08 Jan 2016 11:50:08 -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 86309616E9; Fri, 8 Jan 2016 19:50:07 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=Idh1bYyI; 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 8CE2561B55; Fri, 8 Jan 2016 19:37:36 +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 2E16961680; Fri, 8 Jan 2016 19:34:32 +0000 (UTC) Received: from mail-lf0-f43.google.com (mail-lf0-f43.google.com [209.85.215.43]) by lists.linaro.org (Postfix) with ESMTPS id DACAC616B9 for ; Fri, 8 Jan 2016 19:31:53 +0000 (UTC) Received: by mail-lf0-f43.google.com with SMTP id d17so15377174lfb.1 for ; Fri, 08 Jan 2016 11:31:53 -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=Wr2M7r1QZpwlG7c3SYb3qy2M6m1kdAyU5u3TJy9ZEcU=; b=Idh1bYyInDQdJLS3Ed9/haCF39X+45QyZYnQsbYp6+89Pu1/3PxsIjXy5XcI3RurVD TTMMMuH0w2QPpQm8FCG6XQVx3NadEVuw3QKSuXUWaMvYPUOC897UxLgCp39ddwYGAptT gUWKEpc0oBsZp0PZfRxvbsMtSSzLuFgoWF8QY= 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=Wr2M7r1QZpwlG7c3SYb3qy2M6m1kdAyU5u3TJy9ZEcU=; b=h0f7zGmXP263eSPAyp42XSoRaHjBjMo8dCFoeEH7XFLhqXIXNsIrLtkydunpn1HbLf nQHr/plOMe9Z1PuBTBIZVqGP2BTVCN6NQNOu7e6Q5HdrlwRrNk+CIWoHSuCp7caK3ARA JA3/86xmYdARg1gIWao5BUzBEJvCEmkyiAD8HQdNWjghe0yL7iR3grmpenKDwJsduaLT jOCMPk0Suq3sQzpidhKCiBQJkbON8BZ0RNsUv39oamUYayoCkXA53sVLqfynGj8Fo9uy 7MEDioc9q1LMm8wEFdckPN39OZacOCgUz55w2GYLAHUES/tOjK7Mra7YCu75O9189wr4 jy8A== X-Gm-Message-State: ALoCoQn0m2ikpLVIRMTh9QEzVvLllmpRh0s8bpjxECv1KnfXUkhrqnYBIInv9rQq3kq8X9jpohwVIfHcYBiK6XKN3ZR22YajrA== X-Received: by 10.25.19.154 with SMTP id 26mr42762107lft.127.1452281512841; Fri, 08 Jan 2016 11:31:52 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id l204sm2085534lfg.49.2016.01.08.11.31.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 11:31:52 -0800 (PST) From: Christophe Milard To: anders.roxell@linaro.org, mike.holmes@linaro.org, stuart.haslam@linaro.org, maxim.uvarov@linaro.org, bill.fischofer@linaro.org, petri.savolainen@linaro.org, edavis@broadcom.com Date: Fri, 8 Jan 2016 21:29:59 +0100 Message-Id: <1452285014-60320-17-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> References: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [API-NEXT RFC 16/31] linux-generic: driver: nic device alloc and free 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" Function to allocate and free a Nic device are added here. The DPDK PMD drivers make use of a shared mem area (dev->data), which is kept here, but some question remains to be answered about its usage (dpdk hash of inspiration: 9702b2b53f250aa50973e6d86abce45b4a919eda) Signed-off-by: Christophe Milard --- platform/linux-generic/include/odp/nic.h | 1 + platform/linux-generic/odp_nic.c | 72 ++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/platform/linux-generic/include/odp/nic.h b/platform/linux-generic/include/odp/nic.h index 7688bee..3b2c950 100644 --- a/platform/linux-generic/include/odp/nic.h +++ b/platform/linux-generic/include/odp/nic.h @@ -22,6 +22,7 @@ extern "C" { #include #include #include +#include /** @ingroup odp_nic * @{ diff --git a/platform/linux-generic/odp_nic.c b/platform/linux-generic/odp_nic.c index 8a4cd43..5faf642 100644 --- a/platform/linux-generic/odp_nic.c +++ b/platform/linux-generic/odp_nic.c @@ -210,3 +210,75 @@ void odp_nic_driver_register(odp_nic_driver_t *drv) else ODP_ERR("Maximum number of drivers exceeded... "); } + +odp_nic_dev_t *odp_nic_dev_alloc(const char *unique_id, int private_sz, + int nb_rxqueues, int nb_txqueues, + odp_pktio_t pktio) +{ + odp_shm_t shm; + odp_nic_dev_t *dev; + + char name[ODP_SHM_NAME_LEN]; + + dev = malloc(sizeof(odp_nic_dev_t)); + + /* allocate memory for data (global to the NIC): */ + /* FIXME: this is a shared mem data struct in DPDK: don't + * fully understand why at this stage as it contains pointers + * ...needs review... */ + snprintf(name, sizeof(name), "ETH_dev_data:%s", unique_id); + shm = odp_shm_lookup(name); + if (shm == ODP_SHM_INVALID) { + shm = odp_shm_reserve(name, + sizeof(odp_nic_dev_data_t), + ODP_CACHE_LINE_SIZE, 0); + } + dev->data = odp_shm_addr(shm); + if (!dev->data) + goto out1; + + dev->data_shm = shm; + + /* 1 port per ethernet device, matching the pktio entry index: */ + dev->data->port_id = _odp_typeval(pktio); + + /* allocate memory for driver private data: */ + dev->data->dev_private = malloc(private_sz); + if (!dev->data->dev_private) + goto out2; + + /* allocate memory for the rx queues: */ + dev->data->rx_queues = malloc(sizeof(dev->data->rx_queues[0]) * + nb_rxqueues); + if (!dev->data->rx_queues) + goto out3; + + /* allocate memory for the tx queues: */ + dev->data->tx_queues = malloc(sizeof(dev->data->tx_queues[0]) + * nb_txqueues); + if (!dev->data->tx_queues) + goto out4; + + dev->data->nb_rx_queues = nb_rxqueues; + dev->data->nb_tx_queues = nb_txqueues; + + return dev; + +out4: + free(dev->data->rx_queues); +out3: + free(dev->data->dev_private); +out2: + if (odp_shm_free(shm) < 0) + ODP_ERR("Shm free failed for ETH_dev_data"); +out1: return NULL; +} + +void odp_nic_dev_free(odp_nic_dev_t *nic_dev) +{ + free(nic_dev->data->tx_queues); + free(nic_dev->data->rx_queues); + free(nic_dev->data->dev_private); + odp_shm_free(nic_dev->data_shm); + free(nic_dev); +}