Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: add --force, --enable-sriov to opae.io #3038

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion binaries/opae.io/opae/io/utils.py
Expand Up @@ -123,9 +123,23 @@ 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 os.path.exists(sriov):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Linux kernel folks would suggest trying to minimize indentation by something like the following:

if not os.path.exists(sriov):
LOG.error("Cannot enable sriov because {sriov} does not exist")
return FALSE

try:...

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
return False


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 +228,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
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