Lines Matching +full:out +full:- +full:of +full:- +full:window

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2020-21 IBM Corp.
26 /* The hypervisor allows one credit per window right now */
71 * Allocate VAS window hcall
88 if (win->win_addr == VAS_INVALID_WIN_ADDRESS) { in h_allocate_vas_window()
90 return -ENOTSUPP; in h_allocate_vas_window()
92 win->vas_win.winid = retbuf[0]; in h_allocate_vas_window()
93 win->win_addr = retbuf[1]; in h_allocate_vas_window()
94 win->complete_irq = retbuf[2]; in h_allocate_vas_window()
95 win->fault_irq = retbuf[3]; in h_allocate_vas_window()
102 return -EIO; in h_allocate_vas_window()
106 * Deallocate VAS window hcall.
123 return -EIO; in h_deallocate_vas_window()
127 * Modify VAS window.
128 * After the window is opened with allocate window hcall, configure it
141 win->vas_win.winid, win->pid, 0, in h_modify_vas_window()
151 rc, win->vas_win.winid, win->pid); in h_modify_vas_window()
152 return -EIO; in h_modify_vas_window()
186 return -EIO; in h_query_vas_capabilities()
204 return -EIO; in h_get_nx_fault()
210 * When the fault interrupt is received for each window, query the
224 while (atomic_read(&txwin->pending_faults)) { in pseries_vas_fault_thread_fn()
225 rc = h_get_nx_fault(txwin->vas_win.winid, (u64)virt_to_phys(&crb)); in pseries_vas_fault_thread_fn()
227 tsk_ref = &txwin->vas_win.task_ref; in pseries_vas_fault_thread_fn()
231 atomic_dec(&txwin->pending_faults); in pseries_vas_fault_thread_fn()
242 * during this window, the hypervisor will not deliver this
244 * of calling the default primary handler.
254 atomic_inc(&txwin->pending_faults); in pseries_vas_irq_handler()
260 * Allocate window and setup IRQ mapping.
272 * interrupt per window. So the IRQ setup and fault handling in allocate_setup_window()
273 * will be done for each open window separately. in allocate_setup_window()
275 txwin->fault_virq = irq_create_mapping(NULL, txwin->fault_irq); in allocate_setup_window()
276 if (!txwin->fault_virq) { in allocate_setup_window()
277 pr_err("Failed irq mapping %d\n", txwin->fault_irq); in allocate_setup_window()
278 rc = -EINVAL; in allocate_setup_window()
282 txwin->name = kasprintf(GFP_KERNEL, "vas-win-%d", in allocate_setup_window()
283 txwin->vas_win.winid); in allocate_setup_window()
284 if (!txwin->name) { in allocate_setup_window()
285 rc = -ENOMEM; in allocate_setup_window()
289 rc = request_threaded_irq(txwin->fault_virq, in allocate_setup_window()
292 txwin->name, txwin); in allocate_setup_window()
294 pr_err("VAS-Window[%d]: Request IRQ(%u) failed with %d\n", in allocate_setup_window()
295 txwin->vas_win.winid, txwin->fault_virq, rc); in allocate_setup_window()
299 txwin->vas_win.wcreds_max = DEF_WIN_CREDS; in allocate_setup_window()
303 kfree(txwin->name); in allocate_setup_window()
305 irq_dispose_mapping(txwin->fault_virq); in allocate_setup_window()
307 h_deallocate_vas_window(txwin->vas_win.winid); in allocate_setup_window()
313 free_irq(txwin->fault_virq, txwin); in free_irq_setup()
314 kfree(txwin->name); in free_irq_setup()
315 irq_dispose_mapping(txwin->fault_virq); in free_irq_setup()
329 return ERR_PTR(-ENOMEM); in vas_allocate_window()
332 * A VAS window can have many credits which means that many in vas_allocate_window()
334 * restricts one credit per window. in vas_allocate_window()
335 * The hypervisor introduces 2 different types of credits: in vas_allocate_window()
337 * A limited number of credits are assigned to partitions in vas_allocate_window()
339 * over-committed on a system depends on whether the CPUs in vas_allocate_window()
340 * are in shared or dedicated modes - that is, more requests in vas_allocate_window()
343 * Then the process has to resend requests or fall-back to in vas_allocate_window()
345 * Quality of Service (QoS) credit type (Uses high priority FIFO): in vas_allocate_window()
352 * Allocate window with QoS credits if user requested. Otherwise in vas_allocate_window()
360 cop_feat_caps = &caps->caps; in vas_allocate_window()
362 if (atomic_inc_return(&cop_feat_caps->nr_used_credits) > in vas_allocate_window()
363 atomic_read(&cop_feat_caps->nr_total_credits)) { in vas_allocate_window()
364 pr_err_ratelimited("Credits are not available to allocate window\n"); in vas_allocate_window()
365 rc = -EINVAL; in vas_allocate_window()
366 goto out; in vas_allocate_window()
369 if (vas_id == -1) { in vas_allocate_window()
371 * The user space is requesting to allocate a window on in vas_allocate_window()
377 * VAS_DEFAULT_DOMAIN_ID (-1) is passed for domain values. in vas_allocate_window()
386 goto out; in vas_allocate_window()
390 txwin->pid = mfspr(SPRN_PID); in vas_allocate_window()
393 * Allocate / Deallocate window hcalls and setup / free IRQs in vas_allocate_window()
395 * Open VAS window: Allocate window hcall and setup IRQ in vas_allocate_window()
396 * Close VAS window: Deallocate window hcall and free IRQ in vas_allocate_window()
398 * completed before closing the window. So expects OS in vas_allocate_window()
400 * after the deallocate window hcall is returned. in vas_allocate_window()
401 * So once the window is closed with deallocate hcall before in vas_allocate_window()
404 * result in setup IRQ fail for the new window since the in vas_allocate_window()
409 rc = -EBUSY; in vas_allocate_window()
412 cop_feat_caps->win_type); in vas_allocate_window()
414 caps->nr_open_wins_progress++; in vas_allocate_window()
419 goto out; in vas_allocate_window()
422 * Modify window and it is ready to use. in vas_allocate_window()
426 rc = get_vas_user_win_ref(&txwin->vas_win.task_ref); in vas_allocate_window()
430 txwin->win_type = cop_feat_caps->win_type; in vas_allocate_window()
434 * closes all open windows from the list. But the window is in vas_allocate_window()
443 * removal after the window is opened. So if there are any in vas_allocate_window()
445 * window to user space. New windows will be opened only in vas_allocate_window()
450 if (!caps->nr_close_wins && !migration_in_progress) { in vas_allocate_window()
451 list_add(&txwin->win_list, &caps->list); in vas_allocate_window()
452 caps->nr_open_windows++; in vas_allocate_window()
453 caps->nr_open_wins_progress--; in vas_allocate_window()
455 vas_user_win_add_mm_context(&txwin->vas_win.task_ref); in vas_allocate_window()
456 return &txwin->vas_win; in vas_allocate_window()
460 put_vas_user_win_ref(&txwin->vas_win.task_ref); in vas_allocate_window()
461 rc = -EBUSY; in vas_allocate_window()
462 pr_err_ratelimited("No credit is available to allocate window\n"); in vas_allocate_window()
466 * Window is not operational. Free IRQ before closing in vas_allocate_window()
467 * window so that do not have to hold mutex. in vas_allocate_window()
470 h_deallocate_vas_window(txwin->vas_win.winid); in vas_allocate_window()
475 caps->nr_open_wins_progress--; in vas_allocate_window()
477 out: in vas_allocate_window()
478 atomic_dec(&cop_feat_caps->nr_used_credits); in vas_allocate_window()
488 return win->win_addr; in vas_paste_address()
497 * are processed before closing the window - Means all in deallocate_free_window()
498 * credits have to be returned. In the case of fault in deallocate_free_window()
504 rc = h_deallocate_vas_window(win->vas_win.winid); in deallocate_free_window()
518 return -EINVAL; in vas_deallocate_window()
523 if (win->win_type >= VAS_MAX_FEAT_TYPE) { in vas_deallocate_window()
524 pr_err("Window (%u): Invalid window type %u\n", in vas_deallocate_window()
525 vwin->winid, win->win_type); in vas_deallocate_window()
526 return -EINVAL; in vas_deallocate_window()
529 caps = &vascaps[win->win_type].caps; in vas_deallocate_window()
532 * VAS window is already closed in the hypervisor when in vas_deallocate_window()
537 if (!(win->vas_win.status & VAS_WIN_NO_CRED_CLOSE) && in vas_deallocate_window()
538 !(win->vas_win.status & VAS_WIN_MIGRATE_CLOSE)) { in vas_deallocate_window()
545 vascaps[win->win_type].nr_close_wins--; in vas_deallocate_window()
547 list_del(&win->win_list); in vas_deallocate_window()
548 atomic_dec(&caps->nr_used_credits); in vas_deallocate_window()
549 vascaps[win->win_type].nr_open_windows--; in vas_deallocate_window()
552 mm_context_remove_vas_window(vwin->task_ref.mm); in vas_deallocate_window()
553 put_vas_user_win_ref(&vwin->task_ref); in vas_deallocate_window()
560 .open_win = vas_allocate_window, /* Open and configure window */
562 .close_win = vas_deallocate_window, /* Close window */
566 * Supporting only nx-gzip coprocessor type now, but this API code
573 return -ENOTSUPP; in vas_register_api_pseries()
598 INIT_LIST_HEAD(&vcaps->list); in get_vas_capabilities()
600 vcaps->feat = feat; in get_vas_capabilities()
601 caps = &vcaps->caps; in get_vas_capabilities()
608 caps->user_mode = hv_caps->user_mode; in get_vas_capabilities()
609 if (!(caps->user_mode & VAS_COPY_PASTE_USER_MODE)) { in get_vas_capabilities()
611 return -ENOTSUPP; in get_vas_capabilities()
614 caps->descriptor = be64_to_cpu(hv_caps->descriptor); in get_vas_capabilities()
615 caps->win_type = hv_caps->win_type; in get_vas_capabilities()
616 if (caps->win_type >= VAS_MAX_FEAT_TYPE) { in get_vas_capabilities()
617 pr_err("Unsupported window type %u\n", caps->win_type); in get_vas_capabilities()
618 return -EINVAL; in get_vas_capabilities()
620 caps->max_lpar_creds = be16_to_cpu(hv_caps->max_lpar_creds); in get_vas_capabilities()
621 caps->max_win_creds = be16_to_cpu(hv_caps->max_win_creds); in get_vas_capabilities()
622 atomic_set(&caps->nr_total_credits, in get_vas_capabilities()
623 be16_to_cpu(hv_caps->target_lpar_creds)); in get_vas_capabilities()
625 caps->def_lpar_creds = be16_to_cpu(hv_caps->def_lpar_creds); in get_vas_capabilities()
627 if (caps->max_win_creds < DEF_WIN_CREDS) { in get_vas_capabilities()
628 pr_err("Window creds(%u) > max allowed window creds(%u)\n", in get_vas_capabilities()
629 DEF_WIN_CREDS, caps->max_win_creds); in get_vas_capabilities()
630 return -EINVAL; in get_vas_capabilities()
646 * core add and set the window active status. When NX sees the page
648 * by setting the remapping to new paste address if the window is
655 struct vas_cop_feat_caps *caps = &vcaps->caps; in reconfig_open_windows()
663 if (!vcaps->nr_close_wins) in reconfig_open_windows()
680 if ((vcaps->nr_close_wins > creds) && !migrate) in reconfig_open_windows()
681 mv_ents = vcaps->nr_close_wins - creds; in reconfig_open_windows()
683 list_for_each_entry_safe(win, tmp, &vcaps->list, win_list) { in reconfig_open_windows()
687 mv_ents--; in reconfig_open_windows()
699 list_for_each_entry_safe_from(win, tmp, &vcaps->list, win_list) { in reconfig_open_windows()
701 * This window is closed with DLPAR and migration events. in reconfig_open_windows()
702 * So reopen the window with the last event. in reconfig_open_windows()
706 * this window will be opened with the last event. in reconfig_open_windows()
708 if ((win->vas_win.status & VAS_WIN_NO_CRED_CLOSE) && in reconfig_open_windows()
709 (win->vas_win.status & VAS_WIN_MIGRATE_CLOSE)) { in reconfig_open_windows()
710 win->vas_win.status &= ~flag; in reconfig_open_windows()
715 * Nothing to do on this window if it is not closed in reconfig_open_windows()
718 if (!(win->vas_win.status & flag)) in reconfig_open_windows()
722 caps->win_type); in reconfig_open_windows()
728 goto out; in reconfig_open_windows()
730 mutex_lock(&win->vas_win.task_ref.mmap_mutex); in reconfig_open_windows()
732 * Set window status to active in reconfig_open_windows()
734 win->vas_win.status &= ~flag; in reconfig_open_windows()
735 mutex_unlock(&win->vas_win.task_ref.mmap_mutex); in reconfig_open_windows()
736 win->win_type = caps->win_type; in reconfig_open_windows()
737 if (!--vcaps->nr_close_wins) in reconfig_open_windows()
742 out: in reconfig_open_windows()
744 * Window modify HCALL failed. So close the window to the in reconfig_open_windows()
748 h_deallocate_vas_window(win->vas_win.winid); in reconfig_open_windows()
774 list_for_each_entry_safe(win, tmp, &vcap->list, win_list) { in reconfig_close_windows()
776 * This window is already closed due to lost credit in reconfig_close_windows()
777 * or for migration before. Go for next window. in reconfig_close_windows()
778 * For migration, nothing to do since this window in reconfig_close_windows()
782 if ((win->vas_win.status & VAS_WIN_MIGRATE_CLOSE) || in reconfig_close_windows()
783 (win->vas_win.status & VAS_WIN_NO_CRED_CLOSE)) { in reconfig_close_windows()
784 win->vas_win.status |= flag; in reconfig_close_windows()
788 task_ref = &win->vas_win.task_ref; in reconfig_close_windows()
794 mmap_write_lock(task_ref->mm); in reconfig_close_windows()
795 mutex_lock(&task_ref->mmap_mutex); in reconfig_close_windows()
796 vma = task_ref->vma; in reconfig_close_windows()
798 * Number of available credits are reduced, So select in reconfig_close_windows()
801 win->vas_win.status |= flag; in reconfig_close_windows()
805 * is done with mmap() after the window is opened with ioctl. in reconfig_close_windows()
812 mutex_unlock(&task_ref->mmap_mutex); in reconfig_close_windows()
813 mmap_write_unlock(task_ref->mm); in reconfig_close_windows()
815 * Close VAS window in the hypervisor, but do not in reconfig_close_windows()
830 vcap->nr_close_wins++; in reconfig_close_windows()
839 if (!migrate && !--excess_creds) in reconfig_close_windows()
848 * changes. Reconfig window configurations based on the credits
860 return -EINVAL; in vas_reconfig_capabilties()
864 caps = &vcaps->caps; in vas_reconfig_capabilties()
868 old_nr_creds = atomic_read(&caps->nr_total_credits); in vas_reconfig_capabilties()
870 atomic_set(&caps->nr_total_credits, new_nr_creds); in vas_reconfig_capabilties()
872 * The total number of available credits may be decreased or in vas_reconfig_capabilties()
883 rc = reconfig_open_windows(vcaps, new_nr_creds - old_nr_creds, in vas_reconfig_capabilties()
889 * On pseries, each window will have 1 credit. in vas_reconfig_capabilties()
891 nr_active_wins = vcaps->nr_open_windows - vcaps->nr_close_wins; in vas_reconfig_capabilties()
894 nr_active_wins - new_nr_creds, in vas_reconfig_capabilties()
907 * NX-GZIP is not enabled. Nothing to do for DLPAR event in pseries_vas_dlpar_cpu()
928 * Total number of default credits available (target_credits)
929 * in LPAR depends on number of cores configured. It varies based on
939 struct device_node *dn = rd->dn; in pseries_vas_notifier()
953 intserv = of_get_property(dn, "ibm,ppc-interrupt-server#s", in pseries_vas_notifier()
984 * NX-GZIP is not enabled. Nothing to do for migration. in vas_migration_handler()
996 caps = &vcaps->caps; in vas_migration_handler()
997 old_nr_creds = atomic_read(&caps->nr_total_credits); in vas_migration_handler()
1000 vcaps->feat, in vas_migration_handler()
1015 atomic_read(&caps->nr_used_credits), in vas_migration_handler()
1016 vcaps->nr_open_windows - vcaps->nr_close_wins); in vas_migration_handler()
1029 goto out; in vas_migration_handler()
1035 rc = reconfig_close_windows(vcaps, vcaps->nr_open_windows, in vas_migration_handler()
1039 * open. So wait for closing these in-progress open in vas_migration_handler()
1043 while (vcaps->nr_open_wins_progress) { in vas_migration_handler()
1052 atomic_set(&caps->nr_total_credits, new_nr_creds); in vas_migration_handler()
1059 rc = -EINVAL; in vas_migration_handler()
1060 goto out; in vas_migration_handler()
1067 goto out; in vas_migration_handler()
1072 out: in vas_migration_handler()
1087 return -ENOTSUPP; in pseries_vas_init()
1092 return -ENOMEM; in pseries_vas_init()
1099 goto out; in pseries_vas_init()
1101 caps_all.descriptor = be64_to_cpu(hv_caps->descriptor); in pseries_vas_init()
1102 caps_all.feat_type = be64_to_cpu(hv_caps->feat_type); in pseries_vas_init()
1114 goto out; in pseries_vas_init()
1137 out: in pseries_vas_init()