Skip to content

Commit

Permalink
[device/celestica]: Implement Questone2BD platform API version 1.0 (#149
Browse files Browse the repository at this point in the history
)

* add questone2bd sensor config
* add questone2bd sonic_platform api
* add questone2bd sonic_platform api installer
* update questone2bd api to skip exception
* fix psu api/sensor
* fix psu i2c on fan api
  • Loading branch information
Wirut Getbamrung committed Apr 13, 2020
1 parent 4db1379 commit 191f978
Show file tree
Hide file tree
Showing 15 changed files with 3,134 additions and 1 deletion.
86 changes: 86 additions & 0 deletions device/celestica/x86_64-cel_questone2bd-r0/sensors.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
chip "syscpld-i2c-*-0d"
label temp1 "Switch temp"
set temp1_max_hyst 98
set temp1_max 104
ignore temp2

chip "fancpld-i2c-*-0d"
label fan1 "Fan 4 Front"
label fan2 "Fan 4 Rear"
label fan3 "Fan 3 Front"
label fan4 "Fan 3 Rear"
label fan5 "Fan 2 Front"
label fan6 "Fan 2 Rear"
label fan7 "Fan 1 Front"
label fan8 "Fan 1 Rear"
set fan1_min 1000
set fan1_max 27170
set fan2_min 1000
set fan2_max 32670
set fan3_min 1000
set fan3_max 27170
set fan4_min 1000
set fan4_max 32670
set fan5_min 1000
set fan5_max 27170
set fan6_min 1000
set fan6_max 32670
set fan7_min 1000
set fan7_max 27170
set fan8_min 1000
set fan8_max 32670
ignore fan9
ignore fan10

chip "lm75b-i2c-*-4d"
compute temp1 @+(0), @/(0)

chip "lm75b-i2c-*-48"
set temp1_max 70
set temp1_max_hyst 60

chip "dps1100-i2c-*-58"
set in1_min 90
set in1_max 264
set in2_min 10.8
set in2_max 13.2
set fan1_min 1000
set fan1_max 30000
set temp1_max_hyst 60
set temp1_max 70
set temp2_max_hyst 60
set temp2_max 70
set power1_max 1222
set power2_max 1100
set curr1_min 0
set curr1_max 7
set curr2_min 0
set curr2_max 90

chip "dps1100-i2c-*-59"
set in1_min 90
set in1_max 264
set in2_min 10.8
set in2_max 13.2
set fan1_min 1000
set fan1_max 30000
set temp1_max_hyst 60
set temp1_max 70
set temp2_max_hyst 60
set temp2_max 70
set power1_max 1222
set power2_max 1100
set curr1_min 0
set curr1_max 7
set curr2_min 0
set curr2_max 90

# chip "ir38060-i2c-*-43"

# chip "ir38062-i2c-*-49"

# chip "ir3595-i2c-*-12"

# chip "ir38060-i2c-*-47"

# chip "ir3584-i2c-*-70"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__all__ = ["platform", "chassis"]
from sonic_platform import *
213 changes: 213 additions & 0 deletions device/celestica/x86_64-cel_questone2bd-r0/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#!/usr/bin/env python

#############################################################################
# Celestica
#
# Module contains an implementation of SONiC Platform Base API and
# provides the Chassis information which are available in the platform
#
#############################################################################

try:
import sys
import re
import os
import subprocess
import json
from sonic_platform_base.chassis_base import ChassisBase
from sonic_platform.component import Component
from sonic_platform.eeprom import Eeprom
from sonic_platform.fan import Fan
from sonic_platform.sfp import Sfp
from sonic_platform.psu import Psu
from sonic_platform.thermal import Thermal
from helper import APIHelper
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

NUM_FAN_TRAY = 4
NUM_FAN = 2
NUM_PSU = 2
NUM_THERMAL = 12
NUM_SFP = 56
NUM_COMPONENT = 7
REBOOT_CAUSE_REG = "0xA106"
TLV_EEPROM_I2C_BUS = 0
TLV_EEPROM_I2C_ADDR = 56

BASE_CPLD_PLATFORM = "questone2bd.cpldb"
BASE_GETREG_PATH = "/sys/devices/platform/{}/getreg".format(BASE_CPLD_PLATFORM)


class Chassis(ChassisBase):
"""Platform-specific Chassis class"""

def __init__(self):
ChassisBase.__init__(self)
self._eeprom = Eeprom(TLV_EEPROM_I2C_BUS, TLV_EEPROM_I2C_ADDR)
self._api_helper = APIHelper()

for index in range(0, NUM_PSU):
psu = Psu(index)
self._psu_list.append(psu)

for fant_index in range(0, NUM_FAN_TRAY):
for fan_index in range(0, NUM_FAN):
fan = Fan(fant_index, fan_index)
self._fan_list.append(fan)

for index in range(0, NUM_SFP):
sfp = Sfp(index)
self._sfp_list.append(sfp)

for index in range(0, NUM_COMPONENT):
component = Component(index)
self._component_list.append(component)

for index in range(0, NUM_THERMAL):
thermal = Thermal(index)
self._thermal_list.append(thermal)

def get_base_mac(self):
"""
Retrieves the base MAC address for the chassis
Returns:
A string containing the MAC address in the format
'XX:XX:XX:XX:XX:XX'
"""
return self._eeprom.get_mac()

def get_serial_number(self):
"""
Retrieves the hardware serial number for the chassis
Returns:
A string containing the hardware serial number for this chassis.
"""
return self._eeprom.get_serial()

def get_system_eeprom_info(self):
"""
Retrieves the full content of system EEPROM information for the chassis
Returns:
A dictionary where keys are the type code defined in
OCP ONIE TlvInfo EEPROM format and values are their corresponding
values.
"""
return self._eeprom.get_eeprom()

def get_reboot_cause(self):
"""
Retrieves the cause of the previous reboot
Returns:
A tuple (string, string) where the first element is a string
containing the cause of the previous reboot. This string must be
one of the predefined strings in this class. If the first string
is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
to pass a description of the reboot cause.
"""

raw_cause = self._api_helper.get_register_value(
BASE_GETREG_PATH, REBOOT_CAUSE_REG)
hx_cause = raw_cause.lower()
reboot_cause = {
"0x00": self.REBOOT_CAUSE_HARDWARE_OTHER,
"0x11": self.REBOOT_CAUSE_POWER_LOSS,
"0x22": self.REBOOT_CAUSE_NON_HARDWARE,
"0x33": self.REBOOT_CAUSE_HARDWARE_OTHER,
"0x44": self.REBOOT_CAUSE_NON_HARDWARE,
"0x55": self.REBOOT_CAUSE_NON_HARDWARE,
"0x66": self.REBOOT_CAUSE_WATCHDOG,
"0x77": self.REBOOT_CAUSE_NON_HARDWARE
}.get(hx_cause, self.REBOOT_CAUSE_HARDWARE_OTHER)

description = {
"0x00": "Unknown reason",
"0x11": "The last reset is Power on reset",
"0x22": "The last reset is soft-set CPU warm reset",
"0x33": "The last reset is soft-set CPU cold reset",
"0x44": "The last reset is CPU warm reset",
"0x55": "The last reset is CPU cold reset",
"0x66": "The last reset is watchdog reset",
"0x77": "The last reset is power cycle reset"
}.get(hx_cause, "Unknown reason")

return (reboot_cause, description)

def get_sfp(self, index):
"""
Retrieves sfp represented by (1-based) index <index>
Args:
index: An integer, the index (1-based) of the sfp to retrieve.
The index should be the sequence of a physical port in a chassis,
starting from 1.
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
Returns:
An object dervied from SfpBase representing the specified sfp
"""
sfp = None

try:
# The index will start from 1
sfp = self._sfp_list[index-1]
except IndexError:
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list)))
return sfp

def get_watchdog(self):
"""
Retreives hardware watchdog device on this chassis
Returns:
An object derived from WatchdogBase representing the hardware
watchdog device
"""
if self._watchdog is None:
from sonic_platform.watchdog import Watchdog
self._watchdog = Watchdog()

return self._watchdog

##############################################################
###################### Device methods ########################
##############################################################

def get_name(self):
"""
Retrieves the name of the device
Returns:
string: The name of the device
"""
return self._eeprom.get_product()

def get_presence(self):
"""
Retrieves the presence of the PSU
Returns:
bool: True if PSU is present, False if not
"""
return True

def get_model(self):
"""
Retrieves the model number (or part number) of the device
Returns:
string: Model/part number of device
"""
return self._eeprom.get_pn()

def get_serial(self):
"""
Retrieves the serial number of the device
Returns:
string: Serial number of device
"""
return self.get_serial_number()

def get_status(self):
"""
Retrieves the operational status of the device
Returns:
A boolean value, True if device is operating properly, False if not
"""
return True
Loading

0 comments on commit 191f978

Please sign in to comment.