santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Oracle. All rights reserved. |
| 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | #ifndef _RDS_IB_MR_H |
| 33 | #define _RDS_IB_MR_H |
| 34 | |
| 35 | #include <linux/kernel.h> |
| 36 | |
| 37 | #include "rds.h" |
| 38 | #include "ib.h" |
| 39 | |
| 40 | #define RDS_MR_1M_POOL_SIZE (8192 / 2) |
| 41 | #define RDS_MR_1M_MSG_SIZE 256 |
| 42 | #define RDS_MR_8K_MSG_SIZE 2 |
| 43 | #define RDS_MR_8K_SCALE (256 / (RDS_MR_8K_MSG_SIZE + 1)) |
| 44 | #define RDS_MR_8K_POOL_SIZE (RDS_MR_8K_SCALE * (8192 / 2)) |
| 45 | |
santosh.shilimkar@oracle.com | a69365a | 2016-03-01 15:20:47 -0800 | [diff] [blame] | 46 | struct rds_ib_fmr { |
| 47 | struct ib_fmr *fmr; |
santosh.shilimkar@oracle.com | a69365a | 2016-03-01 15:20:47 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
Avinash Repaka | 1659185 | 2016-03-01 15:20:54 -0800 | [diff] [blame] | 50 | enum rds_ib_fr_state { |
| 51 | FRMR_IS_FREE, /* mr invalidated & ready for use */ |
| 52 | FRMR_IS_INUSE, /* mr is in use or used & can be invalidated */ |
| 53 | FRMR_IS_STALE, /* Stale MR and needs to be dropped */ |
| 54 | }; |
| 55 | |
| 56 | struct rds_ib_frmr { |
| 57 | struct ib_mr *mr; |
| 58 | enum rds_ib_fr_state fr_state; |
| 59 | bool fr_inv; |
| 60 | struct ib_send_wr fr_wr; |
| 61 | unsigned int dma_npages; |
| 62 | unsigned int sg_byte_len; |
| 63 | }; |
| 64 | |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 65 | /* This is stored as mr->r_trans_private. */ |
| 66 | struct rds_ib_mr { |
santosh.shilimkar@oracle.com | d4de76d | 2016-03-01 15:20:49 -0800 | [diff] [blame] | 67 | struct rds_ib_device *device; |
| 68 | struct rds_ib_mr_pool *pool; |
| 69 | struct rds_ib_connection *ic; |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 70 | |
santosh.shilimkar@oracle.com | d4de76d | 2016-03-01 15:20:49 -0800 | [diff] [blame] | 71 | struct llist_node llnode; |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 72 | |
| 73 | /* unmap_list is for freeing */ |
santosh.shilimkar@oracle.com | d4de76d | 2016-03-01 15:20:49 -0800 | [diff] [blame] | 74 | struct list_head unmap_list; |
| 75 | unsigned int remap_count; |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 76 | |
santosh.shilimkar@oracle.com | d4de76d | 2016-03-01 15:20:49 -0800 | [diff] [blame] | 77 | struct scatterlist *sg; |
| 78 | unsigned int sg_len; |
| 79 | int sg_dma_len; |
santosh.shilimkar@oracle.com | a69365a | 2016-03-01 15:20:47 -0800 | [diff] [blame] | 80 | |
| 81 | union { |
| 82 | struct rds_ib_fmr fmr; |
Avinash Repaka | 1659185 | 2016-03-01 15:20:54 -0800 | [diff] [blame] | 83 | struct rds_ib_frmr frmr; |
santosh.shilimkar@oracle.com | a69365a | 2016-03-01 15:20:47 -0800 | [diff] [blame] | 84 | } u; |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | /* Our own little MR pool */ |
| 88 | struct rds_ib_mr_pool { |
| 89 | unsigned int pool_type; |
| 90 | struct mutex flush_lock; /* serialize fmr invalidate */ |
| 91 | struct delayed_work flush_worker; /* flush worker */ |
| 92 | |
| 93 | atomic_t item_count; /* total # of MRs */ |
| 94 | atomic_t dirty_count; /* # dirty of MRs */ |
| 95 | |
| 96 | struct llist_head drop_list; /* MRs not reached max_maps */ |
| 97 | struct llist_head free_list; /* unused MRs */ |
| 98 | struct llist_head clean_list; /* unused & unmapped MRs */ |
| 99 | wait_queue_head_t flush_wait; |
| 100 | |
| 101 | atomic_t free_pinned; /* memory pinned by free MRs */ |
| 102 | unsigned long max_items; |
| 103 | unsigned long max_items_soft; |
| 104 | unsigned long max_free_pinned; |
| 105 | struct ib_fmr_attr fmr_attr; |
Avinash Repaka | 1659185 | 2016-03-01 15:20:54 -0800 | [diff] [blame] | 106 | bool use_fastreg; |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | extern struct workqueue_struct *rds_ib_mr_wq; |
santosh.shilimkar@oracle.com | 2cb2912 | 2016-03-01 15:20:52 -0800 | [diff] [blame] | 110 | extern bool prefer_frmr; |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 111 | |
| 112 | struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_dev, |
| 113 | int npages); |
| 114 | void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev, |
| 115 | struct rds_info_rdma_connection *iinfo); |
| 116 | void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *); |
| 117 | void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents, |
| 118 | struct rds_sock *rs, u32 *key_ret); |
| 119 | void rds_ib_sync_mr(void *trans_private, int dir); |
| 120 | void rds_ib_free_mr(void *trans_private, int invalidate); |
| 121 | void rds_ib_flush_mrs(void); |
| 122 | int rds_ib_mr_init(void); |
| 123 | void rds_ib_mr_exit(void); |
| 124 | |
| 125 | void __rds_ib_teardown_mr(struct rds_ib_mr *); |
| 126 | void rds_ib_teardown_mr(struct rds_ib_mr *); |
| 127 | struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device *, int); |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 128 | struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *); |
| 129 | int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **); |
santosh.shilimkar@oracle.com | 490ea59 | 2016-03-01 15:20:48 -0800 | [diff] [blame] | 130 | struct rds_ib_mr *rds_ib_reg_fmr(struct rds_ib_device *, struct scatterlist *, |
| 131 | unsigned long, u32 *); |
| 132 | struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *); |
| 133 | void rds_ib_unreg_fmr(struct list_head *, unsigned int *, |
| 134 | unsigned long *, unsigned int); |
| 135 | void rds_ib_free_fmr_list(struct rds_ib_mr *); |
Avinash Repaka | 1659185 | 2016-03-01 15:20:54 -0800 | [diff] [blame] | 136 | struct rds_ib_mr *rds_ib_reg_frmr(struct rds_ib_device *rds_ibdev, |
| 137 | struct rds_ib_connection *ic, |
| 138 | struct scatterlist *sg, |
| 139 | unsigned long nents, u32 *key); |
| 140 | void rds_ib_unreg_frmr(struct list_head *list, unsigned int *nfreed, |
| 141 | unsigned long *unpinned, unsigned int goal); |
| 142 | void rds_ib_free_frmr_list(struct rds_ib_mr *); |
santosh.shilimkar@oracle.com | f6df683 | 2016-03-01 15:20:46 -0800 | [diff] [blame] | 143 | #endif |