Linux Audio

Check our new training course

Loading...
v4.6
  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
 46struct rds_ib_fmr {
 47	struct ib_fmr		*fmr;
 48	u64			*dma;
 49};
 50
 51enum rds_ib_fr_state {
 52	FRMR_IS_FREE,	/* mr invalidated & ready for use */
 53	FRMR_IS_INUSE,	/* mr is in use or used & can be invalidated */
 54	FRMR_IS_STALE,	/* Stale MR and needs to be dropped  */
 55};
 56
 57struct rds_ib_frmr {
 58	struct ib_mr		*mr;
 59	enum rds_ib_fr_state	fr_state;
 60	bool			fr_inv;
 
 
 
 61	struct ib_send_wr	fr_wr;
 62	unsigned int		dma_npages;
 63	unsigned int		sg_byte_len;
 64};
 65
 66/* This is stored as mr->r_trans_private. */
 67struct rds_ib_mr {
 
 68	struct rds_ib_device		*device;
 69	struct rds_ib_mr_pool		*pool;
 70	struct rds_ib_connection	*ic;
 71
 72	struct llist_node		llnode;
 73
 74	/* unmap_list is for freeing */
 75	struct list_head		unmap_list;
 76	unsigned int			remap_count;
 77
 78	struct scatterlist		*sg;
 79	unsigned int			sg_len;
 80	int				sg_dma_len;
 81
 
 82	union {
 83		struct rds_ib_fmr	fmr;
 84		struct rds_ib_frmr	frmr;
 
 85	} u;
 86};
 87
 88/* Our own little MR pool */
 89struct rds_ib_mr_pool {
 90	unsigned int            pool_type;
 91	struct mutex		flush_lock;	/* serialize fmr invalidate */
 92	struct delayed_work	flush_worker;	/* flush worker */
 93
 94	atomic_t		item_count;	/* total # of MRs */
 95	atomic_t		dirty_count;	/* # dirty of MRs */
 96
 97	struct llist_head	drop_list;	/* MRs not reached max_maps */
 98	struct llist_head	free_list;	/* unused MRs */
 99	struct llist_head	clean_list;	/* unused & unmapped MRs */
100	wait_queue_head_t	flush_wait;
 
101
102	atomic_t		free_pinned;	/* memory pinned by free MRs */
103	unsigned long		max_items;
104	unsigned long		max_items_soft;
105	unsigned long		max_free_pinned;
106	struct ib_fmr_attr	fmr_attr;
107	bool			use_fastreg;
108};
109
110extern struct workqueue_struct *rds_ib_mr_wq;
111extern unsigned int rds_ib_mr_1m_pool_size;
112extern unsigned int rds_ib_mr_8k_pool_size;
113extern bool prefer_frmr;
114
115struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_dev,
116					     int npages);
117void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev,
118			struct rds_info_rdma_connection *iinfo);
 
 
119void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *);
120void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,
121		    struct rds_sock *rs, u32 *key_ret);
 
 
122void rds_ib_sync_mr(void *trans_private, int dir);
123void rds_ib_free_mr(void *trans_private, int invalidate);
124void rds_ib_flush_mrs(void);
125int rds_ib_mr_init(void);
126void rds_ib_mr_exit(void);
 
127
128void __rds_ib_teardown_mr(struct rds_ib_mr *);
129void rds_ib_teardown_mr(struct rds_ib_mr *);
130struct rds_ib_mr *rds_ib_alloc_fmr(struct rds_ib_device *, int);
131int rds_ib_map_fmr(struct rds_ib_device *, struct rds_ib_mr *,
132		   struct scatterlist *, unsigned int);
133struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *);
134int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **);
135struct rds_ib_mr *rds_ib_reg_fmr(struct rds_ib_device *, struct scatterlist *,
136				 unsigned long, u32 *);
137struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *);
138void rds_ib_unreg_fmr(struct list_head *, unsigned int *,
139		      unsigned long *, unsigned int);
140void rds_ib_free_fmr_list(struct rds_ib_mr *);
141struct rds_ib_mr *rds_ib_reg_frmr(struct rds_ib_device *rds_ibdev,
142				  struct rds_ib_connection *ic,
143				  struct scatterlist *sg,
144				  unsigned long nents, u32 *key);
145void rds_ib_unreg_frmr(struct list_head *list, unsigned int *nfreed,
146		       unsigned long *unpinned, unsigned int goal);
147void rds_ib_free_frmr_list(struct rds_ib_mr *);
148#endif
v6.13.7
  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
 
 
 
 
 
 46enum rds_ib_fr_state {
 47	FRMR_IS_FREE,	/* mr invalidated & ready for use */
 48	FRMR_IS_INUSE,	/* mr is in use or used & can be invalidated */
 49	FRMR_IS_STALE,	/* Stale MR and needs to be dropped  */
 50};
 51
 52struct rds_ib_frmr {
 53	struct ib_mr		*mr;
 54	enum rds_ib_fr_state	fr_state;
 55	bool			fr_inv;
 56	wait_queue_head_t	fr_inv_done;
 57	bool			fr_reg;
 58	wait_queue_head_t	fr_reg_done;
 59	struct ib_send_wr	fr_wr;
 60	unsigned int		dma_npages;
 61	unsigned int		sg_byte_len;
 62};
 63
 64/* This is stored as mr->r_trans_private. */
 65struct rds_ib_mr {
 66	struct delayed_work		work;
 67	struct rds_ib_device		*device;
 68	struct rds_ib_mr_pool		*pool;
 69	struct rds_ib_connection	*ic;
 70
 71	struct llist_node		llnode;
 72
 73	/* unmap_list is for freeing */
 74	struct list_head		unmap_list;
 75	unsigned int			remap_count;
 76
 77	struct scatterlist		*sg;
 78	unsigned int			sg_len;
 79	int				sg_dma_len;
 80
 81	u8				odp:1;
 82	union {
 
 83		struct rds_ib_frmr	frmr;
 84		struct ib_mr		*mr;
 85	} u;
 86};
 87
 88/* Our own little MR pool */
 89struct rds_ib_mr_pool {
 90	unsigned int            pool_type;
 91	struct mutex		flush_lock;	/* serialize fmr invalidate */
 92	struct delayed_work	flush_worker;	/* flush worker */
 93
 94	atomic_t		item_count;	/* total # of MRs */
 95	atomic_t		dirty_count;	/* # dirty of MRs */
 96
 97	struct llist_head	drop_list;	/* MRs not reached max_maps */
 98	struct llist_head	free_list;	/* unused MRs */
 99	struct llist_head	clean_list;	/* unused & unmapped MRs */
100	wait_queue_head_t	flush_wait;
101	spinlock_t		clean_lock;	/* "clean_list" concurrency */
102
103	atomic_t		free_pinned;	/* memory pinned by free MRs */
104	unsigned long		max_items;
105	unsigned long		max_items_soft;
106	unsigned long		max_free_pinned;
107	unsigned int		max_pages;
 
108};
109
110extern struct workqueue_struct *rds_ib_mr_wq;
 
 
111extern bool prefer_frmr;
112
113struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *rds_dev,
114					     int npages);
115void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev,
116			struct rds_info_rdma_connection *iinfo);
117void rds6_ib_get_mr_info(struct rds_ib_device *rds_ibdev,
118			 struct rds6_info_rdma_connection *iinfo6);
119void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *);
120void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,
121		    struct rds_sock *rs, u32 *key_ret,
122		    struct rds_connection *conn, u64 start, u64 length,
123		    int need_odp);
124void rds_ib_sync_mr(void *trans_private, int dir);
125void rds_ib_free_mr(void *trans_private, int invalidate);
126void rds_ib_flush_mrs(void);
127int rds_ib_mr_init(void);
128void rds_ib_mr_exit(void);
129u32 rds_ib_get_lkey(void *trans_private);
130
131void __rds_ib_teardown_mr(struct rds_ib_mr *);
132void rds_ib_teardown_mr(struct rds_ib_mr *);
 
 
 
133struct rds_ib_mr *rds_ib_reuse_mr(struct rds_ib_mr_pool *);
134int rds_ib_flush_mr_pool(struct rds_ib_mr_pool *, int, struct rds_ib_mr **);
 
 
135struct rds_ib_mr *rds_ib_try_reuse_ibmr(struct rds_ib_mr_pool *);
 
 
 
136struct 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);
140void rds_ib_unreg_frmr(struct list_head *list, unsigned int *nfreed,
141		       unsigned long *unpinned, unsigned int goal);
142void rds_ib_free_frmr_list(struct rds_ib_mr *);
143#endif