2 * ccw based virtio transport
4 * Copyright IBM Corp. 2012
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License (version 2 only)
8 * as published by the Free Software Foundation.
10 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
13 #include <linux/kernel_stat.h>
14 #include <linux/init.h>
15 #include <linux/bootmem.h>
16 #include <linux/err.h>
17 #include <linux/virtio.h>
18 #include <linux/virtio_config.h>
19 #include <linux/slab.h>
20 #include <linux/interrupt.h>
21 #include <linux/virtio_ring.h>
22 #include <linux/pfn.h>
23 #include <linux/async.h>
24 #include <linux/wait.h>
25 #include <linux/list.h>
26 #include <linux/bitops.h>
27 #include <linux/module.h>
29 #include <linux/kvm_para.h>
30 #include <asm/setup.h>
33 #include <asm/ccwdev.h>
34 #include <asm/virtio-ccw.h>
37 * virtio related functions
40 struct vq_config_block {
45 #define VIRTIO_CCW_CONFIG_SIZE 0x100
46 /* same as PCI config space size, should be enough for all drivers */
48 struct virtio_ccw_device {
49 struct virtio_device vdev;
51 __u8 config[VIRTIO_CCW_CONFIG_SIZE];
52 struct ccw_device *cdev;
55 wait_queue_head_t wait_q;
57 struct list_head virtqueues;
58 unsigned long indicators;
59 unsigned long indicators2;
60 struct vq_config_block *config_block;
63 struct vq_info_block {
70 struct virtio_feature_desc {
75 struct virtio_ccw_vq_info {
79 struct vq_info_block *info_block;
80 struct list_head node;
84 #define CCW_CMD_SET_VQ 0x13
85 #define CCW_CMD_VDEV_RESET 0x33
86 #define CCW_CMD_SET_IND 0x43
87 #define CCW_CMD_SET_CONF_IND 0x53
88 #define CCW_CMD_READ_FEAT 0x12
89 #define CCW_CMD_WRITE_FEAT 0x11
90 #define CCW_CMD_READ_CONF 0x22
91 #define CCW_CMD_WRITE_CONF 0x21
92 #define CCW_CMD_WRITE_STATUS 0x31
93 #define CCW_CMD_READ_VQ_CONF 0x32
95 #define VIRTIO_CCW_DOING_SET_VQ 0x00010000
96 #define VIRTIO_CCW_DOING_RESET 0x00040000
97 #define VIRTIO_CCW_DOING_READ_FEAT 0x00080000
98 #define VIRTIO_CCW_DOING_WRITE_FEAT 0x00100000
99 #define VIRTIO_CCW_DOING_READ_CONFIG 0x00200000
100 #define VIRTIO_CCW_DOING_WRITE_CONFIG 0x00400000
101 #define VIRTIO_CCW_DOING_WRITE_STATUS 0x00800000
102 #define VIRTIO_CCW_DOING_SET_IND 0x01000000
103 #define VIRTIO_CCW_DOING_READ_VQ_CONF 0x02000000
104 #define VIRTIO_CCW_DOING_SET_CONF_IND 0x04000000
105 #define VIRTIO_CCW_INTPARM_MASK 0xffff0000
107 static struct virtio_ccw_device *to_vc_device(struct virtio_device *vdev)
109 return container_of(vdev, struct virtio_ccw_device, vdev);
112 static int doing_io(struct virtio_ccw_device *vcdev, __u32 flag)
117 spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
121 ret = vcdev->curr_io & flag;
122 spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
126 static int ccw_io_helper(struct virtio_ccw_device *vcdev,
127 struct ccw1 *ccw, __u32 intparm)
131 int flag = intparm & VIRTIO_CCW_INTPARM_MASK;
134 spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags);
135 ret = ccw_device_start(vcdev->cdev, ccw, intparm, 0, 0);
139 vcdev->curr_io |= flag;
141 spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags);
143 } while (ret == -EBUSY);
144 wait_event(vcdev->wait_q, doing_io(vcdev, flag) == 0);
145 return ret ? ret : vcdev->err;
148 static inline long do_kvm_notify(struct subchannel_id schid,
149 unsigned long queue_index,
152 register unsigned long __nr asm("1") = KVM_S390_VIRTIO_CCW_NOTIFY;
153 register struct subchannel_id __schid asm("2") = schid;
154 register unsigned long __index asm("3") = queue_index;
155 register long __rc asm("2");
156 register long __cookie asm("4") = cookie;
158 asm volatile ("diag 2,4,0x500\n"
159 : "=d" (__rc) : "d" (__nr), "d" (__schid), "d" (__index),
165 static bool virtio_ccw_kvm_notify(struct virtqueue *vq)
167 struct virtio_ccw_vq_info *info = vq->priv;
168 struct virtio_ccw_device *vcdev;
169 struct subchannel_id schid;
171 vcdev = to_vc_device(info->vq->vdev);
172 ccw_device_get_schid(vcdev->cdev, &schid);
173 info->cookie = do_kvm_notify(schid, vq->index, info->cookie);
174 if (info->cookie < 0)
179 static int virtio_ccw_read_vq_conf(struct virtio_ccw_device *vcdev,
180 struct ccw1 *ccw, int index)
182 vcdev->config_block->index = index;
183 ccw->cmd_code = CCW_CMD_READ_VQ_CONF;
185 ccw->count = sizeof(struct vq_config_block);
186 ccw->cda = (__u32)(unsigned long)(vcdev->config_block);
187 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_VQ_CONF);
188 return vcdev->config_block->num;
191 static void virtio_ccw_del_vq(struct virtqueue *vq, struct ccw1 *ccw)
193 struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev);
194 struct virtio_ccw_vq_info *info = vq->priv;
198 unsigned int index = vq->index;
200 /* Remove from our list. */
201 spin_lock_irqsave(&vcdev->lock, flags);
202 list_del(&info->node);
203 spin_unlock_irqrestore(&vcdev->lock, flags);
205 /* Release from host. */
206 info->info_block->queue = 0;
207 info->info_block->align = 0;
208 info->info_block->index = index;
209 info->info_block->num = 0;
210 ccw->cmd_code = CCW_CMD_SET_VQ;
212 ccw->count = sizeof(*info->info_block);
213 ccw->cda = (__u32)(unsigned long)(info->info_block);
214 ret = ccw_io_helper(vcdev, ccw,
215 VIRTIO_CCW_DOING_SET_VQ | index);
217 * -ENODEV isn't considered an error: The device is gone anyway.
218 * This may happen on device detach.
220 if (ret && (ret != -ENODEV))
221 dev_warn(&vq->vdev->dev, "Error %d while deleting queue %d",
224 vring_del_virtqueue(vq);
225 size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
226 free_pages_exact(info->queue, size);
227 kfree(info->info_block);
231 static void virtio_ccw_del_vqs(struct virtio_device *vdev)
233 struct virtqueue *vq, *n;
236 ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
241 list_for_each_entry_safe(vq, n, &vdev->vqs, list)
242 virtio_ccw_del_vq(vq, ccw);
247 static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
248 int i, vq_callback_t *callback,
252 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
254 struct virtqueue *vq = NULL;
255 struct virtio_ccw_vq_info *info;
256 unsigned long size = 0; /* silence the compiler */
259 /* Allocate queue. */
260 info = kzalloc(sizeof(struct virtio_ccw_vq_info), GFP_KERNEL);
262 dev_warn(&vcdev->cdev->dev, "no info\n");
266 info->info_block = kzalloc(sizeof(*info->info_block),
267 GFP_DMA | GFP_KERNEL);
268 if (!info->info_block) {
269 dev_warn(&vcdev->cdev->dev, "no info block\n");
273 info->num = virtio_ccw_read_vq_conf(vcdev, ccw, i);
274 size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
275 info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
276 if (info->queue == NULL) {
277 dev_warn(&vcdev->cdev->dev, "no queue\n");
282 vq = vring_new_virtqueue(i, info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev,
283 true, info->queue, virtio_ccw_kvm_notify,
286 /* For now, we fail if we can't get the requested size. */
287 dev_warn(&vcdev->cdev->dev, "no vq\n");
292 /* Register it with the host. */
293 info->info_block->queue = (__u64)info->queue;
294 info->info_block->align = KVM_VIRTIO_CCW_RING_ALIGN;
295 info->info_block->index = i;
296 info->info_block->num = info->num;
297 ccw->cmd_code = CCW_CMD_SET_VQ;
299 ccw->count = sizeof(*info->info_block);
300 ccw->cda = (__u32)(unsigned long)(info->info_block);
301 err = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_VQ | i);
303 dev_warn(&vcdev->cdev->dev, "SET_VQ failed\n");
310 /* Save it to our list. */
311 spin_lock_irqsave(&vcdev->lock, flags);
312 list_add(&info->node, &vcdev->virtqueues);
313 spin_unlock_irqrestore(&vcdev->lock, flags);
319 vring_del_virtqueue(vq);
322 free_pages_exact(info->queue, size);
323 kfree(info->info_block);
329 static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs,
330 struct virtqueue *vqs[],
331 vq_callback_t *callbacks[],
334 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
335 unsigned long *indicatorp = NULL;
339 ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
343 for (i = 0; i < nvqs; ++i) {
344 vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i],
346 if (IS_ERR(vqs[i])) {
347 ret = PTR_ERR(vqs[i]);
353 /* We need a data area under 2G to communicate. */
354 indicatorp = kmalloc(sizeof(&vcdev->indicators), GFP_DMA | GFP_KERNEL);
357 *indicatorp = (unsigned long) &vcdev->indicators;
358 /* Register queue indicators with host. */
359 vcdev->indicators = 0;
360 ccw->cmd_code = CCW_CMD_SET_IND;
362 ccw->count = sizeof(vcdev->indicators);
363 ccw->cda = (__u32)(unsigned long) indicatorp;
364 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_IND);
367 /* Register indicators2 with host for config changes */
368 *indicatorp = (unsigned long) &vcdev->indicators2;
369 vcdev->indicators2 = 0;
370 ccw->cmd_code = CCW_CMD_SET_CONF_IND;
372 ccw->count = sizeof(vcdev->indicators2);
373 ccw->cda = (__u32)(unsigned long) indicatorp;
374 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_CONF_IND);
384 virtio_ccw_del_vqs(vdev);
388 static void virtio_ccw_reset(struct virtio_device *vdev)
390 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
393 ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
397 /* Zero status bits. */
400 /* Send a reset ccw on device. */
401 ccw->cmd_code = CCW_CMD_VDEV_RESET;
405 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_RESET);
409 static u32 virtio_ccw_get_features(struct virtio_device *vdev)
411 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
412 struct virtio_feature_desc *features;
416 ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
420 features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL);
425 /* Read the feature bits from the host. */
426 /* TODO: Features > 32 bits */
428 ccw->cmd_code = CCW_CMD_READ_FEAT;
430 ccw->count = sizeof(*features);
431 ccw->cda = (__u32)(unsigned long)features;
432 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_FEAT);
438 rc = le32_to_cpu(features->features);
446 static void virtio_ccw_finalize_features(struct virtio_device *vdev)
448 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
449 struct virtio_feature_desc *features;
453 ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
457 features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL);
461 /* Give virtio_ring a chance to accept features. */
462 vring_transport_features(vdev);
464 for (i = 0; i < sizeof(*vdev->features) / sizeof(features->features);
466 int highbits = i % 2 ? 32 : 0;
468 features->features = cpu_to_le32(vdev->features[i / 2]
470 /* Write the feature bits to the host. */
471 ccw->cmd_code = CCW_CMD_WRITE_FEAT;
473 ccw->count = sizeof(*features);
474 ccw->cda = (__u32)(unsigned long)features;
475 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_FEAT);
482 static void virtio_ccw_get_config(struct virtio_device *vdev,
483 unsigned int offset, void *buf, unsigned len)
485 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
490 ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
494 config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL);
498 /* Read the config area from the host. */
499 ccw->cmd_code = CCW_CMD_READ_CONF;
501 ccw->count = offset + len;
502 ccw->cda = (__u32)(unsigned long)config_area;
503 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_CONFIG);
507 memcpy(vcdev->config, config_area, sizeof(vcdev->config));
508 memcpy(buf, &vcdev->config[offset], len);
515 static void virtio_ccw_set_config(struct virtio_device *vdev,
516 unsigned int offset, const void *buf,
519 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
523 ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
527 config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL);
531 memcpy(&vcdev->config[offset], buf, len);
532 /* Write the config area to the host. */
533 memcpy(config_area, vcdev->config, sizeof(vcdev->config));
534 ccw->cmd_code = CCW_CMD_WRITE_CONF;
536 ccw->count = offset + len;
537 ccw->cda = (__u32)(unsigned long)config_area;
538 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_CONFIG);
545 static u8 virtio_ccw_get_status(struct virtio_device *vdev)
547 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
549 return *vcdev->status;
552 static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status)
554 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
557 ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
561 /* Write the status to the host. */
562 *vcdev->status = status;
563 ccw->cmd_code = CCW_CMD_WRITE_STATUS;
565 ccw->count = sizeof(status);
566 ccw->cda = (__u32)(unsigned long)vcdev->status;
567 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_STATUS);
571 static struct virtio_config_ops virtio_ccw_config_ops = {
572 .get_features = virtio_ccw_get_features,
573 .finalize_features = virtio_ccw_finalize_features,
574 .get = virtio_ccw_get_config,
575 .set = virtio_ccw_set_config,
576 .get_status = virtio_ccw_get_status,
577 .set_status = virtio_ccw_set_status,
578 .reset = virtio_ccw_reset,
579 .find_vqs = virtio_ccw_find_vqs,
580 .del_vqs = virtio_ccw_del_vqs,
585 * ccw bus driver related functions
588 static void virtio_ccw_release_dev(struct device *_d)
590 struct virtio_device *dev = container_of(_d, struct virtio_device,
592 struct virtio_ccw_device *vcdev = to_vc_device(dev);
594 kfree(vcdev->status);
595 kfree(vcdev->config_block);
599 static int irb_is_error(struct irb *irb)
601 if (scsw_cstat(&irb->scsw) != 0)
603 if (scsw_dstat(&irb->scsw) & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))
605 if (scsw_cc(&irb->scsw) != 0)
610 static struct virtqueue *virtio_ccw_vq_by_ind(struct virtio_ccw_device *vcdev,
613 struct virtio_ccw_vq_info *info;
615 struct virtqueue *vq;
618 spin_lock_irqsave(&vcdev->lock, flags);
619 list_for_each_entry(info, &vcdev->virtqueues, node) {
620 if (info->vq->index == index) {
625 spin_unlock_irqrestore(&vcdev->lock, flags);
629 static void virtio_ccw_int_handler(struct ccw_device *cdev,
630 unsigned long intparm,
633 __u32 activity = intparm & VIRTIO_CCW_INTPARM_MASK;
634 struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
636 struct virtqueue *vq;
637 struct virtio_driver *drv;
639 /* Check if it's a notification from the host. */
640 if ((intparm == 0) &&
641 (scsw_stctl(&irb->scsw) ==
642 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))) {
645 if (irb_is_error(irb))
646 vcdev->err = -EIO; /* XXX - use real error */
647 if (vcdev->curr_io & activity) {
649 case VIRTIO_CCW_DOING_READ_FEAT:
650 case VIRTIO_CCW_DOING_WRITE_FEAT:
651 case VIRTIO_CCW_DOING_READ_CONFIG:
652 case VIRTIO_CCW_DOING_WRITE_CONFIG:
653 case VIRTIO_CCW_DOING_WRITE_STATUS:
654 case VIRTIO_CCW_DOING_SET_VQ:
655 case VIRTIO_CCW_DOING_SET_IND:
656 case VIRTIO_CCW_DOING_SET_CONF_IND:
657 case VIRTIO_CCW_DOING_RESET:
658 case VIRTIO_CCW_DOING_READ_VQ_CONF:
659 vcdev->curr_io &= ~activity;
660 wake_up(&vcdev->wait_q);
663 /* don't know what to do... */
664 dev_warn(&cdev->dev, "Suspicious activity '%08x'\n",
670 for_each_set_bit(i, &vcdev->indicators,
671 sizeof(vcdev->indicators) * BITS_PER_BYTE) {
672 /* The bit clear must happen before the vring kick. */
673 clear_bit(i, &vcdev->indicators);
675 vq = virtio_ccw_vq_by_ind(vcdev, i);
676 vring_interrupt(0, vq);
678 if (test_bit(0, &vcdev->indicators2)) {
679 drv = container_of(vcdev->vdev.dev.driver,
680 struct virtio_driver, driver);
682 if (drv && drv->config_changed)
683 drv->config_changed(&vcdev->vdev);
684 clear_bit(0, &vcdev->indicators2);
689 * We usually want to autoonline all devices, but give the admin
690 * a way to exempt devices from this.
692 #define __DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \
694 static unsigned long devs_no_auto[__MAX_SSID + 1][__DEV_WORDS];
696 static char *no_auto = "";
698 module_param(no_auto, charp, 0444);
699 MODULE_PARM_DESC(no_auto, "list of ccw bus id ranges not to be auto-onlined");
701 static int virtio_ccw_check_autoonline(struct ccw_device *cdev)
703 struct ccw_dev_id id;
705 ccw_device_get_id(cdev, &id);
706 if (test_bit(id.devno, devs_no_auto[id.ssid]))
711 static void virtio_ccw_auto_online(void *data, async_cookie_t cookie)
713 struct ccw_device *cdev = data;
716 ret = ccw_device_set_online(cdev);
718 dev_warn(&cdev->dev, "Failed to set online: %d\n", ret);
721 static int virtio_ccw_probe(struct ccw_device *cdev)
723 cdev->handler = virtio_ccw_int_handler;
725 if (virtio_ccw_check_autoonline(cdev))
726 async_schedule(virtio_ccw_auto_online, cdev);
730 static void virtio_ccw_remove(struct ccw_device *cdev)
732 struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
735 unregister_virtio_device(&vcdev->vdev);
736 dev_set_drvdata(&cdev->dev, NULL);
738 cdev->handler = NULL;
741 static int virtio_ccw_offline(struct ccw_device *cdev)
743 struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
745 unregister_virtio_device(&vcdev->vdev);
746 dev_set_drvdata(&cdev->dev, NULL);
751 static int virtio_ccw_online(struct ccw_device *cdev)
754 struct virtio_ccw_device *vcdev;
756 vcdev = kzalloc(sizeof(*vcdev), GFP_KERNEL);
758 dev_warn(&cdev->dev, "Could not get memory for virtio\n");
762 vcdev->config_block = kzalloc(sizeof(*vcdev->config_block),
763 GFP_DMA | GFP_KERNEL);
764 if (!vcdev->config_block) {
768 vcdev->status = kzalloc(sizeof(*vcdev->status), GFP_DMA | GFP_KERNEL);
769 if (!vcdev->status) {
774 vcdev->vdev.dev.parent = &cdev->dev;
775 vcdev->vdev.dev.release = virtio_ccw_release_dev;
776 vcdev->vdev.config = &virtio_ccw_config_ops;
778 init_waitqueue_head(&vcdev->wait_q);
779 INIT_LIST_HEAD(&vcdev->virtqueues);
780 spin_lock_init(&vcdev->lock);
782 dev_set_drvdata(&cdev->dev, vcdev);
783 vcdev->vdev.id.vendor = cdev->id.cu_type;
784 vcdev->vdev.id.device = cdev->id.cu_model;
785 ret = register_virtio_device(&vcdev->vdev);
787 dev_warn(&cdev->dev, "Failed to register virtio device: %d\n",
793 dev_set_drvdata(&cdev->dev, NULL);
794 put_device(&vcdev->vdev.dev);
798 kfree(vcdev->status);
799 kfree(vcdev->config_block);
805 static int virtio_ccw_cio_notify(struct ccw_device *cdev, int event)
807 /* TODO: Check whether we need special handling here. */
811 static struct ccw_device_id virtio_ids[] = {
812 { CCW_DEVICE(0x3832, 0) },
815 MODULE_DEVICE_TABLE(ccw, virtio_ids);
817 static struct ccw_driver virtio_ccw_driver = {
819 .owner = THIS_MODULE,
820 .name = "virtio_ccw",
823 .probe = virtio_ccw_probe,
824 .remove = virtio_ccw_remove,
825 .set_offline = virtio_ccw_offline,
826 .set_online = virtio_ccw_online,
827 .notify = virtio_ccw_cio_notify,
828 .int_class = IRQIO_VIR,
831 static int __init pure_hex(char **cp, unsigned int *val, int min_digit,
832 int max_digit, int max_val)
839 while (diff <= max_digit) {
840 int value = hex_to_bin(**cp);
844 *val = *val * 16 + value;
849 if ((diff < min_digit) || (diff > max_digit) || (*val > max_val))
855 static int __init parse_busid(char *str, unsigned int *cssid,
856 unsigned int *ssid, unsigned int *devno)
867 ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID);
868 if (ret || (str_work[0] != '.'))
871 ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID);
872 if (ret || (str_work[0] != '.'))
875 ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL);
876 if (ret || (str_work[0] != '\0'))
884 static void __init no_auto_parse(void)
886 unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to;
891 while ((parm = strsep(&str, ","))) {
892 rc = parse_busid(strsep(&parm, "-"), &from_cssid,
897 rc = parse_busid(parm, &to_cssid,
899 if ((from_ssid > to_ssid) ||
900 ((from_ssid == to_ssid) && (from > to)))
903 to_cssid = from_cssid;
909 while ((from_ssid < to_ssid) ||
910 ((from_ssid == to_ssid) && (from <= to))) {
911 set_bit(from, devs_no_auto[from_ssid]);
913 if (from > __MAX_SUBCHANNEL) {
921 static int __init virtio_ccw_init(void)
923 /* parse no_auto string before we do anything further */
925 return ccw_driver_register(&virtio_ccw_driver);
927 module_init(virtio_ccw_init);
929 static void __exit virtio_ccw_exit(void)
931 ccw_driver_unregister(&virtio_ccw_driver);
933 module_exit(virtio_ccw_exit);