rapidio: move rio_pw_enable into core code
authorAlexandre Bounine <alexandre.bounine@idt.com>
Tue, 22 Mar 2016 21:26:41 +0000 (14:26 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 22 Mar 2016 22:36:02 +0000 (15:36 -0700)
Make rio_pw_enable() routine available to other RapidIO drivers.

Signed-off-by: Alexandre Bounine <alexandre.bounine@idt.com>
Cc: Matt Porter <mporter@kernel.crashing.org>
Cc: Aurelien Jacquiot <a-jacquiot@ti.com>
Cc: Andre van Herk <andre.van.herk@prodrive-technologies.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/rapidio/rio-scan.c
drivers/rapidio/rio.c
include/linux/rio.h
include/linux/rio_drv.h

index f730914f6ff669477f115d31480cc6fc3010e48b..a63a380809d14c7ffaa6be198c0747f9b648193e 100644 (file)
@@ -973,17 +973,6 @@ static void rio_init_em(struct rio_dev *rdev)
        }
 }
 
-/**
- * rio_pw_enable - Enables/disables port-write handling by a master port
- * @port: Master port associated with port-write handling
- * @enable:  1=enable,  0=disable
- */
-static void rio_pw_enable(struct rio_mport *port, int enable)
-{
-       if (port->ops->pwenable)
-               port->ops->pwenable(port, enable);
-}
-
 /**
  * rio_enum_mport- Start enumeration through a master port
  * @mport: Master port to send transactions
index 095801c4d239ac2648474063f6fe3670c8f3f43b..673774bf6dd676b2d7a37b2b6dddf480e5eba2d3 100644 (file)
@@ -559,6 +559,24 @@ int rio_release_inb_pwrite(struct rio_dev *rdev)
 }
 EXPORT_SYMBOL_GPL(rio_release_inb_pwrite);
 
+/**
+ * rio_pw_enable - Enables/disables port-write handling by a master port
+ * @mport: Master port associated with port-write handling
+ * @enable:  1=enable,  0=disable
+ */
+void rio_pw_enable(struct rio_mport *mport, int enable)
+{
+       if (mport->ops->pwenable) {
+               mutex_lock(&mport->lock);
+
+               if ((enable && ++mport->pwe_refcnt == 1) ||
+                   (!enable && mport->pwe_refcnt && --mport->pwe_refcnt == 0))
+                       mport->ops->pwenable(mport, enable);
+               mutex_unlock(&mport->lock);
+       }
+}
+EXPORT_SYMBOL_GPL(rio_pw_enable);
+
 /**
  * rio_map_inb_region -- Map inbound memory region.
  * @mport: Master port.
@@ -2041,6 +2059,7 @@ int rio_mport_initialize(struct rio_mport *mport)
        mport->host_deviceid = rio_get_hdid(mport->id);
        mport->nscan = NULL;
        mutex_init(&mport->lock);
+       mport->pwe_refcnt = 0;
 
        return 0;
 }
index 948f60550ae545b77ebc68275415a324052f9b86..cb3c47543bb09751e2561c49abc0ad12d23ca492 100644 (file)
@@ -266,6 +266,7 @@ enum rio_phy_type {
  * @dma: DMA device associated with mport
  * @nscan: RapidIO network enumeration/discovery operations
  * @state: mport device state
+ * @pwe_refcnt: port-write enable ref counter to track enable/disable requests
  */
 struct rio_mport {
        struct list_head dbells;        /* list of doorbell events */
@@ -296,6 +297,7 @@ struct rio_mport {
 #endif
        struct rio_scan *nscan;
        atomic_t state;
+       unsigned int pwe_refcnt;
 };
 
 static inline int rio_mport_is_running(struct rio_mport *mport)
index 341b3bf7833342ab90aeede86b28cf2f71843368..9fb2bcd0a9876c1d56ba87ab904b46fc61b25135 100644 (file)
@@ -375,6 +375,7 @@ extern int rio_request_inb_pwrite(struct rio_dev *,
                        int (*)(struct rio_dev *, union rio_pw_msg*, int));
 extern int rio_release_inb_pwrite(struct rio_dev *);
 extern int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg);
+extern void rio_pw_enable(struct rio_mport *mport, int enable);
 
 /* LDM support */
 int rio_register_driver(struct rio_driver *);