Blame view

block/blk-mq-pci.c 1.28 KB
8c16567d8   Christoph Hellwig   block: switch all...
1
  // SPDX-License-Identifier: GPL-2.0
973c4e372   Christoph Hellwig   blk-mq: provide a...
2
3
  /*
   * Copyright (c) 2016 Christoph Hellwig.
973c4e372   Christoph Hellwig   blk-mq: provide a...
4
   */
8ec2ef2b6   Stephen Rothwell   blk_mq: linux/blk...
5
6
  #include <linux/kobject.h>
  #include <linux/blkdev.h>
973c4e372   Christoph Hellwig   blk-mq: provide a...
7
8
9
10
  #include <linux/blk-mq.h>
  #include <linux/blk-mq-pci.h>
  #include <linux/pci.h>
  #include <linux/module.h>
0da73d00c   Minwoo Im   blk-mq: code clea...
11
  #include "blk-mq.h"
973c4e372   Christoph Hellwig   blk-mq: provide a...
12
13
  /**
   * blk_mq_pci_map_queues - provide a default queue mapping for PCI device
0542cd57d   Bart Van Assche   block: Fix blk_mq...
14
   * @qmap:	CPU to hardware queue map.
973c4e372   Christoph Hellwig   blk-mq: provide a...
15
   * @pdev:	PCI device associated with @set.
f23f5bece   Keith Busch   blk-mq: Allow PCI...
16
   * @offset:	Offset to use for the pci irq vector
973c4e372   Christoph Hellwig   blk-mq: provide a...
17
18
   *
   * This function assumes the PCI device @pdev has at least as many available
018c259bb   Sagi Grimberg   blk-mq-pci: Fix t...
19
   * interrupt vectors as @set has queues.  It will then query the vector
973c4e372   Christoph Hellwig   blk-mq: provide a...
20
21
22
23
   * corresponding to each queue for it's affinity mask and built queue mapping
   * that maps a queue to the CPUs that have irq affinity for the corresponding
   * vector.
   */
ed76e329d   Jens Axboe   blk-mq: abstract ...
24
  int blk_mq_pci_map_queues(struct blk_mq_queue_map *qmap, struct pci_dev *pdev,
f23f5bece   Keith Busch   blk-mq: Allow PCI...
25
  			    int offset)
973c4e372   Christoph Hellwig   blk-mq: provide a...
26
27
28
  {
  	const struct cpumask *mask;
  	unsigned int queue, cpu;
ed76e329d   Jens Axboe   blk-mq: abstract ...
29
  	for (queue = 0; queue < qmap->nr_queues; queue++) {
f23f5bece   Keith Busch   blk-mq: Allow PCI...
30
  		mask = pci_irq_get_affinity(pdev, queue + offset);
973c4e372   Christoph Hellwig   blk-mq: provide a...
31
  		if (!mask)
c00539037   Christoph Hellwig   blk-mq-pci: add a...
32
  			goto fallback;
973c4e372   Christoph Hellwig   blk-mq: provide a...
33
34
  
  		for_each_cpu(cpu, mask)
843477d4c   Jens Axboe   blk-mq: initial s...
35
  			qmap->mq_map[cpu] = qmap->queue_offset + queue;
973c4e372   Christoph Hellwig   blk-mq: provide a...
36
37
38
  	}
  
  	return 0;
c00539037   Christoph Hellwig   blk-mq-pci: add a...
39
40
  
  fallback:
ed76e329d   Jens Axboe   blk-mq: abstract ...
41
42
  	WARN_ON_ONCE(qmap->nr_queues > 1);
  	blk_mq_clear_mq_map(qmap);
c00539037   Christoph Hellwig   blk-mq-pci: add a...
43
  	return 0;
973c4e372   Christoph Hellwig   blk-mq: provide a...
44
45
  }
  EXPORT_SYMBOL_GPL(blk_mq_pci_map_queues);