diff options
Diffstat (limited to 'drivers/s390/cio/device.c')
-rw-r--r-- | drivers/s390/cio/device.c | 157 |
1 files changed, 121 insertions, 36 deletions
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c index 74f6b539974a..d35dc3f25d06 100644 --- a/drivers/s390/cio/device.c +++ b/drivers/s390/cio/device.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/list.h> | 17 | #include <linux/list.h> |
18 | #include <linux/device.h> | 18 | #include <linux/device.h> |
19 | #include <linux/workqueue.h> | 19 | #include <linux/workqueue.h> |
20 | #include <linux/timer.h> | ||
20 | 21 | ||
21 | #include <asm/ccwdev.h> | 22 | #include <asm/ccwdev.h> |
22 | #include <asm/cio.h> | 23 | #include <asm/cio.h> |
@@ -28,6 +29,12 @@ | |||
28 | #include "css.h" | 29 | #include "css.h" |
29 | #include "device.h" | 30 | #include "device.h" |
30 | #include "ioasm.h" | 31 | #include "ioasm.h" |
32 | #include "io_sch.h" | ||
33 | |||
34 | static struct timer_list recovery_timer; | ||
35 | static spinlock_t recovery_lock; | ||
36 | static int recovery_phase; | ||
37 | static const unsigned long recovery_delay[] = { 3, 30, 300 }; | ||
31 | 38 | ||
32 | /******************* bus type handling ***********************/ | 39 | /******************* bus type handling ***********************/ |
33 | 40 | ||
@@ -115,19 +122,18 @@ static int ccw_uevent(struct device *dev, struct kobj_uevent_env *env) | |||
115 | 122 | ||
116 | struct bus_type ccw_bus_type; | 123 | struct bus_type ccw_bus_type; |
117 | 124 | ||
118 | static int io_subchannel_probe (struct subchannel *); | 125 | static void io_subchannel_irq(struct subchannel *); |
119 | static int io_subchannel_remove (struct subchannel *); | 126 | static int io_subchannel_probe(struct subchannel *); |
120 | static int io_subchannel_notify(struct device *, int); | 127 | static int io_subchannel_remove(struct subchannel *); |
121 | static void io_subchannel_verify(struct device *); | 128 | static int io_subchannel_notify(struct subchannel *, int); |
122 | static void io_subchannel_ioterm(struct device *); | 129 | static void io_subchannel_verify(struct subchannel *); |
130 | static void io_subchannel_ioterm(struct subchannel *); | ||
123 | static void io_subchannel_shutdown(struct subchannel *); | 131 | static void io_subchannel_shutdown(struct subchannel *); |
124 | 132 | ||
125 | static struct css_driver io_subchannel_driver = { | 133 | static struct css_driver io_subchannel_driver = { |
134 | .owner = THIS_MODULE, | ||
126 | .subchannel_type = SUBCHANNEL_TYPE_IO, | 135 | .subchannel_type = SUBCHANNEL_TYPE_IO, |
127 | .drv = { | 136 | .name = "io_subchannel", |
128 | .name = "io_subchannel", | ||
129 | .bus = &css_bus_type, | ||
130 | }, | ||
131 | .irq = io_subchannel_irq, | 137 | .irq = io_subchannel_irq, |
132 | .notify = io_subchannel_notify, | 138 | .notify = io_subchannel_notify, |
133 | .verify = io_subchannel_verify, | 139 | .verify = io_subchannel_verify, |
@@ -142,6 +148,8 @@ struct workqueue_struct *ccw_device_notify_work; | |||
142 | wait_queue_head_t ccw_device_init_wq; | 148 | wait_queue_head_t ccw_device_init_wq; |
143 | atomic_t ccw_device_init_count; | 149 | atomic_t ccw_device_init_count; |
144 | 150 | ||
151 | static void recovery_func(unsigned long data); | ||
152 | |||
145 | static int __init | 153 | static int __init |
146 | init_ccw_bus_type (void) | 154 | init_ccw_bus_type (void) |
147 | { | 155 | { |
@@ -149,6 +157,7 @@ init_ccw_bus_type (void) | |||
149 | 157 | ||
150 | init_waitqueue_head(&ccw_device_init_wq); | 158 | init_waitqueue_head(&ccw_device_init_wq); |
151 | atomic_set(&ccw_device_init_count, 0); | 159 | atomic_set(&ccw_device_init_count, 0); |
160 | setup_timer(&recovery_timer, recovery_func, 0); | ||
152 | 161 | ||
153 | ccw_device_work = create_singlethread_workqueue("cio"); | 162 | ccw_device_work = create_singlethread_workqueue("cio"); |
154 | if (!ccw_device_work) | 163 | if (!ccw_device_work) |
@@ -166,7 +175,8 @@ init_ccw_bus_type (void) | |||
166 | if ((ret = bus_register (&ccw_bus_type))) | 175 | if ((ret = bus_register (&ccw_bus_type))) |
167 | goto out_err; | 176 | goto out_err; |
168 | 177 | ||
169 | if ((ret = driver_register(&io_subchannel_driver.drv))) | 178 | ret = css_driver_register(&io_subchannel_driver); |
179 | if (ret) | ||
170 | goto out_err; | 180 | goto out_err; |
171 | 181 | ||
172 | wait_event(ccw_device_init_wq, | 182 | wait_event(ccw_device_init_wq, |
@@ -186,7 +196,7 @@ out_err: | |||
186 | static void __exit | 196 | static void __exit |
187 | cleanup_ccw_bus_type (void) | 197 | cleanup_ccw_bus_type (void) |
188 | { | 198 | { |
189 | driver_unregister(&io_subchannel_driver.drv); | 199 | css_driver_unregister(&io_subchannel_driver); |
190 | bus_unregister(&ccw_bus_type); | 200 | bus_unregister(&ccw_bus_type); |
191 | destroy_workqueue(ccw_device_notify_work); | 201 | destroy_workqueue(ccw_device_notify_work); |
192 | destroy_workqueue(ccw_device_work); | 202 | destroy_workqueue(ccw_device_work); |
@@ -773,7 +783,7 @@ static void sch_attach_device(struct subchannel *sch, | |||
773 | { | 783 | { |
774 | css_update_ssd_info(sch); | 784 | css_update_ssd_info(sch); |
775 | spin_lock_irq(sch->lock); | 785 | spin_lock_irq(sch->lock); |
776 | sch->dev.driver_data = cdev; | 786 | sch_set_cdev(sch, cdev); |
777 | cdev->private->schid = sch->schid; | 787 | cdev->private->schid = sch->schid; |
778 | cdev->ccwlock = sch->lock; | 788 | cdev->ccwlock = sch->lock; |
779 | device_trigger_reprobe(sch); | 789 | device_trigger_reprobe(sch); |
@@ -795,7 +805,7 @@ static void sch_attach_disconnected_device(struct subchannel *sch, | |||
795 | put_device(&other_sch->dev); | 805 | put_device(&other_sch->dev); |
796 | return; | 806 | return; |
797 | } | 807 | } |
798 | other_sch->dev.driver_data = NULL; | 808 | sch_set_cdev(other_sch, NULL); |
799 | /* No need to keep a subchannel without ccw device around. */ | 809 | /* No need to keep a subchannel without ccw device around. */ |
800 | css_sch_device_unregister(other_sch); | 810 | css_sch_device_unregister(other_sch); |
801 | put_device(&other_sch->dev); | 811 | put_device(&other_sch->dev); |
@@ -831,12 +841,12 @@ static void sch_create_and_recog_new_device(struct subchannel *sch) | |||
831 | return; | 841 | return; |
832 | } | 842 | } |
833 | spin_lock_irq(sch->lock); | 843 | spin_lock_irq(sch->lock); |
834 | sch->dev.driver_data = cdev; | 844 | sch_set_cdev(sch, cdev); |
835 | spin_unlock_irq(sch->lock); | 845 | spin_unlock_irq(sch->lock); |
836 | /* Start recognition for the new ccw device. */ | 846 | /* Start recognition for the new ccw device. */ |
837 | if (io_subchannel_recog(cdev, sch)) { | 847 | if (io_subchannel_recog(cdev, sch)) { |
838 | spin_lock_irq(sch->lock); | 848 | spin_lock_irq(sch->lock); |
839 | sch->dev.driver_data = NULL; | 849 | sch_set_cdev(sch, NULL); |
840 | spin_unlock_irq(sch->lock); | 850 | spin_unlock_irq(sch->lock); |
841 | if (cdev->dev.release) | 851 | if (cdev->dev.release) |
842 | cdev->dev.release(&cdev->dev); | 852 | cdev->dev.release(&cdev->dev); |
@@ -940,7 +950,7 @@ io_subchannel_register(struct work_struct *work) | |||
940 | cdev->private->dev_id.devno, ret); | 950 | cdev->private->dev_id.devno, ret); |
941 | put_device(&cdev->dev); | 951 | put_device(&cdev->dev); |
942 | spin_lock_irqsave(sch->lock, flags); | 952 | spin_lock_irqsave(sch->lock, flags); |
943 | sch->dev.driver_data = NULL; | 953 | sch_set_cdev(sch, NULL); |
944 | spin_unlock_irqrestore(sch->lock, flags); | 954 | spin_unlock_irqrestore(sch->lock, flags); |
945 | kfree (cdev->private); | 955 | kfree (cdev->private); |
946 | kfree (cdev); | 956 | kfree (cdev); |
@@ -1022,7 +1032,7 @@ io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch) | |||
1022 | int rc; | 1032 | int rc; |
1023 | struct ccw_device_private *priv; | 1033 | struct ccw_device_private *priv; |
1024 | 1034 | ||
1025 | sch->dev.driver_data = cdev; | 1035 | sch_set_cdev(sch, cdev); |
1026 | sch->driver = &io_subchannel_driver; | 1036 | sch->driver = &io_subchannel_driver; |
1027 | cdev->ccwlock = sch->lock; | 1037 | cdev->ccwlock = sch->lock; |
1028 | 1038 | ||
@@ -1082,7 +1092,7 @@ static void ccw_device_move_to_sch(struct work_struct *work) | |||
1082 | } | 1092 | } |
1083 | if (former_parent) { | 1093 | if (former_parent) { |
1084 | spin_lock_irq(former_parent->lock); | 1094 | spin_lock_irq(former_parent->lock); |
1085 | former_parent->dev.driver_data = NULL; | 1095 | sch_set_cdev(former_parent, NULL); |
1086 | spin_unlock_irq(former_parent->lock); | 1096 | spin_unlock_irq(former_parent->lock); |
1087 | css_sch_device_unregister(former_parent); | 1097 | css_sch_device_unregister(former_parent); |
1088 | /* Reset intparm to zeroes. */ | 1098 | /* Reset intparm to zeroes. */ |
@@ -1096,6 +1106,18 @@ out: | |||
1096 | put_device(&cdev->dev); | 1106 | put_device(&cdev->dev); |
1097 | } | 1107 | } |
1098 | 1108 | ||
1109 | static void io_subchannel_irq(struct subchannel *sch) | ||
1110 | { | ||
1111 | struct ccw_device *cdev; | ||
1112 | |||
1113 | cdev = sch_get_cdev(sch); | ||
1114 | |||
1115 | CIO_TRACE_EVENT(3, "IRQ"); | ||
1116 | CIO_TRACE_EVENT(3, sch->dev.bus_id); | ||
1117 | if (cdev) | ||
1118 | dev_fsm_event(cdev, DEV_EVENT_INTERRUPT); | ||
1119 | } | ||
1120 | |||
1099 | static int | 1121 | static int |
1100 | io_subchannel_probe (struct subchannel *sch) | 1122 | io_subchannel_probe (struct subchannel *sch) |
1101 | { | 1123 | { |
@@ -1104,13 +1126,13 @@ io_subchannel_probe (struct subchannel *sch) | |||
1104 | unsigned long flags; | 1126 | unsigned long flags; |
1105 | struct ccw_dev_id dev_id; | 1127 | struct ccw_dev_id dev_id; |
1106 | 1128 | ||
1107 | if (sch->dev.driver_data) { | 1129 | cdev = sch_get_cdev(sch); |
1130 | if (cdev) { | ||
1108 | /* | 1131 | /* |
1109 | * This subchannel already has an associated ccw_device. | 1132 | * This subchannel already has an associated ccw_device. |
1110 | * Register it and exit. This happens for all early | 1133 | * Register it and exit. This happens for all early |
1111 | * device, e.g. the console. | 1134 | * device, e.g. the console. |
1112 | */ | 1135 | */ |
1113 | cdev = sch->dev.driver_data; | ||
1114 | cdev->dev.groups = ccwdev_attr_groups; | 1136 | cdev->dev.groups = ccwdev_attr_groups; |
1115 | device_initialize(&cdev->dev); | 1137 | device_initialize(&cdev->dev); |
1116 | ccw_device_register(cdev); | 1138 | ccw_device_register(cdev); |
@@ -1132,6 +1154,11 @@ io_subchannel_probe (struct subchannel *sch) | |||
1132 | */ | 1154 | */ |
1133 | dev_id.devno = sch->schib.pmcw.dev; | 1155 | dev_id.devno = sch->schib.pmcw.dev; |
1134 | dev_id.ssid = sch->schid.ssid; | 1156 | dev_id.ssid = sch->schid.ssid; |
1157 | /* Allocate I/O subchannel private data. */ | ||
1158 | sch->private = kzalloc(sizeof(struct io_subchannel_private), | ||
1159 | GFP_KERNEL | GFP_DMA); | ||
1160 | if (!sch->private) | ||
1161 | return -ENOMEM; | ||
1135 | cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL); | 1162 | cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL); |
1136 | if (!cdev) | 1163 | if (!cdev) |
1137 | cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent), | 1164 | cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent), |
@@ -1149,16 +1176,18 @@ io_subchannel_probe (struct subchannel *sch) | |||
1149 | return 0; | 1176 | return 0; |
1150 | } | 1177 | } |
1151 | cdev = io_subchannel_create_ccwdev(sch); | 1178 | cdev = io_subchannel_create_ccwdev(sch); |
1152 | if (IS_ERR(cdev)) | 1179 | if (IS_ERR(cdev)) { |
1180 | kfree(sch->private); | ||
1153 | return PTR_ERR(cdev); | 1181 | return PTR_ERR(cdev); |
1154 | 1182 | } | |
1155 | rc = io_subchannel_recog(cdev, sch); | 1183 | rc = io_subchannel_recog(cdev, sch); |
1156 | if (rc) { | 1184 | if (rc) { |
1157 | spin_lock_irqsave(sch->lock, flags); | 1185 | spin_lock_irqsave(sch->lock, flags); |
1158 | sch->dev.driver_data = NULL; | 1186 | sch_set_cdev(sch, NULL); |
1159 | spin_unlock_irqrestore(sch->lock, flags); | 1187 | spin_unlock_irqrestore(sch->lock, flags); |
1160 | if (cdev->dev.release) | 1188 | if (cdev->dev.release) |
1161 | cdev->dev.release(&cdev->dev); | 1189 | cdev->dev.release(&cdev->dev); |
1190 | kfree(sch->private); | ||
1162 | } | 1191 | } |
1163 | 1192 | ||
1164 | return rc; | 1193 | return rc; |
@@ -1170,25 +1199,25 @@ io_subchannel_remove (struct subchannel *sch) | |||
1170 | struct ccw_device *cdev; | 1199 | struct ccw_device *cdev; |
1171 | unsigned long flags; | 1200 | unsigned long flags; |
1172 | 1201 | ||
1173 | if (!sch->dev.driver_data) | 1202 | cdev = sch_get_cdev(sch); |
1203 | if (!cdev) | ||
1174 | return 0; | 1204 | return 0; |
1175 | cdev = sch->dev.driver_data; | ||
1176 | /* Set ccw device to not operational and drop reference. */ | 1205 | /* Set ccw device to not operational and drop reference. */ |
1177 | spin_lock_irqsave(cdev->ccwlock, flags); | 1206 | spin_lock_irqsave(cdev->ccwlock, flags); |
1178 | sch->dev.driver_data = NULL; | 1207 | sch_set_cdev(sch, NULL); |
1179 | cdev->private->state = DEV_STATE_NOT_OPER; | 1208 | cdev->private->state = DEV_STATE_NOT_OPER; |
1180 | spin_unlock_irqrestore(cdev->ccwlock, flags); | 1209 | spin_unlock_irqrestore(cdev->ccwlock, flags); |
1181 | ccw_device_unregister(cdev); | 1210 | ccw_device_unregister(cdev); |
1182 | put_device(&cdev->dev); | 1211 | put_device(&cdev->dev); |
1212 | kfree(sch->private); | ||
1183 | return 0; | 1213 | return 0; |
1184 | } | 1214 | } |
1185 | 1215 | ||
1186 | static int | 1216 | static int io_subchannel_notify(struct subchannel *sch, int event) |
1187 | io_subchannel_notify(struct device *dev, int event) | ||
1188 | { | 1217 | { |
1189 | struct ccw_device *cdev; | 1218 | struct ccw_device *cdev; |
1190 | 1219 | ||
1191 | cdev = dev->driver_data; | 1220 | cdev = sch_get_cdev(sch); |
1192 | if (!cdev) | 1221 | if (!cdev) |
1193 | return 0; | 1222 | return 0; |
1194 | if (!cdev->drv) | 1223 | if (!cdev->drv) |
@@ -1198,22 +1227,20 @@ io_subchannel_notify(struct device *dev, int event) | |||
1198 | return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0; | 1227 | return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0; |
1199 | } | 1228 | } |
1200 | 1229 | ||
1201 | static void | 1230 | static void io_subchannel_verify(struct subchannel *sch) |
1202 | io_subchannel_verify(struct device *dev) | ||
1203 | { | 1231 | { |
1204 | struct ccw_device *cdev; | 1232 | struct ccw_device *cdev; |
1205 | 1233 | ||
1206 | cdev = dev->driver_data; | 1234 | cdev = sch_get_cdev(sch); |
1207 | if (cdev) | 1235 | if (cdev) |
1208 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); | 1236 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); |
1209 | } | 1237 | } |
1210 | 1238 | ||
1211 | static void | 1239 | static void io_subchannel_ioterm(struct subchannel *sch) |
1212 | io_subchannel_ioterm(struct device *dev) | ||
1213 | { | 1240 | { |
1214 | struct ccw_device *cdev; | 1241 | struct ccw_device *cdev; |
1215 | 1242 | ||
1216 | cdev = dev->driver_data; | 1243 | cdev = sch_get_cdev(sch); |
1217 | if (!cdev) | 1244 | if (!cdev) |
1218 | return; | 1245 | return; |
1219 | /* Internal I/O will be retried by the interrupt handler. */ | 1246 | /* Internal I/O will be retried by the interrupt handler. */ |
@@ -1231,7 +1258,7 @@ io_subchannel_shutdown(struct subchannel *sch) | |||
1231 | struct ccw_device *cdev; | 1258 | struct ccw_device *cdev; |
1232 | int ret; | 1259 | int ret; |
1233 | 1260 | ||
1234 | cdev = sch->dev.driver_data; | 1261 | cdev = sch_get_cdev(sch); |
1235 | 1262 | ||
1236 | if (cio_is_console(sch->schid)) | 1263 | if (cio_is_console(sch->schid)) |
1237 | return; | 1264 | return; |
@@ -1271,6 +1298,9 @@ ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch) | |||
1271 | { | 1298 | { |
1272 | int rc; | 1299 | int rc; |
1273 | 1300 | ||
1301 | /* Attach subchannel private data. */ | ||
1302 | sch->private = cio_get_console_priv(); | ||
1303 | memset(sch->private, 0, sizeof(struct io_subchannel_private)); | ||
1274 | /* Initialize the ccw_device structure. */ | 1304 | /* Initialize the ccw_device structure. */ |
1275 | cdev->dev.parent= &sch->dev; | 1305 | cdev->dev.parent= &sch->dev; |
1276 | rc = io_subchannel_recog(cdev, sch); | 1306 | rc = io_subchannel_recog(cdev, sch); |
@@ -1456,6 +1486,7 @@ int ccw_driver_register(struct ccw_driver *cdriver) | |||
1456 | 1486 | ||
1457 | drv->bus = &ccw_bus_type; | 1487 | drv->bus = &ccw_bus_type; |
1458 | drv->name = cdriver->name; | 1488 | drv->name = cdriver->name; |
1489 | drv->owner = cdriver->owner; | ||
1459 | 1490 | ||
1460 | return driver_register(drv); | 1491 | return driver_register(drv); |
1461 | } | 1492 | } |
@@ -1481,6 +1512,60 @@ ccw_device_get_subchannel_id(struct ccw_device *cdev) | |||
1481 | return sch->schid; | 1512 | return sch->schid; |
1482 | } | 1513 | } |
1483 | 1514 | ||
1515 | static int recovery_check(struct device *dev, void *data) | ||
1516 | { | ||
1517 | struct ccw_device *cdev = to_ccwdev(dev); | ||
1518 | int *redo = data; | ||
1519 | |||
1520 | spin_lock_irq(cdev->ccwlock); | ||
1521 | switch (cdev->private->state) { | ||
1522 | case DEV_STATE_DISCONNECTED: | ||
1523 | CIO_MSG_EVENT(3, "recovery: trigger 0.%x.%04x\n", | ||
1524 | cdev->private->dev_id.ssid, | ||
1525 | cdev->private->dev_id.devno); | ||
1526 | dev_fsm_event(cdev, DEV_EVENT_VERIFY); | ||
1527 | *redo = 1; | ||
1528 | break; | ||
1529 | case DEV_STATE_DISCONNECTED_SENSE_ID: | ||
1530 | *redo = 1; | ||
1531 | break; | ||
1532 | } | ||
1533 | spin_unlock_irq(cdev->ccwlock); | ||
1534 | |||
1535 | return 0; | ||
1536 | } | ||
1537 | |||
1538 | static void recovery_func(unsigned long data) | ||
1539 | { | ||
1540 | int redo = 0; | ||
1541 | |||
1542 | bus_for_each_dev(&ccw_bus_type, NULL, &redo, recovery_check); | ||
1543 | if (redo) { | ||
1544 | spin_lock_irq(&recovery_lock); | ||
1545 | if (!timer_pending(&recovery_timer)) { | ||
1546 | if (recovery_phase < ARRAY_SIZE(recovery_delay) - 1) | ||
1547 | recovery_phase++; | ||
1548 | mod_timer(&recovery_timer, jiffies + | ||
1549 | recovery_delay[recovery_phase] * HZ); | ||
1550 | } | ||
1551 | spin_unlock_irq(&recovery_lock); | ||
1552 | } else | ||
1553 | CIO_MSG_EVENT(2, "recovery: end\n"); | ||
1554 | } | ||
1555 | |||
1556 | void ccw_device_schedule_recovery(void) | ||
1557 | { | ||
1558 | unsigned long flags; | ||
1559 | |||
1560 | CIO_MSG_EVENT(2, "recovery: schedule\n"); | ||
1561 | spin_lock_irqsave(&recovery_lock, flags); | ||
1562 | if (!timer_pending(&recovery_timer) || (recovery_phase != 0)) { | ||
1563 | recovery_phase = 0; | ||
1564 | mod_timer(&recovery_timer, jiffies + recovery_delay[0] * HZ); | ||
1565 | } | ||
1566 | spin_unlock_irqrestore(&recovery_lock, flags); | ||
1567 | } | ||
1568 | |||
1484 | MODULE_LICENSE("GPL"); | 1569 | MODULE_LICENSE("GPL"); |
1485 | EXPORT_SYMBOL(ccw_device_set_online); | 1570 | EXPORT_SYMBOL(ccw_device_set_online); |
1486 | EXPORT_SYMBOL(ccw_device_set_offline); | 1571 | EXPORT_SYMBOL(ccw_device_set_offline); |