Skip to content

Commit 07e75bc

Browse files
[sfp-refactor] Add initial support for SFF-8472 in sonic_xcvr (#223)
* Implement SFF-8472 * Remove duplicate cmis module monitors field * Fix TestDateField * Fix rx power and tx power scale * Add tests * Add FixedNumberRegField, enhance sff8472 tests
1 parent ab59735 commit 07e75bc

File tree

13 files changed

+994
-26
lines changed

13 files changed

+994
-26
lines changed

sonic_platform_base/sonic_xcvr/api/public/cmis.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
"""
23
cmis.py
34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
"""
2+
sff8472.py
3+
4+
Implementation of XcvrApi that corresponds to the SFF-8472 specification for
5+
SFP+ pluggable transceivers.
6+
"""
7+
from ...fields import consts
8+
from ..xcvr_api import XcvrApi
9+
10+
class Sff8472Api(XcvrApi):
11+
NUM_CHANNELS = 1
12+
13+
def __init__(self, xcvr_eeprom):
14+
super(Sff8472Api, self).__init__(xcvr_eeprom)
15+
16+
def get_model(self):
17+
return self.xcvr_eeprom.read(consts.VENDOR_PART_NO_FIELD)
18+
19+
def get_serial(self):
20+
return self.xcvr_eeprom.read(consts.VENDOR_SERIAL_NO_FIELD)
21+
22+
def get_transceiver_info(self):
23+
serial_id = self.xcvr_eeprom.read(consts.SERIAL_ID_FIELD)
24+
if serial_id is None:
25+
return None
26+
smf_km_len = serial_id[consts.LENGTH_SMF_KM_FIELD]
27+
smf_m_len = serial_id[consts.LENGTH_SMF_M_FIELD]
28+
om4_len = serial_id[consts.LENGTH_OM4_FIELD]
29+
om3_len = serial_id[consts.LENGTH_OM3_FIELD]
30+
om2_len = serial_id[consts.LENGTH_OM2_FIELD]
31+
om1_len = serial_id[consts.LENGTH_OM1_FIELD]
32+
33+
len_types = ["Length SMF (km)", "Length SMF (100m)", "Length OM2 (10m)", "Length OM1(10m)", "Length OM4(10m)", "Length OM3(10m)"]
34+
cable_len = 0
35+
cable_type = None
36+
for len, type in zip([smf_km_len, smf_m_len, om2_len, om1_len, om4_len, om3_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": serial_id[consts.EXT_ID_FIELD],
51+
"ext_rateselect_compliance": serial_id[consts.RATE_ID_FIELD],
52+
"cable_type": cable_type,
53+
"cable_length": float(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) if self.get_rx_los_support() else 'N/A',
87+
"tx_fault": all(tx_fault) if self.get_tx_fault_support() else 'N/A',
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+
# Added to avoid failing xcvrd. Ideally xcvrd should be fixed so that this is not necessary
100+
for i in range(2, 5):
101+
bulk_status["tx%dbias" % i] = 'N/A'
102+
bulk_status["rx%dpower" % i] = 'N/A'
103+
bulk_status["tx%dpower" % i] = 'N/A'
104+
105+
return bulk_status
106+
107+
def get_transceiver_threshold_info(self):
108+
threshold_info_keys = ['temphighalarm', 'temphighwarning',
109+
'templowalarm', 'templowwarning',
110+
'vcchighalarm', 'vcchighwarning',
111+
'vcclowalarm', 'vcclowwarning',
112+
'rxpowerhighalarm', 'rxpowerhighwarning',
113+
'rxpowerlowalarm', 'rxpowerlowwarning',
114+
'txpowerhighalarm', 'txpowerhighwarning',
115+
'txpowerlowalarm', 'txpowerlowwarning',
116+
'txbiashighalarm', 'txbiashighwarning',
117+
'txbiaslowalarm', 'txbiaslowwarning'
118+
]
119+
threshold_info_dict = dict.fromkeys(threshold_info_keys, 'N/A')
120+
thresh_support = self.get_transceiver_thresholds_support()
121+
if thresh_support is None:
122+
return None
123+
if not thresh_support:
124+
return threshold_info_dict
125+
thresholds = self.xcvr_eeprom.read(consts.THRESHOLDS_FIELD)
126+
if thresholds is None:
127+
return threshold_info_dict
128+
129+
return {
130+
"temphighalarm": float("{:.3f}".format(thresholds[consts.TEMP_HIGH_ALARM_FIELD])),
131+
"templowalarm": float("{:.3f}".format(thresholds[consts.TEMP_LOW_ALARM_FIELD])),
132+
"temphighwarning": float("{:.3f}".format(thresholds[consts.TEMP_HIGH_WARNING_FIELD])),
133+
"templowwarning": float("{:.3f}".format(thresholds[consts.TEMP_LOW_WARNING_FIELD])),
134+
"vcchighalarm": float("{:.3f}".format(thresholds[consts.VOLTAGE_HIGH_ALARM_FIELD])),
135+
"vcclowalarm": float("{:.3f}".format(thresholds[consts.VOLTAGE_LOW_ALARM_FIELD])),
136+
"vcchighwarning": float("{:.3f}".format(thresholds[consts.VOLTAGE_HIGH_WARNING_FIELD])),
137+
"vcclowwarning": float("{:.3f}".format(thresholds[consts.VOLTAGE_LOW_WARNING_FIELD])),
138+
"rxpowerhighalarm": float("{:.3f}".format(self.mw_to_dbm(thresholds[consts.RX_POWER_HIGH_ALARM_FIELD]))),
139+
"rxpowerlowalarm": float("{:.3f}".format(self.mw_to_dbm(thresholds[consts.RX_POWER_LOW_ALARM_FIELD]))),
140+
"rxpowerhighwarning": float("{:.3f}".format(self.mw_to_dbm(thresholds[consts.RX_POWER_HIGH_WARNING_FIELD]))),
141+
"rxpowerlowwarning": float("{:.3f}".format(self.mw_to_dbm(thresholds[consts.RX_POWER_LOW_WARNING_FIELD]))),
142+
"txpowerhighalarm": float("{:.3f}".format(self.mw_to_dbm(thresholds[consts.TX_POWER_HIGH_ALARM_FIELD]))),
143+
"txpowerlowalarm": float("{:.3f}".format(self.mw_to_dbm(thresholds[consts.TX_POWER_LOW_ALARM_FIELD]))),
144+
"txpowerhighwarning": float("{:.3f}".format(self.mw_to_dbm(thresholds[consts.TX_POWER_HIGH_WARNING_FIELD]))),
145+
"txpowerlowwarning": float("{:.3f}".format(self.mw_to_dbm(thresholds[consts.TX_POWER_LOW_WARNING_FIELD]))),
146+
"txbiashighalarm": float("{:.3f}".format(thresholds[consts.TX_BIAS_HIGH_ALARM_FIELD])),
147+
"txbiaslowalarm": float("{:.3f}".format(thresholds[consts.TX_BIAS_LOW_ALARM_FIELD])),
148+
"txbiashighwarning": float("{:.3f}".format(thresholds[consts.TX_BIAS_HIGH_WARNING_FIELD])),
149+
"txbiaslowwarning": float("{:.3f}".format(thresholds[consts.TX_BIAS_LOW_WARNING_FIELD]))
150+
}
151+
152+
def get_rx_los(self):
153+
rx_los_support = self.get_rx_los_support()
154+
if rx_los_support is None:
155+
return None
156+
if not rx_los_support:
157+
return ["N/A"]
158+
rx_los = self.xcvr_eeprom.read(consts.RX_LOS_FIELD)
159+
if rx_los is None:
160+
return None
161+
return [rx_los]
162+
163+
def get_tx_fault(self):
164+
tx_fault_support = self.get_tx_fault_support()
165+
if tx_fault_support is None:
166+
return None
167+
if not tx_fault_support:
168+
return ["N/A"]
169+
tx_fault = self.xcvr_eeprom.read(consts.TX_FAULT_FIELD)
170+
if tx_fault is None:
171+
return None
172+
return [tx_fault]
173+
174+
def get_tx_disable(self):
175+
tx_disable_support = self.get_tx_disable_support()
176+
if tx_disable_support is None:
177+
return None
178+
if not tx_disable_support:
179+
return ["N/A"]
180+
tx_disable = self.xcvr_eeprom.read(consts.TX_DISABLE_FIELD)
181+
tx_disable_select = self.xcvr_eeprom.read(consts.TX_DISABLE_SELECT_FIELD)
182+
if tx_disable is None or tx_disable_select is None:
183+
return None
184+
return [tx_disable or tx_disable_select]
185+
186+
def get_tx_disable_channel(self):
187+
tx_disable_list = self.get_tx_disable()
188+
if tx_disable_list is None:
189+
return None
190+
if tx_disable_list[0] == "N/A":
191+
return "N/A"
192+
return int(tx_disable_list[0])
193+
194+
def get_module_temperature(self):
195+
if not self.get_temperature_support():
196+
return 'N/A'
197+
temp = self.xcvr_eeprom.read(consts.TEMPERATURE_FIELD)
198+
if temp is None:
199+
return None
200+
return float("{:.3f}".format(temp))
201+
202+
def get_voltage(self):
203+
voltage_support = self.get_voltage_support()
204+
if voltage_support is None:
205+
return None
206+
if not voltage_support:
207+
return 'N/A'
208+
voltage = self.xcvr_eeprom.read(consts.VOLTAGE_FIELD)
209+
if voltage is None:
210+
return None
211+
return float("{:.3f}".format(voltage))
212+
213+
def get_tx_bias(self):
214+
tx_bias_support = self.get_tx_bias_support()
215+
if tx_bias_support is None:
216+
return None
217+
if not tx_bias_support:
218+
return ["N/A"]
219+
tx_bias = self.xcvr_eeprom.read(consts.TX_BIAS_FIELD)
220+
if tx_bias is None:
221+
return None
222+
return [float("{:.3f}".format(tx_bias))]
223+
224+
def get_rx_power(self):
225+
rx_power_support = self.get_rx_power_support()
226+
if rx_power_support is None:
227+
return None
228+
if not rx_power_support:
229+
return ["N/A"]
230+
rx_power = self.xcvr_eeprom.read(consts.RX_POWER_FIELD)
231+
if rx_power is None:
232+
return None
233+
return [float("{:.3f}".format(rx_power))]
234+
235+
def get_tx_power(self):
236+
tx_power_support = self.get_tx_power_support()
237+
if tx_power_support is None:
238+
return None
239+
if not tx_power_support:
240+
return ["N/A"]
241+
tx_power = self.xcvr_eeprom.read(consts.TX_POWER_FIELD)
242+
if tx_power is None:
243+
return None
244+
return [float("{:.3f}".format(tx_power))]
245+
246+
def tx_disable(self, tx_disable):
247+
return self.xcvr_eeprom.write(consts.TX_DISABLE_SELECT_FIELD, tx_disable)
248+
249+
def tx_disable_channel(self, channel, disable):
250+
channel_state = self.get_tx_disable_channel()
251+
if channel_state is None or channel_state == "N/A":
252+
return False
253+
254+
for i in range(self.NUM_CHANNELS):
255+
mask = (1 << i)
256+
if not (channel & mask):
257+
continue
258+
if disable:
259+
channel_state |= mask
260+
else:
261+
channel_state &= ~mask
262+
263+
return self.xcvr_eeprom.write(consts.TX_DISABLE_FIELD, channel_state)
264+
265+
def is_flat_memory(self):
266+
return not self.xcvr_eeprom.read(consts.PAGING_SUPPORT_FIELD)
267+
268+
def get_temperature_support(self):
269+
return self.xcvr_eeprom.read(consts.DDM_SUPPORT_FIELD)
270+
271+
def get_voltage_support(self):
272+
return self.xcvr_eeprom.read(consts.DDM_SUPPORT_FIELD)
273+
274+
def get_tx_power_support(self):
275+
return self.xcvr_eeprom.read(consts.DDM_SUPPORT_FIELD)
276+
277+
def get_rx_power_support(self):
278+
return self.xcvr_eeprom.read(consts.DDM_SUPPORT_FIELD)
279+
280+
def get_rx_los_support(self):
281+
return self.xcvr_eeprom.read(consts.RX_LOS_SUPPORT_FIELD)
282+
283+
def get_tx_bias_support(self):
284+
return self.xcvr_eeprom.read(consts.DDM_SUPPORT_FIELD)
285+
286+
def get_tx_fault_support(self):
287+
return self.xcvr_eeprom.read(consts.TX_FAULT_SUPPORT_FIELD)
288+
289+
def get_tx_disable_support(self):
290+
return self.xcvr_eeprom.read(consts.TX_DISABLE_SUPPORT_FIELD)
291+
292+
def get_transceiver_thresholds_support(self):
293+
return self.xcvr_eeprom.read(consts.DDM_SUPPORT_FIELD)
294+
295+
def get_lpmode_support(self):
296+
return False
297+
298+
def get_power_override_support(self):
299+
return False

0 commit comments

Comments
 (0)