From 42a9c7223f345188c48d1c61c2ee650ab830b424 Mon Sep 17 00:00:00 2001 From: Fuzail Khan Date: Wed, 4 Nov 2020 23:10:18 -0800 Subject: [PATCH] Correcting the indentation and resolving merge conflict --- platform/pddf/i2c/utils/pddfparse.py | 31 ++-- .../sonic_platform_pddf_base/pddf_sfp.py | 46 +++-- .../sonic_platform_pddf_base/pddfparse.py | 164 +++++++++++++++--- 3 files changed, 186 insertions(+), 55 deletions(-) diff --git a/platform/pddf/i2c/utils/pddfparse.py b/platform/pddf/i2c/utils/pddfparse.py index a0483ae12a08..f9ce8fca0b42 100755 --- a/platform/pddf/i2c/utils/pddfparse.py +++ b/platform/pddf/i2c/utils/pddfparse.py @@ -392,6 +392,18 @@ def create_xcvr_i2c_device(self, dev, ops): cmd="echo %s 0x%x > /sys/bus/i2c/devices/i2c-%d/new_device" % (dev['i2c']['topo_info']['dev_type'], int(dev['i2c']['topo_info']['dev_addr'], 0), int(dev['i2c']['topo_info']['parent_bus'], 0)) create_ret = self.runcmd(cmd) + #print "\n" + if create_ret!=0: + return create_ret + # Add port name + port_name_sysfs = '/sys/bus/i2c/devices/{}-00{:02x}/port_name'.format( + int(dev['i2c']['topo_info']['parent_bus'], 0),int(dev['i2c']['topo_info']['dev_addr'], 0)) + + if os.path.exists(port_name_sysfs): + cmd="echo {} > /sys/bus/i2c/devices/{}-00{:02x}/port_name".format( + dev['dev_info']['virt_parent'].lower(), int(dev['i2c']['topo_info']['parent_bus'], 0), + int(dev['i2c']['topo_info']['dev_addr'], 0)) + create_ret = self.runcmd(cmd) if create_ret!=0: return create_ret @@ -973,12 +985,10 @@ def show_led_device(self, key, ops): self.sysfs_obj[KEY] = [] path="pddf/devices/led" for attr in self.data[key]['i2c']['attr_list']: - self.sysfs_attr('device_name', self.data[key]['dev_info']['device_name'], path, - self.sysfs_obj, KEY) - self.sysfs_attr('swpld_addr', self.data[key]['dev_info']['device_name'], path, - self.sysfs_obj, KEY) - self.sysfs_attr('swpld_addr_offset', self.data[key]['dev_info']['device_name'], path, - self.sysfs_obj, KEY) + self.sysfs_attr('device_name', self.data[key]['dev_info']['device_name'],path,self.sysfs_obj,KEY) + self.sysfs_attr('swpld_addr', self.data[key]['dev_info']['device_name'],path,self.sysfs_obj, KEY) + self.sysfs_attr('swpld_addr_offset',self.data[key]['dev_info']['device_name'], + path,self.sysfs_obj, KEY) self.sysfs_device(self.data[key]['dev_attr'], path, self.sysfs_obj, KEY) for attr_key in attr.keys(): attr_path="pddf/devices/led/" + attr['attr_name'] @@ -1159,8 +1169,8 @@ def verify_sysfs_data(self, verify_type): path="pddf/devices/led/" + attr['attr_name'] for entry in attr.keys(): if (entry != 'attr_name' and entry != 'swpld_addr' and entry != 'swpld_addr_offset'): - self.verify_attr(entry, attr, path) - if ( entry == 'swpld_addr' or entry == 'swpld_addr_offset'): + self.verify_attr(entry, attr, path) + if ( entry == 'swpld_addr' or entry == 'swpld_addr_offset'): self.verify_attr(entry, attr, 'pddf/devices/led') @@ -1579,7 +1589,7 @@ def dev_parse(self, dev, ops): if attr['device_type'] == 'SFP' or attr['device_type'] == 'SFP28' or \ attr['device_type'] == 'QSFP' or attr['device_type'] == 'QSFP28': - return self.optic_parse(dev, ops) + return self.optic_parse(dev, ops) if attr['device_type'] == 'CPLD': return self.cpld_parse(dev, ops) @@ -1621,7 +1631,8 @@ def create_led_device(self, key, ops): for attr_key in attr.keys(): if (attr_key == 'swpld_addr_offset' or attr_key == 'swpld_addr'): self.create_attr(attr_key, attr[attr_key], path) - elif (attr_key != 'attr_name' and attr_key != 'descr'): + elif (attr_key != 'attr_name' and attr_key != 'descr' and + attr_key != 'attr_devtype' and attr_key != 'attr_devname'): state_path=path+'/state_attr' self.create_attr(attr_key, attr[attr_key],state_path) cmd="echo '" + attr['attr_name']+"' > /sys/kernel/pddf/devices/led/dev_ops" diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_sfp.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_sfp.py index f18d70f413b6..856f4c748d10 100755 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_sfp.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddf_sfp.py @@ -184,14 +184,19 @@ def __init__(self, index, pddf_data=None, pddf_plugin_data=None): self.is_osfp_port = True if (self.sfp_type=='OSFP' or self.sfp_type=='QSFP-DD') else False self.eeprom_path = self.pddf_obj.get_path(self.device, 'eeprom') - self.info_dict_keys = ['type', 'hardwarerev', 'serialnum', 'manufacturename', 'modelname', 'Connector', 'encoding', 'ext_identifier', - 'ext_rateselect_compliance', 'cable_type', 'cable_length', 'nominal_bit_rate', 'specification_compliance', 'vendor_date', 'vendor_oui'] + self.info_dict_keys = ['type', 'hardware_rev', 'serial', 'manufacturer', 'model', 'connector', 'encoding', + 'ext_identifier', 'ext_rateselect_compliance', 'cable_type', 'cable_length', 'nominal_bit_rate', + 'specification_compliance', 'vendor_date', 'vendor_oui', 'application_advertisement'] - self.dom_dict_keys = ['rx_los', 'tx_fault', 'reset_status', 'power_lpmode', 'tx_disable', 'tx_disable_channel', 'temperature', 'voltage', - 'rx1power', 'rx2power', 'rx3power', 'rx4power', 'tx1bias', 'tx2bias', 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power'] + self.dom_dict_keys = ['rx_los', 'tx_fault', 'reset_status', 'power_lpmode', 'tx_disable', 'tx_disable_channel', + 'temperature', 'voltage', 'rx1power', 'rx2power', 'rx3power', 'rx4power', 'tx1bias', 'tx2bias', + 'tx3bias', 'tx4bias', 'tx1power', 'tx2power', 'tx3power', 'tx4power'] - self.threshold_dict_keys = ['temphighalarm', 'temphighwarning', 'templowalarm', 'templowwarning', 'vcchighalarm', 'vcchighwarning', 'vcclowalarm', 'vcclowwarning', 'rxpowerhighalarm', 'rxpowerhighwarning', - 'rxpowerlowalarm', 'rxpowerlowwarning', 'txpowerhighalarm', 'txpowerhighwarning', 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', 'txbiaslowwarning'] + self.threshold_dict_keys = ['temphighalarm', 'temphighwarning', 'templowalarm', 'templowwarning', + 'vcchighalarm', 'vcchighwarning', 'vcclowalarm', 'vcclowwarning', 'rxpowerhighalarm', + 'rxpowerhighwarning', 'rxpowerlowalarm', 'rxpowerlowwarning', 'txpowerhighalarm', 'txpowerhighwarning', + 'txpowerlowalarm', 'txpowerlowwarning', 'txbiashighalarm', 'txbiashighwarning', 'txbiaslowalarm', + 'txbiaslowwarning'] SfpBase.__init__(self) @@ -204,11 +209,11 @@ def get_transceiver_info(self): keys |Value Format |Information ---------------------------|---------------|---------------------------- type |1*255VCHAR |type of SFP - hardwarerev |1*255VCHAR |hardware version of SFP - serialnum |1*255VCHAR |serial number of the SFP - manufacturename |1*255VCHAR |SFP vendor name - modelname |1*255VCHAR |SFP model name - Connector |1*255VCHAR |connector information + hardware_rev |1*255VCHAR |hardware version of SFP + serial |1*255VCHAR |serial number of the SFP + manufacturer |1*255VCHAR |SFP vendor name + model |1*255VCHAR |SFP model name + connector |1*255VCHAR |connector information encoding |1*255VCHAR |encoding information ext_identifier |1*255VCHAR |extend identifier ext_rateselect_compliance |1*255VCHAR |extended rateSelect compliance @@ -217,6 +222,7 @@ def get_transceiver_info(self): specification_compliance |1*255VCHAR |specification compliance vendor_date |1*255VCHAR |vendor date vendor_oui |1*255VCHAR |vendor OUI + application_advertisement |1*255VCHAR |supported applications advertisement ======================================================================== """ # check present status @@ -307,7 +313,7 @@ def get_transceiver_info(self): if sfp_interface_bulk_data: xcvr_info_dict['type'] = sfp_interface_bulk_data['data']['type']['value'] - xcvr_info_dict['Connector'] = sfp_interface_bulk_data['data']['Connector']['value'] + xcvr_info_dict['connector'] = sfp_interface_bulk_data['data']['Connector']['value'] xcvr_info_dict['encoding'] = sfp_interface_bulk_data['data']['EncodingCodes']['value'] xcvr_info_dict['ext_identifier'] = sfp_interface_bulk_data['data']['Extended Identifier']['value'] xcvr_info_dict['ext_rateselect_compliance'] = sfp_interface_bulk_data['data']['RateIdentifier']['value'] @@ -316,10 +322,10 @@ def get_transceiver_info(self): xcvr_info_dict['type'] = sfp_type_data['data']['type']['value'] if sfp_type_data else 'N/A' xcvr_info_dict['type_abbrv_name'] = sfp_type_abbrv_name['data']['type_abbrv_name']['value'] if sfp_type_abbrv_name else 'N/A' - xcvr_info_dict['manufacturename'] = sfp_vendor_name_data['data']['Vendor Name']['value'] if sfp_vendor_name_data else 'N/A' - xcvr_info_dict['modelname'] = sfp_vendor_pn_data['data']['Vendor PN']['value'] if sfp_vendor_pn_data else 'N/A' - xcvr_info_dict['hardwarerev'] = sfp_vendor_rev_data['data']['Vendor Rev']['value'] if sfp_vendor_rev_data else 'N/A' - xcvr_info_dict['serialnum'] = sfp_vendor_sn_data['data']['Vendor SN']['value'] if sfp_vendor_sn_data else 'N/A' + xcvr_info_dict['manufacturer'] = sfp_vendor_name_data['data']['Vendor Name']['value'] if sfp_vendor_name_data else 'N/A' + xcvr_info_dict['model'] = sfp_vendor_pn_data['data']['Vendor PN']['value'] if sfp_vendor_pn_data else 'N/A' + xcvr_info_dict['hardware_rev'] = sfp_vendor_rev_data['data']['Vendor Rev']['value'] if sfp_vendor_rev_data else 'N/A' + xcvr_info_dict['serial'] = sfp_vendor_sn_data['data']['Vendor SN']['value'] if sfp_vendor_sn_data else 'N/A' xcvr_info_dict['vendor_oui'] = sfp_vendor_oui_data['data']['Vendor OUI']['value'] if sfp_vendor_oui_data else 'N/A' xcvr_info_dict['vendor_date'] = sfp_vendor_date_data['data']['VendorDataCode(YYYY-MM-DD Lot)']['value'] if sfp_vendor_date_data else 'N/A' xcvr_info_dict['cable_type'] = "Unknown" @@ -341,6 +347,8 @@ def get_transceiver_info(self): xcvr_info_dict['nominal_bit_rate'] = str(sfp_interface_bulk_data['data']['Nominal Bit Rate(100Mbs)']['value']) else: xcvr_info_dict['nominal_bit_rate'] = 'N/A' + elif sfp_type == 'OSFP': + pass else: for key in sfp_cable_length_tup: if key in sfp_interface_bulk_data['data']: @@ -1334,7 +1342,7 @@ def get_model(self): """ transceiver_dom_info_dict = self.get_transceiver_info() if transceiver_dom_info_dict is not None: - return transceiver_dom_info_dict.get("modelname", "N/A") + return transceiver_dom_info_dict.get("model", "N/A") else: return None @@ -1346,7 +1354,7 @@ def get_serial(self): """ transceiver_dom_info_dict = self.get_transceiver_info() if transceiver_dom_info_dict is not None: - return transceiver_dom_info_dict.get("serialnum", "N/A") + return transceiver_dom_info_dict.get("serial", "N/A") else: return None @@ -1366,7 +1374,7 @@ def get_connector_type(self): """ transceiver_dom_info_dict = self.get_transceiver_info() if transceiver_dom_info_dict is not None: - return transceiver_dom_info_dict.get("Connector", "N/A") + return transceiver_dom_info_dict.get("connector", "N/A") else: return None diff --git a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfparse.py b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfparse.py index 4a17eadbf5b7..aa47beaa0fc7 100755 --- a/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfparse.py +++ b/platform/pddf/platform-api-pddf-base/sonic_platform_pddf_base/pddfparse.py @@ -146,6 +146,118 @@ def get_led_color(self): return (color_map[color]) + + def get_led_color_devtype(self, key): + attr_list=self.data[key]['i2c']['attr_list'] + for attr in attr_list: + if 'attr_devtype' in attr: + return attr['attr_devtype'].strip() + else: + return 'cpld' + + def get_led_color_from_gpio(self, led_device_name): + attr_list=self.data[led_device_name]['i2c']['attr_list'] + attr=attr_list[0] + if ':' in attr['bits']: + bits_list=attr['bits'].split(':') + bits_list.sort(reverse=True) + max_bit=int(bits_list[0]) + else: + max_bit=0 + base_offset=int(attr['swpld_addr_offset'], 16) + value = 0 + bit = 0 + while bit <= max_bit: + offset=base_offset + bit + if 'attr_devname' in attr: + attr_path = self.get_gpio_attr_path(self.data[attr['attr_devname']], hex(offset)) + else: + status= "[FAILED] attr_devname is not configured" + return (status) + if not os.path.exists(attr_path): + status= "[FAILED] {} does not exist".format(attr_path) + return (status) + cmd = 'cat ' + attr_path + gpio_value = subprocess.check_output(cmd, shell=True) + value |= int(gpio_value) << bit + bit += 1 + + for attr in attr_list: + if int(attr['value'].strip(), 16) == value: + return(color_map[attr['attr_name']]) + return (color_map['STATUS_LED_COLOR_OFF']) + + + def get_led_color_from_cpld(self, led_device_name): + index=self.data[led_device_name]['dev_attr']['index'] + device_name=self.data[led_device_name]['dev_info']['device_name'] + self.create_attr('device_name', device_name, self.get_led_path()) + self.create_attr('index', index, self.get_led_path()) + self.create_attr('dev_ops', 'get_status', self.get_led_path()) + return self.get_led_color() + + def set_led_color_from_gpio(self, led_device_name, color): + attr_list=self.data[led_device_name]['i2c']['attr_list'] + for attr in attr_list: + if attr['attr_name'].strip() == color.strip(): + base_offset=int(attr['swpld_addr_offset'], 16) + if ':' in attr['bits']: + bits_list=attr['bits'].split(':') + bits_list.sort(reverse=True) + max_bit = int(bits_list[0]) + else: + max_bit=0 + value=int(attr['value'], 16) + i = 0 + while i <= max_bit: + _value =(value>>i) & 1 + base_offset += i + attr_path = self.get_gpio_attr_path(self.data[attr['attr_devname']], hex(base_offset)) + i += 1 + try: + cmd = "echo {} > {}".format(_value, attr_path) + self.runcmd(cmd) + except Exception as e: + print "Invalid gpio path : " + attr_path + return (False) + return (True) + + def set_led_color_from_cpld(self, led_device_name, color): + index=self.data[led_device_name]['dev_attr']['index'] + device_name=self.data[led_device_name]['dev_info']['device_name'] + self.create_attr('device_name', device_name, self.get_led_path()) + self.create_attr('index', index, self.get_led_path()) + self.create_attr('color', color, self.get_led_cur_state_path()) + self.create_attr('dev_ops', 'set_status', self.get_led_path()) + return (True) + + + def get_system_led_color(self, led_device_name): + if (not led_device_name in self.data.keys()): + status= "[FAILED] " + led_device_name + " is not configured" + return (status) + + type = self.get_led_color_devtype(led_device_name) + + if type == 'gpio': + color = self.get_led_color_from_gpio(led_device_name) + elif type == 'cpld': + color = self.get_led_color_from_cpld(led_device_name) + return color + + def set_system_led_color(self, led_device_name, color): + result, msg = self.is_supported_sysled_state(led_device_name, color); + if result == False: + print msg + return (result) + + type = self.get_led_color_devtype(led_device_name) + + if type == 'gpio': + return (self.set_led_color_from_gpio(led_device_name, color)) + else: + return (self.set_led_color_from_cpld(led_device_name, color)) + ################################################################################################################### # SHOW ATTRIBIUTES DEFS ################################################################################################################### @@ -584,11 +696,9 @@ def show_led_device(self, key, ops): self.sysfs_obj[KEY] = [] path="pddf/devices/led" for attr in self.data[key]['i2c']['attr_list']: - self.sysfs_attr('device_name', self.data[key]['dev_info']['device_name'], path, - self.sysfs_obj, KEY) - self.sysfs_attr('swpld_addr', self.data[key]['dev_info']['device_name'], path, - self.sysfs_obj, KEY) - self.sysfs_attr('swpld_addr_offset', self.data[key]['dev_info']['device_name'], path, + self.sysfs_attr('device_name', self.data[key]['dev_info']['device_name'],path,self.sysfs_obj,KEY) + self.sysfs_attr('swpld_addr', self.data[key]['dev_info']['device_name'],path,self.sysfs_obj,KEY) + self.sysfs_attr('swpld_addr_offset', self.data[key]['dev_info']['device_name'],path, self.sysfs_obj, KEY) self.sysfs_device(self.data[key]['dev_attr'], path, self.sysfs_obj, KEY) for attr_key in attr.keys(): @@ -773,9 +883,9 @@ def verify_sysfs_data(self, verify_type): path="pddf/devices/led/" + attr['attr_name'] for entry in attr.keys(): if (entry != 'attr_name' and entry != 'swpld_addr' and entry != 'swpld_addr_offset'): - self.verify_attr(entry, attr, path) + self.verify_attr(entry, attr, path) if ( entry == 'swpld_addr' or entry == 'swpld_addr_offset'): - self.verify_attr(entry, attr, 'pddf/devices/led') + self.verify_attr(entry, attr, 'pddf/devices/led') @@ -1133,8 +1243,9 @@ def dev_parse(self, dev, ops): if attr['device_type'] == 'TEMP_SENSOR': return self.temp_sensor_parse(dev, ops) - if attr['device_type'] == 'SFP' or attr['device_type'] == 'SFP28' or \ - attr['device_type'] == 'QSFP' or attr['device_type'] == 'QSFP28': + if attr['device_type'] == 'SFP' or attr['device_type'] == 'QSFP' or \ + attr['device_type'] == 'SFP28' or attr['device_type'] == 'QSFP28' or \ + attr['device_type'] == 'QSFP-DD': return self.optic_parse(dev, ops) if attr['device_type'] == 'CPLD': @@ -1156,25 +1267,26 @@ def create_attr(self, key, value, path): self.runcmd(cmd) def create_led_platform_device(self, key, ops): - if ops['attr']=='all' or ops['attr']=='PLATFORM': - path='pddf/devices/platform' - self.create_attr('num_psus', self.data['PLATFORM']['num_psus'], path) - self.create_attr('num_fantrays', self.data['PLATFORM']['num_fantrays'], path) + if ops['attr']=='all' or ops['attr']=='PLATFORM': + path='pddf/devices/platform' + self.create_attr('num_psus', self.data['PLATFORM']['num_psus'], path) + self.create_attr('num_fantrays', self.data['PLATFORM']['num_fantrays'], path) def create_led_device(self, key, ops): - if ops['attr']=='all' or ops['attr']==self.data[key]['dev_info']['device_name']: - path="pddf/devices/led" - for attr in self.data[key]['i2c']['attr_list']: - self.create_attr('device_name', self.data[key]['dev_info']['device_name'], path) - self.create_device(self.data[key]['dev_attr'], path, ops) - for attr_key in attr.keys(): - if (attr_key == 'swpld_addr_offset' or attr_key == 'swpld_addr'): - self.create_attr(attr_key, attr[attr_key], path) - elif (attr_key != 'attr_name' and attr_key != 'descr'): - state_path=path+'/state_attr' - self.create_attr(attr_key, attr[attr_key],state_path) - cmd="echo '" + attr['attr_name']+"' > /sys/kernel/pddf/devices/led/dev_ops" - self.runcmd(cmd) + if ops['attr']=='all' or ops['attr']==self.data[key]['dev_info']['device_name']: + path="pddf/devices/led" + for attr in self.data[key]['i2c']['attr_list']: + self.create_attr('device_name', self.data[key]['dev_info']['device_name'], path) + self.create_device(self.data[key]['dev_attr'], path, ops) + for attr_key in attr.keys(): + if (attr_key == 'swpld_addr_offset' or attr_key == 'swpld_addr'): + self.create_attr(attr_key, attr[attr_key], path) + elif (attr_key != 'attr_name' and attr_key != 'descr' and attr_key != 'attr_devtype' and + attr_key != 'attr_devname'): + state_path=path+'/state_attr' + self.create_attr(attr_key, attr[attr_key],state_path) + cmd="echo '" + attr['attr_name']+"' > /sys/kernel/pddf/devices/led/dev_ops" + self.runcmd(cmd) def led_parse(self, ops):