Lines Matching refs:ctx
310 static void slb_invalid(struct cxl_context *ctx) in slb_invalid() argument
312 struct cxl *adapter = ctx->afu->adapter; in slb_invalid()
315 WARN_ON(!mutex_is_locked(&ctx->afu->spa_mutex)); in slb_invalid()
318 ((u64)be32_to_cpu(ctx->elem->common.pid) << 32) | in slb_invalid()
319 be32_to_cpu(ctx->elem->lpid)); in slb_invalid()
332 static int do_process_element_cmd(struct cxl_context *ctx, in do_process_element_cmd() argument
339 trace_cxl_llcmd(ctx, cmd); in do_process_element_cmd()
341 WARN_ON(!ctx->afu->enabled); in do_process_element_cmd()
343 ctx->elem->software_state = cpu_to_be32(pe_state); in do_process_element_cmd()
345 *(ctx->afu->sw_command_status) = cpu_to_be64(cmd | 0 | ctx->pe); in do_process_element_cmd()
347 cxl_p1n_write(ctx->afu, CXL_PSL_LLCMD_An, cmd | ctx->pe); in do_process_element_cmd()
350 dev_warn(&ctx->afu->dev, "WARNING: Process Element Command timed out!\n"); in do_process_element_cmd()
354 if (!cxl_adapter_link_ok(ctx->afu->adapter)) { in do_process_element_cmd()
355 dev_warn(&ctx->afu->dev, "WARNING: Device link down, aborting Process Element Command!\n"); in do_process_element_cmd()
359 state = be64_to_cpup(ctx->afu->sw_command_status); in do_process_element_cmd()
366 (cmd | (cmd >> 16) | ctx->pe)) in do_process_element_cmd()
379 trace_cxl_llcmd_done(ctx, cmd, rc); in do_process_element_cmd()
383 static int add_process_element(struct cxl_context *ctx) in add_process_element() argument
387 mutex_lock(&ctx->afu->spa_mutex); in add_process_element()
388 pr_devel("%s Adding pe: %i started\n", __func__, ctx->pe); in add_process_element()
389 if (!(rc = do_process_element_cmd(ctx, CXL_SPA_SW_CMD_ADD, CXL_PE_SOFTWARE_STATE_V))) in add_process_element()
390 ctx->pe_inserted = true; in add_process_element()
391 pr_devel("%s Adding pe: %i finished\n", __func__, ctx->pe); in add_process_element()
392 mutex_unlock(&ctx->afu->spa_mutex); in add_process_element()
396 static int terminate_process_element(struct cxl_context *ctx) in terminate_process_element() argument
401 if (!(ctx->elem->software_state & cpu_to_be32(CXL_PE_SOFTWARE_STATE_V))) in terminate_process_element()
404 mutex_lock(&ctx->afu->spa_mutex); in terminate_process_element()
405 pr_devel("%s Terminate pe: %i started\n", __func__, ctx->pe); in terminate_process_element()
410 if (cxl_adapter_link_ok(ctx->afu->adapter)) in terminate_process_element()
411 rc = do_process_element_cmd(ctx, CXL_SPA_SW_CMD_TERMINATE, in terminate_process_element()
413 ctx->elem->software_state = 0; /* Remove Valid bit */ in terminate_process_element()
414 pr_devel("%s Terminate pe: %i finished\n", __func__, ctx->pe); in terminate_process_element()
415 mutex_unlock(&ctx->afu->spa_mutex); in terminate_process_element()
419 static int remove_process_element(struct cxl_context *ctx) in remove_process_element() argument
423 mutex_lock(&ctx->afu->spa_mutex); in remove_process_element()
424 pr_devel("%s Remove pe: %i started\n", __func__, ctx->pe); in remove_process_element()
429 if (cxl_adapter_link_ok(ctx->afu->adapter)) in remove_process_element()
430 rc = do_process_element_cmd(ctx, CXL_SPA_SW_CMD_REMOVE, 0); in remove_process_element()
433 ctx->pe_inserted = false; in remove_process_element()
434 slb_invalid(ctx); in remove_process_element()
435 pr_devel("%s Remove pe: %i finished\n", __func__, ctx->pe); in remove_process_element()
436 mutex_unlock(&ctx->afu->spa_mutex); in remove_process_element()
442 void cxl_assign_psn_space(struct cxl_context *ctx) in cxl_assign_psn_space() argument
444 if (!ctx->afu->pp_size || ctx->master) { in cxl_assign_psn_space()
445 ctx->psn_phys = ctx->afu->psn_phys; in cxl_assign_psn_space()
446 ctx->psn_size = ctx->afu->adapter->ps_size; in cxl_assign_psn_space()
448 ctx->psn_phys = ctx->afu->psn_phys + in cxl_assign_psn_space()
449 (ctx->afu->pp_offset + ctx->afu->pp_size * ctx->pe); in cxl_assign_psn_space()
450 ctx->psn_size = ctx->afu->pp_size; in cxl_assign_psn_space()
496 static u64 calculate_sr(struct cxl_context *ctx) in calculate_sr() argument
501 if (ctx->master) in calculate_sr()
505 if (ctx->kernel) { in calculate_sr()
517 static int attach_afu_directed(struct cxl_context *ctx, u64 wed, u64 amr) in attach_afu_directed() argument
522 cxl_assign_psn_space(ctx); in attach_afu_directed()
524 ctx->elem->ctxtime = 0; /* disable */ in attach_afu_directed()
525 ctx->elem->lpid = cpu_to_be32(mfspr(SPRN_LPID)); in attach_afu_directed()
526 ctx->elem->haurp = 0; /* disable */ in attach_afu_directed()
527 ctx->elem->sdr = cpu_to_be64(mfspr(SPRN_SDR1)); in attach_afu_directed()
530 if (ctx->kernel) in attach_afu_directed()
532 ctx->elem->common.tid = 0; in attach_afu_directed()
533 ctx->elem->common.pid = cpu_to_be32(pid); in attach_afu_directed()
535 ctx->elem->sr = cpu_to_be64(calculate_sr(ctx)); in attach_afu_directed()
537 ctx->elem->common.csrp = 0; /* disable */ in attach_afu_directed()
538 ctx->elem->common.aurp0 = 0; /* disable */ in attach_afu_directed()
539 ctx->elem->common.aurp1 = 0; /* disable */ in attach_afu_directed()
541 cxl_prefault(ctx, wed); in attach_afu_directed()
543 ctx->elem->common.sstp0 = cpu_to_be64(ctx->sstp0); in attach_afu_directed()
544 ctx->elem->common.sstp1 = cpu_to_be64(ctx->sstp1); in attach_afu_directed()
547 ctx->elem->ivte_offsets[r] = cpu_to_be16(ctx->irqs.offset[r]); in attach_afu_directed()
548 ctx->elem->ivte_ranges[r] = cpu_to_be16(ctx->irqs.range[r]); in attach_afu_directed()
551 ctx->elem->common.amr = cpu_to_be64(amr); in attach_afu_directed()
552 ctx->elem->common.wed = cpu_to_be64(wed); in attach_afu_directed()
555 if ((result = cxl_afu_check_and_enable(ctx->afu))) in attach_afu_directed()
558 return add_process_element(ctx); in attach_afu_directed()
601 static int attach_dedicated(struct cxl_context *ctx, u64 wed, u64 amr) in attach_dedicated() argument
603 struct cxl_afu *afu = ctx->afu; in attach_dedicated()
608 if (ctx->kernel) in attach_dedicated()
612 cxl_p1n_write(afu, CXL_PSL_SR_An, calculate_sr(ctx)); in attach_dedicated()
614 if ((rc = cxl_write_sstp(afu, ctx->sstp0, ctx->sstp1))) in attach_dedicated()
617 cxl_prefault(ctx, wed); in attach_dedicated()
620 (((u64)ctx->irqs.offset[0] & 0xffff) << 48) | in attach_dedicated()
621 (((u64)ctx->irqs.offset[1] & 0xffff) << 32) | in attach_dedicated()
622 (((u64)ctx->irqs.offset[2] & 0xffff) << 16) | in attach_dedicated()
623 ((u64)ctx->irqs.offset[3] & 0xffff)); in attach_dedicated()
625 (((u64)ctx->irqs.range[0] & 0xffff) << 48) | in attach_dedicated()
626 (((u64)ctx->irqs.range[1] & 0xffff) << 32) | in attach_dedicated()
627 (((u64)ctx->irqs.range[2] & 0xffff) << 16) | in attach_dedicated()
628 ((u64)ctx->irqs.range[3] & 0xffff)); in attach_dedicated()
633 cxl_assign_psn_space(ctx); in attach_dedicated()
689 int cxl_attach_process(struct cxl_context *ctx, bool kernel, u64 wed, u64 amr) in cxl_attach_process() argument
691 if (!cxl_adapter_link_ok(ctx->afu->adapter)) { in cxl_attach_process()
696 ctx->kernel = kernel; in cxl_attach_process()
697 if (ctx->afu->current_mode == CXL_MODE_DIRECTED) in cxl_attach_process()
698 return attach_afu_directed(ctx, wed, amr); in cxl_attach_process()
700 if (ctx->afu->current_mode == CXL_MODE_DEDICATED) in cxl_attach_process()
701 return attach_dedicated(ctx, wed, amr); in cxl_attach_process()
706 static inline int detach_process_native_dedicated(struct cxl_context *ctx) in detach_process_native_dedicated() argument
708 __cxl_afu_reset(ctx->afu); in detach_process_native_dedicated()
709 cxl_afu_disable(ctx->afu); in detach_process_native_dedicated()
710 cxl_psl_purge(ctx->afu); in detach_process_native_dedicated()
714 static inline int detach_process_native_afu_directed(struct cxl_context *ctx) in detach_process_native_afu_directed() argument
716 if (!ctx->pe_inserted) in detach_process_native_afu_directed()
718 if (terminate_process_element(ctx)) in detach_process_native_afu_directed()
720 if (remove_process_element(ctx)) in detach_process_native_afu_directed()
726 int cxl_detach_process(struct cxl_context *ctx) in cxl_detach_process() argument
728 trace_cxl_detach(ctx); in cxl_detach_process()
730 if (ctx->afu->current_mode == CXL_MODE_DEDICATED) in cxl_detach_process()
731 return detach_process_native_dedicated(ctx); in cxl_detach_process()
733 return detach_process_native_afu_directed(ctx); in cxl_detach_process()
772 int cxl_ack_irq(struct cxl_context *ctx, u64 tfc, u64 psl_reset_mask) in cxl_ack_irq() argument
774 trace_cxl_psl_irq_ack(ctx, tfc); in cxl_ack_irq()
776 cxl_p2n_write(ctx->afu, CXL_PSL_TFC_An, tfc); in cxl_ack_irq()
778 recover_psl_err(ctx->afu, psl_reset_mask); in cxl_ack_irq()