Skip to content
Closed
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
66 changes: 66 additions & 0 deletions device/accton/x86_64-accton_as9716_32d-r0/pddf/pd-plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{

"XCVR":
{
"xcvr_present":
{
"i2c":
{
"valmap-SFP28": {"1":true, "0":false },
"valmap-QSFP28": {"1":true, "0":false}
}
}
},
"PSU":
{
"psu_present":
{
"i2c":
{
"valmap": { "1":true, "0":false }
}
},

"psu_power_good":
{
"i2c":
{
"valmap": { "1": true, "0":false }
}
},

"psu_fan_dir":
{
"i2c":
{
"valmap": { "F2B":"EXHAUST", "B2F":"INTAKE" }
}
},

"PSU_FAN_MAX_SPEED":"18000"
},

"FAN":
{
"direction":
{
"i2c":
{
"valmap": {"1":"INTAKE", "0":"EXHAUST"}
}
},

"present":
{
"i2c":
{
"valmap": {"1":true, "0":false}
}
},

"duty_cycle_to_pwm": "lambda dc: ((dc*100)/625 - 1)",

"pwm_to_duty_cycle": "lambda pwm: (((pwm+1)*625)/100)"
}

}
1,939 changes: 1,939 additions & 0 deletions device/accton/x86_64-accton_as9716_32d-r0/pddf/pddf-device.json

Large diffs are not rendered by default.

Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ifneq ($(KERNELRELEASE),)
obj-m:= accton_as9716_32d_cpld.o accton_as9716_32d_fan.o \
accton_as9716_32d_leds.o accton_as9716_32d_psu.o accton_i2c_psu.o
accton_as9716_32d_leds.o accton_as9716_32d_psu.o accton_i2c_psu.o \
pddf_custom_psu.o

else
ifeq (,$(KERNEL_SRC))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#include <linux/module.h>
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/delay.h>
#include <linux/mutex.h>
#include <linux/sysfs.h>
#include <linux/slab.h>
#include <linux/dmi.h>
#include "../../../../pddf/i2c/modules/include/pddf_psu_defs.h"

ssize_t pddf_show_custom_psu_v_out(struct device *dev, struct device_attribute *da, char *buf);
extern PSU_SYSFS_ATTR_DATA access_psu_v_out;

static int two_complement_to_int(u16 data, u8 valid_bit, int mask)
{
u16 valid_data = data & mask;
bool is_negative = valid_data >> (valid_bit - 1);

return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data;
}

static u8 psu_get_vout_mode(struct i2c_client *client)
{
u8 status = 0, retry = 10;
uint8_t offset = 0x20; // VOUT_MODE

while (retry) {
status = i2c_smbus_read_byte_data((struct i2c_client *)client, offset);
if (unlikely(status < 0)) {
msleep(60);
retry--;
continue;
}
break;
}

if (status < 0)
{
printk(KERN_ERR "%s: Get PSU Vout mode failed\n", __func__);
return 0;
}
else
{
/*printk(KERN_ERR "%s: vout_mode reg value 0x%x\n", __func__, status);*/
return status;
}
}

static u16 psu_get_v_out(struct i2c_client *client)
{
u16 status = 0, retry = 10;
uint8_t offset = 0x8b; // READ_VOUT

while (retry) {
status = i2c_smbus_read_word_data((struct i2c_client *)client, offset);
if (unlikely(status < 0)) {
msleep(60);
retry--;
continue;
}
break;
}

if (status < 0)
{
printk(KERN_ERR "%s: Get PSU Vout failed\n", __func__);
return 0;
}
else
{
/*printk(KERN_ERR "%s: vout reg value 0x%x\n", __func__, status);*/
return status;
}
}

ssize_t pddf_show_custom_psu_v_out(struct device *dev, struct device_attribute *da, char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
int exponent, mantissa;
int multiplier = 1000;

u16 value = psu_get_v_out(client);
u8 vout_mode = psu_get_vout_mode(client);

if ((vout_mode >> 5) == 0)
exponent = two_complement_to_int(vout_mode & 0x1f, 5, 0x1f);
else
{
printk(KERN_ERR "%s: Only support linear mode for vout mode\n", __func__);
exponent = 0;
}
mantissa = value;
if (exponent >= 0)
return sprintf(buf, "%d\n", (mantissa << exponent) * multiplier);
else
return sprintf(buf, "%d\n", (mantissa * multiplier) / (1 << -exponent));
}



static int __init pddf_custom_psu_init(void)
{
access_psu_v_out.show = pddf_show_custom_psu_v_out;
access_psu_v_out.do_get = NULL;
printk(KERN_ERR "pddf_custom_psu_init\n");
return 0;
}

static void __exit pddf_custom_psu_exit(void)
{
printk(KERN_ERR "pddf_custom_psu_exit\n");
return;
}

MODULE_AUTHOR("Broadcom");
MODULE_DESCRIPTION("pddf custom psu api");
MODULE_LICENSE("GPL");

module_init(pddf_custom_psu_init);
module_exit(pddf_custom_psu_exit);

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Accton AS9716-32D Platform Monitoring service
Before=pmon.service
After=pddf-platform-init.service
DefaultDependencies=no

[Service]
ExecStart=/usr/local/bin/accton_as9716_32d_pddf_monitor.py
KillSignal=SIGKILL
SuccessExitStatus=SIGKILL

# Resource Limitations
LimitCORE=infinity

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# All the derived classes for PDDF
__all__ = ["platform", "chassis", "sfp", "psu", "thermal"]
import platform
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python

#############################################################################
# PDDF
# Module contains an implementation of SONiC Chassis API
#
#############################################################################

try:
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

class Chassis(PddfChassis):
"""
PDDF Platform-specific Chassis class
"""

def __init__(self, pddf_data=None, pddf_plugin_data=None):
PddfChassis.__init__(self, pddf_data, pddf_plugin_data)

# Provide the functions/variables below for which implementation is to be overwritten
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python

try:
from sonic_platform_pddf_base.pddf_eeprom import PddfEeprom
except ImportError, e:
raise ImportError(str(e) + "- required module not found")


class Eeprom(PddfEeprom):

def __init__(self, pddf_data=None, pddf_plugin_data=None):
PddfEeprom.__init__(self, pddf_data, pddf_plugin_data)

# Provide the functions/variables below for which implementation is to be overwritten
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python


try:
from sonic_platform_pddf_base.pddf_fan import PddfFan
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


class Fan(PddfFan):
"""PDDF Platform-Specific Fan class"""

def __init__(self, tray_idx, fan_idx=0, pddf_data=None, pddf_plugin_data=None, is_psu_fan=False, psu_index=0):
# idx is 0-based
PddfFan.__init__(self, tray_idx, fan_idx, pddf_data, pddf_plugin_data, is_psu_fan, psu_index)

# Provide the functions/variables below for which implementation is to be overwritten
# Since psu_fan airflow direction cant be read from sysfs, it is fixed as 'F2B' or 'intake'
def get_direction(self):
"""
Retrieves the direction of fan

Returns:
A string, either FAN_DIRECTION_INTAKE or FAN_DIRECTION_EXHAUST
depending on fan direction
"""
if self.is_psu_fan:
direction = self.FAN_DIRECTION_INTAKE

else:
idx = (self.fantray_index-1)*self.platform['num_fans_pertray'] + self.fan_index
attr = "fan" + str(idx) + "_direction"
output = self.pddf_obj.get_attr_name_output("FAN-CTRL", attr)
if not output:
return False

mode = output['mode']
val = output['status']

val = val.rstrip()
vmap = self.plugin_data['FAN']['direction'][mode]['valmap']
if val in vmap:
direction = vmap[val]
else:
direction = val

return direction

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python

#############################################################################
# PDDF
# Module contains an implementation of SONiC Platform Base API and
# provides the platform information
#
#############################################################################


try:
from sonic_platform_pddf_base.pddf_platform import PddfPlatform
except ImportError as e:
raise ImportError(str(e) + "- required module not found")


class Platform(PddfPlatform):
"""
PDDF Platform-Specific Platform Class
"""

def __init__(self):
PddfPlatform.__init__(self)

# Provide the functions/variables below for which implementation is to be overwritten
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python
#


try:
from sonic_platform_pddf_base.pddf_psu import PddfPsu
except ImportError as e:
raise ImportError (str(e) + "- required module not found")


class Psu(PddfPsu):
"""PDDF Platform-Specific PSU class"""

PLATFORM_PSU_CAPACITY = 1200

def __init__(self, index, pddf_data=None, pddf_plugin_data=None):
PddfPsu.__init__(self, index, pddf_data, pddf_plugin_data)

# Provide the functions/variables below for which implementation is to be overwritten
def get_capacity(self):
"""
Gets the capacity (maximum output power) of the PSU in watts

Returns:
An integer, the capacity of PSU
"""
return (self.PLATFORM_PSU_CAPACITY)

def get_type(self):
"""
Gets the type of the PSU
Returns:
A string, the type of PSU (AC/DC)
"""
return "DC"
def get_input_current(self):
return 0

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python

try:
from sonic_platform_pddf_base.pddf_sfp import PddfSfp
except ImportError, e:
raise ImportError (str(e) + "- required module not found")


class Sfp(PddfSfp):
"""
PDDF Platform-Specific Sfp class
"""

def __init__(self, index, pddf_data=None, pddf_plugin_data=None):
PddfSfp.__init__(self, index, pddf_data, pddf_plugin_data)

# Provide the functions/variables below for which implementation is to be overwritten
Loading