CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2020-09-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Sep  2 12:27:54 UTC 2020

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixgbe_82598.c ixgbe_82599.c
ixgbe_phy.c ixgbe_type.h ixgbe_x550.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1601):

sys/dev/pci/ixgbe/ixgbe_82598.c: revision 1.13
sys/dev/pci/ixgbe/ixgbe.c: revision 1.219
sys/dev/pci/ixgbe/ixgbe_phy.c: revision 1.20
sys/dev/pci/ixgbe/ixgbe_x550.c: revision 1.17
sys/dev/pci/ixgbe/ixgbe_82599.c: revision 1.22
sys/dev/pci/ixgbe/ixgbe_type.h: revision 1.44

Add recovery code for unsupported SFP+.

Before this commit:
   If an unsupported SFP module is inserted before booting, the driver attach
   failed and there was no way to recover form it without rebooting or
   detaching/reattaching driver (drvctl -d && drvctl -r pciN).

After this commit:
   We can automatically recover any time by replacing it with a supported
   module.


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.41 -r1.88.2.42 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.8.8.4 -r1.8.8.5 src/sys/dev/pci/ixgbe/ixgbe_82598.c
cvs rdiff -u -r1.14.8.5 -r1.14.8.6 src/sys/dev/pci/ixgbe/ixgbe_82599.c
cvs rdiff -u -r1.11.6.6 -r1.11.6.7 src/sys/dev/pci/ixgbe/ixgbe_phy.c
cvs rdiff -u -r1.22.2.11 -r1.22.2.12 src/sys/dev/pci/ixgbe/ixgbe_type.h
cvs rdiff -u -r1.5.6.8 -r1.5.6.9 src/sys/dev/pci/ixgbe/ixgbe_x550.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/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.41 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.42
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.41	Wed Sep  2 12:24:08 2020
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Wed Sep  2 12:27:54 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.41 2020/09/02 12:24:08 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.42 2020/09/02 12:27:54 martin Exp $ */
 
 /**
 
@@ -776,6 +776,7 @@ ixgbe_attach(device_t parent, device_t d
 	pcireg_t	id, subid;
 	const ixgbe_vendor_info_t *ent;
 	struct pci_attach_args *pa = aux;
+	bool unsupported_sfp = false;
 	const char *str;
 	char buf[256];
 
@@ -956,8 +957,8 @@ ixgbe_attach(device_t parent, device_t d
 		error = IXGBE_SUCCESS;
 	} else if (error == IXGBE_ERR_SFP_NOT_SUPPORTED) {
 		aprint_error_dev(dev, "Unsupported SFP+ module detected!\n");
-		error = EIO;
-		goto err_late;
+		unsupported_sfp = true;
+		error = IXGBE_SUCCESS;
 	} else if (error) {
 		aprint_error_dev(dev, "Hardware initialization failed\n");
 		error = EIO;
@@ -1126,13 +1127,6 @@ ixgbe_attach(device_t parent, device_t d
 		"please contact your Intel or hardware representative "
 		"who provided you with this hardware.\n");
 		break;
-	case IXGBE_ERR_SFP_NOT_SUPPORTED:
-		aprint_error_dev(dev, "Unsupported SFP+ Module\n");
-		error = EIO;
-		goto err_late;
-	case IXGBE_ERR_SFP_NOT_PRESENT:
-		aprint_error_dev(dev, "No SFP+ Module found\n");
-		/* falls thru */
 	default:
 		break;
 	}
@@ -1165,16 +1159,22 @@ ixgbe_attach(device_t parent, device_t d
 			oui, model, rev);
 	}
 
-	/* Enable the optics for 82599 SFP+ fiber */
-	ixgbe_enable_tx_laser(hw);
-
 	/* Enable EEE power saving */
 	if (adapter->feat_cap & IXGBE_FEATURE_EEE)
 		hw->mac.ops.setup_eee(hw,
 		adapter->feat_en & IXGBE_FEATURE_EEE);
 
 	/* Enable power to the phy. */
-	ixgbe_set_phy_power(hw, TRUE);
+	if (!unsupported_sfp) {
+		/* Enable the optics for 82599 SFP+ fiber */
+		ixgbe_enable_tx_laser(hw);
+
+		/*
+		 * XXX Currently, ixgbe_set_phy_power() supports only copper
+		 * PHY, so it's not required to test with !unsupported_sfp.
+		 */
+		ixgbe_set_phy_power(hw, TRUE);
+	}
 
 	/* Initialize statistics */
 	ixgbe_update_stats_counters(adapter);
@@ -3860,6 +3860,7 @@ ixgbe_init_locked(struct adapter *adapte
 	u32		txdctl, mhadd;
 	u32		rxdctl, rxctrl;
 	u32		ctrl_ext;
+	bool		unsupported_sfp = false;
 	int		i, j, err;
 
 	/* XXX check IFF_UP and IFF_RUNNING, power-saving state! */
@@ -3867,6 +3868,7 @@ ixgbe_init_locked(struct adapter *adapte
 	KASSERT(mutex_owned(&adapter->core_mtx));
 	INIT_DEBUGOUT("ixgbe_init_locked: begin");
 
+	hw->need_unsupported_sfp_recovery = false;
 	hw->adapter_stopped = FALSE;
 	ixgbe_stop_adapter(hw);
 	callout_stop(&adapter->timer);
@@ -4040,12 +4042,14 @@ ixgbe_init_locked(struct adapter *adapte
 	 */
 	if (hw->phy.type == ixgbe_phy_none) {
 		err = hw->phy.ops.identify(hw);
-		if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
-			device_printf(dev,
-			"Unsupported SFP+ module type was detected.\n");
-			return;
-		}
-	}
+		if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
+			unsupported_sfp = true;
+	} else if (hw->phy.type == ixgbe_phy_sfp_unsupported)
+		unsupported_sfp = true;
+
+	if (unsupported_sfp)
+		device_printf(dev,
+		"Unsupported SFP+ module type was detected.\n");
 
 	/* Set moderati

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2020-09-02 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Sep  2 12:24:09 UTC 2020

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: if_bypass.c ixgbe.c ixgbe_common.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1600):

sys/dev/pci/ixgbe/if_bypass.c: revision 1.6
sys/dev/pci/ixgbe/ixgbe_common.c: revision 1.28
sys/dev/pci/ixgbe/ixgbe.c: revision 1.246

Fix checking return value of atomic_cas_uint().

This change fixes a bug that extra delay() is called only once even if
atomic_cas_uint() isn't failed or delay() isn't called when atomic_cas_uint()
failed.

The reason of this bug was that I simply converted FreeBSD' atomic_cmpset_int()
to atomic_cas_uint(). The return value's semantics is different.

 -

Minor change.
  - Print "X550EM X" instead of "X550EM" for Xeon D devices.
  - Fix typo in comment. Same as FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.2.4.5 -r1.2.4.6 src/sys/dev/pci/ixgbe/if_bypass.c
cvs rdiff -u -r1.88.2.40 -r1.88.2.41 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.13.2.9 -r1.13.2.10 src/sys/dev/pci/ixgbe/ixgbe_common.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/if_bypass.c
diff -u src/sys/dev/pci/ixgbe/if_bypass.c:1.2.4.5 src/sys/dev/pci/ixgbe/if_bypass.c:1.2.4.6
--- src/sys/dev/pci/ixgbe/if_bypass.c:1.2.4.5	Fri Jan 24 18:37:31 2020
+++ src/sys/dev/pci/ixgbe/if_bypass.c	Wed Sep  2 12:24:08 2020
@@ -45,9 +45,9 @@
 static void
 ixgbe_bypass_mutex_enter(struct adapter *adapter)
 {
-	while (atomic_cas_uint(&adapter->bypass.low, 0, 1) == 0)
+	while (atomic_cas_uint(&adapter->bypass.low, 0, 1) != 0)
 		usec_delay(3000);
-	while (atomic_cas_uint(&adapter->bypass.high, 0, 1) == 0)
+	while (atomic_cas_uint(&adapter->bypass.high, 0, 1) != 0)
 		usec_delay(3000);
 	return;
 } /* ixgbe_bypass_mutex_enter */
@@ -58,9 +58,9 @@ ixgbe_bypass_mutex_enter(struct adapter 
 static void
 ixgbe_bypass_mutex_clear(struct adapter *adapter)
 {
-	while (atomic_cas_uint(&adapter->bypass.high, 1, 0) == 0)
+	while (atomic_cas_uint(&adapter->bypass.high, 1, 0) != 1)
 		usec_delay(6000);
-	while (atomic_cas_uint(&adapter->bypass.low, 1, 0) == 0)
+	while (atomic_cas_uint(&adapter->bypass.low, 1, 0) != 1)
 		usec_delay(6000);
 	return;
 } /* ixgbe_bypass_mutex_clear */
@@ -73,7 +73,7 @@ ixgbe_bypass_mutex_clear(struct adapter 
 static void
 ixgbe_bypass_wd_mutex_enter(struct adapter *adapter)
 {
-	while (atomic_cas_uint(&adapter->bypass.high, 0, 1) == 0)
+	while (atomic_cas_uint(&adapter->bypass.high, 0, 1) != 0)
 		usec_delay(3000);
 	return;
 } /* ixgbe_bypass_wd_mutex_enter */
@@ -84,7 +84,7 @@ ixgbe_bypass_wd_mutex_enter(struct adapt
 static void
 ixgbe_bypass_wd_mutex_clear(struct adapter *adapter)
 {
-	while (atomic_cas_uint(&adapter->bypass.high, 1, 0) == 0)
+	while (atomic_cas_uint(&adapter->bypass.high, 1, 0) != 1)
 		usec_delay(6000);
 	return;
 } /* ixgbe_bypass_wd_mutex_clear */
@@ -585,7 +585,7 @@ ixgbe_bp_log(SYSCTLFN_ARGS)
 		return (error);
 
 	/* Keep the log display single-threaded */
-	while (atomic_cas_uint(&adapter->bypass.log, 0, 1) == 0)
+	while (atomic_cas_uint(&adapter->bypass.log, 0, 1) != 0)
 		usec_delay(3000);
 
 	ixgbe_bypass_mutex_enter(adapter);
@@ -713,14 +713,14 @@ ixgbe_bp_log(SYSCTLFN_ARGS)
 
 	status = 0; /* reset */
 	/* Another log command can now run */
-	while (atomic_cas_uint(&adapter->bypass.log, 1, 0) == 0)
+	while (atomic_cas_uint(&adapter->bypass.log, 1, 0) != 1)
 		usec_delay(3000);
 	return (error);
 
 unlock_err:
 	ixgbe_bypass_mutex_clear(adapter);
 	status = 0; /* reset */
-	while (atomic_cas_uint(&adapter->bypass.log, 1, 0) == 0)
+	while (atomic_cas_uint(&adapter->bypass.log, 1, 0) != 1)
 		usec_delay(3000);
 	return (EINVAL);
 } /* ixgbe_bp_log */

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.40 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.41
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.40	Wed Aug  5 15:58:02 2020
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Wed Sep  2 12:24:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.40 2020/08/05 15:58:02 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.41 2020/09/02 12:24:08 martin Exp $ */
 
 /**
 
@@ -858,7 +858,7 @@ ixgbe_attach(device_t parent, device_t d
 		str = "X550";
 		break;
 	case ixgbe_mac_X550EM_x:
-		str = "X550EM";
+		str = "X550EM X";
 		break;
 	case ixgbe_mac_X550EM_a:
 		str = "X550EM A";

Index: src/sys/dev/pci/ixgbe/ixgbe_common.c
diff -u src/sys/dev/pci/ixgbe/ixgbe_common.c:1.13.2.9 src/sys/dev/pci/ixgbe/ixgbe_common.c:1.13.2.10
--- src/sys/dev/pci/ixgbe/ixgbe_common.c:1.13.2.9	Wed Aug  5 15:58:02 2020
+++ src/sys/dev/pci/ixgbe/ixgbe_common.c	Wed Sep  2 12:24:08 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_common.c,v 1.13.2.9 2020/08/05 15:58:02 martin Exp $ */
+/* $NetBSD: ixgbe_common.c,v 1.13.2.10 2020/09/02 12:24

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2020-08-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Aug  5 15:58:03 UTC 2020

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c ixgbe.c ixgbe.h
ixgbe_82598.c ixgbe_common.c ixgbe_netbsd.c ixgbe_osdep.h
ixgbe_phy.c ixgbe_vf.c ixgbe_x550.c ixv.c

Log Message:
Pull up the following revisions, requested by msaitoh in ticket #1587:

sys/dev/pci/ixgbe/ix_txrx.c 1.62-1.63 via patch
sys/dev/pci/ixgbe/ixgbe.c   1.225, 1.228-1.229,
1.232 via patch
sys/dev/pci/ixgbe/ixgbe.h   1.64, 1.66
sys/dev/pci/ixgbe/ixv.c 1.146, 1.148-1.150
via patch
sys/dev/pci/ixgbe/ixgbe_common.c1.27
sys/dev/pci/ixgbe/ixgbe_vf.c1.23
sys/dev/pci/ixgbe/ixgbe_82598.c 1.15
sys/dev/pci/ixgbe/ixgbe_x550.c  1.18
sys/dev/pci/ixgbe/ixgbe_netbsd.c1.14
sys/dev/pci/ixgbe/ixgbe_phy.c   1.21
sys/dev/pci/ixgbe/ixgbe_osdep.h 1.26

- Fix IXGBE_LE32_TO_CPUS() macro for big endian machine. This problem
  was only on X550.
- Add debug printf()s.
- Use unsigned to avoid undefined behavior in
  ixgbe_fc_enable_generic().
- Modify a little to reduce diff between ixgbe.c and ixv.c.
  No functional change.
- Modify comment.
- Remove unused macros.
- Whitespace fix.
- Fix typos.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.19 -r1.24.2.20 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.39 -r1.88.2.40 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.19 -r1.24.6.20 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.8.8.3 -r1.8.8.4 src/sys/dev/pci/ixgbe/ixgbe_82598.c
cvs rdiff -u -r1.13.2.8 -r1.13.2.9 src/sys/dev/pci/ixgbe/ixgbe_common.c
cvs rdiff -u -r1.6.2.5 -r1.6.2.6 src/sys/dev/pci/ixgbe/ixgbe_netbsd.c
cvs rdiff -u -r1.17.6.6 -r1.17.6.7 src/sys/dev/pci/ixgbe/ixgbe_osdep.h
cvs rdiff -u -r1.11.6.5 -r1.11.6.6 src/sys/dev/pci/ixgbe/ixgbe_phy.c
cvs rdiff -u -r1.12.8.4 -r1.12.8.5 src/sys/dev/pci/ixgbe/ixgbe_vf.c
cvs rdiff -u -r1.5.6.7 -r1.5.6.8 src/sys/dev/pci/ixgbe/ixgbe_x550.c
cvs rdiff -u -r1.56.2.29 -r1.56.2.30 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.24.2.19 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.20
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.19	Fri Jan 24 18:37:31 2020
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Wed Aug  5 15:58:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.19 2020/01/24 18:37:31 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.20 2020/08/05 15:58:02 martin Exp $ */
 
 /**
 
@@ -926,7 +926,7 @@ ixgbe_tx_ctx_setup(struct tx_ring *txr, 
 	vlan_macip_lens |= ip_hlen;
 
 	/* No support for offloads for non-L4 next headers */
- 	switch (ipproto) {
+	switch (ipproto) {
 	case IPPROTO_TCP:
 		if (mp->m_pkthdr.csum_flags &
 		(M_CSUM_TCPv4 | M_CSUM_TCPv6))
@@ -1569,7 +1569,6 @@ ixgbe_setup_receive_ring(struct rx_ring 
 		rxbuf->addr = htole64(rxbuf->pmap->dm_segs[0].ds_addr);
 	}
 
-
 	/* Setup our descriptor indices */
 	rxr->next_to_check = 0;
 	rxr->next_to_refresh = 0;
@@ -1625,6 +1624,7 @@ ixgbe_setup_receive_structures(struct ad
 	struct rx_ring *rxr = adapter->rx_rings;
 	intj;
 
+	INIT_DEBUGOUT("ixgbe_setup_receive_structures");
 	for (j = 0; j < adapter->num_queues; j++, rxr++)
 		if (ixgbe_setup_receive_ring(rxr))
 			goto fail;
@@ -2233,7 +2233,7 @@ ixgbe_allocate_queues(struct adapter *ad
 
 	/* First, allocate the top level queue structs */
 	adapter->queues = (struct ix_queue *)malloc(sizeof(struct ix_queue) *
-adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO);
+	adapter->num_queues, M_DEVBUF, M_NOWAIT | M_ZERO);
 if (adapter->queues == NULL) {
 		aprint_error_dev(dev, "Unable to allocate queue memory\n");
 error = ENOMEM;
@@ -2300,7 +2300,7 @@ ixgbe_allocate_queues(struct adapter *ad
 			"Critical Failure setting up transmit buffers\n");
 			error = ENOMEM;
 			goto err_tx_desc;
-	}
+		}
 		if (!(adapter->feat_en & IXGBE_FEATURE_LEGACY_TX)) {
 			/* Allocate a buf ring */
 			txr->txr_interq = pcq_create(IXGBE_BR_SIZE, KM_SLEEP);

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.39 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.40
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.39	Fri Jan 24 18:37:31 2020
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Wed Aug  5 15:58:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.39 2020/01/24 18:37:31 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.40 2020/08/05 15:58:02 martin Exp $ */
 
 /

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2020-01-24 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jan 24 18:37:32 UTC 2020

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: if_bypass.c ix_txrx.c ixgbe.c ixgbe.h
ixgbe_82598.c ixgbe_api.c ixgbe_common.c ixgbe_netbsd.c
ixgbe_osdep.c ixgbe_osdep.h ixgbe_phy.c ixv.c

Log Message:
Pull up the following, requested by msaitoh in ticket #1490:

sys/dev/pci/ixgbe/if_bypass.c   1.5
sys/dev/pci/ixgbe/ixgbe_osdep.c 1.5
sys/dev/pci/ixgbe/ix_txrx.c 1.58-1.60
sys/dev/pci/ixgbe/ixgbe.c   1.195,1.220-1.221 via patch
sys/dev/pci/ixgbe/ixgbe.h   1.60-1.2
sys/dev/pci/ixgbe/ixgbe_api.c   1.24
sys/dev/pci/ixgbe/ixgbe_common.c1.26
sys/dev/pci/ixgbe/ixgbe_netbsd.c1.11-1.12
sys/dev/pci/ixgbe/ixgbe_osdep.h 1.24
sys/dev/pci/ixgbe/ixgbe_phy.c   1.19
sys/dev/pci/ixgbe/ixgbe_82598.c 1.14
sys/dev/pci/ixgbe/ixv.c 1.122,1.142,1.144 via patch

- Use unsigned to avoid undefined behavior in
  ix{gbe,v}_[un]register_vlan().
- Free RX structure correctly when detaching.
- Remove unused code.
- Remove extra spaces.
- Fix some typos in comment.
- KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.2.4.4 -r1.2.4.5 src/sys/dev/pci/ixgbe/if_bypass.c
cvs rdiff -u -r1.24.2.18 -r1.24.2.19 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.38 -r1.88.2.39 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.18 -r1.24.6.19 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.8.8.2 -r1.8.8.3 src/sys/dev/pci/ixgbe/ixgbe_82598.c
cvs rdiff -u -r1.15.8.5 -r1.15.8.6 src/sys/dev/pci/ixgbe/ixgbe_api.c
cvs rdiff -u -r1.13.2.7 -r1.13.2.8 src/sys/dev/pci/ixgbe/ixgbe_common.c
cvs rdiff -u -r1.6.2.4 -r1.6.2.5 src/sys/dev/pci/ixgbe/ixgbe_netbsd.c
cvs rdiff -u -r1.1.12.3 -r1.1.12.4 src/sys/dev/pci/ixgbe/ixgbe_osdep.c
cvs rdiff -u -r1.17.6.5 -r1.17.6.6 src/sys/dev/pci/ixgbe/ixgbe_osdep.h
cvs rdiff -u -r1.11.6.4 -r1.11.6.5 src/sys/dev/pci/ixgbe/ixgbe_phy.c
cvs rdiff -u -r1.56.2.28 -r1.56.2.29 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/if_bypass.c
diff -u src/sys/dev/pci/ixgbe/if_bypass.c:1.2.4.4 src/sys/dev/pci/ixgbe/if_bypass.c:1.2.4.5
--- src/sys/dev/pci/ixgbe/if_bypass.c:1.2.4.4	Sat Apr 14 10:25:11 2018
+++ src/sys/dev/pci/ixgbe/if_bypass.c	Fri Jan 24 18:37:31 2020
@@ -101,7 +101,7 @@ ixgbe_get_bypass_time(u32 *year, u32 *se
 	nanotime(¤t);
 	*sec = current.tv_sec;
 
-	while(*sec > SEC_THIS_YEAR(*year)) {
+	while (*sec > SEC_THIS_YEAR(*year)) {
 		*sec -= SEC_THIS_YEAR(*year);
 		(*year)++;
 	}

Index: src/sys/dev/pci/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.18 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.19
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.18	Sun Nov 10 13:36:29 2019
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Fri Jan 24 18:37:31 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.18 2019/11/10 13:36:29 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.19 2020/01/24 18:37:31 martin Exp $ */
 
 /**
 
@@ -148,7 +148,7 @@ ixgbe_legacy_start_locked(struct ifnet *
 		return (ENETDOWN);
 	if (txr->txr_no_space)
 		return (ENETDOWN);
-	
+
 	while (!IFQ_IS_EMPTY(&ifp->if_snd)) {
 		if (txr->tx_avail <= IXGBE_QUEUE_MIN_FREE)
 			break;
@@ -1693,6 +1693,10 @@ ixgbe_free_receive_buffers(struct rx_rin
 rxbuf->pmap = NULL;
 			}
 		}
+
+		/* NetBSD specific. See ixgbe_netbsd.c */
+		ixgbe_jcl_destroy(adapter, rxr);
+
 		if (rxr->rx_buffers != NULL) {
 			free(rxr->rx_buffers, M_DEVBUF);
 			rxr->rx_buffers = NULL;
@@ -2379,3 +2383,24 @@ tx_fail:
 fail:
 	return (error);
 } /* ixgbe_allocate_queues */
+
+/
+ * ixgbe_free_queues
+ *
+ *   Free descriptors for the transmit and receive rings, and then
+ *   the memory associated with each.
+ /
+void
+ixgbe_free_queues(struct adapter *adapter)
+{
+	struct ix_queue *que;
+	int i;
+
+	ixgbe_free_transmit_structures(adapter);
+	ixgbe_free_receive_structures(adapter);
+	for (i = 0; i < adapter->num_queues; i++) {
+		que = &adapter->queues[i];
+		mutex_destroy(&que->dc_mtx);
+	}
+	free(adapter->queues, M_DEVBUF);
+} /* ixgbe_free_queues */

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.38 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.39
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.38	Thu Dec 26 20:25:07 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Fri Jan 24 18:37:31 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.38 2019/12/26 20:25:07 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.39 2020/01/24 18:37:31 martin Exp $ */
 
 /*

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2019-12-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Dec 26 20:25:07 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1478):

sys/dev/pci/ixgbe/ixgbe.c: revision 1.218

 Add missing core lock in ixgbe_handle_mod().


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.37 -r1.88.2.38 src/sys/dev/pci/ixgbe/ixgbe.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/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.37 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.38
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.37	Tue Nov 19 10:48:15 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Dec 26 20:25:07 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.37 2019/11/19 10:48:15 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.38 2019/12/26 20:25:07 martin Exp $ */
 
 /**
 
@@ -4572,6 +4572,7 @@ ixgbe_handle_mod(void *context)
 	device_t	dev = adapter->dev;
 	u32		err, cage_full = 0;
 
+	IXGBE_CORE_LOCK(adapter);
 	++adapter->mod_sicount.ev_count;
 	if (adapter->hw.need_crosstalk_fix) {
 		switch (hw->mac.type) {
@@ -4589,14 +4590,14 @@ ixgbe_handle_mod(void *context)
 		}
 
 		if (!cage_full)
-			return;
+			goto out;
 	}
 
 	err = hw->phy.ops.identify_sfp(hw);
 	if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
 		device_printf(dev,
 		"Unsupported SFP+ module type was detected.\n");
-		return;
+		goto out;
 	}
 
 	if (hw->mac.type == ixgbe_mac_82598EB)
@@ -4607,9 +4608,11 @@ ixgbe_handle_mod(void *context)
 	if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
 		device_printf(dev,
 		"Setup failure - unsupported SFP+ module type.\n");
-		return;
+		goto out;
 	}
 	softint_schedule(adapter->msf_si);
+out:
+	IXGBE_CORE_UNLOCK(adapter);
 } /* ixgbe_handle_mod */
 
 



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2019-04-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Apr  1 12:35:38 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixgbe_type.h ixv.c

Log Message:
Pull up the following, requested by msaitohin ticket #1225:

sys/dev/pci/ixgbe/ixgbe.c   1.175-1.178
sys/dev/pci/ixgbe/ixv.c 1.110-1.111 via patch

- NetBSD currently uses traffic class 0 only. Other traffic classes
  aren't used yet. When IXGBE_TC_COUNTER_NUM is set to lower than
  IXGBE_DCB_MAX_TRAFFIC_CLASS (e.g. 1), other traffic classes' counters
  are not used. It means we don't generate evcnt for them and don't
  add the values in ixgbe_update_stats_counters().
- It's not required to calculate unused queues' statistics.
- Fix a bug that the VLAN HW tagging function is not correctly disabled
  when all vlan is detached.
- Fix a bug that VLAN HW tagging function is not correctly controlled
  on 82598.
- Control VLAN HW filter function correctly. Note that currently
  VLAN HW filter function doesn't work because NetBSD doesn't support
  it yet.
- Don't clear IXGBE_VLNCTRL_CFIEN bit When ETHERCAP_VLAN_HWFILTER is
  set. I think it's not required (and Linux doesn't do it). This change
  has no effect to NetBSD because ETHERCAP_VLAN_HWFILTER is not
  supported yet.


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.28 -r1.88.2.29 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.22.2.7 -r1.22.2.8 src/sys/dev/pci/ixgbe/ixgbe_type.h
cvs rdiff -u -r1.56.2.20 -r1.56.2.21 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/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.28 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.29
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.28	Fri Mar  1 17:33:24 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Mon Apr  1 12:35:38 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.28 2019/03/01 17:33:24 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.29 2019/04/01 12:35:38 martin Exp $ */
 
 /**
 
@@ -1558,8 +1558,8 @@ ixgbe_update_stats_counters(struct adapt
 		}
 	}
 
-	/* 8 registers */
-	for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
+	/* 8 registers exist */
+	for (i = 0; i < IXGBE_TC_COUNTER_NUM; i++) {
 		uint32_t mp;
 
 		/* MPC */
@@ -1739,7 +1739,7 @@ ixgbe_add_hw_stats(struct adapter *adapt
 
 	/* Max number of traffic class is 8 */
 	KASSERT(IXGBE_DCB_MAX_TRAFFIC_CLASS == 8);
-	for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
+	for (i = 0; i < IXGBE_TC_COUNTER_NUM; i++) {
 		snprintf(adapter->tcs[i].evnamebuf,
 		sizeof(adapter->tcs[i].evnamebuf), "%s tc%d",
 		xname, i);
@@ -2038,7 +2038,7 @@ ixgbe_clear_evcnt(struct adapter *adapte
 	adapter->msf_sicount.ev_count = 0;
 	adapter->phy_sicount.ev_count = 0;
 
-	for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
+	for (i = 0; i < IXGBE_TC_COUNTER_NUM; i++) {
 		if (i < __arraycount(stats->mpc)) {
 			stats->mpc[i].ev_count = 0;
 			if (hw->mac.type == ixgbe_mac_82598EB)
@@ -2310,33 +2310,34 @@ ixgbe_setup_vlan_hw_support(struct adapt
 	struct rx_ring	*rxr;
 	int i;
 	u32		ctrl;
-
+	bool		hwtagging;
 
 	/*
-	 * We get here thru init_locked, meaning
-	 * a soft reset, this has already cleared
-	 * the VFTA and other state, so if there
-	 * have been no vlan's registered do nothing.
+	 *  This function is called from both if_init and ifflags_cb()
+	 * on NetBSD.
 	 */
-	if (!VLAN_ATTACHED(&adapter->osdep.ec))
-		return;
+
+	/* Enable HW tagging only if any vlan is attached */
+	hwtagging = (ec->ec_capenable & ETHERCAP_VLAN_HWTAGGING)
+	&& VLAN_ATTACHED(ec);
 
 	/* Setup the queues for vlans */
-	if (ec->ec_capenable & ETHERCAP_VLAN_HWTAGGING) {
-		for (i = 0; i < adapter->num_queues; i++) {
-			rxr = &adapter->rx_rings[i];
-			/* On 82599 the VLAN enable is per/queue in RXDCTL */
-			if (hw->mac.type != ixgbe_mac_82598EB) {
-ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxr->me));
+	for (i = 0; i < adapter->num_queues; i++) {
+		rxr = &adapter->rx_rings[i];
+		/*
+		 * On 82599 and later, the VLAN enable is per/queue in RXDCTL.
+		 */
+		if (hw->mac.type != ixgbe_mac_82598EB) {
+			ctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(rxr->me));
+			if (hwtagging)
 ctrl |= IXGBE_RXDCTL_VME;
-IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxr->me), ctrl);
-			}
-			rxr->vtag_strip = TRUE;
+			else
+ctrl &= ~IXGBE_RXDCTL_VME;
+			IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(rxr->me), ctrl);
 		}
+		rxr->vtag_strip = hwtagging ? TRUE : FALSE;
 	}
 
-	if ((ec->ec_capenable & ETHERCAP_VLAN_HWFILTER) == 0)
-		return;
 	/*
 	 * A soft reset zero's out the VFTA, so
 	 * we need to repopulate it now.
@@ -2348,12 +2349,17 @@ ixgbe_setup_vlan_hw_support(struct adapt
 
 	ctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
 	/* Enable the Filter Table if enabled */
-	if (ec->ec_capenable & ETHERCAP_VLAN_HWFILTER) {
-		ctrl &= ~IXG

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2019-03-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Mar  1 17:33:25 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c ixgbe.c ixgbe.h ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1199):

sys/dev/pci/ixgbe/ixv.c: revision 1.109
sys/dev/pci/ixgbe/ixgbe.h: revision 1.54
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.52
sys/dev/pci/ixgbe/ixgbe.c: revision 1.174

  Fix a bug that if_link_state_change(ifp, LINK_STATE_DOWN) isn't called unless
link goes up at least one time. Without this change, never linkup-ed media
keeps LINK_STATE_UNKNOWN instead of LINK_STATE_DOWN.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.14 -r1.24.2.15 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.27 -r1.88.2.28 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.15 -r1.24.6.16 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.56.2.19 -r1.56.2.20 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.24.2.14 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.15
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.14	Thu Dec 20 11:34:33 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Fri Mar  1 17:33:24 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.14 2018/12/20 11:34:33 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.15 2019/03/01 17:33:24 martin Exp $ */
 
 /**
 
@@ -136,7 +136,7 @@ ixgbe_legacy_start_locked(struct ifnet *
 
 	IXGBE_TX_LOCK_ASSERT(txr);
 
-	if (!adapter->link_active) {
+	if (adapter->link_active != LINK_STATE_UP) {
 		/*
 		 * discard all packets buffered in IFQ to avoid
 		 * sending old packets at next link up timing.
@@ -282,7 +282,7 @@ ixgbe_mq_start_locked(struct ifnet *ifp,
 	struct mbuf*next;
 	intenqueued = 0, err = 0;
 
-	if (!txr->adapter->link_active) {
+	if (txr->adapter->link_active != LINK_STATE_UP) {
 		/*
 		 * discard all packets buffered in txr_interq to avoid
 		 * sending old packets at next link up timing.

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.27 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.28
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.27	Mon Jan 28 13:03:02 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Fri Mar  1 17:33:24 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.27 2019/01/28 13:03:02 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.28 2019/03/01 17:33:24 martin Exp $ */
 
 /**
 
@@ -1594,7 +1594,7 @@ ixgbe_update_stats_counters(struct adapt
 	stats->mpctotal.ev_count += total_missed_rx;
 
 	/* Document says M[LR]FC are valid when link is up and 10Gbps */
-	if ((adapter->link_active == TRUE)
+	if ((adapter->link_active == LINK_STATE_UP)
 	&& (adapter->link_speed == IXGBE_LINK_SPEED_10GB_FULL)) {
 		stats->mlfc.ev_count += IXGBE_READ_REG(hw, IXGBE_MLFC);
 		stats->mrfc.ev_count += IXGBE_READ_REG(hw, IXGBE_MRFC);
@@ -2692,7 +2692,7 @@ ixgbe_media_status(struct ifnet *ifp, st
 	ifmr->ifm_status = IFM_AVALID;
 	ifmr->ifm_active = IFM_ETHER;
 
-	if (!adapter->link_active) {
+	if (adapter->link_active != LINK_STATE_UP) {
 		ifmr->ifm_active |= IFM_NONE;
 		IXGBE_CORE_UNLOCK(adapter);
 		return;
@@ -4665,7 +4665,7 @@ ixgbe_update_link_status(struct adapter 
 	KASSERT(mutex_owned(&adapter->core_mtx));
 
 	if (adapter->link_up) {
-		if (adapter->link_active == FALSE) {
+		if (adapter->link_active != LINK_STATE_UP) {
 			/*
 			 * To eliminate influence of the previous state
 			 * in the same way as ixgbe_init_locked().
@@ -4714,7 +4714,7 @@ ixgbe_update_link_status(struct adapter 
 device_printf(dev, "Link is up %s %s \n",
 bpsmsg, "Full Duplex");
 			}
-			adapter->link_active = TRUE;
+			adapter->link_active = LINK_STATE_UP;
 			/* Update any Flow Control changes */
 			ixgbe_fc_enable(&adapter->hw);
 			/* Update DMA coalescing config */
@@ -4724,12 +4724,17 @@ ixgbe_update_link_status(struct adapter 
 			if (adapter->feat_en & IXGBE_FEATURE_SRIOV)
 ixgbe_ping_all_vfs(adapter);
 		}
-	} else { /* Link down */
-		if (adapter->link_active == TRUE) {
+	} else {
+		/*
+		 * Do it when link active changes to DOWN. i.e.
+		 * a) LINK_STATE_UNKNOWN -> LINK_STATE_DOWN
+		 * b) LINK_STATE_UP  -> LINK_STATE_DOWN
+		 */
+		if (adapter->link_active != LINK_STATE_DOWN) {
 			if (bootverbose)
 device_printf(dev, "Link is Down\n");
 			if_link_state_change(ifp, LINK_STATE_DOWN);
-			adapter->link_active = FALSE;
+			adapter->link_active = LINK_STATE_DOWN;
 			if (adapter->feat_en & IXGBE_FEATURE_SRIOV)
 ixgbe_ping_all_vfs(adapter);
 			ixgbe_drain_all(adapter);

Index: src/sys/dev/pci/ixgbe/ixgbe.h
diff -u src/sys/dev/pci/ixgbe/ixgbe.h:1.24.6.15 src/sys/dev/pci/ixgbe/ixgbe.h:1.24.6.16
--- src/sys/dev/pci/ixgbe

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2019-01-28 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Jan 28 13:03:02 UTC 2019

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixgbe.h

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1171):

sys/dev/pci/ixgbe/ixgbe.c: revision 1.168
sys/dev/pci/ixgbe/ixgbe.h: revision 1.52
sys/dev/pci/ixgbe/ixgbe.c: revision 1.172
sys/dev/pci/ixgbe/ixgbe.c: revision 1.173

  Some counters are not per queue but per traffic class. Make new evcnt group
"ixgM tcN" (N = 0..7) and move those counters into it. We are using only
traffic class 0, so we will see only tc0's counter are updated.

 -

  Call ixgbe_init_swfw_semaphore(hw) before calling ixgbe_check_wol_support()
because ixgbe_check_wol_support()->ixgbe_check_wol_support()->
ixgbe_get_device_caps() accesses semaphore.

 -

- Move the location of calling setup_eee() in ixgbe_attach(). The previous
   location was too early. The new location is before calling
   ixgbe_set_phy_power().
- Restore call of setup_eee() in ixgbe_init_locked(). It was removed in
   rev. 1.99 (FreeBSD r320688).
- When calling setup_eee(), pass enable/disable correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.26 -r1.88.2.27 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.14 -r1.24.6.15 src/sys/dev/pci/ixgbe/ixgbe.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/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.26 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.27
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.26	Sun Jan 27 18:35:19 2019
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Mon Jan 28 13:03:02 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.26 2019/01/27 18:35:19 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.27 2019/01/28 13:03:02 martin Exp $ */
 
 /**
 
@@ -873,6 +873,9 @@ ixgbe_attach(device_t parent, device_t d
 	} else
 		adapter->num_segs = IXGBE_82598_SCATTER;
 
+	/* Ensure SW/FW semaphore is free */
+	ixgbe_init_swfw_semaphore(hw);
+
 	hw->mac.ops.set_lan_id(hw);
 	ixgbe_init_device_features(adapter);
 
@@ -899,13 +902,6 @@ ixgbe_attach(device_t parent, device_t d
 		ixgbe_check_fan_failure(adapter, esdp, FALSE);
 	}
 
-	/* Ensure SW/FW semaphore is free */
-	ixgbe_init_swfw_semaphore(hw);
-
-	/* Enable EEE power saving */
-	if (adapter->feat_en & IXGBE_FEATURE_EEE)
-		hw->mac.ops.setup_eee(hw, TRUE);
-
 	/* Set an initial default flow control value */
 	hw->fc.requested_mode = ixgbe_flow_control;
 
@@ -1148,6 +1144,11 @@ ixgbe_attach(device_t parent, device_t d
 	/* Enable the optics for 82599 SFP+ fiber */
 	ixgbe_enable_tx_laser(hw);
 
+	/* Enable EEE power saving */
+	if (adapter->feat_cap & IXGBE_FEATURE_EEE)
+		hw->mac.ops.setup_eee(hw,
+		adapter->feat_en & IXGBE_FEATURE_EEE);
+
 	/* Enable power to the phy. */
 	ixgbe_set_phy_power(hw, TRUE);
 
@@ -1535,6 +1536,7 @@ ixgbe_update_stats_counters(struct adapt
 	u32   missed_rx = 0, bprc, lxon, lxoff, total;
 	u64   total_missed_rx = 0;
 	uint64_t  crcerrs, rlec;
+	int		  i, j;
 
 	crcerrs = IXGBE_READ_REG(hw, IXGBE_CRCERRS);
 	stats->crcerrs.ev_count += crcerrs;
@@ -1545,8 +1547,8 @@ ixgbe_update_stats_counters(struct adapt
 		stats->mbsdc.ev_count += IXGBE_READ_REG(hw, IXGBE_MBSDC);
 
 	/* 16 registers */
-	for (int i = 0; i < __arraycount(stats->qprc); i++) {
-		int j = i % adapter->num_queues;
+	for (i = 0; i < __arraycount(stats->qprc); i++) {
+		j = i % adapter->num_queues;
 
 		stats->qprc[j].ev_count += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
 		stats->qptc[j].ev_count += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
@@ -1557,36 +1559,35 @@ ixgbe_update_stats_counters(struct adapt
 	}
 
 	/* 8 registers */
-	for (int i = 0; i < __arraycount(stats->mpc); i++) {
+	for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
 		uint32_t mp;
-		int j = i % adapter->num_queues;
 
 		/* MPC */
 		mp = IXGBE_READ_REG(hw, IXGBE_MPC(i));
 		/* global total per queue */
-		stats->mpc[j].ev_count += mp;
+		stats->mpc[i].ev_count += mp;
 		/* running comprehensive total for stats display */
 		total_missed_rx += mp;
 
 		if (hw->mac.type == ixgbe_mac_82598EB)
-			stats->rnbc[j].ev_count
+			stats->rnbc[i].ev_count
 			+= IXGBE_READ_REG(hw, IXGBE_RNBC(i));
 
-		stats->pxontxc[j].ev_count
+		stats->pxontxc[i].ev_count
 		+= IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
-		stats->pxofftxc[j].ev_count
+		stats->pxofftxc[i].ev_count
 		+= IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
 		if (hw->mac.type >= ixgbe_mac_82599EB) {
-			stats->pxonrxc[j].ev_count
+			stats->pxonrxc[i].ev_count
 			+= IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
-			stats->pxoffrxc[j].ev_count
+			stats->pxoffrxc[i].ev_count
 			+= IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
-			stats->pxon2offc[j].ev_count
+			stats->pxon2offc[i].ev_count
 			+= IXGBE_READ_REG(

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-12-20 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Dec 20 11:34:33 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #1141):

sys/dev/pci/ixgbe/ix_txrx.c: revision 1.51

Apply the same fix as if_wm.c:r1.606 to ixg(4). Pointed out by msaitoh@n.o, 
thanks.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.13 -r1.24.2.14 src/sys/dev/pci/ixgbe/ix_txrx.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.24.2.13 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.14
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.13	Fri Sep  7 12:37:20 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Thu Dec 20 11:34:33 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.13 2018/09/07 12:37:20 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.14 2018/12/20 11:34:33 martin Exp $ */
 
 /**
 
@@ -230,7 +230,7 @@ ixgbe_mq_start(struct ifnet *ifp, struct
 			i = m->m_pkthdr.flowid % adapter->num_queues;
 	} else
 #endif /* 0 */
-		i = cpu_index(curcpu()) % adapter->num_queues;
+		i = (cpu_index(curcpu()) % ncpu) % adapter->num_queues;
 
 	/* Check for a hung queue and pick alternative */
 	if (((1 << i) & adapter->active_queues) == 0)



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-11-08 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Nov  8 12:04:49 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1084):

sys/dev/pci/ixgbe/ixv.c: revision 1.107
sys/dev/pci/ixgbe/ixgbe.c: revision 1.167

  Don't set LRO capability flag because we don't support it yet.

This doesn't change any behavior other than if_capabilities' visibility
(e.g. ifconfig).


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.24 -r1.88.2.25 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.56.2.17 -r1.56.2.18 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/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.24 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.25
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.24	Sun Sep 23 17:43:36 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Nov  8 12:04:48 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.24 2018/09/23 17:43:36 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.25 2018/11/08 12:04:48 martin Exp $ */
 
 /**
 
@@ -1312,8 +1312,7 @@ ixgbe_setup_interface(device_t dev, stru
 	ifp->if_capabilities |= IFCAP_RXCSUM
 			 |  IFCAP_TXCSUM
 			 |  IFCAP_TSOv4
-			 |  IFCAP_TSOv6
-			 |  IFCAP_LRO;
+			 |  IFCAP_TSOv6;
 	ifp->if_capenable = 0;
 
 	ec->ec_capabilities |= ETHERCAP_VLAN_HWTAGGING

Index: src/sys/dev/pci/ixgbe/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.56.2.17 src/sys/dev/pci/ixgbe/ixv.c:1.56.2.18
--- src/sys/dev/pci/ixgbe/ixv.c:1.56.2.17	Sat Jun  9 14:59:43 2018
+++ src/sys/dev/pci/ixgbe/ixv.c	Thu Nov  8 12:04:48 2018
@@ -1,4 +1,4 @@
-/*$NetBSD: ixv.c,v 1.56.2.17 2018/06/09 14:59:43 martin Exp $*/
+/*$NetBSD: ixv.c,v 1.56.2.18 2018/11/08 12:04:48 martin Exp $*/
 
 /**
 
@@ -1554,9 +1554,9 @@ ixv_setup_interface(device_t dev, struct
 	ec->ec_capenable = ec->ec_capabilities;
 
 	/* Don't enable LRO by default */
-	ifp->if_capabilities |= IFCAP_LRO;
 #if 0
-	ifp->if_capenable = ifp->if_capabilities;
+	/* NetBSD doesn't support LRO yet */
+	ifp->if_capabilities |= IFCAP_LRO;
 #endif
 
 	/*



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-09-23 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Sep 23 17:43:37 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1029):

sys/dev/pci/ixgbe/ixgbe.c: revision 1.166

- Fix a bug that Denverton accessed wrong register in
   ixgbe_setup_low_power_mode(). The location of some registers in Denverton
   were changed. The GRC register is one of them, so use IXGBE_GRC_BY_MAC(hw)
   instead of IXGBE_GRC.

- ixgbe_check_wol_support() tests the capability of WOL, but the sysctl
   knobs for WOL were added only for IXGBE_DEV_ID_X550EM_X_10G_T. Add the
   knobs when adapter->wol_support is not 0.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.23 -r1.88.2.24 src/sys/dev/pci/ixgbe/ixgbe.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/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.23 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.24
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.23	Wed Sep  5 08:42:22 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Sun Sep 23 17:43:36 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.23 2018/09/05 08:42:22 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.24 2018/09/23 17:43:36 martin Exp $ */
 
 /**
 
@@ -3277,7 +3277,7 @@ ixgbe_add_device_sysctls(struct adapter 
 			aprint_error_dev(dev, "could not create sysctl\n");
 
 	/* for WoL-capable devices */
-	if (hw->device_id == IXGBE_DEV_ID_X550EM_X_10G_T) {
+	if (adapter->wol_support) {
 		if (sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_READWRITE,
 		CTLTYPE_BOOL, "wol_enable",
 		SYSCTL_DESCR("Enable/Disable Wake on LAN"),
@@ -3663,8 +3663,8 @@ ixgbe_setup_low_power_mode(struct adapte
 		IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
 	} else {
 		/* Turn off support for APM wakeup. (Using ACPI instead) */
-		IXGBE_WRITE_REG(hw, IXGBE_GRC,
-		IXGBE_READ_REG(hw, IXGBE_GRC) & ~(u32)2);
+		IXGBE_WRITE_REG(hw, IXGBE_GRC_BY_MAC(hw),
+		IXGBE_READ_REG(hw, IXGBE_GRC_BY_MAC(hw)) & ~(u32)2);
 
 		/*
 		 * Clear Wake Up Status register to prevent any previous wakeup



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-09-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Sep  7 12:37:20 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1014):

sys/dev/pci/ixgbe/ix_txrx.c: revision 1.50

  Fix a bug that ixgbe_mq_start(an if_transmit function) returned wrong
value on error. pcq_put returns false on error, so returning it to caller
indicated no error.

XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.12 -r1.24.2.13 src/sys/dev/pci/ixgbe/ix_txrx.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.24.2.12 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.13
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.12	Tue Aug  7 13:33:23 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Fri Sep  7 12:37:20 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.12 2018/08/07 13:33:23 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.13 2018/09/07 12:37:20 martin Exp $ */
 
 /**
 
@@ -202,7 +202,7 @@ ixgbe_mq_start(struct ifnet *ifp, struct
 {
 	struct adapter	*adapter = ifp->if_softc;
 	struct tx_ring	*txr;
-	int 		i, err = 0;
+	int 		i;
 #ifdef RSS
 	uint32_t bucket_id;
 #endif
@@ -238,11 +238,10 @@ ixgbe_mq_start(struct ifnet *ifp, struct
 
 	txr = &adapter->tx_rings[i];
 
-	err = pcq_put(txr->txr_interq, m);
-	if (err == false) {
+	if (__predict_false(!pcq_put(txr->txr_interq, m))) {
 		m_freem(m);
 		txr->pcq_drops.ev_count++;
-		return (err);
+		return ENOBUFS;
 	}
 	if (IXGBE_TX_TRYLOCK(txr)) {
 		ixgbe_mq_start_locked(ifp, txr);



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-09-05 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Sep  5 08:42:22 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #1006):

sys/dev/pci/ixgbe/ixgbe.c: revision 1.164

  Fix a bug that media change may fail. I noticed that ifconfig ixgN media XXX
took a 10 or more seconds on a Denverton machie. I occurred by trying take a
lock and timed out. The reason was that ixgbe_media_change() didn't take
CORE_LOCK. Do it.

  This problem was from FreeBSD's pre-iflib ixgbe (I don't know whether this
problem really occurs on FreeBSD or not). Post-iflib ixgbe has no problem
because iflib_media_change() takes a lock.
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.22 -r1.88.2.23 src/sys/dev/pci/ixgbe/ixgbe.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/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.22 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.23
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.22	Tue Aug  7 13:33:23 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Wed Sep  5 08:42:22 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.22 2018/08/07 13:33:23 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.23 2018/09/05 08:42:22 martin Exp $ */
 
 /**
 
@@ -2841,6 +2841,7 @@ ixgbe_media_change(struct ifnet *ifp)
 	if (hw->phy.media_type == ixgbe_media_type_backplane)
 		return (EPERM);
 
+	IXGBE_CORE_LOCK(adapter);
 	/*
 	 * We don't actually need to check against the supported
 	 * media types of the adapter; ifmedia will take care of
@@ -2853,6 +2854,7 @@ ixgbe_media_change(struct ifnet *ifp)
 		if (err != IXGBE_SUCCESS) {
 			device_printf(adapter->dev, "Unable to determine "
 			"supported advertise speeds\n");
+			IXGBE_CORE_UNLOCK(adapter);
 			return (ENODEV);
 		}
 		speed |= link_caps;
@@ -2913,10 +2915,12 @@ ixgbe_media_change(struct ifnet *ifp)
 			adapter->advertise |= 1 << 5;
 	}
 
+	IXGBE_CORE_UNLOCK(adapter);
 	return (0);
 
 invalid:
 	device_printf(adapter->dev, "Invalid media type!\n");
+	IXGBE_CORE_UNLOCK(adapter);
 
 	return (EINVAL);
 } /* ixgbe_media_change */



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-08-07 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Aug  7 13:33:23 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c ixgbe.c ixgbe.h
ixgbe_netbsd.c ixgbe_osdep.h ixgbe_type.h ixgbe_x550.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #961):

sys/dev/pci/ixgbe/ixgbe_x550.c: revision 1.13
sys/dev/pci/ixgbe/ixgbe.h: revision 1.51
sys/dev/pci/ixgbe/ixgbe_type.h: revision 1.36
sys/dev/pci/ixgbe/ixgbe_osdep.h: revision 1.23
sys/dev/pci/ixgbe/ixgbe_netbsd.c: revision 1.8
sys/dev/pci/ixgbe/ixgbe.c: revision 1.163
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.49

  Add force_10_100_autonego sysctl. The default value is 0(false).

This sysctl is only for 550EM_a with PHY firmware for a while.

  Make jcl allocation per queue to reduce mutex spin. Tested by me and
knakahara.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.11 -r1.24.2.12 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.21 -r1.88.2.22 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.13 -r1.24.6.14 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.6.2.1 -r1.6.2.2 src/sys/dev/pci/ixgbe/ixgbe_netbsd.c
cvs rdiff -u -r1.17.6.4 -r1.17.6.5 src/sys/dev/pci/ixgbe/ixgbe_osdep.h
cvs rdiff -u -r1.22.2.6 -r1.22.2.7 src/sys/dev/pci/ixgbe/ixgbe_type.h
cvs rdiff -u -r1.5.6.4 -r1.5.6.5 src/sys/dev/pci/ixgbe/ixgbe_x550.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.24.2.11 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.12
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.11	Sat Jun  9 14:59:43 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Tue Aug  7 13:33:23 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.11 2018/06/09 14:59:43 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.12 2018/08/07 13:33:23 martin Exp $ */
 
 /**
 
@@ -1343,7 +1343,7 @@ ixgbe_refresh_mbufs(struct rx_ring *rxr,
 	while (j != limit) {
 		rxbuf = &rxr->rx_buffers[i];
 		if (rxbuf->buf == NULL) {
-			mp = ixgbe_getjcl(&adapter->jcl_head, M_NOWAIT,
+			mp = ixgbe_getjcl(&rxr->jcl_head, M_NOWAIT,
 			MT_DATA, M_PKTHDR, rxr->mbuf_sz);
 			if (mp == NULL) {
 rxr->no_jmbuf.ev_count++;
@@ -1505,6 +1505,17 @@ ixgbe_setup_receive_ring(struct rx_ring 
 	/* Free current RX buffer structs and their mbufs */
 	ixgbe_free_receive_ring(rxr);
 
+	IXGBE_RX_UNLOCK(rxr);
+	/*
+	 * Now reinitialize our supply of jumbo mbufs.  The number
+	 * or size of jumbo mbufs may have changed.
+	 * Assume all of rxr->ptag are the same.
+	 */
+	ixgbe_jcl_reinit(adapter, rxr->ptag->dt_dmat, rxr,
+	(2 * adapter->num_rx_desc), adapter->rx_mbuf_sz);
+
+	IXGBE_RX_LOCK(rxr);
+
 	/* Now replenish the mbufs */
 	for (int j = 0; j != rxr->num_desc; ++j) {
 		struct mbuf *mp;
@@ -1534,7 +1545,7 @@ ixgbe_setup_receive_ring(struct rx_ring 
 #endif /* DEV_NETMAP */
 
 		rxbuf->flags = 0;
-		rxbuf->buf = ixgbe_getjcl(&adapter->jcl_head, M_NOWAIT,
+		rxbuf->buf = ixgbe_getjcl(&rxr->jcl_head, M_NOWAIT,
 		MT_DATA, M_PKTHDR, adapter->rx_mbuf_sz);
 		if (rxbuf->buf == NULL) {
 			error = ENOBUFS;
@@ -1611,15 +1622,6 @@ ixgbe_setup_receive_structures(struct ad
 	struct rx_ring *rxr = adapter->rx_rings;
 	intj;
 
-	/*
-	 * Now reinitialize our supply of jumbo mbufs.  The number
-	 * or size of jumbo mbufs may have changed.
-	 * Assume all of rxr->ptag are the same.
-	 */
-	ixgbe_jcl_reinit(adapter, rxr->ptag->dt_dmat,
-	(2 * adapter->num_rx_desc) * adapter->num_queues,
-	adapter->rx_mbuf_sz);
-
 	for (j = 0; j < adapter->num_queues; j++, rxr++)
 		if (ixgbe_setup_receive_ring(rxr))
 			goto fail;

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.21 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.22
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.21	Thu Jul 26 23:21:54 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Tue Aug  7 13:33:23 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.21 2018/07/26 23:21:54 snj Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.22 2018/08/07 13:33:23 martin Exp $ */
 
 /**
 
@@ -3315,6 +3315,15 @@ ixgbe_add_device_sysctls(struct adapter 
 			aprint_error_dev(dev, "could not create sysctl\n");
 	}
 
+	if ((hw->mac.type == ixgbe_mac_X550EM_a)
+	&& (hw->phy.type == ixgbe_phy_fw))
+		if (sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_READWRITE,
+		CTLTYPE_BOOL, "force_10_100_autonego",
+		SYSCTL_DESCR("Force autonego on 10M and 100M"),
+		NULL, 0, &hw->phy.force_10_100_autonego, 0,
+		CTL_CREATE, CTL_EOL) != 0)
+			aprint_error_dev(dev, "could not create sysctl\n");
+
 	if (adapter->feat_cap & IXGBE_FEATURE_EEE) {
 		if (sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_READWRITE,
 		CTLTYPE_INT, "eee_state",

Index: src/sys/dev/

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-07-26 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Thu Jul 26 23:21:54 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixgbe_82599.c ixgbe_api.c
ixgbe_type.h ixgbe_x540.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #935):
sys/dev/pci/ixgbe/ixgbe.c: revision 1.162
sys/dev/pci/ixgbe/ixgbe_82599.c: revision 1.20
sys/dev/pci/ixgbe/ixgbe_api.c: revision 1.21
sys/dev/pci/ixgbe/ixgbe_type.h: revision 1.35
sys/dev/pci/ixgbe/ixgbe_x540.c: revision 1.16
Apply changes of FreeBSD ix-3.2.18.tgz:
  - Add IXGBE_DEV_ID_82599_LS(0x154f) support.
  - Increase timeout for newer than ixgbe_mac_X550 (i.e. Xeon-D and Denverton)
in ixgbe_acquire_swfw_sync_X540().
  - Add some unused macros (IXGBE_FW_LESM_*).
--
Remove nmbclusters check. We don't use the mbuf cluster. The old code also had
a bug that ixgbe_total_ports adds two every port and never decrement in
the detach path. Found by hikaru@.
The code was removed in FreeBSD when it switched to use iflib and OpenBSD
removed the code 8 years ago.


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.20 -r1.88.2.21 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.14.8.3 -r1.14.8.4 src/sys/dev/pci/ixgbe/ixgbe_82599.c
cvs rdiff -u -r1.15.8.3 -r1.15.8.4 src/sys/dev/pci/ixgbe/ixgbe_api.c
cvs rdiff -u -r1.22.2.5 -r1.22.2.6 src/sys/dev/pci/ixgbe/ixgbe_type.h
cvs rdiff -u -r1.9.6.3 -r1.9.6.4 src/sys/dev/pci/ixgbe/ixgbe_x540.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/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.20 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.21
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.20	Sat Jun  9 14:59:43 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Jul 26 23:21:54 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.20 2018/06/09 14:59:43 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.21 2018/07/26 23:21:54 snj Exp $ */
 
 /**
 
@@ -392,9 +392,6 @@ static int ixgbe_enable_rss = 1;
 SYSCTL_INT(_hw_ix, OID_AUTO, enable_rss, CTLFLAG_RDTUN, &ixgbe_enable_rss, 0,
 "Enable Receive-Side Scaling (RSS)");
 
-/* Keep running tab on them for sanity check */
-static int ixgbe_total_ports;
-
 #if 0
 static int (*ixgbe_start_locked)(struct ifnet *, struct tx_ring *);
 static int (*ixgbe_ring_empty)(struct ifnet *, pcq_t *);
@@ -929,21 +926,6 @@ ixgbe_attach(device_t parent, device_t d
 	} else
 		adapter->num_tx_desc = ixgbe_txd;
 
-	/*
-	 * With many RX rings it is easy to exceed the
-	 * system mbuf allocation. Tuning nmbclusters
-	 * can alleviate this.
-	 */
-	if (nmbclusters > 0) {
-		int s;
-		s = (ixgbe_rxd * adapter->num_queues) * ixgbe_total_ports;
-		if (s > nmbclusters) {
-			aprint_error_dev(dev, "RX Descriptors exceed "
-			"system mbuf max, using default instead!\n");
-			ixgbe_rxd = DEFAULT_RXD;
-		}
-	}
-
 	if (((ixgbe_rxd * sizeof(union ixgbe_adv_rx_desc)) % DBA_ALIGN) != 0 ||
 	ixgbe_rxd < MIN_RXD || ixgbe_rxd > MAX_RXD) {
 		aprint_error_dev(dev, "RXD config issue, using default!\n");
@@ -5956,7 +5938,6 @@ ixgbe_lookup(const struct pci_attach_arg
 			(ent->subvendor_id == 0)) &&
 		((PCI_SUBSYS_ID(subid) == ent->subdevice_id) ||
 			(ent->subdevice_id == 0))) {
-			++ixgbe_total_ports;
 			return ent;
 		}
 	}

Index: src/sys/dev/pci/ixgbe/ixgbe_82599.c
diff -u src/sys/dev/pci/ixgbe/ixgbe_82599.c:1.14.8.3 src/sys/dev/pci/ixgbe/ixgbe_82599.c:1.14.8.4
--- src/sys/dev/pci/ixgbe/ixgbe_82599.c:1.14.8.3	Sat Apr 14 10:25:11 2018
+++ src/sys/dev/pci/ixgbe/ixgbe_82599.c	Thu Jul 26 23:21:54 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_82599.c,v 1.14.8.3 2018/04/14 10:25:11 martin Exp $ */
+/* $NetBSD: ixgbe_82599.c,v 1.14.8.4 2018/07/26 23:21:54 snj Exp $ */
 
 /**
   SPDX-License-Identifier: BSD-3-Clause
@@ -566,6 +566,9 @@ enum ixgbe_media_type ixgbe_get_media_ty
 	case IXGBE_DEV_ID_82599_T3_LOM:
 		media_type = ixgbe_media_type_copper;
 		break;
+	case IXGBE_DEV_ID_82599_LS:
+		media_type = ixgbe_media_type_fiber_lco;
+		break;
 	case IXGBE_DEV_ID_82599_QSFP_SF_QP:
 		media_type = ixgbe_media_type_fiber_qsfp;
 		break;

Index: src/sys/dev/pci/ixgbe/ixgbe_api.c
diff -u src/sys/dev/pci/ixgbe/ixgbe_api.c:1.15.8.3 src/sys/dev/pci/ixgbe/ixgbe_api.c:1.15.8.4
--- src/sys/dev/pci/ixgbe/ixgbe_api.c:1.15.8.3	Sat Apr 14 10:25:11 2018
+++ src/sys/dev/pci/ixgbe/ixgbe_api.c	Thu Jul 26 23:21:54 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_api.c,v 1.15.8.3 2018/04/14 10:25:11 martin Exp $ */
+/* $NetBSD: ixgbe_api.c,v 1.15.8.4 2018/07/26 23:21:54 snj Exp $ */
 
 /**
   SPDX-License-Identifier: BSD-3-Clause
@@ -173,6 +173,7 @@ s32 ixgbe_set_mac_type(struct ixgbe_hw *
 	case IXGBE_DEV_ID_82599_SFP_SF_QP:
 	case IXGBE_DEV_ID_82

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-06-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Jun  9 14:59:43 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c ixgbe.c ixgbe.h
ixgbe_netbsd.c ixgbe_netbsd.h ixgbe_osdep.h ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #864):

sys/dev/pci/ixgbe/ix_txrx.c 1.40-1.47 (patch)
sys/dev/pci/ixgbe/ixgbe.c   1.148,1.149,1.151,
1.152,1.154,
1.155,1.157-1.160 
(patch)
sys/dev/pci/ixgbe/ixgbe.h   1.43,1.44,1.46,1.49 
(patch)
sys/dev/pci/ixgbe/ixgbe_netbsd.c1.7 (patch)
sys/dev/pci/ixgbe/ixgbe_netbsd.h1.8 (patch)
sys/dev/pci/ixgbe/ixgbe_osdep.h 1.22 (patch)
sys/dev/pci/ixgbe/ixv.c 1.100-1.104 (patch)
sys/dev/pci/ixgbe/ixv.c 1.94,1.95,1.99 (patch)

 Remove unused structure entries. No functional change.
 -
 Remove unused IXGBE_FC_HI and IXGBE_FC_LO. The watermark of the flow control
is automatically calculated from the size of the packet buffer.
 -
 Use ixgbe_eitr_write() when writing the EITR for the link interrupt like
queue's EITR to write the register safely. This change is not relatively
so important than queue's EITR because link's EITR is written in if_init().
 -
 Don't free and reallocate bus_dmamem when it's not required. Currently,
the watchdog timer is completely broken and never fire (it's from FreeBSD
(pre iflib)). If the problem is fixed and watchdog fired, ixgbe_init() always
calls ixgbe_jcl_reinit() and it causes panic. The reason is that
ixgbe_local_timer1(it includes watchdog function) is softint and
xgbe_jcl_reinit() calls bus_dmamem*() functions. bus_dmamem*() can't be called
from interrupt context.

 One of the way to prevent panic is use worqueue for the timer, but it's
not a small change. (I'll do it in future).

 Another way is not reallocate dmamem if it's not required. If both the MTU
(rx_mbuf_sz in reality) and the number of RX descriptors are not changed, it's
not required to call bus_dmamem_{unmap,free}(). Even if we use workque, this
change save time of ixgbe_init().

 I have a code to fix broken watchdog timer but it sometime causes watchdog
timeout, so I don't commit it yet.
 -
Count some register correctly:
- QPRDC register is only for 82599 and newer.
- Count IXGBE_QPRDC, PX{ON,OFF}{T,R}XC[NT].
 The TQSMR register is not for receiving but for transmitting, so move the
initialization from ixgbe_initialize_receive_units() to
ixgbe_initialize_transmit_units(). No functional change.
 -
 Whitespace fix. No functional change.
 -
 Add rxd_nxck (Receive Descriptor next to check) read only sysctl.
 Don't check IFF_RUNNING in ixgbe_rxeof(). Doing break and leaving a deacriptor
with DD bit is worse than just processing the entry. And it's also racy to
check IFF_RUNNING in rxeof(). If you'd like to strictly obey IFF_RUNNING,
it would be better to do it in the upper layer.
 Same as DragonFly (a part of 79251f5ebe4cf9dd2f3e6aed590e09d756d39922).
 Add "bool txr_no_space" for TX descriptor shortage. Use it like IFF_OACTIVE.
 Clear que->disabled_count in {ixgbe,ixv}_init_locked(). Without this,
interrupt mask state and EIMS may mismatch and if_init doesn't recover
from TX/RX stall problem.
 This change itself doesn't fix PR#53294.
 -
 Add hw.ixgN.debug sysctl. "sysctl -w hw.ixgN.debug=1" dumps some registers
to console.
 -
Constify several variables in ixgbe/ so that they land in .rodata (1038
bytes).
 -
 Don't call ixgbe_rearm_queues() in ixgbe_local_timer1().
   ixgbe_enable_queue() and ixgbe_disable_queue() try to enable/disable queue
  interrupt safely. It has the internal counter. When a queue's MSI-X is
  received, ixgbe_msix_que() is called (IPL_NET). This function disable the
  queue's interrupt by ixgbe_disable_queue() and issues an softint.
  ixgbe_handle() queue is called by the softint (IPL_SOFTNET), process TX, RX
  and call ixgbe_enable_queue() at the end.

   ixgbe_local_timer1() is a callout and run always on CPU 0 (IPL_SOFTCLOCK).
  When ixgbe_rearm_queues() called, an MSI-X interrupt is issued for a specific
  queue. It may not CPU 0. If this interrupt's ixgbe_msix_que() is called and
  sofint_schedule() is called before the last sofint's softint_execute() is not
  called, the softint_schedule() fails because of SOFTINT_PENDING. It result
  in breaking ixgbe_{enable,disable}_queue()'s internal counter.
   ixgbe_local_timer1() is written not to call ixgbe_rearm_queues() if
  the interrupt is disabled, but it's called because of unknown bug or a race.

  One solution to avoid this problem is to not to use the internal counter,
  but it's little difficult. Another solution is stop using
  ixgbe_rearm_queues() at all. Essentially, ixgbe_rearm_queues() is not
  required (it w

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-05-15 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue May 15 13:37:24 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #824):

sys/dev/pci/ixgbe/ixv.c: revision 1.97

Fix panic or hangup when "sysctl -w hw.ixgN.debug=1".
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.56.2.14 -r1.56.2.15 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/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.56.2.14 src/sys/dev/pci/ixgbe/ixv.c:1.56.2.15
--- src/sys/dev/pci/ixgbe/ixv.c:1.56.2.14	Sat Apr 14 10:25:11 2018
+++ src/sys/dev/pci/ixgbe/ixv.c	Tue May 15 13:37:24 2018
@@ -1,4 +1,4 @@
-/*$NetBSD: ixv.c,v 1.56.2.14 2018/04/14 10:25:11 martin Exp $*/
+/*$NetBSD: ixv.c,v 1.56.2.15 2018/05/15 13:37:24 martin Exp $*/
 
 /**
 
@@ -2603,21 +2603,18 @@ ixv_print_debug_info(struct adapter *ada
 static int
 ixv_sysctl_debug(SYSCTLFN_ARGS)
 {
-	struct sysctlnode node;
-	struct adapter *adapter;
+	struct sysctlnode node = *rnode;
+	struct adapter *adapter = (struct adapter *)node.sysctl_data;
 	interror, result;
 
-	node = *rnode;
 	node.sysctl_data = &result;
 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
 
 	if (error || newp == NULL)
 		return error;
 
-	if (result == 1) {
-		adapter = (struct adapter *)node.sysctl_data;
+	if (result == 1)
 		ixv_print_debug_info(adapter);
-	}
 
 	return 0;
 } /* ixv_sysctl_debug */



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-04-17 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Apr 17 08:20:06 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixgbe.h

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #769):

sys/dev/pci/ixgbe/ixgbe.c: revision 1.147
sys/dev/pci/ixgbe/ixgbe.h: revision 1.42

Fix panic when "sysctl -w hw.ixg0.txrx_workqueue=[01]" while there is traffic.
The operation is not supported, however causing panic is problem.


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.17 -r1.88.2.18 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.10 -r1.24.6.11 src/sys/dev/pci/ixgbe/ixgbe.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/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.17 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.18
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.17	Sat Apr 14 10:25:11 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Tue Apr 17 08:20:06 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.17 2018/04/14 10:25:11 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.18 2018/04/17 08:20:06 martin Exp $ */
 
 /**
 
@@ -2487,7 +2487,7 @@ static inline void
 ixgbe_sched_handle_que(struct adapter *adapter, struct ix_queue *que)
 {
 
-	if (adapter->txrx_use_workqueue) {
+	if(que->txrx_use_workqueue) {
 		/*
 		 * adapter->que_wq is bound to each CPU instead of
 		 * each NIC queue to reduce workqueue kthread. As we
@@ -2531,6 +2531,12 @@ ixgbe_msix_que(void *arg)
 	ixgbe_disable_queue(adapter, que->msix);
 	++que->irqs.ev_count;
 
+	/*
+	 * Don't change "que->txrx_use_workqueue" from this point to avoid
+	 * flip-flopping softint/workqueue mode in one deferred processing.
+	 */
+	que->txrx_use_workqueue = adapter->txrx_use_workqueue;
+
 #ifdef __NetBSD__
 	/* Don't run ixgbe_rxeof in interrupt context */
 	more = true;
@@ -3174,6 +3180,16 @@ ixgbe_add_device_sysctls(struct adapter 
 	CTL_EOL) != 0)
 		aprint_error_dev(dev, "could not create sysctl\n");
 
+	/*
+	 * If each "que->txrx_use_workqueue" is changed in sysctl handler,
+	 * it causesflip-flopping softint/workqueue mode in one deferred
+	 * processing. Therefore, preempt_disable()/preempt_enable() are
+	 * required in ixgbe_sched_handle_que() to avoid
+	 * KASSERT(ixgbe_sched_handle_que()) in softint_schedule().
+	 * I think changing "que->txrx_use_workqueue" in interrupt handler
+	 * is lighter than doing preempt_disable()/preempt_enable() in every
+	 * ixgbe_sched_handle_que().
+	 */
 	adapter->txrx_use_workqueue = ixgbe_txrx_workqueue;
 	if (sysctl_createv(log, 0, &rnode, &cnode, CTLFLAG_READWRITE,
 	CTLTYPE_BOOL, "txrx_workqueue", SYSCTL_DESCR("Use workqueue for packet processing"),
@@ -4798,6 +4814,11 @@ ixgbe_legacy_irq(void *arg)
 	}
 
 	if ((ifp->if_flags & IFF_RUNNING) != 0) {
+		/*
+		 * The same as ixgbe_msix_que() about "que->txrx_use_workqueue".
+		 */
+		que->txrx_use_workqueue = adapter->txrx_use_workqueue;
+
 #ifdef __NetBSD__
 		/* Don't run ixgbe_rxeof in interrupt context */
 		more = true;

Index: src/sys/dev/pci/ixgbe/ixgbe.h
diff -u src/sys/dev/pci/ixgbe/ixgbe.h:1.24.6.10 src/sys/dev/pci/ixgbe/ixgbe.h:1.24.6.11
--- src/sys/dev/pci/ixgbe/ixgbe.h:1.24.6.10	Sat Apr 14 10:25:12 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.h	Tue Apr 17 08:20:06 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.h,v 1.24.6.10 2018/04/14 10:25:12 martin Exp $ */
+/* $NetBSD: ixgbe.h,v 1.24.6.11 2018/04/17 08:20:06 martin Exp $ */
 
 /**
   SPDX-License-Identifier: BSD-3-Clause
@@ -346,6 +346,7 @@ struct ix_queue {
 	 * > 0 : this queue is disabled
 	 *   the value is ixgbe_disable_queue() called count
 	 */
+	bool txrx_use_workqueue;
 };
 
 /*



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-04-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Apr 14 10:25:12 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: if_bypass.c if_fdir.c if_sriov.c
ix_txrx.c ixgbe.c ixgbe.h ixgbe_82598.c ixgbe_82598.h ixgbe_82599.c
ixgbe_82599.h ixgbe_api.c ixgbe_api.h ixgbe_common.c ixgbe_common.h
ixgbe_dcb.c ixgbe_dcb.h ixgbe_dcb_82598.c ixgbe_dcb_82598.h
ixgbe_dcb_82599.c ixgbe_dcb_82599.h ixgbe_fdir.h ixgbe_mbx.c
ixgbe_mbx.h ixgbe_osdep.c ixgbe_osdep.h ixgbe_phy.c ixgbe_phy.h
ixgbe_rss.h ixgbe_sriov.h ixgbe_type.h ixgbe_vf.c ixgbe_vf.h
ixgbe_x540.c ixgbe_x540.h ixgbe_x550.c ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #750):

sys/dev/pci/ixgbe/ixgbe_x540.h: revision 1.8
sys/dev/pci/ixgbe/ixgbe_82598.c: revision 1.11
sys/dev/pci/ixgbe/ixgbe_dcb_82599.c: revision 1.6
sys/dev/pci/ixgbe/ixgbe_82598.c: revision 1.12
sys/dev/pci/ixgbe/ixgbe_dcb_82599.c: revision 1.7
sys/dev/pci/ixgbe/ixgbe_dcb_82598.h: revision 1.6
sys/dev/pci/ixgbe/ixgbe_fdir.h: revision 1.2
sys/dev/pci/ixgbe/ixgbe_dcb_82599.h: revision 1.6
sys/dev/pci/ixgbe/ixgbe_dcb_82598.c: revision 1.6
sys/dev/pci/ixgbe/ixgbe_82599.c: revision 1.18
sys/dev/pci/ixgbe/if_sriov.c: revision 1.3
sys/dev/pci/ixgbe/ixgbe_dcb_82598.c: revision 1.7
sys/dev/pci/ixgbe/ixgbe_82599.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe_mbx.h: revision 1.13
sys/dev/pci/ixgbe/ixgbe_dcb.c: revision 1.7
sys/dev/pci/ixgbe/ixgbe_api.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe_vf.c: revision 1.16
sys/dev/pci/ixgbe/ixgbe_dcb.c: revision 1.8
sys/dev/pci/ixgbe/ixgbe_vf.c: revision 1.17
sys/dev/pci/ixgbe/ixgbe_dcb.h: revision 1.6
sys/dev/pci/ixgbe/if_bypass.c: revision 1.4
sys/dev/pci/ixgbe/ixv.c: revision 1.91
sys/dev/pci/ixgbe/ixgbe_rss.h: revision 1.4
sys/dev/pci/ixgbe/ixv.c: revision 1.92
sys/dev/pci/ixgbe/ixv.c: revision 1.93
sys/dev/pci/ixgbe/ixgbe_osdep.c: revision 1.4
sys/dev/pci/ixgbe/ixgbe_common.h: revision 1.12
sys/dev/pci/ixgbe/ixgbe_common.h: revision 1.13
sys/dev/pci/ixgbe/ixgbe_api.h: revision 1.13
sys/dev/pci/ixgbe/ixgbe_x550.c: revision 1.12
sys/dev/pci/ixgbe/ixgbe_type.h: revision 1.33
sys/dev/pci/ixgbe/if_fdir.c: revision 1.2
sys/dev/pci/ixgbe/ixgbe_type.h: revision 1.34
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.39
sys/dev/pci/ixgbe/ixgbe_vf.h: revision 1.13
sys/dev/pci/ixgbe/ixgbe_api.c: revision 1.20
sys/dev/pci/ixgbe/ixgbe_sriov.h: revision 1.3
sys/dev/pci/ixgbe/ixgbe_common.c: revision 1.21
sys/dev/pci/ixgbe/ixgbe_osdep.h: revision 1.21
sys/dev/pci/ixgbe/ixgbe_common.c: revision 1.22
sys/dev/pci/ixgbe/ixgbe_82599.h: revision 1.7
sys/dev/pci/ixgbe/ixgbe.c: revision 1.144
sys/dev/pci/ixgbe/ixgbe.c: revision 1.145
sys/dev/pci/ixgbe/ixgbe_phy.c: revision 1.16
sys/dev/pci/ixgbe/ixgbe.c: revision 1.146
sys/dev/pci/ixgbe/ixgbe_phy.c: revision 1.17
sys/dev/pci/ixgbe/ixgbe_82598.h: revision 1.8
sys/dev/pci/ixgbe/ixgbe.h: revision 1.41
sys/dev/pci/ixgbe/ixgbe_mbx.c: revision 1.10
sys/dev/pci/ixgbe/ixgbe_x540.c: revision 1.14
sys/dev/pci/ixgbe/ixgbe_x540.c: revision 1.15
sys/dev/pci/ixgbe/ixgbe_phy.h: revision 1.11

Sync with the remaining part of FreeBSD r328265 except sfp_reinit stuff:
 - Always schedule module intterrupt in ixgbe_config_link() when a device is
   SFP+ based.
 - Use not loop index but txr->me in ixv_initialize_{transmit,receive}_units().
   It's required for VMDQ but NetBSD doesn't use it, so it's not a bug in
   NetBSD.
 - Simplify ixgbe_bp_wd_set(). No functional change.
 - Whitespace.

Sync with FreeBSD r331224 except ixv_if_update_admin_status()'s change:
 - Fix length of reading buffer when the command is Read Flash in
   ixgbe_host_interface_command().
 - Add missing start_hw() call in ixv_init_locked(). This is not a real bug
   because start_hw just set hw->adapter_stopped to false and anyone refer it.
 - Style change.
 - Update comment.

Read sc_if_flags after taking core lock. Same as if_wm.c rev. 1.418.


To generate a diff of this commit:
cvs rdiff -u -r1.2.4.3 -r1.2.4.4 src/sys/dev/pci/ixgbe/if_bypass.c
cvs rdiff -u -r1.1.4.2 -r1.1.4.3 src/sys/dev/pci/ixgbe/if_fdir.c \
src/sys/dev/pci/ixgbe/ixgbe_fdir.h
cvs rdiff -u -r1.1.4.3 -r1.1.4.4 src/sys/dev/pci/ixgbe/if_sriov.c \
src/sys/dev/pci/ixgbe/ixgbe_sriov.h
cvs rdiff -u -r1.24.2.9 -r1.24.2.10 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.16 -r1.88.2.17 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.9 -r1.24.6.10 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.8.8.1 -r1.8.8.2 src/sys/dev/pci/ixgbe/ixgbe_82598.c \
src/sys/dev/pci/ixgbe/ixg

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-04-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Apr  4 16:18:49 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c ixgbe.c ixgbe.h
ixgbe_82599.c ixgbe_api.h ixgbe_common.c ixgbe_common.h
ixgbe_x550.c ixgbe_x550.h ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #690):
sys/dev/pci/ixgbe/ixgbe_82599.c: revision 1.17
sys/dev/pci/ixgbe/ixgbe.c: revision 1.138
sys/dev/pci/ixgbe/ixv.c: revision 1.90
sys/dev/pci/ixgbe/ixgbe.c: revision 1.139
sys/dev/pci/ixgbe/ixgbe_common.c: revision 1.19
sys/dev/pci/ixgbe/ixgbe_common.h: revision 1.11
sys/dev/pci/ixgbe/ixgbe.h: revision 1.38
sys/dev/pci/ixgbe/ixgbe_api.h: revision 1.12
sys/dev/pci/ixgbe/ixgbe.h: revision 1.39
sys/dev/pci/ixgbe/ixgbe_x550.c: revision 1.10
sys/dev/pci/ixgbe/ixgbe_x550.c: revision 1.11
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.37
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.38
sys/dev/pci/ixgbe/ixgbe.c: revision 1.140
sys/dev/pci/ixgbe/ixgbe_common.c: revision 1.20
sys/dev/pci/ixgbe/ixgbe.c: revision 1.141
sys/dev/pci/ixgbe/ixgbe.c: revision 1.142
sys/dev/pci/ixgbe/ixgbe.c: revision 1.143
sys/dev/pci/ixgbe/ixgbe.h: revision 1.40
sys/dev/pci/ixgbe/ixgbe_x550.h: revision 1.4

Fix the problem between eitr and link_speed.

In ixgbe_msix_que(), que->eitr_setting is limited to IXGBE_MIN_RSC_EITR_10G1G
when link_speed is 1Gbps or 10Gbps. However, que->eitr_setting is set to EITR
register in the *next* Tx/Rx interrupt. If link_speed changes from 100Mbps to
1Gbps ro 10Gbps, que->eitr_setting which is not limited can be set to EITR
register, that is, the problem fixed by ixgbe.c:r1.124 can occur in this case.

To fix this case, que->eitr_setting should be clear when link_speed is changed
or link state is changed.

Furthermore, expand the variants used for AIM (txr->bytes, txr->packets,
rxr->bytes and rxr->packets) from u32 to u64 to avoid wraparound which causes
que->eitr_setting calculation mistake.
XXX pullup-8

Don't write EIMC directly. It is required to manage with struct ix_queue status.
XXX pullup-8

-  Add missing IFM_NONE support. If a interface support linkdown,
  "ifconfig ixgN media none" drpos link.  Not all interface can do link down.
 Tested:
82598 AT2 (T)
92599 SF+(SFI) (X520-DA2)
X540
X550-T1
X550EM_x (X10SDV-8C-TLN4F)
X550EM_a (A2SDi-H-TP4F port 0, 1 (T))
 Doesn't work:
X550EM_a (A2SDi-H-TP4F port 2, 3 (SFP+ (KR)))
X550EM_a (MA10-ST0 port 2, 3 (SFP+ (SFI)))
(Denverton SFP+ can't force link down because SFP+'s TX_DISABLE pin is
pull down. Is there a way to shutdown SFP+ cage's power?)
 Not tested:
82598 fiber.
- Change some functions static.

Avoid issues caused by sending old packets at next link-up time.

This modification consists by the following two parts.
- drain packets in if_snd queue or corresponding txr->txr_interq
  when link_active == false in ifp->if_start(), ifp->if_transmit(),
  and deferred Tx processing
- drain packets in if_snd queue and all of txr->txr_interq's
  at link-down time
ok by msaitoh@n.o.

 Fix long standing bug that 82598 SFP+ panics in ixgbe_handle_mod() because
hw->mac.ops.setup_sfp is NULL. This change is a part of FreeBSD r327031.

Fix a bug that "ifconfig ixgN down up" forgot IFM_NONE setting.
 - Don't assume autoneg == 0 is the first call of ixgbe_config_link().
   Check ifm_media, too.
 - Don't override autoneg_advertised in ixgbe_get_phy_id_fw() to not to
   be inconsistent with if_media value.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.8 -r1.24.2.9 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.15 -r1.88.2.16 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.8 -r1.24.6.9 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.14.8.1 -r1.14.8.2 src/sys/dev/pci/ixgbe/ixgbe_82599.c
cvs rdiff -u -r1.9.8.1 -r1.9.8.2 src/sys/dev/pci/ixgbe/ixgbe_api.h
cvs rdiff -u -r1.13.2.2 -r1.13.2.3 src/sys/dev/pci/ixgbe/ixgbe_common.c
cvs rdiff -u -r1.7.8.2 -r1.7.8.3 src/sys/dev/pci/ixgbe/ixgbe_common.h
cvs rdiff -u -r1.5.6.2 -r1.5.6.3 src/sys/dev/pci/ixgbe/ixgbe_x550.c
cvs rdiff -u -r1.2.12.1 -r1.2.12.2 src/sys/dev/pci/ixgbe/ixgbe_x550.h
cvs rdiff -u -r1.56.2.12 -r1.56.2.13 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.24.2.8 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.9
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.8	Fri Mar 30 12:07:34 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Wed Apr  4 16:18:49 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.8 2018/03/30 12:07:34 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.9 2018/04/04 16:18:49 martin Exp $ */
 
 /***

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-03-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Mar 30 12:07:35 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: if_bypass.c if_sriov.c ix_txrx.c
ixgbe.c ixgbe.h ixgbe_common.c ixgbe_common.h ixgbe_osdep.c
ixgbe_osdep.h ixgbe_phy.c ixgbe_sriov.h ixgbe_type.h ixgbe_vf.h
ixgbe_x540.c ixgbe_x550.c ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #673):

sys/dev/pci/ixgbe/if_sriov.c: revision 1.2
sys/dev/pci/ixgbe/ixgbe.c: revision 1.135
sys/dev/pci/ixgbe/ixgbe.c: revision 1.136
sys/dev/pci/ixgbe/ixgbe.c: revision 1.137
sys/dev/pci/ixgbe/ixgbe_common.c: revision 1.17
sys/dev/pci/ixgbe/if_bypass.c: revision 1.3
sys/dev/pci/ixgbe/ixgbe_common.c: revision 1.18
sys/dev/pci/ixgbe/ixgbe_common.h: revision 1.10
sys/dev/pci/ixgbe/ixgbe.h: revision 1.36
sys/dev/pci/ixgbe/ixgbe_osdep.c: revision 1.3
sys/dev/pci/ixgbe/ixgbe.h: revision 1.37
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.36
sys/dev/pci/ixgbe/ixgbe_type.h: revision 1.32
sys/dev/pci/ixgbe/ixgbe_vf.h: revision 1.12
sys/dev/pci/ixgbe/ixgbe_sriov.h: revision 1.2
sys/dev/pci/ixgbe/ixgbe_osdep.h: revision 1.20
sys/dev/pci/ixgbe/ixv.c: revision 1.88
sys/dev/pci/ixgbe/ixgbe_phy.c: revision 1.15
sys/dev/pci/ixgbe/ixv.c: revision 1.89
sys/dev/pci/ixgbe/ixgbe_x540.c: revision 1.13
sys/dev/pci/ixgbe/ixgbe_x550.c: revision 1.8
sys/dev/pci/ixgbe/ixgbe_x550.c: revision 1.9

Add some changes from ix-3.2.17.tar.gz and r328265. Not fully synchronized.

Some others (e.g. sfp cage interrupt and bypass adapter  stuff) will be merged
later:

- Initialize firmware command buffer correctly in ixgbe_read_ee_hostif_X550()
  and ixgbe_read_ee_hostif_buffer_X550(). These functions are used when reading
  NVM.
- Fix a bug that ixgbe_mng_present() misunderstand management capability on
  X550 and newer on some environment. X550 changed FWSM bit definition.
  See X540 document and X550's document and compare them.
- Fix checksum calculation in ixgbe_set_fw_drv_ver_generic(). This function is
  not used in NetBSD.
- Add some unused funtions.
- Whitespace fix.
- Check offset correctly in ixgbe_get_oem_prod_version(). Note that this
  function is not used.
- Set PHY correctly in ixgbe_setup_mac_link_sfp_x550a() if a device is a
  C3000 KR SFP+.

Fix race about writing adapter->link_active for ixg(4).
adapter->link_active is updated by ixgbe_update_link_status() only.

The function is called from the following four functions.
- ixgbe_media_status()
- ixgbe_local_timer1()
- ixgbe_stop()
- ixgbe_handle_link()

The functions other than ixgbe_handle_link() call ixgbe_update_link_status()
with holding IXGBE_CORE_LOCK, however ixgbe_handle_link() calls it without
holding IXGBE_CORE_LOCK. That can cause race. So, add IXGBE_CORE_LOCK to
ixgbe_handle_link().

Tested by msaitoh@n.o and me.

Fix race about writing adapter->link_active for ixv(4).
adapter->link_active is updated by ixv_update_link_status() only.

The function is called from the following two functions.
- ixv_media_status()
- ixv_handle_link()

ixv_media_status() calls ixv_update_link_status() with holding
IXGBE_CORE_LOCK, however ixv_handle_link() calls it without
holding IXGBE_CORE_LOCK, the same as ixg(4).

ok by msaitoh@n.o.

- Add link related softint's counter.
- Fix indent.


To generate a diff of this commit:
cvs rdiff -u -r1.2.4.2 -r1.2.4.3 src/sys/dev/pci/ixgbe/if_bypass.c
cvs rdiff -u -r1.1.4.2 -r1.1.4.3 src/sys/dev/pci/ixgbe/if_sriov.c \
src/sys/dev/pci/ixgbe/ixgbe_sriov.h
cvs rdiff -u -r1.24.2.7 -r1.24.2.8 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.14 -r1.88.2.15 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.7 -r1.24.6.8 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.13.2.1 -r1.13.2.2 src/sys/dev/pci/ixgbe/ixgbe_common.c
cvs rdiff -u -r1.7.8.1 -r1.7.8.2 src/sys/dev/pci/ixgbe/ixgbe_common.h
cvs rdiff -u -r1.1.12.1 -r1.1.12.2 src/sys/dev/pci/ixgbe/ixgbe_osdep.c
cvs rdiff -u -r1.17.6.1 -r1.17.6.2 src/sys/dev/pci/ixgbe/ixgbe_osdep.h
cvs rdiff -u -r1.11.6.1 -r1.11.6.2 src/sys/dev/pci/ixgbe/ixgbe_phy.c
cvs rdiff -u -r1.22.2.3 -r1.22.2.4 src/sys/dev/pci/ixgbe/ixgbe_type.h
cvs rdiff -u -r1.8.6.1 -r1.8.6.2 src/sys/dev/pci/ixgbe/ixgbe_vf.h
cvs rdiff -u -r1.9.6.1 -r1.9.6.2 src/sys/dev/pci/ixgbe/ixgbe_x540.c
cvs rdiff -u -r1.5.6.1 -r1.5.6.2 src/sys/dev/pci/ixgbe/ixgbe_x550.c
cvs rdiff -u -r1.56.2.11 -r1.56.2.12 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/if_bypass.c
diff -u src/sys/dev/pci/ixgbe/if_bypass.c:1.2.4.2 src/sys/dev/pci/ixgbe/if_bypass.c:1.2.4.3
--- src/sys/dev/pci/ixgbe/if_bypass.c:1.2.4.2	Thu Dec 21 19:28:54 2017
+++ src/sys/dev/pci/ixgbe/if_bypass.c	Fri Mar 30 12:07:34 2

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-03-13 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Mar 13 14:59:06 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c ixgbe.c ixgbe.h ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #626):
sys/dev/pci/ixgbe/ixgbe.c: revision 1.134
sys/dev/pci/ixgbe/ixgbe.h: revision 1.35
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.35
sys/dev/pci/ixgbe/ixv.c: revision 1.87
  Make some event counters MP safe. Now all of the event counters are
MP safe.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.6 -r1.24.2.7 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.13 -r1.88.2.14 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.6 -r1.24.6.7 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.56.2.10 -r1.56.2.11 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.24.2.6 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.7
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.6	Tue Mar  6 11:12:40 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Tue Mar 13 14:59:06 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.6 2018/03/06 11:12:40 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.7 2018/03/13 14:59:06 martin Exp $ */
 
 /**
 
@@ -392,10 +392,10 @@ retry:
 
 		switch (error) {
 		case EAGAIN:
-			adapter->eagain_tx_dma_setup.ev_count++;
+			txr->q_eagain_tx_dma_setup++;
 			return EAGAIN;
 		case ENOMEM:
-			adapter->enomem_tx_dma_setup.ev_count++;
+			txr->q_enomem_tx_dma_setup++;
 			return EAGAIN;
 		case EFBIG:
 			/* Try it again? - one try */
@@ -405,23 +405,23 @@ retry:
  * XXX: m_defrag will choke on
  * non-MCLBYTES-sized clusters
  */
-adapter->efbig_tx_dma_setup.ev_count++;
+txr->q_efbig_tx_dma_setup++;
 m = m_defrag(m_head, M_NOWAIT);
 if (m == NULL) {
-	adapter->mbuf_defrag_failed.ev_count++;
+	txr->q_mbuf_defrag_failed++;
 	return ENOBUFS;
 }
 m_head = m;
 goto retry;
 			} else {
-adapter->efbig2_tx_dma_setup.ev_count++;
+txr->q_efbig2_tx_dma_setup++;
 return error;
 			}
 		case EINVAL:
-			adapter->einval_tx_dma_setup.ev_count++;
+			txr->q_einval_tx_dma_setup++;
 			return error;
 		default:
-			adapter->other_tx_dma_setup.ev_count++;
+			txr->q_other_tx_dma_setup++;
 			return error;
 		}
 	}

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.13 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.14
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.13	Thu Mar  8 12:31:25 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Tue Mar 13 14:59:06 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.13 2018/03/08 12:31:25 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.14 2018/03/13 14:59:06 martin Exp $ */
 
 /**
 
@@ -1980,8 +1980,8 @@ ixgbe_clear_evcnt(struct adapter *adapte
 	adapter->other_tx_dma_setup.ev_count = 0;
 	adapter->eagain_tx_dma_setup.ev_count = 0;
 	adapter->enomem_tx_dma_setup.ev_count = 0;
-	adapter->watchdog_events.ev_count = 0;
 	adapter->tso_err.ev_count = 0;
+	adapter->watchdog_events.ev_count = 0;
 	adapter->link_irq.ev_count = 0;
 
 	txr = adapter->tx_rings;
@@ -1995,6 +1995,14 @@ ixgbe_clear_evcnt(struct adapter *adapte
 #ifndef IXGBE_LEGACY_TX
 		txr->pcq_drops.ev_count = 0;
 #endif
+		txr->q_efbig_tx_dma_setup = 0;
+		txr->q_mbuf_defrag_failed = 0;
+		txr->q_efbig2_tx_dma_setup = 0;
+		txr->q_einval_tx_dma_setup = 0;
+		txr->q_other_tx_dma_setup = 0;
+		txr->q_eagain_tx_dma_setup = 0;
+		txr->q_enomem_tx_dma_setup = 0;
+		txr->q_tso_err = 0;
 
 		if (i < __arraycount(stats->mpc)) {
 			stats->mpc[i].ev_count = 0;
@@ -4190,7 +4198,9 @@ ixgbe_local_timer1(void *arg)
 	device_t	dev = adapter->dev;
 	struct ix_queue *que = adapter->queues;
 	u64		queues = 0;
+	u64		v0, v1, v2, v3, v4, v5, v6, v7;
 	int		hung = 0;
+	int		i;
 
 	KASSERT(mutex_owned(&adapter->core_mtx));
 
@@ -4202,12 +4212,37 @@ ixgbe_local_timer1(void *arg)
 	ixgbe_update_link_status(adapter);
 	ixgbe_update_stats_counters(adapter);
 
+	/* Update some event counters */
+	v0 = v1 = v2 = v3 = v4 = v5 = v6 = v7 = 0;
+	que = adapter->queues;
+	for (i = 0; i < adapter->num_queues; i++, que++) {
+		struct tx_ring  *txr = que->txr;
+
+		v0 += txr->q_efbig_tx_dma_setup;
+		v1 += txr->q_mbuf_defrag_failed;
+		v2 += txr->q_efbig2_tx_dma_setup;
+		v3 += txr->q_einval_tx_dma_setup;
+		v4 += txr->q_other_tx_dma_setup;
+		v5 += txr->q_eagain_tx_dma_setup;
+		v6 += txr->q_enomem_tx_dma_setup;
+		v7 += txr->q_tso_err;
+	}
+	adapter->efbig_tx_dma_setup.ev_count = v0;
+	adapter->mbuf_defrag_failed.ev_count = v1;
+	adapter->efbig2_tx_dma_setup.ev_count = v2;
+	adapter->einval_tx_dma_setup.ev_count = v3;
+	adapter->other_tx_dma_setup.ev_count = v4;
+	adapter->eagain_tx_dma_se

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-03-08 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Mar  8 12:31:25 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixgbe.h ixv.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #612):
sys/dev/pci/ixgbe/ixgbe.c: revision 1.129-1.133
sys/dev/pci/ixgbe/ixgbe.h: revision 1.34
sys/dev/pci/ixgbe/ixv.c: revision 1.85,1.86

- Make "Handled queue in softint" and "Requeued in softint" evcnt(9) per queue
  and count them correctly.
- Remove #if 0'ed code.

Don't increment que->req.ev_count in MSI-X interrupt because it's not
reschedule.

Fix another poll mode assumption breaking. Implemented by msaitoh@n.o, I just 
commit by proxy.
ixgbe_rearm_queues() writes EICS register(s). 82599, X540 and X550
specifications say "Following a write of 1b to any bit in the EICS register
(interrupt cause set), its corresponding bit in the EIMS register is auto
set as well enabling its interrupt." in "Extended Interrupt Auto Mask Enable
(EIAM) Register" section. That is, ixgbe_rearm_queues() causes interrupts
regardless of the status managed by ixgbe_enable_queue()/ixgbe_disable_queue().

That can break poll mode assumption.

In fact, the problem occurs in the following situation
- CPU#A has high load traffic, in contrast, CPU#B has not so high load 
traffic
- CPU#A is occurred interrupt by its NIC queue
  - CPU#A calls ixgbe_disable_queue() in interrupt handler(ixgbe_msix_que())
  - CPU#A kick softint handler(ixgbe_handle_que())
- CPU#A begins softint
- CPU#A's NIC queue is set que->txr->busy flag
- With some reason, CPU#A can do ixg interrupt handler
  E.g. when one of CPU#A's softnet handlers sleeps, ipl is lowered
- CPU#B starts callout
  - CPU#B calls ixgbe_local_timer1()
- CPU#B writes EICS bit corresponding CPU#A's NIC queue bit
- CPU#A's NIC queue causes interrupt whie CPU#A is running in poll mode
  - CPU#A calls ixgbe_disable_queue() in interrupt handler *again*
- CPU#A has done polling, and then CPU#A calls ixgbe_enable_queue() *once*
- CPU#A's NIC queue interrupt is disabled until ixg is detached as
  ixgbe_disable_queue() is called twice though ixgbe_disable_queue() is
  called once only
NOTE:
82598 does not say so, but it is treated in the same way because of no harm.
By the way, we will refactor ixgbe_local_timer(watchdog processing) later.

Fix INTx/MSI handler did not schedule workqueue. Pointed out by msaitoh@n.o.

Reduce duplicated code which schedule deferred packet processing. No functional 
change.


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.12 -r1.88.2.13 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.5 -r1.24.6.6 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.56.2.9 -r1.56.2.10 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/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.12 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.13
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.12	Tue Mar  6 11:12:41 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Mar  8 12:31:25 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.12 2018/03/06 11:12:41 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.13 2018/03/08 12:31:25 martin Exp $ */
 
 /**
 
@@ -1686,10 +1686,6 @@ ixgbe_add_hw_stats(struct adapter *adapt
 	const char *xname = device_xname(dev);
 
 	/* Driver Statistics */
-	evcnt_attach_dynamic(&adapter->handleq, EVCNT_TYPE_MISC,
-	NULL, xname, "Handled queue in softint");
-	evcnt_attach_dynamic(&adapter->req, EVCNT_TYPE_MISC,
-	NULL, xname, "Requeued in softint");
 	evcnt_attach_dynamic(&adapter->efbig_tx_dma_setup, EVCNT_TYPE_MISC,
 	NULL, xname, "Driver tx dma soft fail EFBIG");
 	evcnt_attach_dynamic(&adapter->mbuf_defrag_failed, EVCNT_TYPE_MISC,
@@ -1736,15 +1732,6 @@ ixgbe_add_hw_stats(struct adapter *adapt
 		(void *)&adapter->queues[i], 0, CTL_CREATE, CTL_EOL) != 0)
 			break;
 
-#if 0 /* XXX msaitoh */
-		if (sysctl_createv(log, 0, &rnode, &cnode,
-		CTLFLAG_READONLY, CTLTYPE_QUAD,
-		"irqs", SYSCTL_DESCR("irqs on this queue"),
-			NULL, 0, &(adapter->queues[i].irqs),
-		0, CTL_CREATE, CTL_EOL) != 0)
-			break;
-#endif
-
 		if (sysctl_createv(log, 0, &rnode, &cnode,
 		CTLFLAG_READONLY, CTLTYPE_INT,
 		"txd_head", SYSCTL_DESCR("Transmit Descriptor Head"),
@@ -1761,6 +1748,11 @@ ixgbe_add_hw_stats(struct adapter *adapt
 
 		evcnt_attach_dynamic(&adapter->queues[i].irqs, EVCNT_TYPE_INTR,
 		NULL, adapter->queues[i].evnamebuf, "IRQs on queue");
+		evcnt_attach_dynamic(&adapter->queues[i].handleq,
+		EVCNT_TYPE_MISC, NULL, adapter->queues[i].evnamebuf,
+		"Handled queue in softint");
+		evcnt_attach_dynamic(&adapter->queues[i].req, EVCNT_TYPE_MISC,
+		NULL, adapter->queues[i].evname

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-03-06 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Mar  6 11:12:41 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c ixgbe.c ixgbe.h ixv.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #605):
sys/dev/pci/ixgbe/ixgbe.h: revision 1.32
sys/dev/pci/ixgbe/ixgbe.h: revision 1.33
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.34
sys/dev/pci/ixgbe/ixgbe.c: revision 1.128
sys/dev/pci/ixgbe/ixv.c: revision 1.83
sys/dev/pci/ixgbe/ixv.c: revision 1.84

Add hw.ixvM.q[01].{interrupt_rate,[tr]xd_head,[tr]xd_tail} sysctls as ixg(4).

ixg(4) supports workqueue poll mode, but not enabled by default yet. (that is, 
the default behavior is *not* changed)

At the time of high load near the wire rate, the turnaround time
of update/delete processing such as "ifconfig ixg0 inet XXX" or
"ifconfig ixg0 delete" is very long. The main reason is CPU
starvation caused by ixg(4)'s softint poll mode. ixg(4) uses
workqueue poll mode instead of softint poll mode, so that this
problem will be fix.

This change may cause performance issues, so it is not enabled
by default yet. Although there are that issues, if you want to use
workqueue poll mode, do "sysctl -w hw.ixgXX.txrx_workqueue=1" while
there is no traffic on the ixgXX.

ok by msaitoh@n.o.

ixv(4) also supports workqueue poll mode, but not enabled by default yet, 
either.
ok by msaitoh@n.o.

Move the location of "struct work" as FreeBSD's "struct task" in ixgbe.h.
No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.5 -r1.24.2.6 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.11 -r1.88.2.12 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.4 -r1.24.6.5 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.56.2.8 -r1.56.2.9 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.24.2.5 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.6
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.5	Thu Mar  1 19:02:15 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Tue Mar  6 11:12:40 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.5 2018/03/01 19:02:15 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.6 2018/03/06 11:12:40 martin Exp $ */
 
 /**
 
@@ -238,8 +238,26 @@ ixgbe_mq_start(struct ifnet *ifp, struct
 	if (IXGBE_TX_TRYLOCK(txr)) {
 		ixgbe_mq_start_locked(ifp, txr);
 		IXGBE_TX_UNLOCK(txr);
-	} else
-		softint_schedule(txr->txr_si);
+	} else {
+		if (adapter->txrx_use_workqueue) {
+			/*
+			 * This function itself is not called in interrupt
+			 * context, however it can be called in fast softint
+			 * context right after receiving forwarding packets.
+			 * So, it is required to protect workqueue from twice
+			 * enqueuing when the machine uses both spontaneous
+			 * packets and forwarding packets.
+			 */
+			u_int *enqueued = percpu_getref(adapter->txr_wq_enqueued);
+			if (*enqueued == 0) {
+*enqueued = 1;
+percpu_putref(adapter->txr_wq_enqueued);
+workqueue_enqueue(adapter->txr_wq, &txr->wq_cookie, curcpu());
+			} else
+percpu_putref(adapter->txr_wq_enqueued);
+		} else
+			softint_schedule(txr->txr_si);
+	}
 
 	return (0);
 } /* ixgbe_mq_start */
@@ -291,7 +309,8 @@ ixgbe_mq_start_locked(struct ifnet *ifp,
 /
  * ixgbe_deferred_mq_start
  *
- *   Called from a taskqueue to drain queued transmit packets.
+ *   Called from a softint and workqueue (indirectly) to drain queued
+ *   transmit packets.
  /
 void
 ixgbe_deferred_mq_start(void *arg)
@@ -307,6 +326,24 @@ ixgbe_deferred_mq_start(void *arg)
 } /* ixgbe_deferred_mq_start */
 
 /
+ * ixgbe_deferred_mq_start_work
+ *
+ *   Called from a workqueue to drain queued transmit packets.
+ /
+void
+ixgbe_deferred_mq_start_work(struct work *wk, void *arg)
+{
+	struct tx_ring *txr = container_of(wk, struct tx_ring, wq_cookie);
+	struct adapter *adapter = txr->adapter;
+	u_int *enqueued = percpu_getref(adapter->txr_wq_enqueued);
+	*enqueued = 0;
+	percpu_putref(adapter->txr_wq_enqueued);
+
+	ixgbe_deferred_mq_start(txr);
+} /* ixgbe_deferred_mq_start */
+
+
+/
  * ixgbe_xmit
  *
  *   Maps the mbufs to tx descriptors, allowing the

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.11 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.12
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.11	Thu Mar  1 19:02:15 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Tue Mar  6 11:12:41 2018
@@ -1,4 +1,4 @

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-03-01 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Mar  1 19:02:15 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c ixgbe.c ixgbe.h ixv.c

Log Message:
Pull up following revision(s) (requested by knakahara in ticket #597):
sys/dev/pci/ixgbe/ixgbe.h: revision 1.31
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.33
sys/dev/pci/ixgbe/ixgbe.c: revision 1.127
sys/dev/pci/ixgbe/ixv.c: revision 1.82
Fix poll mode assumption breaking.
ixgbe_{enable,disable}_intr() forcibly enable/disable all interrupts
regardless of current state. That can break poll mode assumption,
that is, queue interrupts must not occur while polling Tx/Rx rings.
E.g. "ifconfig ixg0 delete && ifconfig ixg0 192.168.0.1" on heavy
load traffic can causes this issue.
This fix may have 1% or 2% performance impact at short packets.
XXX
ixgbe_rearm_queues() which is called only via watchdog can also break
this poll mode assumption because writing EICS casues interrupts
immediately when interrupt auto mask enabled.
We will fix it with other issues about watchdog later.
ok by msaitoh@n.o.
Apply ixgbe.c:r1.127 to ixv.c. Pointed out by msaitoh@n.o.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.4 -r1.24.2.5 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.10 -r1.88.2.11 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.3 -r1.24.6.4 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.56.2.7 -r1.56.2.8 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.24.2.4 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.5
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.4	Mon Feb 26 13:55:54 2018
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Thu Mar  1 19:02:15 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ix_txrx.c,v 1.24.2.4 2018/02/26 13:55:54 martin Exp $ */
+/* $NetBSD: ix_txrx.c,v 1.24.2.5 2018/03/01 19:02:15 martin Exp $ */
 
 /**
 
@@ -2260,6 +2260,9 @@ ixgbe_allocate_queues(struct adapter *ad
 		que->me = i;
 		que->txr = &adapter->tx_rings[i];
 		que->rxr = &adapter->rx_rings[i];
+
+		mutex_init(&que->im_mtx, MUTEX_DEFAULT, IPL_NET);
+		que->im_nest = 0;
 	}
 
 	return (0);

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.10 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.11
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.10	Mon Feb 26 13:55:54 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Mar  1 19:02:15 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.10 2018/02/26 13:55:54 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.11 2018/03/01 19:02:15 martin Exp $ */
 
 /**
 
@@ -2384,9 +2384,14 @@ static inline void
 ixgbe_enable_queue(struct adapter *adapter, u32 vector)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
+	struct ix_queue *que = &adapter->queues[vector];
 	u64 queue = (u64)(1ULL << vector);
 	u32 mask;
 
+	mutex_enter(&que->im_mtx);
+	if (que->im_nest > 0 && --que->im_nest > 0)
+		goto out;
+
 	if (hw->mac.type == ixgbe_mac_82598EB) {
 		mask = (IXGBE_EIMS_RTX_QUEUE & queue);
 		IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
@@ -2398,6 +2403,8 @@ ixgbe_enable_queue(struct adapter *adapt
 		if (mask)
 			IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
 	}
+out:
+	mutex_exit(&que->im_mtx);
 } /* ixgbe_enable_queue */
 
 /
@@ -2407,9 +2414,14 @@ static inline void
 ixgbe_disable_queue(struct adapter *adapter, u32 vector)
 {
 	struct ixgbe_hw *hw = &adapter->hw;
+	struct ix_queue *que = &adapter->queues[vector];
 	u64 queue = (u64)(1ULL << vector);
 	u32 mask;
 
+	mutex_enter(&que->im_mtx);
+	if (que->im_nest++ > 0)
+		goto  out;
+
 	if (hw->mac.type == ixgbe_mac_82598EB) {
 		mask = (IXGBE_EIMS_RTX_QUEUE & queue);
 		IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
@@ -2421,6 +2433,8 @@ ixgbe_disable_queue(struct adapter *adap
 		if (mask)
 			IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
 	}
+out:
+	mutex_exit(&que->im_mtx);
 } /* ixgbe_disable_queue */
 
 /
@@ -3427,6 +3441,10 @@ ixgbe_detach(device_t dev, int flags)
 
 	ixgbe_free_transmit_structures(adapter);
 	ixgbe_free_receive_structures(adapter);
+	for (int i = 0; i < adapter->num_queues; i++) {
+		struct ix_queue * que = &adapter->queues[i];
+		mutex_destroy(&que->im_mtx);
+	}
 	free(adapter->queues, M_DEVBUF);
 	free(adapter->mta, M_DEVBUF);
 
@@ -4568,15 +4586,17 @@ ixgbe_enable_intr(struct adapter *adapte
 static void
 ixgbe_disable_intr(struct adapter *adapter)
 {
+	struct ix_queue	*que = adapter->queues;
+
+	/* disable interrupts other than queues */
+	IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~IXGBE_EIMC_RTX_QUEUE);
+
 	if (adapter->msix_mem

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-02-26 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Mon Feb 26 13:55:54 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c ixgbe.c ixgbe.h
ixgbe_type.h ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #592):
sys/dev/pci/ixgbe/ixv.c: revision 1.79
sys/dev/pci/ixgbe/ixgbe.h: revision 1.30
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.31
sys/dev/pci/ixgbe/ix_txrx.c: revision 1.32
sys/dev/pci/ixgbe/ixgbe_type.h: revision 1.31
sys/dev/pci/ixgbe/ixgbe.c: revision 1.120
sys/dev/pci/ixgbe/ixgbe.c: revision 1.121
sys/dev/pci/ixgbe/ixgbe.c: revision 1.123
sys/dev/pci/ixgbe/ixgbe.c: revision 1.124
sys/dev/pci/ixgbe/ixgbe.c: revision 1.125
sys/dev/pci/ixgbe/ixgbe.c: revision 1.126
sys/dev/pci/ixgbe/ixv.c: revision 1.80
sys/dev/pci/ixgbe/ixv.c: revision 1.81
 CID-1427719: Integer handling issues  (BAD_SHIFT). Print bus/slot info
correctly on 82599_SFP_SF_QP(DID 0x154a) and 82599_QSFP_SF_QP(DID 0x1558).
 Fix a bug that RX may stall on heavy load on ixg(4). ixgbe_rxeof() has loop
limit and the function returns true if a packet are still in the RX ring.
ixgbe_handle_que() didn't check the return value. Check the return vaule
and issue a softint.
 This bug is derived from FreeBSD and ixv(4) has no this bug.
XXX pullup-8
 Fix a bug that the first call of ifflags_cb() causes linkdown. The first
call of ix(gbe|v)_ifflags_cb() refered uninitialized adapter->if_flags.
adapter->if_flags should be initialized in the end of xxx_init().
XXX pullup-[678] (ixgbe)
XXX pullup-8 (ixv)
- Fix a bug that RX may stall on heavy load on ixg(4) derived from FreeBSD's
 AIM (Auto Interrupt Moderation) bug.
 When I use a machine as a NFS client, sometimes one of queue pairs doesn't
 get any interrupt other than every second tick via ixgbe_local_timer1().
 When the problem occured, the queue pair's hw.ixgM.qN.interrupt_rate is
 always 50. When this problem occuring, set hw.ixgM.qN.interrupt_rate lower
 than 17 recover from stall. i.e.:
  sysctl -w hw.ixgM.qN.interrupt_rate=17 (don't revocer)
  sysctl -w hw.ixgM.qN.interrupt_rate=16 (recover)
  Relatios between the interrupt_rate and EICR's ITR_INTERVAL field is as
 follows:
 int_rate | EICR[11:0]   | interval in us | recover |
  |(ITR_INTERVAL)| (10G and 1G)   | |
 -+--++-+
   50 | 0x008(0) |  2 | not |
   17 | 0x010(1) |  4 | not |
   16 | 0x018(2) |  6 | recover |
  The reason why int_rate becomes 50 is that xgbe_tx_eof() doesn't
 increment rxr->packets(*1). Even if we fix rxr->packets' bug, interrupt_rate
 might become greater than 16 and it might cause stall.
  While reading datasheets, knakahara noticed a section titled with "ITR
 Affect on RSC Functionality". It says "When RSC is enabled on specific RX
 queues, the associated ITR interval with these queus must be enabled and must
 be larger (in time uints) than RSC delay". Currently, RSC_DELAY field in the
 GPIE register is 0 and it means 4us for 10G and 1G. The greater ITR_INTERVAL
 value of 4us is 6us == 16. Yes, BINGO!
  This description is noted in 82599 and newer datasheets and not in 82598
 datasheet. I don't know if 82598 has this limitation but, I apply this
 limitation all of chips.
 (*1) Note that this bug is going to be fixed in the next commit to distinct
 between two different bugs.
- The bitfield of EITR register is different between 82598 and others.
 Only ixgbe_msix_que() taken care of it. Make new function ixgbe_eitr_write()
 and use it in all of functions which modify ITR_INTERVAL.
XXX pullup-8
 Increment rxr->packets correctly in ixgbe_rxeof() to calculate ITR value
of AIM (Auto Interrupt Moderation) correctly. See also ixgbe.c rev. 1.124.
XXX pullup-8
Improve a comment about reading EICS register defined write-only by spec.
It seems that is workaround for silicon errata.
ok by msaitoh@n.o.
- Apply ixgbe.c rev. 1.124 to ixv.c. Fix a bug that RX may stall on heavy load
 on ixv(4) derived from FreeBSD's AIM (Auto Interrupt Moderation) bug.
 ITR_INTERVAL value must be larger than 4us.
- The bitfield of EITR register is different between 82598 and others.
 ixv.c had a bug that it accessed 82598's way even though only 82599 and
 newer support virtual function. Fix it using with new ixv_eitr_write()
 function.
 Fix a potential bug that TX/RX might stall when TX rate limit reached.
This change is almost the same as the RX rate limit bug fix in ixgbe.c
rev. 1.121. I've never got any stall, but this must be a bug.


To generate a diff of this commit:
cvs rdiff -u -r1.24.2.3 -r1.24.2.4 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.9 -r1.88.2.10 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24.6.2 -r1.24.6.3 src/sys/dev/pci/ixgbe/ixgbe.h
cvs rdiff -u -r1.22.2.2 -r1.22.2.3 src/sys/dev/pci/ixgbe/ixgb

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2018-01-13 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sat Jan 13 21:40:01 UTC 2018

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #490):
sys/dev/pci/ixgbe/ixgbe.c: revision 1.116-1.119
sys/dev/pci/ixgbe/ixv.c: revision 1.76-1.77
Don't panic when resource shortage occured. Fixes PR#52820 reported by
kardel@:
 - Don't use if_free() because ixgbe(4) don't use if_alloc().
 - Move location of {ixgbe,ixv}_setup_interface() call at a position that
   any error don't occur. One of the reason is that it should be. Another
   reason is that it's hard to call ether_ifdetach() and if_detach() when
   cold == 1 (because of pserialize_perform, xc_wait, timing of domaininit
   and maybe more).
--
Don't panic when resource shortage occured. Like ixgbe.c rev. 1.116.
 - Move location of {ixgbe,ixv}_setup_interface() call at a position that
   any error don't occur. One of the reason is that it should be. Another
   reason is that it's hard to call ether_ifdetach() and if_detach() when
   cold == 1 (because of pserialize_perform, xc_wait, timing of domaininit
   and maybe more).
--
Fix panic when only link interrupt can't be established.
--
- If MSI can't be used on some environment, fallback to INTx correctly.
- Use single vector MSI when number of CPU is 1 to save interrupt slot.
--
Fallback from MSI-X to MSI or INTx if MSI-X setup failed.


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.7 -r1.88.2.8 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.56.2.4 -r1.56.2.5 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/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.7 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.8
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.7	Tue Jan  2 10:20:33 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Sat Jan 13 21:40:01 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.7 2018/01/02 10:20:33 snj Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.8 2018/01/13 21:40:01 snj Exp $ */
 
 /**
 
@@ -172,12 +172,14 @@ static void ixgbe_media_status(struc
 static int  ixgbe_media_change(struct ifnet *);
 static int  ixgbe_allocate_pci_resources(struct adapter *,
 		const struct pci_attach_args *);
+static void  ixgbe_free_softint(struct adapter *);
 static void	ixgbe_get_slot_info(struct adapter *);
 static int  ixgbe_allocate_msix(struct adapter *,
 		const struct pci_attach_args *);
 static int  ixgbe_allocate_legacy(struct adapter *,
 		const struct pci_attach_args *);
 static int  ixgbe_configure_interrupts(struct adapter *);
+static void	ixgbe_free_pciintr_resources(struct adapter *);
 static void	ixgbe_free_pci_resources(struct adapter *);
 static void	ixgbe_local_timer(void *);
 static void	ixgbe_local_timer1(void *);
@@ -1043,17 +1045,54 @@ ixgbe_attach(device_t parent, device_t d
 	hw->eeprom.ops.read(hw, IXGBE_ETRACKID_L, &low);
 	aprint_normal(" ETrackID %08x\n", ((uint32_t)high << 16) | low);
 
-	/* Setup OS specific network interface */
-	if (ixgbe_setup_interface(dev, adapter) != 0)
-		goto err_late;
-
-	if (adapter->feat_en & IXGBE_FEATURE_MSIX)
+	if (adapter->feat_en & IXGBE_FEATURE_MSIX) {
 		error = ixgbe_allocate_msix(adapter, pa);
-	else
+		if (error) {
+			/* Free allocated queue structures first */
+			ixgbe_free_transmit_structures(adapter);
+			ixgbe_free_receive_structures(adapter);
+			free(adapter->queues, M_DEVBUF);
+
+			/* Fallback to legacy interrupt */
+			adapter->feat_en &= ~IXGBE_FEATURE_MSIX;
+			if (adapter->feat_cap & IXGBE_FEATURE_MSI)
+adapter->feat_en |= IXGBE_FEATURE_MSI;
+			adapter->num_queues = 1;
+
+			/* Allocate our TX/RX Queues again */
+			if (ixgbe_allocate_queues(adapter)) {
+error = ENOMEM;
+goto err_out;
+			}
+		}
+	}
+	if ((adapter->feat_en & IXGBE_FEATURE_MSIX) == 0)
 		error = ixgbe_allocate_legacy(adapter, pa);
 	if (error) 
 		goto err_late;
 
+	/* Tasklets for Link, SFP, Multispeed Fiber and Flow Director */
+	adapter->link_si = softint_establish(SOFTINT_NET |IXGBE_SOFTINFT_FLAGS,
+	ixgbe_handle_link, adapter);
+	adapter->mod_si = softint_establish(SOFTINT_NET | IXGBE_SOFTINFT_FLAGS,
+	ixgbe_handle_mod, adapter);
+	adapter->msf_si = softint_establish(SOFTINT_NET | IXGBE_SOFTINFT_FLAGS,
+	ixgbe_handle_msf, adapter);
+	adapter->phy_si = softint_establish(SOFTINT_NET | IXGBE_SOFTINFT_FLAGS,
+	ixgbe_handle_phy, adapter);
+	if (adapter->feat_en & IXGBE_FEATURE_FDIR)
+		adapter->fdir_si =
+		softint_establish(SOFTINT_NET | IXGBE_SOFTINFT_FLAGS,
+			ixgbe_reinit_fdir, adapter);
+	if ((adapter->link_si == NULL) || (adapter->mod_si == NULL)
+	|| (adapter->msf_si == NULL) || (adapter->phy_si == NULL)
+	|| ((adapter->feat_en & IXGBE_FEATURE_FDIR)
+		&& (adapter->fdir_si == N

CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2017-11-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Nov 21 11:38:19 UTC 2017

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c

Log Message:
Revert the pullup of the following revision(s) (requested by msaitoh in ticket 
#361):
sys/dev/pci/ixgbe/ixgbe.c: revision 1.97
Revert a part of ticket #248 because it panics when attaching.
It is hard to fix with a small change.


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.3 -r1.88.2.4 src/sys/dev/pci/ixgbe/ixgbe.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/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.3 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.4
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.3	Thu Aug 31 11:37:37 2017
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Tue Nov 21 11:38:19 2017
@@ -59,7 +59,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 /*$FreeBSD: head/sys/dev/ixgbe/if_ix.c 302384 2016-07-07 03:39:18Z sbruno $*/
-/*$NetBSD: ixgbe.c,v 1.88.2.3 2017/08/31 11:37:37 martin Exp $*/
+/*$NetBSD: ixgbe.c,v 1.88.2.4 2017/11/21 11:38:19 martin Exp $*/
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2960,7 +2960,6 @@ static int
 ixgbe_setup_msix(struct adapter *adapter)
 {
 	device_t dev = adapter->dev;
-	struct ixgbe_mac_info *mac = &adapter->hw.mac;
 	int want, queues, msgs;
 
 	/* Override by tuneable */
@@ -2987,9 +2986,8 @@ ixgbe_setup_msix(struct adapter *adapter
 	if (ixgbe_num_queues != 0)
 		queues = ixgbe_num_queues;
 	/* Set max queues to 8 when autoconfiguring */
-	else
-		queues = min(queues,
-		min(mac->max_tx_queues, mac->max_rx_queues));
+	else if ((ixgbe_num_queues == 0) && (queues > 8))
+		queues = 8;
 
 	/* reflect correct sysctl value */
 	ixgbe_num_queues = queues;



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2017-09-23 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sat Sep 23 17:47:34 UTC 2017

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixv.c

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #288):
sys/dev/pci/ixgbe/ixv.c: 1.59 and 1.62 via patch
- Use cprng_strong64() instead of cprng_fast64() to prevent panic.
- Set get_link_status to true before calling ixv_config_link() in
  ixv_init_locked() to get the first link status correctly.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.56.2.1 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/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.56 src/sys/dev/pci/ixgbe/ixv.c:1.56.2.1
--- src/sys/dev/pci/ixgbe/ixv.c:1.56	Fri May 26 09:17:32 2017
+++ src/sys/dev/pci/ixgbe/ixv.c	Sat Sep 23 17:47:34 2017
@@ -31,7 +31,7 @@
 
 **/
 /*$FreeBSD: head/sys/dev/ixgbe/if_ixv.c 302384 2016-07-07 03:39:18Z sbruno $*/
-/*$NetBSD: ixv.c,v 1.56 2017/05/26 09:17:32 msaitoh Exp $*/
+/*$NetBSD: ixv.c,v 1.56.2.1 2017/09/23 17:47:34 snj Exp $*/
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -430,7 +430,7 @@ ixv_attach(device_t parent, device_t dev
 	/* If no mac address was assigned, make a random one */
 	if (!ixv_check_ether_addr(hw->mac.addr)) {
 		u8 addr[ETHER_ADDR_LEN];
-		uint64_t rndval = cprng_fast64();
+		uint64_t rndval = cprng_strong64();
 
 		memcpy(addr, &rndval, sizeof(addr));
 		addr[0] &= 0xFE;
@@ -820,8 +820,8 @@ ixv_init_locked(struct adapter *adapter)
 	ixv_init_stats(adapter);
 
 	/* Config/Enable Link */
-	ixv_config_link(adapter);
 	hw->mac.get_link_status = TRUE;
+	ixv_config_link(adapter);
 
 	/* Start watchdog */
 	callout_reset(&adapter->timer, hz, ixv_local_timer, adapter);



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2017-08-31 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Aug 31 11:37:37 UTC 2017

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ixgbe.c ixgbe.h

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #248):
sys/dev/pci/ixgbe/ixgbe.h: revision 1.25
sys/dev/pci/ixgbe/ixgbe.c: revision 1.96
sys/dev/pci/ixgbe/ixgbe.c: revision 1.97
  Remove unused counters.
  Don't limit number of queue pair to 8. Take max TX queues and max RX queues
into account. 82598 has 32 TX queue and 64 RX queues. Others has 128 TX queues
and 128 RX queues. Number of MSI-X table entries is 64, so the max queue pairs
is 63 (64 minus the Others (e.g. link status change)).


To generate a diff of this commit:
cvs rdiff -u -r1.88.2.2 -r1.88.2.3 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.24 -r1.24.6.1 src/sys/dev/pci/ixgbe/ixgbe.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/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.2 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.3
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.2	Sat Aug  5 03:49:35 2017
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Thu Aug 31 11:37:37 2017
@@ -59,7 +59,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 /*$FreeBSD: head/sys/dev/ixgbe/if_ix.c 302384 2016-07-07 03:39:18Z sbruno $*/
-/*$NetBSD: ixgbe.c,v 1.88.2.2 2017/08/05 03:49:35 snj Exp $*/
+/*$NetBSD: ixgbe.c,v 1.88.2.3 2017/08/31 11:37:37 martin Exp $*/
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -2960,6 +2960,7 @@ static int
 ixgbe_setup_msix(struct adapter *adapter)
 {
 	device_t dev = adapter->dev;
+	struct ixgbe_mac_info *mac = &adapter->hw.mac;
 	int want, queues, msgs;
 
 	/* Override by tuneable */
@@ -2986,8 +2987,9 @@ ixgbe_setup_msix(struct adapter *adapter
 	if (ixgbe_num_queues != 0)
 		queues = ixgbe_num_queues;
 	/* Set max queues to 8 when autoconfiguring */
-	else if ((ixgbe_num_queues == 0) && (queues > 8))
-		queues = 8;
+	else
+		queues = min(queues,
+		min(mac->max_tx_queues, mac->max_rx_queues));
 
 	/* reflect correct sysctl value */
 	ixgbe_num_queues = queues;
@@ -4847,18 +4849,6 @@ ixgbe_add_hw_stats(struct adapter *adapt
 	const char *xname = device_xname(dev);
 
 	/* Driver Statistics */
-#if 0
-	/* These counters are not updated by the software */
-	SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "mbuf_header_failed",
-			CTLFLAG_RD, &adapter->mbuf_header_failed,
-			"???");
-	SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "mbuf_packet_failed",
-			CTLFLAG_RD, &adapter->mbuf_packet_failed,
-			"???");
-	SYSCTL_ADD_ULONG(ctx, child, OID_AUTO, "no_tx_map_avail",
-			CTLFLAG_RD, &adapter->no_tx_map_avail,
-			"???");
-#endif
 	evcnt_attach_dynamic(&adapter->handleq, EVCNT_TYPE_MISC,
 	NULL, xname, "Handled queue in softint");
 	evcnt_attach_dynamic(&adapter->req, EVCNT_TYPE_MISC,

Index: src/sys/dev/pci/ixgbe/ixgbe.h
diff -u src/sys/dev/pci/ixgbe/ixgbe.h:1.24 src/sys/dev/pci/ixgbe/ixgbe.h:1.24.6.1
--- src/sys/dev/pci/ixgbe/ixgbe.h:1.24	Mon Feb 13 10:13:54 2017
+++ src/sys/dev/pci/ixgbe/ixgbe.h	Thu Aug 31 11:37:37 2017
@@ -59,7 +59,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 /*$FreeBSD: head/sys/dev/ixgbe/ixgbe.h 303890 2016-08-09 19:32:06Z dumbbell $*/
-/*$NetBSD: ixgbe.h,v 1.24 2017/02/13 10:13:54 msaitoh Exp $*/
+/*$NetBSD: ixgbe.h,v 1.24.6.1 2017/08/31 11:37:37 martin Exp $*/
 
 
 #ifndef _IXGBE_H_
@@ -400,7 +400,6 @@ struct tx_ring {
 	u32			packets;
 	/* Soft Stats */
 	struct evcnt	   	tso_tx;
-	struct evcnt	   	no_tx_map_avail;
 	struct evcnt		no_desc_avail;
 	struct evcnt		total_packets;
 	struct evcnt		pcq_drops;
@@ -580,8 +579,6 @@ struct adapter {
 
 	/* Misc stats maintained by the driver */
 	struct evcnt   		mbuf_defrag_failed;
-	struct evcnt	   	mbuf_header_failed;
-	struct evcnt	   	mbuf_packet_failed;
 	struct evcnt	   	efbig_tx_dma_setup;
 	struct evcnt	   	efbig2_tx_dma_setup;
 	struct evcnt	   	einval_tx_dma_setup;



CVS commit: [netbsd-8] src/sys/dev/pci/ixgbe

2017-08-04 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sat Aug  5 03:49:35 UTC 2017

Modified Files:
src/sys/dev/pci/ixgbe [netbsd-8]: ix_txrx.c ixgbe.c ixgbe_api.c
ixgbe_type.h

Log Message:
Pull up following revision(s) (requested by msaitoh in ticket #175):
sys/dev/pci/ixgbe/ix_txrx.c: 1.25-1.27
sys/dev/pci/ixgbe/ixgbe.c: 1.91-1.95
sys/dev/pci/ixgbe/ixgbe_type.h: 1.23-1.25
sys/dev/pci/ixgbe/ixgbe_api.c: 1.16
sync ixg(4) up to ixgbe.c rev. 1.95:
- Increase total number of RX buffers on multiqueue.
- Fix the partial chain check in ixgbe_rx_discard(). This bug was
  added in ixgbe.c rev. 1.33.
- Fix a double free in ixgbe_rxeof().
- Print verbose output in ixgbe_update_link_status() correctly on 5Gbps
  and 2.5Gbps (NBASE-T) for X550T[12] and newer.
- Change hw.ixgN.ts to hw.ixgN.thermal_test. Same as FreeBSD.
- Fix a bug that ifconfig ixgN media 1000baseT and 10Gbase-T advertised
  additional unwanted speeds.
- Print PHY ID.
- Remove unused variable.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.24.2.1 src/sys/dev/pci/ixgbe/ix_txrx.c
cvs rdiff -u -r1.88.2.1 -r1.88.2.2 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.15 -r1.15.8.1 src/sys/dev/pci/ixgbe/ixgbe_api.c
cvs rdiff -u -r1.22 -r1.22.2.1 src/sys/dev/pci/ixgbe/ixgbe_type.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/ixgbe/ix_txrx.c
diff -u src/sys/dev/pci/ixgbe/ix_txrx.c:1.24 src/sys/dev/pci/ixgbe/ix_txrx.c:1.24.2.1
--- src/sys/dev/pci/ixgbe/ix_txrx.c:1.24	Thu May 18 08:25:37 2017
+++ src/sys/dev/pci/ixgbe/ix_txrx.c	Sat Aug  5 03:49:35 2017
@@ -59,7 +59,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 /*$FreeBSD: head/sys/dev/ixgbe/ix_txrx.c 301538 2016-06-07 04:51:50Z sephe $*/
-/*$NetBSD: ix_txrx.c,v 1.24 2017/05/18 08:25:37 msaitoh Exp $*/
+/*$NetBSD: ix_txrx.c,v 1.24.2.1 2017/08/05 03:49:35 snj Exp $*/
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -1446,21 +1446,10 @@ fail:
 
 static void 
 ixgbe_free_receive_ring(struct rx_ring *rxr)
-{ 
-	struct ixgbe_rx_buf   *rxbuf;
+{
 
 	for (int i = 0; i < rxr->num_desc; i++) {
-		rxbuf = &rxr->rx_buffers[i];
-		if (rxbuf->buf != NULL) {
-			bus_dmamap_sync(rxr->ptag->dt_dmat, rxbuf->pmap,
-			0, rxbuf->buf->m_pkthdr.len,
-			BUS_DMASYNC_POSTREAD);
-			ixgbe_dmamap_unload(rxr->ptag, rxbuf->pmap);
-			rxbuf->buf->m_flags |= M_PKTHDR;
-			m_freem(rxbuf->buf);
-			rxbuf->buf = NULL;
-			rxbuf->flags = 0;
-		}
+		ixgbe_rx_discard(rxr, i);
 	}
 }
 
@@ -1510,7 +1499,8 @@ ixgbe_setup_receive_ring(struct rx_ring 
 	 * or size of jumbo mbufs may have changed.
 	 */
 	ixgbe_jcl_reinit(&adapter->jcl_head, rxr->ptag->dt_dmat,
-	2 * adapter->num_rx_desc, adapter->rx_mbuf_sz);
+	(2 * adapter->num_rx_desc) * adapter->num_queues,
+	adapter->rx_mbuf_sz);
 
 	IXGBE_RX_LOCK(rxr);
 
@@ -1631,7 +1621,9 @@ fail:
 	 */
 	for (int i = 0; i < j; ++i) {
 		rxr = &adapter->rx_rings[i];
+		IXGBE_RX_LOCK(rxr);
 		ixgbe_free_receive_ring(rxr);
+		IXGBE_RX_UNLOCK(rxr);
 	}
 
 	return (ENOBUFS);
@@ -1685,15 +1677,7 @@ ixgbe_free_receive_buffers(struct rx_rin
 	if (rxr->rx_buffers != NULL) {
 		for (int i = 0; i < adapter->num_rx_desc; i++) {
 			rxbuf = &rxr->rx_buffers[i];
-			if (rxbuf->buf != NULL) {
-bus_dmamap_sync(rxr->ptag->dt_dmat,
-rxbuf->pmap, 0, rxbuf->buf->m_pkthdr.len,
-BUS_DMASYNC_POSTREAD);
-ixgbe_dmamap_unload(rxr->ptag, rxbuf->pmap);
-rxbuf->buf->m_flags |= M_PKTHDR;
-m_freem(rxbuf->buf);
-			}
-			rxbuf->buf = NULL;
+			ixgbe_rx_discard(rxr, i);
 			if (rxbuf->pmap != NULL) {
 ixgbe_dmamap_destroy(rxr->ptag, rxbuf->pmap);
 rxbuf->pmap = NULL;
@@ -1770,12 +1754,15 @@ ixgbe_rx_discard(struct rx_ring *rxr, in
 	** and mapping.
 	*/
 
-	if (rbuf->buf != NULL) {/* Partial chain ? */
-		rbuf->fmp->m_flags |= M_PKTHDR;
+	if (rbuf->fmp != NULL) {/* Partial chain ? */
+		bus_dmamap_sync(rxr->ptag->dt_dmat, rbuf->pmap, 0,
+		rbuf->buf->m_pkthdr.len, BUS_DMASYNC_POSTREAD);
 		m_freem(rbuf->fmp);
 		rbuf->fmp = NULL;
 		rbuf->buf = NULL; /* rbuf->buf is part of fmp's chain */
 	} else if (rbuf->buf) {
+		bus_dmamap_sync(rxr->ptag->dt_dmat, rbuf->pmap, 0,
+		rbuf->buf->m_pkthdr.len, BUS_DMASYNC_POSTREAD);
 		m_free(rbuf->buf);
 		rbuf->buf = NULL;
 	}
@@ -1869,6 +1856,9 @@ ixgbe_rxeof(struct ix_queue *que)
 			goto next_desc;
 		}
 
+		bus_dmamap_sync(rxr->ptag->dt_dmat, rbuf->pmap, 0,
+		rbuf->buf->m_pkthdr.len, BUS_DMASYNC_POSTREAD);
+
 		/*
 		** On 82599 which supports a hardware
 		** LRO (called HW RSC), packets need

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.1 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.2
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.1	Tue Jul  4 14:57:19 2017
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Sat Aug  5 03:49:35 2017
@@ -59,7 +59,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 /*$FreeBSD: head/sys/dev/ixgbe/if_ix.c 302384 2016-07-07 03