Lines Matching +full:num +full:- +full:irqs

1 // SPDX-License-Identifier: GPL-2.0-or-later
28 if (afu->phb == NULL) in pci_error_handlers()
31 list_for_each_entry(afu_dev, &afu->phb->bus->devices, bus_list) { in pci_error_handlers()
32 afu_drv = to_pci_driver(afu_dev->dev.driver); in pci_error_handlers()
36 err_handler = afu_drv->err_handler; in pci_error_handlers()
39 afu_dev->error_state = state; in pci_error_handlers()
42 err_handler->error_detected) in pci_error_handlers()
43 err_handler->error_detected(afu_dev, state); in pci_error_handlers()
46 afu_dev->error_state = state; in pci_error_handlers()
49 err_handler->slot_reset) in pci_error_handlers()
50 err_handler->slot_reset(afu_dev); in pci_error_handlers()
54 err_handler->resume) in pci_error_handlers()
55 err_handler->resume(afu_dev); in pci_error_handlers()
65 dev_crit(&ctx->afu->dev, "PSL ERROR STATUS: 0x%.16llx\n", errstat); in guest_handle_psl_slice_error()
67 return cxl_ops->ack_irq(ctx, 0, errstat); in guest_handle_psl_slice_error()
80 return -EINVAL; in guest_collect_vpd()
96 return -ENOMEM; in guest_collect_vpd()
100 rc = -ENOMEM; in guest_collect_vpd()
107 rc = -ENOMEM; in guest_collect_vpd()
112 if ((i == (entries - 1)) && mod) in guest_collect_vpd()
117 rc = cxl_h_collect_vpd_adapter(adapter->guest->handle, in guest_collect_vpd()
120 rc = cxl_h_collect_vpd(afu->guest->handle, 0, in guest_collect_vpd()
141 len -= tocopy; in guest_collect_vpd()
158 return cxl_h_collect_int_info(ctx->afu->guest->handle, ctx->process_token, info); in guest_get_irq_info()
167 pr_devel("%d: received PSL interrupt %i\n", ctx->pe, irq); in guest_psl_irq()
184 return -EIO; in afu_read_error_state()
186 rc = cxl_h_read_error_state(afu->guest->handle, &state); in afu_read_error_state()
203 rc = cxl_h_get_fn_error_interrupt(afu->guest->handle, &serr); in guest_slice_irq_err()
205 dev_crit(&afu->dev, "Couldn't read PSL_SERR_An: %d\n", rc); in guest_slice_irq_err()
211 dev_crit(&afu->dev, "AFU_ERR_An: 0x%.16llx\n", afu_error); in guest_slice_irq_err()
212 dev_crit(&afu->dev, "PSL_DSISR_An: 0x%.16llx\n", dsisr); in guest_slice_irq_err()
214 rc = cxl_h_ack_fn_error_interrupt(afu->guest->handle, serr); in guest_slice_irq_err()
216 dev_crit(&afu->dev, "Couldn't ack slice error interrupt: %d\n", in guest_slice_irq_err()
228 for (i = 0; i < adapter->guest->irq_nranges; i++) { in irq_alloc_range()
229 cur = &adapter->guest->irq_avail[i]; in irq_alloc_range()
230 n = bitmap_find_next_zero_area(cur->bitmap, cur->range, in irq_alloc_range()
232 if (n < cur->range) { in irq_alloc_range()
233 bitmap_set(cur->bitmap, n, len); in irq_alloc_range()
234 *irq = cur->offset + n; in irq_alloc_range()
235 pr_devel("guest: allocate IRQs %#x->%#x\n", in irq_alloc_range()
236 *irq, *irq + len - 1); in irq_alloc_range()
241 return -ENOSPC; in irq_alloc_range()
250 return -ENOENT; in irq_free_range()
252 for (i = 0; i < adapter->guest->irq_nranges; i++) { in irq_free_range()
253 cur = &adapter->guest->irq_avail[i]; in irq_free_range()
254 if (irq >= cur->offset && in irq_free_range()
255 (irq + len) <= (cur->offset + cur->range)) { in irq_free_range()
256 n = irq - cur->offset; in irq_free_range()
257 bitmap_clear(cur->bitmap, n, len); in irq_free_range()
258 pr_devel("guest: release IRQs %#x->%#x\n", in irq_free_range()
259 irq, irq + len - 1); in irq_free_range()
263 return -ENOENT; in irq_free_range()
272 spin_lock(&adapter->afu_list_lock); in guest_reset()
273 for (i = 0; i < adapter->slices; i++) { in guest_reset()
274 if ((afu = adapter->afu[i])) { in guest_reset()
281 rc = cxl_h_reset_adapter(adapter->guest->handle); in guest_reset()
282 for (i = 0; i < adapter->slices; i++) { in guest_reset()
283 if (!rc && (afu = adapter->afu[i])) { in guest_reset()
289 spin_unlock(&adapter->afu_list_lock); in guest_reset()
297 spin_lock(&adapter->guest->irq_alloc_lock); in guest_alloc_one_irq()
299 irq = -ENOSPC; in guest_alloc_one_irq()
300 spin_unlock(&adapter->guest->irq_alloc_lock); in guest_alloc_one_irq()
306 spin_lock(&adapter->guest->irq_alloc_lock); in guest_release_one_irq()
308 spin_unlock(&adapter->guest->irq_alloc_lock); in guest_release_one_irq()
311 static int guest_alloc_irq_ranges(struct cxl_irq_ranges *irqs, in guest_alloc_irq_ranges() argument
312 struct cxl *adapter, unsigned int num) in guest_alloc_irq_ranges() argument
316 memset(irqs, 0, sizeof(struct cxl_irq_ranges)); in guest_alloc_irq_ranges()
318 spin_lock(&adapter->guest->irq_alloc_lock); in guest_alloc_irq_ranges()
319 for (i = 0; i < CXL_IRQ_RANGES && num; i++) { in guest_alloc_irq_ranges()
320 try = num; in guest_alloc_irq_ranges()
328 irqs->offset[i] = irq; in guest_alloc_irq_ranges()
329 irqs->range[i] = try; in guest_alloc_irq_ranges()
330 num -= try; in guest_alloc_irq_ranges()
332 if (num) in guest_alloc_irq_ranges()
334 spin_unlock(&adapter->guest->irq_alloc_lock); in guest_alloc_irq_ranges()
339 irq_free_range(adapter, irqs->offset[i], irqs->range[i]); in guest_alloc_irq_ranges()
340 spin_unlock(&adapter->guest->irq_alloc_lock); in guest_alloc_irq_ranges()
341 return -ENOSPC; in guest_alloc_irq_ranges()
344 static void guest_release_irq_ranges(struct cxl_irq_ranges *irqs, in guest_release_irq_ranges() argument
349 spin_lock(&adapter->guest->irq_alloc_lock); in guest_release_irq_ranges()
351 irq_free_range(adapter, irqs->offset[i], irqs->range[i]); in guest_release_irq_ranges()
352 spin_unlock(&adapter->guest->irq_alloc_lock); in guest_release_irq_ranges()
357 afu->err_irq_name = kasprintf(GFP_KERNEL, "cxl-%s-err", in guest_register_serr_irq()
358 dev_name(&afu->dev)); in guest_register_serr_irq()
359 if (!afu->err_irq_name) in guest_register_serr_irq()
360 return -ENOMEM; in guest_register_serr_irq()
362 if (!(afu->serr_virq = cxl_map_irq(afu->adapter, afu->serr_hwirq, in guest_register_serr_irq()
363 guest_slice_irq_err, afu, afu->err_irq_name))) { in guest_register_serr_irq()
364 kfree(afu->err_irq_name); in guest_register_serr_irq()
365 afu->err_irq_name = NULL; in guest_register_serr_irq()
366 return -ENOMEM; in guest_register_serr_irq()
374 cxl_unmap_irq(afu->serr_virq, afu); in guest_release_serr_irq()
375 cxl_ops->release_one_irq(afu->adapter, afu->serr_hwirq); in guest_release_serr_irq()
376 kfree(afu->err_irq_name); in guest_release_serr_irq()
381 return cxl_h_control_faults(ctx->afu->guest->handle, ctx->process_token, in guest_ack_irq()
391 pr_devel("Disabling AFU(%d) interrupts\n", ctx->afu->slice); in disable_afu_irqs()
393 hwirq = ctx->irqs.offset[r]; in disable_afu_irqs()
394 for (i = 0; i < ctx->irqs.range[r]; hwirq++, i++) { in disable_afu_irqs()
407 pr_devel("Enabling AFU(%d) interrupts\n", ctx->afu->slice); in enable_afu_irqs()
409 hwirq = ctx->irqs.offset[r]; in enable_afu_irqs()
410 for (i = 0; i < ctx->irqs.range[r]; hwirq++, i++) { in enable_afu_irqs()
424 if (afu->crs_len < sz) in _guest_afu_cr_readXX()
425 return -ENOENT; in _guest_afu_cr_readXX()
427 if (unlikely(offset >= afu->crs_len)) in _guest_afu_cr_readXX()
428 return -ERANGE; in _guest_afu_cr_readXX()
432 return -ENOMEM; in _guest_afu_cr_readXX()
434 rc = cxl_h_get_config(afu->guest->handle, cr_idx, offset, in _guest_afu_cr_readXX()
506 return -EPERM; in guest_afu_cr_write32()
512 return -EPERM; in guest_afu_cr_write16()
518 return -EPERM; in guest_afu_cr_write8()
524 struct cxl *adapter = ctx->afu->adapter; in attach_afu_directed()
534 return -ENOMEM; in attach_afu_directed()
536 elem->version = cpu_to_be64(CXL_PROCESS_ELEMENT_VERSION); in attach_afu_directed()
537 if (ctx->kernel) { in attach_afu_directed()
544 pid = current->pid; in attach_afu_directed()
550 if (uid_eq(cred->euid, GLOBAL_ROOT_UID)) in attach_afu_directed()
554 elem->flags = cpu_to_be64(flags); in attach_afu_directed()
555 elem->common.tid = cpu_to_be32(0); /* Unused */ in attach_afu_directed()
556 elem->common.pid = cpu_to_be32(pid); in attach_afu_directed()
557 elem->common.csrp = cpu_to_be64(0); /* disable */ in attach_afu_directed()
558 elem->common.u.psl8.aurp0 = cpu_to_be64(0); /* disable */ in attach_afu_directed()
559 elem->common.u.psl8.aurp1 = cpu_to_be64(0); /* disable */ in attach_afu_directed()
563 elem->common.u.psl8.sstp0 = cpu_to_be64(ctx->sstp0); in attach_afu_directed()
564 elem->common.u.psl8.sstp1 = cpu_to_be64(ctx->sstp1); in attach_afu_directed()
568 * kernel contexts that may not have allocated any AFU IRQs at all: in attach_afu_directed()
570 if (ctx->irqs.range[0] == 0) { in attach_afu_directed()
577 for (i = 0; i < ctx->irqs.range[r]; i++) { in attach_afu_directed()
579 elem->pslVirtualIsn = cpu_to_be32(ctx->irqs.offset[0]); in attach_afu_directed()
581 idx = ctx->irqs.offset[r] + i - adapter->guest->irq_base_offset; in attach_afu_directed()
582 elem->applicationVirtualIsnBitmap[idx / 8] |= 0x80 >> (idx % 8); in attach_afu_directed()
586 elem->common.amr = cpu_to_be64(amr); in attach_afu_directed()
587 elem->common.wed = cpu_to_be64(wed); in attach_afu_directed()
591 rc = cxl_h_attach_process(ctx->afu->guest->handle, elem, in attach_afu_directed()
592 &ctx->process_token, &mmio_addr, &mmio_size); in attach_afu_directed()
594 if (ctx->master || !ctx->afu->pp_psa) { in attach_afu_directed()
595 ctx->psn_phys = ctx->afu->psn_phys; in attach_afu_directed()
596 ctx->psn_size = ctx->afu->adapter->ps_size; in attach_afu_directed()
598 ctx->psn_phys = mmio_addr; in attach_afu_directed()
599 ctx->psn_size = mmio_size; in attach_afu_directed()
601 if (ctx->afu->pp_psa && mmio_size && in attach_afu_directed()
602 ctx->afu->pp_size == 0) { in attach_afu_directed()
606 * Compared to bare-metal, it is too late and we in attach_afu_directed()
611 ctx->afu->pp_size = mmio_size; in attach_afu_directed()
613 /* from PAPR: process element is bytes 4-7 of process token */ in attach_afu_directed()
614 ctx->external_pe = ctx->process_token & 0xFFFFFFFF; in attach_afu_directed()
616 ctx->pe, ctx->external_pe, ctx->psn_size); in attach_afu_directed()
617 ctx->pe_inserted = true; in attach_afu_directed()
630 ctx->kernel = kernel; in guest_attach_process()
631 if (ctx->afu->current_mode == CXL_MODE_DIRECTED) in guest_attach_process()
636 return -EINVAL; in guest_attach_process()
641 if (!ctx->pe_inserted) in detach_afu_directed()
643 if (cxl_h_detach_process(ctx->afu->guest->handle, ctx->process_token)) in detach_afu_directed()
644 return -1; in detach_afu_directed()
653 if (!cxl_ops->link_ok(ctx->afu->adapter, ctx->afu)) in guest_detach_process()
654 return -EIO; in guest_detach_process()
656 if (ctx->afu->current_mode == CXL_MODE_DIRECTED) in guest_detach_process()
659 return -EINVAL; in guest_detach_process()
668 idr_destroy(&afu->contexts_idr); in guest_release_afu()
670 kfree(afu->guest); in guest_release_afu()
688 return -ENOMEM; in guest_afu_read_err_buffer()
690 rc = cxl_h_get_afu_err(afu->guest->handle, in guest_afu_read_err_buffer()
698 count = ERR_BUFF_MAX_COPY_SIZE - (off & 0x7); in guest_afu_read_err_buffer()
739 dev_info(&afu->dev, "Activating AFU(%d) directed mode\n", afu->slice); in activate_afu_directed()
741 afu->current_mode = CXL_MODE_DIRECTED; in activate_afu_directed()
743 afu->num_procs = afu->max_procs_virtualised; in activate_afu_directed()
766 if (!(mode & afu->modes_supported)) in guest_afu_activate_mode()
767 return -EINVAL; in guest_afu_activate_mode()
773 dev_err(&afu->dev, "Dedicated mode not supported\n"); in guest_afu_activate_mode()
775 return -EINVAL; in guest_afu_activate_mode()
780 dev_info(&afu->dev, "Deactivating AFU(%d) directed mode\n", afu->slice); in deactivate_afu_directed()
782 afu->current_mode = 0; in deactivate_afu_directed()
783 afu->num_procs = 0; in deactivate_afu_directed()
788 cxl_ops->afu_reset(afu); in deactivate_afu_directed()
797 if (!(mode & afu->modes_supported)) in guest_afu_deactivate_mode()
798 return -EINVAL; in guest_afu_deactivate_mode()
807 pr_devel("AFU(%d) reset request\n", afu->slice); in guest_afu_reset()
808 return cxl_h_reset_afu(afu->guest->handle); in guest_afu_reset()
813 if (!(afu->p2n_mmio = ioremap(afu->guest->p2n_phys, afu->guest->p2n_size))) { in guest_map_slice_regs()
814 dev_err(&afu->dev, "Error mapping AFU(%d) MMIO regions\n", in guest_map_slice_regs()
815 afu->slice); in guest_map_slice_regs()
816 return -ENOMEM; in guest_map_slice_regs()
823 if (afu->p2n_mmio) in guest_unmap_slice_regs()
824 iounmap(afu->p2n_mmio); in guest_unmap_slice_regs()
835 if (afu->guest->previous_state == cur_state) in afu_update_state()
838 pr_devel("AFU(%d) update state to %#x\n", afu->slice, cur_state); in afu_update_state()
842 afu->guest->previous_state = cur_state; in afu_update_state()
850 if ((rc = cxl_ops->afu_reset(afu))) in afu_update_state()
859 afu->guest->previous_state = 0; in afu_update_state()
863 afu->guest->previous_state = cur_state; in afu_update_state()
867 dev_err(&afu->dev, "AFU is in permanent error state\n"); in afu_update_state()
870 afu->guest->previous_state = cur_state; in afu_update_state()
875 afu->slice, cur_state); in afu_update_state()
876 return -EINVAL; in afu_update_state()
887 if (!afu_update_state(afu_guest->parent) && in afu_handle_errstate()
888 afu_guest->previous_state == H_STATE_PERM_UNAVAILABLE) in afu_handle_errstate()
891 if (afu_guest->handle_err) in afu_handle_errstate()
892 schedule_delayed_work(&afu_guest->work_err, in afu_handle_errstate()
910 if (afu->pp_irqs < 0) { in afu_properties_look_ok()
911 dev_err(&afu->dev, "Unexpected per-process minimum interrupt value\n"); in afu_properties_look_ok()
912 return -EINVAL; in afu_properties_look_ok()
915 if (afu->max_procs_virtualised < 1) { in afu_properties_look_ok()
916 dev_err(&afu->dev, "Unexpected max number of processes virtualised value\n"); in afu_properties_look_ok()
917 return -EINVAL; in afu_properties_look_ok()
929 pr_devel("in %s - AFU(%d)\n", __func__, slice); in cxl_guest_init_afu()
931 return -ENOMEM; in cxl_guest_init_afu()
933 if (!(afu->guest = kzalloc(sizeof(struct cxl_afu_guest), GFP_KERNEL))) { in cxl_guest_init_afu()
935 return -ENOMEM; in cxl_guest_init_afu()
938 if ((rc = dev_set_name(&afu->dev, "afu%i.%i", in cxl_guest_init_afu()
939 adapter->adapter_num, in cxl_guest_init_afu()
943 adapter->slices++; in cxl_guest_init_afu()
948 if ((rc = cxl_ops->afu_reset(afu))) in cxl_guest_init_afu()
981 if (afu->max_procs_virtualised == 1) in cxl_guest_init_afu()
982 afu->modes_supported = CXL_MODE_DEDICATED; in cxl_guest_init_afu()
984 afu->modes_supported = CXL_MODE_DIRECTED; in cxl_guest_init_afu()
989 adapter->afu[afu->slice] = afu; in cxl_guest_init_afu()
991 afu->enabled = true; in cxl_guest_init_afu()
997 afu->guest->parent = afu; in cxl_guest_init_afu()
998 afu->guest->handle_err = true; in cxl_guest_init_afu()
999 INIT_DELAYED_WORK(&afu->guest->work_err, afu_handle_errstate); in cxl_guest_init_afu()
1000 schedule_delayed_work(&afu->guest->work_err, msecs_to_jiffies(1000)); in cxl_guest_init_afu()
1003 dev_info(&afu->dev, "Can't register vPHB\n"); in cxl_guest_init_afu()
1010 device_del(&afu->dev); in cxl_guest_init_afu()
1012 put_device(&afu->dev); in cxl_guest_init_afu()
1019 kfree(afu->guest); in cxl_guest_init_afu()
1031 afu->guest->handle_err = false; in cxl_guest_remove_afu()
1032 flush_delayed_work(&afu->guest->work_err); in cxl_guest_remove_afu()
1037 spin_lock(&afu->adapter->afu_list_lock); in cxl_guest_remove_afu()
1038 afu->adapter->afu[afu->slice] = NULL; in cxl_guest_remove_afu()
1039 spin_unlock(&afu->adapter->afu_list_lock); in cxl_guest_remove_afu()
1042 cxl_ops->afu_deactivate_mode(afu, afu->current_mode); in cxl_guest_remove_afu()
1046 device_unregister(&afu->dev); in cxl_guest_remove_afu()
1054 if (adapter->guest) { in free_adapter()
1055 if (adapter->guest->irq_avail) { in free_adapter()
1056 for (i = 0; i < adapter->guest->irq_nranges; i++) { in free_adapter()
1057 cur = &adapter->guest->irq_avail[i]; in free_adapter()
1058 bitmap_free(cur->bitmap); in free_adapter()
1060 kfree(adapter->guest->irq_avail); in free_adapter()
1062 kfree(adapter->guest->status); in free_adapter()
1063 kfree(adapter->guest); in free_adapter()
1074 if (strlen(adapter->guest->status) && in properties_look_ok()
1075 strcmp(adapter->guest->status, "okay")) { in properties_look_ok()
1077 return -EINVAL; in properties_look_ok()
1095 device_unregister(&adapter->dev); in cxl_guest_remove_adapter()
1110 return ERR_PTR(-ENOMEM); in cxl_guest_init_adapter()
1112 if (!(adapter->guest = kzalloc(sizeof(struct cxl_guest), GFP_KERNEL))) { in cxl_guest_init_adapter()
1114 return ERR_PTR(-ENOMEM); in cxl_guest_init_adapter()
1117 adapter->slices = 0; in cxl_guest_init_adapter()
1118 adapter->guest->pdev = pdev; in cxl_guest_init_adapter()
1119 adapter->dev.parent = &pdev->dev; in cxl_guest_init_adapter()
1120 adapter->dev.release = release_adapter; in cxl_guest_init_adapter()
1121 dev_set_drvdata(&pdev->dev, adapter); in cxl_guest_init_adapter()
1127 adapter->psl_timebase_synced = true; in cxl_guest_init_adapter()
1157 device_del(&adapter->dev); in cxl_guest_init_adapter()
1159 put_device(&adapter->dev); in cxl_guest_init_adapter()
1172 pdev = adapter->guest->pdev; in cxl_guest_reload_module()