Add sys command for powercycle on host shutdown.

The new command will trigger a power cycle the next time the host shuts
down. This can exist in parallel with the existing mechanism to trigger
a power cycle after a specified time interval.

The implementation of host state detection and power cycling is platfrom
specific; the new command will just add a temporary file that marks the
system ready to powercycle on the next shutdown. Usually, a systemd unit
would be enabled by the presence of this file to handle the power
cycling process.

Signed-off-by: Shounak Mitra <shounak@google.com>
Change-Id: I0cc40307748fb996be3f6062d8cba1a4b5049683
10 files changed
tree: f946c34900380601a21cb1246d4aca84ed3a98f8
  1. test/
  2. .clang-format
  3. .gitignore
  4. .lcovrc
  5. bootstrap.sh
  6. cable.cpp
  7. cable.hpp
  8. commands.hpp
  9. configure.ac
  10. cpld.cpp
  11. cpld.hpp
  12. entity_name.cpp
  13. entity_name.hpp
  14. errors.hpp
  15. eth.cpp
  16. eth.hpp
  17. gbmc-psu-hardreset.target
  18. handler.cpp
  19. handler.hpp
  20. handler_impl.hpp
  21. ipmi.cpp
  22. ipmi.hpp
  23. LICENSE
  24. machine_name.cpp
  25. machine_name.hpp
  26. main.cpp
  27. MAINTAINERS
  28. Makefile.am
  29. pcie_i2c.cpp
  30. pcie_i2c.hpp
  31. psu.cpp
  32. psu.hpp
  33. README.md
  34. util.cpp
  35. util.hpp
README.md

Sys Commands (0x32)

There are and will be a variety of sys specific commands.

Cablecheck - SubCommand 0x00

The cablecheck command checks whether the BMC is seeing traffic between itself and the host's NIC. Sys specifies which if_name is expected to be connected. The BMC presently only checks traffic on the interface specified. There are now ethernet statistics available over IPMI, which can be checked directly in lieu of this.

Request

Byte(s)ValueData
0x000x00Subcommand
0x01If_name lengthWhere you expect the cable, eth0 or eth1, etc
0x02 ...The nameThe string, not null-terminated

Response

Byte(s)ValueData
0x000x00Subcommand
0x010x00/0x010 for false, 1 for true

CpldVersion - SubCommand 0x01

Any CPLD on the system that can only be read directly via the BMC can have its version exported to Sys via the cpld version command.

Request

Byte(s)ValueData
0x000x01Subcommand
0x01CPLD IDA one-byte identifier for the CPLD file to read, unsigned byte.

Response

Byte(s)ValueData
0x000x01Subcommand
0x01MajorMajor version
0x02MinorMinor Version
0x03Sub 1Third version number
0x04Sub 2Fourth version number

Per the above, if the version number doesn't fit in a byte it'll be cast to size.

GetNcsiEthDevice - SubCommand 0x02

The BMC itself must have hard-coded into the image, which ethernet device is connected to the host NIC. This is true also in the mapping of ethernet device to channel number. The channel number is used to configure the ethernet device over IPMI, instead of the interface name. This is because we leverage the current IPMI command set to read and write the networking configuration. Sys can be programmed already to have this information in the board protobuf, however, this information -- can be read from the BMC over IPMI.

Request

Byte(s)ValueData
0x000x02Subcommand

Response

Byte(s)ValueData
0x000x02Subcommand
0x01Channel numberThe IPMI channel number for use with the network configuration commands (such as reading the MAC or IP address of the BMC).
0x02if_name lengthThe length of the if_name in bytes.
0x03...if_nameThe interface name, not null-terminated

DelayedHardReset - SubCommand 0x03

Sys needs to be able to tell the BMC to reset the host but given a delay in seconds.

Request

Byte(s)ValueData
0x000x03Subcommand
0x01..0x04Seconds to delay (uint32)

Response

Byte(s)ValueData
0x000x03Subcommand

GetPCIeSlotsCount - SubCommand 0x04

Sys can get the total number of PCIe slots from BMC using this command. When BMC receives this command, BMC can enumerate over all the PCIe slots and create a hashmap with all the available PCIe slot name - I2C bus number mappings. BMC can then send the total number of PCIe slots as part of this command response.

Request

Byte(s)ValueData
0x000x04Subcommand

Response

Byte(s)ValueData
0x000x04Subcommand
0x01Total number of PCIe slotsTotal number of PCIe slots

GetPCIeSlotI2cBusMapping - SubCommand 0x05

If Sys gets N total slots as part of the above command, then Sys can send this command N times with Entry IDs ranging from 0 to N - 1. Say, Sys sends this command with Entry ID as 1, BMC can go and fetch the first PCIe slot name - I2C bus number mapping from the hashmap created above and then send the PCIe slot name and I2C bus number as part of the command response.

Request

Byte(s)ValueData
0x000x05Subcommand
0x01Entry IDEntry ID ranging from 0 to N - 1

Response

Byte(s)ValueData
0x000x05Subcommand
0x01I2C bus numberThe I2C bus number which is input to the above PCIe slot
0x02PCIe slot name lengthThe PCIe slot name length
0x03...PCIe slot nameThe PCIe slot name without null terminator

GetEntityName - SubCommand 0x06

Gsys can get the "Entity ID:Entity Instance" to Entity name mapping from BMC using this command. When BMC receives this command, BMC can check the related JSON file and then send the name for that particular entity as this command response.

Request

Byte(s)ValueData
0x000x06Subcommand
0x01Entity IDEntity ID
0x02Entity InstanceEntity Instance

Response

Byte(s)ValueData
0x000x06Subcommand
0x01Entity name length (say N)Entity name length
0x02...0x02 + N - 1Entity nameEntity name without null terminator

GetMachineName - SubCommand 0x07

The BMC parses /etc/os-release for the OPENBMC_TARGET_MACHINE field and returns its value.

Request

Byte(s)ValueData
0x000x06Subcommand

Response

Byte(s)ValueData
0x000x06Subcommand
0x01Model name length (say N)Model name length
0x02...0x02 + N - 1Model nameModel name without null terminator

HardResetOnShutdown - SubCommand 0x08

Tells the BMC to powercycle the next time the host shuts down.

Request

Byte(s)ValueData
0x000x08Subcommand

Response

Byte(s)ValueData
0x000x08Subcommand