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()
434 struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl, in get_rhte() argument
437 struct cxlflash_cfg *cfg = ctxi->cfg; in get_rhte()
441 if (unlikely(!ctxi->rht_start)) { in get_rhte()
453 if (unlikely(ctxi->rht_lun[rhndl] != lli)) { in get_rhte()
459 rhte = &ctxi->rht_start[rhndl]; in get_rhte()
478 struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi, in rhte_checkout() argument
481 struct cxlflash_cfg *cfg = ctxi->cfg; in rhte_checkout()
488 if (ctxi->rht_start[i].nmask == 0) { in rhte_checkout()
489 rhte = &ctxi->rht_start[i]; in rhte_checkout()
490 ctxi->rht_out++; in rhte_checkout()
495 ctxi->rht_lun[i] = lli; in rhte_checkout()
506 void rhte_checkin(struct ctx_info *ctxi, in rhte_checkin() argument
509 u32 rsrc_handle = rhte - ctxi->rht_start; in rhte_checkin()
513 ctxi->rht_out--; in rhte_checkin()
514 ctxi->rht_lun[rsrc_handle] = NULL; in rhte_checkin()
515 ctxi->rht_needs_ws[rsrc_handle] = false; in rhte_checkin()
629 struct ctx_info *ctxi, in _cxlflash_disk_release() argument
653 if (!ctxi) { in _cxlflash_disk_release()
654 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in _cxlflash_disk_release()
655 if (unlikely(!ctxi)) { in _cxlflash_disk_release()
665 rhte = get_rhte(ctxi, rhndl, lli); in _cxlflash_disk_release()
684 rc = _cxlflash_vlun_resize(sdev, ctxi, &size); in _cxlflash_disk_release()
708 if (!ctxi->err_recovery_active) { in _cxlflash_disk_release()
720 rhte_checkin(ctxi, rhte); in _cxlflash_disk_release()
725 put_context(ctxi); in _cxlflash_disk_release()
750 struct ctx_info *ctxi) in destroy_context() argument
754 if (ctxi->initialized) { in destroy_context()
755 WARN_ON(!list_empty(&ctxi->luns)); in destroy_context()
758 if (afu->afu_map && ctxi->ctrl_map) { in destroy_context()
759 writeq_be(0, &ctxi->ctrl_map->rht_start); in destroy_context()
760 writeq_be(0, &ctxi->ctrl_map->rht_cnt_id); in destroy_context()
761 writeq_be(0, &ctxi->ctrl_map->ctx_cap); in destroy_context()
766 free_page((ulong)ctxi->rht_start); in destroy_context()
767 kfree(ctxi->rht_needs_ws); in destroy_context()
768 kfree(ctxi->rht_lun); in destroy_context()
769 kfree(ctxi); in destroy_context()
781 struct ctx_info *ctxi = NULL; in create_context() local
786 ctxi = kzalloc(sizeof(*ctxi), GFP_KERNEL); in create_context()
789 if (unlikely(!ctxi || !lli || !ws)) { in create_context()
800 ctxi->rht_lun = lli; in create_context()
801 ctxi->rht_needs_ws = ws; in create_context()
802 ctxi->rht_start = rhte; in create_context()
804 return ctxi; in create_context()
809 kfree(ctxi); in create_context()
810 ctxi = NULL; in create_context()
824 static void init_context(struct ctx_info *ctxi, struct cxlflash_cfg *cfg, in init_context() argument
830 ctxi->rht_perms = perms; in init_context()
831 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl; in init_context()
832 ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid); in init_context()
833 ctxi->irqs = irqs; in init_context()
834 ctxi->pid = task_tgid_nr(current); /* tgid = pid */ in init_context()
835 ctxi->ctx = ctx; in init_context()
836 ctxi->cfg = cfg; in init_context()
837 ctxi->file = file; in init_context()
838 ctxi->initialized = true; in init_context()
839 mutex_init(&ctxi->mutex); in init_context()
840 kref_init(&ctxi->kref); in init_context()
841 INIT_LIST_HEAD(&ctxi->luns); in init_context()
842 INIT_LIST_HEAD(&ctxi->list); /* initialize for list_empty() */ in init_context()
855 struct ctx_info *ctxi = container_of(kref, struct ctx_info, kref); in remove_context() local
856 struct cxlflash_cfg *cfg = ctxi->cfg; in remove_context()
857 u64 ctxid = DECODE_CTXID(ctxi->ctxid); in remove_context()
860 WARN_ON(!mutex_is_locked(&ctxi->mutex)); in remove_context()
861 ctxi->unavail = true; in remove_context()
862 mutex_unlock(&ctxi->mutex); in remove_context()
864 mutex_lock(&ctxi->mutex); in remove_context()
866 if (!list_empty(&ctxi->list)) in remove_context()
867 list_del(&ctxi->list); in remove_context()
870 mutex_unlock(&ctxi->mutex); in remove_context()
873 destroy_context(cfg, ctxi); in remove_context()
889 struct ctx_info *ctxi, in _cxlflash_disk_detach() argument
906 if (!ctxi) { in _cxlflash_disk_detach()
907 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in _cxlflash_disk_detach()
908 if (unlikely(!ctxi)) { in _cxlflash_disk_detach()
919 if (ctxi->rht_out) { in _cxlflash_disk_detach()
922 if (ctxi->rht_lun[i] == lli) { in _cxlflash_disk_detach()
924 _cxlflash_disk_release(sdev, ctxi, &rel); in _cxlflash_disk_detach()
928 if (ctxi->rht_out == 0) in _cxlflash_disk_detach()
934 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list) in _cxlflash_disk_detach()
946 if (kref_put(&ctxi->kref, remove_context)) in _cxlflash_disk_detach()
951 put_context(ctxi); in _cxlflash_disk_detach()
994 struct ctx_info *ctxi = NULL; in cxlflash_cxl_release() local
1007 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_cxl_release()
1008 if (unlikely(!ctxi)) { in cxlflash_cxl_release()
1009 ctxi = get_context(cfg, ctxid, file, ctrl | CTX_CTRL_CLONE); in cxlflash_cxl_release()
1010 if (!ctxi) { in cxlflash_cxl_release()
1018 put_context(ctxi); in cxlflash_cxl_release()
1025 detach.context_id = ctxi->ctxid; in cxlflash_cxl_release()
1026 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list) in cxlflash_cxl_release()
1027 _cxlflash_disk_detach(lun_access->sdev, ctxi, &detach); in cxlflash_cxl_release()
1044 static void unmap_context(struct ctx_info *ctxi) in unmap_context() argument
1046 unmap_mapping_range(ctxi->file->f_mapping, 0, 0, 1); in unmap_context()
1109 struct ctx_info *ctxi = NULL; in cxlflash_mmap_fault() local
1122 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_mmap_fault()
1123 if (unlikely(!ctxi)) { in cxlflash_mmap_fault()
1130 if (likely(!ctxi->err_recovery_active)) { in cxlflash_mmap_fault()
1132 rc = ctxi->cxl_mmap_vmops->fault(vmf); in cxlflash_mmap_fault()
1150 if (likely(ctxi)) in cxlflash_mmap_fault()
1151 put_context(ctxi); in cxlflash_mmap_fault()
1182 struct ctx_info *ctxi = NULL; in cxlflash_cxl_mmap() local
1195 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_cxl_mmap()
1196 if (unlikely(!ctxi)) { in cxlflash_cxl_mmap()
1207 ctxi->cxl_mmap_vmops = vma->vm_ops; in cxlflash_cxl_mmap()
1212 if (likely(ctxi)) in cxlflash_cxl_mmap()
1213 put_context(ctxi); in cxlflash_cxl_mmap()
1235 struct ctx_info *ctxi = NULL; in cxlflash_mark_contexts_error() local
1240 ctxi = cfg->ctx_tbl[i]; in cxlflash_mark_contexts_error()
1241 if (ctxi) { in cxlflash_mark_contexts_error()
1242 mutex_lock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1244 list_add(&ctxi->list, &cfg->ctx_err_recovery); in cxlflash_mark_contexts_error()
1245 ctxi->err_recovery_active = true; in cxlflash_mark_contexts_error()
1246 ctxi->ctrl_map = NULL; in cxlflash_mark_contexts_error()
1247 unmap_context(ctxi); in cxlflash_mark_contexts_error()
1248 mutex_unlock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1323 struct ctx_info *ctxi = NULL; in cxlflash_disk_attach() local
1360 ctxi = get_context(cfg, rctxid, NULL, 0); in cxlflash_disk_attach()
1361 if (!ctxi) { in cxlflash_disk_attach()
1368 list_for_each_entry(lun_access, &ctxi->luns, list) in cxlflash_disk_attach()
1394 if (ctxi) { in cxlflash_disk_attach()
1397 kref_get(&ctxi->kref); in cxlflash_disk_attach()
1398 list_add(&lun_access->list, &ctxi->luns); in cxlflash_disk_attach()
1402 ctxi = create_context(cfg); in cxlflash_disk_attach()
1403 if (unlikely(!ctxi)) { in cxlflash_disk_attach()
1443 init_context(ctxi, cfg, ctx, ctxid, file, perms, irqs); in cxlflash_disk_attach()
1445 rc = afu_attach(cfg, ctxi); in cxlflash_disk_attach()
1457 list_add(&lun_access->list, &ctxi->luns); in cxlflash_disk_attach()
1459 mutex_lock(&ctxi->mutex); in cxlflash_disk_attach()
1460 cfg->ctx_tbl[ctxid] = ctxi; in cxlflash_disk_attach()
1471 attach->context_id = ctxi->ctxid; in cxlflash_disk_attach()
1481 if (ctxi) in cxlflash_disk_attach()
1482 put_context(ctxi); in cxlflash_disk_attach()
1512 if (ctxi) { in cxlflash_disk_attach()
1513 destroy_context(cfg, ctxi); in cxlflash_disk_attach()
1514 ctxi = NULL; in cxlflash_disk_attach()
1533 struct ctx_info *ctxi, in recover_context() argument
1552 rc = cfg->ops->start_work(ctx, ctxi->irqs); in recover_context()
1574 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl; in recover_context()
1576 rc = afu_attach(cfg, ctxi); in recover_context()
1586 ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid); in recover_context()
1587 ctxi->ctx = ctx; in recover_context()
1588 ctxi->file = file; in recover_context()
1596 mutex_unlock(&ctxi->mutex); in recover_context()
1598 mutex_lock(&ctxi->mutex); in recover_context()
1599 list_del_init(&ctxi->list); in recover_context()
1600 cfg->ctx_tbl[ctxid] = ctxi; in recover_context()
1656 struct ctx_info *ctxi = NULL; in cxlflash_afu_recover() local
1689 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in cxlflash_afu_recover()
1690 if (unlikely(!ctxi)) { in cxlflash_afu_recover()
1696 if (ctxi->err_recovery_active) { in cxlflash_afu_recover()
1698 rc = recover_context(cfg, ctxi, &new_adap_fd); in cxlflash_afu_recover()
1720 ctxi->err_recovery_active = false; in cxlflash_afu_recover()
1728 recover->context_id = ctxi->ctxid; in cxlflash_afu_recover()
1744 put_context(ctxi); in cxlflash_afu_recover()
1745 ctxi = NULL; in cxlflash_afu_recover()
1755 if (likely(ctxi)) in cxlflash_afu_recover()
1756 put_context(ctxi); in cxlflash_afu_recover()
1838 struct ctx_info *ctxi = NULL; in cxlflash_disk_verify() local
1853 ctxi = get_context(cfg, rctxid, lli, 0); in cxlflash_disk_verify()
1854 if (unlikely(!ctxi)) { in cxlflash_disk_verify()
1860 rhte = get_rhte(ctxi, rhndl, lli); in cxlflash_disk_verify()
1876 ctxi->unavail = true; in cxlflash_disk_verify()
1877 mutex_unlock(&ctxi->mutex); in cxlflash_disk_verify()
1882 mutex_lock(&ctxi->mutex); in cxlflash_disk_verify()
1883 ctxi->unavail = false; in cxlflash_disk_verify()
1886 mutex_lock(&ctxi->mutex); in cxlflash_disk_verify()
1887 ctxi->unavail = false; in cxlflash_disk_verify()
1907 if (likely(ctxi)) in cxlflash_disk_verify()
1908 put_context(ctxi); in cxlflash_disk_verify()
1979 struct ctx_info *ctxi = NULL; in cxlflash_disk_direct_open() local
1990 ctxi = get_context(cfg, rctxid, lli, 0); in cxlflash_disk_direct_open()
1991 if (unlikely(!ctxi)) { in cxlflash_disk_direct_open()
1997 rhte = rhte_checkout(ctxi, lli); in cxlflash_disk_direct_open()
2005 rsrc_handle = (rhte - ctxi->rht_start); in cxlflash_disk_direct_open()
2007 rht_format1(rhte, lli->lun_id[sdev->channel], ctxi->rht_perms, port); in cxlflash_disk_direct_open()
2021 if (likely(ctxi)) in cxlflash_disk_direct_open()
2022 put_context(ctxi); in cxlflash_disk_direct_open()
2029 _cxlflash_disk_release(sdev, ctxi, &rel); in cxlflash_disk_direct_open()