Lines Matching refs:afu
18 static void pci_error_handlers(struct cxl_afu *afu, in pci_error_handlers() argument
24 if (afu->phb == NULL) in pci_error_handlers()
27 list_for_each_entry(afu_dev, &afu->phb->bus->devices, bus_list) { in pci_error_handlers()
59 dev_crit(&ctx->afu->dev, "PSL ERROR STATUS: 0x%.16llx\n", errstat); in guest_handle_psl_slice_error()
64 static ssize_t guest_collect_vpd(struct cxl *adapter, struct cxl_afu *afu, in guest_collect_vpd() argument
114 rc = cxl_h_collect_vpd(afu->guest->handle, 0, in guest_collect_vpd()
152 return cxl_h_collect_int_info(ctx->afu->guest->handle, ctx->process_token, info); in guest_get_irq_info()
172 static int afu_read_error_state(struct cxl_afu *afu, int *state_out) in afu_read_error_state() argument
177 if (!afu) in afu_read_error_state()
180 rc = cxl_h_read_error_state(afu->guest->handle, &state); in afu_read_error_state()
193 struct cxl_afu *afu = data; in guest_slice_irq_err() local
197 rc = cxl_h_get_fn_error_interrupt(afu->guest->handle, &serr); in guest_slice_irq_err()
199 dev_crit(&afu->dev, "Couldn't read PSL_SERR_An: %d\n", rc); in guest_slice_irq_err()
202 afu_error = cxl_p2n_read(afu, CXL_AFU_ERR_An); in guest_slice_irq_err()
203 dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An); in guest_slice_irq_err()
204 cxl_afu_decode_psl_serr(afu, serr); in guest_slice_irq_err()
205 dev_crit(&afu->dev, "AFU_ERR_An: 0x%.16llx\n", afu_error); in guest_slice_irq_err()
206 dev_crit(&afu->dev, "PSL_DSISR_An: 0x%.16llx\n", dsisr); in guest_slice_irq_err()
208 rc = cxl_h_ack_fn_error_interrupt(afu->guest->handle, serr); in guest_slice_irq_err()
210 dev_crit(&afu->dev, "Couldn't ack slice error interrupt: %d\n", in guest_slice_irq_err()
262 struct cxl_afu *afu = NULL; in guest_reset() local
268 if ((afu = adapter->afu[i])) { in guest_reset()
269 pci_error_handlers(afu, CXL_ERROR_DETECTED_EVENT, in guest_reset()
271 cxl_context_detach_all(afu); in guest_reset()
277 if (!rc && (afu = adapter->afu[i])) { in guest_reset()
278 pci_error_handlers(afu, CXL_SLOT_RESET_EVENT, in guest_reset()
280 pci_error_handlers(afu, CXL_RESUME_EVENT, 0); in guest_reset()
349 static int guest_register_serr_irq(struct cxl_afu *afu) in guest_register_serr_irq() argument
351 afu->err_irq_name = kasprintf(GFP_KERNEL, "cxl-%s-err", in guest_register_serr_irq()
352 dev_name(&afu->dev)); in guest_register_serr_irq()
353 if (!afu->err_irq_name) in guest_register_serr_irq()
356 if (!(afu->serr_virq = cxl_map_irq(afu->adapter, afu->serr_hwirq, in guest_register_serr_irq()
357 guest_slice_irq_err, afu, afu->err_irq_name))) { in guest_register_serr_irq()
358 kfree(afu->err_irq_name); in guest_register_serr_irq()
359 afu->err_irq_name = NULL; in guest_register_serr_irq()
366 static void guest_release_serr_irq(struct cxl_afu *afu) in guest_release_serr_irq() argument
368 cxl_unmap_irq(afu->serr_virq, afu); in guest_release_serr_irq()
369 cxl_ops->release_one_irq(afu->adapter, afu->serr_hwirq); in guest_release_serr_irq()
370 kfree(afu->err_irq_name); in guest_release_serr_irq()
375 return cxl_h_control_faults(ctx->afu->guest->handle, ctx->process_token, in guest_ack_irq()
385 pr_devel("Disabling AFU(%d) interrupts\n", ctx->afu->slice); in disable_afu_irqs()
401 pr_devel("Enabling AFU(%d) interrupts\n", ctx->afu->slice); in enable_afu_irqs()
411 static int _guest_afu_cr_readXX(int sz, struct cxl_afu *afu, int cr_idx, in _guest_afu_cr_readXX() argument
418 if (afu->crs_len < sz) in _guest_afu_cr_readXX()
421 if (unlikely(offset >= afu->crs_len)) in _guest_afu_cr_readXX()
428 rc = cxl_h_get_config(afu->guest->handle, cr_idx, offset, in _guest_afu_cr_readXX()
455 static int guest_afu_cr_read32(struct cxl_afu *afu, int cr_idx, u64 offset, in guest_afu_cr_read32() argument
461 rc = _guest_afu_cr_readXX(4, afu, cr_idx, offset, &val); in guest_afu_cr_read32()
467 static int guest_afu_cr_read16(struct cxl_afu *afu, int cr_idx, u64 offset, in guest_afu_cr_read16() argument
473 rc = _guest_afu_cr_readXX(2, afu, cr_idx, offset, &val); in guest_afu_cr_read16()
479 static int guest_afu_cr_read8(struct cxl_afu *afu, int cr_idx, u64 offset, in guest_afu_cr_read8() argument
485 rc = _guest_afu_cr_readXX(1, afu, cr_idx, offset, &val); in guest_afu_cr_read8()
491 static int guest_afu_cr_read64(struct cxl_afu *afu, int cr_idx, u64 offset, in guest_afu_cr_read64() argument
494 return _guest_afu_cr_readXX(8, afu, cr_idx, offset, out); in guest_afu_cr_read64()
497 static int guest_afu_cr_write32(struct cxl_afu *afu, int cr, u64 off, u32 in) in guest_afu_cr_write32() argument
503 static int guest_afu_cr_write16(struct cxl_afu *afu, int cr, u64 off, u16 in) in guest_afu_cr_write16() argument
509 static int guest_afu_cr_write8(struct cxl_afu *afu, int cr, u64 off, u8 in) in guest_afu_cr_write8() argument
518 struct cxl *adapter = ctx->afu->adapter; in attach_afu_directed()
585 rc = cxl_h_attach_process(ctx->afu->guest->handle, elem, in attach_afu_directed()
588 if (ctx->master || !ctx->afu->pp_psa) { in attach_afu_directed()
589 ctx->psn_phys = ctx->afu->psn_phys; in attach_afu_directed()
590 ctx->psn_size = ctx->afu->adapter->ps_size; in attach_afu_directed()
595 if (ctx->afu->pp_psa && mmio_size && in attach_afu_directed()
596 ctx->afu->pp_size == 0) { in attach_afu_directed()
605 ctx->afu->pp_size = mmio_size; in attach_afu_directed()
625 if (ctx->afu->current_mode == CXL_MODE_DIRECTED) in guest_attach_process()
637 if (cxl_h_detach_process(ctx->afu->guest->handle, ctx->process_token)) in detach_afu_directed()
647 if (!cxl_ops->link_ok(ctx->afu->adapter, ctx->afu)) in guest_detach_process()
650 if (ctx->afu->current_mode == CXL_MODE_DIRECTED) in guest_detach_process()
658 struct cxl_afu *afu = to_cxl_afu(dev); in guest_release_afu() local
662 idr_destroy(&afu->contexts_idr); in guest_release_afu()
664 kfree(afu->guest); in guest_release_afu()
665 kfree(afu); in guest_release_afu()
668 ssize_t cxl_guest_read_afu_vpd(struct cxl_afu *afu, void *buf, size_t len) in cxl_guest_read_afu_vpd() argument
670 return guest_collect_vpd(NULL, afu, buf, len); in cxl_guest_read_afu_vpd()
674 static ssize_t guest_afu_read_err_buffer(struct cxl_afu *afu, char *buf, in guest_afu_read_err_buffer() argument
684 rc = cxl_h_get_afu_err(afu->guest->handle, in guest_afu_read_err_buffer()
700 static int guest_afu_check_and_enable(struct cxl_afu *afu) in guest_afu_check_and_enable() argument
729 static int activate_afu_directed(struct cxl_afu *afu) in activate_afu_directed() argument
733 dev_info(&afu->dev, "Activating AFU(%d) directed mode\n", afu->slice); in activate_afu_directed()
735 afu->current_mode = CXL_MODE_DIRECTED; in activate_afu_directed()
737 afu->num_procs = afu->max_procs_virtualised; in activate_afu_directed()
739 if ((rc = cxl_chardev_m_afu_add(afu))) in activate_afu_directed()
742 if ((rc = cxl_sysfs_afu_m_add(afu))) in activate_afu_directed()
745 if ((rc = cxl_chardev_s_afu_add(afu))) in activate_afu_directed()
750 cxl_sysfs_afu_m_remove(afu); in activate_afu_directed()
752 cxl_chardev_afu_remove(afu); in activate_afu_directed()
756 static int guest_afu_activate_mode(struct cxl_afu *afu, int mode) in guest_afu_activate_mode() argument
760 if (!(mode & afu->modes_supported)) in guest_afu_activate_mode()
764 return activate_afu_directed(afu); in guest_afu_activate_mode()
767 dev_err(&afu->dev, "Dedicated mode not supported\n"); in guest_afu_activate_mode()
772 static int deactivate_afu_directed(struct cxl_afu *afu) in deactivate_afu_directed() argument
774 dev_info(&afu->dev, "Deactivating AFU(%d) directed mode\n", afu->slice); in deactivate_afu_directed()
776 afu->current_mode = 0; in deactivate_afu_directed()
777 afu->num_procs = 0; in deactivate_afu_directed()
779 cxl_sysfs_afu_m_remove(afu); in deactivate_afu_directed()
780 cxl_chardev_afu_remove(afu); in deactivate_afu_directed()
782 cxl_ops->afu_reset(afu); in deactivate_afu_directed()
787 static int guest_afu_deactivate_mode(struct cxl_afu *afu, int mode) in guest_afu_deactivate_mode() argument
791 if (!(mode & afu->modes_supported)) in guest_afu_deactivate_mode()
795 return deactivate_afu_directed(afu); in guest_afu_deactivate_mode()
799 static int guest_afu_reset(struct cxl_afu *afu) in guest_afu_reset() argument
801 pr_devel("AFU(%d) reset request\n", afu->slice); in guest_afu_reset()
802 return cxl_h_reset_afu(afu->guest->handle); in guest_afu_reset()
805 static int guest_map_slice_regs(struct cxl_afu *afu) in guest_map_slice_regs() argument
807 if (!(afu->p2n_mmio = ioremap(afu->guest->p2n_phys, afu->guest->p2n_size))) { in guest_map_slice_regs()
808 dev_err(&afu->dev, "Error mapping AFU(%d) MMIO regions\n", in guest_map_slice_regs()
809 afu->slice); in guest_map_slice_regs()
815 static void guest_unmap_slice_regs(struct cxl_afu *afu) in guest_unmap_slice_regs() argument
817 if (afu->p2n_mmio) in guest_unmap_slice_regs()
818 iounmap(afu->p2n_mmio); in guest_unmap_slice_regs()
821 static int afu_update_state(struct cxl_afu *afu) in afu_update_state() argument
825 rc = afu_read_error_state(afu, &cur_state); in afu_update_state()
829 if (afu->guest->previous_state == cur_state) in afu_update_state()
832 pr_devel("AFU(%d) update state to %#x\n", afu->slice, cur_state); in afu_update_state()
836 afu->guest->previous_state = cur_state; in afu_update_state()
840 pci_error_handlers(afu, CXL_ERROR_DETECTED_EVENT, in afu_update_state()
843 cxl_context_detach_all(afu); in afu_update_state()
844 if ((rc = cxl_ops->afu_reset(afu))) in afu_update_state()
847 rc = afu_read_error_state(afu, &cur_state); in afu_update_state()
849 pci_error_handlers(afu, CXL_SLOT_RESET_EVENT, in afu_update_state()
851 pci_error_handlers(afu, CXL_RESUME_EVENT, 0); in afu_update_state()
853 afu->guest->previous_state = 0; in afu_update_state()
857 afu->guest->previous_state = cur_state; in afu_update_state()
861 dev_err(&afu->dev, "AFU is in permanent error state\n"); in afu_update_state()
862 pci_error_handlers(afu, CXL_ERROR_DETECTED_EVENT, in afu_update_state()
864 afu->guest->previous_state = cur_state; in afu_update_state()
869 afu->slice, cur_state); in afu_update_state()
890 static bool guest_link_ok(struct cxl *cxl, struct cxl_afu *afu) in guest_link_ok() argument
894 if (afu && (!afu_read_error_state(afu, &state))) { in guest_link_ok()
902 static int afu_properties_look_ok(struct cxl_afu *afu) in afu_properties_look_ok() argument
904 if (afu->pp_irqs < 0) { in afu_properties_look_ok()
905 dev_err(&afu->dev, "Unexpected per-process minimum interrupt value\n"); in afu_properties_look_ok()
909 if (afu->max_procs_virtualised < 1) { in afu_properties_look_ok()
910 dev_err(&afu->dev, "Unexpected max number of processes virtualised value\n"); in afu_properties_look_ok()
919 struct cxl_afu *afu; in cxl_guest_init_afu() local
924 if (!(afu = cxl_alloc_afu(adapter, slice))) in cxl_guest_init_afu()
927 if (!(afu->guest = kzalloc(sizeof(struct cxl_afu_guest), GFP_KERNEL))) { in cxl_guest_init_afu()
928 kfree(afu); in cxl_guest_init_afu()
932 if ((rc = dev_set_name(&afu->dev, "afu%i.%i", in cxl_guest_init_afu()
939 if ((rc = cxl_of_read_afu_handle(afu, afu_np))) in cxl_guest_init_afu()
942 if ((rc = cxl_ops->afu_reset(afu))) in cxl_guest_init_afu()
945 if ((rc = cxl_of_read_afu_properties(afu, afu_np))) in cxl_guest_init_afu()
948 if ((rc = afu_properties_look_ok(afu))) in cxl_guest_init_afu()
951 if ((rc = guest_map_slice_regs(afu))) in cxl_guest_init_afu()
954 if ((rc = guest_register_serr_irq(afu))) in cxl_guest_init_afu()
961 if ((rc = cxl_register_afu(afu))) in cxl_guest_init_afu()
964 if ((rc = cxl_sysfs_afu_add(afu))) in cxl_guest_init_afu()
975 if (afu->max_procs_virtualised == 1) in cxl_guest_init_afu()
976 afu->modes_supported = CXL_MODE_DEDICATED; in cxl_guest_init_afu()
978 afu->modes_supported = CXL_MODE_DIRECTED; in cxl_guest_init_afu()
980 if ((rc = cxl_afu_select_best_mode(afu))) in cxl_guest_init_afu()
983 adapter->afu[afu->slice] = afu; in cxl_guest_init_afu()
985 afu->enabled = true; in cxl_guest_init_afu()
991 afu->guest->parent = afu; in cxl_guest_init_afu()
992 afu->guest->handle_err = true; in cxl_guest_init_afu()
993 INIT_DELAYED_WORK(&afu->guest->work_err, afu_handle_errstate); in cxl_guest_init_afu()
994 schedule_delayed_work(&afu->guest->work_err, msecs_to_jiffies(1000)); in cxl_guest_init_afu()
996 if ((rc = cxl_pci_vphb_add(afu))) in cxl_guest_init_afu()
997 dev_info(&afu->dev, "Can't register vPHB\n"); in cxl_guest_init_afu()
1002 cxl_sysfs_afu_remove(afu); in cxl_guest_init_afu()
1004 device_unregister(&afu->dev); in cxl_guest_init_afu()
1006 guest_release_serr_irq(afu); in cxl_guest_init_afu()
1008 guest_unmap_slice_regs(afu); in cxl_guest_init_afu()
1011 kfree(afu->guest); in cxl_guest_init_afu()
1012 kfree(afu); in cxl_guest_init_afu()
1017 void cxl_guest_remove_afu(struct cxl_afu *afu) in cxl_guest_remove_afu() argument
1019 if (!afu) in cxl_guest_remove_afu()
1023 afu->guest->handle_err = false; in cxl_guest_remove_afu()
1024 flush_delayed_work(&afu->guest->work_err); in cxl_guest_remove_afu()
1026 cxl_pci_vphb_remove(afu); in cxl_guest_remove_afu()
1027 cxl_sysfs_afu_remove(afu); in cxl_guest_remove_afu()
1029 spin_lock(&afu->adapter->afu_list_lock); in cxl_guest_remove_afu()
1030 afu->adapter->afu[afu->slice] = NULL; in cxl_guest_remove_afu()
1031 spin_unlock(&afu->adapter->afu_list_lock); in cxl_guest_remove_afu()
1033 cxl_context_detach_all(afu); in cxl_guest_remove_afu()
1034 cxl_ops->afu_deactivate_mode(afu, afu->current_mode); in cxl_guest_remove_afu()
1035 guest_release_serr_irq(afu); in cxl_guest_remove_afu()
1036 guest_unmap_slice_regs(afu); in cxl_guest_remove_afu()
1038 device_unregister(&afu->dev); in cxl_guest_remove_afu()