1#! /usr/bin/env python 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright(c) 2010-2014 Intel Corporation 4# 5 6import sys 7import os 8import getopt 9import subprocess 10from os.path import exists, abspath, dirname, basename 11 12# The PCI base class for all devices 13network_class = {'Class': '02', 'Vendor': None, 'Device': None, 14 'SVendor': None, 'SDevice': None} 15acceleration_class = {'Class': '12', 'Vendor': None, 'Device': None, 16 'SVendor': None, 'SDevice': None} 17ifpga_class = {'Class': '12', 'Vendor': '8086', 'Device': '0b30', 18 'SVendor': None, 'SDevice': None} 19encryption_class = {'Class': '10', 'Vendor': None, 'Device': None, 20 'SVendor': None, 'SDevice': None} 21intel_processor_class = {'Class': '0b', 'Vendor': '8086', 'Device': None, 22 'SVendor': None, 'SDevice': None} 23cavium_sso = {'Class': '08', 'Vendor': '177d', 'Device': 'a04b,a04d', 24 'SVendor': None, 'SDevice': None} 25cavium_fpa = {'Class': '08', 'Vendor': '177d', 'Device': 'a053', 26 'SVendor': None, 'SDevice': None} 27cavium_pkx = {'Class': '08', 'Vendor': '177d', 'Device': 'a0dd,a049', 28 'SVendor': None, 'SDevice': None} 29cavium_tim = {'Class': '08', 'Vendor': '177d', 'Device': 'a051', 30 'SVendor': None, 'SDevice': None} 31cavium_zip = {'Class': '12', 'Vendor': '177d', 'Device': 'a037', 32 'SVendor': None, 'SDevice': None} 33avp_vnic = {'Class': '05', 'Vendor': '1af4', 'Device': '1110', 34 'SVendor': None, 'SDevice': None} 35 36octeontx2_sso = {'Class': '08', 'Vendor': '177d', 'Device': 'a0f9,a0fa', 37 'SVendor': None, 'SDevice': None} 38octeontx2_npa = {'Class': '08', 'Vendor': '177d', 'Device': 'a0fb,a0fc', 39 'SVendor': None, 'SDevice': None} 40octeontx2_dma = {'Class': '08', 'Vendor': '177d', 'Device': 'a081', 41 'SVendor': None, 'SDevice': None} 42 43intel_ioat_bdw = {'Class': '08', 'Vendor': '8086', 'Device': '6f20,6f21,6f22,6f23,6f24,6f25,6f26,6f27,6f2e,6f2f', 44 'SVendor': None, 'SDevice': None} 45intel_ioat_skx = {'Class': '08', 'Vendor': '8086', 'Device': '2021', 46 'SVendor': None, 'SDevice': None} 47intel_ntb_skx = {'Class': '06', 'Vendor': '8086', 'Device': '201c', 48 'SVendor': None, 'SDevice': None} 49 50network_devices = [network_class, cavium_pkx, avp_vnic, ifpga_class] 51baseband_devices = [acceleration_class] 52crypto_devices = [encryption_class, intel_processor_class] 53eventdev_devices = [cavium_sso, cavium_tim, octeontx2_sso] 54mempool_devices = [cavium_fpa, octeontx2_npa] 55compress_devices = [cavium_zip] 56misc_devices = [intel_ioat_bdw, intel_ioat_skx, intel_ntb_skx, octeontx2_dma] 57 58# global dict ethernet devices present. Dictionary indexed by PCI address. 59# Each device within this is itself a dictionary of device properties 60devices = {} 61# list of supported DPDK drivers 62dpdk_drivers = ["igb_uio", "vfio-pci", "uio_pci_generic"] 63 64# command-line arg flags 65b_flag = None 66status_flag = False 67force_flag = False 68args = [] 69 70 71def usage(): 72 '''Print usage information for the program''' 73 argv0 = basename(sys.argv[0]) 74 print(""" 75Usage: 76------ 77 78 %(argv0)s [options] DEVICE1 DEVICE2 .... 79 80where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax 81or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may 82also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc. 83 84Options: 85 --help, --usage: 86 Display usage information and quit 87 88 -s, --status: 89 Print the current status of all known network, crypto, event 90 and mempool devices. 91 For each device, it displays the PCI domain, bus, slot and function, 92 along with a text description of the device. Depending upon whether the 93 device is being used by a kernel driver, the igb_uio driver, or no 94 driver, other relevant information will be displayed: 95 * the Linux interface name e.g. if=eth0 96 * the driver being used e.g. drv=igb_uio 97 * any suitable drivers not currently using that device 98 e.g. unused=igb_uio 99 NOTE: if this flag is passed along with a bind/unbind option, the 100 status display will always occur after the other operations have taken 101 place. 102 103 --status-dev: 104 Print the status of given device group. Supported device groups are: 105 "net", "baseband", "crypto", "event", "mempool" and "compress" 106 107 -b driver, --bind=driver: 108 Select the driver to use or \"none\" to unbind the device 109 110 -u, --unbind: 111 Unbind a device (Equivalent to \"-b none\") 112 113 --force: 114 By default, network devices which are used by Linux - as indicated by 115 having routes in the routing table - cannot be modified. Using the 116 --force flag overrides this behavior, allowing active links to be 117 forcibly unbound. 118 WARNING: This can lead to loss of network connection and should be used 119 with caution. 120 121Examples: 122--------- 123 124To display current device status: 125 %(argv0)s --status 126 127To display current network device status: 128 %(argv0)s --status-dev net 129 130To bind eth1 from the current driver and move to use igb_uio 131 %(argv0)s --bind=igb_uio eth1 132 133To unbind 0000:01:00.0 from using any driver 134 %(argv0)s -u 0000:01:00.0 135 136To bind 0000:02:00.0 and 0000:02:00.1 to the ixgbe kernel driver 137 %(argv0)s -b ixgbe 02:00.0 02:00.1 138 139 """ % locals()) # replace items from local variables 140 141 142# This is roughly compatible with check_output function in subprocess module 143# which is only available in python 2.7. 144def check_output(args, stderr=None): 145 '''Run a command and capture its output''' 146 return subprocess.Popen(args, stdout=subprocess.PIPE, 147 stderr=stderr).communicate()[0] 148 149 150def check_modules(): 151 '''Checks that igb_uio is loaded''' 152 global dpdk_drivers 153 154 # list of supported modules 155 mods = [{"Name": driver, "Found": False} for driver in dpdk_drivers] 156 157 # first check if module is loaded 158 try: 159 # Get list of sysfs modules (both built-in and dynamically loaded) 160 sysfs_path = '/sys/module/' 161 162 # Get the list of directories in sysfs_path 163 sysfs_mods = [os.path.join(sysfs_path, o) for o 164 in os.listdir(sysfs_path) 165 if os.path.isdir(os.path.join(sysfs_path, o))] 166 167 # Extract the last element of '/sys/module/abc' in the array 168 sysfs_mods = [a.split('/')[-1] for a in sysfs_mods] 169 170 # special case for vfio_pci (module is named vfio-pci, 171 # but its .ko is named vfio_pci) 172 sysfs_mods = [a if a != 'vfio_pci' else 'vfio-pci' for a in sysfs_mods] 173 174 for mod in mods: 175 if mod["Name"] in sysfs_mods: 176 mod["Found"] = True 177 except: 178 pass 179 180 # check if we have at least one loaded module 181 if True not in [mod["Found"] for mod in mods] and b_flag is not None: 182 if b_flag in dpdk_drivers: 183 print("Error - no supported modules(DPDK driver) are loaded") 184 sys.exit(1) 185 else: 186 print("Warning - no supported modules(DPDK driver) are loaded") 187 188 # change DPDK driver list to only contain drivers that are loaded 189 dpdk_drivers = [mod["Name"] for mod in mods if mod["Found"]] 190 191 192def has_driver(dev_id): 193 '''return true if a device is assigned to a driver. False otherwise''' 194 return "Driver_str" in devices[dev_id] 195 196 197def get_pci_device_details(dev_id, probe_lspci): 198 '''This function gets additional details for a PCI device''' 199 device = {} 200 201 if probe_lspci: 202 extra_info = check_output(["lspci", "-vmmks", dev_id]).splitlines() 203 204 # parse lspci details 205 for line in extra_info: 206 if len(line) == 0: 207 continue 208 name, value = line.decode().split("\t", 1) 209 name = name.strip(":") + "_str" 210 device[name] = value 211 # check for a unix interface name 212 device["Interface"] = "" 213 for base, dirs, _ in os.walk("/sys/bus/pci/devices/%s/" % dev_id): 214 if "net" in dirs: 215 device["Interface"] = \ 216 ",".join(os.listdir(os.path.join(base, "net"))) 217 break 218 # check if a port is used for ssh connection 219 device["Ssh_if"] = False 220 device["Active"] = "" 221 222 return device 223 224def clear_data(): 225 '''This function clears any old data''' 226 global devices 227 devices = {} 228 229def get_device_details(devices_type): 230 '''This function populates the "devices" dictionary. The keys used are 231 the pci addresses (domain:bus:slot.func). The values are themselves 232 dictionaries - one for each NIC.''' 233 global devices 234 global dpdk_drivers 235 236 # first loop through and read details for all devices 237 # request machine readable format, with numeric IDs and String 238 dev = {} 239 dev_lines = check_output(["lspci", "-Dvmmnnk"]).splitlines() 240 for dev_line in dev_lines: 241 if len(dev_line) == 0: 242 if device_type_match(dev, devices_type): 243 # Replace "Driver" with "Driver_str" to have consistency of 244 # of dictionary key names 245 if "Driver" in dev.keys(): 246 dev["Driver_str"] = dev.pop("Driver") 247 if "Module" in dev.keys(): 248 dev["Module_str"] = dev.pop("Module") 249 # use dict to make copy of dev 250 devices[dev["Slot"]] = dict(dev) 251 # Clear previous device's data 252 dev = {} 253 else: 254 name, value = dev_line.decode().split("\t", 1) 255 value_list = value.rsplit(' ', 1) 256 if len(value_list) > 1: 257 # String stored in <name>_str 258 dev[name.rstrip(":") + '_str'] = value_list[0] 259 # Numeric IDs 260 dev[name.rstrip(":")] = value_list[len(value_list) - 1] \ 261 .rstrip("]").lstrip("[") 262 263 if devices_type == network_devices: 264 # check what is the interface if any for an ssh connection if 265 # any to this host, so we can mark it later. 266 ssh_if = [] 267 route = check_output(["ip", "-o", "route"]) 268 # filter out all lines for 169.254 routes 269 route = "\n".join(filter(lambda ln: not ln.startswith("169.254"), 270 route.decode().splitlines())) 271 rt_info = route.split() 272 for i in range(len(rt_info) - 1): 273 if rt_info[i] == "dev": 274 ssh_if.append(rt_info[i+1]) 275 276 # based on the basic info, get extended text details 277 for d in devices.keys(): 278 if not device_type_match(devices[d], devices_type): 279 continue 280 281 # get additional info and add it to existing data 282 devices[d] = devices[d].copy() 283 # No need to probe lspci 284 devices[d].update(get_pci_device_details(d, False).items()) 285 286 if devices_type == network_devices: 287 for _if in ssh_if: 288 if _if in devices[d]["Interface"].split(","): 289 devices[d]["Ssh_if"] = True 290 devices[d]["Active"] = "*Active*" 291 break 292 293 # add igb_uio to list of supporting modules if needed 294 if "Module_str" in devices[d]: 295 for driver in dpdk_drivers: 296 if driver not in devices[d]["Module_str"]: 297 devices[d]["Module_str"] = \ 298 devices[d]["Module_str"] + ",%s" % driver 299 else: 300 devices[d]["Module_str"] = ",".join(dpdk_drivers) 301 302 # make sure the driver and module strings do not have any duplicates 303 if has_driver(d): 304 modules = devices[d]["Module_str"].split(",") 305 if devices[d]["Driver_str"] in modules: 306 modules.remove(devices[d]["Driver_str"]) 307 devices[d]["Module_str"] = ",".join(modules) 308 309 310def device_type_match(dev, devices_type): 311 for i in range(len(devices_type)): 312 param_count = len( 313 [x for x in devices_type[i].values() if x is not None]) 314 match_count = 0 315 if dev["Class"][0:2] == devices_type[i]["Class"]: 316 match_count = match_count + 1 317 for key in devices_type[i].keys(): 318 if key != 'Class' and devices_type[i][key]: 319 value_list = devices_type[i][key].split(',') 320 for value in value_list: 321 if value.strip(' ') == dev[key]: 322 match_count = match_count + 1 323 # count must be the number of non None parameters to match 324 if match_count == param_count: 325 return True 326 return False 327 328def dev_id_from_dev_name(dev_name): 329 '''Take a device "name" - a string passed in by user to identify a NIC 330 device, and determine the device id - i.e. the domain:bus:slot.func - for 331 it, which can then be used to index into the devices array''' 332 333 # check if it's already a suitable index 334 if dev_name in devices: 335 return dev_name 336 # check if it's an index just missing the domain part 337 elif "0000:" + dev_name in devices: 338 return "0000:" + dev_name 339 else: 340 # check if it's an interface name, e.g. eth1 341 for d in devices.keys(): 342 if dev_name in devices[d]["Interface"].split(","): 343 return devices[d]["Slot"] 344 # if nothing else matches - error 345 print("Unknown device: %s. " 346 "Please specify device in \"bus:slot.func\" format" % dev_name) 347 sys.exit(1) 348 349 350def unbind_one(dev_id, force): 351 '''Unbind the device identified by "dev_id" from its current driver''' 352 dev = devices[dev_id] 353 if not has_driver(dev_id): 354 print("%s %s %s is not currently managed by any driver\n" % 355 (dev["Slot"], dev["Device_str"], dev["Interface"])) 356 return 357 358 # prevent us disconnecting ourselves 359 if dev["Ssh_if"] and not force: 360 print("Routing table indicates that interface %s is active. " 361 "Skipping unbind" % (dev_id)) 362 return 363 364 # write to /sys to unbind 365 filename = "/sys/bus/pci/drivers/%s/unbind" % dev["Driver_str"] 366 try: 367 f = open(filename, "a") 368 except: 369 print("Error: unbind failed for %s - Cannot open %s" 370 % (dev_id, filename)) 371 sys.exit(1) 372 f.write(dev_id) 373 f.close() 374 375 376def bind_one(dev_id, driver, force): 377 '''Bind the device given by "dev_id" to the driver "driver". If the device 378 is already bound to a different driver, it will be unbound first''' 379 dev = devices[dev_id] 380 saved_driver = None # used to rollback any unbind in case of failure 381 382 # prevent disconnection of our ssh session 383 if dev["Ssh_if"] and not force: 384 print("Routing table indicates that interface %s is active. " 385 "Not modifying" % (dev_id)) 386 return 387 388 # unbind any existing drivers we don't want 389 if has_driver(dev_id): 390 if dev["Driver_str"] == driver: 391 print("%s already bound to driver %s, skipping\n" 392 % (dev_id, driver)) 393 return 394 else: 395 saved_driver = dev["Driver_str"] 396 unbind_one(dev_id, force) 397 dev["Driver_str"] = "" # clear driver string 398 399 # For kernels >= 3.15 driver_override can be used to specify the driver 400 # for a device rather than relying on the driver to provide a positive 401 # match of the device. The existing process of looking up 402 # the vendor and device ID, adding them to the driver new_id, 403 # will erroneously bind other devices too which has the additional burden 404 # of unbinding those devices 405 if driver in dpdk_drivers: 406 filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id 407 if os.path.exists(filename): 408 try: 409 f = open(filename, "w") 410 except: 411 print("Error: bind failed for %s - Cannot open %s" 412 % (dev_id, filename)) 413 return 414 try: 415 f.write("%s" % driver) 416 f.close() 417 except: 418 print("Error: bind failed for %s - Cannot write driver %s to " 419 "PCI ID " % (dev_id, driver)) 420 return 421 # For kernels < 3.15 use new_id to add PCI id's to the driver 422 else: 423 filename = "/sys/bus/pci/drivers/%s/new_id" % driver 424 try: 425 f = open(filename, "w") 426 except: 427 print("Error: bind failed for %s - Cannot open %s" 428 % (dev_id, filename)) 429 return 430 try: 431 # Convert Device and Vendor Id to int to write to new_id 432 f.write("%04x %04x" % (int(dev["Vendor"],16), 433 int(dev["Device"], 16))) 434 f.close() 435 except: 436 print("Error: bind failed for %s - Cannot write new PCI ID to " 437 "driver %s" % (dev_id, driver)) 438 return 439 440 # do the bind by writing to /sys 441 filename = "/sys/bus/pci/drivers/%s/bind" % driver 442 try: 443 f = open(filename, "a") 444 except: 445 print("Error: bind failed for %s - Cannot open %s" 446 % (dev_id, filename)) 447 if saved_driver is not None: # restore any previous driver 448 bind_one(dev_id, saved_driver, force) 449 return 450 try: 451 f.write(dev_id) 452 f.close() 453 except: 454 # for some reason, closing dev_id after adding a new PCI ID to new_id 455 # results in IOError. however, if the device was successfully bound, 456 # we don't care for any errors and can safely ignore IOError 457 tmp = get_pci_device_details(dev_id, True) 458 if "Driver_str" in tmp and tmp["Driver_str"] == driver: 459 return 460 print("Error: bind failed for %s - Cannot bind to driver %s" 461 % (dev_id, driver)) 462 if saved_driver is not None: # restore any previous driver 463 bind_one(dev_id, saved_driver, force) 464 return 465 466 # For kernels > 3.15 driver_override is used to bind a device to a driver. 467 # Before unbinding it, overwrite driver_override with empty string so that 468 # the device can be bound to any other driver 469 filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id 470 if os.path.exists(filename): 471 try: 472 f = open(filename, "w") 473 except: 474 print("Error: unbind failed for %s - Cannot open %s" 475 % (dev_id, filename)) 476 sys.exit(1) 477 try: 478 f.write("\00") 479 f.close() 480 except: 481 print("Error: unbind failed for %s - Cannot open %s" 482 % (dev_id, filename)) 483 sys.exit(1) 484 485 486def unbind_all(dev_list, force=False): 487 """Unbind method, takes a list of device locations""" 488 489 if dev_list[0] == "dpdk": 490 for d in devices.keys(): 491 if "Driver_str" in devices[d]: 492 if devices[d]["Driver_str"] in dpdk_drivers: 493 unbind_one(devices[d]["Slot"], force) 494 return 495 496 dev_list = map(dev_id_from_dev_name, dev_list) 497 for d in dev_list: 498 unbind_one(d, force) 499 500 501def bind_all(dev_list, driver, force=False): 502 """Bind method, takes a list of device locations""" 503 global devices 504 505 dev_list = map(dev_id_from_dev_name, dev_list) 506 507 for d in dev_list: 508 bind_one(d, driver, force) 509 510 # For kernels < 3.15 when binding devices to a generic driver 511 # (i.e. one that doesn't have a PCI ID table) using new_id, some devices 512 # that are not bound to any other driver could be bound even if no one has 513 # asked them to. hence, we check the list of drivers again, and see if 514 # some of the previously-unbound devices were erroneously bound. 515 if not os.path.exists("/sys/bus/pci/devices/%s/driver_override" % d): 516 for d in devices.keys(): 517 # skip devices that were already bound or that we know should be bound 518 if "Driver_str" in devices[d] or d in dev_list: 519 continue 520 521 # update information about this device 522 devices[d] = dict(devices[d].items() + 523 get_pci_device_details(d, True).items()) 524 525 # check if updated information indicates that the device was bound 526 if "Driver_str" in devices[d]: 527 unbind_one(d, force) 528 529 530def display_devices(title, dev_list, extra_params=None): 531 '''Displays to the user the details of a list of devices given in 532 "dev_list". The "extra_params" parameter, if given, should contain a string 533 with %()s fields in it for replacement by the named fields in each 534 device's dictionary.''' 535 strings = [] # this holds the strings to print. We sort before printing 536 print("\n%s" % title) 537 print("="*len(title)) 538 if len(dev_list) == 0: 539 strings.append("<none>") 540 else: 541 for dev in dev_list: 542 if extra_params is not None: 543 strings.append("%s '%s %s' %s" % (dev["Slot"], 544 dev["Device_str"], 545 dev["Device"], 546 extra_params % dev)) 547 else: 548 strings.append("%s '%s'" % (dev["Slot"], dev["Device_str"])) 549 # sort before printing, so that the entries appear in PCI order 550 strings.sort() 551 print("\n".join(strings)) # print one per line 552 553def show_device_status(devices_type, device_name): 554 global dpdk_drivers 555 kernel_drv = [] 556 dpdk_drv = [] 557 no_drv = [] 558 559 # split our list of network devices into the three categories above 560 for d in devices.keys(): 561 if device_type_match(devices[d], devices_type): 562 if not has_driver(d): 563 no_drv.append(devices[d]) 564 continue 565 if devices[d]["Driver_str"] in dpdk_drivers: 566 dpdk_drv.append(devices[d]) 567 else: 568 kernel_drv.append(devices[d]) 569 570 n_devs = len(dpdk_drv) + len(kernel_drv) + len(no_drv) 571 572 # don't bother displaying anything if there are no devices 573 if n_devs == 0: 574 msg = "No '%s' devices detected" % device_name 575 print("") 576 print(msg) 577 print("".join('=' * len(msg))) 578 return 579 580 # print each category separately, so we can clearly see what's used by DPDK 581 if len(dpdk_drv) != 0: 582 display_devices("%s devices using DPDK-compatible driver" % device_name, 583 dpdk_drv, "drv=%(Driver_str)s unused=%(Module_str)s") 584 if len(kernel_drv) != 0: 585 display_devices("%s devices using kernel driver" % device_name, kernel_drv, 586 "if=%(Interface)s drv=%(Driver_str)s " 587 "unused=%(Module_str)s %(Active)s") 588 if len(no_drv) != 0: 589 display_devices("Other %s devices" % device_name, no_drv, 590 "unused=%(Module_str)s") 591 592def show_status(): 593 '''Function called when the script is passed the "--status" option. 594 Displays to the user what devices are bound to the igb_uio driver, the 595 kernel driver or to no driver''' 596 597 if status_dev == "net" or status_dev == "all": 598 show_device_status(network_devices, "Network") 599 600 if status_dev == "baseband" or status_dev == "all": 601 show_device_status(baseband_devices, "Baseband") 602 603 if status_dev == "crypto" or status_dev == "all": 604 show_device_status(crypto_devices, "Crypto") 605 606 if status_dev == "event" or status_dev == "all": 607 show_device_status(eventdev_devices, "Eventdev") 608 609 if status_dev == "mempool" or status_dev == "all": 610 show_device_status(mempool_devices, "Mempool") 611 612 if status_dev == "compress" or status_dev == "all": 613 show_device_status(compress_devices , "Compress") 614 615 if status_dev == "misc" or status_dev == "all": 616 show_device_status(misc_devices, "Misc (rawdev)") 617 618def parse_args(): 619 '''Parses the command-line arguments given by the user and takes the 620 appropriate action for each''' 621 global b_flag 622 global status_flag 623 global status_dev 624 global force_flag 625 global args 626 if len(sys.argv) <= 1: 627 usage() 628 sys.exit(0) 629 630 try: 631 opts, args = getopt.getopt(sys.argv[1:], "b:us", 632 ["help", "usage", "status", "status-dev=", 633 "force", "bind=", "unbind", ]) 634 except getopt.GetoptError as error: 635 print(str(error)) 636 print("Run '%s --usage' for further information" % sys.argv[0]) 637 sys.exit(1) 638 639 for opt, arg in opts: 640 if opt == "--help" or opt == "--usage": 641 usage() 642 sys.exit(0) 643 if opt == "--status-dev": 644 status_flag = True 645 status_dev = arg 646 if opt == "--status" or opt == "-s": 647 status_flag = True 648 status_dev = "all" 649 if opt == "--force": 650 force_flag = True 651 if opt == "-b" or opt == "-u" or opt == "--bind" or opt == "--unbind": 652 if b_flag is not None: 653 print("Error - Only one bind or unbind may be specified\n") 654 sys.exit(1) 655 if opt == "-u" or opt == "--unbind": 656 b_flag = "none" 657 else: 658 b_flag = arg 659 660 661def do_arg_actions(): 662 '''do the actual action requested by the user''' 663 global b_flag 664 global status_flag 665 global force_flag 666 global args 667 668 if b_flag is None and not status_flag: 669 print("Error: No action specified for devices." 670 "Please give a -b or -u option") 671 print("Run '%s --usage' for further information" % sys.argv[0]) 672 sys.exit(1) 673 674 if b_flag is not None and len(args) == 0: 675 print("Error: No devices specified.") 676 print("Run '%s --usage' for further information" % sys.argv[0]) 677 sys.exit(1) 678 679 if b_flag == "none" or b_flag == "None": 680 unbind_all(args, force_flag) 681 elif b_flag is not None: 682 bind_all(args, b_flag, force_flag) 683 if status_flag: 684 if b_flag is not None: 685 clear_data() 686 # refresh if we have changed anything 687 get_device_details(network_devices) 688 get_device_details(baseband_devices) 689 get_device_details(crypto_devices) 690 get_device_details(eventdev_devices) 691 get_device_details(mempool_devices) 692 get_device_details(compress_devices) 693 get_device_details(misc_devices) 694 show_status() 695 696 697def main(): 698 '''program main function''' 699 # check if lspci is installed, suppress any output 700 with open(os.devnull, 'w') as devnull: 701 ret = subprocess.call(['which', 'lspci'], 702 stdout=devnull, stderr=devnull) 703 if ret != 0: 704 print("'lspci' not found - please install 'pciutils'") 705 sys.exit(1) 706 parse_args() 707 check_modules() 708 clear_data() 709 get_device_details(network_devices) 710 get_device_details(baseband_devices) 711 get_device_details(crypto_devices) 712 get_device_details(eventdev_devices) 713 get_device_details(mempool_devices) 714 get_device_details(compress_devices) 715 get_device_details(misc_devices) 716 do_arg_actions() 717 718if __name__ == "__main__": 719 main() 720