CVS commit: [netbsd-10] src/sys/dev/pci/igc

2024-06-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jun 27 19:33:11 UTC 2024

Modified Files:
src/sys/dev/pci/igc [netbsd-10]: if_igc.h

Log Message:
Pull up following revision(s) (requested by rin in ticket #729):

sys/dev/pci/igc/if_igc.h: revision 1.3

igc: Use __HAVE_ATOMIC64_LOADSTORE instead of __HAVE_ATOMIC64_OPS
to detect atomic_loadstore(9) is applicable to 64-bit integers.

Thanks riastradh@ for explanation in PR kern/58340


To generate a diff of this commit:
cvs rdiff -u -r1.2.2.2 -r1.2.2.3 src/sys/dev/pci/igc/if_igc.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/igc/if_igc.h
diff -u src/sys/dev/pci/igc/if_igc.h:1.2.2.2 src/sys/dev/pci/igc/if_igc.h:1.2.2.3
--- src/sys/dev/pci/igc/if_igc.h:1.2.2.2	Sun Oct  8 13:19:34 2023
+++ src/sys/dev/pci/igc/if_igc.h	Thu Jun 27 19:33:11 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_igc.h,v 1.2.2.2 2023/10/08 13:19:34 martin Exp $	*/
+/*	$NetBSD: if_igc.h,v 1.2.2.3 2024/06/27 19:33:11 martin Exp $	*/
 /*	$OpenBSD: if_igc.h,v 1.2 2022/01/09 05:42:50 jsg Exp $	*/
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
@@ -39,13 +39,14 @@
 #endif
 
 #include 
+#include 
 #include 
 #include 
 
 #include 
 #include 
 
-#ifdef __HAVE_ATOMIC64_OPS
+#ifdef __HAVE_ATOMIC64_LOADSTORE
 #define	IGC_EVENT_COUNTERS
 #endif
 



CVS commit: [netbsd-10] src/sys/dev/pci/igc

2024-06-27 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Jun 27 19:33:11 UTC 2024

Modified Files:
src/sys/dev/pci/igc [netbsd-10]: if_igc.h

Log Message:
Pull up following revision(s) (requested by rin in ticket #729):

sys/dev/pci/igc/if_igc.h: revision 1.3

igc: Use __HAVE_ATOMIC64_LOADSTORE instead of __HAVE_ATOMIC64_OPS
to detect atomic_loadstore(9) is applicable to 64-bit integers.

Thanks riastradh@ for explanation in PR kern/58340


To generate a diff of this commit:
cvs rdiff -u -r1.2.2.2 -r1.2.2.3 src/sys/dev/pci/igc/if_igc.h

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



CVS commit: [netbsd-10] src/sys/dev/pci/igc

2024-06-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jun 21 10:54:50 UTC 2024

Modified Files:
src/sys/dev/pci/igc [netbsd-10]: if_igc.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #713):

sys/dev/pci/igc/if_igc.c: revision 1.14
sys/dev/pci/igc/if_igc.c: revision 1.7
sys/dev/pci/igc/if_igc.c: revision 1.8
sys/dev/pci/igc/if_igc.c: revision 1.9

Fix build of the MODULAR kernel, which explicitly excludes vlans.

igc(4): Notify which of 64- or 32-bit DMA is used

Remove unnecssary #include

igc: Add missing '\n' to a DPRINTF message


To generate a diff of this commit:
cvs rdiff -u -r1.3.2.4 -r1.3.2.5 src/sys/dev/pci/igc/if_igc.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/igc/if_igc.c
diff -u src/sys/dev/pci/igc/if_igc.c:1.3.2.4 src/sys/dev/pci/igc/if_igc.c:1.3.2.5
--- src/sys/dev/pci/igc/if_igc.c:1.3.2.4	Fri Feb 23 18:41:02 2024
+++ src/sys/dev/pci/igc/if_igc.c	Fri Jun 21 10:54:50 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_igc.c,v 1.3.2.4 2024/02/23 18:41:02 martin Exp $	*/
+/*	$NetBSD: if_igc.c,v 1.3.2.5 2024/06/21 10:54:50 martin Exp $	*/
 /*	$OpenBSD: if_igc.c,v 1.13 2023/04/28 10:18:57 bluhm Exp $	*/
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
@@ -30,10 +30,9 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_igc.c,v 1.3.2.4 2024/02/23 18:41:02 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_igc.c,v 1.3.2.5 2024/06/21 10:54:50 martin Exp $");
 
 #ifdef _KERNEL_OPT
-#include "opt_net_mpsafe.h"
 #include "opt_if_igc.h"
 #if 0 /* notyet */
 #include "vlan.h"
@@ -354,7 +353,6 @@ igc_attach(device_t parent, device_t sel
 
 	const struct igc_product *igcp = igc_lookup(pa);
 	KASSERT(igcp != NULL);
-	pci_aprint_devinfo_fancy(pa, "Ethernet controller", igcp->igcp_name, 1);
 
 	sc->sc_dev = self;
 	callout_init(>sc_tick_ch, CALLOUT_MPSAFE);
@@ -363,17 +361,23 @@ igc_attach(device_t parent, device_t sel
 
 	sc->osdep.os_sc = sc;
 	sc->osdep.os_pa = *pa;
-#ifdef __aarch64__
+#ifndef __aarch64__
 	/*
 	 * XXX PR port-arm/57643
 	 * 64-bit DMA does not work at least for LX2K with 32/64GB memory.
 	 * smmu(4) support may be required.
 	 */
-	sc->osdep.os_dmat = pa->pa_dmat;
-#else
-	sc->osdep.os_dmat = pci_dma64_available(pa) ?
-	pa->pa_dmat64 : pa->pa_dmat;
+	if (pci_dma64_available(pa)) {
+		aprint_verbose(", 64-bit DMA");
+		sc->osdep.os_dmat = pa->pa_dmat64;
+	} else
 #endif
+	{
+		aprint_verbose(", 32-bit DMA");
+		sc->osdep.os_dmat = pa->pa_dmat;
+	}
+
+	pci_aprint_devinfo_fancy(pa, "Ethernet controller", igcp->igcp_name, 1);
 
 	/* Determine hardware and mac info */
 	igc_identify_hardware(sc);
@@ -2119,7 +2123,9 @@ igc_rxeof(struct rx_ring *rxr, u_int lim
 		const bool eop = staterr & IGC_RXD_STAT_EOP;
 		const uint16_t len = le16toh(rxdesc->wb.upper.length);
 
+#if NVLAN > 0
 		const uint16_t vtag = le16toh(rxdesc->wb.upper.vlan);
+#endif
 
 		const uint32_t ptype = le32toh(rxdesc->wb.lower.lo_dword.data) &
 		IGC_PKTTYPE_MASK;
@@ -2800,7 +2806,7 @@ igc_intr(void *arg)
 
 	/* Definitely not our interrupt. */
 	if (reg_icr == 0x0) {
-		DPRINTF(MISC, "not for me");
+		DPRINTF(MISC, "not for me\n");
 		return 0;
 	}
 



CVS commit: [netbsd-10] src/sys/dev/pci/igc

2024-06-21 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jun 21 10:54:50 UTC 2024

Modified Files:
src/sys/dev/pci/igc [netbsd-10]: if_igc.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #713):

sys/dev/pci/igc/if_igc.c: revision 1.14
sys/dev/pci/igc/if_igc.c: revision 1.7
sys/dev/pci/igc/if_igc.c: revision 1.8
sys/dev/pci/igc/if_igc.c: revision 1.9

Fix build of the MODULAR kernel, which explicitly excludes vlans.

igc(4): Notify which of 64- or 32-bit DMA is used

Remove unnecssary #include

igc: Add missing '\n' to a DPRINTF message


To generate a diff of this commit:
cvs rdiff -u -r1.3.2.4 -r1.3.2.5 src/sys/dev/pci/igc/if_igc.c

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



CVS commit: [netbsd-10] src/sys/dev/pci/igc

2024-02-23 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Feb 23 18:41:02 UTC 2024

Modified Files:
src/sys/dev/pci/igc [netbsd-10]: if_igc.c igc_defines.h

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

sys/dev/pci/igc/if_igc.c: revision 1.12
sys/dev/pci/igc/if_igc.c: revision 1.13
sys/dev/pci/igc/igc_defines.h: revision 1.3
sys/dev/pci/igc/if_igc.c: revision 1.10
sys/dev/pci/igc/if_igc.c: revision 1.11

igc(4): Count iqdrops.

 TODO: RQDPC should be visible via evcnt(9).

igc: Add missing igc_check_for_link() call.

 It's required to set the collision distance, configure flow control
from the negotiated result and set the LTR thresholds.

With this change, ifconfig igcN show the flow control status correctly.

igc(4): Modify dmesg output of PHY and NVM info.
 - Print PHY info first and then print NVM info.
 - Remove debug output.

igc(4): Print EtrackID.


To generate a diff of this commit:
cvs rdiff -u -r1.3.2.3 -r1.3.2.4 src/sys/dev/pci/igc/if_igc.c
cvs rdiff -u -r1.2.2.2 -r1.2.2.3 src/sys/dev/pci/igc/igc_defines.h

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



CVS commit: [netbsd-10] src/sys/dev/pci/igc

2024-02-23 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Feb 23 18:41:02 UTC 2024

Modified Files:
src/sys/dev/pci/igc [netbsd-10]: if_igc.c igc_defines.h

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

sys/dev/pci/igc/if_igc.c: revision 1.12
sys/dev/pci/igc/if_igc.c: revision 1.13
sys/dev/pci/igc/igc_defines.h: revision 1.3
sys/dev/pci/igc/if_igc.c: revision 1.10
sys/dev/pci/igc/if_igc.c: revision 1.11

igc(4): Count iqdrops.

 TODO: RQDPC should be visible via evcnt(9).

igc: Add missing igc_check_for_link() call.

 It's required to set the collision distance, configure flow control
from the negotiated result and set the LTR thresholds.

With this change, ifconfig igcN show the flow control status correctly.

igc(4): Modify dmesg output of PHY and NVM info.
 - Print PHY info first and then print NVM info.
 - Remove debug output.

igc(4): Print EtrackID.


To generate a diff of this commit:
cvs rdiff -u -r1.3.2.3 -r1.3.2.4 src/sys/dev/pci/igc/if_igc.c
cvs rdiff -u -r1.2.2.2 -r1.2.2.3 src/sys/dev/pci/igc/igc_defines.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/igc/if_igc.c
diff -u src/sys/dev/pci/igc/if_igc.c:1.3.2.3 src/sys/dev/pci/igc/if_igc.c:1.3.2.4
--- src/sys/dev/pci/igc/if_igc.c:1.3.2.3	Sat Oct 14 06:49:37 2023
+++ src/sys/dev/pci/igc/if_igc.c	Fri Feb 23 18:41:02 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_igc.c,v 1.3.2.3 2023/10/14 06:49:37 martin Exp $	*/
+/*	$NetBSD: if_igc.c,v 1.3.2.4 2024/02/23 18:41:02 martin Exp $	*/
 /*	$OpenBSD: if_igc.c,v 1.13 2023/04/28 10:18:57 bluhm Exp $	*/
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_igc.c,v 1.3.2.3 2023/10/14 06:49:37 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_igc.c,v 1.3.2.4 2024/02/23 18:41:02 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -1112,11 +1112,35 @@ igc_update_counters(struct igc_softc *sc
 
 	/* Mac statistics */
 	struct igc_hw *hw = >hw;
+	struct ifnet *ifp = >sc_ec.ec_if;
+	uint64_t iqdrops = 0;
 
 	for (int cnt = 0; cnt < IGC_MAC_COUNTERS; cnt++) {
-		IGC_MAC_COUNTER_ADD(sc, cnt, igc_read_mac_counter(hw,
-		igc_mac_counters[cnt].reg, igc_mac_counters[cnt].is64));
+		uint64_t val;
+		bus_size_t regaddr = igc_mac_counters[cnt].reg;
+
+		val = igc_read_mac_counter(hw, regaddr,
+		igc_mac_counters[cnt].is64);
+		IGC_MAC_COUNTER_ADD(sc, cnt, val);
+		/* XXX Count MPC to iqdrops. */
+		if (regaddr == IGC_MPC)
+			iqdrops += val;
+	}
+
+	for (int iq = 0; iq < sc->sc_nqueues; iq++) {
+		uint32_t val;
+
+		/* XXX RQDPC should be visible via evcnt(9). */
+		val = IGC_READ_REG(hw, IGC_RQDPC(iq));
+
+		/* RQDPC is not cleard on read. */
+		if (val != 0)
+			IGC_WRITE_REG(hw, IGC_RQDPC(iq), 0);
+		iqdrops += val;
 	}
+
+	if (iqdrops != 0)
+		if_statadd(ifp, if_iqdrops, iqdrops);
 #endif
 }
 
@@ -2518,6 +2542,9 @@ igc_update_link_status(struct igc_softc 
 	struct ifnet *ifp = >sc_ec.ec_if;
 	struct igc_hw *hw = >hw;
 
+	if (hw->mac.get_link_status == true)
+		igc_check_for_link(hw);
+
 	if (IGC_READ_REG(>hw, IGC_STATUS) & IGC_STATUS_LU) {
 		if (sc->link_active == 0) {
 			igc_get_speed_and_duplex(hw, >link_speed,
@@ -3817,7 +3844,7 @@ igc_print_devinfo(struct igc_softc *sc)
 	struct igc_hw *hw = >hw;
 	struct igc_phy_info *phy = >phy;
 	u_int oui, model, rev;
-	uint16_t id1, id2, nvm_ver, phy_ver;
+	uint16_t id1, id2, nvm_ver, phy_ver, etk_lo, etk_hi;
 	char descr[MII_MAX_DESCR_LEN];
 
 	/* Print PHY Info */
@@ -3829,23 +3856,26 @@ igc_print_devinfo(struct igc_softc *sc)
 	rev = MII_REV(id2);
 	mii_get_descr(descr, sizeof(descr), oui, model);
 	if (descr[0])
-		aprint_normal_dev(dev, "PHY: %s, rev. %d\n",
+		aprint_normal_dev(dev, "PHY: %s, rev. %d",
 		descr, rev);
 	else
 		aprint_normal_dev(dev,
-		"PHY OUI 0x%06x, model 0x%04x, rev. %d\n",
+		"PHY OUI 0x%06x, model 0x%04x, rev. %d",
 		oui, model, rev);
 
-	/* Get NVM version */
+	/* PHY FW version */
+	phy->ops.read_reg(hw, 0x1e, _ver);
+	aprint_normal(", PHY FW version 0x%04hx\n", phy_ver);
+
+	/* NVM version */
 	hw->nvm.ops.read(hw, NVM_VERSION, 1, _ver);
 
-	/* Get PHY FW version */
-	phy->ops.read_reg(hw, 0x1e, _ver);
+	/* EtrackID */
+	hw->nvm.ops.read(hw, NVM_ETKID_LO, 1, _lo);
+	hw->nvm.ops.read(hw, NVM_ETKID_HI, 1, _hi);
 
-	aprint_normal_dev(dev, "ROM image version %x.%02x",
+	aprint_normal_dev(dev,
+	"NVM image version %x.%02x, EtrackID %04hx%04hx\n",
 	(nvm_ver & NVM_VERSION_MAJOR) >> NVM_VERSION_MAJOR_SHIFT,
-	(nvm_ver & NVM_VERSION_MINOR));
-	aprint_debug("(0x%04hx)", nvm_ver);
-
-	aprint_normal(", PHY FW version 0x%04hx\n", phy_ver);
+	nvm_ver & NVM_VERSION_MINOR, etk_hi, etk_lo);
 }

Index: src/sys/dev/pci/igc/igc_defines.h
diff -u src/sys/dev/pci/igc/igc_defines.h:1.2.2.2 src/sys/dev/pci/igc/igc_defines.h:1.2.2.3
--- 

CVS commit: [netbsd-10] src/sys/dev/pci/igc

2023-10-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Oct 14 06:49:37 UTC 2023

Modified Files:
src/sys/dev/pci/igc [netbsd-10]: if_igc.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #410):

sys/dev/pci/igc/if_igc.c: revision 1.4
sys/dev/pci/igc/if_igc.c: revision 1.5
sys/dev/pci/igc/if_igc.c: revision 1.6

igc(4): Fix half duplex setting
 From FreeBSD: 3b8d04f845b416d29a258658b8a48d1afb4a2e81

igc(4): `nvm_ver & ...' has type int, so use %x, not %hx.
This happens even though nvm_ver is unsigned short (uint16_t),
because of the integer promotions.
Should fix clang build.

igc(4): igc_init: Enable interrupt after everything is set up
Inspired by "ixgbe: Enable interrupt after setting IFF_RUNNING.":
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/pci/ixgbe/ixgbe.c#rev1.337

Just for sure, callout_schedule(9) for igc_tick() is also postponed.
This is NFC for now, although.


To generate a diff of this commit:
cvs rdiff -u -r1.3.2.2 -r1.3.2.3 src/sys/dev/pci/igc/if_igc.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/igc/if_igc.c
diff -u src/sys/dev/pci/igc/if_igc.c:1.3.2.2 src/sys/dev/pci/igc/if_igc.c:1.3.2.3
--- src/sys/dev/pci/igc/if_igc.c:1.3.2.2	Sun Oct  8 13:19:34 2023
+++ src/sys/dev/pci/igc/if_igc.c	Sat Oct 14 06:49:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_igc.c,v 1.3.2.2 2023/10/08 13:19:34 martin Exp $	*/
+/*	$NetBSD: if_igc.c,v 1.3.2.3 2023/10/14 06:49:37 martin Exp $	*/
 /*	$OpenBSD: if_igc.c,v 1.13 2023/04/28 10:18:57 bluhm Exp $	*/
 /*-
  * SPDX-License-Identifier: BSD-2-Clause
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_igc.c,v 1.3.2.2 2023/10/08 13:19:34 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_igc.c,v 1.3.2.3 2023/10/14 06:49:37 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -1541,17 +1541,17 @@ igc_init_locked(struct igc_softc *sc)
 		mutex_exit(>rxr_lock);
 	}
 
-	igc_enable_intr(sc);
-
 	sc->sc_core_stopping = false;
 
-	callout_schedule(>sc_tick_ch, hz);
-
 	ifp->if_flags |= IFF_RUNNING;
 
 	/* Save last flags for the callback */
 	sc->sc_if_flags = ifp->if_flags;
 
+	callout_schedule(>sc_tick_ch, hz);
+
+	igc_enable_intr(sc);
+
 	return 0;
 }
 
@@ -2378,16 +2378,16 @@ igc_media_change(struct ifnet *ifp)
 		sc->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
 		break;
 	case IFM_100_TX:
-		if ((ifm->ifm_media & IFM_GMASK) == IFM_HDX)
-			sc->hw.phy.autoneg_advertised = ADVERTISE_100_HALF;
-		else
+		if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
 			sc->hw.phy.autoneg_advertised = ADVERTISE_100_FULL;
+		else
+			sc->hw.phy.autoneg_advertised = ADVERTISE_100_HALF;
 		break;
 	case IFM_10_T:
-		if ((ifm->ifm_media & IFM_GMASK) == IFM_HDX)
-			sc->hw.phy.autoneg_advertised = ADVERTISE_10_HALF;
-		else
+		if ((ifm->ifm_media & IFM_GMASK) == IFM_FDX)
 			sc->hw.phy.autoneg_advertised = ADVERTISE_10_FULL;
+		else
+			sc->hw.phy.autoneg_advertised = ADVERTISE_10_HALF;
 		break;
 	default:
 		return EINVAL;
@@ -3842,7 +3842,7 @@ igc_print_devinfo(struct igc_softc *sc)
 	/* Get PHY FW version */
 	phy->ops.read_reg(hw, 0x1e, _ver);
 
-	aprint_normal_dev(dev, "ROM image version %x.%02hx",
+	aprint_normal_dev(dev, "ROM image version %x.%02x",
 	(nvm_ver & NVM_VERSION_MAJOR) >> NVM_VERSION_MAJOR_SHIFT,
 	(nvm_ver & NVM_VERSION_MINOR));
 	aprint_debug("(0x%04hx)", nvm_ver);



CVS commit: [netbsd-10] src/sys/dev/pci/igc

2023-10-14 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sat Oct 14 06:49:37 UTC 2023

Modified Files:
src/sys/dev/pci/igc [netbsd-10]: if_igc.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #410):

sys/dev/pci/igc/if_igc.c: revision 1.4
sys/dev/pci/igc/if_igc.c: revision 1.5
sys/dev/pci/igc/if_igc.c: revision 1.6

igc(4): Fix half duplex setting
 From FreeBSD: 3b8d04f845b416d29a258658b8a48d1afb4a2e81

igc(4): `nvm_ver & ...' has type int, so use %x, not %hx.
This happens even though nvm_ver is unsigned short (uint16_t),
because of the integer promotions.
Should fix clang build.

igc(4): igc_init: Enable interrupt after everything is set up
Inspired by "ixgbe: Enable interrupt after setting IFF_RUNNING.":
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/pci/ixgbe/ixgbe.c#rev1.337

Just for sure, callout_schedule(9) for igc_tick() is also postponed.
This is NFC for now, although.


To generate a diff of this commit:
cvs rdiff -u -r1.3.2.2 -r1.3.2.3 src/sys/dev/pci/igc/if_igc.c

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