]> err.no Git - linux-2.6/blob - drivers/s390/cio/device.c
[S390] cio: Dont call css_update_ssd_info from interrupt context.
[linux-2.6] / drivers / s390 / cio / device.c
1 /*
2  *  drivers/s390/cio/device.c
3  *  bus driver for ccw devices
4  *
5  *    Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
6  *                       IBM Corporation
7  *    Author(s): Arnd Bergmann (arndb@de.ibm.com)
8  *               Cornelia Huck (cornelia.huck@de.ibm.com)
9  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
10  */
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/spinlock.h>
14 #include <linux/errno.h>
15 #include <linux/err.h>
16 #include <linux/slab.h>
17 #include <linux/list.h>
18 #include <linux/device.h>
19 #include <linux/workqueue.h>
20
21 #include <asm/ccwdev.h>
22 #include <asm/cio.h>
23 #include <asm/param.h>          /* HZ */
24
25 #include "cio.h"
26 #include "cio_debug.h"
27 #include "css.h"
28 #include "device.h"
29 #include "ioasm.h"
30
31 /******************* bus type handling ***********************/
32
33 /* The Linux driver model distinguishes between a bus type and
34  * the bus itself. Of course we only have one channel
35  * subsystem driver and one channel system per machine, but
36  * we still use the abstraction. T.R. says it's a good idea. */
37 static int
38 ccw_bus_match (struct device * dev, struct device_driver * drv)
39 {
40         struct ccw_device *cdev = to_ccwdev(dev);
41         struct ccw_driver *cdrv = to_ccwdrv(drv);
42         const struct ccw_device_id *ids = cdrv->ids, *found;
43
44         if (!ids)
45                 return 0;
46
47         found = ccw_device_id_match(ids, &cdev->id);
48         if (!found)
49                 return 0;
50
51         cdev->id.driver_info = found->driver_info;
52
53         return 1;
54 }
55
56 /* Store modalias string delimited by prefix/suffix string into buffer with
57  * specified size. Return length of resulting string (excluding trailing '\0')
58  * even if string doesn't fit buffer (snprintf semantics). */
59 static int snprint_alias(char *buf, size_t size,
60                          struct ccw_device_id *id, const char *suffix)
61 {
62         int len;
63
64         len = snprintf(buf, size, "ccw:t%04Xm%02X", id->cu_type, id->cu_model);
65         if (len > size)
66                 return len;
67         buf += len;
68         size -= len;
69
70         if (id->dev_type != 0)
71                 len += snprintf(buf, size, "dt%04Xdm%02X%s", id->dev_type,
72                                 id->dev_model, suffix);
73         else
74                 len += snprintf(buf, size, "dtdm%s", suffix);
75
76         return len;
77 }
78
79 /* Set up environment variables for ccw device uevent. Return 0 on success,
80  * non-zero otherwise. */
81 static int ccw_uevent(struct device *dev, char **envp, int num_envp,
82                       char *buffer, int buffer_size)
83 {
84         struct ccw_device *cdev = to_ccwdev(dev);
85         struct ccw_device_id *id = &(cdev->id);
86         int i = 0;
87         int len = 0;
88         int ret;
89         char modalias_buf[30];
90
91         /* CU_TYPE= */
92         ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
93                              "CU_TYPE=%04X", id->cu_type);
94         if (ret)
95                 return ret;
96
97         /* CU_MODEL= */
98         ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
99                              "CU_MODEL=%02X", id->cu_model);
100         if (ret)
101                 return ret;
102
103         /* The next two can be zero, that's ok for us */
104         /* DEV_TYPE= */
105         ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
106                              "DEV_TYPE=%04X", id->dev_type);
107         if (ret)
108                 return ret;
109
110         /* DEV_MODEL= */
111         ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
112                              "DEV_MODEL=%02X", id->dev_model);
113         if (ret)
114                 return ret;
115
116         /* MODALIAS=  */
117         snprint_alias(modalias_buf, sizeof(modalias_buf), id, "");
118         ret = add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
119                              "MODALIAS=%s", modalias_buf);
120         return ret;
121 }
122
123 struct bus_type ccw_bus_type;
124
125 static int io_subchannel_probe (struct subchannel *);
126 static int io_subchannel_remove (struct subchannel *);
127 static int io_subchannel_notify(struct device *, int);
128 static void io_subchannel_verify(struct device *);
129 static void io_subchannel_ioterm(struct device *);
130 static void io_subchannel_shutdown(struct subchannel *);
131
132 struct css_driver io_subchannel_driver = {
133         .subchannel_type = SUBCHANNEL_TYPE_IO,
134         .drv = {
135                 .name = "io_subchannel",
136                 .bus  = &css_bus_type,
137         },
138         .irq = io_subchannel_irq,
139         .notify = io_subchannel_notify,
140         .verify = io_subchannel_verify,
141         .termination = io_subchannel_ioterm,
142         .probe = io_subchannel_probe,
143         .remove = io_subchannel_remove,
144         .shutdown = io_subchannel_shutdown,
145 };
146
147 struct workqueue_struct *ccw_device_work;
148 struct workqueue_struct *ccw_device_notify_work;
149 wait_queue_head_t ccw_device_init_wq;
150 atomic_t ccw_device_init_count;
151
152 static int __init
153 init_ccw_bus_type (void)
154 {
155         int ret;
156
157         init_waitqueue_head(&ccw_device_init_wq);
158         atomic_set(&ccw_device_init_count, 0);
159
160         ccw_device_work = create_singlethread_workqueue("cio");
161         if (!ccw_device_work)
162                 return -ENOMEM; /* FIXME: better errno ? */
163         ccw_device_notify_work = create_singlethread_workqueue("cio_notify");
164         if (!ccw_device_notify_work) {
165                 ret = -ENOMEM; /* FIXME: better errno ? */
166                 goto out_err;
167         }
168         slow_path_wq = create_singlethread_workqueue("kslowcrw");
169         if (!slow_path_wq) {
170                 ret = -ENOMEM; /* FIXME: better errno ? */
171                 goto out_err;
172         }
173         if ((ret = bus_register (&ccw_bus_type)))
174                 goto out_err;
175
176         if ((ret = driver_register(&io_subchannel_driver.drv)))
177                 goto out_err;
178
179         wait_event(ccw_device_init_wq,
180                    atomic_read(&ccw_device_init_count) == 0);
181         flush_workqueue(ccw_device_work);
182         return 0;
183 out_err:
184         if (ccw_device_work)
185                 destroy_workqueue(ccw_device_work);
186         if (ccw_device_notify_work)
187                 destroy_workqueue(ccw_device_notify_work);
188         if (slow_path_wq)
189                 destroy_workqueue(slow_path_wq);
190         return ret;
191 }
192
193 static void __exit
194 cleanup_ccw_bus_type (void)
195 {
196         driver_unregister(&io_subchannel_driver.drv);
197         bus_unregister(&ccw_bus_type);
198         destroy_workqueue(ccw_device_notify_work);
199         destroy_workqueue(ccw_device_work);
200 }
201
202 subsys_initcall(init_ccw_bus_type);
203 module_exit(cleanup_ccw_bus_type);
204
205 /************************ device handling **************************/
206
207 /*
208  * A ccw_device has some interfaces in sysfs in addition to the
209  * standard ones.
210  * The following entries are designed to export the information which
211  * resided in 2.4 in /proc/subchannels. Subchannel and device number
212  * are obvious, so they don't have an entry :)
213  * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
214  */
215 static ssize_t
216 chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
217 {
218         struct subchannel *sch = to_subchannel(dev);
219         struct chsc_ssd_info *ssd = &sch->ssd_info;
220         ssize_t ret = 0;
221         int chp;
222         int mask;
223
224         for (chp = 0; chp < 8; chp++) {
225                 mask = 0x80 >> chp;
226                 if (ssd->path_mask & mask)
227                         ret += sprintf(buf + ret, "%02x ", ssd->chpid[chp].id);
228                 else
229                         ret += sprintf(buf + ret, "00 ");
230         }
231         ret += sprintf (buf+ret, "\n");
232         return min((ssize_t)PAGE_SIZE, ret);
233 }
234
235 static ssize_t
236 pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
237 {
238         struct subchannel *sch = to_subchannel(dev);
239         struct pmcw *pmcw = &sch->schib.pmcw;
240
241         return sprintf (buf, "%02x %02x %02x\n",
242                         pmcw->pim, pmcw->pam, pmcw->pom);
243 }
244
245 static ssize_t
246 devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
247 {
248         struct ccw_device *cdev = to_ccwdev(dev);
249         struct ccw_device_id *id = &(cdev->id);
250
251         if (id->dev_type != 0)
252                 return sprintf(buf, "%04x/%02x\n",
253                                 id->dev_type, id->dev_model);
254         else
255                 return sprintf(buf, "n/a\n");
256 }
257
258 static ssize_t
259 cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
260 {
261         struct ccw_device *cdev = to_ccwdev(dev);
262         struct ccw_device_id *id = &(cdev->id);
263
264         return sprintf(buf, "%04x/%02x\n",
265                        id->cu_type, id->cu_model);
266 }
267
268 static ssize_t
269 modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
270 {
271         struct ccw_device *cdev = to_ccwdev(dev);
272         struct ccw_device_id *id = &(cdev->id);
273         int len;
274
275         len = snprint_alias(buf, PAGE_SIZE, id, "\n") + 1;
276
277         return len > PAGE_SIZE ? PAGE_SIZE : len;
278 }
279
280 static ssize_t
281 online_show (struct device *dev, struct device_attribute *attr, char *buf)
282 {
283         struct ccw_device *cdev = to_ccwdev(dev);
284
285         return sprintf(buf, cdev->online ? "1\n" : "0\n");
286 }
287
288 int ccw_device_is_orphan(struct ccw_device *cdev)
289 {
290         return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent));
291 }
292
293 static void ccw_device_unregister(struct work_struct *work)
294 {
295         struct ccw_device_private *priv;
296         struct ccw_device *cdev;
297
298         priv = container_of(work, struct ccw_device_private, kick_work);
299         cdev = priv->cdev;
300         if (test_and_clear_bit(1, &cdev->private->registered))
301                 device_unregister(&cdev->dev);
302         put_device(&cdev->dev);
303 }
304
305 static void
306 ccw_device_remove_disconnected(struct ccw_device *cdev)
307 {
308         struct subchannel *sch;
309         unsigned long flags;
310         /*
311          * Forced offline in disconnected state means
312          * 'throw away device'.
313          */
314         if (ccw_device_is_orphan(cdev)) {
315                 /* Deregister ccw device. */
316                 spin_lock_irqsave(cdev->ccwlock, flags);
317                 cdev->private->state = DEV_STATE_NOT_OPER;
318                 spin_unlock_irqrestore(cdev->ccwlock, flags);
319                 if (get_device(&cdev->dev)) {
320                         PREPARE_WORK(&cdev->private->kick_work,
321                                      ccw_device_unregister);
322                         queue_work(ccw_device_work, &cdev->private->kick_work);
323                 }
324                 return ;
325         }
326         sch = to_subchannel(cdev->dev.parent);
327         css_sch_device_unregister(sch);
328         /* Reset intparm to zeroes. */
329         sch->schib.pmcw.intparm = 0;
330         cio_modify(sch);
331         put_device(&sch->dev);
332 }
333
334 int
335 ccw_device_set_offline(struct ccw_device *cdev)
336 {
337         int ret;
338
339         if (!cdev)
340                 return -ENODEV;
341         if (!cdev->online || !cdev->drv)
342                 return -EINVAL;
343
344         if (cdev->drv->set_offline) {
345                 ret = cdev->drv->set_offline(cdev);
346                 if (ret != 0)
347                         return ret;
348         }
349         cdev->online = 0;
350         spin_lock_irq(cdev->ccwlock);
351         ret = ccw_device_offline(cdev);
352         if (ret == -ENODEV) {
353                 if (cdev->private->state != DEV_STATE_NOT_OPER) {
354                         cdev->private->state = DEV_STATE_OFFLINE;
355                         dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
356                 }
357                 spin_unlock_irq(cdev->ccwlock);
358                 return ret;
359         }
360         spin_unlock_irq(cdev->ccwlock);
361         if (ret == 0)
362                 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
363         else {
364                 pr_debug("ccw_device_offline returned %d, device %s\n",
365                          ret, cdev->dev.bus_id);
366                 cdev->online = 1;
367         }
368         return ret;
369 }
370
371 int
372 ccw_device_set_online(struct ccw_device *cdev)
373 {
374         int ret;
375
376         if (!cdev)
377                 return -ENODEV;
378         if (cdev->online || !cdev->drv)
379                 return -EINVAL;
380
381         spin_lock_irq(cdev->ccwlock);
382         ret = ccw_device_online(cdev);
383         spin_unlock_irq(cdev->ccwlock);
384         if (ret == 0)
385                 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
386         else {
387                 pr_debug("ccw_device_online returned %d, device %s\n",
388                          ret, cdev->dev.bus_id);
389                 return ret;
390         }
391         if (cdev->private->state != DEV_STATE_ONLINE)
392                 return -ENODEV;
393         if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
394                 cdev->online = 1;
395                 return 0;
396         }
397         spin_lock_irq(cdev->ccwlock);
398         ret = ccw_device_offline(cdev);
399         spin_unlock_irq(cdev->ccwlock);
400         if (ret == 0)
401                 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
402         else 
403                 pr_debug("ccw_device_offline returned %d, device %s\n",
404                          ret, cdev->dev.bus_id);
405         return (ret == 0) ? -ENODEV : ret;
406 }
407
408 static void online_store_handle_offline(struct ccw_device *cdev)
409 {
410         if (cdev->private->state == DEV_STATE_DISCONNECTED)
411                 ccw_device_remove_disconnected(cdev);
412         else if (cdev->drv && cdev->drv->set_offline)
413                 ccw_device_set_offline(cdev);
414 }
415
416 static int online_store_recog_and_online(struct ccw_device *cdev)
417 {
418         int ret;
419
420         /* Do device recognition, if needed. */
421         if (cdev->id.cu_type == 0) {
422                 ret = ccw_device_recognition(cdev);
423                 if (ret) {
424                         printk(KERN_WARNING"Couldn't start recognition "
425                                "for device %s (ret=%d)\n",
426                                cdev->dev.bus_id, ret);
427                         return ret;
428                 }
429                 wait_event(cdev->private->wait_q,
430                            cdev->private->flags.recog_done);
431         }
432         if (cdev->drv && cdev->drv->set_online)
433                 ccw_device_set_online(cdev);
434         return 0;
435 }
436 static void online_store_handle_online(struct ccw_device *cdev, int force)
437 {
438         int ret;
439
440         ret = online_store_recog_and_online(cdev);
441         if (ret)
442                 return;
443         if (force && cdev->private->state == DEV_STATE_BOXED) {
444                 ret = ccw_device_stlck(cdev);
445                 if (ret) {
446                         printk(KERN_WARNING"ccw_device_stlck for device %s "
447                                "returned %d!\n", cdev->dev.bus_id, ret);
448                         return;
449                 }
450                 if (cdev->id.cu_type == 0)
451                         cdev->private->state = DEV_STATE_NOT_OPER;
452                 online_store_recog_and_online(cdev);
453         }
454
455 }
456
457 static ssize_t online_store (struct device *dev, struct device_attribute *attr,
458                              const char *buf, size_t count)
459 {
460         struct ccw_device *cdev = to_ccwdev(dev);
461         int i, force;
462         char *tmp;
463
464         if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
465                 return -EAGAIN;
466
467         if (cdev->drv && !try_module_get(cdev->drv->owner)) {
468                 atomic_set(&cdev->private->onoff, 0);
469                 return -EINVAL;
470         }
471         if (!strncmp(buf, "force\n", count)) {
472                 force = 1;
473                 i = 1;
474         } else {
475                 force = 0;
476                 i = simple_strtoul(buf, &tmp, 16);
477         }
478
479         switch (i) {
480         case 0:
481                 online_store_handle_offline(cdev);
482                 break;
483         case 1:
484                 online_store_handle_online(cdev, force);
485                 break;
486         default:
487                 count = -EINVAL;
488         }
489         if (cdev->drv)
490                 module_put(cdev->drv->owner);
491         atomic_set(&cdev->private->onoff, 0);
492         return count;
493 }
494
495 static ssize_t
496 available_show (struct device *dev, struct device_attribute *attr, char *buf)
497 {
498         struct ccw_device *cdev = to_ccwdev(dev);
499         struct subchannel *sch;
500
501         if (ccw_device_is_orphan(cdev))
502                 return sprintf(buf, "no device\n");
503         switch (cdev->private->state) {
504         case DEV_STATE_BOXED:
505                 return sprintf(buf, "boxed\n");
506         case DEV_STATE_DISCONNECTED:
507         case DEV_STATE_DISCONNECTED_SENSE_ID:
508         case DEV_STATE_NOT_OPER:
509                 sch = to_subchannel(dev->parent);
510                 if (!sch->lpm)
511                         return sprintf(buf, "no path\n");
512                 else
513                         return sprintf(buf, "no device\n");
514         default:
515                 /* All other states considered fine. */
516                 return sprintf(buf, "good\n");
517         }
518 }
519
520 static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
521 static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
522 static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
523 static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
524 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
525 static DEVICE_ATTR(online, 0644, online_show, online_store);
526 extern struct device_attribute dev_attr_cmb_enable;
527 static DEVICE_ATTR(availability, 0444, available_show, NULL);
528
529 static struct attribute * subch_attrs[] = {
530         &dev_attr_chpids.attr,
531         &dev_attr_pimpampom.attr,
532         NULL,
533 };
534
535 static struct attribute_group subch_attr_group = {
536         .attrs = subch_attrs,
537 };
538
539 struct attribute_group *subch_attr_groups[] = {
540         &subch_attr_group,
541         NULL,
542 };
543
544 static struct attribute * ccwdev_attrs[] = {
545         &dev_attr_devtype.attr,
546         &dev_attr_cutype.attr,
547         &dev_attr_modalias.attr,
548         &dev_attr_online.attr,
549         &dev_attr_cmb_enable.attr,
550         &dev_attr_availability.attr,
551         NULL,
552 };
553
554 static struct attribute_group ccwdev_attr_group = {
555         .attrs = ccwdev_attrs,
556 };
557
558 static int
559 device_add_files (struct device *dev)
560 {
561         return sysfs_create_group(&dev->kobj, &ccwdev_attr_group);
562 }
563
564 static void
565 device_remove_files(struct device *dev)
566 {
567         sysfs_remove_group(&dev->kobj, &ccwdev_attr_group);
568 }
569
570 /* this is a simple abstraction for device_register that sets the
571  * correct bus type and adds the bus specific files */
572 static int ccw_device_register(struct ccw_device *cdev)
573 {
574         struct device *dev = &cdev->dev;
575         int ret;
576
577         dev->bus = &ccw_bus_type;
578
579         if ((ret = device_add(dev)))
580                 return ret;
581
582         set_bit(1, &cdev->private->registered);
583         if ((ret = device_add_files(dev))) {
584                 if (test_and_clear_bit(1, &cdev->private->registered))
585                         device_del(dev);
586         }
587         return ret;
588 }
589
590 struct match_data {
591         struct ccw_dev_id dev_id;
592         struct ccw_device * sibling;
593 };
594
595 static int
596 match_devno(struct device * dev, void * data)
597 {
598         struct match_data * d = data;
599         struct ccw_device * cdev;
600
601         cdev = to_ccwdev(dev);
602         if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
603             !ccw_device_is_orphan(cdev) &&
604             ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) &&
605             (cdev != d->sibling))
606                 return 1;
607         return 0;
608 }
609
610 static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id,
611                                                      struct ccw_device *sibling)
612 {
613         struct device *dev;
614         struct match_data data;
615
616         data.dev_id = *dev_id;
617         data.sibling = sibling;
618         dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno);
619
620         return dev ? to_ccwdev(dev) : NULL;
621 }
622
623 static int match_orphan(struct device *dev, void *data)
624 {
625         struct ccw_dev_id *dev_id;
626         struct ccw_device *cdev;
627
628         dev_id = data;
629         cdev = to_ccwdev(dev);
630         return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
631 }
632
633 static struct ccw_device *
634 get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css,
635                               struct ccw_dev_id *dev_id)
636 {
637         struct device *dev;
638
639         dev = device_find_child(&css->pseudo_subchannel->dev, dev_id,
640                                 match_orphan);
641
642         return dev ? to_ccwdev(dev) : NULL;
643 }
644
645 static void
646 ccw_device_add_changed(struct work_struct *work)
647 {
648         struct ccw_device_private *priv;
649         struct ccw_device *cdev;
650
651         priv = container_of(work, struct ccw_device_private, kick_work);
652         cdev = priv->cdev;
653         if (device_add(&cdev->dev)) {
654                 put_device(&cdev->dev);
655                 return;
656         }
657         set_bit(1, &cdev->private->registered);
658         if (device_add_files(&cdev->dev)) {
659                 if (test_and_clear_bit(1, &cdev->private->registered))
660                         device_unregister(&cdev->dev);
661         }
662 }
663
664 void ccw_device_do_unreg_rereg(struct work_struct *work)
665 {
666         struct ccw_device_private *priv;
667         struct ccw_device *cdev;
668         struct subchannel *sch;
669
670         priv = container_of(work, struct ccw_device_private, kick_work);
671         cdev = priv->cdev;
672         sch = to_subchannel(cdev->dev.parent);
673
674         device_remove_files(&cdev->dev);
675         if (test_and_clear_bit(1, &cdev->private->registered))
676                 device_del(&cdev->dev);
677         PREPARE_WORK(&cdev->private->kick_work,
678                      ccw_device_add_changed);
679         queue_work(ccw_device_work, &cdev->private->kick_work);
680 }
681
682 static void
683 ccw_device_release(struct device *dev)
684 {
685         struct ccw_device *cdev;
686
687         cdev = to_ccwdev(dev);
688         kfree(cdev->private);
689         kfree(cdev);
690 }
691
692 static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
693 {
694         struct ccw_device *cdev;
695
696         cdev  = kzalloc(sizeof(*cdev), GFP_KERNEL);
697         if (cdev) {
698                 cdev->private = kzalloc(sizeof(struct ccw_device_private),
699                                         GFP_KERNEL | GFP_DMA);
700                 if (cdev->private)
701                         return cdev;
702         }
703         kfree(cdev);
704         return ERR_PTR(-ENOMEM);
705 }
706
707 static int io_subchannel_initialize_dev(struct subchannel *sch,
708                                         struct ccw_device *cdev)
709 {
710         cdev->private->cdev = cdev;
711         atomic_set(&cdev->private->onoff, 0);
712         cdev->dev.parent = &sch->dev;
713         cdev->dev.release = ccw_device_release;
714         INIT_LIST_HEAD(&cdev->private->kick_work.entry);
715         /* Do first half of device_register. */
716         device_initialize(&cdev->dev);
717         if (!get_device(&sch->dev)) {
718                 if (cdev->dev.release)
719                         cdev->dev.release(&cdev->dev);
720                 return -ENODEV;
721         }
722         return 0;
723 }
724
725 static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
726 {
727         struct ccw_device *cdev;
728         int ret;
729
730         cdev = io_subchannel_allocate_dev(sch);
731         if (!IS_ERR(cdev)) {
732                 ret = io_subchannel_initialize_dev(sch, cdev);
733                 if (ret) {
734                         kfree(cdev);
735                         cdev = ERR_PTR(ret);
736                 }
737         }
738         return cdev;
739 }
740
741 static int io_subchannel_recog(struct ccw_device *, struct subchannel *);
742
743 static void sch_attach_device(struct subchannel *sch,
744                               struct ccw_device *cdev)
745 {
746         css_update_ssd_info(sch);
747         spin_lock_irq(sch->lock);
748         sch->dev.driver_data = cdev;
749         cdev->private->schid = sch->schid;
750         cdev->ccwlock = sch->lock;
751         device_trigger_reprobe(sch);
752         spin_unlock_irq(sch->lock);
753 }
754
755 static void sch_attach_disconnected_device(struct subchannel *sch,
756                                            struct ccw_device *cdev)
757 {
758         struct subchannel *other_sch;
759         int ret;
760
761         other_sch = to_subchannel(get_device(cdev->dev.parent));
762         ret = device_move(&cdev->dev, &sch->dev);
763         if (ret) {
764                 CIO_MSG_EVENT(2, "Moving disconnected device 0.%x.%04x failed "
765                               "(ret=%d)!\n", cdev->private->dev_id.ssid,
766                               cdev->private->dev_id.devno, ret);
767                 put_device(&other_sch->dev);
768                 return;
769         }
770         other_sch->dev.driver_data = NULL;
771         /* No need to keep a subchannel without ccw device around. */
772         css_sch_device_unregister(other_sch);
773         put_device(&other_sch->dev);
774         sch_attach_device(sch, cdev);
775 }
776
777 static void sch_attach_orphaned_device(struct subchannel *sch,
778                                        struct ccw_device *cdev)
779 {
780         int ret;
781
782         /* Try to move the ccw device to its new subchannel. */
783         ret = device_move(&cdev->dev, &sch->dev);
784         if (ret) {
785                 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage "
786                               "failed (ret=%d)!\n",
787                               cdev->private->dev_id.ssid,
788                               cdev->private->dev_id.devno, ret);
789                 return;
790         }
791         sch_attach_device(sch, cdev);
792 }
793
794 static void sch_create_and_recog_new_device(struct subchannel *sch)
795 {
796         struct ccw_device *cdev;
797
798         /* Need to allocate a new ccw device. */
799         cdev = io_subchannel_create_ccwdev(sch);
800         if (IS_ERR(cdev)) {
801                 /* OK, we did everything we could... */
802                 css_sch_device_unregister(sch);
803                 return;
804         }
805         spin_lock_irq(sch->lock);
806         sch->dev.driver_data = cdev;
807         spin_unlock_irq(sch->lock);
808         /* Start recognition for the new ccw device. */
809         if (io_subchannel_recog(cdev, sch)) {
810                 spin_lock_irq(sch->lock);
811                 sch->dev.driver_data = NULL;
812                 spin_unlock_irq(sch->lock);
813                 if (cdev->dev.release)
814                         cdev->dev.release(&cdev->dev);
815                 css_sch_device_unregister(sch);
816         }
817 }
818
819
820 void ccw_device_move_to_orphanage(struct work_struct *work)
821 {
822         struct ccw_device_private *priv;
823         struct ccw_device *cdev;
824         struct ccw_device *replacing_cdev;
825         struct subchannel *sch;
826         int ret;
827         struct channel_subsystem *css;
828         struct ccw_dev_id dev_id;
829
830         priv = container_of(work, struct ccw_device_private, kick_work);
831         cdev = priv->cdev;
832         sch = to_subchannel(cdev->dev.parent);
833         css = to_css(sch->dev.parent);
834         dev_id.devno = sch->schib.pmcw.dev;
835         dev_id.ssid = sch->schid.ssid;
836
837         /*
838          * Move the orphaned ccw device to the orphanage so the replacing
839          * ccw device can take its place on the subchannel.
840          */
841         ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev);
842         if (ret) {
843                 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed "
844                               "(ret=%d)!\n", cdev->private->dev_id.ssid,
845                               cdev->private->dev_id.devno, ret);
846                 return;
847         }
848         cdev->ccwlock = css->pseudo_subchannel->lock;
849         /*
850          * Search for the replacing ccw device
851          * - among the disconnected devices
852          * - in the orphanage
853          */
854         replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
855         if (replacing_cdev) {
856                 sch_attach_disconnected_device(sch, replacing_cdev);
857                 return;
858         }
859         replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id);
860         if (replacing_cdev) {
861                 sch_attach_orphaned_device(sch, replacing_cdev);
862                 return;
863         }
864         sch_create_and_recog_new_device(sch);
865 }
866
867 /*
868  * Register recognized device.
869  */
870 static void
871 io_subchannel_register(struct work_struct *work)
872 {
873         struct ccw_device_private *priv;
874         struct ccw_device *cdev;
875         struct subchannel *sch;
876         int ret;
877         unsigned long flags;
878
879         priv = container_of(work, struct ccw_device_private, kick_work);
880         cdev = priv->cdev;
881         sch = to_subchannel(cdev->dev.parent);
882         css_update_ssd_info(sch);
883         /*
884          * io_subchannel_register() will also be called after device
885          * recognition has been done for a boxed device (which will already
886          * be registered). We need to reprobe since we may now have sense id
887          * information.
888          */
889         if (klist_node_attached(&cdev->dev.knode_parent)) {
890                 if (!cdev->drv) {
891                         ret = device_reprobe(&cdev->dev);
892                         if (ret)
893                                 /* We can't do much here. */
894                                 dev_info(&cdev->dev, "device_reprobe() returned"
895                                          " %d\n", ret);
896                 }
897                 goto out;
898         }
899         /* make it known to the system */
900         ret = ccw_device_register(cdev);
901         if (ret) {
902                 printk (KERN_WARNING "%s: could not register %s\n",
903                         __func__, cdev->dev.bus_id);
904                 put_device(&cdev->dev);
905                 spin_lock_irqsave(sch->lock, flags);
906                 sch->dev.driver_data = NULL;
907                 spin_unlock_irqrestore(sch->lock, flags);
908                 kfree (cdev->private);
909                 kfree (cdev);
910                 put_device(&sch->dev);
911                 if (atomic_dec_and_test(&ccw_device_init_count))
912                         wake_up(&ccw_device_init_wq);
913                 return;
914         }
915         put_device(&cdev->dev);
916 out:
917         cdev->private->flags.recog_done = 1;
918         put_device(&sch->dev);
919         wake_up(&cdev->private->wait_q);
920         if (atomic_dec_and_test(&ccw_device_init_count))
921                 wake_up(&ccw_device_init_wq);
922 }
923
924 void
925 ccw_device_call_sch_unregister(struct work_struct *work)
926 {
927         struct ccw_device_private *priv;
928         struct ccw_device *cdev;
929         struct subchannel *sch;
930
931         priv = container_of(work, struct ccw_device_private, kick_work);
932         cdev = priv->cdev;
933         sch = to_subchannel(cdev->dev.parent);
934         css_sch_device_unregister(sch);
935         /* Reset intparm to zeroes. */
936         sch->schib.pmcw.intparm = 0;
937         cio_modify(sch);
938         put_device(&cdev->dev);
939         put_device(&sch->dev);
940 }
941
942 /*
943  * subchannel recognition done. Called from the state machine.
944  */
945 void
946 io_subchannel_recog_done(struct ccw_device *cdev)
947 {
948         struct subchannel *sch;
949
950         if (css_init_done == 0) {
951                 cdev->private->flags.recog_done = 1;
952                 return;
953         }
954         switch (cdev->private->state) {
955         case DEV_STATE_NOT_OPER:
956                 cdev->private->flags.recog_done = 1;
957                 /* Remove device found not operational. */
958                 if (!get_device(&cdev->dev))
959                         break;
960                 sch = to_subchannel(cdev->dev.parent);
961                 PREPARE_WORK(&cdev->private->kick_work,
962                              ccw_device_call_sch_unregister);
963                 queue_work(slow_path_wq, &cdev->private->kick_work);
964                 if (atomic_dec_and_test(&ccw_device_init_count))
965                         wake_up(&ccw_device_init_wq);
966                 break;
967         case DEV_STATE_BOXED:
968                 /* Device did not respond in time. */
969         case DEV_STATE_OFFLINE:
970                 /* 
971                  * We can't register the device in interrupt context so
972                  * we schedule a work item.
973                  */
974                 if (!get_device(&cdev->dev))
975                         break;
976                 PREPARE_WORK(&cdev->private->kick_work,
977                              io_subchannel_register);
978                 queue_work(slow_path_wq, &cdev->private->kick_work);
979                 break;
980         }
981 }
982
983 static int
984 io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
985 {
986         int rc;
987         struct ccw_device_private *priv;
988
989         sch->dev.driver_data = cdev;
990         sch->driver = &io_subchannel_driver;
991         cdev->ccwlock = sch->lock;
992
993         /* Init private data. */
994         priv = cdev->private;
995         priv->dev_id.devno = sch->schib.pmcw.dev;
996         priv->dev_id.ssid = sch->schid.ssid;
997         priv->schid = sch->schid;
998         priv->state = DEV_STATE_NOT_OPER;
999         INIT_LIST_HEAD(&priv->cmb_list);
1000         init_waitqueue_head(&priv->wait_q);
1001         init_timer(&priv->timer);
1002
1003         /* Set an initial name for the device. */
1004         snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x",
1005                   sch->schid.ssid, sch->schib.pmcw.dev);
1006
1007         /* Increase counter of devices currently in recognition. */
1008         atomic_inc(&ccw_device_init_count);
1009
1010         /* Start async. device sensing. */
1011         spin_lock_irq(sch->lock);
1012         rc = ccw_device_recognition(cdev);
1013         spin_unlock_irq(sch->lock);
1014         if (rc) {
1015                 if (atomic_dec_and_test(&ccw_device_init_count))
1016                         wake_up(&ccw_device_init_wq);
1017         }
1018         return rc;
1019 }
1020
1021 static void ccw_device_move_to_sch(struct work_struct *work)
1022 {
1023         struct ccw_device_private *priv;
1024         int rc;
1025         struct subchannel *sch;
1026         struct ccw_device *cdev;
1027         struct subchannel *former_parent;
1028
1029         priv = container_of(work, struct ccw_device_private, kick_work);
1030         sch = priv->sch;
1031         cdev = priv->cdev;
1032         former_parent = ccw_device_is_orphan(cdev) ?
1033                 NULL : to_subchannel(get_device(cdev->dev.parent));
1034         mutex_lock(&sch->reg_mutex);
1035         /* Try to move the ccw device to its new subchannel. */
1036         rc = device_move(&cdev->dev, &sch->dev);
1037         mutex_unlock(&sch->reg_mutex);
1038         if (rc) {
1039                 CIO_MSG_EVENT(2, "Moving device 0.%x.%04x to subchannel "
1040                               "0.%x.%04x failed (ret=%d)!\n",
1041                               cdev->private->dev_id.ssid,
1042                               cdev->private->dev_id.devno, sch->schid.ssid,
1043                               sch->schid.sch_no, rc);
1044                 css_sch_device_unregister(sch);
1045                 goto out;
1046         }
1047         if (former_parent) {
1048                 spin_lock_irq(former_parent->lock);
1049                 former_parent->dev.driver_data = NULL;
1050                 spin_unlock_irq(former_parent->lock);
1051                 css_sch_device_unregister(former_parent);
1052                 /* Reset intparm to zeroes. */
1053                 former_parent->schib.pmcw.intparm = 0;
1054                 cio_modify(former_parent);
1055         }
1056         sch_attach_device(sch, cdev);
1057 out:
1058         if (former_parent)
1059                 put_device(&former_parent->dev);
1060         put_device(&cdev->dev);
1061 }
1062
1063 static int
1064 io_subchannel_probe (struct subchannel *sch)
1065 {
1066         struct ccw_device *cdev;
1067         int rc;
1068         unsigned long flags;
1069         struct ccw_dev_id dev_id;
1070
1071         if (sch->dev.driver_data) {
1072                 /*
1073                  * This subchannel already has an associated ccw_device.
1074                  * Register it and exit. This happens for all early
1075                  * device, e.g. the console.
1076                  */
1077                 cdev = sch->dev.driver_data;
1078                 device_initialize(&cdev->dev);
1079                 ccw_device_register(cdev);
1080                 /*
1081                  * Check if the device is already online. If it is
1082                  * the reference count needs to be corrected
1083                  * (see ccw_device_online and css_init_done for the
1084                  * ugly details).
1085                  */
1086                 if (cdev->private->state != DEV_STATE_NOT_OPER &&
1087                     cdev->private->state != DEV_STATE_OFFLINE &&
1088                     cdev->private->state != DEV_STATE_BOXED)
1089                         get_device(&cdev->dev);
1090                 return 0;
1091         }
1092         /*
1093          * First check if a fitting device may be found amongst the
1094          * disconnected devices or in the orphanage.
1095          */
1096         dev_id.devno = sch->schib.pmcw.dev;
1097         dev_id.ssid = sch->schid.ssid;
1098         cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL);
1099         if (!cdev)
1100                 cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent),
1101                                                      &dev_id);
1102         if (cdev) {
1103                 /*
1104                  * Schedule moving the device until when we have a registered
1105                  * subchannel to move to and succeed the probe. We can
1106                  * unregister later again, when the probe is through.
1107                  */
1108                 cdev->private->sch = sch;
1109                 PREPARE_WORK(&cdev->private->kick_work,
1110                              ccw_device_move_to_sch);
1111                 queue_work(slow_path_wq, &cdev->private->kick_work);
1112                 return 0;
1113         }
1114         cdev = io_subchannel_create_ccwdev(sch);
1115         if (IS_ERR(cdev))
1116                 return PTR_ERR(cdev);
1117
1118         rc = io_subchannel_recog(cdev, sch);
1119         if (rc) {
1120                 spin_lock_irqsave(sch->lock, flags);
1121                 sch->dev.driver_data = NULL;
1122                 spin_unlock_irqrestore(sch->lock, flags);
1123                 if (cdev->dev.release)
1124                         cdev->dev.release(&cdev->dev);
1125         }
1126
1127         return rc;
1128 }
1129
1130 static int
1131 io_subchannel_remove (struct subchannel *sch)
1132 {
1133         struct ccw_device *cdev;
1134         unsigned long flags;
1135
1136         if (!sch->dev.driver_data)
1137                 return 0;
1138         cdev = sch->dev.driver_data;
1139         /* Set ccw device to not operational and drop reference. */
1140         spin_lock_irqsave(cdev->ccwlock, flags);
1141         sch->dev.driver_data = NULL;
1142         cdev->private->state = DEV_STATE_NOT_OPER;
1143         spin_unlock_irqrestore(cdev->ccwlock, flags);
1144         /*
1145          * Put unregistration on workqueue to avoid livelocks on the css bus
1146          * semaphore.
1147          */
1148         if (get_device(&cdev->dev)) {
1149                 PREPARE_WORK(&cdev->private->kick_work,
1150                              ccw_device_unregister);
1151                 queue_work(ccw_device_work, &cdev->private->kick_work);
1152         }
1153         return 0;
1154 }
1155
1156 static int
1157 io_subchannel_notify(struct device *dev, int event)
1158 {
1159         struct ccw_device *cdev;
1160
1161         cdev = dev->driver_data;
1162         if (!cdev)
1163                 return 0;
1164         if (!cdev->drv)
1165                 return 0;
1166         if (!cdev->online)
1167                 return 0;
1168         return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0;
1169 }
1170
1171 static void
1172 io_subchannel_verify(struct device *dev)
1173 {
1174         struct ccw_device *cdev;
1175
1176         cdev = dev->driver_data;
1177         if (cdev)
1178                 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
1179 }
1180
1181 static void
1182 io_subchannel_ioterm(struct device *dev)
1183 {
1184         struct ccw_device *cdev;
1185
1186         cdev = dev->driver_data;
1187         if (!cdev)
1188                 return;
1189         /* Internal I/O will be retried by the interrupt handler. */
1190         if (cdev->private->flags.intretry)
1191                 return;
1192         cdev->private->state = DEV_STATE_CLEAR_VERIFY;
1193         if (cdev->handler)
1194                 cdev->handler(cdev, cdev->private->intparm,
1195                               ERR_PTR(-EIO));
1196 }
1197
1198 static void
1199 io_subchannel_shutdown(struct subchannel *sch)
1200 {
1201         struct ccw_device *cdev;
1202         int ret;
1203
1204         cdev = sch->dev.driver_data;
1205
1206         if (cio_is_console(sch->schid))
1207                 return;
1208         if (!sch->schib.pmcw.ena)
1209                 /* Nothing to do. */
1210                 return;
1211         ret = cio_disable_subchannel(sch);
1212         if (ret != -EBUSY)
1213                 /* Subchannel is disabled, we're done. */
1214                 return;
1215         cdev->private->state = DEV_STATE_QUIESCE;
1216         if (cdev->handler)
1217                 cdev->handler(cdev, cdev->private->intparm,
1218                               ERR_PTR(-EIO));
1219         ret = ccw_device_cancel_halt_clear(cdev);
1220         if (ret == -EBUSY) {
1221                 ccw_device_set_timeout(cdev, HZ/10);
1222                 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
1223         }
1224         cio_disable_subchannel(sch);
1225 }
1226
1227 #ifdef CONFIG_CCW_CONSOLE
1228 static struct ccw_device console_cdev;
1229 static struct ccw_device_private console_private;
1230 static int console_cdev_in_use;
1231
1232 static DEFINE_SPINLOCK(ccw_console_lock);
1233
1234 spinlock_t * cio_get_console_lock(void)
1235 {
1236         return &ccw_console_lock;
1237 }
1238
1239 static int
1240 ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch)
1241 {
1242         int rc;
1243
1244         /* Initialize the ccw_device structure. */
1245         cdev->dev.parent= &sch->dev;
1246         rc = io_subchannel_recog(cdev, sch);
1247         if (rc)
1248                 return rc;
1249
1250         /* Now wait for the async. recognition to come to an end. */
1251         spin_lock_irq(cdev->ccwlock);
1252         while (!dev_fsm_final_state(cdev))
1253                 wait_cons_dev();
1254         rc = -EIO;
1255         if (cdev->private->state != DEV_STATE_OFFLINE)
1256                 goto out_unlock;
1257         ccw_device_online(cdev);
1258         while (!dev_fsm_final_state(cdev))
1259                 wait_cons_dev();
1260         if (cdev->private->state != DEV_STATE_ONLINE)
1261                 goto out_unlock;
1262         rc = 0;
1263 out_unlock:
1264         spin_unlock_irq(cdev->ccwlock);
1265         return 0;
1266 }
1267
1268 struct ccw_device *
1269 ccw_device_probe_console(void)
1270 {
1271         struct subchannel *sch;
1272         int ret;
1273
1274         if (xchg(&console_cdev_in_use, 1) != 0)
1275                 return ERR_PTR(-EBUSY);
1276         sch = cio_probe_console();
1277         if (IS_ERR(sch)) {
1278                 console_cdev_in_use = 0;
1279                 return (void *) sch;
1280         }
1281         memset(&console_cdev, 0, sizeof(struct ccw_device));
1282         memset(&console_private, 0, sizeof(struct ccw_device_private));
1283         console_cdev.private = &console_private;
1284         console_private.cdev = &console_cdev;
1285         ret = ccw_device_console_enable(&console_cdev, sch);
1286         if (ret) {
1287                 cio_release_console();
1288                 console_cdev_in_use = 0;
1289                 return ERR_PTR(ret);
1290         }
1291         console_cdev.online = 1;
1292         return &console_cdev;
1293 }
1294 #endif
1295
1296 /*
1297  * get ccw_device matching the busid, but only if owned by cdrv
1298  */
1299 static int
1300 __ccwdev_check_busid(struct device *dev, void *id)
1301 {
1302         char *bus_id;
1303
1304         bus_id = id;
1305
1306         return (strncmp(bus_id, dev->bus_id, BUS_ID_SIZE) == 0);
1307 }
1308
1309
1310 struct ccw_device *
1311 get_ccwdev_by_busid(struct ccw_driver *cdrv, const char *bus_id)
1312 {
1313         struct device *dev;
1314         struct device_driver *drv;
1315
1316         drv = get_driver(&cdrv->driver);
1317         if (!drv)
1318                 return NULL;
1319
1320         dev = driver_find_device(drv, NULL, (void *)bus_id,
1321                                  __ccwdev_check_busid);
1322         put_driver(drv);
1323
1324         return dev ? to_ccwdev(dev) : NULL;
1325 }
1326
1327 /************************** device driver handling ************************/
1328
1329 /* This is the implementation of the ccw_driver class. The probe, remove
1330  * and release methods are initially very similar to the device_driver
1331  * implementations, with the difference that they have ccw_device
1332  * arguments.
1333  *
1334  * A ccw driver also contains the information that is needed for
1335  * device matching.
1336  */
1337 static int
1338 ccw_device_probe (struct device *dev)
1339 {
1340         struct ccw_device *cdev = to_ccwdev(dev);
1341         struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1342         int ret;
1343
1344         cdev->drv = cdrv; /* to let the driver call _set_online */
1345
1346         ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1347
1348         if (ret) {
1349                 cdev->drv = NULL;
1350                 return ret;
1351         }
1352
1353         return 0;
1354 }
1355
1356 static int
1357 ccw_device_remove (struct device *dev)
1358 {
1359         struct ccw_device *cdev = to_ccwdev(dev);
1360         struct ccw_driver *cdrv = cdev->drv;
1361         int ret;
1362
1363         pr_debug("removing device %s\n", cdev->dev.bus_id);
1364         if (cdrv->remove)
1365                 cdrv->remove(cdev);
1366         if (cdev->online) {
1367                 cdev->online = 0;
1368                 spin_lock_irq(cdev->ccwlock);
1369                 ret = ccw_device_offline(cdev);
1370                 spin_unlock_irq(cdev->ccwlock);
1371                 if (ret == 0)
1372                         wait_event(cdev->private->wait_q,
1373                                    dev_fsm_final_state(cdev));
1374                 else
1375                         //FIXME: we can't fail!
1376                         pr_debug("ccw_device_offline returned %d, device %s\n",
1377                                  ret, cdev->dev.bus_id);
1378         }
1379         ccw_device_set_timeout(cdev, 0);
1380         cdev->drv = NULL;
1381         return 0;
1382 }
1383
1384 struct bus_type ccw_bus_type = {
1385         .name   = "ccw",
1386         .match  = ccw_bus_match,
1387         .uevent = ccw_uevent,
1388         .probe  = ccw_device_probe,
1389         .remove = ccw_device_remove,
1390 };
1391
1392 int
1393 ccw_driver_register (struct ccw_driver *cdriver)
1394 {
1395         struct device_driver *drv = &cdriver->driver;
1396
1397         drv->bus = &ccw_bus_type;
1398         drv->name = cdriver->name;
1399
1400         return driver_register(drv);
1401 }
1402
1403 void
1404 ccw_driver_unregister (struct ccw_driver *cdriver)
1405 {
1406         driver_unregister(&cdriver->driver);
1407 }
1408
1409 /* Helper func for qdio. */
1410 struct subchannel_id
1411 ccw_device_get_subchannel_id(struct ccw_device *cdev)
1412 {
1413         struct subchannel *sch;
1414
1415         sch = to_subchannel(cdev->dev.parent);
1416         return sch->schid;
1417 }
1418
1419 MODULE_LICENSE("GPL");
1420 EXPORT_SYMBOL(ccw_device_set_online);
1421 EXPORT_SYMBOL(ccw_device_set_offline);
1422 EXPORT_SYMBOL(ccw_driver_register);
1423 EXPORT_SYMBOL(ccw_driver_unregister);
1424 EXPORT_SYMBOL(get_ccwdev_by_busid);
1425 EXPORT_SYMBOL(ccw_bus_type);
1426 EXPORT_SYMBOL(ccw_device_work);
1427 EXPORT_SYMBOL(ccw_device_notify_work);
1428 EXPORT_SYMBOL_GPL(ccw_device_get_subchannel_id);