sonic-buildimage/platform/barefoot/sonic-platform-modules-bfn-montara/sonic_platform/sfp.py
Andriy Kokhan 4037867b7d
[BFN] Updated platform plugins (#9540)
* [BFN] Updated platform APIs impl

Signed-off-by: Andriy Kokhan <andriyx.kokhan@intel.com>

* Extended BFN platform SFP APIs implementation

* Update sfp.py

* [BFN] Extended SFP platform plugin implementation

Signed-off-by: Andriy Kokhan <andriyx.kokhan@intel.com>

* [BFN] Extended Fans platform plugin implementation

* [BFN] divided classes Fan and  FanDrawer into 2 files

* Signed-off-by: Vadym Yashchenko <vadymx.yashchenko@intel.com>

What I did
	Add get_model() function
	Add get_low_critical_threshold() function
	Change __get(...) function.
How I did it
	Differnece from previous implementation of __get(...) function is return real value or -9999.9 if value is not provided by thrift API

* Add get_presence() function and revised __get() function

Signed-off-by: Vadym Yashchenko <vadymx.yashchenko@intel.com>

* [BFN] Updated PSU platform APIs impl

Signed-off-by: Dmytro Lytvynenko <dmytrox.lytvynenko@intel.com>

* Added BFN PSU cache (#9)

Signed-off-by: Andriy Kokhan <andriyx.kokhan@intel.com>

* [BFN]  Fans and Fantray platform APIs update (#7)

* [BFN] Updated SFP platform APIs (#10)

Signed-off-by: Volodymyr Boyko <volodymyrx.boiko@intel.com>

* [BFN] Updated platform API for thermal (#8)

* Signed-off-by: Vadym Yashchenko <vadymx.yashchenko@intel.com>

* Revert "[BFN]  Fans and Fantray platform APIs update (#7)" (#11)

This reverts commit c62a733443be49cbe4ba2d06047aac7516f0495e.

* Add support health monitor system (#15)

Signed-off-by: Petro Bratash <petrox.bratash@intel.com>

* Update chassis.py

* [BFN] Updated FANs and FAN Tray platform API (#14)

* Fix fix_alignment (#17)

Signed-off-by: Petro Bratash <petrox.bratash@intel.com>

* [BFN] Improvement show environment (#16)

* Added PSU temperature skip into platform.json (#18)

Signed-off-by: Andriy Kokhan <andriyx.kokhan@intel.com>

* Do not skip psud on Newport

Signed-off-by: Andriy Kokhan <andriyx.kokhan@intel.com>

* [BFN] fix fan status from Not OK to Ok (#19)

* [BFN] Updated SFP platform plugin (#13)

Signed-off-by: Volodymyr Boyko <volodymyrx.boiko@intel.com>

* [DPB] Fix typo for Ethernet0 2x200G[100G,40G] breakout mode (#21)

Signed-off-by: Mykola Gerasymenko <mykolax.gerasymenko@intel.com>

* [barefoot] Tmp fix vendor_rev (#22)

Signed-off-by: Volodymyr Boyko <volodymyrx.boiko@intel.com>

* Fixed python issues in sonic_platform/fan_drawer.py

Signed-off-by: Andriy Kokhan <andriyx.kokhan@intel.com>

* Updated fan_drawer.py

* Fixing trailing white spaces in fan_drawer.py

* [BFN] Fix thrift for SFPs API

Signed-off-by: Volodymyr Boyko <volodymyrx.boiko@intel.com>

* In platform.json, replaced 'false' with '0' to workaround ast.literal_eval() issue

Signed-off-by: Andriy Kokhan <andriyx.kokhan@intel.com>

* [Newport] Thermal manager  (#23)

* Signed-off-by: Vadym Yashchenko <vadymx.yashchenko@intel.com>

* Revert "In platform.json, replaced 'false' with '0' to workaround ast.literal_eval() issue"

This reverts commit 1e73127830.

* Removed 'controllable' options from platform.json to fix factory default config generation

Signed-off-by: Andriy Kokhan <andriyx.kokhan@intel.com>

* Update thermal_manager.py

* Migrated SFP plugin to sonic_xcvr API (#30)

Signed-off-by: Andriy Kokhan <andriyx.kokhan@intel.com>

Co-authored-by: KostiantynYarovyiBf <kostiantynx.yarovyi@intel.com>
Co-authored-by: Vadym Yashchenko <vadymx.yashchenko@intel.com>
Co-authored-by: Dmytro Lytvynenko <dmytrox.lytvynenko@intel.com>
Co-authored-by: Volodymyr Boiko <volodymyrx.boiko@intel.com>
Co-authored-by: Petro Bratash <petrox.bratash@intel.com>
Co-authored-by: Mykola Gerasymenko <mykolax.gerasymenko@intel.com>
2022-01-17 11:16:20 +05:30

208 lines
6.3 KiB
Python

#!/usr/bin/env python
try:
import os
from sonic_platform_base.sonic_xcvr.sfp_optoe_base import SfpOptoeBase
from sonic_platform.platform_thrift_client import thrift_try
from sonic_platform.platform_thrift_client import pltfm_mgr_try
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
SFP_TYPE = "SFP"
QSFP_TYPE = "QSFP"
QSFP_DD_TYPE = "QSFP_DD"
class Sfp(SfpOptoeBase):
"""
BFN Platform-specific SFP class
"""
SFP_EEPROM_PATH = "/var/run/platform/sfp/"
def __init__(self, port_num):
SfpOptoeBase.__init__(self)
self.index = port_num
self.port_num = port_num
self.sfp_type = QSFP_TYPE
if not os.path.exists(self.SFP_EEPROM_PATH):
try:
os.makedirs(self.SFP_EEPROM_PATH)
except OSError as e:
if e.errno != errno.EEXIST:
raise
self.eeprom_path = self.SFP_EEPROM_PATH + "sfp{}-eeprom-cache".format(self.index)
def get_presence(self):
"""
Retrieves the presence of the sfp
"""
presence = False
def qsfp_presence_get(client):
return client.pltfm_mgr.pltfm_mgr_qsfp_presence_get(self.index)
try:
presence = thrift_try(qsfp_presence_get)
except Exception as e:
print( e.__doc__)
print(e.message)
return presence
def get_lpmode(self):
"""
Retrieves the lpmode (low power mode) status of this SFP
"""
def qsfp_lpmode_get(client):
return client.pltfm_mgr.pltfm_mgr_qsfp_lpmode_get(self.index)
return thrift_try(qsfp_lpmode_get)
def set_lpmode(self, lpmode):
"""
Sets the lpmode (low power mode) of SFP
"""
def qsfp_lpmode_set(client):
return client.pltfm_mgr.pltfm_mgr_qsfp_lpmode_set(self.index, lpmode)
status = thrift_try(qsfp_lpmode_set)
return (status == 0)
def get_eeprom_path(self):
def qsfp_info_get(client):
return client.pltfm_mgr.pltfm_mgr_qsfp_info_get(self.index)
if self.get_presence():
eeprom_hex = thrift_try(qsfp_info_get)
eeprom_raw = bytearray.fromhex(eeprom_hex)
with open(self.eeprom_path, 'wb') as fp:
fp.write(eeprom_raw)
return self.eeprom_path
return None
def write_eeprom(self, offset, num_bytes, write_buffer):
# Not supported at the moment
return False
def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""
return "sfp{}".format(self.index)
def get_reset_status(self):
"""
Retrieves the reset status of SFP
"""
def get_qsfp_reset(pltfm_mgr):
return pltfm_mgr.pltfm_mgr_qsfp_reset_get(self.index)
_, status = pltfm_mgr_try(get_qsfp_reset, False)
return status
def reset(self):
"""
Reset SFP and return all user module settings to their default srate.
"""
def qsfp_reset(client):
client.pltfm_mgr.pltfm_mgr_qsfp_reset(self.index, True)
return client.pltfm_mgr.pltfm_mgr_qsfp_reset(self.index, False)
err = thrift_try(qsfp_reset)
return not err
def get_status(self):
"""
Retrieves the operational status of the device
"""
reset = self.get_reset_status()
if reset:
status = False
else:
status = True
return status
def get_position_in_parent(self):
"""
Retrieves 1-based relative physical position in parent device.
Returns:
integer: The 1-based relative physical position in parent
device or -1 if cannot determine the position
"""
return self.index
def is_replaceable(self):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
return True
def get_error_description(self):
"""
Retrives the error descriptions of the SFP module
Returns:
String that represents the current error descriptions of vendor specific errors
In case there are multiple errors, they should be joined by '|',
like: "Bad EEPROM|Unsupported cable"
"""
if not self.get_presence():
return self.SFP_STATUS_UNPLUGGED
return self.SFP_STATUS_OK
def tx_disable(self, tx_disable):
"""
Disable SFP TX for all channels
Args:
tx_disable : A Boolean, True to enable tx_disable mode, False to disable
tx_disable mode.
Returns:
A boolean, True if tx_disable is set successfully, False if not
"""
if self.sfp_type == QSFP_TYPE:
return self.tx_disable_channel(0xF, tx_disable)
return False
def tx_disable_channel(self, channel, disable):
"""
Sets the tx_disable for specified SFP channels
Args:
channel : A hex of 4 bits (bit 0 to bit 3) which represent channel 0 to 3,
e.g. 0x5 for channel 0 and channel 2.
disable : A boolean, True to disable TX channels specified in channel,
False to enable
Returns:
A boolean, True if successful, False if not
"""
def qsfp_tx_disable_channel(client):
return client.pltfm_mgr.pltfm_mgr_qsfp_tx_disable(self.index, channel, disable)
if self.sfp_type == QSFP_TYPE:
status = thrift_try(qsfp_tx_disable_channel)
return (status == 0)
return False
def get_power_override(self):
def get_qsfp_power_override(pltfm_mgr):
return pltfm_mgr.pltfm_mgr_qsfp_pwr_override_get(self.index)
_, pwr_override = pltfm_mgr_try(get_qsfp_power_override)
return pwr_override
def set_power_override(self, power_override, power_set):
def set_qsfp_power_override(pltfm_mgr):
return pltfm_mgr.pltfm_mgr_qsfp_pwr_override_set(
self.index, power_override, power_set
)
_, status = pltfm_mgr_try(set_qsfp_power_override)
return status