Lines Matching refs:afu

18 static void pci_error_handlers(struct cxl_afu *afu,  in pci_error_handlers()  argument
26 if (afu->phb == NULL) in pci_error_handlers()
29 list_for_each_entry(afu_dev, &afu->phb->bus->devices, bus_list) { in pci_error_handlers()
63 dev_crit(&ctx->afu->dev, "PSL ERROR STATUS: 0x%.16llx\n", errstat); in guest_handle_psl_slice_error()
68 static ssize_t guest_collect_vpd(struct cxl *adapter, struct cxl_afu *afu, in guest_collect_vpd() argument
118 rc = cxl_h_collect_vpd(afu->guest->handle, 0, in guest_collect_vpd()
156 return cxl_h_collect_int_info(ctx->afu->guest->handle, ctx->process_token, info); in guest_get_irq_info()
176 static int afu_read_error_state(struct cxl_afu *afu, int *state_out) in afu_read_error_state() argument
181 if (!afu) in afu_read_error_state()
184 rc = cxl_h_read_error_state(afu->guest->handle, &state); in afu_read_error_state()
197 struct cxl_afu *afu = data; in guest_slice_irq_err() local
201 rc = cxl_h_get_fn_error_interrupt(afu->guest->handle, &serr); in guest_slice_irq_err()
203 dev_crit(&afu->dev, "Couldn't read PSL_SERR_An: %d\n", rc); in guest_slice_irq_err()
206 afu_error = cxl_p2n_read(afu, CXL_AFU_ERR_An); in guest_slice_irq_err()
207 dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); in guest_slice_irq_err()
208 cxl_afu_decode_psl_serr(afu, serr); in guest_slice_irq_err()
209 dev_crit(&afu->dev, "AFU_ERR_An: 0x%.16llx\n", afu_error); in guest_slice_irq_err()
210 dev_crit(&afu->dev, "PSL_DSISR_An: 0x%.16llx\n", dsisr); in guest_slice_irq_err()
212 rc = cxl_h_ack_fn_error_interrupt(afu->guest->handle, serr); in guest_slice_irq_err()
214 dev_crit(&afu->dev, "Couldn't ack slice error interrupt: %d\n", in guest_slice_irq_err()
266 struct cxl_afu *afu = NULL; in guest_reset() local
272 if ((afu = adapter->afu[i])) { in guest_reset()
273 pci_error_handlers(afu, CXL_ERROR_DETECTED_EVENT, in guest_reset()
275 cxl_context_detach_all(afu); in guest_reset()
281 if (!rc && (afu = adapter->afu[i])) { in guest_reset()
282 pci_error_handlers(afu, CXL_SLOT_RESET_EVENT, in guest_reset()
284 pci_error_handlers(afu, CXL_RESUME_EVENT, 0); in guest_reset()
353 static int guest_register_serr_irq(struct cxl_afu *afu) in guest_register_serr_irq() argument
355 afu->err_irq_name = kasprintf(GFP_KERNEL, "cxl-%s-err", in guest_register_serr_irq()
356 dev_name(&afu->dev)); in guest_register_serr_irq()
357 if (!afu->err_irq_name) in guest_register_serr_irq()
360 if (!(afu->serr_virq = cxl_map_irq(afu->adapter, afu->serr_hwirq, in guest_register_serr_irq()
361 guest_slice_irq_err, afu, afu->err_irq_name))) { in guest_register_serr_irq()
362 kfree(afu->err_irq_name); in guest_register_serr_irq()
363 afu->err_irq_name = NULL; in guest_register_serr_irq()
370 static void guest_release_serr_irq(struct cxl_afu *afu) in guest_release_serr_irq() argument
372 cxl_unmap_irq(afu->serr_virq, afu); in guest_release_serr_irq()
373 cxl_ops->release_one_irq(afu->adapter, afu->serr_hwirq); in guest_release_serr_irq()
374 kfree(afu->err_irq_name); in guest_release_serr_irq()
379 return cxl_h_control_faults(ctx->afu->guest->handle, ctx->process_token, in guest_ack_irq()
389 pr_devel("Disabling AFU(%d) interrupts\n", ctx->afu->slice); in disable_afu_irqs()
405 pr_devel("Enabling AFU(%d) interrupts\n", ctx->afu->slice); in enable_afu_irqs()
415 static int _guest_afu_cr_readXX(int sz, struct cxl_afu *afu, int cr_idx, in _guest_afu_cr_readXX() argument
422 if (afu->crs_len < sz) in _guest_afu_cr_readXX()
425 if (unlikely(offset >= afu->crs_len)) in _guest_afu_cr_readXX()
432 rc = cxl_h_get_config(afu->guest->handle, cr_idx, offset, in _guest_afu_cr_readXX()
459 static int guest_afu_cr_read32(struct cxl_afu *afu, int cr_idx, u64 offset, in guest_afu_cr_read32() argument
465 rc = _guest_afu_cr_readXX(4, afu, cr_idx, offset, &val); in guest_afu_cr_read32()
471 static int guest_afu_cr_read16(struct cxl_afu *afu, int cr_idx, u64 offset, in guest_afu_cr_read16() argument
477 rc = _guest_afu_cr_readXX(2, afu, cr_idx, offset, &val); in guest_afu_cr_read16()
483 static int guest_afu_cr_read8(struct cxl_afu *afu, int cr_idx, u64 offset, in guest_afu_cr_read8() argument
489 rc = _guest_afu_cr_readXX(1, afu, cr_idx, offset, &val); in guest_afu_cr_read8()
495 static int guest_afu_cr_read64(struct cxl_afu *afu, int cr_idx, u64 offset, in guest_afu_cr_read64() argument
498 return _guest_afu_cr_readXX(8, afu, cr_idx, offset, out); in guest_afu_cr_read64()
501 static int guest_afu_cr_write32(struct cxl_afu *afu, int cr, u64 off, u32 in) in guest_afu_cr_write32() argument
507 static int guest_afu_cr_write16(struct cxl_afu *afu, int cr, u64 off, u16 in) in guest_afu_cr_write16() argument
513 static int guest_afu_cr_write8(struct cxl_afu *afu, int cr, u64 off, u8 in) in guest_afu_cr_write8() argument
522 struct cxl *adapter = ctx->afu->adapter; in attach_afu_directed()
589 rc = cxl_h_attach_process(ctx->afu->guest->handle, elem, in attach_afu_directed()
592 if (ctx->master || !ctx->afu->pp_psa) { in attach_afu_directed()
593 ctx->psn_phys = ctx->afu->psn_phys; in attach_afu_directed()
594 ctx->psn_size = ctx->afu->adapter->ps_size; in attach_afu_directed()
599 if (ctx->afu->pp_psa && mmio_size && in attach_afu_directed()
600 ctx->afu->pp_size == 0) { in attach_afu_directed()
609 ctx->afu->pp_size = mmio_size; in attach_afu_directed()
629 if (ctx->afu->current_mode == CXL_MODE_DIRECTED) in guest_attach_process()
641 if (cxl_h_detach_process(ctx->afu->guest->handle, ctx->process_token)) in detach_afu_directed()
651 if (!cxl_ops->link_ok(ctx->afu->adapter, ctx->afu)) in guest_detach_process()
654 if (ctx->afu->current_mode == CXL_MODE_DIRECTED) in guest_detach_process()
662 struct cxl_afu *afu = to_cxl_afu(dev); in guest_release_afu() local
666 idr_destroy(&afu->contexts_idr); in guest_release_afu()
668 kfree(afu->guest); in guest_release_afu()
669 kfree(afu); in guest_release_afu()
672 ssize_t cxl_guest_read_afu_vpd(struct cxl_afu *afu, void *buf, size_t len) in cxl_guest_read_afu_vpd() argument
674 return guest_collect_vpd(NULL, afu, buf, len); in cxl_guest_read_afu_vpd()
678 static ssize_t guest_afu_read_err_buffer(struct cxl_afu *afu, char *buf, in guest_afu_read_err_buffer() argument
688 rc = cxl_h_get_afu_err(afu->guest->handle, in guest_afu_read_err_buffer()
704 static int guest_afu_check_and_enable(struct cxl_afu *afu) in guest_afu_check_and_enable() argument
733 static int activate_afu_directed(struct cxl_afu *afu) in activate_afu_directed() argument
737 dev_info(&afu->dev, "Activating AFU(%d) directed mode\n", afu->slice); in activate_afu_directed()
739 afu->current_mode = CXL_MODE_DIRECTED; in activate_afu_directed()
741 afu->num_procs = afu->max_procs_virtualised; in activate_afu_directed()
743 if ((rc = cxl_chardev_m_afu_add(afu))) in activate_afu_directed()
746 if ((rc = cxl_sysfs_afu_m_add(afu))) in activate_afu_directed()
749 if ((rc = cxl_chardev_s_afu_add(afu))) in activate_afu_directed()
754 cxl_sysfs_afu_m_remove(afu); in activate_afu_directed()
756 cxl_chardev_afu_remove(afu); in activate_afu_directed()
760 static int guest_afu_activate_mode(struct cxl_afu *afu, int mode) in guest_afu_activate_mode() argument
764 if (!(mode & afu->modes_supported)) in guest_afu_activate_mode()
768 return activate_afu_directed(afu); in guest_afu_activate_mode()
771 dev_err(&afu->dev, "Dedicated mode not supported\n"); in guest_afu_activate_mode()
776 static int deactivate_afu_directed(struct cxl_afu *afu) in deactivate_afu_directed() argument
778 dev_info(&afu->dev, "Deactivating AFU(%d) directed mode\n", afu->slice); in deactivate_afu_directed()
780 afu->current_mode = 0; in deactivate_afu_directed()
781 afu->num_procs = 0; in deactivate_afu_directed()
783 cxl_sysfs_afu_m_remove(afu); in deactivate_afu_directed()
784 cxl_chardev_afu_remove(afu); in deactivate_afu_directed()
786 cxl_ops->afu_reset(afu); in deactivate_afu_directed()
791 static int guest_afu_deactivate_mode(struct cxl_afu *afu, int mode) in guest_afu_deactivate_mode() argument
795 if (!(mode & afu->modes_supported)) in guest_afu_deactivate_mode()
799 return deactivate_afu_directed(afu); in guest_afu_deactivate_mode()
803 static int guest_afu_reset(struct cxl_afu *afu) in guest_afu_reset() argument
805 pr_devel("AFU(%d) reset request\n", afu->slice); in guest_afu_reset()
806 return cxl_h_reset_afu(afu->guest->handle); in guest_afu_reset()
809 static int guest_map_slice_regs(struct cxl_afu *afu) in guest_map_slice_regs() argument
811 if (!(afu->p2n_mmio = ioremap(afu->guest->p2n_phys, afu->guest->p2n_size))) { in guest_map_slice_regs()
812 dev_err(&afu->dev, "Error mapping AFU(%d) MMIO regions\n", in guest_map_slice_regs()
813 afu->slice); in guest_map_slice_regs()
819 static void guest_unmap_slice_regs(struct cxl_afu *afu) in guest_unmap_slice_regs() argument
821 if (afu->p2n_mmio) in guest_unmap_slice_regs()
822 iounmap(afu->p2n_mmio); in guest_unmap_slice_regs()
825 static int afu_update_state(struct cxl_afu *afu) in afu_update_state() argument
829 rc = afu_read_error_state(afu, &cur_state); in afu_update_state()
833 if (afu->guest->previous_state == cur_state) in afu_update_state()
836 pr_devel("AFU(%d) update state to %#x\n", afu->slice, cur_state); in afu_update_state()
840 afu->guest->previous_state = cur_state; in afu_update_state()
844 pci_error_handlers(afu, CXL_ERROR_DETECTED_EVENT, in afu_update_state()
847 cxl_context_detach_all(afu); in afu_update_state()
848 if ((rc = cxl_ops->afu_reset(afu))) in afu_update_state()
851 rc = afu_read_error_state(afu, &cur_state); in afu_update_state()
853 pci_error_handlers(afu, CXL_SLOT_RESET_EVENT, in afu_update_state()
855 pci_error_handlers(afu, CXL_RESUME_EVENT, 0); in afu_update_state()
857 afu->guest->previous_state = 0; in afu_update_state()
861 afu->guest->previous_state = cur_state; in afu_update_state()
865 dev_err(&afu->dev, "AFU is in permanent error state\n"); in afu_update_state()
866 pci_error_handlers(afu, CXL_ERROR_DETECTED_EVENT, in afu_update_state()
868 afu->guest->previous_state = cur_state; in afu_update_state()
873 afu->slice, cur_state); in afu_update_state()
894 static bool guest_link_ok(struct cxl *cxl, struct cxl_afu *afu) in guest_link_ok() argument
898 if (afu && (!afu_read_error_state(afu, &state))) { in guest_link_ok()
906 static int afu_properties_look_ok(struct cxl_afu *afu) in afu_properties_look_ok() argument
908 if (afu->pp_irqs < 0) { in afu_properties_look_ok()
909 dev_err(&afu->dev, "Unexpected per-process minimum interrupt value\n"); in afu_properties_look_ok()
913 if (afu->max_procs_virtualised < 1) { in afu_properties_look_ok()
914 dev_err(&afu->dev, "Unexpected max number of processes virtualised value\n"); in afu_properties_look_ok()
923 struct cxl_afu *afu; in cxl_guest_init_afu() local
928 if (!(afu = cxl_alloc_afu(adapter, slice))) in cxl_guest_init_afu()
931 if (!(afu->guest = kzalloc(sizeof(struct cxl_afu_guest), GFP_KERNEL))) { in cxl_guest_init_afu()
932 kfree(afu); in cxl_guest_init_afu()
936 if ((rc = dev_set_name(&afu->dev, "afu%i.%i", in cxl_guest_init_afu()
943 if ((rc = cxl_of_read_afu_handle(afu, afu_np))) in cxl_guest_init_afu()
946 if ((rc = cxl_ops->afu_reset(afu))) in cxl_guest_init_afu()
949 if ((rc = cxl_of_read_afu_properties(afu, afu_np))) in cxl_guest_init_afu()
952 if ((rc = afu_properties_look_ok(afu))) in cxl_guest_init_afu()
955 if ((rc = guest_map_slice_regs(afu))) in cxl_guest_init_afu()
958 if ((rc = guest_register_serr_irq(afu))) in cxl_guest_init_afu()
965 if ((rc = cxl_register_afu(afu))) in cxl_guest_init_afu()
968 if ((rc = cxl_sysfs_afu_add(afu))) in cxl_guest_init_afu()
979 if (afu->max_procs_virtualised == 1) in cxl_guest_init_afu()
980 afu->modes_supported = CXL_MODE_DEDICATED; in cxl_guest_init_afu()
982 afu->modes_supported = CXL_MODE_DIRECTED; in cxl_guest_init_afu()
984 if ((rc = cxl_afu_select_best_mode(afu))) in cxl_guest_init_afu()
987 adapter->afu[afu->slice] = afu; in cxl_guest_init_afu()
989 afu->enabled = true; in cxl_guest_init_afu()
995 afu->guest->parent = afu; in cxl_guest_init_afu()
996 afu->guest->handle_err = true; in cxl_guest_init_afu()
997 INIT_DELAYED_WORK(&afu->guest->work_err, afu_handle_errstate); in cxl_guest_init_afu()
998 schedule_delayed_work(&afu->guest->work_err, msecs_to_jiffies(1000)); in cxl_guest_init_afu()
1000 if ((rc = cxl_pci_vphb_add(afu))) in cxl_guest_init_afu()
1001 dev_info(&afu->dev, "Can't register vPHB\n"); in cxl_guest_init_afu()
1006 cxl_sysfs_afu_remove(afu); in cxl_guest_init_afu()
1008 device_unregister(&afu->dev); in cxl_guest_init_afu()
1010 guest_release_serr_irq(afu); in cxl_guest_init_afu()
1012 guest_unmap_slice_regs(afu); in cxl_guest_init_afu()
1015 kfree(afu->guest); in cxl_guest_init_afu()
1016 kfree(afu); in cxl_guest_init_afu()
1021 void cxl_guest_remove_afu(struct cxl_afu *afu) in cxl_guest_remove_afu() argument
1023 if (!afu) in cxl_guest_remove_afu()
1027 afu->guest->handle_err = false; in cxl_guest_remove_afu()
1028 flush_delayed_work(&afu->guest->work_err); in cxl_guest_remove_afu()
1030 cxl_pci_vphb_remove(afu); in cxl_guest_remove_afu()
1031 cxl_sysfs_afu_remove(afu); in cxl_guest_remove_afu()
1033 spin_lock(&afu->adapter->afu_list_lock); in cxl_guest_remove_afu()
1034 afu->adapter->afu[afu->slice] = NULL; in cxl_guest_remove_afu()
1035 spin_unlock(&afu->adapter->afu_list_lock); in cxl_guest_remove_afu()
1037 cxl_context_detach_all(afu); in cxl_guest_remove_afu()
1038 cxl_ops->afu_deactivate_mode(afu, afu->current_mode); in cxl_guest_remove_afu()
1039 guest_release_serr_irq(afu); in cxl_guest_remove_afu()
1040 guest_unmap_slice_regs(afu); in cxl_guest_remove_afu()
1042 device_unregister(&afu->dev); in cxl_guest_remove_afu()