Lines Matching refs:ctxi
119 struct ctx_info *ctxi; in find_error_context() local
121 list_for_each_entry(ctxi, &cfg->ctx_err_recovery, list) in find_error_context()
122 if ((ctxi->ctxid == rctxid) || (ctxi->file == file)) in find_error_context()
123 return ctxi; in find_error_context()
147 struct ctx_info *ctxi = NULL; in get_context() local
166 ctxi = cfg->ctx_tbl[ctxid]; in get_context()
167 if (ctxi) in get_context()
168 if ((file && (ctxi->file != file)) || in get_context()
169 (!file && (ctxi->ctxid != rctxid))) in get_context()
170 ctxi = NULL; in get_context()
173 (!ctxi && (ctx_ctrl & CTX_CTRL_ERR_FALLBACK))) in get_context()
174 ctxi = find_error_context(cfg, rctxid, file); in get_context()
175 if (!ctxi) { in get_context()
192 rc = mutex_trylock(&ctxi->mutex); in get_context()
198 if (ctxi->unavail) in get_context()
201 ctxpid = ctxi->pid; in get_context()
207 list_for_each_entry(lun_access, &ctxi->luns, list) in get_context()
216 "ctx_ctrl=%u\n", __func__, rctxid, ctxi, ctxpid, pid, in get_context()
219 return ctxi; in get_context()
222 mutex_unlock(&ctxi->mutex); in get_context()
223 ctxi = NULL; in get_context()
233 void put_context(struct ctx_info *ctxi) in put_context() argument
235 mutex_unlock(&ctxi->mutex); in put_context()
249 static int afu_attach(struct cxlflash_cfg *cfg, struct ctx_info *ctxi) in afu_attach() argument
253 struct sisl_ctrl_map __iomem *ctrl_map = ctxi->ctrl_map; in afu_attach()
270 writeq_be((u64)ctxi->rht_start, &ctrl_map->rht_start); in afu_attach()
415 struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl, in get_rhte() argument
420 if (unlikely(!ctxi->rht_start)) { in get_rhte()
431 if (unlikely(ctxi->rht_lun[rhndl] != lli)) { in get_rhte()
437 rhte = &ctxi->rht_start[rhndl]; in get_rhte()
456 struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi, in rhte_checkout() argument
464 if (ctxi->rht_start[i].nmask == 0) { in rhte_checkout()
465 rhte = &ctxi->rht_start[i]; in rhte_checkout()
466 ctxi->rht_out++; in rhte_checkout()
471 ctxi->rht_lun[i] = lli; in rhte_checkout()
482 void rhte_checkin(struct ctx_info *ctxi, in rhte_checkin() argument
485 u32 rsrc_handle = rhte - ctxi->rht_start; in rhte_checkin()
489 ctxi->rht_out--; in rhte_checkin()
490 ctxi->rht_lun[rsrc_handle] = NULL; in rhte_checkin()
491 ctxi->rht_needs_ws[rsrc_handle] = false; in rhte_checkin()
605 struct ctx_info *ctxi, in _cxlflash_disk_release() argument
628 if (!ctxi) { in _cxlflash_disk_release()
629 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in _cxlflash_disk_release()
630 if (unlikely(!ctxi)) { in _cxlflash_disk_release()
640 rhte = get_rhte(ctxi, rhndl, lli); in _cxlflash_disk_release()
659 rc = _cxlflash_vlun_resize(sdev, ctxi, &size); in _cxlflash_disk_release()
683 if (!ctxi->err_recovery_active) in _cxlflash_disk_release()
691 rhte_checkin(ctxi, rhte); in _cxlflash_disk_release()
696 put_context(ctxi); in _cxlflash_disk_release()
722 struct ctx_info *ctxi) in destroy_context() argument
726 WARN_ON(!list_empty(&ctxi->luns)); in destroy_context()
729 if (afu->afu_map && ctxi->ctrl_map) { in destroy_context()
730 writeq_be(0, &ctxi->ctrl_map->rht_start); in destroy_context()
731 writeq_be(0, &ctxi->ctrl_map->rht_cnt_id); in destroy_context()
732 writeq_be(0, &ctxi->ctrl_map->ctx_cap); in destroy_context()
736 free_page((ulong)ctxi->rht_start); in destroy_context()
737 kfree(ctxi->rht_needs_ws); in destroy_context()
738 kfree(ctxi->rht_lun); in destroy_context()
739 kfree(ctxi); in destroy_context()
762 struct ctx_info *ctxi = NULL; in create_context() local
767 ctxi = kzalloc(sizeof(*ctxi), GFP_KERNEL); in create_context()
770 if (unlikely(!ctxi || !lli || !ws)) { in create_context()
781 ctxi->rht_lun = lli; in create_context()
782 ctxi->rht_needs_ws = ws; in create_context()
783 ctxi->rht_start = rhte; in create_context()
784 ctxi->rht_perms = perms; in create_context()
786 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl; in create_context()
787 ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid); in create_context()
788 ctxi->lfd = adap_fd; in create_context()
789 ctxi->pid = current->tgid; /* tgid = pid */ in create_context()
790 ctxi->ctx = ctx; in create_context()
791 ctxi->file = file; in create_context()
792 mutex_init(&ctxi->mutex); in create_context()
793 INIT_LIST_HEAD(&ctxi->luns); in create_context()
794 INIT_LIST_HEAD(&ctxi->list); /* initialize for list_empty() */ in create_context()
796 mutex_lock(&ctxi->mutex); in create_context()
798 return ctxi; in create_context()
803 kfree(ctxi); in create_context()
804 ctxi = NULL; in create_context()
821 struct ctx_info *ctxi, in _cxlflash_disk_detach() argument
839 if (!ctxi) { in _cxlflash_disk_detach()
840 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in _cxlflash_disk_detach()
841 if (unlikely(!ctxi)) { in _cxlflash_disk_detach()
852 if (ctxi->rht_out) { in _cxlflash_disk_detach()
855 if (ctxi->rht_lun[i] == lli) { in _cxlflash_disk_detach()
857 _cxlflash_disk_release(sdev, ctxi, &rel); in _cxlflash_disk_detach()
861 if (ctxi->rht_out == 0) in _cxlflash_disk_detach()
867 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list) in _cxlflash_disk_detach()
876 if (list_empty(&ctxi->luns)) { in _cxlflash_disk_detach()
877 ctxi->unavail = true; in _cxlflash_disk_detach()
878 mutex_unlock(&ctxi->mutex); in _cxlflash_disk_detach()
880 mutex_lock(&ctxi->mutex); in _cxlflash_disk_detach()
883 if (!list_empty(&ctxi->list)) in _cxlflash_disk_detach()
884 list_del(&ctxi->list); in _cxlflash_disk_detach()
887 mutex_unlock(&ctxi->mutex); in _cxlflash_disk_detach()
889 lfd = ctxi->lfd; in _cxlflash_disk_detach()
890 destroy_context(cfg, ctxi); in _cxlflash_disk_detach()
891 ctxi = NULL; in _cxlflash_disk_detach()
911 put_context(ctxi); in _cxlflash_disk_detach()
966 struct ctx_info *ctxi = NULL; in cxlflash_cxl_release() local
979 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_cxl_release()
980 if (unlikely(!ctxi)) { in cxlflash_cxl_release()
981 ctxi = get_context(cfg, ctxid, file, ctrl | CTX_CTRL_CLONE); in cxlflash_cxl_release()
982 if (!ctxi) { in cxlflash_cxl_release()
990 put_context(ctxi); in cxlflash_cxl_release()
995 __func__, ctxi->lfd, ctxid); in cxlflash_cxl_release()
998 ctxi->lfd = -1; in cxlflash_cxl_release()
999 detach.context_id = ctxi->ctxid; in cxlflash_cxl_release()
1000 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list) in cxlflash_cxl_release()
1001 _cxlflash_disk_detach(lun_access->sdev, ctxi, &detach); in cxlflash_cxl_release()
1017 static void unmap_context(struct ctx_info *ctxi) in unmap_context() argument
1019 unmap_mapping_range(ctxi->file->f_mapping, 0, 0, 1); in unmap_context()
1079 struct ctx_info *ctxi = NULL; in cxlflash_mmap_fault() local
1092 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_mmap_fault()
1093 if (unlikely(!ctxi)) { in cxlflash_mmap_fault()
1099 __func__, ctxi->lfd, ctxid); in cxlflash_mmap_fault()
1101 if (likely(!ctxi->err_recovery_active)) { in cxlflash_mmap_fault()
1103 rc = ctxi->cxl_mmap_vmops->fault(vma, vmf); in cxlflash_mmap_fault()
1122 if (likely(ctxi)) in cxlflash_mmap_fault()
1123 put_context(ctxi); in cxlflash_mmap_fault()
1154 struct ctx_info *ctxi = NULL; in cxlflash_cxl_mmap() local
1167 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_cxl_mmap()
1168 if (unlikely(!ctxi)) { in cxlflash_cxl_mmap()
1175 __func__, ctxi->lfd, ctxid); in cxlflash_cxl_mmap()
1180 ctxi->cxl_mmap_vmops = vma->vm_ops; in cxlflash_cxl_mmap()
1185 if (likely(ctxi)) in cxlflash_cxl_mmap()
1186 put_context(ctxi); in cxlflash_cxl_mmap()
1208 struct ctx_info *ctxi = NULL; in cxlflash_mark_contexts_error() local
1213 ctxi = cfg->ctx_tbl[i]; in cxlflash_mark_contexts_error()
1214 if (ctxi) { in cxlflash_mark_contexts_error()
1215 mutex_lock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1217 list_add(&ctxi->list, &cfg->ctx_err_recovery); in cxlflash_mark_contexts_error()
1218 ctxi->err_recovery_active = true; in cxlflash_mark_contexts_error()
1219 ctxi->ctrl_map = NULL; in cxlflash_mark_contexts_error()
1220 unmap_context(ctxi); in cxlflash_mark_contexts_error()
1221 mutex_unlock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1297 struct ctx_info *ctxi = NULL; in cxlflash_disk_attach() local
1332 ctxi = get_context(cfg, rctxid, NULL, 0); in cxlflash_disk_attach()
1333 if (!ctxi) { in cxlflash_disk_attach()
1340 list_for_each_entry(lun_access, &ctxi->luns, list) in cxlflash_disk_attach()
1366 if (ctxi) { in cxlflash_disk_attach()
1369 list_add(&lun_access->list, &ctxi->luns); in cxlflash_disk_attach()
1370 fd = ctxi->lfd; in cxlflash_disk_attach()
1399 ctxi = create_context(cfg, ctx, ctxid, fd, file, perms); in cxlflash_disk_attach()
1400 if (unlikely(!ctxi)) { in cxlflash_disk_attach()
1406 work = &ctxi->work; in cxlflash_disk_attach()
1417 rc = afu_attach(cfg, ctxi); in cxlflash_disk_attach()
1429 list_add(&lun_access->list, &ctxi->luns); in cxlflash_disk_attach()
1430 mutex_unlock(&ctxi->mutex); in cxlflash_disk_attach()
1432 mutex_lock(&ctxi->mutex); in cxlflash_disk_attach()
1433 cfg->ctx_tbl[ctxid] = ctxi; in cxlflash_disk_attach()
1439 attach->context_id = ctxi->ctxid; in cxlflash_disk_attach()
1449 if (ctxi) in cxlflash_disk_attach()
1450 put_context(ctxi); in cxlflash_disk_attach()
1459 put_context(ctxi); in cxlflash_disk_attach()
1460 destroy_context(cfg, ctxi); in cxlflash_disk_attach()
1461 ctxi = NULL; in cxlflash_disk_attach()
1492 static int recover_context(struct cxlflash_cfg *cfg, struct ctx_info *ctxi) in recover_context() argument
1524 rc = cxl_start_work(ctx, &ctxi->work); in recover_context()
1532 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl; in recover_context()
1534 rc = afu_attach(cfg, ctxi); in recover_context()
1544 old_fd = ctxi->lfd; in recover_context()
1545 ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid); in recover_context()
1546 ctxi->lfd = fd; in recover_context()
1547 ctxi->ctx = ctx; in recover_context()
1548 ctxi->file = file; in recover_context()
1556 mutex_unlock(&ctxi->mutex); in recover_context()
1558 mutex_lock(&ctxi->mutex); in recover_context()
1559 list_del_init(&ctxi->list); in recover_context()
1560 cfg->ctx_tbl[ctxid] = ctxi; in recover_context()
1611 struct ctx_info *ctxi = NULL; in cxlflash_afu_recover() local
1629 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in cxlflash_afu_recover()
1630 if (unlikely(!ctxi)) { in cxlflash_afu_recover()
1636 if (ctxi->err_recovery_active) { in cxlflash_afu_recover()
1638 rc = recover_context(cfg, ctxi); in cxlflash_afu_recover()
1658 ctxi->err_recovery_active = false; in cxlflash_afu_recover()
1659 recover->context_id = ctxi->ctxid; in cxlflash_afu_recover()
1660 recover->adap_fd = ctxi->lfd; in cxlflash_afu_recover()
1677 put_context(ctxi); in cxlflash_afu_recover()
1678 ctxi = NULL; in cxlflash_afu_recover()
1688 if (likely(ctxi)) in cxlflash_afu_recover()
1689 put_context(ctxi); in cxlflash_afu_recover()
1771 struct ctx_info *ctxi = NULL; in cxlflash_disk_verify() local
1786 ctxi = get_context(cfg, rctxid, lli, 0); in cxlflash_disk_verify()
1787 if (unlikely(!ctxi)) { in cxlflash_disk_verify()
1793 rhte = get_rhte(ctxi, rhndl, lli); in cxlflash_disk_verify()
1809 ctxi->unavail = true; in cxlflash_disk_verify()
1810 mutex_unlock(&ctxi->mutex); in cxlflash_disk_verify()
1815 mutex_lock(&ctxi->mutex); in cxlflash_disk_verify()
1816 ctxi->unavail = false; in cxlflash_disk_verify()
1819 mutex_lock(&ctxi->mutex); in cxlflash_disk_verify()
1820 ctxi->unavail = false; in cxlflash_disk_verify()
1840 if (likely(ctxi)) in cxlflash_disk_verify()
1841 put_context(ctxi); in cxlflash_disk_verify()
1911 struct ctx_info *ctxi = NULL; in cxlflash_disk_direct_open() local
1923 ctxi = get_context(cfg, rctxid, lli, 0); in cxlflash_disk_direct_open()
1924 if (unlikely(!ctxi)) { in cxlflash_disk_direct_open()
1930 rhte = rhte_checkout(ctxi, lli); in cxlflash_disk_direct_open()
1937 rsrc_handle = (rhte - ctxi->rht_start); in cxlflash_disk_direct_open()
1939 rht_format1(rhte, lli->lun_id[sdev->channel], ctxi->rht_perms, port); in cxlflash_disk_direct_open()
1948 if (likely(ctxi)) in cxlflash_disk_direct_open()
1949 put_context(ctxi); in cxlflash_disk_direct_open()