blob: 2c9dfe1b85d8eba72f140d57ff6cc020246e1b38 [file] [log] [blame]
Allen.Wang4a0948d2021-12-15 13:41:18 +08001#!/bin/bash
2#
3# Power Control tool
4# Enable/disable AC relay
5# On/off System by step moter to press power key
6
7export PATH=$PATH:/usr/sbin:/usr/libexec
8
Potin Lai501f4c72022-06-13 13:23:57 +08009# shellcheck source=meta-facebook/meta-bletchley/recipes-bletchley/plat-tools/files/bletchley-common-functions
10source /usr/libexec/bletchley-common-functions
11
Allen.Wang4a0948d2021-12-15 13:41:18 +080012DELAY_POWER_ON="0.5"
13DELAY_POWER_OFF="5"
Potin Lai27083c32022-06-02 19:13:24 +080014DELAY_POWER_RECOVERY_MODE="10"
Allen.Wang4a0948d2021-12-15 13:41:18 +080015POWER_BTN_TIMEOUT_CNT=60
16
Potin Laibb91c1b2022-04-28 15:03:05 +080017REV_EVT="EVT"
18REV_DVT="DVT"
19REV_UNKNOW="UNKNOW"
20
21DBUS_HOST_ST_ON="xyz.openbmc_project.State.Host.HostState.Running"
22DBUS_HOST_ST_OFF="xyz.openbmc_project.State.Host.HostState.Off"
23
24HOST_ST_UNKNOW="Unknow"
25HOST_ST_ON="On"
26HOST_ST_OFF="Off"
Potin Lai27083c32022-06-02 19:13:24 +080027HOST_ST_SLEEP="Sleep"
28HOST_ST_DFU="DFU"
29HOST_ST_RECOVERY="Recovery"
Potin Laibb91c1b2022-04-28 15:03:05 +080030HOST_AC_ON="AC On"
31HOST_AC_OFF="AC Off"
32
Potin Lai27083c32022-06-02 19:13:24 +080033ACTION_ON="on"
34ACTION_OFF="off"
35ACTION_DFU="dfu"
36ACTION_RECOVERY="recovery"
Potin Lai2320b0e2022-06-28 10:38:37 +080037ACTION_CYCLE="cycle"
38ACTION_RESET="reset"
Potin Lai27083c32022-06-02 19:13:24 +080039ACTION_AC_ON="ac-on"
40ACTION_AC_OFF="ac-off"
41ACTION_STATUS="status"
42
43VALID_SLED_ACTIONS="
44 $ACTION_ON
45 $ACTION_OFF
46 $ACTION_AC_ON
47 $ACTION_AC_OFF
48 $ACTION_STATUS
49 $ACTION_DFU
50 $ACTION_RECOVERY
Potin Lai2320b0e2022-06-28 10:38:37 +080051 $ACTION_CYCLE
52 $ACTION_RESET
Potin Lai27083c32022-06-02 19:13:24 +080053"
54
55function is_valid_sled_action()
56{
57 local ACTION=$1
58 for i in $VALID_SLED_ACTIONS
59 do
60 if [ "$i" = "$ACTION" ]; then
61 return 0
62 fi
63 done
64 return 1
65}
66
67function get_board_rev()
68{
Potin Laibb91c1b2022-04-28 15:03:05 +080069 local rev_id0
70 local rev_id1
71 local rev_id2
72 local rev_val
73
74 rev_id0=$(get_gpio "REV_ID0")
75 rev_id1=$(get_gpio "REV_ID1")
76 rev_id2=$(get_gpio "REV_ID2")
77 rev_val=$((rev_id0+(rev_id1<<1)+(rev_id2<<2)))
78
79 case $rev_val in
80 0)
81 echo "$REV_EVT"
82 ;;
83 1)
84 echo "$REV_DVT"
85 ;;
86 *)
87 echo "$REV_UNKNOW"
88 return 1
89 ;;
90 esac
91
92 return 0
93}
94
Allen.Wang4a0948d2021-12-15 13:41:18 +080095#Switch pull low while it be touched
Potin Lai27083c32022-06-02 19:13:24 +080096function wait_for_switch()
97{
Allen.Wang4a0948d2021-12-15 13:41:18 +080098 TARGET_PIN=$1
99 TARGET_SWITCH=1
100 TIME_CNT=0
101 while [ "$TARGET_SWITCH" -eq 1 ] ;do
102 TARGET_SWITCH=$(get_gpio "$TARGET_PIN")
103 sleep 0.1
104 TIME_CNT=$(( TIME_CNT +1))
105 if [ $TIME_CNT -gt $POWER_BTN_TIMEOUT_CNT ];then
106 echo "Error: Too long to get target switch, force exit" >&2
107 break
108 fi
109 done
110}
111
Potin Lai27083c32022-06-02 19:13:24 +0800112function trigger_power_button()
113{
Allen.Wang4a0948d2021-12-15 13:41:18 +0800114 local sled_num=$1
Allen.Wang6af0dff2021-12-28 20:23:05 +0800115 local delay_time=$2
Allen.Wang4a0948d2021-12-15 13:41:18 +0800116
117 #SLED{N}_MS_DETECT1 (initial position)
118 GPIO_DETECT_PIN1="SLED${sled_num}_MS_DETECT1"
119 #SLED{N}_MS_DETECT0 (MAC position)
120 GPIO_DETECT_PIN0="SLED${sled_num}_MS_DETECT0"
121
122 echo "Motor go forward to press Power key"
123 motor-ctrl "sled${sled_num}" f >/dev/null
124 wait_for_switch "${GPIO_DETECT_PIN0}"
125 motor-ctrl "sled${sled_num}" s >/dev/null
126
127 if [ "$(get_gpio "$GPIO_DETECT_PIN0")" -eq 0 ];then
128 echo "Power key switch triggered"
129 echo "Press power key for Sled${1} ${delay_time} seconds..."
130 sleep "$delay_time"
131 else
Allen.Wang6af0dff2021-12-28 20:23:05 +0800132 echo "Power key switch not trigger, back motor to initial position"
Allen.Wang4a0948d2021-12-15 13:41:18 +0800133 fi
134
135 motor-ctrl "sled${sled_num}" r >/dev/null
136 wait_for_switch "${GPIO_DETECT_PIN1}"
137 motor-ctrl "sled${sled_num}" s >/dev/null
138 if [ "$(get_gpio "$GPIO_DETECT_PIN1")" -eq 0 ];then
139 echo "Motor reverse to initial position successful"
140 else
Allen.Wang6af0dff2021-12-28 20:23:05 +0800141 echo "Initial position switch not trigger, force stop motor"
Allen.Wang4a0948d2021-12-15 13:41:18 +0800142 fi
143}
144
Potin Lai27083c32022-06-02 19:13:24 +0800145function release_power_button()
146{
Potin Laidb5648e2022-02-16 00:57:55 +0800147 local sled_num=$1
148 GPIO_DETECT_PIN1="SLED${sled_num}_MS_DETECT1"
149
150 if [ "$(get_gpio "$GPIO_DETECT_PIN1")" -eq 0 ]; then
151 echo "Motor at initial position already"
152 return 0
153 fi
154
155 motor-ctrl "sled${sled_num}" r >/dev/null
156 wait_for_switch "${GPIO_DETECT_PIN1}"
157 motor-ctrl "sled${sled_num}" s >/dev/null
158 if [ "$(get_gpio "$GPIO_DETECT_PIN1")" -eq 0 ];then
159 echo "Motor reverse to initial position successful"
160 return 0
161 fi
162
163 echo "Error: Initial position switch not trigger"
164 return 1
165}
166
Potin Lai27083c32022-06-02 19:13:24 +0800167function press_power_button()
168{
Potin Laidb5648e2022-02-16 00:57:55 +0800169 local sled_num=$1
170
171 GPIO_DETECT_PIN0="SLED${sled_num}_MS_DETECT0"
172
173 echo "Motor go forward to press Power button"
174 motor-ctrl "sled${sled_num}" f >/dev/null
175 wait_for_switch "${GPIO_DETECT_PIN0}"
176 motor-ctrl "sled${sled_num}" s >/dev/null
177
178 if [ "$(get_gpio "$GPIO_DETECT_PIN0")" -eq 0 ];then
179 echo "Power button switch triggered"
180 return 0
181 fi
182
183 echo "Error: Power button switch not trigger"
184 return 1
185}
186
Allen.Wang4a0948d2021-12-15 13:41:18 +0800187#Get i2c bus number for sledN
Potin Lai27083c32022-06-02 19:13:24 +0800188function get_bus_num()
189{
Allen.Wang4a0948d2021-12-15 13:41:18 +0800190 SLED_NUM=$1
191 local bus=0
Allen.Wang5ff992e2022-01-04 21:00:38 +0800192 #Mapping Sled number 1~6 to i2c bus number 0~5
193 if [[ "$SLED_NUM" = [1-6] ]]; then
194 bus=$(( SLED_NUM - 1 ))
Allen.Wang4a0948d2021-12-15 13:41:18 +0800195 fi
196 echo "$bus"
197}
198
Potin Lai27083c32022-06-02 19:13:24 +0800199function get_ac_status()
200{
Allen.Wang4a0948d2021-12-15 13:41:18 +0800201 i2c_bus=$(get_bus_num "$1")
202 p1_output_reg=$(i2cget -f -y "$i2c_bus" 0x76 0x03)
203 p1_config_reg=$(i2cget -f -y "$i2c_bus" 0x76 0x07)
204 host_pwr="$(( (p1_output_reg & 0x80)>>7 ))"
205 is_output="$(( (~p1_config_reg & 0x80)>>7 ))"
206
207 if [ "$(( host_pwr & is_output ))" -eq 1 ];then
Potin Laibb91c1b2022-04-28 15:03:05 +0800208 echo "$HOST_AC_ON"
Allen.Wang4a0948d2021-12-15 13:41:18 +0800209 else
Potin Laibb91c1b2022-04-28 15:03:05 +0800210 echo "$HOST_AC_OFF"
Allen.Wang4a0948d2021-12-15 13:41:18 +0800211 fi
212}
213
Potin Laibb91c1b2022-04-28 15:03:05 +0800214function get_host_status_dbus()
215{
216 local sled_num=$1
217 local object="/xyz/openbmc_project/state/host${sled_num}"
218 local service="xyz.openbmc_project.State.Host${sled_num}"
219 local interface="xyz.openbmc_project.State.Host"
220 local property="CurrentHostState"
221 local host_state
222
223 host_state=$(busctl get-property "$service" "$object" "$interface" "$property" | cut -d '"' -f2)
224
225 if [ "$host_state" = "$DBUS_HOST_ST_ON" ]; then
226 echo "$HOST_ST_ON"
227 elif [ "$host_state" = "$DBUS_HOST_ST_OFF" ]; then
228 echo "$HOST_ST_OFF"
229 else
230 echo "$HOST_ST_UNKNOW"
231 return 1
232 fi
233
234 return 0
235}
236
237function get_host_status_mdio()
Potin Laidc251662022-04-01 11:16:50 +0800238{
Potin Lai27083c32022-06-02 19:13:24 +0800239 local SLED_NUM=$1
240 local MDIO_BUS=0
Potin Laibb91c1b2022-04-28 15:03:05 +0800241
Potin Laidc251662022-04-01 11:16:50 +0800242 declare -a PORT_MAP=(0 3 2 1 7 6 5)
243
244 # check /dev/mem
245 if ! create_dev_mem; then
246 return 1
247 fi
248
Potin Lai27083c32022-06-02 19:13:24 +0800249 local CHECK_CNT=0
250 local MDIO_ERR_CNT=0
251 local CUR_HOST_ST=$HOST_ST_UNKNOW
252 local SLED_LAST_ACTION
253
254 if [ -f /tmp/sled"${SLED_NUM}"-last-action ]; then
255 SLED_LAST_ACTION=$(cat /tmp/sled"${SLED_NUM}"-last-action)
256 fi
Potin Laidc251662022-04-01 11:16:50 +0800257
258 while true
259 do
260 if POST_ST_VAL=$(mdio-util c22 r $MDIO_BUS "${PORT_MAP[SLED_NUM]}" 0); then
Potin Lai27083c32022-06-02 19:13:24 +0800261 if [ $((POST_ST_VAL&16#0800)) -eq $((16#0000)) ]; then
262 case $SLED_LAST_ACTION in
263 "$ACTION_DFU")
264 TMP_HOST_ST="$HOST_ST_DFU"
265 ;;
266 *)
267 TMP_HOST_ST="$HOST_ST_OFF"
268 ;;
269 esac
270 elif [ $((POST_ST_VAL&16#0A00)) -eq $((16#0A00)) ]; then
Potin Laidc251662022-04-01 11:16:50 +0800271 TMP_HOST_ST="$HOST_ST_ON"
Potin Lai27083c32022-06-02 19:13:24 +0800272 case $SLED_LAST_ACTION in
273 "$ACTION_RECOVERY")
274 TMP_HOST_ST="$HOST_ST_RECOVERY"
275 ;;
276 *)
277 TMP_HOST_ST="$HOST_ST_ON"
278 ;;
279 esac
280 elif [ $((POST_ST_VAL&16#0900)) -eq $((16#0900)) ]; then
281 TMP_HOST_ST="$HOST_ST_SLEEP"
Potin Laidc251662022-04-01 11:16:50 +0800282 else
Potin Lai27083c32022-06-02 19:13:24 +0800283 TMP_HOST_ST="$HOST_ST_UNKNOW"
Potin Laidc251662022-04-01 11:16:50 +0800284 fi
285
286 if [ "$CUR_HOST_ST" == "$TMP_HOST_ST" ]; then
287 CHECK_CNT=$((CHECK_CNT+1))
288 else
289 CUR_HOST_ST=$TMP_HOST_ST
290 CHECK_CNT=0
291 fi
292
293 if [ "$CHECK_CNT" -ge 5 ]; then
294 echo "$CUR_HOST_ST"
295 break
296 fi
297 else
298 MDIO_ERR_CNT=$((MDIO_ERR_CNT+1))
299 if [ "$MDIO_ERR_CNT" -ge 5 ]; then
300 echo "$HOST_ST_UNKNOW"
301 return 1
302 fi
303 fi
304 done
305
306 return 0
307}
308
Potin Laibb91c1b2022-04-28 15:03:05 +0800309function get_host_status()
310{
311 local sled_num=$1
Potin Laibb91c1b2022-04-28 15:03:05 +0800312
Potin Lai27083c32022-06-02 19:13:24 +0800313 if [ "$(get_ac_status "$SLED_NUM")" == "$HOST_AC_OFF" ];then
314 echo "$HOST_AC_OFF"
315 return 0
316 fi
Potin Laibb91c1b2022-04-28 15:03:05 +0800317
Potin Lai27083c32022-06-02 19:13:24 +0800318 if [ "$(get_board_rev)" = "$REV_EVT" ]; then
Potin Laibb91c1b2022-04-28 15:03:05 +0800319 get_host_status_dbus "$sled_num"
320 else
321 get_host_status_mdio "$sled_num"
322 fi
Potin Laibb91c1b2022-04-28 15:03:05 +0800323 return $?
324}
325
Potin Lai2320b0e2022-06-28 10:38:37 +0800326function do_action_reset()
327{
328 # 1. Power off
329 # 2. Power on
330
331 local SLED_NUM=$1
332 local CUR_ST=$2
333
334 if [ "$CUR_ST" != "$HOST_ST_OFF" ]; then
335 do_action_off "$SLED_NUM"
336 else
337 echo "sled${SLED_NUM}: already powered off"
338 fi
339
340 sleep 3
341 do_action_on "$SLED_NUM"
342}
343
344function do_action_cycle()
345{
346 # 1. AC off
347 # 2. AC on
348 # 3. Power on
349
350 local SLED_NUM=$1
351
352 do_action_ac_off "$SLED_NUM"
353 sleep 3
354 do_action_ac_on "$SLED_NUM"
355 sleep 3
356 do_action_on "$SLED_NUM"
357}
358
Potin Lai27083c32022-06-02 19:13:24 +0800359function do_action_ac_on()
360{
361 local SLED_NUM=$1
362 echo "sled${SLED_NUM}: turn on AC"
363 set_gpio "power-host${SLED_NUM}" 1
364 echo "$ACTION_AC_ON" > "/tmp/sled${SLED_NUM}-last-action"
365}
366
367function do_action_ac_off()
368{
369 local SLED_NUM=$1
370 echo "sled${SLED_NUM}: turn off AC"
371 set_gpio "power-host${SLED_NUM}" 0
372 echo "$ACTION_AC_OFF" > "/tmp/sled${SLED_NUM}-last-action"
373}
374
375function do_action_on()
376{
377 local SLED_NUM=$1
378 echo "sled${SLED_NUM}: power on host"
379 trigger_power_button "$SLED_NUM" "$DELAY_POWER_ON"
380 echo "$ACTION_ON" > "/tmp/sled${SLED_NUM}-last-action"
381}
382
383function do_action_off()
384{
385 local SLED_NUM=$1
386 echo "sled${SLED_NUM}: power off host"
387 trigger_power_button "$SLED_NUM" "$DELAY_POWER_OFF"
388 echo "$ACTION_OFF" > "/tmp/sled${SLED_NUM}-last-action"
389}
390
391function do_action_recovery()
392{
393 local SLED_NUM=$1
394 echo "sled${SLED_NUM}: trigger host recovery mode"
395 trigger_power_button "$SLED_NUM" "$DELAY_POWER_RECOVERY_MODE"
396 echo "$ACTION_RECOVERY" > "/tmp/sled${SLED_NUM}-last-action"
397}
398
399function do_action_dfu()
400{
401 local SLED_NUM=$1
402 echo "sled${SLED_NUM}: trigger host dfu mode"
403
404 # turn ac off, and hold for 25 seconds
405 do_action_ac_off "$SLED_NUM"
406 sleep 25
407
408 # press power button
409 echo "SLED$SLED_NUM: pressing power button"
410 if ! press_power_button "$SLED_NUM"; then
411 echo "SLED$SLED_NUM: press power button failed"
412 echo "SLED$SLED_NUM: releasing power button"
413 release_power_button "$SLED_NUM"
414 exit 1
415 fi
416 sleep 1
417
418 # turn ac on
419 echo "SLED$SLED_NUM: turn ac-on"
420 do_action_ac_on "$SLED_NUM"
421 sleep 3
422
423 # release power button
424 echo "SLED$SLED_NUM: releasing host power button"
425 if ! release_power_button "$SLED_NUM"; then
426 echo "SLED$SLED_NUM: release power button failed"
427 exit 1
428 fi
429 echo "$ACTION_DFU" > "/tmp/sled${SLED_NUM}-last-action"
430}
431
432function host_state_on_action_handler()
433{
434 local SLED_NUM=$1
435 local ACTION=$2
436
437 case $ACTION in
438 "$ACTION_OFF")
439 do_action_off "$SLED_NUM"
440 ;;
441 "$ACTION_AC_OFF")
442 do_action_ac_off "$SLED_NUM"
443 ;;
Potin Lai2320b0e2022-06-28 10:38:37 +0800444 "$ACTION_RESET")
445 do_action_reset "$SLED_NUM" "$HOST_ST_ON"
446 ;;
447 "$ACTION_CYCLE")
448 do_action_cycle "$SLED_NUM"
449 ;;
Potin Lai27083c32022-06-02 19:13:24 +0800450 *)
451 echo "Invalid action ($ACTION) for current host state (On)"
452 return 1
453 ;;
454 esac
455}
456
457function host_state_sleep_action_handler()
458{
459 local SLED_NUM=$1
460 local ACTION=$2
461
462 case $ACTION in
463 "$ACTION_ON")
464 do_action_on "$SLED_NUM"
465 ;;
466 "$ACTION_OFF")
467 do_action_off "$SLED_NUM"
468 ;;
469 "$ACTION_AC_OFF")
470 do_action_ac_off "$SLED_NUM"
471 ;;
Potin Lai2320b0e2022-06-28 10:38:37 +0800472 "$ACTION_RESET")
473 do_action_reset "$SLED_NUM" "$HOST_ST_ON"
474 ;;
475 "$ACTION_CYCLE")
476 do_action_cycle "$SLED_NUM"
477 ;;
Potin Lai27083c32022-06-02 19:13:24 +0800478 *)
479 echo "Invalid action ($ACTION) for current host state (Sleep)"
480 return 1
481 ;;
482 esac
483}
484
485function host_state_off_action_handler()
486{
487 local SLED_NUM=$1
488 local ACTION=$2
489
490 case $ACTION in
491 "$ACTION_ON")
492 do_action_on "$SLED_NUM"
493 ;;
494 "$ACTION_RECOVERY")
495 do_action_recovery "$SLED_NUM"
496 ;;
497 "$ACTION_AC_OFF")
498 do_action_ac_off "$SLED_NUM"
499 ;;
Potin Lai2320b0e2022-06-28 10:38:37 +0800500 "$ACTION_RESET")
501 do_action_reset "$SLED_NUM" "$HOST_ST_ON"
502 ;;
503 "$ACTION_CYCLE")
504 do_action_cycle "$SLED_NUM"
505 ;;
Potin Lai27083c32022-06-02 19:13:24 +0800506 *)
507 echo "Invalid action ($ACTION) for current host state (Off)"
508 return 1
509 ;;
510 esac
511}
512
513function host_state_ac_off_action_handler()
514{
515 local SLED_NUM=$1
516 local ACTION=$2
517
518 case $ACTION in
519 "$ACTION_AC_ON")
520 do_action_ac_on "$SLED_NUM"
521 ;;
522 "$ACTION_DFU")
523 do_action_dfu "$SLED_NUM"
524 ;;
525 "$ACTION_AC_OFF")
526 echo "sled${SLED_NUM}: already ac off"
527 return 1
528 ;;
Potin Lai2320b0e2022-06-28 10:38:37 +0800529 "$ACTION_CYCLE")
530 do_action_reset "$SLED_NUM"
531 ;;
Potin Lai27083c32022-06-02 19:13:24 +0800532 *)
533 echo "Invalid action ($ACTION) for current host state (AC Off)"
534 return 1
535 ;;
536 esac
537}
538
539function host_state_ac_on_action_handler()
540{
541 local SLED_NUM=$1
542 local ACTION=$2
543
544 case $ACTION in
545 "$ACTION_AC_OFF")
546 do_action_ac_off "$SLED_NUM"
547 ;;
Potin Lai2320b0e2022-06-28 10:38:37 +0800548 "$ACTION_CYCLE")
549 do_action_cycle "$SLED_NUM"
550 ;;
Potin Lai27083c32022-06-02 19:13:24 +0800551 *)
552 echo "sled${SLED_NUM}: already ac on"
553 return 1
554 ;;
555 esac
556}
557
558function host_state_recovery_action_handler()
559{
560 local SLED_NUM=$1
561 local ACTION=$2
562
563 case $ACTION in
564 "$ACTION_OFF")
565 do_action_off "$SLED_NUM"
566 ;;
567 "$ACTION_AC_OFF")
568 do_action_ac_off "$SLED_NUM"
569 ;;
Potin Lai2320b0e2022-06-28 10:38:37 +0800570 "$ACTION_RESET")
571 do_action_reset "$SLED_NUM" "$HOST_ST_ON"
572 ;;
573 "$ACTION_CYCLE")
574 do_action_cycle "$SLED_NUM"
575 ;;
Potin Lai27083c32022-06-02 19:13:24 +0800576 *)
577 echo "Invalid action ($ACTION) for current host state (Recovery)"
578 return 1
579 ;;
580 esac
581}
582
583function host_state_dfu_action_handler()
584{
585 local SLED_NUM=$1
586 local ACTION=$2
587
588 case $ACTION in
589 "$ACTION_AC_OFF")
590 do_action_ac_off "$SLED_NUM"
591 ;;
Potin Lai2320b0e2022-06-28 10:38:37 +0800592 "$ACTION_CYCLE")
593 do_action_cycle "$SLED_NUM"
594 ;;
Potin Lai27083c32022-06-02 19:13:24 +0800595 *)
596 echo "Invalid action ($ACTION) for current host state (DFU)"
597 return 1
598 ;;
599 esac
600}
601
Potin Laidc251662022-04-01 11:16:50 +0800602function create_dev_mem()
603{
604 CHECK_CNT=0
605 while true
606 do
607 CHECK_CNT=$((CHECK_CNT+1))
608 if [ -c /dev/mem ]; then
609 # /dev/mem already exist
610 return 0
611 elif mknod /dev/mem c 1 1; then
612 # mknod success
613 return 0
614 elif [ "$CHECK_CNT" -ge 5 ]; then
615 break
616 fi
617 sleep 1
618 done
619
620 echo "create /dev/mem failed"
621 return 1
622}
623
Allen.Wang4a0948d2021-12-15 13:41:18 +0800624function show_usage(){
Potin Lai27083c32022-06-02 19:13:24 +0800625 echo "Usage: power-ctrl [sled1 | sled2 | sled3 | sled4 | sled5 | sled6] [$VALID_SLED_ACTIONS]"
Allen.Wang4a0948d2021-12-15 13:41:18 +0800626 echo " power-ctrl chassis-cycle"
627}
628
Potin Lai27083c32022-06-02 19:13:24 +0800629
Allen.Wang4a0948d2021-12-15 13:41:18 +0800630if [ $# -eq 1 ]; then
631 if [ "$1" = "chassis-cycle" ];then
632 echo "chassis cycle...."
633 i2cset -y -f 12 0x11 0xd9 c
634 exit 0
635 else
636 echo "Invalid argument: [ $1 ]"
637 show_usage
638 exit 1;
639 fi
640fi
641
642if [ $# -gt 2 ]; then
643 echo "Too many arguments"
644 show_usage
645 exit 1;
646fi
647
Allen.Wang5ff992e2022-01-04 21:00:38 +0800648if [[ "$1" =~ ^(sled[1-6]{1})$ ]]; then
Allen.Wang4a0948d2021-12-15 13:41:18 +0800649 SLED=$1
650 ACTION=$2
651 SLED_NUM=${SLED:4}
652else
653 echo "invalid sled name: ${1}"
654 show_usage
655 exit 1;
656fi
657
658#Check if sled is present
Potin Lai501f4c72022-06-13 13:23:57 +0800659if ! is_sled_present "${SLED_NUM}"; then
Allen.Wang4a0948d2021-12-15 13:41:18 +0800660 echo "${SLED} is not present!"
661 exit 1
Potin Lai27083c32022-06-02 19:13:24 +0800662elif ! is_valid_sled_action "$ACTION"; then
663 echo "Unknown action: $ACTION"
664 show_usage
665 exit 1
Allen.Wang4a0948d2021-12-15 13:41:18 +0800666fi
667
Potin Laia8d258f2022-06-14 18:35:10 +0800668if [ "$ACTION" = "$ACTION_AC_ON" ]; then
669 if [ "$(get_ac_status "$SLED_NUM")" = "$HOST_AC_OFF" ]; then
670 do_action_ac_on "$SLED_NUM"
671 fi
672elif [ "$ACTION" = "$ACTION_AC_OFF" ]; then
673 if [ "$(get_ac_status "$SLED_NUM")" != "$HOST_AC_OFF" ]; then
674 do_action_ac_off "$SLED_NUM"
675 fi
676elif [ "$ACTION" = "$ACTION_STATUS" ];then
677 HOST_CURR_STATUS=$(get_host_status "$SLED_NUM")
Potin Lai27083c32022-06-02 19:13:24 +0800678 echo "$HOST_CURR_STATUS"
Allen.Wang4a0948d2021-12-15 13:41:18 +0800679else
Potin Laia8d258f2022-06-14 18:35:10 +0800680 HOST_CURR_STATUS=$(get_host_status "$SLED_NUM")
Potin Lai27083c32022-06-02 19:13:24 +0800681 case $HOST_CURR_STATUS in
682 "$HOST_AC_OFF")
683 host_state_ac_off_action_handler "$SLED_NUM" "$ACTION"
684 ;;
685 "$HOST_AC_ON")
686 host_state_ac_on_action_handler "$SLED_NUM" "$ACTION"
687 ;;
688 "$HOST_ST_OFF")
689 host_state_off_action_handler "$SLED_NUM" "$ACTION"
690 ;;
691 "$HOST_ST_ON")
692 host_state_on_action_handler "$SLED_NUM" "$ACTION"
693 ;;
694 "$HOST_ST_SLEEP")
695 host_state_sleep_action_handler "$SLED_NUM" "$ACTION"
696 ;;
697 "$HOST_ST_DFU")
698 host_state_dfu_action_handler "$SLED_NUM" "$ACTION"
699 ;;
700 "$HOST_ST_RECOVERY")
701 host_state_recovery_action_handler "$SLED_NUM" "$ACTION"
702 ;;
703 esac
Allen.Wang4a0948d2021-12-15 13:41:18 +0800704fi