Lines Matching refs:ctxi

131 	struct ctx_info *ctxi;  in find_error_context()  local
133 list_for_each_entry(ctxi, &cfg->ctx_err_recovery, list) in find_error_context()
134 if ((ctxi->ctxid == rctxid) || (ctxi->file == file)) in find_error_context()
135 return ctxi; in find_error_context()
159 struct ctx_info *ctxi = NULL; in get_context() local
178 ctxi = cfg->ctx_tbl[ctxid]; in get_context()
179 if (ctxi) in get_context()
180 if ((file && (ctxi->file != file)) || in get_context()
181 (!file && (ctxi->ctxid != rctxid))) in get_context()
182 ctxi = NULL; in get_context()
185 (!ctxi && (ctx_ctrl & CTX_CTRL_ERR_FALLBACK))) in get_context()
186 ctxi = find_error_context(cfg, rctxid, file); in get_context()
187 if (!ctxi) { in get_context()
204 rc = mutex_trylock(&ctxi->mutex); in get_context()
210 if (ctxi->unavail) in get_context()
213 ctxpid = ctxi->pid; in get_context()
219 list_for_each_entry(lun_access, &ctxi->luns, list) in get_context()
228 "ctx_ctrl=%u\n", __func__, rctxid, ctxi, ctxpid, pid, in get_context()
231 return ctxi; in get_context()
234 mutex_unlock(&ctxi->mutex); in get_context()
235 ctxi = NULL; in get_context()
245 void put_context(struct ctx_info *ctxi) in put_context() argument
247 mutex_unlock(&ctxi->mutex); in put_context()
261 static int afu_attach(struct cxlflash_cfg *cfg, struct ctx_info *ctxi) in afu_attach() argument
265 struct sisl_ctrl_map __iomem *ctrl_map = ctxi->ctrl_map; in afu_attach()
285 for (i = 0; i < ctxi->irqs; i++) { in afu_attach()
286 val = cfg->ops->get_irq_objhndl(ctxi->ctx, i); in afu_attach()
297 writeq_be((u64)ctxi->rht_start, &ctrl_map->rht_start); in afu_attach()
436 struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl, in get_rhte() argument
439 struct cxlflash_cfg *cfg = ctxi->cfg; in get_rhte()
443 if (unlikely(!ctxi->rht_start)) { in get_rhte()
455 if (unlikely(ctxi->rht_lun[rhndl] != lli)) { in get_rhte()
461 rhte = &ctxi->rht_start[rhndl]; in get_rhte()
480 struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi, in rhte_checkout() argument
483 struct cxlflash_cfg *cfg = ctxi->cfg; in rhte_checkout()
490 if (ctxi->rht_start[i].nmask == 0) { in rhte_checkout()
491 rhte = &ctxi->rht_start[i]; in rhte_checkout()
492 ctxi->rht_out++; in rhte_checkout()
497 ctxi->rht_lun[i] = lli; in rhte_checkout()
508 void rhte_checkin(struct ctx_info *ctxi, in rhte_checkin() argument
511 u32 rsrc_handle = rhte - ctxi->rht_start; in rhte_checkin()
515 ctxi->rht_out--; in rhte_checkin()
516 ctxi->rht_lun[rsrc_handle] = NULL; in rhte_checkin()
517 ctxi->rht_needs_ws[rsrc_handle] = false; in rhte_checkin()
631 struct ctx_info *ctxi, in _cxlflash_disk_release() argument
655 if (!ctxi) { in _cxlflash_disk_release()
656 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in _cxlflash_disk_release()
657 if (unlikely(!ctxi)) { in _cxlflash_disk_release()
667 rhte = get_rhte(ctxi, rhndl, lli); in _cxlflash_disk_release()
686 rc = _cxlflash_vlun_resize(sdev, ctxi, &size); in _cxlflash_disk_release()
710 if (!ctxi->err_recovery_active) { in _cxlflash_disk_release()
722 rhte_checkin(ctxi, rhte); in _cxlflash_disk_release()
727 put_context(ctxi); in _cxlflash_disk_release()
752 struct ctx_info *ctxi) in destroy_context() argument
756 if (ctxi->initialized) { in destroy_context()
757 WARN_ON(!list_empty(&ctxi->luns)); in destroy_context()
760 if (afu->afu_map && ctxi->ctrl_map) { in destroy_context()
761 writeq_be(0, &ctxi->ctrl_map->rht_start); in destroy_context()
762 writeq_be(0, &ctxi->ctrl_map->rht_cnt_id); in destroy_context()
763 writeq_be(0, &ctxi->ctrl_map->ctx_cap); in destroy_context()
768 free_page((ulong)ctxi->rht_start); in destroy_context()
769 kfree(ctxi->rht_needs_ws); in destroy_context()
770 kfree(ctxi->rht_lun); in destroy_context()
771 kfree(ctxi); in destroy_context()
783 struct ctx_info *ctxi = NULL; in create_context() local
788 ctxi = kzalloc(sizeof(*ctxi), GFP_KERNEL); in create_context()
791 if (unlikely(!ctxi || !lli || !ws)) { in create_context()
802 ctxi->rht_lun = lli; in create_context()
803 ctxi->rht_needs_ws = ws; in create_context()
804 ctxi->rht_start = rhte; in create_context()
806 return ctxi; in create_context()
811 kfree(ctxi); in create_context()
812 ctxi = NULL; in create_context()
826 static void init_context(struct ctx_info *ctxi, struct cxlflash_cfg *cfg, in init_context() argument
832 ctxi->rht_perms = perms; in init_context()
833 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl; in init_context()
834 ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid); in init_context()
835 ctxi->irqs = irqs; in init_context()
836 ctxi->pid = task_tgid_nr(current); /* tgid = pid */ in init_context()
837 ctxi->ctx = ctx; in init_context()
838 ctxi->cfg = cfg; in init_context()
839 ctxi->file = file; in init_context()
840 ctxi->initialized = true; in init_context()
841 mutex_init(&ctxi->mutex); in init_context()
842 kref_init(&ctxi->kref); in init_context()
843 INIT_LIST_HEAD(&ctxi->luns); in init_context()
844 INIT_LIST_HEAD(&ctxi->list); /* initialize for list_empty() */ in init_context()
857 struct ctx_info *ctxi = container_of(kref, struct ctx_info, kref); in remove_context() local
858 struct cxlflash_cfg *cfg = ctxi->cfg; in remove_context()
859 u64 ctxid = DECODE_CTXID(ctxi->ctxid); in remove_context()
862 WARN_ON(!mutex_is_locked(&ctxi->mutex)); in remove_context()
863 ctxi->unavail = true; in remove_context()
864 mutex_unlock(&ctxi->mutex); in remove_context()
866 mutex_lock(&ctxi->mutex); in remove_context()
868 if (!list_empty(&ctxi->list)) in remove_context()
869 list_del(&ctxi->list); in remove_context()
872 mutex_unlock(&ctxi->mutex); in remove_context()
875 destroy_context(cfg, ctxi); in remove_context()
891 struct ctx_info *ctxi, in _cxlflash_disk_detach() argument
908 if (!ctxi) { in _cxlflash_disk_detach()
909 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in _cxlflash_disk_detach()
910 if (unlikely(!ctxi)) { in _cxlflash_disk_detach()
921 if (ctxi->rht_out) { in _cxlflash_disk_detach()
924 if (ctxi->rht_lun[i] == lli) { in _cxlflash_disk_detach()
926 _cxlflash_disk_release(sdev, ctxi, &rel); in _cxlflash_disk_detach()
930 if (ctxi->rht_out == 0) in _cxlflash_disk_detach()
936 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list) in _cxlflash_disk_detach()
948 if (kref_put(&ctxi->kref, remove_context)) in _cxlflash_disk_detach()
953 put_context(ctxi); in _cxlflash_disk_detach()
996 struct ctx_info *ctxi = NULL; in cxlflash_cxl_release() local
1009 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_cxl_release()
1010 if (unlikely(!ctxi)) { in cxlflash_cxl_release()
1011 ctxi = get_context(cfg, ctxid, file, ctrl | CTX_CTRL_CLONE); in cxlflash_cxl_release()
1012 if (!ctxi) { in cxlflash_cxl_release()
1020 put_context(ctxi); in cxlflash_cxl_release()
1027 detach.context_id = ctxi->ctxid; in cxlflash_cxl_release()
1028 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list) in cxlflash_cxl_release()
1029 _cxlflash_disk_detach(lun_access->sdev, ctxi, &detach); in cxlflash_cxl_release()
1046 static void unmap_context(struct ctx_info *ctxi) in unmap_context() argument
1048 unmap_mapping_range(ctxi->file->f_mapping, 0, 0, 1); in unmap_context()
1111 struct ctx_info *ctxi = NULL; in cxlflash_mmap_fault() local
1124 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_mmap_fault()
1125 if (unlikely(!ctxi)) { in cxlflash_mmap_fault()
1132 if (likely(!ctxi->err_recovery_active)) { in cxlflash_mmap_fault()
1134 rc = ctxi->cxl_mmap_vmops->fault(vmf); in cxlflash_mmap_fault()
1152 if (likely(ctxi)) in cxlflash_mmap_fault()
1153 put_context(ctxi); in cxlflash_mmap_fault()
1184 struct ctx_info *ctxi = NULL; in cxlflash_cxl_mmap() local
1197 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_cxl_mmap()
1198 if (unlikely(!ctxi)) { in cxlflash_cxl_mmap()
1209 ctxi->cxl_mmap_vmops = vma->vm_ops; in cxlflash_cxl_mmap()
1214 if (likely(ctxi)) in cxlflash_cxl_mmap()
1215 put_context(ctxi); in cxlflash_cxl_mmap()
1237 struct ctx_info *ctxi = NULL; in cxlflash_mark_contexts_error() local
1242 ctxi = cfg->ctx_tbl[i]; in cxlflash_mark_contexts_error()
1243 if (ctxi) { in cxlflash_mark_contexts_error()
1244 mutex_lock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1246 list_add(&ctxi->list, &cfg->ctx_err_recovery); in cxlflash_mark_contexts_error()
1247 ctxi->err_recovery_active = true; in cxlflash_mark_contexts_error()
1248 ctxi->ctrl_map = NULL; in cxlflash_mark_contexts_error()
1249 unmap_context(ctxi); in cxlflash_mark_contexts_error()
1250 mutex_unlock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1325 struct ctx_info *ctxi = NULL; in cxlflash_disk_attach() local
1362 ctxi = get_context(cfg, rctxid, NULL, 0); in cxlflash_disk_attach()
1363 if (!ctxi) { in cxlflash_disk_attach()
1370 list_for_each_entry(lun_access, &ctxi->luns, list) in cxlflash_disk_attach()
1396 if (ctxi) { in cxlflash_disk_attach()
1399 kref_get(&ctxi->kref); in cxlflash_disk_attach()
1400 list_add(&lun_access->list, &ctxi->luns); in cxlflash_disk_attach()
1404 ctxi = create_context(cfg); in cxlflash_disk_attach()
1405 if (unlikely(!ctxi)) { in cxlflash_disk_attach()
1445 init_context(ctxi, cfg, ctx, ctxid, file, perms, irqs); in cxlflash_disk_attach()
1447 rc = afu_attach(cfg, ctxi); in cxlflash_disk_attach()
1459 list_add(&lun_access->list, &ctxi->luns); in cxlflash_disk_attach()
1461 mutex_lock(&ctxi->mutex); in cxlflash_disk_attach()
1462 cfg->ctx_tbl[ctxid] = ctxi; in cxlflash_disk_attach()
1473 attach->context_id = ctxi->ctxid; in cxlflash_disk_attach()
1483 if (ctxi) in cxlflash_disk_attach()
1484 put_context(ctxi); in cxlflash_disk_attach()
1514 if (ctxi) { in cxlflash_disk_attach()
1515 destroy_context(cfg, ctxi); in cxlflash_disk_attach()
1516 ctxi = NULL; in cxlflash_disk_attach()
1535 struct ctx_info *ctxi, in recover_context() argument
1554 rc = cfg->ops->start_work(ctx, ctxi->irqs); in recover_context()
1576 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl; in recover_context()
1578 rc = afu_attach(cfg, ctxi); in recover_context()
1588 ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid); in recover_context()
1589 ctxi->ctx = ctx; in recover_context()
1590 ctxi->file = file; in recover_context()
1598 mutex_unlock(&ctxi->mutex); in recover_context()
1600 mutex_lock(&ctxi->mutex); in recover_context()
1601 list_del_init(&ctxi->list); in recover_context()
1602 cfg->ctx_tbl[ctxid] = ctxi; in recover_context()
1658 struct ctx_info *ctxi = NULL; in cxlflash_afu_recover() local
1691 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in cxlflash_afu_recover()
1692 if (unlikely(!ctxi)) { in cxlflash_afu_recover()
1698 if (ctxi->err_recovery_active) { in cxlflash_afu_recover()
1700 rc = recover_context(cfg, ctxi, &new_adap_fd); in cxlflash_afu_recover()
1722 ctxi->err_recovery_active = false; in cxlflash_afu_recover()
1730 recover->context_id = ctxi->ctxid; in cxlflash_afu_recover()
1746 put_context(ctxi); in cxlflash_afu_recover()
1747 ctxi = NULL; in cxlflash_afu_recover()
1757 if (likely(ctxi)) in cxlflash_afu_recover()
1758 put_context(ctxi); in cxlflash_afu_recover()
1841 struct ctx_info *ctxi = NULL; in cxlflash_disk_verify() local
1856 ctxi = get_context(cfg, rctxid, lli, 0); in cxlflash_disk_verify()
1857 if (unlikely(!ctxi)) { in cxlflash_disk_verify()
1863 rhte = get_rhte(ctxi, rhndl, lli); in cxlflash_disk_verify()
1879 ctxi->unavail = true; in cxlflash_disk_verify()
1880 mutex_unlock(&ctxi->mutex); in cxlflash_disk_verify()
1885 mutex_lock(&ctxi->mutex); in cxlflash_disk_verify()
1886 ctxi->unavail = false; in cxlflash_disk_verify()
1889 mutex_lock(&ctxi->mutex); in cxlflash_disk_verify()
1890 ctxi->unavail = false; in cxlflash_disk_verify()
1910 if (likely(ctxi)) in cxlflash_disk_verify()
1911 put_context(ctxi); in cxlflash_disk_verify()
1982 struct ctx_info *ctxi = NULL; in cxlflash_disk_direct_open() local
1993 ctxi = get_context(cfg, rctxid, lli, 0); in cxlflash_disk_direct_open()
1994 if (unlikely(!ctxi)) { in cxlflash_disk_direct_open()
2000 rhte = rhte_checkout(ctxi, lli); in cxlflash_disk_direct_open()
2008 rsrc_handle = (rhte - ctxi->rht_start); in cxlflash_disk_direct_open()
2010 rht_format1(rhte, lli->lun_id[sdev->channel], ctxi->rht_perms, port); in cxlflash_disk_direct_open()
2024 if (likely(ctxi)) in cxlflash_disk_direct_open()
2025 put_context(ctxi); in cxlflash_disk_direct_open()
2032 _cxlflash_disk_release(sdev, ctxi, &rel); in cxlflash_disk_direct_open()