18c2ecf20Sopenharmony_ci#ifndef _HFI1_USER_EXP_RCV_H 28c2ecf20Sopenharmony_ci#define _HFI1_USER_EXP_RCV_H 38c2ecf20Sopenharmony_ci/* 48c2ecf20Sopenharmony_ci * Copyright(c) 2020 - Cornelis Networks, Inc. 58c2ecf20Sopenharmony_ci * Copyright(c) 2015 - 2017 Intel Corporation. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license. When using or 88c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * GPL LICENSE SUMMARY 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 138c2ecf20Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as 148c2ecf20Sopenharmony_ci * published by the Free Software Foundation. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but 178c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of 188c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 198c2ecf20Sopenharmony_ci * General Public License for more details. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * BSD LICENSE 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 248c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 258c2ecf20Sopenharmony_ci * are met: 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * - Redistributions of source code must retain the above copyright 288c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 298c2ecf20Sopenharmony_ci * - Redistributions in binary form must reproduce the above copyright 308c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in 318c2ecf20Sopenharmony_ci * the documentation and/or other materials provided with the 328c2ecf20Sopenharmony_ci * distribution. 338c2ecf20Sopenharmony_ci * - Neither the name of Intel Corporation nor the names of its 348c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived 358c2ecf20Sopenharmony_ci * from this software without specific prior written permission. 368c2ecf20Sopenharmony_ci * 378c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 388c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 398c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 408c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 418c2ecf20Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 428c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 438c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 448c2ecf20Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 458c2ecf20Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 468c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 478c2ecf20Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 488c2ecf20Sopenharmony_ci * 498c2ecf20Sopenharmony_ci */ 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#include "hfi.h" 528c2ecf20Sopenharmony_ci#include "exp_rcv.h" 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_cistruct tid_pageset { 558c2ecf20Sopenharmony_ci u16 idx; 568c2ecf20Sopenharmony_ci u16 count; 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_cistruct tid_user_buf { 608c2ecf20Sopenharmony_ci struct mmu_interval_notifier notifier; 618c2ecf20Sopenharmony_ci struct mutex cover_mutex; 628c2ecf20Sopenharmony_ci unsigned long vaddr; 638c2ecf20Sopenharmony_ci unsigned long length; 648c2ecf20Sopenharmony_ci unsigned int npages; 658c2ecf20Sopenharmony_ci struct page **pages; 668c2ecf20Sopenharmony_ci struct tid_pageset *psets; 678c2ecf20Sopenharmony_ci unsigned int n_psets; 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistruct tid_rb_node { 718c2ecf20Sopenharmony_ci struct mmu_interval_notifier notifier; 728c2ecf20Sopenharmony_ci struct hfi1_filedata *fdata; 738c2ecf20Sopenharmony_ci struct mutex invalidate_mutex; /* covers hw removal */ 748c2ecf20Sopenharmony_ci unsigned long phys; 758c2ecf20Sopenharmony_ci struct tid_group *grp; 768c2ecf20Sopenharmony_ci u32 rcventry; 778c2ecf20Sopenharmony_ci dma_addr_t dma_addr; 788c2ecf20Sopenharmony_ci bool freed; 798c2ecf20Sopenharmony_ci unsigned int npages; 808c2ecf20Sopenharmony_ci struct page *pages[]; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistatic inline int num_user_pages(unsigned long addr, 848c2ecf20Sopenharmony_ci unsigned long len) 858c2ecf20Sopenharmony_ci{ 868c2ecf20Sopenharmony_ci const unsigned long spage = addr & PAGE_MASK; 878c2ecf20Sopenharmony_ci const unsigned long epage = (addr + len - 1) & PAGE_MASK; 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci return 1 + ((epage - spage) >> PAGE_SHIFT); 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ciint hfi1_user_exp_rcv_init(struct hfi1_filedata *fd, 938c2ecf20Sopenharmony_ci struct hfi1_ctxtdata *uctxt); 948c2ecf20Sopenharmony_civoid hfi1_user_exp_rcv_free(struct hfi1_filedata *fd); 958c2ecf20Sopenharmony_ciint hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd, 968c2ecf20Sopenharmony_ci struct hfi1_tid_info *tinfo); 978c2ecf20Sopenharmony_ciint hfi1_user_exp_rcv_clear(struct hfi1_filedata *fd, 988c2ecf20Sopenharmony_ci struct hfi1_tid_info *tinfo); 998c2ecf20Sopenharmony_ciint hfi1_user_exp_rcv_invalid(struct hfi1_filedata *fd, 1008c2ecf20Sopenharmony_ci struct hfi1_tid_info *tinfo); 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic inline struct mm_struct *mm_from_tid_node(struct tid_rb_node *node) 1038c2ecf20Sopenharmony_ci{ 1048c2ecf20Sopenharmony_ci return node->notifier.mm; 1058c2ecf20Sopenharmony_ci} 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#endif /* _HFI1_USER_EXP_RCV_H */ 108