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