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()
350 rc = -ENOMEM; in read_cap16()
362 up_read(&cfg->ioctl_rwsem); in read_cap16()
365 down_read(&cfg->ioctl_rwsem); in read_cap16()
370 rc = -ENODEV; in read_cap16()
405 rc = -EIO; in read_cap16()
411 * note that we don't need to worry about unaligned access in read_cap16()
414 mutex_lock(&gli->mutex); in read_cap16()
415 gli->max_lba = be64_to_cpu(*((__be64 *)&cmd_buf[0])); in read_cap16()
416 gli->blk_len = be32_to_cpu(*((__be32 *)&cmd_buf[8])); in read_cap16()
417 mutex_unlock(&gli->mutex); in read_cap16()
424 __func__, gli->max_lba, gli->blk_len, rc); in read_cap16()
429 * get_rhte() - obtains validated resource handle table entry reference
439 struct cxlflash_cfg *cfg = ctxi->cfg; in get_rhte()
440 struct device *dev = &cfg->dev->dev; 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()
462 if (unlikely(rhte->nmask == 0)) { in get_rhte()
474 * rhte_checkout() - obtains free/empty resource handle table entry
483 struct cxlflash_cfg *cfg = ctxi->cfg; in rhte_checkout()
484 struct device *dev = &cfg->dev->dev; 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()
504 * rhte_checkin() - releases a resource handle table entry
511 u32 rsrc_handle = rhte - ctxi->rht_start; in rhte_checkin()
513 rhte->nmask = 0; in rhte_checkin()
514 rhte->fp = 0; 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()
521 * rht_format1() - populates a RHTE for format 1
531 * Populate the Format 1 RHT entry for direct access (physical in rht_format1()
539 rhte_f1->fp = SISL_RHT_FP(1U, 0); in rht_format1()
542 rhte_f1->lun_id = lun_id; in rht_format1()
553 rhte_f1->dw = dummy.dw; in rht_format1()
559 * cxlflash_lun_attach() - attaches a user to a LUN and manages the LUN's mode
564 * Return: 0 on success, -errno on failure
571 mutex_lock(&gli->mutex); in cxlflash_lun_attach()
573 if (gli->mode == MODE_NONE) in cxlflash_lun_attach()
574 gli->mode = mode; in cxlflash_lun_attach()
575 else if (gli->mode != mode) { in cxlflash_lun_attach()
577 __func__, gli->mode, mode); in cxlflash_lun_attach()
578 rc = -EINVAL; in cxlflash_lun_attach()
582 gli->users++; in cxlflash_lun_attach()
583 WARN_ON(gli->users <= 0); in cxlflash_lun_attach()
585 pr_debug("%s: Returning rc=%d gli->mode=%u gli->users=%u\n", in cxlflash_lun_attach()
586 __func__, rc, gli->mode, gli->users); in cxlflash_lun_attach()
588 mutex_unlock(&gli->mutex); in cxlflash_lun_attach()
593 * cxlflash_lun_detach() - detaches a user from a LUN and resets the LUN's mode
597 * are no longer required (service is safe to call even when block allocation
598 * resources were not present - such as when transitioning from physical mode).
604 mutex_lock(&gli->mutex); in cxlflash_lun_detach()
605 WARN_ON(gli->mode == MODE_NONE); in cxlflash_lun_detach()
606 if (--gli->users == 0) { in cxlflash_lun_detach()
607 gli->mode = MODE_NONE; in cxlflash_lun_detach()
608 cxlflash_ba_terminate(&gli->blka.ba_lun); in cxlflash_lun_detach()
610 pr_debug("%s: gli->users=%u\n", __func__, gli->users); in cxlflash_lun_detach()
611 WARN_ON(gli->users < 0); in cxlflash_lun_detach()
612 mutex_unlock(&gli->mutex); in cxlflash_lun_detach()
616 * _cxlflash_disk_release() - releases the specified resource entry
628 * Return: 0 on success, -errno on failure
634 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in _cxlflash_disk_release()
635 struct device *dev = &cfg->dev->dev; in _cxlflash_disk_release()
636 struct llun_info *lli = sdev->hostdata; in _cxlflash_disk_release()
637 struct glun_info *gli = lli->parent; in _cxlflash_disk_release()
638 struct afu *afu = cfg->afu; in _cxlflash_disk_release()
642 res_hndl_t rhndl = release->rsrc_handle; in _cxlflash_disk_release()
646 u64 ctxid = DECODE_CTXID(release->context_id), in _cxlflash_disk_release()
647 rctxid = release->context_id; in _cxlflash_disk_release()
652 dev_dbg(dev, "%s: ctxid=%llu rhndl=%llu gli->mode=%u gli->users=%u\n", in _cxlflash_disk_release()
653 __func__, ctxid, release->rsrc_handle, gli->mode, gli->users); in _cxlflash_disk_release()
660 rc = -EINVAL; in _cxlflash_disk_release()
671 rc = -EINVAL; in _cxlflash_disk_release()
682 switch (gli->mode) { in _cxlflash_disk_release()
695 * Clear the Format 1 RHT entry for direct access in _cxlflash_disk_release()
701 rhte_f1->valid = 0; in _cxlflash_disk_release()
704 rhte_f1->lun_id = 0; in _cxlflash_disk_release()
707 rhte_f1->dw = 0; in _cxlflash_disk_release()
708 dma_wmb(); /* Make RHT entry bottom-half clearing visible */ in _cxlflash_disk_release()
710 if (!ctxi->err_recovery_active) { in _cxlflash_disk_release()
739 * destroy_context() - releases a context
743 * This routine is safe to be called with a a non-initialized context.
748 * removed [so there is no need to worry about clearing] and context
754 struct afu *afu = cfg->afu; in destroy_context()
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()
775 * create_context() - allocates and initializes a context
782 struct device *dev = &cfg->dev->dev; 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()
817 * init_context() - initializes a previously allocated context
823 * @perms: User-specified permissions.
824 * @irqs: User-specified number of interrupts.
830 struct afu *afu = cfg->afu; in init_context()
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()
848 * remove_context() - context kref release handler
851 * When a context no longer has any references it can safely be removed
852 * from global access and destroyed. Note that it is assumed the thread
853 * relinquishing access to the context holds its mutex.
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()
865 mutex_lock(&cfg->ctx_tbl_list_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()
870 cfg->ctx_tbl[ctxid] = NULL; in remove_context()
871 mutex_unlock(&cfg->ctx_tbl_list_mutex); in remove_context()
872 mutex_unlock(&ctxi->mutex); in remove_context()
879 * _cxlflash_disk_detach() - detaches a LUN from a context
884 * As part of the detach, all per-context resources associated with the LUN
888 * Return: 0 on success, -errno on failure
894 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in _cxlflash_disk_detach()
895 struct device *dev = &cfg->dev->dev; in _cxlflash_disk_detach()
896 struct llun_info *lli = sdev->hostdata; in _cxlflash_disk_detach()
903 u64 ctxid = DECODE_CTXID(detach->context_id), in _cxlflash_disk_detach()
904 rctxid = detach->context_id; in _cxlflash_disk_detach()
913 rc = -EINVAL; in _cxlflash_disk_detach()
921 if (ctxi->rht_out) { in _cxlflash_disk_detach()
924 if (ctxi->rht_lun[i] == lli) { in _cxlflash_disk_detach()
929 /* No need to loop further if we're done */ 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()
937 if (lun_access->lli == lli) { in _cxlflash_disk_detach()
938 list_del(&lun_access->list); in _cxlflash_disk_detach()
948 if (kref_put(&ctxi->kref, remove_context)) in _cxlflash_disk_detach()
965 * cxlflash_cxl_release() - release handler for adapter file descriptor
966 * @inode: File-system inode associated with fd.
992 struct cxlflash_cfg *cfg = container_of(file->f_op, struct cxlflash_cfg, in cxlflash_cxl_release()
994 void *ctx = cfg->ops->fops_get_context(file); in cxlflash_cxl_release()
995 struct device *dev = &cfg->dev->dev; in cxlflash_cxl_release()
1002 ctxid = cfg->ops->process_element(ctx); in cxlflash_cxl_release()
1026 down_read(&cfg->ioctl_rwsem); 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()
1030 up_read(&cfg->ioctl_rwsem); in cxlflash_cxl_release()
1032 cfg->ops->fd_release(inode, file); in cxlflash_cxl_release()
1039 * unmap_context() - clears a previously established mapping
1048 unmap_mapping_range(ctxi->file->f_mapping, 0, 0, 1); in unmap_context()
1052 * get_err_page() - obtains and allocates the error notification page
1060 struct device *dev = &cfg->dev->dev; in get_err_page()
1070 memset(page_address(err_page), -1, PAGE_SIZE); in get_err_page()
1089 * cxlflash_mmap_fault() - mmap fault handler for adapter file descriptor
1099 * indicate cached/not-cached depending on the memory backing the fault.
1105 struct vm_area_struct *vma = vmf->vma; in cxlflash_mmap_fault()
1106 struct file *file = vma->vm_file; in cxlflash_mmap_fault()
1107 struct cxlflash_cfg *cfg = container_of(file->f_op, struct cxlflash_cfg, in cxlflash_mmap_fault()
1109 void *ctx = cfg->ops->fops_get_context(file); in cxlflash_mmap_fault()
1110 struct device *dev = &cfg->dev->dev; in cxlflash_mmap_fault()
1117 ctxid = cfg->ops->process_element(ctx); in cxlflash_mmap_fault()
1132 if (likely(!ctxi->err_recovery_active)) { in cxlflash_mmap_fault()
1133 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); in cxlflash_mmap_fault()
1134 rc = ctxi->cxl_mmap_vmops->fault(vmf); in cxlflash_mmap_fault()
1147 vmf->page = err_page; in cxlflash_mmap_fault()
1148 vma->vm_page_prot = pgprot_cached(vma->vm_page_prot); in cxlflash_mmap_fault()
1170 * cxlflash_cxl_mmap() - mmap handler for adapter file descriptor
1176 * Return: 0 on success, -errno on failure
1180 struct cxlflash_cfg *cfg = container_of(file->f_op, struct cxlflash_cfg, in cxlflash_cxl_mmap()
1182 void *ctx = cfg->ops->fops_get_context(file); in cxlflash_cxl_mmap()
1183 struct device *dev = &cfg->dev->dev; in cxlflash_cxl_mmap()
1189 ctxid = cfg->ops->process_element(ctx); in cxlflash_cxl_mmap()
1193 rc = -EIO; in cxlflash_cxl_mmap()
1200 rc = -EIO; in cxlflash_cxl_mmap()
1206 rc = cfg->ops->fd_mmap(file, vma); in cxlflash_cxl_mmap()
1209 ctxi->cxl_mmap_vmops = vma->vm_ops; in cxlflash_cxl_mmap()
1210 vma->vm_ops = &cxlflash_mmap_vmops; in cxlflash_cxl_mmap()
1226 * cxlflash_mark_contexts_error() - move contexts to error state and list
1229 * A context is only moved over to the error list when there are no outstanding
1232 * Return: 0 on success, -errno on failure
1239 mutex_lock(&cfg->ctx_tbl_list_mutex); in cxlflash_mark_contexts_error()
1242 ctxi = cfg->ctx_tbl[i]; in cxlflash_mark_contexts_error()
1244 mutex_lock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1245 cfg->ctx_tbl[i] = NULL; 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()
1250 mutex_unlock(&ctxi->mutex); in cxlflash_mark_contexts_error()
1254 mutex_unlock(&cfg->ctx_tbl_list_mutex); in cxlflash_mark_contexts_error()
1266 * check_state() - checks and responds to the current adapter state
1276 * Return: 0 on success, -errno on failure
1280 struct device *dev = &cfg->dev->dev; in check_state()
1284 switch (cfg->state) { in check_state()
1287 up_read(&cfg->ioctl_rwsem); in check_state()
1288 rc = wait_event_interruptible(cfg->reset_waitq, in check_state()
1289 cfg->state != STATE_RESET); in check_state()
1290 down_read(&cfg->ioctl_rwsem); in check_state()
1296 rc = -ENODEV; in check_state()
1306 * cxlflash_disk_attach() - attach a LUN to a context
1315 * Return: 0 on success, -errno on failure
1320 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in cxlflash_disk_attach()
1321 struct device *dev = &cfg->dev->dev; in cxlflash_disk_attach()
1322 struct afu *afu = cfg->afu; in cxlflash_disk_attach()
1323 struct llun_info *lli = sdev->hostdata; in cxlflash_disk_attach()
1324 struct glun_info *gli = lli->parent; in cxlflash_disk_attach()
1329 int ctxid = -1; in cxlflash_disk_attach()
1330 u64 irqs = attach->num_interrupts; in cxlflash_disk_attach()
1337 int fd = -1; in cxlflash_disk_attach()
1342 rc = -EINVAL; in cxlflash_disk_attach()
1346 if (gli->max_lba == 0) { in cxlflash_disk_attach()
1347 dev_dbg(dev, "%s: No capacity info for LUN=%016llx\n", in cxlflash_disk_attach()
1348 __func__, lli->lun_id[sdev->channel]); in cxlflash_disk_attach()
1353 rc = -ENODEV; in cxlflash_disk_attach()
1356 dev_dbg(dev, "%s: LBA = %016llx\n", __func__, gli->max_lba); in cxlflash_disk_attach()
1357 dev_dbg(dev, "%s: BLK_LEN = %08x\n", __func__, gli->blk_len); in cxlflash_disk_attach()
1360 if (attach->hdr.flags & DK_CXLFLASH_ATTACH_REUSE_CONTEXT) { in cxlflash_disk_attach()
1361 rctxid = attach->context_id; in cxlflash_disk_attach()
1366 rc = -EINVAL; in cxlflash_disk_attach()
1370 list_for_each_entry(lun_access, &ctxi->luns, list) in cxlflash_disk_attach()
1371 if (lun_access->lli == lli) { in cxlflash_disk_attach()
1374 rc = -EINVAL; in cxlflash_disk_attach()
1388 rc = -ENOMEM; in cxlflash_disk_attach()
1392 lun_access->lli = lli; in cxlflash_disk_attach()
1393 lun_access->sdev = sdev; in cxlflash_disk_attach()
1395 /* Non-NULL context indicates reuse (another context reference) */ 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()
1408 rc = -ENOMEM; in cxlflash_disk_attach()
1412 ctx = cfg->ops->dev_context_init(cfg->dev, cfg->afu_cookie); in cxlflash_disk_attach()
1416 rc = -ENODEV; in cxlflash_disk_attach()
1420 rc = cfg->ops->start_work(ctx, irqs); in cxlflash_disk_attach()
1427 ctxid = cfg->ops->process_element(ctx); in cxlflash_disk_attach()
1430 rc = -EPERM; in cxlflash_disk_attach()
1434 file = cfg->ops->get_fd(ctx, &cfg->cxl_fops, &fd); in cxlflash_disk_attach()
1436 rc = -ENODEV; in cxlflash_disk_attach()
1442 perms = SISL_RHT_PERM(attach->hdr.flags + 1); in cxlflash_disk_attach()
1454 * No error paths after this point. Once the fd is installed it's in cxlflash_disk_attach()
1456 * There is no need to worry about a deadlock here because no one in cxlflash_disk_attach()
1459 list_add(&lun_access->list, &ctxi->luns); in cxlflash_disk_attach()
1460 mutex_lock(&cfg->ctx_tbl_list_mutex); in cxlflash_disk_attach()
1461 mutex_lock(&ctxi->mutex); in cxlflash_disk_attach()
1462 cfg->ctx_tbl[ctxid] = ctxi; in cxlflash_disk_attach()
1463 mutex_unlock(&cfg->ctx_tbl_list_mutex); in cxlflash_disk_attach()
1467 if (fd != -1) in cxlflash_disk_attach()
1472 attach->hdr.return_flags = flags; in cxlflash_disk_attach()
1473 attach->context_id = ctxi->ctxid; in cxlflash_disk_attach()
1474 attach->block_size = gli->blk_len; in cxlflash_disk_attach()
1475 attach->mmio_size = sizeof(afu->afu_map->hosts[0].harea); in cxlflash_disk_attach()
1476 attach->last_lba = gli->max_lba; in cxlflash_disk_attach()
1477 attach->max_xfer = sdev->host->max_sectors * MAX_SECTOR_UNIT; in cxlflash_disk_attach()
1478 attach->max_xfer /= gli->blk_len; in cxlflash_disk_attach()
1481 attach->adap_fd = fd; in cxlflash_disk_attach()
1487 __func__, ctxid, fd, attach->block_size, rc, attach->last_lba); in cxlflash_disk_attach()
1493 cfg->ops->stop_context(ctx); in cxlflash_disk_attach()
1494 cfg->ops->release_context(ctx); in cxlflash_disk_attach()
1499 * Here, we're overriding the fops with a dummy all-NULL fops because in cxlflash_disk_attach()
1506 file->f_op = &null_fops; in cxlflash_disk_attach()
1509 fd = -1; in cxlflash_disk_attach()
1525 * recover_context() - recovers a context in error
1530 * Restablishes the state for a context-in-error.
1532 * Return: 0 on success, -errno on failure
1538 struct device *dev = &cfg->dev->dev; in recover_context()
1540 int fd = -1; in recover_context()
1541 int ctxid = -1; in recover_context()
1544 struct afu *afu = cfg->afu; in recover_context()
1546 ctx = cfg->ops->dev_context_init(cfg->dev, cfg->afu_cookie); in recover_context()
1550 rc = -ENODEV; in recover_context()
1554 rc = cfg->ops->start_work(ctx, ctxi->irqs); in recover_context()
1561 ctxid = cfg->ops->process_element(ctx); in recover_context()
1564 rc = -EPERM; in recover_context()
1568 file = cfg->ops->get_fd(ctx, &cfg->cxl_fops, &fd); in recover_context()
1570 rc = -ENODEV; in recover_context()
1576 ctxi->ctrl_map = &afu->afu_map->ctrls[ctxid].ctrl; in recover_context()
1585 * No error paths after this point. Once the fd is installed it's 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()
1595 * order with the table/list mutex to avoid a deadlock - safe to do in recover_context()
1596 * here because no one can find us at this moment in time. in recover_context()
1598 mutex_unlock(&ctxi->mutex); in recover_context()
1599 mutex_lock(&cfg->ctx_tbl_list_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()
1603 mutex_unlock(&cfg->ctx_tbl_list_mutex); in recover_context()
1615 cfg->ops->stop_context(ctx); in recover_context()
1617 cfg->ops->release_context(ctx); in recover_context()
1622 * cxlflash_afu_recover() - initiates AFU recovery
1637 * avoid a 3-way deadlock when multiple process recoveries operate in
1649 * Return: 0 on success, -errno on failure
1654 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in cxlflash_afu_recover()
1655 struct device *dev = &cfg->dev->dev; in cxlflash_afu_recover()
1656 struct llun_info *lli = sdev->hostdata; in cxlflash_afu_recover()
1657 struct afu *afu = cfg->afu; in cxlflash_afu_recover()
1659 struct mutex *mutex = &cfg->ctx_recovery_mutex; in cxlflash_afu_recover()
1662 u64 ctxid = DECODE_CTXID(recover->context_id), in cxlflash_afu_recover()
1663 rctxid = recover->context_id; in cxlflash_afu_recover()
1667 int new_adap_fd = -1; in cxlflash_afu_recover()
1670 atomic_inc(&cfg->recovery_threads); in cxlflash_afu_recover()
1671 up_read(&cfg->ioctl_rwsem); in cxlflash_afu_recover()
1673 down_read(&cfg->ioctl_rwsem); in cxlflash_afu_recover()
1682 rc = -ENODEV; in cxlflash_afu_recover()
1687 __func__, recover->reason, rctxid); in cxlflash_afu_recover()
1694 rc = -EINVAL; in cxlflash_afu_recover()
1698 if (ctxi->err_recovery_active) { in cxlflash_afu_recover()
1704 if ((rc == -ENODEV) && in cxlflash_afu_recover()
1705 ((atomic_read(&cfg->recovery_threads) > 1) || in cxlflash_afu_recover()
1706 (lretry--))) { in cxlflash_afu_recover()
1722 ctxi->err_recovery_active = false; in cxlflash_afu_recover()
1729 recover->hdr.return_flags = flags; in cxlflash_afu_recover()
1730 recover->context_id = ctxi->ctxid; in cxlflash_afu_recover()
1731 recover->adap_fd = new_adap_fd; in cxlflash_afu_recover()
1732 recover->mmio_size = sizeof(afu->afu_map->hosts[0].harea); in cxlflash_afu_recover()
1737 reg = readq_be(&hwq->ctrl_map->mbox_r); in cxlflash_afu_recover()
1738 if (reg == -1) { in cxlflash_afu_recover()
1743 * get_context() as it is no longer needed and sleep for a short in cxlflash_afu_recover()
1755 dev_dbg(dev, "%s: MMIO working, no recovery required\n", __func__); in cxlflash_afu_recover()
1761 atomic_dec_if_positive(&cfg->recovery_threads); in cxlflash_afu_recover()
1766 * process_sense() - evaluates and processes sense data
1770 * Return: 0 on success, -errno on failure
1775 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in process_sense()
1776 struct device *dev = &cfg->dev->dev; in process_sense()
1777 struct llun_info *lli = sdev->hostdata; in process_sense()
1778 struct glun_info *gli = lli->parent; in process_sense()
1779 u64 prev_lba = gli->max_lba; in process_sense()
1783 rc = scsi_normalize_sense((const u8 *)&verify->sense_data, in process_sense()
1787 rc = -EINVAL; in process_sense()
1803 rc = -ENODEV; in process_sense()
1806 if (prev_lba != gli->max_lba) in process_sense()
1809 gli->max_lba); in process_sense()
1812 scsi_scan_host(cfg->host); in process_sense()
1815 rc = -EIO; in process_sense()
1820 rc = -EIO; in process_sense()
1830 * cxlflash_disk_verify() - verifies a LUN is the same and handle size changes
1834 * Return: 0 on success, -errno on failure
1841 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in cxlflash_disk_verify()
1842 struct device *dev = &cfg->dev->dev; in cxlflash_disk_verify()
1843 struct llun_info *lli = sdev->hostdata; in cxlflash_disk_verify()
1844 struct glun_info *gli = lli->parent; in cxlflash_disk_verify()
1846 res_hndl_t rhndl = verify->rsrc_handle; in cxlflash_disk_verify()
1847 u64 ctxid = DECODE_CTXID(verify->context_id), in cxlflash_disk_verify()
1848 rctxid = verify->context_id; in cxlflash_disk_verify()
1852 "flags=%016llx\n", __func__, ctxid, verify->rsrc_handle, in cxlflash_disk_verify()
1853 verify->hint, verify->hdr.flags); in cxlflash_disk_verify()
1858 rc = -EINVAL; in cxlflash_disk_verify()
1866 rc = -EINVAL; in cxlflash_disk_verify()
1874 if (verify->hint & DK_CXLFLASH_VERIFY_HINT_SENSE) { in cxlflash_disk_verify()
1878 ctxi->unavail = true; in cxlflash_disk_verify()
1879 mutex_unlock(&ctxi->mutex); in cxlflash_disk_verify()
1884 mutex_lock(&ctxi->mutex); in cxlflash_disk_verify()
1885 ctxi->unavail = false; in cxlflash_disk_verify()
1888 mutex_lock(&ctxi->mutex); in cxlflash_disk_verify()
1889 ctxi->unavail = false; in cxlflash_disk_verify()
1892 switch (gli->mode) { in cxlflash_disk_verify()
1894 last_lba = gli->max_lba; in cxlflash_disk_verify()
1898 last_lba = ((u64)rhte->lxt_cnt * MC_CHUNK_SIZE * gli->blk_len); in cxlflash_disk_verify()
1900 last_lba--; in cxlflash_disk_verify()
1906 verify->last_lba = last_lba; in cxlflash_disk_verify()
1912 __func__, rc, verify->last_lba); in cxlflash_disk_verify()
1917 * decode_ioctl() - translates an encoded ioctl to an easily identifiable string
1951 * cxlflash_disk_direct_open() - opens a direct (physical) disk
1956 * to be used to identify the direct lun and the size (in blocks) of
1957 * the direct lun in last LBA format.
1959 * Return: 0 on success, -errno on failure
1963 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in cxlflash_disk_direct_open()
1964 struct device *dev = &cfg->dev->dev; in cxlflash_disk_direct_open()
1965 struct afu *afu = cfg->afu; in cxlflash_disk_direct_open()
1966 struct llun_info *lli = sdev->hostdata; in cxlflash_disk_direct_open()
1967 struct glun_info *gli = lli->parent; in cxlflash_disk_direct_open()
1972 u64 ctxid = DECODE_CTXID(pphys->context_id), in cxlflash_disk_direct_open()
1973 rctxid = pphys->context_id; in cxlflash_disk_direct_open()
1976 u64 rsrc_handle = -1; in cxlflash_disk_direct_open()
1977 u32 port = CHAN2PORTMASK(sdev->channel); in cxlflash_disk_direct_open()
1995 rc = -EINVAL; in cxlflash_disk_direct_open()
2003 rc = -EMFILE; /* too many opens */ in cxlflash_disk_direct_open()
2007 rsrc_handle = (rhte - ctxi->rht_start); in cxlflash_disk_direct_open()
2009 rht_format1(rhte, lli->lun_id[sdev->channel], ctxi->rht_perms, port); in cxlflash_disk_direct_open()
2011 last_lba = gli->max_lba; in cxlflash_disk_direct_open()
2012 pphys->hdr.return_flags = 0; in cxlflash_disk_direct_open()
2013 pphys->last_lba = last_lba; in cxlflash_disk_direct_open()
2014 pphys->rsrc_handle = rsrc_handle; in cxlflash_disk_direct_open()
2039 * ioctl_common() - common IOCTL handler for driver
2047 * Return: 0 on success, -errno on failure
2051 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in ioctl_common()
2052 struct device *dev = &cfg->dev->dev; in ioctl_common()
2053 struct llun_info *lli = sdev->hostdata; in ioctl_common()
2058 rc = -EINVAL; in ioctl_common()
2063 if (unlikely(rc) && (cfg->state == STATE_FAILTERM)) { in ioctl_common()
2079 * cxlflash_ioctl() - IOCTL handler for driver
2092 * Return: 0 on success, -errno on failure
2098 struct cxlflash_cfg *cfg = shost_priv(sdev->host); in cxlflash_ioctl()
2099 struct device *dev = &cfg->dev->dev; in cxlflash_ioctl()
2100 struct afu *afu = cfg->afu; in cxlflash_ioctl()
2107 struct Scsi_Host *shost = sdev->host; in cxlflash_ioctl()
2127 down_read(&cfg->ioctl_rwsem); in cxlflash_ioctl()
2130 if (afu->internal_lun) in cxlflash_ioctl()
2137 __func__, decode_ioctl(cmd), afu->internal_lun); in cxlflash_ioctl()
2138 rc = -EINVAL; in cxlflash_ioctl()
2153 __func__, decode_ioctl(cmd), cmd, shost->host_no, in cxlflash_ioctl()
2154 sdev->channel, sdev->id, sdev->lun); in cxlflash_ioctl()
2163 idx = _IOC_NR(cmd) - _IOC_NR(DK_CXLFLASH_ATTACH); in cxlflash_ioctl()
2172 rc = -EINVAL; in cxlflash_ioctl()
2179 rc = -EFAULT; in cxlflash_ioctl()
2184 if (hdr->version != DK_CXLFLASH_VERSION_0) { in cxlflash_ioctl()
2186 __func__, hdr->version, decode_ioctl(cmd)); in cxlflash_ioctl()
2187 rc = -EINVAL; in cxlflash_ioctl()
2191 if (hdr->rsvd[0] || hdr->rsvd[1] || hdr->rsvd[2] || hdr->return_flags) { in cxlflash_ioctl()
2193 rc = -EINVAL; in cxlflash_ioctl()
2202 rc = -EFAULT; in cxlflash_ioctl()
2208 up_read(&cfg->ioctl_rwsem); in cxlflash_ioctl()
2212 decode_ioctl(cmd), cmd, shost->host_no, in cxlflash_ioctl()
2213 sdev->channel, sdev->id, sdev->lun, rc); in cxlflash_ioctl()
2217 cmd, shost->host_no, sdev->channel, sdev->id, in cxlflash_ioctl()
2218 sdev->lun, rc); in cxlflash_ioctl()