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

Feature: add --force, --enable-sriov to opae.io #3079

Merged
merged 3 commits into from
Jan 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions doc/sphinx/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Jinja2==3.1.1
requests==2.31.0
docutils==0.14
pygments==2.15.0
sphinx==4.5.0
sphinx==5.0.1
sphinx-rtd-theme==1.0.0
sphinx_fontawesome==0.0.6
sphinx-markdown==1.0.2
recommonmark==0.7.0
breathe==4.33.1
breathe==4.34.0
urllib3==1.26.18
2 changes: 2 additions & 0 deletions include/opae/cxx/core/shared_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class shared_buffer {
/** shared_buffer factory method - allocate a shared_buffer.
* @param[in] handle The handle used to allocate the buffer.
* @param[in] len The length in bytes of the requested buffer.
* @param[in] read_only Set to true for a read only buffer.
* @return A valid shared_buffer smart pointer on success, or an
* empty smart pointer on failure.
*/
Expand All @@ -74,6 +75,7 @@ class shared_buffer {
* @param[in] base The base of the pre-allocated memory.
* @param[in] len The size of the pre-allocated memory,
* which must be a multiple of the page size.
* @param[in] read_only Set to true for a read only buffer.
* @return A valid shared_buffer smart pointer on success, or an
* empty smart pointer on failure.
*/
Expand Down
4 changes: 2 additions & 2 deletions include/opae/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ fpga_result fpgaGetMetricsByName(fpga_handle handle,
* Retrieve metrics / sendor threshold information and values
*
* @param[in] handle Handle to previously opened fpga resource
* @param[inout] metrics_threshold pointer to array of metric thresholds
* @param[inout] metric_thresholds Pointer to array of metric thresholds
* user allocates threshold array memory
* Number of thresholds returns enumerated thresholds if user pass
* NULL metrics_thresholds
* @param[inout] num_thresholds number of thresholds
* @param[inout] num_thresholds Number of thresholds
*
*
* @returns FPGA_OK on success. FPGA_NOT_FOUND if the Metrics are not
Expand Down
1 change: 1 addition & 0 deletions include/opae/vfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ enum opae_vfio_buffer_flags {
* to ignore.
* @param[out] iova Optional pointer to receive the IOVA address
* for the buffer. Pass NULL to ignore.
* @param[in] flags Flags for allocation (e.g. OPAE_VFIO_BUF_PREALLOCATED).
* @returns Non-zero on error. Zero on success.
*
* Example
Expand Down