Lines Matching refs:afu

18 	struct ocxl_afu *afu;
20 afu = kzalloc(sizeof(struct ocxl_afu), GFP_KERNEL);
21 if (!afu)
24 kref_init(&afu->kref);
25 mutex_init(&afu->contexts_lock);
26 mutex_init(&afu->afu_control_lock);
27 idr_init(&afu->contexts_idr);
28 afu->fn = fn;
30 return afu;
35 struct ocxl_afu *afu = container_of(kref, struct ocxl_afu, kref);
37 idr_destroy(&afu->contexts_idr);
38 ocxl_fn_put(afu->fn);
39 kfree(afu);
42 void ocxl_afu_get(struct ocxl_afu *afu)
44 kref_get(&afu->kref);
48 void ocxl_afu_put(struct ocxl_afu *afu)
50 kref_put(&afu->kref, free_afu);
54 static int assign_afu_actag(struct ocxl_afu *afu)
56 struct ocxl_fn *fn = afu->fn;
61 * if there were not enough actags for the function, each afu
64 actag_count = afu->config.actag_supported *
72 afu->actag_base = fn->actag_base + actag_offset;
73 afu->actag_enabled = actag_count;
75 ocxl_config_set_afu_actag(pci_dev, afu->config.dvsec_afu_control_pos,
76 afu->actag_base, afu->actag_enabled);
78 afu->actag_base, afu->actag_enabled);
82 static void reclaim_afu_actag(struct ocxl_afu *afu)
84 struct ocxl_fn *fn = afu->fn;
87 start_offset = afu->actag_base - fn->actag_base;
88 size = afu->actag_enabled;
89 ocxl_actag_afu_free(afu->fn, start_offset, size);
92 static int assign_afu_pasid(struct ocxl_afu *afu)
94 struct ocxl_fn *fn = afu->fn;
102 pasid_count = 1 << afu->config.pasid_supported_log;
109 afu->pasid_base = fn->pasid_base + pasid_offset;
110 afu->pasid_count = 0;
111 afu->pasid_max = pasid_count;
113 ocxl_config_set_afu_pasid(pci_dev, afu->config.dvsec_afu_control_pos,
114 afu->pasid_base,
115 afu->config.pasid_supported_log);
117 afu->pasid_base, pasid_count);
121 static void reclaim_afu_pasid(struct ocxl_afu *afu)
123 struct ocxl_fn *fn = afu->fn;
126 start_offset = afu->pasid_base - fn->pasid_base;
127 size = 1 << afu->config.pasid_supported_log;
128 ocxl_pasid_afu_free(afu->fn, start_offset, size);
162 static int map_mmio_areas(struct ocxl_afu *afu)
165 struct pci_dev *pci_dev = to_pci_dev(afu->fn->dev.parent);
167 rc = reserve_fn_bar(afu->fn, afu->config.global_mmio_bar);
171 rc = reserve_fn_bar(afu->fn, afu->config.pp_mmio_bar);
173 release_fn_bar(afu->fn, afu->config.global_mmio_bar);
177 afu->global_mmio_start =
178 pci_resource_start(pci_dev, afu->config.global_mmio_bar) +
179 afu->config.global_mmio_offset;
180 afu->pp_mmio_start =
181 pci_resource_start(pci_dev, afu->config.pp_mmio_bar) +
182 afu->config.pp_mmio_offset;
184 afu->global_mmio_ptr = ioremap(afu->global_mmio_start,
185 afu->config.global_mmio_size);
186 if (!afu->global_mmio_ptr) {
187 release_fn_bar(afu->fn, afu->config.pp_mmio_bar);
188 release_fn_bar(afu->fn, afu->config.global_mmio_bar);
197 afu->irq_base_offset = afu->config.pp_mmio_stride + PAGE_SIZE;
201 static void unmap_mmio_areas(struct ocxl_afu *afu)
203 if (afu->global_mmio_ptr) {
204 iounmap(afu->global_mmio_ptr);
205 afu->global_mmio_ptr = NULL;
207 afu->global_mmio_start = 0;
208 afu->pp_mmio_start = 0;
209 release_fn_bar(afu->fn, afu->config.pp_mmio_bar);
210 release_fn_bar(afu->fn, afu->config.global_mmio_bar);
213 static int configure_afu(struct ocxl_afu *afu, u8 afu_idx, struct pci_dev *dev)
217 rc = ocxl_config_read_afu(dev, &afu->fn->config, &afu->config, afu_idx);
221 rc = assign_afu_actag(afu);
225 rc = assign_afu_pasid(afu);
229 rc = map_mmio_areas(afu);
236 reclaim_afu_pasid(afu);
238 reclaim_afu_actag(afu);
242 static void deconfigure_afu(struct ocxl_afu *afu)
244 unmap_mmio_areas(afu);
245 reclaim_afu_pasid(afu);
246 reclaim_afu_actag(afu);
249 static int activate_afu(struct pci_dev *dev, struct ocxl_afu *afu)
251 ocxl_config_set_afu_state(dev, afu->config.dvsec_afu_control_pos, 1);
256 static void deactivate_afu(struct ocxl_afu *afu)
258 struct pci_dev *dev = to_pci_dev(afu->fn->dev.parent);
260 ocxl_config_set_afu_state(dev, afu->config.dvsec_afu_control_pos, 0);
266 struct ocxl_afu *afu;
268 afu = alloc_afu(fn);
269 if (!afu)
272 rc = configure_afu(afu, afu_idx, dev);
274 ocxl_afu_put(afu);
278 rc = activate_afu(dev, afu);
280 deconfigure_afu(afu);
281 ocxl_afu_put(afu);
285 list_add_tail(&afu->list, &fn->afu_list);
290 static void remove_afu(struct ocxl_afu *afu)
292 list_del(&afu->list);
293 ocxl_context_detach_all(afu);
294 deactivate_afu(afu);
295 deconfigure_afu(afu);
296 ocxl_afu_put(afu); // matches the implicit get in alloc_afu
478 u8 afu;
493 for (afu = 0; afu <= fn->config.max_afu_index; afu++) {
494 rc = ocxl_config_check_afu_index(dev, &fn->config, afu);
496 rc = init_afu(dev, fn, afu);
499 "Can't initialize AFU index %d\n", afu);
518 struct ocxl_afu *afu;
520 list_for_each_entry(afu, &fn->afu_list, list) {
521 if (afu->config.idx == afu_idx)
522 return afu;
537 struct ocxl_afu *afu, *tmp;
539 list_for_each_entry_safe(afu, tmp, &fn->afu_list, list) {
540 remove_afu(afu);
550 struct ocxl_afu_config *ocxl_afu_config(struct ocxl_afu *afu)
552 return &afu->config;
556 void ocxl_afu_set_private(struct ocxl_afu *afu, void *private)
558 afu->private = private;
562 void *ocxl_afu_get_private(struct ocxl_afu *afu)
564 if (afu)
565 return afu->private;