summaryrefslogtreecommitdiff
path: root/tools/devbind/devbind.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/devbind/devbind.py')
-rw-r--r--tools/devbind/devbind.py34
1 files changed, 28 insertions, 6 deletions
diff --git a/tools/devbind/devbind.py b/tools/devbind/devbind.py
index 62d4a5b..c0ec822 100644
--- a/tools/devbind/devbind.py
+++ b/tools/devbind/devbind.py
@@ -26,7 +26,12 @@ def init():
with open("/etc/sysconfig/mrzcpd", 'r') as drive_fp:
for line in drive_fp.readlines():
if re.search("DEFAULT_UIO_MODULE=*", line):
- dpdk_driver = line.split('DEFAULT_UIO_MODULE=')[1]
+ str_driver = line.split('DEFAULT_UIO_MODULE=')[1]
+ match = re.search(r'"(.*?)"', str_driver)
+ if match:
+ dpdk_driver = match.group(1)
+ if match.group(1) == "vfio_pci".strip():
+ dpdk_driver = "vfio-pci"
if re.search("MRZCPD_ROOT=*", line):
mrzcpd_root = line.split('MRZCPD_ROOT=')[1]
@@ -79,18 +84,35 @@ def nic_bind():
for d in interfaces:
if d in hwinfo and hwinfo.get(d).get('driver') != 'mlx5_core':
bind_cmd = dpdk_bind + ' --bind=' + \
- dpdk_driver.replace("\n", " ") + hwinfo.get(d).get('pci')
+ dpdk_driver + " " + hwinfo.get(d).get('pci')
print("bind cmd:", bind_cmd)
if os.system(bind_cmd):
print("bind dev err")
sys.exit(1)
+def nic_unbind():
+ for d in interfaces:
+ if d in hwinfo and hwinfo.get(d).get('driver') != 'mlx5_core':
+ dpdk_driver_unbind = hwinfo.get(d).get('driver')
+ unbind_cmd = dpdk_bind + ' --bind=' + \
+ dpdk_driver_unbind + " " + hwinfo.get(d).get('pci')
+ print("unbind cmd:", unbind_cmd)
+ if os.system(unbind_cmd):
+ print("unbind dev err")
+ sys.exit(1)
+
+
def main():
- # module load
- module_load()
- # bind dev
- nic_bind()
+ args = sys.argv
+ if args[1] == "bind":
+ # module load
+ module_load()
+ # bind dev
+ nic_bind()
+ elif args[1] == "unbind":
+ # unbind dev
+ nic_unbind()
if __name__ == "__main__":