svn commit: r354221 - in head/sys: contrib/ena-com dev/ena modules/ena
Marcin Wojtas
mw at FreeBSD.org
Thu Oct 31 15:51:20 UTC 2019
Author: mw
Date: Thu Oct 31 15:51:18 2019
New Revision: 354221
URL: https://svnweb.freebsd.org/changeset/base/354221
Log:
Introduce NETMAP support in ENA
Mock implementation of NETMAP routines is located in ena_netmap.c/.h
files. All code is protected under the DEV_NETMAP macro. Makefile was
updated with files and flag.
As ENA driver provide own implementations of (un)likely it must be
undefined before including NETMAP headers.
ena_netmap_attach function is called on the end of NIC attach. It fills
structure with NIC configuration and callbacks. Then provides it to
netmap_attach. Similarly netmap_detach is called during ena_detach.
Three callbacks are used.
nm_register is implemented by ena_netmap_reg. It is called when user
space application open or close NIC in NETMAP mode. Current action is
recognized based on onoff parameter: true means on and false off. As
NICs rings need to be reconfigured ena_down and ena_up are reused.
When user space application wants to receive new packets from NIC
nm_rxsync is called, and when there are new packets ready for Tx
nm_txsync is called.
Differential Revision: https://reviews.freebsd.org/D21934
Submitted by: Rafal Kozik <rk at semihalf.com>
Michal Krawczyk <mk at semihalf.com>
Obtained from: Semihalf
Sponsored by: Amazon, Inc.
Added:
head/sys/dev/ena/ena_netmap.c (contents, props changed)
head/sys/dev/ena/ena_netmap.h (contents, props changed)
Modified:
head/sys/contrib/ena-com/ena_plat.h
head/sys/dev/ena/ena.c
head/sys/modules/ena/Makefile
Modified: head/sys/contrib/ena-com/ena_plat.h
==============================================================================
--- head/sys/contrib/ena-com/ena_plat.h Thu Oct 31 15:44:26 2019 (r354220)
+++ head/sys/contrib/ena-com/ena_plat.h Thu Oct 31 15:51:18 2019 (r354221)
@@ -103,6 +103,7 @@ extern struct ena_bus_space ebs;
#define ENA_RSC (1 << 6) /* Goes with TXPTH or RXPTH, free/alloc res. */
#define ENA_IOQ (1 << 7) /* Detailed info about IO queues. */
#define ENA_ADMQ (1 << 8) /* Detailed info about admin queue. */
+#define ENA_NETMAP (1 << 9) /* Detailed info about netmap. */
extern int ena_log_level;
Modified: head/sys/dev/ena/ena.c
==============================================================================
--- head/sys/dev/ena/ena.c Thu Oct 31 15:44:26 2019 (r354220)
+++ head/sys/dev/ena/ena.c Thu Oct 31 15:51:18 2019 (r354221)
@@ -80,6 +80,10 @@ __FBSDID("$FreeBSD$");
#include "ena.h"
#include "ena_sysctl.h"
+#ifdef DEV_NETMAP
+#include "ena_netmap.h"
+#endif /* DEV_NETMAP */
+
/*********************************************************
* Function prototypes
*********************************************************/
@@ -3317,12 +3321,24 @@ ena_attach(device_t pdev)
sizeof(struct ena_hw_stats));
ena_sysctl_add_nodes(adapter);
+#ifdef DEV_NETMAP
+ rc = ena_netmap_attach(adapter);
+ if (rc != 0) {
+ device_printf(pdev, "netmap attach failed: %d\n", rc);
+ goto err_detach;
+ }
+#endif /* DEV_NETMAP */
+
/* Tell the stack that the interface is not active */
if_setdrvflagbits(adapter->ifp, IFF_DRV_OACTIVE, IFF_DRV_RUNNING);
ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEVICE_RUNNING, adapter);
return (0);
+#ifdef DEV_NETMAP
+err_detach:
+ ether_ifdetach(adapter->ifp);
+#endif /* DEV_NETMAP */
err_msix_free:
ena_com_dev_reset(adapter->ena_dev, ENA_REGS_RESET_INIT_ERR);
ena_free_mgmnt_irq(adapter);
@@ -3378,6 +3394,10 @@ ena_detach(device_t pdev)
ena_destroy_device(adapter, true);
sx_unlock(&adapter->ioctl_sx);
+#ifdef DEV_NETMAP
+ netmap_detach(adapter->ifp);
+#endif /* DEV_NETMAP */
+
ena_free_all_io_rings_resources(adapter);
ena_free_counters((counter_u64_t *)&adapter->hw_stats,
@@ -3518,5 +3538,8 @@ MODULE_PNP_INFO("U16:vendor;U16:device", pci, ena, ena
nitems(ena_vendor_info_array) - 1);
MODULE_DEPEND(ena, pci, 1, 1, 1);
MODULE_DEPEND(ena, ether, 1, 1, 1);
+#ifdef DEV_NETMAP
+MODULE_DEPEND(ena, netmap, 1, 1, 1);
+#endif /* DEV_NETMAP */
/*********************************************************************/
Added: head/sys/dev/ena/ena_netmap.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/sys/dev/ena/ena_netmap.c Thu Oct 31 15:51:18 2019 (r354221)
@@ -0,0 +1,111 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#ifdef DEV_NETMAP
+
+#include "ena.h"
+#include "ena_netmap.h"
+
+static int ena_netmap_reg(struct netmap_adapter *, int);
+static int ena_netmap_txsync(struct netmap_kring *, int);
+static int ena_netmap_rxsync(struct netmap_kring *, int);
+
+int
+ena_netmap_attach(struct ena_adapter *adapter)
+{
+ struct netmap_adapter na;
+
+ ena_trace(ENA_NETMAP, "netmap attach\n");
+
+ bzero(&na, sizeof(na));
+ na.na_flags = NAF_MOREFRAG;
+ na.ifp = adapter->ifp;
+ na.num_tx_desc = adapter->tx_ring_size;
+ na.num_rx_desc = adapter->rx_ring_size;
+ na.num_tx_rings = adapter->num_queues;
+ na.num_rx_rings = adapter->num_queues;
+ na.rx_buf_maxsize = adapter->buf_ring_size;
+ na.nm_txsync = ena_netmap_txsync;
+ na.nm_rxsync = ena_netmap_rxsync;
+ na.nm_register = ena_netmap_reg;
+
+ return (netmap_attach(&na));
+}
+
+static int
+ena_netmap_reg(struct netmap_adapter *na, int onoff)
+{
+ struct ifnet *ifp = na->ifp;
+ struct ena_adapter* adapter = ifp->if_softc;
+ int rc;
+
+ sx_xlock(&adapter->ioctl_sx);
+ ENA_FLAG_CLEAR_ATOMIC(ENA_FLAG_TRIGGER_RESET, adapter);
+ ena_down(adapter);
+
+ if (onoff) {
+ ena_trace(ENA_NETMAP, "netmap on\n");
+ nm_set_native_flags(na);
+ } else {
+ ena_trace(ENA_NETMAP, "netmap off\n");
+ nm_clear_native_flags(na);
+ }
+
+ rc = ena_up(adapter);
+ if (rc != 0) {
+ ena_trace(ENA_WARNING, "ena_up failed with rc=%d\n", rc);
+ adapter->reset_reason = ENA_REGS_RESET_DRIVER_INVALID_STATE;
+ nm_clear_native_flags(na);
+ ena_destroy_device(adapter, false);
+ ENA_FLAG_SET_ATOMIC(ENA_FLAG_DEV_UP_BEFORE_RESET, adapter);
+ rc = ena_restore_device(adapter);
+ }
+ sx_unlock(&adapter->ioctl_sx);
+
+ return (rc);
+}
+
+static int
+ena_netmap_txsync(struct netmap_kring *kring, int flags)
+{
+ ena_trace(ENA_NETMAP, "netmap txsync\n");
+ return (0);
+}
+
+static int
+ena_netmap_rxsync(struct netmap_kring *kring, int flags)
+{
+ ena_trace(ENA_NETMAP, "netmap rxsync\n");
+ return (0);
+}
+
+#endif /* DEV_NETMAP */
Added: head/sys/dev/ena/ena_netmap.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/sys/dev/ena/ena_netmap.h Thu Oct 31 15:51:18 2019 (r354221)
@@ -0,0 +1,51 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright (c) 2015-2019 Amazon.com, Inc. or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ *
+ */
+
+#ifndef _ENA_NETMAP_H_
+#define _ENA_NETMAP_H_
+
+/* Undef (un)likely as they are defined in netmap_kern.h */
+#ifdef likely
+#undef likely
+#endif /* likely */
+#ifdef unlikely
+#undef unlikely
+#endif /* unlikely */
+
+#include <net/netmap.h>
+#include <sys/selinfo.h>
+#include <dev/netmap/netmap_kern.h>
+
+int ena_netmap_attach(struct ena_adapter *);
+
+#endif /* _ENA_NETMAP_H_ */
Modified: head/sys/modules/ena/Makefile
==============================================================================
--- head/sys/modules/ena/Makefile Thu Oct 31 15:44:26 2019 (r354220)
+++ head/sys/modules/ena/Makefile Thu Oct 31 15:51:18 2019 (r354221)
@@ -34,7 +34,8 @@
${SRCTOP}/sys/contrib/ena-com
KMOD = if_ena
-SRCS = ena.c ena_com.c ena_eth_com.c ena_sysctl.c ena_datapath.c
+SRCS = ena_com.c ena_eth_com.c
+SRCS += ena.c ena_sysctl.c ena_datapath.c ena_netmap.c
SRCS += device_if.h bus_if.h pci_if.h
CFLAGS += -I${SRCTOP}/sys/contrib
More information about the svn-src-all
mailing list