18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright(c) 2015 - 2020 Intel Corporation. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license. When using or 58c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * GPL LICENSE SUMMARY 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 108c2ecf20Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as 118c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but 148c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 158c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 168c2ecf20Sopenharmony_ci * General Public License for more details. 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * BSD LICENSE 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 218c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 228c2ecf20Sopenharmony_ci * are met: 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above copyright 258c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 268c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above copyright 278c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in 288c2ecf20Sopenharmony_ci * the documentation and/or other materials provided with the 298c2ecf20Sopenharmony_ci * distribution. 308c2ecf20Sopenharmony_ci * - Neither the name of Intel Corporation nor the names of its 318c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived 328c2ecf20Sopenharmony_ci * from this software without specific prior written permission. 338c2ecf20Sopenharmony_ci * 348c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 358c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 368c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 378c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 388c2ecf20Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 398c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 408c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 418c2ecf20Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 428c2ecf20Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 438c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 448c2ecf20Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 458c2ecf20Sopenharmony_ci * 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_ci#ifndef _HFI1_AFFINITY_H 488c2ecf20Sopenharmony_ci#define _HFI1_AFFINITY_H 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#include "hfi.h" 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_cienum irq_type { 538c2ecf20Sopenharmony_ci IRQ_SDMA, 548c2ecf20Sopenharmony_ci IRQ_RCVCTXT, 558c2ecf20Sopenharmony_ci IRQ_NETDEVCTXT, 568c2ecf20Sopenharmony_ci IRQ_GENERAL, 578c2ecf20Sopenharmony_ci IRQ_OTHER 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* Can be used for both memory and cpu */ 618c2ecf20Sopenharmony_cienum affinity_flags { 628c2ecf20Sopenharmony_ci AFF_AUTO, 638c2ecf20Sopenharmony_ci AFF_NUMA_LOCAL, 648c2ecf20Sopenharmony_ci AFF_DEV_LOCAL, 658c2ecf20Sopenharmony_ci AFF_IRQ_LOCAL 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistruct cpu_mask_set { 698c2ecf20Sopenharmony_ci struct cpumask mask; 708c2ecf20Sopenharmony_ci struct cpumask used; 718c2ecf20Sopenharmony_ci uint gen; 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_cistruct hfi1_msix_entry; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci/* Initialize non-HT cpu cores mask */ 778c2ecf20Sopenharmony_civoid init_real_cpu_mask(void); 788c2ecf20Sopenharmony_ci/* Initialize driver affinity data */ 798c2ecf20Sopenharmony_ciint hfi1_dev_affinity_init(struct hfi1_devdata *dd); 808c2ecf20Sopenharmony_ci/* 818c2ecf20Sopenharmony_ci * Set IRQ affinity to a CPU. The function will determine the 828c2ecf20Sopenharmony_ci * CPU and set the affinity to it. 838c2ecf20Sopenharmony_ci */ 848c2ecf20Sopenharmony_ciint hfi1_get_irq_affinity(struct hfi1_devdata *dd, 858c2ecf20Sopenharmony_ci struct hfi1_msix_entry *msix); 868c2ecf20Sopenharmony_ci/* 878c2ecf20Sopenharmony_ci * Remove the IRQ's CPU affinity. This function also updates 888c2ecf20Sopenharmony_ci * any internal CPU tracking data 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_civoid hfi1_put_irq_affinity(struct hfi1_devdata *dd, 918c2ecf20Sopenharmony_ci struct hfi1_msix_entry *msix); 928c2ecf20Sopenharmony_ci/* 938c2ecf20Sopenharmony_ci * Determine a CPU affinity for a user process, if the process does not 948c2ecf20Sopenharmony_ci * have an affinity set yet. 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ciint hfi1_get_proc_affinity(int node); 978c2ecf20Sopenharmony_ci/* Release a CPU used by a user process. */ 988c2ecf20Sopenharmony_civoid hfi1_put_proc_affinity(int cpu); 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_cistruct hfi1_affinity_node { 1018c2ecf20Sopenharmony_ci int node; 1028c2ecf20Sopenharmony_ci u16 __percpu *comp_vect_affinity; 1038c2ecf20Sopenharmony_ci struct cpu_mask_set def_intr; 1048c2ecf20Sopenharmony_ci struct cpu_mask_set rcv_intr; 1058c2ecf20Sopenharmony_ci struct cpumask general_intr_mask; 1068c2ecf20Sopenharmony_ci struct cpumask comp_vect_mask; 1078c2ecf20Sopenharmony_ci struct list_head list; 1088c2ecf20Sopenharmony_ci}; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_cistruct hfi1_affinity_node_list { 1118c2ecf20Sopenharmony_ci struct list_head list; 1128c2ecf20Sopenharmony_ci struct cpumask real_cpu_mask; 1138c2ecf20Sopenharmony_ci struct cpu_mask_set proc; 1148c2ecf20Sopenharmony_ci int num_core_siblings; 1158c2ecf20Sopenharmony_ci int num_possible_nodes; 1168c2ecf20Sopenharmony_ci int num_online_nodes; 1178c2ecf20Sopenharmony_ci int num_online_cpus; 1188c2ecf20Sopenharmony_ci struct mutex lock; /* protects affinity nodes */ 1198c2ecf20Sopenharmony_ci}; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ciint node_affinity_init(void); 1228c2ecf20Sopenharmony_civoid node_affinity_destroy_all(void); 1238c2ecf20Sopenharmony_ciextern struct hfi1_affinity_node_list node_affinity; 1248c2ecf20Sopenharmony_civoid hfi1_dev_affinity_clean_up(struct hfi1_devdata *dd); 1258c2ecf20Sopenharmony_ciint hfi1_comp_vect_mappings_lookup(struct rvt_dev_info *rdi, int comp_vect); 1268c2ecf20Sopenharmony_ciint hfi1_comp_vectors_set_up(struct hfi1_devdata *dd); 1278c2ecf20Sopenharmony_civoid hfi1_comp_vectors_clean_up(struct hfi1_devdata *dd); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#endif /* _HFI1_AFFINITY_H */ 130