Skip to content

Commit 0fdd198

Browse files
[sfp-refactor] Add initial support for SFF-8436 in sonic_xcvr (#215)
1 parent a09f5a3 commit 0fdd198

File tree

11 files changed

+817
-11
lines changed

11 files changed

+817
-11
lines changed

sonic_platform_base/sfp_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def get_transceiver_info(self):
109109
keys |Value Format |Information
110110
---------------------------|---------------|----------------------------
111111
type |1*255VCHAR |type of SFP
112+
type_abbrv_name |1*255VCHAR |type of SFP, abbreviated
112113
hardware_rev |1*255VCHAR |hardware version of SFP
113114
serial |1*255VCHAR |serial number of the SFP
114115
manufacturer |1*255VCHAR |SFP vendor name
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
from ...fields import consts
2+
from ..xcvr_api import XcvrApi
3+
4+
class Sff8436Api(XcvrApi):
5+
NUM_CHANNELS = 4
6+
7+
def __init__(self, xcvr_eeprom):
8+
super(Sff8436Api, self).__init__(xcvr_eeprom)
9+
10+
def get_model(self):
11+
return self.xcvr_eeprom.read(consts.VENDOR_PART_NO_FIELD)
12+
13+
def get_serial(self):
14+
return self.xcvr_eeprom.read(consts.VENDOR_SERIAL_NO_FIELD)
15+
16+
def get_transceiver_info(self):
17+
serial_id = self.xcvr_eeprom.read(consts.SERIAL_ID_FIELD)
18+
if serial_id is None:
19+
return None
20+
21+
ext_id = serial_id[consts.EXT_ID_FIELD]
22+
power_class = ext_id[consts.POWER_CLASS_FIELD]
23+
clei_code = ext_id[consts.CLEI_CODE_FIELD]
24+
cdr_tx = ext_id[consts.CDR_TX_FIELD]
25+
cdr_rx = ext_id[consts.CDR_RX_FIELD]
26+
27+
smf_len = serial_id[consts.LENGTH_SMF_KM_FIELD]
28+
om3_len = serial_id[consts.LENGTH_OM3_FIELD]
29+
om2_len = serial_id[consts.LENGTH_OM2_FIELD]
30+
om1_len = serial_id[consts.LENGTH_OM1_FIELD]
31+
cable_assembly_len = serial_id[consts.LENGTH_ASSEMBLY_FIELD]
32+
33+
len_types = ['Length(km)', 'Length OM3(2m)', 'Length OM2(m)', 'Length OM1(m)', 'Length Cable Assembly(m)']
34+
cable_len = 0
35+
cable_type = "Unknown"
36+
for len, type in zip([smf_len, om3_len, om2_len, om1_len, cable_assembly_len], len_types):
37+
if len > 0:
38+
cable_len = len
39+
cable_type = type
40+
41+
xcvr_info = {
42+
"type": serial_id[consts.ID_FIELD],
43+
"type_abbrv_name": serial_id[consts.ID_ABBRV_FIELD],
44+
"hardware_rev": serial_id[consts.VENDOR_REV_FIELD],
45+
"serial": serial_id[consts.VENDOR_SERIAL_NO_FIELD],
46+
"manufacturer": serial_id[consts.VENDOR_NAME_FIELD],
47+
"model": serial_id[consts.VENDOR_PART_NO_FIELD],
48+
"connector": serial_id[consts.CONNECTOR_FIELD],
49+
"encoding": serial_id[consts.ENCODING_FIELD],
50+
"ext_identifier": ", ".join([power_class, clei_code, cdr_tx, cdr_rx]),
51+
"ext_rateselect_compliance": serial_id[consts.EXT_RATE_SELECT_COMPLIANCE_FIELD],
52+
"cable_type": cable_type,
53+
"cable_length": cable_len,
54+
"nominal_bit_rate": serial_id[consts.NOMINAL_BR_FIELD],
55+
"specification_compliance": str(serial_id[consts.SPEC_COMPLIANCE_FIELD]),
56+
"vendor_date": serial_id[consts.VENDOR_DATE_FIELD],
57+
"vendor_oui": serial_id[consts.VENDOR_OUI_FIELD],
58+
"application_advertisement": "N/A",
59+
}
60+
61+
return xcvr_info
62+
63+
def get_transceiver_bulk_status(self):
64+
rx_los = self.get_rx_los()
65+
tx_fault = self.get_tx_fault()
66+
tx_disable = self.get_tx_disable()
67+
tx_disabled_channel = self.get_tx_disable_channel()
68+
temp = self.get_module_temperature()
69+
voltage = self.get_voltage()
70+
tx_bias = self.get_tx_bias()
71+
rx_power = self.get_rx_power()
72+
tx_power = self.get_tx_power()
73+
read_failed = rx_los is None or \
74+
tx_fault is None or \
75+
tx_disable is None or \
76+
tx_disabled_channel is None or \
77+
temp is None or \
78+
voltage is None or \
79+
tx_bias is None or \
80+
rx_power is None or \
81+
tx_power is None
82+
if read_failed:
83+
return None
84+
85+
bulk_status = {
86+
"rx_los": all(rx_los),
87+
"tx_fault": all(tx_fault),
88+
"tx_disable": all(tx_disable),
89+
"tx_disabled_channel": tx_disabled_channel,
90+
"temperature": temp,
91+
"voltage": voltage
92+
}
93+
94+
for i in range(1, self.NUM_CHANNELS + 1):
95+
bulk_status["tx%dbias" % i] = tx_bias[i - 1]
96+
bulk_status["rx%dpower" % i] = rx_power[i - 1]
97+
bulk_status["tx%dpower" % i] = tx_power[i - 1]
98+
99+
return bulk_status
100+
101+
def get_transceiver_threshold_info(self):
102+
threshold_info_keys = ['temphighalarm', 'temphighwarning',
103+
'templowalarm', 'templowwarning',
104+
'vcchighalarm', 'vcchighwarning',
105+
'vcclowalarm', 'vcclowwarning',
106+
'rxpowerhighalarm', 'rxpowerhighwarning',
107+
'rxpowerlowalarm', 'rxpowerlowwarning',
108+
'txpowerhighalarm', 'txpowerhighwarning',
109+
'txpowerlowalarm', 'txpowerlowwarning',
110+
'txbiashighalarm', 'txbiashighwarning',
111+
'txbiaslowalarm', 'txbiaslowwarning'
112+
]
113+
threshold_info_dict = dict.fromkeys(threshold_info_keys, 'N/A')
114+
flat_mem = self.is_flat_memory()
115+
if flat_mem is None:
116+
return None
117+
if flat_mem:
118+
return threshold_info_dict
119+
120+
temp_thresholds = self.xcvr_eeprom.read(consts.TEMP_THRESHOLDS_FIELD)
121+
voltage_thresholds = self.xcvr_eeprom.read(consts.VOLTAGE_THRESHOLDS_FIELD)
122+
rx_power_thresholds = self.xcvr_eeprom.read(consts.RX_POWER_THRESHOLDS_FIELD)
123+
tx_bias_thresholds = self.xcvr_eeprom.read(consts.TX_BIAS_THRESHOLDS_FIELD)
124+
read_failed = temp_thresholds is None or \
125+
voltage_thresholds is None or \
126+
rx_power_thresholds is None or \
127+
tx_bias_thresholds is None
128+
if read_failed:
129+
return None
130+
131+
for thresh in rx_power_thresholds:
132+
rx_power_thresholds[thresh] = self.mw_to_dbm(rx_power_thresholds[thresh])
133+
134+
return {
135+
"temphighalarm": float("{:.3f}".format(temp_thresholds[consts.TEMP_HIGH_ALARM_FIELD])),
136+
"templowalarm": float("{:.3f}".format(temp_thresholds[consts.TEMP_LOW_ALARM_FIELD])),
137+
"temphighwarning": float("{:.3f}".format(temp_thresholds[consts.TEMP_HIGH_WARNING_FIELD])),
138+
"templowwarning": float("{:.3f}".format(temp_thresholds[consts.TEMP_LOW_WARNING_FIELD])),
139+
"vcchighalarm": float("{:.3f}".format(voltage_thresholds[consts.VOLTAGE_HIGH_ALARM_FIELD])),
140+
"vcclowalarm": float("{:.3f}".format(voltage_thresholds[consts.VOLTAGE_LOW_ALARM_FIELD])),
141+
"vcchighwarning": float("{:.3f}".format(voltage_thresholds[consts.VOLTAGE_HIGH_WARNING_FIELD])),
142+
"vcclowwarning": float("{:.3f}".format(voltage_thresholds[consts.VOLTAGE_LOW_WARNING_FIELD])),
143+
"rxpowerhighalarm": float("{:.3f}".format(rx_power_thresholds[consts.RX_POWER_HIGH_ALARM_FIELD])),
144+
"rxpowerlowalarm": float("{:.3f}".format(rx_power_thresholds[consts.RX_POWER_LOW_ALARM_FIELD])),
145+
"rxpowerhighwarning": float("{:.3f}".format(rx_power_thresholds[consts.RX_POWER_HIGH_WARNING_FIELD])),
146+
"rxpowerlowwarning": float("{:.3f}".format(rx_power_thresholds[consts.RX_POWER_LOW_WARNING_FIELD])),
147+
"txpowerhighalarm": "N/A",
148+
"txpowerlowalarm": "N/A",
149+
"txpowerhighwarning": "N/A",
150+
"txpowerlowwarning": "N/A",
151+
"txbiashighalarm": float("{:.3f}".format(tx_bias_thresholds[consts.TX_BIAS_HIGH_ALARM_FIELD])),
152+
"txbiaslowalarm": float("{:.3f}".format(tx_bias_thresholds[consts.TX_BIAS_LOW_ALARM_FIELD])),
153+
"txbiashighwarning": float("{:.3f}".format(tx_bias_thresholds[consts.TX_BIAS_HIGH_WARNING_FIELD])),
154+
"txbiaslowwarning": float("{:.3f}".format(tx_bias_thresholds[consts.TX_BIAS_LOW_WARNING_FIELD]))
155+
}
156+
157+
def get_rx_los(self):
158+
rx_los = self.xcvr_eeprom.read(consts.RX_LOS_FIELD)
159+
if rx_los is None:
160+
return None
161+
return [bool(rx_los & (1 << i)) for i in range(self.NUM_CHANNELS)]
162+
163+
def get_tx_fault(self):
164+
tx_fault = self.xcvr_eeprom.read(consts.TX_FAULT_FIELD)
165+
if tx_fault is None:
166+
return None
167+
return [bool(tx_fault & (1 << i)) for i in range(self.NUM_CHANNELS)]
168+
169+
def get_tx_disable(self):
170+
tx_disable = self.xcvr_eeprom.read(consts.TX_DISABLE_FIELD)
171+
if tx_disable is None:
172+
return None
173+
return [bool(tx_disable & (1 << i)) for i in range(self.NUM_CHANNELS)]
174+
175+
def get_tx_disable_channel(self):
176+
return self.xcvr_eeprom.read(consts.TX_DISABLE_FIELD)
177+
178+
def get_module_temperature(self):
179+
temp = self.xcvr_eeprom.read(consts.TEMPERATURE_FIELD)
180+
if temp is None:
181+
return None
182+
return float("{:.3f}".format(temp))
183+
184+
def get_voltage(self):
185+
voltage = self.xcvr_eeprom.read(consts.VOLTAGE_FIELD)
186+
if voltage is None:
187+
return None
188+
return float("{:.3f}".format(voltage))
189+
190+
def get_tx_bias(self):
191+
tx_bias = self.xcvr_eeprom.read(consts.TX_BIAS_FIELD)
192+
if tx_bias is None:
193+
return None
194+
return [channel_bias for channel_bias in tx_bias.values()]
195+
196+
def get_rx_power(self):
197+
rx_power = self.xcvr_eeprom.read(consts.RX_POWER_FIELD)
198+
if rx_power is None:
199+
return None
200+
return [float("{:.3f}".format(channel_power)) for channel_power in rx_power.values()]
201+
202+
def get_tx_power(self):
203+
return ["N/A" for _ in range(self.NUM_CHANNELS)]
204+
205+
def tx_disable(self, tx_disable):
206+
val = 0xF if tx_disable else 0x0
207+
return self.xcvr_eeprom.write(consts.TX_DISABLE_FIELD, val)
208+
209+
def tx_disable_channel(self, channel, disable):
210+
channel_state = self.get_tx_disable_channel()
211+
if channel_state is None:
212+
return False
213+
214+
for i in range(self.NUM_CHANNELS):
215+
mask = (1 << i)
216+
if not (channel & mask):
217+
continue
218+
if disable:
219+
channel_state |= mask
220+
else:
221+
channel_state &= ~mask
222+
223+
return self.xcvr_eeprom.write(consts.TX_DISABLE_FIELD, channel_state)
224+
225+
def get_power_override(self):
226+
return self.xcvr_eeprom.read(consts.POWER_OVERRIDE_FIELD)
227+
228+
def set_power_override(self, power_override, power_set):
229+
ret = self.xcvr_eeprom.write(consts.POWER_OVERRIDE_FIELD, power_override)
230+
if power_override:
231+
ret &= self.xcvr_eeprom.write(consts.POWER_SET_FIELD, power_set)
232+
return ret
233+
234+
def is_flat_memory(self):
235+
return self.xcvr_eeprom.read(consts.FLAT_MEM_FIELD)
236+
237+
def get_tx_power_support(self):
238+
return False
239+
240+
def is_copper(self):
241+
eth_compliance = self.xcvr_eeprom.read(consts.ETHERNET_10_40G_COMPLIANCE_FIELD)
242+
if eth_compliance is None:
243+
return None
244+
return eth_compliance == "40GBASE-CR4"
245+
246+
def get_temperature_support(self):
247+
return True
248+
249+
def get_voltage_support(self):
250+
return True

0 commit comments

Comments
 (0)