include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / infiniband / hw / ipath / ipath_driver.c
index daad09a..6302626 100644 (file)
@@ -31,6 +31,7 @@
  * SOFTWARE.
  */
 
+#include <linux/sched.h>
 #include <linux/spinlock.h>
 #include <linux/idr.h>
 #include <linux/pci.h>
@@ -38,6 +39,8 @@
 #include <linux/delay.h>
 #include <linux/netdevice.h>
 #include <linux/vmalloc.h>
+#include <linux/bitmap.h>
+#include <linux/slab.h>
 
 #include "ipath_kernel.h"
 #include "ipath_verbs.h"
@@ -470,14 +473,14 @@ static int __devinit ipath_init_one(struct pci_dev *pdev,
                goto bail_disable;
        }
 
-       ret = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
+       ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
        if (ret) {
                /*
                 * if the 64 bit setup fails, try 32 bit.  Some systems
                 * do not setup 64 bit maps on systems with 2GB or less
                 * memory installed.
                 */
-               ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
+               ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
                if (ret) {
                        dev_info(&pdev->dev,
                                "Unable to set DMA mask for unit %u: %d\n",
@@ -486,7 +489,7 @@ static int __devinit ipath_init_one(struct pci_dev *pdev,
                }
                else {
                        ipath_dbg("No 64bit DMA mask, used 32 bit mask\n");
-                       ret = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
+                       ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
                        if (ret)
                                dev_info(&pdev->dev,
                                        "Unable to set DMA consistent mask "
@@ -496,7 +499,7 @@ static int __devinit ipath_init_one(struct pci_dev *pdev,
                }
        }
        else {
-               ret = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
+               ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
                if (ret)
                        dev_info(&pdev->dev,
                                "Unable to set DMA consistent mask "
@@ -661,6 +664,8 @@ bail:
 static void __devexit cleanup_device(struct ipath_devdata *dd)
 {
        int port;
+       struct ipath_portdata **tmp;
+       unsigned long flags;
 
        if (*dd->ipath_statusp & IPATH_STATUS_CHIP_PRESENT) {
                /* can't do anything more with chip; needs re-init */
@@ -742,20 +747,21 @@ static void __devexit cleanup_device(struct ipath_devdata *dd)
 
        /*
         * free any resources still in use (usually just kernel ports)
-        * at unload; we do for portcnt, not cfgports, because cfgports
-        * could have changed while we were loaded.
+        * at unload; we do for portcnt, because that's what we allocate.
+        * We acquire lock to be really paranoid that ipath_pd isn't being
+        * accessed from some interrupt-related code (that should not happen,
+        * but best to be sure).
         */
+       spin_lock_irqsave(&dd->ipath_uctxt_lock, flags);
+       tmp = dd->ipath_pd;
+       dd->ipath_pd = NULL;
+       spin_unlock_irqrestore(&dd->ipath_uctxt_lock, flags);
        for (port = 0; port < dd->ipath_portcnt; port++) {
-               struct ipath_portdata *pd = dd->ipath_pd[port];
-               dd->ipath_pd[port] = NULL;
+               struct ipath_portdata *pd = tmp[port];
+               tmp[port] = NULL; /* debugging paranoia */
                ipath_free_pddata(dd, pd);
        }
-       kfree(dd->ipath_pd);
-       /*
-        * debuggability, in case some cleanup path tries to use it
-        * after this
-        */
-       dd->ipath_pd = NULL;
+       kfree(tmp);
 }
 
 static void __devexit ipath_remove_one(struct pci_dev *pdev)
@@ -1259,7 +1265,7 @@ reloop:
                         */
                        ipath_cdbg(ERRPKT, "Error Pkt, but no eflags! egrbuf"
                                  " %x, len %x hdrq+%x rhf: %Lx\n",
-                                 etail, tlen, l,
+                                 etail, tlen, l, (unsigned long long)
                                  le64_to_cpu(*(__le64 *) rhf_addr));
                        if (ipath_debug & __IPATH_ERRPKTDBG) {
                                u32 j, *d, dw = rsize-2;
@@ -1457,7 +1463,8 @@ static void ipath_reset_availshadow(struct ipath_devdata *dd)
                        0xaaaaaaaaaaaaaaaaULL); /* All BUSY bits in qword */
                if (oldval != dd->ipath_pioavailshadow[i])
                        ipath_dbg("shadow[%d] was %Lx, now %lx\n",
-                               i, oldval, dd->ipath_pioavailshadow[i]);
+                               i, (unsigned long long) oldval,
+                               dd->ipath_pioavailshadow[i]);
        }
        spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
 }
@@ -1692,7 +1699,7 @@ void ipath_chg_pioavailkernel(struct ipath_devdata *dd, unsigned start,
                              unsigned len, int avail)
 {
        unsigned long flags;
-       unsigned end, cnt = 0, next;
+       unsigned end, cnt = 0;
 
        /* There are two bits per send buffer (busy and generation) */
        start *= 2;
@@ -1743,12 +1750,7 @@ void ipath_chg_pioavailkernel(struct ipath_devdata *dd, unsigned start,
 
        if (dd->ipath_pioupd_thresh) {
                end = 2 * (dd->ipath_piobcnt2k + dd->ipath_piobcnt4k);
-               next = find_first_bit(dd->ipath_pioavailkernel, end);
-               while (next < end) {
-                       cnt++;
-                       next = find_next_bit(dd->ipath_pioavailkernel, end,
-                                       next + 1);
-               }
+               cnt = bitmap_weight(dd->ipath_pioavailkernel, end);
        }
        spin_unlock_irqrestore(&ipath_pioavail_lock, flags);
 
@@ -2585,6 +2587,7 @@ int ipath_reset_device(int unit)
 {
        int ret, i;
        struct ipath_devdata *dd = ipath_lookup(unit);
+       unsigned long flags;
 
        if (!dd) {
                ret = -ENODEV;
@@ -2610,18 +2613,21 @@ int ipath_reset_device(int unit)
                goto bail;
        }
 
+       spin_lock_irqsave(&dd->ipath_uctxt_lock, flags);
        if (dd->ipath_pd)
                for (i = 1; i < dd->ipath_cfgports; i++) {
-                       if (dd->ipath_pd[i] && dd->ipath_pd[i]->port_cnt) {
-                               ipath_dbg("unit %u port %d is in use "
-                                         "(PID %u cmd %s), can't reset\n",
-                                         unit, i,
-                                         pid_nr(dd->ipath_pd[i]->port_pid),
-                                         dd->ipath_pd[i]->port_comm);
-                               ret = -EBUSY;
-                               goto bail;
-                       }
+                       if (!dd->ipath_pd[i] || !dd->ipath_pd[i]->port_cnt)
+                               continue;
+                       spin_unlock_irqrestore(&dd->ipath_uctxt_lock, flags);
+                       ipath_dbg("unit %u port %d is in use "
+                                 "(PID %u cmd %s), can't reset\n",
+                                 unit, i,
+                                 pid_nr(dd->ipath_pd[i]->port_pid),
+                                 dd->ipath_pd[i]->port_comm);
+                       ret = -EBUSY;
+                       goto bail;
                }
+       spin_unlock_irqrestore(&dd->ipath_uctxt_lock, flags);
 
        if (dd->ipath_flags & IPATH_HAS_SEND_DMA)
                teardown_sdma(dd);
@@ -2655,9 +2661,12 @@ static int ipath_signal_procs(struct ipath_devdata *dd, int sig)
 {
        int i, sub, any = 0;
        struct pid *pid;
+       unsigned long flags;
 
        if (!dd->ipath_pd)
                return 0;
+
+       spin_lock_irqsave(&dd->ipath_uctxt_lock, flags);
        for (i = 1; i < dd->ipath_cfgports; i++) {
                if (!dd->ipath_pd[i] || !dd->ipath_pd[i]->port_cnt)
                        continue;
@@ -2681,6 +2690,7 @@ static int ipath_signal_procs(struct ipath_devdata *dd, int sig)
                        any++;
                }
        }
+       spin_unlock_irqrestore(&dd->ipath_uctxt_lock, flags);
        return any;
 }
 
@@ -2703,7 +2713,7 @@ static void ipath_hol_signal_up(struct ipath_devdata *dd)
  * to prevent HoL blocking, then start the HoL timer that
  * periodically continues, then stop procs, so they can detect
  * link down if they want, and do something about it.
- * Timer may already be running, so use __mod_timer, not add_timer.
+ * Timer may already be running, so use mod_timer, not add_timer.
  */
 void ipath_hol_down(struct ipath_devdata *dd)
 {
@@ -2712,7 +2722,7 @@ void ipath_hol_down(struct ipath_devdata *dd)
        dd->ipath_hol_next = IPATH_HOL_DOWNCONT;
        dd->ipath_hol_timer.expires = jiffies +
                msecs_to_jiffies(ipath_hol_timeout_ms);
-       __mod_timer(&dd->ipath_hol_timer, dd->ipath_hol_timer.expires);
+       mod_timer(&dd->ipath_hol_timer, dd->ipath_hol_timer.expires);
 }
 
 /*
@@ -2751,7 +2761,7 @@ void ipath_hol_event(unsigned long opaque)
        else {
                dd->ipath_hol_timer.expires = jiffies +
                        msecs_to_jiffies(ipath_hol_timeout_ms);
-               __mod_timer(&dd->ipath_hol_timer,
+               mod_timer(&dd->ipath_hol_timer,
                        dd->ipath_hol_timer.expires);
        }
 }