+ return -1;
+
+ *persistent = !next_valid;
+ *bootdev = next_valid ? next_bootdev : default_bootdev;
+ return 0;
+}
+
+static int clear_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
+ bool persistent __attribute__((unused)))
+{
+ uint16_t resp_len;
+ uint8_t resp[1];
+ uint8_t req[] = {
+ 0x05, /* parameter selector: boot flags */
+ 0x80, /* data 1: valid */
+ 0x00, /* data 2: bootdev: no override */
+ 0x00, /* data 3: system defaults */
+ 0x00, /* data 4: no request for shared mode, mux defaults */
+ 0x00, /* data 5: no instance request */
+ };
+
+ resp_len = sizeof(resp);
+
+ ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS,
+ IPMI_CMD_CHASSIS_SET_SYSTEM_BOOT_OPTIONS,
+ req, sizeof(req),
+ resp, &resp_len,
+ ipmi_timeout);
+ return 0;
+}
+
+static int get_ipmi_bootdev_ipmi(struct platform_powerpc *platform,
+ uint8_t *bootdev, bool *persistent)
+{
+ uint16_t resp_len;
+ uint8_t resp[8];
+ int rc;
+ uint8_t req[] = {
+ 0x05, /* parameter selector: boot flags */
+ 0x00, /* no set selector */
+ 0x00, /* no block selector */
+ };
+
+ resp_len = sizeof(resp);
+ rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS,
+ IPMI_CMD_CHASSIS_GET_SYSTEM_BOOT_OPTIONS,
+ req, sizeof(req),
+ resp, &resp_len,
+ ipmi_timeout);
+ if (rc) {
+ pb_log("platform: error reading IPMI boot options\n");
+ return -1;
+ }
+
+ if (resp_len != sizeof(resp)) {
+ pb_log("platform: unexpected length (%d) in "
+ "boot options response\n", resp_len);
+ return -1;
+ }
+
+ pb_debug("IPMI get_bootdev response:\n");
+ for (int i = 0; i < resp_len; i++)
+ pb_debug("%x ", resp[i]);
+ pb_debug("\n");
+
+ if (resp[0] != 0) {
+ pb_log("platform: non-zero completion code %d from IPMI req\n",
+ resp[0]);
+ return -1;
+ }
+
+ /* check for correct parameter version */
+ if ((resp[1] & 0xf) != 0x1) {
+ pb_log("platform: unexpected version (0x%x) in "
+ "boot options response\n", resp[0]);
+ return -1;
+ }
+
+ /* check for valid paramters */
+ if (resp[2] & 0x80) {
+ pb_debug("platform: boot options are invalid/locked\n");
+ return -1;
+ }
+
+ *persistent = false;
+
+ /* check for valid flags */
+ if (!(resp[3] & 0x80)) {
+ pb_debug("platform: boot flags are invalid, ignoring\n");
+ return -1;
+ }
+
+ *persistent = resp[3] & 0x40;
+ *bootdev = (resp[4] >> 2) & 0x0f;
+ return 0;
+}
+
+static int set_ipmi_os_boot_sensor(struct platform_powerpc *platform)
+{
+ int sensor_number;
+ uint16_t resp_len;
+ uint8_t resp[1];
+ uint8_t req[] = {
+ 0x00, /* sensor number: os boot */
+ 0xA9, /* operation: set everything */
+ 0x00, /* sensor reading: none */
+ 0x40, /* assertion mask lsb: set state 6 */
+ 0x00, /* assertion mask msb: none */
+ 0x00, /* deassertion mask lsb: none */
+ 0x00, /* deassertion mask msb: none */
+ 0x00, /* event data 1: none */
+ 0x00, /* event data 2: none */
+ 0x00, /* event data 3: none */
+ };
+
+ sensor_number = get_ipmi_sensor(platform, IPMI_SENSOR_ID_OS_BOOT);
+ if (sensor_number < 0) {
+ pb_log("Couldn't find OS boot sensor in device tree\n");
+ return -1;
+ }
+
+ req[0] = sensor_number;
+
+ resp_len = sizeof(resp);
+
+ ipmi_transaction(platform->ipmi, IPMI_NETFN_SE,
+ IPMI_CMD_SENSOR_SET,
+ req, sizeof(req),
+ resp, &resp_len,
+ ipmi_timeout); return 0;
+
+ return 0;
+}
+
+static void get_ipmi_bmc_mac(struct platform *p, uint8_t *buf)
+{
+ struct platform_powerpc *platform = p->platform_data;
+ uint16_t resp_len = 8;
+ uint8_t resp[8];
+ uint8_t req[] = { 0x1, 0x5, 0x0, 0x0 };
+ int i, rc;
+
+ rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_TRANSPORT,
+ IPMI_CMD_TRANSPORT_GET_LAN_PARAMS,
+ req, sizeof(req),
+ resp, &resp_len,
+ ipmi_timeout);
+
+ pb_debug("BMC MAC resp [%d][%d]:\n", rc, resp_len);
+
+ if (rc == 0 && resp_len > 0) {
+ for (i = 2; i < resp_len; i++) {
+ pb_debug(" %x", resp[i]);
+ buf[i - 2] = resp[i];
+ }
+ pb_debug("\n");
+ }
+
+}
+
+/*
+ * Retrieve info from the "Get Device ID" IPMI commands.
+ * See Chapter 20.1 in the IPMIv2 specification.
+ */
+static void get_ipmi_bmc_versions(struct platform *p, struct system_info *info)
+{
+ struct platform_powerpc *platform = p->platform_data;
+ uint16_t resp_len = 16;
+ uint8_t resp[16], bcd;
+ int i, rc;
+
+ /* Retrieve info from current side */
+ rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_APP,
+ IPMI_CMD_APP_GET_DEVICE_ID,
+ NULL, 0,
+ resp, &resp_len,
+ ipmi_timeout);
+
+ pb_debug("BMC version resp [%d][%d]:\n", rc, resp_len);
+ if (resp_len > 0) {
+ for (i = 0; i < resp_len; i++) {
+ pb_debug(" %x", resp[i]);
+ }
+ pb_debug("\n");
+ }
+
+ if (rc == 0 && (resp_len == 12 || resp_len == 16)) {
+ info->bmc_current = talloc_array(info, char *, 4);
+ info->n_bmc_current = 4;
+
+ info->bmc_current[0] = talloc_asprintf(info, "Device ID: 0x%x",
+ resp[1]);
+ info->bmc_current[1] = talloc_asprintf(info, "Device Rev: 0x%x",
+ resp[2]);
+ bcd = resp[4] & 0x0f;
+ bcd += 10 * (resp[4] >> 4);
+ /* rev1.rev2.aux_revision */
+ info->bmc_current[2] = talloc_asprintf(info,
+ "Firmware version: %u.%02u",
+ resp[3], bcd);
+ if (resp_len == 16) {
+ info->bmc_current[2] = talloc_asprintf_append(
+ info->bmc_current[2],
+ ".%02x%02x%02x%02x",
+ resp[12], resp[13], resp[14], resp[15]);
+ }
+ bcd = resp[5] & 0x0f;
+ bcd += 10 * (resp[5] >> 4);
+ info->bmc_current[3] = talloc_asprintf(info, "IPMI version: %u",
+ bcd);
+ } else
+ pb_log("Failed to retrieve Device ID from IPMI\n");
+
+ /* Retrieve info from golden side */
+ memset(resp, 0, sizeof(resp));
+ resp_len = 16;
+ rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_AMI,
+ IPMI_CMD_APP_GET_DEVICE_ID_GOLDEN,
+ NULL, 0,
+ resp, &resp_len,
+ ipmi_timeout);
+
+ pb_debug("BMC golden resp [%d][%d]:\n", rc, resp_len);
+ if (resp_len > 0) {
+ for (i = 0; i < resp_len; i++) {
+ pb_debug(" %x", resp[i]);
+ }
+ pb_debug("\n");
+ }
+
+ if (rc == 0 && (resp_len == 12 || resp_len == 16)) {
+ info->bmc_golden = talloc_array(info, char *, 4);
+ info->n_bmc_golden = 4;
+
+ info->bmc_golden[0] = talloc_asprintf(info, "Device ID: 0x%x",
+ resp[1]);
+ info->bmc_golden[1] = talloc_asprintf(info, "Device Rev: 0x%x",
+ resp[2]);
+ bcd = resp[4] & 0x0f;
+ bcd += 10 * (resp[4] >> 4);
+ /* rev1.rev2.aux_revision */
+ info->bmc_golden[2] = talloc_asprintf(info,
+ "Firmware version: %u.%02u",
+ resp[3], bcd);
+ if (resp_len == 16) {
+ info->bmc_golden[2] = talloc_asprintf_append(
+ info->bmc_golden[2],
+ ".%02x%02x%02x%02x",
+ resp[12], resp[13], resp[14], resp[15]);
+ }
+ bcd = resp[5] & 0x0f;
+ bcd += 10 * (resp[5] >> 4);
+ info->bmc_golden[3] = talloc_asprintf(info, "IPMI version: %u",
+ bcd);
+ } else
+ pb_log("Failed to retrieve Golden Device ID from IPMI\n");
+}
+
+static void get_ipmi_network_override(struct platform_powerpc *platform,
+ struct config *config)
+{
+ uint16_t min_len = 12, resp_len = 53, version;
+ const uint32_t magic_value = 0x21706221;
+ uint8_t resp[resp_len];
+ uint32_t cookie;
+ bool persistent;
+ int i, rc;
+ uint8_t req[] = {
+ 0x61, /* parameter selector: OEM section (network) */
+ 0x00, /* no set selector */
+ 0x00, /* no block selector */
+ };
+
+ rc = ipmi_transaction(platform->ipmi, IPMI_NETFN_CHASSIS,
+ IPMI_CMD_CHASSIS_GET_SYSTEM_BOOT_OPTIONS,
+ req, sizeof(req),
+ resp, &resp_len,
+ ipmi_timeout);
+
+ pb_debug("IPMI net override resp [%d][%d]:\n", rc, resp_len);
+ if (resp_len > 0) {
+ for (i = 0; i < resp_len; i++) {
+ pb_debug(" %02x", resp[i]);
+ if (i && (i + 1) % 16 == 0 && i != resp_len - 1)
+ pb_debug("\n");
+ else if (i && (i + 1) % 8 == 0)
+ pb_debug(" ");
+ }
+ pb_debug("\n");
+ }
+
+ if (rc) {
+ pb_debug("IPMI network config option unavailable\n");
+ return;
+ }
+
+ if (resp_len < min_len) {
+ pb_debug("IPMI net response too small\n");
+ return;
+ }
+
+ if (resp[0] != 0) {
+ pb_log("platform: non-zero completion code %d from IPMI network req\n",
+ resp[0]);