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()
435 struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl, in get_rhte() argument
438 struct cxlflash_cfg *cfg = ctxi->cfg; in get_rhte()
442 if (unlikely(!ctxi->rht_start)) { in get_rhte()
454 if (unlikely(ctxi->rht_lun[rhndl] != lli)) { in get_rhte()
460 rhte = &ctxi->rht_start[rhndl]; in get_rhte()
479 struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi, in rhte_checkout() argument
482 struct cxlflash_cfg *cfg = ctxi->cfg; in rhte_checkout()
489 if (ctxi->rht_start[i].nmask == 0) { in rhte_checkout()
490 rhte = &ctxi->rht_start[i]; in rhte_checkout()
491 ctxi->rht_out++; in rhte_checkout()
496 ctxi->rht_lun[i] = lli; in rhte_checkout()
507 void rhte_checkin(struct ctx_info *ctxi, in rhte_checkin() argument
510 u32 rsrc_handle = rhte - ctxi->rht_start; in rhte_checkin()
514 ctxi->rht_out--; in rhte_checkin()
515 ctxi->rht_lun[rsrc_handle] = NULL; in rhte_checkin()
516 ctxi->rht_needs_ws[rsrc_handle] = false; in rhte_checkin()
630 struct ctx_info *ctxi, in _cxlflash_disk_release() argument
654 if (!ctxi) { in _cxlflash_disk_release()
655 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in _cxlflash_disk_release()
656 if (unlikely(!ctxi)) { in _cxlflash_disk_release()
666 rhte = get_rhte(ctxi, rhndl, lli); in _cxlflash_disk_release()
685 rc = _cxlflash_vlun_resize(sdev, ctxi, &size); in _cxlflash_disk_release()
709 if (!ctxi->err_recovery_active) { in _cxlflash_disk_release()
721 rhte_checkin(ctxi, rhte); in _cxlflash_disk_release()
726 put_context(ctxi); in _cxlflash_disk_release()
751 struct ctx_info *ctxi) in destroy_context() argument
755 if (ctxi->initialized) { in destroy_context()
756 WARN_ON(!list_empty(&ctxi->luns)); in destroy_context()
759 if (afu->afu_map && ctxi->ctrl_map) { in destroy_context()
760 writeq_be(0, &ctxi->ctrl_map->rht_start); in destroy_context()
761 writeq_be(0, &ctxi->ctrl_map->rht_cnt_id); in destroy_context()
762 writeq_be(0, &ctxi->ctrl_map->ctx_cap); in destroy_context()
767 free_page((ulong)ctxi->rht_start); in destroy_context()
768 kfree(ctxi->rht_needs_ws); in destroy_context()
769 kfree(ctxi->rht_lun); in destroy_context()
770 kfree(ctxi); in destroy_context()
782 struct ctx_info *ctxi = NULL; in create_context() local
787 ctxi = kzalloc(sizeof(*ctxi), GFP_KERNEL); in create_context()
790 if (unlikely(!ctxi || !lli || !ws)) { in create_context()
801 ctxi->rht_lun = lli; in create_context()
802 ctxi->rht_needs_ws = ws; in create_context()
803 ctxi->rht_start = rhte; in create_context()
805 return ctxi; in create_context()
810 kfree(ctxi); in create_context()
811 ctxi = NULL; in create_context()
825 static void init_context(struct ctx_info *ctxi, struct cxlflash_cfg *cfg, in init_context() argument
831 ctxi->rht_perms = perms; in init_context()
832 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl; in init_context()
833 ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid); in init_context()
834 ctxi->irqs = irqs; in init_context()
835 ctxi->pid = task_tgid_nr(current); /* tgid = pid */ in init_context()
836 ctxi->ctx = ctx; in init_context()
837 ctxi->cfg = cfg; in init_context()
838 ctxi->file = file; in init_context()
839 ctxi->initialized = true; in init_context()
840 mutex_init(&ctxi->mutex); in init_context()
841 kref_init(&ctxi->kref); in init_context()
842 INIT_LIST_HEAD(&ctxi->luns); in init_context()
843 INIT_LIST_HEAD(&ctxi->list); /* initialize for list_empty() */ in init_context()
856 struct ctx_info *ctxi = container_of(kref, struct ctx_info, kref); in remove_context() local
857 struct cxlflash_cfg *cfg = ctxi->cfg; in remove_context()
858 u64 ctxid = DECODE_CTXID(ctxi->ctxid); in remove_context()
861 WARN_ON(!mutex_is_locked(&ctxi->mutex)); in remove_context()
862 ctxi->unavail = true; in remove_context()
863 mutex_unlock(&ctxi->mutex); in remove_context()
865 mutex_lock(&ctxi->mutex); in remove_context()
867 if (!list_empty(&ctxi->list)) in remove_context()
868 list_del(&ctxi->list); in remove_context()
871 mutex_unlock(&ctxi->mutex); in remove_context()
874 destroy_context(cfg, ctxi); in remove_context()
890 struct ctx_info *ctxi, in _cxlflash_disk_detach() argument
907 if (!ctxi) { in _cxlflash_disk_detach()
908 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in _cxlflash_disk_detach()
909 if (unlikely(!ctxi)) { in _cxlflash_disk_detach()
920 if (ctxi->rht_out) { in _cxlflash_disk_detach()
923 if (ctxi->rht_lun[i] == lli) { in _cxlflash_disk_detach()
925 _cxlflash_disk_release(sdev, ctxi, &rel); in _cxlflash_disk_detach()
929 if (ctxi->rht_out == 0) in _cxlflash_disk_detach()
935 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list) in _cxlflash_disk_detach()
947 if (kref_put(&ctxi->kref, remove_context)) in _cxlflash_disk_detach()
952 put_context(ctxi); in _cxlflash_disk_detach()
995 struct ctx_info *ctxi = NULL; in cxlflash_cxl_release() local
1008 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_cxl_release()
1009 if (unlikely(!ctxi)) { in cxlflash_cxl_release()
1010 ctxi = get_context(cfg, ctxid, file, ctrl | CTX_CTRL_CLONE); in cxlflash_cxl_release()
1011 if (!ctxi) { in cxlflash_cxl_release()
1019 put_context(ctxi); in cxlflash_cxl_release()
1026 detach.context_id = ctxi->ctxid; in cxlflash_cxl_release()
1027 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list) in cxlflash_cxl_release()
1028 _cxlflash_disk_detach(lun_access->sdev, ctxi, &detach); in cxlflash_cxl_release()
1045 static void unmap_context(struct ctx_info *ctxi) in unmap_context() argument
1047 unmap_mapping_range(ctxi->file->f_mapping, 0, 0, 1); in unmap_context()
1110 struct ctx_info *ctxi = NULL; in cxlflash_mmap_fault() local
1123 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_mmap_fault()
1124 if (unlikely(!ctxi)) { in cxlflash_mmap_fault()
1131 if (likely(!ctxi->err_recovery_active)) { in cxlflash_mmap_fault()
1133 rc = ctxi->cxl_mmap_vmops->fault(vmf); in cxlflash_mmap_fault()
1151 if (likely(ctxi)) in cxlflash_mmap_fault()
1152 put_context(ctxi); in cxlflash_mmap_fault()
1183 struct ctx_info *ctxi = NULL; in cxlflash_cxl_mmap() local
1196 ctxi = get_context(cfg, ctxid, file, ctrl); in cxlflash_cxl_mmap()
1197 if (unlikely(!ctxi)) { in cxlflash_cxl_mmap()
1208 ctxi->cxl_mmap_vmops = vma->vm_ops; in cxlflash_cxl_mmap()
1213 if (likely(ctxi)) in cxlflash_cxl_mmap()
1214 put_context(ctxi); in cxlflash_cxl_mmap()
1236 struct ctx_info *ctxi = NULL; in cxlflash_mark_contexts_error() local
1241 ctxi = cfg->ctx_tbl[i]; in cxlflash_mark_contexts_error()
1242 if (ctxi) { in cxlflash_mark_contexts_error()
1243 mutex_lock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1245 list_add(&ctxi->list, &cfg->ctx_err_recovery); in cxlflash_mark_contexts_error()
1246 ctxi->err_recovery_active = true; in cxlflash_mark_contexts_error()
1247 ctxi->ctrl_map = NULL; in cxlflash_mark_contexts_error()
1248 unmap_context(ctxi); in cxlflash_mark_contexts_error()
1249 mutex_unlock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1324 struct ctx_info *ctxi = NULL; in cxlflash_disk_attach() local
1361 ctxi = get_context(cfg, rctxid, NULL, 0); in cxlflash_disk_attach()
1362 if (!ctxi) { in cxlflash_disk_attach()
1369 list_for_each_entry(lun_access, &ctxi->luns, list) in cxlflash_disk_attach()
1395 if (ctxi) { in cxlflash_disk_attach()
1398 kref_get(&ctxi->kref); in cxlflash_disk_attach()
1399 list_add(&lun_access->list, &ctxi->luns); in cxlflash_disk_attach()
1403 ctxi = create_context(cfg); in cxlflash_disk_attach()
1404 if (unlikely(!ctxi)) { in cxlflash_disk_attach()
1444 init_context(ctxi, cfg, ctx, ctxid, file, perms, irqs); in cxlflash_disk_attach()
1446 rc = afu_attach(cfg, ctxi); in cxlflash_disk_attach()
1458 list_add(&lun_access->list, &ctxi->luns); in cxlflash_disk_attach()
1460 mutex_lock(&ctxi->mutex); in cxlflash_disk_attach()
1461 cfg->ctx_tbl[ctxid] = ctxi; in cxlflash_disk_attach()
1472 attach->context_id = ctxi->ctxid; in cxlflash_disk_attach()
1482 if (ctxi) in cxlflash_disk_attach()
1483 put_context(ctxi); in cxlflash_disk_attach()
1513 if (ctxi) { in cxlflash_disk_attach()
1514 destroy_context(cfg, ctxi); in cxlflash_disk_attach()
1515 ctxi = NULL; in cxlflash_disk_attach()
1534 struct ctx_info *ctxi, in recover_context() argument
1553 rc = cfg->ops->start_work(ctx, ctxi->irqs); in recover_context()
1575 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl; in recover_context()
1577 rc = afu_attach(cfg, ctxi); in recover_context()
1587 ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid); in recover_context()
1588 ctxi->ctx = ctx; in recover_context()
1589 ctxi->file = file; in recover_context()
1597 mutex_unlock(&ctxi->mutex); in recover_context()
1599 mutex_lock(&ctxi->mutex); in recover_context()
1600 list_del_init(&ctxi->list); in recover_context()
1601 cfg->ctx_tbl[ctxid] = ctxi; in recover_context()
1657 struct ctx_info *ctxi = NULL; in cxlflash_afu_recover() local
1690 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK); in cxlflash_afu_recover()
1691 if (unlikely(!ctxi)) { in cxlflash_afu_recover()
1697 if (ctxi->err_recovery_active) { in cxlflash_afu_recover()
1699 rc = recover_context(cfg, ctxi, &new_adap_fd); in cxlflash_afu_recover()
1721 ctxi->err_recovery_active = false; in cxlflash_afu_recover()
1729 recover->context_id = ctxi->ctxid; in cxlflash_afu_recover()
1745 put_context(ctxi); in cxlflash_afu_recover()
1746 ctxi = NULL; in cxlflash_afu_recover()
1756 if (likely(ctxi)) in cxlflash_afu_recover()
1757 put_context(ctxi); in cxlflash_afu_recover()
1839 struct ctx_info *ctxi = NULL; in cxlflash_disk_verify() local
1854 ctxi = get_context(cfg, rctxid, lli, 0); in cxlflash_disk_verify()
1855 if (unlikely(!ctxi)) { in cxlflash_disk_verify()
1861 rhte = get_rhte(ctxi, rhndl, lli); in cxlflash_disk_verify()
1877 ctxi->unavail = true; in cxlflash_disk_verify()
1878 mutex_unlock(&ctxi->mutex); in cxlflash_disk_verify()
1883 mutex_lock(&ctxi->mutex); in cxlflash_disk_verify()
1884 ctxi->unavail = false; in cxlflash_disk_verify()
1887 mutex_lock(&ctxi->mutex); in cxlflash_disk_verify()
1888 ctxi->unavail = false; in cxlflash_disk_verify()
1908 if (likely(ctxi)) in cxlflash_disk_verify()
1909 put_context(ctxi); in cxlflash_disk_verify()
1980 struct ctx_info *ctxi = NULL; in cxlflash_disk_direct_open() local
1991 ctxi = get_context(cfg, rctxid, lli, 0); in cxlflash_disk_direct_open()
1992 if (unlikely(!ctxi)) { in cxlflash_disk_direct_open()
1998 rhte = rhte_checkout(ctxi, lli); in cxlflash_disk_direct_open()
2006 rsrc_handle = (rhte - ctxi->rht_start); in cxlflash_disk_direct_open()
2008 rht_format1(rhte, lli->lun_id[sdev->channel], ctxi->rht_perms, port); in cxlflash_disk_direct_open()
2022 if (likely(ctxi)) in cxlflash_disk_direct_open()
2023 put_context(ctxi); in cxlflash_disk_direct_open()
2030 _cxlflash_disk_release(sdev, ctxi, &rel); in cxlflash_disk_direct_open()