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