Merge tag 'spi-fix-v6.5-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi

Pull spi fixes from Mark Brown:
"A bunch of fixes for the Qualcomm QSPI driver, fixing multiple issues
with the newly added DMA mode - it had a number of issues exposed when
tested in a wider range of use cases, both race condition style issues
and issues with different inputs to those that had been used in test"

* tag 'spi-fix-v6.5-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi:
spi: spi-qcom-qspi: Add mem_ops to avoid PIO for badly sized reads
spi: spi-qcom-qspi: Fallback to PIO for xfers that aren't multiples of 4 bytes
spi: spi-qcom-qspi: Add DMA_CHAIN_DONE to ALL_IRQS
spi: spi-qcom-qspi: Call dma_wmb() after setting up descriptors
spi: spi-qcom-qspi: Use GFP_ATOMIC flag while allocating for descriptor
spi: spi-qcom-qspi: Ignore disabled interrupts' status in isr

Changed files
+49 -5
drivers
+49 -5
drivers/spi/spi-qcom-qspi.c
··· 69 69 WR_FIFO_OVERRUN) 70 70 #define QSPI_ALL_IRQS (QSPI_ERR_IRQS | RESP_FIFO_RDY | \ 71 71 WR_FIFO_EMPTY | WR_FIFO_FULL | \ 72 - TRANSACTION_DONE) 72 + TRANSACTION_DONE | DMA_CHAIN_DONE) 73 73 74 74 #define PIO_XFER_CTRL 0x0014 75 75 #define REQUEST_COUNT_MSK 0xffff ··· 308 308 dma_addr_t dma_cmd_desc; 309 309 310 310 /* allocate for dma cmd descriptor */ 311 - virt_cmd_desc = dma_pool_alloc(ctrl->dma_cmd_pool, GFP_KERNEL | __GFP_ZERO, &dma_cmd_desc); 312 - if (!virt_cmd_desc) 313 - return -ENOMEM; 311 + virt_cmd_desc = dma_pool_alloc(ctrl->dma_cmd_pool, GFP_ATOMIC | __GFP_ZERO, &dma_cmd_desc); 312 + if (!virt_cmd_desc) { 313 + dev_warn_once(ctrl->dev, "Couldn't find memory for descriptor\n"); 314 + return -EAGAIN; 315 + } 314 316 315 317 ctrl->virt_cmd_desc[ctrl->n_cmd_desc] = virt_cmd_desc; 316 318 ctrl->dma_cmd_desc[ctrl->n_cmd_desc] = dma_cmd_desc; ··· 357 355 358 356 for (i = 0; i < sgt->nents; i++) { 359 357 dma_ptr_sg = sg_dma_address(sgt->sgl + i); 358 + dma_len_sg = sg_dma_len(sgt->sgl + i); 360 359 if (!IS_ALIGNED(dma_ptr_sg, QSPI_ALIGN_REQ)) { 361 360 dev_warn_once(ctrl->dev, "dma_address not aligned to %d\n", QSPI_ALIGN_REQ); 361 + return -EAGAIN; 362 + } 363 + /* 364 + * When reading with DMA the controller writes to memory 1 word 365 + * at a time. If the length isn't a multiple of 4 bytes then 366 + * the controller can clobber the things later in memory. 367 + * Fallback to PIO to be safe. 368 + */ 369 + if (ctrl->xfer.dir == QSPI_READ && (dma_len_sg & 0x03)) { 370 + dev_warn_once(ctrl->dev, "fallback to PIO for read of size %#010x\n", 371 + dma_len_sg); 362 372 return -EAGAIN; 363 373 } 364 374 } ··· 455 441 456 442 ret = qcom_qspi_setup_dma_desc(ctrl, xfer); 457 443 if (ret != -EAGAIN) { 458 - if (!ret) 444 + if (!ret) { 445 + dma_wmb(); 459 446 qcom_qspi_dma_xfer(ctrl); 447 + } 460 448 goto exit; 461 449 } 462 450 dev_warn_once(ctrl->dev, "DMA failure, falling back to PIO\n"); ··· 619 603 int_status = readl(ctrl->base + MSTR_INT_STATUS); 620 604 writel(int_status, ctrl->base + MSTR_INT_STATUS); 621 605 606 + /* Ignore disabled interrupts */ 607 + int_status &= readl(ctrl->base + MSTR_INT_EN); 608 + 622 609 /* PIO mode handling */ 623 610 if (ctrl->xfer.dir == QSPI_WRITE) { 624 611 if (int_status & WR_FIFO_EMPTY) ··· 665 646 spin_unlock(&ctrl->lock); 666 647 return ret; 667 648 } 649 + 650 + static int qcom_qspi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) 651 + { 652 + /* 653 + * If qcom_qspi_can_dma() is going to return false we don't need to 654 + * adjust anything. 655 + */ 656 + if (op->data.nbytes <= QSPI_MAX_BYTES_FIFO) 657 + return 0; 658 + 659 + /* 660 + * When reading, the transfer needs to be a multiple of 4 bytes so 661 + * shrink the transfer if that's not true. The caller will then do a 662 + * second transfer to finish things up. 663 + */ 664 + if (op->data.dir == SPI_MEM_DATA_IN && (op->data.nbytes & 0x3)) 665 + op->data.nbytes &= ~0x3; 666 + 667 + return 0; 668 + } 669 + 670 + static const struct spi_controller_mem_ops qcom_qspi_mem_ops = { 671 + .adjust_op_size = qcom_qspi_adjust_op_size, 672 + }; 668 673 669 674 static int qcom_qspi_probe(struct platform_device *pdev) 670 675 { ··· 774 731 if (of_property_read_bool(pdev->dev.of_node, "iommus")) 775 732 master->can_dma = qcom_qspi_can_dma; 776 733 master->auto_runtime_pm = true; 734 + master->mem_ops = &qcom_qspi_mem_ops; 777 735 778 736 ret = devm_pm_opp_set_clkname(&pdev->dev, "core"); 779 737 if (ret)