Lines Matching +full:disable +full:- +full:cqe +full:- +full:dcmd
1 // SPDX-License-Identifier: GPL-2.0-only
10 #include <linux/dma-mapping.h>
37 return cq_host->desc_base + (tag * cq_host->slot_sz); in get_desc()
44 return desc + cq_host->task_desc_len; in get_link_desc()
49 return cq_host->trans_desc_dma_base + in get_trans_desc_dma()
50 (cq_host->mmc->max_segs * tag * in get_trans_desc_dma()
51 cq_host->trans_desc_len); in get_trans_desc_dma()
56 return cq_host->trans_desc_base + in get_trans_desc()
57 (cq_host->trans_desc_len * cq_host->mmc->max_segs * tag); in get_trans_desc()
68 memset(link_temp, 0, cq_host->link_desc_len); in setup_trans_desc()
69 if (cq_host->link_desc_len > 8) in setup_trans_desc()
72 if (tag == DCMD_SLOT && (cq_host->mmc->caps2 & MMC_CAP2_CQE_DCMD)) { in setup_trans_desc()
79 if (cq_host->dma64) { in setup_trans_desc()
103 struct mmc_host *mmc = cq_host->mmc; in cqhci_dumpregs()
131 CQHCI_DUMP("SSC2: 0x%08x | DCMD rsp: 0x%08x\n", in cqhci_dumpregs()
141 if (cq_host->ops->dumpregs) in cqhci_dumpregs()
142 cq_host->ops->dumpregs(mmc); in cqhci_dumpregs()
150 * |----------|
151 * |task desc | |->|----------|
152 * |----------| | |trans desc|
153 * |link desc-|->| |----------|
154 * |----------| .
156 * no. of slots max-segs
157 * . |----------|
158 * |----------|
167 if (cq_host->caps & CQHCI_TASK_DESC_SZ_128) { in cqhci_host_alloc_tdl()
170 cq_host->task_desc_len = 16; in cqhci_host_alloc_tdl()
172 cq_host->task_desc_len = 8; in cqhci_host_alloc_tdl()
180 if (cq_host->dma64) { in cqhci_host_alloc_tdl()
181 if (cq_host->quirks & CQHCI_QUIRK_SHORT_TXFR_DESC_SZ) in cqhci_host_alloc_tdl()
182 cq_host->trans_desc_len = 12; in cqhci_host_alloc_tdl()
184 cq_host->trans_desc_len = 16; in cqhci_host_alloc_tdl()
185 cq_host->link_desc_len = 16; in cqhci_host_alloc_tdl()
187 cq_host->trans_desc_len = 8; in cqhci_host_alloc_tdl()
188 cq_host->link_desc_len = 8; in cqhci_host_alloc_tdl()
192 cq_host->slot_sz = cq_host->task_desc_len + cq_host->link_desc_len; in cqhci_host_alloc_tdl()
194 cq_host->desc_size = cq_host->slot_sz * cq_host->num_slots; in cqhci_host_alloc_tdl()
196 cq_host->data_size = cq_host->trans_desc_len * cq_host->mmc->max_segs * in cqhci_host_alloc_tdl()
197 cq_host->mmc->cqe_qdepth; in cqhci_host_alloc_tdl()
199 pr_debug("%s: cqhci: desc_size: %zu data_sz: %zu slot-sz: %d\n", in cqhci_host_alloc_tdl()
200 mmc_hostname(cq_host->mmc), cq_host->desc_size, cq_host->data_size, in cqhci_host_alloc_tdl()
201 cq_host->slot_sz); in cqhci_host_alloc_tdl()
204 * allocate a dma-mapped chunk of memory for the descriptors in cqhci_host_alloc_tdl()
205 * allocate a dma-mapped chunk of memory for link descriptors in cqhci_host_alloc_tdl()
206 * setup each link-desc memory offset per slot-number to in cqhci_host_alloc_tdl()
209 cq_host->desc_base = dmam_alloc_coherent(mmc_dev(cq_host->mmc), in cqhci_host_alloc_tdl()
210 cq_host->desc_size, in cqhci_host_alloc_tdl()
211 &cq_host->desc_dma_base, in cqhci_host_alloc_tdl()
213 if (!cq_host->desc_base) in cqhci_host_alloc_tdl()
214 return -ENOMEM; in cqhci_host_alloc_tdl()
216 cq_host->trans_desc_base = dmam_alloc_coherent(mmc_dev(cq_host->mmc), in cqhci_host_alloc_tdl()
217 cq_host->data_size, in cqhci_host_alloc_tdl()
218 &cq_host->trans_desc_dma_base, in cqhci_host_alloc_tdl()
220 if (!cq_host->trans_desc_base) { in cqhci_host_alloc_tdl()
221 dmam_free_coherent(mmc_dev(cq_host->mmc), cq_host->desc_size, in cqhci_host_alloc_tdl()
222 cq_host->desc_base, in cqhci_host_alloc_tdl()
223 cq_host->desc_dma_base); in cqhci_host_alloc_tdl()
224 cq_host->desc_base = NULL; in cqhci_host_alloc_tdl()
225 cq_host->desc_dma_base = 0; in cqhci_host_alloc_tdl()
226 return -ENOMEM; in cqhci_host_alloc_tdl()
229 pr_debug("%s: cqhci: desc-base: 0x%p trans-base: 0x%p\n desc_dma 0x%llx trans_dma: 0x%llx\n", in cqhci_host_alloc_tdl()
230 mmc_hostname(cq_host->mmc), cq_host->desc_base, cq_host->trans_desc_base, in cqhci_host_alloc_tdl()
231 (unsigned long long)cq_host->desc_dma_base, in cqhci_host_alloc_tdl()
232 (unsigned long long)cq_host->trans_desc_dma_base); in cqhci_host_alloc_tdl()
234 for (; i < (cq_host->num_slots); i++) in cqhci_host_alloc_tdl()
242 struct mmc_host *mmc = cq_host->mmc; in __cqhci_enable()
255 if (mmc->caps2 & MMC_CAP2_CQE_DCMD) in __cqhci_enable()
258 if (cq_host->caps & CQHCI_TASK_DESC_SZ_128) in __cqhci_enable()
263 cqhci_writel(cq_host, lower_32_bits(cq_host->desc_dma_base), in __cqhci_enable()
265 cqhci_writel(cq_host, upper_32_bits(cq_host->desc_dma_base), in __cqhci_enable()
268 cqhci_writel(cq_host, cq_host->rca, CQHCI_SSC2); in __cqhci_enable()
276 mmc->cqe_on = true; in __cqhci_enable()
278 if (cq_host->ops->enable) in __cqhci_enable()
279 cq_host->ops->enable(mmc); in __cqhci_enable()
286 cq_host->activated = true; in __cqhci_enable()
297 cq_host->mmc->cqe_on = false; in __cqhci_disable()
299 cq_host->activated = false; in __cqhci_disable()
304 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_deactivate()
306 if (cq_host->enabled && cq_host->activated) in cqhci_deactivate()
315 /* Re-enable is done upon first request */ in cqhci_resume()
322 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_enable()
325 if (!card->ext_csd.cmdq_en) in cqhci_enable()
326 return -EINVAL; in cqhci_enable()
328 if (cq_host->enabled) in cqhci_enable()
331 cq_host->rca = card->rca; in cqhci_enable()
335 pr_err("%s: Failed to enable CQE, error %d\n", in cqhci_enable()
342 cq_host->enabled = true; in cqhci_enable()
360 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_off()
364 if (!cq_host->enabled || !mmc->cqe_on || cq_host->recovery_halt) in cqhci_off()
367 if (cq_host->ops->disable) in cqhci_off()
368 cq_host->ops->disable(mmc, false); in cqhci_off()
375 pr_err("%s: cqhci: CQE stuck on\n", mmc_hostname(mmc)); in cqhci_off()
377 pr_debug("%s: cqhci: CQE off\n", mmc_hostname(mmc)); in cqhci_off()
379 if (cq_host->ops->post_disable) in cqhci_off()
380 cq_host->ops->post_disable(mmc); in cqhci_off()
382 mmc->cqe_on = false; in cqhci_off()
387 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_disable()
389 if (!cq_host->enabled) in cqhci_disable()
396 dmam_free_coherent(mmc_dev(mmc), cq_host->data_size, in cqhci_disable()
397 cq_host->trans_desc_base, in cqhci_disable()
398 cq_host->trans_desc_dma_base); in cqhci_disable()
400 dmam_free_coherent(mmc_dev(mmc), cq_host->desc_size, in cqhci_disable()
401 cq_host->desc_base, in cqhci_disable()
402 cq_host->desc_dma_base); in cqhci_disable()
404 cq_host->trans_desc_base = NULL; in cqhci_disable()
405 cq_host->desc_base = NULL; in cqhci_disable()
407 cq_host->enabled = false; in cqhci_disable()
413 u32 req_flags = mrq->data->flags; in cqhci_prep_task_desc()
425 CQHCI_BLK_COUNT(mrq->data->blocks) | in cqhci_prep_task_desc()
426 CQHCI_BLK_ADDR((u64)mrq->data->blk_addr); in cqhci_prep_task_desc()
429 mmc_hostname(mrq->host), mrq->tag, (unsigned long long)*data); in cqhci_prep_task_desc()
435 struct mmc_data *data = mrq->data; in cqhci_dma_map()
438 return -EINVAL; in cqhci_dma_map()
440 sg_count = dma_map_sg(mmc_dev(host), data->sg, in cqhci_dma_map()
441 data->sg_len, in cqhci_dma_map()
442 (data->flags & MMC_DATA_WRITE) ? in cqhci_dma_map()
445 pr_err("%s: sg-len: %d\n", __func__, data->sg_len); in cqhci_dma_map()
446 return -ENOMEM; in cqhci_dma_map()
477 struct mmc_data *data = mrq->data; in cqhci_prep_tran_desc()
480 bool dma64 = cq_host->dma64; in cqhci_prep_tran_desc()
485 sg_count = cqhci_dma_map(mrq->host, mrq); in cqhci_prep_tran_desc()
488 mmc_hostname(mrq->host), __func__, sg_count); in cqhci_prep_tran_desc()
494 for_each_sg(data->sg, sg, sg_count, i) { in cqhci_prep_tran_desc()
501 desc += cq_host->trans_desc_len; in cqhci_prep_tran_desc()
515 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_prep_dcmd_desc()
518 if (!(mrq->cmd->flags & MMC_RSP_PRESENT)) { in cqhci_prep_dcmd_desc()
522 if (mrq->cmd->flags & MMC_RSP_R1B) { in cqhci_prep_dcmd_desc()
531 task_desc = (__le64 __force *)get_desc(cq_host, cq_host->dcmd_slot); in cqhci_prep_dcmd_desc()
532 memset(task_desc, 0, cq_host->task_desc_len); in cqhci_prep_dcmd_desc()
538 CQHCI_CMD_INDEX(mrq->cmd->opcode) | in cqhci_prep_dcmd_desc()
540 if (cq_host->ops->update_dcmd_desc) in cqhci_prep_dcmd_desc()
541 cq_host->ops->update_dcmd_desc(mmc, mrq, &data); in cqhci_prep_dcmd_desc()
544 pr_debug("%s: cqhci: dcmd: cmd: %d timing: %d resp: %d\n", in cqhci_prep_dcmd_desc()
545 mmc_hostname(mmc), mrq->cmd->opcode, timing, resp_type); in cqhci_prep_dcmd_desc()
547 dataddr[0] = cpu_to_le64((u64)mrq->cmd->arg); in cqhci_prep_dcmd_desc()
553 struct mmc_data *data = mrq->data; in cqhci_post_req()
556 dma_unmap_sg(mmc_dev(host), data->sg, data->sg_len, in cqhci_post_req()
557 (data->flags & MMC_DATA_READ) ? in cqhci_post_req()
564 return mrq->cmd ? DCMD_SLOT : mrq->tag; in cqhci_tag()
573 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_request()
576 if (!cq_host->enabled) { in cqhci_request()
578 return -EINVAL; in cqhci_request()
581 /* First request after resume has to re-enable */ in cqhci_request()
582 if (!cq_host->activated) in cqhci_request()
585 if (!mmc->cqe_on) { in cqhci_request()
586 if (cq_host->ops->pre_enable) in cqhci_request()
587 cq_host->ops->pre_enable(mmc); in cqhci_request()
590 mmc->cqe_on = true; in cqhci_request()
591 pr_debug("%s: cqhci: CQE on\n", mmc_hostname(mmc)); in cqhci_request()
593 pr_err("%s: cqhci: CQE failed to exit halt state\n", in cqhci_request()
596 if (cq_host->ops->enable) in cqhci_request()
597 cq_host->ops->enable(mmc); in cqhci_request()
600 if (mrq->data) { in cqhci_request()
614 spin_lock_irqsave(&cq_host->lock, flags); in cqhci_request()
616 if (cq_host->recovery_halt) { in cqhci_request()
617 err = -EBUSY; in cqhci_request()
621 cq_host->slot[tag].mrq = mrq; in cqhci_request()
622 cq_host->slot[tag].flags = 0; in cqhci_request()
624 cq_host->qcnt += 1; in cqhci_request()
632 spin_unlock_irqrestore(&cq_host->lock, flags); in cqhci_request()
643 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_recovery_needed()
645 if (!cq_host->recovery_halt) { in cqhci_recovery_needed()
646 cq_host->recovery_halt = true; in cqhci_recovery_needed()
648 wake_up(&cq_host->wait_queue); in cqhci_recovery_needed()
649 if (notify && mrq->recovery_notifier) in cqhci_recovery_needed()
650 mrq->recovery_notifier(mrq); in cqhci_recovery_needed()
659 case -EILSEQ: in cqhci_error_flags()
661 case -ETIMEDOUT: in cqhci_error_flags()
671 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_error_irq()
676 spin_lock(&cq_host->lock); in cqhci_error_irq()
684 if (cq_host->recovery_halt) in cqhci_error_irq()
687 if (!cq_host->qcnt) { in cqhci_error_irq()
696 slot = &cq_host->slot[tag]; in cqhci_error_irq()
697 if (slot->mrq) { in cqhci_error_irq()
698 slot->flags = cqhci_error_flags(cmd_error, data_error); in cqhci_error_irq()
699 cqhci_recovery_needed(mmc, slot->mrq, true); in cqhci_error_irq()
705 slot = &cq_host->slot[tag]; in cqhci_error_irq()
706 if (slot->mrq) { in cqhci_error_irq()
707 slot->flags = cqhci_error_flags(data_error, cmd_error); in cqhci_error_irq()
708 cqhci_recovery_needed(mmc, slot->mrq, true); in cqhci_error_irq()
712 if (!cq_host->recovery_halt) { in cqhci_error_irq()
718 slot = &cq_host->slot[tag]; in cqhci_error_irq()
719 if (!slot->mrq) in cqhci_error_irq()
721 slot->flags = cqhci_error_flags(data_error, cmd_error); in cqhci_error_irq()
722 cqhci_recovery_needed(mmc, slot->mrq, true); in cqhci_error_irq()
728 spin_unlock(&cq_host->lock); in cqhci_error_irq()
733 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_finish_mrq()
734 struct cqhci_slot *slot = &cq_host->slot[tag]; in cqhci_finish_mrq()
735 struct mmc_request *mrq = slot->mrq; in cqhci_finish_mrq()
745 if (cq_host->recovery_halt) { in cqhci_finish_mrq()
746 slot->flags |= CQHCI_COMPLETED; in cqhci_finish_mrq()
750 slot->mrq = NULL; in cqhci_finish_mrq()
752 cq_host->qcnt -= 1; in cqhci_finish_mrq()
754 data = mrq->data; in cqhci_finish_mrq()
756 if (data->error) in cqhci_finish_mrq()
757 data->bytes_xfered = 0; in cqhci_finish_mrq()
759 data->bytes_xfered = data->blksz * data->blocks; in cqhci_finish_mrq()
770 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_irq()
787 spin_lock(&cq_host->lock); in cqhci_irq()
789 for_each_set_bit(tag, &comp_status, cq_host->num_slots) { in cqhci_irq()
796 if (cq_host->waiting_for_idle && !cq_host->qcnt) { in cqhci_irq()
797 cq_host->waiting_for_idle = false; in cqhci_irq()
798 wake_up(&cq_host->wait_queue); in cqhci_irq()
801 spin_unlock(&cq_host->lock); in cqhci_irq()
805 wake_up(&cq_host->wait_queue); in cqhci_irq()
808 wake_up(&cq_host->wait_queue); in cqhci_irq()
819 spin_lock_irqsave(&cq_host->lock, flags); in cqhci_is_idle()
820 is_idle = !cq_host->qcnt || cq_host->recovery_halt; in cqhci_is_idle()
821 *ret = cq_host->recovery_halt ? -EBUSY : 0; in cqhci_is_idle()
822 cq_host->waiting_for_idle = !is_idle; in cqhci_is_idle()
823 spin_unlock_irqrestore(&cq_host->lock, flags); in cqhci_is_idle()
830 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_wait_for_idle()
833 wait_event(cq_host->wait_queue, cqhci_is_idle(cq_host, &ret)); in cqhci_wait_for_idle()
841 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_timeout()
843 struct cqhci_slot *slot = &cq_host->slot[tag]; in cqhci_timeout()
847 spin_lock_irqsave(&cq_host->lock, flags); in cqhci_timeout()
848 timed_out = slot->mrq == mrq; in cqhci_timeout()
850 slot->flags |= CQHCI_EXTERNAL_TIMEOUT; in cqhci_timeout()
852 *recovery_needed = cq_host->recovery_halt; in cqhci_timeout()
854 spin_unlock_irqrestore(&cq_host->lock, flags); in cqhci_timeout()
872 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_clear_all_tasks()
882 wait_event_timeout(cq_host->wait_queue, cqhci_tasks_cleared(cq_host), in cqhci_clear_all_tasks()
903 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_halt()
916 wait_event_timeout(cq_host->wait_queue, cqhci_halted(cq_host), in cqhci_halt()
939 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_recovery_start()
943 WARN_ON(!cq_host->recovery_halt); in cqhci_recovery_start()
947 if (cq_host->ops->disable) in cqhci_recovery_start()
948 cq_host->ops->disable(mmc, true); in cqhci_recovery_start()
950 mmc->cqe_on = false; in cqhci_recovery_start()
958 /* CRC errors might indicate re-tuning so prefer to report that */ in cqhci_error_from_flags()
960 return -EILSEQ; in cqhci_error_from_flags()
963 return -ETIMEDOUT; in cqhci_error_from_flags()
965 return -EIO; in cqhci_error_from_flags()
970 struct cqhci_slot *slot = &cq_host->slot[tag]; in cqhci_recover_mrq()
971 struct mmc_request *mrq = slot->mrq; in cqhci_recover_mrq()
977 slot->mrq = NULL; in cqhci_recover_mrq()
979 cq_host->qcnt -= 1; in cqhci_recover_mrq()
981 data = mrq->data; in cqhci_recover_mrq()
983 data->bytes_xfered = 0; in cqhci_recover_mrq()
984 data->error = cqhci_error_from_flags(slot->flags); in cqhci_recover_mrq()
986 mrq->cmd->error = cqhci_error_from_flags(slot->flags); in cqhci_recover_mrq()
989 mmc_cqe_request_done(cq_host->mmc, mrq); in cqhci_recover_mrq()
996 for (i = 0; i < cq_host->num_slots; i++) in cqhci_recover_mrqs()
1012 struct cqhci_host *cq_host = mmc->cqe_private; in cqhci_recovery_finish()
1019 WARN_ON(!cq_host->recovery_halt); in cqhci_recovery_finish()
1029 * be disabled/re-enabled, but not to disable before clearing tasks. in cqhci_recovery_finish()
1033 pr_debug("%s: cqhci: disable / re-enable\n", mmc_hostname(mmc)); in cqhci_recovery_finish()
1048 WARN_ON(cq_host->qcnt); in cqhci_recovery_finish()
1050 spin_lock_irqsave(&cq_host->lock, flags); in cqhci_recovery_finish()
1051 cq_host->qcnt = 0; in cqhci_recovery_finish()
1052 cq_host->recovery_halt = false; in cqhci_recovery_finish()
1053 mmc->cqe_on = false; in cqhci_recovery_finish()
1054 spin_unlock_irqrestore(&cq_host->lock, flags); in cqhci_recovery_finish()
1056 /* Ensure all writes are done before interrupts are re-enabled */ in cqhci_recovery_finish()
1087 dev_dbg(&pdev->dev, "CMDQ not supported\n"); in cqhci_pltfm_init()
1088 return ERR_PTR(-EINVAL); in cqhci_pltfm_init()
1091 cq_host = devm_kzalloc(&pdev->dev, sizeof(*cq_host), GFP_KERNEL); in cqhci_pltfm_init()
1093 return ERR_PTR(-ENOMEM); in cqhci_pltfm_init()
1094 cq_host->mmio = devm_ioremap(&pdev->dev, in cqhci_pltfm_init()
1095 cqhci_memres->start, in cqhci_pltfm_init()
1097 if (!cq_host->mmio) { in cqhci_pltfm_init()
1098 dev_err(&pdev->dev, "failed to remap cqhci regs\n"); in cqhci_pltfm_init()
1099 return ERR_PTR(-EBUSY); in cqhci_pltfm_init()
1101 dev_dbg(&pdev->dev, "CMDQ ioremap: done\n"); in cqhci_pltfm_init()
1124 cq_host->dma64 = dma64; in cqhci_init()
1125 cq_host->mmc = mmc; in cqhci_init()
1126 cq_host->mmc->cqe_private = cq_host; in cqhci_init()
1128 cq_host->num_slots = NUM_SLOTS; in cqhci_init()
1129 cq_host->dcmd_slot = DCMD_SLOT; in cqhci_init()
1131 mmc->cqe_ops = &cqhci_cqe_ops; in cqhci_init()
1133 mmc->cqe_qdepth = NUM_SLOTS; in cqhci_init()
1134 if (mmc->caps2 & MMC_CAP2_CQE_DCMD) in cqhci_init()
1135 mmc->cqe_qdepth -= 1; in cqhci_init()
1137 cq_host->slot = devm_kcalloc(mmc_dev(mmc), cq_host->num_slots, in cqhci_init()
1138 sizeof(*cq_host->slot), GFP_KERNEL); in cqhci_init()
1139 if (!cq_host->slot) { in cqhci_init()
1140 err = -ENOMEM; in cqhci_init()
1144 spin_lock_init(&cq_host->lock); in cqhci_init()
1146 init_completion(&cq_host->halt_comp); in cqhci_init()
1147 init_waitqueue_head(&cq_host->wait_queue); in cqhci_init()