Lines Matching refs:fn

6 static struct ocxl_fn *ocxl_fn_get(struct ocxl_fn *fn)  in ocxl_fn_get()  argument
8 return (get_device(&fn->dev) == NULL) ? NULL : fn; in ocxl_fn_get()
11 static void ocxl_fn_put(struct ocxl_fn *fn) in ocxl_fn_put() argument
13 put_device(&fn->dev); in ocxl_fn_put()
16 static struct ocxl_afu *alloc_afu(struct ocxl_fn *fn) in alloc_afu() argument
28 afu->fn = fn; in alloc_afu()
29 ocxl_fn_get(fn); in alloc_afu()
38 ocxl_fn_put(afu->fn); in free_afu()
56 struct ocxl_fn *fn = afu->fn; in assign_afu_actag() local
58 struct pci_dev *pci_dev = to_pci_dev(fn->dev.parent); in assign_afu_actag()
65 fn->actag_enabled / fn->actag_supported; in assign_afu_actag()
66 actag_offset = ocxl_actag_afu_alloc(fn, actag_count); in assign_afu_actag()
72 afu->actag_base = fn->actag_base + actag_offset; in assign_afu_actag()
84 struct ocxl_fn *fn = afu->fn; in reclaim_afu_actag() local
87 start_offset = afu->actag_base - fn->actag_base; in reclaim_afu_actag()
89 ocxl_actag_afu_free(afu->fn, start_offset, size); in reclaim_afu_actag()
94 struct ocxl_fn *fn = afu->fn; in assign_afu_pasid() local
96 struct pci_dev *pci_dev = to_pci_dev(fn->dev.parent); in assign_afu_pasid()
103 pasid_offset = ocxl_pasid_afu_alloc(fn, pasid_count); in assign_afu_pasid()
109 afu->pasid_base = fn->pasid_base + pasid_offset; in assign_afu_pasid()
123 struct ocxl_fn *fn = afu->fn; in reclaim_afu_pasid() local
126 start_offset = afu->pasid_base - fn->pasid_base; in reclaim_afu_pasid()
128 ocxl_pasid_afu_free(afu->fn, start_offset, size); in reclaim_afu_pasid()
131 static int reserve_fn_bar(struct ocxl_fn *fn, int bar) in reserve_fn_bar() argument
133 struct pci_dev *dev = to_pci_dev(fn->dev.parent); in reserve_fn_bar()
140 if (fn->bar_used[idx]++ == 0) { in reserve_fn_bar()
148 static void release_fn_bar(struct ocxl_fn *fn, int bar) in release_fn_bar() argument
150 struct pci_dev *dev = to_pci_dev(fn->dev.parent); in release_fn_bar()
157 if (--fn->bar_used[idx] == 0) in release_fn_bar()
159 WARN_ON(fn->bar_used[idx] < 0); in release_fn_bar()
165 struct pci_dev *pci_dev = to_pci_dev(afu->fn->dev.parent); in map_mmio_areas()
167 rc = reserve_fn_bar(afu->fn, afu->config.global_mmio_bar); in map_mmio_areas()
171 rc = reserve_fn_bar(afu->fn, afu->config.pp_mmio_bar); in map_mmio_areas()
173 release_fn_bar(afu->fn, afu->config.global_mmio_bar); in map_mmio_areas()
187 release_fn_bar(afu->fn, afu->config.pp_mmio_bar); in map_mmio_areas()
188 release_fn_bar(afu->fn, afu->config.global_mmio_bar); in map_mmio_areas()
209 release_fn_bar(afu->fn, afu->config.pp_mmio_bar); in unmap_mmio_areas()
210 release_fn_bar(afu->fn, afu->config.global_mmio_bar); in unmap_mmio_areas()
217 rc = ocxl_config_read_afu(dev, &afu->fn->config, &afu->config, afu_idx); in configure_afu()
258 struct pci_dev *dev = to_pci_dev(afu->fn->dev.parent); in deactivate_afu()
263 static int init_afu(struct pci_dev *dev, struct ocxl_fn *fn, u8 afu_idx) in init_afu() argument
268 afu = alloc_afu(fn); in init_afu()
285 list_add_tail(&afu->list, &fn->afu_list); in init_afu()
301 struct ocxl_fn *fn; in alloc_function() local
303 fn = kzalloc(sizeof(struct ocxl_fn), GFP_KERNEL); in alloc_function()
304 if (!fn) in alloc_function()
307 INIT_LIST_HEAD(&fn->afu_list); in alloc_function()
308 INIT_LIST_HEAD(&fn->pasid_list); in alloc_function()
309 INIT_LIST_HEAD(&fn->actag_list); in alloc_function()
311 return fn; in alloc_function()
314 static void free_function(struct ocxl_fn *fn) in free_function() argument
316 WARN_ON(!list_empty(&fn->afu_list)); in free_function()
317 WARN_ON(!list_empty(&fn->pasid_list)); in free_function()
318 kfree(fn); in free_function()
323 struct ocxl_fn *fn = container_of(dev, struct ocxl_fn, dev); in free_function_dev() local
325 free_function(fn); in free_function_dev()
328 static int set_function_device(struct ocxl_fn *fn, struct pci_dev *dev) in set_function_device() argument
330 fn->dev.parent = &dev->dev; in set_function_device()
331 fn->dev.release = free_function_dev; in set_function_device()
332 return dev_set_name(&fn->dev, "ocxlfn.%s", dev_name(&dev->dev)); in set_function_device()
335 static int assign_function_actag(struct ocxl_fn *fn) in assign_function_actag() argument
337 struct pci_dev *dev = to_pci_dev(fn->dev.parent); in assign_function_actag()
345 fn->actag_base = base; in assign_function_actag()
346 fn->actag_enabled = enabled; in assign_function_actag()
347 fn->actag_supported = supported; in assign_function_actag()
349 ocxl_config_set_actag(dev, fn->config.dvsec_function_pos, in assign_function_actag()
350 fn->actag_base, fn->actag_enabled); in assign_function_actag()
351 dev_dbg(&fn->dev, "actag range starting at %d, enabled %d\n", in assign_function_actag()
352 fn->actag_base, fn->actag_enabled); in assign_function_actag()
356 static int set_function_pasid(struct ocxl_fn *fn) in set_function_pasid() argument
358 struct pci_dev *dev = to_pci_dev(fn->dev.parent); in set_function_pasid()
362 if (fn->config.max_pasid_log < 0) in set_function_pasid()
369 desired_count = 1 << fn->config.max_pasid_log; in set_function_pasid()
372 dev_err(&fn->dev, in set_function_pasid()
378 fn->pasid_base = 0; in set_function_pasid()
382 static int configure_function(struct ocxl_fn *fn, struct pci_dev *dev) in configure_function() argument
413 rc = ocxl_config_read_function(dev, &fn->config); in configure_function()
417 rc = set_function_device(fn, dev); in configure_function()
421 rc = assign_function_actag(fn); in configure_function()
425 rc = set_function_pasid(fn); in configure_function()
429 rc = ocxl_link_setup(dev, 0, &fn->link); in configure_function()
433 rc = ocxl_config_set_TL(dev, fn->config.dvsec_tl_pos); in configure_function()
435 ocxl_link_release(dev, fn->link); in configure_function()
441 static void deconfigure_function(struct ocxl_fn *fn) in deconfigure_function() argument
443 struct pci_dev *dev = to_pci_dev(fn->dev.parent); in deconfigure_function()
445 ocxl_link_release(dev, fn->link); in deconfigure_function()
451 struct ocxl_fn *fn; in init_function() local
454 fn = alloc_function(); in init_function()
455 if (!fn) in init_function()
458 rc = configure_function(fn, dev); in init_function()
460 free_function(fn); in init_function()
464 rc = device_register(&fn->dev); in init_function()
466 deconfigure_function(fn); in init_function()
467 put_device(&fn->dev); in init_function()
470 return fn; in init_function()
479 struct ocxl_fn *fn; in ocxl_function_open() local
486 fn = init_function(dev); in ocxl_function_open()
487 if (IS_ERR(fn)) { in ocxl_function_open()
489 PTR_ERR(fn)); in ocxl_function_open()
490 return fn; in ocxl_function_open()
493 for (afu = 0; afu <= fn->config.max_afu_index; afu++) { in ocxl_function_open()
494 rc = ocxl_config_check_afu_index(dev, &fn->config, afu); in ocxl_function_open()
496 rc = init_afu(dev, fn, afu); in ocxl_function_open()
506 return fn; in ocxl_function_open()
510 struct list_head *ocxl_function_afu_list(struct ocxl_fn *fn) in ocxl_function_afu_list() argument
512 return &fn->afu_list; in ocxl_function_afu_list()
516 struct ocxl_afu *ocxl_function_fetch_afu(struct ocxl_fn *fn, u8 afu_idx) in ocxl_function_fetch_afu() argument
520 list_for_each_entry(afu, &fn->afu_list, list) { in ocxl_function_fetch_afu()
529 const struct ocxl_fn_config *ocxl_function_config(struct ocxl_fn *fn) in ocxl_function_config() argument
531 return &fn->config; in ocxl_function_config()
535 void ocxl_function_close(struct ocxl_fn *fn) in ocxl_function_close() argument
539 list_for_each_entry_safe(afu, tmp, &fn->afu_list, list) { in ocxl_function_close()
543 deconfigure_function(fn); in ocxl_function_close()
544 device_unregister(&fn->dev); in ocxl_function_close()