[PATCH V4 03/15 net-next] qca_spi: Improve SPI IRQ handling

From: Stefan Wahren
Date: Sun Jan 28 2024 - 15:13:09 EST


The functions qcaspi_netdev_open/close are responsible of request &
free of the SPI interrupt, which wasn't the best choice because
allocation problems are discovered not during probe. So let us split
IRQ allocation & enabling, so we can take advantage of a device
managed IRQ.

Signed-off-by: Stefan Wahren <wahrenst@xxxxxxx>
Reviewed-by: Jacob Keller <jacob.e.keller@xxxxxxxxx>
---
drivers/net/ethernet/qualcomm/qca_spi.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/qca_spi.c b/drivers/net/ethernet/qualcomm/qca_spi.c
index fe50c2dd7cc8..3f7e38a11ba0 100644
--- a/drivers/net/ethernet/qualcomm/qca_spi.c
+++ b/drivers/net/ethernet/qualcomm/qca_spi.c
@@ -688,7 +688,6 @@ qcaspi_netdev_open(struct net_device *dev)
{
struct qcaspi *qca = netdev_priv(dev);
struct task_struct *thread;
- int ret = 0;

if (!qca)
return -EINVAL;
@@ -709,14 +708,7 @@ qcaspi_netdev_open(struct net_device *dev)

qca->spi_thread = thread;

- ret = request_irq(qca->spi_dev->irq, qcaspi_intr_handler, 0,
- dev->name, qca);
- if (ret) {
- netdev_err(dev, "%s: unable to get IRQ %d (irqval=%d).\n",
- QCASPI_DRV_NAME, qca->spi_dev->irq, ret);
- kthread_stop(qca->spi_thread);
- return ret;
- }
+ enable_irq(qca->spi_dev->irq);

/* SPI thread takes care of TX queue */

@@ -731,7 +723,7 @@ qcaspi_netdev_close(struct net_device *dev)
netif_stop_queue(dev);

qcaspi_write_register(qca, SPI_REG_INTR_ENABLE, 0, wr_verify);
- free_irq(qca->spi_dev->irq, qca);
+ disable_irq(qca->spi_dev->irq);

if (qca->spi_thread) {
kthread_stop(qca->spi_thread);
@@ -989,6 +981,15 @@ qca_spi_probe(struct spi_device *spi)

spi_set_drvdata(spi, qcaspi_devs);

+ ret = devm_request_irq(&spi->dev, spi->irq, qcaspi_intr_handler,
+ IRQF_NO_AUTOEN, qca->net_dev->name, qca);
+ if (ret) {
+ dev_err(&spi->dev, "Unable to get IRQ %d (irqval=%d).\n",
+ spi->irq, ret);
+ free_netdev(qcaspi_devs);
+ return ret;
+ }
+
ret = of_get_ethdev_address(spi->dev.of_node, qca->net_dev);
if (ret) {
eth_hw_addr_random(qca->net_dev);
--
2.34.1