Christoph Hellwig | 8c16567 | 2019-04-30 14:42:39 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Sagi Grimberg | 24c5dc6 | 2017-07-13 11:09:43 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Sagi Grimberg. |
Sagi Grimberg | 24c5dc6 | 2017-07-13 11:09:43 +0300 | [diff] [blame] | 4 | */ |
| 5 | #include <linux/blk-mq.h> |
| 6 | #include <linux/blk-mq-rdma.h> |
| 7 | #include <rdma/ib_verbs.h> |
| 8 | |
| 9 | /** |
| 10 | * blk_mq_rdma_map_queues - provide a default queue mapping for rdma device |
Bart Van Assche | 0542cd5 | 2019-05-30 17:00:49 -0700 | [diff] [blame] | 11 | * @map: CPU to hardware queue map. |
| 12 | * @dev: rdma device to provide a mapping for. |
Sagi Grimberg | 24c5dc6 | 2017-07-13 11:09:43 +0300 | [diff] [blame] | 13 | * @first_vec: first interrupt vectors to use for queues (usually 0) |
| 14 | * |
| 15 | * This function assumes the rdma device @dev has at least as many available |
| 16 | * interrupt vetors as @set has queues. It will then query it's affinity mask |
| 17 | * and built queue mapping that maps a queue to the CPUs that have irq affinity |
| 18 | * for the corresponding vector. |
| 19 | * |
| 20 | * In case either the driver passed a @dev with less vectors than |
| 21 | * @set->nr_hw_queues, or @dev does not provide an affinity mask for a |
| 22 | * vector, we fallback to the naive mapping. |
| 23 | */ |
Sagi Grimberg | e42b386 | 2018-12-11 23:38:54 -0800 | [diff] [blame] | 24 | int blk_mq_rdma_map_queues(struct blk_mq_queue_map *map, |
Sagi Grimberg | 24c5dc6 | 2017-07-13 11:09:43 +0300 | [diff] [blame] | 25 | struct ib_device *dev, int first_vec) |
| 26 | { |
| 27 | const struct cpumask *mask; |
| 28 | unsigned int queue, cpu; |
| 29 | |
Sagi Grimberg | e42b386 | 2018-12-11 23:38:54 -0800 | [diff] [blame] | 30 | for (queue = 0; queue < map->nr_queues; queue++) { |
Sagi Grimberg | 24c5dc6 | 2017-07-13 11:09:43 +0300 | [diff] [blame] | 31 | mask = ib_get_vector_affinity(dev, first_vec + queue); |
| 32 | if (!mask) |
| 33 | goto fallback; |
| 34 | |
| 35 | for_each_cpu(cpu, mask) |
Sagi Grimberg | e42b386 | 2018-12-11 23:38:54 -0800 | [diff] [blame] | 36 | map->mq_map[cpu] = map->queue_offset + queue; |
Sagi Grimberg | 24c5dc6 | 2017-07-13 11:09:43 +0300 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | |
| 41 | fallback: |
Sagi Grimberg | e42b386 | 2018-12-11 23:38:54 -0800 | [diff] [blame] | 42 | return blk_mq_map_queues(map); |
Sagi Grimberg | 24c5dc6 | 2017-07-13 11:09:43 +0300 | [diff] [blame] | 43 | } |
| 44 | EXPORT_SYMBOL_GPL(blk_mq_rdma_map_queues); |