x86: return the irq_handler from register_irq()
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 7 Oct 2019 19:12:13 +0000 (15:12 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 8 Oct 2019 21:11:11 +0000 (17:11 -0400)
register_irq() is a mess.  This helps a little - at least the caller can
determine the vector assigned.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/riscv/trap.c
kern/arch/x86/trap.c
kern/drivers/dma/ioat/init.c
kern/drivers/net/bnx2x/bnx2x_cmn.c
kern/drivers/net/mlx4/eq.c
kern/drivers/net/r8169.c
kern/include/trap.h

index 0e8a980..d3be282 100644 (file)
@@ -343,7 +343,8 @@ void send_nmi(uint32_t os_coreid)
        printk("%s not implemented\n", __FUNCTION);
 }
 
-int register_irq(int irq, isr_t handler, void *irq_arg, uint32_t tbdf)
+struct irq_handler *register_irq(int irq, isr_t handler, void *irq_arg,
+                                uint32_t tbdf)
 {
        printk("%s not implemented\n", __FUNCTION);
        return -1;
index 7647360..15fbdc8 100644 (file)
@@ -780,7 +780,8 @@ void handle_irq(struct hw_trapframe *hw_tf)
 }
 
 /* The irq field may be ignored based on the type of Bus. */
-int register_irq(int irq, isr_t handler, void *irq_arg, uint32_t tbdf)
+struct irq_handler *register_irq(int irq, isr_t handler, void *irq_arg,
+                                uint32_t tbdf)
 {
        struct irq_handler *irq_h;
        int vector;
@@ -792,7 +793,7 @@ int register_irq(int irq, isr_t handler, void *irq_arg, uint32_t tbdf)
        vector = bus_irq_setup(irq_h);
        if (vector == -1) {
                kfree(irq_h);
-               return -1;
+               return NULL;
        }
        printk("IRQ %d, vector %d (0x%x), type %s\n", irq, vector, vector,
               irq_h->type);
@@ -811,7 +812,7 @@ int register_irq(int irq, isr_t handler, void *irq_arg, uint32_t tbdf)
         * The lapic IRQs need to be unmasked on a per-core basis */
        if (irq_h->unmask && strcmp(irq_h->type, "lapic"))
                irq_h->unmask(irq_h, vector);
-       return 0;
+       return irq_h;
 }
 
 /* These routing functions only allow the routing of an irq to a single core.
index badca85..fda838f 100644 (file)
@@ -412,6 +412,7 @@ int ioat_dma_setup_interrupts(struct ioatdma_device *ioat_dma)
        int i, j, msixcnt;
        int err = -EINVAL;
        uint8_t intrctrl = 0;
+       struct irq_handler *irq_h;
 
 #if 1 // AKAROS
        /* Our IRQ setup needs a lot of work.  Let's just assume MSI-X, since
@@ -435,12 +436,12 @@ int ioat_dma_setup_interrupts(struct ioatdma_device *ioat_dma)
                 * for msi/msix.  Passing 0 for now, since -1 doesn't seem like
                 * a good idea.  This tries to do too much, and you have no
                 * control / insight into what its doing. */
-               err = register_irq(0 /* ignored for msi(x)! */,
-                                  ioat_dma_do_interrupt_msix, ioat_chan,
-                                  pci_to_tbdf(pdev));
+               irq_h = register_irq(0 /* ignored for msi(x)! */,
+                                    ioat_dma_do_interrupt_msix, ioat_chan,
+                                    pci_to_tbdf(pdev));
                /* TODO: this is a mess - we also don't know if we're actually
                 * MSIX or not!  We don't even know our vector... */
-               if (err) {
+               if (!irq_h) {
                        warn("MSIX failed (cnt %d), leaking vectors etc!", i);
                        for (j = 0; j < i; j++) {
                                msix = &ioat_dma->msix_entries[j];
index 835bd61..26cbb0a 100644 (file)
@@ -1747,14 +1747,15 @@ static void bullshit_handler(struct hw_trapframe *hw_tf, void *cnic_turd)
 
 static int bnx2x_req_msix_irqs(struct bnx2x *bp)
 {
-       int i, rc, offset = 0;
+       int i, offset = 0;
+       struct irq_handler *irq_h;
 
        /* no default status block for vf */
        if (IS_PF(bp)) {
-               rc = register_irq(bp->msix_table[offset++].vector,
-                                 bnx2x_msix_sp_int, bp->dev,
-                                 pci_to_tbdf(bp->pdev));
-               if (rc) {
+               irq_h = register_irq(bp->msix_table[offset++].vector,
+                                    bnx2x_msix_sp_int, bp->dev,
+                                    pci_to_tbdf(bp->pdev));
+               if (!irq_h) {
                        BNX2X_ERR("request sp irq failed\n");
                        return -EBUSY;
                }
@@ -1763,9 +1764,9 @@ static int bnx2x_req_msix_irqs(struct bnx2x *bp)
        if (CNIC_SUPPORT(bp)) {
                offset++;
                // AKAROS_PORT
-               rc = register_irq(0, bullshit_handler, 0,
-                                 pci_to_tbdf(bp->pdev));
-               if (rc) {
+               irq_h = register_irq(0, bullshit_handler, 0,
+                                    pci_to_tbdf(bp->pdev));
+               if (!irq_h) {
                        BNX2X_ERR("Fucked up getting a CNIC MSIX vector!");
                        return -EBUSY;
                }
@@ -1776,11 +1777,12 @@ static int bnx2x_req_msix_irqs(struct bnx2x *bp)
                snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
                         bp->dev->name, i);
 
-               rc = register_irq(bp->msix_table[offset].vector,
-                                 bnx2x_msix_fp_int, fp, pci_to_tbdf(bp->pdev));
-               if (rc) {
-                       BNX2X_ERR("request fp #%d irq (%d) failed  rc %d\n", i,
-                             bp->msix_table[offset].vector, rc);
+               irq_h = register_irq(bp->msix_table[offset].vector,
+                                    bnx2x_msix_fp_int, fp,
+                                    pci_to_tbdf(bp->pdev));
+               if (!irq_h) {
+                       BNX2X_ERR("request fp #%d irq (%d) failed\n", i,
+                             bp->msix_table[offset].vector);
                        bnx2x_free_msix_irqs(bp, offset);
                        return -EBUSY;
                }
index 4589b08..3236ed9 100644 (file)
@@ -1159,6 +1159,7 @@ void mlx4_free_eq_table(struct mlx4_dev *dev)
 int mlx4_init_eq_table(struct mlx4_dev *dev)
 {
        struct mlx4_priv *priv = mlx4_priv(dev);
+       struct irq_handler *irq_h;
        int err;
        int i;
 
@@ -1261,12 +1262,12 @@ int mlx4_init_eq_table(struct mlx4_dev *dev)
                                           priv->eq_table.eq + i,
                                           pci_to_tbdf(PCIDEV));
 #else
-                       err = register_irq(priv->eq_table.eq[i].irq,
-                                          mlx4_msi_x_interrupt_akaros,
-                                          priv->eq_table.eq + i,
-                                          pci_to_tbdf(dev->persist->pdev));
+                       irq_h = register_irq(priv->eq_table.eq[i].irq,
+                                            mlx4_msi_x_interrupt_akaros,
+                                            priv->eq_table.eq + i,
+                                            pci_to_tbdf(dev->persist->pdev));
 #endif
-                       if (err)
+                       if (!irq_h)
                                goto err_out_async;
 
                        priv->eq_table.eq[i].have_irq = 1;
index e2372b8..d75ccb8 100644 (file)
@@ -7813,10 +7813,8 @@ static int rtl_open(struct ether *dev)
 
        rtl_request_firmware(tp);
 
-       retval = register_irq(pdev->irqline, rtl8169_interrupt, dev,
-                             pci_to_tbdf(pdev));
-
-       if (retval < 0)
+       if (!register_irq(pdev->irqline, rtl8169_interrupt, dev,
+                         pci_to_tbdf(pdev)))
                goto err_release_fw_2;
 
        rtl_lock_work(tp);
index d8c2683..66d0d1b 100644 (file)
@@ -14,7 +14,8 @@
 typedef void (*isr_t)(struct hw_trapframe *hw_tf, void *data);
 
 void idt_init(void);
-int register_irq(int irq, isr_t handler, void *irq_arg, uint32_t tbdf);
+struct irq_handler *register_irq(int irq, isr_t handler, void *irq_arg,
+                                uint32_t tbdf);
 int route_irqs(int cpu_vec, int coreid);
 void print_trapframe(struct hw_trapframe *hw_tf);
 void print_swtrapframe(struct sw_trapframe *sw_tf);