diff options
author | Corey Minyard <cminyard@mvista.com> | 2017-09-16 16:11:48 -0400 |
---|---|---|
committer | Corey Minyard <cminyard@mvista.com> | 2017-09-28 13:26:02 -0400 |
commit | ac2673d56be609168c3f0792588c1f9ef5824041 (patch) | |
tree | d8129de169e1a12304257f53c9360c63726e2c81 | |
parent | 3dd377b5b07707c1a37e9129b36eaa1a86ccf9cf (diff) |
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>
-rw-r--r-- | drivers/char/ipmi/ipmi_ssif.c | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/drivers/char/ipmi/ipmi_ssif.c b/drivers/char/ipmi/ipmi_ssif.c index dd716d06ce73..7b2d4000b11e 100644 --- a/drivers/char/ipmi/ipmi_ssif.c +++ b/drivers/char/ipmi/ipmi_ssif.c | |||
@@ -1173,6 +1173,61 @@ MODULE_PARM_DESC(trydmi, "Setting this to zero will disable the default scan of | |||
1173 | static DEFINE_MUTEX(ssif_infos_mutex); | 1173 | static DEFINE_MUTEX(ssif_infos_mutex); |
1174 | static LIST_HEAD(ssif_infos); | 1174 | static LIST_HEAD(ssif_infos); |
1175 | 1175 | ||
1176 | #define IPMI_SSIF_ATTR(name) \ | ||
1177 | static ssize_t ipmi_##name##_show(struct device *dev, \ | ||
1178 | struct device_attribute *attr, \ | ||
1179 | char *buf) \ | ||
1180 | { \ | ||
1181 | struct ssif_info *ssif_info = dev_get_drvdata(dev); \ | ||
1182 | \ | ||
1183 | return snprintf(buf, 10, "%u\n", ssif_get_stat(ssif_info, name));\ | ||
1184 | } \ | ||
1185 | static DEVICE_ATTR(name, S_IRUGO, ipmi_##name##_show, NULL) | ||
1186 | |||
1187 | static ssize_t ipmi_type_show(struct device *dev, | ||
1188 | struct device_attribute *attr, | ||
1189 | char *buf) | ||
1190 | { | ||
1191 | return snprintf(buf, 10, "ssif\n"); | ||
1192 | } | ||
1193 | static DEVICE_ATTR(type, S_IRUGO, ipmi_type_show, NULL); | ||
1194 | |||
1195 | IPMI_SSIF_ATTR(sent_messages); | ||
1196 | IPMI_SSIF_ATTR(sent_messages_parts); | ||
1197 | IPMI_SSIF_ATTR(send_retries); | ||
1198 | IPMI_SSIF_ATTR(send_errors); | ||
1199 | IPMI_SSIF_ATTR(received_messages); | ||
1200 | IPMI_SSIF_ATTR(received_message_parts); | ||
1201 | IPMI_SSIF_ATTR(receive_retries); | ||
1202 | IPMI_SSIF_ATTR(receive_errors); | ||
1203 | IPMI_SSIF_ATTR(flag_fetches); | ||
1204 | IPMI_SSIF_ATTR(hosed); | ||
1205 | IPMI_SSIF_ATTR(events); | ||
1206 | IPMI_SSIF_ATTR(watchdog_pretimeouts); | ||
1207 | IPMI_SSIF_ATTR(alerts); | ||
1208 | |||
1209 | static struct attribute *ipmi_ssif_dev_attrs[] = { | ||
1210 | &dev_attr_type.attr, | ||
1211 | &dev_attr_sent_messages.attr, | ||
1212 | &dev_attr_sent_messages_parts.attr, | ||
1213 | &dev_attr_send_retries.attr, | ||
1214 | &dev_attr_send_errors.attr, | ||
1215 | &dev_attr_received_messages.attr, | ||
1216 | &dev_attr_received_message_parts.attr, | ||
1217 | &dev_attr_receive_retries.attr, | ||
1218 | &dev_attr_receive_errors.attr, | ||
1219 | &dev_attr_flag_fetches.attr, | ||
1220 | &dev_attr_hosed.attr, | ||
1221 | &dev_attr_events.attr, | ||
1222 | &dev_attr_watchdog_pretimeouts.attr, | ||
1223 | &dev_attr_alerts.attr, | ||
1224 | NULL | ||
1225 | }; | ||
1226 | |||
1227 | static const struct attribute_group ipmi_ssif_dev_attr_group = { | ||
1228 | .attrs = ipmi_ssif_dev_attrs, | ||
1229 | }; | ||
1230 | |||
1176 | static int ssif_remove(struct i2c_client *client) | 1231 | static int ssif_remove(struct i2c_client *client) |
1177 | { | 1232 | { |
1178 | struct ssif_info *ssif_info = i2c_get_clientdata(client); | 1233 | struct ssif_info *ssif_info = i2c_get_clientdata(client); |
@@ -1193,6 +1248,9 @@ static int ssif_remove(struct i2c_client *client) | |||
1193 | } | 1248 | } |
1194 | ssif_info->intf = NULL; | 1249 | ssif_info->intf = NULL; |
1195 | 1250 | ||
1251 | device_remove_group(&ssif_info->client->dev, &ipmi_ssif_dev_attr_group); | ||
1252 | dev_set_drvdata(&ssif_info->client->dev, NULL); | ||
1253 | |||
1196 | /* make sure the driver is not looking for flags any more. */ | 1254 | /* make sure the driver is not looking for flags any more. */ |
1197 | while (ssif_info->ssif_state != SSIF_NORMAL) | 1255 | while (ssif_info->ssif_state != SSIF_NORMAL) |
1198 | schedule_timeout(1); | 1256 | schedule_timeout(1); |
@@ -1665,13 +1723,23 @@ static int ssif_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1665 | } | 1723 | } |
1666 | } | 1724 | } |
1667 | 1725 | ||
1726 | dev_set_drvdata(&ssif_info->client->dev, ssif_info); | ||
1727 | rv = device_add_group(&ssif_info->client->dev, | ||
1728 | &ipmi_ssif_dev_attr_group); | ||
1729 | if (rv) { | ||
1730 | dev_err(&ssif_info->client->dev, | ||
1731 | "Unable to add device attributes: error %d\n", | ||
1732 | rv); | ||
1733 | goto out; | ||
1734 | } | ||
1735 | |||
1668 | rv = ipmi_register_smi(&ssif_info->handlers, | 1736 | rv = ipmi_register_smi(&ssif_info->handlers, |
1669 | ssif_info, | 1737 | ssif_info, |
1670 | &ssif_info->client->dev, | 1738 | &ssif_info->client->dev, |
1671 | slave_addr); | 1739 | slave_addr); |
1672 | if (rv) { | 1740 | if (rv) { |
1673 | pr_err(PFX "Unable to register device: error %d\n", rv); | 1741 | pr_err(PFX "Unable to register device: error %d\n", rv); |
1674 | goto out; | 1742 | goto out_remove_attr; |
1675 | } | 1743 | } |
1676 | 1744 | ||
1677 | rv = ipmi_smi_add_proc_entry(ssif_info->intf, "type", | 1745 | 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) | |||
1707 | kfree(resp); | 1775 | kfree(resp); |
1708 | return rv; | 1776 | return rv; |
1709 | 1777 | ||
1710 | out_err_unreg: | 1778 | out_err_unreg: |
1711 | ipmi_unregister_smi(ssif_info->intf); | 1779 | ipmi_unregister_smi(ssif_info->intf); |
1780 | |||
1781 | out_remove_attr: | ||
1782 | device_remove_group(&ssif_info->client->dev, &ipmi_ssif_dev_attr_group); | ||
1783 | dev_set_drvdata(&ssif_info->client->dev, NULL); | ||
1712 | goto out; | 1784 | goto out; |
1713 | } | 1785 | } |
1714 | 1786 | ||