From patchwork Fri Jan 8 20:30:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 59403 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp756751lbb; Fri, 8 Jan 2016 11:50:44 -0800 (PST) X-Received: by 10.55.80.131 with SMTP id e125mr70916464qkb.62.1452282642408; Fri, 08 Jan 2016 11:50:42 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t9si101197854qhb.67.2016.01.08.11.50.42; Fri, 08 Jan 2016 11:50:42 -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 E9C59615DC; Fri, 8 Jan 2016 19:50:41 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=FoTQ2d5l; 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 47BB461C83; Fri, 8 Jan 2016 19:37:43 +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 E9CF66195C; Fri, 8 Jan 2016 19:34:48 +0000 (UTC) Received: from mail-lf0-f51.google.com (mail-lf0-f51.google.com [209.85.215.51]) by lists.linaro.org (Postfix) with ESMTPS id 0FB7961B77 for ; Fri, 8 Jan 2016 19:31:55 +0000 (UTC) Received: by mail-lf0-f51.google.com with SMTP id m198so33834698lfm.0 for ; Fri, 08 Jan 2016 11:31:54 -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=VM5XE0zmWKgMFTWdN2JFF1Ck9Ef7cdgJARCjr7ktogA=; b=FoTQ2d5l3cmQIuLOJvhcvqM0vOcwsux0xs7OR/js812iYno++pKFIGHpv3VUXiWbbZ CVi+9+BotbJRwvT4VwCBKP4fyfNoWshw/EqIsI6Ho9B+gvpB5dFcrWANNWrl52+LHUjN Gq39+ukNyZeZnZS52KC0vR2uLLb3B6VzCMioc= 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=VM5XE0zmWKgMFTWdN2JFF1Ck9Ef7cdgJARCjr7ktogA=; b=YotU5uhK6YSBzB87urbkX13ZVmO7nyhptcpxdyNxHDHR1QBxq4jufJ0ry/gzqCpkQW efEw6QXwY/fCBrLLTbTZa2wnzUF1KC7XhuZ1WtdiNh3nieD4QkojBnRt2c690nIGqmNQ dJwRbS9uzaxeWlSszp5bocazfAlJVZXxVS2S6+o/EH6OWvSnKdgEZL4OC7KRVp00eOSE 34P7CzGZ9bccs1CWfQXvUPsvCMyUr7DmfzjHUkCxznDfLW0D0zTgSNAU5pakUvi01TwH 4VU+2NTqjEWg3WqlNDiCiGZ8m22Pm4TGfRaVxox8E0WV88/5fkFLMqdYaDAAe0lQiCuD ZKyg== X-Gm-Message-State: ALoCoQmm/OwvLfUAIxKeLKzwSN5l/2EQ733D7dVDKMoOgYMBc1B/FYRfACPcgKuS9LD1mco6uuKKzy955uB8DX6yq4crNPQYYg== X-Received: by 10.25.212.140 with SMTP id l134mr42087626lfg.118.1452281513986; Fri, 08 Jan 2016 11:31:53 -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.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 11:31:53 -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:30:00 +0100 Message-Id: <1452285014-60320-18-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 17/31] linux-generic: nic pktio 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" A new pktio is created for nic cards. At this stage, only pci-vfio is supported. The interface name format must have the form: pmd::::, for instance "pmd:0000:23:00.0" A linux generic pci_vfio driver must be running on the interface, of course. Signed-off-by: Christophe Milard --- platform/linux-generic/Makefile.am | 2 + platform/linux-generic/include/odp_nic_internal.h | 59 ++++++++++++++++++ .../linux-generic/include/odp_packet_io_internal.h | 1 + platform/linux-generic/odp_nic.c | 58 ++++++++++++++++++ platform/linux-generic/pktio/io_ops.c | 3 + platform/linux-generic/pktio/nic.c | 71 ++++++++++++++++++++++ 6 files changed, 194 insertions(+) create mode 100644 platform/linux-generic/include/odp_nic_internal.h create mode 100644 platform/linux-generic/pktio/nic.c diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index c47bf52..1e323d4 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -107,6 +107,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_forward_typedefs_internal.h \ ${srcdir}/include/odp_internal.h \ ${srcdir}/include/odp_name_table_internal.h \ + ${srcdir}/include/odp_nic_internal.h \ ${srcdir}/include/odp_packet_internal.h \ ${srcdir}/include/odp_packet_io_internal.h \ ${srcdir}/include/odp_packet_io_queue.h \ @@ -155,6 +156,7 @@ __LIB__libodp_la_SOURCES = \ pktio/pktio_common.c \ pktio/loop.c \ pktio/netmap.c \ + pktio/nic.c \ pktio/socket.c \ pktio/socket_mmap.c \ pktio/tap.c \ diff --git a/platform/linux-generic/include/odp_nic_internal.h b/platform/linux-generic/include/odp_nic_internal.h new file mode 100644 index 0000000..4f0f137 --- /dev/null +++ b/platform/linux-generic/include/odp_nic_internal.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2015, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** + * @file + * + * ODP nic driver interface - implementation internal + */ + +#ifndef ODP_NIC_INTERNAL_H_ +#define ODP_NIC_INTERNAL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +/** @addtogroup odp_nic + * @{ + */ + +/* the entries for each nic pktio */ +typedef struct _odp_nic_pktio_tbl_t { + odp_pci_dev_t pci_dev; + odp_nic_dev_t *nic_dev; + odp_nic_sgmt_pool_t tx_sgmt_pool; + odp_nic_sgmt_pool_t rx_sgmt_pool; +} _odp_nic_pktio_tbl_t; + +extern _odp_nic_pktio_tbl_t _odp_nic_pktio_tbl[ODP_CONFIG_PKTIO_ENTRIES]; + +/* +* probe all drivers for the given pci address. stop at the first that +* can handle the NIC +*/ +int driver_probe(odp_pktio_t pktio, const char *pci_address, odp_pool_t pool); + +/* + * unprobe a driver (i.e. release all resources allocated by a successful + * probe) + */ +void driver_unprobe(pktio_entry_t *pktio_entry); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 4fd3c87..96e08e0 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -210,6 +210,7 @@ int single_send_queue(pktio_entry_t *entry, int index, odp_packet_t packets[], int num); extern const pktio_if_ops_t netmap_pktio_ops; +extern const pktio_if_ops_t nic_pktio_ops; extern const pktio_if_ops_t sock_mmsg_pktio_ops; extern const pktio_if_ops_t sock_mmap_pktio_ops; extern const pktio_if_ops_t loopback_pktio_ops; diff --git a/platform/linux-generic/odp_nic.c b/platform/linux-generic/odp_nic.c index 5faf642..e28d98c 100644 --- a/platform/linux-generic/odp_nic.c +++ b/platform/linux-generic/odp_nic.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #ifdef WITH_DRIVERS @@ -15,6 +17,8 @@ odp_spinlock_t drv_registration_mutex; +_odp_nic_pktio_tbl_t _odp_nic_pktio_tbl[ODP_CONFIG_PKTIO_ENTRIES]; + /* * registered drivers: * Because at registration time, drivers give function pointers (whose @@ -282,3 +286,57 @@ void odp_nic_dev_free(odp_nic_dev_t *nic_dev) odp_shm_free(nic_dev->data_shm); free(nic_dev); } + +int driver_probe(odp_pktio_t pktio, const char *pci_address, odp_pool_t pool) +{ + int i; + + odp_nic_sgmt_pool_t tx_sgmt_pool; + odp_nic_sgmt_pool_t rx_sgmt_pool; + odp_nic_dev_t *nic_dev; + odp_pci_dev_t pci_dev; + _odp_nic_pktio_tbl_t *nic_entry; + + /* init the PCI device: */ + pci_dev = _odp_pci_init(pci_address); + if (pci_dev == ODP_PCI_DEV_INVALID) + return -1; + + rx_sgmt_pool = odp_nic_sgmt_pool_create(pool); + tx_sgmt_pool = odp_nic_sgmt_pool_create(ODP_POOL_ALL_PKTS); + for (i = 0; i < registered_drv.nb_drivers; i++) { + nic_dev = registered_drv.drivers[i].probe(pci_dev, pktio, + rx_sgmt_pool, + tx_sgmt_pool); + if (nic_dev) { + nic_entry = &_odp_nic_pktio_tbl[_odp_typeval(pktio)]; + nic_entry->nic_dev = nic_dev; + nic_entry->pci_dev = pci_dev; + nic_entry->tx_sgmt_pool = tx_sgmt_pool; + nic_entry->rx_sgmt_pool = rx_sgmt_pool; + return 0; + } + } + odp_nic_sgmt_pool_destroy(tx_sgmt_pool); + odp_nic_sgmt_pool_destroy(rx_sgmt_pool); + _odp_pci_release(pci_dev); + return -1; +} + +void driver_unprobe(pktio_entry_t *pktio_entry) +{ + _odp_nic_pktio_tbl_t *nic_entry; + odp_nic_dev_t *nic_dev; + odp_pci_dev_t pci_dev; + odp_pktio_t pktio; + + pktio = pktio_entry->s.handle; + nic_entry = &_odp_nic_pktio_tbl[_odp_typeval(pktio)]; + nic_dev = nic_entry->nic_dev; + pci_dev = nic_entry->pci_dev; + nic_dev->dev_ops->unprobe(pci_dev, nic_dev); + + odp_nic_sgmt_pool_destroy(nic_entry->tx_sgmt_pool); + odp_nic_sgmt_pool_destroy(nic_entry->rx_sgmt_pool); + _odp_pci_release(pci_dev); +} diff --git a/platform/linux-generic/pktio/io_ops.c b/platform/linux-generic/pktio/io_ops.c index 1933abc..ffb0251 100644 --- a/platform/linux-generic/pktio/io_ops.c +++ b/platform/linux-generic/pktio/io_ops.c @@ -12,6 +12,9 @@ * Array must be NULL terminated */ const pktio_if_ops_t * const pktio_if_ops[] = { &loopback_pktio_ops, +#ifdef WITH_DRIVERS + &nic_pktio_ops, +#endif #ifdef ODP_NETMAP &netmap_pktio_ops, #endif diff --git a/platform/linux-generic/pktio/nic.c b/platform/linux-generic/pktio/nic.c new file mode 100644 index 0000000..1df93e1 --- /dev/null +++ b/platform/linux-generic/pktio/nic.c @@ -0,0 +1,71 @@ +/* Copyright (c) 2015, Linaro Limited + * Copyright (c) 2015, Nokia Solutions and Networks + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include +#include + +/* + * parse the device name for something like "pmd:" + * returns a pointer to the pci address on success or NULL if no match + */ + +static const char *parse_devname(const char *devname) +{ + if (strncmp(devname, "pmd:", 4) != 0) + return NULL; + + /*FIXME check for complete pci address format */ + return &devname[4]; +} + +static int nic_open(odp_pktio_t pktio, + pktio_entry_t *pktio_entry ODP_UNUSED, + const char *devname, odp_pool_t pool) +{ + /* check if devname has the form "pmd:" */ + const char *pci_address = parse_devname(devname); + + if (!pci_address) + return -1; + + if (driver_probe(pktio, pci_address, pool)) + return -1; + + return 0; +} + +static int nic_close(pktio_entry_t *entry) +{ + driver_unprobe(entry); + return 0; +} + +const pktio_if_ops_t nic_pktio_ops = { + .name = "Nic", + .init = NULL, + .term = NULL, + .open = nic_open, + .close = nic_close, + .start = NULL, + .stop = NULL, + .recv = NULL, + .send = NULL, + .mtu_get = NULL, + .promisc_mode_set = NULL, + .promisc_mode_get = NULL, + .mac_get = NULL, + .capability = NULL, + .input_queues_config = NULL, + .output_queues_config = NULL, + .in_queues = NULL, + .pktin_queues = NULL, + .pktout_queues = NULL, + .recv_queue = NULL, + .send_queue = NULL +};