[dpdk-dev] [PATCH] fix the net device bugs and add some funcs to generate vfs in net_device

Liu, Yong yong.liu at intel.com
Thu Mar 19 04:21:49 CET 2015


On 3/19/2015 11:17 AM, Yong Liu wrote:
Mistook sending, please ignore this patch.
> From: sjiajiax <sunx.jiajia at intel.com>
>
> add some codes to test the vf actions
>
> diff --git a/tools/DTF/framework/dut.py b/tools/DTF/framework/dut.py
> index 02c7639..2b85f23 100644
> --- a/tools/DTF/framework/dut.py
> +++ b/tools/DTF/framework/dut.py
> @@ -10,7 +10,7 @@ from ssh_connection import SSHConnection
>  from crb import Crb
>  from net_device import NetDevice
>  from logger import getLogger
> -
> +import pdb
>  
>  class Dut(Crb):
>  
> @@ -390,7 +390,8 @@ class Dut(Crb):
>  
>          for (pci_bus, pci_id) in self.pci_devices_info:
>  
> -            if not dts.accepted_nic(pci_id):
> +            #if not dts.accepted_nic(pci_id):
> +            if pci_id == '1106:3119':
>                  self.logger.info("DUT: [000:%s %s] %s" % (pci_bus, pci_id,
>                                                            skipped))
>                  continue
> @@ -488,25 +489,31 @@ class Dut(Crb):
>          """
>          Generate SRIOV VFs with default driver it is bound now or specifid driver.
>          """
> -        pci_bus = self.port_info[port_id]['pci']
> -        port = self.port_info[port_id]['port']
> -
> -        bus_id = pci_bus.split(':')[0]
> -        devfun_id = pci_bus.split(':')[1]
> -        port_driver = self.get_dev_driver(bus_id, devfun_id) 
> +        port = self.ports_info[port_id]['port']
> +        port_driver = port.get_nic_driver()
>  
>          if driver == 'default': 
> -            if not port_dirver:
> +            if not port_driver:
>                  self.logger.info("No driver on specified port, can not generate SRIOV VF.")
>                  return None
>          else:
>              if port_driver != driver:
> -                self.bind_interfaces_linux(driver, pci_bus)
> +                port.bind_driver(driver)
>          port.generate_sriov_vfs(vf_num)
>  
> -        sriov_vfs_pci = port.get_sriov_vfs_pci(bus_id, devfun_id)        
> +        sriov_vfs_pci = port.get_sriov_vfs_pci()        
>          self.ports_info[port_id]['sriov_vfs_pci'] = sriov_vfs_pci
>  
> +    def destroy_sriov_vfs_by_port(self, port_id):
> +        port = self.ports_info[port_id]['port']
> +        port_driver = port.get_nic_driver()
> +
> +        if not port_driver:
> +            self.logger.info("No driver on specified port, skip destroy SRIOV VF.")
> +        else:
> +            sriov_vfs_pci = port.destroy_sriov_vfs()
> +        self.ports_info[port_id]['sriov_vfs_pci'] = ''
> +
>      def get_vm_core_list(self):
>          return VMCORELIST[self.crb['VM CoreList']]
>  
> diff --git a/tools/DTF/framework/net_device.py b/tools/DTF/framework/net_device.py
> index 9186ad6..1a99f68 100644
> --- a/tools/DTF/framework/net_device.py
> +++ b/tools/DTF/framework/net_device.py
> @@ -1,3 +1,5 @@
> +import os
> +import re
>  from functools import wraps
>  import pdb
>  
> @@ -12,19 +14,21 @@ class NetDevice(object):
>          self.crb = crb
>          self.bus_id = bus_id
>          self.devfun_id = devfun_id
> +        self.default_driver = self.get_nic_driver()
>          self.intf_name = self.get_interface_name()
>  
>      def __send_expect(self, cmds, expected, timeout=TIMEOUT, alt_session=False):
>          return self.crb.send_expect(cmds, expected, timeout=TIMEOUT, alt_session=False)
>  
>      def __get_os_type(self):
> -        return self.crb.__get_os_type()
> +        return self.crb.get_os_type()
>  
>      def nic_has_driver(func):
>          @wraps(func)
> -        def wrapper(self, *args, **kwargs):
> -            self.current_driver = self.get_nic_driver()
> -            if not self.current_driver:
> +        def wrapper(*args, **kwargs):
> +            nic_instance = args[0]
> +            nic_instance.current_driver = nic_instance.get_nic_driver()
> +            if not nic_instance.current_driver:
>                  return ''
>              return func(*args, **kwargs)
>          return wrapper
> @@ -201,17 +205,17 @@ class NetDevice(object):
>              generic_driver = 'generic'
>              get_sriov_vfs_pci_linux = getattr(self, 'get_sriov_vfs_pci_linux_%s' % generic_driver)
>  
> -        return get_sriov_vfs_pci_linux(intf, bus_id, devfun_id)
> +        return get_sriov_vfs_pci_linux(bus_id, devfun_id)
>          
>      def get_sriov_vfs_pci_linux_generic(self, bus_id, devfun_id):
>          sriov_numvfs = self.__send_expect("cat /sys/bus/pci/devices/0000\:%s\:%s/sriov_numvfs" %
>                                              (bus_id, devfun_id), "# ")
>          sriov_vfs_pci = []
> -        if sriov_numvfs == 0:
> +        if int(sriov_numvfs) == 0:
>              pass
>          else:
>              try:
> -                virtfns = self.send_exepct("ls -d /sys/bus/pci/devices/0000\:%s\:%s/virtfn*" %
> +                virtfns = self.__send_expect("ls -d /sys/bus/pci/devices/0000\:%s\:%s/virtfn*" %
>                                              (bus_id, devfun_id), "# ")
>                  for virtfn in virtfns.split():
>                      vf_uevent = self.__send_expect("cat %s" % os.path.join(virtfn, "uevent"), "# ")
> @@ -243,53 +247,59 @@ class NetDevice(object):
>          return generate_sriov_vfs_linux(bus_id, devfun_id, vf_num)
>  
>      def generate_sriov_vfs_linux_generic(self, bus_id, devfun_id, vf_num): 
> -        pci_dev_driver = self.crb.get_pci_dev_driver(bus_id, devfun_id)
> +        pdb.set_trace()
> +        nic_driver = self.get_nic_driver()
>  
> -        if pci_dev_driver:
> +        if not nic_driver:
>              return None
>  
>          vf_reg_file = "sriov_numvfs"
> -        vf_reg_path = os.path.join("/sys/bus/pci/device/0000:%s\:%s" %
> +        vf_reg_path = os.path.join("/sys/bus/pci/devices/0000:%s:%s" %
>                                      (bus_id, devfun_id), vf_reg_file)
>          self.__send_expect("echo %d > %s" %
>                            (int(vf_num), vf_reg_path), "# ")
>  
>      def generate_sriov_vfs_linux_igb_uio(self, bus_id, devfun_id, vf_num): 
> -        pci_dev_driver = self.crb.get_pci_dev_driver(bus_id, devfun_id)
> +        nic_driver = self.get_nic_driver()
>  
> -        if pci_dev_driver:
> +        if not nic_driver:
>              return None
>  
>          vf_reg_file = "max_vfs"
> -        vf_reg_path = os.path.join("/sys/bus/pci/device/0000:%s\:%s" %
> +        vf_reg_path = os.path.join("/sys/bus/pci/devices/0000:%s:%s" %
>                                      (bus_id, devfun_id), vf_reg_file)
>          self.__send_expect("echo %d > %s" %
>                            (int(vf_num), vf_reg_path), "# ")
>  
>      def destroy_sriov_vfs(self):
> -        self.generate_sriov_vfs_linux(self.bus_id, self.devfun_id, 0)
> -
> -    def bind_vf(self, driver='pci-stub'):
> -        bind_vf = getattr(self, 'bind_vf_%s' % self.__get_os_type())
> -        return  bind_vf(driver)
> -
> -    def bind_vf_linux(self, driver):
> +        self.generate_sriov_vfs(0)
> +
> +    def bind_driver(self, driver=''):
> +        bind_driver = getattr(self, 'bind_driver_%s' % self.__get_os_type())
> +        if not driver:
> +            if not self.default_driver:
> +               print "Must specify a driver because default driver is NULL!" 
> +               return
> +            driver = self.default_driver
> +        return  bind_driver(driver)
> +
> +    def bind_driver_linux(self, driver):
>          driver_alias = driver.replace('-', '_')
>          try:
> -            bind_vf_linux = getattr(self, 'bind_vf_linux_%s' % driver_alias)
> -            return bind_vf_linux(self.bus_id, self.devfun_id)
> +            bind_driver_linux = getattr(self, 'bind_driver_linux_%s' % driver_alias)
> +            return bind_driver_linux(self.bus_id, self.devfun_id)
>          except Exception,e:
>              driver_alias = 'generic'
> -            bind_vf_linux = getattr(self, 'bind_vf_linux_%s' % driver_alias)
> -            return bind_vf_linux(self.bus_id, self.devfun_id, driver)
> +            bind_driver_linux = getattr(self, 'bind_driver_linux_%s' % driver_alias)
> +            return bind_driver_linux(self.bus_id, self.devfun_id, driver)
>  
> -    def bind_vf_linux_generic(self, bus_id, devfun_id, driver):
> +    def bind_driver_linux_generic(self, bus_id, devfun_id, driver):
>          nic_pci_num = ':'.join(['0000', bus_id, devfun_id])
>          self.__send_expect("echo %s > /sys/bus/pci/devices/0000\:%s\:%s/driver/unbind" %
>                              (nic_pci_num, bus_id, devfun_id), "# ")
> -        self.__send_expect("echo %s > /sys/bus/pci/drivers/pci-stub/bind" % nic_pci_num, "# ")
> +        self.__send_expect("echo %s > /sys/bus/pci/drivers/%s/bind" % (nic_pci_num, driver), "# ")
>   
> -    def bind_vf_linux_pci_stub(self, bus_id, devfun_id):
> +    def bind_driver_linux_pci_stub(self, bus_id, devfun_id):
>          nic_pci_num = ':'.join(['0000', bus_id, devfun_id])
>          pci_id = self.get_card_type()
>          self.__send_expect("echo %s > /sys/bus/pci/drivers/pci-stub/new_id" % nic_pci_num, "# ")
> @@ -297,11 +307,21 @@ class NetDevice(object):
>                              (nic_pci_num, bus_id, devfun_id), "# ")
>          self.__send_expect("echo %s > /sys/bus/pci/drivers/pci-stub/bind" % nic_pci_num, "# ")
>  
> -    def unbind_vf(self):
> -        unbind_vf = getattr(self, 'unbind_vf_%s' % self.__get_os_type())
> -        return unbind_vf(self.bus_id, self.devfun_id)
> +    @nic_has_driver
> +    def unbind_driver(self, driver=''):
> +        unbind_driver = getattr(self, 'unbind_driver_%s' % self.__get_os_type())
> +        if not driver:
> +            driver = 'generic'
> +        return unbind_driver(self.bus_id, self.devfun_id, driver)
>  
> -    def unbind_vf_linux(self, bus_id, devfun_id):
> +    def unbind_driver_linux(self, bus_id, devfun_id, driver):
> +        driver_alias = driver.replace('-', '_')
> +
> +        unbind_driver_linux = getattr(self, 'unbind_driver_linux_%s' % driver_alias)
> +        return unbind_driver_linux(bus_id, devfun_id)
> +
> +    def unbind_driver_linux_generic(self, bus_id, devfun_id):
>          nic_pci_num = ':'.join(['0000', bus_id, devfun_id])
> -        self.__send_expect("echo %s > /sys/bus/pci/driver/unbind" % nic_pci_num, "# ")
> +        self.__send_expect("echo %s > /sys/bus/pci/devices/0000\:%s\:%s/driver/unbind" % 
> +                            (nic_pci_num, bus_id, devfun_id), "# ")
>          
> diff --git a/tools/DTF/framework/qemu_kvm.py b/tools/DTF/framework/qemu_kvm.py
> index 687851f..f405c49 100644
> --- a/tools/DTF/framework/qemu_kvm.py
> +++ b/tools/DTF/framework/qemu_kvm.py
> @@ -299,21 +299,39 @@ if __name__ == "__main__":
>      dut.set_speedup_options(read_cache, skip_setup)
>      tester.set_speedup_options(read_cache, skip_setup)
>  
> +    dut.dut_prerequisites()
> +    port0 = dut.ports_info[0]['port']
> +    dut.generate_sriov_vfs_by_port(0, 4)
> +    print "port 0 sriov vfs: ", dut.ports_info[0]
> +
> +    dut.destroy_sriov_vfs_by_port(0) 
> +
> +    time.sleep(2)
> +
> +    pdb.set_trace()
> +    port0.unbind_driver()
> +    port0_pci = dut.ports_info[0]['pci']
> +
>      # Start VM by the command options
>      virt_proxy = VirtProxy('qemu_kvm', dut)
>      cmd = [('enable-kvm',''),
>             ('cpu','host'),
>             ('drive','file=/home/image/fedora21-try-02.qcow2'),
>             ('net','nic,macaddr=00:00:00:55:00:06'),
> -           ('net', 'tap,script=/etc/qemu-ifup')]
> +           ('net', 'tap,script=/etc/qemu-ifup'),
> +           ('device', 'pci-assign,host=%s' % port0_pci)]
>      vm_name = virt_proxy.virt.start_vm(*cmd)
>  
>      try:
>          print virt_proxy.virt.session.send_expect("ifconfig", '# ')
> -        print virt_proxy.virt.vm_info
> +        print "VM info:", virt_proxy.virt.vm_info
>  
>          vm_dut = virt_proxy.virt.get_vm_dut(vm_name)
>          print vm_dut.session.send_expect('ifconfig', '# ')
> +        print vm_dut.session.send_expect('lspci -nn | grep -i eth', '# ')
> +
> +        pdb.set_trace()
> +        port0.bind_driver()
>  
>          dut.logger.logger_exit()
>          tester.logger.logger_exit()



More information about the dev mailing list