Module Name:    src
Committed By:   martin
Date:           Fri Aug  9 16:06:39 UTC 2019

Modified Files:
        src/doc [netbsd-9]: 3RDPARTY
        src/sys/arch/amd64/conf [netbsd-9]: GENERIC
        src/sys/dev/pci [netbsd-9]: if_ena.c

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

        doc/3RDPARTY: revision 1.1641
        sys/dev/pci/if_ena.c: revision 1.16
        sys/arch/amd64/conf/GENERIC: revision 1.532

If the memory space's BAR and the MSI-X table is on the same BAR,
reserve the space. Almost the same as nvme_pci.c and xhci_pci.c.
Tested by ryoon@.

Add ena(4).


To generate a diff of this commit:
cvs rdiff -u -r1.1640 -r1.1640.2.1 src/doc/3RDPARTY
cvs rdiff -u -r1.531.2.1 -r1.531.2.2 src/sys/arch/amd64/conf/GENERIC
cvs rdiff -u -r1.15 -r1.15.2.1 src/sys/dev/pci/if_ena.c

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

Modified files:

Index: src/doc/3RDPARTY
diff -u src/doc/3RDPARTY:1.1640 src/doc/3RDPARTY:1.1640.2.1
--- src/doc/3RDPARTY:1.1640	Tue Jul 30 14:57:06 2019
+++ src/doc/3RDPARTY	Fri Aug  9 16:06:39 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: 3RDPARTY,v 1.1640 2019/07/30 14:57:06 joerg Exp $
+#	$NetBSD: 3RDPARTY,v 1.1640.2.1 2019/08/09 16:06:39 martin Exp $
 #
 # This file contains a list of the software that has been integrated into
 # NetBSD where we are not the primary maintainer.
@@ -2109,6 +2109,7 @@ Notes:
 Use groff2netbsd from external/gpl2/groff/groff2netbsd to prepare the
 distribution for import.
 Update MDATE in src/external/gpl2/groff/Makefile.inc.
+
 Package:	gmake
 Version:	3.81 (Last GPlv2+ version)
 Current Vers:	4.2
@@ -2174,3 +2175,15 @@ License:	BSD-like (4-clause)
 Location:	usr.bin/indent
 Notes:
 Tests are stored in tests/usr.bin/indent.
+
+Package:	ena
+Version:	0.8.1
+Current Vers:	2.0.0
+Maintainer:	Amazon.com
+Archive Site:	https://github.com/amzn/amzn-drivers/tree/master/kernel/fbsd/ena
+Home Page:	https://github.com/amzn/amzn-drivers/
+Mailing List:	none
+Responsible:
+License:	BSD-like (2 and 3-clause)
+Location:	sys/external/bsd/ena-com
+Notes:

Index: src/sys/arch/amd64/conf/GENERIC
diff -u src/sys/arch/amd64/conf/GENERIC:1.531.2.1 src/sys/arch/amd64/conf/GENERIC:1.531.2.2
--- src/sys/arch/amd64/conf/GENERIC:1.531.2.1	Fri Aug  9 15:59:52 2019
+++ src/sys/arch/amd64/conf/GENERIC	Fri Aug  9 16:06:39 2019
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.531.2.1 2019/08/09 15:59:52 martin Exp $
+# $NetBSD: GENERIC,v 1.531.2.2 2019/08/09 16:06:39 martin Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@ include 	"arch/amd64/conf/std.amd64"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident		"GENERIC-$Revision: 1.531.2.1 $"
+#ident		"GENERIC-$Revision: 1.531.2.2 $"
 
 maxusers	64		# estimated number of users
 
@@ -771,6 +771,7 @@ bnx*	at pci? dev ? function ?	# Broadcom
 bwi*	at pci? dev ? function ?	# Broadcom BCM43xx wireless
 bwfm*	at pci? dev ? function ?	# Broadcom FullMAC
 dge*	at pci? dev ? function ?	# Intel 82597 10GbE LR
+ena*	at pci? dev ? function ?	# Amazon.com Elastic Network Adapter
 ep*	at pci? dev ? function ?	# 3Com 3c59x
 epic*	at pci? dev ? function ?	# SMC EPIC/100 Ethernet
 esh*	at pci? dev ? function ?	# Essential HIPPI card

Index: src/sys/dev/pci/if_ena.c
diff -u src/sys/dev/pci/if_ena.c:1.15 src/sys/dev/pci/if_ena.c:1.15.2.1
--- src/sys/dev/pci/if_ena.c:1.15	Wed May 29 10:07:29 2019
+++ src/sys/dev/pci/if_ena.c	Fri Aug  9 16:06:39 2019
@@ -31,7 +31,7 @@
 #if 0
 __FBSDID("$FreeBSD: head/sys/dev/ena/ena.c 333456 2018-05-10 09:37:54Z mw $");
 #endif
-__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.15 2019/05/29 10:07:29 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ena.c,v 1.15.2.1 2019/08/09 16:06:39 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -273,15 +273,57 @@ static int
 ena_allocate_pci_resources(struct pci_attach_args *pa,
     struct ena_adapter *adapter)
 {
-	bus_size_t size;
+	pcireg_t memtype, reg;
+	bus_addr_t memaddr;
+	bus_size_t mapsize;
+	int flags, error;
+	int msixoff;
+
+	memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, ENA_REG_BAR);
+	if (PCI_MAPREG_TYPE(memtype) != PCI_MAPREG_TYPE_MEM) {
+		aprint_error_dev(adapter->pdev, "invalid type (type=0x%x)\n",
+		    memtype);
+		return ENXIO;
+	}
+	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);
+	}
 
-	/*
-	 * Map control/status registers.
-	*/
-	pcireg_t memtype = pci_mapreg_type(pa->pa_pc, pa->pa_tag, ENA_REG_BAR);
-	if (pci_mapreg_map(pa, ENA_REG_BAR, memtype, 0, &adapter->sc_btag,
-	    &adapter->sc_bhandle, NULL, &size)) {
-		aprint_error(": can't map mem space\n");
+	adapter->sc_btag = pa->pa_memt;
+	error = pci_mapreg_info(pa->pa_pc, pa->pa_tag, ENA_REG_BAR,
+	    memtype, &memaddr, &mapsize, &flags);
+	if (error) {
+		aprint_error_dev(adapter->pdev, "can't get map info\n");
+		return ENXIO;
+	}
+
+	if (pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_MSIX, &msixoff,
+	    NULL)) {
+		pcireg_t msixtbl;
+		uint32_t table_offset;
+		int bir;
+
+		msixtbl = pci_conf_read(pa->pa_pc, pa->pa_tag,
+		    msixoff + PCI_MSIX_TBLOFFSET);
+		table_offset = msixtbl & PCI_MSIX_TBLOFFSET_MASK;
+		bir = msixtbl & PCI_MSIX_PBABIR_MASK;
+		if (bir == PCI_MAPREG_NUM(ENA_REG_BAR))
+			mapsize = table_offset;
+	}
+
+	error = bus_space_map(adapter->sc_btag, memaddr, mapsize, flags,
+	    &adapter->sc_bhandle);
+	if (error != 0) {
+		aprint_error_dev(adapter->pdev,
+		    "can't map mem space (error=%d)\n", error);
 		return ENXIO;
 	}
 

Reply via email to