Lines Matching refs:afu

20 static void pci_error_handlers(struct cxl_afu *afu,
28 if (afu->phb == NULL)
31 list_for_each_entry(afu_dev, &afu->phb->bus->devices, bus_list) {
65 dev_crit(&ctx->afu->dev, "PSL ERROR STATUS: 0x%.16llx\n", errstat);
70 static ssize_t guest_collect_vpd(struct cxl *adapter, struct cxl_afu *afu,
120 rc = cxl_h_collect_vpd(afu->guest->handle, 0,
158 return cxl_h_collect_int_info(ctx->afu->guest->handle, ctx->process_token, info);
178 static int afu_read_error_state(struct cxl_afu *afu, int *state_out)
183 if (!afu)
186 rc = cxl_h_read_error_state(afu->guest->handle, &state);
199 struct cxl_afu *afu = data;
203 rc = cxl_h_get_fn_error_interrupt(afu->guest->handle, &serr);
205 dev_crit(&afu->dev, "Couldn't read PSL_SERR_An: %d\n", rc);
208 afu_error = cxl_p2n_read(afu, CXL_AFU_ERR_An);
209 dsisr = cxl_p2n_read(afu, CXL_PSL_DSISR_An);
210 cxl_afu_decode_psl_serr(afu, serr);
211 dev_crit(&afu->dev, "AFU_ERR_An: 0x%.16llx\n", afu_error);
212 dev_crit(&afu->dev, "PSL_DSISR_An: 0x%.16llx\n", dsisr);
214 rc = cxl_h_ack_fn_error_interrupt(afu->guest->handle, serr);
216 dev_crit(&afu->dev, "Couldn't ack slice error interrupt: %d\n",
268 struct cxl_afu *afu = NULL;
274 if ((afu = adapter->afu[i])) {
275 pci_error_handlers(afu, CXL_ERROR_DETECTED_EVENT,
277 cxl_context_detach_all(afu);
283 if (!rc && (afu = adapter->afu[i])) {
284 pci_error_handlers(afu, CXL_SLOT_RESET_EVENT,
286 pci_error_handlers(afu, CXL_RESUME_EVENT, 0);
355 static int guest_register_serr_irq(struct cxl_afu *afu)
357 afu->err_irq_name = kasprintf(GFP_KERNEL, "cxl-%s-err",
358 dev_name(&afu->dev));
359 if (!afu->err_irq_name)
362 if (!(afu->serr_virq = cxl_map_irq(afu->adapter, afu->serr_hwirq,
363 guest_slice_irq_err, afu, afu->err_irq_name))) {
364 kfree(afu->err_irq_name);
365 afu->err_irq_name = NULL;
372 static void guest_release_serr_irq(struct cxl_afu *afu)
374 cxl_unmap_irq(afu->serr_virq, afu);
375 cxl_ops->release_one_irq(afu->adapter, afu->serr_hwirq);
376 kfree(afu->err_irq_name);
381 return cxl_h_control_faults(ctx->afu->guest->handle, ctx->process_token,
391 pr_devel("Disabling AFU(%d) interrupts\n", ctx->afu->slice);
407 pr_devel("Enabling AFU(%d) interrupts\n", ctx->afu->slice);
417 static int _guest_afu_cr_readXX(int sz, struct cxl_afu *afu, int cr_idx,
424 if (afu->crs_len < sz)
427 if (unlikely(offset >= afu->crs_len))
434 rc = cxl_h_get_config(afu->guest->handle, cr_idx, offset,
461 static int guest_afu_cr_read32(struct cxl_afu *afu, int cr_idx, u64 offset,
467 rc = _guest_afu_cr_readXX(4, afu, cr_idx, offset, &val);
473 static int guest_afu_cr_read16(struct cxl_afu *afu, int cr_idx, u64 offset,
479 rc = _guest_afu_cr_readXX(2, afu, cr_idx, offset, &val);
485 static int guest_afu_cr_read8(struct cxl_afu *afu, int cr_idx, u64 offset,
491 rc = _guest_afu_cr_readXX(1, afu, cr_idx, offset, &val);
497 static int guest_afu_cr_read64(struct cxl_afu *afu, int cr_idx, u64 offset,
500 return _guest_afu_cr_readXX(8, afu, cr_idx, offset, out);
503 static int guest_afu_cr_write32(struct cxl_afu *afu, int cr, u64 off, u32 in)
509 static int guest_afu_cr_write16(struct cxl_afu *afu, int cr, u64 off, u16 in)
515 static int guest_afu_cr_write8(struct cxl_afu *afu, int cr, u64 off, u8 in)
524 struct cxl *adapter = ctx->afu->adapter;
591 rc = cxl_h_attach_process(ctx->afu->guest->handle, elem,
594 if (ctx->master || !ctx->afu->pp_psa) {
595 ctx->psn_phys = ctx->afu->psn_phys;
596 ctx->psn_size = ctx->afu->adapter->ps_size;
601 if (ctx->afu->pp_psa && mmio_size &&
602 ctx->afu->pp_size == 0) {
611 ctx->afu->pp_size = mmio_size;
631 if (ctx->afu->current_mode == CXL_MODE_DIRECTED)
643 if (cxl_h_detach_process(ctx->afu->guest->handle, ctx->process_token))
653 if (!cxl_ops->link_ok(ctx->afu->adapter, ctx->afu))
656 if (ctx->afu->current_mode == CXL_MODE_DIRECTED)
664 struct cxl_afu *afu = to_cxl_afu(dev);
668 idr_destroy(&afu->contexts_idr);
670 kfree(afu->guest);
671 kfree(afu);
674 ssize_t cxl_guest_read_afu_vpd(struct cxl_afu *afu, void *buf, size_t len)
676 return guest_collect_vpd(NULL, afu, buf, len);
680 static ssize_t guest_afu_read_err_buffer(struct cxl_afu *afu, char *buf,
690 rc = cxl_h_get_afu_err(afu->guest->handle,
706 static int guest_afu_check_and_enable(struct cxl_afu *afu)
735 static int activate_afu_directed(struct cxl_afu *afu)
739 dev_info(&afu->dev, "Activating AFU(%d) directed mode\n", afu->slice);
741 afu->current_mode = CXL_MODE_DIRECTED;
743 afu->num_procs = afu->max_procs_virtualised;
745 if ((rc = cxl_chardev_m_afu_add(afu)))
748 if ((rc = cxl_sysfs_afu_m_add(afu)))
751 if ((rc = cxl_chardev_s_afu_add(afu)))
756 cxl_sysfs_afu_m_remove(afu);
758 cxl_chardev_afu_remove(afu);
762 static int guest_afu_activate_mode(struct cxl_afu *afu, int mode)
766 if (!(mode & afu->modes_supported))
770 return activate_afu_directed(afu);
773 dev_err(&afu->dev, "Dedicated mode not supported\n");
778 static int deactivate_afu_directed(struct cxl_afu *afu)
780 dev_info(&afu->dev, "Deactivating AFU(%d) directed mode\n", afu->slice);
782 afu->current_mode = 0;
783 afu->num_procs = 0;
785 cxl_sysfs_afu_m_remove(afu);
786 cxl_chardev_afu_remove(afu);
788 cxl_ops->afu_reset(afu);
793 static int guest_afu_deactivate_mode(struct cxl_afu *afu, int mode)
797 if (!(mode & afu->modes_supported))
801 return deactivate_afu_directed(afu);
805 static int guest_afu_reset(struct cxl_afu *afu)
807 pr_devel("AFU(%d) reset request\n", afu->slice);
808 return cxl_h_reset_afu(afu->guest->handle);
811 static int guest_map_slice_regs(struct cxl_afu *afu)
813 if (!(afu->p2n_mmio = ioremap(afu->guest->p2n_phys, afu->guest->p2n_size))) {
814 dev_err(&afu->dev, "Error mapping AFU(%d) MMIO regions\n",
815 afu->slice);
821 static void guest_unmap_slice_regs(struct cxl_afu *afu)
823 if (afu->p2n_mmio)
824 iounmap(afu->p2n_mmio);
827 static int afu_update_state(struct cxl_afu *afu)
831 rc = afu_read_error_state(afu, &cur_state);
835 if (afu->guest->previous_state == cur_state)
838 pr_devel("AFU(%d) update state to %#x\n", afu->slice, cur_state);
842 afu->guest->previous_state = cur_state;
846 pci_error_handlers(afu, CXL_ERROR_DETECTED_EVENT,
849 cxl_context_detach_all(afu);
850 if ((rc = cxl_ops->afu_reset(afu)))
853 rc = afu_read_error_state(afu, &cur_state);
855 pci_error_handlers(afu, CXL_SLOT_RESET_EVENT,
857 pci_error_handlers(afu, CXL_RESUME_EVENT, 0);
859 afu->guest->previous_state = 0;
863 afu->guest->previous_state = cur_state;
867 dev_err(&afu->dev, "AFU is in permanent error state\n");
868 pci_error_handlers(afu, CXL_ERROR_DETECTED_EVENT,
870 afu->guest->previous_state = cur_state;
875 afu->slice, cur_state);
896 static bool guest_link_ok(struct cxl *cxl, struct cxl_afu *afu)
900 if (afu && (!afu_read_error_state(afu, &state))) {
908 static int afu_properties_look_ok(struct cxl_afu *afu)
910 if (afu->pp_irqs < 0) {
911 dev_err(&afu->dev, "Unexpected per-process minimum interrupt value\n");
915 if (afu->max_procs_virtualised < 1) {
916 dev_err(&afu->dev, "Unexpected max number of processes virtualised value\n");
925 struct cxl_afu *afu;
930 if (!(afu = cxl_alloc_afu(adapter, slice)))
933 if (!(afu->guest = kzalloc(sizeof(struct cxl_afu_guest), GFP_KERNEL))) {
934 kfree(afu);
938 if ((rc = dev_set_name(&afu->dev, "afu%i.%i",
945 if ((rc = cxl_of_read_afu_handle(afu, afu_np)))
948 if ((rc = cxl_ops->afu_reset(afu)))
951 if ((rc = cxl_of_read_afu_properties(afu, afu_np)))
954 if ((rc = afu_properties_look_ok(afu)))
957 if ((rc = guest_map_slice_regs(afu)))
960 if ((rc = guest_register_serr_irq(afu)))
964 * After we call this function we must not free the afu directly, even
967 if ((rc = cxl_register_afu(afu)))
970 if ((rc = cxl_sysfs_afu_add(afu)))
981 if (afu->max_procs_virtualised == 1)
982 afu->modes_supported = CXL_MODE_DEDICATED;
984 afu->modes_supported = CXL_MODE_DIRECTED;
986 if ((rc = cxl_afu_select_best_mode(afu)))
989 adapter->afu[afu->slice] = afu;
991 afu->enabled = true;
995 * of the AFU using "afu" stored in the guest structure.
997 afu->guest->parent = afu;
998 afu->guest->handle_err = true;
999 INIT_DELAYED_WORK(&afu->guest->work_err, afu_handle_errstate);
1000 schedule_delayed_work(&afu->guest->work_err, msecs_to_jiffies(1000));
1002 if ((rc = cxl_pci_vphb_add(afu)))
1003 dev_info(&afu->dev, "Can't register vPHB\n");
1008 cxl_sysfs_afu_remove(afu);
1010 device_del(&afu->dev);
1012 put_device(&afu->dev);
1014 guest_release_serr_irq(afu);
1016 guest_unmap_slice_regs(afu);
1019 kfree(afu->guest);
1020 kfree(afu);
1025 void cxl_guest_remove_afu(struct cxl_afu *afu)
1027 if (!afu)
1031 afu->guest->handle_err = false;
1032 flush_delayed_work(&afu->guest->work_err);
1034 cxl_pci_vphb_remove(afu);
1035 cxl_sysfs_afu_remove(afu);
1037 spin_lock(&afu->adapter->afu_list_lock);
1038 afu->adapter->afu[afu->slice] = NULL;
1039 spin_unlock(&afu->adapter->afu_list_lock);
1041 cxl_context_detach_all(afu);
1042 cxl_ops->afu_deactivate_mode(afu, afu->current_mode);
1043 guest_release_serr_irq(afu);
1044 guest_unmap_slice_regs(afu);
1046 device_unregister(&afu->dev);