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

Add support fpga drv and pimutility for minipack platform #3053

Merged
merged 20 commits into from
Aug 15, 2019
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
59 changes: 59 additions & 0 deletions device/accton/x86_64-accton_minipack-r0/plugins/led_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python
#
# led_control.py
#
# Platform-specific LED control functionality for SONiC
#

try:
from sonic_led.led_control_base import LedControlBase
import swsssdk
import threading
import os
import logging
import struct
import time
import syslog
from socket import *
from select import *
from minipack.pimutil import PimUtil
except ImportError, e:
raise ImportError(str(e) + " - required module not found")


class LedControl(LedControlBase):
"""Platform specific LED control class"""
SONIC_PORT_NAME_PREFIX = "Ethernet"


def __init__(self):
pim=PimUtil()
pim.init_pim_fpga()

def _port_name_to_index(self, port_name):
# Strip "Ethernet" off port name
if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX):
return -1

port_idx = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):])
return port_idx

def _port_state_to_mode(self, port_idx, state):
if state == "up":
return 1, 4 #port linkup, led is green
else:
return 0, 0 #port linkdown, led is off

def port_link_state_change(self, portname, state):
pim=PimUtil()
port_idx = self._port_name_to_index(portname)
new_control, led_mode = self._port_state_to_mode(port_idx, state)
color, control=pim.get_port_led(port_idx)

if color==led_mode:
if control==new_control:
return

pim.set_port_led(port_idx, led_mode, new_control)#port linkup, led is green
#port linkdown, led is off

104 changes: 78 additions & 26 deletions device/accton/x86_64-accton_minipack-r0/plugins/sfputil.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
try:
import time
from sonic_sfp.sfputilbase import SfpUtilBase
import os
import sys, getopt
from minipack.pimutil import PimUtil
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))

Expand All @@ -16,7 +19,7 @@ class SfpUtil(SfpUtilBase):
PORT_START = 0
PORT_END = 128

BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/"
LOCAL_OOM_PATH = "/usr/local/bin/minipack_qsfp/port%d_eeprom"

_port_to_is_present = {}
_port_to_lp_mode = {}
Expand Down Expand Up @@ -53,42 +56,91 @@ def sfp_map(self, index):


def __init__(self):
eeprom_path = self.BASE_OOM_PATH + "eeprom"

for x in range(0, self.port_end+1):
bus = self.sfp_map(x)
self.port_to_eeprom_mapping[x] = eeprom_path.format(
bus)
for x in range(0, self.port_end):
self.port_to_eeprom_mapping[x] = self.LOCAL_OOM_PATH %x

SfpUtilBase.__init__(self)
pim=PimUtil()
pim.init_pim_fpga()

def __del__(self):
self.value=0

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

eeprom_path = self.port_to_eeprom_mapping[port_num]
with open(eeprom_path) as f:
try:
content = f.read(1)
except IOError as e:
#Not print any error, for if any, treat as Not present.
return False
return True

pim=PimUtil()
status=pim.get_qsfp_presence(port_num)
return status

def get_low_power_mode(self, port_num):
raise NotImplementedError
if port_num < self.port_start or port_num > self.port_end:
return False

pim=PimUtil()
return pim.get_low_power_mode(port_num)

def set_low_power_mode(self, port_num, lpmode):
raise NotImplementedError
if port_num < self.port_start or port_num > self.port_end:
return False
pim=PimUtil()
pim.set_low_power_mode(port_num, lpmode)
return True

def reset(self, port_num):
raise NotImplementedError
if port_num < self.port_start or port_num > self.port_end:
return False
pim=PimUtil()
pim.reset(port_num)
return True

def get_transceiver_change_event(self, timeout=0):
jostar-yang marked this conversation as resolved.
Show resolved Hide resolved
pim=PimUtil()
start_time = time.time()
port_dict = {}
forever = False

def get_transceiver_change_event(self):
"""
TODO: This function need to be implemented
when decide to support monitoring SFP(Xcvrd)
on this platform.
"""
raise NotImplementedError
if timeout == 0:
forever = True
elif timeout > 0:
timeout = timeout / float(1000) # Convert to secs
else:
print "get_transceiver_change_event:Invalid timeout value", timeout
return False, {}

end_time = start_time + timeout
if start_time > end_time:
print 'get_transceiver_change_event:' \
'time wrap / invalid timeout value', timeout

return False, {} # Time wrap or possibly incorrect timeout

while timeout >= 0:
change_status=0
port_dict = pim.get_qsfp_interrupt()
present=0
for key, value in port_dict.iteritems():
if value==1:
present=self.get_presence(key)
change_status=1
if present:
port_dict[key]='1'
else:
port_dict[key]='0'

if change_status:
return True, port_dict
if forever:
time.sleep(1)
else:
timeout = end_time - time.time()
if timeout >= 1:
time.sleep(1) # We poll at 1 second granularity
else:
if timeout > 0:
time.sleep(timeout)
return True, {}
print "get_evt_change_event: Should not reach here."
return False, {}
Loading