Module Name: src Committed By: msaitoh Date: Thu Aug 1 13:43:28 UTC 2019
Modified Files: src/sys/dev/pci: if_ena.c Log Message: 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@. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 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/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.16 --- src/sys/dev/pci/if_ena.c:1.15 Wed May 29 10:07:29 2019 +++ src/sys/dev/pci/if_ena.c Thu Aug 1 13:43:28 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.16 2019/08/01 13:43:28 msaitoh 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; }