Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mthca_memfree.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3  * Copyright (c) 2005 Cisco Systems. All rights reserved.
4  * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5  *
6  * This software is available to you under a choice of one of two
7  * licenses. You may choose to be licensed under the terms of the GNU
8  * General Public License (GPL) Version 2, available from the file
9  * COPYING in the main directory of this source tree, or the
10  * OpenIB.org BSD license below:
11  *
12  * Redistribution and use in source and binary forms, with or
13  * without modification, are permitted provided that the following
14  * conditions are met:
15  *
16  * - Redistributions of source code must retain the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer.
19  *
20  * - Redistributions in binary form must reproduce the above
21  * copyright notice, this list of conditions and the following
22  * disclaimer in the documentation and/or other materials
23  * provided with the distribution.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32  * SOFTWARE.
33  */
34 
35 #ifndef MTHCA_MEMFREE_H
36 #define MTHCA_MEMFREE_H
37 
38 #include <linux/list.h>
39 #include <linux/mutex.h>
40 
41 #define MTHCA_ICM_CHUNK_LEN \
42  ((256 - sizeof (struct list_head) - 2 * sizeof (int)) / \
43  (sizeof (struct scatterlist)))
44 
45 enum {
49 };
50 
52  struct list_head list;
53  int npages;
54  int nsg;
56 };
57 
58 struct mthca_icm {
60  int refcount;
61 };
62 
65  int num_icm;
66  int num_obj;
67  int obj_size;
68  int lowmem;
69  int coherent;
70  struct mutex mutex;
71  struct mthca_icm *icm[0];
72 };
73 
75  struct mthca_icm *icm;
77  int page_idx;
78 };
79 
80 struct mthca_dev;
81 
82 struct mthca_icm *mthca_alloc_icm(struct mthca_dev *dev, int npages,
83  gfp_t gfp_mask, int coherent);
84 void mthca_free_icm(struct mthca_dev *dev, struct mthca_icm *icm, int coherent);
85 
87  u64 virt, int obj_size,
88  int nobj, int reserved,
89  int use_lowmem, int use_coherent);
91 int mthca_table_get(struct mthca_dev *dev, struct mthca_icm_table *table, int obj);
92 void mthca_table_put(struct mthca_dev *dev, struct mthca_icm_table *table, int obj);
95  int start, int end);
97  int start, int end);
98 
99 static inline void mthca_icm_first(struct mthca_icm *icm,
100  struct mthca_icm_iter *iter)
101 {
102  iter->icm = icm;
103  iter->chunk = list_empty(&icm->chunk_list) ?
104  NULL : list_entry(icm->chunk_list.next,
105  struct mthca_icm_chunk, list);
106  iter->page_idx = 0;
107 }
108 
109 static inline int mthca_icm_last(struct mthca_icm_iter *iter)
110 {
111  return !iter->chunk;
112 }
113 
114 static inline void mthca_icm_next(struct mthca_icm_iter *iter)
115 {
116  if (++iter->page_idx >= iter->chunk->nsg) {
117  if (iter->chunk->list.next == &iter->icm->chunk_list) {
118  iter->chunk = NULL;
119  return;
120  }
121 
122  iter->chunk = list_entry(iter->chunk->list.next,
123  struct mthca_icm_chunk, list);
124  iter->page_idx = 0;
125  }
126 }
127 
128 static inline dma_addr_t mthca_icm_addr(struct mthca_icm_iter *iter)
129 {
130  return sg_dma_address(&iter->chunk->mem[iter->page_idx]);
131 }
132 
133 static inline unsigned long mthca_icm_size(struct mthca_icm_iter *iter)
134 {
135  return sg_dma_len(&iter->chunk->mem[iter->page_idx]);
136 }
137 
142 };
143 
145  int npages;
149  struct mutex mutex;
150 };
151 
160 };
161 
162 struct mthca_user_db_table;
163 struct mthca_uar;
164 
165 int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
166  struct mthca_user_db_table *db_tab, int index, u64 uaddr);
167 void mthca_unmap_user_db(struct mthca_dev *dev, struct mthca_uar *uar,
168  struct mthca_user_db_table *db_tab, int index);
170 void mthca_cleanup_user_db_tab(struct mthca_dev *dev, struct mthca_uar *uar,
171  struct mthca_user_db_table *db_tab);
172 
173 int mthca_init_db_tab(struct mthca_dev *dev);
174 void mthca_cleanup_db_tab(struct mthca_dev *dev);
175 int mthca_alloc_db(struct mthca_dev *dev, enum mthca_db_type type,
176  u32 qn, __be32 **db);
177 void mthca_free_db(struct mthca_dev *dev, int type, int db_index);
178 
179 #endif /* MTHCA_MEMFREE_H */