blk-mq-pci.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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-pci.h>
  8. #include <linux/pci.h>
  9. #include <linux/module.h>
  10. #include "blk-mq.h"
  11. /**
  12. * blk_mq_pci_map_queues - provide a default queue mapping for PCI device
  13. * @qmap: CPU to hardware queue map.
  14. * @pdev: PCI device associated with @set.
  15. * @offset: Offset to use for the pci irq vector
  16. *
  17. * This function assumes the PCI device @pdev has at least as many available
  18. * interrupt vectors as @set has queues. It will then query the vector
  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. */
  23. void blk_mq_pci_map_queues(struct blk_mq_queue_map *qmap, struct pci_dev *pdev,
  24. int offset)
  25. {
  26. const struct cpumask *mask;
  27. unsigned int queue, cpu;
  28. for (queue = 0; queue < qmap->nr_queues; queue++) {
  29. mask = pci_irq_get_affinity(pdev, queue + offset);
  30. if (!mask)
  31. goto fallback;
  32. for_each_cpu(cpu, mask)
  33. qmap->mq_map[cpu] = qmap->queue_offset + queue;
  34. }
  35. return;
  36. fallback:
  37. WARN_ON_ONCE(qmap->nr_queues > 1);
  38. blk_mq_clear_mq_map(qmap);
  39. }
  40. EXPORT_SYMBOL_GPL(blk_mq_pci_map_queues);