From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id CF2D0590C for ; Thu, 19 Mar 2015 04:23:19 +0100 (CET) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 18 Mar 2015 20:23:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,427,1422950400"; d="scan'208";a="682244550" Received: from pgsmsx108.gar.corp.intel.com ([10.221.44.103]) by fmsmga001.fm.intel.com with ESMTP; 18 Mar 2015 20:23:02 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by PGSMSX108.gar.corp.intel.com (10.221.44.103) with Microsoft SMTP Server (TLS) id 14.3.224.2; Thu, 19 Mar 2015 11:21:50 +0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.108]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.10]) with mapi id 14.03.0224.002; Thu, 19 Mar 2015 11:21:49 +0800 From: "Liu, Yong" To: "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] fix the net device bugs and add some funcs to generate vfs in net_device Thread-Index: AQHQYfNGy8L+3MSY8EOYr8Z+/G2fvQ== Date: Thu, 19 Mar 2015 03:21:49 +0000 Message-ID: <86228AFD5BCD8E4EBFD2B90117B5E81E10DA7CFC@SHSMSX103.ccr.corp.intel.com> References: <1426735018-19411-1-git-send-email-yong.liu@intel.com> <1426735018-19411-4-git-send-email-yong.liu@intel.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] fix the net device bugs and add some funcs to generate vfs in net_device X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2015 03:23:20 -0000 On 3/19/2015 11:17 AM, Yong Liu wrote:=0A= Mistook sending, please ignore this patch.=0A= > From: sjiajiax =0A= >=0A= > add some codes to test the vf actions=0A= >=0A= > diff --git a/tools/DTF/framework/dut.py b/tools/DTF/framework/dut.py=0A= > index 02c7639..2b85f23 100644=0A= > --- a/tools/DTF/framework/dut.py=0A= > +++ b/tools/DTF/framework/dut.py=0A= > @@ -10,7 +10,7 @@ from ssh_connection import SSHConnection=0A= > from crb import Crb=0A= > from net_device import NetDevice=0A= > from logger import getLogger=0A= > -=0A= > +import pdb=0A= > =0A= > class Dut(Crb):=0A= > =0A= > @@ -390,7 +390,8 @@ class Dut(Crb):=0A= > =0A= > for (pci_bus, pci_id) in self.pci_devices_info:=0A= > =0A= > - if not dts.accepted_nic(pci_id):=0A= > + #if not dts.accepted_nic(pci_id):=0A= > + if pci_id =3D=3D '1106:3119':=0A= > self.logger.info("DUT: [000:%s %s] %s" % (pci_bus, pci_i= d,=0A= > skipped))=0A= > continue=0A= > @@ -488,25 +489,31 @@ class Dut(Crb):=0A= > """=0A= > Generate SRIOV VFs with default driver it is bound now or specif= id driver.=0A= > """=0A= > - pci_bus =3D self.port_info[port_id]['pci']=0A= > - port =3D self.port_info[port_id]['port']=0A= > -=0A= > - bus_id =3D pci_bus.split(':')[0]=0A= > - devfun_id =3D pci_bus.split(':')[1]=0A= > - port_driver =3D self.get_dev_driver(bus_id, devfun_id) =0A= > + port =3D self.ports_info[port_id]['port']=0A= > + port_driver =3D port.get_nic_driver()=0A= > =0A= > if driver =3D=3D 'default': =0A= > - if not port_dirver:=0A= > + if not port_driver:=0A= > self.logger.info("No driver on specified port, can not g= enerate SRIOV VF.")=0A= > return None=0A= > else:=0A= > if port_driver !=3D driver:=0A= > - self.bind_interfaces_linux(driver, pci_bus)=0A= > + port.bind_driver(driver)=0A= > port.generate_sriov_vfs(vf_num)=0A= > =0A= > - sriov_vfs_pci =3D port.get_sriov_vfs_pci(bus_id, devfun_id) = =0A= > + sriov_vfs_pci =3D port.get_sriov_vfs_pci() =0A= > self.ports_info[port_id]['sriov_vfs_pci'] =3D sriov_vfs_pci=0A= > =0A= > + def destroy_sriov_vfs_by_port(self, port_id):=0A= > + port =3D self.ports_info[port_id]['port']=0A= > + port_driver =3D port.get_nic_driver()=0A= > +=0A= > + if not port_driver:=0A= > + self.logger.info("No driver on specified port, skip destroy = SRIOV VF.")=0A= > + else:=0A= > + sriov_vfs_pci =3D port.destroy_sriov_vfs()=0A= > + self.ports_info[port_id]['sriov_vfs_pci'] =3D ''=0A= > +=0A= > def get_vm_core_list(self):=0A= > return VMCORELIST[self.crb['VM CoreList']]=0A= > =0A= > diff --git a/tools/DTF/framework/net_device.py b/tools/DTF/framework/net_= device.py=0A= > index 9186ad6..1a99f68 100644=0A= > --- a/tools/DTF/framework/net_device.py=0A= > +++ b/tools/DTF/framework/net_device.py=0A= > @@ -1,3 +1,5 @@=0A= > +import os=0A= > +import re=0A= > from functools import wraps=0A= > import pdb=0A= > =0A= > @@ -12,19 +14,21 @@ class NetDevice(object):=0A= > self.crb =3D crb=0A= > self.bus_id =3D bus_id=0A= > self.devfun_id =3D devfun_id=0A= > + self.default_driver =3D self.get_nic_driver()=0A= > self.intf_name =3D self.get_interface_name()=0A= > =0A= > def __send_expect(self, cmds, expected, timeout=3DTIMEOUT, alt_sessi= on=3DFalse):=0A= > return self.crb.send_expect(cmds, expected, timeout=3DTIMEOUT, a= lt_session=3DFalse)=0A= > =0A= > def __get_os_type(self):=0A= > - return self.crb.__get_os_type()=0A= > + return self.crb.get_os_type()=0A= > =0A= > def nic_has_driver(func):=0A= > @wraps(func)=0A= > - def wrapper(self, *args, **kwargs):=0A= > - self.current_driver =3D self.get_nic_driver()=0A= > - if not self.current_driver:=0A= > + def wrapper(*args, **kwargs):=0A= > + nic_instance =3D args[0]=0A= > + nic_instance.current_driver =3D nic_instance.get_nic_driver(= )=0A= > + if not nic_instance.current_driver:=0A= > return ''=0A= > return func(*args, **kwargs)=0A= > return wrapper=0A= > @@ -201,17 +205,17 @@ class NetDevice(object):=0A= > generic_driver =3D 'generic'=0A= > get_sriov_vfs_pci_linux =3D getattr(self, 'get_sriov_vfs_pci= _linux_%s' % generic_driver)=0A= > =0A= > - return get_sriov_vfs_pci_linux(intf, bus_id, devfun_id)=0A= > + return get_sriov_vfs_pci_linux(bus_id, devfun_id)=0A= > =0A= > def get_sriov_vfs_pci_linux_generic(self, bus_id, devfun_id):=0A= > sriov_numvfs =3D self.__send_expect("cat /sys/bus/pci/devices/00= 00\:%s\:%s/sriov_numvfs" %=0A= > (bus_id, devfun_id), "# ")= =0A= > sriov_vfs_pci =3D []=0A= > - if sriov_numvfs =3D=3D 0:=0A= > + if int(sriov_numvfs) =3D=3D 0:=0A= > pass=0A= > else:=0A= > try:=0A= > - virtfns =3D self.send_exepct("ls -d /sys/bus/pci/devices= /0000\:%s\:%s/virtfn*" %=0A= > + virtfns =3D self.__send_expect("ls -d /sys/bus/pci/devic= es/0000\:%s\:%s/virtfn*" %=0A= > (bus_id, devfun_id), "# ")= =0A= > for virtfn in virtfns.split():=0A= > vf_uevent =3D self.__send_expect("cat %s" % os.path.= join(virtfn, "uevent"), "# ")=0A= > @@ -243,53 +247,59 @@ class NetDevice(object):=0A= > return generate_sriov_vfs_linux(bus_id, devfun_id, vf_num)=0A= > =0A= > def generate_sriov_vfs_linux_generic(self, bus_id, devfun_id, vf_num= ): =0A= > - pci_dev_driver =3D self.crb.get_pci_dev_driver(bus_id, devfun_id= )=0A= > + pdb.set_trace()=0A= > + nic_driver =3D self.get_nic_driver()=0A= > =0A= > - if pci_dev_driver:=0A= > + if not nic_driver:=0A= > return None=0A= > =0A= > vf_reg_file =3D "sriov_numvfs"=0A= > - vf_reg_path =3D os.path.join("/sys/bus/pci/device/0000:%s\:%s" %= =0A= > + vf_reg_path =3D os.path.join("/sys/bus/pci/devices/0000:%s:%s" %= =0A= > (bus_id, devfun_id), vf_reg_file)=0A= > self.__send_expect("echo %d > %s" %=0A= > (int(vf_num), vf_reg_path), "# ")=0A= > =0A= > def generate_sriov_vfs_linux_igb_uio(self, bus_id, devfun_id, vf_num= ): =0A= > - pci_dev_driver =3D self.crb.get_pci_dev_driver(bus_id, devfun_id= )=0A= > + nic_driver =3D self.get_nic_driver()=0A= > =0A= > - if pci_dev_driver:=0A= > + if not nic_driver:=0A= > return None=0A= > =0A= > vf_reg_file =3D "max_vfs"=0A= > - vf_reg_path =3D os.path.join("/sys/bus/pci/device/0000:%s\:%s" %= =0A= > + vf_reg_path =3D os.path.join("/sys/bus/pci/devices/0000:%s:%s" %= =0A= > (bus_id, devfun_id), vf_reg_file)=0A= > self.__send_expect("echo %d > %s" %=0A= > (int(vf_num), vf_reg_path), "# ")=0A= > =0A= > def destroy_sriov_vfs(self):=0A= > - self.generate_sriov_vfs_linux(self.bus_id, self.devfun_id, 0)=0A= > -=0A= > - def bind_vf(self, driver=3D'pci-stub'):=0A= > - bind_vf =3D getattr(self, 'bind_vf_%s' % self.__get_os_type())= =0A= > - return bind_vf(driver)=0A= > -=0A= > - def bind_vf_linux(self, driver):=0A= > + self.generate_sriov_vfs(0)=0A= > +=0A= > + def bind_driver(self, driver=3D''):=0A= > + bind_driver =3D getattr(self, 'bind_driver_%s' % self.__get_os_t= ype())=0A= > + if not driver:=0A= > + if not self.default_driver:=0A= > + print "Must specify a driver because default driver is NU= LL!" =0A= > + return=0A= > + driver =3D self.default_driver=0A= > + return bind_driver(driver)=0A= > +=0A= > + def bind_driver_linux(self, driver):=0A= > driver_alias =3D driver.replace('-', '_')=0A= > try:=0A= > - bind_vf_linux =3D getattr(self, 'bind_vf_linux_%s' % driver_= alias)=0A= > - return bind_vf_linux(self.bus_id, self.devfun_id)=0A= > + bind_driver_linux =3D getattr(self, 'bind_driver_linux_%s' %= driver_alias)=0A= > + return bind_driver_linux(self.bus_id, self.devfun_id)=0A= > except Exception,e:=0A= > driver_alias =3D 'generic'=0A= > - bind_vf_linux =3D getattr(self, 'bind_vf_linux_%s' % driver_= alias)=0A= > - return bind_vf_linux(self.bus_id, self.devfun_id, driver)=0A= > + bind_driver_linux =3D getattr(self, 'bind_driver_linux_%s' %= driver_alias)=0A= > + return bind_driver_linux(self.bus_id, self.devfun_id, driver= )=0A= > =0A= > - def bind_vf_linux_generic(self, bus_id, devfun_id, driver):=0A= > + def bind_driver_linux_generic(self, bus_id, devfun_id, driver):=0A= > nic_pci_num =3D ':'.join(['0000', bus_id, devfun_id])=0A= > self.__send_expect("echo %s > /sys/bus/pci/devices/0000\:%s\:%s/= driver/unbind" %=0A= > (nic_pci_num, bus_id, devfun_id), "# ")=0A= > - self.__send_expect("echo %s > /sys/bus/pci/drivers/pci-stub/bind= " % nic_pci_num, "# ")=0A= > + self.__send_expect("echo %s > /sys/bus/pci/drivers/%s/bind" % (n= ic_pci_num, driver), "# ")=0A= > =0A= > - def bind_vf_linux_pci_stub(self, bus_id, devfun_id):=0A= > + def bind_driver_linux_pci_stub(self, bus_id, devfun_id):=0A= > nic_pci_num =3D ':'.join(['0000', bus_id, devfun_id])=0A= > pci_id =3D self.get_card_type()=0A= > self.__send_expect("echo %s > /sys/bus/pci/drivers/pci-stub/new_= id" % nic_pci_num, "# ")=0A= > @@ -297,11 +307,21 @@ class NetDevice(object):=0A= > (nic_pci_num, bus_id, devfun_id), "# ")=0A= > self.__send_expect("echo %s > /sys/bus/pci/drivers/pci-stub/bind= " % nic_pci_num, "# ")=0A= > =0A= > - def unbind_vf(self):=0A= > - unbind_vf =3D getattr(self, 'unbind_vf_%s' % self.__get_os_type(= ))=0A= > - return unbind_vf(self.bus_id, self.devfun_id)=0A= > + @nic_has_driver=0A= > + def unbind_driver(self, driver=3D''):=0A= > + unbind_driver =3D getattr(self, 'unbind_driver_%s' % self.__get_= os_type())=0A= > + if not driver:=0A= > + driver =3D 'generic'=0A= > + return unbind_driver(self.bus_id, self.devfun_id, driver)=0A= > =0A= > - def unbind_vf_linux(self, bus_id, devfun_id):=0A= > + def unbind_driver_linux(self, bus_id, devfun_id, driver):=0A= > + driver_alias =3D driver.replace('-', '_')=0A= > +=0A= > + unbind_driver_linux =3D getattr(self, 'unbind_driver_linux_%s' %= driver_alias)=0A= > + return unbind_driver_linux(bus_id, devfun_id)=0A= > +=0A= > + def unbind_driver_linux_generic(self, bus_id, devfun_id):=0A= > nic_pci_num =3D ':'.join(['0000', bus_id, devfun_id])=0A= > - self.__send_expect("echo %s > /sys/bus/pci/driver/unbind" % nic_= pci_num, "# ")=0A= > + self.__send_expect("echo %s > /sys/bus/pci/devices/0000\:%s\:%s/= driver/unbind" % =0A= > + (nic_pci_num, bus_id, devfun_id), "# ")=0A= > =0A= > diff --git a/tools/DTF/framework/qemu_kvm.py b/tools/DTF/framework/qemu_k= vm.py=0A= > index 687851f..f405c49 100644=0A= > --- a/tools/DTF/framework/qemu_kvm.py=0A= > +++ b/tools/DTF/framework/qemu_kvm.py=0A= > @@ -299,21 +299,39 @@ if __name__ =3D=3D "__main__":=0A= > dut.set_speedup_options(read_cache, skip_setup)=0A= > tester.set_speedup_options(read_cache, skip_setup)=0A= > =0A= > + dut.dut_prerequisites()=0A= > + port0 =3D dut.ports_info[0]['port']=0A= > + dut.generate_sriov_vfs_by_port(0, 4)=0A= > + print "port 0 sriov vfs: ", dut.ports_info[0]=0A= > +=0A= > + dut.destroy_sriov_vfs_by_port(0) =0A= > +=0A= > + time.sleep(2)=0A= > +=0A= > + pdb.set_trace()=0A= > + port0.unbind_driver()=0A= > + port0_pci =3D dut.ports_info[0]['pci']=0A= > +=0A= > # Start VM by the command options=0A= > virt_proxy =3D VirtProxy('qemu_kvm', dut)=0A= > cmd =3D [('enable-kvm',''),=0A= > ('cpu','host'),=0A= > ('drive','file=3D/home/image/fedora21-try-02.qcow2'),=0A= > ('net','nic,macaddr=3D00:00:00:55:00:06'),=0A= > - ('net', 'tap,script=3D/etc/qemu-ifup')]=0A= > + ('net', 'tap,script=3D/etc/qemu-ifup'),=0A= > + ('device', 'pci-assign,host=3D%s' % port0_pci)]=0A= > vm_name =3D virt_proxy.virt.start_vm(*cmd)=0A= > =0A= > try:=0A= > print virt_proxy.virt.session.send_expect("ifconfig", '# ')=0A= > - print virt_proxy.virt.vm_info=0A= > + print "VM info:", virt_proxy.virt.vm_info=0A= > =0A= > vm_dut =3D virt_proxy.virt.get_vm_dut(vm_name)=0A= > print vm_dut.session.send_expect('ifconfig', '# ')=0A= > + print vm_dut.session.send_expect('lspci -nn | grep -i eth', '# '= )=0A= > +=0A= > + pdb.set_trace()=0A= > + port0.bind_driver()=0A= > =0A= > dut.logger.logger_exit()=0A= > tester.logger.logger_exit()=0A= =0A=