2 * drivers/s390/cio/device.c
3 * bus driver for ccw devices
6 * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH,
8 * Author(s): Arnd Bergmann (arndb@de.ibm.com)
9 * Cornelia Huck (cohuck@de.ibm.com)
10 * Martin Schwidefsky (schwidefsky@de.ibm.com)
12 #include <linux/config.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/spinlock.h>
16 #include <linux/errno.h>
17 #include <linux/err.h>
18 #include <linux/slab.h>
19 #include <linux/list.h>
20 #include <linux/device.h>
21 #include <linux/workqueue.h>
23 #include <asm/ccwdev.h>
25 #include <asm/param.h> /* HZ */
32 /******************* bus type handling ***********************/
34 /* The Linux driver model distinguishes between a bus type and
35 * the bus itself. Of course we only have one channel
36 * subsystem driver and one channel system per machine, but
37 * we still use the abstraction. T.R. says it's a good idea. */
39 ccw_bus_match (struct device * dev, struct device_driver * drv)
41 struct ccw_device *cdev = to_ccwdev(dev);
42 struct ccw_driver *cdrv = to_ccwdrv(drv);
43 const struct ccw_device_id *ids = cdrv->ids, *found;
48 found = ccw_device_id_match(ids, &cdev->id);
52 cdev->id.driver_info = found->driver_info;
58 * Hotplugging interface for ccw devices.
59 * Heavily modeled on pci and usb hotplug.
62 ccw_hotplug (struct device *dev, char **envp, int num_envp,
63 char *buffer, int buffer_size)
65 struct ccw_device *cdev = to_ccwdev(dev);
72 /* what we want to pass to /sbin/hotplug */
75 length += scnprintf(buffer, buffer_size - length, "CU_TYPE=%04X",
77 if ((buffer_size - length <= 0) || (i >= num_envp))
83 length += scnprintf(buffer, buffer_size - length, "CU_MODEL=%02X",
85 if ((buffer_size - length <= 0) || (i >= num_envp))
90 /* The next two can be zero, that's ok for us */
92 length += scnprintf(buffer, buffer_size - length, "DEV_TYPE=%04X",
94 if ((buffer_size - length <= 0) || (i >= num_envp))
100 length += scnprintf(buffer, buffer_size - length, "DEV_MODEL=%02X",
102 if ((buffer_size - length <= 0) || (i >= num_envp))
110 struct bus_type ccw_bus_type = {
112 .match = &ccw_bus_match,
113 .hotplug = &ccw_hotplug,
116 static int io_subchannel_probe (struct device *);
117 static int io_subchannel_remove (struct device *);
118 void io_subchannel_irq (struct device *);
119 static int io_subchannel_notify(struct device *, int);
120 static void io_subchannel_verify(struct device *);
121 static void io_subchannel_ioterm(struct device *);
122 static void io_subchannel_shutdown(struct device *);
124 struct css_driver io_subchannel_driver = {
125 .subchannel_type = SUBCHANNEL_TYPE_IO,
127 .name = "io_subchannel",
128 .bus = &css_bus_type,
129 .probe = &io_subchannel_probe,
130 .remove = &io_subchannel_remove,
131 .shutdown = &io_subchannel_shutdown,
133 .irq = io_subchannel_irq,
134 .notify = io_subchannel_notify,
135 .verify = io_subchannel_verify,
136 .termination = io_subchannel_ioterm,
139 struct workqueue_struct *ccw_device_work;
140 struct workqueue_struct *ccw_device_notify_work;
141 static wait_queue_head_t ccw_device_init_wq;
142 static atomic_t ccw_device_init_count;
145 init_ccw_bus_type (void)
149 init_waitqueue_head(&ccw_device_init_wq);
150 atomic_set(&ccw_device_init_count, 0);
152 ccw_device_work = create_singlethread_workqueue("cio");
153 if (!ccw_device_work)
154 return -ENOMEM; /* FIXME: better errno ? */
155 ccw_device_notify_work = create_singlethread_workqueue("cio_notify");
156 if (!ccw_device_notify_work) {
157 ret = -ENOMEM; /* FIXME: better errno ? */
160 slow_path_wq = create_singlethread_workqueue("kslowcrw");
162 ret = -ENOMEM; /* FIXME: better errno ? */
165 if ((ret = bus_register (&ccw_bus_type)))
168 if ((ret = driver_register(&io_subchannel_driver.drv)))
171 wait_event(ccw_device_init_wq,
172 atomic_read(&ccw_device_init_count) == 0);
173 flush_workqueue(ccw_device_work);
177 destroy_workqueue(ccw_device_work);
178 if (ccw_device_notify_work)
179 destroy_workqueue(ccw_device_notify_work);
181 destroy_workqueue(slow_path_wq);
186 cleanup_ccw_bus_type (void)
188 driver_unregister(&io_subchannel_driver.drv);
189 bus_unregister(&ccw_bus_type);
190 destroy_workqueue(ccw_device_notify_work);
191 destroy_workqueue(ccw_device_work);
194 subsys_initcall(init_ccw_bus_type);
195 module_exit(cleanup_ccw_bus_type);
197 /************************ device handling **************************/
200 * A ccw_device has some interfaces in sysfs in addition to the
202 * The following entries are designed to export the information which
203 * resided in 2.4 in /proc/subchannels. Subchannel and device number
204 * are obvious, so they don't have an entry :)
205 * TODO: Split chpids and pimpampom up? Where is "in use" in the tree?
208 chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
210 struct subchannel *sch = to_subchannel(dev);
211 struct ssd_info *ssd = &sch->ssd_info;
215 for (chp = 0; chp < 8; chp++)
216 ret += sprintf (buf+ret, "%02x ", ssd->chpid[chp]);
218 ret += sprintf (buf+ret, "\n");
219 return min((ssize_t)PAGE_SIZE, ret);
223 pimpampom_show (struct device * dev, struct device_attribute *attr, char * buf)
225 struct subchannel *sch = to_subchannel(dev);
226 struct pmcw *pmcw = &sch->schib.pmcw;
228 return sprintf (buf, "%02x %02x %02x\n",
229 pmcw->pim, pmcw->pam, pmcw->pom);
233 devtype_show (struct device *dev, struct device_attribute *attr, char *buf)
235 struct ccw_device *cdev = to_ccwdev(dev);
236 struct ccw_device_id *id = &(cdev->id);
238 if (id->dev_type != 0)
239 return sprintf(buf, "%04x/%02x\n",
240 id->dev_type, id->dev_model);
242 return sprintf(buf, "n/a\n");
246 cutype_show (struct device *dev, struct device_attribute *attr, char *buf)
248 struct ccw_device *cdev = to_ccwdev(dev);
249 struct ccw_device_id *id = &(cdev->id);
251 return sprintf(buf, "%04x/%02x\n",
252 id->cu_type, id->cu_model);
256 modalias_show (struct device *dev, struct device_attribute *attr, char *buf)
258 struct ccw_device *cdev = to_ccwdev(dev);
259 struct ccw_device_id *id = &(cdev->id);
262 ret = sprintf(buf, "ccw:t%04Xm%02x",
263 id->cu_type, id->cu_model);
264 if (id->dev_type != 0)
265 ret += sprintf(buf + ret, "dt%04Xdm%02X\n",
266 id->dev_type, id->dev_model);
268 ret += sprintf(buf + ret, "dtdm\n");
273 online_show (struct device *dev, struct device_attribute *attr, char *buf)
275 struct ccw_device *cdev = to_ccwdev(dev);
277 return sprintf(buf, cdev->online ? "1\n" : "0\n");
281 ccw_device_remove_disconnected(struct ccw_device *cdev)
283 struct subchannel *sch;
285 * Forced offline in disconnected state means
286 * 'throw away device'.
288 sch = to_subchannel(cdev->dev.parent);
289 device_unregister(&sch->dev);
290 /* Reset intparm to zeroes. */
291 sch->schib.pmcw.intparm = 0;
293 put_device(&sch->dev);
297 ccw_device_set_offline(struct ccw_device *cdev)
303 if (!cdev->online || !cdev->drv)
306 if (cdev->drv->set_offline) {
307 ret = cdev->drv->set_offline(cdev);
312 spin_lock_irq(cdev->ccwlock);
313 ret = ccw_device_offline(cdev);
314 if (ret == -ENODEV) {
315 if (cdev->private->state != DEV_STATE_NOT_OPER) {
316 cdev->private->state = DEV_STATE_OFFLINE;
317 dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
319 spin_unlock_irq(cdev->ccwlock);
322 spin_unlock_irq(cdev->ccwlock);
324 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
326 pr_debug("ccw_device_offline returned %d, device %s\n",
327 ret, cdev->dev.bus_id);
334 ccw_device_set_online(struct ccw_device *cdev)
340 if (cdev->online || !cdev->drv)
343 spin_lock_irq(cdev->ccwlock);
344 ret = ccw_device_online(cdev);
345 spin_unlock_irq(cdev->ccwlock);
347 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
349 pr_debug("ccw_device_online returned %d, device %s\n",
350 ret, cdev->dev.bus_id);
353 if (cdev->private->state != DEV_STATE_ONLINE)
355 if (!cdev->drv->set_online || cdev->drv->set_online(cdev) == 0) {
359 spin_lock_irq(cdev->ccwlock);
360 ret = ccw_device_offline(cdev);
361 spin_unlock_irq(cdev->ccwlock);
363 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
365 pr_debug("ccw_device_offline returned %d, device %s\n",
366 ret, cdev->dev.bus_id);
367 return (ret = 0) ? -ENODEV : ret;
371 online_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
373 struct ccw_device *cdev = to_ccwdev(dev);
377 if (atomic_compare_and_swap(0, 1, &cdev->private->onoff))
380 if (cdev->drv && !try_module_get(cdev->drv->owner)) {
381 atomic_set(&cdev->private->onoff, 0);
384 if (!strncmp(buf, "force\n", count)) {
389 i = simple_strtoul(buf, &tmp, 16);
392 /* Do device recognition, if needed. */
393 if (cdev->id.cu_type == 0) {
394 ret = ccw_device_recognition(cdev);
396 printk(KERN_WARNING"Couldn't start recognition "
397 "for device %s (ret=%d)\n",
398 cdev->dev.bus_id, ret);
401 wait_event(cdev->private->wait_q,
402 cdev->private->flags.recog_done);
404 if (cdev->drv && cdev->drv->set_online)
405 ccw_device_set_online(cdev);
407 if (cdev->private->state == DEV_STATE_DISCONNECTED)
408 ccw_device_remove_disconnected(cdev);
409 else if (cdev->drv && cdev->drv->set_offline)
410 ccw_device_set_offline(cdev);
412 if (force && cdev->private->state == DEV_STATE_BOXED) {
413 ret = ccw_device_stlck(cdev);
415 printk(KERN_WARNING"ccw_device_stlck for device %s "
416 "returned %d!\n", cdev->dev.bus_id, ret);
419 /* Do device recognition, if needed. */
420 if (cdev->id.cu_type == 0) {
421 cdev->private->state = DEV_STATE_NOT_OPER;
422 ret = ccw_device_recognition(cdev);
424 printk(KERN_WARNING"Couldn't start recognition "
425 "for device %s (ret=%d)\n",
426 cdev->dev.bus_id, ret);
429 wait_event(cdev->private->wait_q,
430 cdev->private->flags.recog_done);
432 if (cdev->drv && cdev->drv->set_online)
433 ccw_device_set_online(cdev);
437 module_put(cdev->drv->owner);
438 atomic_set(&cdev->private->onoff, 0);
443 available_show (struct device *dev, struct device_attribute *attr, char *buf)
445 struct ccw_device *cdev = to_ccwdev(dev);
446 struct subchannel *sch;
448 switch (cdev->private->state) {
449 case DEV_STATE_BOXED:
450 return sprintf(buf, "boxed\n");
451 case DEV_STATE_DISCONNECTED:
452 case DEV_STATE_DISCONNECTED_SENSE_ID:
453 case DEV_STATE_NOT_OPER:
454 sch = to_subchannel(dev->parent);
456 return sprintf(buf, "no path\n");
458 return sprintf(buf, "no device\n");
460 /* All other states considered fine. */
461 return sprintf(buf, "good\n");
465 static DEVICE_ATTR(chpids, 0444, chpids_show, NULL);
466 static DEVICE_ATTR(pimpampom, 0444, pimpampom_show, NULL);
467 static DEVICE_ATTR(devtype, 0444, devtype_show, NULL);
468 static DEVICE_ATTR(cutype, 0444, cutype_show, NULL);
469 static DEVICE_ATTR(modalias, 0444, modalias_show, NULL);
470 static DEVICE_ATTR(online, 0644, online_show, online_store);
471 extern struct device_attribute dev_attr_cmb_enable;
472 static DEVICE_ATTR(availability, 0444, available_show, NULL);
474 static struct attribute * subch_attrs[] = {
475 &dev_attr_chpids.attr,
476 &dev_attr_pimpampom.attr,
480 static struct attribute_group subch_attr_group = {
481 .attrs = subch_attrs,
485 subchannel_add_files (struct device *dev)
487 return sysfs_create_group(&dev->kobj, &subch_attr_group);
490 static struct attribute * ccwdev_attrs[] = {
491 &dev_attr_devtype.attr,
492 &dev_attr_cutype.attr,
493 &dev_attr_modalias.attr,
494 &dev_attr_online.attr,
495 &dev_attr_cmb_enable.attr,
496 &dev_attr_availability.attr,
500 static struct attribute_group ccwdev_attr_group = {
501 .attrs = ccwdev_attrs,
505 device_add_files (struct device *dev)
507 return sysfs_create_group(&dev->kobj, &ccwdev_attr_group);
511 device_remove_files(struct device *dev)
513 sysfs_remove_group(&dev->kobj, &ccwdev_attr_group);
516 /* this is a simple abstraction for device_register that sets the
517 * correct bus type and adds the bus specific files */
519 ccw_device_register(struct ccw_device *cdev)
521 struct device *dev = &cdev->dev;
524 dev->bus = &ccw_bus_type;
526 if ((ret = device_add(dev)))
529 set_bit(1, &cdev->private->registered);
530 if ((ret = device_add_files(dev))) {
531 if (test_and_clear_bit(1, &cdev->private->registered))
539 struct ccw_device * sibling;
543 match_devno(struct device * dev, void * data)
545 struct match_data * d = (struct match_data *)data;
546 struct ccw_device * cdev;
548 cdev = to_ccwdev(dev);
549 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
550 (cdev->private->devno == d->devno) &&
551 (cdev != d->sibling)) {
552 cdev->private->state = DEV_STATE_NOT_OPER;
558 static struct ccw_device *
559 get_disc_ccwdev_by_devno(unsigned int devno, struct ccw_device *sibling)
562 struct match_data data = {
567 dev = bus_find_device(&ccw_bus_type, NULL, &data, match_devno);
569 return dev ? to_ccwdev(dev) : NULL;
573 ccw_device_add_changed(void *data)
576 struct ccw_device *cdev;
578 cdev = (struct ccw_device *)data;
579 if (device_add(&cdev->dev)) {
580 put_device(&cdev->dev);
583 set_bit(1, &cdev->private->registered);
584 if (device_add_files(&cdev->dev)) {
585 if (test_and_clear_bit(1, &cdev->private->registered))
586 device_unregister(&cdev->dev);
590 extern int css_get_ssd_info(struct subchannel *sch);
593 ccw_device_do_unreg_rereg(void *data)
595 struct ccw_device *cdev;
596 struct subchannel *sch;
599 cdev = (struct ccw_device *)data;
600 sch = to_subchannel(cdev->dev.parent);
601 if (cdev->private->devno != sch->schib.pmcw.dev) {
603 * The device number has changed. This is usually only when
604 * a device has been detached under VM and then re-appeared
605 * on another subchannel because of a different attachment
606 * order than before. Ideally, we should should just switch
607 * subchannels, but unfortunately, this is not possible with
608 * the current implementation.
609 * Instead, we search for the old subchannel for this device
610 * number and deregister so there are no collisions with the
611 * newly registered ccw_device.
612 * FIXME: Find another solution so the block layer doesn't
613 * get possibly sick...
615 struct ccw_device *other_cdev;
618 other_cdev = get_disc_ccwdev_by_devno(sch->schib.pmcw.dev,
621 struct subchannel *other_sch;
623 other_sch = to_subchannel(other_cdev->dev.parent);
624 if (get_device(&other_sch->dev)) {
625 stsch(other_sch->irq, &other_sch->schib);
626 if (other_sch->schib.pmcw.dnv) {
627 other_sch->schib.pmcw.intparm = 0;
628 cio_modify(other_sch);
630 device_unregister(&other_sch->dev);
633 /* Update ssd info here. */
634 css_get_ssd_info(sch);
635 cdev->private->devno = sch->schib.pmcw.dev;
638 device_remove_files(&cdev->dev);
639 if (test_and_clear_bit(1, &cdev->private->registered))
640 device_del(&cdev->dev);
642 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.0.%04x",
643 sch->schib.pmcw.dev);
644 PREPARE_WORK(&cdev->private->kick_work,
645 ccw_device_add_changed, (void *)cdev);
646 queue_work(ccw_device_work, &cdev->private->kick_work);
650 ccw_device_release(struct device *dev)
652 struct ccw_device *cdev;
654 cdev = to_ccwdev(dev);
655 kfree(cdev->private);
660 * Register recognized device.
663 io_subchannel_register(void *data)
665 struct ccw_device *cdev;
666 struct subchannel *sch;
670 cdev = (struct ccw_device *) data;
671 sch = to_subchannel(cdev->dev.parent);
673 if (klist_node_attached(&cdev->dev.knode_parent)) {
674 bus_rescan_devices(&ccw_bus_type);
677 /* make it known to the system */
678 ret = ccw_device_register(cdev);
680 printk (KERN_WARNING "%s: could not register %s\n",
681 __func__, cdev->dev.bus_id);
682 put_device(&cdev->dev);
683 spin_lock_irqsave(&sch->lock, flags);
684 sch->dev.driver_data = NULL;
685 spin_unlock_irqrestore(&sch->lock, flags);
686 kfree (cdev->private);
688 put_device(&sch->dev);
689 if (atomic_dec_and_test(&ccw_device_init_count))
690 wake_up(&ccw_device_init_wq);
694 ret = subchannel_add_files(cdev->dev.parent);
696 printk(KERN_WARNING "%s: could not add attributes to %s\n",
697 __func__, sch->dev.bus_id);
698 put_device(&cdev->dev);
700 cdev->private->flags.recog_done = 1;
701 put_device(&sch->dev);
702 wake_up(&cdev->private->wait_q);
703 if (atomic_dec_and_test(&ccw_device_init_count))
704 wake_up(&ccw_device_init_wq);
708 ccw_device_call_sch_unregister(void *data)
710 struct ccw_device *cdev = data;
711 struct subchannel *sch;
713 sch = to_subchannel(cdev->dev.parent);
714 device_unregister(&sch->dev);
715 /* Reset intparm to zeroes. */
716 sch->schib.pmcw.intparm = 0;
718 put_device(&cdev->dev);
719 put_device(&sch->dev);
723 * subchannel recognition done. Called from the state machine.
726 io_subchannel_recog_done(struct ccw_device *cdev)
728 struct subchannel *sch;
730 if (css_init_done == 0) {
731 cdev->private->flags.recog_done = 1;
734 switch (cdev->private->state) {
735 case DEV_STATE_NOT_OPER:
736 cdev->private->flags.recog_done = 1;
737 /* Remove device found not operational. */
738 if (!get_device(&cdev->dev))
740 sch = to_subchannel(cdev->dev.parent);
741 PREPARE_WORK(&cdev->private->kick_work,
742 ccw_device_call_sch_unregister, (void *) cdev);
743 queue_work(slow_path_wq, &cdev->private->kick_work);
744 if (atomic_dec_and_test(&ccw_device_init_count))
745 wake_up(&ccw_device_init_wq);
747 case DEV_STATE_BOXED:
748 /* Device did not respond in time. */
749 case DEV_STATE_OFFLINE:
751 * We can't register the device in interrupt context so
752 * we schedule a work item.
754 if (!get_device(&cdev->dev))
756 PREPARE_WORK(&cdev->private->kick_work,
757 io_subchannel_register, (void *) cdev);
758 queue_work(slow_path_wq, &cdev->private->kick_work);
764 io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
767 struct ccw_device_private *priv;
769 sch->dev.driver_data = cdev;
770 sch->driver = &io_subchannel_driver;
771 cdev->ccwlock = &sch->lock;
772 /* Init private data. */
773 priv = cdev->private;
774 priv->devno = sch->schib.pmcw.dev;
775 priv->irq = sch->irq;
776 priv->state = DEV_STATE_NOT_OPER;
777 INIT_LIST_HEAD(&priv->cmb_list);
778 init_waitqueue_head(&priv->wait_q);
779 init_timer(&priv->timer);
781 /* Set an initial name for the device. */
782 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.0.%04x",
783 sch->schib.pmcw.dev);
785 /* Increase counter of devices currently in recognition. */
786 atomic_inc(&ccw_device_init_count);
788 /* Start async. device sensing. */
789 spin_lock_irq(&sch->lock);
790 rc = ccw_device_recognition(cdev);
791 spin_unlock_irq(&sch->lock);
793 if (atomic_dec_and_test(&ccw_device_init_count))
794 wake_up(&ccw_device_init_wq);
800 io_subchannel_probe (struct device *pdev)
802 struct subchannel *sch;
803 struct ccw_device *cdev;
807 sch = to_subchannel(pdev);
808 if (sch->dev.driver_data) {
810 * This subchannel already has an associated ccw_device.
811 * Register it and exit. This happens for all early
812 * device, e.g. the console.
814 cdev = sch->dev.driver_data;
815 device_initialize(&cdev->dev);
816 ccw_device_register(cdev);
817 subchannel_add_files(&sch->dev);
819 * Check if the device is already online. If it is
820 * the reference count needs to be corrected
821 * (see ccw_device_online and css_init_done for the
824 if (cdev->private->state != DEV_STATE_NOT_OPER &&
825 cdev->private->state != DEV_STATE_OFFLINE &&
826 cdev->private->state != DEV_STATE_BOXED)
827 get_device(&cdev->dev);
830 cdev = kmalloc (sizeof(*cdev), GFP_KERNEL);
833 memset(cdev, 0, sizeof(struct ccw_device));
834 cdev->private = kmalloc(sizeof(struct ccw_device_private),
835 GFP_KERNEL | GFP_DMA);
836 if (!cdev->private) {
840 memset(cdev->private, 0, sizeof(struct ccw_device_private));
841 atomic_set(&cdev->private->onoff, 0);
842 cdev->dev = (struct device) {
844 .release = ccw_device_release,
846 INIT_LIST_HEAD(&cdev->private->kick_work.entry);
847 /* Do first half of device_register. */
848 device_initialize(&cdev->dev);
850 if (!get_device(&sch->dev)) {
851 if (cdev->dev.release)
852 cdev->dev.release(&cdev->dev);
856 rc = io_subchannel_recog(cdev, to_subchannel(pdev));
858 spin_lock_irqsave(&sch->lock, flags);
859 sch->dev.driver_data = NULL;
860 spin_unlock_irqrestore(&sch->lock, flags);
861 if (cdev->dev.release)
862 cdev->dev.release(&cdev->dev);
869 ccw_device_unregister(void *data)
871 struct ccw_device *cdev;
873 cdev = (struct ccw_device *)data;
874 if (test_and_clear_bit(1, &cdev->private->registered))
875 device_unregister(&cdev->dev);
876 put_device(&cdev->dev);
880 io_subchannel_remove (struct device *dev)
882 struct ccw_device *cdev;
885 if (!dev->driver_data)
887 cdev = dev->driver_data;
888 /* Set ccw device to not operational and drop reference. */
889 spin_lock_irqsave(cdev->ccwlock, flags);
890 dev->driver_data = NULL;
891 cdev->private->state = DEV_STATE_NOT_OPER;
892 spin_unlock_irqrestore(cdev->ccwlock, flags);
894 * Put unregistration on workqueue to avoid livelocks on the css bus
897 if (get_device(&cdev->dev)) {
898 PREPARE_WORK(&cdev->private->kick_work,
899 ccw_device_unregister, (void *) cdev);
900 queue_work(ccw_device_work, &cdev->private->kick_work);
906 io_subchannel_notify(struct device *dev, int event)
908 struct ccw_device *cdev;
910 cdev = dev->driver_data;
917 return cdev->drv->notify ? cdev->drv->notify(cdev, event) : 0;
921 io_subchannel_verify(struct device *dev)
923 struct ccw_device *cdev;
925 cdev = dev->driver_data;
927 dev_fsm_event(cdev, DEV_EVENT_VERIFY);
931 io_subchannel_ioterm(struct device *dev)
933 struct ccw_device *cdev;
935 cdev = dev->driver_data;
938 cdev->private->state = DEV_STATE_CLEAR_VERIFY;
940 cdev->handler(cdev, cdev->private->intparm,
945 io_subchannel_shutdown(struct device *dev)
947 struct subchannel *sch;
948 struct ccw_device *cdev;
951 sch = to_subchannel(dev);
952 cdev = dev->driver_data;
954 if (cio_is_console(sch->irq))
956 if (!sch->schib.pmcw.ena)
959 ret = cio_disable_subchannel(sch);
961 /* Subchannel is disabled, we're done. */
963 cdev->private->state = DEV_STATE_QUIESCE;
965 cdev->handler(cdev, cdev->private->intparm,
967 ret = ccw_device_cancel_halt_clear(cdev);
969 ccw_device_set_timeout(cdev, HZ/10);
970 wait_event(cdev->private->wait_q, dev_fsm_final_state(cdev));
972 cio_disable_subchannel(sch);
975 #ifdef CONFIG_CCW_CONSOLE
976 static struct ccw_device console_cdev;
977 static struct ccw_device_private console_private;
978 static int console_cdev_in_use;
981 ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch)
985 /* Initialize the ccw_device structure. */
986 cdev->dev = (struct device) {
989 /* Initialize the subchannel structure */
990 sch->dev.parent = &css_bus_device;
991 sch->dev.bus = &css_bus_type;
993 rc = io_subchannel_recog(cdev, sch);
997 /* Now wait for the async. recognition to come to an end. */
998 spin_lock_irq(cdev->ccwlock);
999 while (!dev_fsm_final_state(cdev))
1002 if (cdev->private->state != DEV_STATE_OFFLINE)
1004 ccw_device_online(cdev);
1005 while (!dev_fsm_final_state(cdev))
1007 if (cdev->private->state != DEV_STATE_ONLINE)
1011 spin_unlock_irq(cdev->ccwlock);
1016 ccw_device_probe_console(void)
1018 struct subchannel *sch;
1021 if (xchg(&console_cdev_in_use, 1) != 0)
1023 sch = cio_probe_console();
1025 console_cdev_in_use = 0;
1026 return (void *) sch;
1028 memset(&console_cdev, 0, sizeof(struct ccw_device));
1029 memset(&console_private, 0, sizeof(struct ccw_device_private));
1030 console_cdev.private = &console_private;
1031 ret = ccw_device_console_enable(&console_cdev, sch);
1033 cio_release_console();
1034 console_cdev_in_use = 0;
1035 return ERR_PTR(ret);
1037 console_cdev.online = 1;
1038 return &console_cdev;
1043 * get ccw_device matching the busid, but only if owned by cdrv
1046 __ccwdev_check_busid(struct device *dev, void *id)
1050 bus_id = (char *)id;
1052 return (strncmp(bus_id, dev->bus_id, BUS_ID_SIZE) == 0);
1057 get_ccwdev_by_busid(struct ccw_driver *cdrv, const char *bus_id)
1060 struct device_driver *drv;
1062 drv = get_driver(&cdrv->driver);
1066 dev = driver_find_device(drv, NULL, (void *)bus_id,
1067 __ccwdev_check_busid);
1070 return dev ? to_ccwdev(dev) : 0;
1073 /************************** device driver handling ************************/
1075 /* This is the implementation of the ccw_driver class. The probe, remove
1076 * and release methods are initially very similar to the device_driver
1077 * implementations, with the difference that they have ccw_device
1080 * A ccw driver also contains the information that is needed for
1084 ccw_device_probe (struct device *dev)
1086 struct ccw_device *cdev = to_ccwdev(dev);
1087 struct ccw_driver *cdrv = to_ccwdrv(dev->driver);
1090 cdev->drv = cdrv; /* to let the driver call _set_online */
1092 ret = cdrv->probe ? cdrv->probe(cdev) : -ENODEV;
1103 ccw_device_remove (struct device *dev)
1105 struct ccw_device *cdev = to_ccwdev(dev);
1106 struct ccw_driver *cdrv = cdev->drv;
1109 pr_debug("removing device %s\n", cdev->dev.bus_id);
1114 spin_lock_irq(cdev->ccwlock);
1115 ret = ccw_device_offline(cdev);
1116 spin_unlock_irq(cdev->ccwlock);
1118 wait_event(cdev->private->wait_q,
1119 dev_fsm_final_state(cdev));
1121 //FIXME: we can't fail!
1122 pr_debug("ccw_device_offline returned %d, device %s\n",
1123 ret, cdev->dev.bus_id);
1125 ccw_device_set_timeout(cdev, 0);
1131 ccw_driver_register (struct ccw_driver *cdriver)
1133 struct device_driver *drv = &cdriver->driver;
1135 drv->bus = &ccw_bus_type;
1136 drv->name = cdriver->name;
1137 drv->probe = ccw_device_probe;
1138 drv->remove = ccw_device_remove;
1140 return driver_register(drv);
1144 ccw_driver_unregister (struct ccw_driver *cdriver)
1146 driver_unregister(&cdriver->driver);
1149 MODULE_LICENSE("GPL");
1150 EXPORT_SYMBOL(ccw_device_set_online);
1151 EXPORT_SYMBOL(ccw_device_set_offline);
1152 EXPORT_SYMBOL(ccw_driver_register);
1153 EXPORT_SYMBOL(ccw_driver_unregister);
1154 EXPORT_SYMBOL(get_ccwdev_by_busid);
1155 EXPORT_SYMBOL(ccw_bus_type);
1156 EXPORT_SYMBOL(ccw_device_work);
1157 EXPORT_SYMBOL(ccw_device_notify_work);