[S390] Fix IRQ tracing.
[linux-2.6-block.git] / drivers / s390 / cio / css.c
CommitLineData
1da177e4
LT
1/*
2 * drivers/s390/cio/css.c
3 * driver for channel subsystem
1da177e4
LT
4 *
5 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
6 * IBM Corporation
7 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
4ce3b30c 8 * Cornelia Huck (cornelia.huck@de.ibm.com)
1da177e4
LT
9 */
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/device.h>
13#include <linux/slab.h>
14#include <linux/errno.h>
15#include <linux/list.h>
16
17#include "css.h"
18#include "cio.h"
19#include "cio_debug.h"
20#include "ioasm.h"
21#include "chsc.h"
40154b82 22#include "device.h"
83b3370c 23#include "idset.h"
7ad6a249 24#include "chp.h"
1da177e4 25
1da177e4 26int css_init_done = 0;
40154b82 27static int need_reprobe = 0;
fb6958a5 28static int max_ssid = 0;
1da177e4 29
a28c6944 30struct channel_subsystem *css[__MAX_CSSID + 1];
1da177e4 31
a28c6944 32int css_characteristics_avail = 0;
1da177e4 33
4d284cac 34int
f97a56fb
CH
35for_each_subchannel(int(*fn)(struct subchannel_id, void *), void *data)
36{
37 struct subchannel_id schid;
38 int ret;
39
40 init_subchannel_id(&schid);
41 ret = -ENODEV;
42 do {
fb6958a5
CH
43 do {
44 ret = fn(schid, data);
45 if (ret)
46 break;
47 } while (schid.sch_no++ < __MAX_SUBCHANNEL);
48 schid.sch_no = 0;
49 } while (schid.ssid++ < max_ssid);
f97a56fb
CH
50 return ret;
51}
52
1da177e4 53static struct subchannel *
a8237fc4 54css_alloc_subchannel(struct subchannel_id schid)
1da177e4
LT
55{
56 struct subchannel *sch;
57 int ret;
58
59 sch = kmalloc (sizeof (*sch), GFP_KERNEL | GFP_DMA);
60 if (sch == NULL)
61 return ERR_PTR(-ENOMEM);
a8237fc4 62 ret = cio_validate_subchannel (sch, schid);
1da177e4
LT
63 if (ret < 0) {
64 kfree(sch);
65 return ERR_PTR(ret);
66 }
1da177e4
LT
67
68 if (sch->st != SUBCHANNEL_TYPE_IO) {
69 /* For now we ignore all non-io subchannels. */
70 kfree(sch);
71 return ERR_PTR(-EINVAL);
72 }
73
74 /*
75 * Set intparm to subchannel address.
76 * This is fine even on 64bit since the subchannel is always located
77 * under 2G.
78 */
79 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
80 ret = cio_modify(sch);
81 if (ret) {
82 kfree(sch);
83 return ERR_PTR(ret);
84 }
85 return sch;
86}
87
88static void
89css_free_subchannel(struct subchannel *sch)
90{
91 if (sch) {
92 /* Reset intparm to zeroes. */
93 sch->schib.pmcw.intparm = 0;
94 cio_modify(sch);
2ec22984 95 kfree(sch->lock);
1da177e4
LT
96 kfree(sch);
97 }
1da177e4
LT
98}
99
100static void
101css_subchannel_release(struct device *dev)
102{
103 struct subchannel *sch;
104
105 sch = to_subchannel(dev);
2ec22984
CH
106 if (!cio_is_console(sch->schid)) {
107 kfree(sch->lock);
1da177e4 108 kfree(sch);
2ec22984 109 }
1da177e4
LT
110}
111
07c6a338 112static int css_sch_device_register(struct subchannel *sch)
6ab4879a
CH
113{
114 int ret;
115
116 mutex_lock(&sch->reg_mutex);
117 ret = device_register(&sch->dev);
118 mutex_unlock(&sch->reg_mutex);
119 return ret;
120}
121
122void css_sch_device_unregister(struct subchannel *sch)
123{
124 mutex_lock(&sch->reg_mutex);
125 device_unregister(&sch->dev);
126 mutex_unlock(&sch->reg_mutex);
127}
128
7ad6a249
PO
129static void ssd_from_pmcw(struct chsc_ssd_info *ssd, struct pmcw *pmcw)
130{
131 int i;
132 int mask;
133
134 memset(ssd, 0, sizeof(struct chsc_ssd_info));
135 ssd->path_mask = pmcw->pim;
136 for (i = 0; i < 8; i++) {
137 mask = 0x80 >> i;
138 if (pmcw->pim & mask) {
139 chp_id_init(&ssd->chpid[i]);
140 ssd->chpid[i].id = pmcw->chpid[i];
141 }
142 }
143}
144
145static void ssd_register_chpids(struct chsc_ssd_info *ssd)
146{
147 int i;
148 int mask;
149
150 for (i = 0; i < 8; i++) {
151 mask = 0x80 >> i;
152 if (ssd->path_mask & mask)
153 if (!chp_is_registered(ssd->chpid[i]))
154 chp_new(ssd->chpid[i]);
155 }
156}
157
158void css_update_ssd_info(struct subchannel *sch)
159{
160 int ret;
161
162 if (cio_is_console(sch->schid)) {
163 /* Console is initialized too early for functions requiring
164 * memory allocation. */
165 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
166 } else {
167 ret = chsc_get_ssd_info(sch->schid, &sch->ssd_info);
168 if (ret)
169 ssd_from_pmcw(&sch->ssd_info, &sch->schib.pmcw);
170 ssd_register_chpids(&sch->ssd_info);
171 }
172}
173
174static int css_register_subchannel(struct subchannel *sch)
1da177e4
LT
175{
176 int ret;
177
178 /* Initialize the subchannel structure */
a28c6944 179 sch->dev.parent = &css[0]->device;
1da177e4
LT
180 sch->dev.bus = &css_bus_type;
181 sch->dev.release = &css_subchannel_release;
529192f3 182 sch->dev.groups = subch_attr_groups;
7ad6a249 183 css_update_ssd_info(sch);
1da177e4 184 /* make it known to the system */
6ab4879a 185 ret = css_sch_device_register(sch);
7674da77 186 if (ret) {
1da177e4
LT
187 printk (KERN_WARNING "%s: could not register %s\n",
188 __func__, sch->dev.bus_id);
7674da77
CH
189 return ret;
190 }
1da177e4
LT
191 return ret;
192}
193
f7e5d67c 194static int css_probe_device(struct subchannel_id schid)
1da177e4
LT
195{
196 int ret;
197 struct subchannel *sch;
198
a8237fc4 199 sch = css_alloc_subchannel(schid);
1da177e4
LT
200 if (IS_ERR(sch))
201 return PTR_ERR(sch);
202 ret = css_register_subchannel(sch);
203 if (ret)
204 css_free_subchannel(sch);
205 return ret;
206}
207
b0744bd2
CH
208static int
209check_subchannel(struct device * dev, void * data)
210{
211 struct subchannel *sch;
a8237fc4 212 struct subchannel_id *schid = data;
b0744bd2
CH
213
214 sch = to_subchannel(dev);
a8237fc4 215 return schid_equal(&sch->schid, schid);
b0744bd2
CH
216}
217
1da177e4 218struct subchannel *
a8237fc4 219get_subchannel_by_schid(struct subchannel_id schid)
1da177e4 220{
1da177e4
LT
221 struct device *dev;
222
b0744bd2 223 dev = bus_find_device(&css_bus_type, NULL,
12975aef 224 &schid, check_subchannel);
1da177e4 225
b0744bd2 226 return dev ? to_subchannel(dev) : NULL;
1da177e4
LT
227}
228
4d284cac 229static int css_get_subchannel_status(struct subchannel *sch)
1da177e4
LT
230{
231 struct schib schib;
1da177e4 232
564337f3 233 if (stsch(sch->schid, &schib) || !schib.pmcw.dnv)
1da177e4 234 return CIO_GONE;
564337f3 235 if (sch->schib.pmcw.dnv && (schib.pmcw.dev != sch->schib.pmcw.dev))
1da177e4 236 return CIO_REVALIDATE;
564337f3 237 if (!sch->lpm)
1da177e4
LT
238 return CIO_NO_PATH;
239 return CIO_OPER;
240}
564337f3
PO
241
242static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
1da177e4
LT
243{
244 int event, ret, disc;
1da177e4 245 unsigned long flags;
564337f3 246 enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
1da177e4 247
2ec22984 248 spin_lock_irqsave(sch->lock, flags);
564337f3 249 disc = device_is_disconnected(sch);
1da177e4 250 if (disc && slow) {
564337f3 251 /* Disconnected devices are evaluated directly only.*/
2ec22984 252 spin_unlock_irqrestore(sch->lock, flags);
564337f3 253 return 0;
1da177e4 254 }
564337f3
PO
255 /* No interrupt after machine check - kill pending timers. */
256 device_kill_pending_timer(sch);
1da177e4 257 if (!disc && !slow) {
564337f3 258 /* Non-disconnected devices are evaluated on the slow path. */
2ec22984 259 spin_unlock_irqrestore(sch->lock, flags);
564337f3 260 return -EAGAIN;
1da177e4 261 }
564337f3 262 event = css_get_subchannel_status(sch);
fb6958a5 263 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, %s, %s path.\n",
564337f3
PO
264 sch->schid.ssid, sch->schid.sch_no, event,
265 disc ? "disconnected" : "normal",
266 slow ? "slow" : "fast");
267 /* Analyze subchannel status. */
268 action = NONE;
1da177e4
LT
269 switch (event) {
270 case CIO_NO_PATH:
564337f3
PO
271 if (disc) {
272 /* Check if paths have become available. */
273 action = REPROBE;
1da177e4
LT
274 break;
275 }
564337f3
PO
276 /* fall through */
277 case CIO_GONE:
278 /* Prevent unwanted effects when opening lock. */
279 cio_disable_subchannel(sch);
280 device_set_disconnected(sch);
281 /* Ask driver what to do with device. */
282 action = UNREGISTER;
283 if (sch->driver && sch->driver->notify) {
2ec22984 284 spin_unlock_irqrestore(sch->lock, flags);
564337f3 285 ret = sch->driver->notify(&sch->dev, event);
2ec22984 286 spin_lock_irqsave(sch->lock, flags);
564337f3
PO
287 if (ret)
288 action = NONE;
1da177e4 289 }
1da177e4
LT
290 break;
291 case CIO_REVALIDATE:
564337f3
PO
292 /* Device will be removed, so no notify necessary. */
293 if (disc)
294 /* Reprobe because immediate unregister might block. */
295 action = REPROBE;
296 else
297 action = UNREGISTER_PROBE;
1da177e4
LT
298 break;
299 case CIO_OPER:
564337f3 300 if (disc)
1da177e4 301 /* Get device operational again. */
564337f3
PO
302 action = REPROBE;
303 break;
304 }
305 /* Perform action. */
306 ret = 0;
307 switch (action) {
308 case UNREGISTER:
309 case UNREGISTER_PROBE:
310 /* Unregister device (will use subchannel lock). */
2ec22984 311 spin_unlock_irqrestore(sch->lock, flags);
564337f3 312 css_sch_device_unregister(sch);
2ec22984 313 spin_lock_irqsave(sch->lock, flags);
564337f3
PO
314
315 /* Reset intparm to zeroes. */
316 sch->schib.pmcw.intparm = 0;
317 cio_modify(sch);
564337f3
PO
318 break;
319 case REPROBE:
320 device_trigger_reprobe(sch);
1da177e4
LT
321 break;
322 default:
564337f3
PO
323 break;
324 }
2ec22984 325 spin_unlock_irqrestore(sch->lock, flags);
c2b1449b
CH
326 /* Probe if necessary. */
327 if (action == UNREGISTER_PROBE)
328 ret = css_probe_device(sch->schid);
564337f3
PO
329
330 return ret;
331}
332
333static int css_evaluate_new_subchannel(struct subchannel_id schid, int slow)
334{
335 struct schib schib;
336
337 if (!slow) {
338 /* Will be done on the slow path. */
339 return -EAGAIN;
340 }
758976f9 341 if (stsch_err(schid, &schib) || !schib.pmcw.dnv) {
564337f3
PO
342 /* Unusable - ignore. */
343 return 0;
1da177e4 344 }
564337f3
PO
345 CIO_MSG_EVENT(4, "Evaluating schid 0.%x.%04x, event %d, unknown, "
346 "slow path.\n", schid.ssid, schid.sch_no, CIO_OPER);
347
348 return css_probe_device(schid);
349}
350
83b3370c 351static void css_evaluate_subchannel(struct subchannel_id schid, int slow)
564337f3
PO
352{
353 struct subchannel *sch;
354 int ret;
355
356 sch = get_subchannel_by_schid(schid);
357 if (sch) {
358 ret = css_evaluate_known_subchannel(sch, slow);
359 put_device(&sch->dev);
360 } else
361 ret = css_evaluate_new_subchannel(schid, slow);
83b3370c
PO
362 if (ret == -EAGAIN)
363 css_schedule_eval(schid);
1da177e4
LT
364}
365
83b3370c
PO
366static struct idset *slow_subchannel_set;
367static spinlock_t slow_subchannel_lock;
368
369static int __init slow_subchannel_init(void)
1da177e4 370{
83b3370c
PO
371 spin_lock_init(&slow_subchannel_lock);
372 slow_subchannel_set = idset_sch_new();
373 if (!slow_subchannel_set) {
374 printk(KERN_WARNING "cio: could not allocate slow subchannel "
375 "set\n");
376 return -ENOMEM;
377 }
378 return 0;
1da177e4
LT
379}
380
83b3370c 381subsys_initcall(slow_subchannel_init);
1da177e4 382
83b3370c 383static void css_slow_path_func(struct work_struct *unused)
1da177e4 384{
83b3370c 385 struct subchannel_id schid;
1da177e4 386
83b3370c 387 CIO_TRACE_EVENT(4, "slowpath");
1da177e4 388 spin_lock_irq(&slow_subchannel_lock);
83b3370c
PO
389 init_subchannel_id(&schid);
390 while (idset_sch_get_first(slow_subchannel_set, &schid)) {
391 idset_sch_del(slow_subchannel_set, schid);
1da177e4 392 spin_unlock_irq(&slow_subchannel_lock);
83b3370c 393 css_evaluate_subchannel(schid, 1);
1da177e4 394 spin_lock_irq(&slow_subchannel_lock);
1da177e4
LT
395 }
396 spin_unlock_irq(&slow_subchannel_lock);
397}
398
83b3370c 399static DECLARE_WORK(slow_path_work, css_slow_path_func);
1da177e4
LT
400struct workqueue_struct *slow_path_wq;
401
83b3370c
PO
402void css_schedule_eval(struct subchannel_id schid)
403{
404 unsigned long flags;
405
406 spin_lock_irqsave(&slow_subchannel_lock, flags);
407 idset_sch_add(slow_subchannel_set, schid);
408 queue_work(slow_path_wq, &slow_path_work);
409 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
410}
411
412void css_schedule_eval_all(void)
413{
414 unsigned long flags;
415
416 spin_lock_irqsave(&slow_subchannel_lock, flags);
417 idset_fill(slow_subchannel_set);
418 queue_work(slow_path_wq, &slow_path_work);
419 spin_unlock_irqrestore(&slow_subchannel_lock, flags);
420}
421
40154b82
PO
422/* Reprobe subchannel if unregistered. */
423static int reprobe_subchannel(struct subchannel_id schid, void *data)
424{
425 struct subchannel *sch;
426 int ret;
427
428 CIO_DEBUG(KERN_INFO, 6, "cio: reprobe 0.%x.%04x\n",
429 schid.ssid, schid.sch_no);
430 if (need_reprobe)
431 return -EAGAIN;
432
433 sch = get_subchannel_by_schid(schid);
434 if (sch) {
435 /* Already known. */
436 put_device(&sch->dev);
437 return 0;
438 }
439
440 ret = css_probe_device(schid);
441 switch (ret) {
442 case 0:
443 break;
444 case -ENXIO:
445 case -ENOMEM:
446 /* These should abort looping */
447 break;
448 default:
449 ret = 0;
450 }
451
452 return ret;
453}
454
455/* Work function used to reprobe all unregistered subchannels. */
4927b3f7 456static void reprobe_all(struct work_struct *unused)
40154b82
PO
457{
458 int ret;
459
460 CIO_MSG_EVENT(2, "reprobe start\n");
461
462 need_reprobe = 0;
463 /* Make sure initial subchannel scan is done. */
464 wait_event(ccw_device_init_wq,
465 atomic_read(&ccw_device_init_count) == 0);
466 ret = for_each_subchannel(reprobe_subchannel, NULL);
467
468 CIO_MSG_EVENT(2, "reprobe done (rc=%d, need_reprobe=%d)\n", ret,
469 need_reprobe);
470}
471
2b67fc46 472static DECLARE_WORK(css_reprobe_work, reprobe_all);
40154b82
PO
473
474/* Schedule reprobing of all unregistered subchannels. */
475void css_schedule_reprobe(void)
476{
477 need_reprobe = 1;
478 queue_work(ccw_device_work, &css_reprobe_work);
479}
480
481EXPORT_SYMBOL_GPL(css_schedule_reprobe);
482
1da177e4
LT
483/*
484 * Called from the machine check handler for subchannel report words.
485 */
83b3370c 486void css_process_crw(int rsid1, int rsid2)
1da177e4 487{
a8237fc4 488 struct subchannel_id mchk_schid;
1da177e4 489
fb6958a5
CH
490 CIO_CRW_EVENT(2, "source is subchannel %04X, subsystem id %x\n",
491 rsid1, rsid2);
a8237fc4 492 init_subchannel_id(&mchk_schid);
fb6958a5
CH
493 mchk_schid.sch_no = rsid1;
494 if (rsid2 != 0)
495 mchk_schid.ssid = (rsid2 >> 8) & 3;
496
1da177e4
LT
497 /*
498 * Since we are always presented with IPI in the CRW, we have to
499 * use stsch() to find out if the subchannel in question has come
500 * or gone.
501 */
83b3370c 502 css_evaluate_subchannel(mchk_schid, 0);
1da177e4
LT
503}
504
f97a56fb
CH
505static int __init
506__init_channel_subsystem(struct subchannel_id schid, void *data)
507{
508 struct subchannel *sch;
509 int ret;
510
511 if (cio_is_console(schid))
512 sch = cio_get_console_subchannel();
513 else {
514 sch = css_alloc_subchannel(schid);
515 if (IS_ERR(sch))
516 ret = PTR_ERR(sch);
517 else
518 ret = 0;
519 switch (ret) {
520 case 0:
521 break;
522 case -ENOMEM:
523 panic("Out of memory in init_channel_subsystem\n");
524 /* -ENXIO: no more subchannels. */
525 case -ENXIO:
526 return ret;
e843e280
GS
527 /* -EIO: this subchannel set not supported. */
528 case -EIO:
529 return ret;
f97a56fb
CH
530 default:
531 return 0;
532 }
533 }
534 /*
535 * We register ALL valid subchannels in ioinfo, even those
536 * that have been present before init_channel_subsystem.
537 * These subchannels can't have been registered yet (kmalloc
538 * not working) so we do it now. This is true e.g. for the
539 * console subchannel.
540 */
541 css_register_subchannel(sch);
542 return 0;
543}
544
1da177e4 545static void __init
a28c6944 546css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
1da177e4 547{
a28c6944
CH
548 if (css_characteristics_avail && css_general_characteristics.mcss) {
549 css->global_pgid.pgid_high.ext_cssid.version = 0x80;
550 css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
551 } else {
1da177e4 552#ifdef CONFIG_SMP
a28c6944 553 css->global_pgid.pgid_high.cpu_addr = hard_smp_processor_id();
1da177e4 554#else
a28c6944 555 css->global_pgid.pgid_high.cpu_addr = 0;
1da177e4
LT
556#endif
557 }
a28c6944
CH
558 css->global_pgid.cpu_id = ((cpuid_t *) __LC_CPUID)->ident;
559 css->global_pgid.cpu_model = ((cpuid_t *) __LC_CPUID)->machine;
560 css->global_pgid.tod_high = tod_high;
561
562}
563
3b793060
CH
564static void
565channel_subsystem_release(struct device *dev)
566{
567 struct channel_subsystem *css;
568
569 css = to_css(dev);
495a5b45 570 mutex_destroy(&css->mutex);
3b793060
CH
571 kfree(css);
572}
573
495a5b45
CH
574static ssize_t
575css_cm_enable_show(struct device *dev, struct device_attribute *attr,
576 char *buf)
577{
578 struct channel_subsystem *css = to_css(dev);
579
580 if (!css)
581 return 0;
582 return sprintf(buf, "%x\n", css->cm_enabled);
583}
584
585static ssize_t
586css_cm_enable_store(struct device *dev, struct device_attribute *attr,
587 const char *buf, size_t count)
588{
589 struct channel_subsystem *css = to_css(dev);
590 int ret;
591
592 switch (buf[0]) {
593 case '0':
594 ret = css->cm_enabled ? chsc_secm(css, 0) : 0;
595 break;
596 case '1':
597 ret = css->cm_enabled ? 0 : chsc_secm(css, 1);
598 break;
599 default:
600 ret = -EINVAL;
601 }
602 return ret < 0 ? ret : count;
603}
604
605static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
606
4d284cac 607static int __init setup_css(int nr)
a28c6944
CH
608{
609 u32 tod_high;
d7b5a4c9 610 int ret;
a28c6944
CH
611
612 memset(css[nr], 0, sizeof(struct channel_subsystem));
d7b5a4c9
CH
613 css[nr]->pseudo_subchannel =
614 kzalloc(sizeof(*css[nr]->pseudo_subchannel), GFP_KERNEL);
615 if (!css[nr]->pseudo_subchannel)
616 return -ENOMEM;
617 css[nr]->pseudo_subchannel->dev.parent = &css[nr]->device;
618 css[nr]->pseudo_subchannel->dev.release = css_subchannel_release;
619 sprintf(css[nr]->pseudo_subchannel->dev.bus_id, "defunct");
620 ret = cio_create_sch_lock(css[nr]->pseudo_subchannel);
621 if (ret) {
622 kfree(css[nr]->pseudo_subchannel);
623 return ret;
624 }
495a5b45 625 mutex_init(&css[nr]->mutex);
a28c6944
CH
626 css[nr]->valid = 1;
627 css[nr]->cssid = nr;
628 sprintf(css[nr]->device.bus_id, "css%x", nr);
3b793060 629 css[nr]->device.release = channel_subsystem_release;
a28c6944
CH
630 tod_high = (u32) (get_clock() >> 32);
631 css_generate_pgid(css[nr], tod_high);
d7b5a4c9 632 return 0;
1da177e4
LT
633}
634
635/*
636 * Now that the driver core is running, we can setup our channel subsystem.
637 * The struct subchannel's are created during probing (except for the
638 * static console subchannel).
639 */
640static int __init
641init_channel_subsystem (void)
642{
a28c6944 643 int ret, i;
1da177e4
LT
644
645 if (chsc_determine_css_characteristics() == 0)
646 css_characteristics_avail = 1;
647
1da177e4
LT
648 if ((ret = bus_register(&css_bus_type)))
649 goto out;
1da177e4 650
fb6958a5
CH
651 /* Try to enable MSS. */
652 ret = chsc_enable_facility(CHSC_SDA_OC_MSS);
653 switch (ret) {
654 case 0: /* Success. */
655 max_ssid = __MAX_SSID;
656 break;
657 case -ENOMEM:
658 goto out_bus;
659 default:
660 max_ssid = 0;
661 }
a28c6944
CH
662 /* Setup css structure. */
663 for (i = 0; i <= __MAX_CSSID; i++) {
664 css[i] = kmalloc(sizeof(struct channel_subsystem), GFP_KERNEL);
665 if (!css[i]) {
666 ret = -ENOMEM;
fb6958a5 667 goto out_unregister;
a28c6944 668 }
d7b5a4c9 669 ret = setup_css(i);
a28c6944
CH
670 if (ret)
671 goto out_free;
d7b5a4c9
CH
672 ret = device_register(&css[i]->device);
673 if (ret)
674 goto out_free_all;
7e560814
CH
675 if (css_characteristics_avail &&
676 css_chsc_characteristics.secm) {
677 ret = device_create_file(&css[i]->device,
678 &dev_attr_cm_enable);
679 if (ret)
680 goto out_device;
681 }
d7b5a4c9
CH
682 ret = device_register(&css[i]->pseudo_subchannel->dev);
683 if (ret)
684 goto out_file;
a28c6944 685 }
1da177e4
LT
686 css_init_done = 1;
687
688 ctl_set_bit(6, 28);
689
f97a56fb 690 for_each_subchannel(__init_channel_subsystem, NULL);
1da177e4 691 return 0;
d7b5a4c9
CH
692out_file:
693 device_remove_file(&css[i]->device, &dev_attr_cm_enable);
7e560814
CH
694out_device:
695 device_unregister(&css[i]->device);
d7b5a4c9
CH
696out_free_all:
697 kfree(css[i]->pseudo_subchannel->lock);
698 kfree(css[i]->pseudo_subchannel);
a28c6944
CH
699out_free:
700 kfree(css[i]);
fb6958a5 701out_unregister:
a28c6944
CH
702 while (i > 0) {
703 i--;
d7b5a4c9 704 device_unregister(&css[i]->pseudo_subchannel->dev);
495a5b45
CH
705 if (css_characteristics_avail && css_chsc_characteristics.secm)
706 device_remove_file(&css[i]->device,
707 &dev_attr_cm_enable);
a28c6944
CH
708 device_unregister(&css[i]->device);
709 }
fb6958a5 710out_bus:
1da177e4
LT
711 bus_unregister(&css_bus_type);
712out:
713 return ret;
714}
715
d7b5a4c9
CH
716int sch_is_pseudo_sch(struct subchannel *sch)
717{
718 return sch == to_css(sch->dev.parent)->pseudo_subchannel;
719}
720
1da177e4
LT
721/*
722 * find a driver for a subchannel. They identify by the subchannel
723 * type with the exception that the console subchannel driver has its own
724 * subchannel type although the device is an i/o subchannel
725 */
726static int
727css_bus_match (struct device *dev, struct device_driver *drv)
728{
729 struct subchannel *sch = container_of (dev, struct subchannel, dev);
730 struct css_driver *driver = container_of (drv, struct css_driver, drv);
731
732 if (sch->st == driver->subchannel_type)
733 return 1;
734
735 return 0;
736}
737
8bbace7e
CH
738static int
739css_probe (struct device *dev)
740{
741 struct subchannel *sch;
742
743 sch = to_subchannel(dev);
744 sch->driver = container_of (dev->driver, struct css_driver, drv);
745 return (sch->driver->probe ? sch->driver->probe(sch) : 0);
746}
747
748static int
749css_remove (struct device *dev)
750{
751 struct subchannel *sch;
752
753 sch = to_subchannel(dev);
754 return (sch->driver->remove ? sch->driver->remove(sch) : 0);
755}
756
757static void
758css_shutdown (struct device *dev)
759{
760 struct subchannel *sch;
761
762 sch = to_subchannel(dev);
763 if (sch->driver->shutdown)
764 sch->driver->shutdown(sch);
765}
766
1da177e4 767struct bus_type css_bus_type = {
8bbace7e
CH
768 .name = "css",
769 .match = css_bus_match,
770 .probe = css_probe,
771 .remove = css_remove,
772 .shutdown = css_shutdown,
1da177e4
LT
773};
774
775subsys_initcall(init_channel_subsystem);
776
1da177e4
LT
777MODULE_LICENSE("GPL");
778EXPORT_SYMBOL(css_bus_type);
1da177e4 779EXPORT_SYMBOL_GPL(css_characteristics_avail);