blk-mq-pci.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2016 Christoph Hellwig.
  4. */
  5. #include <linux/kobject.h>
  6. #include <linux/blkdev.h>
  7. #include <linux/blk-mq.h>
  8. #include <linux/blk-mq-pci.h>
  9. #include <linux/pci.h>
  10. #include <linux/module.h>
  11. #include "blk-mq.h"
  12. /**
  13. * blk_mq_pci_map_queues - provide a default queue mapping for PCI device
  14. * @qmap: CPU to hardware queue map.
  15. * @pdev: PCI device associated with @set.
  16. * @offset: Offset to use for the pci irq vector
  17. *
  18. * This function assumes the PCI device @pdev has at least as many available
  19. * interrupt vectors as @set has queues. It will then query the vector
  20. * corresponding to each queue for it's affinity mask and built queue mapping
  21. * that maps a queue to the CPUs that have irq affinity for the corresponding
  22. * vector.
  23. */
  24. int blk_mq_pci_map_queues(struct blk_mq_queue_map *qmap, struct pci_dev *pdev,
  25. int offset)
  26. {
  27. const struct cpumask *mask;
  28. unsigned int queue, cpu;
  29. for (queue = 0; queue < qmap->nr_queues; queue++) {
  30. mask = pci_irq_get_affinity(pdev, queue + offset);
  31. if (!mask)
  32. goto fallback;
  33. for_each_cpu(cpu, mask)
  34. qmap->mq_map[cpu] = qmap->queue_offset + queue;
  35. }
  36. return 0;
  37. fallback:
  38. WARN_ON_ONCE(qmap->nr_queues > 1);
  39. blk_mq_clear_mq_map(qmap);
  40. return 0;
  41. }
  42. EXPORT_SYMBOL_GPL(blk_mq_pci_map_queues);