[v2] usertools: enhance device bind script module detection

Message ID 20191102142316.750-1-pbhagavatula@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] usertools: enhance device bind script module detection |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/travis-robot success Travis build: passed
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-compilation success Compile Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Pavan Nikhilesh Bhagavatula Nov. 2, 2019, 2:23 p.m. UTC
  From: Pavan Nikhilesh <pbhagavatula@marvell.com>

Some kernel modules use '-' in their name when registering through
`pci_register_driver` and the same name  is populated in
'/sys/bus/pci/drivers/'.
But the kernel always populates modules names replacing '-' with '_'
in '/sys/module/'.

Example:
	# ./usertools/dpdk-devbind.py -b octeontx2-nicpf 0002:03:00.0
	Error: Driver 'octeontx2-nicpf' is not loaded.

	# ls /sys/bus/pci/drivers/octeontx2-nicpf
	bind  module  new_id  remove_id  uevent  unbind
	# ls /sys/module/octeontx2_nicpf/
	drivers  uevent  version

The patch addresses it by always replacing '-' with '_' when looking in
'/sys/module/'

Signed-off-by: Phanendra Vukkisala <pvukkisala@marvell.com>
Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>
---
 usertools/dpdk-devbind.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Thomas Monjalon Nov. 26, 2019, 10:55 p.m. UTC | #1
02/11/2019 15:23, pbhagavatula@marvell.com:
> From: Pavan Nikhilesh <pbhagavatula@marvell.com>
> 
> Some kernel modules use '-' in their name when registering through
> `pci_register_driver` and the same name  is populated in
> '/sys/bus/pci/drivers/'.
> But the kernel always populates modules names replacing '-' with '_'
> in '/sys/module/'.
> 
> Example:
> 	# ./usertools/dpdk-devbind.py -b octeontx2-nicpf 0002:03:00.0
> 	Error: Driver 'octeontx2-nicpf' is not loaded.
> 
> 	# ls /sys/bus/pci/drivers/octeontx2-nicpf
> 	bind  module  new_id  remove_id  uevent  unbind
> 	# ls /sys/module/octeontx2_nicpf/
> 	drivers  uevent  version
> 
> The patch addresses it by always replacing '-' with '_' when looking in
> '/sys/module/'
> 
> Signed-off-by: Phanendra Vukkisala <pvukkisala@marvell.com>
> Signed-off-by: Pavan Nikhilesh <pbhagavatula@marvell.com>

Applied, thanks for the clear explanation.
  

Patch

diff --git a/usertools/dpdk-devbind.py b/usertools/dpdk-devbind.py
index 7b5cbc12c..b1d149876 100755
--- a/usertools/dpdk-devbind.py
+++ b/usertools/dpdk-devbind.py
@@ -153,6 +153,9 @@  def check_output(args, stderr=None):
 def module_is_loaded(module):
     global loaded_modules
 
+    if module == 'vfio_pci':
+        module = 'vfio-pci'
+
     if loaded_modules:
         return module in loaded_modules
 
@@ -520,7 +523,7 @@  def bind_all(dev_list, driver, force=False):
         pass
 
     # check if we're attempting to bind to a driver that isn't loaded
-    if not module_is_loaded(driver):
+    if not module_is_loaded(driver.replace('-','_')):
         sys.exit("Error: Driver '%s' is not loaded." % driver)
 
     try: