]>
Commit | Line | Data |
---|---|---|
8c16567d | 1 | // SPDX-License-Identifier: GPL-2.0 |
73473427 CH |
2 | /* |
3 | * Copyright (c) 2016 Christoph Hellwig. | |
73473427 CH |
4 | */ |
5 | #include <linux/device.h> | |
73473427 CH |
6 | #include <linux/blk-mq-virtio.h> |
7 | #include <linux/virtio_config.h> | |
8 | #include <linux/module.h> | |
9 | #include "blk-mq.h" | |
10 | ||
11 | /** | |
12 | * blk_mq_virtio_map_queues - provide a default queue mapping for virtio device | |
0542cd57 BVA |
13 | * @qmap: CPU to hardware queue map. |
14 | * @vdev: virtio device to provide a mapping for. | |
73473427 CH |
15 | * @first_vec: first interrupt vectors to use for queues (usually 0) |
16 | * | |
17 | * This function assumes the virtio device @vdev has at least as many available | |
7901b6e4 | 18 | * interrupt vectors as @set has queues. It will then query the vector |
73473427 CH |
19 | * corresponding to each queue for it's affinity mask and built queue mapping |
20 | * that maps a queue to the CPUs that have irq affinity for the corresponding | |
21 | * vector. | |
22 | */ | |
a4e1d0b7 | 23 | void blk_mq_virtio_map_queues(struct blk_mq_queue_map *qmap, |
73473427 CH |
24 | struct virtio_device *vdev, int first_vec) |
25 | { | |
26 | const struct cpumask *mask; | |
27 | unsigned int queue, cpu; | |
28 | ||
29 | if (!vdev->config->get_vq_affinity) | |
30 | goto fallback; | |
31 | ||
ed76e329 | 32 | for (queue = 0; queue < qmap->nr_queues; queue++) { |
73473427 CH |
33 | mask = vdev->config->get_vq_affinity(vdev, first_vec + queue); |
34 | if (!mask) | |
35 | goto fallback; | |
36 | ||
37 | for_each_cpu(cpu, mask) | |
843477d4 | 38 | qmap->mq_map[cpu] = qmap->queue_offset + queue; |
73473427 CH |
39 | } |
40 | ||
a4e1d0b7 BVA |
41 | return; |
42 | ||
73473427 | 43 | fallback: |
a4e1d0b7 | 44 | blk_mq_map_queues(qmap); |
73473427 CH |
45 | } |
46 | EXPORT_SYMBOL_GPL(blk_mq_virtio_map_queues); |