]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
dcbd16d5 | 2 | * driver for channel subsystem |
1da177e4 | 3 | * |
34aec07c | 4 | * Copyright IBM Corp. 2002, 2010 |
dcbd16d5 SO |
5 | * |
6 | * Author(s): Arnd Bergmann (arndb@de.ibm.com) | |
7 | * Cornelia Huck (cornelia.huck@de.ibm.com) | |
1da177e4 | 8 | */ |
e6d5a428 ME |
9 | |
10 | #define KMSG_COMPONENT "cio" | |
11 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt | |
12 | ||
1da177e4 LT |
13 | #include <linux/module.h> |
14 | #include <linux/init.h> | |
15 | #include <linux/device.h> | |
16 | #include <linux/slab.h> | |
17 | #include <linux/errno.h> | |
18 | #include <linux/list.h> | |
a55360df | 19 | #include <linux/reboot.h> |
dcbd16d5 | 20 | #include <linux/suspend.h> |
879acca5 | 21 | #include <linux/proc_fs.h> |
3a3fc29a | 22 | #include <asm/isc.h> |
f5daba1d | 23 | #include <asm/crw.h> |
1da177e4 LT |
24 | |
25 | #include "css.h" | |
26 | #include "cio.h" | |
27 | #include "cio_debug.h" | |
28 | #include "ioasm.h" | |
29 | #include "chsc.h" | |
40154b82 | 30 | #include "device.h" |
83b3370c | 31 | #include "idset.h" |
7ad6a249 | 32 | #include "chp.h" |
1da177e4 | 33 | |
1da177e4 | 34 | int css_init_done = 0; |
b0a285d3 | 35 | int max_ssid; |
1da177e4 | 36 | |
7c9f4e3a | 37 | struct channel_subsystem *channel_subsystems[__MAX_CSSID + 1]; |
3041b6ab | 38 | static struct bus_type css_bus_type; |
1da177e4 | 39 | |
4d284cac | 40 | int |
f97a56fb CH |
41 | for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data) |
42 | { | |
43 | struct subchannel_id schid; | |
44 | int ret; | |
45 | ||
46 | init_subchannel_id(&schid); | |
47 | ret = -ENODEV; | |
48 | do { | |
fb6958a5 CH |
49 | do { |
50 | ret = fn(schid, data); | |
51 | if (ret) | |
52 | break; | |
53 | } while (schid.sch_no++ < __MAX_SUBCHANNEL); | |
54 | schid.sch_no = 0; | |
55 | } while (schid.ssid++ < max_ssid); | |
f97a56fb CH |
56 | return ret; |
57 | } | |
58 | ||
e82a1567 PO |
59 | struct cb_data { |
60 | void *data; | |
61 | struct idset *set; | |
62 | int (*fn_known_sch)(struct subchannel *, void *); | |
63 | int (*fn_unknown_sch)(struct subchannel_id, void *); | |
64 | }; | |
65 | ||
66 | static int call_fn_known_sch(struct device *dev, void *data) | |
67 | { | |
68 | struct subchannel *sch = to_subchannel(dev); | |
69 | struct cb_data *cb = data; | |
70 | int rc = 0; | |
71 | ||
72 | idset_sch_del(cb->set, sch->schid); | |
73 | if (cb->fn_known_sch) | |
74 | rc = cb->fn_known_sch(sch, cb->data); | |
75 | return rc; | |
76 | } | |
77 | ||
78 | static int call_fn_unknown_sch(struct subchannel_id schid, void *data) | |
79 | { | |
80 | struct cb_data *cb = data; | |
81 | int rc = 0; | |
82 | ||
83 | if (idset_sch_contains(cb->set, schid)) | |
84 | rc = cb->fn_unknown_sch(schid, cb->data); | |
85 | return rc; | |
86 | } | |
87 | ||
90ac24a5 SO |
88 | static int call_fn_all_sch(struct subchannel_id schid, void *data) |
89 | { | |
90 | struct cb_data *cb = data; | |
91 | struct subchannel *sch; | |
92 | int rc = 0; | |
93 | ||
94 | sch = get_subchannel_by_schid(schid); | |
95 | if (sch) { | |
96 | if (cb->fn_known_sch) | |
97 | rc = cb->fn_known_sch(sch, cb->data); | |
98 | put_device(&sch->dev); | |
99 | } else { | |
100 | if (cb->fn_unknown_sch) | |
101 | rc = cb->fn_unknown_sch(schid, cb->data); | |
102 | } | |
103 | ||
104 | return rc; | |
105 | } | |
106 | ||
e82a1567 PO |
107 | int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *), |
108 | int (*fn_unknown)(struct subchannel_id, | |
109 | void *), void *data) | |
110 | { | |
111 | struct cb_data cb; | |
112 | int rc; | |
113 | ||
e82a1567 PO |
114 | cb.data = data; |
115 | cb.fn_known_sch = fn_known; | |
116 | cb.fn_unknown_sch = fn_unknown; | |
90ac24a5 SO |
117 | |
118 | cb.set = idset_sch_new(); | |
119 | if (!cb.set) | |
120 | /* fall back to brute force scanning in case of oom */ | |
121 | return for_each_subchannel(call_fn_all_sch, &cb); | |
122 | ||
123 | idset_fill(cb.set); | |
124 | ||
e82a1567 PO |
125 | /* Process registered subchannels. */ |
126 | rc = bus_for_each_dev(&css_bus_type, NULL, &cb, call_fn_known_sch); | |
127 | if (rc) | |
128 | goto out; | |
129 | /* Process unregistered subchannels. */ | |
130 | if (fn_unknown) | |
131 | rc = for_each_subchannel(call_fn_unknown_sch, &cb); | |
132 | out: | |
133 | idset_free(cb.set); | |
134 | ||
135 | return rc; | |
136 | } | |
137 | ||
390935ac PO |
138 | static void css_sch_todo(struct work_struct *work); |
139 | ||
e5dcf002 SO |
140 | static int css_sch_create_locks(struct subchannel *sch) |
141 | { | |
142 | sch->lock = kmalloc(sizeof(*sch->lock), GFP_KERNEL); | |
143 | if (!sch->lock) | |
144 | return -ENOMEM; | |
145 | ||
146 | spin_lock_init(sch->lock); | |
147 | mutex_init(&sch->reg_mutex); | |
148 | ||
149 | return 0; | |
150 | } | |
151 | ||
c135ad1c SO |
152 | static void css_subchannel_release(struct device *dev) |
153 | { | |
863fc849 | 154 | struct subchannel *sch = to_subchannel(dev); |
c135ad1c | 155 | |
863fc849 SO |
156 | sch->config.intparm = 0; |
157 | cio_commit_config(sch); | |
158 | kfree(sch->lock); | |
159 | kfree(sch); | |
c135ad1c SO |
160 | } |
161 | ||
863fc849 | 162 | struct subchannel *css_alloc_subchannel(struct subchannel_id schid) |
1da177e4 LT |
163 | { |
164 | struct subchannel *sch; | |
165 | int ret; | |
166 | ||
e5dcf002 SO |
167 | sch = kzalloc(sizeof(*sch), GFP_KERNEL | GFP_DMA); |
168 | if (!sch) | |
1da177e4 | 169 | return ERR_PTR(-ENOMEM); |
e5dcf002 SO |
170 | |
171 | ret = cio_validate_subchannel(sch, schid); | |
172 | if (ret < 0) | |
173 | goto err; | |
174 | ||
175 | ret = css_sch_create_locks(sch); | |
176 | if (ret) | |
177 | goto err; | |
178 | ||
390935ac | 179 | INIT_WORK(&sch->todo_work, css_sch_todo); |
c135ad1c SO |
180 | sch->dev.release = &css_subchannel_release; |
181 | device_initialize(&sch->dev); | |
1da177e4 | 182 | return sch; |
e5dcf002 SO |
183 | |
184 | err: | |
185 | kfree(sch); | |
186 | return ERR_PTR(ret); | |
1da177e4 LT |
187 | } |
188 | ||
07c6a338 | 189 | static int css_sch_device_register(struct subchannel *sch) |
6ab4879a CH |
190 | { |
191 | int ret; | |
192 | ||
193 | mutex_lock(&sch->reg_mutex); | |
6ee4fec6 SO |
194 | dev_set_name(&sch->dev, "0.%x.%04x", sch->schid.ssid, |
195 | sch->schid.sch_no); | |
c135ad1c | 196 | ret = device_add(&sch->dev); |
6ab4879a CH |
197 | mutex_unlock(&sch->reg_mutex); |
198 | return ret; | |
199 | } | |
200 | ||
44a1c19e CH |
201 | /** |
202 | * css_sch_device_unregister - unregister a subchannel | |
203 | * @sch: subchannel to be unregistered | |
204 | */ | |
6ab4879a CH |
205 | void css_sch_device_unregister(struct subchannel *sch) |
206 | { | |
207 | mutex_lock(&sch->reg_mutex); | |
ef60cd13 SO |
208 | if (device_is_registered(&sch->dev)) |
209 | device_unregister(&sch->dev); | |
6ab4879a CH |
210 | mutex_unlock(&sch->reg_mutex); |
211 | } | |
44a1c19e | 212 | EXPORT_SYMBOL_GPL(css_sch_device_unregister); |
6ab4879a | 213 | |
7ad6a249 PO |
214 | static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw) |
215 | { | |
216 | int i; | |
217 | int mask; | |
218 | ||
219 | memset(ssd, 0, sizeof(struct chsc_ssd_info)); | |
220 | ssd->path_mask = pmcw->pim; | |
221 | for (i = 0; i < 8; i++) { | |
222 | mask = 0x80 >> i; | |
223 | if (pmcw->pim & mask) { | |
224 | chp_id_init(&ssd->chpid[i]); | |
225 | ssd->chpid[i].id = pmcw->chpid[i]; | |
226 | } | |
227 | } | |
228 | } | |
229 | ||
230 | static void ssd_register_chpids(struct chsc_ssd_info *ssd) | |
231 | { | |
232 | int i; | |
233 | int mask; | |
234 | ||
235 | for (i = 0; i < 8; i++) { | |
236 | mask = 0x80 >> i; | |
237 | if (ssd->path_mask & mask) | |
238 | if (!chp_is_registered(ssd->chpid[i])) | |
239 | chp_new(ssd->chpid[i]); | |
240 | } | |
241 | } | |
242 | ||
243 | void css_update_ssd_info(struct subchannel *sch) | |
244 | { | |
245 | int ret; | |
246 | ||
14556b33 SO |
247 | ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info); |
248 | if (ret) | |
7ad6a249 | 249 | ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw); |
14556b33 SO |
250 | |
251 | ssd_register_chpids(&sch->ssd_info); | |
7ad6a249 PO |
252 | } |
253 | ||
7e9db9ea CH |
254 | static ssize_t type_show(struct device *dev, struct device_attribute *attr, |
255 | char *buf) | |
256 | { | |
257 | struct subchannel *sch = to_subchannel(dev); | |
258 | ||
259 | return sprintf(buf, "%01x\n", sch->st); | |
260 | } | |
261 | ||
262 | static DEVICE_ATTR(type, 0444, type_show, NULL); | |
263 | ||
264 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, | |
265 | char *buf) | |
266 | { | |
267 | struct subchannel *sch = to_subchannel(dev); | |
268 | ||
269 | return sprintf(buf, "css:t%01X\n", sch->st); | |
270 | } | |
271 | ||
272 | static DEVICE_ATTR(modalias, 0444, modalias_show, NULL); | |
273 | ||
274 | static struct attribute *subch_attrs[] = { | |
275 | &dev_attr_type.attr, | |
276 | &dev_attr_modalias.attr, | |
277 | NULL, | |
278 | }; | |
279 | ||
280 | static struct attribute_group subch_attr_group = { | |
281 | .attrs = subch_attrs, | |
282 | }; | |
283 | ||
a4dbd674 | 284 | static const struct attribute_group *default_subch_attr_groups[] = { |
7e9db9ea CH |
285 | &subch_attr_group, |
286 | NULL, | |
287 | }; | |
288 | ||
14556b33 | 289 | int css_register_subchannel(struct subchannel *sch) |
1da177e4 LT |
290 | { |
291 | int ret; | |
292 | ||
293 | /* Initialize the subchannel structure */ | |
7c9f4e3a | 294 | sch->dev.parent = &channel_subsystems[0]->device; |
1da177e4 | 295 | sch->dev.bus = &css_bus_type; |
7e9db9ea | 296 | sch->dev.groups = default_subch_attr_groups; |
5bf04b20 CH |
297 | /* |
298 | * We don't want to generate uevents for I/O subchannels that don't | |
299 | * have a working ccw device behind them since they will be | |
300 | * unregistered before they can be used anyway, so we delay the add | |
301 | * uevent until after device recognition was successful. | |
7e9db9ea CH |
302 | * Note that we suppress the uevent for all subchannel types; |
303 | * the subchannel driver can decide itself when it wants to inform | |
304 | * userspace of its existence. | |
5bf04b20 | 305 | */ |
f67f129e | 306 | dev_set_uevent_suppress(&sch->dev, 1); |
7ad6a249 | 307 | css_update_ssd_info(sch); |
1da177e4 | 308 | /* make it known to the system */ |
6ab4879a | 309 | ret = css_sch_device_register(sch); |
7674da77 | 310 | if (ret) { |
e556bbbd CH |
311 | CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n", |
312 | sch->schid.ssid, sch->schid.sch_no, ret); | |
7674da77 CH |
313 | return ret; |
314 | } | |
7e9db9ea CH |
315 | if (!sch->driver) { |
316 | /* | |
317 | * No driver matched. Generate the uevent now so that | |
318 | * a fitting driver module may be loaded based on the | |
319 | * modalias. | |
320 | */ | |
f67f129e | 321 | dev_set_uevent_suppress(&sch->dev, 0); |
7e9db9ea CH |
322 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); |
323 | } | |
1da177e4 LT |
324 | return ret; |
325 | } | |
326 | ||
4e5ebd51 | 327 | static int css_probe_device(struct subchannel_id schid) |
1da177e4 | 328 | { |
1da177e4 | 329 | struct subchannel *sch; |
4e5ebd51 | 330 | int ret; |
1da177e4 | 331 | |
14556b33 SO |
332 | sch = css_alloc_subchannel(schid); |
333 | if (IS_ERR(sch)) | |
334 | return PTR_ERR(sch); | |
335 | ||
1da177e4 | 336 | ret = css_register_subchannel(sch); |
863fc849 SO |
337 | if (ret) |
338 | put_device(&sch->dev); | |
339 | ||
1da177e4 LT |
340 | return ret; |
341 | } | |
342 | ||
b0744bd2 CH |
343 | static int |
344 | check_subchannel(struct device * dev, void * data) | |
345 | { | |
346 | struct subchannel *sch; | |
a8237fc4 | 347 | struct subchannel_id *schid = data; |
b0744bd2 CH |
348 | |
349 | sch = to_subchannel(dev); | |
a8237fc4 | 350 | return schid_equal(&sch->schid, schid); |
b0744bd2 CH |
351 | } |
352 | ||
1da177e4 | 353 | struct subchannel * |
a8237fc4 | 354 | get_subchannel_by_schid(struct subchannel_id schid) |
1da177e4 | 355 | { |
1da177e4 LT |
356 | struct device *dev; |
357 | ||
b0744bd2 | 358 | dev = bus_find_device(&css_bus_type, NULL, |
12975aef | 359 | &schid, check_subchannel); |
1da177e4 | 360 | |
b0744bd2 | 361 | return dev ? to_subchannel(dev) : NULL; |
1da177e4 LT |
362 | } |
363 | ||
b279a4f5 CH |
364 | /** |
365 | * css_sch_is_valid() - check if a subchannel is valid | |
366 | * @schib: subchannel information block for the subchannel | |
367 | */ | |
368 | int css_sch_is_valid(struct schib *schib) | |
369 | { | |
370 | if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv) | |
371 | return 0; | |
b3a686f4 CH |
372 | if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w) |
373 | return 0; | |
b279a4f5 CH |
374 | return 1; |
375 | } | |
376 | EXPORT_SYMBOL_GPL(css_sch_is_valid); | |
377 | ||
564337f3 PO |
378 | static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow) |
379 | { | |
380 | struct schib schib; | |
381 | ||
382 | if (!slow) { | |
383 | /* Will be done on the slow path. */ | |
384 | return -EAGAIN; | |
385 | } | |
cec85466 SO |
386 | if (stsch_err(schid, &schib)) { |
387 | /* Subchannel is not provided. */ | |
388 | return -ENXIO; | |
389 | } | |
390 | if (!css_sch_is_valid(&schib)) { | |
564337f3 PO |
391 | /* Unusable - ignore. */ |
392 | return 0; | |
1da177e4 | 393 | } |
5d6e6b6f PO |
394 | CIO_MSG_EVENT(4, "event: sch 0.%x.%04x, new\n", schid.ssid, |
395 | schid.sch_no); | |
564337f3 PO |
396 | |
397 | return css_probe_device(schid); | |
398 | } | |
399 | ||
c820de39 CH |
400 | static int css_evaluate_known_subchannel(struct subchannel *sch, int slow) |
401 | { | |
402 | int ret = 0; | |
403 | ||
404 | if (sch->driver) { | |
405 | if (sch->driver->sch_event) | |
406 | ret = sch->driver->sch_event(sch, slow); | |
407 | else | |
408 | dev_dbg(&sch->dev, | |
409 | "Got subchannel machine check but " | |
410 | "no sch_event handler provided.\n"); | |
411 | } | |
5d6e6b6f PO |
412 | if (ret != 0 && ret != -EAGAIN) { |
413 | CIO_MSG_EVENT(2, "eval: sch 0.%x.%04x, rc=%d\n", | |
414 | sch->schid.ssid, sch->schid.sch_no, ret); | |
415 | } | |
c820de39 CH |
416 | return ret; |
417 | } | |
418 | ||
83b3370c | 419 | static void css_evaluate_subchannel(struct subchannel_id schid, int slow) |
564337f3 PO |
420 | { |
421 | struct subchannel *sch; | |
422 | int ret; | |
423 | ||
424 | sch = get_subchannel_by_schid(schid); | |
425 | if (sch) { | |
426 | ret = css_evaluate_known_subchannel(sch, slow); | |
427 | put_device(&sch->dev); | |
428 | } else | |
429 | ret = css_evaluate_new_subchannel(schid, slow); | |
83b3370c PO |
430 | if (ret == -EAGAIN) |
431 | css_schedule_eval(schid); | |
1da177e4 LT |
432 | } |
433 | ||
817e5000 SO |
434 | /** |
435 | * css_sched_sch_todo - schedule a subchannel operation | |
436 | * @sch: subchannel | |
437 | * @todo: todo | |
438 | * | |
439 | * Schedule the operation identified by @todo to be performed on the slow path | |
440 | * workqueue. Do nothing if another operation with higher priority is already | |
441 | * scheduled. Needs to be called with subchannel lock held. | |
442 | */ | |
443 | void css_sched_sch_todo(struct subchannel *sch, enum sch_todo todo) | |
444 | { | |
445 | CIO_MSG_EVENT(4, "sch_todo: sched sch=0.%x.%04x todo=%d\n", | |
446 | sch->schid.ssid, sch->schid.sch_no, todo); | |
447 | if (sch->todo >= todo) | |
448 | return; | |
449 | /* Get workqueue ref. */ | |
450 | if (!get_device(&sch->dev)) | |
451 | return; | |
452 | sch->todo = todo; | |
453 | if (!queue_work(cio_work_q, &sch->todo_work)) { | |
454 | /* Already queued, release workqueue ref. */ | |
455 | put_device(&sch->dev); | |
456 | } | |
457 | } | |
01c5e6dc | 458 | EXPORT_SYMBOL_GPL(css_sched_sch_todo); |
817e5000 SO |
459 | |
460 | static void css_sch_todo(struct work_struct *work) | |
461 | { | |
462 | struct subchannel *sch; | |
463 | enum sch_todo todo; | |
464 | int ret; | |
465 | ||
466 | sch = container_of(work, struct subchannel, todo_work); | |
467 | /* Find out todo. */ | |
468 | spin_lock_irq(sch->lock); | |
469 | todo = sch->todo; | |
470 | CIO_MSG_EVENT(4, "sch_todo: sch=0.%x.%04x, todo=%d\n", sch->schid.ssid, | |
471 | sch->schid.sch_no, todo); | |
472 | sch->todo = SCH_TODO_NOTHING; | |
473 | spin_unlock_irq(sch->lock); | |
474 | /* Perform todo. */ | |
475 | switch (todo) { | |
476 | case SCH_TODO_NOTHING: | |
477 | break; | |
478 | case SCH_TODO_EVAL: | |
479 | ret = css_evaluate_known_subchannel(sch, 1); | |
480 | if (ret == -EAGAIN) { | |
481 | spin_lock_irq(sch->lock); | |
482 | css_sched_sch_todo(sch, todo); | |
483 | spin_unlock_irq(sch->lock); | |
484 | } | |
485 | break; | |
486 | case SCH_TODO_UNREG: | |
487 | css_sch_device_unregister(sch); | |
488 | break; | |
489 | } | |
490 | /* Release workqueue ref. */ | |
491 | put_device(&sch->dev); | |
492 | } | |
493 | ||
83b3370c PO |
494 | static struct idset *slow_subchannel_set; |
495 | static spinlock_t slow_subchannel_lock; | |
25530553 SO |
496 | static wait_queue_head_t css_eval_wq; |
497 | static atomic_t css_eval_scheduled; | |
83b3370c PO |
498 | |
499 | static int __init slow_subchannel_init(void) | |
1da177e4 | 500 | { |
83b3370c | 501 | spin_lock_init(&slow_subchannel_lock); |
25530553 SO |
502 | atomic_set(&css_eval_scheduled, 0); |
503 | init_waitqueue_head(&css_eval_wq); | |
83b3370c PO |
504 | slow_subchannel_set = idset_sch_new(); |
505 | if (!slow_subchannel_set) { | |
e556bbbd | 506 | CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n"); |
83b3370c PO |
507 | return -ENOMEM; |
508 | } | |
509 | return 0; | |
1da177e4 LT |
510 | } |
511 | ||
e82a1567 | 512 | static int slow_eval_known_fn(struct subchannel *sch, void *data) |
1da177e4 | 513 | { |
e82a1567 PO |
514 | int eval; |
515 | int rc; | |
1da177e4 LT |
516 | |
517 | spin_lock_irq(&slow_subchannel_lock); | |
e82a1567 PO |
518 | eval = idset_sch_contains(slow_subchannel_set, sch->schid); |
519 | idset_sch_del(slow_subchannel_set, sch->schid); | |
520 | spin_unlock_irq(&slow_subchannel_lock); | |
521 | if (eval) { | |
522 | rc = css_evaluate_known_subchannel(sch, 1); | |
523 | if (rc == -EAGAIN) | |
524 | css_schedule_eval(sch->schid); | |
1da177e4 | 525 | } |
e82a1567 PO |
526 | return 0; |
527 | } | |
528 | ||
529 | static int slow_eval_unknown_fn(struct subchannel_id schid, void *data) | |
530 | { | |
531 | int eval; | |
532 | int rc = 0; | |
533 | ||
534 | spin_lock_irq(&slow_subchannel_lock); | |
535 | eval = idset_sch_contains(slow_subchannel_set, schid); | |
536 | idset_sch_del(slow_subchannel_set, schid); | |
1da177e4 | 537 | spin_unlock_irq(&slow_subchannel_lock); |
e82a1567 PO |
538 | if (eval) { |
539 | rc = css_evaluate_new_subchannel(schid, 1); | |
540 | switch (rc) { | |
541 | case -EAGAIN: | |
542 | css_schedule_eval(schid); | |
543 | rc = 0; | |
544 | break; | |
545 | case -ENXIO: | |
546 | case -ENOMEM: | |
547 | case -EIO: | |
548 | /* These should abort looping */ | |
cec85466 | 549 | idset_sch_del_subseq(slow_subchannel_set, schid); |
e82a1567 PO |
550 | break; |
551 | default: | |
552 | rc = 0; | |
553 | } | |
554 | } | |
555 | return rc; | |
556 | } | |
557 | ||
558 | static void css_slow_path_func(struct work_struct *unused) | |
559 | { | |
25530553 SO |
560 | unsigned long flags; |
561 | ||
e82a1567 PO |
562 | CIO_TRACE_EVENT(4, "slowpath"); |
563 | for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn, | |
564 | NULL); | |
25530553 SO |
565 | spin_lock_irqsave(&slow_subchannel_lock, flags); |
566 | if (idset_is_empty(slow_subchannel_set)) { | |
567 | atomic_set(&css_eval_scheduled, 0); | |
568 | wake_up(&css_eval_wq); | |
569 | } | |
570 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); | |
1da177e4 LT |
571 | } |
572 | ||
83b3370c | 573 | static DECLARE_WORK(slow_path_work, css_slow_path_func); |
be5d3823 | 574 | struct workqueue_struct *cio_work_q; |
1da177e4 | 575 | |
83b3370c PO |
576 | void css_schedule_eval(struct subchannel_id schid) |
577 | { | |
578 | unsigned long flags; | |
579 | ||
580 | spin_lock_irqsave(&slow_subchannel_lock, flags); | |
581 | idset_sch_add(slow_subchannel_set, schid); | |
25530553 | 582 | atomic_set(&css_eval_scheduled, 1); |
be5d3823 | 583 | queue_work(cio_work_q, &slow_path_work); |
83b3370c PO |
584 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
585 | } | |
586 | ||
587 | void css_schedule_eval_all(void) | |
588 | { | |
589 | unsigned long flags; | |
590 | ||
591 | spin_lock_irqsave(&slow_subchannel_lock, flags); | |
592 | idset_fill(slow_subchannel_set); | |
25530553 | 593 | atomic_set(&css_eval_scheduled, 1); |
be5d3823 | 594 | queue_work(cio_work_q, &slow_path_work); |
83b3370c PO |
595 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
596 | } | |
597 | ||
703e5c99 | 598 | static int __unset_registered(struct device *dev, void *data) |
22806dc1 | 599 | { |
703e5c99 SO |
600 | struct idset *set = data; |
601 | struct subchannel *sch = to_subchannel(dev); | |
40154b82 | 602 | |
703e5c99 SO |
603 | idset_sch_del(set, sch->schid); |
604 | return 0; | |
56e25e97 PO |
605 | } |
606 | ||
a8481c2a | 607 | static void css_schedule_eval_all_unreg(void) |
40154b82 | 608 | { |
703e5c99 SO |
609 | unsigned long flags; |
610 | struct idset *unreg_set; | |
40154b82 | 611 | |
703e5c99 SO |
612 | /* Find unregistered subchannels. */ |
613 | unreg_set = idset_sch_new(); | |
614 | if (!unreg_set) { | |
615 | /* Fallback. */ | |
616 | css_schedule_eval_all(); | |
56e25e97 PO |
617 | return; |
618 | } | |
703e5c99 SO |
619 | idset_fill(unreg_set); |
620 | bus_for_each_dev(&css_bus_type, NULL, unreg_set, __unset_registered); | |
621 | /* Apply to slow_subchannel_set. */ | |
622 | spin_lock_irqsave(&slow_subchannel_lock, flags); | |
623 | idset_add_set(slow_subchannel_set, unreg_set); | |
624 | atomic_set(&css_eval_scheduled, 1); | |
be5d3823 | 625 | queue_work(cio_work_q, &slow_path_work); |
703e5c99 SO |
626 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); |
627 | idset_free(unreg_set); | |
40154b82 PO |
628 | } |
629 | ||
703e5c99 SO |
630 | void css_wait_for_slow_path(void) |
631 | { | |
be5d3823 | 632 | flush_workqueue(cio_work_q); |
703e5c99 | 633 | } |
40154b82 PO |
634 | |
635 | /* Schedule reprobing of all unregistered subchannels. */ | |
636 | void css_schedule_reprobe(void) | |
637 | { | |
703e5c99 | 638 | css_schedule_eval_all_unreg(); |
40154b82 | 639 | } |
40154b82 PO |
640 | EXPORT_SYMBOL_GPL(css_schedule_reprobe); |
641 | ||
1da177e4 LT |
642 | /* |
643 | * Called from the machine check handler for subchannel report words. | |
644 | */ | |
c1156189 | 645 | static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow) |
1da177e4 | 646 | { |
a8237fc4 | 647 | struct subchannel_id mchk_schid; |
4bc4e965 | 648 | struct subchannel *sch; |
1da177e4 | 649 | |
c1156189 CH |
650 | if (overflow) { |
651 | css_schedule_eval_all(); | |
652 | return; | |
653 | } | |
654 | CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, " | |
655 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", | |
656 | crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc, | |
657 | crw0->erc, crw0->rsid); | |
658 | if (crw1) | |
659 | CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, " | |
660 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", | |
661 | crw1->slct, crw1->oflw, crw1->chn, crw1->rsc, | |
662 | crw1->anc, crw1->erc, crw1->rsid); | |
a8237fc4 | 663 | init_subchannel_id(&mchk_schid); |
c1156189 CH |
664 | mchk_schid.sch_no = crw0->rsid; |
665 | if (crw1) | |
8d7bfb4a | 666 | mchk_schid.ssid = (crw1->rsid >> 4) & 3; |
fb6958a5 | 667 | |
4bc4e965 SO |
668 | if (crw0->erc == CRW_ERC_PMOD) { |
669 | sch = get_subchannel_by_schid(mchk_schid); | |
670 | if (sch) { | |
671 | css_update_ssd_info(sch); | |
672 | put_device(&sch->dev); | |
673 | } | |
674 | } | |
c1156189 | 675 | /* |
1da177e4 LT |
676 | * Since we are always presented with IPI in the CRW, we have to |
677 | * use stsch() to find out if the subchannel in question has come | |
678 | * or gone. | |
679 | */ | |
83b3370c | 680 | css_evaluate_subchannel(mchk_schid, 0); |
1da177e4 LT |
681 | } |
682 | ||
683 | static void __init | |
a28c6944 | 684 | css_generate_pgid(struct channel_subsystem *css, u32 tod_high) |
1da177e4 | 685 | { |
94038a99 MS |
686 | struct cpuid cpu_id; |
687 | ||
75784c00 | 688 | if (css_general_characteristics.mcss) { |
a28c6944 CH |
689 | css->global_pgid.pgid_high.ext_cssid.version = 0x80; |
690 | css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid; | |
691 | } else { | |
1da177e4 | 692 | #ifdef CONFIG_SMP |
7b468488 | 693 | css->global_pgid.pgid_high.cpu_addr = stap(); |
1da177e4 | 694 | #else |
a28c6944 | 695 | css->global_pgid.pgid_high.cpu_addr = 0; |
1da177e4 LT |
696 | #endif |
697 | } | |
94038a99 MS |
698 | get_cpu_id(&cpu_id); |
699 | css->global_pgid.cpu_id = cpu_id.ident; | |
700 | css->global_pgid.cpu_model = cpu_id.machine; | |
a28c6944 CH |
701 | css->global_pgid.tod_high = tod_high; |
702 | ||
703 | } | |
704 | ||
3b793060 CH |
705 | static void |
706 | channel_subsystem_release(struct device *dev) | |
707 | { | |
708 | struct channel_subsystem *css; | |
709 | ||
710 | css = to_css(dev); | |
495a5b45 | 711 | mutex_destroy(&css->mutex); |
a2164b81 CH |
712 | if (css->pseudo_subchannel) { |
713 | /* Implies that it has been generated but never registered. */ | |
714 | css_subchannel_release(&css->pseudo_subchannel->dev); | |
715 | css->pseudo_subchannel = NULL; | |
716 | } | |
3b793060 CH |
717 | kfree(css); |
718 | } | |
719 | ||
495a5b45 CH |
720 | static ssize_t |
721 | css_cm_enable_show(struct device *dev, struct device_attribute *attr, | |
722 | char *buf) | |
723 | { | |
724 | struct channel_subsystem *css = to_css(dev); | |
8284fb19 | 725 | int ret; |
495a5b45 CH |
726 | |
727 | if (!css) | |
728 | return 0; | |
8284fb19 ME |
729 | mutex_lock(&css->mutex); |
730 | ret = sprintf(buf, "%x\n", css->cm_enabled); | |
731 | mutex_unlock(&css->mutex); | |
732 | return ret; | |
495a5b45 CH |
733 | } |
734 | ||
735 | static ssize_t | |
736 | css_cm_enable_store(struct device *dev, struct device_attribute *attr, | |
737 | const char *buf, size_t count) | |
738 | { | |
739 | struct channel_subsystem *css = to_css(dev); | |
740 | int ret; | |
2f972202 | 741 | unsigned long val; |
495a5b45 | 742 | |
0178722b | 743 | ret = kstrtoul(buf, 16, &val); |
2f972202 CH |
744 | if (ret) |
745 | return ret; | |
8284fb19 | 746 | mutex_lock(&css->mutex); |
2f972202 CH |
747 | switch (val) { |
748 | case 0: | |
495a5b45 CH |
749 | ret = css->cm_enabled ? chsc_secm(css, 0) : 0; |
750 | break; | |
2f972202 | 751 | case 1: |
495a5b45 CH |
752 | ret = css->cm_enabled ? 0 : chsc_secm(css, 1); |
753 | break; | |
754 | default: | |
755 | ret = -EINVAL; | |
756 | } | |
8284fb19 | 757 | mutex_unlock(&css->mutex); |
495a5b45 CH |
758 | return ret < 0 ? ret : count; |
759 | } | |
760 | ||
761 | static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store); | |
762 | ||
4d284cac | 763 | static int __init setup_css(int nr) |
a28c6944 CH |
764 | { |
765 | u32 tod_high; | |
d7b5a4c9 | 766 | int ret; |
7c9f4e3a | 767 | struct channel_subsystem *css; |
a28c6944 | 768 | |
7c9f4e3a CH |
769 | css = channel_subsystems[nr]; |
770 | memset(css, 0, sizeof(struct channel_subsystem)); | |
771 | css->pseudo_subchannel = | |
772 | kzalloc(sizeof(*css->pseudo_subchannel), GFP_KERNEL); | |
773 | if (!css->pseudo_subchannel) | |
d7b5a4c9 | 774 | return -ENOMEM; |
7c9f4e3a CH |
775 | css->pseudo_subchannel->dev.parent = &css->device; |
776 | css->pseudo_subchannel->dev.release = css_subchannel_release; | |
1bf5b285 | 777 | dev_set_name(&css->pseudo_subchannel->dev, "defunct"); |
5d6e6b6f | 778 | mutex_init(&css->pseudo_subchannel->reg_mutex); |
e5dcf002 | 779 | ret = css_sch_create_locks(css->pseudo_subchannel); |
d7b5a4c9 | 780 | if (ret) { |
7c9f4e3a | 781 | kfree(css->pseudo_subchannel); |
d7b5a4c9 CH |
782 | return ret; |
783 | } | |
7c9f4e3a CH |
784 | mutex_init(&css->mutex); |
785 | css->valid = 1; | |
786 | css->cssid = nr; | |
1bf5b285 | 787 | dev_set_name(&css->device, "css%x", nr); |
7c9f4e3a | 788 | css->device.release = channel_subsystem_release; |
1aae0560 | 789 | tod_high = (u32) (get_tod_clock() >> 32); |
7c9f4e3a | 790 | css_generate_pgid(css, tod_high); |
d7b5a4c9 | 791 | return 0; |
1da177e4 LT |
792 | } |
793 | ||
a55360df CH |
794 | static int css_reboot_event(struct notifier_block *this, |
795 | unsigned long event, | |
796 | void *ptr) | |
797 | { | |
798 | int ret, i; | |
799 | ||
800 | ret = NOTIFY_DONE; | |
801 | for (i = 0; i <= __MAX_CSSID; i++) { | |
802 | struct channel_subsystem *css; | |
803 | ||
804 | css = channel_subsystems[i]; | |
8284fb19 | 805 | mutex_lock(&css->mutex); |
a55360df CH |
806 | if (css->cm_enabled) |
807 | if (chsc_secm(css, 0)) | |
808 | ret = NOTIFY_BAD; | |
8284fb19 | 809 | mutex_unlock(&css->mutex); |
a55360df CH |
810 | } |
811 | ||
812 | return ret; | |
813 | } | |
814 | ||
815 | static struct notifier_block css_reboot_notifier = { | |
816 | .notifier_call = css_reboot_event, | |
817 | }; | |
818 | ||
dcbd16d5 SO |
819 | /* |
820 | * Since the css devices are neither on a bus nor have a class | |
821 | * nor have a special device type, we cannot stop/restart channel | |
822 | * path measurements via the normal suspend/resume callbacks, but have | |
823 | * to use notifiers. | |
824 | */ | |
825 | static int css_power_event(struct notifier_block *this, unsigned long event, | |
826 | void *ptr) | |
827 | { | |
dcbd16d5 SO |
828 | int ret, i; |
829 | ||
830 | switch (event) { | |
831 | case PM_HIBERNATION_PREPARE: | |
832 | case PM_SUSPEND_PREPARE: | |
833 | ret = NOTIFY_DONE; | |
834 | for (i = 0; i <= __MAX_CSSID; i++) { | |
835 | struct channel_subsystem *css; | |
836 | ||
837 | css = channel_subsystems[i]; | |
838 | mutex_lock(&css->mutex); | |
839 | if (!css->cm_enabled) { | |
840 | mutex_unlock(&css->mutex); | |
841 | continue; | |
842 | } | |
f0c077a8 AM |
843 | ret = __chsc_do_secm(css, 0); |
844 | ret = notifier_from_errno(ret); | |
dcbd16d5 SO |
845 | mutex_unlock(&css->mutex); |
846 | } | |
847 | break; | |
848 | case PM_POST_HIBERNATION: | |
849 | case PM_POST_SUSPEND: | |
850 | ret = NOTIFY_DONE; | |
851 | for (i = 0; i <= __MAX_CSSID; i++) { | |
852 | struct channel_subsystem *css; | |
853 | ||
854 | css = channel_subsystems[i]; | |
855 | mutex_lock(&css->mutex); | |
856 | if (!css->cm_enabled) { | |
857 | mutex_unlock(&css->mutex); | |
858 | continue; | |
859 | } | |
f0c077a8 AM |
860 | ret = __chsc_do_secm(css, 1); |
861 | ret = notifier_from_errno(ret); | |
dcbd16d5 SO |
862 | mutex_unlock(&css->mutex); |
863 | } | |
864 | /* search for subchannels, which appeared during hibernation */ | |
865 | css_schedule_reprobe(); | |
866 | break; | |
867 | default: | |
868 | ret = NOTIFY_DONE; | |
869 | } | |
870 | return ret; | |
871 | ||
872 | } | |
873 | static struct notifier_block css_power_notifier = { | |
874 | .notifier_call = css_power_event, | |
875 | }; | |
876 | ||
1da177e4 LT |
877 | /* |
878 | * Now that the driver core is running, we can setup our channel subsystem. | |
14556b33 | 879 | * The struct subchannel's are created during probing. |
1da177e4 | 880 | */ |
2f17644d | 881 | static int __init css_bus_init(void) |
1da177e4 | 882 | { |
a28c6944 | 883 | int ret, i; |
1da177e4 | 884 | |
34aec07c SO |
885 | ret = chsc_init(); |
886 | if (ret) | |
887 | return ret; | |
888 | ||
34196f82 | 889 | chsc_determine_css_characteristics(); |
b0a285d3 SO |
890 | /* Try to enable MSS. */ |
891 | ret = chsc_enable_facility(CHSC_SDA_OC_MSS); | |
818c272b | 892 | if (ret) |
b0a285d3 | 893 | max_ssid = 0; |
818c272b SO |
894 | else /* Success. */ |
895 | max_ssid = __MAX_SSID; | |
b0a285d3 | 896 | |
4434a38c CH |
897 | ret = slow_subchannel_init(); |
898 | if (ret) | |
899 | goto out; | |
900 | ||
f5daba1d | 901 | ret = crw_register_handler(CRW_RSC_SCH, css_process_crw); |
c1156189 CH |
902 | if (ret) |
903 | goto out; | |
904 | ||
1da177e4 LT |
905 | if ((ret = bus_register(&css_bus_type))) |
906 | goto out; | |
1da177e4 | 907 | |
a28c6944 CH |
908 | /* Setup css structure. */ |
909 | for (i = 0; i <= __MAX_CSSID; i++) { | |
7c9f4e3a CH |
910 | struct channel_subsystem *css; |
911 | ||
912 | css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL); | |
913 | if (!css) { | |
a28c6944 | 914 | ret = -ENOMEM; |
fb6958a5 | 915 | goto out_unregister; |
a28c6944 | 916 | } |
7c9f4e3a | 917 | channel_subsystems[i] = css; |
d7b5a4c9 | 918 | ret = setup_css(i); |
a2164b81 CH |
919 | if (ret) { |
920 | kfree(channel_subsystems[i]); | |
921 | goto out_unregister; | |
922 | } | |
7c9f4e3a | 923 | ret = device_register(&css->device); |
a2164b81 CH |
924 | if (ret) { |
925 | put_device(&css->device); | |
926 | goto out_unregister; | |
927 | } | |
75784c00 | 928 | if (css_chsc_characteristics.secm) { |
7c9f4e3a | 929 | ret = device_create_file(&css->device, |
7e560814 CH |
930 | &dev_attr_cm_enable); |
931 | if (ret) | |
932 | goto out_device; | |
933 | } | |
7c9f4e3a | 934 | ret = device_register(&css->pseudo_subchannel->dev); |
c6304933 SO |
935 | if (ret) { |
936 | put_device(&css->pseudo_subchannel->dev); | |
d7b5a4c9 | 937 | goto out_file; |
c6304933 | 938 | } |
a28c6944 | 939 | } |
a55360df CH |
940 | ret = register_reboot_notifier(&css_reboot_notifier); |
941 | if (ret) | |
a2164b81 | 942 | goto out_unregister; |
dcbd16d5 SO |
943 | ret = register_pm_notifier(&css_power_notifier); |
944 | if (ret) { | |
945 | unregister_reboot_notifier(&css_reboot_notifier); | |
946 | goto out_unregister; | |
947 | } | |
1da177e4 LT |
948 | css_init_done = 1; |
949 | ||
3a3fc29a | 950 | /* Enable default isc for I/O subchannels. */ |
6ef556cc | 951 | isc_register(IO_SCH_ISC); |
1da177e4 | 952 | |
1da177e4 | 953 | return 0; |
d7b5a4c9 | 954 | out_file: |
a2164b81 CH |
955 | if (css_chsc_characteristics.secm) |
956 | device_remove_file(&channel_subsystems[i]->device, | |
957 | &dev_attr_cm_enable); | |
7e560814 | 958 | out_device: |
7c9f4e3a | 959 | device_unregister(&channel_subsystems[i]->device); |
fb6958a5 | 960 | out_unregister: |
a28c6944 | 961 | while (i > 0) { |
7c9f4e3a CH |
962 | struct channel_subsystem *css; |
963 | ||
a28c6944 | 964 | i--; |
7c9f4e3a CH |
965 | css = channel_subsystems[i]; |
966 | device_unregister(&css->pseudo_subchannel->dev); | |
a2164b81 | 967 | css->pseudo_subchannel = NULL; |
75784c00 | 968 | if (css_chsc_characteristics.secm) |
7c9f4e3a | 969 | device_remove_file(&css->device, |
495a5b45 | 970 | &dev_attr_cm_enable); |
7c9f4e3a | 971 | device_unregister(&css->device); |
a28c6944 | 972 | } |
1da177e4 LT |
973 | bus_unregister(&css_bus_type); |
974 | out: | |
34aec07c | 975 | crw_unregister_handler(CRW_RSC_SCH); |
b827d1c8 | 976 | idset_free(slow_subchannel_set); |
34aec07c | 977 | chsc_init_cleanup(); |
e6d5a428 ME |
978 | pr_alert("The CSS device driver initialization failed with " |
979 | "errno=%d\n", ret); | |
1da177e4 LT |
980 | return ret; |
981 | } | |
982 | ||
2f17644d SO |
983 | static void __init css_bus_cleanup(void) |
984 | { | |
985 | struct channel_subsystem *css; | |
986 | int i; | |
987 | ||
988 | for (i = 0; i <= __MAX_CSSID; i++) { | |
989 | css = channel_subsystems[i]; | |
990 | device_unregister(&css->pseudo_subchannel->dev); | |
991 | css->pseudo_subchannel = NULL; | |
992 | if (css_chsc_characteristics.secm) | |
993 | device_remove_file(&css->device, &dev_attr_cm_enable); | |
994 | device_unregister(&css->device); | |
995 | } | |
996 | bus_unregister(&css_bus_type); | |
34aec07c | 997 | crw_unregister_handler(CRW_RSC_SCH); |
b827d1c8 | 998 | idset_free(slow_subchannel_set); |
34aec07c | 999 | chsc_init_cleanup(); |
2f17644d SO |
1000 | isc_unregister(IO_SCH_ISC); |
1001 | } | |
1002 | ||
1003 | static int __init channel_subsystem_init(void) | |
1004 | { | |
1005 | int ret; | |
1006 | ||
1007 | ret = css_bus_init(); | |
1008 | if (ret) | |
1009 | return ret; | |
be5d3823 SO |
1010 | cio_work_q = create_singlethread_workqueue("cio"); |
1011 | if (!cio_work_q) { | |
1012 | ret = -ENOMEM; | |
1013 | goto out_bus; | |
1014 | } | |
2f17644d SO |
1015 | ret = io_subchannel_init(); |
1016 | if (ret) | |
be5d3823 | 1017 | goto out_wq; |
2f17644d SO |
1018 | |
1019 | return ret; | |
be5d3823 SO |
1020 | out_wq: |
1021 | destroy_workqueue(cio_work_q); | |
1022 | out_bus: | |
1023 | css_bus_cleanup(); | |
1024 | return ret; | |
2f17644d SO |
1025 | } |
1026 | subsys_initcall(channel_subsystem_init); | |
1027 | ||
8ea7f559 SO |
1028 | static int css_settle(struct device_driver *drv, void *unused) |
1029 | { | |
1030 | struct css_driver *cssdrv = to_cssdriver(drv); | |
1031 | ||
1032 | if (cssdrv->settle) | |
b4c70721 | 1033 | return cssdrv->settle(); |
8ea7f559 SO |
1034 | return 0; |
1035 | } | |
1036 | ||
0d01bb89 | 1037 | int css_complete_work(void) |
879acca5 SO |
1038 | { |
1039 | int ret; | |
1040 | ||
1041 | /* Wait for the evaluation of subchannels to finish. */ | |
b4c70721 SO |
1042 | ret = wait_event_interruptible(css_eval_wq, |
1043 | atomic_read(&css_eval_scheduled) == 0); | |
1044 | if (ret) | |
1045 | return -EINTR; | |
879acca5 SO |
1046 | flush_workqueue(cio_work_q); |
1047 | /* Wait for the subchannel type specific initialization to finish */ | |
b4c70721 | 1048 | return bus_for_each_drv(&css_bus_type, NULL, NULL, css_settle); |
879acca5 SO |
1049 | } |
1050 | ||
1051 | ||
2f17644d SO |
1052 | /* |
1053 | * Wait for the initialization of devices to finish, to make sure we are | |
1054 | * done with our setup if the search for the root device starts. | |
1055 | */ | |
1056 | static int __init channel_subsystem_init_sync(void) | |
1057 | { | |
14556b33 SO |
1058 | /* Register subchannels which are already in use. */ |
1059 | cio_register_early_subchannels(); | |
703e5c99 SO |
1060 | /* Start initial subchannel evaluation. */ |
1061 | css_schedule_eval_all(); | |
879acca5 SO |
1062 | css_complete_work(); |
1063 | return 0; | |
2f17644d SO |
1064 | } |
1065 | subsys_initcall_sync(channel_subsystem_init_sync); | |
1066 | ||
889ee955 SO |
1067 | void channel_subsystem_reinit(void) |
1068 | { | |
62da177a SO |
1069 | struct channel_path *chp; |
1070 | struct chp_id chpid; | |
1071 | ||
889ee955 | 1072 | chsc_enable_facility(CHSC_SDA_OC_MSS); |
62da177a SO |
1073 | chp_id_for_each(&chpid) { |
1074 | chp = chpid_to_chp(chpid); | |
cce0eacc PO |
1075 | if (chp) |
1076 | chp_update_desc(chp); | |
62da177a | 1077 | } |
889ee955 SO |
1078 | } |
1079 | ||
879acca5 SO |
1080 | #ifdef CONFIG_PROC_FS |
1081 | static ssize_t cio_settle_write(struct file *file, const char __user *buf, | |
1082 | size_t count, loff_t *ppos) | |
1083 | { | |
b4c70721 SO |
1084 | int ret; |
1085 | ||
879acca5 SO |
1086 | /* Handle pending CRW's. */ |
1087 | crw_wait_for_channel_report(); | |
b4c70721 SO |
1088 | ret = css_complete_work(); |
1089 | ||
1090 | return ret ? ret : count; | |
879acca5 SO |
1091 | } |
1092 | ||
1093 | static const struct file_operations cio_settle_proc_fops = { | |
58ea91c0 | 1094 | .open = nonseekable_open, |
879acca5 | 1095 | .write = cio_settle_write, |
6038f373 | 1096 | .llseek = no_llseek, |
879acca5 SO |
1097 | }; |
1098 | ||
1099 | static int __init cio_settle_init(void) | |
1100 | { | |
1101 | struct proc_dir_entry *entry; | |
1102 | ||
1103 | entry = proc_create("cio_settle", S_IWUSR, NULL, | |
1104 | &cio_settle_proc_fops); | |
1105 | if (!entry) | |
1106 | return -ENOMEM; | |
1107 | return 0; | |
1108 | } | |
1109 | device_initcall(cio_settle_init); | |
1110 | #endif /*CONFIG_PROC_FS*/ | |
1111 | ||
d7b5a4c9 CH |
1112 | int sch_is_pseudo_sch(struct subchannel *sch) |
1113 | { | |
1114 | return sch == to_css(sch->dev.parent)->pseudo_subchannel; | |
1115 | } | |
1116 | ||
f08adc00 | 1117 | static int css_bus_match(struct device *dev, struct device_driver *drv) |
1da177e4 | 1118 | { |
084325d8 CH |
1119 | struct subchannel *sch = to_subchannel(dev); |
1120 | struct css_driver *driver = to_cssdriver(drv); | |
f08adc00 | 1121 | struct css_device_id *id; |
1da177e4 | 1122 | |
f08adc00 CH |
1123 | for (id = driver->subchannel_type; id->match_flags; id++) { |
1124 | if (sch->st == id->type) | |
1125 | return 1; | |
1126 | } | |
1da177e4 LT |
1127 | |
1128 | return 0; | |
1129 | } | |
1130 | ||
98c13c28 | 1131 | static int css_probe(struct device *dev) |
8bbace7e CH |
1132 | { |
1133 | struct subchannel *sch; | |
98c13c28 | 1134 | int ret; |
8bbace7e CH |
1135 | |
1136 | sch = to_subchannel(dev); | |
084325d8 | 1137 | sch->driver = to_cssdriver(dev->driver); |
98c13c28 CH |
1138 | ret = sch->driver->probe ? sch->driver->probe(sch) : 0; |
1139 | if (ret) | |
1140 | sch->driver = NULL; | |
1141 | return ret; | |
8bbace7e CH |
1142 | } |
1143 | ||
98c13c28 | 1144 | static int css_remove(struct device *dev) |
8bbace7e CH |
1145 | { |
1146 | struct subchannel *sch; | |
98c13c28 | 1147 | int ret; |
8bbace7e CH |
1148 | |
1149 | sch = to_subchannel(dev); | |
98c13c28 CH |
1150 | ret = sch->driver->remove ? sch->driver->remove(sch) : 0; |
1151 | sch->driver = NULL; | |
1152 | return ret; | |
8bbace7e CH |
1153 | } |
1154 | ||
98c13c28 | 1155 | static void css_shutdown(struct device *dev) |
8bbace7e CH |
1156 | { |
1157 | struct subchannel *sch; | |
1158 | ||
1159 | sch = to_subchannel(dev); | |
98c13c28 | 1160 | if (sch->driver && sch->driver->shutdown) |
8bbace7e CH |
1161 | sch->driver->shutdown(sch); |
1162 | } | |
1163 | ||
7e9db9ea CH |
1164 | static int css_uevent(struct device *dev, struct kobj_uevent_env *env) |
1165 | { | |
1166 | struct subchannel *sch = to_subchannel(dev); | |
1167 | int ret; | |
1168 | ||
1169 | ret = add_uevent_var(env, "ST=%01X", sch->st); | |
1170 | if (ret) | |
1171 | return ret; | |
1172 | ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st); | |
1173 | return ret; | |
1174 | } | |
1175 | ||
dcbd16d5 SO |
1176 | static int css_pm_prepare(struct device *dev) |
1177 | { | |
1178 | struct subchannel *sch = to_subchannel(dev); | |
1179 | struct css_driver *drv; | |
1180 | ||
1181 | if (mutex_is_locked(&sch->reg_mutex)) | |
1182 | return -EAGAIN; | |
1183 | if (!sch->dev.driver) | |
1184 | return 0; | |
1185 | drv = to_cssdriver(sch->dev.driver); | |
1186 | /* Notify drivers that they may not register children. */ | |
1187 | return drv->prepare ? drv->prepare(sch) : 0; | |
1188 | } | |
1189 | ||
1190 | static void css_pm_complete(struct device *dev) | |
1191 | { | |
1192 | struct subchannel *sch = to_subchannel(dev); | |
1193 | struct css_driver *drv; | |
1194 | ||
1195 | if (!sch->dev.driver) | |
1196 | return; | |
1197 | drv = to_cssdriver(sch->dev.driver); | |
1198 | if (drv->complete) | |
1199 | drv->complete(sch); | |
1200 | } | |
1201 | ||
1202 | static int css_pm_freeze(struct device *dev) | |
1203 | { | |
1204 | struct subchannel *sch = to_subchannel(dev); | |
1205 | struct css_driver *drv; | |
1206 | ||
1207 | if (!sch->dev.driver) | |
1208 | return 0; | |
1209 | drv = to_cssdriver(sch->dev.driver); | |
1210 | return drv->freeze ? drv->freeze(sch) : 0; | |
1211 | } | |
1212 | ||
1213 | static int css_pm_thaw(struct device *dev) | |
1214 | { | |
1215 | struct subchannel *sch = to_subchannel(dev); | |
1216 | struct css_driver *drv; | |
1217 | ||
1218 | if (!sch->dev.driver) | |
1219 | return 0; | |
1220 | drv = to_cssdriver(sch->dev.driver); | |
1221 | return drv->thaw ? drv->thaw(sch) : 0; | |
1222 | } | |
1223 | ||
1224 | static int css_pm_restore(struct device *dev) | |
1225 | { | |
1226 | struct subchannel *sch = to_subchannel(dev); | |
1227 | struct css_driver *drv; | |
1228 | ||
eb4f5d93 | 1229 | css_update_ssd_info(sch); |
dcbd16d5 SO |
1230 | if (!sch->dev.driver) |
1231 | return 0; | |
1232 | drv = to_cssdriver(sch->dev.driver); | |
1233 | return drv->restore ? drv->restore(sch) : 0; | |
1234 | } | |
1235 | ||
47145210 | 1236 | static const struct dev_pm_ops css_pm_ops = { |
dcbd16d5 SO |
1237 | .prepare = css_pm_prepare, |
1238 | .complete = css_pm_complete, | |
1239 | .freeze = css_pm_freeze, | |
1240 | .thaw = css_pm_thaw, | |
1241 | .restore = css_pm_restore, | |
1242 | }; | |
1243 | ||
3041b6ab | 1244 | static struct bus_type css_bus_type = { |
8bbace7e CH |
1245 | .name = "css", |
1246 | .match = css_bus_match, | |
1247 | .probe = css_probe, | |
1248 | .remove = css_remove, | |
1249 | .shutdown = css_shutdown, | |
7e9db9ea | 1250 | .uevent = css_uevent, |
dcbd16d5 | 1251 | .pm = &css_pm_ops, |
1da177e4 LT |
1252 | }; |
1253 | ||
25b7bb58 CH |
1254 | /** |
1255 | * css_driver_register - register a css driver | |
1256 | * @cdrv: css driver to register | |
1257 | * | |
1258 | * This is mainly a wrapper around driver_register that sets name | |
1259 | * and bus_type in the embedded struct device_driver correctly. | |
1260 | */ | |
1261 | int css_driver_register(struct css_driver *cdrv) | |
1262 | { | |
25b7bb58 CH |
1263 | cdrv->drv.bus = &css_bus_type; |
1264 | return driver_register(&cdrv->drv); | |
1265 | } | |
1266 | EXPORT_SYMBOL_GPL(css_driver_register); | |
1267 | ||
1268 | /** | |
1269 | * css_driver_unregister - unregister a css driver | |
1270 | * @cdrv: css driver to unregister | |
1271 | * | |
1272 | * This is a wrapper around driver_unregister. | |
1273 | */ | |
1274 | void css_driver_unregister(struct css_driver *cdrv) | |
1275 | { | |
1276 | driver_unregister(&cdrv->drv); | |
1277 | } | |
1278 | EXPORT_SYMBOL_GPL(css_driver_unregister); | |
1279 | ||
1da177e4 | 1280 | MODULE_LICENSE("GPL"); |