Module Name:    src
Committed By:   msaitoh
Date:           Fri Dec  2 10:34:23 UTC 2016

Modified Files:
        src/sys/dev/pci/ixgbe: ix_txrx.c ixgbe.c ixgbe.h ixgbe_mbx.h ixgbe_vf.c
            ixv.c

Log Message:
Update ixg(4) and ixv(4) up to FreeBSD r289238:
- Add support for sysctl knobs to live tune the per interrupt rx/tx packet
  processing limits in ixgbe(4)
- Some others (netmap, etc.)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.46 -r1.47 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/pci/ixgbe/ixgbe_mbx.h
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/pci/ixgbe/ixgbe_vf.c
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/pci/ixgbe/ixv.c

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/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.6 src/sys/dev/pci/ixgbe/ix_txrx.c:1.7
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.6	Fri Dec  2 10:24:31 2016
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Fri Dec  2 10:34:23 2016
@@ -58,8 +58,8 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-/*$FreeBSD: head/sys/dev/ixgbe/ix_txrx.c 285528 2015-07-14 09:13:18Z hiren $*/
-/*$NetBSD: ix_txrx.c,v 1.6 2016/12/02 10:24:31 msaitoh Exp $*/
+/*$FreeBSD: head/sys/dev/ixgbe/ix_txrx.c 289238 2015-10-13 17:34:18Z sbruno $*/
+/*$NetBSD: ix_txrx.c,v 1.7 2016/12/02 10:34:23 msaitoh Exp $*/
 
 #include "ixgbe.h"
 
@@ -267,11 +267,7 @@ ixgbe_mq_start(struct ifnet *ifp, struct
 	 * If everything is setup correctly, it should be the
 	 * same bucket that the current CPU we're on is.
 	 */
-#if __FreeBSD_version < 1100054
-	if (m->m_flags & M_FLOWID) {
-#else
 	if (M_HASHTYPE_GET(m) != M_HASHTYPE_NONE) {
-#endif
 #ifdef	RSS
 		if (rss_hash2bucket(m->m_pkthdr.flowid,
 		    M_HASHTYPE_GET(m), &bucket_id) == 0)
@@ -1028,7 +1024,7 @@ ixgbe_txeof(struct tx_ring *txr)
 	struct adapter		*adapter = txr->adapter;
 	struct ifnet		*ifp = adapter->ifp;
 	u32			work, processed = 0;
-	u16			limit = txr->process_limit;
+	u32			limit = adapter->tx_process_limit;
 	struct ixgbe_tx_buf	*buf;
 	union ixgbe_adv_tx_desc *txd;
 
@@ -1818,7 +1814,7 @@ ixgbe_rxeof(struct ix_queue *que)
 #endif /* LRO */
 	int			i, nextp, processed = 0;
 	u32			staterr = 0;
-	u16			count = rxr->process_limit;
+	u32			count = adapter->rx_process_limit;
 	union ixgbe_adv_rx_desc	*cur;
 	struct ixgbe_rx_buf	*rbuf, *nbuf;
 #ifdef RSS

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.46 src/sys/dev/pci/ixgbe/ixgbe.c:1.47
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.46	Fri Dec  2 10:24:31 2016
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Fri Dec  2 10:34:23 2016
@@ -58,8 +58,8 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-/*$FreeBSD: head/sys/dev/ixgbe/if_ix.c 285590 2015-07-15 00:35:50Z pkelsey $*/
-/*$NetBSD: ixgbe.c,v 1.46 2016/12/02 10:24:31 msaitoh Exp $*/
+/*$FreeBSD: head/sys/dev/ixgbe/if_ix.c 289238 2015-10-13 17:34:18Z sbruno $*/
+/*$NetBSD: ixgbe.c,v 1.47 2016/12/02 10:34:23 msaitoh Exp $*/
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -198,6 +198,8 @@ static void	ixgbe_add_device_sysctls(str
 static void     ixgbe_add_hw_stats(struct adapter *);
 
 /* Sysctl handlers */
+static void	ixgbe_set_sysctl_value(struct adapter *, const char *,
+		    const char *, int *, int);
 static int	ixgbe_set_flowcntl(SYSCTLFN_PROTO);
 static int	ixgbe_set_advertise(SYSCTLFN_PROTO);
 static int	ixgbe_sysctl_thermal_test(SYSCTLFN_PROTO);
@@ -449,6 +451,11 @@ ixgbe_attach(device_t parent, device_t d
 	aprint_normal(": %s, Version - %s\n",
 	    ixgbe_strings[ent->index], ixgbe_driver_version);
 
+#ifdef DEV_NETMAP
+	adapter->init_locked = ixgbe_init_locked;
+	adapter->stop_locked = ixgbe_stop;
+#endif
+
 	/* Core Lock Init*/
 	IXGBE_CORE_LOCK_INIT(adapter, device_xname(dev));
 
@@ -465,6 +472,15 @@ ixgbe_attach(device_t parent, device_t d
 		goto err_out;
 	}
 
+	/* Sysctls for limiting the amount of work done in the taskqueues */
+	ixgbe_set_sysctl_value(adapter, "rx_processing_limit",
+	    "max number of rx packets to process",
+	    &adapter->rx_process_limit, ixgbe_rx_process_limit);
+
+	ixgbe_set_sysctl_value(adapter, "tx_processing_limit",
+	    "max number of tx packets to process",
+	&adapter->tx_process_limit, ixgbe_tx_process_limit);
+
 	/* Do descriptor calc and sanity checks */
 	if (((ixgbe_txd * sizeof(union ixgbe_adv_tx_desc)) % DBA_ALIGN) != 0 ||
 	    ixgbe_txd < MIN_TXD || ixgbe_txd > MAX_TXD) {
@@ -687,6 +703,8 @@ ixgbe_detach(device_t dev, int flags)
 	}
 #endif /* PCI_IOV */
 
+	pmf_device_deregister(dev);
+
 	/* Stop the adapter */
 	IXGBE_CORE_LOCK(adapter);
 	ixgbe_setup_low_power_mode(adapter);
@@ -3033,9 +3051,6 @@ ixgbe_initialize_transmit_units(struct a
 		/* Cache the tail address */
 		txr->tail = IXGBE_TDT(j);
 
-		/* Set the processing limit */
-		txr->process_limit = ixgbe_tx_process_limit;
-
 		/* Disable Head Writeback */
 		switch (hw->mac.type) {
 		case ixgbe_mac_82598EB:
@@ -3293,9 +3308,6 @@ ixgbe_initialize_receive_units(struct ad
 		IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0);
 		IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0);
 
-		/* Set the processing limit */
-		rxr->process_limit = ixgbe_rx_process_limit;
-
 		/* Set the driver rx tail address */
 		rxr->tail =  IXGBE_RDT(rxr->me);
 	}
@@ -4700,6 +4712,27 @@ ixgbe_add_hw_stats(struct adapter *adapt
 	    stats->namebuf, "1024-1522 byte frames transmitted");
 }
 
+static void
+ixgbe_set_sysctl_value(struct adapter *adapter, const char *name,
+    const char *description, int *limit, int value)
+{
+	device_t dev =  adapter->dev;
+	struct sysctllog **log;
+	const struct sysctlnode *rnode, *cnode;
+
+	log = &adapter->sysctllog;
+	if ((rnode = ixgbe_sysctl_instance(adapter)) == NULL) {
+		aprint_error_dev(dev, "could not create sysctl root\n");
+		return;
+	}
+	if (sysctl_createv(log, 0, &rnode, &cnode,
+	    CTLFLAG_READWRITE, CTLTYPE_INT,
+	    name, SYSCTL_DESCR(description),
+		NULL, 0, limit, 0, CTL_CREATE, CTL_EOL) != 0)
+		aprint_error_dev(dev, "could not create sysctl\n");
+	*limit = value;
+}
+
 /*
 ** Set flow control using sysctl:
 ** Flow control values:

Index: src/sys/dev/pci/ixgbe/ixgbe.h
diff -u src/sys/dev/pci/ixgbe/ixgbe.h:1.14 src/sys/dev/pci/ixgbe/ixgbe.h:1.15
--- src/sys/dev/pci/ixgbe/ixgbe.h:1.14	Fri Dec  2 10:24:31 2016
+++ src/sys/dev/pci/ixgbe/ixgbe.h	Fri Dec  2 10:34:23 2016
@@ -58,8 +58,8 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-/*$FreeBSD: head/sys/dev/ixgbe/ixgbe.h 283893 2015-06-01 20:05:06Z jhb $*/
-/*$NetBSD: ixgbe.h,v 1.14 2016/12/02 10:24:31 msaitoh Exp $*/
+/*$FreeBSD: head/sys/dev/ixgbe/ixgbe.h 289238 2015-10-13 17:34:18Z sbruno $*/
+/*$NetBSD: ixgbe.h,v 1.15 2016/12/02 10:34:23 msaitoh Exp $*/
 
 
 #ifndef _IXGBE_H_
@@ -388,7 +388,6 @@ struct tx_ring {
 	volatile u16		tx_avail;
 	u16			next_avail_desc;
 	u16			next_to_clean;
-	u32			process_limit;
 	u16			num_desc;
 	u32			txd_cmd;
 	ixgbe_dma_tag_t		*txtag;
@@ -431,7 +430,6 @@ struct rx_ring {
         u16 			next_to_check;
 	u16			num_desc;
 	u16			mbuf_sz;
-	u32			process_limit;
 	char			mtx_name[16];
 	struct ixgbe_rx_buf	*rx_buffers;
 	ixgbe_dma_tag_t		*ptag;
@@ -559,6 +557,7 @@ struct adapter {
 	 */
 	struct tx_ring		*tx_rings;
 	u32			num_tx_desc;
+	u32			tx_process_limit;
 
 	/*
 	 * Receive rings:
@@ -567,6 +566,7 @@ struct adapter {
 	struct rx_ring		*rx_rings;
 	u64			active_queues;
 	u32			num_rx_desc;
+	u32			rx_process_limit;
 
 	/* Multicast array memory */
 	struct ixgbe_mc_addr	*mta;
@@ -575,6 +575,10 @@ struct adapter {
 #ifdef PCI_IOV
 	struct ixgbe_vf		*vfs;
 #endif
+#ifdef DEV_NETMAP
+	void 			(*init_locked)(struct adapter *);
+	void 			(*stop_locked)(void *);
+#endif
 
 	/* Misc stats maintained by the driver */
 	struct evcnt   		dropped_pkts;

Index: src/sys/dev/pci/ixgbe/ixgbe_mbx.h
diff -u src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.8 src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.9
--- src/sys/dev/pci/ixgbe/ixgbe_mbx.h:1.8	Fri Dec  2 10:24:31 2016
+++ src/sys/dev/pci/ixgbe/ixgbe_mbx.h	Fri Dec  2 10:34:23 2016
@@ -31,7 +31,7 @@
 
 ******************************************************************************/
 /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_mbx.h 283883 2015-06-01 17:43:34Z jfv $*/
-/*$NetBSD: ixgbe_mbx.h,v 1.8 2016/12/02 10:24:31 msaitoh Exp $*/
+/*$NetBSD: ixgbe_mbx.h,v 1.9 2016/12/02 10:34:23 msaitoh Exp $*/
 
 #ifndef _IXGBE_MBX_H_
 #define _IXGBE_MBX_H_

Index: src/sys/dev/pci/ixgbe/ixgbe_vf.c
diff -u src/sys/dev/pci/ixgbe/ixgbe_vf.c:1.10 src/sys/dev/pci/ixgbe/ixgbe_vf.c:1.11
--- src/sys/dev/pci/ixgbe/ixgbe_vf.c:1.10	Fri Dec  2 10:24:31 2016
+++ src/sys/dev/pci/ixgbe/ixgbe_vf.c	Fri Dec  2 10:34:23 2016
@@ -31,7 +31,7 @@
 
 ******************************************************************************/
 /*$FreeBSD: head/sys/dev/ixgbe/ixgbe_vf.c 285590 2015-07-15 00:35:50Z pkelsey $*/
-/*$NetBSD: ixgbe_vf.c,v 1.10 2016/12/02 10:24:31 msaitoh Exp $*/
+/*$NetBSD: ixgbe_vf.c,v 1.11 2016/12/02 10:34:23 msaitoh Exp $*/
 
 
 #include "ixgbe_api.h"

Index: src/sys/dev/pci/ixgbe/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.24 src/sys/dev/pci/ixgbe/ixv.c:1.25
--- src/sys/dev/pci/ixgbe/ixv.c:1.24	Fri Dec  2 10:24:31 2016
+++ src/sys/dev/pci/ixgbe/ixv.c	Fri Dec  2 10:34:23 2016
@@ -30,8 +30,8 @@
   POSSIBILITY OF SUCH DAMAGE.
 
 ******************************************************************************/
-/*$FreeBSD: head/sys/dev/ixgbe/if_ixv.c 285590 2015-07-15 00:35:50Z pkelsey $*/
-/*$NetBSD: ixv.c,v 1.24 2016/12/02 10:24:31 msaitoh Exp $*/
+/*$FreeBSD: head/sys/dev/ixgbe/if_ixv.c 289238 2015-10-13 17:34:18Z sbruno $*/
+/*$NetBSD: ixv.c,v 1.25 2016/12/02 10:34:23 msaitoh Exp $*/
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -121,6 +121,8 @@ static void	ixv_save_stats(struct adapte
 static void	ixv_init_stats(struct adapter *);
 static void	ixv_update_stats(struct adapter *);
 static void	ixv_add_stats_sysctls(struct adapter *);
+static void	ixv_set_sysctl_value(struct adapter *, const char *,
+		    const char *, int *, int);
 
 /* The MSI/X Interrupt handlers */
 static int	ixv_msix_que(void *);
@@ -133,6 +135,18 @@ static void	ixv_handle_mbx(void *);
 const struct sysctlnode *ixv_sysctl_instance(struct adapter *);
 static ixgbe_vendor_info_t *ixv_lookup(const struct pci_attach_args *);
 
+#ifdef DEV_NETMAP
+/*
+ * This is defined in <dev/netmap/ixgbe_netmap.h>, which is included by
+ * if_ix.c.
+ */
+extern void ixgbe_netmap_attach(struct adapter *adapter);
+
+#include <net/netmap.h>
+#include <sys/selinfo.h>
+#include <dev/netmap/netmap_kern.h>
+#endif /* DEV_NETMAP */
+
 /*********************************************************************
  *  FreeBSD Device Interface Entry Points
  *********************************************************************/
@@ -161,6 +175,9 @@ devclass_t ixv_devclass;
 DRIVER_MODULE(ixv, pci, ixv_driver, ixv_devclass, 0, 0);
 MODULE_DEPEND(ixv, pci, 1, 1, 1);
 MODULE_DEPEND(ixv, ether, 1, 1, 1);
+#ifdef DEV_NETMAP
+MODULE_DEPEND(ix, netmap, 1, 1, 1);
+#endif /* DEV_NETMAP */
 /* XXX depend on 'ix' ? */
 #endif
 
@@ -327,6 +344,11 @@ ixv_attach(device_t parent, device_t dev
 	aprint_normal(": %s, Version - %s\n",
 	    ixv_strings[ent->index], ixv_driver_version);
 
+#ifdef DEV_NETMAP
+	adapter->init_locked = ixv_init_locked;
+	adapter->stop_locked = ixv_stop;
+#endif
+
 	/* Core Lock Init*/
 	IXGBE_CORE_LOCK_INIT(adapter, device_xname(dev));
 
@@ -346,6 +368,15 @@ ixv_attach(device_t parent, device_t dev
 		goto err_out;
 	}
 
+	/* Sysctls for limiting the amount of work done in the taskqueues */
+	ixv_set_sysctl_value(adapter, "rx_processing_limit",
+	    "max number of rx packets to process",
+	    &adapter->rx_process_limit, ixv_rx_process_limit);
+
+	ixv_set_sysctl_value(adapter, "tx_processing_limit",
+	    "max number of tx packets to process",
+	    &adapter->tx_process_limit, ixv_tx_process_limit);
+
 	/* Do descriptor calc and sanity checks */
 	if (((ixv_txd * sizeof(union ixgbe_adv_tx_desc)) % DBA_ALIGN) != 0 ||
 	    ixv_txd < MIN_TXD || ixv_txd > MAX_TXD) {
@@ -426,6 +457,9 @@ ixv_attach(device_t parent, device_t dev
 	    ixv_unregister_vlan, adapter, EVENTHANDLER_PRI_FIRST);
 #endif
 
+#ifdef DEV_NETMAP
+	ixgbe_netmap_attach(adapter);
+#endif /* DEV_NETMAP */
 	INIT_DEBUGOUT("ixv_attach: end");
 	adapter->osdep.attached = true;
 	return;
@@ -495,6 +529,9 @@ ixv_detach(device_t dev, int flags)
 
 	ether_ifdetach(adapter->ifp);
 	callout_halt(&adapter->timer, NULL);
+#ifdef DEV_NETMAP
+	netmap_detach(adapter->ifp);
+#endif /* DEV_NETMAP */
 	ixv_free_pci_resources(adapter);
 #if 0 /* XXX the NetBSD port is probably missing something here */
 	bus_generic_detach(dev);
@@ -1652,9 +1689,6 @@ ixv_initialize_transmit_units(struct ada
 		/* Set Tx Tail register */
 		txr->tail = IXGBE_VFTDT(i);
 
-		/* Set the processing limit */
-		txr->process_limit = ixv_tx_process_limit;
-
 		/* Set Ring parameters */
 		IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(i),
 		       (tdba & 0x00000000ffffffffULL));
@@ -1743,9 +1777,6 @@ ixv_initialize_receive_units(struct adap
 		reg |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
 		IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(i), reg);
 
-		/* Set the processing limit */
-		rxr->process_limit = ixv_rx_process_limit;
-
 		/* Capture Rx Tail index */
 		rxr->tail = IXGBE_VFRDT(rxr->me);
 
@@ -1763,8 +1794,33 @@ ixv_initialize_receive_units(struct adap
 		wmb();
 
 		/* Set the Tail Pointer */
-		IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me),
-		    adapter->num_rx_desc - 1);
+#ifdef DEV_NETMAP
+		/*
+		 * In netmap mode, we must preserve the buffers made
+		 * available to userspace before the if_init()
+		 * (this is true by default on the TX side, because
+		 * init makes all buffers available to userspace).
+		 *
+		 * netmap_reset() and the device specific routines
+		 * (e.g. ixgbe_setup_receive_rings()) map these
+		 * buffers at the end of the NIC ring, so here we
+		 * must set the RDT (tail) register to make sure
+		 * they are not overwritten.
+		 *
+		 * In this driver the NIC ring starts at RDH = 0,
+		 * RDT points to the last slot available for reception (?),
+		 * so RDT = num_rx_desc - 1 means the whole ring is available.
+		 */
+		if (ifp->if_capenable & IFCAP_NETMAP) {
+			struct netmap_adapter *na = NA(adapter->ifp);
+			struct netmap_kring *kring = &na->rx_rings[i];
+			int t = na->num_rx_desc - 1 - nm_kr_rxspace(kring);
+
+			IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me), t);
+		} else
+#endif /* DEV_NETMAP */
+			IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rxr->me),
+			    adapter->num_rx_desc - 1);
 	}
 
 	rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
@@ -2121,6 +2177,26 @@ ixv_add_stats_sysctls(struct adapter *ad
 	    xname, "TX TSO");
 }
 
+static void
+ixv_set_sysctl_value(struct adapter *adapter, const char *name,
+	const char *description, int *limit, int value)
+{
+	device_t dev =  adapter->dev;
+	struct sysctllog **log;
+	const struct sysctlnode *rnode, *cnode;
+
+	log = &adapter->sysctllog;
+	if ((rnode = ixv_sysctl_instance(adapter)) == NULL) {
+		aprint_error_dev(dev, "could not create sysctl root\n");
+		return;
+	}
+	if (sysctl_createv(log, 0, &rnode, &cnode,
+	    CTLFLAG_READWRITE|CTLFLAG_IMMEDIATE, CTLTYPE_INT,
+	    name, SYSCTL_DESCR(description),
+	    NULL, value, limit, CTL_CREATE, CTL_EOL) != 0)
+		aprint_error_dev(dev, "could not create sysctl\n");
+}
+
 /**********************************************************************
  *
  *  This routine is called only when em_display_debug_stats is enabled.

Reply via email to