blk-mq-rdma.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2017 Sagi Grimberg.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. */
  13. #include <linux/blk-mq.h>
  14. #include <linux/blk-mq-rdma.h>
  15. #include <rdma/ib_verbs.h>
  16. /**
  17. * blk_mq_rdma_map_queues - provide a default queue mapping for rdma device
  18. * @set: tagset to provide the mapping for
  19. * @dev: rdma device associated with @set.
  20. * @first_vec: first interrupt vectors to use for queues (usually 0)
  21. *
  22. * This function assumes the rdma device @dev has at least as many available
  23. * interrupt vetors as @set has queues. It will then query it's affinity mask
  24. * and built queue mapping that maps a queue to the CPUs that have irq affinity
  25. * for the corresponding vector.
  26. *
  27. * In case either the driver passed a @dev with less vectors than
  28. * @set->nr_hw_queues, or @dev does not provide an affinity mask for a
  29. * vector, we fallback to the naive mapping.
  30. */
  31. int blk_mq_rdma_map_queues(struct blk_mq_tag_set *set,
  32. struct ib_device *dev, int first_vec)
  33. {
  34. const struct cpumask *mask;
  35. unsigned int queue, cpu;
  36. for (queue = 0; queue < set->nr_hw_queues; queue++) {
  37. mask = ib_get_vector_affinity(dev, first_vec + queue);
  38. if (!mask)
  39. goto fallback;
  40. for_each_cpu(cpu, mask)
  41. set->mq_map[cpu] = queue;
  42. }
  43. return 0;
  44. fallback:
  45. return blk_mq_map_queues(set);
  46. }
  47. EXPORT_SYMBOL_GPL(blk_mq_rdma_map_queues);