main.c (e5451c8f8330e03ad3cfa16048b4daf961af434f) main.c (8633186209e35dfafc27c3d0f0d5e702ab47265f)
1/*
2 * Copyright 2014 IBM Corp.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */

--- 18 unchanged lines hidden (view full) ---

27
28static DEFINE_SPINLOCK(adapter_idr_lock);
29static DEFINE_IDR(cxl_adapter_idr);
30
31uint cxl_verbose;
32module_param_named(verbose, cxl_verbose, uint, 0600);
33MODULE_PARM_DESC(verbose, "Enable verbose dmesg output");
34
1/*
2 * Copyright 2014 IBM Corp.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 */

--- 18 unchanged lines hidden (view full) ---

27
28static DEFINE_SPINLOCK(adapter_idr_lock);
29static DEFINE_IDR(cxl_adapter_idr);
30
31uint cxl_verbose;
32module_param_named(verbose, cxl_verbose, uint, 0600);
33MODULE_PARM_DESC(verbose, "Enable verbose dmesg output");
34
35int cxl_afu_slbia(struct cxl_afu *afu)
36{
37 unsigned long timeout = jiffies + (HZ * CXL_TIMEOUT);
38
39 pr_devel("cxl_afu_slbia issuing SLBIA command\n");
40 cxl_p2n_write(afu, CXL_SLBIA_An, CXL_TLB_SLB_IQ_ALL);
41 while (cxl_p2n_read(afu, CXL_SLBIA_An) & CXL_TLB_SLB_P) {
42 if (time_after_eq(jiffies, timeout)) {
43 dev_warn(&afu->dev, "WARNING: CXL AFU SLBIA timed out!\n");
44 return -EBUSY;
45 }
46 /* If the adapter has gone down, we can assume that we
47 * will PERST it and that will invalidate everything.
48 */
49 if (!cxl_adapter_link_ok(afu->adapter))
50 return -EIO;
51 cpu_relax();
52 }
53 return 0;
54}
55
35static inline void _cxl_slbia(struct cxl_context *ctx, struct mm_struct *mm)
36{
37 struct task_struct *task;
38 unsigned long flags;
39 if (!(task = get_pid_task(ctx->pid, PIDTYPE_PID))) {
40 pr_devel("%s unable to get task %i\n",
41 __func__, pid_nr(ctx->pid));
42 return;

--- 126 unchanged lines hidden (view full) ---

169 return 0;
170}
171
172void cxl_remove_adapter_nr(struct cxl *adapter)
173{
174 idr_remove(&cxl_adapter_idr, adapter->adapter_num);
175}
176
56static inline void _cxl_slbia(struct cxl_context *ctx, struct mm_struct *mm)
57{
58 struct task_struct *task;
59 unsigned long flags;
60 if (!(task = get_pid_task(ctx->pid, PIDTYPE_PID))) {
61 pr_devel("%s unable to get task %i\n",
62 __func__, pid_nr(ctx->pid));
63 return;

--- 126 unchanged lines hidden (view full) ---

190 return 0;
191}
192
193void cxl_remove_adapter_nr(struct cxl *adapter)
194{
195 idr_remove(&cxl_adapter_idr, adapter->adapter_num);
196}
197
198struct cxl *cxl_alloc_adapter(void)
199{
200 struct cxl *adapter;
201
202 if (!(adapter = kzalloc(sizeof(struct cxl), GFP_KERNEL)))
203 return NULL;
204
205 spin_lock_init(&adapter->afu_list_lock);
206
207 if (cxl_alloc_adapter_nr(adapter))
208 goto err1;
209
210 if (dev_set_name(&adapter->dev, "card%i", adapter->adapter_num))
211 goto err2;
212
213 return adapter;
214
215err2:
216 cxl_remove_adapter_nr(adapter);
217err1:
218 kfree(adapter);
219 return NULL;
220}
221
222struct cxl_afu *cxl_alloc_afu(struct cxl *adapter, int slice)
223{
224 struct cxl_afu *afu;
225
226 if (!(afu = kzalloc(sizeof(struct cxl_afu), GFP_KERNEL)))
227 return NULL;
228
229 afu->adapter = adapter;
230 afu->dev.parent = &adapter->dev;
231 afu->dev.release = cxl_release_afu;
232 afu->slice = slice;
233 idr_init(&afu->contexts_idr);
234 mutex_init(&afu->contexts_lock);
235 spin_lock_init(&afu->afu_cntl_lock);
236 mutex_init(&afu->spa_mutex);
237
238 afu->prefault_mode = CXL_PREFAULT_NONE;
239 afu->irqs_max = afu->adapter->user_irqs;
240
241 return afu;
242}
243
177int cxl_afu_select_best_mode(struct cxl_afu *afu)
178{
179 if (afu->modes_supported & CXL_MODE_DIRECTED)
180 return cxl_afu_activate_mode(afu, CXL_MODE_DIRECTED);
181
182 if (afu->modes_supported & CXL_MODE_DEDICATED)
183 return cxl_afu_activate_mode(afu, CXL_MODE_DEDICATED);
184

--- 49 unchanged lines hidden ---
244int cxl_afu_select_best_mode(struct cxl_afu *afu)
245{
246 if (afu->modes_supported & CXL_MODE_DIRECTED)
247 return cxl_afu_activate_mode(afu, CXL_MODE_DIRECTED);
248
249 if (afu->modes_supported & CXL_MODE_DEDICATED)
250 return cxl_afu_activate_mode(afu, CXL_MODE_DEDICATED);
251

--- 49 unchanged lines hidden ---