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 &= ~IXGBE_VLNCTRL_CFIEN;
+	if (ec->ec_capenable & ETHERCAP_VLAN_HWFILTER)
 		ctrl |= IXGBE_VLNCTRL_VFE;
+	else
+		ctrl &= ~IXGBE_VLNCTRL_VFE;
+	/* VLAN hw tagging for 82598 */
+	if (hw->mac.type == ixgbe_mac_82598EB) {
+		if (hwtagging)
+			ctrl |= IXGBE_VLNCTRL_VME;
+		else
+			ctrl &= ~IXGBE_VLNCTRL_VME;
 	}
-	if (hw->mac.type == ixgbe_mac_82598EB)
-		ctrl |= IXGBE_VLNCTRL_VME;
 	IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, ctrl);
 } /* ixgbe_setup_vlan_hw_support */
 
@@ -3539,7 +3545,7 @@ ixgbe_detach(device_t dev, int flags)
 	evcnt_detach(&adapter->msf_sicount);
 	evcnt_detach(&adapter->phy_sicount);
 
-	for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
+	for (i = 0; i < IXGBE_TC_COUNTER_NUM; i++) {
 		if (i < __arraycount(stats->mpc)) {
 			evcnt_detach(&stats->mpc[i]);
 			if (hw->mac.type == ixgbe_mac_82598EB)

Index: src/sys/dev/pci/ixgbe/ixgbe_type.h
diff -u src/sys/dev/pci/ixgbe/ixgbe_type.h:1.22.2.7 src/sys/dev/pci/ixgbe/ixgbe_type.h:1.22.2.8
--- src/sys/dev/pci/ixgbe/ixgbe_type.h:1.22.2.7	Tue Aug  7 13:33:23 2018
+++ src/sys/dev/pci/ixgbe/ixgbe_type.h	Mon Apr  1 12:35:38 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe_type.h,v 1.22.2.7 2018/08/07 13:33:23 martin Exp $ */
+/* $NetBSD: ixgbe_type.h,v 1.22.2.8 2019/04/01 12:35:38 martin Exp $ */
 
 /******************************************************************************
   SPDX-License-Identifier: BSD-3-Clause
@@ -3851,6 +3851,21 @@ struct ixgbe_fc_info {
 	enum ixgbe_fc_mode requested_mode; /* FC mode requested by caller */
 };
 
+/*
+ * 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().
+ */
+#if !defined(IXGBE_TC_COUNTER_NUM)
+#define IXGBE_TC_COUNTER_NUM IXGBE_DCB_MAX_TRAFFIC_CLASS
+#endif
+#if ((IXGBE_TC_COUNTER_NUM < 1)					\
+    || (IXGBE_TC_COUNTER_NUM > IXGBE_DCB_MAX_TRAFFIC_CLASS))
+#error Wrong IXGBE_TC_COUNTER_NUM value
+#endif
+
 /* Statistics counters collected by the MAC */
 struct ixgbe_hw_stats {
 	char namebuf[32];
@@ -3865,7 +3880,7 @@ struct ixgbe_hw_stats {
 	struct evcnt mspdc;
 	struct evcnt mbsdc;
 	struct evcnt mpctotal;
-	struct evcnt mpc[8];
+	struct evcnt mpc[IXGBE_TC_COUNTER_NUM];
 	struct evcnt mlfc;
 	struct evcnt mrfc;
 	struct evcnt rlec;
@@ -3873,10 +3888,10 @@ struct ixgbe_hw_stats {
 	struct evcnt lxonrxc;
 	struct evcnt lxofftxc;
 	struct evcnt lxoffrxc;
-	struct evcnt pxontxc[8];
-	struct evcnt pxonrxc[8];
-	struct evcnt pxofftxc[8];
-	struct evcnt pxoffrxc[8];
+	struct evcnt pxontxc[IXGBE_TC_COUNTER_NUM];
+	struct evcnt pxonrxc[IXGBE_TC_COUNTER_NUM];
+	struct evcnt pxofftxc[IXGBE_TC_COUNTER_NUM];
+	struct evcnt pxoffrxc[IXGBE_TC_COUNTER_NUM];
 	struct evcnt prc64;
 	struct evcnt prc127;
 	struct evcnt prc255;
@@ -3889,7 +3904,7 @@ struct ixgbe_hw_stats {
 	struct evcnt gptc;
 	struct evcnt gorc;
 	struct evcnt gotc;
-	struct evcnt rnbc[8];
+	struct evcnt rnbc[IXGBE_TC_COUNTER_NUM];
 	struct evcnt ruc;
 	struct evcnt rfc;
 	struct evcnt roc;
@@ -3914,7 +3929,7 @@ struct ixgbe_hw_stats {
 	struct evcnt qbrc[16];
 	struct evcnt qbtc[16];
 	struct evcnt qprdc[16];
-	struct evcnt pxon2offc[8];
+	struct evcnt pxon2offc[IXGBE_TC_COUNTER_NUM];
 	u64 fdirustat_add;
 	u64 fdirustat_remove;
 	u64 fdirfstat_fadd;

Index: src/sys/dev/pci/ixgbe/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.56.2.20 src/sys/dev/pci/ixgbe/ixv.c:1.56.2.21
--- src/sys/dev/pci/ixgbe/ixv.c:1.56.2.20	Fri Mar  1 17:33:24 2019
+++ src/sys/dev/pci/ixgbe/ixv.c	Mon Apr  1 12:35:38 2019
@@ -1,4 +1,4 @@
-/*$NetBSD: ixv.c,v 1.56.2.20 2019/03/01 17:33:24 martin Exp $*/
+/*$NetBSD: ixv.c,v 1.56.2.21 2019/04/01 12:35:38 martin Exp $*/
 
 /******************************************************************************
 
@@ -1973,28 +1973,35 @@ ixv_sysctl_rdt_handler(SYSCTLFN_ARGS)
 static void
 ixv_setup_vlan_support(struct adapter *adapter)
 {
+	struct ethercom *ec = &adapter->osdep.ec;
 	struct ixgbe_hw *hw = &adapter->hw;
+	struct rx_ring	*rxr;
 	u32		ctrl, vid, vfta, retry;
+	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);
 
 	/* Enable the queues */
 	for (int i = 0; i < adapter->num_queues; i++) {
-		ctrl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(i));
-		ctrl |= IXGBE_RXDCTL_VME;
-		IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(i), ctrl);
+ 		rxr = &adapter->rx_rings[i];
+		ctrl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(rxr->me));
+		if (hwtagging)
+			ctrl |= IXGBE_RXDCTL_VME;
+		else
+			ctrl &= ~IXGBE_RXDCTL_VME;
+		IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(rxr->me), ctrl);
 		/*
 		 * Let Rx path know that it needs to store VLAN tag
 		 * as part of extra mbuf info.
 		 */
-		adapter->rx_rings[i].vtag_strip = TRUE;
+		rxr->vtag_strip = hwtagging ? TRUE : FALSE;
 	}
 
 	/*

Reply via email to