Skip to content

Commit

Permalink
Add basic OSFP support for sfputil (sonic-net#20)
Browse files Browse the repository at this point in the history
Enable decode of QSFP-DD/OSFP transceivers, and vendor information.
  • Loading branch information
zzhiyuan authored and lguohan committed Feb 14, 2019
1 parent d4bf78c commit 2c09812
Show file tree
Hide file tree
Showing 5 changed files with 291 additions and 72 deletions.
149 changes: 149 additions & 0 deletions sonic_sfp/inf8628.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#! /usr/bin/env python
#----------------------------------------------------------------------------
# QSFP-DD 8X Transceiver (QSFP Double Density)
#----------------------------------------------------------------------------

from __future__ import print_function

try:
from sff8024 import type_of_transceiver
from sffbase import sffbase
except ImportError as e:
raise ImportError ("%s - required module not found" % e)

class inf8628InterfaceId(sffbase):

def decode_revision_compliance(self, eeprom_data, offset, size):
return '%c.%c' % (eeprom_data[offset][0], eeprom_data[offset][1])

def decode_module_state(self, eeprom_data, offset, size):
module_state_byte = eeprom_data[offset]
module_state = int(module_state_byte, 16) & 14
if module_state == 2:
return 'Low Power State'
elif module_state == 4:
return 'Power Up State'
elif module_state == 6:
return 'Ready State'
elif module_state == 8:
return 'Power Down State'
elif module_state == 10:
return 'Fault State'
return 'Unknown State %s' % module_state

version = '1.0'

interface_id = {
'Identifier':
{'offset': 0,
'size': 1,
'type': 'enum',
'decode': type_of_transceiver},
'Revision Compliance':
{'offset': 1,
'type': 'func',
'decode': {'func': decode_revision_compliance}},
'Module State':
{'offset': 3,
'type': 'func',
'decode': {'func': decode_module_state}},
'Interrupt Asserted':
{'offset': 3,
'bit': 0,
'type': 'bitvalue'},
'Vendor Name':
{'offset': 129,
'size': 16,
'type': 'str'},
'Vendor Part Number':
{'offset': 148,
'size': 16,
'type': 'str'},
'Vendor Revision':
{'offset': 164,
'size': 2,
'type': 'str'},
'Vendor Serial Number':
{'offset': 166,
'size': 16,
'type': 'str'},
}

sfp_type = {
'type':
{'offset': 0,
'size': 1,
'type': 'enum',
'decode': type_of_transceiver}
}

vendor_name = {
'Vendor Name':
{'offset': 0,
'size': 16,
'type': 'str'}
}

vendor_pn = {
'Vendor PN':
{'offset': 0,
'size': 16,
'type': 'str'}
}

vendor_rev = {
'Vendor Rev':
{'offset': 0,
'size': 2,
'type': 'str'}
}

vendor_sn = {
'Vendor SN':
{'offset': 0,
'size': 16,
'type': 'str'}
}

def __init__(self, eeprom_raw_data=None):
self.interface_data = None
start_pos = 0

if eeprom_raw_data is not None:
self.interface_data = sffbase.parse(self,
self.interface_id,
eeprom_raw_data,
start_pos)

def parse(self, eeprom_raw_data, start_pos):
return sffbase.parse(self, self.interface_id, eeprom_raw_data, start_pos)

def parse_sfp_type(self, type_raw_data, start_pos):
return sffbase.parse(self, self.sfp_type, type_raw_data, start_pos)

def parse_vendor_name(self, name_raw_data, start_pos):
return sffbase.parse(self, self.vendor_name, name_raw_data, start_pos)

def parse_vendor_rev(self, rev_raw_data, start_pos):
return sffbase.parse(self, self.vendor_rev, rev_raw_data, start_pos)

def parse_vendor_pn(self, pn_raw_data, start_pos):
return sffbase.parse(self, self.vendor_pn, pn_raw_data, start_pos)

def parse_vendor_sn(self, sn_raw_data, start_pos):
return sffbase.parse(self, self.vendor_sn, sn_raw_data, start_pos)

def dump_pretty(self):
if self.interface_data is None:
print('Object not initialized, nothing to print')
return
sffbase.dump_pretty(self, self.interface_data)

def get_calibration_type(self):
return self.calibration_type

def get_data(self):
return self.interface_data

def get_data_pretty(self):
return sffbase.get_data_pretty(self, self.interface_data)
36 changes: 36 additions & 0 deletions sonic_sfp/sff8024.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#! /usr/bin/env python
#----------------------------------------------------------------------------
# SFF-8024 Rev 4.5
#----------------------------------------------------------------------------

from __future__ import print_function

type_of_transceiver = {
'00': 'Unknown or unspecified',
'01': 'GBIC',
'02': 'Module/connector soldered to motherboard',
'03': 'SFP/SFP+/SFP28',
'04': '300 pin XBI',
'05': 'XENPAK',
'06': 'XFP',
'07': 'XFF',
'08': 'XFP-E',
'09': 'XPAK',
'0a': 'X2',
'0b': 'DWDM-SFP/SFP+',
'0c': 'QSFP',
'0d': 'QSFP+ or later',
'0e': 'CXP or later',
'0f': 'Shielded Mini Multilane HD 4X',
'10': 'Shielded Mini Multilane HD 8X',
'11': 'QSFP28 or later',
'12': 'CXP2 (aka CXP28) or later',
'13': 'CDFP (Style 1/Style2)',
'14': 'Shielded Mini Multilane HD 4X Fanout Cable',
'15': 'Shielded Mini Multilane HD 8X Fanout Cable',
'16': 'CDFP (Style 3)',
'17': 'microQSFP',
'18': 'QSFP-DD Double Density 8X Pluggable Transceiver',
'19': 'OSFP 8X Pluggable Transceiver',
'1a': 'SFP-DD Double Density 2X Pluggable Transceiver'
}
19 changes: 1 addition & 18 deletions sonic_sfp/sff8436.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import getopt
import types
from math import log10
from sff8024 import type_of_transceiver
from sffbase import sffbase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
Expand Down Expand Up @@ -185,24 +186,6 @@ class sff8436InterfaceId(sffbase):
{'offset': 9,
'bit': 0}}}}

type_of_transceiver = {
'00':'Unknown or unspecified',
'01':'GBIC',
'02': 'Module/connector soldered to motherboard',
'03': 'SFP',
'04': '300 pin XBI',
'05': 'XENPAK',
'06': 'XFP',
'07': 'XFF',
'08': 'XFP-E',
'09': 'XPAK',
'0a': 'X2',
'0b': 'DWDM-SFP',
'0c': 'QSFP',
'0d': 'QSFP+',
'11': 'QSFP28'
}

ext_type_of_transceiver = {
'00': 'Power Class 1(1.5W max)',
'04': 'Power Class 1(1.5W max), CDR present in Tx',
Expand Down
15 changes: 1 addition & 14 deletions sonic_sfp/sff8472.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import getopt
import types
from math import log10
from sff8024 import type_of_transceiver
from sffbase import sffbase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
Expand Down Expand Up @@ -258,20 +259,6 @@ class sff8472InterfaceId(sffbase):
{'offset': 10,
'bit': 0}}}}

type_of_transceiver = {'00':'Unknown',
'01':'GBIC',
'02': 'Module soldered to motherboard',
'03': 'SFP or SFP Plus',
'04': '300 pin XBI',
'05': 'XENPAK',
'06': 'XFP',
'07': 'XFF',
'08': 'XFP-E',
'09': 'XPAK',
'0a': 'X2',
'0b': 'DWDM-SFP',
'0d': 'QSFP'}

exttypeoftransceiver = {'00': 'GBIC def not specified',
'01':'GBIC is compliant with MOD_DEF 1',
'02':'GBIC is compliant with MOD_DEF 2',
Expand Down
Loading

0 comments on commit 2c09812

Please sign in to comment.