Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci If the memory space's BAR and the MSI-X table is...



details:   https://anonhg.NetBSD.org/src/rev/f3e4d713daf4
branches:  trunk
changeset: 1002467:f3e4d713daf4
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Thu Aug 01 13:43:28 2019 +0000

description:
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@.

diffstat:

 sys/dev/pci/if_ena.c |  62 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 52 insertions(+), 10 deletions(-)

diffs (79 lines):

diff -r 1166b50fca1d -r f3e4d713daf4 sys/dev/pci/if_ena.c
--- a/sys/dev/pci/if_ena.c      Thu Aug 01 13:36:37 2019 +0000
+++ b/sys/dev/pci/if_ena.c      Thu Aug 01 13:43:28 2019 +0000
@@ -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 @@
 ena_allocate_pci_resources(struct pci_attach_args *pa,
     struct ena_adapter *adapter)
 {
-       bus_size_t size;
-
-       /*
-        * 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");
+       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);
+       }
+
+       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;
        }
 



Home | Main Index | Thread Index | Old Index