diff options
author | Sebastian Ott <sebott@linux.vnet.ibm.com> | 2012-05-15 11:54:12 -0400 |
---|---|---|
committer | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2012-05-16 08:42:47 -0400 |
commit | 20cdffa437f51f3afdf41e431ca17014434d3037 (patch) | |
tree | 5bcb41f1ff17a1ca60c245c46ff6a5d7427a9f9e /drivers/s390 | |
parent | b7a610f7b4cb95150ee58ea7454ca2ace10634c5 (diff) |
s390/ctcm: switch to ccwgroup_create_dev
Switch to the new ccwgroup_create_dev interface. Also wrap device
attributes in a struct device_type and let the driver core create
these attributes automagically.
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Sebastian Ott <sebott@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'drivers/s390')
-rw-r--r-- | drivers/s390/net/ctcm_main.c | 36 | ||||
-rw-r--r-- | drivers/s390/net/ctcm_main.h | 8 | ||||
-rw-r--r-- | drivers/s390/net/ctcm_sysfs.c | 37 |
3 files changed, 22 insertions, 59 deletions
diff --git a/drivers/s390/net/ctcm_main.c b/drivers/s390/net/ctcm_main.c index 11f3b071f305..abb84c3849e0 100644 --- a/drivers/s390/net/ctcm_main.c +++ b/drivers/s390/net/ctcm_main.c | |||
@@ -1296,6 +1296,11 @@ static void ctcm_irq_handler(struct ccw_device *cdev, | |||
1296 | 1296 | ||
1297 | } | 1297 | } |
1298 | 1298 | ||
1299 | static const struct device_type ctcm_devtype = { | ||
1300 | .name = "ctcm", | ||
1301 | .groups = ctcm_attr_groups, | ||
1302 | }; | ||
1303 | |||
1299 | /** | 1304 | /** |
1300 | * Add ctcm specific attributes. | 1305 | * Add ctcm specific attributes. |
1301 | * Add ctcm private data. | 1306 | * Add ctcm private data. |
@@ -1307,7 +1312,6 @@ static void ctcm_irq_handler(struct ccw_device *cdev, | |||
1307 | static int ctcm_probe_device(struct ccwgroup_device *cgdev) | 1312 | static int ctcm_probe_device(struct ccwgroup_device *cgdev) |
1308 | { | 1313 | { |
1309 | struct ctcm_priv *priv; | 1314 | struct ctcm_priv *priv; |
1310 | int rc; | ||
1311 | 1315 | ||
1312 | CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, | 1316 | CTCM_DBF_TEXT_(SETUP, CTC_DBF_INFO, |
1313 | "%s %p", | 1317 | "%s %p", |
@@ -1324,17 +1328,11 @@ static int ctcm_probe_device(struct ccwgroup_device *cgdev) | |||
1324 | put_device(&cgdev->dev); | 1328 | put_device(&cgdev->dev); |
1325 | return -ENOMEM; | 1329 | return -ENOMEM; |
1326 | } | 1330 | } |
1327 | |||
1328 | rc = ctcm_add_files(&cgdev->dev); | ||
1329 | if (rc) { | ||
1330 | kfree(priv); | ||
1331 | put_device(&cgdev->dev); | ||
1332 | return rc; | ||
1333 | } | ||
1334 | priv->buffer_size = CTCM_BUFSIZE_DEFAULT; | 1331 | priv->buffer_size = CTCM_BUFSIZE_DEFAULT; |
1335 | cgdev->cdev[0]->handler = ctcm_irq_handler; | 1332 | cgdev->cdev[0]->handler = ctcm_irq_handler; |
1336 | cgdev->cdev[1]->handler = ctcm_irq_handler; | 1333 | cgdev->cdev[1]->handler = ctcm_irq_handler; |
1337 | dev_set_drvdata(&cgdev->dev, priv); | 1334 | dev_set_drvdata(&cgdev->dev, priv); |
1335 | cgdev->dev.type = &ctcm_devtype; | ||
1338 | 1336 | ||
1339 | return 0; | 1337 | return 0; |
1340 | } | 1338 | } |
@@ -1611,11 +1609,6 @@ static int ctcm_new_device(struct ccwgroup_device *cgdev) | |||
1611 | goto out_dev; | 1609 | goto out_dev; |
1612 | } | 1610 | } |
1613 | 1611 | ||
1614 | if (ctcm_add_attributes(&cgdev->dev)) { | ||
1615 | result = -ENODEV; | ||
1616 | goto out_unregister; | ||
1617 | } | ||
1618 | |||
1619 | strlcpy(priv->fsm->name, dev->name, sizeof(priv->fsm->name)); | 1612 | strlcpy(priv->fsm->name, dev->name, sizeof(priv->fsm->name)); |
1620 | 1613 | ||
1621 | dev_info(&dev->dev, | 1614 | dev_info(&dev->dev, |
@@ -1629,8 +1622,6 @@ static int ctcm_new_device(struct ccwgroup_device *cgdev) | |||
1629 | priv->channel[CTCM_WRITE]->id, priv->protocol); | 1622 | priv->channel[CTCM_WRITE]->id, priv->protocol); |
1630 | 1623 | ||
1631 | return 0; | 1624 | return 0; |
1632 | out_unregister: | ||
1633 | unregister_netdev(dev); | ||
1634 | out_dev: | 1625 | out_dev: |
1635 | ctcm_free_netdevice(dev); | 1626 | ctcm_free_netdevice(dev); |
1636 | out_ccw2: | 1627 | out_ccw2: |
@@ -1669,7 +1660,6 @@ static int ctcm_shutdown_device(struct ccwgroup_device *cgdev) | |||
1669 | /* Close the device */ | 1660 | /* Close the device */ |
1670 | ctcm_close(dev); | 1661 | ctcm_close(dev); |
1671 | dev->flags &= ~IFF_RUNNING; | 1662 | dev->flags &= ~IFF_RUNNING; |
1672 | ctcm_remove_attributes(&cgdev->dev); | ||
1673 | channel_free(priv->channel[CTCM_READ]); | 1663 | channel_free(priv->channel[CTCM_READ]); |
1674 | } else | 1664 | } else |
1675 | dev = NULL; | 1665 | dev = NULL; |
@@ -1711,7 +1701,6 @@ static void ctcm_remove_device(struct ccwgroup_device *cgdev) | |||
1711 | 1701 | ||
1712 | if (cgdev->state == CCWGROUP_ONLINE) | 1702 | if (cgdev->state == CCWGROUP_ONLINE) |
1713 | ctcm_shutdown_device(cgdev); | 1703 | ctcm_shutdown_device(cgdev); |
1714 | ctcm_remove_files(&cgdev->dev); | ||
1715 | dev_set_drvdata(&cgdev->dev, NULL); | 1704 | dev_set_drvdata(&cgdev->dev, NULL); |
1716 | kfree(priv); | 1705 | kfree(priv); |
1717 | put_device(&cgdev->dev); | 1706 | put_device(&cgdev->dev); |
@@ -1780,7 +1769,7 @@ static struct ccwgroup_driver ctcm_group_driver = { | |||
1780 | }, | 1769 | }, |
1781 | .max_slaves = 2, | 1770 | .max_slaves = 2, |
1782 | .driver_id = 0xC3E3C3D4, /* CTCM */ | 1771 | .driver_id = 0xC3E3C3D4, /* CTCM */ |
1783 | .probe = ctcm_probe_device, | 1772 | .setup = ctcm_probe_device, |
1784 | .remove = ctcm_remove_device, | 1773 | .remove = ctcm_remove_device, |
1785 | .set_online = ctcm_new_device, | 1774 | .set_online = ctcm_new_device, |
1786 | .set_offline = ctcm_shutdown_device, | 1775 | .set_offline = ctcm_shutdown_device, |
@@ -1789,18 +1778,15 @@ static struct ccwgroup_driver ctcm_group_driver = { | |||
1789 | .restore = ctcm_pm_resume, | 1778 | .restore = ctcm_pm_resume, |
1790 | }; | 1779 | }; |
1791 | 1780 | ||
1792 | static ssize_t | 1781 | static ssize_t ctcm_driver_group_store(struct device_driver *ddrv, |
1793 | ctcm_driver_group_store(struct device_driver *ddrv, const char *buf, | 1782 | const char *buf, size_t count) |
1794 | size_t count) | ||
1795 | { | 1783 | { |
1796 | int err; | 1784 | int err; |
1797 | 1785 | ||
1798 | err = ccwgroup_create_from_string(ctcm_root_dev, | 1786 | err = ccwgroup_create_dev(ctcm_root_dev, ctcm_group_driver.driver_id, |
1799 | ctcm_group_driver.driver_id, | 1787 | &ctcm_group_driver, 2, buf); |
1800 | &ctcm_ccw_driver, 2, buf); | ||
1801 | return err ? err : count; | 1788 | return err ? err : count; |
1802 | } | 1789 | } |
1803 | |||
1804 | static DRIVER_ATTR(group, 0200, NULL, ctcm_driver_group_store); | 1790 | static DRIVER_ATTR(group, 0200, NULL, ctcm_driver_group_store); |
1805 | 1791 | ||
1806 | static struct attribute *ctcm_group_attrs[] = { | 1792 | static struct attribute *ctcm_group_attrs[] = { |
diff --git a/drivers/s390/net/ctcm_main.h b/drivers/s390/net/ctcm_main.h index 24d5215eb0c4..b9056a55d995 100644 --- a/drivers/s390/net/ctcm_main.h +++ b/drivers/s390/net/ctcm_main.h | |||
@@ -225,13 +225,7 @@ struct ctcm_priv { | |||
225 | int ctcm_open(struct net_device *dev); | 225 | int ctcm_open(struct net_device *dev); |
226 | int ctcm_close(struct net_device *dev); | 226 | int ctcm_close(struct net_device *dev); |
227 | 227 | ||
228 | /* | 228 | extern const struct attribute_group *ctcm_attr_groups[]; |
229 | * prototypes for non-static sysfs functions | ||
230 | */ | ||
231 | int ctcm_add_attributes(struct device *dev); | ||
232 | void ctcm_remove_attributes(struct device *dev); | ||
233 | int ctcm_add_files(struct device *dev); | ||
234 | void ctcm_remove_files(struct device *dev); | ||
235 | 229 | ||
236 | /* | 230 | /* |
237 | * Compatibility macros for busy handling | 231 | * Compatibility macros for busy handling |
diff --git a/drivers/s390/net/ctcm_sysfs.c b/drivers/s390/net/ctcm_sysfs.c index 650aec1839e9..0c27ae726475 100644 --- a/drivers/s390/net/ctcm_sysfs.c +++ b/drivers/s390/net/ctcm_sysfs.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #define KMSG_COMPONENT "ctcm" | 13 | #define KMSG_COMPONENT "ctcm" |
14 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | 14 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
15 | 15 | ||
16 | #include <linux/device.h> | ||
16 | #include <linux/sysfs.h> | 17 | #include <linux/sysfs.h> |
17 | #include <linux/slab.h> | 18 | #include <linux/slab.h> |
18 | #include "ctcm_main.h" | 19 | #include "ctcm_main.h" |
@@ -108,10 +109,12 @@ static void ctcm_print_statistics(struct ctcm_priv *priv) | |||
108 | } | 109 | } |
109 | 110 | ||
110 | static ssize_t stats_show(struct device *dev, | 111 | static ssize_t stats_show(struct device *dev, |
111 | struct device_attribute *attr, char *buf) | 112 | struct device_attribute *attr, char *buf) |
112 | { | 113 | { |
114 | struct ccwgroup_device *gdev = to_ccwgroupdev(dev); | ||
113 | struct ctcm_priv *priv = dev_get_drvdata(dev); | 115 | struct ctcm_priv *priv = dev_get_drvdata(dev); |
114 | if (!priv) | 116 | |
117 | if (!priv || gdev->state != CCWGROUP_ONLINE) | ||
115 | return -ENODEV; | 118 | return -ENODEV; |
116 | ctcm_print_statistics(priv); | 119 | ctcm_print_statistics(priv); |
117 | return sprintf(buf, "0\n"); | 120 | return sprintf(buf, "0\n"); |
@@ -190,34 +193,14 @@ static struct attribute *ctcm_attr[] = { | |||
190 | &dev_attr_protocol.attr, | 193 | &dev_attr_protocol.attr, |
191 | &dev_attr_type.attr, | 194 | &dev_attr_type.attr, |
192 | &dev_attr_buffer.attr, | 195 | &dev_attr_buffer.attr, |
196 | &dev_attr_stats.attr, | ||
193 | NULL, | 197 | NULL, |
194 | }; | 198 | }; |
195 | 199 | ||
196 | static struct attribute_group ctcm_attr_group = { | 200 | static struct attribute_group ctcm_attr_group = { |
197 | .attrs = ctcm_attr, | 201 | .attrs = ctcm_attr, |
198 | }; | 202 | }; |
199 | 203 | const struct attribute_group *ctcm_attr_groups[] = { | |
200 | int ctcm_add_attributes(struct device *dev) | 204 | &ctcm_attr_group, |
201 | { | 205 | NULL, |
202 | int rc; | 206 | }; |
203 | |||
204 | rc = device_create_file(dev, &dev_attr_stats); | ||
205 | |||
206 | return rc; | ||
207 | } | ||
208 | |||
209 | void ctcm_remove_attributes(struct device *dev) | ||
210 | { | ||
211 | device_remove_file(dev, &dev_attr_stats); | ||
212 | } | ||
213 | |||
214 | int ctcm_add_files(struct device *dev) | ||
215 | { | ||
216 | return sysfs_create_group(&dev->kobj, &ctcm_attr_group); | ||
217 | } | ||
218 | |||
219 | void ctcm_remove_files(struct device *dev) | ||
220 | { | ||
221 | sysfs_remove_group(&dev->kobj, &ctcm_attr_group); | ||
222 | } | ||
223 | |||