test/cksum: new test for L3/L4 checksum API
[dpdk.git] / usertools / dpdk-devbind.py
index b0aba2c..98bd1b7 100755 (executable)
@@ -7,9 +7,10 @@ import sys
 import os
 import subprocess
 import argparse
+import platform
 
 from glob import glob
-from os.path import exists, abspath, dirname, basename
+from os.path import exists, basename
 from os.path import join as path_join
 
 # The PCI base class for all devices
@@ -107,7 +108,17 @@ def module_is_loaded(module):
 
     loaded_modules = sysfs_mods
 
-    return module in sysfs_mods
+    # add built-in modules as loaded
+    release = platform.uname().release
+    filename = os.path.join("/lib/modules/", release, "modules.builtin")
+    if os.path.exists(filename):
+        try:
+            with open(filename) as f:
+                loaded_modules += [os.path.splitext(os.path.basename(mod))[0] for mod in f]
+        except IOError:
+            print("Warning: cannot read list of built-in kernel modules")
+
+    return module in loaded_modules
 
 
 def check_modules():
@@ -341,7 +352,7 @@ def bind_one(dev_id, driver, force):
     # of unbinding those devices
     if driver in dpdk_drivers:
         filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id
-        if os.path.exists(filename):
+        if exists(filename):
             try:
                 f = open(filename, "w")
             except:
@@ -404,7 +415,7 @@ def bind_one(dev_id, driver, force):
     # Before unbinding it, overwrite driver_override with empty string so that
     # the device can be bound to any other driver
     filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id
-    if os.path.exists(filename):
+    if exists(filename):
         try:
             f = open(filename, "w")
         except:
@@ -472,7 +483,7 @@ def bind_all(dev_list, driver, force=False):
     # that are not bound to any other driver could be bound even if no one has
     # asked them to. hence, we check the list of drivers again, and see if
     # some of the previously-unbound devices were erroneously bound.
-    if not os.path.exists("/sys/bus/pci/devices/%s/driver_override" % d):
+    if not exists("/sys/bus/pci/devices/%s/driver_override" % d):
         for d in devices.keys():
             # skip devices that were already bound or that we know should be bound
             if "Driver_str" in devices[d] or d in dev_list:
@@ -557,28 +568,28 @@ def show_status():
     Displays to the user what devices are bound to the igb_uio driver, the
     kernel driver or to no driver'''
 
-    if status_dev == "net" or status_dev == "all":
+    if status_dev in ["net", "all"]:
         show_device_status(network_devices, "Network", if_field=True)
 
-    if status_dev == "baseband" or status_dev == "all":
+    if status_dev in ["baseband", "all"]:
         show_device_status(baseband_devices, "Baseband")
 
-    if status_dev == "crypto" or status_dev == "all":
+    if status_dev in ["crypto", "all"]:
         show_device_status(crypto_devices, "Crypto")
 
-    if status_dev == "event" or status_dev == "all":
+    if status_dev in ["event", "all"]:
         show_device_status(eventdev_devices, "Eventdev")
 
-    if status_dev == "mempool" or status_dev == "all":
+    if status_dev in ["mempool", "all"]:
         show_device_status(mempool_devices, "Mempool")
 
-    if status_dev == "compress" or status_dev == "all":
+    if status_dev in ["compress", "all"]:
         show_device_status(compress_devices, "Compress")
 
-    if status_dev == "misc" or status_dev == "all":
+    if status_dev in ["misc", "all"]:
         show_device_status(misc_devices, "Misc (rawdev)")
 
-    if status_dev == "regex" or status_dev == "all":
+    if status_dev in ["regex", "all"]:
         show_device_status(regex_devices, "Regex")
 
 
@@ -634,7 +645,8 @@ To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver
     parser.add_argument(
         '--status-dev',
         help="Print the status of given device group.",
-        choices=['net', 'baseband', 'crypto', 'event', 'mempool', 'compress'])
+        choices=['baseband', 'compress', 'crypto', 'event',
+                'mempool', 'misc', 'net', 'regex'])
     bind_group = parser.add_mutually_exclusive_group()
     bind_group.add_argument(
         '-b',
@@ -703,7 +715,7 @@ def do_arg_actions():
     global force_flag
     global args
 
-    if b_flag == "none" or b_flag == "None":
+    if b_flag in ["none", "None"]:
         unbind_all(args, force_flag)
     elif b_flag is not None:
         bind_all(args, b_flag, force_flag)