<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <br>
    <br>
    <div class="moz-cite-prefix">Le 26/04/2023 à 17:22, Frederic Barrat
      a écrit :<br>
    </div>
    <blockquote type="cite"
      cite="mid:2a504b8e-bac4-c36d-2312-427543904251@linux.ibm.com">
      <br>
      <br>
      On 29/04/2022 11:47, Christophe Lombard wrote:
      <br>
      <blockquote type="cite">Signed-off-by: Christophe Lombard
        <a class="moz-txt-link-rfc2396E" href="mailto:clombard@linux.vnet.ibm.com"><clombard@linux.vnet.ibm.com></a>
        <br>
      </blockquote>
      <br>
      <br>
      There's no commit message, so I'm not too sure of what the intent
      was.
      <br>
    </blockquote>
    <br>
    oups. Thanks<br>
    <br>
    <blockquote type="cite"
      cite="mid:2a504b8e-bac4-c36d-2312-427543904251@linux.ibm.com">My
      first reaction is: if the OS is making IPMI-specific calls and we
      don't have IPMI, why are we pretending? We should fix the OS.
      <br>
      <br>
    </blockquote>
    <br>
    <span class="HwtZe" lang="en"><span class="jCAhz ChMk0b"><span
          class="ryNqvb">The idea is to respond transparently to
          specific ipmi requests coming from opal calls, as we do for
          flash access requests via opal calls.</span></span></span><br>
    <br>
    <blockquote type="cite"
      cite="mid:2a504b8e-bac4-c36d-2312-427543904251@linux.ibm.com"> 
      Fred
      <br>
      <br>
      <br>
      <blockquote type="cite">---
        <br>
          core/pldm/Makefile.inc |   2 +-
        <br>
          core/pldm/pldm-opal.c  | 143
        +++++++++++++++++++++++++++++++++++++++++
        <br>
          include/pldm.h         |   5 ++
        <br>
          3 files changed, 149 insertions(+), 1 deletion(-)
        <br>
          create mode 100644 core/pldm/pldm-opal.c
        <br>
        <br>
        diff --git a/core/pldm/Makefile.inc b/core/pldm/Makefile.inc
        <br>
        index cf174c86..ebccb104 100644
        <br>
        --- a/core/pldm/Makefile.inc
        <br>
        +++ b/core/pldm/Makefile.inc
        <br>
        @@ -16,7 +16,7 @@ PLDM_OBJS = pldm-common.o pldm-responder.o
        pldm-requester.o
        <br>
          PLDM_OBJS += pldm-base-requests.o pldm-platform-requests.o
        <br>
          PLDM_OBJS += pldm-bios-requests.o pldm-fru-requests.o
        <br>
          PLDM_OBJS += pldm-file-io-requests.o pldm-lid-files.o
        <br>
        -PLDM_OBJS += pldm-watchdog.o pldm-rtc.o
        <br>
        +PLDM_OBJS += pldm-watchdog.o pldm-rtc.o pldm-opal.o
        <br>
            PLDM = $(PLDM_DIR)/built-in.a
        <br>
          $(PLDM): $(PLDM_OBJS:%=$(PLDM_DIR)/%)
        <br>
        diff --git a/core/pldm/pldm-opal.c b/core/pldm/pldm-opal.c
        <br>
        new file mode 100644
        <br>
        index 00000000..8aea0246
        <br>
        --- /dev/null
        <br>
        +++ b/core/pldm/pldm-opal.c
        <br>
        @@ -0,0 +1,143 @@
        <br>
        +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
        <br>
        +// Copyright 2022 IBM Corp.
        <br>
        +
        <br>
        +#define pr_fmt(fmt) "PLDM: " fmt
        <br>
        +
        <br>
        +#include <stdlib.h>
        <br>
        +#include <string.h>
        <br>
        +#include <device.h>
        <br>
        +#include <ipmi.h>
        <br>
        +#include <opal.h>
        <br>
        +#include <lock.h>
        <br>
        +#include <ccan/list/list.h>
        <br>
        +#include "pldm.h"
        <br>
        +
        <br>
        +static struct lock msgq_lock = LOCK_UNLOCKED;
        <br>
        +static struct list_head msgq = LIST_HEAD_INIT(msgq);
        <br>
        +
        <br>
        +/*
        <br>
        + * static void opal_send_complete(struct ipmi_msg *msg)
        <br>
        + * {
        <br>
        + *    lock(&msgq_lock);
        <br>
        + *    list_add_tail(&msgq, &msg->link);
        <br>
        + *   
        opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv,
        <br>
        + *                ipmi_backend->opal_event_ipmi_recv);
        <br>
        + *    unlock(&msgq_lock);
        <br>
        + * }
        <br>
        + */
        <br>
        +
        <br>
        +static int64_t opal_ipmi_send(uint64_t interface __unused,
        <br>
        +                  struct opal_ipmi_msg *opal_ipmi_msg, uint64_t
        msg_len)
        <br>
        +{
        <br>
        +    int16_t ipmi_code;
        <br>
        +
        <br>
        +    if (opal_ipmi_msg->version !=
        OPAL_IPMI_MSG_FORMAT_VERSION_1) {
        <br>
        +        prerror("OPAL IPMI: Incorrect version\n");
        <br>
        +        return OPAL_UNSUPPORTED;
        <br>
        +    }
        <br>
        +
        <br>
        +    msg_len -= sizeof(struct opal_ipmi_msg);
        <br>
        +    if (msg_len > IPMI_MAX_REQ_SIZE) {
        <br>
        +        prerror("OPAL IPMI: Invalid request length\n");
        <br>
        +        return OPAL_PARAMETER;
        <br>
        +    }
        <br>
        +
        <br>
        +    ipmi_code = IPMI_CODE(opal_ipmi_msg->netfn >> 2,
        opal_ipmi_msg->cmd);
        <br>
        +    if ((ipmi_code == IPMI_CHASSIS_GET_SYS_BOOT_OPT_CMD) ||
        <br>
        +        (opal_ipmi_msg->cmd ==
        IPMI_CODE(opal_ipmi_msg->netfn >> 2, 0x1a)) ||
        <br>
        +        (opal_ipmi_msg->cmd ==
        IPMI_CODE(opal_ipmi_msg->netfn >> 2, 0x42))) {
        <br>
        +        prerror("OPAL IPMI: Command not supported\n");
        <br>
        +        return OPAL_UNSUPPORTED;
        <br>
        +    }
        <br>
        +
        <br>
        +    prlog(PR_TRACE, "%s - cmd: 0x%02x netfn: 0x%02x len:
        0x%02llx\n",
        <br>
        +            __func__, opal_ipmi_msg->cmd,
        opal_ipmi_msg->netfn >> 2,
        <br>
        +            msg_len);
        <br>
        +
        <br>
        +    /* FIXME - Send PLDM requests
        <br>
        +     * IPMI_BMC_GET_DEVICE_ID     IPMI_CMD_GET_DEVICE_ID     
        0x01
        <br>
        +     * IPMI_CMD_GET_DEVICE_GUID                              
        0x08
        <br>
        +     * IPMI_SET_WDT                 
        IPMI_CMD_SET_WATCHDOG_TIMER 0x24
        <br>
        +     */
        <br>
        +    return OPAL_UNSUPPORTED;
        <br>
        +}
        <br>
        +
        <br>
        +static int64_t opal_ipmi_recv(uint64_t interface,
        <br>
        +                  struct opal_ipmi_msg *opal_ipmi_msg, __be64
        *msg_len)
        <br>
        +{
        <br>
        +    struct ipmi_msg *msg;
        <br>
        +    int64_t rc;
        <br>
        +
        <br>
        +    lock(&msgq_lock);
        <br>
        +    msg = list_top(&msgq, struct ipmi_msg, link);
        <br>
        +
        <br>
        +    if (!msg) {
        <br>
        +        rc = OPAL_EMPTY;
        <br>
        +        goto out_unlock;
        <br>
        +    }
        <br>
        +
        <br>
        +    if (opal_ipmi_msg->version !=
        OPAL_IPMI_MSG_FORMAT_VERSION_1) {
        <br>
        +        prerror("OPAL IPMI: Incorrect version\n");
        <br>
        +        rc = OPAL_UNSUPPORTED;
        <br>
        +        goto out_del_msg;
        <br>
        +    }
        <br>
        +
        <br>
        +    if (interface != IPMI_DEFAULT_INTERFACE) {
        <br>
        +        prerror("IPMI: Invalid interface 0x%llx in %s\n",
        interface, __func__);
        <br>
        +        rc = OPAL_PARAMETER;
        <br>
        +        goto out_del_msg;
        <br>
        +    }
        <br>
        +
        <br>
        +    if (be64_to_cpu(*msg_len) - sizeof(struct opal_ipmi_msg)
        < msg->resp_size + 1) {
        <br>
        +        rc = OPAL_RESOURCE;
        <br>
        +        goto out_del_msg;
        <br>
        +    }
        <br>
        +
        <br>
        +    list_del(&msg->link);
        <br>
        +    if (list_empty(&msgq))
        <br>
        +       
        opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv,
        0);
        <br>
        +    unlock(&msgq_lock);
        <br>
        +
        <br>
        +    opal_ipmi_msg->cmd = msg->cmd;
        <br>
        +    opal_ipmi_msg->netfn = msg->netfn;
        <br>
        +    opal_ipmi_msg->data[0] = msg->cc;
        <br>
        +    memcpy(&opal_ipmi_msg->data[1], msg->data,
        msg->resp_size);
        <br>
        +
        <br>
        +    prlog(PR_TRACE, "%s - cmd: 0x%02x netfn: 0x%02x resp_size:
        0x%02x\n",
        <br>
        +            __func__, msg->cmd, msg->netfn >> 2,
        msg->resp_size);
        <br>
        +
        <br>
        +    /* Add one as the completion code is returned in the
        message data */
        <br>
        +    *msg_len = cpu_to_be64(msg->resp_size + sizeof(struct
        opal_ipmi_msg) + 1);
        <br>
        +    ipmi_free_msg(msg);
        <br>
        +
        <br>
        +    return OPAL_SUCCESS;
        <br>
        +
        <br>
        +out_del_msg:
        <br>
        +    list_del(&msg->link);
        <br>
        +    if (list_empty(&msgq))
        <br>
        +       
        opal_update_pending_evt(ipmi_backend->opal_event_ipmi_recv,
        0);
        <br>
        +    ipmi_free_msg(msg);
        <br>
        +out_unlock:
        <br>
        +    unlock(&msgq_lock);
        <br>
        +    return rc;
        <br>
        +}
        <br>
        +
        <br>
        +void pldm_opal_init(void)
        <br>
        +{
        <br>
        +    struct dt_node *opal_ipmi, *opal_event = NULL;
        <br>
        +
        <br>
        +    opal_ipmi = dt_new(opal_node, "ipmi");
        <br>
        +    dt_add_property_strings(opal_ipmi, "compatible",
        "ibm,opal-ipmi");
        <br>
        +    dt_add_property_cells(opal_ipmi, "ibm,ipmi-interface-id",
        <br>
        +                  IPMI_DEFAULT_INTERFACE);
        <br>
        +    dt_add_property_cells(opal_ipmi, "interrupts",
        <br>
        +                 
        ilog2(ipmi_backend->opal_event_ipmi_recv));
        <br>
        +
        <br>
        +    opal_event = dt_find_by_name(opal_node, "event");
        <br>
        +    if (opal_event)
        <br>
        +        dt_add_property_cells(opal_ipmi, "interrupt-parent",
        <br>
        +                      opal_event->phandle);
        <br>
        +
        <br>
        +    opal_register(OPAL_IPMI_SEND, opal_ipmi_send, 3);
        <br>
        +    opal_register(OPAL_IPMI_RECV, opal_ipmi_recv, 3);
        <br>
        +}
        <br>
        diff --git a/include/pldm.h b/include/pldm.h
        <br>
        index 019e811f..8a91ee99 100644
        <br>
        --- a/include/pldm.h
        <br>
        +++ b/include/pldm.h
        <br>
        @@ -59,4 +59,9 @@ int pldm_platform_send_progress_state_change(
        <br>
           */
        <br>
          void pldm_rtc_init(void);
        <br>
          +/**
        <br>
        + * Register ipmi host interface access callbacks
        <br>
        + */
        <br>
        +void pldm_opal_init(void);
        <br>
        +
        <br>
          #endif /* __PLDM_H__ */
        <br>
      </blockquote>
    </blockquote>
    <br>
  </body>
</html>