hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/s390/virtio/virtio_ccw.c
....@@ -9,7 +9,7 @@
99
1010 #include <linux/kernel_stat.h>
1111 #include <linux/init.h>
12
-#include <linux/bootmem.h>
12
+#include <linux/memblock.h>
1313 #include <linux/err.h>
1414 #include <linux/virtio.h>
1515 #include <linux/virtio_config.h>
....@@ -46,9 +46,15 @@
4646 #define VIRTIO_CCW_CONFIG_SIZE 0x100
4747 /* same as PCI config space size, should be enough for all drivers */
4848
49
+struct vcdev_dma_area {
50
+ unsigned long indicators;
51
+ unsigned long indicators2;
52
+ struct vq_config_block config_block;
53
+ __u8 status;
54
+};
55
+
4956 struct virtio_ccw_device {
5057 struct virtio_device vdev;
51
- __u8 *status;
5258 __u8 config[VIRTIO_CCW_CONFIG_SIZE];
5359 struct ccw_device *cdev;
5460 __u32 curr_io;
....@@ -58,15 +64,23 @@
5864 spinlock_t lock;
5965 struct mutex io_lock; /* Serializes I/O requests */
6066 struct list_head virtqueues;
61
- unsigned long indicators;
62
- unsigned long indicators2;
63
- struct vq_config_block *config_block;
6467 bool is_thinint;
6568 bool going_away;
6669 bool device_lost;
6770 unsigned int config_ready;
6871 void *airq_info;
72
+ struct vcdev_dma_area *dma_area;
6973 };
74
+
75
+static inline unsigned long *indicators(struct virtio_ccw_device *vcdev)
76
+{
77
+ return &vcdev->dma_area->indicators;
78
+}
79
+
80
+static inline unsigned long *indicators2(struct virtio_ccw_device *vcdev)
81
+{
82
+ return &vcdev->dma_area->indicators2;
83
+}
7084
7185 struct vq_info_block_legacy {
7286 __u64 queue;
....@@ -108,7 +122,6 @@
108122 struct virtio_ccw_vq_info {
109123 struct virtqueue *vq;
110124 int num;
111
- void *queue;
112125 union {
113126 struct vq_info_block s;
114127 struct vq_info_block_legacy l;
....@@ -127,12 +140,19 @@
127140
128141 struct airq_info {
129142 rwlock_t lock;
130
- u8 summary_indicator;
143
+ u8 summary_indicator_idx;
131144 struct airq_struct airq;
132145 struct airq_iv *aiv;
133146 };
134147 static struct airq_info *airq_areas[MAX_AIRQ_AREAS];
135148 static DEFINE_MUTEX(airq_areas_lock);
149
+
150
+static u8 *summary_indicators;
151
+
152
+static inline u8 *get_summary_indicator(struct airq_info *info)
153
+{
154
+ return summary_indicators + info->summary_indicator_idx;
155
+}
136156
137157 #define CCW_CMD_SET_VQ 0x13
138158 #define CCW_CMD_VDEV_RESET 0x33
....@@ -183,7 +203,7 @@
183203 write_unlock_irqrestore(&info->lock, flags);
184204 }
185205
186
-static void virtio_airq_handler(struct airq_struct *airq)
206
+static void virtio_airq_handler(struct airq_struct *airq, bool floating)
187207 {
188208 struct airq_info *info = container_of(airq, struct airq_info, airq);
189209 unsigned long ai;
....@@ -197,7 +217,7 @@
197217 break;
198218 vring_interrupt(0, (void *)airq_iv_get_ptr(info->aiv, ai));
199219 }
200
- info->summary_indicator = 0;
220
+ *(get_summary_indicator(info)) = 0;
201221 smp_wmb();
202222 /* Walk through indicators field, summary indicator not active. */
203223 for (ai = 0;;) {
....@@ -209,7 +229,7 @@
209229 read_unlock(&info->lock);
210230 }
211231
212
-static struct airq_info *new_airq_info(void)
232
+static struct airq_info *new_airq_info(int index)
213233 {
214234 struct airq_info *info;
215235 int rc;
....@@ -218,13 +238,15 @@
218238 if (!info)
219239 return NULL;
220240 rwlock_init(&info->lock);
221
- info->aiv = airq_iv_create(VIRTIO_IV_BITS, AIRQ_IV_ALLOC | AIRQ_IV_PTR);
241
+ info->aiv = airq_iv_create(VIRTIO_IV_BITS, AIRQ_IV_ALLOC | AIRQ_IV_PTR
242
+ | AIRQ_IV_CACHELINE);
222243 if (!info->aiv) {
223244 kfree(info);
224245 return NULL;
225246 }
226247 info->airq.handler = virtio_airq_handler;
227
- info->airq.lsi_ptr = &info->summary_indicator;
248
+ info->summary_indicator_idx = index;
249
+ info->airq.lsi_ptr = get_summary_indicator(info);
228250 info->airq.lsi_mask = 0xff;
229251 info->airq.isc = VIRTIO_AIRQ_ISC;
230252 rc = register_adapter_interrupt(&info->airq);
....@@ -247,7 +269,7 @@
247269 for (i = 0; i < MAX_AIRQ_AREAS && !indicator_addr; i++) {
248270 mutex_lock(&airq_areas_lock);
249271 if (!airq_areas[i])
250
- airq_areas[i] = new_airq_info();
272
+ airq_areas[i] = new_airq_info(i);
251273 info = airq_areas[i];
252274 mutex_unlock(&airq_areas_lock);
253275 if (!info)
....@@ -329,29 +351,29 @@
329351 struct airq_info *airq_info = vcdev->airq_info;
330352
331353 if (vcdev->is_thinint) {
332
- thinint_area = kzalloc(sizeof(*thinint_area),
333
- GFP_DMA | GFP_KERNEL);
354
+ thinint_area = ccw_device_dma_zalloc(vcdev->cdev,
355
+ sizeof(*thinint_area));
334356 if (!thinint_area)
335357 return;
336358 thinint_area->summary_indicator =
337
- (unsigned long) &airq_info->summary_indicator;
359
+ (unsigned long) get_summary_indicator(airq_info);
338360 thinint_area->isc = VIRTIO_AIRQ_ISC;
339361 ccw->cmd_code = CCW_CMD_SET_IND_ADAPTER;
340362 ccw->count = sizeof(*thinint_area);
341363 ccw->cda = (__u32)(unsigned long) thinint_area;
342364 } else {
343365 /* payload is the address of the indicators */
344
- indicatorp = kmalloc(sizeof(&vcdev->indicators),
345
- GFP_DMA | GFP_KERNEL);
366
+ indicatorp = ccw_device_dma_zalloc(vcdev->cdev,
367
+ sizeof(indicators(vcdev)));
346368 if (!indicatorp)
347369 return;
348370 *indicatorp = 0;
349371 ccw->cmd_code = CCW_CMD_SET_IND;
350
- ccw->count = sizeof(&vcdev->indicators);
372
+ ccw->count = sizeof(indicators(vcdev));
351373 ccw->cda = (__u32)(unsigned long) indicatorp;
352374 }
353375 /* Deregister indicators from host. */
354
- vcdev->indicators = 0;
376
+ *indicators(vcdev) = 0;
355377 ccw->flags = 0;
356378 ret = ccw_io_helper(vcdev, ccw,
357379 vcdev->is_thinint ?
....@@ -362,8 +384,8 @@
362384 "Failed to deregister indicators (%d)\n", ret);
363385 else if (vcdev->is_thinint)
364386 virtio_ccw_drop_indicators(vcdev);
365
- kfree(indicatorp);
366
- kfree(thinint_area);
387
+ ccw_device_dma_free(vcdev->cdev, indicatorp, sizeof(indicators(vcdev)));
388
+ ccw_device_dma_free(vcdev->cdev, thinint_area, sizeof(*thinint_area));
367389 }
368390
369391 static inline long __do_kvm_notify(struct subchannel_id schid,
....@@ -410,15 +432,15 @@
410432 {
411433 int ret;
412434
413
- vcdev->config_block->index = index;
435
+ vcdev->dma_area->config_block.index = index;
414436 ccw->cmd_code = CCW_CMD_READ_VQ_CONF;
415437 ccw->flags = 0;
416438 ccw->count = sizeof(struct vq_config_block);
417
- ccw->cda = (__u32)(unsigned long)(vcdev->config_block);
439
+ ccw->cda = (__u32)(unsigned long)(&vcdev->dma_area->config_block);
418440 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_VQ_CONF);
419441 if (ret)
420442 return ret;
421
- return vcdev->config_block->num ?: -ENOENT;
443
+ return vcdev->dma_area->config_block.num ?: -ENOENT;
422444 }
423445
424446 static void virtio_ccw_del_vq(struct virtqueue *vq, struct ccw1 *ccw)
....@@ -426,7 +448,6 @@
426448 struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev);
427449 struct virtio_ccw_vq_info *info = vq->priv;
428450 unsigned long flags;
429
- unsigned long size;
430451 int ret;
431452 unsigned int index = vq->index;
432453
....@@ -464,9 +485,8 @@
464485 ret, index);
465486
466487 vring_del_virtqueue(vq);
467
- size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
468
- free_pages_exact(info->queue, size);
469
- kfree(info->info_block);
488
+ ccw_device_dma_free(vcdev->cdev, info->info_block,
489
+ sizeof(*info->info_block));
470490 kfree(info);
471491 }
472492
....@@ -476,7 +496,7 @@
476496 struct ccw1 *ccw;
477497 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
478498
479
- ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
499
+ ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw));
480500 if (!ccw)
481501 return;
482502
....@@ -485,7 +505,7 @@
485505 list_for_each_entry_safe(vq, n, &vdev->vqs, list)
486506 virtio_ccw_del_vq(vq, ccw);
487507
488
- kfree(ccw);
508
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
489509 }
490510
491511 static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev,
....@@ -497,8 +517,9 @@
497517 int err;
498518 struct virtqueue *vq = NULL;
499519 struct virtio_ccw_vq_info *info;
500
- unsigned long size = 0; /* silence the compiler */
520
+ u64 queue;
501521 unsigned long flags;
522
+ bool may_reduce;
502523
503524 /* Allocate queue. */
504525 info = kzalloc(sizeof(struct virtio_ccw_vq_info), GFP_KERNEL);
....@@ -507,8 +528,8 @@
507528 err = -ENOMEM;
508529 goto out_err;
509530 }
510
- info->info_block = kzalloc(sizeof(*info->info_block),
511
- GFP_DMA | GFP_KERNEL);
531
+ info->info_block = ccw_device_dma_zalloc(vcdev->cdev,
532
+ sizeof(*info->info_block));
512533 if (!info->info_block) {
513534 dev_warn(&vcdev->cdev->dev, "no info block\n");
514535 err = -ENOMEM;
....@@ -519,37 +540,34 @@
519540 err = info->num;
520541 goto out_err;
521542 }
522
- size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN));
523
- info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
524
- if (info->queue == NULL) {
525
- dev_warn(&vcdev->cdev->dev, "no queue\n");
526
- err = -ENOMEM;
527
- goto out_err;
528
- }
543
+ may_reduce = vcdev->revision > 0;
544
+ vq = vring_create_virtqueue(i, info->num, KVM_VIRTIO_CCW_RING_ALIGN,
545
+ vdev, true, may_reduce, ctx,
546
+ virtio_ccw_kvm_notify, callback, name);
529547
530
- vq = vring_new_virtqueue(i, info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev,
531
- true, ctx, info->queue, virtio_ccw_kvm_notify,
532
- callback, name);
533548 if (!vq) {
534549 /* For now, we fail if we can't get the requested size. */
535550 dev_warn(&vcdev->cdev->dev, "no vq\n");
536551 err = -ENOMEM;
537552 goto out_err;
538553 }
554
+ /* it may have been reduced */
555
+ info->num = virtqueue_get_vring_size(vq);
539556
540557 /* Register it with the host. */
558
+ queue = virtqueue_get_desc_addr(vq);
541559 if (vcdev->revision == 0) {
542
- info->info_block->l.queue = (__u64)info->queue;
560
+ info->info_block->l.queue = queue;
543561 info->info_block->l.align = KVM_VIRTIO_CCW_RING_ALIGN;
544562 info->info_block->l.index = i;
545563 info->info_block->l.num = info->num;
546564 ccw->count = sizeof(info->info_block->l);
547565 } else {
548
- info->info_block->s.desc = (__u64)info->queue;
566
+ info->info_block->s.desc = queue;
549567 info->info_block->s.index = i;
550568 info->info_block->s.num = info->num;
551
- info->info_block->s.avail = (__u64)virtqueue_get_avail(vq);
552
- info->info_block->s.used = (__u64)virtqueue_get_used(vq);
569
+ info->info_block->s.avail = (__u64)virtqueue_get_avail_addr(vq);
570
+ info->info_block->s.used = (__u64)virtqueue_get_used_addr(vq);
553571 ccw->count = sizeof(info->info_block->s);
554572 }
555573 ccw->cmd_code = CCW_CMD_SET_VQ;
....@@ -575,9 +593,8 @@
575593 if (vq)
576594 vring_del_virtqueue(vq);
577595 if (info) {
578
- if (info->queue)
579
- free_pages_exact(info->queue, size);
580
- kfree(info->info_block);
596
+ ccw_device_dma_free(vcdev->cdev, info->info_block,
597
+ sizeof(*info->info_block));
581598 }
582599 kfree(info);
583600 return ERR_PTR(err);
....@@ -591,7 +608,8 @@
591608 struct virtio_thinint_area *thinint_area = NULL;
592609 struct airq_info *info;
593610
594
- thinint_area = kzalloc(sizeof(*thinint_area), GFP_DMA | GFP_KERNEL);
611
+ thinint_area = ccw_device_dma_zalloc(vcdev->cdev,
612
+ sizeof(*thinint_area));
595613 if (!thinint_area) {
596614 ret = -ENOMEM;
597615 goto out;
....@@ -606,7 +624,7 @@
606624 }
607625 info = vcdev->airq_info;
608626 thinint_area->summary_indicator =
609
- (unsigned long) &info->summary_indicator;
627
+ (unsigned long) get_summary_indicator(info);
610628 thinint_area->isc = VIRTIO_AIRQ_ISC;
611629 ccw->cmd_code = CCW_CMD_SET_IND_ADAPTER;
612630 ccw->flags = CCW_FLAG_SLI;
....@@ -627,7 +645,7 @@
627645 virtio_ccw_drop_indicators(vcdev);
628646 }
629647 out:
630
- kfree(thinint_area);
648
+ ccw_device_dma_free(vcdev->cdev, thinint_area, sizeof(*thinint_area));
631649 return ret;
632650 }
633651
....@@ -640,16 +658,22 @@
640658 {
641659 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
642660 unsigned long *indicatorp = NULL;
643
- int ret, i;
661
+ int ret, i, queue_idx = 0;
644662 struct ccw1 *ccw;
645663
646
- ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
664
+ ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw));
647665 if (!ccw)
648666 return -ENOMEM;
649667
650668 for (i = 0; i < nvqs; ++i) {
651
- vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i],
652
- ctx ? ctx[i] : false, ccw);
669
+ if (!names[i]) {
670
+ vqs[i] = NULL;
671
+ continue;
672
+ }
673
+
674
+ vqs[i] = virtio_ccw_setup_vq(vdev, queue_idx++, callbacks[i],
675
+ names[i], ctx ? ctx[i] : false,
676
+ ccw);
653677 if (IS_ERR(vqs[i])) {
654678 ret = PTR_ERR(vqs[i]);
655679 vqs[i] = NULL;
....@@ -661,10 +685,11 @@
661685 * We need a data area under 2G to communicate. Our payload is
662686 * the address of the indicators.
663687 */
664
- indicatorp = kmalloc(sizeof(&vcdev->indicators), GFP_DMA | GFP_KERNEL);
688
+ indicatorp = ccw_device_dma_zalloc(vcdev->cdev,
689
+ sizeof(indicators(vcdev)));
665690 if (!indicatorp)
666691 goto out;
667
- *indicatorp = (unsigned long) &vcdev->indicators;
692
+ *indicatorp = (unsigned long) indicators(vcdev);
668693 if (vcdev->is_thinint) {
669694 ret = virtio_ccw_register_adapter_ind(vcdev, vqs, nvqs, ccw);
670695 if (ret)
....@@ -673,32 +698,36 @@
673698 }
674699 if (!vcdev->is_thinint) {
675700 /* Register queue indicators with host. */
676
- vcdev->indicators = 0;
701
+ *indicators(vcdev) = 0;
677702 ccw->cmd_code = CCW_CMD_SET_IND;
678703 ccw->flags = 0;
679
- ccw->count = sizeof(&vcdev->indicators);
704
+ ccw->count = sizeof(indicators(vcdev));
680705 ccw->cda = (__u32)(unsigned long) indicatorp;
681706 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_IND);
682707 if (ret)
683708 goto out;
684709 }
685710 /* Register indicators2 with host for config changes */
686
- *indicatorp = (unsigned long) &vcdev->indicators2;
687
- vcdev->indicators2 = 0;
711
+ *indicatorp = (unsigned long) indicators2(vcdev);
712
+ *indicators2(vcdev) = 0;
688713 ccw->cmd_code = CCW_CMD_SET_CONF_IND;
689714 ccw->flags = 0;
690
- ccw->count = sizeof(&vcdev->indicators2);
715
+ ccw->count = sizeof(indicators2(vcdev));
691716 ccw->cda = (__u32)(unsigned long) indicatorp;
692717 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_CONF_IND);
693718 if (ret)
694719 goto out;
695720
696
- kfree(indicatorp);
697
- kfree(ccw);
721
+ if (indicatorp)
722
+ ccw_device_dma_free(vcdev->cdev, indicatorp,
723
+ sizeof(indicators(vcdev)));
724
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
698725 return 0;
699726 out:
700
- kfree(indicatorp);
701
- kfree(ccw);
727
+ if (indicatorp)
728
+ ccw_device_dma_free(vcdev->cdev, indicatorp,
729
+ sizeof(indicators(vcdev)));
730
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
702731 virtio_ccw_del_vqs(vdev);
703732 return ret;
704733 }
....@@ -708,12 +737,12 @@
708737 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
709738 struct ccw1 *ccw;
710739
711
- ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
740
+ ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw));
712741 if (!ccw)
713742 return;
714743
715744 /* Zero status bits. */
716
- *vcdev->status = 0;
745
+ vcdev->dma_area->status = 0;
717746
718747 /* Send a reset ccw on device. */
719748 ccw->cmd_code = CCW_CMD_VDEV_RESET;
....@@ -721,7 +750,7 @@
721750 ccw->count = 0;
722751 ccw->cda = 0;
723752 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_RESET);
724
- kfree(ccw);
753
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
725754 }
726755
727756 static u64 virtio_ccw_get_features(struct virtio_device *vdev)
....@@ -732,11 +761,11 @@
732761 u64 rc;
733762 struct ccw1 *ccw;
734763
735
- ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
764
+ ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw));
736765 if (!ccw)
737766 return 0;
738767
739
- features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL);
768
+ features = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*features));
740769 if (!features) {
741770 rc = 0;
742771 goto out_free;
....@@ -769,9 +798,16 @@
769798 rc |= (u64)le32_to_cpu(features->features) << 32;
770799
771800 out_free:
772
- kfree(features);
773
- kfree(ccw);
801
+ ccw_device_dma_free(vcdev->cdev, features, sizeof(*features));
802
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
774803 return rc;
804
+}
805
+
806
+static void ccw_transport_features(struct virtio_device *vdev)
807
+{
808
+ /*
809
+ * Currently nothing to do here.
810
+ */
775811 }
776812
777813 static int virtio_ccw_finalize_features(struct virtio_device *vdev)
....@@ -788,17 +824,20 @@
788824 return -EINVAL;
789825 }
790826
791
- ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
827
+ ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw));
792828 if (!ccw)
793829 return -ENOMEM;
794830
795
- features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL);
831
+ features = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*features));
796832 if (!features) {
797833 ret = -ENOMEM;
798834 goto out_free;
799835 }
800836 /* Give virtio_ring a chance to accept features. */
801837 vring_transport_features(vdev);
838
+
839
+ /* Give virtio_ccw a chance to accept features. */
840
+ ccw_transport_features(vdev);
802841
803842 features->index = 0;
804843 features->features = cpu_to_le32((u32)vdev->features);
....@@ -824,8 +863,8 @@
824863 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_FEAT);
825864
826865 out_free:
827
- kfree(features);
828
- kfree(ccw);
866
+ ccw_device_dma_free(vcdev->cdev, features, sizeof(*features));
867
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
829868
830869 return ret;
831870 }
....@@ -839,11 +878,12 @@
839878 void *config_area;
840879 unsigned long flags;
841880
842
- ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
881
+ ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw));
843882 if (!ccw)
844883 return;
845884
846
- config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL);
885
+ config_area = ccw_device_dma_zalloc(vcdev->cdev,
886
+ VIRTIO_CCW_CONFIG_SIZE);
847887 if (!config_area)
848888 goto out_free;
849889
....@@ -865,8 +905,8 @@
865905 memcpy(buf, config_area + offset, len);
866906
867907 out_free:
868
- kfree(config_area);
869
- kfree(ccw);
908
+ ccw_device_dma_free(vcdev->cdev, config_area, VIRTIO_CCW_CONFIG_SIZE);
909
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
870910 }
871911
872912 static void virtio_ccw_set_config(struct virtio_device *vdev,
....@@ -878,11 +918,12 @@
878918 void *config_area;
879919 unsigned long flags;
880920
881
- ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
921
+ ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw));
882922 if (!ccw)
883923 return;
884924
885
- config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL);
925
+ config_area = ccw_device_dma_zalloc(vcdev->cdev,
926
+ VIRTIO_CCW_CONFIG_SIZE);
886927 if (!config_area)
887928 goto out_free;
888929
....@@ -901,61 +942,68 @@
901942 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_CONFIG);
902943
903944 out_free:
904
- kfree(config_area);
905
- kfree(ccw);
945
+ ccw_device_dma_free(vcdev->cdev, config_area, VIRTIO_CCW_CONFIG_SIZE);
946
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
906947 }
907948
908949 static u8 virtio_ccw_get_status(struct virtio_device *vdev)
909950 {
910951 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
911
- u8 old_status = *vcdev->status;
952
+ u8 old_status = vcdev->dma_area->status;
912953 struct ccw1 *ccw;
913954
914955 if (vcdev->revision < 2)
915
- return *vcdev->status;
956
+ return vcdev->dma_area->status;
916957
917
- ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
958
+ ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw));
918959 if (!ccw)
919960 return old_status;
920961
921962 ccw->cmd_code = CCW_CMD_READ_STATUS;
922963 ccw->flags = 0;
923
- ccw->count = sizeof(*vcdev->status);
924
- ccw->cda = (__u32)(unsigned long)vcdev->status;
964
+ ccw->count = sizeof(vcdev->dma_area->status);
965
+ ccw->cda = (__u32)(unsigned long)&vcdev->dma_area->status;
925966 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_STATUS);
926967 /*
927968 * If the channel program failed (should only happen if the device
928969 * was hotunplugged, and then we clean up via the machine check
929
- * handler anyway), vcdev->status was not overwritten and we just
970
+ * handler anyway), vcdev->dma_area->status was not overwritten and we just
930971 * return the old status, which is fine.
931972 */
932
- kfree(ccw);
973
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
933974
934
- return *vcdev->status;
975
+ return vcdev->dma_area->status;
935976 }
936977
937978 static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status)
938979 {
939980 struct virtio_ccw_device *vcdev = to_vc_device(vdev);
940
- u8 old_status = *vcdev->status;
981
+ u8 old_status = vcdev->dma_area->status;
941982 struct ccw1 *ccw;
942983 int ret;
943984
944
- ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
985
+ ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw));
945986 if (!ccw)
946987 return;
947988
948989 /* Write the status to the host. */
949
- *vcdev->status = status;
990
+ vcdev->dma_area->status = status;
950991 ccw->cmd_code = CCW_CMD_WRITE_STATUS;
951992 ccw->flags = 0;
952993 ccw->count = sizeof(status);
953
- ccw->cda = (__u32)(unsigned long)vcdev->status;
994
+ ccw->cda = (__u32)(unsigned long)&vcdev->dma_area->status;
954995 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_STATUS);
955996 /* Write failed? We assume status is unchanged. */
956997 if (ret)
957
- *vcdev->status = old_status;
958
- kfree(ccw);
998
+ vcdev->dma_area->status = old_status;
999
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
1000
+}
1001
+
1002
+static const char *virtio_ccw_bus_name(struct virtio_device *vdev)
1003
+{
1004
+ struct virtio_ccw_device *vcdev = to_vc_device(vdev);
1005
+
1006
+ return dev_name(&vcdev->cdev->dev);
9591007 }
9601008
9611009 static const struct virtio_config_ops virtio_ccw_config_ops = {
....@@ -968,6 +1016,7 @@
9681016 .reset = virtio_ccw_reset,
9691017 .find_vqs = virtio_ccw_find_vqs,
9701018 .del_vqs = virtio_ccw_del_vqs,
1019
+ .bus_name = virtio_ccw_bus_name,
9711020 };
9721021
9731022
....@@ -980,8 +1029,8 @@
9801029 struct virtio_device *dev = dev_to_virtio(_d);
9811030 struct virtio_ccw_device *vcdev = to_vc_device(dev);
9821031
983
- kfree(vcdev->status);
984
- kfree(vcdev->config_block);
1032
+ ccw_device_dma_free(vcdev->cdev, vcdev->dma_area,
1033
+ sizeof(*vcdev->dma_area));
9851034 kfree(vcdev);
9861035 }
9871036
....@@ -1079,17 +1128,17 @@
10791128 vcdev->err = -EIO;
10801129 }
10811130 virtio_ccw_check_activity(vcdev, activity);
1082
- for_each_set_bit(i, &vcdev->indicators,
1083
- sizeof(vcdev->indicators) * BITS_PER_BYTE) {
1131
+ for_each_set_bit(i, indicators(vcdev),
1132
+ sizeof(*indicators(vcdev)) * BITS_PER_BYTE) {
10841133 /* The bit clear must happen before the vring kick. */
1085
- clear_bit(i, &vcdev->indicators);
1134
+ clear_bit(i, indicators(vcdev));
10861135 barrier();
10871136 vq = virtio_ccw_vq_by_ind(vcdev, i);
10881137 vring_interrupt(0, vq);
10891138 }
1090
- if (test_bit(0, &vcdev->indicators2)) {
1139
+ if (test_bit(0, indicators2(vcdev))) {
10911140 virtio_config_changed(&vcdev->vdev);
1092
- clear_bit(0, &vcdev->indicators2);
1141
+ clear_bit(0, indicators2(vcdev));
10931142 }
10941143 }
10951144
....@@ -1189,12 +1238,12 @@
11891238 struct ccw1 *ccw;
11901239 int ret;
11911240
1192
- ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL);
1241
+ ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw));
11931242 if (!ccw)
11941243 return -ENOMEM;
1195
- rev = kzalloc(sizeof(*rev), GFP_DMA | GFP_KERNEL);
1244
+ rev = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*rev));
11961245 if (!rev) {
1197
- kfree(ccw);
1246
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
11981247 return -ENOMEM;
11991248 }
12001249
....@@ -1224,8 +1273,8 @@
12241273 }
12251274 } while (ret == -EOPNOTSUPP);
12261275
1227
- kfree(ccw);
1228
- kfree(rev);
1276
+ ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw));
1277
+ ccw_device_dma_free(vcdev->cdev, rev, sizeof(*rev));
12291278 return ret;
12301279 }
12311280
....@@ -1241,24 +1290,19 @@
12411290 ret = -ENOMEM;
12421291 goto out_free;
12431292 }
1244
- vcdev->config_block = kzalloc(sizeof(*vcdev->config_block),
1245
- GFP_DMA | GFP_KERNEL);
1246
- if (!vcdev->config_block) {
1247
- ret = -ENOMEM;
1248
- goto out_free;
1249
- }
1250
- vcdev->status = kzalloc(sizeof(*vcdev->status), GFP_DMA | GFP_KERNEL);
1251
- if (!vcdev->status) {
1293
+ vcdev->vdev.dev.parent = &cdev->dev;
1294
+ vcdev->cdev = cdev;
1295
+ vcdev->dma_area = ccw_device_dma_zalloc(vcdev->cdev,
1296
+ sizeof(*vcdev->dma_area));
1297
+ if (!vcdev->dma_area) {
12521298 ret = -ENOMEM;
12531299 goto out_free;
12541300 }
12551301
12561302 vcdev->is_thinint = virtio_ccw_use_airq; /* at least try */
12571303
1258
- vcdev->vdev.dev.parent = &cdev->dev;
12591304 vcdev->vdev.dev.release = virtio_ccw_release_dev;
12601305 vcdev->vdev.config = &virtio_ccw_config_ops;
1261
- vcdev->cdev = cdev;
12621306 init_waitqueue_head(&vcdev->wait_q);
12631307 INIT_LIST_HEAD(&vcdev->virtqueues);
12641308 spin_lock_init(&vcdev->lock);
....@@ -1289,8 +1333,8 @@
12891333 return ret;
12901334 out_free:
12911335 if (vcdev) {
1292
- kfree(vcdev->status);
1293
- kfree(vcdev->config_block);
1336
+ ccw_device_dma_free(vcdev->cdev, vcdev->dma_area,
1337
+ sizeof(*vcdev->dma_area));
12941338 }
12951339 kfree(vcdev);
12961340 return ret;
....@@ -1328,27 +1372,6 @@
13281372 {},
13291373 };
13301374
1331
-#ifdef CONFIG_PM_SLEEP
1332
-static int virtio_ccw_freeze(struct ccw_device *cdev)
1333
-{
1334
- struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
1335
-
1336
- return virtio_device_freeze(&vcdev->vdev);
1337
-}
1338
-
1339
-static int virtio_ccw_restore(struct ccw_device *cdev)
1340
-{
1341
- struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
1342
- int ret;
1343
-
1344
- ret = virtio_ccw_set_transport_rev(vcdev);
1345
- if (ret)
1346
- return ret;
1347
-
1348
- return virtio_device_restore(&vcdev->vdev);
1349
-}
1350
-#endif
1351
-
13521375 static struct ccw_driver virtio_ccw_driver = {
13531376 .driver = {
13541377 .owner = THIS_MODULE,
....@@ -1361,11 +1384,6 @@
13611384 .set_online = virtio_ccw_online,
13621385 .notify = virtio_ccw_cio_notify,
13631386 .int_class = IRQIO_VIR,
1364
-#ifdef CONFIG_PM_SLEEP
1365
- .freeze = virtio_ccw_freeze,
1366
- .thaw = virtio_ccw_restore,
1367
- .restore = virtio_ccw_restore,
1368
-#endif
13691387 };
13701388
13711389 static int __init pure_hex(char **cp, unsigned int *val, int min_digit,
....@@ -1460,8 +1478,17 @@
14601478
14611479 static int __init virtio_ccw_init(void)
14621480 {
1481
+ int rc;
1482
+
14631483 /* parse no_auto string before we do anything further */
14641484 no_auto_parse();
1465
- return ccw_driver_register(&virtio_ccw_driver);
1485
+
1486
+ summary_indicators = cio_dma_zalloc(MAX_AIRQ_AREAS);
1487
+ if (!summary_indicators)
1488
+ return -ENOMEM;
1489
+ rc = ccw_driver_register(&virtio_ccw_driver);
1490
+ if (rc)
1491
+ cio_dma_free(summary_indicators, MAX_AIRQ_AREAS);
1492
+ return rc;
14661493 }
14671494 device_initcall(virtio_ccw_init);