1*fe267a55SPedro F. Giffuni /*- 2*fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0 3*fe267a55SPedro F. Giffuni * 4aa0a1e58SJeff Roberson * Copyright (c) 2004 Topspin Corporation. All rights reserved. 5aa0a1e58SJeff Roberson * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. 6aa0a1e58SJeff Roberson * 7aa0a1e58SJeff Roberson * This software is available to you under a choice of one of two 8aa0a1e58SJeff Roberson * licenses. You may choose to be licensed under the terms of the GNU 9aa0a1e58SJeff Roberson * General Public License (GPL) Version 2, available from the file 10aa0a1e58SJeff Roberson * COPYING in the main directory of this source tree, or the 11aa0a1e58SJeff Roberson * OpenIB.org BSD license below: 12aa0a1e58SJeff Roberson * 13aa0a1e58SJeff Roberson * Redistribution and use in source and binary forms, with or 14aa0a1e58SJeff Roberson * without modification, are permitted provided that the following 15aa0a1e58SJeff Roberson * conditions are met: 16aa0a1e58SJeff Roberson * 17aa0a1e58SJeff Roberson * - Redistributions of source code must retain the above 18aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following 19aa0a1e58SJeff Roberson * disclaimer. 20aa0a1e58SJeff Roberson * 21aa0a1e58SJeff Roberson * - Redistributions in binary form must reproduce the above 22aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following 23aa0a1e58SJeff Roberson * disclaimer in the documentation and/or other materials 24aa0a1e58SJeff Roberson * provided with the distribution. 25aa0a1e58SJeff Roberson * 26aa0a1e58SJeff Roberson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 27aa0a1e58SJeff Roberson * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28aa0a1e58SJeff Roberson * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 29aa0a1e58SJeff Roberson * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 30aa0a1e58SJeff Roberson * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 31aa0a1e58SJeff Roberson * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 32aa0a1e58SJeff Roberson * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 33aa0a1e58SJeff Roberson * SOFTWARE. 34aa0a1e58SJeff Roberson */ 35aa0a1e58SJeff Roberson 36aa0a1e58SJeff Roberson #if !defined(IB_FMR_POOL_H) 37aa0a1e58SJeff Roberson #define IB_FMR_POOL_H 38aa0a1e58SJeff Roberson 39aa0a1e58SJeff Roberson #include <rdma/ib_verbs.h> 40aa0a1e58SJeff Roberson 41aa0a1e58SJeff Roberson struct ib_fmr_pool; 42aa0a1e58SJeff Roberson 43aa0a1e58SJeff Roberson /** 44aa0a1e58SJeff Roberson * struct ib_fmr_pool_param - Parameters for creating FMR pool 45aa0a1e58SJeff Roberson * @max_pages_per_fmr:Maximum number of pages per map request. 46aa0a1e58SJeff Roberson * @page_shift: Log2 of sizeof "pages" mapped by this fmr 47aa0a1e58SJeff Roberson * @access:Access flags for FMRs in pool. 48aa0a1e58SJeff Roberson * @pool_size:Number of FMRs to allocate for pool. 49aa0a1e58SJeff Roberson * @dirty_watermark:Flush is triggered when @dirty_watermark dirty 50aa0a1e58SJeff Roberson * FMRs are present. 51aa0a1e58SJeff Roberson * @flush_function:Callback called when unmapped FMRs are flushed and 52aa0a1e58SJeff Roberson * more FMRs are possibly available for mapping 53aa0a1e58SJeff Roberson * @flush_arg:Context passed to user's flush function. 54aa0a1e58SJeff Roberson * @cache:If set, FMRs may be reused after unmapping for identical map 55aa0a1e58SJeff Roberson * requests. 56aa0a1e58SJeff Roberson */ 57aa0a1e58SJeff Roberson struct ib_fmr_pool_param { 58aa0a1e58SJeff Roberson int max_pages_per_fmr; 59aa0a1e58SJeff Roberson int page_shift; 60aa0a1e58SJeff Roberson enum ib_access_flags access; 61aa0a1e58SJeff Roberson int pool_size; 62aa0a1e58SJeff Roberson int dirty_watermark; 63aa0a1e58SJeff Roberson void (*flush_function)(struct ib_fmr_pool *pool, 64aa0a1e58SJeff Roberson void *arg); 65aa0a1e58SJeff Roberson void *flush_arg; 66aa0a1e58SJeff Roberson unsigned cache:1; 67aa0a1e58SJeff Roberson }; 68aa0a1e58SJeff Roberson 69aa0a1e58SJeff Roberson struct ib_pool_fmr { 70aa0a1e58SJeff Roberson struct ib_fmr *fmr; 71aa0a1e58SJeff Roberson struct ib_fmr_pool *pool; 72aa0a1e58SJeff Roberson struct list_head list; 73aa0a1e58SJeff Roberson struct hlist_node cache_node; 74aa0a1e58SJeff Roberson int ref_count; 75aa0a1e58SJeff Roberson int remap_count; 76aa0a1e58SJeff Roberson u64 io_virtual_address; 77aa0a1e58SJeff Roberson int page_list_len; 78aa0a1e58SJeff Roberson u64 page_list[0]; 79aa0a1e58SJeff Roberson }; 80aa0a1e58SJeff Roberson 81aa0a1e58SJeff Roberson struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd, 82aa0a1e58SJeff Roberson struct ib_fmr_pool_param *params); 83aa0a1e58SJeff Roberson 84aa0a1e58SJeff Roberson void ib_destroy_fmr_pool(struct ib_fmr_pool *pool); 85aa0a1e58SJeff Roberson 86aa0a1e58SJeff Roberson int ib_flush_fmr_pool(struct ib_fmr_pool *pool); 87aa0a1e58SJeff Roberson 88aa0a1e58SJeff Roberson struct ib_pool_fmr *ib_fmr_pool_map_phys(struct ib_fmr_pool *pool_handle, 89aa0a1e58SJeff Roberson u64 *page_list, 90aa0a1e58SJeff Roberson int list_len, 91aa0a1e58SJeff Roberson u64 io_virtual_address); 92aa0a1e58SJeff Roberson 93aa0a1e58SJeff Roberson int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr); 94aa0a1e58SJeff Roberson 95aa0a1e58SJeff Roberson #endif /* IB_FMR_POOL_H */ 96