[SPARC64]: Fix several bugs in MSI handling.
authorDavid S. Miller <davem@sunset.davemloft.net>
Fri, 31 Aug 2007 05:27:28 +0000 (22:27 -0700)
committerDavid S. Miller <davem@sunset.davemloft.net>
Fri, 31 Aug 2007 06:06:51 +0000 (23:06 -0700)
1) sun4{u,v}_build_msi() have improper return value handling.

   We should always return negative error codes, instead of
   using the magic value "0" which could in fact be a valid
   MSI number.

2) sun4{u,v}_build_msi() should return -ENOMEM instead of
   calling prom_prom() halt with kzalloc() of the interrupt
   data fails.

3) We 'remembered' the MSI number using a singleton in the
   struct device archdata area, this doesn't work for MSI-X
   which can cause multiple MSIs assosciated with one device.

   Delete that archdata member, and instead store the MSI
   number in the IRQ chip data area.

Signed-off-by: David S. Miller <davem@davemloft.net>
arch/sparc64/kernel/irq.c
arch/sparc64/kernel/pci.c
arch/sparc64/kernel/pci_sun4v.c
include/asm-sparc64/device.h
include/asm-sparc64/irq.h

index 51b8875a13a8e9c76bca90e81086f2ad96439e99..23956096b3bf2f4044628eea93332251afe12adf 100644 (file)
@@ -217,8 +217,27 @@ struct irq_handler_data {
        void            (*pre_handler)(unsigned int, void *, void *);
        void            *pre_handler_arg1;
        void            *pre_handler_arg2;
+
+       u32             msi;
 };
 
+void sparc64_set_msi(unsigned int virt_irq, u32 msi)
+{
+       struct irq_handler_data *data = get_irq_chip_data(virt_irq);
+
+       if (data)
+               data->msi = msi;
+}
+
+u32 sparc64_get_msi(unsigned int virt_irq)
+{
+       struct irq_handler_data *data = get_irq_chip_data(virt_irq);
+
+       if (data)
+               return data->msi;
+       return 0xffffffff;
+}
+
 static inline struct ino_bucket *virt_irq_to_bucket(unsigned int virt_irq)
 {
        unsigned int real_irq = virt_to_real_irq(virt_irq);
@@ -741,7 +760,7 @@ unsigned int sun4v_build_msi(u32 devhandle, unsigned int *virt_irq_p,
                        break;
        }
        if (devino >= msi_end)
-               return 0;
+               return -ENOSPC;
 
        sysino = sun4v_devino_to_sysino(devhandle, devino);
        bucket = &ivector_table[sysino];
@@ -755,8 +774,8 @@ unsigned int sun4v_build_msi(u32 devhandle, unsigned int *virt_irq_p,
 
        data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
        if (unlikely(!data)) {
-               prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
-               prom_halt();
+               virt_irq_free(*virt_irq_p);
+               return -ENOMEM;
        }
        set_irq_chip_data(bucket->virt_irq, data);
 
index 3d93e9203ba2d412ccb6b0e71b5c1432ca9a06d3..139b4cff80191149f89400c4cfb402751cf87c02 100644 (file)
@@ -393,7 +393,6 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
        sd->host_controller = pbm;
        sd->prom_node = node;
        sd->op = of_find_device_by_node(node);
-       sd->msi_num = 0xffffffff;
 
        sd = &sd->op->dev.archdata;
        sd->iommu = pbm->iommu;
index 466f4aa8fc82236549567ba47007fa193cf24857..da724b13e89e45eaf567bdfb380268bbd7fcecf9 100644 (file)
@@ -940,13 +940,13 @@ static int pci_sun4v_setup_msi_irq(unsigned int *virt_irq_p,
        if (msi_num < 0)
                return msi_num;
 
-       devino = sun4v_build_msi(pbm->devhandle, virt_irq_p,
-                                pbm->msiq_first_devino,
-                                (pbm->msiq_first_devino +
-                                 pbm->msiq_num));
-       err = -ENOMEM;
-       if (!devino)
+       err = sun4v_build_msi(pbm->devhandle, virt_irq_p,
+                             pbm->msiq_first_devino,
+                             (pbm->msiq_first_devino +
+                              pbm->msiq_num));
+       if (err < 0)
                goto out_err;
+       devino = err;
 
        msiqid = ((devino - pbm->msiq_first_devino) +
                  pbm->msiq_first);
@@ -971,7 +971,7 @@ static int pci_sun4v_setup_msi_irq(unsigned int *virt_irq_p,
        if (pci_sun4v_msi_setvalid(pbm->devhandle, msi_num, HV_MSIVALID_VALID))
                goto out_err;
 
-       pdev->dev.archdata.msi_num = msi_num;
+       sparc64_set_msi(*virt_irq_p, msi_num);
 
        if (entry->msi_attrib.is_64) {
                msg.address_hi = pbm->msi64_start >> 32;
@@ -993,8 +993,6 @@ static int pci_sun4v_setup_msi_irq(unsigned int *virt_irq_p,
 
 out_err:
        free_msi(pbm, msi_num);
-       sun4v_destroy_msi(*virt_irq_p);
-       *virt_irq_p = 0;
        return err;
 
 }
@@ -1006,7 +1004,7 @@ static void pci_sun4v_teardown_msi_irq(unsigned int virt_irq,
        unsigned long msiqid, err;
        unsigned int msi_num;
 
-       msi_num = pdev->dev.archdata.msi_num;
+       msi_num = sparc64_get_msi(virt_irq);
        err = pci_sun4v_msi_getmsiq(pbm->devhandle, msi_num, &msiqid);
        if (err) {
                printk(KERN_ERR "%s: getmsiq gives error %lu\n",
index d5a4559b95557990fd637f1c5cb3f8e89d0b0734..5111e8717be321e395ea8ebf76c8ff32f02ed9cf 100644 (file)
@@ -16,8 +16,6 @@ struct dev_archdata {
 
        struct device_node      *prom_node;
        struct of_device        *op;
-
-       unsigned int            msi_num;
 };
 
 #endif /* _ASM_SPARC64_DEVICE_H */
index c041e10ae7df9a75367923380c43c19ed93f4c2e..c00ad152771b04f7787310d4b7300c2ce7da8032 100644 (file)
@@ -53,6 +53,9 @@ extern unsigned int sun4v_build_msi(u32 devhandle, unsigned int *virt_irq_p,
 extern void sun4v_destroy_msi(unsigned int virt_irq);
 extern unsigned int sbus_build_irq(void *sbus, unsigned int ino);
 
+extern void sparc64_set_msi(unsigned int virt_irq, u32 msi);
+extern u32 sparc64_get_msi(unsigned int virt_irq);
+
 extern void fixup_irqs(void);
 
 static __inline__ void set_softint(unsigned long bits)