common/sfc_efx/base: add efsys option for Riverhead
[dpdk.git] / usertools / dpdk-devbind.py
index dc00882..094c2ff 100755 (executable)
@@ -8,7 +8,13 @@ import sys
 import os
 import getopt
 import subprocess
 import os
 import getopt
 import subprocess
+from glob import glob
 from os.path import exists, abspath, dirname, basename
 from os.path import exists, abspath, dirname, basename
+from os.path import join as path_join
+
+if sys.version_info.major < 3:
+    print("WARNING: Python 2 is deprecated for use in DPDK, and will not work in future releases.", file=sys.stderr)
+    print("Please use Python 3 instead", file=sys.stderr)
 
 # The PCI base class for all devices
 network_class = {'Class': '02', 'Vendor': None, 'Device': None,
 
 # The PCI base class for all devices
 network_class = {'Class': '02', 'Vendor': None, 'Device': None,
@@ -85,6 +91,8 @@ Usage:
 where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
 or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
 also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
 where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
 or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
 also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
+If devices are specified using PCI <domain:>bus:device:func format, then
+shell wildcards and ranges may be used, e.g. 80:04.*, 80:04.[0-3]
 
 Options:
     --help, --usage:
 
 Options:
     --help, --usage:
@@ -141,6 +149,9 @@ To unbind 0000:01:00.0 from using any driver
 To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
         %(argv0)s -b ixgbe 02:00.0 02:00.1
 
 To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
         %(argv0)s -b ixgbe 02:00.0 02:00.1
 
+To bind all functions on device 0000:02:00 to ixgbe kernel driver
+        %(argv0)s -b ixgbe 02:00.*
+
     """ % locals())  # replace items from local variables
 
 
     """ % locals())  # replace items from local variables
 
 
@@ -579,7 +590,7 @@ def display_devices(title, dev_list, extra_params=None):
     strings.sort()
     print("\n".join(strings))  # print one per line
 
     strings.sort()
     print("\n".join(strings))  # print one per line
 
-def show_device_status(devices_type, device_name):
+def show_device_status(devices_type, device_name, if_field=False):
     global dpdk_drivers
     kernel_drv = []
     dpdk_drv = []
     global dpdk_drivers
     kernel_drv = []
     dpdk_drv = []
@@ -611,8 +622,11 @@ def show_device_status(devices_type, device_name):
         display_devices("%s devices using DPDK-compatible driver" % device_name,
                         dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s")
     if len(kernel_drv) != 0:
         display_devices("%s devices using DPDK-compatible driver" % device_name,
                         dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s")
     if len(kernel_drv) != 0:
+        if_text = ""
+        if if_field:
+            if_text = "if=%(Interface)s "
         display_devices("%s devices using kernel driver" % device_name, kernel_drv,
         display_devices("%s devices using kernel driver" % device_name, kernel_drv,
-                        "if=%(Interface)s drv=%(Driver_str)s "
+                        if_text + "drv=%(Driver_str)s "
                         "unused=%(Module_str)s %(Active)s")
     if len(no_drv) != 0:
         display_devices("Other %s devices" % device_name, no_drv,
                         "unused=%(Module_str)s %(Active)s")
     if len(no_drv) != 0:
         display_devices("Other %s devices" % device_name, no_drv,
@@ -624,7 +638,7 @@ def show_status():
     kernel driver or to no driver'''
 
     if status_dev == "net" or status_dev == "all":
     kernel driver or to no driver'''
 
     if status_dev == "net" or status_dev == "all":
-        show_device_status(network_devices, "Network")
+        show_device_status(network_devices, "Network", if_field=True)
 
     if status_dev == "baseband" or status_dev == "all":
         show_device_status(baseband_devices, "Baseband")
 
     if status_dev == "baseband" or status_dev == "all":
         show_device_status(baseband_devices, "Baseband")
@@ -644,6 +658,19 @@ def show_status():
     if status_dev == "misc" or status_dev == "all":
         show_device_status(misc_devices, "Misc (rawdev)")
 
     if status_dev == "misc" or status_dev == "all":
         show_device_status(misc_devices, "Misc (rawdev)")
 
+
+def pci_glob(arg):
+    '''Returns a list containing either:
+    * List of PCI B:D:F matching arg, using shell wildcards e.g. 80:04.*
+    * Only the passed arg if matching list is empty'''
+    sysfs_path = "/sys/bus/pci/devices"
+    for _glob in [arg, '0000:' + arg]:
+        paths = [basename(path) for path in glob(path_join(sysfs_path, _glob))]
+        if paths:
+            return paths
+    return [arg]
+
+
 def parse_args():
     '''Parses the command-line arguments given by the user and takes the
     appropriate action for each'''
 def parse_args():
     '''Parses the command-line arguments given by the user and takes the
     appropriate action for each'''
@@ -685,6 +712,11 @@ def parse_args():
             else:
                 b_flag = arg
 
             else:
                 b_flag = arg
 
+    # resolve any PCI globs in the args
+    new_args = []
+    for arg in args:
+        new_args.extend(pci_glob(arg))
+    args = new_args
 
 def do_arg_actions():
     '''do the actual action requested by the user'''
 
 def do_arg_actions():
     '''do the actual action requested by the user'''