Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys make ena(4) compile, with best efford exercised to conve...
details: https://anonhg.NetBSD.org/src/rev/ef4756c81406
branches: trunk
changeset: 319948:ef4756c81406
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Sat Jun 16 15:00:35 2018 +0000
description:
make ena(4) compile, with best efford exercised to convert code to NetBSD
equivalents; where possible left the original code intact to make it
easier to compare against FreeBSD original
made non-working stubs for some functions which don't have direct
equivalent yet - this includes all of <sys/buf_ring.h>, m_getjcl(),
m_append, and m_collapse(); these need to be adressed
left XXX/TODO in if_enavar.h, colocated with the non-working stubs
diffstat:
sys/dev/pci/if_ena.c | 926 ++++++++++++++++++-----------------
sys/dev/pci/if_enavar.h | 129 ++++-
sys/external/bsd/ena-com/ena_plat.h | 4 +-
3 files changed, 586 insertions(+), 473 deletions(-)
diffs (truncated from 2067 to 300 lines):
diff -r da0537986387 -r ef4756c81406 sys/dev/pci/if_ena.c
--- a/sys/dev/pci/if_ena.c Sat Jun 16 14:41:25 2018 +0000
+++ b/sys/dev/pci/if_ena.c Sat Jun 16 15:00:35 2018 +0000
@@ -31,7 +31,7 @@
#if 0
__FBSDID("$FreeBSD: head/sys/dev/ena/ena.c 333456 2018-05-10 09:37:54Z mw $");
#endif
-__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.3 2018/06/01 09:34:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.4 2018/06/16 15:00:35 jdolecek Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -47,31 +47,37 @@
#include <sys/sysctl.h>
#include <sys/time.h>
#include <sys/workqueue.h>
+#include <sys/callout.h>
+#include <sys/interrupt.h>
+#include <sys/cpu.h>
#include <sys/bus.h>
+#include <net/if_ether.h>
+#include <net/if_vlanvar.h>
+
#include <dev/pci/if_enavar.h>
/*********************************************************
* Function prototypes
*********************************************************/
static int ena_probe(device_t, cfdata_t, void *);
-static void ena_intr_msix_mgmnt(void *);
-static int ena_allocate_pci_resources(struct ena_adapter*);
+static int ena_intr_msix_mgmnt(void *);
+static int ena_allocate_pci_resources(struct pci_attach_args *,
+ struct ena_adapter *);
static void ena_free_pci_resources(struct ena_adapter *);
static int ena_change_mtu(struct ifnet *, int);
-static inline void ena_alloc_counters(struct evcnt *, int);
-static inline void ena_free_counters(struct evcnt *, int);
-static inline void ena_reset_counters(struct evcnt *, int);
static void ena_init_io_rings_common(struct ena_adapter *,
struct ena_ring *, uint16_t);
static void ena_init_io_rings(struct ena_adapter *);
static void ena_free_io_ring_resources(struct ena_adapter *, unsigned int);
static void ena_free_all_io_rings_resources(struct ena_adapter *);
+#if 0
static int ena_setup_tx_dma_tag(struct ena_adapter *);
static int ena_free_tx_dma_tag(struct ena_adapter *);
static int ena_setup_rx_dma_tag(struct ena_adapter *);
static int ena_free_rx_dma_tag(struct ena_adapter *);
+#endif
static int ena_setup_tx_resources(struct ena_adapter *, int);
static void ena_free_tx_resources(struct ena_adapter *, int);
static int ena_setup_all_tx_resources(struct ena_adapter *);
@@ -96,19 +102,19 @@
static void ena_destroy_all_io_queues(struct ena_adapter *);
static int ena_create_io_queues(struct ena_adapter *);
static int ena_tx_cleanup(struct ena_ring *);
-static void ena_deferred_rx_cleanup(void *, int);
+static void ena_deferred_rx_cleanup(struct work *, void *);
static int ena_rx_cleanup(struct ena_ring *);
static inline int validate_tx_req_id(struct ena_ring *, uint16_t);
+#if 0
static void ena_rx_hash_mbuf(struct ena_ring *, struct ena_com_rx_ctx *,
struct mbuf *);
+#endif
static struct mbuf* ena_rx_mbuf(struct ena_ring *, struct ena_com_rx_buf_info *,
struct ena_com_rx_ctx *, uint16_t *);
static inline void ena_rx_checksum(struct ena_ring *, struct ena_com_rx_ctx *,
struct mbuf *);
-static void ena_handle_msix(void *);
+static int ena_handle_msix(void *);
static int ena_enable_msix(struct ena_adapter *);
-static void ena_setup_mgmnt_intr(struct ena_adapter *);
-static void ena_setup_io_intr(struct ena_adapter *);
static int ena_request_mgmnt_irq(struct ena_adapter *);
static int ena_request_io_irq(struct ena_adapter *);
static void ena_free_mgmnt_irq(struct ena_adapter *);
@@ -125,7 +131,7 @@
#endif
static int ena_media_change(struct ifnet *);
static void ena_media_status(struct ifnet *, struct ifmediareq *);
-static void ena_init(void *);
+static int ena_init(struct ifnet *);
static int ena_ioctl(struct ifnet *, u_long, void *);
static int ena_get_dev_offloads(struct ena_com_dev_get_features_ctx *);
static void ena_update_host_info(struct ena_admin_host_info *, struct ifnet *);
@@ -138,17 +144,21 @@
static int ena_xmit_mbuf(struct ena_ring *, struct mbuf **);
static void ena_start_xmit(struct ena_ring *);
static int ena_mq_start(struct ifnet *, struct mbuf *);
-static void ena_deferred_mq_start(void *, int);
+static void ena_deferred_mq_start(struct work *, void *);
+#if 0
static void ena_qflush(struct ifnet *);
-static int ena_calc_io_queue_num(struct ena_adapter *,
- struct ena_com_dev_get_features_ctx *);
+#endif
+static int ena_calc_io_queue_num(struct pci_attach_args *,
+ struct ena_adapter *, struct ena_com_dev_get_features_ctx *);
static int ena_calc_queue_size(struct ena_adapter *, uint16_t *,
uint16_t *, struct ena_com_dev_get_features_ctx *);
+#if 0
static int ena_rss_init_default(struct ena_adapter *);
static void ena_rss_init_default_deferred(void *);
+#endif
static void ena_config_host_info(struct ena_com_dev *);
-static int ena_attach(device_t parent, device_t self, void *aux);
-static int ena_detach(device_t);
+static void ena_attach(device_t, device_t, void *);
+static int ena_detach(device_t, int);
static int ena_device_init(struct ena_adapter *, device_t,
struct ena_com_dev_get_features_ctx *, int *);
static int ena_enable_msix_and_set_admin_interrupts(struct ena_adapter *,
@@ -217,8 +227,8 @@
dma->tag = adapter->sc_dmat;
- if (bus_dmamap_create(dma->tag, maxsize, 1, maxsize, 0,
- BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW, &dma->map) != 0) {
+ if ((error = bus_dmamap_create(dma->tag, maxsize, 1, maxsize, 0,
+ BUS_DMA_WAITOK | BUS_DMA_ALLOCNOW, &dma->map)) != 0) {
ena_trace(ENA_ALERT, "bus_dmamap_create(%ju) failed: %d\n",
(uintmax_t)maxsize, error);
goto fail_create;
@@ -262,19 +272,19 @@
}
static int
-ena_allocate_pci_resources(struct ena_adapter* adapter)
+ena_allocate_pci_resources(struct pci_attach_args *pa,
+ struct ena_adapter *adapter)
{
- device_t pdev = adapter->pdev;
- int rid;
-
- rid = PCIR_BAR(ENA_REG_BAR);
- adapter->memory = NULL;
- adapter->registers = bus_alloc_resource_any(pdev, SYS_RES_MEMORY,
- &rid, RF_ACTIVE);
- if (unlikely(adapter->registers == NULL)) {
- device_printf(pdev, "Unable to allocate bus resource: "
- "registers\n");
- return (ENXIO);
+ bus_size_t size;
+
+ /*
+ * Map control/status registers.
+ */
+ pcireg_t memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, ENA_REG_BAR);
+ if (pci_mapreg_map(pa, ENA_REG_BAR, memtype, 0, &adapter->sc_btag,
+ &adapter->sc_bhandle, NULL, &size)) {
+ aprint_error(": can't map mem space\n");
+ return ENXIO;
}
return (0);
@@ -283,17 +293,7 @@
static void
ena_free_pci_resources(struct ena_adapter *adapter)
{
- device_t pdev = adapter->pdev;
-
- if (adapter->memory != NULL) {
- bus_release_resource(pdev, SYS_RES_MEMORY,
- PCIR_BAR(ENA_MEM_BAR), adapter->memory);
- }
-
- if (adapter->registers != NULL) {
- bus_release_resource(pdev, SYS_RES_MEMORY,
- PCIR_BAR(ENA_REG_BAR), adapter->registers);
- }
+ /* Nothing to do */
}
static int
@@ -339,16 +339,84 @@
return (rc);
}
+#define EVCNT_INIT(st, f) \
+ do { \
+ evcnt_attach_dynamic(&st->f, EVCNT_TYPE_MISC, NULL, \
+ st->name, #f); \
+ } while (0)
+
static inline void
-ena_alloc_counters(struct evcnt *begin, int size)
+ena_alloc_counters_rx(struct ena_stats_rx *st, int queue)
+{
+ snprintf(st->name, sizeof(st->name), "ena rxq%d", queue);
+
+ EVCNT_INIT(st, cnt);
+ EVCNT_INIT(st, bytes);
+ EVCNT_INIT(st, refil_partial);
+ EVCNT_INIT(st, bad_csum);
+ EVCNT_INIT(st, mjum_alloc_fail);
+ EVCNT_INIT(st, mbuf_alloc_fail);
+ EVCNT_INIT(st, dma_mapping_err);
+ EVCNT_INIT(st, bad_desc_num);
+ EVCNT_INIT(st, bad_req_id);
+ EVCNT_INIT(st, empty_rx_ring);
+
+ /* Make sure all code is updated when new fields added */
+ CTASSERT(offsetof(struct ena_stats_rx, empty_rx_ring)
+ + sizeof(st->empty_rx_ring) == sizeof(*st));
+}
+
+static inline void
+ena_alloc_counters_tx(struct ena_stats_tx *st, int queue)
{
- struct evcnt *end = (struct evcnt *)((char *)begin + size);
-
- for (; begin < end; ++begin)
- *begin = counter_u64_alloc(M_WAITOK);
+ snprintf(st->name, sizeof(st->name), "ena txq%d", queue);
+
+ EVCNT_INIT(st, cnt);
+ EVCNT_INIT(st, bytes);
+ EVCNT_INIT(st, prepare_ctx_err);
+ EVCNT_INIT(st, dma_mapping_err);
+ EVCNT_INIT(st, doorbells);
+ EVCNT_INIT(st, missing_tx_comp);
+ EVCNT_INIT(st, bad_req_id);
+ EVCNT_INIT(st, collapse);
+ EVCNT_INIT(st, collapse_err);
+
+ /* Make sure all code is updated when new fields added */
+ CTASSERT(offsetof(struct ena_stats_tx, collapse_err)
+ + sizeof(st->collapse_err) == sizeof(*st));
}
static inline void
+ena_alloc_counters_dev(struct ena_stats_dev *st, int queue)
+{
+ snprintf(st->name, sizeof(st->name), "ena dev ioq%d", queue);
+
+ EVCNT_INIT(st, wd_expired);
+ EVCNT_INIT(st, interface_up);
+ EVCNT_INIT(st, interface_down);
+ EVCNT_INIT(st, admin_q_pause);
+
+ /* Make sure all code is updated when new fields added */
+ CTASSERT(offsetof(struct ena_stats_dev, admin_q_pause)
+ + sizeof(st->admin_q_pause) == sizeof(*st));
+}
+
+static inline void
+ena_alloc_counters_hwstats(struct ena_hw_stats *st, int queue)
+{
+ snprintf(st->name, sizeof(st->name), "ena hw ioq%d", queue);
+
+ EVCNT_INIT(st, rx_packets);
+ EVCNT_INIT(st, tx_packets);
+ EVCNT_INIT(st, rx_bytes);
+ EVCNT_INIT(st, tx_bytes);
+ EVCNT_INIT(st, rx_drops);
+
+ /* Make sure all code is updated when new fields added */
+ CTASSERT(offsetof(struct ena_hw_stats, rx_drops)
+ + sizeof(st->rx_drops) == sizeof(*st));
+}
+static inline void
ena_free_counters(struct evcnt *begin, int size)
{
struct evcnt *end = (struct evcnt *)((char *)begin + size);
@@ -406,8 +474,7 @@
M_WAITOK, &txr->ring_mtx);
/* Alloc TX statistics. */
- ena_alloc_counters((struct evcnt *)&txr->tx_stats,
- sizeof(txr->tx_stats));
+ ena_alloc_counters_tx(&txr->tx_stats, i);
/* RX specific ring state */
rxr->ring_size = adapter->rx_ring_size;
@@ -415,8 +482,7 @@
ena_com_get_nonadaptive_moderation_interval_rx(ena_dev);
/* Alloc RX statistics. */
- ena_alloc_counters((struct evcnt *)&rxr->rx_stats,
- sizeof(rxr->rx_stats));
+ ena_alloc_counters_rx(&rxr->rx_stats, i);
/* Initialize locks */
snprintf(txr->mtx_name, sizeof(txr->mtx_name), "%s:tx(%d)",
@@ -563,7 +629,9 @@
/* ... and create the buffer DMA maps */
for (i = 0; i < tx_ring->ring_size; i++) {
- err = bus_dmamap_create(adapter->sc_dmat, 0,
+ err = bus_dmamap_create(adapter->sc_dmat,
+ ENA_TSO_MAXSIZE, adapter->max_tx_sgl_size - 1,
+ ENA_TSO_MAXSIZE, 0, 0,
&tx_ring->tx_buffer_info[i].map);
if (unlikely(err != 0)) {
ena_trace(ENA_ALERT,
@@ -572,17 +640,17 @@
}
Home |
Main Index |
Thread Index |
Old Index