IB/qib: Correct nfreectxts for multiple HCAs
authorMike Marciniszyn <mike.marciniszyn@qlogic.com>
Thu, 6 Oct 2011 16:33:35 +0000 (09:33 -0700)
committerRoland Dreier <roland@purestorage.com>
Thu, 6 Oct 2011 16:33:35 +0000 (09:33 -0700)
The code that was recently introduced to report the number
of free contexts is flawed for multiple HCAs:

       /* Return the number of free user ports (contexts) available. */
       return scnprintf(buf, PAGE_SIZE, "%u\n", dd->cfgctxts -
                dd->first_user_ctxt - (u32)qib_stats.sps_ctxts);

The qib_stats is global to the module, not per HCA, so the code is broken
for multiple HCAs.

This patch adds a qib_devdata field, freectxts, that reflects the free
contexts for this HCA.

Signed-off-by: Mike Marciniszyn <mike.marciniszyn@qlogic.com>
Reviewed-by: Ram Vepa <ram.vepa@qlogic.com>
Signed-off-by: Roland Dreier <roland@purestorage.com>
drivers/infiniband/hw/qib/qib.h
drivers/infiniband/hw/qib/qib_file_ops.c
drivers/infiniband/hw/qib/qib_init.c
drivers/infiniband/hw/qib/qib_sysfs.c

index c9624ea..ee993e7 100644 (file)
@@ -807,6 +807,10 @@ struct qib_devdata {
         * supports, less gives more pio bufs/ctxt, etc.
         */
        u32 cfgctxts;
         * supports, less gives more pio bufs/ctxt, etc.
         */
        u32 cfgctxts;
+       /*
+        * number of ctxts available for PSM open
+        */
+       u32 freectxts;
 
        /*
         * hint that we should update pioavailshadow before
 
        /*
         * hint that we should update pioavailshadow before
index 2625303..7763366 100644 (file)
@@ -1284,6 +1284,7 @@ static int setup_ctxt(struct qib_pportdata *ppd, int ctxt,
        strlcpy(rcd->comm, current->comm, sizeof(rcd->comm));
        ctxt_fp(fp) = rcd;
        qib_stats.sps_ctxts++;
        strlcpy(rcd->comm, current->comm, sizeof(rcd->comm));
        ctxt_fp(fp) = rcd;
        qib_stats.sps_ctxts++;
+       dd->freectxts++;
        ret = 0;
        goto bail;
 
        ret = 0;
        goto bail;
 
@@ -1792,6 +1793,7 @@ static int qib_close(struct inode *in, struct file *fp)
                if (dd->pageshadow)
                        unlock_expected_tids(rcd);
                qib_stats.sps_ctxts--;
                if (dd->pageshadow)
                        unlock_expected_tids(rcd);
                qib_stats.sps_ctxts--;
+               dd->freectxts--;
        }
 
        mutex_unlock(&qib_mutex);
        }
 
        mutex_unlock(&qib_mutex);
index a01f3fc..021636d 100644 (file)
@@ -398,6 +398,7 @@ static void enable_chip(struct qib_devdata *dd)
                if (rcd)
                        dd->f_rcvctrl(rcd->ppd, rcvmask, i);
        }
                if (rcd)
                        dd->f_rcvctrl(rcd->ppd, rcvmask, i);
        }
+       dd->freectxts = dd->cfgctxts - dd->first_user_ctxt;
 }
 
 static void verify_interrupt(unsigned long opaque)
 }
 
 static void verify_interrupt(unsigned long opaque)
index 14d129d..78fbd56 100644 (file)
@@ -515,8 +515,7 @@ static ssize_t show_nfreectxts(struct device *device,
        struct qib_devdata *dd = dd_from_dev(dev);
 
        /* Return the number of free user ports (contexts) available. */
        struct qib_devdata *dd = dd_from_dev(dev);
 
        /* Return the number of free user ports (contexts) available. */
-       return scnprintf(buf, PAGE_SIZE, "%u\n", dd->cfgctxts -
-               dd->first_user_ctxt - (u32)qib_stats.sps_ctxts);
+       return scnprintf(buf, PAGE_SIZE, "%u\n", dd->freectxts);
 }
 
 static ssize_t show_serial(struct device *device,
 }
 
 static ssize_t show_serial(struct device *device,