Lines Matching +full:no +full:- +full:unaligned +full:- +full:direct +full:- +full:access
1 // SPDX-License-Identifier: GPL-2.0-or-later
16 #include <asm/unaligned.h>
32 * marshal_rele_to_resize() - translate release to resize structure
39 resize->hdr = release->hdr; in marshal_rele_to_resize()
40 resize->context_id = release->context_id; in marshal_rele_to_resize()
41 resize->rsrc_handle = release->rsrc_handle; in marshal_rele_to_resize()
45 * marshal_det_to_rele() - translate detach to release structure
52 release->hdr = detach->hdr; in marshal_det_to_rele()
53 release->context_id = detach->context_id; in marshal_det_to_rele()
57 * marshal_udir_to_rele() - translate udirect to release structure
64 release->hdr = udirect->hdr; in marshal_udir_to_rele()
65 release->context_id = udirect->context_id; in marshal_udir_to_rele()
66 release->rsrc_handle = udirect->rsrc_handle; in marshal_udir_to_rele()
70 * cxlflash_free_errpage() - frees resources associated with global error page
84 * cxlflash_stop_term_user_contexts() - stops/terminates known user contexts
97 struct device *dev = &cfg->dev->dev; in cxlflash_stop_term_user_contexts()
104 if (cfg->ctx_tbl[i]) { in cxlflash_stop_term_user_contexts()
109 if (!found && list_empty(&cfg->ctx_err_recovery)) in cxlflash_stop_term_user_contexts()
114 wake_up_all(&cfg->reset_waitq); in cxlflash_stop_term_user_contexts()
121 * find_error_context() - locates a context by cookie on the error recovery list
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()
141 * get_context() - obtains a validated and locked context reference
143 * @rctxid: Desired context (raw, un-decoded format).
147 * NOTE: despite the name pid, in linux, current->pid actually refers
158 struct device *dev = &cfg->dev->dev; in get_context()
177 mutex_lock(&cfg->ctx_tbl_list_mutex); in get_context()
178 ctxi = cfg->ctx_tbl[ctxid]; in get_context()
180 if ((file && (ctxi->file != file)) || in get_context()
181 (!file && (ctxi->ctxid != rctxid))) in get_context()
188 mutex_unlock(&cfg->ctx_tbl_list_mutex); in get_context()
200 * cfg->ctx_tbl_list_mutex -> ctxi->mutex in get_context()
204 rc = mutex_trylock(&ctxi->mutex); in get_context()
205 mutex_unlock(&cfg->ctx_tbl_list_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()
220 if (lun_access->lli == lli) in get_context()
234 mutex_unlock(&ctxi->mutex); in get_context()
240 * put_context() - release a context that was retrieved from get_context()
247 mutex_unlock(&ctxi->mutex); in put_context()
251 * afu_attach() - attach a context to the AFU
259 * Return: 0 on success, -errno on failure
263 struct device *dev = &cfg->dev->dev; in afu_attach()
264 struct afu *afu = cfg->afu; in afu_attach()
265 struct sisl_ctrl_map __iomem *ctrl_map = ctxi->ctrl_map; in afu_attach()
272 readq_be(&ctrl_map->mbox_r); in afu_attach()
274 writeq_be(val, &ctrl_map->ctx_cap); in afu_attach()
275 val = readq_be(&ctrl_map->ctx_cap); in afu_attach()
279 rc = -EAGAIN; 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()
287 writeq_be(val, &ctrl_map->lisn_ea[i]); in afu_attach()
291 val = hwq->ctx_hndl; in afu_attach()
292 writeq_be(SISL_LISN_PASID(val, val), &ctrl_map->lisn_pasid[0]); in afu_attach()
293 writeq_be(SISL_LISN_PASID(0UL, val), &ctrl_map->lisn_pasid[1]); in afu_attach()
297 writeq_be((u64)ctxi->rht_start, &ctrl_map->rht_start); in afu_attach()
298 val = SISL_RHT_CNT_ID((u64)MAX_RHT_PER_CONTEXT, (u64)(hwq->ctx_hndl)); in afu_attach()
299 writeq_be(val, &ctrl_map->rht_cnt_id); in afu_attach()
306 * read_cap16() - issues a SCSI READ_CAP16 command
328 * Return: 0 on success, -errno on failure
332 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in read_cap16()
333 struct device *dev = &cfg->dev->dev; in read_cap16()
334 struct glun_info *gli = lli->parent; in read_cap16()
347 rc = -ENOMEM; in read_cap16()
359 up_read(&cfg->ioctl_rwsem); in read_cap16()
363 down_read(&cfg->ioctl_rwsem); in read_cap16()
368 rc = -ENODEV; in read_cap16()
403 rc = -EIO; in read_cap16()
409 * note that we don't need to worry about unaligned access in read_cap16()
412 mutex_lock(&gli->mutex); in read_cap16()
413 gli->max_lba = be64_to_cpu(*((__be64 *)&cmd_buf[0])); in read_cap16()
414 gli->blk_len = be32_to_cpu(*((__be32 *)&cmd_buf[8])); in read_cap16()
415 mutex_unlock(&gli->mutex); in read_cap16()
422 __func__, gli->max_lba, gli->blk_len, rc); in read_cap16()
427 * get_rhte() - obtains validated resource handle table entry reference
437 struct cxlflash_cfg *cfg = ctxi->cfg; in get_rhte()
438 struct device *dev = &cfg->dev->dev; 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()
460 if (unlikely(rhte->nmask == 0)) { in get_rhte()
472 * rhte_checkout() - obtains free/empty resource handle table entry
481 struct cxlflash_cfg *cfg = ctxi->cfg; in rhte_checkout()
482 struct device *dev = &cfg->dev->dev; 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()
502 * rhte_checkin() - releases a resource handle table entry
509 u32 rsrc_handle = rhte - ctxi->rht_start; in rhte_checkin()
511 rhte->nmask = 0; in rhte_checkin()
512 rhte->fp = 0; 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()
519 * rht_format1() - populates a RHTE for format 1
529 * Populate the Format 1 RHT entry for direct access (physical in rht_format1()
537 rhte_f1->fp = SISL_RHT_FP(1U, 0); in rht_format1()
540 rhte_f1->lun_id = lun_id; in rht_format1()
551 rhte_f1->dw = dummy.dw; in rht_format1()
557 * cxlflash_lun_attach() - attaches a user to a LUN and manages the LUN's mode
562 * Return: 0 on success, -errno on failure
569 mutex_lock(&gli->mutex); in cxlflash_lun_attach()
571 if (gli->mode == MODE_NONE) in cxlflash_lun_attach()
572 gli->mode = mode; in cxlflash_lun_attach()
573 else if (gli->mode != mode) { in cxlflash_lun_attach()
575 __func__, gli->mode, mode); in cxlflash_lun_attach()
576 rc = -EINVAL; in cxlflash_lun_attach()
580 gli->users++; in cxlflash_lun_attach()
581 WARN_ON(gli->users <= 0); in cxlflash_lun_attach()
583 pr_debug("%s: Returning rc=%d gli->mode=%u gli->users=%u\n", in cxlflash_lun_attach()
584 __func__, rc, gli->mode, gli->users); in cxlflash_lun_attach()
586 mutex_unlock(&gli->mutex); in cxlflash_lun_attach()
591 * cxlflash_lun_detach() - detaches a user from a LUN and resets the LUN's mode
595 * are no longer required (service is safe to call even when block allocation
596 * resources were not present - such as when transitioning from physical mode).
602 mutex_lock(&gli->mutex); in cxlflash_lun_detach()
603 WARN_ON(gli->mode == MODE_NONE); in cxlflash_lun_detach()
604 if (--gli->users == 0) { in cxlflash_lun_detach()
605 gli->mode = MODE_NONE; in cxlflash_lun_detach()
606 cxlflash_ba_terminate(&gli->blka.ba_lun); in cxlflash_lun_detach()
608 pr_debug("%s: gli->users=%u\n", __func__, gli->users); in cxlflash_lun_detach()
609 WARN_ON(gli->users < 0); in cxlflash_lun_detach()
610 mutex_unlock(&gli->mutex); in cxlflash_lun_detach()
614 * _cxlflash_disk_release() - releases the specified resource entry
626 * Return: 0 on success, -errno on failure
632 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in _cxlflash_disk_release()
633 struct device *dev = &cfg->dev->dev; in _cxlflash_disk_release()
634 struct llun_info *lli = sdev->hostdata; in _cxlflash_disk_release()
635 struct glun_info *gli = lli->parent; in _cxlflash_disk_release()
636 struct afu *afu = cfg->afu; in _cxlflash_disk_release()
640 res_hndl_t rhndl = release->rsrc_handle; in _cxlflash_disk_release()
644 u64 ctxid = DECODE_CTXID(release->context_id), in _cxlflash_disk_release()
645 rctxid = release->context_id; in _cxlflash_disk_release()
650 dev_dbg(dev, "%s: ctxid=%llu rhndl=%llu gli->mode=%u gli->users=%u\n", in _cxlflash_disk_release()
651 __func__, ctxid, release->rsrc_handle, gli->mode, gli->users); in _cxlflash_disk_release()
658 rc = -EINVAL; in _cxlflash_disk_release()
669 rc = -EINVAL; in _cxlflash_disk_release()
680 switch (gli->mode) { in _cxlflash_disk_release()
693 * Clear the Format 1 RHT entry for direct access in _cxlflash_disk_release()
699 rhte_f1->valid = 0; in _cxlflash_disk_release()
702 rhte_f1->lun_id = 0; in _cxlflash_disk_release()
705 rhte_f1->dw = 0; in _cxlflash_disk_release()
706 dma_wmb(); /* Make RHT entry bottom-half clearing visible */ in _cxlflash_disk_release()
708 if (!ctxi->err_recovery_active) { in _cxlflash_disk_release()
737 * destroy_context() - releases a context
741 * This routine is safe to be called with a a non-initialized context.
746 * removed [so there is no need to worry about clearing] and context
752 struct afu *afu = cfg->afu; in destroy_context()
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()
773 * create_context() - allocates and initializes a context
780 struct device *dev = &cfg->dev->dev; 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()
815 * init_context() - initializes a previously allocated context
821 * @perms: User-specified permissions.
822 * @irqs: User-specified number of interrupts.
828 struct afu *afu = cfg->afu; in init_context()
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()
846 * remove_context() - context kref release handler
849 * When a context no longer has any references it can safely be removed
850 * from global access and destroyed. Note that it is assumed the thread
851 * relinquishing access to the context holds its mutex.
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()
863 mutex_lock(&cfg->ctx_tbl_list_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()
868 cfg->ctx_tbl[ctxid] = NULL; in remove_context()
869 mutex_unlock(&cfg->ctx_tbl_list_mutex); in remove_context()
870 mutex_unlock(&ctxi->mutex); in remove_context()
877 * _cxlflash_disk_detach() - detaches a LUN from a context
882 * As part of the detach, all per-context resources associated with the LUN
886 * Return: 0 on success, -errno on failure
892 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in _cxlflash_disk_detach()
893 struct device *dev = &cfg->dev->dev; in _cxlflash_disk_detach()
894 struct llun_info *lli = sdev->hostdata; in _cxlflash_disk_detach()
901 u64 ctxid = DECODE_CTXID(detach->context_id), in _cxlflash_disk_detach()
902 rctxid = detach->context_id; in _cxlflash_disk_detach()
911 rc = -EINVAL; in _cxlflash_disk_detach()
919 if (ctxi->rht_out) { in _cxlflash_disk_detach()
922 if (ctxi->rht_lun[i] == lli) { in _cxlflash_disk_detach()
927 /* No need to loop further if we're done */ 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()
935 if (lun_access->lli == lli) { in _cxlflash_disk_detach()
936 list_del(&lun_access->list); in _cxlflash_disk_detach()
946 if (kref_put(&ctxi->kref, remove_context)) in _cxlflash_disk_detach()
963 * cxlflash_cxl_release() - release handler for adapter file descriptor
964 * @inode: File-system inode associated with fd.
990 struct cxlflash_cfg *cfg = container_of(file->f_op, struct cxlflash_cfg, in cxlflash_cxl_release()
992 void *ctx = cfg->ops->fops_get_context(file); in cxlflash_cxl_release()
993 struct device *dev = &cfg->dev->dev; in cxlflash_cxl_release()
1000 ctxid = cfg->ops->process_element(ctx); in cxlflash_cxl_release()
1024 down_read(&cfg->ioctl_rwsem); 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()
1028 up_read(&cfg->ioctl_rwsem); in cxlflash_cxl_release()
1030 cfg->ops->fd_release(inode, file); in cxlflash_cxl_release()
1037 * unmap_context() - clears a previously established mapping
1046 unmap_mapping_range(ctxi->file->f_mapping, 0, 0, 1); in unmap_context()
1050 * get_err_page() - obtains and allocates the error notification page
1058 struct device *dev = &cfg->dev->dev; in get_err_page()
1068 memset(page_address(err_page), -1, PAGE_SIZE); in get_err_page()
1087 * cxlflash_mmap_fault() - mmap fault handler for adapter file descriptor
1097 * indicate cached/not-cached depending on the memory backing the fault.
1103 struct vm_area_struct *vma = vmf->vma; in cxlflash_mmap_fault()
1104 struct file *file = vma->vm_file; in cxlflash_mmap_fault()
1105 struct cxlflash_cfg *cfg = container_of(file->f_op, struct cxlflash_cfg, in cxlflash_mmap_fault()
1107 void *ctx = cfg->ops->fops_get_context(file); in cxlflash_mmap_fault()
1108 struct device *dev = &cfg->dev->dev; in cxlflash_mmap_fault()
1115 ctxid = cfg->ops->process_element(ctx); in cxlflash_mmap_fault()
1130 if (likely(!ctxi->err_recovery_active)) { in cxlflash_mmap_fault()
1131 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); in cxlflash_mmap_fault()
1132 rc = ctxi->cxl_mmap_vmops->fault(vmf); in cxlflash_mmap_fault()
1145 vmf->page = err_page; in cxlflash_mmap_fault()
1146 vma->vm_page_prot = pgprot_cached(vma->vm_page_prot); in cxlflash_mmap_fault()
1168 * cxlflash_cxl_mmap() - mmap handler for adapter file descriptor
1174 * Return: 0 on success, -errno on failure
1178 struct cxlflash_cfg *cfg = container_of(file->f_op, struct cxlflash_cfg, in cxlflash_cxl_mmap()
1180 void *ctx = cfg->ops->fops_get_context(file); in cxlflash_cxl_mmap()
1181 struct device *dev = &cfg->dev->dev; in cxlflash_cxl_mmap()
1187 ctxid = cfg->ops->process_element(ctx); in cxlflash_cxl_mmap()
1191 rc = -EIO; in cxlflash_cxl_mmap()
1198 rc = -EIO; in cxlflash_cxl_mmap()
1204 rc = cfg->ops->fd_mmap(file, vma); in cxlflash_cxl_mmap()
1207 ctxi->cxl_mmap_vmops = vma->vm_ops; in cxlflash_cxl_mmap()
1208 vma->vm_ops = &cxlflash_mmap_vmops; in cxlflash_cxl_mmap()
1224 * cxlflash_mark_contexts_error() - move contexts to error state and list
1227 * A context is only moved over to the error list when there are no outstanding
1230 * Return: 0 on success, -errno on failure
1237 mutex_lock(&cfg->ctx_tbl_list_mutex); in cxlflash_mark_contexts_error()
1240 ctxi = cfg->ctx_tbl[i]; in cxlflash_mark_contexts_error()
1242 mutex_lock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1243 cfg->ctx_tbl[i] = NULL; 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()
1248 mutex_unlock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1252 mutex_unlock(&cfg->ctx_tbl_list_mutex); in cxlflash_mark_contexts_error()
1264 * check_state() - checks and responds to the current adapter state
1274 * Return: 0 on success, -errno on failure
1278 struct device *dev = &cfg->dev->dev; in check_state()
1282 switch (cfg->state) { in check_state()
1285 up_read(&cfg->ioctl_rwsem); in check_state()
1286 rc = wait_event_interruptible(cfg->reset_waitq, in check_state()
1287 cfg->state != STATE_RESET); in check_state()
1288 down_read(&cfg->ioctl_rwsem); in check_state()
1294 rc = -ENODEV; in check_state()
1304 * cxlflash_disk_attach() - attach a LUN to a context
1313 * Return: 0 on success, -errno on failure
1318 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in cxlflash_disk_attach()
1319 struct device *dev = &cfg->dev->dev; in cxlflash_disk_attach()
1320 struct afu *afu = cfg->afu; in cxlflash_disk_attach()
1321 struct llun_info *lli = sdev->hostdata; in cxlflash_disk_attach()
1322 struct glun_info *gli = lli->parent; in cxlflash_disk_attach()
1327 int ctxid = -1; in cxlflash_disk_attach()
1328 u64 irqs = attach->num_interrupts; in cxlflash_disk_attach()
1335 int fd = -1; in cxlflash_disk_attach()
1340 rc = -EINVAL; in cxlflash_disk_attach()
1344 if (gli->max_lba == 0) { in cxlflash_disk_attach()
1345 dev_dbg(dev, "%s: No capacity info for LUN=%016llx\n", in cxlflash_disk_attach()
1346 __func__, lli->lun_id[sdev->channel]); in cxlflash_disk_attach()
1351 rc = -ENODEV; in cxlflash_disk_attach()
1354 dev_dbg(dev, "%s: LBA = %016llx\n", __func__, gli->max_lba); in cxlflash_disk_attach()
1355 dev_dbg(dev, "%s: BLK_LEN = %08x\n", __func__, gli->blk_len); in cxlflash_disk_attach()
1358 if (attach->hdr.flags & DK_CXLFLASH_ATTACH_REUSE_CONTEXT) { in cxlflash_disk_attach()
1359 rctxid = attach->context_id; in cxlflash_disk_attach()
1364 rc = -EINVAL; in cxlflash_disk_attach()
1368 list_for_each_entry(lun_access, &ctxi->luns, list) in cxlflash_disk_attach()
1369 if (lun_access->lli == lli) { in cxlflash_disk_attach()
1372 rc = -EINVAL; in cxlflash_disk_attach()
1386 rc = -ENOMEM; in cxlflash_disk_attach()
1390 lun_access->lli = lli; in cxlflash_disk_attach()
1391 lun_access->sdev = sdev; in cxlflash_disk_attach()
1393 /* Non-NULL context indicates reuse (another context reference) */ 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()
1406 rc = -ENOMEM; in cxlflash_disk_attach()
1410 ctx = cfg->ops->dev_context_init(cfg->dev, cfg->afu_cookie); in cxlflash_disk_attach()
1414 rc = -ENODEV; in cxlflash_disk_attach()
1418 rc = cfg->ops->start_work(ctx, irqs); in cxlflash_disk_attach()
1425 ctxid = cfg->ops->process_element(ctx); in cxlflash_disk_attach()
1428 rc = -EPERM; in cxlflash_disk_attach()
1432 file = cfg->ops->get_fd(ctx, &cfg->cxl_fops, &fd); in cxlflash_disk_attach()
1434 rc = -ENODEV; in cxlflash_disk_attach()
1440 perms = SISL_RHT_PERM(attach->hdr.flags + 1); in cxlflash_disk_attach()
1452 * No error paths after this point. Once the fd is installed it's in cxlflash_disk_attach()
1454 * There is no need to worry about a deadlock here because no one in cxlflash_disk_attach()
1457 list_add(&lun_access->list, &ctxi->luns); in cxlflash_disk_attach()
1458 mutex_lock(&cfg->ctx_tbl_list_mutex); in cxlflash_disk_attach()
1459 mutex_lock(&ctxi->mutex); in cxlflash_disk_attach()
1460 cfg->ctx_tbl[ctxid] = ctxi; in cxlflash_disk_attach()
1461 mutex_unlock(&cfg->ctx_tbl_list_mutex); in cxlflash_disk_attach()
1465 if (fd != -1) in cxlflash_disk_attach()
1470 attach->hdr.return_flags = flags; in cxlflash_disk_attach()
1471 attach->context_id = ctxi->ctxid; in cxlflash_disk_attach()
1472 attach->block_size = gli->blk_len; in cxlflash_disk_attach()
1473 attach->mmio_size = sizeof(afu->afu_map->hosts[0].harea); in cxlflash_disk_attach()
1474 attach->last_lba = gli->max_lba; in cxlflash_disk_attach()
1475 attach->max_xfer = sdev->host->max_sectors * MAX_SECTOR_UNIT; in cxlflash_disk_attach()
1476 attach->max_xfer /= gli->blk_len; in cxlflash_disk_attach()
1479 attach->adap_fd = fd; in cxlflash_disk_attach()
1485 __func__, ctxid, fd, attach->block_size, rc, attach->last_lba); in cxlflash_disk_attach()
1491 cfg->ops->stop_context(ctx); in cxlflash_disk_attach()
1492 cfg->ops->release_context(ctx); in cxlflash_disk_attach()
1497 * Here, we're overriding the fops with a dummy all-NULL fops because in cxlflash_disk_attach()
1504 file->f_op = &null_fops; in cxlflash_disk_attach()
1507 fd = -1; in cxlflash_disk_attach()
1523 * recover_context() - recovers a context in error
1528 * Restablishes the state for a context-in-error.
1530 * Return: 0 on success, -errno on failure
1536 struct device *dev = &cfg->dev->dev; in recover_context()
1538 int fd = -1; in recover_context()
1539 int ctxid = -1; in recover_context()
1542 struct afu *afu = cfg->afu; in recover_context()
1544 ctx = cfg->ops->dev_context_init(cfg->dev, cfg->afu_cookie); in recover_context()
1548 rc = -ENODEV; in recover_context()
1552 rc = cfg->ops->start_work(ctx, ctxi->irqs); in recover_context()
1559 ctxid = cfg->ops->process_element(ctx); in recover_context()
1562 rc = -EPERM; in recover_context()
1566 file = cfg->ops->get_fd(ctx, &cfg->cxl_fops, &fd); in recover_context()
1568 rc = -ENODEV; in recover_context()
1574 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl; in recover_context()
1583 * No error paths after this point. Once the fd is installed it's 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()
1593 * order with the table/list mutex to avoid a deadlock - safe to do in recover_context()
1594 * here because no one can find us at this moment in time. in recover_context()
1596 mutex_unlock(&ctxi->mutex); in recover_context()
1597 mutex_lock(&cfg->ctx_tbl_list_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()
1601 mutex_unlock(&cfg->ctx_tbl_list_mutex); in recover_context()
1613 cfg->ops->stop_context(ctx); in recover_context()
1615 cfg->ops->release_context(ctx); in recover_context()
1620 * cxlflash_afu_recover() - initiates AFU recovery
1635 * avoid a 3-way deadlock when multiple process recoveries operate in
1647 * Return: 0 on success, -errno on failure
1652 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in cxlflash_afu_recover()
1653 struct device *dev = &cfg->dev->dev; in cxlflash_afu_recover()
1654 struct llun_info *lli = sdev->hostdata; in cxlflash_afu_recover()
1655 struct afu *afu = cfg->afu; in cxlflash_afu_recover()
1657 struct mutex *mutex = &cfg->ctx_recovery_mutex; in cxlflash_afu_recover()
1660 u64 ctxid = DECODE_CTXID(recover->context_id), in cxlflash_afu_recover()
1661 rctxid = recover->context_id; in cxlflash_afu_recover()
1665 int new_adap_fd = -1; in cxlflash_afu_recover()
1668 atomic_inc(&cfg->recovery_threads); in cxlflash_afu_recover()
1669 up_read(&cfg->ioctl_rwsem); in cxlflash_afu_recover()
1671 down_read(&cfg->ioctl_rwsem); in cxlflash_afu_recover()
1680 rc = -ENODEV; in cxlflash_afu_recover()
1685 __func__, recover->reason, rctxid); in cxlflash_afu_recover()
1692 rc = -EINVAL; in cxlflash_afu_recover()
1696 if (ctxi->err_recovery_active) { in cxlflash_afu_recover()
1702 if ((rc == -ENODEV) && in cxlflash_afu_recover()
1703 ((atomic_read(&cfg->recovery_threads) > 1) || in cxlflash_afu_recover()
1704 (lretry--))) { in cxlflash_afu_recover()
1720 ctxi->err_recovery_active = false; in cxlflash_afu_recover()
1727 recover->hdr.return_flags = flags; in cxlflash_afu_recover()
1728 recover->context_id = ctxi->ctxid; in cxlflash_afu_recover()
1729 recover->adap_fd = new_adap_fd; in cxlflash_afu_recover()
1730 recover->mmio_size = sizeof(afu->afu_map->hosts[0].harea); in cxlflash_afu_recover()
1735 reg = readq_be(&hwq->ctrl_map->mbox_r); in cxlflash_afu_recover()
1736 if (reg == -1) { in cxlflash_afu_recover()
1741 * get_context() as it is no longer needed and sleep for a short in cxlflash_afu_recover()
1753 dev_dbg(dev, "%s: MMIO working, no recovery required\n", __func__); in cxlflash_afu_recover()
1759 atomic_dec_if_positive(&cfg->recovery_threads); in cxlflash_afu_recover()
1764 * process_sense() - evaluates and processes sense data
1768 * Return: 0 on success, -errno on failure
1773 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in process_sense()
1774 struct device *dev = &cfg->dev->dev; in process_sense()
1775 struct llun_info *lli = sdev->hostdata; in process_sense()
1776 struct glun_info *gli = lli->parent; in process_sense()
1777 u64 prev_lba = gli->max_lba; in process_sense()
1781 rc = scsi_normalize_sense((const u8 *)&verify->sense_data, in process_sense()
1785 rc = -EINVAL; in process_sense()
1801 rc = -ENODEV; in process_sense()
1804 if (prev_lba != gli->max_lba) in process_sense()
1807 gli->max_lba); in process_sense()
1810 scsi_scan_host(cfg->host); in process_sense()
1813 rc = -EIO; in process_sense()
1818 rc = -EIO; in process_sense()
1828 * cxlflash_disk_verify() - verifies a LUN is the same and handle size changes
1832 * Return: 0 on success, -errno on failure
1839 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in cxlflash_disk_verify()
1840 struct device *dev = &cfg->dev->dev; in cxlflash_disk_verify()
1841 struct llun_info *lli = sdev->hostdata; in cxlflash_disk_verify()
1842 struct glun_info *gli = lli->parent; in cxlflash_disk_verify()
1844 res_hndl_t rhndl = verify->rsrc_handle; in cxlflash_disk_verify()
1845 u64 ctxid = DECODE_CTXID(verify->context_id), in cxlflash_disk_verify()
1846 rctxid = verify->context_id; in cxlflash_disk_verify()
1850 "flags=%016llx\n", __func__, ctxid, verify->rsrc_handle, in cxlflash_disk_verify()
1851 verify->hint, verify->hdr.flags); in cxlflash_disk_verify()
1856 rc = -EINVAL; in cxlflash_disk_verify()
1864 rc = -EINVAL; in cxlflash_disk_verify()
1872 if (verify->hint & DK_CXLFLASH_VERIFY_HINT_SENSE) { 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()
1890 switch (gli->mode) { in cxlflash_disk_verify()
1892 last_lba = gli->max_lba; in cxlflash_disk_verify()
1896 last_lba = ((u64)rhte->lxt_cnt * MC_CHUNK_SIZE * gli->blk_len); in cxlflash_disk_verify()
1898 last_lba--; in cxlflash_disk_verify()
1904 verify->last_lba = last_lba; in cxlflash_disk_verify()
1910 __func__, rc, verify->last_lba); in cxlflash_disk_verify()
1915 * decode_ioctl() - translates an encoded ioctl to an easily identifiable string
1949 * cxlflash_disk_direct_open() - opens a direct (physical) disk
1954 * to be used to identify the direct lun and the size (in blocks) of
1955 * the direct lun in last LBA format.
1957 * Return: 0 on success, -errno on failure
1961 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in cxlflash_disk_direct_open()
1962 struct device *dev = &cfg->dev->dev; in cxlflash_disk_direct_open()
1963 struct afu *afu = cfg->afu; in cxlflash_disk_direct_open()
1964 struct llun_info *lli = sdev->hostdata; in cxlflash_disk_direct_open()
1965 struct glun_info *gli = lli->parent; in cxlflash_disk_direct_open()
1970 u64 ctxid = DECODE_CTXID(pphys->context_id), in cxlflash_disk_direct_open()
1971 rctxid = pphys->context_id; in cxlflash_disk_direct_open()
1974 u64 rsrc_handle = -1; in cxlflash_disk_direct_open()
1975 u32 port = CHAN2PORTMASK(sdev->channel); in cxlflash_disk_direct_open()
1993 rc = -EINVAL; in cxlflash_disk_direct_open()
2001 rc = -EMFILE; /* too many opens */ 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()
2009 last_lba = gli->max_lba; in cxlflash_disk_direct_open()
2010 pphys->hdr.return_flags = 0; in cxlflash_disk_direct_open()
2011 pphys->last_lba = last_lba; in cxlflash_disk_direct_open()
2012 pphys->rsrc_handle = rsrc_handle; in cxlflash_disk_direct_open()
2037 * ioctl_common() - common IOCTL handler for driver
2045 * Return: 0 on success, -errno on failure
2049 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in ioctl_common()
2050 struct device *dev = &cfg->dev->dev; in ioctl_common()
2051 struct llun_info *lli = sdev->hostdata; in ioctl_common()
2056 rc = -EINVAL; in ioctl_common()
2061 if (unlikely(rc) && (cfg->state == STATE_FAILTERM)) { in ioctl_common()
2077 * cxlflash_ioctl() - IOCTL handler for driver
2090 * Return: 0 on success, -errno on failure
2096 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in cxlflash_ioctl()
2097 struct device *dev = &cfg->dev->dev; in cxlflash_ioctl()
2098 struct afu *afu = cfg->afu; in cxlflash_ioctl()
2105 struct Scsi_Host *shost = sdev->host; in cxlflash_ioctl()
2125 down_read(&cfg->ioctl_rwsem); in cxlflash_ioctl()
2128 if (afu->internal_lun) in cxlflash_ioctl()
2135 __func__, decode_ioctl(cmd), afu->internal_lun); in cxlflash_ioctl()
2136 rc = -EINVAL; in cxlflash_ioctl()
2151 __func__, decode_ioctl(cmd), cmd, shost->host_no, in cxlflash_ioctl()
2152 sdev->channel, sdev->id, sdev->lun); in cxlflash_ioctl()
2161 idx = _IOC_NR(cmd) - _IOC_NR(DK_CXLFLASH_ATTACH); in cxlflash_ioctl()
2170 rc = -EINVAL; in cxlflash_ioctl()
2177 rc = -EFAULT; in cxlflash_ioctl()
2182 if (hdr->version != DK_CXLFLASH_VERSION_0) { in cxlflash_ioctl()
2184 __func__, hdr->version, decode_ioctl(cmd)); in cxlflash_ioctl()
2185 rc = -EINVAL; in cxlflash_ioctl()
2189 if (hdr->rsvd[0] || hdr->rsvd[1] || hdr->rsvd[2] || hdr->return_flags) { in cxlflash_ioctl()
2191 rc = -EINVAL; in cxlflash_ioctl()
2200 rc = -EFAULT; in cxlflash_ioctl()
2206 up_read(&cfg->ioctl_rwsem); in cxlflash_ioctl()
2210 decode_ioctl(cmd), cmd, shost->host_no, in cxlflash_ioctl()
2211 sdev->channel, sdev->id, sdev->lun, rc); in cxlflash_ioctl()
2215 cmd, shost->host_no, sdev->channel, sdev->id, in cxlflash_ioctl()
2216 sdev->lun, rc); in cxlflash_ioctl()