Skip to content

Commit 6cb445c

Browse files
ciju-juniperlguohan
authored andcommitted
[Juniper][QFX5210]Adding the system reboot handler (#3599)
The following changes are done as part of this commit: - Adding the system reboot handler - Adding swizzle reset case for the reboot reason - Workaround for the boot problem from Golden bios - Adding the logging messages for platform scripts - EEPROM parsing and library routines
1 parent 07235d0 commit 6cb445c

File tree

6 files changed

+429
-39
lines changed

6 files changed

+429
-39
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
systemctl enable qfx5210-platform-init.service
22
systemctl start qfx5210-platform-init.service
3+
4+
# There are primary and secondary bios in qfx5210 platform.
5+
# There is a problem with bios which prevents the OS booting from the
6+
# secondary bios when the OS was installed using primary bios.
7+
# Secondary bios fails to detect the UEFI partition. Right now
8+
# the workaround is to have a folder structure /EFI/BOOT/BOOT64x.efi
9+
10+
SONIC_VERSION=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v build_version)
11+
FIRST_BOOT_FILE="/host/image-${SONIC_VERSION}/platform/firsttime"
12+
13+
if [ -f $FIRST_BOOT_FILE ]; then
14+
mkdir /tmp/sda1
15+
mount /dev/sda1 /tmp/sda1
16+
cd /tmp/sda1/EFI
17+
mkdir BOOT > /dev/null 2>&1
18+
cp SONiC-OS/grubx64.efi BOOT/BOOTX64.EFI
19+
cd /tmp
20+
umount sda1
21+
efibootmgr -c -L "SONiC" -l "\EFI\BOOT\BOOTX64.EFI" > /dev/null 2>&1
22+
fi

platform/broadcom/sonic-platform-modules-juniper/qfx5210/modules/x86-64-juniper-qfx5210-64x-psu.c

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <linux/slab.h>
3737
#include <linux/delay.h>
3838
#include <linux/dmi.h>
39+
#include <linux/notifier.h>
40+
#include <linux/reboot.h>
3941

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

5056
/* Addresses scanned
5157
*/
@@ -78,6 +84,36 @@ static struct attribute *qfx5210_64x_psu_attributes[] = {
7884
NULL
7985
};
8086

87+
static int qfx5210_cpld_soft_reset(struct notifier_block *nb,
88+
unsigned long action,
89+
void *data)
90+
{
91+
int ret = 0;
92+
93+
switch (action) {
94+
case SYS_POWER_OFF:
95+
case SYS_HALT:
96+
printk(KERN_CRIT "System halt/power_off\n");
97+
break;
98+
case SYS_RESTART:
99+
printk(KERN_CRIT "System restart: qfx5210_cpld_soft_reset\n");
100+
ret = juniper_i2c_cpld_write(0x65, 0x04, 0x01);
101+
if (ret) {
102+
printk(KERN_CRIT "qfx5210_cpld_soft_reset failed\n");
103+
}
104+
msleep(100);
105+
break;
106+
default:
107+
/* Do Nothing */
108+
break;
109+
}
110+
return NOTIFY_DONE;
111+
}
112+
113+
static struct notifier_block qfx5210_nb = {
114+
.notifier_call = qfx5210_cpld_soft_reset,
115+
};
116+
81117
static ssize_t show_status(struct device *dev, struct device_attribute *da,
82118
char *buf)
83119
{
@@ -103,11 +139,6 @@ static const struct attribute_group qfx5210_64x_psu_group = {
103139
.attrs = qfx5210_64x_psu_attributes,
104140
};
105141

106-
/*
107-
* This function is defined in juniper_i2c_cpld.c
108-
*/
109-
extern int juniper_i2c_cpld_write(unsigned short, u8, u8);
110-
111142
/*
112143
* QFX5210 power off sequence
113144
*/
@@ -126,7 +157,6 @@ static void qfx5210_cpld_power_off(void)
126157
*/
127158
static void (*default_pm_power_off)(void);
128159

129-
130160
static int qfx5210_64x_psu_probe(struct i2c_client *client,
131161
const struct i2c_device_id *dev_id)
132162
{
@@ -165,12 +195,7 @@ static int qfx5210_64x_psu_probe(struct i2c_client *client,
165195

166196
dev_info(&client->dev, "%s: psu '%s'\n",
167197
dev_name(data->hwmon_dev), client->name);
168-
/*
169-
* Store the default poweroff handler for later usage
170-
*/
171-
default_pm_power_off = pm_power_off;
172-
pm_power_off = qfx5210_cpld_power_off;
173-
198+
174199
return 0;
175200

176201
exit_remove:
@@ -189,19 +214,14 @@ static int qfx5210_64x_psu_remove(struct i2c_client *client)
189214
hwmon_device_unregister(data->hwmon_dev);
190215
sysfs_remove_group(&client->dev.kobj, &qfx5210_64x_psu_group);
191216
kfree(data);
192-
193-
/*
194-
* Restore the poweroff handler
195-
*/
196-
pm_power_off = default_pm_power_off;
197-
217+
198218
return 0;
199219
}
200220

201221
enum psu_index
202222
{
203223
qfx5210_64x_psu1,
204-
qfx5210_64x_psu2
224+
qfx5210_64x_psu2
205225
};
206226

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

260280
static int __init qfx5210_64x_psu_init(void)
261281
{
282+
/*
283+
* Store the default poweroff handler for later usage
284+
*/
285+
default_pm_power_off = pm_power_off;
286+
/*
287+
* Register the cpld poweroff handler
288+
*/
289+
pm_power_off = qfx5210_cpld_power_off;
290+
/*
291+
* Register the cpld soft reset handler
292+
*/
293+
if(register_reboot_notifier(&qfx5210_nb)) {
294+
printk(KERN_ALERT "Restart handler registration failed\n");
295+
}
296+
262297
return i2c_add_driver(&qfx5210_64x_psu_driver);
263298
}
264299

265300
static void __exit qfx5210_64x_psu_exit(void)
266301
{
302+
/*
303+
* Restore the poweroff handler
304+
*/
305+
pm_power_off = default_pm_power_off;
306+
/*
307+
* Unregister the cpld soft reset handler
308+
*/
309+
if (!unregister_restart_handler(&qfx5210_nb)) {
310+
printk(KERN_CRIT "Failed to uregister restart handler\n");
311+
}
312+
267313
i2c_del_driver(&qfx5210_64x_psu_driver);
268314
}
269315

platform/broadcom/sonic-platform-modules-juniper/qfx5210/service/qfx5210-platform-init.service

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ DefaultDependencies=no
88
ExecStartPre=/usr/local/bin/juniper_qfx5210_util.py install
99
ExecStart=/usr/local/bin/juniper_qfx5210_monitor.py
1010
RemainAfterExit=yes
11+
StandardOutput=syslog+console
12+
StandardError=syslog+console
1113

1214
[Install]
1315
WantedBy=multi-user.target

platform/broadcom/sonic-platform-modules-juniper/qfx5210/sonic_platform/chassis.py

Lines changed: 133 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(self):
6060

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

7373
def get_product_name(self):
74-
product_name_list = self.get_qfx5210_parameter_value('ProductName')
74+
product_name_list = self.get_qfx5210_parameter_value('Product Name')
7575
if product_name_list:
7676
product_name = ''.join(product_name_list)
7777
return product_name
7878
else:
7979
return False
8080

81+
8182
def get_part_number(self):
82-
part_number_list = self.get_qfx5210_parameter_value('PartNumber')
83+
part_number_list = self.get_qfx5210_parameter_value('Part Number')
8384
if part_number_list:
8485
part_number = ''.join(part_number_list)
8586
return part_number
8687
else:
8788
return False
8889

90+
8991
def get_serial_number(self):
90-
serial_number_list = self.get_qfx5210_parameter_value('SerialNumber')
92+
serial_number_list = self.get_qfx5210_parameter_value('Serial Number')
9193
if serial_number_list:
9294
serial_number = ''.join(serial_number_list)
9395
return serial_number
9496
else:
9597
return False
9698

99+
97100
def get_base_mac(self):
98101
mac_list = self.get_qfx5210_parameter_value('MAC')
99102
if mac_list:
@@ -102,13 +105,134 @@ def get_base_mac(self):
102105
else:
103106
return False
104107

108+
109+
def get_mfg_date(self):
110+
mfgdate_list = self.get_qfx5210_parameter_value('Manufacture Date')
111+
if mfgdate_list:
112+
mfgdate = ''.join(mfgdate_list)
113+
return mfgdate
114+
else:
115+
return False
116+
117+
def get_deviceversion_name(self):
118+
device_version_list = self.get_qfx5210_parameter_value('Device Version')
119+
if device_version_list:
120+
deviceversion_name = ''.join(device_version_list)
121+
return deviceversion_name
122+
else:
123+
return False
124+
105125
def get_platform_name(self):
106-
platform_name_list = self.get_qfx5210_parameter_value('PlatformName')
126+
platform_name_list = self.get_qfx5210_parameter_value('Platform Name')
107127
if platform_name_list:
108128
platform_name = ''.join(platform_name_list)
109129
return platform_name
110130
else:
111131
return False
132+
133+
def get_MACnumber_name(self):
134+
MACnumber_name_list = self.get_qfx5210_parameter_value('Number of MAC Addresses')
135+
if MACnumber_name_list:
136+
MACnumber_name = ''.join(MACnumber_name_list)
137+
return MACnumber_name
138+
else:
139+
return False
140+
141+
def get_vendor_name(self):
142+
vendor_name_list = self.get_qfx5210_parameter_value('Vendor Name')
143+
if vendor_name_list:
144+
vendor_name = ''.join(vendor_name_list)
145+
return vendor_name
146+
else:
147+
return False
148+
149+
def get_mfg_name(self):
150+
mfg_name_list = self.get_qfx5210_parameter_value('Manufacture Name')
151+
if mfg_name_list:
152+
mfg_name = ''.join(mfg_name_list)
153+
return mfg_name
154+
else:
155+
return False
156+
157+
def get_vendorext_name(self):
158+
vendorext_list = self.get_qfx5210_parameter_value('Vendor Extension')
159+
if vendorext_list:
160+
vendorext = ''.join(vendorext_list)
161+
return vendorext
162+
else:
163+
return False
164+
165+
def get_vendorextIANA_name(self):
166+
vendorext_list = self.get_qfx5210_parameter_value('IANA')
167+
if vendorext_list:
168+
vendorext = ''.join(vendorext_list)
169+
return vendorext
170+
else:
171+
return False
172+
173+
def get_vendorextASMREV_name(self):
174+
vendorext_list = self.get_qfx5210_parameter_value('Assembly Part Number Rev')
175+
if vendorext_list:
176+
vendorext = ''.join(vendorext_list)
177+
return vendorext
178+
else:
179+
return False
180+
181+
def get_vendorextASMPartNum_name(self):
182+
vendorext_list = self.get_qfx5210_parameter_value('Assembly Part Number')
183+
if vendorext_list:
184+
vendorext = ''.join(vendorext_list)
185+
return vendorext
186+
else:
187+
return False
188+
189+
def get_vendorextASMID_name(self):
190+
vendorext_list = self.get_qfx5210_parameter_value('Assembly ID')
191+
if vendorext_list:
192+
vendorext = ''.join(vendorext_list)
193+
return vendorext
194+
else:
195+
return False
196+
197+
def get_vendorextASMMajNum_name(self):
198+
vendorext_list = self.get_qfx5210_parameter_value('Assembly Major Revision')
199+
if vendorext_list:
200+
vendorext = ''.join(vendorext_list)
201+
return vendorext
202+
else:
203+
return False
204+
205+
def get_vendorextASMMinNum_name(self):
206+
vendorext_list = self.get_qfx5210_parameter_value('Assembly Minor Revision')
207+
if vendorext_list:
208+
vendorext = ''.join(vendorext_list)
209+
return vendorext
210+
else:
211+
return False
212+
213+
def get_vendorextCLEI_name(self):
214+
vendorext_list = self.get_qfx5210_parameter_value('CLEI code')
215+
if vendorext_list:
216+
vendorext = ''.join(vendorext_list)
217+
return vendorext
218+
else:
219+
return False
220+
221+
def get_onieversion_name(self):
222+
onieversion_name_list = self.get_qfx5210_parameter_value('ONIE Version')
223+
if onieversion_name_list:
224+
onieversion_name = ''.join(onieversion_name_list)
225+
return onieversion_name
226+
else:
227+
return False
228+
229+
def get_crc_name(self):
230+
crc_list = self.get_qfx5210_parameter_value('CRC')
231+
if crc_list:
232+
crc_name = ''.join(crc_list)
233+
return crc_name
234+
else:
235+
return False
112236

113237
def get_fan_type(self, fantype_path):
114238
try:
@@ -134,6 +258,8 @@ def get_reboot_cause(self):
134258
return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None)
135259
elif last_reboot_reason == "0x20":
136260
return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None)
261+
elif last_reboot_reason == "0x10":
262+
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Swizzle Reset")
137263
else:
138264
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Unknown reason")
139265
else:
@@ -145,5 +271,7 @@ def get_reboot_cause(self):
145271
return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None)
146272
elif last_reboot_reason == "0x20":
147273
return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None)
274+
elif last_reboot_reason == "0x10":
275+
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Swizzle Reset")
148276
else:
149277
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Unknown reason")

0 commit comments

Comments
 (0)