1f6df683fSsantosh.shilimkar@oracle.com /* 2f6df683fSsantosh.shilimkar@oracle.com * Copyright (c) 2016 Oracle. All rights reserved. 3f6df683fSsantosh.shilimkar@oracle.com * 4f6df683fSsantosh.shilimkar@oracle.com * This software is available to you under a choice of one of two 5f6df683fSsantosh.shilimkar@oracle.com * licenses. You may choose to be licensed under the terms of the GNU 6f6df683fSsantosh.shilimkar@oracle.com * General Public License (GPL) Version 2, available from the file 7f6df683fSsantosh.shilimkar@oracle.com * COPYING in the main directory of this source tree, or the 8f6df683fSsantosh.shilimkar@oracle.com * OpenIB.org BSD license below: 9f6df683fSsantosh.shilimkar@oracle.com * 10f6df683fSsantosh.shilimkar@oracle.com * Redistribution and use in source and binary forms, with or 11f6df683fSsantosh.shilimkar@oracle.com * without modification, are permitted provided that the following 12f6df683fSsantosh.shilimkar@oracle.com * conditions are met: 13f6df683fSsantosh.shilimkar@oracle.com * 14f6df683fSsantosh.shilimkar@oracle.com * - Redistributions of source code must retain the above 15f6df683fSsantosh.shilimkar@oracle.com * copyright notice, this list of conditions and the following 16f6df683fSsantosh.shilimkar@oracle.com * disclaimer. 17f6df683fSsantosh.shilimkar@oracle.com * 18f6df683fSsantosh.shilimkar@oracle.com * - Redistributions in binary form must reproduce the above 19f6df683fSsantosh.shilimkar@oracle.com * copyright notice, this list of conditions and the following 20f6df683fSsantosh.shilimkar@oracle.com * disclaimer in the documentation and/or other materials 21f6df683fSsantosh.shilimkar@oracle.com * provided with the distribution. 22f6df683fSsantosh.shilimkar@oracle.com * 23f6df683fSsantosh.shilimkar@oracle.com * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24f6df683fSsantosh.shilimkar@oracle.com * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25f6df683fSsantosh.shilimkar@oracle.com * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26f6df683fSsantosh.shilimkar@oracle.com * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27f6df683fSsantosh.shilimkar@oracle.com * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28f6df683fSsantosh.shilimkar@oracle.com * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29f6df683fSsantosh.shilimkar@oracle.com * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30f6df683fSsantosh.shilimkar@oracle.com * SOFTWARE. 31f6df683fSsantosh.shilimkar@oracle.com */ 32f6df683fSsantosh.shilimkar@oracle.com #ifndef _RDS_IB_MR_H 33f6df683fSsantosh.shilimkar@oracle.com #define _RDS_IB_MR_H 34f6df683fSsantosh.shilimkar@oracle.com 35f6df683fSsantosh.shilimkar@oracle.com #include <linux/kernel.h> 36f6df683fSsantosh.shilimkar@oracle.com 37f6df683fSsantosh.shilimkar@oracle.com #include "rds.h" 38f6df683fSsantosh.shilimkar@oracle.com #include "ib.h" 39f6df683fSsantosh.shilimkar@oracle.com 40f6df683fSsantosh.shilimkar@oracle.com #define RDS_MR_1M_POOL_SIZE (8192 / 2) 41f6df683fSsantosh.shilimkar@oracle.com #define RDS_MR_1M_MSG_SIZE 256 42f6df683fSsantosh.shilimkar@oracle.com #define RDS_MR_8K_MSG_SIZE 2 43f6df683fSsantosh.shilimkar@oracle.com #define RDS_MR_8K_SCALE (256 / (RDS_MR_8K_MSG_SIZE + 1)) 44f6df683fSsantosh.shilimkar@oracle.com #define RDS_MR_8K_POOL_SIZE (RDS_MR_8K_SCALE * (8192 / 2)) 45f6df683fSsantosh.shilimkar@oracle.com 461659185fSAvinash Repaka enum rds_ib_fr_state { 471659185fSAvinash Repaka FRMR_IS_FREE, /* mr invalidated & ready for use */ 481659185fSAvinash Repaka FRMR_IS_INUSE, /* mr is in use or used & can be invalidated */ 491659185fSAvinash Repaka FRMR_IS_STALE, /* Stale MR and needs to be dropped */ 501659185fSAvinash Repaka }; 511659185fSAvinash Repaka 521659185fSAvinash Repaka struct rds_ib_frmr { 531659185fSAvinash Repaka struct ib_mr *mr; 541659185fSAvinash Repaka enum rds_ib_fr_state fr_state; 551659185fSAvinash Repaka bool fr_inv; 562c7da8e6SGerd Rausch wait_queue_head_t fr_inv_done; 575f33141dSGerd Rausch bool fr_reg; 585f33141dSGerd Rausch wait_queue_head_t fr_reg_done; 591659185fSAvinash Repaka struct ib_send_wr fr_wr; 601659185fSAvinash Repaka unsigned int dma_npages; 611659185fSAvinash Repaka unsigned int sg_byte_len; 621659185fSAvinash Repaka }; 631659185fSAvinash Repaka 64f6df683fSsantosh.shilimkar@oracle.com /* This is stored as mr->r_trans_private. */ 65f6df683fSsantosh.shilimkar@oracle.com struct rds_ib_mr { 662eafa174SHans Westgaard Ry struct delayed_work work; 67f6df683fSsantosh.shilimkar@oracle.com struct rds_ib_device *device; 68f6df683fSsantosh.shilimkar@oracle.com struct rds_ib_mr_pool *pool; 69d4de76daSsantosh.shilimkar@oracle.com struct rds_ib_connection *ic; 70f6df683fSsantosh.shilimkar@oracle.com 71f6df683fSsantosh.shilimkar@oracle.com struct llist_node llnode; 72f6df683fSsantosh.shilimkar@oracle.com 73f6df683fSsantosh.shilimkar@oracle.com /* unmap_list is for freeing */ 74f6df683fSsantosh.shilimkar@oracle.com struct list_head unmap_list; 75f6df683fSsantosh.shilimkar@oracle.com unsigned int remap_count; 76f6df683fSsantosh.shilimkar@oracle.com 77f6df683fSsantosh.shilimkar@oracle.com struct scatterlist *sg; 78f6df683fSsantosh.shilimkar@oracle.com unsigned int sg_len; 79f6df683fSsantosh.shilimkar@oracle.com int sg_dma_len; 80a69365a3Ssantosh.shilimkar@oracle.com 812eafa174SHans Westgaard Ry u8 odp:1; 82a69365a3Ssantosh.shilimkar@oracle.com union { 831659185fSAvinash Repaka struct rds_ib_frmr frmr; 842eafa174SHans Westgaard Ry struct ib_mr *mr; 85a69365a3Ssantosh.shilimkar@oracle.com } u; 86f6df683fSsantosh.shilimkar@oracle.com }; 87f6df683fSsantosh.shilimkar@oracle.com 88f6df683fSsantosh.shilimkar@oracle.com /* Our own little MR pool */ 89f6df683fSsantosh.shilimkar@oracle.com struct rds_ib_mr_pool { 90f6df683fSsantosh.shilimkar@oracle.com unsigned int pool_type; 91f6df683fSsantosh.shilimkar@oracle.com struct mutex flush_lock; /* serialize fmr invalidate */ 92f6df683fSsantosh.shilimkar@oracle.com struct delayed_work flush_worker; /* flush worker */ 93f6df683fSsantosh.shilimkar@oracle.com 94f6df683fSsantosh.shilimkar@oracle.com atomic_t item_count; /* total # of MRs */ 95f6df683fSsantosh.shilimkar@oracle.com atomic_t dirty_count; /* # dirty of MRs */ 96f6df683fSsantosh.shilimkar@oracle.com 97f6df683fSsantosh.shilimkar@oracle.com struct llist_head drop_list; /* MRs not reached max_maps */ 98f6df683fSsantosh.shilimkar@oracle.com struct llist_head free_list; /* unused MRs */ 99f6df683fSsantosh.shilimkar@oracle.com struct llist_head clean_list; /* unused & unmapped MRs */ 100f6df683fSsantosh.shilimkar@oracle.com wait_queue_head_t flush_wait; 101c9467447SGerd Rausch spinlock_t clean_lock; /* "clean_list" concurrency */ 102f6df683fSsantosh.shilimkar@oracle.com 103f6df683fSsantosh.shilimkar@oracle.com atomic_t free_pinned; /* memory pinned by free MRs */ 104f6df683fSsantosh.shilimkar@oracle.com unsigned long max_items; 105f6df683fSsantosh.shilimkar@oracle.com unsigned long max_items_soft; 106f6df683fSsantosh.shilimkar@oracle.com unsigned long max_free_pinned; 107*07549ee2SMax Gurtovoy unsigned int max_pages; 108f6df683fSsantosh.shilimkar@oracle.com }; 109f6df683fSsantosh.shilimkar@oracle.com 110f6df683fSsantosh.shilimkar@oracle.com extern struct workqueue_struct *rds_ib_mr_wq; 1112cb2912dSsantosh.shilimkar@oracle.com extern bool prefer_frmr; 112f6df683fSsantosh.shilimkar@oracle.com 113f6df683fSsantosh.shilimkar@oracle.com struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_dev, 114f6df683fSsantosh.shilimkar@oracle.com int npages); 115f6df683fSsantosh.shilimkar@oracle.com void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev, 116f6df683fSsantosh.shilimkar@oracle.com struct rds_info_rdma_connection *iinfo); 117b7ff8b10SKa-Cheong Poon void rds6_ib_get_mr_info(struct rds_ib_device *rds_ibdev, 118b7ff8b10SKa-Cheong Poon struct rds6_info_rdma_connection *iinfo6); 119f6df683fSsantosh.shilimkar@oracle.com void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *); 120f6df683fSsantosh.shilimkar@oracle.com void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents, 1219e630bcbSAvinash Repaka struct rds_sock *rs, u32 *key_ret, 1222eafa174SHans Westgaard Ry struct rds_connection *conn, u64 start, u64 length, 1232eafa174SHans Westgaard Ry int need_odp); 124f6df683fSsantosh.shilimkar@oracle.com void rds_ib_sync_mr(void *trans_private, int dir); 125f6df683fSsantosh.shilimkar@oracle.com void rds_ib_free_mr(void *trans_private, int invalidate); 126f6df683fSsantosh.shilimkar@oracle.com void rds_ib_flush_mrs(void); 127f6df683fSsantosh.shilimkar@oracle.com int rds_ib_mr_init(void); 128f6df683fSsantosh.shilimkar@oracle.com void rds_ib_mr_exit(void); 1292eafa174SHans Westgaard Ry u32 rds_ib_get_lkey(void *trans_private); 130f6df683fSsantosh.shilimkar@oracle.com 131f6df683fSsantosh.shilimkar@oracle.com void __rds_ib_teardown_mr(struct rds_ib_mr *); 132f6df683fSsantosh.shilimkar@oracle.com void rds_ib_teardown_mr(struct rds_ib_mr *); 133f6df683fSsantosh.shilimkar@oracle.com struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *); 134f6df683fSsantosh.shilimkar@oracle.com int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **); 135490ea596Ssantosh.shilimkar@oracle.com struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *); 1361659185fSAvinash Repaka struct rds_ib_mr *rds_ib_reg_frmr(struct rds_ib_device *rds_ibdev, 1371659185fSAvinash Repaka struct rds_ib_connection *ic, 1381659185fSAvinash Repaka struct scatterlist *sg, 1391659185fSAvinash Repaka unsigned long nents, u32 *key); 1401659185fSAvinash Repaka void rds_ib_unreg_frmr(struct list_head *list, unsigned int *nfreed, 1411659185fSAvinash Repaka unsigned long *unpinned, unsigned int goal); 1421659185fSAvinash Repaka void rds_ib_free_frmr_list(struct rds_ib_mr *); 143f6df683fSsantosh.shilimkar@oracle.com #endif 144