On 11/12/23 12:37, Jyan Chou [周芷安] wrote: > Hi Adrian, > >>>>> + >>>>> +static irqreturn_t dw_mci_cqe_interrupt(int irq, void *dev_id) { >>>>> + struct dw_mci *host = dev_id; >>>>> + struct mmc_host *mmc = host->slot->mmc; >>>>> + struct cqhci_host *cq_host = NULL; >>>>> + int cmd_error = 0, data_error = 0; >>>>> + >>>>> + if (host->pdata && (host->pdata->caps2 & MMC_CAP2_CQE)) >>>>> + cq_host = mmc->cqe_private; >>>>> + >>>>> + dw_mci_get_int(host); >>>>> + >>>>> + if (host->pdata && (host->pdata->caps2 & MMC_CAP2_CQE)) { >>>>> + if (!mmc->cqe_on && !cq_host->activated) >>>> >>>> Shouldn't really look at internals like mmc->cqe_on or cq_host->activated. >>>> There are the cqhci_host_ops ->enable() and ->disable() callbacks to >>>> keep track of whether cqhci is expecting interrupts. >>> >>> Does this means we need to use cqhci_host_ops ->enable() and >>> ->disable() callbacks instead of mmc->cqe_on && !cq_host->activated? >> Thanks. >> >> Yes. ->enable() is always called before cqhci operation and ->disable() before >> non-cqhci operation, so they can be used to determine if an interrupt is for >> cqhci. > > Thanks for your advice, and I got your point for calling cqhci_host_ops ->enable() > > and ->disable() callbacks, but the reason we used " if (!mmc->cqe_on && !cq_host->activated) " > > is that when sending command like cmd0, 1, 7, 8... in mmc_init_card before mmc_cmdq_enable, > > we need to use interrupt in legacy mode, it is much better to write in this way? > > + events = mci_readw(host, NORMAL_INT_STAT_R); > - if (host->pdata && (host->pdata->caps2 & MMC_CAP2_CQE)) { > - if (!mmc->cqe_on && !cq_host->activated) > + if (mmc->caps2 & MMC_CAP2_CQE) { > + if (!(events & CQE_EVENT)) > dw_mci_clr_signal_int(host); > > Using CQE_EVENT to determine whether Command Queue enable or not. Unless you expect CQ interrupts before cqhci_host_ops ->enable() is called, then you know it is legacy mode.