Page MenuHomeFreeBSD

D21934.diff
No OneTemporary

D21934.diff

Index: head/sys/contrib/ena-com/ena_plat.h
===================================================================
--- head/sys/contrib/ena-com/ena_plat.h
+++ head/sys/contrib/ena-com/ena_plat.h
@@ -103,6 +103,7 @@
#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;
Index: head/sys/dev/ena/ena.c
===================================================================
--- head/sys/dev/ena/ena.c
+++ head/sys/dev/ena/ena.c
@@ -80,6 +80,10 @@
#include "ena.h"
#include "ena_sysctl.h"
+#ifdef DEV_NETMAP
+#include "ena_netmap.h"
+#endif /* DEV_NETMAP */
+
/*********************************************************
* Function prototypes
*********************************************************/
@@ -3317,12 +3321,24 @@
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_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 @@
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 */
/*********************************************************************/
Index: head/sys/dev/ena/ena_netmap.h
===================================================================
--- head/sys/dev/ena/ena_netmap.h
+++ head/sys/dev/ena/ena_netmap.h
@@ -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_ */
Index: head/sys/dev/ena/ena_netmap.c
===================================================================
--- head/sys/dev/ena/ena_netmap.c
+++ head/sys/dev/ena/ena_netmap.c
@@ -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 */
Index: head/sys/modules/ena/Makefile
===================================================================
--- head/sys/modules/ena/Makefile
+++ head/sys/modules/ena/Makefile
@@ -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

File Metadata

Mime Type
text/plain
Expires
Tue, May 19, 2:00 PM (15 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33314734
Default Alt Text
D21934.diff (8 KB)

Event Timeline