From patchwork Tue Oct 9 07:32:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 981068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42TpqT19t7z9s9G for ; Tue, 9 Oct 2018 18:33:09 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="EsLk9jIm"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="g/NvvSdP"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42TpqS6fQjzF3CT for ; Tue, 9 Oct 2018 18:33:08 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="EsLk9jIm"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="g/NvvSdP"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=aj.id.au (client-ip=66.111.4.27; helo=out3-smtp.messagingengine.com; envelope-from=andrew@aj.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="EsLk9jIm"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="g/NvvSdP"; dkim-atps=neutral Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42TpqD1SppzF3BW for ; Tue, 9 Oct 2018 18:32:55 +1100 (AEDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 83BD421F38; Tue, 9 Oct 2018 03:32:53 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 09 Oct 2018 03:32:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=from :to:cc:subject:date:message-id:in-reply-to:references; s=fm3; bh=DJUvCVYCboiVWOI35UCMpS0PJwVnFng506h8NRDZTh4=; b=EsLk9jImnE1F o25bYjNRJ5nb1g2Xfs86HH6xt/SWWqhk9Ii+fUgVu7b9RgxITZ3cI72gDSLyocb1 Bk9qgl9Wp1CRJ0XZAPSace/aZqRGgWZ5lu43kCtFnTVFuQHNLs+fpxW/5J4O2TlY Ii06+sjpB4gsxsYulZGhSOmsCy5u13wFpAzHiaQvwYA9GYbP/oF4NZb6bMHVr21Z tR/0POQ3v98E+Ic09v1h6pj0tO7hL8PRR+HrdHPuHjAEzFwSGQc18buL61F1gBQ8 xayU5kM7t3eeoa1t+C2+ji9pRVsaAbcHTLRkaahN9zvy/rKYpY8KBI0lrZ3pG6yU twdz5zoDzQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=DJUvCVYCboiVWOI35UCMpS0PJwVnF ng506h8NRDZTh4=; b=g/NvvSdPIvR6lK5d4iW9DcusFFCw3M1l3TDYFlSIbP0hO 05m/rg4oC3M+wvZbmAogZEW5G3jl6640MUFJrh/np/4Zj2RNmHQbTs7EOW5ndZ3t dVvVsmHVBH3KGtRfsK1UORtOgXQrY42iVDInZgc/TF0wbOUaCvBZ3aCEFa10gIo4 cpgeXmKHL+4RZjwrZLoqZGeeP0S0MjkrcwmPGFS1UwfhckBI+RRc2pdCLueoVfnQ Oxi1FhIorPk16zD09U+kklTYhtGdOBGVnO0GkqmvMoBlerHtd8OuoEjFjmExy5b4 PFHfXmp/wcV43Qzg+1nMEeTnz7NenlycbVOBLw9oQ== X-ME-Sender: X-ME-Proxy: Received: from dave.ibm.com (50-203-181-99-static.hfc.comcastbusiness.net [50.203.181.99]) by mail.messagingengine.com (Postfix) with ESMTPA id 1FFC2E4307; Tue, 9 Oct 2018 03:32:52 -0400 (EDT) From: Andrew Jeffery To: skiboot@lists.ozlabs.org Date: Tue, 9 Oct 2018 00:32:27 -0700 Message-Id: <20181009073237.16251-2-andrew@aj.id.au> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181009073237.16251-1-andrew@aj.id.au> References: <20181009073237.16251-1-andrew@aj.id.au> Subject: [Skiboot] [PATCH v3 01/11] ipmi: Introduce registration for SEL command handlers X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dkodihal@in.ibm.com, Andrew Jeffery , anoo@linux.ibm.com MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Andrew Jeffery --- hw/ipmi/ipmi-sel.c | 118 ++++++++++++++++++++++++++++++++++----------- include/ipmi.h | 5 ++ 2 files changed, 94 insertions(+), 29 deletions(-) diff --git a/hw/ipmi/ipmi-sel.c b/hw/ipmi/ipmi-sel.c index eb63147bdc52..cfcd1d424596 100644 --- a/hw/ipmi/ipmi-sel.c +++ b/hw/ipmi/ipmi-sel.c @@ -15,6 +15,10 @@ */ #define pr_fmt(fmt) "IPMI: " fmt +#include +#include +#include +#include #include #include #include @@ -37,10 +41,14 @@ #define SEL_NETFN_IBM 0x3a /* OEM SEL Commands */ +/* TODO: Move these to their respective source files */ #define CMD_AMI_POWER 0x04 #define CMD_AMI_PNOR_ACCESS 0x07 #define CMD_AMI_OCC_RESET 0x0e +/* XXX: Listed here for completeness, registered in libflash/ipmi-flash.c */ +#define CMD_OP_HIOMAP_EVENT 0x0f + #define SOFT_OFF 0x00 #define SOFT_REBOOT 0x01 @@ -137,21 +145,11 @@ struct ipmi_sel_panic_msg { }; static struct ipmi_sel_panic_msg ipmi_sel_panic_msg; +static LIST_HEAD(sel_handlers); + /* Forward declaration */ static void ipmi_elog_poll(struct ipmi_msg *msg); -void ipmi_sel_init(void) -{ - /* Already done */ - if (ipmi_sel_panic_msg.msg != NULL) - return; - - memset(&ipmi_sel_panic_msg, 0, sizeof(struct ipmi_sel_panic_msg)); - ipmi_sel_panic_msg.msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE, - IPMI_RESERVE_SEL, ipmi_elog_poll, - NULL, NULL, IPMI_MAX_REQ_SIZE, 2); -} - /* * Allocate IPMI message: * For normal event, allocate memory using ipmi_mkmsg and for PANIC @@ -458,7 +456,7 @@ int ipmi_elog_commit(struct errorlog *elog_buf) #define ACCESS_DENIED 0x00 #define ACCESS_GRANTED 0x01 -static void sel_pnor(uint8_t access) +static void sel_pnor(uint8_t access, void *context __unused) { struct ipmi_msg *msg; uint8_t granted = ACCESS_GRANTED; @@ -501,7 +499,7 @@ static void sel_pnor(uint8_t access) } } -static void sel_power(uint8_t power) +static void sel_power(uint8_t power, void *context __unused) { switch (power) { case SOFT_OFF: @@ -562,7 +560,7 @@ static uint32_t occ_sensor_id_to_chip(uint8_t sensor, uint32_t *chip) return 0; } -static void sel_occ_reset(uint8_t sensor) +static void sel_occ_reset(uint8_t sensor, void *context __unused) { uint32_t chip; int rc; @@ -581,8 +579,77 @@ static void sel_occ_reset(uint8_t sensor) prd_occ_reset(chip); } +struct ipmi_sel_handler { + uint8_t oem_cmd; + void (*fn)(uint8_t data, void *context); + void *context; + struct list_node node; +}; + +int ipmi_sel_register(uint8_t oem_cmd, + void (*fn)(uint8_t data, void *context), + void *context) +{ + struct ipmi_sel_handler *handler; + + list_for_each(&sel_handlers, handler, node) { + if (handler->oem_cmd == oem_cmd) { + prerror("Handler for SEL command 0x%02x already registered\n", + oem_cmd); + return -EINVAL; + } + } + + handler = malloc(sizeof(*handler)); + if (!handler) + return -ENOMEM; + + handler->oem_cmd = oem_cmd; + handler->fn = fn; + handler->context = context; + + list_add(&sel_handlers, &handler->node); + + return 0; +} + +void ipmi_sel_init(void) +{ + int rc; + + /* Already done */ + if (ipmi_sel_panic_msg.msg != NULL) + return; + + memset(&ipmi_sel_panic_msg, 0, sizeof(struct ipmi_sel_panic_msg)); + ipmi_sel_panic_msg.msg = ipmi_mkmsg(IPMI_DEFAULT_INTERFACE, + IPMI_RESERVE_SEL, ipmi_elog_poll, + NULL, NULL, IPMI_MAX_REQ_SIZE, 2); + + /* Hackishly register these old-style handlers here for now */ + /* TODO: Move them to their appropriate source files */ + rc = ipmi_sel_register(CMD_AMI_POWER, sel_power, NULL); + if (rc < 0) { + prerror("Failed to register SEL handler for %s", + stringify(CMD_AMI_POWER)); + } + + rc = ipmi_sel_register(CMD_AMI_OCC_RESET, sel_occ_reset, NULL); + if (rc < 0) { + prerror("Failed to register SEL handler for %s", + stringify(CMD_AMI_OCC_RESET)); + } + + rc = ipmi_sel_register(CMD_AMI_PNOR_ACCESS, sel_pnor, NULL); + if (rc < 0) { + prerror("Failed to register SEL handler for %s", + stringify(CMD_AMI_PNOR_ACCESS)); + } +} + void ipmi_parse_sel(struct ipmi_msg *msg) { + struct ipmi_sel_handler *handler; struct oem_sel sel; assert(msg->resp_size <= 16); @@ -606,19 +673,12 @@ void ipmi_parse_sel(struct ipmi_msg *msg) return; } - switch (sel.cmd) { - case CMD_AMI_POWER: - sel_power(sel.data[0]); - break; - case CMD_AMI_OCC_RESET: - sel_occ_reset(sel.data[0]); - break; - case CMD_AMI_PNOR_ACCESS: - sel_pnor(sel.data[0]); - break; - default: - prlog(PR_WARNING, - "unknown OEM SEL command %02x received\n", - sel.cmd); + list_for_each(&sel_handlers, handler, node) { + if (handler->oem_cmd == sel.cmd) { + handler->fn(sel.data[0], handler->context); + return; + } } + + prlog(PR_WARNING, "unknown OEM SEL command %02x received\n", sel.cmd); } diff --git a/include/ipmi.h b/include/ipmi.h index 0acfbf563ca5..a2735f16b551 100644 --- a/include/ipmi.h +++ b/include/ipmi.h @@ -241,6 +241,11 @@ void ipmi_register_backend(struct ipmi_backend *backend); /* Allocate IPMI SEL panic message */ void ipmi_sel_init(void); +/* Register SEL handler with IPMI core */ +int ipmi_sel_register(uint8_t oem_cmd, + void (*handler)(uint8_t data, void *context), + void *context); + /* Register rtc ipmi commands with as opal callbacks. */ void ipmi_rtc_init(void);