From f165779c8c0ce76e5ad3328b401f198c65c58ed3 Mon Sep 17 00:00:00 2001 From: Moshe Levi Date: Wed, 19 Jul 2017 08:18:21 +0300 Subject: [PATCH] add support to plx Change-Id: I024f8459e941b7ff5960031c91b041522a782f79 --- networking_mlnx/eswitchd/db/device_db.py | 3 +- networking_mlnx/eswitchd/resource_mngr.py | 10 +++--- networking_mlnx/eswitchd/utils/pci_utils.py | 32 ++++--------------- .../tests/unit/eswitchd/test_pci_utils.py | 18 ----------- 4 files changed, 12 insertions(+), 51 deletions(-) diff --git a/networking_mlnx/eswitchd/db/device_db.py b/networking_mlnx/eswitchd/db/device_db.py index 29f0ef9..1248800 100644 --- a/networking_mlnx/eswitchd/db/device_db.py +++ b/networking_mlnx/eswitchd/db/device_db.py @@ -24,12 +24,11 @@ class DeviceDB(object): def __init__(self): self.device_db = {} - def add_fabric(self, fabric, pf, pci_id, hca_port, fabric_type, + def add_fabric(self, fabric, pf, hca_port, fabric_type, pf_mlx_dev): pf_details = {} pf_details['vfs'] = {} pf_details['pf_device_type'] = None - pf_details['pci_id'] = pci_id pf_details['hca_port'] = hca_port pf_details['fabric_type'] = fabric_type pf_details['pf_mlx_dev'] = pf_mlx_dev diff --git a/networking_mlnx/eswitchd/resource_mngr.py b/networking_mlnx/eswitchd/resource_mngr.py index 31f0ff0..4ff77bd 100644 --- a/networking_mlnx/eswitchd/resource_mngr.py +++ b/networking_mlnx/eswitchd/resource_mngr.py @@ -33,8 +33,8 @@ class ResourceManager(object): self.device_db = device_db.DeviceDB() def add_fabric(self, fabric, pf, fabric_type): - pci_id, hca_port, pf_mlx_dev = self._get_pf_details(pf) - self.device_db.add_fabric(fabric, pf, pci_id, hca_port, fabric_type, + hca_port, pf_mlx_dev = self._get_pf_details(pf) + self.device_db.add_fabric(fabric, pf, hca_port, fabric_type, pf_mlx_dev) vfs = self.discover_devices(pf) LOG.info(_LI("PF %(pf)s, vfs = %(vf)s"), {'pf': pf, 'vf': vfs}) @@ -123,7 +123,5 @@ class ResourceManager(object): def _get_pf_details(self, pf): hca_port = self.pci_utils.get_eth_port(pf) - pci_id = self.pci_utils.get_pf_pci(pf) - pf_pci_id = self.pci_utils.get_pf_pci(pf, 'normal') - pf_mlx_dev = self.pci_utils.get_pf_mlx_dev(pf_pci_id) - return (pci_id, hca_port, pf_mlx_dev) + pf_mlx_dev = self.pci_utils.get_pf_mlx_dev(pf) + return (hca_port, pf_mlx_dev) diff --git a/networking_mlnx/eswitchd/utils/pci_utils.py b/networking_mlnx/eswitchd/utils/pci_utils.py index 42ed73e..a7c420d 100644 --- a/networking_mlnx/eswitchd/utils/pci_utils.py +++ b/networking_mlnx/eswitchd/utils/pci_utils.py @@ -33,7 +33,7 @@ class pciUtils(object): ETH_PATH = "/sys/class/net/%(interface)s" ETH_DEV = ETH_PATH + "/device" ETH_PORT = ETH_PATH + "/dev_id" - PF_MLX_DEV_PATH = "/sys/class/infiniband/*" + INFINIBAND_PATH = 'device/infiniband' VENDOR_PATH = ETH_DEV + '/vendor' DEVICE_TYPE_PATH = ETH_DEV + '/virtfn%(vf_num)s/device' _VIRTFN_RE = re.compile("virtfn(?P\d+)") @@ -144,30 +144,12 @@ class pciUtils(object): % mlnx_pfs) return mlnx_pfs[0] - def get_eth_vf(self, dev): - vf_path = pciUtils.ETH_DEV % {'interface': dev} - try: - device = os.readlink(vf_path) - vf = device.split('/')[3] - return vf - except Exception: - return None - - def get_pf_pci(self, pf, type=None): - vf = self.get_eth_vf(pf) - if vf: - if type == 'normal': - return vf - else: - return vf[:-2] - return None - - def get_pf_mlx_dev(self, pci_id): - paths = glob.glob(pciUtils.PF_MLX_DEV_PATH) - for path in paths: - id = os.readlink(path).split('/')[5] - if pci_id == id: - return path.split('/')[-1] + def get_pf_mlx_dev(self, pf): + dev_path = ( + os.path.join(pciUtils.ETH_PATH % {'interface': pf}, + pciUtils.INFINIBAND_PATH)) + dev_info = os.listdir(dev_path) + return dev_info.pop() def get_guid_index(self, pf_mlx_dev, dev, hca_port): guid_index = None diff --git a/networking_mlnx/tests/unit/eswitchd/test_pci_utils.py b/networking_mlnx/tests/unit/eswitchd/test_pci_utils.py index 524b321..031d5ca 100644 --- a/networking_mlnx/tests/unit/eswitchd/test_pci_utils.py +++ b/networking_mlnx/tests/unit/eswitchd/test_pci_utils.py @@ -24,7 +24,6 @@ sys.modules['ethtool'] = mock.Mock() from networking_mlnx._i18n import _LE from networking_mlnx.eswitchd.utils import pci_utils -from networking_mlnx.eswitchd.utils.pci_utils import pciUtils from networking_mlnx.tests import base if six.PY3: @@ -134,20 +133,3 @@ class TestPciUtils(base.TestCase): is_sriov = self.pci_utils.is_sriov_pf(pf) self.assertFalse(is_sriov) - - def test_get_eth_vf_invalid(self): - pf = "pf_that_does_not_exist" - ret_val = self.pci_utils.get_eth_vf(pf) - self.assertIsNone(ret_val) - - @mock.patch('networking_mlnx.eswitchd.utils.pci_utils.os.readlink') - @mock.patch('networking_mlnx.eswitchd.utils.pci_utils.os') - def test_get_pf_pci_type_none(self, mock_os, mock_readlink): - inst = pciUtils() - mock_readlink.return_value = "../../../0000:81:00.0" - assert inst.get_pf_pci("dev") == "0000:81:00" - - def test_get_pf_pci_none(self): - pf = "pf_that_does_not_exist" - ret_val = self.pci_utils.get_pf_pci(pf) - self.assertIsNone(ret_val)