Commit df04ced6 authored by Eddie James's avatar Eddie James Committed by Guenter Roeck
Browse files

hwmon (occ): Add sysfs attributes for additional OCC data



The OCC provides a variety of additional information about the state of
the host processor, such as throttling, error conditions, and the number
of OCCs detected in the system. This information is essential to service
processor applications such as fan control and host management.
Therefore, export this data in the form of sysfs attributes attached to
the platform device (to which the hwmon device is also attached).

Signed-off-by: default avatarEddie James <eajames@linux.ibm.com>
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent 54076cb3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
occ-p8-hwmon-objs := common.o p8_i2c.o
occ-p9-hwmon-objs := common.o p9_sbe.o
occ-p8-hwmon-objs := common.o sysfs.o p8_i2c.o
occ-p9-hwmon-objs := common.o sysfs.o p9_sbe.o

obj-$(CONFIG_SENSORS_OCC_P8_I2C) += occ-p8-hwmon.o
obj-$(CONFIG_SENSORS_OCC_P9_SBE) += occ-p9-hwmon.o
+42 −3
Original line number Diff line number Diff line
@@ -14,6 +14,11 @@

#define EXTN_FLAG_SENSOR_ID		BIT(7)

#define OCC_ERROR_COUNT_THRESHOLD	2	/* required by OCC spec */

#define OCC_STATE_SAFE			4
#define OCC_SAFE_TIMEOUT		msecs_to_jiffies(60000) /* 1 min */

#define OCC_UPDATE_FREQUENCY		msecs_to_jiffies(1000)

#define OCC_TEMP_SENSOR_FAULT		0xFF
@@ -115,8 +120,10 @@ struct extended_sensor {

static int occ_poll(struct occ *occ)
{
	int rc;
	u16 checksum = occ->poll_cmd_data + 1;
	u8 cmd[8];
	struct occ_poll_response_header *header;

	/* big endian */
	cmd[0] = 0;			/* sequence number */
@@ -129,7 +136,35 @@ static int occ_poll(struct occ *occ)
	cmd[7] = 0;

	/* mutex should already be locked if necessary */
	return occ->send_cmd(occ, cmd);
	rc = occ->send_cmd(occ, cmd);
	if (rc) {
		if (occ->error_count++ > OCC_ERROR_COUNT_THRESHOLD)
			occ->error = rc;

		goto done;
	}

	/* clear error since communication was successful */
	occ->error_count = 0;
	occ->error = 0;

	/* check for safe state */
	header = (struct occ_poll_response_header *)occ->resp.data;
	if (header->occ_state == OCC_STATE_SAFE) {
		if (occ->last_safe) {
			if (time_after(jiffies,
				       occ->last_safe + OCC_SAFE_TIMEOUT))
				occ->error = -EHOSTDOWN;
		} else {
			occ->last_safe = jiffies;
		}
	} else {
		occ->last_safe = 0;
	}

done:
	occ_sysfs_poll_done(occ);
	return rc;
}

static int occ_set_user_power_cap(struct occ *occ, u16 user_power_cap)
@@ -161,7 +196,7 @@ static int occ_set_user_power_cap(struct occ *occ, u16 user_power_cap)
	return rc;
}

static int occ_update_response(struct occ *occ)
int occ_update_response(struct occ *occ)
{
	int rc = mutex_lock_interruptible(&occ->lock);

@@ -1055,5 +1090,9 @@ int occ_setup(struct occ *occ, const char *name)
		return rc;
	}

	return 0;
	rc = occ_setup_sysfs(occ);
	if (rc)
		dev_err(occ->bus_dev, "failed to setup sysfs: %d\n", rc);

	return rc;
}
+17 −0
Original line number Diff line number Diff line
@@ -104,8 +104,25 @@ struct occ {
	struct occ_attribute *attrs;
	struct attribute_group group;
	const struct attribute_group *groups[2];

	int error;                      /* latest transfer error */
	unsigned int error_count;       /* number of xfr errors observed */
	unsigned long last_safe;        /* time OCC entered "safe" state */

	/*
	 * Store the previous state data for comparison in order to notify
	 * sysfs readers of state changes.
	 */
	int prev_error;
	u8 prev_stat;
	u8 prev_ext_stat;
	u8 prev_occs_present;
};

int occ_setup(struct occ *occ, const char *name);
int occ_setup_sysfs(struct occ *occ);
void occ_shutdown(struct occ *occ);
void occ_sysfs_poll_done(struct occ *occ);
int occ_update_response(struct occ *occ);

#endif /* OCC_COMMON_H */
+10 −0
Original line number Diff line number Diff line
@@ -223,6 +223,15 @@ static int p8_i2c_occ_probe(struct i2c_client *client,
	return occ_setup(occ, "p8_occ");
}

static int p8_i2c_occ_remove(struct i2c_client *client)
{
	struct occ *occ = dev_get_drvdata(&client->dev);

	occ_shutdown(occ);

	return 0;
}

static const struct of_device_id p8_i2c_occ_of_match[] = {
	{ .compatible = "ibm,p8-occ-hwmon" },
	{}
@@ -236,6 +245,7 @@ static struct i2c_driver p8_i2c_occ_driver = {
		.of_match_table = p8_i2c_occ_of_match,
	},
	.probe = p8_i2c_occ_probe,
	.remove = p8_i2c_occ_remove,
};

module_i2c_driver(p8_i2c_occ_driver);
+1 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ static int p9_sbe_occ_remove(struct platform_device *pdev)
	struct p9_sbe_occ *ctx = to_p9_sbe_occ(occ);

	ctx->sbe = NULL;
	occ_shutdown(occ);

	return 0;
}
Loading