add support to plx
Change-Id: I024f8459e941b7ff5960031c91b041522a782f79
This commit is contained in:
parent
7378c5f662
commit
f165779c8c
|
@ -24,12 +24,11 @@ class DeviceDB(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.device_db = {}
|
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_mlx_dev):
|
||||||
pf_details = {}
|
pf_details = {}
|
||||||
pf_details['vfs'] = {}
|
pf_details['vfs'] = {}
|
||||||
pf_details['pf_device_type'] = None
|
pf_details['pf_device_type'] = None
|
||||||
pf_details['pci_id'] = pci_id
|
|
||||||
pf_details['hca_port'] = hca_port
|
pf_details['hca_port'] = hca_port
|
||||||
pf_details['fabric_type'] = fabric_type
|
pf_details['fabric_type'] = fabric_type
|
||||||
pf_details['pf_mlx_dev'] = pf_mlx_dev
|
pf_details['pf_mlx_dev'] = pf_mlx_dev
|
||||||
|
|
|
@ -33,8 +33,8 @@ class ResourceManager(object):
|
||||||
self.device_db = device_db.DeviceDB()
|
self.device_db = device_db.DeviceDB()
|
||||||
|
|
||||||
def add_fabric(self, fabric, pf, fabric_type):
|
def add_fabric(self, fabric, pf, fabric_type):
|
||||||
pci_id, hca_port, pf_mlx_dev = self._get_pf_details(pf)
|
hca_port, pf_mlx_dev = self._get_pf_details(pf)
|
||||||
self.device_db.add_fabric(fabric, pf, pci_id, hca_port, fabric_type,
|
self.device_db.add_fabric(fabric, pf, hca_port, fabric_type,
|
||||||
pf_mlx_dev)
|
pf_mlx_dev)
|
||||||
vfs = self.discover_devices(pf)
|
vfs = self.discover_devices(pf)
|
||||||
LOG.info(_LI("PF %(pf)s, vfs = %(vf)s"), {'pf': pf, 'vf': vfs})
|
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):
|
def _get_pf_details(self, pf):
|
||||||
hca_port = self.pci_utils.get_eth_port(pf)
|
hca_port = self.pci_utils.get_eth_port(pf)
|
||||||
pci_id = self.pci_utils.get_pf_pci(pf)
|
pf_mlx_dev = self.pci_utils.get_pf_mlx_dev(pf)
|
||||||
pf_pci_id = self.pci_utils.get_pf_pci(pf, 'normal')
|
return (hca_port, pf_mlx_dev)
|
||||||
pf_mlx_dev = self.pci_utils.get_pf_mlx_dev(pf_pci_id)
|
|
||||||
return (pci_id, hca_port, pf_mlx_dev)
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class pciUtils(object):
|
||||||
ETH_PATH = "/sys/class/net/%(interface)s"
|
ETH_PATH = "/sys/class/net/%(interface)s"
|
||||||
ETH_DEV = ETH_PATH + "/device"
|
ETH_DEV = ETH_PATH + "/device"
|
||||||
ETH_PORT = ETH_PATH + "/dev_id"
|
ETH_PORT = ETH_PATH + "/dev_id"
|
||||||
PF_MLX_DEV_PATH = "/sys/class/infiniband/*"
|
INFINIBAND_PATH = 'device/infiniband'
|
||||||
VENDOR_PATH = ETH_DEV + '/vendor'
|
VENDOR_PATH = ETH_DEV + '/vendor'
|
||||||
DEVICE_TYPE_PATH = ETH_DEV + '/virtfn%(vf_num)s/device'
|
DEVICE_TYPE_PATH = ETH_DEV + '/virtfn%(vf_num)s/device'
|
||||||
_VIRTFN_RE = re.compile("virtfn(?P<vf_num>\d+)")
|
_VIRTFN_RE = re.compile("virtfn(?P<vf_num>\d+)")
|
||||||
|
@ -144,30 +144,12 @@ class pciUtils(object):
|
||||||
% mlnx_pfs)
|
% mlnx_pfs)
|
||||||
return mlnx_pfs[0]
|
return mlnx_pfs[0]
|
||||||
|
|
||||||
def get_eth_vf(self, dev):
|
def get_pf_mlx_dev(self, pf):
|
||||||
vf_path = pciUtils.ETH_DEV % {'interface': dev}
|
dev_path = (
|
||||||
try:
|
os.path.join(pciUtils.ETH_PATH % {'interface': pf},
|
||||||
device = os.readlink(vf_path)
|
pciUtils.INFINIBAND_PATH))
|
||||||
vf = device.split('/')[3]
|
dev_info = os.listdir(dev_path)
|
||||||
return vf
|
return dev_info.pop()
|
||||||
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_guid_index(self, pf_mlx_dev, dev, hca_port):
|
def get_guid_index(self, pf_mlx_dev, dev, hca_port):
|
||||||
guid_index = None
|
guid_index = None
|
||||||
|
|
|
@ -24,7 +24,6 @@ sys.modules['ethtool'] = mock.Mock()
|
||||||
|
|
||||||
from networking_mlnx._i18n import _LE
|
from networking_mlnx._i18n import _LE
|
||||||
from networking_mlnx.eswitchd.utils import pci_utils
|
from networking_mlnx.eswitchd.utils import pci_utils
|
||||||
from networking_mlnx.eswitchd.utils.pci_utils import pciUtils
|
|
||||||
from networking_mlnx.tests import base
|
from networking_mlnx.tests import base
|
||||||
|
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
|
@ -134,20 +133,3 @@ class TestPciUtils(base.TestCase):
|
||||||
|
|
||||||
is_sriov = self.pci_utils.is_sriov_pf(pf)
|
is_sriov = self.pci_utils.is_sriov_pf(pf)
|
||||||
self.assertFalse(is_sriov)
|
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)
|
|
||||||
|
|
Loading…
Reference in New Issue