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