From 3f00ab8be6c37f9ca6435727d425306c0a5704c0 Mon Sep 17 00:00:00 2001
From: Devendar Gali <devendar.gali@amd.com>
Date: Tue, 20 Feb 2024 16:50:24 +0530
Subject: [PATCH] QDMA: Bypass user BAR check for XRT application

If the user BAR is not present in the customer specific design
do not return error as this check is specific to example design.
Instead report user BAR not found and proceed further.

Signed-off-by: Devendar Gali <devendar.gali@amd.com>
---
 QDMA/linux-kernel/RELEASE               |  7 +++++--
 QDMA/linux-kernel/driver/libqdma/xdev.c | 18 ++++++++++++++----
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/QDMA/linux-kernel/RELEASE b/QDMA/linux-kernel/RELEASE
index 8733947..39807d7 100755
--- a/QDMA/linux-kernel/RELEASE
+++ b/QDMA/linux-kernel/RELEASE
@@ -180,8 +180,11 @@ DRIVER LIMITATIONS:
 	- For optimal QDMA streaming performance, packet buffers of the descriptor ring should be aligned to at least 256 bytes.
 	- FLR is not supported in the Driver for CentOS because linux kernels provided in CentOS versions does not support the driver call back registration for FLR functionality
 
-
-
+- XRT Only
+	- QDMA: Bypass user BAR check for XRT application
+		- The existing driver code assmues the presence of the user BAR as indicated in the functional example design. If this user BAR is not detected during the driver probing process,
+                  it results in a failure. However, this check is specific to example design and some customer designs might not contain user BAR. So bypassing the user BAR check to prevent
+                  driver returning error and proceed further.
 
 
 
diff --git a/QDMA/linux-kernel/driver/libqdma/xdev.c b/QDMA/linux-kernel/driver/libqdma/xdev.c
index a524e4d..19880a5 100755
--- a/QDMA/linux-kernel/driver/libqdma/xdev.c
+++ b/QDMA/linux-kernel/driver/libqdma/xdev.c
@@ -42,6 +42,9 @@
 #ifdef DEBUGFS
 #include "qdma_debugfs_dev.h"
 #endif
+#ifdef __XRT__
+#include "qdma_access_errors.h"
+#endif
 
 #ifdef __LIST_NEXT_ENTRY__
 #define list_next_entry(pos, member) \
@@ -535,6 +538,7 @@ static int xdev_map_bars(struct xlnx_dma_dev *xdev, struct pci_dev *pdev)
 static int xdev_identify_bars(struct xlnx_dma_dev *xdev, struct pci_dev *pdev)
 {
 	int bar_idx = 0;
+	int rv = 0;
 	u8 num_bars_present = 0;
 	int bar_id_list[QDMA_BAR_NUM];
 	int bar_id_idx = 0;
@@ -553,7 +557,6 @@ static int xdev_identify_bars(struct xlnx_dma_dev *xdev, struct pci_dev *pdev)
 	}
 
 	if (num_bars_present > 1) {
-		int rv = 0;
 
 		/* AXI Master Lite BAR IDENTIFICATION */
 		if ((xdev->version_info.ip_type == QDMA_VERSAL_HARD_IP) &&
@@ -575,7 +578,14 @@ static int xdev_identify_bars(struct xlnx_dma_dev *xdev, struct pci_dev *pdev)
 		if (rv < 0) {
 			pr_err("get AXI Master Lite bar failed with error = %d",
 					rv);
+#ifdef __XRT__
+			/** This change is for XRT application,
+			 * when there is no user BAR in desin
+			 */
+			rv = QDMA_ERR_HWACC_BAR_NOT_FOUND;
+#else
 			return xdev->hw.qdma_get_error_code(rv);
+#endif
 		}
 
 		pr_info("AXI Master Lite BAR %d.\n",
@@ -598,7 +608,7 @@ static int xdev_identify_bars(struct xlnx_dma_dev *xdev, struct pci_dev *pdev)
 			}
 		}
 	}
-	return 0;
+	return rv;
 }
 
 /*****************************************************************************/
@@ -1167,7 +1177,7 @@ int qdma_device_open(const char *mod_name, struct qdma_dev_conf *conf,
 	}
 
 	rv = xdev_identify_bars(xdev, pdev);
-	if (rv) {
+	if (rv < 0) {
 		pr_err("Failed to identify bars, err %d", rv);
 		goto unmap_bars;
 	}
@@ -1185,7 +1195,7 @@ int qdma_device_open(const char *mod_name, struct qdma_dev_conf *conf,
 
 	*dev_hndl = (unsigned long)xdev;
 
-	return 0;
+	return rv;
 
 cleanup_qdma:
 	qdma_device_offline(pdev, (unsigned long)xdev, XDEV_FLR_INACTIVE);
-- 
GitLab