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

Modify ag9064 platform module and add support psutil. #3305

Merged
merged 1 commit into from
Aug 8, 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
78 changes: 78 additions & 0 deletions device/delta/x86_64-delta_ag9064-r0/plugins/psuutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# Module contains an implementation of SONiC PSU Base API and
# provides the PSUs status which are available in the platform
#

import os.path
import subprocess

try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""

def __init__(self):
PsuBase.__init__(self)
self.psu_presence = "cat /sys/devices/platform/delta-ag9064-cpld.0/psu{}_scan"
self.psu_status = "cat /sys/devices/platform/delta-ag9064-swpld1.0/psu{}_pwr_ok"

def get_num_psus(self):
"""
Retrieves the number of PSUs available on the device

:return: An integer, the number of PSUs available on the device
"""
return 2

def get_psu_status(self, index):
"""
Retrieves the oprational status of power supply unit (PSU) defined
by 1-based index <index>

:param index: An integer, 1-based index of the PSU of which to query status
:return: Boolean, True if PSU is operating properly, False if PSU is faulty
"""
if index is None:
return False

status = 0
try:
p = os.popen(self.psu_status.format(index))
content = p.readline().rstrip()
reg_value = int(content)
if reg_value != 0:
return False
status = 1
p.close()
except IOError:
return False
return status == 1



def get_psu_presence(self, index):
"""
Retrieves the presence status of power supply unit (PSU) defined
by 1-based index <index>

:param index: An integer, 1-based index of the PSU of which to query status
:return: Boolean, True if PSU is plugged, False if not
"""
if index is None:
return False
status = 0
try:
p = os.popen(self.psu_presence.format(index))
content = p.readline().rstrip()
reg_value = int(content, 16)
if reg_value != 0:
return False
status = 1
p.close()
except IOError:
return False
return status == 1

4 changes: 2 additions & 2 deletions device/delta/x86_64-delta_ag9064-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SfpUtil(SfpUtilBase):
PORT_END = 63
PORTS_IN_BLOCK = 64

EEPROM_OFFSET = 20
EEPROM_OFFSET = 1

_port_to_eeprom_mapping = {}

Expand All @@ -38,7 +38,7 @@ def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping

def __init__(self):
eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom"
eeprom_path = "/sys/kernel/sfp/eeprom_sfp_{0}"

for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,38 @@
#define IPMI_MAX_INTF (4)
#define DELTA_NETFN 0x38
#define BMC_BUS_5 0x04
#define BMC_BUS_1 0x00
#define CMD_SETDATA 0x03
#define CMD_GETDATA 0x02
#define CMD_DEVICE_SCAN 0x01

#define CPUPLD_ADDR 0x31
#define SWPLD1_ADDR 0x35
#define SWPLD2_ADDR 0x34
#define SWPLD3_ADDR 0x33
#define SWPLD4_ADDR 0x32
#define QSFP_PORT_MUX_REG 0x13
#define PSU1_EEPROM_ADDR 0x50
#define PSU2_EEPROM_ADDR 0x51

#define DEFAULT_NUM 1
#define BUS9_DEV_NUM 64
#define BUS9_BASE_NUM 20
#define EEPROM_SIZE 640
#define EEPROM_ARCH_SIZE 256
#define EEPROM_MASK 20
#define ATTR_R 1
#define ATTR_W 2

extern int dni_bmc_cmd(char set_cmd, char *cmd_data, int cmd_data_len);
extern int dni_create_user(void);
extern unsigned char dni_log2 (unsigned char num);

extern void device_release(struct device *dev);
extern void msg_handler(struct ipmi_recv_msg *recv_msg,void* handler_data);
extern void dummy_smi_free(struct ipmi_smi_msg *msg);
extern void dummy_recv_free(struct ipmi_recv_msg *msg);
extern void dni_klock(void);
extern void dni_kunlock(void);

static ipmi_user_t ipmi_mh_user = NULL;
static struct ipmi_user_hndl ipmi_hndlrs = { .ipmi_recv_hndl = msg_handler,};
Expand Down Expand Up @@ -129,6 +139,8 @@ enum cpld_attributes {
SWPLD3_REG_VALUE,
SWPLD4_REG_ADDR,
SWPLD4_REG_VALUE,
PSU1_SCAN,
PSU2_SCAN,
//CPLD
CPLD_VER,
CPU_BOARD_VER,
Expand Down Expand Up @@ -203,6 +215,73 @@ enum cpld_attributes {
FAN_EEPROM_WP,
};

enum sfp_attributes{
EEPROM_SFP_1,
EEPROM_SFP_2,
EEPROM_SFP_3,
EEPROM_SFP_4,
EEPROM_SFP_5,
EEPROM_SFP_6,
EEPROM_SFP_7,
EEPROM_SFP_8,
EEPROM_SFP_9,
EEPROM_SFP_10,
EEPROM_SFP_11,
EEPROM_SFP_12,
EEPROM_SFP_13,
EEPROM_SFP_14,
EEPROM_SFP_15,
EEPROM_SFP_16,
EEPROM_SFP_17,
EEPROM_SFP_18,
EEPROM_SFP_19,
EEPROM_SFP_20,
EEPROM_SFP_21,
EEPROM_SFP_22,
EEPROM_SFP_23,
EEPROM_SFP_24,
EEPROM_SFP_25,
EEPROM_SFP_26,
EEPROM_SFP_27,
EEPROM_SFP_28,
EEPROM_SFP_29,
EEPROM_SFP_30,
EEPROM_SFP_31,
EEPROM_SFP_32,
EEPROM_SFP_33,
EEPROM_SFP_34,
EEPROM_SFP_35,
EEPROM_SFP_36,
EEPROM_SFP_37,
EEPROM_SFP_38,
EEPROM_SFP_39,
EEPROM_SFP_40,
EEPROM_SFP_41,
EEPROM_SFP_42,
EEPROM_SFP_43,
EEPROM_SFP_44,
EEPROM_SFP_45,
EEPROM_SFP_46,
EEPROM_SFP_47,
EEPROM_SFP_48,
EEPROM_SFP_49,
EEPROM_SFP_50,
EEPROM_SFP_51,
EEPROM_SFP_52,
EEPROM_SFP_53,
EEPROM_SFP_54,
EEPROM_SFP_55,
EEPROM_SFP_56,
EEPROM_SFP_57,
EEPROM_SFP_58,
EEPROM_SFP_59,
EEPROM_SFP_60,
EEPROM_SFP_61,
EEPROM_SFP_62,
EEPROM_SFP_63,
EEPROM_SFP_64,
};

static struct cpld_attribute_data attribute_data[] = {
[CPLD_REG_ADDR] = {
},
Expand Down Expand Up @@ -564,4 +643,4 @@ static struct cpld_attribute_data attribute_data[] = {
.reg = 0x15, .mask = 1 << 2,
.note = "“1” = enables the lock-down mechanism.\n“0” = overrides the lock-down function enabling blocks to be erased or programmed using software commands."
},
};
};
Loading