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

[Juniper][QFX5210]Adding the system reboot handler #3599

Merged
merged 16 commits into from
Oct 20, 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
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
systemctl enable qfx5210-platform-init.service
systemctl start qfx5210-platform-init.service

# There are primary and secondary bios in qfx5210 platform.
# There is a problem with bios which prevents the OS booting from the
# secondary bios when the OS was installed using primary bios.
# Secondary bios fails to detect the UEFI partition. Right now
# the workaround is to have a folder structure /EFI/BOOT/BOOT64x.efi

SONIC_VERSION=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v build_version)
FIRST_BOOT_FILE="/host/image-${SONIC_VERSION}/platform/firsttime"

if [ -f $FIRST_BOOT_FILE ]; then
mkdir /tmp/sda1
mount /dev/sda1 /tmp/sda1
cd /tmp/sda1/EFI
mkdir BOOT > /dev/null 2>&1
cp SONiC-OS/grubx64.efi BOOT/BOOTX64.EFI
cd /tmp
umount sda1
efibootmgr -c -L "SONiC" -l "\EFI\BOOT\BOOTX64.EFI" > /dev/null 2>&1
ciju-juniper marked this conversation as resolved.
Show resolved Hide resolved
fi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/dmi.h>
#include <linux/notifier.h>
#include <linux/reboot.h>

#define PSU_STATUS_I2C_ADDR 0x60
#define PSU_STATUS_I2C_REG_OFFSET 0x03
Expand All @@ -46,6 +48,10 @@
static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf);
static struct qfx5210_64x_psu_data *qfx5210_64x_psu_update_device(struct device *dev);
extern int juniper_i2c_cpld_read (u8 cpld_addr, u8 reg);
/*
* This function is defined in juniper_i2c_cpld.c
*/
extern int juniper_i2c_cpld_write(unsigned short, u8, u8);

/* Addresses scanned
*/
Expand Down Expand Up @@ -78,6 +84,36 @@ static struct attribute *qfx5210_64x_psu_attributes[] = {
NULL
};

static int qfx5210_cpld_soft_reset(struct notifier_block *nb,
unsigned long action,
void *data)
{
int ret = 0;

switch (action) {
case SYS_POWER_OFF:
case SYS_HALT:
printk(KERN_CRIT "System halt/power_off\n");
break;
case SYS_RESTART:
printk(KERN_CRIT "System restart: qfx5210_cpld_soft_reset\n");
ret = juniper_i2c_cpld_write(0x65, 0x04, 0x01);
if (ret) {
printk(KERN_CRIT "qfx5210_cpld_soft_reset failed\n");
}
msleep(100);
break;
default:
/* Do Nothing */
break;
}
return NOTIFY_DONE;
}

static struct notifier_block qfx5210_nb = {
.notifier_call = qfx5210_cpld_soft_reset,
};

static ssize_t show_status(struct device *dev, struct device_attribute *da,
char *buf)
{
Expand All @@ -103,11 +139,6 @@ static const struct attribute_group qfx5210_64x_psu_group = {
.attrs = qfx5210_64x_psu_attributes,
};

/*
* This function is defined in juniper_i2c_cpld.c
*/
extern int juniper_i2c_cpld_write(unsigned short, u8, u8);

/*
* QFX5210 power off sequence
*/
Expand All @@ -126,7 +157,6 @@ static void qfx5210_cpld_power_off(void)
*/
static void (*default_pm_power_off)(void);


static int qfx5210_64x_psu_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
Expand Down Expand Up @@ -165,12 +195,7 @@ static int qfx5210_64x_psu_probe(struct i2c_client *client,

dev_info(&client->dev, "%s: psu '%s'\n",
dev_name(data->hwmon_dev), client->name);
/*
* Store the default poweroff handler for later usage
*/
default_pm_power_off = pm_power_off;
pm_power_off = qfx5210_cpld_power_off;


return 0;

exit_remove:
Expand All @@ -189,19 +214,14 @@ static int qfx5210_64x_psu_remove(struct i2c_client *client)
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &qfx5210_64x_psu_group);
kfree(data);

/*
* Restore the poweroff handler
*/
pm_power_off = default_pm_power_off;


return 0;
}

enum psu_index
{
qfx5210_64x_psu1,
qfx5210_64x_psu2
qfx5210_64x_psu2
};

static const struct i2c_device_id qfx5210_64x_psu_id[] = {
Expand Down Expand Up @@ -259,11 +279,37 @@ static struct qfx5210_64x_psu_data *qfx5210_64x_psu_update_device(struct device

static int __init qfx5210_64x_psu_init(void)
{
/*
* Store the default poweroff handler for later usage
*/
default_pm_power_off = pm_power_off;
/*
* Register the cpld poweroff handler
*/
pm_power_off = qfx5210_cpld_power_off;
/*
* Register the cpld soft reset handler
*/
if(register_reboot_notifier(&qfx5210_nb)) {
printk(KERN_ALERT "Restart handler registration failed\n");
}

return i2c_add_driver(&qfx5210_64x_psu_driver);
}

static void __exit qfx5210_64x_psu_exit(void)
{
/*
* Restore the poweroff handler
*/
pm_power_off = default_pm_power_off;
/*
* Unregister the cpld soft reset handler
*/
if (!unregister_restart_handler(&qfx5210_nb)) {
printk(KERN_CRIT "Failed to uregister restart handler\n");
}

i2c_del_driver(&qfx5210_64x_psu_driver);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ DefaultDependencies=no
ExecStartPre=/usr/local/bin/juniper_qfx5210_util.py install
ExecStart=/usr/local/bin/juniper_qfx5210_monitor.py
RemainAfterExit=yes
StandardOutput=syslog+console
StandardError=syslog+console

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self):

def get_qfx5210_parameter_value(self,parameter_name):
try:
with open("/var/run/qfx5210_eeprom", "r") as file:
with open("/var/run/eeprom", "r") as file:
for item in file:
content = item.split('=')
if content[0] == parameter_name:
Expand All @@ -71,29 +71,32 @@ def get_qfx5210_parameter_value(self,parameter_name):
return "False"

def get_product_name(self):
product_name_list = self.get_qfx5210_parameter_value('ProductName')
product_name_list = self.get_qfx5210_parameter_value('Product Name')
if product_name_list:
product_name = ''.join(product_name_list)
return product_name
else:
return False


def get_part_number(self):
part_number_list = self.get_qfx5210_parameter_value('PartNumber')
part_number_list = self.get_qfx5210_parameter_value('Part Number')
if part_number_list:
part_number = ''.join(part_number_list)
return part_number
else:
return False


def get_serial_number(self):
serial_number_list = self.get_qfx5210_parameter_value('SerialNumber')
serial_number_list = self.get_qfx5210_parameter_value('Serial Number')
if serial_number_list:
serial_number = ''.join(serial_number_list)
return serial_number
else:
return False


def get_base_mac(self):
mac_list = self.get_qfx5210_parameter_value('MAC')
if mac_list:
Expand All @@ -102,13 +105,134 @@ def get_base_mac(self):
else:
return False


def get_mfg_date(self):
mfgdate_list = self.get_qfx5210_parameter_value('Manufacture Date')
if mfgdate_list:
mfgdate = ''.join(mfgdate_list)
return mfgdate
else:
return False

def get_deviceversion_name(self):
device_version_list = self.get_qfx5210_parameter_value('Device Version')
if device_version_list:
deviceversion_name = ''.join(device_version_list)
return deviceversion_name
else:
return False

def get_platform_name(self):
platform_name_list = self.get_qfx5210_parameter_value('PlatformName')
platform_name_list = self.get_qfx5210_parameter_value('Platform Name')
if platform_name_list:
platform_name = ''.join(platform_name_list)
return platform_name
else:
return False

def get_MACnumber_name(self):
MACnumber_name_list = self.get_qfx5210_parameter_value('Number of MAC Addresses')
if MACnumber_name_list:
MACnumber_name = ''.join(MACnumber_name_list)
return MACnumber_name
else:
return False

def get_vendor_name(self):
vendor_name_list = self.get_qfx5210_parameter_value('Vendor Name')
if vendor_name_list:
vendor_name = ''.join(vendor_name_list)
return vendor_name
else:
return False

def get_mfg_name(self):
mfg_name_list = self.get_qfx5210_parameter_value('Manufacture Name')
if mfg_name_list:
mfg_name = ''.join(mfg_name_list)
return mfg_name
else:
return False

def get_vendorext_name(self):
vendorext_list = self.get_qfx5210_parameter_value('Vendor Extension')
if vendorext_list:
vendorext = ''.join(vendorext_list)
return vendorext
else:
return False

def get_vendorextIANA_name(self):
vendorext_list = self.get_qfx5210_parameter_value('IANA')
if vendorext_list:
vendorext = ''.join(vendorext_list)
return vendorext
else:
return False

def get_vendorextASMREV_name(self):
vendorext_list = self.get_qfx5210_parameter_value('Assembly Part Number Rev')
if vendorext_list:
vendorext = ''.join(vendorext_list)
return vendorext
else:
return False

def get_vendorextASMPartNum_name(self):
vendorext_list = self.get_qfx5210_parameter_value('Assembly Part Number')
if vendorext_list:
vendorext = ''.join(vendorext_list)
return vendorext
else:
return False

def get_vendorextASMID_name(self):
vendorext_list = self.get_qfx5210_parameter_value('Assembly ID')
if vendorext_list:
vendorext = ''.join(vendorext_list)
return vendorext
else:
return False

def get_vendorextASMMajNum_name(self):
vendorext_list = self.get_qfx5210_parameter_value('Assembly Major Revision')
if vendorext_list:
vendorext = ''.join(vendorext_list)
return vendorext
else:
return False

def get_vendorextASMMinNum_name(self):
vendorext_list = self.get_qfx5210_parameter_value('Assembly Minor Revision')
if vendorext_list:
vendorext = ''.join(vendorext_list)
return vendorext
else:
return False

def get_vendorextCLEI_name(self):
vendorext_list = self.get_qfx5210_parameter_value('CLEI code')
if vendorext_list:
vendorext = ''.join(vendorext_list)
return vendorext
else:
return False

def get_onieversion_name(self):
onieversion_name_list = self.get_qfx5210_parameter_value('ONIE Version')
if onieversion_name_list:
onieversion_name = ''.join(onieversion_name_list)
return onieversion_name
else:
return False

def get_crc_name(self):
crc_list = self.get_qfx5210_parameter_value('CRC')
if crc_list:
crc_name = ''.join(crc_list)
return crc_name
else:
return False

def get_fan_type(self, fantype_path):
try:
Expand All @@ -134,6 +258,8 @@ def get_reboot_cause(self):
return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None)
elif last_reboot_reason == "0x20":
return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None)
elif last_reboot_reason == "0x10":
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Swizzle Reset")
ciju-juniper marked this conversation as resolved.
Show resolved Hide resolved
else:
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Unknown reason")
else:
Expand All @@ -145,5 +271,7 @@ def get_reboot_cause(self):
return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None)
elif last_reboot_reason == "0x20":
return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None)
elif last_reboot_reason == "0x10":
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Swizzle Reset")
else:
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Unknown reason")
Loading