···11+/*22+ * Copyright (c) 2016 Christoph Hellwig.33+ *44+ * This program is free software; you can redistribute it and/or modify it55+ * under the terms and conditions of the GNU General Public License,66+ * version 2, as published by the Free Software Foundation.77+ *88+ * This program is distributed in the hope it will be useful, but WITHOUT99+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or1010+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for1111+ * more details.1212+ */1313+#include <linux/blk-mq.h>1414+#include <linux/blk-mq-pci.h>1515+#include <linux/pci.h>1616+#include <linux/module.h>1717+1818+/**1919+ * blk_mq_pci_map_queues - provide a default queue mapping for PCI device2020+ * @set: tagset to provide the mapping for2121+ * @pdev: PCI device associated with @set.2222+ *2323+ * This function assumes the PCI device @pdev has at least as many available2424+ * interrupt vetors as @set has queues. It will then queuery the vector2525+ * corresponding to each queue for it's affinity mask and built queue mapping2626+ * that maps a queue to the CPUs that have irq affinity for the corresponding2727+ * vector.2828+ */2929+int blk_mq_pci_map_queues(struct blk_mq_tag_set *set, struct pci_dev *pdev)3030+{3131+ const struct cpumask *mask;3232+ unsigned int queue, cpu;3333+3434+ for (queue = 0; queue < set->nr_hw_queues; queue++) {3535+ mask = pci_irq_get_affinity(pdev, queue);3636+ if (!mask)3737+ return -EINVAL;3838+3939+ for_each_cpu(cpu, mask)4040+ set->mq_map[cpu] = queue;4141+ }4242+4343+ return 0;4444+}4545+EXPORT_SYMBOL_GPL(blk_mq_pci_map_queues);