Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2016 Oracle.  All rights reserved.
0003  *
0004  * This software is available to you under a choice of one of two
0005  * licenses.  You may choose to be licensed under the terms of the GNU
0006  * General Public License (GPL) Version 2, available from the file
0007  * COPYING in the main directory of this source tree, or the
0008  * OpenIB.org BSD license below:
0009  *
0010  *     Redistribution and use in source and binary forms, with or
0011  *     without modification, are permitted provided that the following
0012  *     conditions are met:
0013  *
0014  *      - Redistributions of source code must retain the above
0015  *        copyright notice, this list of conditions and the following
0016  *        disclaimer.
0017  *
0018  *      - Redistributions in binary form must reproduce the above
0019  *        copyright notice, this list of conditions and the following
0020  *        disclaimer in the documentation and/or other materials
0021  *        provided with the distribution.
0022  *
0023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0024  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0025  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0026  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0027  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0028  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0029  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0030  * SOFTWARE.
0031  */
0032 #ifndef _RDS_IB_MR_H
0033 #define _RDS_IB_MR_H
0034 
0035 #include <linux/kernel.h>
0036 
0037 #include "rds.h"
0038 #include "ib.h"
0039 
0040 #define RDS_MR_1M_POOL_SIZE     (8192 / 2)
0041 #define RDS_MR_1M_MSG_SIZE      256
0042 #define RDS_MR_8K_MSG_SIZE      2
0043 #define RDS_MR_8K_SCALE         (256 / (RDS_MR_8K_MSG_SIZE + 1))
0044 #define RDS_MR_8K_POOL_SIZE     (RDS_MR_8K_SCALE * (8192 / 2))
0045 
0046 enum rds_ib_fr_state {
0047     FRMR_IS_FREE,   /* mr invalidated & ready for use */
0048     FRMR_IS_INUSE,  /* mr is in use or used & can be invalidated */
0049     FRMR_IS_STALE,  /* Stale MR and needs to be dropped  */
0050 };
0051 
0052 struct rds_ib_frmr {
0053     struct ib_mr        *mr;
0054     enum rds_ib_fr_state    fr_state;
0055     bool            fr_inv;
0056     wait_queue_head_t   fr_inv_done;
0057     bool            fr_reg;
0058     wait_queue_head_t   fr_reg_done;
0059     struct ib_send_wr   fr_wr;
0060     unsigned int        dma_npages;
0061     unsigned int        sg_byte_len;
0062 };
0063 
0064 /* This is stored as mr->r_trans_private. */
0065 struct rds_ib_mr {
0066     struct delayed_work     work;
0067     struct rds_ib_device        *device;
0068     struct rds_ib_mr_pool       *pool;
0069     struct rds_ib_connection    *ic;
0070 
0071     struct llist_node       llnode;
0072 
0073     /* unmap_list is for freeing */
0074     struct list_head        unmap_list;
0075     unsigned int            remap_count;
0076 
0077     struct scatterlist      *sg;
0078     unsigned int            sg_len;
0079     int             sg_dma_len;
0080 
0081     u8              odp:1;
0082     union {
0083         struct rds_ib_frmr  frmr;
0084         struct ib_mr        *mr;
0085     } u;
0086 };
0087 
0088 /* Our own little MR pool */
0089 struct rds_ib_mr_pool {
0090     unsigned int            pool_type;
0091     struct mutex        flush_lock; /* serialize fmr invalidate */
0092     struct delayed_work flush_worker;   /* flush worker */
0093 
0094     atomic_t        item_count; /* total # of MRs */
0095     atomic_t        dirty_count;    /* # dirty of MRs */
0096 
0097     struct llist_head   drop_list;  /* MRs not reached max_maps */
0098     struct llist_head   free_list;  /* unused MRs */
0099     struct llist_head   clean_list; /* unused & unmapped MRs */
0100     wait_queue_head_t   flush_wait;
0101     spinlock_t      clean_lock; /* "clean_list" concurrency */
0102 
0103     atomic_t        free_pinned;    /* memory pinned by free MRs */
0104     unsigned long       max_items;
0105     unsigned long       max_items_soft;
0106     unsigned long       max_free_pinned;
0107     unsigned int        max_pages;
0108 };
0109 
0110 extern struct workqueue_struct *rds_ib_mr_wq;
0111 extern bool prefer_frmr;
0112 
0113 struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_dev,
0114                          int npages);
0115 void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev,
0116             struct rds_info_rdma_connection *iinfo);
0117 void rds6_ib_get_mr_info(struct rds_ib_device *rds_ibdev,
0118              struct rds6_info_rdma_connection *iinfo6);
0119 void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *);
0120 void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,
0121             struct rds_sock *rs, u32 *key_ret,
0122             struct rds_connection *conn, u64 start, u64 length,
0123             int need_odp);
0124 void rds_ib_sync_mr(void *trans_private, int dir);
0125 void rds_ib_free_mr(void *trans_private, int invalidate);
0126 void rds_ib_flush_mrs(void);
0127 int rds_ib_mr_init(void);
0128 void rds_ib_mr_exit(void);
0129 u32 rds_ib_get_lkey(void *trans_private);
0130 
0131 void __rds_ib_teardown_mr(struct rds_ib_mr *);
0132 void rds_ib_teardown_mr(struct rds_ib_mr *);
0133 struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *);
0134 int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **);
0135 struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *);
0136 struct rds_ib_mr *rds_ib_reg_frmr(struct rds_ib_device *rds_ibdev,
0137                   struct rds_ib_connection *ic,
0138                   struct scatterlist *sg,
0139                   unsigned long nents, u32 *key);
0140 void rds_ib_unreg_frmr(struct list_head *list, unsigned int *nfreed,
0141                unsigned long *unpinned, unsigned int goal);
0142 void rds_ib_free_frmr_list(struct rds_ib_mr *);
0143 #endif