Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion binaries/opae.io/opae/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,24 @@ def chown_pci_sva(pci_addr, uid, gid):
os.chown(sva_bind_dev, uid, gid)


def vfio_init(pci_addr, new_owner='', force=False):
def enable_sriov(enable):
sriov = '/sys/module/vfio_pci/parameters/enable_sriov'
if not os.path.exists(sriov):
return False

LOG.info('Enabling SR-IOV for vfio-pci')
try:
with open(sriov, 'w') as outf:
outf.write('Y' if enable else 'N')
except OSError:
return False
return True


def vfio_init(pci_addr, new_owner='', force=False, **kwargs):
vid_did = pci.vid_did_for_address(pci_addr)
driver = get_bound_driver(pci_addr)
init_sriov = kwargs.get('enable_sriov')

msg = '(0x{:04x},0x{:04x}) at {}'.format(
int(vid_did[0], 16), int(vid_did[1], 16), pci_addr)
Expand Down Expand Up @@ -214,6 +229,9 @@ def vfio_init(pci_addr, new_owner='', force=False):
os.chmod(device, 0o660)
chown_pci_sva(pci_addr, user, group)

if init_sriov:
enable_sriov(True)


def vfio_release(pci_addr):
vid_did = pci.vid_did_for_address(pci_addr)
Expand Down
10 changes: 9 additions & 1 deletion binaries/opae.io/pymain.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,22 @@ class init_action(base_action):
init.add_argument('-d', '--device', dest='sdevice',
metavar='DEVICE', type=pci.pci_address,
help='the PCIe address of the FPGA device')
init.add_argument('-e', '--enable-sriov', action='store_true',
default=False,
help='enable SR-IOV during initialization')
init.add_argument('-f', '--force', action='store_true',
default=False,
help='force the driver to unbind, '
'even if saving the previous driver fails')
init.add_argument('user_group', nargs='?', default='root:root',
help='the user:group for assigning device permissions')

def execute(self, args):
if not self.device:
raise SystemExit('Need device for init.')

utils.vfio_init(self.device, args.user_group)
kw = {'enable_sriov': args.enable_sriov}
utils.vfio_init(self.device, args.user_group, force=args.force, **kw)
raise SystemExit(0)


Expand Down