Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sfputil support for Ingrasys S9100 #929

Merged
merged 1 commit into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
250 changes: 236 additions & 14 deletions device/ingrasys/x86_64-ingrasys_s9100-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
#!/usr/bin/env python
# sfputil.py
#
# Platform-specific SFP transceiver interface for SONiC
#

try:
from sonic_sfp.sfputilbase import sfputilbase
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
import time
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))


class sfputil(sfputilbase):
"""Platform specific sfputil class"""
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""

port_start = 0
port_end = 31
ports_in_block = 32
PORT_START = 0
PORT_END = 31
PORTS_IN_BLOCK = 32

port_to_eeprom_mapping = {}
BASE_DIR_PATH = "/sys/class/gpio/gpio{0}/direction"
BASE_VAL_PATH = "/sys/class/gpio/gpio{0}/value"

_port_to_eeprom_mapping = {}
port_to_i2c_mapping = {
0: 11,
1: 10,
Expand Down Expand Up @@ -49,12 +56,227 @@ class sfputil(sfputilbase):
31: 40
}

_qsfp_ports = range(0, ports_in_block + 1)
abs_to_gpio_mapping = {
0: 241,
1: 240,
2: 243,
3: 242,
4: 245,
5: 244,
6: 247,
7: 246,
8: 249,
9: 248,
10: 251,
11: 250,
12: 253,
13: 252,
14: 255,
15: 254,
16: 225,
17: 224,
18: 227,
19: 226,
20: 229,
21: 228,
22: 231,
23: 230,
24: 233,
25: 232,
26: 235,
27: 234,
28: 237,
29: 236,
30: 239,
31: 238
}

lpmode_to_gpio_mapping = {
0: 177,
1: 176,
2: 179,
3: 178,
4: 181,
5: 180,
6: 183,
7: 182,
8: 185,
9: 184,
10: 187,
11: 186,
12: 189,
13: 188,
14: 191,
15: 190,
16: 161,
17: 160,
18: 163,
19: 162,
20: 165,
21: 164,
22: 167,
23: 166,
24: 169,
25: 168,
26: 171,
27: 170,
28: 173,
29: 172,
30: 175,
31: 174
}

reset_to_gpio_mapping = {
0: 145,
1: 144,
2: 147,
3: 146,
4: 149,
5: 148,
6: 151,
7: 150,
8: 153,
9: 152,
10: 155,
11: 154,
12: 157,
13: 156,
14: 159,
15: 158,
16: 129,
17: 128,
18: 131,
19: 130,
20: 133,
21: 132,
22: 135,
23: 134,
24: 137,
25: 136,
26: 139,
27: 138,
28: 141,
29: 140,
30: 143,
31: 142
}

@property
def port_start(self):
return self.PORT_START

@property
def port_end(self):
return self.PORT_END

@property
def qsfp_ports(self):
return range(0, self.PORTS_IN_BLOCK + 1)

def __init__(self, port_num):
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping

def __init__(self):
# Override port_to_eeprom_mapping for class initialization
eeprom_path = '/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom'
eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom"

for x in range(self.port_start, self.port_end + 1):
port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x])
self.port_to_eeprom_mapping[x] = port_eeprom_path
sfputilbase.__init__(self, port_num)

SfpUtilBase.__init__(self)

def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False

try:
abs_device_file = self.BASE_VAL_PATH.format(
self.abs_to_gpio_mapping[port_num])
val_file = open(abs_device_file)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

content = val_file.readline().rstrip()
val_file.close()

# content is a string, either "0" or "1"
if content == "1":
return True

return False

def get_low_power_mode(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False

try:
lpmode_val_device_file = self.BASE_VAL_PATH.format(
self.lpmode_to_gpio_mapping[port_num])
val_file = open(lpmode_val_device_file)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

content = val_file.readline().rstrip()
val_file.close()

# content is a string, either "0" or "1"
if content == "1":
return True

return False

def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False

try:
lpmode_val_device_file = self.BASE_VAL_PATH.format(
self.lpmode_to_gpio_mapping[port_num])
val_file = open(lpmode_val_device_file, "w")
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

val_file.write("1" if lpmode is True else "0")
val_file.close()

return True

def reset(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False

try:
reset_val_device_file = self.BASE_VAL_PATH.format(
self.reset_to_gpio_mapping[port_num])
val_file = open(reset_val_device_file, "w")
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

val_file.write("1")
val_file.close()

# Sleep 1 second to allow it to settle
time.sleep(1)

try:
reset_val_device_file = self.BASE_VAL_PATH.format(
self.reset_to_gpio_mapping[port_num])
val_file = open(reset_val_device_file, "w")
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

val_file.write("0")
val_file.close()

return True