|
| 1 | +/* Copyright 2018 IBM Corp. |
| 2 | + * |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 12 | + * implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <device.h> |
| 18 | +#include <skiboot.h> |
| 19 | +#include <stdlib.h> |
| 20 | +#include <ipmi.h> |
| 21 | +#include <mem_region-malloc.h> |
| 22 | +#include <opal.h> |
| 23 | +#include <timebase.h> |
| 24 | + |
| 25 | +/* |
| 26 | + * Respones data from IPMI Get device ID command (As defined in |
| 27 | + * Section 20.1 Get Device ID Command - IPMI standard spec). |
| 28 | + */ |
| 29 | +struct ipmi_dev_id { |
| 30 | + uint8_t dev_id; |
| 31 | + uint8_t dev_revision; |
| 32 | + uint8_t fw_rev1; |
| 33 | + uint8_t fw_rev2; |
| 34 | + uint8_t ipmi_ver; |
| 35 | + uint8_t add_dev_support; |
| 36 | + uint8_t manufactur_id[3]; |
| 37 | + uint8_t product_id[2]; |
| 38 | + uint8_t aux_fw_rev[4]; |
| 39 | +}; |
| 40 | +static struct ipmi_dev_id *ipmi_dev_id; |
| 41 | + |
| 42 | +/* Got response from BMC? */ |
| 43 | +static bool bmc_info_waiting = false; |
| 44 | +static bool bmc_info_valid = false; |
| 45 | + |
| 46 | +/* This will free ipmi_dev_id structure */ |
| 47 | +void ipmi_dt_add_bmc_info(void) |
| 48 | +{ |
| 49 | + char buf[8]; |
| 50 | + struct dt_node *dt_fw_version; |
| 51 | + |
| 52 | + while (bmc_info_waiting) |
| 53 | + time_wait_ms(5); |
| 54 | + |
| 55 | + if (!bmc_info_valid) |
| 56 | + return; |
| 57 | + |
| 58 | + dt_fw_version = dt_find_by_name(dt_root, "ibm,firmware-versions"); |
| 59 | + if (!dt_fw_version) { |
| 60 | + free(ipmi_dev_id); |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + memset(buf, 0, sizeof(buf)); |
| 65 | + snprintf(buf, sizeof(buf), "%x.%02x", |
| 66 | + ipmi_dev_id->fw_rev1, ipmi_dev_id->fw_rev2); |
| 67 | + dt_add_property_string(dt_fw_version, "bmc-firmware-version", buf); |
| 68 | + |
| 69 | + free(ipmi_dev_id); |
| 70 | +} |
| 71 | + |
| 72 | +static void ipmi_get_bmc_info_resp(struct ipmi_msg *msg) |
| 73 | +{ |
| 74 | + bmc_info_waiting = false; |
| 75 | + |
| 76 | + if (msg->cc != IPMI_CC_NO_ERROR) { |
| 77 | + prlog(PR_ERR, "IPMI: IPMI_BMC_GET_DEVICE_ID cmd returned error" |
| 78 | + " [rc : 0x%x]\n", msg->data[0]); |
| 79 | + return; |
| 80 | + } |
| 81 | + |
| 82 | + bmc_info_valid = true; |
| 83 | + memcpy(ipmi_dev_id, msg->data, msg->resp_size); |
| 84 | + ipmi_free_msg(msg); |
| 85 | +} |
| 86 | + |
| 87 | +int ipmi_get_bmc_info_request(void) |
| 88 | +{ |
| 89 | + int rc; |
| 90 | + struct ipmi_msg *msg; |
| 91 | + |
| 92 | + ipmi_dev_id = zalloc(sizeof(struct ipmi_dev_id)); |
| 93 | + assert(ipmi_dev_id); |
| 94 | + |
| 95 | + msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE, IPMI_BMC_GET_DEVICE_ID, |
| 96 | + ipmi_get_bmc_info_resp, NULL, NULL, |
| 97 | + 0, sizeof(struct ipmi_dev_id)); |
| 98 | + if (!msg) |
| 99 | + return OPAL_NO_MEM; |
| 100 | + |
| 101 | + msg->error = ipmi_get_bmc_info_resp; |
| 102 | + prlog(PR_INFO, "IPMI: Requesting IPMI_BMC_GET_DEVICE_ID\n"); |
| 103 | + rc = ipmi_queue_msg(msg); |
| 104 | + if (rc) { |
| 105 | + prlog(PR_ERR, "IPMI: Failed to queue IPMI_BMC_GET_DEVICE_ID\n"); |
| 106 | + ipmi_free_msg(msg); |
| 107 | + return rc; |
| 108 | + } |
| 109 | + |
| 110 | + bmc_info_waiting = true; |
| 111 | + return rc; |
| 112 | +} |
0 commit comments