Exemple #1
0
/* This will free ipmi_sys_boot_opt structure */
int ipmi_chassis_check_sbe_validation(void)
{
	int rc = -1;

	while (bmc_boot_opt_waiting)
		time_wait_ms(10);

	if (!bmc_boot_opt_valid)
		goto out;

	if ((ipmi_sys_boot_opt->param_valid & 0x8) != 0)
		goto out;
	if (ipmi_sys_boot_opt->param_valid != 0x62)
		goto out;

	rc = ipmi_sys_boot_opt->flag_set;

out:
	free(ipmi_sys_boot_opt);
	return rc;
}
Exemple #2
0
/* This will free ipmi_dev_id structure */
void ipmi_dt_add_bmc_info(void)
{
	char buf[8];
	struct dt_node *dt_fw_version;

	while (bmc_info_waiting)
		time_wait_ms(5);

	if (!bmc_info_valid)
		return;

	dt_fw_version = dt_find_by_name(dt_root, "ibm,firmware-versions");
	if (!dt_fw_version) {
		free(ipmi_dev_id);
		return;
	}

	memset(buf, 0, sizeof(buf));
	snprintf(buf, sizeof(buf), "%x.%02x",
		 ipmi_dev_id->fw_rev1, ipmi_dev_id->fw_rev2);
	dt_add_property_string(dt_fw_version, "bmc-firmware-version", buf);

	free(ipmi_dev_id);
}
/**
 * tpm_i2c_request_send - send request to i2c bus
 * @tpm_bus_id: i2c bus id
 * @tpm_dev_addr: address of the tpm device
 * @read_write: SMBUS_READ or SMBUS_WRITE
 * @offset: any of the I2C interface offset defined
 * @offset_bytes: offset size in bytes
 * @buf: data to be read or written
 * @buflen: buf length
 *
 * This interacts with skiboot i2c API to send an I2C request to the tpm
 * device
 *
 * Returns: Zero on success otherwise a negative error code
 */
int tpm_i2c_request_send(int tpm_bus_id, int tpm_dev_addr, int read_write,
			 uint32_t offset, uint32_t offset_bytes, void* buf,
			 size_t buflen)
{
	int rc, waited, retries, timeout;
	struct i2c_request *req;
	struct i2c_bus *bus;

	bus = i2c_find_bus_by_id(tpm_bus_id);
	if (!bus) {
		/**
		 * @fwts-label TPMI2CInvalidBusID
		 * @fwts-advice tpm_i2c_request_send was passed an invalid bus
		 * ID. This indicates a tb_init() bug.
		 */
		prlog(PR_ERR, "TPM: Invalid bus_id=%x\n", tpm_bus_id);
		rc = STB_ARG_ERROR;
		goto out;
	}

	req = i2c_alloc_req(bus);
	if (!req) {
		/**
		 * @fwts-label TPMI2CAllocationFailed
		 * @fwts-advice OPAL failed to allocate memory for an
		 * i2c_request. This points to an OPAL bug as OPAL run out of
		 * memory and this should never happen.
		 */
		prlog(PR_ERR, "TPM: i2c_alloc_req failed\n");
		rc = STB_DRIVER_ERROR;
		goto out;
	}

	req->dev_addr   = tpm_dev_addr;
	req->op         = read_write;
	req->offset     = offset;
	req->offset_bytes = offset_bytes;
	req->rw_buf     = (void*) buf;
	req->rw_len     = buflen;
	req->completion = tpm_i2c_request_complete;
	req->user_data = &rc;

	/*
	 * Set the request timeout to 10ms per byte. Otherwise, we get
	 * an I2C master timeout for all requests sent to the TPM device
	 * since the I2C master's timeout is too short (1ms per byte).
	 */
	timeout = (buflen + offset_bytes + 2) * I2C_BYTE_TIMEOUT_MS;
	i2c_set_req_timeout(req, timeout);

	for (retries = 0; retries <= TPM_MAX_NACK_RETRIES; retries++) {
		rc = 1;
		waited = 0;
		i2c_queue_req(req);

		do {
			time_wait_ms(REQ_COMPLETE_POLLING);
			waited += REQ_COMPLETE_POLLING;
		} while (waited < timeout && rc == 1);

		if (rc == OPAL_I2C_NACK_RCVD)
			continue;
		else
			/* error or success */
			break;
	}

	DBG("%s tpm req op=%x offset=%x buf=%016llx buflen=%d delay=%d/%d,"
	    "rc=%d\n",
	    (rc) ? "!!!!" : "----", req->op, req->offset,
	    *(uint64_t*) buf, req->rw_len, waited, timeout, rc);

	i2c_free_req(req);
	if (rc)
		rc = STB_DRIVER_ERROR;
out:
	return rc;
}