def crypto_device_init(node, numvfs): """Init Crypto QAT device virtual functions on DUT. :param node: DUT node. :param numvfs: Number of VFs to initialize, 0 - disable the VFs. :type node: dict :type numvfs: int :returns: nothing :raises RuntimeError: If failed to stop VPP or QAT failed to initialize. """ pci_addr = Topology.get_cryptodev(node) # QAT device must be re-bound to kernel driver before initialization. DUTSetup.verify_kernel_module(node, 'qat_dh895xcc', force_load=True) # Stop VPP to prevent deadlock. DUTSetup.stop_service(node, Constants.VPP_UNIT) current_driver = DUTSetup.get_pci_dev_driver( node, pci_addr.replace(':', r'\:')) if current_driver is not None: DUTSetup.pci_driver_unbind(node, pci_addr) # Bind to kernel driver. DUTSetup.pci_driver_bind(node, pci_addr, 'dh895xcc') # Initialize QAT VFs. if numvfs > 0: DUTSetup.set_sriov_numvfs(node, pci_addr, numvfs)
def crypto_device_init(node, numvfs): """Init Crypto QAT device virtual functions on DUT. :param node: DUT node. :param numvfs: Number of VFs to initialize, 0 - disable the VFs. :type node: dict :type numvfs: int :returns: nothing :raises RuntimeError: If QAT failed to initialize. """ ssh = SSH() ssh.connect(node) cryptodev = Topology.get_cryptodev(node) # QAT device must be bind to kernel driver before initialization DUTSetup.pci_driver_unbind(node, cryptodev) DUTSetup.pci_driver_bind(node, cryptodev, "dh895xcc") # Initialize QAT VFs ret_code, _, _ = ssh.exec_command( "sudo sh -c 'echo {} | tee /sys/bus/pci/devices/{}/sriov_numvfs'". format(numvfs, cryptodev.replace(':', r'\:'))) if int(ret_code) != 0: raise RuntimeError('Failed to initialize {} VFs on QAT device on ' 'host: {}'.format(numvfs, node['host']))
def add_cryptodev_config(self, node, count): """Add cryptodev configuration for node. :param node: DUT node. :param count: Number of crypto devices to add. :type node: dict :type count: int :returns: nothing :raises ValueError: If node type is not a DUT """ if node['type'] != NodeType.DUT: raise ValueError('Node type is not a DUT') hostname = Topology.get_node_hostname(node) if hostname not in self._nodeconfig: self._nodeconfig[hostname] = {} cryptodev = Topology.get_cryptodev(node) cryptodev_config = '' for i in range(count): cryptodev_config += 'dev {}\n'.format( re.sub(r'\d.\d$', '1.'+str(i), cryptodev)) self._nodeconfig[hostname]['cryptodev_config'] = cryptodev_config logger.debug('Setting hostname {} Cryptodev config to {}'. format(hostname, cryptodev_config)) uio_driver_config = 'uio-driver {}'.\ format(Topology.get_uio_driver(node)) self._nodeconfig[hostname]['uio_driver_config'] = uio_driver_config logger.debug('Setting hostname {} uio_driver config to {}'. format(hostname, uio_driver_config))
def crypto_device_verify(node, force_init=False, numvfs=32): """Verify if Crypto QAT device virtual functions are initialized on all DUTs. If parameter force initialization is set to True, then try to initialize or remove VFs on QAT. :param node: DUT node. :param force_init: If True then try to initialize to specific value. :param numvfs: Number of VFs to initialize, 0 - disable the VFs. :type node: dict :type force_init: bool :type numvfs: int :returns: nothing :raises RuntimeError: If QAT VFs are not created and force init is set to False. """ pci_addr = Topology.get_cryptodev(node) sriov_numvfs = DUTSetup.get_sriov_numvfs(node, pci_addr) if sriov_numvfs != numvfs: if force_init: # QAT is not initialized and we want to initialize with numvfs DUTSetup.crypto_device_init(node, numvfs) else: raise RuntimeError( 'QAT device failed to create VFs on {host}'.format( host=node['host']))
def add_dpdk_cryptodev(self, count): """Add DPDK Crypto PCI device configuration. :param count: Number of HW crypto devices to add. :type count: int """ cryptodev = Topology.get_cryptodev(self._node) for i in range(count): cryptodev_config = re.sub(r"\d.\d$", f"1.{str(i)}", cryptodev) path = [u"dpdk", f"dev {cryptodev_config}"] self.add_config_item(self._nodeconfig, u"", path) self.add_dpdk_uio_driver(u"vfio-pci")
def add_dpdk_cryptodev(self, count): """Add DPDK Crypto PCI device configuration. :param count: Number of HW crypto devices to add. :type count: int """ cryptodev = Topology.get_cryptodev(self._node) for i in range(count): cryptodev_config = 'dev {0}'.format( re.sub(r'\d.\d$', '1.' + str(i), cryptodev)) path = ['dpdk', cryptodev_config] self.add_config_item(self._nodeconfig, '', path) self.add_dpdk_uio_driver('igb_uio')
def crypto_device_verify(node, force_init=False, numvfs=32): """Verify if Crypto QAT device virtual functions are initialized on all DUTs. If parameter force initialization is set to True, then try to initialize or disable QAT. :param node: DUT node. :param force_init: If True then try to initialize to specific value. :param numvfs: Number of VFs to initialize, 0 - disable the VFs. :type node: dict :type force_init: bool :type numvfs: int :returns: nothing :raises RuntimeError: If QAT is not initialized or failed to initialize. """ ssh = SSH() ssh.connect(node) cryptodev = Topology.get_cryptodev(node) cmd = 'cat /sys/bus/pci/devices/{0}/sriov_numvfs'.\ format(cryptodev.replace(':', r'\:')) # Try to read number of VFs from PCI address of QAT device for _ in range(3): ret_code, stdout, _ = ssh.exec_command(cmd) if int(ret_code) == 0: try: sriov_numvfs = int(stdout) except ValueError: logger.trace( 'Reading sriov_numvfs info failed on {0}'.format( node['host'])) else: if sriov_numvfs != numvfs: if force_init: # QAT is not initialized and we want to initialize # with numvfs DUTSetup.crypto_device_init(node, numvfs) else: raise RuntimeError( 'QAT device {0} is not ' 'initialized to {1} on host {2}'.format( cryptodev, numvfs, node['host'])) break
def crypto_device_init(node, crypto_type, numvfs): """Init Crypto QAT device virtual functions on DUT. :param node: DUT node. :crypto_type: Crypto device type - HW_DH895xcc or HW_C3xxx. :param numvfs: Number of VFs to initialize, 0 - disable the VFs. :type node: dict :type crypto_type: string :type numvfs: int :returns: nothing :raises RuntimeError: If failed to stop VPP or QAT failed to initialize. """ if crypto_type == u"HW_DH895xcc": kernel_mod = u"qat_dh895xcc" kernel_drv = u"dh895xcc" elif crypto_type == u"HW_C3xxx": kernel_mod = u"qat_c3xxx" kernel_drv = u"c3xxx" else: raise RuntimeError( f"Unsupported crypto device type on {node[u'host']}" ) pci_addr = Topology.get_cryptodev(node) # QAT device must be re-bound to kernel driver before initialization. DUTSetup.verify_kernel_module(node, kernel_mod, force_load=True) # Stop VPP to prevent deadlock. DUTSetup.stop_service(node, Constants.VPP_UNIT) current_driver = DUTSetup.get_pci_dev_driver( node, pci_addr.replace(u":", r"\:") ) if current_driver is not None: DUTSetup.pci_driver_unbind(node, pci_addr) # Bind to kernel driver. DUTSetup.pci_driver_bind(node, pci_addr, kernel_drv) # Initialize QAT VFs. if numvfs > 0: DUTSetup.set_sriov_numvfs(node, pci_addr, numvfs)
def crypto_device_init(node, numvfs): """Init Crypto QAT device virtual functions on DUT. :param node: DUT node. :param numvfs: Number of VFs to initialize, 0 - disable the VFs. :type node: dict :type numvfs: int :returns: nothing :raises RuntimeError: If failed to stop VPP or QAT failed to initialize. """ cryptodev = Topology.get_cryptodev(node) # QAT device must be re-bound to kernel driver before initialization driver = 'dh895xcc' kernel_module = 'qat_dh895xcc' current_driver = DUTSetup.get_pci_dev_driver( node, cryptodev.replace(':', r'\:')) DUTSetup.kernel_module_verify(node, kernel_module, force_load=True) VPPUtil.stop_vpp_service(node) if current_driver is not None: DUTSetup.pci_driver_unbind(node, cryptodev) DUTSetup.pci_driver_bind(node, cryptodev, driver) ssh = SSH() ssh.connect(node) # Initialize QAT VFs if numvfs > 0: cmd = 'echo "{0}" | tee /sys/bus/pci/devices/{1}/sriov_numvfs'.\ format(numvfs, cryptodev.replace(':', r'\:'), timeout=180) ret_code, _, _ = ssh.exec_command_sudo("sh -c '{0}'".format(cmd)) if int(ret_code) != 0: raise RuntimeError( 'Failed to initialize {0} VFs on QAT device ' ' on host {1}'.format(numvfs, node['host']))