1 /* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
2 /*
3  * Copyright(c) 2015 - 2020 Intel Corporation.
4  */
5 
6 #ifndef _HFI1_AFFINITY_H
7 #define _HFI1_AFFINITY_H
8 
9 #include "hfi.h"
10 
11 enum irq_type {
12 	IRQ_SDMA,
13 	IRQ_RCVCTXT,
14 	IRQ_NETDEVCTXT,
15 	IRQ_GENERAL,
16 	IRQ_OTHER
17 };
18 
19 /* Can be used for both memory and cpu */
20 enum affinity_flags {
21 	AFF_AUTO,
22 	AFF_NUMA_LOCAL,
23 	AFF_DEV_LOCAL,
24 	AFF_IRQ_LOCAL
25 };
26 
27 struct cpu_mask_set {
28 	struct cpumask mask;
29 	struct cpumask used;
30 	uint gen;
31 };
32 
33 struct hfi1_msix_entry;
34 
35 /* Initialize non-HT cpu cores mask */
36 void init_real_cpu_mask(void);
37 /* Initialize driver affinity data */
38 int hfi1_dev_affinity_init(struct hfi1_devdata *dd);
39 /*
40  * Set IRQ affinity to a CPU. The function will determine the
41  * CPU and set the affinity to it.
42  */
43 int hfi1_get_irq_affinity(struct hfi1_devdata *dd,
44 			  struct hfi1_msix_entry *msix);
45 /*
46  * Remove the IRQ's CPU affinity. This function also updates
47  * any internal CPU tracking data
48  */
49 void hfi1_put_irq_affinity(struct hfi1_devdata *dd,
50 			   struct hfi1_msix_entry *msix);
51 /*
52  * Determine a CPU affinity for a user process, if the process does not
53  * have an affinity set yet.
54  */
55 int hfi1_get_proc_affinity(int node);
56 /* Release a CPU used by a user process. */
57 void hfi1_put_proc_affinity(int cpu);
58 
59 struct hfi1_affinity_node {
60 	int node;
61 	u16 __percpu *comp_vect_affinity;
62 	struct cpu_mask_set def_intr;
63 	struct cpu_mask_set rcv_intr;
64 	struct cpumask general_intr_mask;
65 	struct cpumask comp_vect_mask;
66 	struct list_head list;
67 };
68 
69 struct hfi1_affinity_node_list {
70 	struct list_head list;
71 	struct cpumask real_cpu_mask;
72 	struct cpu_mask_set proc;
73 	int num_core_siblings;
74 	int num_possible_nodes;
75 	int num_online_nodes;
76 	int num_online_cpus;
77 	struct mutex lock; /* protects affinity nodes */
78 };
79 
80 int node_affinity_init(void);
81 void node_affinity_destroy_all(void);
82 extern struct hfi1_affinity_node_list node_affinity;
83 void hfi1_dev_affinity_clean_up(struct hfi1_devdata *dd);
84 int hfi1_comp_vect_mappings_lookup(struct rvt_dev_info *rdi, int comp_vect);
85 int hfi1_comp_vectors_set_up(struct hfi1_devdata *dd);
86 void hfi1_comp_vectors_clean_up(struct hfi1_devdata *dd);
87 
88 #endif /* _HFI1_AFFINITY_H */
89