This source file includes following definitions.
- mthca_icm_first
- mthca_icm_last
- mthca_icm_next
- mthca_icm_addr
- mthca_icm_size
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 {
46 MTHCA_ICM_PAGE_SHIFT = 12,
47 MTHCA_ICM_PAGE_SIZE = 1 << MTHCA_ICM_PAGE_SHIFT,
48 MTHCA_DB_REC_PER_PAGE = MTHCA_ICM_PAGE_SIZE / 8
49 };
50
51 struct mthca_icm_chunk {
52 struct list_head list;
53 int npages;
54 int nsg;
55 struct scatterlist mem[MTHCA_ICM_CHUNK_LEN];
56 };
57
58 struct mthca_icm {
59 struct list_head chunk_list;
60 int refcount;
61 };
62
63 struct mthca_icm_table {
64 u64 virt;
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
74 struct mthca_icm_iter {
75 struct mthca_icm *icm;
76 struct mthca_icm_chunk *chunk;
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
86 struct mthca_icm_table *mthca_alloc_icm_table(struct mthca_dev *dev,
87 u64 virt, int obj_size,
88 int nobj, int reserved,
89 int use_lowmem, int use_coherent);
90 void mthca_free_icm_table(struct mthca_dev *dev, struct mthca_icm_table *table);
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);
93 void *mthca_table_find(struct mthca_icm_table *table, int obj, dma_addr_t *dma_handle);
94 int mthca_table_get_range(struct mthca_dev *dev, struct mthca_icm_table *table,
95 int start, int end);
96 void mthca_table_put_range(struct mthca_dev *dev, struct mthca_icm_table *table,
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
138 struct mthca_db_page {
139 DECLARE_BITMAP(used, MTHCA_DB_REC_PER_PAGE);
140 __be64 *db_rec;
141 dma_addr_t mapping;
142 };
143
144 struct mthca_db_table {
145 int npages;
146 int max_group1;
147 int min_group2;
148 struct mthca_db_page *page;
149 struct mutex mutex;
150 };
151
152 enum mthca_db_type {
153 MTHCA_DB_TYPE_INVALID = 0x0,
154 MTHCA_DB_TYPE_CQ_SET_CI = 0x1,
155 MTHCA_DB_TYPE_CQ_ARM = 0x2,
156 MTHCA_DB_TYPE_SQ = 0x3,
157 MTHCA_DB_TYPE_RQ = 0x4,
158 MTHCA_DB_TYPE_SRQ = 0x5,
159 MTHCA_DB_TYPE_GROUP_SEP = 0x7
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);
169 struct mthca_user_db_table *mthca_init_user_db_tab(struct mthca_dev *dev);
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