ipmi_ssif: Add device attrs for the things in proc

Create a device attribute for everything we show in proc, getting
ready for removing the proc stuff.

Signed-off-by: Corey Minyard <cminyard@mvista.com>
This commit is contained in:
Corey Minyard 2017-09-16 15:11:48 -05:00
parent 3dd377b5b0
commit ac2673d56b
1 changed files with 74 additions and 2 deletions

View File

@ -1173,6 +1173,61 @@ MODULE_PARM_DESC(trydmi, "Setting this to zero will disable the default scan of
static DEFINE_MUTEX(ssif_infos_mutex);
static LIST_HEAD(ssif_infos);
#define IPMI_SSIF_ATTR(name) \
static ssize_t ipmi_##name##_show(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
struct ssif_info *ssif_info = dev_get_drvdata(dev); \
\
return snprintf(buf, 10, "%u\n", ssif_get_stat(ssif_info, name));\
} \
static DEVICE_ATTR(name, S_IRUGO, ipmi_##name##_show, NULL)
static ssize_t ipmi_type_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
return snprintf(buf, 10, "ssif\n");
}
static DEVICE_ATTR(type, S_IRUGO, ipmi_type_show, NULL);
IPMI_SSIF_ATTR(sent_messages);
IPMI_SSIF_ATTR(sent_messages_parts);
IPMI_SSIF_ATTR(send_retries);
IPMI_SSIF_ATTR(send_errors);
IPMI_SSIF_ATTR(received_messages);
IPMI_SSIF_ATTR(received_message_parts);
IPMI_SSIF_ATTR(receive_retries);
IPMI_SSIF_ATTR(receive_errors);
IPMI_SSIF_ATTR(flag_fetches);
IPMI_SSIF_ATTR(hosed);
IPMI_SSIF_ATTR(events);
IPMI_SSIF_ATTR(watchdog_pretimeouts);
IPMI_SSIF_ATTR(alerts);
static struct attribute *ipmi_ssif_dev_attrs[] = {
&dev_attr_type.attr,
&dev_attr_sent_messages.attr,
&dev_attr_sent_messages_parts.attr,
&dev_attr_send_retries.attr,
&dev_attr_send_errors.attr,
&dev_attr_received_messages.attr,
&dev_attr_received_message_parts.attr,
&dev_attr_receive_retries.attr,
&dev_attr_receive_errors.attr,
&dev_attr_flag_fetches.attr,
&dev_attr_hosed.attr,
&dev_attr_events.attr,
&dev_attr_watchdog_pretimeouts.attr,
&dev_attr_alerts.attr,
NULL
};
static const struct attribute_group ipmi_ssif_dev_attr_group = {
.attrs = ipmi_ssif_dev_attrs,
};
static int ssif_remove(struct i2c_client *client)
{
struct ssif_info *ssif_info = i2c_get_clientdata(client);
@ -1193,6 +1248,9 @@ static int ssif_remove(struct i2c_client *client)
}
ssif_info->intf = NULL;
device_remove_group(&ssif_info->client->dev, &ipmi_ssif_dev_attr_group);
dev_set_drvdata(&ssif_info->client->dev, NULL);
/* make sure the driver is not looking for flags any more. */
while (ssif_info->ssif_state != SSIF_NORMAL)
schedule_timeout(1);
@ -1665,13 +1723,23 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
}
}
dev_set_drvdata(&ssif_info->client->dev, ssif_info);
rv = device_add_group(&ssif_info->client->dev,
&ipmi_ssif_dev_attr_group);
if (rv) {
dev_err(&ssif_info->client->dev,
"Unable to add device attributes: error %d\n",
rv);
goto out;
}
rv = ipmi_register_smi(&ssif_info->handlers,
ssif_info,
&ssif_info->client->dev,
slave_addr);
if (rv) {
pr_err(PFX "Unable to register device: error %d\n", rv);
goto out;
goto out_remove_attr;
}
rv = ipmi_smi_add_proc_entry(ssif_info->intf, "type",
@ -1707,8 +1775,12 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id)
kfree(resp);
return rv;
out_err_unreg:
out_err_unreg:
ipmi_unregister_smi(ssif_info->intf);
out_remove_attr:
device_remove_group(&ssif_info->client->dev, &ipmi_ssif_dev_attr_group);
dev_set_drvdata(&ssif_info->client->dev, NULL);
goto out;
}