Lines Matching defs:ctxi

131 	struct ctx_info *ctxi;
133 list_for_each_entry(ctxi, &cfg->ctx_err_recovery, list)
134 if ((ctxi->ctxid == rctxid) || (ctxi->file == file))
135 return ctxi;
159 struct ctx_info *ctxi = NULL;
178 ctxi = cfg->ctx_tbl[ctxid];
179 if (ctxi)
180 if ((file && (ctxi->file != file)) ||
181 (!file && (ctxi->ctxid != rctxid)))
182 ctxi = NULL;
185 (!ctxi && (ctx_ctrl & CTX_CTRL_ERR_FALLBACK)))
186 ctxi = find_error_context(cfg, rctxid, file);
187 if (!ctxi) {
200 * cfg->ctx_tbl_list_mutex -> ctxi->mutex
204 rc = mutex_trylock(&ctxi->mutex);
210 if (ctxi->unavail)
213 ctxpid = ctxi->pid;
219 list_for_each_entry(lun_access, &ctxi->luns, list)
228 "ctx_ctrl=%u\n", __func__, rctxid, ctxi, ctxpid, pid,
231 return ctxi;
234 mutex_unlock(&ctxi->mutex);
235 ctxi = NULL;
241 * @ctxi: Context to release.
245 void put_context(struct ctx_info *ctxi)
247 mutex_unlock(&ctxi->mutex);
253 * @ctxi: Context to attach.
261 static int afu_attach(struct cxlflash_cfg *cfg, struct ctx_info *ctxi)
265 struct sisl_ctrl_map __iomem *ctrl_map = ctxi->ctrl_map;
285 for (i = 0; i < ctxi->irqs; i++) {
286 val = cfg->ops->get_irq_objhndl(ctxi->ctx, i);
297 writeq_be((u64)ctxi->rht_start, &ctrl_map->rht_start);
429 * @ctxi: Context owning the resource handle.
435 struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl,
438 struct cxlflash_cfg *cfg = ctxi->cfg;
442 if (unlikely(!ctxi->rht_start)) {
454 if (unlikely(ctxi->rht_lun[rhndl] != lli)) {
460 rhte = &ctxi->rht_start[rhndl];
474 * @ctxi: Context owning the resource handle.
479 struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi,
482 struct cxlflash_cfg *cfg = ctxi->cfg;
489 if (ctxi->rht_start[i].nmask == 0) {
490 rhte = &ctxi->rht_start[i];
491 ctxi->rht_out++;
496 ctxi->rht_lun[i] = lli;
504 * @ctxi: Context owning the resource handle.
507 void rhte_checkin(struct ctx_info *ctxi,
510 u32 rsrc_handle = rhte - ctxi->rht_start;
514 ctxi->rht_out--;
515 ctxi->rht_lun[rsrc_handle] = NULL;
516 ctxi->rht_needs_ws[rsrc_handle] = false;
617 * @ctxi: Context owning resources.
630 struct ctx_info *ctxi,
654 if (!ctxi) {
655 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
656 if (unlikely(!ctxi)) {
666 rhte = get_rhte(ctxi, rhndl, lli);
685 rc = _cxlflash_vlun_resize(sdev, ctxi, &size);
709 if (!ctxi->err_recovery_active) {
721 rhte_checkin(ctxi, rhte);
726 put_context(ctxi);
740 * @ctxi: Context to release.
751 struct ctx_info *ctxi)
755 if (ctxi->initialized) {
756 WARN_ON(!list_empty(&ctxi->luns));
759 if (afu->afu_map && ctxi->ctrl_map) {
760 writeq_be(0, &ctxi->ctrl_map->rht_start);
761 writeq_be(0, &ctxi->ctrl_map->rht_cnt_id);
762 writeq_be(0, &ctxi->ctrl_map->ctx_cap);
767 free_page((ulong)ctxi->rht_start);
768 kfree(ctxi->rht_needs_ws);
769 kfree(ctxi->rht_lun);
770 kfree(ctxi);
782 struct ctx_info *ctxi = NULL;
787 ctxi = kzalloc(sizeof(*ctxi), GFP_KERNEL);
790 if (unlikely(!ctxi || !lli || !ws)) {
801 ctxi->rht_lun = lli;
802 ctxi->rht_needs_ws = ws;
803 ctxi->rht_start = rhte;
805 return ctxi;
810 kfree(ctxi);
811 ctxi = NULL;
817 * @ctxi: Previously allocated context
825 static void init_context(struct ctx_info *ctxi, struct cxlflash_cfg *cfg,
831 ctxi->rht_perms = perms;
832 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl;
833 ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid);
834 ctxi->irqs = irqs;
835 ctxi->pid = task_tgid_nr(current); /* tgid = pid */
836 ctxi->ctx = ctx;
837 ctxi->cfg = cfg;
838 ctxi->file = file;
839 ctxi->initialized = true;
840 mutex_init(&ctxi->mutex);
841 kref_init(&ctxi->kref);
842 INIT_LIST_HEAD(&ctxi->luns);
843 INIT_LIST_HEAD(&ctxi->list); /* initialize for list_empty() */
856 struct ctx_info *ctxi = container_of(kref, struct ctx_info, kref);
857 struct cxlflash_cfg *cfg = ctxi->cfg;
858 u64 ctxid = DECODE_CTXID(ctxi->ctxid);
861 WARN_ON(!mutex_is_locked(&ctxi->mutex));
862 ctxi->unavail = true;
863 mutex_unlock(&ctxi->mutex);
865 mutex_lock(&ctxi->mutex);
867 if (!list_empty(&ctxi->list))
868 list_del(&ctxi->list);
871 mutex_unlock(&ctxi->mutex);
874 destroy_context(cfg, ctxi);
880 * @ctxi: Context owning resources.
890 struct ctx_info *ctxi,
907 if (!ctxi) {
908 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
909 if (unlikely(!ctxi)) {
920 if (ctxi->rht_out) {
923 if (ctxi->rht_lun[i] == lli) {
925 _cxlflash_disk_release(sdev, ctxi, &rel);
929 if (ctxi->rht_out == 0)
935 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list)
947 if (kref_put(&ctxi->kref, remove_context))
952 put_context(ctxi);
995 struct ctx_info *ctxi = NULL;
1008 ctxi = get_context(cfg, ctxid, file, ctrl);
1009 if (unlikely(!ctxi)) {
1010 ctxi = get_context(cfg, ctxid, file, ctrl | CTX_CTRL_CLONE);
1011 if (!ctxi) {
1019 put_context(ctxi);
1026 detach.context_id = ctxi->ctxid;
1027 list_for_each_entry_safe(lun_access, t, &ctxi->luns, list)
1028 _cxlflash_disk_detach(lun_access->sdev, ctxi, &detach);
1039 * @ctxi: Context owning the mapping.
1045 static void unmap_context(struct ctx_info *ctxi)
1047 unmap_mapping_range(ctxi->file->f_mapping, 0, 0, 1);
1110 struct ctx_info *ctxi = NULL;
1123 ctxi = get_context(cfg, ctxid, file, ctrl);
1124 if (unlikely(!ctxi)) {
1131 if (likely(!ctxi->err_recovery_active)) {
1133 rc = ctxi->cxl_mmap_vmops->fault(vmf);
1151 if (likely(ctxi))
1152 put_context(ctxi);
1183 struct ctx_info *ctxi = NULL;
1196 ctxi = get_context(cfg, ctxid, file, ctrl);
1197 if (unlikely(!ctxi)) {
1208 ctxi->cxl_mmap_vmops = vma->vm_ops;
1213 if (likely(ctxi))
1214 put_context(ctxi);
1236 struct ctx_info *ctxi = NULL;
1241 ctxi = cfg->ctx_tbl[i];
1242 if (ctxi) {
1243 mutex_lock(&ctxi->mutex);
1245 list_add(&ctxi->list, &cfg->ctx_err_recovery);
1246 ctxi->err_recovery_active = true;
1247 ctxi->ctrl_map = NULL;
1248 unmap_context(ctxi);
1249 mutex_unlock(&ctxi->mutex);
1324 struct ctx_info *ctxi = NULL;
1361 ctxi = get_context(cfg, rctxid, NULL, 0);
1362 if (!ctxi) {
1369 list_for_each_entry(lun_access, &ctxi->luns, list)
1395 if (ctxi) {
1398 kref_get(&ctxi->kref);
1399 list_add(&lun_access->list, &ctxi->luns);
1403 ctxi = create_context(cfg);
1404 if (unlikely(!ctxi)) {
1444 init_context(ctxi, cfg, ctx, ctxid, file, perms, irqs);
1446 rc = afu_attach(cfg, ctxi);
1458 list_add(&lun_access->list, &ctxi->luns);
1460 mutex_lock(&ctxi->mutex);
1461 cfg->ctx_tbl[ctxid] = ctxi;
1472 attach->context_id = ctxi->ctxid;
1482 if (ctxi)
1483 put_context(ctxi);
1513 if (ctxi) {
1514 destroy_context(cfg, ctxi);
1515 ctxi = NULL;
1526 * @ctxi: Context to release.
1534 struct ctx_info *ctxi,
1553 rc = cfg->ops->start_work(ctx, ctxi->irqs);
1575 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl;
1577 rc = afu_attach(cfg, ctxi);
1587 ctxi->ctxid = ENCODE_CTXID(ctxi, ctxid);
1588 ctxi->ctx = ctx;
1589 ctxi->file = file;
1597 mutex_unlock(&ctxi->mutex);
1599 mutex_lock(&ctxi->mutex);
1600 list_del_init(&ctxi->list);
1601 cfg->ctx_tbl[ctxid] = ctxi;
1657 struct ctx_info *ctxi = NULL;
1690 ctxi = get_context(cfg, rctxid, lli, CTX_CTRL_ERR_FALLBACK);
1691 if (unlikely(!ctxi)) {
1697 if (ctxi->err_recovery_active) {
1699 rc = recover_context(cfg, ctxi, &new_adap_fd);
1721 ctxi->err_recovery_active = false;
1729 recover->context_id = ctxi->ctxid;
1745 put_context(ctxi);
1746 ctxi = NULL;
1756 if (likely(ctxi))
1757 put_context(ctxi);
1839 struct ctx_info *ctxi = NULL;
1854 ctxi = get_context(cfg, rctxid, lli, 0);
1855 if (unlikely(!ctxi)) {
1861 rhte = get_rhte(ctxi, rhndl, lli);
1877 ctxi->unavail = true;
1878 mutex_unlock(&ctxi->mutex);
1883 mutex_lock(&ctxi->mutex);
1884 ctxi->unavail = false;
1887 mutex_lock(&ctxi->mutex);
1888 ctxi->unavail = false;
1908 if (likely(ctxi))
1909 put_context(ctxi);
1980 struct ctx_info *ctxi = NULL;
1991 ctxi = get_context(cfg, rctxid, lli, 0);
1992 if (unlikely(!ctxi)) {
1998 rhte = rhte_checkout(ctxi, lli);
2006 rsrc_handle = (rhte - ctxi->rht_start);
2008 rht_format1(rhte, lli->lun_id[sdev->channel], ctxi->rht_perms, port);
2022 if (likely(ctxi))
2023 put_context(ctxi);
2030 _cxlflash_disk_release(sdev, ctxi, &rel);