MCPcopy Create free account
hub / github.com/F-Stack/f-stack / bind_one

Function bind_one

dpdk/usertools/dpdk-devbind.py:350–454  ·  view source on GitHub ↗

Bind the device given by "dev_id" to the driver "driver". If the device is already bound to a different driver, it will be unbound first

(dev_id, driver, force)

Source from the content-addressed store, hash-verified

348
349
350def bind_one(dev_id, driver, force):
351 '''Bind the device given by "dev_id" to the driver "driver". If the device
352 is already bound to a different driver, it will be unbound first'''
353 dev = devices[dev_id]
354 saved_driver = None # used to rollback any unbind in case of failure
355
356 # prevent disconnection of our ssh session
357 if dev["Ssh_if"] and not force:
358 print("Warning: routing table indicates that interface %s is active. "
359 "Not modifying" % dev_id, file=sys.stderr)
360 return
361
362 # unbind any existing drivers we don't want
363 if has_driver(dev_id):
364 if dev["Driver_str"] == driver:
365 print("Notice: %s already bound to driver %s, skipping" %
366 (dev_id, driver), file=sys.stderr)
367 return
368 saved_driver = dev["Driver_str"]
369 unbind_one(dev_id, force)
370 dev["Driver_str"] = "" # clear driver string
371
372 # For kernels >= 3.15 driver_override can be used to specify the driver
373 # for a device rather than relying on the driver to provide a positive
374 # match of the device. The existing process of looking up
375 # the vendor and device ID, adding them to the driver new_id,
376 # will erroneously bind other devices too which has the additional burden
377 # of unbinding those devices
378 if driver in dpdk_drivers:
379 filename = "/sys/bus/pci/devices/%s/driver_override" % dev_id
380 if exists(filename):
381 try:
382 f = open(filename, "w")
383 except OSError as err:
384 print("Error: bind failed for %s - Cannot open %s: %s"
385 % (dev_id, filename, err), file=sys.stderr)
386 return
387 try:
388 f.write("%s" % driver)
389 f.close()
390 except OSError as err:
391 print("Error: bind failed for %s - Cannot write driver %s to "
392 "PCI ID: %s" % (dev_id, driver, err), file=sys.stderr)
393 return
394 # For kernels < 3.15 use new_id to add PCI id's to the driver
395 else:
396 filename = "/sys/bus/pci/drivers/%s/new_id" % driver
397 try:
398 f = open(filename, "w")
399 except OSError as err:
400 print("Error: bind failed for %s - Cannot open %s: %s"
401 % (dev_id, filename, err), file=sys.stderr)
402 return
403 try:
404 # Convert Device and Vendor Id to int to write to new_id
405 f.write("%04x %04x" % (int(dev["Vendor"], 16),
406 int(dev["Device"], 16)))
407 f.close()

Callers 1

bind_allFunction · 0.85

Calls 6

has_driverFunction · 0.85
unbind_oneFunction · 0.85
get_pci_device_detailsFunction · 0.85
printFunction · 0.50
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected