Back to home page

LXR

 
 

    


0001 /*
0002  * Copyright (c) 2016 Christoph Hellwig.
0003  *
0004  * This program is free software; you can redistribute it and/or modify it
0005  * under the terms and conditions of the GNU General Public License,
0006  * version 2, as published by the Free Software Foundation.
0007  *
0008  * This program is distributed in the hope it will be useful, but WITHOUT
0009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0010  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
0011  * more details.
0012  */
0013 #include <linux/kobject.h>
0014 #include <linux/blkdev.h>
0015 #include <linux/blk-mq.h>
0016 #include <linux/blk-mq-pci.h>
0017 #include <linux/pci.h>
0018 #include <linux/module.h>
0019 
0020 /**
0021  * blk_mq_pci_map_queues - provide a default queue mapping for PCI device
0022  * @set:    tagset to provide the mapping for
0023  * @pdev:   PCI device associated with @set.
0024  *
0025  * This function assumes the PCI device @pdev has at least as many available
0026  * interrupt vetors as @set has queues.  It will then queuery the vector
0027  * corresponding to each queue for it's affinity mask and built queue mapping
0028  * that maps a queue to the CPUs that have irq affinity for the corresponding
0029  * vector.
0030  */
0031 int blk_mq_pci_map_queues(struct blk_mq_tag_set *set, struct pci_dev *pdev)
0032 {
0033     const struct cpumask *mask;
0034     unsigned int queue, cpu;
0035 
0036     for (queue = 0; queue < set->nr_hw_queues; queue++) {
0037         mask = pci_irq_get_affinity(pdev, queue);
0038         if (!mask)
0039             return -EINVAL;
0040 
0041         for_each_cpu(cpu, mask)
0042             set->mq_map[cpu] = queue;
0043     }
0044 
0045     return 0;
0046 }
0047 EXPORT_SYMBOL_GPL(blk_mq_pci_map_queues);