Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (c) 2016 Christoph Hellwig.
0004  */
0005 #include <linux/kobject.h>
0006 #include <linux/blkdev.h>
0007 #include <linux/blk-mq.h>
0008 #include <linux/blk-mq-pci.h>
0009 #include <linux/pci.h>
0010 #include <linux/module.h>
0011 
0012 #include "blk-mq.h"
0013 
0014 /**
0015  * blk_mq_pci_map_queues - provide a default queue mapping for PCI device
0016  * @qmap:   CPU to hardware queue map.
0017  * @pdev:   PCI device associated with @set.
0018  * @offset: Offset to use for the pci irq vector
0019  *
0020  * This function assumes the PCI device @pdev has at least as many available
0021  * interrupt vectors as @set has queues.  It will then query the vector
0022  * corresponding to each queue for it's affinity mask and built queue mapping
0023  * that maps a queue to the CPUs that have irq affinity for the corresponding
0024  * vector.
0025  */
0026 int blk_mq_pci_map_queues(struct blk_mq_queue_map *qmap, struct pci_dev *pdev,
0027                 int offset)
0028 {
0029     const struct cpumask *mask;
0030     unsigned int queue, cpu;
0031 
0032     for (queue = 0; queue < qmap->nr_queues; queue++) {
0033         mask = pci_irq_get_affinity(pdev, queue + offset);
0034         if (!mask)
0035             goto fallback;
0036 
0037         for_each_cpu(cpu, mask)
0038             qmap->mq_map[cpu] = qmap->queue_offset + queue;
0039     }
0040 
0041     return 0;
0042 
0043 fallback:
0044     WARN_ON_ONCE(qmap->nr_queues > 1);
0045     blk_mq_clear_mq_map(qmap);
0046     return 0;
0047 }
0048 EXPORT_SYMBOL_GPL(blk_mq_pci_map_queues);