]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * drivers/s390/cio/css.c | |
3 | * driver for channel subsystem | |
1da177e4 | 4 | * |
7e9db9ea | 5 | * Copyright IBM Corp. 2002,2008 |
1da177e4 | 6 | * Author(s): Arnd Bergmann (arndb@de.ibm.com) |
4ce3b30c | 7 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
1da177e4 LT |
8 | */ |
9 | #include <linux/module.h> | |
10 | #include <linux/init.h> | |
11 | #include <linux/device.h> | |
12 | #include <linux/slab.h> | |
13 | #include <linux/errno.h> | |
14 | #include <linux/list.h> | |
a55360df | 15 | #include <linux/reboot.h> |
1da177e4 | 16 | |
c1156189 | 17 | #include "../s390mach.h" |
1da177e4 LT |
18 | #include "css.h" |
19 | #include "cio.h" | |
20 | #include "cio_debug.h" | |
21 | #include "ioasm.h" | |
22 | #include "chsc.h" | |
40154b82 | 23 | #include "device.h" |
83b3370c | 24 | #include "idset.h" |
7ad6a249 | 25 | #include "chp.h" |
1da177e4 | 26 | |
1da177e4 | 27 | int css_init_done = 0; |
40154b82 | 28 | static int need_reprobe = 0; |
fb6958a5 | 29 | static int max_ssid = 0; |
1da177e4 | 30 | |
7c9f4e3a | 31 | struct channel_subsystem *channel_subsystems[__MAX_CSSID + 1]; |
1da177e4 | 32 | |
a28c6944 | 33 | int css_characteristics_avail = 0; |
1da177e4 | 34 | |
4d284cac | 35 | int |
f97a56fb CH |
36 | for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data) |
37 | { | |
38 | struct subchannel_id schid; | |
39 | int ret; | |
40 | ||
41 | init_subchannel_id(&schid); | |
42 | ret = -ENODEV; | |
43 | do { | |
fb6958a5 CH |
44 | do { |
45 | ret = fn(schid, data); | |
46 | if (ret) | |
47 | break; | |
48 | } while (schid.sch_no++ < __MAX_SUBCHANNEL); | |
49 | schid.sch_no = 0; | |
50 | } while (schid.ssid++ < max_ssid); | |
f97a56fb CH |
51 | return ret; |
52 | } | |
53 | ||
e82a1567 PO |
54 | struct cb_data { |
55 | void *data; | |
56 | struct idset *set; | |
57 | int (*fn_known_sch)(struct subchannel *, void *); | |
58 | int (*fn_unknown_sch)(struct subchannel_id, void *); | |
59 | }; | |
60 | ||
61 | static int call_fn_known_sch(struct device *dev, void *data) | |
62 | { | |
63 | struct subchannel *sch = to_subchannel(dev); | |
64 | struct cb_data *cb = data; | |
65 | int rc = 0; | |
66 | ||
67 | idset_sch_del(cb->set, sch->schid); | |
68 | if (cb->fn_known_sch) | |
69 | rc = cb->fn_known_sch(sch, cb->data); | |
70 | return rc; | |
71 | } | |
72 | ||
73 | static int call_fn_unknown_sch(struct subchannel_id schid, void *data) | |
74 | { | |
75 | struct cb_data *cb = data; | |
76 | int rc = 0; | |
77 | ||
78 | if (idset_sch_contains(cb->set, schid)) | |
79 | rc = cb->fn_unknown_sch(schid, cb->data); | |
80 | return rc; | |
81 | } | |
82 | ||
83 | int for_each_subchannel_staged(int (*fn_known)(struct subchannel *, void *), | |
84 | int (*fn_unknown)(struct subchannel_id, | |
85 | void *), void *data) | |
86 | { | |
87 | struct cb_data cb; | |
88 | int rc; | |
89 | ||
90 | cb.set = idset_sch_new(); | |
91 | if (!cb.set) | |
92 | return -ENOMEM; | |
93 | idset_fill(cb.set); | |
94 | cb.data = data; | |
95 | cb.fn_known_sch = fn_known; | |
96 | cb.fn_unknown_sch = fn_unknown; | |
97 | /* Process registered subchannels. */ | |
98 | rc = bus_for_each_dev(&css_bus_type, NULL, &cb, call_fn_known_sch); | |
99 | if (rc) | |
100 | goto out; | |
101 | /* Process unregistered subchannels. */ | |
102 | if (fn_unknown) | |
103 | rc = for_each_subchannel(call_fn_unknown_sch, &cb); | |
104 | out: | |
105 | idset_free(cb.set); | |
106 | ||
107 | return rc; | |
108 | } | |
109 | ||
1da177e4 | 110 | static struct subchannel * |
a8237fc4 | 111 | css_alloc_subchannel(struct subchannel_id schid) |
1da177e4 LT |
112 | { |
113 | struct subchannel *sch; | |
114 | int ret; | |
115 | ||
116 | sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA); | |
117 | if (sch == NULL) | |
118 | return ERR_PTR(-ENOMEM); | |
a8237fc4 | 119 | ret = cio_validate_subchannel (sch, schid); |
1da177e4 LT |
120 | if (ret < 0) { |
121 | kfree(sch); | |
122 | return ERR_PTR(ret); | |
123 | } | |
1da177e4 LT |
124 | return sch; |
125 | } | |
126 | ||
127 | static void | |
128 | css_free_subchannel(struct subchannel *sch) | |
129 | { | |
130 | if (sch) { | |
131 | /* Reset intparm to zeroes. */ | |
132 | sch->schib.pmcw.intparm = 0; | |
133 | cio_modify(sch); | |
2ec22984 | 134 | kfree(sch->lock); |
1da177e4 LT |
135 | kfree(sch); |
136 | } | |
1da177e4 LT |
137 | } |
138 | ||
139 | static void | |
140 | css_subchannel_release(struct device *dev) | |
141 | { | |
142 | struct subchannel *sch; | |
143 | ||
144 | sch = to_subchannel(dev); | |
2ec22984 CH |
145 | if (!cio_is_console(sch->schid)) { |
146 | kfree(sch->lock); | |
1da177e4 | 147 | kfree(sch); |
2ec22984 | 148 | } |
1da177e4 LT |
149 | } |
150 | ||
07c6a338 | 151 | static int css_sch_device_register(struct subchannel *sch) |
6ab4879a CH |
152 | { |
153 | int ret; | |
154 | ||
155 | mutex_lock(&sch->reg_mutex); | |
156 | ret = device_register(&sch->dev); | |
157 | mutex_unlock(&sch->reg_mutex); | |
158 | return ret; | |
159 | } | |
160 | ||
44a1c19e CH |
161 | /** |
162 | * css_sch_device_unregister - unregister a subchannel | |
163 | * @sch: subchannel to be unregistered | |
164 | */ | |
6ab4879a CH |
165 | void css_sch_device_unregister(struct subchannel *sch) |
166 | { | |
167 | mutex_lock(&sch->reg_mutex); | |
168 | device_unregister(&sch->dev); | |
169 | mutex_unlock(&sch->reg_mutex); | |
170 | } | |
44a1c19e | 171 | EXPORT_SYMBOL_GPL(css_sch_device_unregister); |
6ab4879a | 172 | |
7ad6a249 PO |
173 | static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw) |
174 | { | |
175 | int i; | |
176 | int mask; | |
177 | ||
178 | memset(ssd, 0, sizeof(struct chsc_ssd_info)); | |
179 | ssd->path_mask = pmcw->pim; | |
180 | for (i = 0; i < 8; i++) { | |
181 | mask = 0x80 >> i; | |
182 | if (pmcw->pim & mask) { | |
183 | chp_id_init(&ssd->chpid[i]); | |
184 | ssd->chpid[i].id = pmcw->chpid[i]; | |
185 | } | |
186 | } | |
187 | } | |
188 | ||
189 | static void ssd_register_chpids(struct chsc_ssd_info *ssd) | |
190 | { | |
191 | int i; | |
192 | int mask; | |
193 | ||
194 | for (i = 0; i < 8; i++) { | |
195 | mask = 0x80 >> i; | |
196 | if (ssd->path_mask & mask) | |
197 | if (!chp_is_registered(ssd->chpid[i])) | |
198 | chp_new(ssd->chpid[i]); | |
199 | } | |
200 | } | |
201 | ||
202 | void css_update_ssd_info(struct subchannel *sch) | |
203 | { | |
204 | int ret; | |
205 | ||
206 | if (cio_is_console(sch->schid)) { | |
207 | /* Console is initialized too early for functions requiring | |
208 | * memory allocation. */ | |
209 | ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw); | |
210 | } else { | |
211 | ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info); | |
212 | if (ret) | |
213 | ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw); | |
214 | ssd_register_chpids(&sch->ssd_info); | |
215 | } | |
216 | } | |
217 | ||
7e9db9ea CH |
218 | static ssize_t type_show(struct device *dev, struct device_attribute *attr, |
219 | char *buf) | |
220 | { | |
221 | struct subchannel *sch = to_subchannel(dev); | |
222 | ||
223 | return sprintf(buf, "%01x\n", sch->st); | |
224 | } | |
225 | ||
226 | static DEVICE_ATTR(type, 0444, type_show, NULL); | |
227 | ||
228 | static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, | |
229 | char *buf) | |
230 | { | |
231 | struct subchannel *sch = to_subchannel(dev); | |
232 | ||
233 | return sprintf(buf, "css:t%01X\n", sch->st); | |
234 | } | |
235 | ||
236 | static DEVICE_ATTR(modalias, 0444, modalias_show, NULL); | |
237 | ||
238 | static struct attribute *subch_attrs[] = { | |
239 | &dev_attr_type.attr, | |
240 | &dev_attr_modalias.attr, | |
241 | NULL, | |
242 | }; | |
243 | ||
244 | static struct attribute_group subch_attr_group = { | |
245 | .attrs = subch_attrs, | |
246 | }; | |
247 | ||
248 | static struct attribute_group *default_subch_attr_groups[] = { | |
249 | &subch_attr_group, | |
250 | NULL, | |
251 | }; | |
252 | ||
7ad6a249 | 253 | static int css_register_subchannel(struct subchannel *sch) |
1da177e4 LT |
254 | { |
255 | int ret; | |
256 | ||
257 | /* Initialize the subchannel structure */ | |
7c9f4e3a | 258 | sch->dev.parent = &channel_subsystems[0]->device; |
1da177e4 LT |
259 | sch->dev.bus = &css_bus_type; |
260 | sch->dev.release = &css_subchannel_release; | |
7e9db9ea | 261 | sch->dev.groups = default_subch_attr_groups; |
5bf04b20 CH |
262 | /* |
263 | * We don't want to generate uevents for I/O subchannels that don't | |
264 | * have a working ccw device behind them since they will be | |
265 | * unregistered before they can be used anyway, so we delay the add | |
266 | * uevent until after device recognition was successful. | |
7e9db9ea CH |
267 | * Note that we suppress the uevent for all subchannel types; |
268 | * the subchannel driver can decide itself when it wants to inform | |
269 | * userspace of its existence. | |
5bf04b20 | 270 | */ |
7e9db9ea | 271 | sch->dev.uevent_suppress = 1; |
7ad6a249 | 272 | css_update_ssd_info(sch); |
1da177e4 | 273 | /* make it known to the system */ |
6ab4879a | 274 | ret = css_sch_device_register(sch); |
7674da77 | 275 | if (ret) { |
e556bbbd CH |
276 | CIO_MSG_EVENT(0, "Could not register sch 0.%x.%04x: %d\n", |
277 | sch->schid.ssid, sch->schid.sch_no, ret); | |
7674da77 CH |
278 | return ret; |
279 | } | |
7e9db9ea CH |
280 | if (!sch->driver) { |
281 | /* | |
282 | * No driver matched. Generate the uevent now so that | |
283 | * a fitting driver module may be loaded based on the | |
284 | * modalias. | |
285 | */ | |
286 | sch->dev.uevent_suppress = 0; | |
287 | kobject_uevent(&sch->dev.kobj, KOBJ_ADD); | |
288 | } | |
1da177e4 LT |
289 | return ret; |
290 | } | |
291 | ||
c820de39 | 292 | int css_probe_device(struct subchannel_id schid) |
1da177e4 LT |
293 | { |
294 | int ret; | |
295 | struct subchannel *sch; | |
296 | ||
a8237fc4 | 297 | sch = css_alloc_subchannel(schid); |
1da177e4 LT |
298 | if (IS_ERR(sch)) |
299 | return PTR_ERR(sch); | |
300 | ret = css_register_subchannel(sch); | |
301 | if (ret) | |
302 | css_free_subchannel(sch); | |
303 | return ret; | |
304 | } | |
305 | ||
b0744bd2 CH |
306 | static int |
307 | check_subchannel(struct device * dev, void * data) | |
308 | { | |
309 | struct subchannel *sch; | |
a8237fc4 | 310 | struct subchannel_id *schid = data; |
b0744bd2 CH |
311 | |
312 | sch = to_subchannel(dev); | |
a8237fc4 | 313 | return schid_equal(&sch->schid, schid); |
b0744bd2 CH |
314 | } |
315 | ||
1da177e4 | 316 | struct subchannel * |
a8237fc4 | 317 | get_subchannel_by_schid(struct subchannel_id schid) |
1da177e4 | 318 | { |
1da177e4 LT |
319 | struct device *dev; |
320 | ||
b0744bd2 | 321 | dev = bus_find_device(&css_bus_type, NULL, |
12975aef | 322 | &schid, check_subchannel); |
1da177e4 | 323 | |
b0744bd2 | 324 | return dev ? to_subchannel(dev) : NULL; |
1da177e4 LT |
325 | } |
326 | ||
b279a4f5 CH |
327 | /** |
328 | * css_sch_is_valid() - check if a subchannel is valid | |
329 | * @schib: subchannel information block for the subchannel | |
330 | */ | |
331 | int css_sch_is_valid(struct schib *schib) | |
332 | { | |
333 | if ((schib->pmcw.st == SUBCHANNEL_TYPE_IO) && !schib->pmcw.dnv) | |
334 | return 0; | |
b3a686f4 CH |
335 | if ((schib->pmcw.st == SUBCHANNEL_TYPE_MSG) && !schib->pmcw.w) |
336 | return 0; | |
b279a4f5 CH |
337 | return 1; |
338 | } | |
339 | EXPORT_SYMBOL_GPL(css_sch_is_valid); | |
340 | ||
564337f3 PO |
341 | static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow) |
342 | { | |
343 | struct schib schib; | |
344 | ||
345 | if (!slow) { | |
346 | /* Will be done on the slow path. */ | |
347 | return -EAGAIN; | |
348 | } | |
b279a4f5 | 349 | if (stsch_err(schid, &schib) || !css_sch_is_valid(&schib)) { |
564337f3 PO |
350 | /* Unusable - ignore. */ |
351 | return 0; | |
1da177e4 | 352 | } |
564337f3 PO |
353 | CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, " |
354 | "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER); | |
355 | ||
356 | return css_probe_device(schid); | |
357 | } | |
358 | ||
c820de39 CH |
359 | static int css_evaluate_known_subchannel(struct subchannel *sch, int slow) |
360 | { | |
361 | int ret = 0; | |
362 | ||
363 | if (sch->driver) { | |
364 | if (sch->driver->sch_event) | |
365 | ret = sch->driver->sch_event(sch, slow); | |
366 | else | |
367 | dev_dbg(&sch->dev, | |
368 | "Got subchannel machine check but " | |
369 | "no sch_event handler provided.\n"); | |
370 | } | |
371 | return ret; | |
372 | } | |
373 | ||
83b3370c | 374 | static void css_evaluate_subchannel(struct subchannel_id schid, int slow) |
564337f3 PO |
375 | { |
376 | struct subchannel *sch; | |
377 | int ret; | |
378 | ||
379 | sch = get_subchannel_by_schid(schid); | |
380 | if (sch) { | |
381 | ret = css_evaluate_known_subchannel(sch, slow); | |
382 | put_device(&sch->dev); | |
383 | } else | |
384 | ret = css_evaluate_new_subchannel(schid, slow); | |
83b3370c PO |
385 | if (ret == -EAGAIN) |
386 | css_schedule_eval(schid); | |
1da177e4 LT |
387 | } |
388 | ||
83b3370c PO |
389 | static struct idset *slow_subchannel_set; |
390 | static spinlock_t slow_subchannel_lock; | |
391 | ||
392 | static int __init slow_subchannel_init(void) | |
1da177e4 | 393 | { |
83b3370c PO |
394 | spin_lock_init(&slow_subchannel_lock); |
395 | slow_subchannel_set = idset_sch_new(); | |
396 | if (!slow_subchannel_set) { | |
e556bbbd | 397 | CIO_MSG_EVENT(0, "could not allocate slow subchannel set\n"); |
83b3370c PO |
398 | return -ENOMEM; |
399 | } | |
400 | return 0; | |
1da177e4 LT |
401 | } |
402 | ||
e82a1567 | 403 | static int slow_eval_known_fn(struct subchannel *sch, void *data) |
1da177e4 | 404 | { |
e82a1567 PO |
405 | int eval; |
406 | int rc; | |
1da177e4 LT |
407 | |
408 | spin_lock_irq(&slow_subchannel_lock); | |
e82a1567 PO |
409 | eval = idset_sch_contains(slow_subchannel_set, sch->schid); |
410 | idset_sch_del(slow_subchannel_set, sch->schid); | |
411 | spin_unlock_irq(&slow_subchannel_lock); | |
412 | if (eval) { | |
413 | rc = css_evaluate_known_subchannel(sch, 1); | |
414 | if (rc == -EAGAIN) | |
415 | css_schedule_eval(sch->schid); | |
1da177e4 | 416 | } |
e82a1567 PO |
417 | return 0; |
418 | } | |
419 | ||
420 | static int slow_eval_unknown_fn(struct subchannel_id schid, void *data) | |
421 | { | |
422 | int eval; | |
423 | int rc = 0; | |
424 | ||
425 | spin_lock_irq(&slow_subchannel_lock); | |
426 | eval = idset_sch_contains(slow_subchannel_set, schid); | |
427 | idset_sch_del(slow_subchannel_set, schid); | |
1da177e4 | 428 | spin_unlock_irq(&slow_subchannel_lock); |
e82a1567 PO |
429 | if (eval) { |
430 | rc = css_evaluate_new_subchannel(schid, 1); | |
431 | switch (rc) { | |
432 | case -EAGAIN: | |
433 | css_schedule_eval(schid); | |
434 | rc = 0; | |
435 | break; | |
436 | case -ENXIO: | |
437 | case -ENOMEM: | |
438 | case -EIO: | |
439 | /* These should abort looping */ | |
440 | break; | |
441 | default: | |
442 | rc = 0; | |
443 | } | |
444 | } | |
445 | return rc; | |
446 | } | |
447 | ||
448 | static void css_slow_path_func(struct work_struct *unused) | |
449 | { | |
450 | CIO_TRACE_EVENT(4, "slowpath"); | |
451 | for_each_subchannel_staged(slow_eval_known_fn, slow_eval_unknown_fn, | |
452 | NULL); | |
1da177e4 LT |
453 | } |
454 | ||
83b3370c | 455 | static DECLARE_WORK(slow_path_work, css_slow_path_func); |
1da177e4 LT |
456 | struct workqueue_struct *slow_path_wq; |
457 | ||
83b3370c PO |
458 | void css_schedule_eval(struct subchannel_id schid) |
459 | { | |
460 | unsigned long flags; | |
461 | ||
462 | spin_lock_irqsave(&slow_subchannel_lock, flags); | |
463 | idset_sch_add(slow_subchannel_set, schid); | |
464 | queue_work(slow_path_wq, &slow_path_work); | |
465 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); | |
466 | } | |
467 | ||
468 | void css_schedule_eval_all(void) | |
469 | { | |
470 | unsigned long flags; | |
471 | ||
472 | spin_lock_irqsave(&slow_subchannel_lock, flags); | |
473 | idset_fill(slow_subchannel_set); | |
474 | queue_work(slow_path_wq, &slow_path_work); | |
475 | spin_unlock_irqrestore(&slow_subchannel_lock, flags); | |
476 | } | |
477 | ||
22806dc1 CH |
478 | void css_wait_for_slow_path(void) |
479 | { | |
480 | flush_workqueue(ccw_device_notify_work); | |
481 | flush_workqueue(slow_path_wq); | |
482 | } | |
483 | ||
40154b82 PO |
484 | /* Reprobe subchannel if unregistered. */ |
485 | static int reprobe_subchannel(struct subchannel_id schid, void *data) | |
486 | { | |
40154b82 PO |
487 | int ret; |
488 | ||
e556bbbd CH |
489 | CIO_MSG_EVENT(6, "cio: reprobe 0.%x.%04x\n", |
490 | schid.ssid, schid.sch_no); | |
40154b82 PO |
491 | if (need_reprobe) |
492 | return -EAGAIN; | |
493 | ||
40154b82 PO |
494 | ret = css_probe_device(schid); |
495 | switch (ret) { | |
496 | case 0: | |
497 | break; | |
498 | case -ENXIO: | |
499 | case -ENOMEM: | |
67175616 | 500 | case -EIO: |
40154b82 PO |
501 | /* These should abort looping */ |
502 | break; | |
503 | default: | |
504 | ret = 0; | |
505 | } | |
506 | ||
507 | return ret; | |
508 | } | |
509 | ||
510 | /* Work function used to reprobe all unregistered subchannels. */ | |
4927b3f7 | 511 | static void reprobe_all(struct work_struct *unused) |
40154b82 PO |
512 | { |
513 | int ret; | |
514 | ||
139b83dd | 515 | CIO_MSG_EVENT(4, "reprobe start\n"); |
40154b82 PO |
516 | |
517 | need_reprobe = 0; | |
518 | /* Make sure initial subchannel scan is done. */ | |
519 | wait_event(ccw_device_init_wq, | |
520 | atomic_read(&ccw_device_init_count) == 0); | |
e82a1567 | 521 | ret = for_each_subchannel_staged(NULL, reprobe_subchannel, NULL); |
40154b82 | 522 | |
139b83dd | 523 | CIO_MSG_EVENT(4, "reprobe done (rc=%d, need_reprobe=%d)\n", ret, |
40154b82 PO |
524 | need_reprobe); |
525 | } | |
526 | ||
2b67fc46 | 527 | static DECLARE_WORK(css_reprobe_work, reprobe_all); |
40154b82 PO |
528 | |
529 | /* Schedule reprobing of all unregistered subchannels. */ | |
530 | void css_schedule_reprobe(void) | |
531 | { | |
532 | need_reprobe = 1; | |
c5d4a999 | 533 | queue_work(slow_path_wq, &css_reprobe_work); |
40154b82 PO |
534 | } |
535 | ||
536 | EXPORT_SYMBOL_GPL(css_schedule_reprobe); | |
537 | ||
1da177e4 LT |
538 | /* |
539 | * Called from the machine check handler for subchannel report words. | |
540 | */ | |
c1156189 | 541 | static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow) |
1da177e4 | 542 | { |
a8237fc4 | 543 | struct subchannel_id mchk_schid; |
1da177e4 | 544 | |
c1156189 CH |
545 | if (overflow) { |
546 | css_schedule_eval_all(); | |
547 | return; | |
548 | } | |
549 | CIO_CRW_EVENT(2, "CRW0 reports slct=%d, oflw=%d, " | |
550 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", | |
551 | crw0->slct, crw0->oflw, crw0->chn, crw0->rsc, crw0->anc, | |
552 | crw0->erc, crw0->rsid); | |
553 | if (crw1) | |
554 | CIO_CRW_EVENT(2, "CRW1 reports slct=%d, oflw=%d, " | |
555 | "chn=%d, rsc=%X, anc=%d, erc=%X, rsid=%X\n", | |
556 | crw1->slct, crw1->oflw, crw1->chn, crw1->rsc, | |
557 | crw1->anc, crw1->erc, crw1->rsid); | |
a8237fc4 | 558 | init_subchannel_id(&mchk_schid); |
c1156189 CH |
559 | mchk_schid.sch_no = crw0->rsid; |
560 | if (crw1) | |
561 | mchk_schid.ssid = (crw1->rsid >> 8) & 3; | |
fb6958a5 | 562 | |
c1156189 | 563 | /* |
1da177e4 LT |
564 | * Since we are always presented with IPI in the CRW, we have to |
565 | * use stsch() to find out if the subchannel in question has come | |
566 | * or gone. | |
567 | */ | |
83b3370c | 568 | css_evaluate_subchannel(mchk_schid, 0); |
1da177e4 LT |
569 | } |
570 | ||
f97a56fb CH |
571 | static int __init |
572 | __init_channel_subsystem(struct subchannel_id schid, void *data) | |
573 | { | |
574 | struct subchannel *sch; | |
575 | int ret; | |
576 | ||
577 | if (cio_is_console(schid)) | |
578 | sch = cio_get_console_subchannel(); | |
579 | else { | |
580 | sch = css_alloc_subchannel(schid); | |
581 | if (IS_ERR(sch)) | |
582 | ret = PTR_ERR(sch); | |
583 | else | |
584 | ret = 0; | |
585 | switch (ret) { | |
586 | case 0: | |
587 | break; | |
588 | case -ENOMEM: | |
589 | panic("Out of memory in init_channel_subsystem\n"); | |
590 | /* -ENXIO: no more subchannels. */ | |
591 | case -ENXIO: | |
592 | return ret; | |
e843e280 GS |
593 | /* -EIO: this subchannel set not supported. */ |
594 | case -EIO: | |
595 | return ret; | |
f97a56fb CH |
596 | default: |
597 | return 0; | |
598 | } | |
599 | } | |
600 | /* | |
601 | * We register ALL valid subchannels in ioinfo, even those | |
602 | * that have been present before init_channel_subsystem. | |
603 | * These subchannels can't have been registered yet (kmalloc | |
604 | * not working) so we do it now. This is true e.g. for the | |
605 | * console subchannel. | |
606 | */ | |
607 | css_register_subchannel(sch); | |
608 | return 0; | |
609 | } | |
610 | ||
1da177e4 | 611 | static void __init |
a28c6944 | 612 | css_generate_pgid(struct channel_subsystem *css, u32 tod_high) |
1da177e4 | 613 | { |
a28c6944 CH |
614 | if (css_characteristics_avail && css_general_characteristics.mcss) { |
615 | css->global_pgid.pgid_high.ext_cssid.version = 0x80; | |
616 | css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid; | |
617 | } else { | |
1da177e4 | 618 | #ifdef CONFIG_SMP |
a28c6944 | 619 | css->global_pgid.pgid_high.cpu_addr = hard_smp_processor_id(); |
1da177e4 | 620 | #else |
a28c6944 | 621 | css->global_pgid.pgid_high.cpu_addr = 0; |
1da177e4 LT |
622 | #endif |
623 | } | |
a28c6944 CH |
624 | css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident; |
625 | css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine; | |
626 | css->global_pgid.tod_high = tod_high; | |
627 | ||
628 | } | |
629 | ||
3b793060 CH |
630 | static void |
631 | channel_subsystem_release(struct device *dev) | |
632 | { | |
633 | struct channel_subsystem *css; | |
634 | ||
635 | css = to_css(dev); | |
495a5b45 | 636 | mutex_destroy(&css->mutex); |
3b793060 CH |
637 | kfree(css); |
638 | } | |
639 | ||
495a5b45 CH |
640 | static ssize_t |
641 | css_cm_enable_show(struct device *dev, struct device_attribute *attr, | |
642 | char *buf) | |
643 | { | |
644 | struct channel_subsystem *css = to_css(dev); | |
8284fb19 | 645 | int ret; |
495a5b45 CH |
646 | |
647 | if (!css) | |
648 | return 0; | |
8284fb19 ME |
649 | mutex_lock(&css->mutex); |
650 | ret = sprintf(buf, "%x\n", css->cm_enabled); | |
651 | mutex_unlock(&css->mutex); | |
652 | return ret; | |
495a5b45 CH |
653 | } |
654 | ||
655 | static ssize_t | |
656 | css_cm_enable_store(struct device *dev, struct device_attribute *attr, | |
657 | const char *buf, size_t count) | |
658 | { | |
659 | struct channel_subsystem *css = to_css(dev); | |
660 | int ret; | |
2f972202 | 661 | unsigned long val; |
495a5b45 | 662 | |
2f972202 CH |
663 | ret = strict_strtoul(buf, 16, &val); |
664 | if (ret) | |
665 | return ret; | |
8284fb19 | 666 | mutex_lock(&css->mutex); |
2f972202 CH |
667 | switch (val) { |
668 | case 0: | |
495a5b45 CH |
669 | ret = css->cm_enabled ? chsc_secm(css, 0) : 0; |
670 | break; | |
2f972202 | 671 | case 1: |
495a5b45 CH |
672 | ret = css->cm_enabled ? 0 : chsc_secm(css, 1); |
673 | break; | |
674 | default: | |
675 | ret = -EINVAL; | |
676 | } | |
8284fb19 | 677 | mutex_unlock(&css->mutex); |
495a5b45 CH |
678 | return ret < 0 ? ret : count; |
679 | } | |
680 | ||
681 | static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store); | |
682 | ||
4d284cac | 683 | static int __init setup_css(int nr) |
a28c6944 CH |
684 | { |
685 | u32 tod_high; | |
d7b5a4c9 | 686 | int ret; |
7c9f4e3a | 687 | struct channel_subsystem *css; |
a28c6944 | 688 | |
7c9f4e3a CH |
689 | css = channel_subsystems[nr]; |
690 | memset(css, 0, sizeof(struct channel_subsystem)); | |
691 | css->pseudo_subchannel = | |
692 | kzalloc(sizeof(*css->pseudo_subchannel), GFP_KERNEL); | |
693 | if (!css->pseudo_subchannel) | |
d7b5a4c9 | 694 | return -ENOMEM; |
7c9f4e3a CH |
695 | css->pseudo_subchannel->dev.parent = &css->device; |
696 | css->pseudo_subchannel->dev.release = css_subchannel_release; | |
697 | sprintf(css->pseudo_subchannel->dev.bus_id, "defunct"); | |
698 | ret = cio_create_sch_lock(css->pseudo_subchannel); | |
d7b5a4c9 | 699 | if (ret) { |
7c9f4e3a | 700 | kfree(css->pseudo_subchannel); |
d7b5a4c9 CH |
701 | return ret; |
702 | } | |
7c9f4e3a CH |
703 | mutex_init(&css->mutex); |
704 | css->valid = 1; | |
705 | css->cssid = nr; | |
706 | sprintf(css->device.bus_id, "css%x", nr); | |
707 | css->device.release = channel_subsystem_release; | |
a28c6944 | 708 | tod_high = (u32) (get_clock() >> 32); |
7c9f4e3a | 709 | css_generate_pgid(css, tod_high); |
d7b5a4c9 | 710 | return 0; |
1da177e4 LT |
711 | } |
712 | ||
a55360df CH |
713 | static int css_reboot_event(struct notifier_block *this, |
714 | unsigned long event, | |
715 | void *ptr) | |
716 | { | |
717 | int ret, i; | |
718 | ||
719 | ret = NOTIFY_DONE; | |
720 | for (i = 0; i <= __MAX_CSSID; i++) { | |
721 | struct channel_subsystem *css; | |
722 | ||
723 | css = channel_subsystems[i]; | |
8284fb19 | 724 | mutex_lock(&css->mutex); |
a55360df CH |
725 | if (css->cm_enabled) |
726 | if (chsc_secm(css, 0)) | |
727 | ret = NOTIFY_BAD; | |
8284fb19 | 728 | mutex_unlock(&css->mutex); |
a55360df CH |
729 | } |
730 | ||
731 | return ret; | |
732 | } | |
733 | ||
734 | static struct notifier_block css_reboot_notifier = { | |
735 | .notifier_call = css_reboot_event, | |
736 | }; | |
737 | ||
1da177e4 LT |
738 | /* |
739 | * Now that the driver core is running, we can setup our channel subsystem. | |
740 | * The struct subchannel's are created during probing (except for the | |
741 | * static console subchannel). | |
742 | */ | |
743 | static int __init | |
744 | init_channel_subsystem (void) | |
745 | { | |
a28c6944 | 746 | int ret, i; |
1da177e4 | 747 | |
4434a38c CH |
748 | ret = chsc_determine_css_characteristics(); |
749 | if (ret == -ENOMEM) | |
750 | goto out; /* No need to continue. */ | |
751 | if (ret == 0) | |
1da177e4 LT |
752 | css_characteristics_avail = 1; |
753 | ||
4434a38c CH |
754 | ret = chsc_alloc_sei_area(); |
755 | if (ret) | |
756 | goto out; | |
757 | ||
758 | ret = slow_subchannel_init(); | |
759 | if (ret) | |
760 | goto out; | |
761 | ||
c1156189 CH |
762 | ret = s390_register_crw_handler(CRW_RSC_SCH, css_process_crw); |
763 | if (ret) | |
764 | goto out; | |
765 | ||
1da177e4 LT |
766 | if ((ret = bus_register(&css_bus_type))) |
767 | goto out; | |
1da177e4 | 768 | |
fb6958a5 CH |
769 | /* Try to enable MSS. */ |
770 | ret = chsc_enable_facility(CHSC_SDA_OC_MSS); | |
771 | switch (ret) { | |
772 | case 0: /* Success. */ | |
773 | max_ssid = __MAX_SSID; | |
774 | break; | |
775 | case -ENOMEM: | |
776 | goto out_bus; | |
777 | default: | |
778 | max_ssid = 0; | |
779 | } | |
a28c6944 CH |
780 | /* Setup css structure. */ |
781 | for (i = 0; i <= __MAX_CSSID; i++) { | |
7c9f4e3a CH |
782 | struct channel_subsystem *css; |
783 | ||
784 | css = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL); | |
785 | if (!css) { | |
a28c6944 | 786 | ret = -ENOMEM; |
fb6958a5 | 787 | goto out_unregister; |
a28c6944 | 788 | } |
7c9f4e3a | 789 | channel_subsystems[i] = css; |
d7b5a4c9 | 790 | ret = setup_css(i); |
a28c6944 CH |
791 | if (ret) |
792 | goto out_free; | |
7c9f4e3a | 793 | ret = device_register(&css->device); |
d7b5a4c9 CH |
794 | if (ret) |
795 | goto out_free_all; | |
7e560814 CH |
796 | if (css_characteristics_avail && |
797 | css_chsc_characteristics.secm) { | |
7c9f4e3a | 798 | ret = device_create_file(&css->device, |
7e560814 CH |
799 | &dev_attr_cm_enable); |
800 | if (ret) | |
801 | goto out_device; | |
802 | } | |
7c9f4e3a | 803 | ret = device_register(&css->pseudo_subchannel->dev); |
d7b5a4c9 CH |
804 | if (ret) |
805 | goto out_file; | |
a28c6944 | 806 | } |
a55360df CH |
807 | ret = register_reboot_notifier(&css_reboot_notifier); |
808 | if (ret) | |
809 | goto out_pseudo; | |
1da177e4 LT |
810 | css_init_done = 1; |
811 | ||
812 | ctl_set_bit(6, 28); | |
813 | ||
f97a56fb | 814 | for_each_subchannel(__init_channel_subsystem, NULL); |
1da177e4 | 815 | return 0; |
a55360df CH |
816 | out_pseudo: |
817 | device_unregister(&channel_subsystems[i]->pseudo_subchannel->dev); | |
d7b5a4c9 | 818 | out_file: |
7c9f4e3a CH |
819 | device_remove_file(&channel_subsystems[i]->device, |
820 | &dev_attr_cm_enable); | |
7e560814 | 821 | out_device: |
7c9f4e3a | 822 | device_unregister(&channel_subsystems[i]->device); |
d7b5a4c9 | 823 | out_free_all: |
7c9f4e3a CH |
824 | kfree(channel_subsystems[i]->pseudo_subchannel->lock); |
825 | kfree(channel_subsystems[i]->pseudo_subchannel); | |
a28c6944 | 826 | out_free: |
7c9f4e3a | 827 | kfree(channel_subsystems[i]); |
fb6958a5 | 828 | out_unregister: |
a28c6944 | 829 | while (i > 0) { |
7c9f4e3a CH |
830 | struct channel_subsystem *css; |
831 | ||
a28c6944 | 832 | i--; |
7c9f4e3a CH |
833 | css = channel_subsystems[i]; |
834 | device_unregister(&css->pseudo_subchannel->dev); | |
495a5b45 | 835 | if (css_characteristics_avail && css_chsc_characteristics.secm) |
7c9f4e3a | 836 | device_remove_file(&css->device, |
495a5b45 | 837 | &dev_attr_cm_enable); |
7c9f4e3a | 838 | device_unregister(&css->device); |
a28c6944 | 839 | } |
fb6958a5 | 840 | out_bus: |
1da177e4 LT |
841 | bus_unregister(&css_bus_type); |
842 | out: | |
c1156189 | 843 | s390_unregister_crw_handler(CRW_RSC_CSS); |
4434a38c CH |
844 | chsc_free_sei_area(); |
845 | kfree(slow_subchannel_set); | |
846 | printk(KERN_WARNING"cio: failed to initialize css driver (%d)!\n", | |
847 | ret); | |
1da177e4 LT |
848 | return ret; |
849 | } | |
850 | ||
d7b5a4c9 CH |
851 | int sch_is_pseudo_sch(struct subchannel *sch) |
852 | { | |
853 | return sch == to_css(sch->dev.parent)->pseudo_subchannel; | |
854 | } | |
855 | ||
1da177e4 LT |
856 | /* |
857 | * find a driver for a subchannel. They identify by the subchannel | |
858 | * type with the exception that the console subchannel driver has its own | |
859 | * subchannel type although the device is an i/o subchannel | |
860 | */ | |
861 | static int | |
862 | css_bus_match (struct device *dev, struct device_driver *drv) | |
863 | { | |
084325d8 CH |
864 | struct subchannel *sch = to_subchannel(dev); |
865 | struct css_driver *driver = to_cssdriver(drv); | |
1da177e4 LT |
866 | |
867 | if (sch->st == driver->subchannel_type) | |
868 | return 1; | |
869 | ||
870 | return 0; | |
871 | } | |
872 | ||
98c13c28 | 873 | static int css_probe(struct device *dev) |
8bbace7e CH |
874 | { |
875 | struct subchannel *sch; | |
98c13c28 | 876 | int ret; |
8bbace7e CH |
877 | |
878 | sch = to_subchannel(dev); | |
084325d8 | 879 | sch->driver = to_cssdriver(dev->driver); |
98c13c28 CH |
880 | ret = sch->driver->probe ? sch->driver->probe(sch) : 0; |
881 | if (ret) | |
882 | sch->driver = NULL; | |
883 | return ret; | |
8bbace7e CH |
884 | } |
885 | ||
98c13c28 | 886 | static int css_remove(struct device *dev) |
8bbace7e CH |
887 | { |
888 | struct subchannel *sch; | |
98c13c28 | 889 | int ret; |
8bbace7e CH |
890 | |
891 | sch = to_subchannel(dev); | |
98c13c28 CH |
892 | ret = sch->driver->remove ? sch->driver->remove(sch) : 0; |
893 | sch->driver = NULL; | |
894 | return ret; | |
8bbace7e CH |
895 | } |
896 | ||
98c13c28 | 897 | static void css_shutdown(struct device *dev) |
8bbace7e CH |
898 | { |
899 | struct subchannel *sch; | |
900 | ||
901 | sch = to_subchannel(dev); | |
98c13c28 | 902 | if (sch->driver && sch->driver->shutdown) |
8bbace7e CH |
903 | sch->driver->shutdown(sch); |
904 | } | |
905 | ||
7e9db9ea CH |
906 | static int css_uevent(struct device *dev, struct kobj_uevent_env *env) |
907 | { | |
908 | struct subchannel *sch = to_subchannel(dev); | |
909 | int ret; | |
910 | ||
911 | ret = add_uevent_var(env, "ST=%01X", sch->st); | |
912 | if (ret) | |
913 | return ret; | |
914 | ret = add_uevent_var(env, "MODALIAS=css:t%01X", sch->st); | |
915 | return ret; | |
916 | } | |
917 | ||
1da177e4 | 918 | struct bus_type css_bus_type = { |
8bbace7e CH |
919 | .name = "css", |
920 | .match = css_bus_match, | |
921 | .probe = css_probe, | |
922 | .remove = css_remove, | |
923 | .shutdown = css_shutdown, | |
7e9db9ea | 924 | .uevent = css_uevent, |
1da177e4 LT |
925 | }; |
926 | ||
25b7bb58 CH |
927 | /** |
928 | * css_driver_register - register a css driver | |
929 | * @cdrv: css driver to register | |
930 | * | |
931 | * This is mainly a wrapper around driver_register that sets name | |
932 | * and bus_type in the embedded struct device_driver correctly. | |
933 | */ | |
934 | int css_driver_register(struct css_driver *cdrv) | |
935 | { | |
936 | cdrv->drv.name = cdrv->name; | |
937 | cdrv->drv.bus = &css_bus_type; | |
4beee646 | 938 | cdrv->drv.owner = cdrv->owner; |
25b7bb58 CH |
939 | return driver_register(&cdrv->drv); |
940 | } | |
941 | EXPORT_SYMBOL_GPL(css_driver_register); | |
942 | ||
943 | /** | |
944 | * css_driver_unregister - unregister a css driver | |
945 | * @cdrv: css driver to unregister | |
946 | * | |
947 | * This is a wrapper around driver_unregister. | |
948 | */ | |
949 | void css_driver_unregister(struct css_driver *cdrv) | |
950 | { | |
951 | driver_unregister(&cdrv->drv); | |
952 | } | |
953 | EXPORT_SYMBOL_GPL(css_driver_unregister); | |
954 | ||
1da177e4 LT |
955 | subsys_initcall(init_channel_subsystem); |
956 | ||
1da177e4 LT |
957 | MODULE_LICENSE("GPL"); |
958 | EXPORT_SYMBOL(css_bus_type); | |
1da177e4 | 959 | EXPORT_SYMBOL_GPL(css_characteristics_avail); |