Re: [PATCH v4] IBM power meter driver

2007-10-12 Thread Darrick J. Wong
On Tue, Oct 09, 2007 at 08:00:44AM -0400, Mark M. Hoffman wrote:

> Sorry it took me so long to get back to this.  I've applied this to my hwmon
> testing branch, but I would still like to get a review from an IPMI expert.

I'm working on finding somebody to do that.

> OBTW: please try to send patches which apply cleanly to some tree to which I
> have access.  E.g.  from the Makefile - preceding and trailing context are not
> present in any git tree that I know.

Oops, sorry about that.

The i5k_amb driver referenced in the Makefile diff is the same one that
I posted to lm-sensors a few weeks ago, though there hasn't been much
discussion after it was pointed out that someone had already written a
driver to achieve the same purpose.  Unfortunately, nothing's happened
to either driver; any thoughts?  I'm thinking that we ought to get one
of them into shape for upstream, though I don't particularly care which
one it is...

--D


signature.asc
Description: Digital signature


Re: [PATCH v4] IBM power meter driver

2007-10-12 Thread Darrick J. Wong
On Tue, Oct 09, 2007 at 08:00:44AM -0400, Mark M. Hoffman wrote:

 Sorry it took me so long to get back to this.  I've applied this to my hwmon
 testing branch, but I would still like to get a review from an IPMI expert.

I'm working on finding somebody to do that.

 OBTW: please try to send patches which apply cleanly to some tree to which I
 have access.  E.g.  from the Makefile - preceding and trailing context are not
 present in any git tree that I know.

Oops, sorry about that.

The i5k_amb driver referenced in the Makefile diff is the same one that
I posted to lm-sensors a few weeks ago, though there hasn't been much
discussion after it was pointed out that someone had already written a
driver to achieve the same purpose.  Unfortunately, nothing's happened
to either driver; any thoughts?  I'm thinking that we ought to get one
of them into shape for upstream, though I don't particularly care which
one it is...

--D


signature.asc
Description: Digital signature


Re: [PATCH v4] IBM power meter driver

2007-10-09 Thread Darrick J. Wong
On Tue, Oct 09, 2007 at 06:44:07PM +0200, Roel Kluin wrote:

> >> +  if (IS_ERR(data->hwmon_dev)) {
> >> +  printk(KERN_ERR DRVNAME ": Error, unable to register hwmon "
> >> + "class device for interface %d\n",
> >> + data->interface);
> >> +  kfree(data);
> >> +  return;
> 
> don't you want to goto out_user here instead?

Err, yes, thank you for catching that.

--D
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4] IBM power meter driver

2007-10-09 Thread Roel Kluin
Mark M. Hoffman wrote:
>> +static void ibmpex_register_bmc(int iface, struct device *dev)
>> +{
>> +struct ibmpex_bmc_data *data;
>> +int err;
>> +
>> +data = kzalloc(sizeof(*data), GFP_KERNEL);
>> +if (!data) {
>> +printk(KERN_ERR DRVNAME ": Insufficient memory for BMC "
>> +   "interface %d.\n", data->interface);
>> +return;
>> +}
>> +
>> +data->address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
>> +data->address.channel = IPMI_BMC_CHANNEL;
>> +data->address.data[0] = 0;
>> +data->interface = iface;
>> +data->bmc_device = dev;
>> +
>> +/* Create IPMI messaging interface user */
>> +err = ipmi_create_user(data->interface, _data.ipmi_hndlrs,
>> +   data, >user);
>> +if (err < 0) {
>> +printk(KERN_ERR DRVNAME ": Error, unable to register user with "
>> +   "ipmi interface %d\n",
>> +   data->interface);
>> +goto out;
>> +}
>> +
>> +mutex_init(>lock);
>> +
>> +/* Initialize message */
>> +data->tx_msgid = 0;
>> +init_completion(>read_complete);
>> +data->tx_message.netfn = PEX_NET_FUNCTION;
>> +data->tx_message.cmd = PEX_COMMAND;
>> +data->tx_message.data = data->tx_msg_data;
>> +
>> +/* Does this BMC support PowerExecutive? */
>> +err = ibmpex_ver_check(data);
>> +if (err)
>> +goto out_user;
>> +
>> +/* Register the BMC as a HWMON class device */
>> +data->hwmon_dev = hwmon_device_register(data->bmc_device);
>> +
>> +if (IS_ERR(data->hwmon_dev)) {
>> +printk(KERN_ERR DRVNAME ": Error, unable to register hwmon "
>> +   "class device for interface %d\n",
>> +   data->interface);
>> +kfree(data);
>> +return;

don't you want to goto out_user here instead?

>> +}
>> +
>> +/* finally add the new bmc data to the bmc data list */
>> +dev_set_drvdata(dev, data);
>> +list_add_tail(>list, _data.bmc_data);
>> +
>> +/* Now go find all the sensors */
>> +err = ibmpex_find_sensors(data);
>> +if (err) {
>> +printk(KERN_ERR "Error %d allocating memory\n", err);
>> +goto out_register;
>> +}
>> +
>> +return;
>> +
>> +out_register:
>> +hwmon_device_unregister(data->hwmon_dev);
>> +out_user:
>> +ipmi_destroy_user(data->user);
>> +out:
>> +kfree(data);
>> +}


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4] IBM power meter driver

2007-10-09 Thread Mark M. Hoffman
Hi Darrick:

* Darrick J. Wong <[EMAIL PROTECTED]> [2007-09-14 12:33:46 -0700]:
> Here's a fourth revision where I've tried to clean up the things that
> people complained about, as well as shifted the sysfs file names to
> match the spec that we've been drifting towards.

Sorry it took me so long to get back to this.  I've applied this to my hwmon
testing branch, but I would still like to get a review from an IPMI expert.

OBTW: please try to send patches which apply cleanly to some tree to which I
have access.  E.g.  from the Makefile - preceding and trailing context are not
present in any git tree that I know.

> ---
> ibm_pex: Driver to export IBM PowerExecutive power meter sensors.
> 
> Signed-off-by: Darrick J. Wong <[EMAIL PROTECTED]>
> ---
> 
>  drivers/hwmon/Kconfig  |   13 +
>  drivers/hwmon/Makefile |1 
>  drivers/hwmon/ibmpex.c |  608 
> 
>  3 files changed, 622 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
> index 5ca5d95..591b666 100644
> --- a/drivers/hwmon/Kconfig
> +++ b/drivers/hwmon/Kconfig
> @@ -315,6 +315,19 @@ config SENSORS_CORETEMP
> sensor inside your CPU. Supported all are all known variants
> of Intel Core family.
>  
> +config SENSORS_IBMPEX
> + tristate "IBM PowerExecutive temperature/power sensors"
> + select IPMI_SI
> + depends on IPMI_HANDLER
> + help
> +   If you say yes here you get support for the temperature and
> +   power sensors in various IBM System X servers that support
> +   PowerExecutive.  So far this includes the x3550, x3650, x3655,
> +   x3755, and certain HS20 blades.
> +
> +   This driver can also be built as a module.  If so, the module
> +   will be called ibmpex.
> +
>  config SENSORS_IT87
>   tristate "ITE IT87xx and compatibles"
>   select HWMON_VID
> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
> index 5070cf7..0fcbcb4 100644
> --- a/drivers/hwmon/Makefile
> +++ b/drivers/hwmon/Makefile
> @@ -38,6 +38,7 @@ obj-$(CONFIG_SENSORS_GL518SM)   += gl518sm.o
>  obj-$(CONFIG_SENSORS_GL520SM)+= gl520sm.o
>  obj-$(CONFIG_SENSORS_HDAPS)  += hdaps.o
>  obj-$(CONFIG_SENSORS_I5K_AMB)+= i5k_amb.o
> +obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
>  obj-$(CONFIG_SENSORS_IPMI)   += ipmisensors.o
>  obj-$(CONFIG_SENSORS_IT87)   += it87.o
>  obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
> diff --git a/drivers/hwmon/ibmpex.c b/drivers/hwmon/ibmpex.c
> new file mode 100644
> index 000..fe2c261
> --- /dev/null
> +++ b/drivers/hwmon/ibmpex.c
> @@ -0,0 +1,608 @@
> +/*
> + * A hwmon driver for the IBM PowerExecutive temperature/power sensors
> + * Copyright (C) 2007 IBM
> + *
> + * Author: Darrick J. Wong <[EMAIL PROTECTED]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define REFRESH_INTERVAL (2 * HZ)
> +#define DRVNAME  "ibmpex"
> +
> +#define PEX_GET_VERSION  1
> +#define PEX_GET_SENSOR_COUNT 2
> +#define PEX_GET_SENSOR_NAME  3
> +#define PEX_RESET_HIGH_LOW   4
> +#define PEX_GET_SENSOR_DATA  6
> +
> +#define PEX_NET_FUNCTION 0x3A
> +#define PEX_COMMAND  0x3C
> +
> +static inline u16 extract_value(const char *data, int offset)
> +{
> + return be16_to_cpup((u16 *)[offset]);
> +}
> +
> +#define TEMP_SENSOR  1
> +#define POWER_SENSOR 2
> +
> +#define PEX_SENSOR_TYPE_LEN  3
> +static u8 const power_sensor_sig[] = {0x70, 0x77, 0x72};
> +static u8 const temp_sensor_sig[]  = {0x74, 0x65, 0x6D};
> +
> +#define PEX_MULT_LEN 2
> +static u8 const watt_sensor_sig[]  = {0x41, 0x43};
> +
> +#define PEX_NUM_SENSOR_FUNCS 3
> +static char const * const power_sensor_name_templates[] = {
> + "%s%d_average",
> + "%s%d_average_lowest",
> + "%s%d_average_highest"
> +};
> +static char const * const temp_sensor_name_templates[] = {
> + "%s%d_input",
> + "%s%d_input_lowest",
> + "%s%d_input_highest"
> +};
> +
> +static void ibmpex_msg_handler(struct ipmi_recv_msg *msg, void 
> *user_msg_data);
> +static void ibmpex_register_bmc(int iface, struct device *dev);
> +static void ibmpex_bmc_gone(int iface);
> +
> +struct 

Re: [PATCH v4] IBM power meter driver

2007-10-09 Thread Mark M. Hoffman
Hi Darrick:

* Darrick J. Wong [EMAIL PROTECTED] [2007-09-14 12:33:46 -0700]:
 Here's a fourth revision where I've tried to clean up the things that
 people complained about, as well as shifted the sysfs file names to
 match the spec that we've been drifting towards.

Sorry it took me so long to get back to this.  I've applied this to my hwmon
testing branch, but I would still like to get a review from an IPMI expert.

OBTW: please try to send patches which apply cleanly to some tree to which I
have access.  E.g.  from the Makefile - preceding and trailing context are not
present in any git tree that I know.

 ---
 ibm_pex: Driver to export IBM PowerExecutive power meter sensors.
 
 Signed-off-by: Darrick J. Wong [EMAIL PROTECTED]
 ---
 
  drivers/hwmon/Kconfig  |   13 +
  drivers/hwmon/Makefile |1 
  drivers/hwmon/ibmpex.c |  608 
 
  3 files changed, 622 insertions(+), 0 deletions(-)
 
 diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
 index 5ca5d95..591b666 100644
 --- a/drivers/hwmon/Kconfig
 +++ b/drivers/hwmon/Kconfig
 @@ -315,6 +315,19 @@ config SENSORS_CORETEMP
 sensor inside your CPU. Supported all are all known variants
 of Intel Core family.
  
 +config SENSORS_IBMPEX
 + tristate IBM PowerExecutive temperature/power sensors
 + select IPMI_SI
 + depends on IPMI_HANDLER
 + help
 +   If you say yes here you get support for the temperature and
 +   power sensors in various IBM System X servers that support
 +   PowerExecutive.  So far this includes the x3550, x3650, x3655,
 +   x3755, and certain HS20 blades.
 +
 +   This driver can also be built as a module.  If so, the module
 +   will be called ibmpex.
 +
  config SENSORS_IT87
   tristate ITE IT87xx and compatibles
   select HWMON_VID
 diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
 index 5070cf7..0fcbcb4 100644
 --- a/drivers/hwmon/Makefile
 +++ b/drivers/hwmon/Makefile
 @@ -38,6 +38,7 @@ obj-$(CONFIG_SENSORS_GL518SM)   += gl518sm.o
  obj-$(CONFIG_SENSORS_GL520SM)+= gl520sm.o
  obj-$(CONFIG_SENSORS_HDAPS)  += hdaps.o
  obj-$(CONFIG_SENSORS_I5K_AMB)+= i5k_amb.o
 +obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
  obj-$(CONFIG_SENSORS_IPMI)   += ipmisensors.o
  obj-$(CONFIG_SENSORS_IT87)   += it87.o
  obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
 diff --git a/drivers/hwmon/ibmpex.c b/drivers/hwmon/ibmpex.c
 new file mode 100644
 index 000..fe2c261
 --- /dev/null
 +++ b/drivers/hwmon/ibmpex.c
 @@ -0,0 +1,608 @@
 +/*
 + * A hwmon driver for the IBM PowerExecutive temperature/power sensors
 + * Copyright (C) 2007 IBM
 + *
 + * Author: Darrick J. Wong [EMAIL PROTECTED]
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by
 + * the Free Software Foundation; either version 2 of the License, or
 + * (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software
 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 + */
 +
 +#include linux/ipmi.h
 +#include linux/module.h
 +#include linux/hwmon.h
 +#include linux/hwmon-sysfs.h
 +#include linux/jiffies.h
 +#include linux/mutex.h
 +
 +#define REFRESH_INTERVAL (2 * HZ)
 +#define DRVNAME  ibmpex
 +
 +#define PEX_GET_VERSION  1
 +#define PEX_GET_SENSOR_COUNT 2
 +#define PEX_GET_SENSOR_NAME  3
 +#define PEX_RESET_HIGH_LOW   4
 +#define PEX_GET_SENSOR_DATA  6
 +
 +#define PEX_NET_FUNCTION 0x3A
 +#define PEX_COMMAND  0x3C
 +
 +static inline u16 extract_value(const char *data, int offset)
 +{
 + return be16_to_cpup((u16 *)data[offset]);
 +}
 +
 +#define TEMP_SENSOR  1
 +#define POWER_SENSOR 2
 +
 +#define PEX_SENSOR_TYPE_LEN  3
 +static u8 const power_sensor_sig[] = {0x70, 0x77, 0x72};
 +static u8 const temp_sensor_sig[]  = {0x74, 0x65, 0x6D};
 +
 +#define PEX_MULT_LEN 2
 +static u8 const watt_sensor_sig[]  = {0x41, 0x43};
 +
 +#define PEX_NUM_SENSOR_FUNCS 3
 +static char const * const power_sensor_name_templates[] = {
 + %s%d_average,
 + %s%d_average_lowest,
 + %s%d_average_highest
 +};
 +static char const * const temp_sensor_name_templates[] = {
 + %s%d_input,
 + %s%d_input_lowest,
 + %s%d_input_highest
 +};
 +
 +static void ibmpex_msg_handler(struct ipmi_recv_msg *msg, void 
 *user_msg_data);
 +static void ibmpex_register_bmc(int iface, struct device *dev);
 +static void ibmpex_bmc_gone(int iface);
 +
 +struct ibmpex_sensor_data {
 + int in_use;
 +

Re: [PATCH v4] IBM power meter driver

2007-10-09 Thread Roel Kluin
Mark M. Hoffman wrote:
 +static void ibmpex_register_bmc(int iface, struct device *dev)
 +{
 +struct ibmpex_bmc_data *data;
 +int err;
 +
 +data = kzalloc(sizeof(*data), GFP_KERNEL);
 +if (!data) {
 +printk(KERN_ERR DRVNAME : Insufficient memory for BMC 
 +   interface %d.\n, data-interface);
 +return;
 +}
 +
 +data-address.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
 +data-address.channel = IPMI_BMC_CHANNEL;
 +data-address.data[0] = 0;
 +data-interface = iface;
 +data-bmc_device = dev;
 +
 +/* Create IPMI messaging interface user */
 +err = ipmi_create_user(data-interface, driver_data.ipmi_hndlrs,
 +   data, data-user);
 +if (err  0) {
 +printk(KERN_ERR DRVNAME : Error, unable to register user with 
 +   ipmi interface %d\n,
 +   data-interface);
 +goto out;
 +}
 +
 +mutex_init(data-lock);
 +
 +/* Initialize message */
 +data-tx_msgid = 0;
 +init_completion(data-read_complete);
 +data-tx_message.netfn = PEX_NET_FUNCTION;
 +data-tx_message.cmd = PEX_COMMAND;
 +data-tx_message.data = data-tx_msg_data;
 +
 +/* Does this BMC support PowerExecutive? */
 +err = ibmpex_ver_check(data);
 +if (err)
 +goto out_user;
 +
 +/* Register the BMC as a HWMON class device */
 +data-hwmon_dev = hwmon_device_register(data-bmc_device);
 +
 +if (IS_ERR(data-hwmon_dev)) {
 +printk(KERN_ERR DRVNAME : Error, unable to register hwmon 
 +   class device for interface %d\n,
 +   data-interface);
 +kfree(data);
 +return;

don't you want to goto out_user here instead?

 +}
 +
 +/* finally add the new bmc data to the bmc data list */
 +dev_set_drvdata(dev, data);
 +list_add_tail(data-list, driver_data.bmc_data);
 +
 +/* Now go find all the sensors */
 +err = ibmpex_find_sensors(data);
 +if (err) {
 +printk(KERN_ERR Error %d allocating memory\n, err);
 +goto out_register;
 +}
 +
 +return;
 +
 +out_register:
 +hwmon_device_unregister(data-hwmon_dev);
 +out_user:
 +ipmi_destroy_user(data-user);
 +out:
 +kfree(data);
 +}


-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4] IBM power meter driver

2007-10-09 Thread Darrick J. Wong
On Tue, Oct 09, 2007 at 06:44:07PM +0200, Roel Kluin wrote:

  +  if (IS_ERR(data-hwmon_dev)) {
  +  printk(KERN_ERR DRVNAME : Error, unable to register hwmon 
  + class device for interface %d\n,
  + data-interface);
  +  kfree(data);
  +  return;
 
 don't you want to goto out_user here instead?

Err, yes, thank you for catching that.

--D
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4] IBM power meter driver

2007-09-14 Thread Darrick J. Wong
Here's a fourth revision where I've tried to clean up the things that
people complained about, as well as shifted the sysfs file names to
match the spec that we've been drifting towards.
---
ibm_pex: Driver to export IBM PowerExecutive power meter sensors.

Signed-off-by: Darrick J. Wong <[EMAIL PROTECTED]>
---

 drivers/hwmon/Kconfig  |   13 +
 drivers/hwmon/Makefile |1 
 drivers/hwmon/ibmpex.c |  608 
 3 files changed, 622 insertions(+), 0 deletions(-)

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5ca5d95..591b666 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -315,6 +315,19 @@ config SENSORS_CORETEMP
  sensor inside your CPU. Supported all are all known variants
  of Intel Core family.
 
+config SENSORS_IBMPEX
+   tristate "IBM PowerExecutive temperature/power sensors"
+   select IPMI_SI
+   depends on IPMI_HANDLER
+   help
+ If you say yes here you get support for the temperature and
+ power sensors in various IBM System X servers that support
+ PowerExecutive.  So far this includes the x3550, x3650, x3655,
+ x3755, and certain HS20 blades.
+
+ This driver can also be built as a module.  If so, the module
+ will be called ibmpex.
+
 config SENSORS_IT87
tristate "ITE IT87xx and compatibles"
select HWMON_VID
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 5070cf7..0fcbcb4 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
 obj-$(CONFIG_SENSORS_GL520SM)  += gl520sm.o
 obj-$(CONFIG_SENSORS_HDAPS)+= hdaps.o
 obj-$(CONFIG_SENSORS_I5K_AMB)  += i5k_amb.o
+obj-$(CONFIG_SENSORS_IBMPEX)   += ibmpex.o
 obj-$(CONFIG_SENSORS_IPMI) += ipmisensors.o
 obj-$(CONFIG_SENSORS_IT87) += it87.o
 obj-$(CONFIG_SENSORS_K8TEMP)   += k8temp.o
diff --git a/drivers/hwmon/ibmpex.c b/drivers/hwmon/ibmpex.c
new file mode 100644
index 000..fe2c261
--- /dev/null
+++ b/drivers/hwmon/ibmpex.c
@@ -0,0 +1,608 @@
+/*
+ * A hwmon driver for the IBM PowerExecutive temperature/power sensors
+ * Copyright (C) 2007 IBM
+ *
+ * Author: Darrick J. Wong <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define REFRESH_INTERVAL   (2 * HZ)
+#define DRVNAME"ibmpex"
+
+#define PEX_GET_VERSION1
+#define PEX_GET_SENSOR_COUNT   2
+#define PEX_GET_SENSOR_NAME3
+#define PEX_RESET_HIGH_LOW 4
+#define PEX_GET_SENSOR_DATA6
+
+#define PEX_NET_FUNCTION   0x3A
+#define PEX_COMMAND0x3C
+
+static inline u16 extract_value(const char *data, int offset)
+{
+   return be16_to_cpup((u16 *)[offset]);
+}
+
+#define TEMP_SENSOR1
+#define POWER_SENSOR   2
+
+#define PEX_SENSOR_TYPE_LEN3
+static u8 const power_sensor_sig[] = {0x70, 0x77, 0x72};
+static u8 const temp_sensor_sig[]  = {0x74, 0x65, 0x6D};
+
+#define PEX_MULT_LEN   2
+static u8 const watt_sensor_sig[]  = {0x41, 0x43};
+
+#define PEX_NUM_SENSOR_FUNCS   3
+static char const * const power_sensor_name_templates[] = {
+   "%s%d_average",
+   "%s%d_average_lowest",
+   "%s%d_average_highest"
+};
+static char const * const temp_sensor_name_templates[] = {
+   "%s%d_input",
+   "%s%d_input_lowest",
+   "%s%d_input_highest"
+};
+
+static void ibmpex_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
+static void ibmpex_register_bmc(int iface, struct device *dev);
+static void ibmpex_bmc_gone(int iface);
+
+struct ibmpex_sensor_data {
+   int in_use;
+   s16 values[PEX_NUM_SENSOR_FUNCS];
+   int multiplier;
+
+   struct sensor_device_attribute_2attr[PEX_NUM_SENSOR_FUNCS];
+};
+
+struct ibmpex_bmc_data {
+   struct list_headlist;
+   struct device   *hwmon_dev;
+   struct device   *bmc_device;
+   struct mutexlock;
+   charvalid;
+   unsigned long   last_updated;   /* In jiffies */
+
+   struct ipmi_addraddress;
+   struct completion   

[PATCH v4] IBM power meter driver

2007-09-14 Thread Darrick J. Wong
Here's a fourth revision where I've tried to clean up the things that
people complained about, as well as shifted the sysfs file names to
match the spec that we've been drifting towards.
---
ibm_pex: Driver to export IBM PowerExecutive power meter sensors.

Signed-off-by: Darrick J. Wong [EMAIL PROTECTED]
---

 drivers/hwmon/Kconfig  |   13 +
 drivers/hwmon/Makefile |1 
 drivers/hwmon/ibmpex.c |  608 
 3 files changed, 622 insertions(+), 0 deletions(-)

diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5ca5d95..591b666 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -315,6 +315,19 @@ config SENSORS_CORETEMP
  sensor inside your CPU. Supported all are all known variants
  of Intel Core family.
 
+config SENSORS_IBMPEX
+   tristate IBM PowerExecutive temperature/power sensors
+   select IPMI_SI
+   depends on IPMI_HANDLER
+   help
+ If you say yes here you get support for the temperature and
+ power sensors in various IBM System X servers that support
+ PowerExecutive.  So far this includes the x3550, x3650, x3655,
+ x3755, and certain HS20 blades.
+
+ This driver can also be built as a module.  If so, the module
+ will be called ibmpex.
+
 config SENSORS_IT87
tristate ITE IT87xx and compatibles
select HWMON_VID
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 5070cf7..0fcbcb4 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_SENSORS_GL518SM) += gl518sm.o
 obj-$(CONFIG_SENSORS_GL520SM)  += gl520sm.o
 obj-$(CONFIG_SENSORS_HDAPS)+= hdaps.o
 obj-$(CONFIG_SENSORS_I5K_AMB)  += i5k_amb.o
+obj-$(CONFIG_SENSORS_IBMPEX)   += ibmpex.o
 obj-$(CONFIG_SENSORS_IPMI) += ipmisensors.o
 obj-$(CONFIG_SENSORS_IT87) += it87.o
 obj-$(CONFIG_SENSORS_K8TEMP)   += k8temp.o
diff --git a/drivers/hwmon/ibmpex.c b/drivers/hwmon/ibmpex.c
new file mode 100644
index 000..fe2c261
--- /dev/null
+++ b/drivers/hwmon/ibmpex.c
@@ -0,0 +1,608 @@
+/*
+ * A hwmon driver for the IBM PowerExecutive temperature/power sensors
+ * Copyright (C) 2007 IBM
+ *
+ * Author: Darrick J. Wong [EMAIL PROTECTED]
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include linux/ipmi.h
+#include linux/module.h
+#include linux/hwmon.h
+#include linux/hwmon-sysfs.h
+#include linux/jiffies.h
+#include linux/mutex.h
+
+#define REFRESH_INTERVAL   (2 * HZ)
+#define DRVNAMEibmpex
+
+#define PEX_GET_VERSION1
+#define PEX_GET_SENSOR_COUNT   2
+#define PEX_GET_SENSOR_NAME3
+#define PEX_RESET_HIGH_LOW 4
+#define PEX_GET_SENSOR_DATA6
+
+#define PEX_NET_FUNCTION   0x3A
+#define PEX_COMMAND0x3C
+
+static inline u16 extract_value(const char *data, int offset)
+{
+   return be16_to_cpup((u16 *)data[offset]);
+}
+
+#define TEMP_SENSOR1
+#define POWER_SENSOR   2
+
+#define PEX_SENSOR_TYPE_LEN3
+static u8 const power_sensor_sig[] = {0x70, 0x77, 0x72};
+static u8 const temp_sensor_sig[]  = {0x74, 0x65, 0x6D};
+
+#define PEX_MULT_LEN   2
+static u8 const watt_sensor_sig[]  = {0x41, 0x43};
+
+#define PEX_NUM_SENSOR_FUNCS   3
+static char const * const power_sensor_name_templates[] = {
+   %s%d_average,
+   %s%d_average_lowest,
+   %s%d_average_highest
+};
+static char const * const temp_sensor_name_templates[] = {
+   %s%d_input,
+   %s%d_input_lowest,
+   %s%d_input_highest
+};
+
+static void ibmpex_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
+static void ibmpex_register_bmc(int iface, struct device *dev);
+static void ibmpex_bmc_gone(int iface);
+
+struct ibmpex_sensor_data {
+   int in_use;
+   s16 values[PEX_NUM_SENSOR_FUNCS];
+   int multiplier;
+
+   struct sensor_device_attribute_2attr[PEX_NUM_SENSOR_FUNCS];
+};
+
+struct ibmpex_bmc_data {
+   struct list_headlist;
+   struct device   *hwmon_dev;
+   struct device   *bmc_device;
+   struct mutexlock;
+   charvalid;
+   unsigned long   last_updated;   /* In jiffies */
+
+   struct