Blame SOURCES/0001-Reinclude-fpgaport-in-tools.patch

e498dc
From 76d42fe3e3f2007e4fe18e27e0a68840713cda2a Mon Sep 17 00:00:00 2001
e498dc
From: Tom Rix <trix@redhat.com>
e498dc
Date: Wed, 13 May 2020 10:57:37 -0400
e498dc
Subject: [PATCH 1/2] Reinclude fpgaport in tools
e498dc
e498dc
In existing documentation fpgaport is the used to do the driver
e498dc
ioctl call for fme port release and assign.  This is needed for
e498dc
the sr-iov workflow.
e498dc
e498dc
Import from 1.4.0 and change to python3
e498dc
e498dc
Signed-off-by: Tom Rix <trix@redhat.com>
e498dc
---
e498dc
 tools/CMakeLists.txt          |  1 +
e498dc
 tools/fpgaport/CMakeLists.txt | 29 ++++++++++++++
e498dc
 tools/fpgaport/fpgaport       | 72 +++++++++++++++++++++++++++++++++++
e498dc
 3 files changed, 102 insertions(+)
e498dc
 create mode 100644 tools/fpgaport/CMakeLists.txt
e498dc
 create mode 100755 tools/fpgaport/fpgaport
e498dc
e498dc
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
e498dc
index 9674af02..d4b55036 100644
e498dc
--- a/tools/CMakeLists.txt
e498dc
+++ b/tools/CMakeLists.txt
e498dc
@@ -31,6 +31,7 @@ opae_add_subdirectory(libboard/board_dc)
e498dc
 opae_add_subdirectory(fpgaconf)
e498dc
 opae_add_subdirectory(fpgainfo)
e498dc
 opae_add_subdirectory(fpgametrics)
e498dc
+opae_add_subdirectory(fpgaport)
e498dc
 
e498dc
 # extra
e498dc
 opae_add_subdirectory(extra/userclk)
e498dc
diff --git a/tools/fpgaport/CMakeLists.txt b/tools/fpgaport/CMakeLists.txt
e498dc
new file mode 100644
e498dc
index 00000000..cb16c8e9
e498dc
--- /dev/null
e498dc
+++ b/tools/fpgaport/CMakeLists.txt
e498dc
@@ -0,0 +1,29 @@
e498dc
+## Copyright(c) 2017, Intel Corporation
e498dc
+##
e498dc
+## Redistribution  and  use  in source  and  binary  forms,  with  or  without
e498dc
+## modification, are permitted provided that the following conditions are met:
e498dc
+##
e498dc
+## * Redistributions of  source code  must retain the  above copyright notice,
e498dc
+##   this list of conditions and the following disclaimer.
e498dc
+## * Redistributions in binary form must reproduce the above copyright notice,
e498dc
+##   this list of conditions and the following disclaimer in the documentation
e498dc
+##   and/or other materials provided with the distribution.
e498dc
+## * Neither the name  of Intel Corporation  nor the names of its contributors
e498dc
+##   may be used to  endorse or promote  products derived  from this  software
e498dc
+##   without specific prior written permission.
e498dc
+##
e498dc
+## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
e498dc
+## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT NOT LIMITED TO,  THE
e498dc
+## IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
e498dc
+## ARE DISCLAIMED.  IN NO EVENT  SHALL THE COPYRIGHT OWNER  OR CONTRIBUTORS BE
e498dc
+## LIABLE  FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
e498dc
+## CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT LIMITED  TO,  PROCUREMENT  OF
e498dc
+## SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
e498dc
+## INTERRUPTION)  HOWEVER CAUSED  AND ON ANY THEORY  OF LIABILITY,  WHETHER IN
e498dc
+## CONTRACT,  STRICT LIABILITY,  OR TORT  (INCLUDING NEGLIGENCE  OR OTHERWISE)
e498dc
+## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
e498dc
+## POSSIBILITY OF SUCH DAMAGE.
e498dc
+
e498dc
+install(PROGRAMS fpgaport
e498dc
+        DESTINATION bin
e498dc
+        COMPONENT toolfpgaport)
e498dc
diff --git a/tools/fpgaport/fpgaport b/tools/fpgaport/fpgaport
e498dc
new file mode 100755
e498dc
index 00000000..2f707183
e498dc
--- /dev/null
e498dc
+++ b/tools/fpgaport/fpgaport
e498dc
@@ -0,0 +1,72 @@
e498dc
+#! /usr/bin/python3
e498dc
+# Copyright(c) 2017, Intel Corporation
e498dc
+#
e498dc
+# Redistribution  and  use  in source  and  binary  forms,  with  or  without
e498dc
+# modification, are permitted provided that the following conditions are met:
e498dc
+#
e498dc
+# * Redistributions of  source code  must retain the  above copyright notice,
e498dc
+#   this list of conditions and the following disclaimer.
e498dc
+# * Redistributions in binary form must reproduce the above copyright notice,
e498dc
+#   this list of conditions and the following disclaimer in the documentation
e498dc
+#   and/or other materials provided with the distribution.
e498dc
+# * Neither the name  of Intel Corporation  nor the names of its contributors
e498dc
+#   may be used to  endorse or promote  products derived  from this  software
e498dc
+#   without specific prior written permission.
e498dc
+#
e498dc
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
e498dc
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT NOT LIMITED TO,  THE
e498dc
+# IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
e498dc
+# ARE DISCLAIMED.  IN NO EVENT  SHALL THE COPYRIGHT OWNER  OR CONTRIBUTORS BE
e498dc
+# LIABLE  FOR  ANY  DIRECT,  INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
e498dc
+# CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT LIMITED  TO,  PROCUREMENT  OF
e498dc
+# SUBSTITUTE GOODS OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
e498dc
+# INTERRUPTION)  HOWEVER CAUSED  AND ON ANY THEORY  OF LIABILITY,  WHETHER IN
e498dc
+# CONTRACT,  STRICT LIABILITY,  OR TORT  (INCLUDING NEGLIGENCE  OR OTHERWISE)
e498dc
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
e498dc
+# POSSIBILITY OF SUCH DAMAGE.
e498dc
+
e498dc
+import fcntl, os, sys, argparse, stat, struct
e498dc
+
e498dc
+FPGA_FME_PORT_ASSIGN = 0xB582
e498dc
+FPGA_FME_PORT_RELEASE = 0xB581
e498dc
+
e498dc
+if __name__ == "__main__":
e498dc
+
e498dc
+	# parse command line arguments
e498dc
+	parser = argparse.ArgumentParser()
e498dc
+	parser.add_argument('action', help = 'action to perform', action = 'store', choices = ['assign', 'release'])
e498dc
+	parser.add_argument('device', help = 'the FPGA (FME) device')
e498dc
+	parser.add_argument('port', type = int, help = 'the number of the port')
e498dc
+
e498dc
+	args = parser.parse_args()
e498dc
+
e498dc
+	# check device file
e498dc
+	try:
e498dc
+		mode = os.stat(args.device).st_mode
e498dc
+		if not stat.S_ISCHR(mode):
e498dc
+			print( args.device, "is not a device file.")
e498dc
+	except Exception as e:
e498dc
+		print("Couldn't open", args.device, ":", e)
e498dc
+		sys.exit(1)
e498dc
+
e498dc
+	# open FPGA device
e498dc
+	try:
e498dc
+		f = open(args.device, "rw")
e498dc
+	except Exception as e:
e498dc
+		print("open() failed:", e)
e498dc
+		sys.exit(1)
e498dc
+
e498dc
+	# send IOCTL
e498dc
+	ioctl_data = struct.pack('III', 12, 0, args.port)
e498dc
+	try:
e498dc
+		if args.action == 'assign':
e498dc
+			ret = fcntl.ioctl(f, FPGA_FME_PORT_ASSIGN, ioctl_data)
e498dc
+		else:
e498dc
+			ret = fcntl.ioctl(f, FPGA_FME_PORT_RELEASE, ioctl_data)
e498dc
+	except Exception as e:
e498dc
+		print("ioctl() failed:", e)
e498dc
+		f.close()
e498dc
+		sys.exit(1)
e498dc
+
e498dc
+	# close FPGA device
e498dc
+	f.close()
e498dc
-- 
e498dc
2.18.2
e498dc