Module Name:    src
Committed By:   martin
Date:           Sun Jan 27 18:35:20 UTC 2019

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

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

        sys/dev/pci/nvme_pci.c: revision 1.26
        sys/dev/pci/xhci_pci.c: revision 1.21
        sys/dev/pci/ixgbe/ixv.c: revision 1.108
        sys/dev/pci/ixgbe/ixgbe.c: revision 1.171
        sys/dev/pci/if_fxp_pci.c: revision 1.84
        sys/dev/pci/if_fxp_pci.c: revision 1.85
        sys/dev/pci/xhci_pci.c: revision 1.16

remove #ifdef DEBUG printf, it seems to have outlived it's usefulness

 -

  KNF. No functional change.

 -

  Nowadays some UEFI BIOSes don't enable some PCI devices' address decoding.
To resolve this problem, pci_map.c rev. 1.34-1.36 changed the
pci_mapreg_(sub)map()'s to set the decode bit if it's not set. It's good for
almost all drivers, but some other drivers don't use pci_mapreg_map().
In drivers which don't use pci_mapreg_map(), some of them explicitly enable
decoding but others don't. Add code to enable decoding to them.

  See also the following discussion:
        http://mail-index.netbsd.org/tech-kern/2017/03/22/msg021678.html


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.82.10.1 src/sys/dev/pci/if_fxp_pci.c
cvs rdiff -u -r1.19.2.1 -r1.19.2.2 src/sys/dev/pci/nvme_pci.c
cvs rdiff -u -r1.8.6.1 -r1.8.6.2 src/sys/dev/pci/xhci_pci.c
cvs rdiff -u -r1.88.2.25 -r1.88.2.26 src/sys/dev/pci/ixgbe/ixgbe.c
cvs rdiff -u -r1.56.2.18 -r1.56.2.19 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/if_fxp_pci.c
diff -u src/sys/dev/pci/if_fxp_pci.c:1.82 src/sys/dev/pci/if_fxp_pci.c:1.82.10.1
--- src/sys/dev/pci/if_fxp_pci.c:1.82	Mon Apr 13 16:33:25 2015
+++ src/sys/dev/pci/if_fxp_pci.c	Sun Jan 27 18:35:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_fxp_pci.c,v 1.82 2015/04/13 16:33:25 riastradh Exp $	*/
+/*	$NetBSD: if_fxp_pci.c,v 1.82.10.1 2019/01/27 18:35:19 martin Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_fxp_pci.c,v 1.82 2015/04/13 16:33:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_fxp_pci.c,v 1.82.10.1 2019/01/27 18:35:19 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -190,13 +190,13 @@ fxp_pci_lookup(const struct pci_attach_a
 	const struct fxp_pci_product *fpp;
 
 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL)
-		return (NULL);
+		return NULL;
 
 	for (fpp = fxp_pci_products; fpp->fpp_name != NULL; fpp++)
 		if (PCI_PRODUCT(pa->pa_id) == fpp->fpp_prodid)
-			return (fpp);
+			return fpp;
 
-	return (NULL);
+	return NULL;
 }
 
 static int
@@ -205,9 +205,9 @@ fxp_pci_match(device_t parent, cfdata_t 
 	struct pci_attach_args *pa = aux;
 
 	if (fxp_pci_lookup(pa) != NULL)
-		return (1);
+		return 1;
 
-	return (0);
+	return 0;
 }
 
 /*
@@ -245,8 +245,7 @@ fxp_pci_confreg_restore(struct fxp_pci_s
 	reg = pci_conf_read(psc->psc_pc, psc->psc_tag, PCI_COMMAND_STATUS_REG);
 #endif
 
-	pci_conf_write(psc->psc_pc, psc->psc_tag,
-	    PCI_COMMAND_STATUS_REG,
+	pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_COMMAND_STATUS_REG,
 	    (reg & 0xffff0000) |
 	    (psc->psc_regs[PCI_COMMAND_STATUS_REG>>2] & 0xffff));
 	pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_BHLC_REG,
@@ -303,6 +302,7 @@ fxp_pci_attach(device_t parent, device_t
 	bus_space_handle_t ioh, memh;
 	int ioh_valid, memh_valid;
 	bus_addr_t addr;
+	pcireg_t csr;
 	int flags;
 	int error;
 	char intrbuf[PCI_INTRSTR_LEN];
@@ -312,8 +312,7 @@ fxp_pci_attach(device_t parent, device_t
 	/*
 	 * Map control/status registers.
 	 */
-	ioh_valid = (pci_mapreg_map(pa, FXP_PCI_IOBA,
-	    PCI_MAPREG_TYPE_IO, 0,
+	ioh_valid = (pci_mapreg_map(pa, FXP_PCI_IOBA, PCI_MAPREG_TYPE_IO, 0,
 	    &iot, &ioh, NULL, NULL) == 0);
 
 	/*
@@ -352,6 +351,15 @@ fxp_pci_attach(device_t parent, device_t
 	if (memh_valid) {
 		sc->sc_st = memt;
 		sc->sc_sh = memh;
+		/*
+		 * Enable address decoding for memory range in case BIOS or
+		 * UEFI didn't set it.
+		 */
+		csr = pci_conf_read(pa->pa_pc, pa->pa_tag,
+		    PCI_COMMAND_STATUS_REG);
+		csr |= PCI_COMMAND_MEM_ENABLE;
+		pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
+		    csr);
 	} else if (ioh_valid) {
 		sc->sc_st = iot;
 		sc->sc_sh = ioh;
@@ -541,5 +549,5 @@ fxp_pci_enable(struct fxp_softc *sc)
 	/* Now restore the configuration registers. */
 	fxp_pci_confreg_restore(psc);
 
-	return (0);
+	return 0;
 }

Index: src/sys/dev/pci/nvme_pci.c
diff -u src/sys/dev/pci/nvme_pci.c:1.19.2.1 src/sys/dev/pci/nvme_pci.c:1.19.2.2
--- src/sys/dev/pci/nvme_pci.c:1.19.2.1	Thu Apr 19 15:37:56 2018
+++ src/sys/dev/pci/nvme_pci.c	Sun Jan 27 18:35:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nvme_pci.c,v 1.19.2.1 2018/04/19 15:37:56 martin Exp $	*/
+/*	$NetBSD: nvme_pci.c,v 1.19.2.2 2019/01/27 18:35:19 martin Exp $	*/
 /*	$OpenBSD: nvme_pci.c,v 1.3 2016/04/14 11:18:32 dlg Exp $ */
 
 /*
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvme_pci.c,v 1.19.2.1 2018/04/19 15:37:56 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvme_pci.c,v 1.19.2.2 2019/01/27 18:35:19 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -160,18 +160,24 @@ nvme_pci_attach(device_t parent, device_
 
 	pci_aprint_devinfo(pa, NULL);
 
-	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
-	if ((reg & PCI_COMMAND_MASTER_ENABLE) == 0) {
-		reg |= PCI_COMMAND_MASTER_ENABLE;
-        	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, reg);
-	}
-
 	/* Map registers */
 	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, NVME_PCI_BAR);
 	if (PCI_MAPREG_TYPE(memtype) != PCI_MAPREG_TYPE_MEM) {
 		aprint_error_dev(self, "invalid type (type=0x%x)\n", memtype);
 		return;
 	}
+	reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
+	if (((reg & PCI_COMMAND_MASTER_ENABLE) == 0) ||
+	    ((reg & PCI_COMMAND_MEM_ENABLE) == 0)) {
+		/*
+		 * Enable address decoding for memory range in case BIOS or
+		 * UEFI didn't set it.
+		 */
+		reg |= PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_MEM_ENABLE;
+        	pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
+		    reg);
+	}
+
 	sc->sc_iot = pa->pa_memt;
 	error = pci_mapreg_info(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START,
 	    memtype, &memaddr, &sc->sc_ios, &flags);

Index: src/sys/dev/pci/xhci_pci.c
diff -u src/sys/dev/pci/xhci_pci.c:1.8.6.1 src/sys/dev/pci/xhci_pci.c:1.8.6.2
--- src/sys/dev/pci/xhci_pci.c:1.8.6.1	Thu Sep 27 14:52:27 2018
+++ src/sys/dev/pci/xhci_pci.c	Sun Jan 27 18:35:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci_pci.c,v 1.8.6.1 2018/09/27 14:52:27 martin Exp $	*/
+/*	$NetBSD: xhci_pci.c,v 1.8.6.2 2019/01/27 18:35:19 martin Exp $	*/
 /*	OpenBSD: xhci_pci.c,v 1.4 2014/07/12 17:38:51 yuo Exp	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.8.6.1 2018/09/27 14:52:27 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_pci.c,v 1.8.6.2 2019/01/27 18:35:19 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -132,15 +132,17 @@ xhci_pci_attach(device_t parent, device_
 	/* Check for quirks */
 	sc->sc_quirks = 0;
 
-	/* check if memory space access is enabled */
 	csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
-#ifdef DEBUG
-	printf("%s: csr: %08x\n", __func__, csr);
-#endif
 	if ((csr & PCI_COMMAND_MEM_ENABLE) == 0) {
-		sc->sc_ios = 0;
-		aprint_error_dev(self, "memory access is disabled\n");
-		return;
+		/*
+		 * Enable address decoding for memory range in case BIOS or
+		 * UEFI didn't set it.
+		 */
+		csr = pci_conf_read(pa->pa_pc, pa->pa_tag,
+		    PCI_COMMAND_STATUS_REG);
+		csr |= PCI_COMMAND_MEM_ENABLE;
+		pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
+		    csr);
 	}
 
 	/* map MMIO registers */

Index: src/sys/dev/pci/ixgbe/ixgbe.c
diff -u src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.25 src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.26
--- src/sys/dev/pci/ixgbe/ixgbe.c:1.88.2.25	Thu Nov  8 12:04:48 2018
+++ src/sys/dev/pci/ixgbe/ixgbe.c	Sun Jan 27 18:35:19 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ixgbe.c,v 1.88.2.25 2018/11/08 12:04:48 martin Exp $ */
+/* $NetBSD: ixgbe.c,v 1.88.2.26 2019/01/27 18:35:19 martin Exp $ */
 
 /******************************************************************************
 
@@ -3344,7 +3344,7 @@ static int
 ixgbe_allocate_pci_resources(struct adapter *adapter,
     const struct pci_attach_args *pa)
 {
-	pcireg_t	memtype;
+	pcireg_t	memtype, csr;
 	device_t dev = adapter->dev;
 	bus_addr_t addr;
 	int flags;
@@ -3369,6 +3369,15 @@ map_err:
 			aprint_error_dev(dev, "unable to map BAR0\n");
 			return ENXIO;
 		}
+		/*
+		 * Enable address decoding for memory range in case BIOS or
+		 * UEFI don't set it.
+		 */
+		csr = pci_conf_read(pa->pa_pc, pa->pa_tag,
+		    PCI_COMMAND_STATUS_REG);
+		csr |= PCI_COMMAND_MEM_ENABLE;
+		pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
+		    csr);
 		break;
 	default:
 		aprint_error_dev(dev, "unexpected type on BAR0\n");

Index: src/sys/dev/pci/ixgbe/ixv.c
diff -u src/sys/dev/pci/ixgbe/ixv.c:1.56.2.18 src/sys/dev/pci/ixgbe/ixv.c:1.56.2.19
--- src/sys/dev/pci/ixgbe/ixv.c:1.56.2.18	Thu Nov  8 12:04:48 2018
+++ src/sys/dev/pci/ixgbe/ixv.c	Sun Jan 27 18:35:19 2019
@@ -1,4 +1,4 @@
-/*$NetBSD: ixv.c,v 1.56.2.18 2018/11/08 12:04:48 martin Exp $*/
+/*$NetBSD: ixv.c,v 1.56.2.19 2019/01/27 18:35:19 martin Exp $*/
 
 /******************************************************************************
 
@@ -1403,7 +1403,7 @@ static int
 ixv_allocate_pci_resources(struct adapter *adapter,
     const struct pci_attach_args *pa)
 {
-	pcireg_t	memtype;
+	pcireg_t	memtype, csr;
 	device_t        dev = adapter->dev;
 	bus_addr_t addr;
 	int flags;
@@ -1428,6 +1428,15 @@ map_err:
 			aprint_error_dev(dev, "unable to map BAR0\n");
 			return ENXIO;
 		}
+		/*
+		 * Enable address decoding for memory range in case it's not
+		 * set.
+		 */
+		csr = pci_conf_read(pa->pa_pc, pa->pa_tag,
+		    PCI_COMMAND_STATUS_REG);
+		csr |= PCI_COMMAND_MEM_ENABLE;
+		pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
+		    csr);
 		break;
 	default:
 		aprint_error_dev(dev, "unexpected type on BAR0\n");

Reply via email to