Module Name:    src
Committed By:   jdolecek
Date:           Mon Jun 11 19:13:38 UTC 2018

Modified Files:
        src/sys/dev/pci: if_msk.c if_mskvar.h

Log Message:
adopt tx/rx buffer size computation from OpenBSD rev. 1.51 to fix
"random" msk failures

the crucial fix is that the start/end adresses are computed and
written to hw registers in number of octets (i.e. size /
sizeof(u_int64_t)), as that is actually what the hardware expects

fixes PR kern/36454 (which had fix which highlighted the trouble),
and seems likely to also fix kern/35711 and port-i386/42514


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/pci/if_msk.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/pci/if_mskvar.h

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

Modified files:

Index: src/sys/dev/pci/if_msk.c
diff -u src/sys/dev/pci/if_msk.c:1.56 src/sys/dev/pci/if_msk.c:1.57
--- src/sys/dev/pci/if_msk.c:1.56	Sat Jun  9 18:53:16 2018
+++ src/sys/dev/pci/if_msk.c	Mon Jun 11 19:13:38 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: if_msk.c,v 1.56 2018/06/09 18:53:16 jdolecek Exp $ */
+/* $NetBSD: if_msk.c,v 1.57 2018/06/11 19:13:38 jdolecek Exp $ */
 /*	$OpenBSD: if_msk.c,v 1.42 2007/01/17 02:43:02 krw Exp $	*/
 
 /*
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_msk.c,v 1.56 2018/06/09 18:53:16 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_msk.c,v 1.57 2018/06/11 19:13:38 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1029,7 +1029,7 @@ msk_attach(device_t parent, device_t sel
 	void *kva;
 	bus_dma_segment_t seg;
 	int i, rseg;
-	u_int32_t chunk, val;
+	u_int32_t chunk;
 
 	sc_if->sk_dev = self;
 	sc_if->sk_port = sa->skc_port;
@@ -1055,25 +1055,18 @@ msk_attach(device_t parent, device_t sel
 	    ether_sprintf(sc_if->sk_enaddr));
 
 	/*
-	 * Set up RAM buffer addresses. The NIC will have a certain
-	 * amount of SRAM on it, somewhere between 512K and 2MB. We
-	 * need to divide this up a) between the transmitter and
- 	 * receiver and b) between the two XMACs, if this is a
-	 * dual port NIC. Our algorithm is to divide up the memory
-	 * evenly so that everyone gets a fair share.
-	 *
-	 * Just to be contrary, Yukon2 appears to have separate memory
-	 * for each MAC.
+	 * Set up RAM buffer addresses. The Yukon2 has a small amount
+	 * of SRAM on it, somewhere between 4K and 48K.  We need to
+	 * divide this up between the transmitter and receiver.  We
+	 * give the receiver 2/3 of the memory (rounded down), and the
+	 * transmitter whatever remains.
 	 */
-	chunk = sc->sk_ramsize  - (sc->sk_ramsize + 2) / 3;
-	val = sc->sk_rboff / sizeof(u_int64_t);
-	sc_if->sk_rx_ramstart = val;
-	val += (chunk / sizeof(u_int64_t));
-	sc_if->sk_rx_ramend = val - 1;
-	chunk = sc->sk_ramsize - chunk;
-	sc_if->sk_tx_ramstart = val;
-	val += (chunk / sizeof(u_int64_t));
-	sc_if->sk_tx_ramend = val - 1;
+	chunk = (2 * (sc->sk_ramsize / sizeof(u_int64_t)) / 3) & ~0xff;
+	sc_if->sk_rx_ramstart = 0;
+	sc_if->sk_rx_ramend = sc_if->sk_rx_ramstart + chunk - 1;
+	chunk = (sc->sk_ramsize / sizeof(u_int64_t)) - chunk;
+	sc_if->sk_tx_ramstart = sc_if->sk_rx_ramend + 1;
+	sc_if->sk_tx_ramend = sc_if->sk_tx_ramstart + chunk - 1;
 
 	DPRINTFN(2, ("msk_attach: rx_ramstart=%#x rx_ramend=%#x\n"
 		     "           tx_ramstart=%#x tx_ramend=%#x\n",
@@ -1214,7 +1207,7 @@ mskc_attach(device_t parent, device_t se
 	const char *intrstr = NULL;
 	bus_size_t size;
 	int rc, sk_nodenum;
-	u_int8_t hw, skrs;
+	u_int8_t hw;
 	const char *revstr = NULL;
 	const struct sysctlnode *node;
 	void *kva;
@@ -1334,23 +1327,14 @@ mskc_attach(device_t parent, device_t se
 	}
 	sc->sk_status_ring = (struct msk_status_desc *)kva;
 
-
 	sc->sk_int_mod = SK_IM_DEFAULT;
 	sc->sk_int_mod_pending = 0;
 
 	/* Reset the adapter. */
 	msk_reset(sc);
 
-	skrs = sk_win_read_1(sc, SK_EPROM0);
-	if (skrs == 0x00)
-		sc->sk_ramsize = 0x20000;
-	else
-		sc->sk_ramsize = skrs * (1<<12);
-	sc->sk_rboff = SK_RBOFF_0;
-
-	DPRINTFN(2, ("mskc_attach: ramsize=%d (%dk), rboff=%d\n",
-		     sc->sk_ramsize, sc->sk_ramsize / 1024,
-		     sc->sk_rboff));
+	sc->sk_ramsize = sk_win_read_1(sc, SK_EPROM0) * 4096;
+	DPRINTFN(2, ("mskc_attach: ramsize=%dK\n", sc->sk_ramsize / 1024));
 
 	switch (sc->sk_type) {
 	case SK_YUKON_XL:

Index: src/sys/dev/pci/if_mskvar.h
diff -u src/sys/dev/pci/if_mskvar.h:1.12 src/sys/dev/pci/if_mskvar.h:1.13
--- src/sys/dev/pci/if_mskvar.h:1.12	Mon Apr 13 16:33:25 2015
+++ src/sys/dev/pci/if_mskvar.h	Mon Jun 11 19:13:38 2018
@@ -1,5 +1,5 @@
 /*	$OpenBSD: if_mskvar.h,v 1.3 2006/12/28 16:34:42 kettenis Exp $	*/
-/*	$NetBSD: if_mskvar.h,v 1.12 2015/04/13 16:33:25 riastradh Exp $	*/
+/*	$NetBSD: if_mskvar.h,v 1.13 2018/06/11 19:13:38 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -193,7 +193,6 @@ struct sk_softc {
 	u_int32_t		sk_workaround;
 	u_int8_t		sk_macs;	/* # of MACs */
 	const char		*sk_name;
-	u_int32_t		sk_rboff;	/* RAMbuffer offset */
 	u_int32_t		sk_ramsize;	/* amount of RAM on NIC */
 	u_int32_t		sk_intrmask;
 	struct sysctllog	*sk_clog;

Reply via email to