Module Name:    src
Committed By:   jmcneill
Date:           Fri Nov 30 14:07:30 UTC 2018

Modified Files:
        src/sys/dev/pci: if_ena.c if_enavar.h

Log Message:
Get this driver into a functional state.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/pci/if_ena.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/pci/if_enavar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_ena.c
diff -u src/sys/dev/pci/if_ena.c:1.10 src/sys/dev/pci/if_ena.c:1.11
--- src/sys/dev/pci/if_ena.c:1.10	Fri Nov 30 11:37:11 2018
+++ src/sys/dev/pci/if_ena.c	Fri Nov 30 14:07:30 2018
@@ -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.10 2018/11/30 11:37:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.11 2018/11/30 14:07:30 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1670,9 +1670,7 @@ ena_rx_cleanup(struct ena_ring *rx_ring)
 	uint16_t next_to_clean;
 	uint32_t refill_required;
 	uint32_t refill_threshold;
-#ifdef LRO
 	uint32_t do_if_input = 0;
-#endif
 	unsigned int qid;
 	int rc, i;
 	int budget = RX_BUDGET;
@@ -1735,12 +1733,12 @@ ena_rx_cleanup(struct ena_ring *rx_ring)
 		counter_u64_add_protected(adapter->hw_stats.rx_bytes,
 		    mbuf->m_pkthdr.len);
 		counter_exit();
-#ifdef LRO
 		/*
 		 * LRO is only for IP/TCP packets and TCP checksum of the packet
 		 * should be computed by hardware.
 		 */
 		do_if_input = 1;
+#ifdef LRO
 		if (((ifp->if_capenable & IFCAP_LRO) != 0)  &&
 		    ((mbuf->m_pkthdr.csum_flags & CSUM_IP_VALID) != 0) &&
 		    (ena_rx_ctx.l4_proto == ENA_ETH_IO_L4_PROTO_TCP)) {
@@ -1754,12 +1752,12 @@ ena_rx_cleanup(struct ena_ring *rx_ring)
 			    (tcp_lro_rx(&rx_ring->lro, mbuf, 0) == 0))
 					do_if_input = 0;
 		}
+#endif
 		if (do_if_input != 0) {
 			ena_trace(ENA_DBG | ENA_RXPTH,
 			    "calling if_input() with mbuf %p", mbuf);
-			(*ifp->if_input)(ifp, mbuf);
+			if_percpuq_enqueue(ifp->if_percpuq, mbuf);
 		}
-#endif
 
 		counter_enter();
 		counter_u64_add_protected(rx_ring->rx_stats.cnt, 1);
@@ -2500,7 +2498,7 @@ ena_setup_ifnet(device_t pdev, struct en
 		ena_trace(ENA_ALERT, "can not allocate ifnet structure\n");
 		return (ENXIO);
 	}
-	if_initname(ifp, device_xname(pdev), device_unit(pdev));
+	if_initname(ifp, "ena", device_unit(pdev));
 	if_setdev(ifp, pdev);
 	if_setsoftc(ifp, adapter);
 

Index: src/sys/dev/pci/if_enavar.h
diff -u src/sys/dev/pci/if_enavar.h:1.5 src/sys/dev/pci/if_enavar.h:1.6
--- src/sys/dev/pci/if_enavar.h:1.5	Wed Nov 28 19:06:54 2018
+++ src/sys/dev/pci/if_enavar.h	Fri Nov 30 14:07:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_enavar.h,v 1.5 2018/11/28 19:06:54 jmcneill Exp $	*/
+/*	$NetBSD: if_enavar.h,v 1.6 2018/11/30 14:07:30 jmcneill Exp $	*/
 
 /*-
  * BSD LICENSE
@@ -273,6 +273,7 @@ struct ena_ring {
 			struct workqueue *cmpl_tq;
 		};
 	};
+	u_int task_pending;
 
 	union {
 		struct ena_stats_tx tx_stats;
@@ -472,16 +473,71 @@ getsbinuptime(void)
  */
 #define buf_ring_alloc(a, b, c, d)	(void *)&a
 #define drbr_free(ifp, b)		do { } while (0)
-#define drbr_flush(ifp, b)		do { } while (0)
-#define drbr_advance(ifp, b)		do { } while (0)
+#define drbr_flush(ifp, b)		IFQ_PURGE(&(ifp)->if_snd)
+#define drbr_advance(ifp, b)					\
+	({							\
+		struct mbuf *__m;				\
+		IFQ_DEQUEUE(&(ifp)->if_snd, __m);		\
+		__m;						\
+	})
 #define drbr_putback(ifp, b, m)		do { } while (0)
-#define drbr_empty(ifp, b)		false
-#define drbr_peek(ifp, b)		NULL
-#define drbr_enqueue(ifp, b, m)		0
+#define drbr_empty(ifp, b)		IFQ_IS_EMPTY(&(ifp)->if_snd)
+#define drbr_peek(ifp, b)					\
+	({							\
+		struct mbuf *__m;				\
+		IFQ_POLL(&(ifp)->if_snd, __m);			\
+		__m;						\
+	})
+#define drbr_enqueue(ifp, b, m)					\
+	({							\
+		int __err;					\
+		IFQ_ENQUEUE(&(ifp)->if_snd, m, __err);		\
+		__err;						\
+	})
 #define m_getjcl(a, b, c, d)		NULL
 #define MJUM16BYTES			MCLBYTES
-#define m_append(m, len, cp)		0
-#define m_collapse(m, how, maxfrags)	NULL
+#define m_append(m, len, cp)		ena_m_append(m, len, cp)
+#define m_collapse(m, how, maxfrags)	m_defrag(m, how)	/* XXX */
 /* XXX XXX XXX */
 
+static inline int
+ena_m_append(struct mbuf *m0, int len, const void *cpv)
+{
+	struct mbuf *m, *n;
+	int remainder, space;
+	const char *cp = cpv;
+
+	KASSERT(len != M_COPYALL);
+	for (m = m0; m->m_next != NULL; m = m->m_next)
+		continue;
+	remainder = len;
+	space = M_TRAILINGSPACE(m);
+	if (space > 0) {
+		/*
+		 * Copy into available space.
+		 */
+		if (space > remainder)
+			space = remainder;
+		memmove(mtod(m, char *) + m->m_len, cp, space);
+		m->m_len += space;
+		cp = cp + space, remainder -= space;
+	}
+	while (remainder > 0) {
+		/*
+		 * Allocate a new mbuf; could check space
+		 * and allocate a cluster instead.
+		 */
+		n = m_get(M_DONTWAIT, m->m_type);
+		if (n == NULL)
+			break;
+		n->m_len = uimin(MLEN, remainder);
+		memmove(mtod(n, void *), cp, n->m_len);
+		cp += n->m_len, remainder -= n->m_len;
+		m->m_next = n;
+		m = n;
+	}
+	if (m0->m_flags & M_PKTHDR)
+		m0->m_pkthdr.len += len - remainder;
+	return (remainder == 0);
+}
 #endif /* !(ENA_H) */

Reply via email to