未验证 提交 baaa2e38 编写于 作者: A Amador Pahim

Merge branch 'ldoktor-pci-addresses2'

Signed-off-by: NAmador Pahim <apahim@redhat.com>
...@@ -48,7 +48,7 @@ def get_pci_addresses(): ...@@ -48,7 +48,7 @@ def get_pci_addresses():
Gets list of pci addresses in the system. Gets list of pci addresses in the system.
Does not return the PCI Bridges/Switches. Does not return the PCI Bridges/Switches.
:return: list of pci addresses. :return: list of full pci addresses including domain (0000:00:14.0)
""" """
addresses = [] addresses = []
cmd = "lspci -D" cmd = "lspci -D"
...@@ -59,21 +59,23 @@ def get_pci_addresses(): ...@@ -59,21 +59,23 @@ def get_pci_addresses():
return addresses return addresses
def get_num_devices_in_domain(domain): def get_num_interfaces_in_pci(dom_pci_address):
""" """
Gets number of devices in a pci domain. Gets number of interfaces of a given partial pci_address starting with
full domain addr.
:parm domain: pci domain. :parm dom_pci_address: Partial pci address including domain addr (0000,
0000:00:1f, 0000:00:1f.2, ...)
:return: number of devices in a pci domain. :return: number of devices in a pci domain.
""" """
cmd = "ls -l /sys/class/*/ -1" cmd = "ls -l /sys/class/*/ -1"
output = process.system_output(cmd, ignore_status=True, shell=True) output = process.system_output(cmd, ignore_status=True, shell=True)
if output: if output:
domain = '/%s' % domain filt = '/%s' % dom_pci_address
count = 0 count = 0
for line in output.splitlines(): for line in output.splitlines():
if domain in line: if filt in line:
count += 1 count += 1
return count return count
...@@ -82,7 +84,7 @@ def get_disks_in_pci_address(pci_address): ...@@ -82,7 +84,7 @@ def get_disks_in_pci_address(pci_address):
""" """
Gets disks in a pci_address. Gets disks in a pci_address.
:parm pci_address: pci address. :parm pci_address: Any segment of a pci address (1f, 0000:00:1f, ...)
:return: list of disks in a pci address. :return: list of disks in a pci address.
""" """
...@@ -99,7 +101,7 @@ def get_nics_in_pci_address(pci_address): ...@@ -99,7 +101,7 @@ def get_nics_in_pci_address(pci_address):
""" """
Gets network interface(nic) in a pci address. Gets network interface(nic) in a pci address.
:parm pci_address: pci address. :parm pci_address: Any segment of a pci address (1f, 0000:00:1f, ...)
:return: list of network interfaces in a pci address. :return: list of network interfaces in a pci address.
""" """
...@@ -116,26 +118,26 @@ def get_pci_fun_list(pci_address): ...@@ -116,26 +118,26 @@ def get_pci_fun_list(pci_address):
Gets list of functions in the given pci address. Gets list of functions in the given pci address.
Example: in address 0000:03:00, functions are 0000:03:00.0 and 0000:03:00.1 Example: in address 0000:03:00, functions are 0000:03:00.0 and 0000:03:00.1
:parm pci_address: pci address. :parm pci_address: Any segment of a pci address (1f, 0000:00:1f, ...)
:return: list of functions in a pci address. :return: list of functions in a pci address.
""" """
return list(dev for dev in get_pci_addresses() if pci_address in dev) return list(dev for dev in get_pci_addresses() if pci_address in dev)
def get_slot_from_sysfs(pci_address): def get_slot_from_sysfs(full_pci_address):
""" """
Gets the pci slot of given address. Gets the pci slot of given address.
:note: Specific for ppc64 processor. :note: Specific for ppc64 processor.
:parm pci_address: pci address. :parm full_pci_address: Full pci address including domain (0000:03:00.0)
:return: slot of pci address from sysfs. :return: slot of pci address from sysfs.
""" """
if not os.path.isfile('/sys/bus/pci/devices/%s/devspec' % pci_address): if not os.path.isfile('/sys/bus/pci/devices/%s/devspec' % full_pci_address):
return return
devspec = read_file("/sys/bus/pci/devices/%s/devspec" % pci_address) devspec = read_file("/sys/bus/pci/devices/%s/devspec" % full_pci_address)
if not os.path.isfile("/proc/device-tree/%s/ibm,loc-code" % devspec): if not os.path.isfile("/proc/device-tree/%s/ibm,loc-code" % devspec):
return return
slot = read_file("/proc/device-tree/%s/ibm,loc-code" % devspec) slot = read_file("/proc/device-tree/%s/ibm,loc-code" % devspec)
...@@ -154,15 +156,15 @@ def get_slot_list(): ...@@ -154,15 +156,15 @@ def get_slot_list():
return list(set(get_slot_from_sysfs(dev) for dev in get_pci_addresses())) return list(set(get_slot_from_sysfs(dev) for dev in get_pci_addresses()))
def get_pci_id_from_sysfs(pci_address): def get_pci_id_from_sysfs(full_pci_address):
""" """
Gets the pci id from sysfs of given pci address. Gets the pci id from sysfs of given pci address.
:parm pci_address: pci address. :parm full_pci_address: Full pci address including domain (0000:03:00.0)
:return: pci id of a pci address from sysfs. :return: pci id of a pci address from sysfs.
""" """
path = "/sys/bus/pci/devices/%s" % pci_address path = "/sys/bus/pci/devices/%s" % full_pci_address
if os.path.isdir(path): if os.path.isdir(path):
path = "%s/%%s" % path path = "%s/%%s" % path
return ":".join(["%04x" % int(open(path % param).read(), 16) return ":".join(["%04x" % int(open(path % param).read(), 16)
...@@ -172,9 +174,9 @@ def get_pci_id_from_sysfs(pci_address): ...@@ -172,9 +174,9 @@ def get_pci_id_from_sysfs(pci_address):
def get_pci_prop(pci_address, prop): def get_pci_prop(pci_address, prop):
""" """
Gets specific pci id of given pci address. Gets specific pci id of given pci address. (first match only)
:parm pci_address: pci address. :parm pci_address: Any segment of a pci address (1f, 0000:00:1f, ...)
:parm part: prop of pci id. :parm part: prop of pci id.
:return: specific pci id of a pci address. :return: specific pci id of a pci address.
...@@ -189,9 +191,9 @@ def get_pci_prop(pci_address, prop): ...@@ -189,9 +191,9 @@ def get_pci_prop(pci_address, prop):
def get_pci_id(pci_address): def get_pci_id(pci_address):
""" """
Gets pci id of given address. Gets pci id of given address. (first match only)
:parm pci_address: pci address. :parm pci_address: Any segment of a pci address (1f, 0000:00:1f, ...)
:return: pci id of a pci address. :return: pci id of a pci address.
""" """
...@@ -207,9 +209,9 @@ def get_pci_id(pci_address): ...@@ -207,9 +209,9 @@ def get_pci_id(pci_address):
def get_driver(pci_address): def get_driver(pci_address):
""" """
Gets the kernel driver in use of given pci address. Gets the kernel driver in use of given pci address. (first match only)
:parm pci_address: pci address. :parm pci_address: Any segment of a pci address (1f, 0000:00:1f, ...)
:return: driver of a pci address. :return: driver of a pci address.
""" """
...@@ -223,12 +225,12 @@ def get_driver(pci_address): ...@@ -223,12 +225,12 @@ def get_driver(pci_address):
def get_memory_address(pci_address): def get_memory_address(pci_address):
""" """
Gets the memory address of a pci address. Gets the memory address of a pci address. (first match only)
:note: There may be multiple memory address for a pci address. :note: There may be multiple memory address for a pci address.
:note: This function returns only the first such address. :note: This function returns only the first such address.
:parm pci_address: pci address. :parm pci_address: Any segment of a pci address (1f, 0000:00:1f, ...)
:return: memory address of a pci_address. :return: memory address of a pci_address.
""" """
...@@ -242,12 +244,12 @@ def get_memory_address(pci_address): ...@@ -242,12 +244,12 @@ def get_memory_address(pci_address):
def get_mask(pci_address): def get_mask(pci_address):
""" """
Gets the mask of pci address. Gets the mask of pci address. (first match only)
:note: There may be multiple memory entries for a pci address. :note: There may be multiple memory entries for a pci address.
:note: This mask is calculated only with the first such entry. :note: This mask is calculated only with the first such entry.
:parm pci_address: pci address. :parm pci_address: Any segment of a pci address (1f, 0000:00:1f, ...)
:return: mask of a pci address. :return: mask of a pci address.
""" """
...@@ -265,18 +267,19 @@ def get_mask(pci_address): ...@@ -265,18 +267,19 @@ def get_mask(pci_address):
return mask return mask
def get_vpd(pci_addr): def get_vpd(dom_pci_address):
""" """
Gets the vpd of the given pci address. Gets the vpd of the given pci address.
lsvpd lists the Vital Product Data of a pci address. lsvpd lists the Vital Product Data of a pci address.
:note: Specific for ppc64 processor. :note: Specific for ppc64 processor.
:parm pci_addr: pci address. :parm dom_pci_address: Partial pci address including domain addr and at
least bus addr (0003:00, 0003:00:1f.2, ...)
:return: dictionary of vpd of a pci address. :return: dictionary of vpd of a pci address.
""" """
cmd = "lsvpd -l %s" % pci_addr cmd = "lsvpd -l %s" % dom_pci_address
vpd = process.system_output(cmd) vpd = process.system_output(cmd)
vpd_dic = {} vpd_dic = {}
dev_list = [] dev_list = []
...@@ -290,28 +293,30 @@ def get_vpd(pci_addr): ...@@ -290,28 +293,30 @@ def get_vpd(pci_addr):
elif '*FC' in line: elif '*FC' in line:
vpd_dic['feature_code'] = line[4:] vpd_dic['feature_code'] = line[4:]
elif '*AX' in line: elif '*AX' in line:
if not (pci_addr in line or vpd_dic['pci_id'].split()[0] in line): if not (dom_pci_address in line or
vpd_dic['pci_id'].split()[0] in line):
dev_list.append(line[4:]) dev_list.append(line[4:])
vpd_dic['devices'] = dev_list vpd_dic['devices'] = dev_list
return vpd_dic return vpd_dic
def get_cfg(pci_addr): def get_cfg(dom_pci_address):
""" """
Gets the cfg data of the given pci address. Gets the cfg data of the given pci address.
lscfg lists the hardware configuration of a pci address. lscfg lists the hardware configuration of a pci address.
:note: Specific for ppc64 processor. :note: Specific for ppc64 processor.
:parm pci_addr: pci address. :parm dom_pci_address: Partial pci address including domain addr and at
least bus addr (0003:00, 0003:00:1f.2, ...)
:return: dictionary of cfg data of a pci address. :return: dictionary of cfg data of a pci address.
""" """
cmd = "lscfg -vl %s" % pci_addr cmd = "lscfg -vl %s" % dom_pci_address
cfg = process.system_output(cmd) cfg = process.system_output(cmd)
cfg_dic = {} cfg_dic = {}
desc = re.match(r' (%s)( [-\w+,\.]+)+([ \n])+([-\w+, \(\)])+' % pci_addr, desc = re.match(r' (%s)( [-\w+,\.]+)+([ \n])+([-\w+, \(\)])+'
cfg).group() % dom_pci_address, cfg).group()
cfg_dic['Description'] = desc cfg_dic['Description'] = desc
for line in cfg.splitlines(): for line in cfg.splitlines():
if 'Manufacturer Name' in line: if 'Manufacturer Name' in line:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册