Greg Kroah-Hartman | 31fb167 | 2017-11-14 18:38:06 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 2 | /* |
| 3 | * ccw based virtio transport |
| 4 | * |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 5 | * Copyright IBM Corp. 2012, 2014 |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 6 | * |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 7 | * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com> |
| 8 | */ |
| 9 | |
| 10 | #include <linux/kernel_stat.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/bootmem.h> |
| 13 | #include <linux/err.h> |
| 14 | #include <linux/virtio.h> |
| 15 | #include <linux/virtio_config.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/virtio_ring.h> |
| 19 | #include <linux/pfn.h> |
| 20 | #include <linux/async.h> |
| 21 | #include <linux/wait.h> |
| 22 | #include <linux/list.h> |
| 23 | #include <linux/bitops.h> |
Paul Gortmaker | acc50ec | 2016-10-30 16:37:32 -0400 | [diff] [blame] | 24 | #include <linux/moduleparam.h> |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 25 | #include <linux/io.h> |
| 26 | #include <linux/kvm_para.h> |
Heinz Graalfs | e75279c | 2014-04-28 11:24:05 +0930 | [diff] [blame] | 27 | #include <linux/notifier.h> |
Martin Schwidefsky | 1ec2772 | 2015-08-20 17:28:44 +0200 | [diff] [blame] | 28 | #include <asm/diag.h> |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 29 | #include <asm/setup.h> |
| 30 | #include <asm/irq.h> |
| 31 | #include <asm/cio.h> |
| 32 | #include <asm/ccwdev.h> |
Cornelia Huck | 6a773cb | 2013-02-28 12:33:17 +0100 | [diff] [blame] | 33 | #include <asm/virtio-ccw.h> |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 34 | #include <asm/isc.h> |
| 35 | #include <asm/airq.h> |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * virtio related functions |
| 39 | */ |
| 40 | |
| 41 | struct vq_config_block { |
| 42 | __u16 index; |
| 43 | __u16 num; |
| 44 | } __packed; |
| 45 | |
| 46 | #define VIRTIO_CCW_CONFIG_SIZE 0x100 |
| 47 | /* same as PCI config space size, should be enough for all drivers */ |
| 48 | |
| 49 | struct virtio_ccw_device { |
| 50 | struct virtio_device vdev; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 51 | __u8 *status; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 52 | __u8 config[VIRTIO_CCW_CONFIG_SIZE]; |
| 53 | struct ccw_device *cdev; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 54 | __u32 curr_io; |
| 55 | int err; |
Thomas Huth | 6bb2c83 | 2014-10-07 16:39:50 +0200 | [diff] [blame] | 56 | unsigned int revision; /* Transport revision */ |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 57 | wait_queue_head_t wait_q; |
| 58 | spinlock_t lock; |
| 59 | struct list_head virtqueues; |
| 60 | unsigned long indicators; |
| 61 | unsigned long indicators2; |
| 62 | struct vq_config_block *config_block; |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 63 | bool is_thinint; |
Heinz Graalfs | 79629b2 | 2014-03-05 15:23:54 +0100 | [diff] [blame] | 64 | bool going_away; |
Heinz Graalfs | e75279c | 2014-04-28 11:24:05 +0930 | [diff] [blame] | 65 | bool device_lost; |
Cornelia Huck | 431dae7 | 2015-06-29 16:44:01 +0200 | [diff] [blame] | 66 | unsigned int config_ready; |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 67 | void *airq_info; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 68 | }; |
| 69 | |
Cornelia Huck | d467424 | 2014-10-07 16:39:51 +0200 | [diff] [blame] | 70 | struct vq_info_block_legacy { |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 71 | __u64 queue; |
| 72 | __u32 align; |
| 73 | __u16 index; |
| 74 | __u16 num; |
| 75 | } __packed; |
| 76 | |
Cornelia Huck | d467424 | 2014-10-07 16:39:51 +0200 | [diff] [blame] | 77 | struct vq_info_block { |
| 78 | __u64 desc; |
| 79 | __u32 res0; |
| 80 | __u16 index; |
| 81 | __u16 num; |
| 82 | __u64 avail; |
| 83 | __u64 used; |
| 84 | } __packed; |
| 85 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 86 | struct virtio_feature_desc { |
Heiko Carstens | fb317002 | 2017-05-09 12:50:53 +0200 | [diff] [blame] | 87 | __le32 features; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 88 | __u8 index; |
| 89 | } __packed; |
| 90 | |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 91 | struct virtio_thinint_area { |
| 92 | unsigned long summary_indicator; |
| 93 | unsigned long indicator; |
| 94 | u64 bit_nr; |
| 95 | u8 isc; |
| 96 | } __packed; |
| 97 | |
Thomas Huth | 6bb2c83 | 2014-10-07 16:39:50 +0200 | [diff] [blame] | 98 | struct virtio_rev_info { |
| 99 | __u16 revision; |
| 100 | __u16 length; |
| 101 | __u8 data[]; |
| 102 | }; |
| 103 | |
| 104 | /* the highest virtio-ccw revision we support */ |
Cornelia Huck | af9ca13 | 2014-10-07 16:39:52 +0200 | [diff] [blame] | 105 | #define VIRTIO_CCW_REV_MAX 1 |
Thomas Huth | 6bb2c83 | 2014-10-07 16:39:50 +0200 | [diff] [blame] | 106 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 107 | struct virtio_ccw_vq_info { |
| 108 | struct virtqueue *vq; |
| 109 | int num; |
| 110 | void *queue; |
Cornelia Huck | d467424 | 2014-10-07 16:39:51 +0200 | [diff] [blame] | 111 | union { |
| 112 | struct vq_info_block s; |
| 113 | struct vq_info_block_legacy l; |
| 114 | } *info_block; |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 115 | int bit_nr; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 116 | struct list_head node; |
Michael S. Tsirkin | 07e1693 | 2013-02-28 12:33:16 +0100 | [diff] [blame] | 117 | long cookie; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 118 | }; |
| 119 | |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 120 | #define VIRTIO_AIRQ_ISC IO_SCH_ISC /* inherit from subchannel */ |
| 121 | |
| 122 | #define VIRTIO_IV_BITS (L1_CACHE_BYTES * 8) |
| 123 | #define MAX_AIRQ_AREAS 20 |
| 124 | |
| 125 | static int virtio_ccw_use_airq = 1; |
| 126 | |
| 127 | struct airq_info { |
| 128 | rwlock_t lock; |
| 129 | u8 summary_indicator; |
| 130 | struct airq_struct airq; |
| 131 | struct airq_iv *aiv; |
| 132 | }; |
| 133 | static struct airq_info *airq_areas[MAX_AIRQ_AREAS]; |
| 134 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 135 | #define CCW_CMD_SET_VQ 0x13 |
| 136 | #define CCW_CMD_VDEV_RESET 0x33 |
| 137 | #define CCW_CMD_SET_IND 0x43 |
| 138 | #define CCW_CMD_SET_CONF_IND 0x53 |
| 139 | #define CCW_CMD_READ_FEAT 0x12 |
| 140 | #define CCW_CMD_WRITE_FEAT 0x11 |
| 141 | #define CCW_CMD_READ_CONF 0x22 |
| 142 | #define CCW_CMD_WRITE_CONF 0x21 |
| 143 | #define CCW_CMD_WRITE_STATUS 0x31 |
| 144 | #define CCW_CMD_READ_VQ_CONF 0x32 |
Pierre Morel | 7d3ce5a | 2015-08-28 11:09:32 +0200 | [diff] [blame] | 145 | #define CCW_CMD_READ_STATUS 0x72 |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 146 | #define CCW_CMD_SET_IND_ADAPTER 0x73 |
Thomas Huth | 6bb2c83 | 2014-10-07 16:39:50 +0200 | [diff] [blame] | 147 | #define CCW_CMD_SET_VIRTIO_REV 0x83 |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 148 | |
| 149 | #define VIRTIO_CCW_DOING_SET_VQ 0x00010000 |
| 150 | #define VIRTIO_CCW_DOING_RESET 0x00040000 |
| 151 | #define VIRTIO_CCW_DOING_READ_FEAT 0x00080000 |
| 152 | #define VIRTIO_CCW_DOING_WRITE_FEAT 0x00100000 |
| 153 | #define VIRTIO_CCW_DOING_READ_CONFIG 0x00200000 |
| 154 | #define VIRTIO_CCW_DOING_WRITE_CONFIG 0x00400000 |
| 155 | #define VIRTIO_CCW_DOING_WRITE_STATUS 0x00800000 |
| 156 | #define VIRTIO_CCW_DOING_SET_IND 0x01000000 |
| 157 | #define VIRTIO_CCW_DOING_READ_VQ_CONF 0x02000000 |
| 158 | #define VIRTIO_CCW_DOING_SET_CONF_IND 0x04000000 |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 159 | #define VIRTIO_CCW_DOING_SET_IND_ADAPTER 0x08000000 |
Thomas Huth | 6bb2c83 | 2014-10-07 16:39:50 +0200 | [diff] [blame] | 160 | #define VIRTIO_CCW_DOING_SET_VIRTIO_REV 0x10000000 |
Pierre Morel | 7d3ce5a | 2015-08-28 11:09:32 +0200 | [diff] [blame] | 161 | #define VIRTIO_CCW_DOING_READ_STATUS 0x20000000 |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 162 | #define VIRTIO_CCW_INTPARM_MASK 0xffff0000 |
| 163 | |
| 164 | static struct virtio_ccw_device *to_vc_device(struct virtio_device *vdev) |
| 165 | { |
| 166 | return container_of(vdev, struct virtio_ccw_device, vdev); |
| 167 | } |
| 168 | |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 169 | static void drop_airq_indicator(struct virtqueue *vq, struct airq_info *info) |
| 170 | { |
| 171 | unsigned long i, flags; |
| 172 | |
| 173 | write_lock_irqsave(&info->lock, flags); |
| 174 | for (i = 0; i < airq_iv_end(info->aiv); i++) { |
| 175 | if (vq == (void *)airq_iv_get_ptr(info->aiv, i)) { |
| 176 | airq_iv_free_bit(info->aiv, i); |
| 177 | airq_iv_set_ptr(info->aiv, i, 0); |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | write_unlock_irqrestore(&info->lock, flags); |
| 182 | } |
| 183 | |
| 184 | static void virtio_airq_handler(struct airq_struct *airq) |
| 185 | { |
| 186 | struct airq_info *info = container_of(airq, struct airq_info, airq); |
| 187 | unsigned long ai; |
| 188 | |
| 189 | inc_irq_stat(IRQIO_VAI); |
| 190 | read_lock(&info->lock); |
| 191 | /* Walk through indicators field, summary indicator active. */ |
| 192 | for (ai = 0;;) { |
| 193 | ai = airq_iv_scan(info->aiv, ai, airq_iv_end(info->aiv)); |
| 194 | if (ai == -1UL) |
| 195 | break; |
| 196 | vring_interrupt(0, (void *)airq_iv_get_ptr(info->aiv, ai)); |
| 197 | } |
| 198 | info->summary_indicator = 0; |
| 199 | smp_wmb(); |
| 200 | /* Walk through indicators field, summary indicator not active. */ |
| 201 | for (ai = 0;;) { |
| 202 | ai = airq_iv_scan(info->aiv, ai, airq_iv_end(info->aiv)); |
| 203 | if (ai == -1UL) |
| 204 | break; |
| 205 | vring_interrupt(0, (void *)airq_iv_get_ptr(info->aiv, ai)); |
| 206 | } |
| 207 | read_unlock(&info->lock); |
| 208 | } |
| 209 | |
| 210 | static struct airq_info *new_airq_info(void) |
| 211 | { |
| 212 | struct airq_info *info; |
| 213 | int rc; |
| 214 | |
| 215 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 216 | if (!info) |
| 217 | return NULL; |
| 218 | rwlock_init(&info->lock); |
| 219 | info->aiv = airq_iv_create(VIRTIO_IV_BITS, AIRQ_IV_ALLOC | AIRQ_IV_PTR); |
| 220 | if (!info->aiv) { |
| 221 | kfree(info); |
| 222 | return NULL; |
| 223 | } |
| 224 | info->airq.handler = virtio_airq_handler; |
| 225 | info->airq.lsi_ptr = &info->summary_indicator; |
| 226 | info->airq.lsi_mask = 0xff; |
| 227 | info->airq.isc = VIRTIO_AIRQ_ISC; |
| 228 | rc = register_adapter_interrupt(&info->airq); |
| 229 | if (rc) { |
| 230 | airq_iv_release(info->aiv); |
| 231 | kfree(info); |
| 232 | return NULL; |
| 233 | } |
| 234 | return info; |
| 235 | } |
| 236 | |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 237 | static unsigned long get_airq_indicator(struct virtqueue *vqs[], int nvqs, |
| 238 | u64 *first, void **airq_info) |
| 239 | { |
| 240 | int i, j; |
| 241 | struct airq_info *info; |
| 242 | unsigned long indicator_addr = 0; |
| 243 | unsigned long bit, flags; |
| 244 | |
| 245 | for (i = 0; i < MAX_AIRQ_AREAS && !indicator_addr; i++) { |
| 246 | if (!airq_areas[i]) |
| 247 | airq_areas[i] = new_airq_info(); |
| 248 | info = airq_areas[i]; |
| 249 | if (!info) |
| 250 | return 0; |
| 251 | write_lock_irqsave(&info->lock, flags); |
| 252 | bit = airq_iv_alloc(info->aiv, nvqs); |
| 253 | if (bit == -1UL) { |
| 254 | /* Not enough vacancies. */ |
| 255 | write_unlock_irqrestore(&info->lock, flags); |
| 256 | continue; |
| 257 | } |
| 258 | *first = bit; |
| 259 | *airq_info = info; |
| 260 | indicator_addr = (unsigned long)info->aiv->vector; |
| 261 | for (j = 0; j < nvqs; j++) { |
| 262 | airq_iv_set_ptr(info->aiv, bit + j, |
| 263 | (unsigned long)vqs[j]); |
| 264 | } |
| 265 | write_unlock_irqrestore(&info->lock, flags); |
| 266 | } |
| 267 | return indicator_addr; |
| 268 | } |
| 269 | |
| 270 | static void virtio_ccw_drop_indicators(struct virtio_ccw_device *vcdev) |
| 271 | { |
| 272 | struct virtio_ccw_vq_info *info; |
| 273 | |
| 274 | list_for_each_entry(info, &vcdev->virtqueues, node) |
| 275 | drop_airq_indicator(info->vq, vcdev->airq_info); |
| 276 | } |
| 277 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 278 | static int doing_io(struct virtio_ccw_device *vcdev, __u32 flag) |
| 279 | { |
| 280 | unsigned long flags; |
| 281 | __u32 ret; |
| 282 | |
| 283 | spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags); |
| 284 | if (vcdev->err) |
| 285 | ret = 0; |
| 286 | else |
| 287 | ret = vcdev->curr_io & flag; |
| 288 | spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags); |
| 289 | return ret; |
| 290 | } |
| 291 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 292 | static int ccw_io_helper(struct virtio_ccw_device *vcdev, |
| 293 | struct ccw1 *ccw, __u32 intparm) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 294 | { |
| 295 | int ret; |
| 296 | unsigned long flags; |
| 297 | int flag = intparm & VIRTIO_CCW_INTPARM_MASK; |
| 298 | |
Christian Borntraeger | b26ba22 | 2013-01-07 15:51:52 +0100 | [diff] [blame] | 299 | do { |
| 300 | spin_lock_irqsave(get_ccwdev_lock(vcdev->cdev), flags); |
| 301 | ret = ccw_device_start(vcdev->cdev, ccw, intparm, 0, 0); |
Cornelia Huck | 99437a2 | 2013-04-04 10:25:06 +0200 | [diff] [blame] | 302 | if (!ret) { |
| 303 | if (!vcdev->curr_io) |
| 304 | vcdev->err = 0; |
Christian Borntraeger | b26ba22 | 2013-01-07 15:51:52 +0100 | [diff] [blame] | 305 | vcdev->curr_io |= flag; |
Cornelia Huck | 99437a2 | 2013-04-04 10:25:06 +0200 | [diff] [blame] | 306 | } |
Christian Borntraeger | b26ba22 | 2013-01-07 15:51:52 +0100 | [diff] [blame] | 307 | spin_unlock_irqrestore(get_ccwdev_lock(vcdev->cdev), flags); |
| 308 | cpu_relax(); |
| 309 | } while (ret == -EBUSY); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 310 | wait_event(vcdev->wait_q, doing_io(vcdev, flag) == 0); |
| 311 | return ret ? ret : vcdev->err; |
| 312 | } |
| 313 | |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 314 | static void virtio_ccw_drop_indicator(struct virtio_ccw_device *vcdev, |
| 315 | struct ccw1 *ccw) |
| 316 | { |
| 317 | int ret; |
| 318 | unsigned long *indicatorp = NULL; |
| 319 | struct virtio_thinint_area *thinint_area = NULL; |
| 320 | struct airq_info *airq_info = vcdev->airq_info; |
| 321 | |
| 322 | if (vcdev->is_thinint) { |
| 323 | thinint_area = kzalloc(sizeof(*thinint_area), |
| 324 | GFP_DMA | GFP_KERNEL); |
| 325 | if (!thinint_area) |
| 326 | return; |
| 327 | thinint_area->summary_indicator = |
| 328 | (unsigned long) &airq_info->summary_indicator; |
| 329 | thinint_area->isc = VIRTIO_AIRQ_ISC; |
| 330 | ccw->cmd_code = CCW_CMD_SET_IND_ADAPTER; |
| 331 | ccw->count = sizeof(*thinint_area); |
| 332 | ccw->cda = (__u32)(unsigned long) thinint_area; |
| 333 | } else { |
Cornelia Huck | c235082 | 2016-03-01 13:44:53 +0100 | [diff] [blame] | 334 | /* payload is the address of the indicators */ |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 335 | indicatorp = kmalloc(sizeof(&vcdev->indicators), |
| 336 | GFP_DMA | GFP_KERNEL); |
| 337 | if (!indicatorp) |
| 338 | return; |
| 339 | *indicatorp = 0; |
| 340 | ccw->cmd_code = CCW_CMD_SET_IND; |
Cornelia Huck | c235082 | 2016-03-01 13:44:53 +0100 | [diff] [blame] | 341 | ccw->count = sizeof(&vcdev->indicators); |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 342 | ccw->cda = (__u32)(unsigned long) indicatorp; |
| 343 | } |
| 344 | /* Deregister indicators from host. */ |
| 345 | vcdev->indicators = 0; |
| 346 | ccw->flags = 0; |
| 347 | ret = ccw_io_helper(vcdev, ccw, |
| 348 | vcdev->is_thinint ? |
| 349 | VIRTIO_CCW_DOING_SET_IND_ADAPTER : |
| 350 | VIRTIO_CCW_DOING_SET_IND); |
| 351 | if (ret && (ret != -ENODEV)) |
| 352 | dev_info(&vcdev->cdev->dev, |
| 353 | "Failed to deregister indicators (%d)\n", ret); |
| 354 | else if (vcdev->is_thinint) |
| 355 | virtio_ccw_drop_indicators(vcdev); |
| 356 | kfree(indicatorp); |
| 357 | kfree(thinint_area); |
| 358 | } |
| 359 | |
Martin Schwidefsky | 1ec2772 | 2015-08-20 17:28:44 +0200 | [diff] [blame] | 360 | static inline long __do_kvm_notify(struct subchannel_id schid, |
| 361 | unsigned long queue_index, |
| 362 | long cookie) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 363 | { |
| 364 | register unsigned long __nr asm("1") = KVM_S390_VIRTIO_CCW_NOTIFY; |
| 365 | register struct subchannel_id __schid asm("2") = schid; |
| 366 | register unsigned long __index asm("3") = queue_index; |
| 367 | register long __rc asm("2"); |
Michael S. Tsirkin | 07e1693 | 2013-02-28 12:33:16 +0100 | [diff] [blame] | 368 | register long __cookie asm("4") = cookie; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 369 | |
| 370 | asm volatile ("diag 2,4,0x500\n" |
Michael S. Tsirkin | 07e1693 | 2013-02-28 12:33:16 +0100 | [diff] [blame] | 371 | : "=d" (__rc) : "d" (__nr), "d" (__schid), "d" (__index), |
| 372 | "d"(__cookie) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 373 | : "memory", "cc"); |
| 374 | return __rc; |
| 375 | } |
| 376 | |
Martin Schwidefsky | 1ec2772 | 2015-08-20 17:28:44 +0200 | [diff] [blame] | 377 | static inline long do_kvm_notify(struct subchannel_id schid, |
| 378 | unsigned long queue_index, |
| 379 | long cookie) |
| 380 | { |
| 381 | diag_stat_inc(DIAG_STAT_X500); |
| 382 | return __do_kvm_notify(schid, queue_index, cookie); |
| 383 | } |
| 384 | |
Heinz Graalfs | 46f9c2b | 2013-10-29 09:38:50 +1030 | [diff] [blame] | 385 | static bool virtio_ccw_kvm_notify(struct virtqueue *vq) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 386 | { |
| 387 | struct virtio_ccw_vq_info *info = vq->priv; |
| 388 | struct virtio_ccw_device *vcdev; |
| 389 | struct subchannel_id schid; |
| 390 | |
| 391 | vcdev = to_vc_device(info->vq->vdev); |
| 392 | ccw_device_get_schid(vcdev->cdev, &schid); |
Linus Torvalds | 01227a8 | 2013-05-05 14:47:31 -0700 | [diff] [blame] | 393 | info->cookie = do_kvm_notify(schid, vq->index, info->cookie); |
Heinz Graalfs | 46f9c2b | 2013-10-29 09:38:50 +1030 | [diff] [blame] | 394 | if (info->cookie < 0) |
| 395 | return false; |
| 396 | return true; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 397 | } |
| 398 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 399 | static int virtio_ccw_read_vq_conf(struct virtio_ccw_device *vcdev, |
| 400 | struct ccw1 *ccw, int index) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 401 | { |
Pierre Morel | ad2aa04 | 2015-09-10 16:35:08 +0200 | [diff] [blame] | 402 | int ret; |
| 403 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 404 | vcdev->config_block->index = index; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 405 | ccw->cmd_code = CCW_CMD_READ_VQ_CONF; |
| 406 | ccw->flags = 0; |
| 407 | ccw->count = sizeof(struct vq_config_block); |
| 408 | ccw->cda = (__u32)(unsigned long)(vcdev->config_block); |
Pierre Morel | ad2aa04 | 2015-09-10 16:35:08 +0200 | [diff] [blame] | 409 | ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_VQ_CONF); |
| 410 | if (ret) |
| 411 | return ret; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 412 | return vcdev->config_block->num; |
| 413 | } |
| 414 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 415 | static void virtio_ccw_del_vq(struct virtqueue *vq, struct ccw1 *ccw) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 416 | { |
| 417 | struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev); |
| 418 | struct virtio_ccw_vq_info *info = vq->priv; |
| 419 | unsigned long flags; |
| 420 | unsigned long size; |
| 421 | int ret; |
Rusty Russell | 9d0ca6e | 2013-03-21 14:17:34 +0000 | [diff] [blame] | 422 | unsigned int index = vq->index; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 423 | |
| 424 | /* Remove from our list. */ |
| 425 | spin_lock_irqsave(&vcdev->lock, flags); |
| 426 | list_del(&info->node); |
| 427 | spin_unlock_irqrestore(&vcdev->lock, flags); |
| 428 | |
| 429 | /* Release from host. */ |
Cornelia Huck | d467424 | 2014-10-07 16:39:51 +0200 | [diff] [blame] | 430 | if (vcdev->revision == 0) { |
| 431 | info->info_block->l.queue = 0; |
| 432 | info->info_block->l.align = 0; |
| 433 | info->info_block->l.index = index; |
| 434 | info->info_block->l.num = 0; |
| 435 | ccw->count = sizeof(info->info_block->l); |
| 436 | } else { |
| 437 | info->info_block->s.desc = 0; |
| 438 | info->info_block->s.index = index; |
| 439 | info->info_block->s.num = 0; |
| 440 | info->info_block->s.avail = 0; |
| 441 | info->info_block->s.used = 0; |
| 442 | ccw->count = sizeof(info->info_block->s); |
| 443 | } |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 444 | ccw->cmd_code = CCW_CMD_SET_VQ; |
| 445 | ccw->flags = 0; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 446 | ccw->cda = (__u32)(unsigned long)(info->info_block); |
| 447 | ret = ccw_io_helper(vcdev, ccw, |
| 448 | VIRTIO_CCW_DOING_SET_VQ | index); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 449 | /* |
| 450 | * -ENODEV isn't considered an error: The device is gone anyway. |
| 451 | * This may happen on device detach. |
| 452 | */ |
| 453 | if (ret && (ret != -ENODEV)) |
Colin Ian King | 9924062 | 2016-09-27 13:08:44 -0700 | [diff] [blame] | 454 | dev_warn(&vq->vdev->dev, "Error %d while deleting queue %d\n", |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 455 | ret, index); |
| 456 | |
| 457 | vring_del_virtqueue(vq); |
| 458 | size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN)); |
| 459 | free_pages_exact(info->queue, size); |
| 460 | kfree(info->info_block); |
| 461 | kfree(info); |
| 462 | } |
| 463 | |
| 464 | static void virtio_ccw_del_vqs(struct virtio_device *vdev) |
| 465 | { |
| 466 | struct virtqueue *vq, *n; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 467 | struct ccw1 *ccw; |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 468 | struct virtio_ccw_device *vcdev = to_vc_device(vdev); |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 469 | |
| 470 | ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); |
| 471 | if (!ccw) |
| 472 | return; |
| 473 | |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 474 | virtio_ccw_drop_indicator(vcdev, ccw); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 475 | |
| 476 | list_for_each_entry_safe(vq, n, &vdev->vqs, list) |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 477 | virtio_ccw_del_vq(vq, ccw); |
| 478 | |
| 479 | kfree(ccw); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev, |
| 483 | int i, vq_callback_t *callback, |
Michael S. Tsirkin | f94682d | 2017-03-06 18:32:29 +0200 | [diff] [blame] | 484 | const char *name, bool ctx, |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 485 | struct ccw1 *ccw) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 486 | { |
| 487 | struct virtio_ccw_device *vcdev = to_vc_device(vdev); |
| 488 | int err; |
Cornelia Huck | c98d368 | 2013-01-25 15:34:16 +0100 | [diff] [blame] | 489 | struct virtqueue *vq = NULL; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 490 | struct virtio_ccw_vq_info *info; |
Cornelia Huck | c98d368 | 2013-01-25 15:34:16 +0100 | [diff] [blame] | 491 | unsigned long size = 0; /* silence the compiler */ |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 492 | unsigned long flags; |
| 493 | |
| 494 | /* Allocate queue. */ |
| 495 | info = kzalloc(sizeof(struct virtio_ccw_vq_info), GFP_KERNEL); |
| 496 | if (!info) { |
| 497 | dev_warn(&vcdev->cdev->dev, "no info\n"); |
| 498 | err = -ENOMEM; |
| 499 | goto out_err; |
| 500 | } |
| 501 | info->info_block = kzalloc(sizeof(*info->info_block), |
| 502 | GFP_DMA | GFP_KERNEL); |
| 503 | if (!info->info_block) { |
| 504 | dev_warn(&vcdev->cdev->dev, "no info block\n"); |
| 505 | err = -ENOMEM; |
| 506 | goto out_err; |
| 507 | } |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 508 | info->num = virtio_ccw_read_vq_conf(vcdev, ccw, i); |
Pierre Morel | ad2aa04 | 2015-09-10 16:35:08 +0200 | [diff] [blame] | 509 | if (info->num < 0) { |
| 510 | err = info->num; |
| 511 | goto out_err; |
| 512 | } |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 513 | size = PAGE_ALIGN(vring_size(info->num, KVM_VIRTIO_CCW_RING_ALIGN)); |
| 514 | info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO); |
| 515 | if (info->queue == NULL) { |
| 516 | dev_warn(&vcdev->cdev->dev, "no queue\n"); |
| 517 | err = -ENOMEM; |
| 518 | goto out_err; |
| 519 | } |
| 520 | |
| 521 | vq = vring_new_virtqueue(i, info->num, KVM_VIRTIO_CCW_RING_ALIGN, vdev, |
Michael S. Tsirkin | f94682d | 2017-03-06 18:32:29 +0200 | [diff] [blame] | 522 | true, ctx, info->queue, virtio_ccw_kvm_notify, |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 523 | callback, name); |
| 524 | if (!vq) { |
| 525 | /* For now, we fail if we can't get the requested size. */ |
| 526 | dev_warn(&vcdev->cdev->dev, "no vq\n"); |
| 527 | err = -ENOMEM; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 528 | goto out_err; |
| 529 | } |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 530 | |
| 531 | /* Register it with the host. */ |
Cornelia Huck | d467424 | 2014-10-07 16:39:51 +0200 | [diff] [blame] | 532 | if (vcdev->revision == 0) { |
| 533 | info->info_block->l.queue = (__u64)info->queue; |
| 534 | info->info_block->l.align = KVM_VIRTIO_CCW_RING_ALIGN; |
| 535 | info->info_block->l.index = i; |
| 536 | info->info_block->l.num = info->num; |
| 537 | ccw->count = sizeof(info->info_block->l); |
| 538 | } else { |
| 539 | info->info_block->s.desc = (__u64)info->queue; |
| 540 | info->info_block->s.index = i; |
| 541 | info->info_block->s.num = info->num; |
| 542 | info->info_block->s.avail = (__u64)virtqueue_get_avail(vq); |
| 543 | info->info_block->s.used = (__u64)virtqueue_get_used(vq); |
| 544 | ccw->count = sizeof(info->info_block->s); |
| 545 | } |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 546 | ccw->cmd_code = CCW_CMD_SET_VQ; |
| 547 | ccw->flags = 0; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 548 | ccw->cda = (__u32)(unsigned long)(info->info_block); |
| 549 | err = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_VQ | i); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 550 | if (err) { |
| 551 | dev_warn(&vcdev->cdev->dev, "SET_VQ failed\n"); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 552 | goto out_err; |
| 553 | } |
| 554 | |
Cornelia Huck | c98d368 | 2013-01-25 15:34:16 +0100 | [diff] [blame] | 555 | info->vq = vq; |
| 556 | vq->priv = info; |
| 557 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 558 | /* Save it to our list. */ |
| 559 | spin_lock_irqsave(&vcdev->lock, flags); |
| 560 | list_add(&info->node, &vcdev->virtqueues); |
| 561 | spin_unlock_irqrestore(&vcdev->lock, flags); |
| 562 | |
| 563 | return vq; |
| 564 | |
| 565 | out_err: |
Cornelia Huck | c98d368 | 2013-01-25 15:34:16 +0100 | [diff] [blame] | 566 | if (vq) |
| 567 | vring_del_virtqueue(vq); |
| 568 | if (info) { |
| 569 | if (info->queue) |
| 570 | free_pages_exact(info->queue, size); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 571 | kfree(info->info_block); |
Cornelia Huck | c98d368 | 2013-01-25 15:34:16 +0100 | [diff] [blame] | 572 | } |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 573 | kfree(info); |
| 574 | return ERR_PTR(err); |
| 575 | } |
| 576 | |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 577 | static int virtio_ccw_register_adapter_ind(struct virtio_ccw_device *vcdev, |
| 578 | struct virtqueue *vqs[], int nvqs, |
| 579 | struct ccw1 *ccw) |
| 580 | { |
| 581 | int ret; |
| 582 | struct virtio_thinint_area *thinint_area = NULL; |
| 583 | struct airq_info *info; |
| 584 | |
| 585 | thinint_area = kzalloc(sizeof(*thinint_area), GFP_DMA | GFP_KERNEL); |
| 586 | if (!thinint_area) { |
| 587 | ret = -ENOMEM; |
| 588 | goto out; |
| 589 | } |
| 590 | /* Try to get an indicator. */ |
| 591 | thinint_area->indicator = get_airq_indicator(vqs, nvqs, |
| 592 | &thinint_area->bit_nr, |
| 593 | &vcdev->airq_info); |
| 594 | if (!thinint_area->indicator) { |
| 595 | ret = -ENOSPC; |
| 596 | goto out; |
| 597 | } |
| 598 | info = vcdev->airq_info; |
| 599 | thinint_area->summary_indicator = |
| 600 | (unsigned long) &info->summary_indicator; |
| 601 | thinint_area->isc = VIRTIO_AIRQ_ISC; |
| 602 | ccw->cmd_code = CCW_CMD_SET_IND_ADAPTER; |
| 603 | ccw->flags = CCW_FLAG_SLI; |
| 604 | ccw->count = sizeof(*thinint_area); |
| 605 | ccw->cda = (__u32)(unsigned long)thinint_area; |
| 606 | ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_IND_ADAPTER); |
| 607 | if (ret) { |
| 608 | if (ret == -EOPNOTSUPP) { |
| 609 | /* |
| 610 | * The host does not support adapter interrupts |
| 611 | * for virtio-ccw, stop trying. |
| 612 | */ |
| 613 | virtio_ccw_use_airq = 0; |
| 614 | pr_info("Adapter interrupts unsupported on host\n"); |
| 615 | } else |
| 616 | dev_warn(&vcdev->cdev->dev, |
| 617 | "enabling adapter interrupts = %d\n", ret); |
| 618 | virtio_ccw_drop_indicators(vcdev); |
| 619 | } |
| 620 | out: |
| 621 | kfree(thinint_area); |
| 622 | return ret; |
| 623 | } |
| 624 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 625 | static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned nvqs, |
| 626 | struct virtqueue *vqs[], |
| 627 | vq_callback_t *callbacks[], |
Christoph Hellwig | fb5e31d | 2017-02-05 18:15:22 +0100 | [diff] [blame] | 628 | const char * const names[], |
Michael S. Tsirkin | f94682d | 2017-03-06 18:32:29 +0200 | [diff] [blame] | 629 | const bool *ctx, |
Christoph Hellwig | fb5e31d | 2017-02-05 18:15:22 +0100 | [diff] [blame] | 630 | struct irq_affinity *desc) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 631 | { |
| 632 | struct virtio_ccw_device *vcdev = to_vc_device(vdev); |
| 633 | unsigned long *indicatorp = NULL; |
| 634 | int ret, i; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 635 | struct ccw1 *ccw; |
| 636 | |
| 637 | ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); |
| 638 | if (!ccw) |
| 639 | return -ENOMEM; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 640 | |
| 641 | for (i = 0; i < nvqs; ++i) { |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 642 | vqs[i] = virtio_ccw_setup_vq(vdev, i, callbacks[i], names[i], |
Michael S. Tsirkin | f94682d | 2017-03-06 18:32:29 +0200 | [diff] [blame] | 643 | ctx ? ctx[i] : false, ccw); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 644 | if (IS_ERR(vqs[i])) { |
| 645 | ret = PTR_ERR(vqs[i]); |
| 646 | vqs[i] = NULL; |
| 647 | goto out; |
| 648 | } |
| 649 | } |
| 650 | ret = -ENOMEM; |
Cornelia Huck | c235082 | 2016-03-01 13:44:53 +0100 | [diff] [blame] | 651 | /* |
| 652 | * We need a data area under 2G to communicate. Our payload is |
| 653 | * the address of the indicators. |
| 654 | */ |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 655 | indicatorp = kmalloc(sizeof(&vcdev->indicators), GFP_DMA | GFP_KERNEL); |
| 656 | if (!indicatorp) |
| 657 | goto out; |
| 658 | *indicatorp = (unsigned long) &vcdev->indicators; |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 659 | if (vcdev->is_thinint) { |
| 660 | ret = virtio_ccw_register_adapter_ind(vcdev, vqs, nvqs, ccw); |
| 661 | if (ret) |
| 662 | /* no error, just fall back to legacy interrupts */ |
Heiko Carstens | 970ba6ac | 2017-01-02 09:59:40 +0100 | [diff] [blame] | 663 | vcdev->is_thinint = false; |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 664 | } |
| 665 | if (!vcdev->is_thinint) { |
| 666 | /* Register queue indicators with host. */ |
| 667 | vcdev->indicators = 0; |
| 668 | ccw->cmd_code = CCW_CMD_SET_IND; |
| 669 | ccw->flags = 0; |
Cornelia Huck | c235082 | 2016-03-01 13:44:53 +0100 | [diff] [blame] | 670 | ccw->count = sizeof(&vcdev->indicators); |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 671 | ccw->cda = (__u32)(unsigned long) indicatorp; |
| 672 | ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_IND); |
| 673 | if (ret) |
| 674 | goto out; |
| 675 | } |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 676 | /* Register indicators2 with host for config changes */ |
| 677 | *indicatorp = (unsigned long) &vcdev->indicators2; |
| 678 | vcdev->indicators2 = 0; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 679 | ccw->cmd_code = CCW_CMD_SET_CONF_IND; |
| 680 | ccw->flags = 0; |
Cornelia Huck | c235082 | 2016-03-01 13:44:53 +0100 | [diff] [blame] | 681 | ccw->count = sizeof(&vcdev->indicators2); |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 682 | ccw->cda = (__u32)(unsigned long) indicatorp; |
| 683 | ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_SET_CONF_IND); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 684 | if (ret) |
| 685 | goto out; |
| 686 | |
| 687 | kfree(indicatorp); |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 688 | kfree(ccw); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 689 | return 0; |
| 690 | out: |
| 691 | kfree(indicatorp); |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 692 | kfree(ccw); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 693 | virtio_ccw_del_vqs(vdev); |
| 694 | return ret; |
| 695 | } |
| 696 | |
| 697 | static void virtio_ccw_reset(struct virtio_device *vdev) |
| 698 | { |
| 699 | struct virtio_ccw_device *vcdev = to_vc_device(vdev); |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 700 | struct ccw1 *ccw; |
| 701 | |
| 702 | ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); |
| 703 | if (!ccw) |
| 704 | return; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 705 | |
| 706 | /* Zero status bits. */ |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 707 | *vcdev->status = 0; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 708 | |
| 709 | /* Send a reset ccw on device. */ |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 710 | ccw->cmd_code = CCW_CMD_VDEV_RESET; |
| 711 | ccw->flags = 0; |
| 712 | ccw->count = 0; |
| 713 | ccw->cda = 0; |
| 714 | ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_RESET); |
| 715 | kfree(ccw); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 716 | } |
| 717 | |
Michael S. Tsirkin | d025477 | 2014-10-07 16:39:43 +0200 | [diff] [blame] | 718 | static u64 virtio_ccw_get_features(struct virtio_device *vdev) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 719 | { |
| 720 | struct virtio_ccw_device *vcdev = to_vc_device(vdev); |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 721 | struct virtio_feature_desc *features; |
Michael S. Tsirkin | 732c56e | 2014-11-27 13:54:28 +0200 | [diff] [blame] | 722 | int ret; |
| 723 | u64 rc; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 724 | struct ccw1 *ccw; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 725 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 726 | ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); |
| 727 | if (!ccw) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 728 | return 0; |
| 729 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 730 | features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL); |
| 731 | if (!features) { |
| 732 | rc = 0; |
| 733 | goto out_free; |
| 734 | } |
| 735 | /* Read the feature bits from the host. */ |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 736 | features->index = 0; |
| 737 | ccw->cmd_code = CCW_CMD_READ_FEAT; |
| 738 | ccw->flags = 0; |
| 739 | ccw->count = sizeof(*features); |
| 740 | ccw->cda = (__u32)(unsigned long)features; |
| 741 | ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_FEAT); |
| 742 | if (ret) { |
| 743 | rc = 0; |
| 744 | goto out_free; |
| 745 | } |
| 746 | |
| 747 | rc = le32_to_cpu(features->features); |
| 748 | |
Michael S. Tsirkin | ce15408 | 2014-12-04 18:59:50 +0200 | [diff] [blame] | 749 | if (vcdev->revision == 0) |
| 750 | goto out_free; |
| 751 | |
Michael S. Tsirkin | 732c56e | 2014-11-27 13:54:28 +0200 | [diff] [blame] | 752 | /* Read second half of the feature bits from the host. */ |
| 753 | features->index = 1; |
| 754 | ccw->cmd_code = CCW_CMD_READ_FEAT; |
| 755 | ccw->flags = 0; |
| 756 | ccw->count = sizeof(*features); |
| 757 | ccw->cda = (__u32)(unsigned long)features; |
| 758 | ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_FEAT); |
| 759 | if (ret == 0) |
| 760 | rc |= (u64)le32_to_cpu(features->features) << 32; |
| 761 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 762 | out_free: |
| 763 | kfree(features); |
| 764 | kfree(ccw); |
| 765 | return rc; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 766 | } |
| 767 | |
Michael S. Tsirkin | 5c609a5 | 2014-12-04 20:20:27 +0200 | [diff] [blame] | 768 | static int virtio_ccw_finalize_features(struct virtio_device *vdev) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 769 | { |
| 770 | struct virtio_ccw_device *vcdev = to_vc_device(vdev); |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 771 | struct virtio_feature_desc *features; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 772 | struct ccw1 *ccw; |
Cornelia Huck | f01a2a8 | 2014-12-09 11:46:59 +0100 | [diff] [blame] | 773 | int ret; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 774 | |
Michael S. Tsirkin | f13d8bc | 2014-12-09 14:46:44 +0200 | [diff] [blame] | 775 | if (vcdev->revision >= 1 && |
Michael S. Tsirkin | 4d23676 | 2014-12-04 19:16:43 +0200 | [diff] [blame] | 776 | !__virtio_test_bit(vdev, VIRTIO_F_VERSION_1)) { |
| 777 | dev_err(&vdev->dev, "virtio: device uses revision 1 " |
| 778 | "but does not have VIRTIO_F_VERSION_1\n"); |
| 779 | return -EINVAL; |
| 780 | } |
| 781 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 782 | ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); |
| 783 | if (!ccw) |
Cornelia Huck | f01a2a8 | 2014-12-09 11:46:59 +0100 | [diff] [blame] | 784 | return -ENOMEM; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 785 | |
| 786 | features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL); |
Cornelia Huck | f01a2a8 | 2014-12-09 11:46:59 +0100 | [diff] [blame] | 787 | if (!features) { |
| 788 | ret = -ENOMEM; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 789 | goto out_free; |
Cornelia Huck | f01a2a8 | 2014-12-09 11:46:59 +0100 | [diff] [blame] | 790 | } |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 791 | /* Give virtio_ring a chance to accept features. */ |
| 792 | vring_transport_features(vdev); |
| 793 | |
Michael S. Tsirkin | e16e12b | 2014-10-07 16:39:42 +0200 | [diff] [blame] | 794 | features->index = 0; |
Michael S. Tsirkin | 732c56e | 2014-11-27 13:54:28 +0200 | [diff] [blame] | 795 | features->features = cpu_to_le32((u32)vdev->features); |
| 796 | /* Write the first half of the feature bits to the host. */ |
| 797 | ccw->cmd_code = CCW_CMD_WRITE_FEAT; |
| 798 | ccw->flags = 0; |
| 799 | ccw->count = sizeof(*features); |
| 800 | ccw->cda = (__u32)(unsigned long)features; |
Cornelia Huck | f01a2a8 | 2014-12-09 11:46:59 +0100 | [diff] [blame] | 801 | ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_FEAT); |
| 802 | if (ret) |
| 803 | goto out_free; |
Michael S. Tsirkin | 732c56e | 2014-11-27 13:54:28 +0200 | [diff] [blame] | 804 | |
Michael S. Tsirkin | ce15408 | 2014-12-04 18:59:50 +0200 | [diff] [blame] | 805 | if (vcdev->revision == 0) |
| 806 | goto out_free; |
| 807 | |
Michael S. Tsirkin | 732c56e | 2014-11-27 13:54:28 +0200 | [diff] [blame] | 808 | features->index = 1; |
| 809 | features->features = cpu_to_le32(vdev->features >> 32); |
| 810 | /* Write the second half of the feature bits to the host. */ |
Michael S. Tsirkin | e16e12b | 2014-10-07 16:39:42 +0200 | [diff] [blame] | 811 | ccw->cmd_code = CCW_CMD_WRITE_FEAT; |
| 812 | ccw->flags = 0; |
| 813 | ccw->count = sizeof(*features); |
| 814 | ccw->cda = (__u32)(unsigned long)features; |
Cornelia Huck | f01a2a8 | 2014-12-09 11:46:59 +0100 | [diff] [blame] | 815 | ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_FEAT); |
Michael S. Tsirkin | e16e12b | 2014-10-07 16:39:42 +0200 | [diff] [blame] | 816 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 817 | out_free: |
| 818 | kfree(features); |
| 819 | kfree(ccw); |
Michael S. Tsirkin | 5c609a5 | 2014-12-04 20:20:27 +0200 | [diff] [blame] | 820 | |
Cornelia Huck | f01a2a8 | 2014-12-09 11:46:59 +0100 | [diff] [blame] | 821 | return ret; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | static void virtio_ccw_get_config(struct virtio_device *vdev, |
| 825 | unsigned int offset, void *buf, unsigned len) |
| 826 | { |
| 827 | struct virtio_ccw_device *vcdev = to_vc_device(vdev); |
| 828 | int ret; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 829 | struct ccw1 *ccw; |
| 830 | void *config_area; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 831 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 832 | ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); |
| 833 | if (!ccw) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 834 | return; |
| 835 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 836 | config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL); |
| 837 | if (!config_area) |
| 838 | goto out_free; |
| 839 | |
| 840 | /* Read the config area from the host. */ |
| 841 | ccw->cmd_code = CCW_CMD_READ_CONF; |
| 842 | ccw->flags = 0; |
| 843 | ccw->count = offset + len; |
| 844 | ccw->cda = (__u32)(unsigned long)config_area; |
| 845 | ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_CONFIG); |
| 846 | if (ret) |
| 847 | goto out_free; |
| 848 | |
Cornelia Huck | 431dae7 | 2015-06-29 16:44:01 +0200 | [diff] [blame] | 849 | memcpy(vcdev->config, config_area, offset + len); |
| 850 | if (buf) |
| 851 | memcpy(buf, &vcdev->config[offset], len); |
| 852 | if (vcdev->config_ready < offset + len) |
| 853 | vcdev->config_ready = offset + len; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 854 | |
| 855 | out_free: |
| 856 | kfree(config_area); |
| 857 | kfree(ccw); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static void virtio_ccw_set_config(struct virtio_device *vdev, |
| 861 | unsigned int offset, const void *buf, |
| 862 | unsigned len) |
| 863 | { |
| 864 | struct virtio_ccw_device *vcdev = to_vc_device(vdev); |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 865 | struct ccw1 *ccw; |
| 866 | void *config_area; |
| 867 | |
| 868 | ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); |
| 869 | if (!ccw) |
| 870 | return; |
| 871 | |
| 872 | config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL); |
| 873 | if (!config_area) |
| 874 | goto out_free; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 875 | |
Cornelia Huck | 431dae7 | 2015-06-29 16:44:01 +0200 | [diff] [blame] | 876 | /* Make sure we don't overwrite fields. */ |
| 877 | if (vcdev->config_ready < offset) |
| 878 | virtio_ccw_get_config(vdev, 0, NULL, offset); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 879 | memcpy(&vcdev->config[offset], buf, len); |
| 880 | /* Write the config area to the host. */ |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 881 | memcpy(config_area, vcdev->config, sizeof(vcdev->config)); |
| 882 | ccw->cmd_code = CCW_CMD_WRITE_CONF; |
| 883 | ccw->flags = 0; |
| 884 | ccw->count = offset + len; |
| 885 | ccw->cda = (__u32)(unsigned long)config_area; |
| 886 | ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_CONFIG); |
| 887 | |
| 888 | out_free: |
| 889 | kfree(config_area); |
| 890 | kfree(ccw); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | static u8 virtio_ccw_get_status(struct virtio_device *vdev) |
| 894 | { |
| 895 | struct virtio_ccw_device *vcdev = to_vc_device(vdev); |
Pierre Morel | 7d3ce5a | 2015-08-28 11:09:32 +0200 | [diff] [blame] | 896 | u8 old_status = *vcdev->status; |
| 897 | struct ccw1 *ccw; |
| 898 | |
| 899 | if (vcdev->revision < 1) |
| 900 | return *vcdev->status; |
| 901 | |
| 902 | ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); |
| 903 | if (!ccw) |
| 904 | return old_status; |
| 905 | |
| 906 | ccw->cmd_code = CCW_CMD_READ_STATUS; |
| 907 | ccw->flags = 0; |
| 908 | ccw->count = sizeof(*vcdev->status); |
| 909 | ccw->cda = (__u32)(unsigned long)vcdev->status; |
| 910 | ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_STATUS); |
| 911 | /* |
| 912 | * If the channel program failed (should only happen if the device |
| 913 | * was hotunplugged, and then we clean up via the machine check |
| 914 | * handler anyway), vcdev->status was not overwritten and we just |
| 915 | * return the old status, which is fine. |
| 916 | */ |
| 917 | kfree(ccw); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 918 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 919 | return *vcdev->status; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status) |
| 923 | { |
| 924 | struct virtio_ccw_device *vcdev = to_vc_device(vdev); |
Michael S. Tsirkin | 4855513 | 2014-10-23 18:40:30 +0300 | [diff] [blame] | 925 | u8 old_status = *vcdev->status; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 926 | struct ccw1 *ccw; |
Michael S. Tsirkin | 4855513 | 2014-10-23 18:40:30 +0300 | [diff] [blame] | 927 | int ret; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 928 | |
| 929 | ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); |
| 930 | if (!ccw) |
| 931 | return; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 932 | |
| 933 | /* Write the status to the host. */ |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 934 | *vcdev->status = status; |
| 935 | ccw->cmd_code = CCW_CMD_WRITE_STATUS; |
| 936 | ccw->flags = 0; |
| 937 | ccw->count = sizeof(status); |
| 938 | ccw->cda = (__u32)(unsigned long)vcdev->status; |
Michael S. Tsirkin | 4855513 | 2014-10-23 18:40:30 +0300 | [diff] [blame] | 939 | ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_STATUS); |
| 940 | /* Write failed? We assume status is unchanged. */ |
| 941 | if (ret) |
| 942 | *vcdev->status = old_status; |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 943 | kfree(ccw); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 944 | } |
| 945 | |
Bhumika Goyal | 0db1dba | 2017-01-14 00:18:56 +0530 | [diff] [blame] | 946 | static const struct virtio_config_ops virtio_ccw_config_ops = { |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 947 | .get_features = virtio_ccw_get_features, |
| 948 | .finalize_features = virtio_ccw_finalize_features, |
| 949 | .get = virtio_ccw_get_config, |
| 950 | .set = virtio_ccw_set_config, |
| 951 | .get_status = virtio_ccw_get_status, |
| 952 | .set_status = virtio_ccw_set_status, |
| 953 | .reset = virtio_ccw_reset, |
| 954 | .find_vqs = virtio_ccw_find_vqs, |
| 955 | .del_vqs = virtio_ccw_del_vqs, |
| 956 | }; |
| 957 | |
| 958 | |
| 959 | /* |
| 960 | * ccw bus driver related functions |
| 961 | */ |
| 962 | |
| 963 | static void virtio_ccw_release_dev(struct device *_d) |
| 964 | { |
Geliang Tang | 15e90f5 | 2016-03-01 13:44:52 +0100 | [diff] [blame] | 965 | struct virtio_device *dev = dev_to_virtio(_d); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 966 | struct virtio_ccw_device *vcdev = to_vc_device(dev); |
| 967 | |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 968 | kfree(vcdev->status); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 969 | kfree(vcdev->config_block); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 970 | kfree(vcdev); |
| 971 | } |
| 972 | |
| 973 | static int irb_is_error(struct irb *irb) |
| 974 | { |
| 975 | if (scsw_cstat(&irb->scsw) != 0) |
| 976 | return 1; |
| 977 | if (scsw_dstat(&irb->scsw) & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) |
| 978 | return 1; |
| 979 | if (scsw_cc(&irb->scsw) != 0) |
| 980 | return 1; |
| 981 | return 0; |
| 982 | } |
| 983 | |
| 984 | static struct virtqueue *virtio_ccw_vq_by_ind(struct virtio_ccw_device *vcdev, |
| 985 | int index) |
| 986 | { |
| 987 | struct virtio_ccw_vq_info *info; |
| 988 | unsigned long flags; |
| 989 | struct virtqueue *vq; |
| 990 | |
| 991 | vq = NULL; |
| 992 | spin_lock_irqsave(&vcdev->lock, flags); |
| 993 | list_for_each_entry(info, &vcdev->virtqueues, node) { |
Rusty Russell | 9d0ca6e | 2013-03-21 14:17:34 +0000 | [diff] [blame] | 994 | if (info->vq->index == index) { |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 995 | vq = info->vq; |
| 996 | break; |
| 997 | } |
| 998 | } |
| 999 | spin_unlock_irqrestore(&vcdev->lock, flags); |
| 1000 | return vq; |
| 1001 | } |
| 1002 | |
Cornelia Huck | 74a599f | 2015-12-03 17:24:00 +0100 | [diff] [blame] | 1003 | static void virtio_ccw_check_activity(struct virtio_ccw_device *vcdev, |
| 1004 | __u32 activity) |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1005 | { |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1006 | if (vcdev->curr_io & activity) { |
| 1007 | switch (activity) { |
| 1008 | case VIRTIO_CCW_DOING_READ_FEAT: |
| 1009 | case VIRTIO_CCW_DOING_WRITE_FEAT: |
| 1010 | case VIRTIO_CCW_DOING_READ_CONFIG: |
| 1011 | case VIRTIO_CCW_DOING_WRITE_CONFIG: |
| 1012 | case VIRTIO_CCW_DOING_WRITE_STATUS: |
Pierre Morel | 7d3ce5a | 2015-08-28 11:09:32 +0200 | [diff] [blame] | 1013 | case VIRTIO_CCW_DOING_READ_STATUS: |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1014 | case VIRTIO_CCW_DOING_SET_VQ: |
| 1015 | case VIRTIO_CCW_DOING_SET_IND: |
| 1016 | case VIRTIO_CCW_DOING_SET_CONF_IND: |
| 1017 | case VIRTIO_CCW_DOING_RESET: |
| 1018 | case VIRTIO_CCW_DOING_READ_VQ_CONF: |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 1019 | case VIRTIO_CCW_DOING_SET_IND_ADAPTER: |
Thomas Huth | 6bb2c83 | 2014-10-07 16:39:50 +0200 | [diff] [blame] | 1020 | case VIRTIO_CCW_DOING_SET_VIRTIO_REV: |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1021 | vcdev->curr_io &= ~activity; |
| 1022 | wake_up(&vcdev->wait_q); |
| 1023 | break; |
| 1024 | default: |
| 1025 | /* don't know what to do... */ |
Cornelia Huck | 74a599f | 2015-12-03 17:24:00 +0100 | [diff] [blame] | 1026 | dev_warn(&vcdev->cdev->dev, |
| 1027 | "Suspicious activity '%08x'\n", activity); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1028 | WARN_ON(1); |
| 1029 | break; |
| 1030 | } |
| 1031 | } |
Cornelia Huck | 74a599f | 2015-12-03 17:24:00 +0100 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | static void virtio_ccw_int_handler(struct ccw_device *cdev, |
| 1035 | unsigned long intparm, |
| 1036 | struct irb *irb) |
| 1037 | { |
| 1038 | __u32 activity = intparm & VIRTIO_CCW_INTPARM_MASK; |
| 1039 | struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev); |
| 1040 | int i; |
| 1041 | struct virtqueue *vq; |
| 1042 | |
| 1043 | if (!vcdev) |
| 1044 | return; |
| 1045 | if (IS_ERR(irb)) { |
| 1046 | vcdev->err = PTR_ERR(irb); |
| 1047 | virtio_ccw_check_activity(vcdev, activity); |
| 1048 | /* Don't poke around indicators, something's wrong. */ |
| 1049 | return; |
| 1050 | } |
| 1051 | /* Check if it's a notification from the host. */ |
| 1052 | if ((intparm == 0) && |
| 1053 | (scsw_stctl(&irb->scsw) == |
| 1054 | (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))) { |
| 1055 | /* OK */ |
| 1056 | } |
| 1057 | if (irb_is_error(irb)) { |
| 1058 | /* Command reject? */ |
| 1059 | if ((scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) && |
| 1060 | (irb->ecw[0] & SNS0_CMD_REJECT)) |
| 1061 | vcdev->err = -EOPNOTSUPP; |
| 1062 | else |
| 1063 | /* Map everything else to -EIO. */ |
| 1064 | vcdev->err = -EIO; |
| 1065 | } |
| 1066 | virtio_ccw_check_activity(vcdev, activity); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1067 | for_each_set_bit(i, &vcdev->indicators, |
| 1068 | sizeof(vcdev->indicators) * BITS_PER_BYTE) { |
| 1069 | /* The bit clear must happen before the vring kick. */ |
| 1070 | clear_bit(i, &vcdev->indicators); |
| 1071 | barrier(); |
| 1072 | vq = virtio_ccw_vq_by_ind(vcdev, i); |
| 1073 | vring_interrupt(0, vq); |
| 1074 | } |
| 1075 | if (test_bit(0, &vcdev->indicators2)) { |
Michael S. Tsirkin | 016c98c | 2014-10-14 10:40:34 +1030 | [diff] [blame] | 1076 | virtio_config_changed(&vcdev->vdev); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1077 | clear_bit(0, &vcdev->indicators2); |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | /* |
| 1082 | * We usually want to autoonline all devices, but give the admin |
| 1083 | * a way to exempt devices from this. |
| 1084 | */ |
| 1085 | #define __DEV_WORDS ((__MAX_SUBCHANNEL + (8*sizeof(long) - 1)) / \ |
| 1086 | (8*sizeof(long))) |
| 1087 | static unsigned long devs_no_auto[__MAX_SSID + 1][__DEV_WORDS]; |
| 1088 | |
| 1089 | static char *no_auto = ""; |
| 1090 | |
| 1091 | module_param(no_auto, charp, 0444); |
| 1092 | MODULE_PARM_DESC(no_auto, "list of ccw bus id ranges not to be auto-onlined"); |
| 1093 | |
| 1094 | static int virtio_ccw_check_autoonline(struct ccw_device *cdev) |
| 1095 | { |
| 1096 | struct ccw_dev_id id; |
| 1097 | |
| 1098 | ccw_device_get_id(cdev, &id); |
| 1099 | if (test_bit(id.devno, devs_no_auto[id.ssid])) |
| 1100 | return 0; |
| 1101 | return 1; |
| 1102 | } |
| 1103 | |
| 1104 | static void virtio_ccw_auto_online(void *data, async_cookie_t cookie) |
| 1105 | { |
| 1106 | struct ccw_device *cdev = data; |
| 1107 | int ret; |
| 1108 | |
| 1109 | ret = ccw_device_set_online(cdev); |
| 1110 | if (ret) |
| 1111 | dev_warn(&cdev->dev, "Failed to set online: %d\n", ret); |
| 1112 | } |
| 1113 | |
| 1114 | static int virtio_ccw_probe(struct ccw_device *cdev) |
| 1115 | { |
| 1116 | cdev->handler = virtio_ccw_int_handler; |
| 1117 | |
| 1118 | if (virtio_ccw_check_autoonline(cdev)) |
| 1119 | async_schedule(virtio_ccw_auto_online, cdev); |
| 1120 | return 0; |
| 1121 | } |
| 1122 | |
Heinz Graalfs | 2e02104 | 2014-02-27 14:34:35 +0100 | [diff] [blame] | 1123 | static struct virtio_ccw_device *virtio_grab_drvdata(struct ccw_device *cdev) |
| 1124 | { |
| 1125 | unsigned long flags; |
| 1126 | struct virtio_ccw_device *vcdev; |
| 1127 | |
| 1128 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 1129 | vcdev = dev_get_drvdata(&cdev->dev); |
Heinz Graalfs | 79629b2 | 2014-03-05 15:23:54 +0100 | [diff] [blame] | 1130 | if (!vcdev || vcdev->going_away) { |
Heinz Graalfs | 2e02104 | 2014-02-27 14:34:35 +0100 | [diff] [blame] | 1131 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 1132 | return NULL; |
| 1133 | } |
Heinz Graalfs | 79629b2 | 2014-03-05 15:23:54 +0100 | [diff] [blame] | 1134 | vcdev->going_away = true; |
Heinz Graalfs | 2e02104 | 2014-02-27 14:34:35 +0100 | [diff] [blame] | 1135 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 1136 | return vcdev; |
| 1137 | } |
| 1138 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1139 | static void virtio_ccw_remove(struct ccw_device *cdev) |
| 1140 | { |
Heinz Graalfs | 79629b2 | 2014-03-05 15:23:54 +0100 | [diff] [blame] | 1141 | unsigned long flags; |
Heinz Graalfs | 2e02104 | 2014-02-27 14:34:35 +0100 | [diff] [blame] | 1142 | struct virtio_ccw_device *vcdev = virtio_grab_drvdata(cdev); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1143 | |
Heinz Graalfs | e75279c | 2014-04-28 11:24:05 +0930 | [diff] [blame] | 1144 | if (vcdev && cdev->online) { |
| 1145 | if (vcdev->device_lost) |
| 1146 | virtio_break_device(&vcdev->vdev); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1147 | unregister_virtio_device(&vcdev->vdev); |
Heinz Graalfs | e75279c | 2014-04-28 11:24:05 +0930 | [diff] [blame] | 1148 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 1149 | dev_set_drvdata(&cdev->dev, NULL); |
| 1150 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
| 1151 | } |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1152 | cdev->handler = NULL; |
| 1153 | } |
| 1154 | |
| 1155 | static int virtio_ccw_offline(struct ccw_device *cdev) |
| 1156 | { |
Heinz Graalfs | 79629b2 | 2014-03-05 15:23:54 +0100 | [diff] [blame] | 1157 | unsigned long flags; |
Heinz Graalfs | 2e02104 | 2014-02-27 14:34:35 +0100 | [diff] [blame] | 1158 | struct virtio_ccw_device *vcdev = virtio_grab_drvdata(cdev); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1159 | |
Heinz Graalfs | e75279c | 2014-04-28 11:24:05 +0930 | [diff] [blame] | 1160 | if (!vcdev) |
| 1161 | return 0; |
| 1162 | if (vcdev->device_lost) |
| 1163 | virtio_break_device(&vcdev->vdev); |
| 1164 | unregister_virtio_device(&vcdev->vdev); |
| 1165 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
| 1166 | dev_set_drvdata(&cdev->dev, NULL); |
| 1167 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1168 | return 0; |
| 1169 | } |
| 1170 | |
Thomas Huth | 6bb2c83 | 2014-10-07 16:39:50 +0200 | [diff] [blame] | 1171 | static int virtio_ccw_set_transport_rev(struct virtio_ccw_device *vcdev) |
| 1172 | { |
| 1173 | struct virtio_rev_info *rev; |
| 1174 | struct ccw1 *ccw; |
| 1175 | int ret; |
| 1176 | |
| 1177 | ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); |
| 1178 | if (!ccw) |
| 1179 | return -ENOMEM; |
| 1180 | rev = kzalloc(sizeof(*rev), GFP_DMA | GFP_KERNEL); |
| 1181 | if (!rev) { |
| 1182 | kfree(ccw); |
| 1183 | return -ENOMEM; |
| 1184 | } |
| 1185 | |
| 1186 | /* Set transport revision */ |
| 1187 | ccw->cmd_code = CCW_CMD_SET_VIRTIO_REV; |
| 1188 | ccw->flags = 0; |
| 1189 | ccw->count = sizeof(*rev); |
| 1190 | ccw->cda = (__u32)(unsigned long)rev; |
| 1191 | |
| 1192 | vcdev->revision = VIRTIO_CCW_REV_MAX; |
| 1193 | do { |
| 1194 | rev->revision = vcdev->revision; |
| 1195 | /* none of our supported revisions carry payload */ |
| 1196 | rev->length = 0; |
| 1197 | ret = ccw_io_helper(vcdev, ccw, |
| 1198 | VIRTIO_CCW_DOING_SET_VIRTIO_REV); |
| 1199 | if (ret == -EOPNOTSUPP) { |
| 1200 | if (vcdev->revision == 0) |
| 1201 | /* |
| 1202 | * The host device does not support setting |
| 1203 | * the revision: let's operate it in legacy |
| 1204 | * mode. |
| 1205 | */ |
| 1206 | ret = 0; |
| 1207 | else |
| 1208 | vcdev->revision--; |
| 1209 | } |
| 1210 | } while (ret == -EOPNOTSUPP); |
| 1211 | |
| 1212 | kfree(ccw); |
| 1213 | kfree(rev); |
| 1214 | return ret; |
| 1215 | } |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1216 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1217 | static int virtio_ccw_online(struct ccw_device *cdev) |
| 1218 | { |
| 1219 | int ret; |
| 1220 | struct virtio_ccw_device *vcdev; |
Heinz Graalfs | 2e02104 | 2014-02-27 14:34:35 +0100 | [diff] [blame] | 1221 | unsigned long flags; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1222 | |
| 1223 | vcdev = kzalloc(sizeof(*vcdev), GFP_KERNEL); |
| 1224 | if (!vcdev) { |
| 1225 | dev_warn(&cdev->dev, "Could not get memory for virtio\n"); |
| 1226 | ret = -ENOMEM; |
| 1227 | goto out_free; |
| 1228 | } |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1229 | vcdev->config_block = kzalloc(sizeof(*vcdev->config_block), |
| 1230 | GFP_DMA | GFP_KERNEL); |
| 1231 | if (!vcdev->config_block) { |
| 1232 | ret = -ENOMEM; |
| 1233 | goto out_free; |
| 1234 | } |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 1235 | vcdev->status = kzalloc(sizeof(*vcdev->status), GFP_DMA | GFP_KERNEL); |
| 1236 | if (!vcdev->status) { |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1237 | ret = -ENOMEM; |
| 1238 | goto out_free; |
| 1239 | } |
| 1240 | |
Cornelia Huck | 96b1453 | 2013-02-06 10:23:39 +0100 | [diff] [blame] | 1241 | vcdev->is_thinint = virtio_ccw_use_airq; /* at least try */ |
| 1242 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1243 | vcdev->vdev.dev.parent = &cdev->dev; |
| 1244 | vcdev->vdev.dev.release = virtio_ccw_release_dev; |
| 1245 | vcdev->vdev.config = &virtio_ccw_config_ops; |
| 1246 | vcdev->cdev = cdev; |
| 1247 | init_waitqueue_head(&vcdev->wait_q); |
| 1248 | INIT_LIST_HEAD(&vcdev->virtqueues); |
| 1249 | spin_lock_init(&vcdev->lock); |
| 1250 | |
Heinz Graalfs | 2e02104 | 2014-02-27 14:34:35 +0100 | [diff] [blame] | 1251 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1252 | dev_set_drvdata(&cdev->dev, vcdev); |
Heinz Graalfs | 2e02104 | 2014-02-27 14:34:35 +0100 | [diff] [blame] | 1253 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1254 | vcdev->vdev.id.vendor = cdev->id.cu_type; |
| 1255 | vcdev->vdev.id.device = cdev->id.cu_model; |
Thomas Huth | 6bb2c83 | 2014-10-07 16:39:50 +0200 | [diff] [blame] | 1256 | |
Michael S. Tsirkin | 2003a7a | 2015-04-15 10:17:44 +0930 | [diff] [blame] | 1257 | ret = virtio_ccw_set_transport_rev(vcdev); |
| 1258 | if (ret) |
| 1259 | goto out_free; |
Thomas Huth | 6bb2c83 | 2014-10-07 16:39:50 +0200 | [diff] [blame] | 1260 | |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1261 | ret = register_virtio_device(&vcdev->vdev); |
| 1262 | if (ret) { |
| 1263 | dev_warn(&cdev->dev, "Failed to register virtio device: %d\n", |
| 1264 | ret); |
| 1265 | goto out_put; |
| 1266 | } |
| 1267 | return 0; |
| 1268 | out_put: |
Heinz Graalfs | 2e02104 | 2014-02-27 14:34:35 +0100 | [diff] [blame] | 1269 | spin_lock_irqsave(get_ccwdev_lock(cdev), flags); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1270 | dev_set_drvdata(&cdev->dev, NULL); |
Heinz Graalfs | 2e02104 | 2014-02-27 14:34:35 +0100 | [diff] [blame] | 1271 | spin_unlock_irqrestore(get_ccwdev_lock(cdev), flags); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1272 | put_device(&vcdev->vdev.dev); |
| 1273 | return ret; |
| 1274 | out_free: |
| 1275 | if (vcdev) { |
Cornelia Huck | 73fa21e | 2013-01-07 15:51:51 +0100 | [diff] [blame] | 1276 | kfree(vcdev->status); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1277 | kfree(vcdev->config_block); |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1278 | } |
| 1279 | kfree(vcdev); |
| 1280 | return ret; |
| 1281 | } |
| 1282 | |
| 1283 | static int virtio_ccw_cio_notify(struct ccw_device *cdev, int event) |
| 1284 | { |
Heinz Graalfs | e75279c | 2014-04-28 11:24:05 +0930 | [diff] [blame] | 1285 | int rc; |
| 1286 | struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev); |
| 1287 | |
| 1288 | /* |
| 1289 | * Make sure vcdev is set |
| 1290 | * i.e. set_offline/remove callback not already running |
| 1291 | */ |
| 1292 | if (!vcdev) |
| 1293 | return NOTIFY_DONE; |
| 1294 | |
| 1295 | switch (event) { |
| 1296 | case CIO_GONE: |
| 1297 | vcdev->device_lost = true; |
| 1298 | rc = NOTIFY_DONE; |
| 1299 | break; |
| 1300 | default: |
| 1301 | rc = NOTIFY_DONE; |
| 1302 | break; |
| 1303 | } |
| 1304 | return rc; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | static struct ccw_device_id virtio_ids[] = { |
| 1308 | { CCW_DEVICE(0x3832, 0) }, |
| 1309 | {}, |
| 1310 | }; |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1311 | |
| 1312 | static struct ccw_driver virtio_ccw_driver = { |
| 1313 | .driver = { |
| 1314 | .owner = THIS_MODULE, |
| 1315 | .name = "virtio_ccw", |
| 1316 | }, |
| 1317 | .ids = virtio_ids, |
| 1318 | .probe = virtio_ccw_probe, |
| 1319 | .remove = virtio_ccw_remove, |
| 1320 | .set_offline = virtio_ccw_offline, |
| 1321 | .set_online = virtio_ccw_online, |
| 1322 | .notify = virtio_ccw_cio_notify, |
Linus Torvalds | 89f8833 | 2013-02-24 13:07:18 -0800 | [diff] [blame] | 1323 | .int_class = IRQIO_VIR, |
Cornelia Huck | 7e64e05 | 2012-12-14 17:02:18 +0100 | [diff] [blame] | 1324 | }; |
| 1325 | |
| 1326 | static int __init pure_hex(char **cp, unsigned int *val, int min_digit, |
| 1327 | int max_digit, int max_val) |
| 1328 | { |
| 1329 | int diff; |
| 1330 | |
| 1331 | diff = 0; |
| 1332 | *val = 0; |
| 1333 | |
| 1334 | while (diff <= max_digit) { |
| 1335 | int value = hex_to_bin(**cp); |
| 1336 | |
| 1337 | if (value < 0) |
| 1338 | break; |
| 1339 | *val = *val * 16 + value; |
| 1340 | (*cp)++; |
| 1341 | diff++; |
| 1342 | } |
| 1343 | |
| 1344 | if ((diff < min_digit) || (diff > max_digit) || (*val > max_val)) |
| 1345 | return 1; |
| 1346 | |
| 1347 | return 0; |
| 1348 | } |
| 1349 | |
| 1350 | static int __init parse_busid(char *str, unsigned int *cssid, |
| 1351 | unsigned int *ssid, unsigned int *devno) |
| 1352 | { |
| 1353 | char *str_work; |
| 1354 | int rc, ret; |
| 1355 | |
| 1356 | rc = 1; |
| 1357 | |
| 1358 | if (*str == '\0') |
| 1359 | goto out; |
| 1360 | |
| 1361 | str_work = str; |
| 1362 | ret = pure_hex(&str_work, cssid, 1, 2, __MAX_CSSID); |
| 1363 | if (ret || (str_work[0] != '.')) |
| 1364 | goto out; |
| 1365 | str_work++; |
| 1366 | ret = pure_hex(&str_work, ssid, 1, 1, __MAX_SSID); |
| 1367 | if (ret || (str_work[0] != '.')) |
| 1368 | goto out; |
| 1369 | str_work++; |
| 1370 | ret = pure_hex(&str_work, devno, 4, 4, __MAX_SUBCHANNEL); |
| 1371 | if (ret || (str_work[0] != '\0')) |
| 1372 | goto out; |
| 1373 | |
| 1374 | rc = 0; |
| 1375 | out: |
| 1376 | return rc; |
| 1377 | } |
| 1378 | |
| 1379 | static void __init no_auto_parse(void) |
| 1380 | { |
| 1381 | unsigned int from_cssid, to_cssid, from_ssid, to_ssid, from, to; |
| 1382 | char *parm, *str; |
| 1383 | int rc; |
| 1384 | |
| 1385 | str = no_auto; |
| 1386 | while ((parm = strsep(&str, ","))) { |
| 1387 | rc = parse_busid(strsep(&parm, "-"), &from_cssid, |
| 1388 | &from_ssid, &from); |
| 1389 | if (rc) |
| 1390 | continue; |
| 1391 | if (parm != NULL) { |
| 1392 | rc = parse_busid(parm, &to_cssid, |
| 1393 | &to_ssid, &to); |
| 1394 | if ((from_ssid > to_ssid) || |
| 1395 | ((from_ssid == to_ssid) && (from > to))) |
| 1396 | rc = -EINVAL; |
| 1397 | } else { |
| 1398 | to_cssid = from_cssid; |
| 1399 | to_ssid = from_ssid; |
| 1400 | to = from; |
| 1401 | } |
| 1402 | if (rc) |
| 1403 | continue; |
| 1404 | while ((from_ssid < to_ssid) || |
| 1405 | ((from_ssid == to_ssid) && (from <= to))) { |
| 1406 | set_bit(from, devs_no_auto[from_ssid]); |
| 1407 | from++; |
| 1408 | if (from > __MAX_SUBCHANNEL) { |
| 1409 | from_ssid++; |
| 1410 | from = 0; |
| 1411 | } |
| 1412 | } |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | static int __init virtio_ccw_init(void) |
| 1417 | { |
| 1418 | /* parse no_auto string before we do anything further */ |
| 1419 | no_auto_parse(); |
| 1420 | return ccw_driver_register(&virtio_ccw_driver); |
| 1421 | } |
Paul Gortmaker | acc50ec | 2016-10-30 16:37:32 -0400 | [diff] [blame] | 1422 | device_initcall(virtio_ccw_init); |