fpga: dfl: Avoid reads to AFU CSRs during enumeration
authorRuss Weight <russell.h.weight@intel.com>
Thu, 16 Sep 2021 21:07:33 +0000 (14:07 -0700)
committerMoritz Fischer <mdf@kernel.org>
Thu, 16 Sep 2021 22:20:55 +0000 (15:20 -0700)
CSR address space for Accelerator Functional Units (AFU) is not available
during the early Device Feature List (DFL) enumeration. Early access
to this space results in invalid data and port errors. This change adds
a condition to prevent an early read from the AFU CSR space.

Fixes: 1604986c3e6b ("fpga: dfl: expose feature revision from struct dfl_device")
Cc: stable@vger.kernel.org
Signed-off-by: Russ Weight <russell.h.weight@intel.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
drivers/fpga/dfl.c

index c99b78ee008aa3d50c4b3cf8952495bbb7976d51..f86666cf2c6a867f53a10bc407074a6be1c3d3f6 100644 (file)
@@ -1019,16 +1019,18 @@ create_feature_instance(struct build_feature_devs_info *binfo,
 {
        unsigned int irq_base, nr_irqs;
        struct dfl_feature_info *finfo;
+       u8 revision = 0;
        int ret;
-       u8 revision;
        u64 v;
 
-       v = readq(binfo->ioaddr + ofst);
-       revision = FIELD_GET(DFH_REVISION, v);
+       if (fid != FEATURE_ID_AFU) {
+               v = readq(binfo->ioaddr + ofst);
+               revision = FIELD_GET(DFH_REVISION, v);
 
-       /* read feature size and id if inputs are invalid */
-       size = size ? size : feature_size(v);
-       fid = fid ? fid : feature_id(v);
+               /* read feature size and id if inputs are invalid */
+               size = size ? size : feature_size(v);
+               fid = fid ? fid : feature_id(v);
+       }
 
        if (binfo->len - ofst < size)
                return -EINVAL;