[RFC PATCH linux v6 2/9] hwmon: Add core On-Chip Controller support for POWER CPUs

Yi TZ Li shliyi at cn.ibm.com
Wed Nov 30 14:50:29 AEDT 2016


Hi Edward,

I was concerned with bellow piece of code when writing P8 occ driver.
Referring to occ spec:
https://github.com/open-power/docs/blob/master/occ/OCC_OpenPwr_FW_Interfaces.pdf
Section: 1.6.2 OCC Command/Response Sequence and Appendix A: Return codes.

OCC responds a command with different return code. Currently, the occ
driver regards any return code
other than 0x0 (Succeed) as error. But we may need to handle occ return
code properly,
e.g: for 0xFF (command in progress), we might not regard it as an error.

> +
> +static u8 occ_send_cmd(struct occ *driver, u8 seq, u8 type, u16 length,
> +             u8 *data, u8 *resp)
> +{
> +   u32 cmd1, cmd2;
> +   u16 checksum;
> +   int i;
> +
> +   length = cpu_to_le16(length);
> +   cmd1 = (seq << 24) | (type << 16) | length;
> +   memcpy(&cmd2, data, length);
> +   cmd2 <<= ((4 - length) * 8);
> +
> +   /* checksum: sum of every bytes of cmd1, cmd2 */
> +   checksum = 0;
> +   for (i = 0; i < 4; i++)
> +      checksum += (cmd1 >> (i * 8)) & 0xFF;
> +   for (i = 0; i < 4; i++)
> +      checksum += (cmd2 >> (i * 8)) & 0xFF;
> +   cmd2 |= checksum << ((2 - length) * 8);
> +
> +   /* Init OCB */
> +   driver->bus_ops.putscom(driver->bus, OCB_STATUS_CONTROL_OR,
0x08000000,
> +            0x00000000);
> +   driver->bus_ops.putscom(driver->bus, OCB_STATUS_CONTROL_AND,
> +            0xFBFFFFFF, 0xFFFFFFFF);
> +
> +   /* Send command */
> +   driver->bus_ops.putscom(driver->bus, OCB_ADDRESS,
> +            driver->config.command_addr, 0x00000000);
> +   driver->bus_ops.putscom(driver->bus, OCB_ADDRESS,
> +            driver->config.command_addr, 0x00000000);
> +   driver->bus_ops.putscom(driver->bus, OCB_DATA, cmd1, cmd2);
> +
> +   /* Trigger attention */
> +   driver->bus_ops.putscom(driver->bus, ATTN_DATA, 0x01010000,
> +            0x00000000);
> +
> +   /* Get response data */
> +   driver->bus_ops.putscom(driver->bus, OCB_ADDRESS,
> +            driver->config.response_addr, 0x00000000);
> +   driver->bus_ops.getscom(driver->bus, OCB_DATA, resp, 0);
> +
> +   /* return status */
> +   return resp[2];
> +}
> +

Thanks,
-Yi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20161130/08a427f9/attachment.html>


More information about the openbmc mailing list