IPMI/ACPI: Install the ACPI IPMI opregion
Subsystems (3)
RFC PATCH 1/1 IPMI/ACPI: Install the ACPI IPMI opregion
From: Zhao Yakui <[email protected]>
Hi,
ACPI 4.0 spec adds the ACPI IPMI opregion, which means that the ACPI AML
code can also communicate with the BMC controller. This patch set is to install the ACPI IPMI opregion space handler and enable the ACPI to access the BMC controller through the IPMI message.
[RFC Patch 01/04]: Add one interface to get more info of low-level interface
It will return the corresponding info of low-level interface based on the expected type(For example: SI_ACPI, SI_PCI and so on.)
[RFC Patch 02/04]: Remove the redudant definition of ipmi_addr_src type
[RFC Patch 03/04]: Add the document description about how to use the function of ipmi_get_smi_info
[RFC Patch 04/04]: Install the IPMI space handler to enable ACPI to access the BMC controller
V10->V11: Delete the incorrect refcount in V10. At the same time the function of ipmi_get_smi_info will return the reference pointer to avoid the memory copy.
V9-V10: Redefine the interface function to get more info of low-level IPMI device. And add the document description about how to use it.
V8-V9: This patch set is based on the mechanism that add one interface that can get more info of low-level IPMI device. For example: the ACPI device handle will be returned for the pnp_acpi. Then the second patch will use the added interface to check whether the IPMI device is what ACPI wanted to communicated with in the new_smi callback function of smi_watcher. If it is, we will install the IPMI opregion handler and enable ACPI to communicate with BMC.
V7->V8: Based on Bjorn's comment, use acpi ipmi notifier hook function to avoid the discovery of ACPI pnp IPMI device again. Then in course of binding /unbinding ipmi pnp driver with the corresponding device, the notifier chain function will be called to install/uninstall the ACPI IPMI opregion space handler.
V6->V7: Based on Corey Minyard's comments, the IPMI opregion handler is put into the separate file again as it only uses the API interface provided by IPMI system. Now it is put into the ACPI subsystem.
V5->V6: Adjust the patch order and refresh the patch set.
V4->V5: According to Bjorn's comment, remove the unnecessary comment. The debug info will be printed by using dev_err/dev_warn instead of by using printk directly.
V3->V4: According to Bjorn's comment, delete the meaningless variable initialization and check. We also do some cleanup.
V2->V3: According to Bjorn's comment, this IPMI opregion code is put into the IPMI subsystem(ipmi_si_intf.c). In such case the part of IPMI opregion code will be installed automatically when IPMI detection module is loaded. When the IPMI system interface is detected by loading PNP device driver, we will record every IPMI system interface defined in ACPI namespace and then install the corresponding IPMI opregion space handler, which is used to enable ACPI AML code to access the BMC controller.
V1->V2: According to Bjorn's comment, we won't install the IPMI space handler by loading an ACPI device driver. Instead we will enumerate the ACPI IPMI device directly in ACPI device tree and then install the IPMI space handler. Then ACPI AML code and access the BMC controller through the IPMI space handler.
Best regards.
Yakui
RFC PATCH 1/4 IPMI: Add one interface to get more info of low-level IPMI device
From: Zhao Yakui <[email protected]>
The IPMI smi_watcher will be used to catch the IPMI interface as they come or go. In order to communicate with the correct IPMI device, it should be confirmed
whether it is what we wanted especially on the system with multiple IPMI
devices. But the new_smi callback function of smi_watcher provides very limited info(only the interface number and dev pointer) and there is no detailed info about the low level interface. For example: which mechansim registers the IPMI interface(ACPI, PCI, DMI and so on).
This is to add one interface that can get more info of low-level IPMI device. For example: the ACPI device handle will be returned for the pnp_acpi IPMI device.
---
In this patch only the info of pnp_acpi IPMI is provided. If the detailed info is also required for other mechanism, please add them in the structure of ipmi_smi_info.
drivers/char/ipmi/ipmi_msghandler.c | 26 ++++++++++++++++++++++++++ drivers/char/ipmi/ipmi_si_intf.c | 28 ++++++++++++++++++++++++---- include/linux/ipmi.h | 23 +++++++++++++++++++++++ include/linux/ipmi_smi.h | 11 +++++++++++ 4 files changed, 84 insertions(+), 4 deletions(-)
drivers/char/ipmi/ipmi_msghandler.c +26 -0
@@ -970,6 +970,32 @@ out_kfree: }EXPORT_SYMBOL (ipmi_create_user); +int ipmi_get_smi_info (int if_num,enum ipmi_addr_src type, +struct ipmi_smi_info **data) +{ +int rv =0 ; +ipmi_smi_t intf; +struct ipmi_smi_handlers *handlers; + +mutex_lock (&ipmi_interfaces_mutex); +list_for_each_entry_rcu (intf, &ipmi_interfaces, link) { +if (intf->intf_num == if_num) + goto found; + } +/* Not found, return an error */ + rv = -EINVAL ; +mutex_unlock (&ipmi_interfaces_mutex); +return rv; + +found: + handlers = intf->handlers; + rv = handlers->get_smi_info (intf->send_info, type, data); +mutex_unlock (&ipmi_interfaces_mutex); + +return rv; +} +EXPORT_SYMBOL (ipmi_get_smi_info); +static void free_user (struct kref *ref) { ipmi_user_t user = container_of(ref, struct ipmi_user, refcount);
drivers/char/ipmi/ipmi_si_intf.c +24 -4
@@ -57,6 +57,7 @@#include <asm/irq.h> #include <linux/interrupt.h> #include <linux/rcupdate.h> +#include <linux/ipmi.h> #include <linux/ipmi_smi.h> #include <asm/io.h> #include "ipmi_si_sm.h"
@@ -107,10 +108,6 @@ enum si_type { };static char *si_to_str[] = {"kcs" ,"smic" ,"bt" }; -enum ipmi_addr_src { -SI_INVALID =0 ,SI_HOTMOD ,SI_HARDCODED ,SI_SPMI ,SI_ACPI ,SI_SMBIOS , -SI_PCI ,SI_DEVICETREE ,SI_DEFAULT -};static char *ipmi_addr_src_to_str[] = {NULL ,"hotmod" ,"hardcoded" ,"SPMI" ,"ACPI" ,"SMBIOS" ,"PCI" ,"device-tree" ,"default" };
@@ -291,6 +288,7 @@ struct smi_info {struct task_struct *thread;struct list_head link; +struct ipmi_smi_info smi_data; };#define smi_inc_stat (smi, stat) \
@@ -1186,6 +1184,22 @@ static int smi_start_processing(void *send_info,return 0 ; } +static int get_smi_info (void *send_info, +enum ipmi_addr_src type, +struct ipmi_smi_info **data) +{ +struct smi_info *new_smi = send_info; +struct ipmi_smi_info *smi_data = &new_smi->smi_data; + +if (new_smi->addr_source != type) +return -EINVAL ; + + smi_data->addr_src = type; + + *data = smi_data; +return 0 ; +} +static void set_maintenance_mode (void *send_info,int enable) {struct smi_info *smi_info = send_info;
@@ -1197,6 +1211,7 @@ static void set_maintenance_mode(void *send_info, int enable)static struct ipmi_smi_handlers handlers = { .owner =THIS_MODULE , .start_processing = smi_start_processing, + .get_smi_info = get_smi_info, .sender = sender, .request_events = request_events, .set_maintenance_mode = set_maintenance_mode,
@@ -2143,6 +2158,8 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,return -ENOMEM ; info->addr_source =SI_ACPI ; + info->smi_data.smi_info.acpi_info.acpi_handle = + acpi_dev->handle; printk(KERN_INFO PFX "probing via ACPI\n"); handle = acpi_dev->handle;
@@ -3092,6 +3109,7 @@ static int try_smi_init(struct smi_info *new_smi) {int rv =0 ;int i; +struct ipmi_smi_info *smi_data = &new_smi->smi_data; printk(KERN_INFO PFX "Trying %s-specified %s state"" machine at %s address 0x%lx, slave address 0x%x,"
@@ -3217,6 +3235,8 @@ static int try_smi_init(struct smi_info *new_smi) new_smi->dev_registered =1 ; } + smi_data->dev = new_smi->dev; + rv = ipmi_register_smi(&handlers, new_smi, &new_smi->device_id,
include/linux/ipmi.h +23 -0
@@ -454,6 +454,29 @@ unsigned int ipmi_addr_length(int addr_type);/* Validate that the given IPMI address is valid. */ int ipmi_validate_addr (struct ipmi_addr *addr,int len); +enum ipmi_addr_src { +SI_INVALID =0 ,SI_HOTMOD ,SI_HARDCODED ,SI_SPMI ,SI_ACPI ,SI_SMBIOS , +SI_PCI ,SI_DEVICETREE ,SI_DEFAULT +}; +struct ipmi_smi_info { +enum ipmi_addr_src addr_src; +struct device *dev; +union { +/* +* Now only SI_ACPI info is provided. If the info is required +* for other type, please add it +*/ +#ifdef CONFIG_ACPI +struct { +void *acpi_handle; + } acpi_info; +#endif + } smi_info; +}; + +/* This is to get the private info of ipmi_smi_t. The pointer is returned */ +extern int ipmi_get_smi_info (int if_num,enum ipmi_addr_src type, +struct ipmi_smi_info **data);#endif /* __KERNEL__ */
include/linux/ipmi_smi.h +11 -0
@@ -86,6 +86,17 @@ struct ipmi_smi_handlers {int (*start_processing)(void *send_info,ipmi_smi_t new_intf); +/* +* Get the detailed private info of the low level interface and return +* the corresponding pointer. +* For example: the ACPI device handle will be returned for the +* pnp_acpi IPMI device. Of course it will firstly compare the +* interface type of low-level interface(Hardcoded type, DMI, +* ACPI and so on). If the type doesn't match, it will return -EINVAL. +*/ +int (*get_smi_info)(void *send_info,enum ipmi_addr_src type, +struct ipmi_smi_info **data); +/* Called to enqueue an SMI message to be sent. This operation is not allowed to fail. If an error occurs, it should report back the error in a received message. It may
Signature · 1 line
1.5.4.5
RFC PATCH 2/4 IPMI: Remove the redundant definition of ipmi_addr_src
From: Zhao Yakui <[email protected]>
The ipmi_addr_src is defined twice. One is in ipmi_smi_info and the other is in generic smi_info. Remove the redunant definition in smi_info.
--- drivers/char/ipmi/ipmi_si_intf.c | 37 +++++++++++++++++-------------------- 1 files changed, 17 insertions(+), 20 deletions(-)
drivers/char/ipmi/ipmi_si_intf.c +17 -20
@@ -193,7 +193,6 @@ struct smi_info {int (*irq_setup)(struct smi_info *info);void (*irq_cleanup)(struct smi_info *info);unsigned int io_size; -enum ipmi_addr_src addr_source;/* ACPI, PCI, SMBIOS, hardcode, etc. */ void (*addr_source_cleanup)(struct smi_info *info);void *addr_source_data;
@@ -1191,11 +1190,9 @@ static int get_smi_info(void *send_info,struct smi_info *new_smi = send_info;struct ipmi_smi_info *smi_data = &new_smi->smi_data; -if (new_smi->addr_source != type) +if (smi_data->addr_src != type)return -EINVAL ; - smi_data->addr_src = type; - *data = smi_data;return 0 ; }
@@ -1800,7 +1797,7 @@ static int hotmod_handler(const char *val, struct kernel_param *kp) goto out; } - info->addr_source =SI_HOTMOD ; + info->smi_data.addr_src =SI_HOTMOD ; info->si_type = si_type; info->io.addr_data = addr; info->io.addr_type = addr_space;
@@ -1863,7 +1860,7 @@ static __devinit void hardcode_find_bmc(void)if (!info)return ; - info->addr_source =SI_HARDCODED ; + info->smi_data.addr_src =SI_HARDCODED ; printk(KERN_INFO PFX "probing via hardcoded address\n");if (!si_type[i] ||strcmp (si_type[i],"kcs" ) ==0 ) {
@@ -2049,7 +2046,7 @@ static __devinit int try_init_spmi(struct SPMITable *spmi)return -ENOMEM ; } - info->addr_source =SI_SPMI ; + info->smi_data.addr_src =SI_SPMI ; printk(KERN_INFO PFX "probing via SPMI\n");/* Figure out the interface type. */
@@ -2157,7 +2154,7 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,if (!info)return -ENOMEM ; - info->addr_source =SI_ACPI ; + info->smi_data.addr_src =SI_ACPI ; info->smi_data.smi_info.acpi_info.acpi_handle = acpi_dev->handle; printk(KERN_INFO PFX "probing via ACPI\n");
@@ -2342,7 +2339,7 @@ static __devinit void try_init_dmi(struct dmi_ipmi_data *ipmi_data)return ; } - info->addr_source =SI_SMBIOS ; + info->smi_data.addr_src =SI_SMBIOS ; printk(KERN_INFO PFX "probing via SMBIOS\n");switch (ipmi_data->type) {
@@ -2447,7 +2444,7 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,if (!info)return -ENOMEM ; - info->addr_source =SI_PCI ; + info->smi_data.addr_src =SI_PCI ;dev_info (&pdev->dev,"probing via PCI" );switch (class_type) {
@@ -2593,7 +2590,7 @@ static int __devinit ipmi_of_probe(struct platform_device *dev, } info->si_type = (enum si_type ) match->data; - info->addr_source =SI_DEVICETREE ; + info->smi_data.addr_src =SI_DEVICETREE ; info->irq_setup = std_irq_setup;if (resource.flags &IORESOURCE_IO ) {
@@ -3035,7 +3032,7 @@ static __devinit void default_find_bmc(void)if (!info)return ; - info->addr_source =SI_DEFAULT ; + info->smi_data.addr_src =SI_DEFAULT ; info->si_type = ipmi_defaults[i].type; info->io_setup = port_setup;
@@ -3082,7 +3079,7 @@ static int add_smi(struct smi_info *new_smi)int rv =0 ; printk(KERN_INFO PFX "Adding %s-specified %s state machine", - ipmi_addr_src_to_str[new_smi->addr_source], + ipmi_addr_src_to_str[new_smi->smi_data.addr_src], si_to_str[new_smi->si_type]);mutex_lock (&smi_infos_lock);if (!is_new_interface (new_smi)) {
@@ -3114,7 +3111,7 @@ static int try_smi_init(struct smi_info *new_smi) printk(KERN_INFO PFX "Trying %s-specified %s state"" machine at %s address 0x%lx, slave address 0x%x," " irq %d\n" , - ipmi_addr_src_to_str[new_smi->addr_source], + ipmi_addr_src_to_str[new_smi->smi_data.addr_src], si_to_str[new_smi->si_type], addr_space_to_str[new_smi->io.addr_type], new_smi->io.addr_data,
@@ -3162,7 +3159,7 @@ static int try_smi_init(struct smi_info *new_smi)/* Do low-level detection first. */ if (new_smi->handlers->detect (new_smi->si_sm)) { -if (new_smi->addr_source) +if (new_smi->smi_data.addr_src) printk(KERN_INFO PFX "Interface detection failed\n"); rv = -ENODEV ; goto out_err;
@@ -3174,7 +3171,7 @@ static int try_smi_init(struct smi_info *new_smi)*/ rv =try_get_dev_id (new_smi);if (rv) { -if (new_smi->addr_source) +if (new_smi->smi_data.addr_src) printk(KERN_INFO PFX "There appears to be no BMC"" at this location\n" ); goto out_err;
@@ -3408,9 +3405,9 @@ static __devinit int init_ipmi_si(void)/* Try to register a device if it has an IRQ and we either haven't successfully registered a device yet or this device has the same type as one we successfully registered */ -if (e->irq && (!type || e->addr_source == type)) { +if (e->irq && (!type || e->smi_data.addr_src == type)) {if (!try_smi_init (e)) { - type = e->addr_source; + type = e->smi_data.addr_src; } } }
@@ -3424,9 +3421,9 @@ static __devinit int init_ipmi_si(void)/* Fall back to the preferred device */ list_for_each_entry (e, &smi_infos, link) { -if (!e->irq && (!type || e->addr_source == type)) { +if (!e->irq && (!type || e->smi_data.addr_src == type)) {if (!try_smi_init (e)) { - type = e->addr_source; + type = e->smi_data.addr_src; } } }
Signature · 1 line
1.5.4.5
RFC PATCH 3/4 IPMI: Add the document description of ipmi_get_smi_info
From: Zhao Yakui <[email protected]>
Add the document description about how to use ipmi_get_smi_info.
--- Documentation/IPMI.txt | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-)
Documentation/IPMI.txt +37 -0
@@ -533,6 +533,43 @@ completion during sending a panic event. Other Pieces ------------ +Get the detailed info related with the IPMI device +-------- +The IPMI smi_watcher will be used to catch the IPMI interface as they come or go. +In order to communicate with the correct IPMI device, it should be confirmed + whether it is what we wanted especially on the system with multiple IPMI +devices. But the new_smi callback function of smi_watcher provides very +limited info(only the interface number and dev pointer) and there is no +detailed info about the low level interface. For example: which mechansim +registers the IPMI interface(ACPI, PCI, DMI and so on). + The function of ipmi_get_smi_info is added to get the +detailed info of IPMI device. The following is the struct definition of +ipmi_smi_info(Now only ACPI info is defined. If the info is required for +other IPMI device type, please add it) . + struct ipmi_smi_info{ + enum ipmi_addr_src addr_src; + struct device *dev; + union { + /* + * Now only SI_ACPI info is provided. If the info is required + * for other type, please add it + */ +#ifdef CONFIG_ACPI + struct { + void *acpi_handle; + } acpi_info; +#endif + } smi_info; +}; + + The following is the definition of ipmi_get_smi_info. + extern int ipmi_get_smi_info(int if_num, enum ipmi_addr_src type, + struct ipmi_smi_info **data); + It is noted that the returned smi_data is not the dynamically +allocated memory. It is only the pointer of the corresponding info stored +in IPMI device. In such case the caller don't try to free the corresponding +memory. + Watchdog --------
Signature · 1 line
1.5.4.5
RFC PATCH 4/4 IPMI/ACPI: Add the IPMI opregion driver to enable ACPI to access BMC controller
From: Zhao Yakui <[email protected]>
ACPI 4.0 spec adds the ACPI IPMI opregion, which means that the ACPI AML code can also communicate with the BMC controller. This is to install the ACPI IPMI opregion and enable the ACPI to access the BMC controller through the IPMI message.
It will create IPMI user interface for every IPMI device detected
in ACPI namespace and install the corresponding IPMI opregion space handler. Then it can enable ACPI to access the BMC controller through the IPMI message.
The following describes how to process the IPMI request in IPMI space handler:
1. format the IPMI message based on the request in AML code. IPMI system address. Now the address type is SYSTEM_INTERFACE_ADDR_TYPE IPMI net function & command
IPMI message payload
2. send the IPMI message by using the function of ipmi_request_settime
3. wait for the completion of IPMI message. It can be done in different
routes: One is in handled in IPMI user recv callback function. Another is handled in timeout function.
4. format the IPMI response and return it to ACPI AML code.
At the same time it also addes the module dependency. The ACPI IPMI opregion will depend on the IPMI subsystem.
--- drivers/acpi/Kconfig | 12 + drivers/acpi/Makefile | 1 + drivers/acpi/acpi_ipmi.c | 510 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 523 insertions(+), 0 deletions(-) create mode 100644 drivers/acpi/acpi_ipmi.c
drivers/acpi/Kconfig +12 -0
@@ -210,6 +210,18 @@ config ACPI_PROCESSOR To compile this driver as a module, choose M here: the module will be called processor. +config ACPI_IPMI + tristate "IPMI" + depends on EXPERIMENTAL && IPMI_SI && IPMI_HANDLER + default n + help + This driver enables the ACPI to access the BMC controller. And it + uses the IPMI request/response message to communicate with BMC + controller, which can be found on on the server. + + To compile this driver as a module, choose M here: + the module will be called as acpi_ipmi. + config ACPI_HOTPLUG_CPU bool depends on ACPI_PROCESSOR && HOTPLUG_CPU
drivers/acpi/Makefile +1 -0
@@ -69,5 +69,6 @@ processor-y += processor_idle.o processor_thermal.o processor-$(CONFIG_CPU_FREQ) += processor_perflib.o obj-$(CONFIG_ACPI_PROCESSOR_AGGREGATOR) += acpi_pad.o +obj-$(CONFIG_ACPI_IPMI) += acpi_ipmi.o obj-$(CONFIG_ACPI_APEI) += apei/
drivers/acpi/acpi_ipmi.c new file +510 -0
510 lines not on this page · raw message
Signature · 1 line
1.5.4.5
Re: [RFC PATCH 1/4] IPMI: Add one interface to get more info of low-level IPMI device
In reply to [email protected]Quoted 10 lines · Yakui
From: Zhao Yakui <[email protected]>
The IPMI
smi_watcherwill be used to catch the IPMI interface as they come or go. In order to communicate with the correct IPMI device, it should be confirmed
whether it is what we wanted especially on the system with multiple IPMI
devices. But thenew_smicallback function ofsmi_watcherprovides very limited info(only the interface number and dev pointer) and there is no detailed info about the low level interface. For example: which mechansim registers the IPMIinterface(ACPI, PCI, DMI and so on).
Quoted 3 lines
This is to add one interface that can get more info of low-level IPMI device. For example: the ACPI device handle will be returned for the
pnp_acpiIPMI device.
Hi, Corey
Does this patch set make sense?
In this patch set the reference pointer is returned instead of
memory copy.
Thanks.
Yakui
Quoted 194 lines
Signed-off-by Zhao Yakui <[email protected]>---
In this patch only the info ofpnp_acpiIPMI is provided. If the detailed info is also required for other mechanism, please add them in the structure ofipmi_smi_info.drivers/char/ipmi/ipmi_msghandler.c | 26 ++++++++++++++++++++++++++ drivers/char/ipmi/ipmi_si_intf.c | 28 ++++++++++++++++++++++++---- include/linux/ipmi.h | 23 +++++++++++++++++++++++ include/linux/ipmi_smi.h | 11 +++++++++++ 4 files changed, 84 insertions(+), 4 deletions(-)drivers/char/ipmi/ipmi_msghandler.c +26
-0@@ -970,6 +970,32 @@ out_kfree: }EXPORT_SYMBOL (ipmi_create_user); +int ipmi_get_smi_info (int if_num,enum ipmi_addr_src type, +struct ipmi_smi_info **data) +{ +int rv =0 ; +ipmi_smi_t intf; +struct ipmi_smi_handlers *handlers; + +mutex_lock (&ipmi_interfaces_mutex); +list_for_each_entry_rcu (intf, &ipmi_interfaces, link) { +if (intf->intf_num == if_num) + goto found; + } +/* Not found, return an error */ + rv = -EINVAL ; +mutex_unlock (&ipmi_interfaces_mutex); +return rv; + +found: + handlers = intf->handlers; + rv = handlers->get_smi_info (intf->send_info, type, data); +mutex_unlock (&ipmi_interfaces_mutex); + +return rv; +} +EXPORT_SYMBOL (ipmi_get_smi_info); +static void free_user (struct kref *ref) { ipmi_user_t user = container_of(ref, struct ipmi_user, refcount);drivers/char/ipmi/ipmi_si_intf.c +24
-4@@ -57,6 +57,7 @@#include <asm/irq.h> #include <linux/interrupt.h> #include <linux/rcupdate.h> +#include <linux/ipmi.h> #include <linux/ipmi_smi.h> #include <asm/io.h> #include "ipmi_si_sm.h" @@ -107,10 +108,6 @@ enum si_type { };static char *si_to_str[] = {"kcs" ,"smic" ,"bt" }; -enum ipmi_addr_src { -SI_INVALID =0 ,SI_HOTMOD ,SI_HARDCODED ,SI_SPMI ,SI_ACPI ,SI_SMBIOS , -SI_PCI ,SI_DEVICETREE ,SI_DEFAULT -};static char *ipmi_addr_src_to_str[] = {NULL ,"hotmod" ,"hardcoded" ,"SPMI" ,"ACPI" ,"SMBIOS" ,"PCI" ,"device-tree" ,"default" };@@ -291,6 +288,7 @@ struct smi_info {struct task_struct *thread;struct list_head link; +struct ipmi_smi_info smi_data; };#define smi_inc_stat (smi, stat) \@@ -1186,6 +1184,22 @@ static int smi_start_processing(void *send_info,return 0 ; } +static int get_smi_info (void *send_info, +enum ipmi_addr_src type, +struct ipmi_smi_info **data) +{ +struct smi_info *new_smi = send_info; +struct ipmi_smi_info *smi_data = &new_smi->smi_data; + +if (new_smi->addr_source != type) +return -EINVAL ; + + smi_data->addr_src = type; + + *data = smi_data; +return 0 ; +} +static void set_maintenance_mode (void *send_info,int enable) {struct smi_info *smi_info = send_info;@@ -1197,6 +1211,7 @@ static void set_maintenance_mode(void *send_info, int enable)static struct ipmi_smi_handlers handlers = { .owner =THIS_MODULE , .start_processing = smi_start_processing, + .get_smi_info = get_smi_info, .sender = sender, .request_events = request_events, .set_maintenance_mode = set_maintenance_mode,@@ -2143,6 +2158,8 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,return -ENOMEM ; info->addr_source =SI_ACPI ; + info->smi_data.smi_info.acpi_info.acpi_handle = + acpi_dev->handle; printk(KERN_INFO PFX "probing via ACPI\n"); handle = acpi_dev->handle;@@ -3092,6 +3109,7 @@ static int try_smi_init(struct smi_info *new_smi) {int rv =0 ;int i; +struct ipmi_smi_info *smi_data = &new_smi->smi_data; printk(KERN_INFO PFX "Trying %s-specified %s state"" machine at %s address 0x%lx, slave address 0x%x," @@ -3217,6 +3235,8 @@ static int try_smi_init(struct smi_info *new_smi) new_smi->dev_registered =1 ; } + smi_data->dev = new_smi->dev; + rv = ipmi_register_smi(&handlers, new_smi, &new_smi->device_id,include/linux/ipmi.h +23
-0@@ -454,6 +454,29 @@ unsigned int ipmi_addr_length(int addr_type);/* Validate that the given IPMI address is valid. */ int ipmi_validate_addr (struct ipmi_addr *addr,int len); +enum ipmi_addr_src { +SI_INVALID =0 ,SI_HOTMOD ,SI_HARDCODED ,SI_SPMI ,SI_ACPI ,SI_SMBIOS , +SI_PCI ,SI_DEVICETREE ,SI_DEFAULT +}; +struct ipmi_smi_info { +enum ipmi_addr_src addr_src; +struct device *dev; +union { +/* +* Now only SI_ACPI info is provided. If the info is required +* for other type, please add it +*/ +#ifdef CONFIG_ACPI +struct { +void *acpi_handle; + } acpi_info; +#endif + } smi_info; +}; + +/* This is to get the private info of ipmi_smi_t. The pointer is returned */ +extern int ipmi_get_smi_info (int if_num,enum ipmi_addr_src type, +struct ipmi_smi_info **data);#endif /* __KERNEL__ */ include/linux/ipmi_smi.h +11
-0@@ -86,6 +86,17 @@ struct ipmi_smi_handlers {int (*start_processing)(void *send_info,ipmi_smi_t new_intf); +/* +* Get the detailed private info of the low level interface and return +* the corresponding pointer. +* For example: the ACPI device handle will be returned for the +* pnp_acpi IPMI device. Of course it will firstly compare the +* interface type of low-level interface(Hardcoded type, DMI, +* ACPI and so on). If the type doesn't match, it will return -EINVAL. +*/ +int (*get_smi_info)(void *send_info,enum ipmi_addr_src type, +struct ipmi_smi_info **data); +/* Called to enqueue an SMI message to be sent. This operation is not allowed to fail. If an error occurs, it should report back the error in a received message. It may
Re: [RFC PATCH 1/4] IPMI: Add one interface to get more info of low-level IPMI device
In reply to [email protected]Well, no, you are returning a pointer to something that is in the smi data structure. For that you would need a refcount, because that structure can cease to exist asynchronously to your code. Instead, just pass in the structure you want to fill in. Like:
int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data)
{
/* checks here */
handlers = intf->handlers;
rv = handlers->get_smi_info(intf->send_info, data);
}static int get_smi_info(void *send_info,
struct ipmi_smi_info *data)
{
struct smi_info *new_smi = send_info;
data->smi_info.dev = new_smi->dev;
data->addr_src = new_smi->addr_source;
data->smi_info.addr_info = new_smi->addr_info;
return 0;
}Why are you passing an address type in to the function? That means you would have to know the address type to get anything out of if. It would be better to just return the info and let the user do the comparison. That way, if something wanted to fetch the info to get the device, or some other info, you don't have to try every address type.
Speaking of the device, that is a refcounted structure. You can't just pass it back without doing refcounts on it.
Can you rename the union addr_info, and comment that which union structure is used depends on the address type?
Also, I don't know anything about this ACPI handle, but is that a permanent structure? Can you just grab it like you do and pass it around? I would guess not.
-corey
Quoted 208 lines · On 10/22/2010 04:10 AM, [email protected] wrote:
From: Zhao Yakui<[email protected]>
The IPMI
smi_watcherwill be used to catch the IPMI interface as they come or go. In order to communicate with the correct IPMI device, it should be confirmed
whether it is what we wanted especially on the system with multiple IPMI
devices. But thenew_smicallback function ofsmi_watcherprovides very limited info(only the interface number and dev pointer) and there is no detailed info about the low level interface. For example: which mechansim registers the IPMIinterface(ACPI, PCI, DMI and so on).This is to add one interface that can get more info of low-level IPMI device. For example: the ACPI device handle will be returned for the
pnp_acpiIPMI device.Signed-off-by Zhao Yakui<[email protected]>---
In this patch only the info ofpnp_acpiIPMI is provided. If the detailed info is also required for other mechanism, please add them in the structure ofipmi_smi_info.drivers/char/ipmi/ipmi_msghandler.c | 26 ++++++++++++++++++++++++++ drivers/char/ipmi/ipmi_si_intf.c | 28 ++++++++++++++++++++++++---- include/linux/ipmi.h | 23 +++++++++++++++++++++++ include/linux/ipmi_smi.h | 11 +++++++++++ 4 files changed, 84 insertions(+), 4 deletions(-)drivers/char/ipmi/ipmi_msghandler.c +26
-0@@ -970,6 +970,32 @@ out_kfree: }EXPORT_SYMBOL (ipmi_create_user); +int ipmi_get_smi_info (int if_num,enum ipmi_addr_src type, +struct ipmi_smi_info **data) +{ +int rv =0 ; +ipmi_smi_t intf; +struct ipmi_smi_handlers *handlers; + +mutex_lock (&ipmi_interfaces_mutex); +list_for_each_entry_rcu (intf,&ipmi_interfaces, link) { +if (intf->intf_num == if_num) + goto found; + } +/* Not found, return an error */ + rv = -EINVAL ; +mutex_unlock (&ipmi_interfaces_mutex); +return rv; + +found: + handlers = intf->handlers; + rv = handlers->get_smi_info (intf->send_info, type, data); +mutex_unlock (&ipmi_interfaces_mutex); + +return rv; +} +EXPORT_SYMBOL (ipmi_get_smi_info); +static void free_user (struct kref *ref) { ipmi_user_t user = container_of(ref, struct ipmi_user, refcount);drivers/char/ipmi/ipmi_si_intf.c +24
-4@@ -57,6 +57,7 @@#include <asm/irq.h> #include <linux/interrupt.h> #include <linux/rcupdate.h> +#include <linux/ipmi.h> #include <linux/ipmi_smi.h> #include <asm/io.h> #include "ipmi_si_sm.h" @@ -107,10 +108,6 @@ enum si_type { };static char *si_to_str[] = {"kcs" ,"smic" ,"bt" }; -enum ipmi_addr_src { -SI_INVALID =0 ,SI_HOTMOD ,SI_HARDCODED ,SI_SPMI ,SI_ACPI ,SI_SMBIOS , -SI_PCI ,SI_DEVICETREE ,SI_DEFAULT -};static char *ipmi_addr_src_to_str[] = {NULL ,"hotmod" ,"hardcoded" ,"SPMI" ,"ACPI" ,"SMBIOS" ,"PCI" ,"device-tree" ,"default" };@@ -291,6 +288,7 @@ struct smi_info {struct task_struct *thread;struct list_head link; +struct ipmi_smi_info smi_data; };#define smi_inc_stat (smi, stat) \@@ -1186,6 +1184,22 @@ static int smi_start_processing(void *send_info,return 0 ; } +static int get_smi_info (void *send_info, +enum ipmi_addr_src type, +struct ipmi_smi_info **data) +{ +struct smi_info *new_smi = send_info; +struct ipmi_smi_info *smi_data =&new_smi->smi_data; + +if (new_smi->addr_source != type) +return -EINVAL ; + + smi_data->addr_src = type; + + *data = smi_data; +return 0 ; +} +static void set_maintenance_mode (void *send_info,int enable) {struct smi_info *smi_info = send_info;@@ -1197,6 +1211,7 @@ static void set_maintenance_mode(void *send_info, int enable)static struct ipmi_smi_handlers handlers = { .owner =THIS_MODULE , .start_processing = smi_start_processing, + .get_smi_info = get_smi_info, .sender = sender, .request_events = request_events, .set_maintenance_mode = set_maintenance_mode,@@ -2143,6 +2158,8 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,return -ENOMEM ; info->addr_source =SI_ACPI ; + info->smi_data.smi_info.acpi_info.acpi_handle = + acpi_dev->handle; printk(KERN_INFO PFX "probing via ACPI\n"); handle = acpi_dev->handle;@@ -3092,6 +3109,7 @@ static int try_smi_init(struct smi_info *new_smi) {int rv =0 ;int i; +struct ipmi_smi_info *smi_data =&new_smi->smi_data; printk(KERN_INFO PFX "Trying %s-specified %s state"" machine at %s address 0x%lx, slave address 0x%x," @@ -3217,6 +3235,8 @@ static int try_smi_init(struct smi_info *new_smi) new_smi->dev_registered =1 ; } + smi_data->dev = new_smi->dev; + rv = ipmi_register_smi(&handlers, new_smi, &new_smi->device_id,include/linux/ipmi.h +23
-0@@ -454,6 +454,29 @@ unsigned int ipmi_addr_length(int addr_type);/* Validate that the given IPMI address is valid. */ int ipmi_validate_addr (struct ipmi_addr *addr,int len); +enum ipmi_addr_src { +SI_INVALID =0 ,SI_HOTMOD ,SI_HARDCODED ,SI_SPMI ,SI_ACPI ,SI_SMBIOS , +SI_PCI ,SI_DEVICETREE ,SI_DEFAULT +}; +struct ipmi_smi_info { +enum ipmi_addr_src addr_src; +struct device *dev; +union { +/* +* Now only SI_ACPI info is provided. If the info is required +* for other type, please add it +*/ +#ifdef CONFIG_ACPI +struct { +void *acpi_handle; + } acpi_info; +#endif + } smi_info; +}; + +/* This is to get the private info of ipmi_smi_t. The pointer is returned */ +extern int ipmi_get_smi_info (int if_num,enum ipmi_addr_src type, +struct ipmi_smi_info **data);#endif /* __KERNEL__ */ include/linux/ipmi_smi.h +11
-0@@ -86,6 +86,17 @@ struct ipmi_smi_handlers {int (*start_processing)(void *send_info,ipmi_smi_t new_intf); +/* +* Get the detailed private info of the low level interface and return +* the corresponding pointer. +* For example: the ACPI device handle will be returned for the +* pnp_acpi IPMI device. Of course it will firstly compare the +* interface type of low-level interface(Hardcoded type, DMI, +* ACPI and so on). If the type doesn't match, it will return -EINVAL. +*/ +int (*get_smi_info)(void *send_info,enum ipmi_addr_src type, +struct ipmi_smi_info **data); +/* Called to enqueue an SMI message to be sent. This operation is not allowed to fail. If an error occurs, it should report back the error in a received message. It may
Re: [RFC PATCH 1/4] IPMI: Add one interface to get more info of low-level IPMI device
Quoted 15 lines · Corey Minyard
Well, no, you are returning a pointer to something that is in the smi data structure. For that you would need a refcount, because that structure can cease to exist asynchronously to your code. Instead, just pass in the structure you want to fill in. Like:
int
ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data){ /* checks here */ handlers = intf->handlers; rv = handlers->get_smi_info(intf->send_info, data); }static int get_smi_info(void
*send_info,
structipmi_smi_info*data)
Quoted 10 lines
{
struct smi_info *new_smi = send_info;
data->smi_info.dev = new_smi->dev;
data->addr_src = new_smi->addr_source;
data->smi_info.addr_info = new_smi->addr_info;
return 0;
}You are right. In theory the refcount should be added if it returns the pointer of ipmi_smi_info. But as it resides in the smi_info, it will always exist before the smi_info is released.
OK. To make the thing simpler, I will use the mechanism you recommended.
Quoted 7 lines
Why are you passing an address type in to the function? That means you would have to know the address type to get anything out of if. It would be better to just return the info and let the user do the comparison. That way, if something wanted to fetch the info to get the device, or some other info, you don't have to try every address type.
OK. I will remove the argument of address type.
Quoted 3 lines
Speaking of the device, that is a refcounted structure. You can't just pass it back without doing refcounts on it.
Yes. In the previous-version patch set, the refcount of dev is increased when the ipmi_get_smi_info is called. And it is decreased when the ipmi_put_smi_info. But after the discussion, it seems that I misunderstand the refcount and then I remove it in this version. Ok, I will call it back.
Quoted 7 lines
Can you rename the union
addr_info, and comment that which union structure is used depends on the address type?Also, I don't know anything about this ACPI handle, but is that a permanent structure? Can you just grab it like you do and pass it around? I would guess not.
Sorry that I don't know the requirement for other address type when defining the structure of ipmi_smi_info. But for the ACPI address type, the acpi handle is very important. So it is defined in the union structure.
Quoted 213 lines
-corey
Quoted 208 lines · On 10/22/2010 04:10 AM, [email protected] wrote:
From: Zhao Yakui<[email protected]>
The IPMI
smi_watcherwill be used to catch the IPMI interface as they come or go. In order to communicate with the correct IPMI device, it should be confirmed
whether it is what we wanted especially on the system with multiple IPMI
devices. But thenew_smicallback function ofsmi_watcherprovides very limited info(only the interface number and dev pointer) and there is no detailed info about the low level interface. For example: which mechansim registers the IPMIinterface(ACPI, PCI, DMI and so on).This is to add one interface that can get more info of low-level IPMI device. For example: the ACPI device handle will be returned for the
pnp_acpiIPMI device.Signed-off-by Zhao Yakui<[email protected]>---
In this patch only the info ofpnp_acpiIPMI is provided. If the detailed info is also required for other mechanism, please add them in the structure ofipmi_smi_info.drivers/char/ipmi/ipmi_msghandler.c | 26 ++++++++++++++++++++++++++ drivers/char/ipmi/ipmi_si_intf.c | 28 ++++++++++++++++++++++++---- include/linux/ipmi.h | 23 +++++++++++++++++++++++ include/linux/ipmi_smi.h | 11 +++++++++++ 4 files changed, 84 insertions(+), 4 deletions(-)drivers/char/ipmi/ipmi_msghandler.c +26
-0@@ -970,6 +970,32 @@ out_kfree: }EXPORT_SYMBOL (ipmi_create_user); +int ipmi_get_smi_info (int if_num,enum ipmi_addr_src type, +struct ipmi_smi_info **data) +{ +int rv =0 ; +ipmi_smi_t intf; +struct ipmi_smi_handlers *handlers; + +mutex_lock (&ipmi_interfaces_mutex); +list_for_each_entry_rcu (intf,&ipmi_interfaces, link) { +if (intf->intf_num == if_num) + goto found; + } +/* Not found, return an error */ + rv = -EINVAL ; +mutex_unlock (&ipmi_interfaces_mutex); +return rv; + +found: + handlers = intf->handlers; + rv = handlers->get_smi_info (intf->send_info, type, data); +mutex_unlock (&ipmi_interfaces_mutex); + +return rv; +} +EXPORT_SYMBOL (ipmi_get_smi_info); +static void free_user (struct kref *ref) { ipmi_user_t user = container_of(ref, struct ipmi_user, refcount);drivers/char/ipmi/ipmi_si_intf.c +24
-4@@ -57,6 +57,7 @@#include <asm/irq.h> #include <linux/interrupt.h> #include <linux/rcupdate.h> +#include <linux/ipmi.h> #include <linux/ipmi_smi.h> #include <asm/io.h> #include "ipmi_si_sm.h" @@ -107,10 +108,6 @@ enum si_type { };static char *si_to_str[] = {"kcs" ,"smic" ,"bt" }; -enum ipmi_addr_src { -SI_INVALID =0 ,SI_HOTMOD ,SI_HARDCODED ,SI_SPMI ,SI_ACPI ,SI_SMBIOS , -SI_PCI ,SI_DEVICETREE ,SI_DEFAULT -};static char *ipmi_addr_src_to_str[] = {NULL ,"hotmod" ,"hardcoded" ,"SPMI" ,"ACPI" ,"SMBIOS" ,"PCI" ,"device-tree" ,"default" };@@ -291,6 +288,7 @@ struct smi_info {struct task_struct *thread;struct list_head link; +struct ipmi_smi_info smi_data; };#define smi_inc_stat (smi, stat) \@@ -1186,6 +1184,22 @@ static int smi_start_processing(void *send_info,return 0 ; } +static int get_smi_info (void *send_info, +enum ipmi_addr_src type, +struct ipmi_smi_info **data) +{ +struct smi_info *new_smi = send_info; +struct ipmi_smi_info *smi_data =&new_smi->smi_data; + +if (new_smi->addr_source != type) +return -EINVAL ; + + smi_data->addr_src = type; + + *data = smi_data; +return 0 ; +} +static void set_maintenance_mode (void *send_info,int enable) {struct smi_info *smi_info = send_info;@@ -1197,6 +1211,7 @@ static void set_maintenance_mode(void *send_info, int enable)static struct ipmi_smi_handlers handlers = { .owner =THIS_MODULE , .start_processing = smi_start_processing, + .get_smi_info = get_smi_info, .sender = sender, .request_events = request_events, .set_maintenance_mode = set_maintenance_mode,@@ -2143,6 +2158,8 @@ static int __devinit ipmi_pnp_probe(struct pnp_dev *dev,return -ENOMEM ; info->addr_source =SI_ACPI ; + info->smi_data.smi_info.acpi_info.acpi_handle = + acpi_dev->handle; printk(KERN_INFO PFX "probing via ACPI\n"); handle = acpi_dev->handle;@@ -3092,6 +3109,7 @@ static int try_smi_init(struct smi_info *new_smi) {int rv =0 ;int i; +struct ipmi_smi_info *smi_data =&new_smi->smi_data; printk(KERN_INFO PFX "Trying %s-specified %s state"" machine at %s address 0x%lx, slave address 0x%x," @@ -3217,6 +3235,8 @@ static int try_smi_init(struct smi_info *new_smi) new_smi->dev_registered =1 ; } + smi_data->dev = new_smi->dev; + rv = ipmi_register_smi(&handlers, new_smi, &new_smi->device_id,include/linux/ipmi.h +23
-0@@ -454,6 +454,29 @@ unsigned int ipmi_addr_length(int addr_type);/* Validate that the given IPMI address is valid. */ int ipmi_validate_addr (struct ipmi_addr *addr,int len); +enum ipmi_addr_src { +SI_INVALID =0 ,SI_HOTMOD ,SI_HARDCODED ,SI_SPMI ,SI_ACPI ,SI_SMBIOS , +SI_PCI ,SI_DEVICETREE ,SI_DEFAULT +}; +struct ipmi_smi_info { +enum ipmi_addr_src addr_src; +struct device *dev; +union { +/* +* Now only SI_ACPI info is provided. If the info is required +* for other type, please add it +*/ +#ifdef CONFIG_ACPI +struct { +void *acpi_handle; + } acpi_info; +#endif + } smi_info; +}; + +/* This is to get the private info of ipmi_smi_t. The pointer is returned */ +extern int ipmi_get_smi_info (int if_num,enum ipmi_addr_src type, +struct ipmi_smi_info **data);#endif /* __KERNEL__ */ include/linux/ipmi_smi.h +11
-0@@ -86,6 +86,17 @@ struct ipmi_smi_handlers {int (*start_processing)(void *send_info,ipmi_smi_t new_intf); +/* +* Get the detailed private info of the low level interface and return +* the corresponding pointer. +* For example: the ACPI device handle will be returned for the +* pnp_acpi IPMI device. Of course it will firstly compare the +* interface type of low-level interface(Hardcoded type, DMI, +* ACPI and so on). If the type doesn't match, it will return -EINVAL. +*/ +int (*get_smi_info)(void *send_info,enum ipmi_addr_src type, +struct ipmi_smi_info **data); +/* Called to enqueue an SMI message to be sent. This operation is not allowed to fail. If an error occurs, it should report back the error in a received message. It may