[PATCH 2/4] rtl8712: Replace semaphore terminate_cmdthread_sema with completion

2016-05-31 Thread Binoy Jayan
The semaphore 'terminate_cmdthread_sema' is used as completion,
so convert it to a struct completion type.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
 rtl8712: Replace semaphore cmd_queue_sema with completion

 drivers/staging/rtl8712/os_intfs.c| 2 +-
 drivers/staging/rtl8712/rtl8712_cmd.c | 2 +-
 drivers/staging/rtl8712/rtl871x_cmd.c | 2 +-
 drivers/staging/rtl8712/rtl871x_cmd.h | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8712/os_intfs.c 
b/drivers/staging/rtl8712/os_intfs.c
index c07bcd0..cc2d0fd 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -245,7 +245,7 @@ void r8712_stop_drv_threads(struct _adapter *padapter)
/*Below is to terminate r8712_cmd_thread & event_thread...*/
complete(&padapter->cmdpriv.cmd_queue_comp);
if (padapter->cmdThread)
-   _down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+   _wait_completion(&padapter->cmdpriv.terminate_cmdthread_comp);
padapter->cmdpriv.cmd_seq = 1;
 }
 
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c 
b/drivers/staging/rtl8712/rtl8712_cmd.c
index 0432702..d07abc7 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -420,7 +420,7 @@ _next:
break;
r8712_free_cmd_obj(pcmd);
} while (1);
-   up(&pcmdpriv->terminate_cmdthread_sema);
+   complete(&pcmdpriv->terminate_cmdthread_comp);
thread_exit();
 }
 
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c 
b/drivers/staging/rtl8712/rtl871x_cmd.c
index 69e650b..74fd928 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -58,7 +58,7 @@ No irqsave is necessary.
 static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
init_completion(&pcmdpriv->cmd_queue_comp);
-   sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
+   init_completion(&pcmdpriv->terminate_cmdthread_comp);
 
_init_queue(&(pcmdpriv->cmd_queue));
 
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h 
b/drivers/staging/rtl8712/rtl871x_cmd.h
index 1907bc9..ebd2e1d 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -51,7 +51,7 @@ struct cmd_obj {
 
 struct cmd_priv {
struct completion cmd_queue_comp;
-   struct semaphore terminate_cmdthread_sema;
+   struct completion terminate_cmdthread_comp;
struct  __queue cmd_queue;
u8 cmd_seq;
u8 *cmd_buf;/*shall be non-paged, and 4 bytes aligned*/
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/4] *** rtl8712: Replace semaphores with mutex / completions ***

2016-05-31 Thread Binoy Jayan
Hi,

These are a set of patches which removes semaphores from:

drivers/staging/rtl8712

They build correctly (individually and as a whole).
NB: I have not tested this as I do not have the following hardware:

"RealTek RTL8712U (RTL8192SU) Wireless LAN NIC driver"

Thanks,
Binoy

Binoy Jayan (4):
  rtl8712: Replace semaphore cmd_queue_sema with completion
  rtl8712: Replace semaphore terminate_cmdthread_sema with completion
  rtl8712: intf_priv: Replace semaphore lock with completion
  rtl8712: pwrctrl_priv: Replace semaphore lock with mutex

 drivers/staging/rtl8712/os_intfs.c|  4 ++--
 drivers/staging/rtl8712/osdep_intf.h  |  2 +-
 drivers/staging/rtl8712/osdep_service.h   |  7 +++
 drivers/staging/rtl8712/rtl8712_cmd.c | 14 +++---
 drivers/staging/rtl8712/rtl871x_cmd.c |  8 
 drivers/staging/rtl8712/rtl871x_cmd.h |  4 ++--
 drivers/staging/rtl8712/rtl871x_pwrctrl.c | 24 
 drivers/staging/rtl8712/rtl871x_pwrctrl.h |  2 +-
 drivers/staging/rtl8712/usb_ops_linux.c   |  6 +++---
 9 files changed, 39 insertions(+), 32 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/4] rtl8712: intf_priv: Replace semaphore lock with completion

2016-05-31 Thread Binoy Jayan
The semaphore 'lock' in 'intf_priv' is used as completion,
so convert it to a struct completion type.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
rtl8712: Replace semaphore terminate_cmdthread_sema with completion


 drivers/staging/rtl8712/osdep_intf.h| 2 +-
 drivers/staging/rtl8712/usb_ops_linux.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8712/osdep_intf.h 
b/drivers/staging/rtl8712/osdep_intf.h
index aa0ec74..5d37e1f 100644
--- a/drivers/staging/rtl8712/osdep_intf.h
+++ b/drivers/staging/rtl8712/osdep_intf.h
@@ -36,7 +36,7 @@ struct intf_priv {
/* when in USB, IO is through interrupt in/out endpoints */
struct usb_device *udev;
struct urb *piorw_urb;
-   struct semaphore io_retevt;
+   struct completion io_retevt_comp;
 };
 
 int r871x_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
diff --git a/drivers/staging/rtl8712/usb_ops_linux.c 
b/drivers/staging/rtl8712/usb_ops_linux.c
index 454cdf6..b55a126 100644
--- a/drivers/staging/rtl8712/usb_ops_linux.c
+++ b/drivers/staging/rtl8712/usb_ops_linux.c
@@ -50,7 +50,7 @@ uint r8712_usb_init_intf_priv(struct intf_priv *pintfpriv)
pintfpriv->piorw_urb = usb_alloc_urb(0, GFP_ATOMIC);
if (!pintfpriv->piorw_urb)
return _FAIL;
-   sema_init(&(pintfpriv->io_retevt), 0);
+   init_completion(&pintfpriv->io_retevt_comp);
return _SUCCESS;
 }
 
@@ -163,7 +163,7 @@ static void usb_write_mem_complete(struct urb *purb)
else
padapter->bSurpriseRemoved = true;
}
-   up(&pintfpriv->io_retevt);
+   complete(&pintfpriv->io_retevt_comp);
 }
 
 void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 
*wmem)
@@ -187,7 +187,7 @@ void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 
addr, u32 cnt, u8 *wmem)
  wmem, cnt, usb_write_mem_complete,
  pio_queue);
usb_submit_urb(piorw_urb, GFP_ATOMIC);
-   _down_sema(&pintfpriv->io_retevt);
+   _wait_completion(&pintfpriv->io_retevt_comp);
 }
 
 static void r8712_usb_read_port_complete(struct urb *purb)
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/4] rtl8712: pwrctrl_priv: Replace semaphore lock with mutex

2016-05-31 Thread Binoy Jayan
The semaphore 'lock' in 'pwrctrl_priv' is used as a simple mutex,
so it should be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
  rtl8712: intf_priv: Replace semaphore lock with completion

 drivers/staging/rtl8712/rtl8712_cmd.c | 10 +-
 drivers/staging/rtl8712/rtl871x_pwrctrl.c | 22 +++---
 drivers/staging/rtl8712/rtl871x_pwrctrl.h |  2 +-
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c 
b/drivers/staging/rtl8712/rtl8712_cmd.c
index d07abc7..e893d65 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -264,9 +264,9 @@ static struct cmd_obj *cmd_hdl_filter(struct _adapter 
*padapter,
 */
if (padapter->pwrctrlpriv.pwr_mode > PS_MODE_ACTIVE) {
padapter->pwrctrlpriv.pwr_mode = PS_MODE_ACTIVE;
-   _enter_pwrlock(&(padapter->pwrctrlpriv.lock));
+   mutex_lock(&padapter->pwrctrlpriv.mutex_lock);
r8712_set_rpwm(padapter, PS_STATE_S4);
-   up(&(padapter->pwrctrlpriv.lock));
+   mutex_unlock(&padapter->pwrctrlpriv.mutex_lock);
}
pcmd_r = pcmd;
break;
@@ -395,10 +395,10 @@ _next:
}
if (pcmd->cmdcode == GEN_CMD_CODE(_SetPwrMode)) {
if (padapter->pwrctrlpriv.bSleep) {
-   _enter_pwrlock(&(padapter->
-  pwrctrlpriv.lock));
+   mutex_lock(&padapter->
+  pwrctrlpriv.mutex_lock);
r8712_set_rpwm(padapter, PS_STATE_S2);
-   up(&padapter->pwrctrlpriv.lock);
+   
mutex_unlock(&padapter->pwrctrlpriv.mutex_lock);
}
}
r8712_free_cmd_obj(pcmd);
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c 
b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
index 98a5e74..8d7ead6 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
@@ -103,14 +103,14 @@ void r8712_cpwm_int_hdl(struct _adapter *padapter,
if (pwrpriv->cpwm_tog == ((preportpwrstate->state) & 0x80))
return;
del_timer(&padapter->pwrctrlpriv.rpwm_check_timer);
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
pwrpriv->cpwm = (preportpwrstate->state) & 0xf;
if (pwrpriv->cpwm >= PS_STATE_S2) {
if (pwrpriv->alives & CMD_ALIVE)
complete(&(pcmdpriv->cmd_queue_comp));
}
pwrpriv->cpwm_tog = (preportpwrstate->state) & 0x80;
-   up(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 static inline void register_task_alive(struct pwrctrl_priv *pwrctrl, uint tag)
@@ -141,10 +141,10 @@ static void SetPSModeWorkItemCallback(struct work_struct 
*work)
struct _adapter *padapter = container_of(pwrpriv,
struct _adapter, pwrctrlpriv);
if (!pwrpriv->bSleep) {
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
r8712_set_rpwm(padapter, PS_STATE_S4);
-   up(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
}
 }
 
@@ -155,11 +155,11 @@ static void rpwm_workitem_callback(struct work_struct 
*work)
struct _adapter *padapter = container_of(pwrpriv,
struct _adapter, pwrctrlpriv);
if (pwrpriv->cpwm != pwrpriv->rpwm) {
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
r8712_read8(padapter, SDIO_HCPWM);
pwrpriv->rpwm_retry = 1;
r8712_set_rpwm(padapter, pwrpriv->rpwm);
-   up(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
}
 }
 
@@ -175,7 +175,7 @@ void r8712_init_pwrctrl_priv(struct _adapter *padapter)
struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
 
memset((unsigned char *)pwrctrlpriv, 0, sizeof(struct pwrctrl_priv));
-   sema_init(&pwrctrlpriv->lock, 1);
+   mutex_init(&pwrctrlpriv->mutex_lock);
pwrctrlpriv->cpwm = PS_STATE_S4;
pwrct

[PATCH 1/4] rtl8712: Replace semaphore cmd_queue_sema with completion

2016-05-31 Thread Binoy Jayan
The semaphore 'cmd_queue_sema' is used as completion,
so convert it to a struct completion type.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/rtl8712/os_intfs.c| 2 +-
 drivers/staging/rtl8712/osdep_service.h   | 7 +++
 drivers/staging/rtl8712/rtl8712_cmd.c | 2 +-
 drivers/staging/rtl8712/rtl871x_cmd.c | 6 +++---
 drivers/staging/rtl8712/rtl871x_cmd.h | 2 +-
 drivers/staging/rtl8712/rtl871x_pwrctrl.c | 2 +-
 6 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8712/os_intfs.c 
b/drivers/staging/rtl8712/os_intfs.c
index ab19112..c07bcd0 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -243,7 +243,7 @@ static u32 start_drv_threads(struct _adapter *padapter)
 void r8712_stop_drv_threads(struct _adapter *padapter)
 {
/*Below is to terminate r8712_cmd_thread & event_thread...*/
-   up(&padapter->cmdpriv.cmd_queue_sema);
+   complete(&padapter->cmdpriv.cmd_queue_comp);
if (padapter->cmdThread)
_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
padapter->cmdpriv.cmd_seq = 1;
diff --git a/drivers/staging/rtl8712/osdep_service.h 
b/drivers/staging/rtl8712/osdep_service.h
index 076d508..dd3b47d 100644
--- a/drivers/staging/rtl8712/osdep_service.h
+++ b/drivers/staging/rtl8712/osdep_service.h
@@ -67,6 +67,13 @@ static inline u32 _down_sema(struct semaphore *sema)
return _SUCCESS;
 }
 
+static inline u32 _wait_completion(struct completion *comp)
+{
+   if (wait_for_completion_interruptible(comp))
+   return _FAIL;
+   return _SUCCESS;
+}
+
 static inline u32 end_of_queue_search(struct list_head *head,
struct list_head *plist)
 {
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c 
b/drivers/staging/rtl8712/rtl8712_cmd.c
index 50f4002..0432702 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -322,7 +322,7 @@ int r8712_cmd_thread(void *context)
 
allow_signal(SIGTERM);
while (1) {
-   if ((_down_sema(&(pcmdpriv->cmd_queue_sema))) == _FAIL)
+   if ((_wait_completion(&(pcmdpriv->cmd_queue_comp))) == _FAIL)
break;
if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
break;
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c 
b/drivers/staging/rtl8712/rtl871x_cmd.c
index 86136cc..69e650b 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -57,7 +57,7 @@ No irqsave is necessary.
 
 static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
-   sema_init(&(pcmdpriv->cmd_queue_sema), 0);
+   init_completion(&pcmdpriv->cmd_queue_comp);
sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
 
_init_queue(&(pcmdpriv->cmd_queue));
@@ -172,7 +172,7 @@ u32 r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct 
cmd_obj *obj)
if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag)
return _FAIL;
res = _enqueue_cmd(&pcmdpriv->cmd_queue, obj);
-   up(&pcmdpriv->cmd_queue_sema);
+   complete(&pcmdpriv->cmd_queue_comp);
return res;
 }
 
@@ -189,7 +189,7 @@ u32 r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct 
cmd_obj *obj)
spin_lock_irqsave(&queue->lock, irqL);
list_add_tail(&obj->list, &queue->queue);
spin_unlock_irqrestore(&queue->lock, irqL);
-   up(&pcmdpriv->cmd_queue_sema);
+   complete(&pcmdpriv->cmd_queue_comp);
return _SUCCESS;
 }
 
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h 
b/drivers/staging/rtl8712/rtl871x_cmd.h
index e4a2a50..1907bc9 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -50,7 +50,7 @@ struct cmd_obj {
 };
 
 struct cmd_priv {
-   struct semaphore cmd_queue_sema;
+   struct completion cmd_queue_comp;
struct semaphore terminate_cmdthread_sema;
struct  __queue cmd_queue;
u8 cmd_seq;
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c 
b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
index bf10d6d..98a5e74 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
@@ -107,7 +107,7 @@ void r8712_cpwm_int_hdl(struct _adapter *padapter,
pwrpriv->cpwm = (preportpwrstate->state) & 0xf;
if (pwrpriv->cpwm >= PS_STATE_S2) {
if (pwrpriv->alives & CMD_ALIVE)
-   up(&(pcmdpriv->cmd_queue_sema));
+   complete(&(pcmdpriv->cmd_queue_comp));
}
pwrpriv->cpwm_tog = (preportpwrstate->state) & 0x80;
up(&pwrpriv->lock);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/5] rtl8192e: Replace semaphore rf_sem with mutex

2016-06-01 Thread Binoy Jayan
The semaphore 'rf_sem' in the rtl8192e is a simple mutex, so it should
be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---

This patch depends on the following patch:
rtl8192e: r8192_priv: Replace semaphore wx_sem with mutex

 drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c | 4 ++--
 drivers/staging/rtl8192e/rtl8192e/rtl_core.c   | 2 +-
 drivers/staging/rtl8192e/rtl8192e/rtl_core.h   | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c 
b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
index 5e3bbe5..14fbcaa 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c
@@ -256,7 +256,7 @@ u32 rtl92e_get_rf_reg(struct net_device *dev, enum 
rf90_radio_path eRFPath,
return 0;
if (priv->rtllib->eRFPowerState != eRfOn && !priv->being_init_adapter)
return  0;
-   down(&priv->rf_sem);
+   mutex_lock(&priv->rf_mutex);
if (priv->Rf_Mode == RF_OP_By_FW) {
Original_Value = _rtl92e_phy_rf_fw_read(dev, eRFPath, RegAddr);
udelay(200);
@@ -265,7 +265,7 @@ u32 rtl92e_get_rf_reg(struct net_device *dev, enum 
rf90_radio_path eRFPath,
}
BitShift =  _rtl92e_calculate_bit_shift(BitMask);
Readback_Value = (Original_Value & BitMask) >> BitShift;
-   up(&priv->rf_sem);
+   mutex_unlock(&priv->rf_mutex);
return Readback_Value;
 }
 
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c 
b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
index 46a5c49..3d1948a 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
@@ -994,7 +994,7 @@ static void _rtl92e_init_priv_lock(struct r8192_priv *priv)
spin_lock_init(&priv->rf_ps_lock);
spin_lock_init(&priv->ps_lock);
mutex_init(&priv->wx_mutex);
-   sema_init(&priv->rf_sem, 1);
+   mutex_init(&priv->rf_mutex);
mutex_init(&priv->mutex);
 }
 
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.h 
b/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
index 369ebf1..6ead460 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
@@ -376,7 +376,7 @@ struct r8192_priv {
struct tasklet_struct   irq_prepare_beacon_tasklet;
 
struct mutexwx_mutex;
-   struct semaphorerf_sem;
+   struct mutexrf_mutex;
struct mutexmutex;
 
struct rt_stats stats;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/5] rtl8192e: r8192_priv: Replace semaphore wx_sem with mutex

2016-06-01 Thread Binoy Jayan
The semaphore 'wx_sem' in the r8192_priv is a simple mutex,
so it should be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---

This patch depends on the following patch:
rtl8192e: rtllib_device: Replace semaphore wx_sem with mutex

 drivers/staging/rtl8192e/rtl8192e/rtl_core.c |  28 
 drivers/staging/rtl8192e/rtl8192e/rtl_core.h |   2 +-
 drivers/staging/rtl8192e/rtl8192e/rtl_wx.c   | 104 +--
 3 files changed, 67 insertions(+), 67 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c 
b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
index 6f7d356..46a5c49 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
@@ -993,7 +993,7 @@ static void _rtl92e_init_priv_lock(struct r8192_priv *priv)
spin_lock_init(&priv->irq_th_lock);
spin_lock_init(&priv->rf_ps_lock);
spin_lock_init(&priv->ps_lock);
-   sema_init(&priv->wx_sem, 1);
+   mutex_init(&priv->wx_mutex);
sema_init(&priv->rf_sem, 1);
mutex_init(&priv->mutex);
 }
@@ -1247,7 +1247,7 @@ static void _rtl92e_if_silent_reset(struct net_device 
*dev)
 
 RESET_START:
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
if (priv->rtllib->state == RTLLIB_LINKED)
rtl92e_leisure_ps_leave(dev);
@@ -1255,7 +1255,7 @@ RESET_START:
if (priv->up) {
netdev_info(dev, "%s():the driver is not up.\n",
__func__);
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
return;
}
priv->up = 0;
@@ -1292,7 +1292,7 @@ RESET_START:
 
rtl92e_dm_backup_state(dev);
 
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
RT_TRACE(COMP_RESET,
 "%s():<==down process is finished\n",
 __func__);
@@ -2179,9 +2179,9 @@ static int _rtl92e_open(struct net_device *dev)
struct r8192_priv *priv = rtllib_priv(dev);
int ret;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
ret = _rtl92e_try_up(dev);
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
return ret;
 
 }
@@ -2206,11 +2206,11 @@ static int _rtl92e_close(struct net_device *dev)
rtllib_stop_scan(priv->rtllib);
}
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
ret = _rtl92e_down(dev, true);
 
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
 
return ret;
 
@@ -2242,11 +2242,11 @@ static void _rtl92e_restart(void *data)
  reset_wq);
struct net_device *dev = priv->rtllib->dev;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
rtl92e_commit(dev);
 
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
 }
 
 static void _rtl92e_set_multicast(struct net_device *dev)
@@ -2265,12 +2265,12 @@ static int _rtl92e_set_mac_adr(struct net_device *dev, 
void *mac)
struct r8192_priv *priv = rtllib_priv(dev);
struct sockaddr *addr = mac;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
ether_addr_copy(dev->dev_addr, addr->sa_data);
 
schedule_work(&priv->reset_wq);
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
 
return 0;
 }
@@ -2287,7 +2287,7 @@ static int _rtl92e_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
struct iw_point *p = &wrq->u.data;
struct ieee_param *ipw = NULL;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
switch (cmd) {
case RTL_IOCTL_WPA_SUPPLICANT:
@@ -2393,7 +2393,7 @@ static int _rtl92e_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
}
 
 out:
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
 
return ret;
 }
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.h 
b/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
index f627fdc..369ebf1 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.h
@@ -375,7 +375,7 @@ struct r8192_priv {
struct tasklet_struct   irq_tx_tasklet;
struct tasklet_struct   irq_prepare_beacon_tasklet;
 
-   struct semaphorewx_sem;
+   struct mutexwx_mutex;
struct semaphorerf_sem;
stru

[PATCH 1/5] rtl8192e: rtllib_device: Replace semaphore wx_sem with mutex

2016-06-01 Thread Binoy Jayan
The semaphore 'wx_sem' in the rtllib_device is a simple mutex,
so it should be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/rtl8192e/rtl8192e/rtl_core.c |  4 +--
 drivers/staging/rtl8192e/rtllib.h|  5 ++--
 drivers/staging/rtl8192e/rtllib_softmac.c| 40 ++--
 drivers/staging/rtl8192e/rtllib_softmac_wx.c | 34 +++
 drivers/staging/rtl8192e/rtllib_wx.c | 10 +++
 5 files changed, 46 insertions(+), 47 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c 
b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
index 9b7cc7d..6f7d356 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_core.c
@@ -1277,14 +1277,14 @@ RESET_START:
rtllib_stop_scan_syncro(ieee);
 
if (ieee->state == RTLLIB_LINKED) {
-   SEM_DOWN_IEEE_WX(&ieee->wx_sem);
+   mutex_lock(&ieee->wx_mutex);
netdev_info(dev, "ieee->state is RTLLIB_LINKED\n");
rtllib_stop_send_beacons(priv->rtllib);
del_timer_sync(&ieee->associate_timer);
cancel_delayed_work(&ieee->associate_retry_wq);
rtllib_stop_scan(ieee);
netif_carrier_off(dev);
-   SEM_UP_IEEE_WX(&ieee->wx_sem);
+   mutex_unlock(&ieee->wx_mutex);
} else {
netdev_info(dev, "ieee->state is NOT LINKED\n");
rtllib_softmac_stop_protocol(priv->rtllib, 0, true);
diff --git a/drivers/staging/rtl8192e/rtllib.h 
b/drivers/staging/rtl8192e/rtllib.h
index 776e179..513dd61 100644
--- a/drivers/staging/rtl8192e/rtllib.h
+++ b/drivers/staging/rtl8192e/rtllib.h
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -1651,7 +1652,7 @@ struct rtllib_device {
short proto_started;
short proto_stoppping;
 
-   struct semaphore wx_sem;
+   struct mutex wx_mutex;
struct semaphore scan_sem;
struct semaphore ips_sem;
 
@@ -2212,7 +2213,5 @@ void rtllib_indicate_packets(struct rtllib_device *ieee,
 void HTUseDefaultSetting(struct rtllib_device *ieee);
 #define RT_ASOC_RETRY_LIMIT5
 u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee);
-#define SEM_DOWN_IEEE_WX(psem) down(psem)
-#define SEM_UP_IEEE_WX(psem) up(psem)
 
 #endif /* RTLLIB_H */
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c 
b/drivers/staging/rtl8192e/rtllib_softmac.c
index cfab715..30abb7f 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -753,7 +753,7 @@ static void rtllib_start_scan(struct rtllib_device *ieee)
}
 }
 
-/* called with wx_sem held */
+/* called with wx_mutex held */
 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh)
 {
if (IS_DOT11D_ENABLE(ieee)) {
@@ -1590,7 +1590,7 @@ static void rtllib_associate_procedure_wq(void *data)
rtllib_stop_scan_syncro(ieee);
if (ieee->rtllib_ips_leave != NULL)
ieee->rtllib_ips_leave(ieee->dev);
-   down(&ieee->wx_sem);
+   mutex_lock(&ieee->wx_mutex);
 
if (ieee->data_hard_stop)
ieee->data_hard_stop(ieee->dev);
@@ -1605,14 +1605,14 @@ static void rtllib_associate_procedure_wq(void *data)
 __func__);
if (ieee->rtllib_ips_leave_wq != NULL)
ieee->rtllib_ips_leave_wq(ieee->dev);
-   up(&ieee->wx_sem);
+   mutex_unlock(&ieee->wx_mutex);
return;
}
ieee->associate_seq = 1;
 
rtllib_associate_step1(ieee, ieee->current_network.bssid);
 
-   up(&ieee->wx_sem);
+   mutex_unlock(&ieee->wx_mutex);
 }
 
 inline void rtllib_softmac_new_net(struct rtllib_device *ieee,
@@ -2582,16 +2582,16 @@ static void rtllib_start_ibss_wq(void *data)
 struct rtllib_device, start_ibss_wq);
/* iwconfig mode ad-hoc will schedule this and return
 * on the other hand this will block further iwconfig SET
-* operations because of the wx_sem hold.
+* operations because of the wx_mutex hold.
 * Anyway some most set operations set a flag to speed-up
 * (abort) this wq (when syncro scanning) before sleeping
-* on the semaphore
+* on the mutex
 */
if (!ieee->proto_started) {
netdev_info(ieee->dev, "==oh driver down return\n");
return;
}
-   down(&ieee->wx_sem);
+   mutex_lock(&ieee->wx_mutex);
 
 

[PATCH 0/5] *** rtl8192e: Replace semaphore with mutex ***

2016-06-01 Thread Binoy Jayan
Resending the same patchset by adding the following lists: 
 de...@driverdev.osuosl.org
 linux-ker...@vger.kernel.org

Hi,

These are a set of patches towards the removing semaphores. 
They build correctly (individually and as a whole).
Is there any way to get this tested as I do not have the following hardware:

"RealTek RTL8192E Wireless LAN NIC driver"

Thanks,
Binoy

Binoy Jayan (5):
  rtl8192e: rtllib_device: Replace semaphore wx_sem with mutex
  rtl8192e: r8192_priv: Replace semaphore wx_sem with mutex
  rtl8192e: Replace semaphore rf_sem with mutex
  rtl8192e: Replace semaphore scan_sem with mutex
  rtl8192e: Replace semaphore ips_sem with mutex

 drivers/staging/rtl8192e/rtl8192e/r8192E_phy.c |   4 +-
 drivers/staging/rtl8192e/rtl8192e/rtl_cam.c|   4 +-
 drivers/staging/rtl8192e/rtl8192e/rtl_core.c   |  34 +++
 drivers/staging/rtl8192e/rtl8192e/rtl_core.h   |   4 +-
 drivers/staging/rtl8192e/rtl8192e/rtl_ps.c |   8 +-
 drivers/staging/rtl8192e/rtl8192e/rtl_wx.c | 120 -
 drivers/staging/rtl8192e/rtllib.h  |  10 +--
 drivers/staging/rtl8192e/rtllib_softmac.c  |  58 ++--
 drivers/staging/rtl8192e/rtllib_softmac_wx.c   |  34 +++
 drivers/staging/rtl8192e/rtllib_wx.c   |  10 +--
 10 files changed, 142 insertions(+), 144 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 5/5] rtl8192e: Replace semaphore ips_sem with mutex

2016-06-01 Thread Binoy Jayan
The semaphore 'ips_sem' in the rtl8192e is a simple mutex, so it should
be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---

This patch depends on the following patch:
rtl8192e: Replace semaphore scan_sem with mutex

 drivers/staging/rtl8192e/rtl8192e/rtl_cam.c |  4 ++--
 drivers/staging/rtl8192e/rtl8192e/rtl_ps.c  |  8 
 drivers/staging/rtl8192e/rtl8192e/rtl_wx.c  | 16 
 drivers/staging/rtl8192e/rtllib.h   |  3 +--
 drivers/staging/rtl8192e/rtllib_softmac.c   |  2 +-
 5 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c 
b/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c
index 803c8b0..30f65af 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_cam.c
@@ -107,9 +107,9 @@ void rtl92e_set_key(struct net_device *dev, u8 EntryNo, u8 
KeyIndex,
__func__);
return;
}
-   down(&priv->rtllib->ips_sem);
+   mutex_lock(&priv->rtllib->ips_mutex);
rtl92e_ips_leave(dev);
-   up(&priv->rtllib->ips_sem);
+   mutex_unlock(&priv->rtllib->ips_mutex);
}
}
priv->rtllib->is_set_key = true;
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_ps.c 
b/drivers/staging/rtl8192e/rtl8192e/rtl_ps.c
index 98e4d88..aa4b015 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_ps.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_ps.c
@@ -179,9 +179,9 @@ void rtl92e_ips_leave_wq(void *data)
struct net_device *dev = ieee->dev;
struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
-   down(&priv->rtllib->ips_sem);
+   mutex_lock(&priv->rtllib->ips_mutex);
rtl92e_ips_leave(dev);
-   up(&priv->rtllib->ips_sem);
+   mutex_unlock(&priv->rtllib->ips_mutex);
 }
 
 void rtl92e_rtllib_ips_leave_wq(struct net_device *dev)
@@ -209,9 +209,9 @@ void rtl92e_rtllib_ips_leave(struct net_device *dev)
 {
struct r8192_priv *priv = (struct r8192_priv *)rtllib_priv(dev);
 
-   down(&priv->rtllib->ips_sem);
+   mutex_lock(&priv->rtllib->ips_mutex);
rtl92e_ips_leave(dev);
-   up(&priv->rtllib->ips_sem);
+   mutex_unlock(&priv->rtllib->ips_mutex);
 }
 
 static bool _rtl92e_ps_set_mode(struct net_device *dev, u8 rtPsMode)
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c 
b/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c
index 78fe833..7413a10 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_wx.c
@@ -281,9 +281,9 @@ static int _rtl92e_wx_set_mode(struct net_device *dev,
netdev_info(dev,
"=>%s(): 
rtl92e_ips_leave\n",
__func__);
-   down(&priv->rtllib->ips_sem);
+   mutex_lock(&priv->rtllib->ips_mutex);
rtl92e_ips_leave(dev);
-   up(&priv->rtllib->ips_sem);
+   mutex_unlock(&priv->rtllib->ips_mutex);
}
}
}
@@ -442,9 +442,9 @@ static int _rtl92e_wx_set_scan(struct net_device *dev,
RT_TRACE(COMP_PS,
 "=>%s(): rtl92e_ips_leave\n",
 __func__);
-   down(&priv->rtllib->ips_sem);
+   mutex_lock(&priv->rtllib->ips_mutex);
rtl92e_ips_leave(dev);
-   up(&priv->rtllib->ips_sem);
+   mutex_unlock(&priv->rtllib->ips_mutex);
}
}
rtllib_stop_scan(priv->rtllib);
@@ -698,9 +698,9 @@ static int _rtl92e_wx_set_enc(struct net_device *dev,
return -ENETDOWN;
 
priv->rtllib->wx_set_enc = 1;
-   down(&priv->rtllib->ips_sem);
+   mutex_lock(&priv->rtllib->ips_mutex);
rtl92e_ips_leave(dev);
-   up(&priv->rtllib->ips_sem);
+   mutex_unlock(&priv->rtllib->ips_mutex);
mutex_lock(&priv->wx_mutex);
 
RT_TRACE(COMP_SEC, "Setting SW wep key");
@@ -905,9 +905,9 @@ static int _rtl92e_wx_set_encode_ext(struct net_device *dev,
mutex_lock(&priv->wx_mutex);
 
priv->rtllib->wx_set_enc = 1;
-   down(&priv->rtllib->ips_sem);
+   mu

[PATCH 4/5] rtl8192e: Replace semaphore scan_sem with mutex

2016-06-01 Thread Binoy Jayan
The semaphore 'scan_sem' in the rtl8192e is a simple mutex, so it should
be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---

This patch depends on the following patch:
rtl8192e: Replace semaphore rf_sem with mutex

 drivers/staging/rtl8192e/rtllib.h |  2 +-
 drivers/staging/rtl8192e/rtllib_softmac.c | 16 
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib.h 
b/drivers/staging/rtl8192e/rtllib.h
index 513dd61..5bdc378 100644
--- a/drivers/staging/rtl8192e/rtllib.h
+++ b/drivers/staging/rtl8192e/rtllib.h
@@ -1653,7 +1653,7 @@ struct rtllib_device {
short proto_stoppping;
 
struct mutex wx_mutex;
-   struct semaphore scan_sem;
+   struct mutex scan_mutex;
struct semaphore ips_sem;
 
spinlock_t mgmt_tx_lock;
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c 
b/drivers/staging/rtl8192e/rtllib_softmac.c
index 30abb7f..7f4033c 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -513,7 +513,7 @@ static void rtllib_softmac_scan_syncro(struct rtllib_device 
*ieee, u8 is_mesh)
 
ieee->be_scan_inprogress = true;
 
-   down(&ieee->scan_sem);
+   mutex_lock(&ieee->scan_mutex);
 
while (1) {
do {
@@ -566,7 +566,7 @@ out:
if (IS_DOT11D_ENABLE(ieee))
DOT11D_ScanComplete(ieee);
}
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
 
ieee->be_scan_inprogress = false;
 
@@ -587,7 +587,7 @@ static void rtllib_softmac_scan_wq(void *data)
if (rtllib_act_scanning(ieee, true))
return;
 
-   down(&ieee->scan_sem);
+   mutex_lock(&ieee->scan_mutex);
 
if (ieee->eRFPowerState == eRfOff) {
netdev_info(ieee->dev,
@@ -618,7 +618,7 @@ static void rtllib_softmac_scan_wq(void *data)
schedule_delayed_work(&ieee->softmac_scan_wq,
  msecs_to_jiffies(RTLLIB_SOFTMAC_SCAN_TIME));
 
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
return;
 
 out:
@@ -630,7 +630,7 @@ out1:
ieee->actscanning = false;
ieee->scan_watch_dog = 0;
ieee->scanning_continue = 0;
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
 }
 
 
@@ -683,7 +683,7 @@ EXPORT_SYMBOL(rtllib_start_send_beacons);
 
 static void rtllib_softmac_stop_scan(struct rtllib_device *ieee)
 {
-   down(&ieee->scan_sem);
+   mutex_lock(&ieee->scan_mutex);
ieee->scan_watch_dog = 0;
if (ieee->scanning_continue == 1) {
ieee->scanning_continue = 0;
@@ -692,7 +692,7 @@ static void rtllib_softmac_stop_scan(struct rtllib_device 
*ieee)
cancel_delayed_work_sync(&ieee->softmac_scan_wq);
}
 
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
 }
 
 void rtllib_stop_scan(struct rtllib_device *ieee)
@@ -3035,7 +3035,7 @@ void rtllib_softmac_init(struct rtllib_device *ieee)
  ieee);
 
mutex_init(&ieee->wx_mutex);
-   sema_init(&ieee->scan_sem, 1);
+   mutex_init(&ieee->scan_mutex);
sema_init(&ieee->ips_sem, 1);
 
spin_lock_init(&ieee->mgmt_tx_lock);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/4] rtl8712: Replace semaphore cmd_queue_sema with completion

2016-06-01 Thread Binoy Jayan
The semaphore 'cmd_queue_sema' is used as completion,
so convert it to a struct completion type.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/rtl8712/os_intfs.c| 2 +-
 drivers/staging/rtl8712/rtl8712_cmd.c | 2 +-
 drivers/staging/rtl8712/rtl871x_cmd.c | 6 +++---
 drivers/staging/rtl8712/rtl871x_cmd.h | 2 +-
 drivers/staging/rtl8712/rtl871x_pwrctrl.c | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8712/os_intfs.c 
b/drivers/staging/rtl8712/os_intfs.c
index ab19112..c07bcd0 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -243,7 +243,7 @@ static u32 start_drv_threads(struct _adapter *padapter)
 void r8712_stop_drv_threads(struct _adapter *padapter)
 {
/*Below is to terminate r8712_cmd_thread & event_thread...*/
-   up(&padapter->cmdpriv.cmd_queue_sema);
+   complete(&padapter->cmdpriv.cmd_queue_comp);
if (padapter->cmdThread)
_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
padapter->cmdpriv.cmd_seq = 1;
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c 
b/drivers/staging/rtl8712/rtl8712_cmd.c
index 50f4002..172f51f 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -322,7 +322,7 @@ int r8712_cmd_thread(void *context)
 
allow_signal(SIGTERM);
while (1) {
-   if ((_down_sema(&(pcmdpriv->cmd_queue_sema))) == _FAIL)
+   if 
(wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp))
break;
if (padapter->bDriverStopped || padapter->bSurpriseRemoved)
break;
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c 
b/drivers/staging/rtl8712/rtl871x_cmd.c
index 86136cc..69e650b 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -57,7 +57,7 @@ No irqsave is necessary.
 
 static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
-   sema_init(&(pcmdpriv->cmd_queue_sema), 0);
+   init_completion(&pcmdpriv->cmd_queue_comp);
sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
 
_init_queue(&(pcmdpriv->cmd_queue));
@@ -172,7 +172,7 @@ u32 r8712_enqueue_cmd(struct cmd_priv *pcmdpriv, struct 
cmd_obj *obj)
if (pcmdpriv->padapter->eeprompriv.bautoload_fail_flag)
return _FAIL;
res = _enqueue_cmd(&pcmdpriv->cmd_queue, obj);
-   up(&pcmdpriv->cmd_queue_sema);
+   complete(&pcmdpriv->cmd_queue_comp);
return res;
 }
 
@@ -189,7 +189,7 @@ u32 r8712_enqueue_cmd_ex(struct cmd_priv *pcmdpriv, struct 
cmd_obj *obj)
spin_lock_irqsave(&queue->lock, irqL);
list_add_tail(&obj->list, &queue->queue);
spin_unlock_irqrestore(&queue->lock, irqL);
-   up(&pcmdpriv->cmd_queue_sema);
+   complete(&pcmdpriv->cmd_queue_comp);
return _SUCCESS;
 }
 
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h 
b/drivers/staging/rtl8712/rtl871x_cmd.h
index e4a2a50..1907bc9 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -50,7 +50,7 @@ struct cmd_obj {
 };
 
 struct cmd_priv {
-   struct semaphore cmd_queue_sema;
+   struct completion cmd_queue_comp;
struct semaphore terminate_cmdthread_sema;
struct  __queue cmd_queue;
u8 cmd_seq;
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c 
b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
index bf10d6d..98a5e74 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
@@ -107,7 +107,7 @@ void r8712_cpwm_int_hdl(struct _adapter *padapter,
pwrpriv->cpwm = (preportpwrstate->state) & 0xf;
if (pwrpriv->cpwm >= PS_STATE_S2) {
if (pwrpriv->alives & CMD_ALIVE)
-   up(&(pcmdpriv->cmd_queue_sema));
+   complete(&(pcmdpriv->cmd_queue_comp));
}
pwrpriv->cpwm_tog = (preportpwrstate->state) & 0x80;
up(&pwrpriv->lock);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 3/4] rtl8712: intf_priv: Replace semaphore lock with completion

2016-06-01 Thread Binoy Jayan
The semaphore 'lock' in 'intf_priv' is used as completion,
so convert it to a struct completion type.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
rtl8712: Replace semaphore terminate_cmdthread_sema with completion


 drivers/staging/rtl8712/osdep_intf.h| 2 +-
 drivers/staging/rtl8712/usb_ops_linux.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8712/osdep_intf.h 
b/drivers/staging/rtl8712/osdep_intf.h
index aa0ec74..5d37e1f 100644
--- a/drivers/staging/rtl8712/osdep_intf.h
+++ b/drivers/staging/rtl8712/osdep_intf.h
@@ -36,7 +36,7 @@ struct intf_priv {
/* when in USB, IO is through interrupt in/out endpoints */
struct usb_device *udev;
struct urb *piorw_urb;
-   struct semaphore io_retevt;
+   struct completion io_retevt_comp;
 };
 
 int r871x_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
diff --git a/drivers/staging/rtl8712/usb_ops_linux.c 
b/drivers/staging/rtl8712/usb_ops_linux.c
index 454cdf6..fc3f263 100644
--- a/drivers/staging/rtl8712/usb_ops_linux.c
+++ b/drivers/staging/rtl8712/usb_ops_linux.c
@@ -50,7 +50,7 @@ uint r8712_usb_init_intf_priv(struct intf_priv *pintfpriv)
pintfpriv->piorw_urb = usb_alloc_urb(0, GFP_ATOMIC);
if (!pintfpriv->piorw_urb)
return _FAIL;
-   sema_init(&(pintfpriv->io_retevt), 0);
+   init_completion(&pintfpriv->io_retevt_comp);
return _SUCCESS;
 }
 
@@ -163,7 +163,7 @@ static void usb_write_mem_complete(struct urb *purb)
else
padapter->bSurpriseRemoved = true;
}
-   up(&pintfpriv->io_retevt);
+   complete(&pintfpriv->io_retevt_comp);
 }
 
 void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 
*wmem)
@@ -187,7 +187,7 @@ void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 
addr, u32 cnt, u8 *wmem)
  wmem, cnt, usb_write_mem_complete,
  pio_queue);
usb_submit_urb(piorw_urb, GFP_ATOMIC);
-   _down_sema(&pintfpriv->io_retevt);
+   wait_for_completion_interruptible(&pintfpriv->io_retevt_comp);
 }
 
 static void r8712_usb_read_port_complete(struct urb *purb)
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 0/4] *** rtl8712: Replace semaphores with mutex / completions ***

2016-06-01 Thread Binoy Jayan
Hi,

These are a set of patches [v2] which removes semaphores from:

drivers/staging/rtl8712

They build correctly (individually and as a whole).
NB: I have not tested this as I do not have the following hardware:

"RealTek RTL8712U (RTL8192SU) Wireless LAN NIC driver"

Rework on comments w.r.t. PATCH v1:

 - Removed wrapper functions _wait_completion, _down_sema and _enter_pwrlock
 - Updated changelog to explain use of mutex_lock instead of
   mutex_lock_interruptible in [PATCH v2 4/4]

Binoy

Binoy Jayan (4):
  rtl8712: Replace semaphore cmd_queue_sema with completion
  rtl8712: Replace semaphore terminate_cmdthread_sema with completion
  rtl8712: intf_priv: Replace semaphore lock with completion
  rtl8712: pwrctrl_priv: Replace semaphore lock with mutex

 drivers/staging/rtl8712/os_intfs.c|  4 ++--
 drivers/staging/rtl8712/osdep_intf.h  |  2 +-
 drivers/staging/rtl8712/osdep_service.h   |  7 ---
 drivers/staging/rtl8712/rtl8712_cmd.c | 14 +++---
 drivers/staging/rtl8712/rtl871x_cmd.c |  8 
 drivers/staging/rtl8712/rtl871x_cmd.h |  4 ++--
 drivers/staging/rtl8712/rtl871x_pwrctrl.c | 24 
 drivers/staging/rtl8712/rtl871x_pwrctrl.h |  7 +--
 drivers/staging/rtl8712/usb_ops_linux.c   |  6 +++---
 9 files changed, 32 insertions(+), 44 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 4/4] rtl8712: pwrctrl_priv: Replace semaphore lock with mutex

2016-06-01 Thread Binoy Jayan
The semaphore 'lock' in 'pwrctrl_priv' is used as a simple mutex, so it
should be written as one. Semaphores are going away in the future.
_enter_pwrlock was using down_interruptible(), so the lock could be broken
by sending a signal. This could be a bug, because nothing checks the return
code here. Hence, using mutex_lock instead of the interruptible version.
Removing the now unused _enter_pwrlock and _down_sema.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
  rtl8712: intf_priv: Replace semaphore lock with completion

 drivers/staging/rtl8712/osdep_service.h   |  7 ---
 drivers/staging/rtl8712/rtl8712_cmd.c | 10 +-
 drivers/staging/rtl8712/rtl871x_pwrctrl.c | 22 +++---
 drivers/staging/rtl8712/rtl871x_pwrctrl.h |  7 +--
 4 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/rtl8712/osdep_service.h 
b/drivers/staging/rtl8712/osdep_service.h
index 076d508..d89ae09 100644
--- a/drivers/staging/rtl8712/osdep_service.h
+++ b/drivers/staging/rtl8712/osdep_service.h
@@ -60,13 +60,6 @@ struct   __queue {
 #define LIST_CONTAINOR(ptr, type, member) \
((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member)))
 
-static inline u32 _down_sema(struct semaphore *sema)
-{
-   if (down_interruptible(sema))
-   return _FAIL;
-   return _SUCCESS;
-}
-
 static inline u32 end_of_queue_search(struct list_head *head,
struct list_head *plist)
 {
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c 
b/drivers/staging/rtl8712/rtl8712_cmd.c
index 1badc6c..9934eab 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -264,9 +264,9 @@ static struct cmd_obj *cmd_hdl_filter(struct _adapter 
*padapter,
 */
if (padapter->pwrctrlpriv.pwr_mode > PS_MODE_ACTIVE) {
padapter->pwrctrlpriv.pwr_mode = PS_MODE_ACTIVE;
-   _enter_pwrlock(&(padapter->pwrctrlpriv.lock));
+   mutex_lock(&padapter->pwrctrlpriv.mutex_lock);
r8712_set_rpwm(padapter, PS_STATE_S4);
-   up(&(padapter->pwrctrlpriv.lock));
+   mutex_unlock(&padapter->pwrctrlpriv.mutex_lock);
}
pcmd_r = pcmd;
break;
@@ -395,10 +395,10 @@ _next:
}
if (pcmd->cmdcode == GEN_CMD_CODE(_SetPwrMode)) {
if (padapter->pwrctrlpriv.bSleep) {
-   _enter_pwrlock(&(padapter->
-  pwrctrlpriv.lock));
+   mutex_lock(&padapter->
+  pwrctrlpriv.mutex_lock);
r8712_set_rpwm(padapter, PS_STATE_S2);
-   up(&padapter->pwrctrlpriv.lock);
+   
mutex_unlock(&padapter->pwrctrlpriv.mutex_lock);
}
}
r8712_free_cmd_obj(pcmd);
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c 
b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
index 98a5e74..8d7ead6 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
@@ -103,14 +103,14 @@ void r8712_cpwm_int_hdl(struct _adapter *padapter,
if (pwrpriv->cpwm_tog == ((preportpwrstate->state) & 0x80))
return;
del_timer(&padapter->pwrctrlpriv.rpwm_check_timer);
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
pwrpriv->cpwm = (preportpwrstate->state) & 0xf;
if (pwrpriv->cpwm >= PS_STATE_S2) {
if (pwrpriv->alives & CMD_ALIVE)
complete(&(pcmdpriv->cmd_queue_comp));
}
pwrpriv->cpwm_tog = (preportpwrstate->state) & 0x80;
-   up(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 static inline void register_task_alive(struct pwrctrl_priv *pwrctrl, uint tag)
@@ -141,10 +141,10 @@ static void SetPSModeWorkItemCallback(struct work_struct 
*work)
struct _adapter *padapter = container_of(pwrpriv,
struct _adapter, pwrctrlpriv);
if (!pwrpriv->bSleep) {
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
r8712_set_rpwm(padapter, PS_STATE_S4);
-   up(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
}
 }
 
@@ -155,11 +155,11 @@ static void 

[PATCH v2 2/4] rtl8712: Replace semaphore terminate_cmdthread_sema with completion

2016-06-01 Thread Binoy Jayan
The semaphore 'terminate_cmdthread_sema' is used as completion,
so convert it to a struct completion type.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
 rtl8712: Replace semaphore cmd_queue_sema with completion

 drivers/staging/rtl8712/os_intfs.c| 2 +-
 drivers/staging/rtl8712/rtl8712_cmd.c | 2 +-
 drivers/staging/rtl8712/rtl871x_cmd.c | 2 +-
 drivers/staging/rtl8712/rtl871x_cmd.h | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8712/os_intfs.c 
b/drivers/staging/rtl8712/os_intfs.c
index c07bcd0..2396bac 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -245,7 +245,7 @@ void r8712_stop_drv_threads(struct _adapter *padapter)
/*Below is to terminate r8712_cmd_thread & event_thread...*/
complete(&padapter->cmdpriv.cmd_queue_comp);
if (padapter->cmdThread)
-   _down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+   
wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
padapter->cmdpriv.cmd_seq = 1;
 }
 
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c 
b/drivers/staging/rtl8712/rtl8712_cmd.c
index 172f51f..1badc6c 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -420,7 +420,7 @@ _next:
break;
r8712_free_cmd_obj(pcmd);
} while (1);
-   up(&pcmdpriv->terminate_cmdthread_sema);
+   complete(&pcmdpriv->terminate_cmdthread_comp);
thread_exit();
 }
 
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c 
b/drivers/staging/rtl8712/rtl871x_cmd.c
index 69e650b..74fd928 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -58,7 +58,7 @@ No irqsave is necessary.
 static sint _init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
init_completion(&pcmdpriv->cmd_queue_comp);
-   sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
+   init_completion(&pcmdpriv->terminate_cmdthread_comp);
 
_init_queue(&(pcmdpriv->cmd_queue));
 
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.h 
b/drivers/staging/rtl8712/rtl871x_cmd.h
index 1907bc9..ebd2e1d 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.h
+++ b/drivers/staging/rtl8712/rtl871x_cmd.h
@@ -51,7 +51,7 @@ struct cmd_obj {
 
 struct cmd_priv {
struct completion cmd_queue_comp;
-   struct semaphore terminate_cmdthread_sema;
+   struct completion terminate_cmdthread_comp;
struct  __queue cmd_queue;
u8 cmd_seq;
u8 *cmd_buf;/*shall be non-paged, and 4 bytes aligned*/
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/4] *** rtl8192u: Replace semaphores with mutexes ***

2016-06-01 Thread Binoy Jayan
Hi,

These are a set of patches which removes semaphores from:

drivers/staging/rtl8192u

They build correctly (individually and as a whole).
NB: I have not tested this as I do not have the following hardware:

"RealTek RTL8192U Wireless LAN NIC driver"

Thanks,
Binoy

Binoy Jayan (4):
  rtl8192u: r8192_priv: Replace semaphore wx_sem with mutex
  rtl8192u: ieee80211_device: Replace semaphore wx_sem with mutex
  rtl8192u: Replace semaphore scan_sem with mutex
  rtl8192u: Replace semaphore rf_sem with mutex

 drivers/staging/rtl8192u/ieee80211/ieee80211.h |  4 +-
 .../staging/rtl8192u/ieee80211/ieee80211_softmac.c | 54 +++
 .../rtl8192u/ieee80211/ieee80211_softmac_wx.c  | 34 -
 drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c  |  6 +-
 drivers/staging/rtl8192u/r8192U.h  |  4 +-
 drivers/staging/rtl8192u/r8192U_core.c | 34 -
 drivers/staging/rtl8192u/r8192U_wx.c   | 80 +++---
 7 files changed, 108 insertions(+), 108 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/4] rtl8192u: Replace semaphore rf_sem with mutex

2016-06-01 Thread Binoy Jayan
The semaphore 'rf_sem' in rtl8192u is a simple mutex, so it should
be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
rtl8192u: Replace semaphore scan_sem with mutex

 drivers/staging/rtl8192u/r8192U.h  | 2 +-
 drivers/staging/rtl8192u/r8192U_core.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U.h 
b/drivers/staging/rtl8192u/r8192U.h
index 2780838..7b921d4 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -880,7 +880,7 @@ typedef struct r8192_priv {
short crcmon;
 
struct mutex wx_mutex;
-   struct semaphore rf_sem;/* Used to lock rf write operation */
+   struct mutex rf_mutex;  /* Used to lock rf write operation */
 
u8 rf_type; /* 0: 1T2R, 1: 2T4R */
RT_RF_TYPE_819xU rf_chip;
diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index c6d3119..46d613a 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -2374,7 +2374,7 @@ static void rtl8192_init_priv_lock(struct r8192_priv 
*priv)
spin_lock_init(&priv->tx_lock);
spin_lock_init(&priv->irq_lock);
mutex_init(&priv->wx_mutex);
-   sema_init(&priv->rf_sem, 1);
+   mutex_init(&priv->rf_mutex);
mutex_init(&priv->mutex);
 }
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/4] rtl8192u: Replace semaphore scan_sem with mutex

2016-06-01 Thread Binoy Jayan
The semaphore 'scan_sem' in rtl8192u is a simple mutex, so it should
be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
rtl8192u: ieee80211_device: Replace semaphore wx_sem with mutex

 drivers/staging/rtl8192u/ieee80211/ieee80211.h |  2 +-
 drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 18 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h 
b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index ef9ae22..09e9499 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -1800,7 +1800,7 @@ struct ieee80211_device {
short proto_started;
 
struct mutex wx_mutex;
-   struct semaphore scan_sem;
+   struct mutex scan_mutex;
 
spinlock_t mgmt_tx_lock;
spinlock_t beacon_lock;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c 
b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index c983e49..e8e83f5 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -427,7 +427,7 @@ void ieee80211_softmac_scan_syncro(struct ieee80211_device 
*ieee)
short ch = 0;
u8 channel_map[MAX_CHANNEL_NUMBER+1];
memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, 
MAX_CHANNEL_NUMBER+1);
-   down(&ieee->scan_sem);
+   mutex_lock(&ieee->scan_mutex);
 
while(1)
{
@@ -475,13 +475,13 @@ void ieee80211_softmac_scan_syncro(struct 
ieee80211_device *ieee)
 out:
if(ieee->state < IEEE80211_LINKED){
ieee->actscanning = false;
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
}
else{
ieee->sync_scan_hurryup = 0;
if(IS_DOT11D_ENABLE(ieee))
DOT11D_ScanComplete(ieee);
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
 }
 }
 EXPORT_SYMBOL(ieee80211_softmac_scan_syncro);
@@ -495,7 +495,7 @@ static void ieee80211_softmac_scan_wq(struct work_struct 
*work)
memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, 
MAX_CHANNEL_NUMBER+1);
if(!ieee->ieee_up)
return;
-   down(&ieee->scan_sem);
+   mutex_lock(&ieee->scan_mutex);
do{
ieee->current_network.channel =
(ieee->current_network.channel + 1) % 
MAX_CHANNEL_NUMBER;
@@ -517,7 +517,7 @@ static void ieee80211_softmac_scan_wq(struct work_struct 
*work)
 
schedule_delayed_work(&ieee->softmac_scan_wq, 
IEEE80211_SOFTMAC_SCAN_TIME);
 
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
return;
 out:
if(IS_DOT11D_ENABLE(ieee))
@@ -525,7 +525,7 @@ out:
ieee->actscanning = false;
watchdog = 0;
ieee->scanning = 0;
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
 }
 
 
@@ -579,7 +579,7 @@ static void ieee80211_softmac_stop_scan(struct 
ieee80211_device *ieee)
 
//ieee->sync_scan_hurryup = 1;
 
-   down(&ieee->scan_sem);
+   mutex_lock(&ieee->scan_mutex);
 // spin_lock_irqsave(&ieee->lock, flags);
 
if (ieee->scanning == 1) {
@@ -589,7 +589,7 @@ static void ieee80211_softmac_stop_scan(struct 
ieee80211_device *ieee)
}
 
 // spin_unlock_irqrestore(&ieee->lock, flags);
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
 }
 
 void ieee80211_stop_scan(struct ieee80211_device *ieee)
@@ -2729,7 +2729,7 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee)
 
 
mutex_init(&ieee->wx_mutex);
-   sema_init(&ieee->scan_sem, 1);
+   mutex_init(&ieee->scan_mutex);
 
spin_lock_init(&ieee->mgmt_tx_lock);
spin_lock_init(&ieee->beacon_lock);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/4] rtl8192u: r8192_priv: Replace semaphore wx_sem with mutex

2016-06-01 Thread Binoy Jayan
The semaphore 'wx_sem' in r8192_priv is a simple mutex, so
it should be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/rtl8192u/r8192U.h  |  2 +-
 drivers/staging/rtl8192u/r8192U_core.c | 28 ++--
 drivers/staging/rtl8192u/r8192U_wx.c   | 80 +-
 3 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U.h 
b/drivers/staging/rtl8192u/r8192U.h
index ee1c722..2780838 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -879,7 +879,7 @@ typedef struct r8192_priv {
/* If 1, allow bad crc frame, reception in monitor mode */
short crcmon;
 
-   struct semaphore wx_sem;
+   struct mutex wx_mutex;
struct semaphore rf_sem;/* Used to lock rf write operation */
 
u8 rf_type; /* 0: 1T2R, 1: 2T4R */
diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index 849a95e..3d1b52f 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -2373,7 +2373,7 @@ static void rtl8192_init_priv_lock(struct r8192_priv 
*priv)
 {
spin_lock_init(&priv->tx_lock);
spin_lock_init(&priv->irq_lock);
-   sema_init(&priv->wx_sem, 1);
+   mutex_init(&priv->wx_mutex);
sema_init(&priv->rf_sem, 1);
mutex_init(&priv->mutex);
 }
@@ -3324,12 +3324,12 @@ RESET_START:
 
/* Set the variable for reset. */
priv->ResetProgress = RESET_TYPE_SILENT;
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
if (priv->up == 0) {
RT_TRACE(COMP_ERR,
 "%s():the driver is not up! return\n",
 __func__);
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
return;
}
priv->up = 0;
@@ -3356,7 +3356,7 @@ RESET_START:
netdev_dbg(dev, "ieee->state is NOT LINKED\n");
ieee80211_softmac_stop_protocol(priv->ieee80211);
}
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
RT_TRACE(COMP_RESET,
 "%s():<==down process is finished\n",
 __func__);
@@ -3556,9 +3556,9 @@ static int rtl8192_open(struct net_device *dev)
struct r8192_priv *priv = ieee80211_priv(dev);
int ret;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
ret = rtl8192_up(dev);
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
return ret;
 
 }
@@ -3580,11 +3580,11 @@ static int rtl8192_close(struct net_device *dev)
struct r8192_priv *priv = ieee80211_priv(dev);
int ret;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
ret = rtl8192_down(dev);
 
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
 
return ret;
 
@@ -3658,11 +3658,11 @@ static void rtl8192_restart(struct work_struct *work)
   reset_wq);
struct net_device *dev = priv->ieee80211->dev;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
rtl8192_commit(dev);
 
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
 }
 
 static void r8192_set_multicast(struct net_device *dev)
@@ -3685,12 +3685,12 @@ static int r8192_set_mac_adr(struct net_device *dev, 
void *mac)
struct r8192_priv *priv = ieee80211_priv(dev);
struct sockaddr *addr = mac;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
ether_addr_copy(dev->dev_addr, addr->sa_data);
 
schedule_work(&priv->reset_wq);
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
 
return 0;
 }
@@ -3707,7 +3707,7 @@ static int rtl8192_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
struct iw_point *p = &wrq->u.data;
struct ieee_param *ipw = NULL;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
 
if (p->length < sizeof(struct ieee_param) || !p->pointer) {
@@ -3800,7 +3800,7 @@ static int rtl8192_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
kfree(ipw);
ipw = NULL;
 out:
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
return ret;
 }
 
diff --git a/drivers/staging/rtl8192u/r8192U_wx.c 
b/drivers/staging/rtl8192u/r8192U_wx.c

[PATCH 2/4] rtl8192u: ieee80211_device: Replace semaphore wx_sem with mutex

2016-06-01 Thread Binoy Jayan
The semaphore 'wx_sem' in ieee80211_device is a simple mutex,
so it should be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
rtl8192u: r8192_priv: Replace semaphore wx_sem with mutex

 drivers/staging/rtl8192u/ieee80211/ieee80211.h |  2 +-
 .../staging/rtl8192u/ieee80211/ieee80211_softmac.c | 36 +++---
 .../rtl8192u/ieee80211/ieee80211_softmac_wx.c  | 34 ++--
 drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c  |  6 ++--
 drivers/staging/rtl8192u/r8192U_core.c |  4 +--
 5 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h 
b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index 68931e5..ef9ae22 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -1799,7 +1799,7 @@ struct ieee80211_device {
short scanning;
short proto_started;
 
-   struct semaphore wx_sem;
+   struct mutex wx_mutex;
struct semaphore scan_sem;
 
spinlock_t mgmt_tx_lock;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c 
b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index ae1274c..c983e49 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -621,7 +621,7 @@ static void ieee80211_start_scan(struct ieee80211_device 
*ieee)
 
 }
 
-/* called with wx_sem held */
+/* called with wx_mutex held */
 void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
 {
if (IS_DOT11D_ENABLE(ieee) )
@@ -1389,7 +1389,7 @@ static void ieee80211_associate_procedure_wq(struct 
work_struct *work)
 {
struct ieee80211_device *ieee = container_of(work, struct 
ieee80211_device, associate_procedure_wq);
ieee->sync_scan_hurryup = 1;
-   down(&ieee->wx_sem);
+   mutex_lock(&ieee->wx_mutex);
 
if (ieee->data_hard_stop)
ieee->data_hard_stop(ieee->dev);
@@ -1402,7 +1402,7 @@ static void ieee80211_associate_procedure_wq(struct 
work_struct *work)
ieee->associate_seq = 1;
ieee80211_associate_step1(ieee);
 
-   up(&ieee->wx_sem);
+   mutex_unlock(&ieee->wx_mutex);
 }
 
 inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct 
ieee80211_network *net)
@@ -2331,7 +2331,7 @@ static void ieee80211_start_ibss_wq(struct work_struct 
*work)
struct ieee80211_device *ieee = container_of(dwork, struct 
ieee80211_device, start_ibss_wq);
/* iwconfig mode ad-hoc will schedule this and return
 * on the other hand this will block further iwconfig SET
-* operations because of the wx_sem hold.
+* operations because of the wx_mutex hold.
 * Anyway some most set operations set a flag to speed-up
 * (abort) this wq (when syncro scanning) before sleeping
 * on the semaphore
@@ -2340,7 +2340,7 @@ static void ieee80211_start_ibss_wq(struct work_struct 
*work)
printk("==oh driver down return\n");
return;
}
-   down(&ieee->wx_sem);
+   mutex_lock(&ieee->wx_mutex);
 
if (ieee->current_network.ssid_len == 0) {
strcpy(ieee->current_network.ssid, IEEE80211_DEFAULT_TX_ESSID);
@@ -2431,7 +2431,7 @@ static void ieee80211_start_ibss_wq(struct work_struct 
*work)
ieee->data_hard_resume(ieee->dev);
netif_carrier_on(ieee->dev);
 
-   up(&ieee->wx_sem);
+   mutex_unlock(&ieee->wx_mutex);
 }
 
 inline void ieee80211_start_ibss(struct ieee80211_device *ieee)
@@ -2439,7 +2439,7 @@ inline void ieee80211_start_ibss(struct ieee80211_device 
*ieee)
schedule_delayed_work(&ieee->start_ibss_wq, 150);
 }
 
-/* this is called only in user context, with wx_sem held */
+/* this is called only in user context, with wx_mutex held */
 void ieee80211_start_bss(struct ieee80211_device *ieee)
 {
unsigned long flags;
@@ -2505,7 +2505,7 @@ static void ieee80211_associate_retry_wq(struct 
work_struct *work)
struct ieee80211_device *ieee = container_of(dwork, struct 
ieee80211_device, associate_retry_wq);
unsigned long flags;
 
-   down(&ieee->wx_sem);
+   mutex_lock(&ieee->wx_mutex);
if(!ieee->proto_started)
goto exit;
 
@@ -2537,7 +2537,7 @@ static void ieee80211_associate_retry_wq(struct 
work_struct *work)
spin_unlock_irqrestore(&ieee->lock, flags);
 
 exit:
-   up(&ieee->wx_sem);
+   mutex_unlock(&ieee->wx_mutex);
 }
 
 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee)
@@ -2583,9 +2583,9 @@ EXPORT_SYMBOL(ieee80211_get_beacon);
 void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee)
 {
   

[PATCH v2 0/4] *** rtl8192u: Replace semaphores with mutexes ***

2016-06-02 Thread Binoy Jayan
Hi,

These are a set of patches [v2] which removes semaphores from:

drivers/staging/rtl8192u

These are part of a bigger effort to eliminate all semaphores 
from the linux kernel.

They build correctly (individually and as a whole).
NB: I have not tested this as I do not have the following hardware:

"RealTek RTL8192U Wireless LAN NIC driver"

Review comments w.r.t. PATCH v1:
  Changed the following patch (PATCH 4/4)
   rtl8192u: Replace semaphore rf_sem with mutex
  with
  rtl8192u: Remove unused semaphore rf_sem
  since 'rf_sem' has no users, removing it instead
  of replacing it with a mutex.

Thanks,
Binoy

Binoy Jayan (4):
  rtl8192u: r8192_priv: Replace semaphore wx_sem with mutex
  rtl8192u: ieee80211_device: Replace semaphore wx_sem with mutex
  rtl8192u: Replace semaphore scan_sem with mutex
  rtl8192u: Remove unused semaphore rf_sem

 drivers/staging/rtl8192u/ieee80211/ieee80211.h |  4 +-
 .../staging/rtl8192u/ieee80211/ieee80211_softmac.c | 54 +++
 .../rtl8192u/ieee80211/ieee80211_softmac_wx.c  | 34 -
 drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c  |  6 +-
 drivers/staging/rtl8192u/r8192U.h  |  3 +-
 drivers/staging/rtl8192u/r8192U_core.c | 33 +
 drivers/staging/rtl8192u/r8192U_wx.c   | 80 +++---
 7 files changed, 106 insertions(+), 108 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/4] rtl8192u: r8192_priv: Replace semaphore wx_sem with mutex

2016-06-02 Thread Binoy Jayan
The semaphore 'wx_sem' in r8192_priv is a simple mutex, so
it should be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/rtl8192u/r8192U.h  |  2 +-
 drivers/staging/rtl8192u/r8192U_core.c | 28 ++--
 drivers/staging/rtl8192u/r8192U_wx.c   | 80 +-
 3 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U.h 
b/drivers/staging/rtl8192u/r8192U.h
index ee1c722..2780838 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -879,7 +879,7 @@ typedef struct r8192_priv {
/* If 1, allow bad crc frame, reception in monitor mode */
short crcmon;
 
-   struct semaphore wx_sem;
+   struct mutex wx_mutex;
struct semaphore rf_sem;/* Used to lock rf write operation */
 
u8 rf_type; /* 0: 1T2R, 1: 2T4R */
diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index 849a95e..3d1b52f 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -2373,7 +2373,7 @@ static void rtl8192_init_priv_lock(struct r8192_priv 
*priv)
 {
spin_lock_init(&priv->tx_lock);
spin_lock_init(&priv->irq_lock);
-   sema_init(&priv->wx_sem, 1);
+   mutex_init(&priv->wx_mutex);
sema_init(&priv->rf_sem, 1);
mutex_init(&priv->mutex);
 }
@@ -3324,12 +3324,12 @@ RESET_START:
 
/* Set the variable for reset. */
priv->ResetProgress = RESET_TYPE_SILENT;
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
if (priv->up == 0) {
RT_TRACE(COMP_ERR,
 "%s():the driver is not up! return\n",
 __func__);
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
return;
}
priv->up = 0;
@@ -3356,7 +3356,7 @@ RESET_START:
netdev_dbg(dev, "ieee->state is NOT LINKED\n");
ieee80211_softmac_stop_protocol(priv->ieee80211);
}
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
RT_TRACE(COMP_RESET,
 "%s():<==down process is finished\n",
 __func__);
@@ -3556,9 +3556,9 @@ static int rtl8192_open(struct net_device *dev)
struct r8192_priv *priv = ieee80211_priv(dev);
int ret;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
ret = rtl8192_up(dev);
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
return ret;
 
 }
@@ -3580,11 +3580,11 @@ static int rtl8192_close(struct net_device *dev)
struct r8192_priv *priv = ieee80211_priv(dev);
int ret;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
ret = rtl8192_down(dev);
 
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
 
return ret;
 
@@ -3658,11 +3658,11 @@ static void rtl8192_restart(struct work_struct *work)
   reset_wq);
struct net_device *dev = priv->ieee80211->dev;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
rtl8192_commit(dev);
 
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
 }
 
 static void r8192_set_multicast(struct net_device *dev)
@@ -3685,12 +3685,12 @@ static int r8192_set_mac_adr(struct net_device *dev, 
void *mac)
struct r8192_priv *priv = ieee80211_priv(dev);
struct sockaddr *addr = mac;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
ether_addr_copy(dev->dev_addr, addr->sa_data);
 
schedule_work(&priv->reset_wq);
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
 
return 0;
 }
@@ -3707,7 +3707,7 @@ static int rtl8192_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
struct iw_point *p = &wrq->u.data;
struct ieee_param *ipw = NULL;
 
-   down(&priv->wx_sem);
+   mutex_lock(&priv->wx_mutex);
 
 
if (p->length < sizeof(struct ieee_param) || !p->pointer) {
@@ -3800,7 +3800,7 @@ static int rtl8192_ioctl(struct net_device *dev, struct 
ifreq *rq, int cmd)
kfree(ipw);
ipw = NULL;
 out:
-   up(&priv->wx_sem);
+   mutex_unlock(&priv->wx_mutex);
return ret;
 }
 
diff --git a/drivers/staging/rtl8192u/r8192U_wx.c 
b/drivers/staging/rtl8192u/r8192U_wx.c

[PATCH v2 2/4] rtl8192u: ieee80211_device: Replace semaphore wx_sem with mutex

2016-06-02 Thread Binoy Jayan
The semaphore 'wx_sem' in ieee80211_device is a simple mutex,
so it should be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
rtl8192u: r8192_priv: Replace semaphore wx_sem with mutex

 drivers/staging/rtl8192u/ieee80211/ieee80211.h |  2 +-
 .../staging/rtl8192u/ieee80211/ieee80211_softmac.c | 36 +++---
 .../rtl8192u/ieee80211/ieee80211_softmac_wx.c  | 34 ++--
 drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c  |  6 ++--
 drivers/staging/rtl8192u/r8192U_core.c |  4 +--
 5 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h 
b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index 68931e5..ef9ae22 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -1799,7 +1799,7 @@ struct ieee80211_device {
short scanning;
short proto_started;
 
-   struct semaphore wx_sem;
+   struct mutex wx_mutex;
struct semaphore scan_sem;
 
spinlock_t mgmt_tx_lock;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c 
b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index ae1274c..c983e49 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -621,7 +621,7 @@ static void ieee80211_start_scan(struct ieee80211_device 
*ieee)
 
 }
 
-/* called with wx_sem held */
+/* called with wx_mutex held */
 void ieee80211_start_scan_syncro(struct ieee80211_device *ieee)
 {
if (IS_DOT11D_ENABLE(ieee) )
@@ -1389,7 +1389,7 @@ static void ieee80211_associate_procedure_wq(struct 
work_struct *work)
 {
struct ieee80211_device *ieee = container_of(work, struct 
ieee80211_device, associate_procedure_wq);
ieee->sync_scan_hurryup = 1;
-   down(&ieee->wx_sem);
+   mutex_lock(&ieee->wx_mutex);
 
if (ieee->data_hard_stop)
ieee->data_hard_stop(ieee->dev);
@@ -1402,7 +1402,7 @@ static void ieee80211_associate_procedure_wq(struct 
work_struct *work)
ieee->associate_seq = 1;
ieee80211_associate_step1(ieee);
 
-   up(&ieee->wx_sem);
+   mutex_unlock(&ieee->wx_mutex);
 }
 
 inline void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct 
ieee80211_network *net)
@@ -2331,7 +2331,7 @@ static void ieee80211_start_ibss_wq(struct work_struct 
*work)
struct ieee80211_device *ieee = container_of(dwork, struct 
ieee80211_device, start_ibss_wq);
/* iwconfig mode ad-hoc will schedule this and return
 * on the other hand this will block further iwconfig SET
-* operations because of the wx_sem hold.
+* operations because of the wx_mutex hold.
 * Anyway some most set operations set a flag to speed-up
 * (abort) this wq (when syncro scanning) before sleeping
 * on the semaphore
@@ -2340,7 +2340,7 @@ static void ieee80211_start_ibss_wq(struct work_struct 
*work)
printk("==oh driver down return\n");
return;
}
-   down(&ieee->wx_sem);
+   mutex_lock(&ieee->wx_mutex);
 
if (ieee->current_network.ssid_len == 0) {
strcpy(ieee->current_network.ssid, IEEE80211_DEFAULT_TX_ESSID);
@@ -2431,7 +2431,7 @@ static void ieee80211_start_ibss_wq(struct work_struct 
*work)
ieee->data_hard_resume(ieee->dev);
netif_carrier_on(ieee->dev);
 
-   up(&ieee->wx_sem);
+   mutex_unlock(&ieee->wx_mutex);
 }
 
 inline void ieee80211_start_ibss(struct ieee80211_device *ieee)
@@ -2439,7 +2439,7 @@ inline void ieee80211_start_ibss(struct ieee80211_device 
*ieee)
schedule_delayed_work(&ieee->start_ibss_wq, 150);
 }
 
-/* this is called only in user context, with wx_sem held */
+/* this is called only in user context, with wx_mutex held */
 void ieee80211_start_bss(struct ieee80211_device *ieee)
 {
unsigned long flags;
@@ -2505,7 +2505,7 @@ static void ieee80211_associate_retry_wq(struct 
work_struct *work)
struct ieee80211_device *ieee = container_of(dwork, struct 
ieee80211_device, associate_retry_wq);
unsigned long flags;
 
-   down(&ieee->wx_sem);
+   mutex_lock(&ieee->wx_mutex);
if(!ieee->proto_started)
goto exit;
 
@@ -2537,7 +2537,7 @@ static void ieee80211_associate_retry_wq(struct 
work_struct *work)
spin_unlock_irqrestore(&ieee->lock, flags);
 
 exit:
-   up(&ieee->wx_sem);
+   mutex_unlock(&ieee->wx_mutex);
 }
 
 struct sk_buff *ieee80211_get_beacon_(struct ieee80211_device *ieee)
@@ -2583,9 +2583,9 @@ EXPORT_SYMBOL(ieee80211_get_beacon);
 void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee)
 {
   

[PATCH v2 3/4] rtl8192u: Replace semaphore scan_sem with mutex

2016-06-02 Thread Binoy Jayan
The semaphore 'scan_sem' in rtl8192u is a simple mutex, so it should
be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
rtl8192u: ieee80211_device: Replace semaphore wx_sem with mutex

 drivers/staging/rtl8192u/ieee80211/ieee80211.h |  2 +-
 drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c | 18 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211.h 
b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
index ef9ae22..09e9499 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211.h
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211.h
@@ -1800,7 +1800,7 @@ struct ieee80211_device {
short proto_started;
 
struct mutex wx_mutex;
-   struct semaphore scan_sem;
+   struct mutex scan_mutex;
 
spinlock_t mgmt_tx_lock;
spinlock_t beacon_lock;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c 
b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index c983e49..e8e83f5 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -427,7 +427,7 @@ void ieee80211_softmac_scan_syncro(struct ieee80211_device 
*ieee)
short ch = 0;
u8 channel_map[MAX_CHANNEL_NUMBER+1];
memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, 
MAX_CHANNEL_NUMBER+1);
-   down(&ieee->scan_sem);
+   mutex_lock(&ieee->scan_mutex);
 
while(1)
{
@@ -475,13 +475,13 @@ void ieee80211_softmac_scan_syncro(struct 
ieee80211_device *ieee)
 out:
if(ieee->state < IEEE80211_LINKED){
ieee->actscanning = false;
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
}
else{
ieee->sync_scan_hurryup = 0;
if(IS_DOT11D_ENABLE(ieee))
DOT11D_ScanComplete(ieee);
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
 }
 }
 EXPORT_SYMBOL(ieee80211_softmac_scan_syncro);
@@ -495,7 +495,7 @@ static void ieee80211_softmac_scan_wq(struct work_struct 
*work)
memcpy(channel_map, GET_DOT11D_INFO(ieee)->channel_map, 
MAX_CHANNEL_NUMBER+1);
if(!ieee->ieee_up)
return;
-   down(&ieee->scan_sem);
+   mutex_lock(&ieee->scan_mutex);
do{
ieee->current_network.channel =
(ieee->current_network.channel + 1) % 
MAX_CHANNEL_NUMBER;
@@ -517,7 +517,7 @@ static void ieee80211_softmac_scan_wq(struct work_struct 
*work)
 
schedule_delayed_work(&ieee->softmac_scan_wq, 
IEEE80211_SOFTMAC_SCAN_TIME);
 
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
return;
 out:
if(IS_DOT11D_ENABLE(ieee))
@@ -525,7 +525,7 @@ out:
ieee->actscanning = false;
watchdog = 0;
ieee->scanning = 0;
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
 }
 
 
@@ -579,7 +579,7 @@ static void ieee80211_softmac_stop_scan(struct 
ieee80211_device *ieee)
 
//ieee->sync_scan_hurryup = 1;
 
-   down(&ieee->scan_sem);
+   mutex_lock(&ieee->scan_mutex);
 // spin_lock_irqsave(&ieee->lock, flags);
 
if (ieee->scanning == 1) {
@@ -589,7 +589,7 @@ static void ieee80211_softmac_stop_scan(struct 
ieee80211_device *ieee)
}
 
 // spin_unlock_irqrestore(&ieee->lock, flags);
-   up(&ieee->scan_sem);
+   mutex_unlock(&ieee->scan_mutex);
 }
 
 void ieee80211_stop_scan(struct ieee80211_device *ieee)
@@ -2729,7 +2729,7 @@ void ieee80211_softmac_init(struct ieee80211_device *ieee)
 
 
mutex_init(&ieee->wx_mutex);
-   sema_init(&ieee->scan_sem, 1);
+   mutex_init(&ieee->scan_mutex);
 
spin_lock_init(&ieee->mgmt_tx_lock);
spin_lock_init(&ieee->beacon_lock);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 4/4] rtl8192u: Remove unused semaphore rf_sem

2016-06-02 Thread Binoy Jayan
The semaphore 'rf_sem' in rtl8192u has no users, hence removing it.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
rtl8192u: Replace semaphore scan_sem with mutex

 drivers/staging/rtl8192u/r8192U.h  | 1 -
 drivers/staging/rtl8192u/r8192U_core.c | 1 -
 2 files changed, 2 deletions(-)

diff --git a/drivers/staging/rtl8192u/r8192U.h 
b/drivers/staging/rtl8192u/r8192U.h
index 2780838..f717cb3 100644
--- a/drivers/staging/rtl8192u/r8192U.h
+++ b/drivers/staging/rtl8192u/r8192U.h
@@ -880,7 +880,6 @@ typedef struct r8192_priv {
short crcmon;
 
struct mutex wx_mutex;
-   struct semaphore rf_sem;/* Used to lock rf write operation */
 
u8 rf_type; /* 0: 1T2R, 1: 2T4R */
RT_RF_TYPE_819xU rf_chip;
diff --git a/drivers/staging/rtl8192u/r8192U_core.c 
b/drivers/staging/rtl8192u/r8192U_core.c
index c6d3119..ccb4259 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -2374,7 +2374,6 @@ static void rtl8192_init_priv_lock(struct r8192_priv 
*priv)
spin_lock_init(&priv->tx_lock);
spin_lock_init(&priv->irq_lock);
mutex_init(&priv->wx_mutex);
-   sema_init(&priv->rf_sem, 1);
mutex_init(&priv->mutex);
 }
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/4] *** rtl8188eu: Replace semaphores with mutexes or completions ***

2016-06-03 Thread Binoy Jayan
Hi,

These are a set of patches which removes semaphores from:

drivers/staging/rtl8188eu

These are part of a bigger effort to eliminate all semaphores 
from the linux kernel.

They build correctly (individually and as a whole).
NB: I have not tested this as I do not have the following hardware:

"Realtek RTL8188EU Wireless LAN NIC driver"

Thanks,
Binoy

Binoy Jayan (4):
  irtl8188eu: Replace semaphore cmd_queue_sema with completion
  rtl8188eu: Replace semaphore terminate_cmdthread_sema with completion
  rtl8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex
  rtl8188eu: Remove unused semaphores

 drivers/staging/rtl8188eu/core/rtw_cmd.c  | 12 ++--
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c  | 20 ++--
 drivers/staging/rtl8188eu/core/rtw_xmit.c |  4 
 drivers/staging/rtl8188eu/include/osdep_service.h |  4 +---
 drivers/staging/rtl8188eu/include/rtw_cmd.h   |  4 ++--
 drivers/staging/rtl8188eu/include/rtw_event.h |  2 +-
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +
 drivers/staging/rtl8188eu/include/rtw_xmit.h  |  3 ---
 drivers/staging/rtl8188eu/os_dep/os_intfs.c   |  6 +++---
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 ---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c   |  8 
 11 files changed, 28 insertions(+), 59 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/4] irtl8188eu: Replace semaphore cmd_queue_sema with completion

2016-06-03 Thread Binoy Jayan
The semaphore 'cmd_queue_sema' is used as completion,
so convert it to struct completion.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c| 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 7748523..a2937e7 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -27,7 +27,7 @@ No irqsave is necessary.
 
 int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
-   sema_init(&(pcmdpriv->cmd_queue_sema), 0);
+   init_completion(&pcmdpriv->cmd_queue_comp);
sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
 
_rtw_init_queue(&(pcmdpriv->cmd_queue));
@@ -122,7 +122,7 @@ u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct 
cmd_obj *cmd_obj)
res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
 
if (res == _SUCCESS)
-   up(&pcmdpriv->cmd_queue_sema);
+   complete(&pcmdpriv->cmd_queue_comp);
 
 exit:
 
@@ -167,7 +167,7 @@ int rtw_cmd_thread(void *context)
RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x 
rtw_cmd_thread \n"));
 
while (1) {
-   if (_rtw_down_sema(&pcmdpriv->cmd_queue_sema) == _FAIL)
+   if 
(wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp))
break;
 
if (padapter->bDriverStopped ||
diff --git a/drivers/staging/rtl8188eu/include/rtw_cmd.h 
b/drivers/staging/rtl8188eu/include/rtw_cmd.h
index 08ca592..3532dd1 100644
--- a/drivers/staging/rtl8188eu/include/rtw_cmd.h
+++ b/drivers/staging/rtl8188eu/include/rtw_cmd.h
@@ -39,7 +39,7 @@ struct cmd_obj {
 };
 
 struct cmd_priv {
-   struct semaphore cmd_queue_sema;
+   struct completion cmd_queue_comp;
struct semaphore terminate_cmdthread_sema;
struct __queue cmd_queue;
u8 cmdthd_running;
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c 
b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index ae2caff..a696d2b 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -772,7 +772,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n"));
 
/* Below is to terminate rtw_cmd_thread & event_thread... */
-   up(&padapter->cmdpriv.cmd_queue_sema);
+   complete(&padapter->cmdpriv.cmd_queue_comp);
if (padapter->cmdThread)
_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/4] rtl8188eu: Replace semaphore terminate_cmdthread_sema with completion

2016-06-03 Thread Binoy Jayan
The semaphore 'terminate_cmdthread_sema' is used as completion,
so convert it to struct completion.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
irtl8188eu: Replace semaphore cmd_queue_sema with completion

 drivers/staging/rtl8188eu/core/rtw_cmd.c| 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index a2937e7..9e12588 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -28,7 +28,7 @@ No irqsave is necessary.
 int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
init_completion(&pcmdpriv->cmd_queue_comp);
-   sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
+   init_completion(&pcmdpriv->terminate_cmdthread_comp);
 
_rtw_init_queue(&(pcmdpriv->cmd_queue));
return _SUCCESS;
@@ -162,7 +162,7 @@ int rtw_cmd_thread(void *context)
allow_signal(SIGTERM);
 
pcmdpriv->cmdthd_running = true;
-   up(&pcmdpriv->terminate_cmdthread_sema);
+   complete(&pcmdpriv->terminate_cmdthread_comp);
 
RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x 
rtw_cmd_thread \n"));
 
@@ -234,7 +234,7 @@ _next:
rtw_free_cmd_obj(pcmd);
}
 
-   up(&pcmdpriv->terminate_cmdthread_sema);
+   complete(&pcmdpriv->terminate_cmdthread_comp);
 
 
complete_and_exit(NULL, 0);
diff --git a/drivers/staging/rtl8188eu/include/rtw_cmd.h 
b/drivers/staging/rtl8188eu/include/rtw_cmd.h
index 3532dd1..2b53f58 100644
--- a/drivers/staging/rtl8188eu/include/rtw_cmd.h
+++ b/drivers/staging/rtl8188eu/include/rtw_cmd.h
@@ -40,7 +40,7 @@ struct cmd_obj {
 
 struct cmd_priv {
struct completion cmd_queue_comp;
-   struct semaphore terminate_cmdthread_sema;
+   struct completion terminate_cmdthread_comp;
struct __queue cmd_queue;
u8 cmdthd_running;
struct adapter *padapter;
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c 
b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index a696d2b..c494845 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -762,7 +762,7 @@ static int rtw_start_drv_threads(struct adapter *padapter)
err = PTR_ERR(padapter->cmdThread);
else
/* wait for cmd_thread to run */
-   _rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+   
wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
return err;
 }
@@ -774,7 +774,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
/* Below is to terminate rtw_cmd_thread & event_thread... */
complete(&padapter->cmdpriv.cmd_queue_comp);
if (padapter->cmdThread)
-   _rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+   
wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
 }
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/4] rtl8188eu: Remove unused semaphores

2016-06-03 Thread Binoy Jayan
The semaphores xmit_sema, terminate_xmitthread_sema and tx_retevt
have no users, hence remove all references to them.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
rtl8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex

 drivers/staging/rtl8188eu/core/rtw_xmit.c | 4 
 drivers/staging/rtl8188eu/include/osdep_service.h | 1 -
 drivers/staging/rtl8188eu/include/rtw_event.h | 1 -
 drivers/staging/rtl8188eu/include/rtw_xmit.h  | 3 ---
 4 files changed, 9 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c 
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index e0a5567..1e1b6d8 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -57,8 +57,6 @@ s32   _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct 
adapter *padapter)
/*  We don't need to memset padapter->XXX to zero, because adapter is 
allocated by vzalloc(). */
 
spin_lock_init(&pxmitpriv->lock);
-   sema_init(&pxmitpriv->xmit_sema, 0);
-   sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
 
/*
Please insert all the queue initializaiton using _rtw_init_queue below
@@ -199,8 +197,6 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct 
adapter *padapter)
 
pxmitpriv->txirp_cnt = 1;
 
-   sema_init(&(pxmitpriv->tx_retevt), 0);
-
/* per AC pending irp */
pxmitpriv->beq_cnt = 0;
pxmitpriv->bkq_cnt = 0;
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h 
b/drivers/staging/rtl8188eu/include/osdep_service.h
index c53c9ea..6f6a8f8 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -35,7 +35,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/staging/rtl8188eu/include/rtw_event.h 
b/drivers/staging/rtl8188eu/include/rtw_event.h
index 0dc63f2..2a45581 100644
--- a/drivers/staging/rtl8188eu/include/rtw_event.h
+++ b/drivers/staging/rtl8188eu/include/rtw_event.h
@@ -18,7 +18,6 @@
 #include 
 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/drivers/staging/rtl8188eu/include/rtw_xmit.h 
b/drivers/staging/rtl8188eu/include/rtw_xmit.h
index a0853ba..7895008 100644
--- a/drivers/staging/rtl8188eu/include/rtw_xmit.h
+++ b/drivers/staging/rtl8188eu/include/rtw_xmit.h
@@ -263,8 +263,6 @@ struct agg_pkt_info {
 
 struct xmit_priv {
spinlock_t lock;
-   struct semaphore xmit_sema;
-   struct semaphore terminate_xmitthread_sema;
struct __queue be_pending;
struct __queue bk_pending;
struct __queue vi_pending;
@@ -289,7 +287,6 @@ struct  xmit_priv {
u8  wmm_para_seq[4];/* sequence for wmm ac parameter strength
 * from large to small. it's value is 0->vo,
 * 1->vi, 2->be, 3->bk. */
-   struct semaphore tx_retevt;/* all tx return event; */
u8  txirp_cnt;/*  */
struct tasklet_struct xmit_tasklet;
/* per AC pending irp */
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/4] rtl8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex

2016-06-03 Thread Binoy Jayan
The semaphore 'lock' in pwrctrl_priv is a simple mutex, so it should
be written as one. Semaphores are going away in the future. Also, remove
the now unused wrappers _init_pwrlock, _enter_pwrlock, _exit_pwrlock
and _rtw_down_sema.

Signed-off-by: Binoy Jayan 
---
This patch depends on the following patch:
rtl8188eu: Replace semaphore terminate_cmdthread_sema with completion

 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c  | 20 ++--
 drivers/staging/rtl8188eu/include/osdep_service.h |  3 +--
 drivers/staging/rtl8188eu/include/rtw_event.h |  1 +
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 ---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c   |  8 
 6 files changed, 17 insertions(+), 39 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c 
b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
index 59c6d8a..0b70fe7 100644
--- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
@@ -38,7 +38,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
LeaveAllPowerSaveMode(padapter);
 
DBG_88E("==> rtw_hw_suspend\n");
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
pwrpriv->bips_processing = true;
/* s1. */
if (pnetdev) {
@@ -73,7 +73,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
pwrpriv->rf_pwrstate = rf_off;
pwrpriv->bips_processing = false;
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
return 0;
 
@@ -90,12 +90,12 @@ static int rtw_hw_resume(struct adapter *padapter)
 
/* system resume */
DBG_88E("==> rtw_hw_resume\n");
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
pwrpriv->bips_processing = true;
rtw_reset_drv_sw(padapter);
 
if (pm_netdev_open(pnetdev, false) != 0) {
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
goto error_exit;
}
 
@@ -113,7 +113,7 @@ static int rtw_hw_resume(struct adapter *padapter)
pwrpriv->rf_pwrstate = rf_on;
pwrpriv->bips_processing = false;
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
 
return 0;
@@ -138,7 +138,7 @@ void ips_enter(struct adapter *padapter)
return;
}
 
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
 
pwrpriv->bips_processing = true;
 
@@ -159,7 +159,7 @@ void ips_enter(struct adapter *padapter)
}
pwrpriv->bips_processing = false;
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 int ips_leave(struct adapter *padapter)
@@ -171,7 +171,7 @@ int ips_leave(struct adapter *padapter)
int keyid;
 
 
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
 
if ((pwrpriv->rf_pwrstate == rf_off) && (!pwrpriv->bips_processing)) {
pwrpriv->bips_processing = true;
@@ -205,7 +205,7 @@ int ips_leave(struct adapter *padapter)
pwrpriv->bpower_saving = false;
}
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
return result;
 }
@@ -504,7 +504,7 @@ void rtw_init_pwrctrl_priv(struct adapter *padapter)
 {
struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
 
-   _init_pwrlock(&pwrctrlpriv->lock);
+   mutex_init(&pwrctrlpriv->mutex_lock);
pwrctrlpriv->rf_pwrstate = rf_on;
pwrctrlpriv->ips_enter_cnts = 0;
pwrctrlpriv->ips_leave_cnts = 0;
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h 
b/drivers/staging/rtl8188eu/include/osdep_service.h
index 5475956..c53c9ea 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -78,8 +79,6 @@ u8 *_rtw_malloc(u32 sz);
 
 void *rtw_malloc2d(int h, int w, int size);
 
-u32  _rtw_down_sema(struct semaphore *sema);
-
 void _rtw_init_queue(struct __queue *pqueue);
 
 struct rtw_netdev_priv_indicator {
diff --git a/drivers/staging/rtl8188eu/include/rtw_event.h 
b/drivers/staging/rtl8188eu/include/rtw_event.h
index 5c34e56..0dc63f2 100644
--- a/drivers/staging/rtl8188eu/include/rtw_event.h
+++ b/drivers/staging/rtl8188eu/include/rtw_event.h
@@ -19,6 +19,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 /*
diff --git a/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h 
b/drivers/staging/rtl8188eu/include/rtw_pwrctrl.h
inde

[PATCH v2 2/4] rtl8188eu: Replace semaphore terminate_cmdthread_sema with completion

2016-06-05 Thread Binoy Jayan
The semaphore 'terminate_cmdthread_sema' is used as completion,
so convert it to struct completion.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c| 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index a2937e7..9e12588 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -28,7 +28,7 @@ No irqsave is necessary.
 int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
init_completion(&pcmdpriv->cmd_queue_comp);
-   sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
+   init_completion(&pcmdpriv->terminate_cmdthread_comp);
 
_rtw_init_queue(&(pcmdpriv->cmd_queue));
return _SUCCESS;
@@ -162,7 +162,7 @@ int rtw_cmd_thread(void *context)
allow_signal(SIGTERM);
 
pcmdpriv->cmdthd_running = true;
-   up(&pcmdpriv->terminate_cmdthread_sema);
+   complete(&pcmdpriv->terminate_cmdthread_comp);
 
RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x 
rtw_cmd_thread \n"));
 
@@ -234,7 +234,7 @@ _next:
rtw_free_cmd_obj(pcmd);
}
 
-   up(&pcmdpriv->terminate_cmdthread_sema);
+   complete(&pcmdpriv->terminate_cmdthread_comp);
 
 
complete_and_exit(NULL, 0);
diff --git a/drivers/staging/rtl8188eu/include/rtw_cmd.h 
b/drivers/staging/rtl8188eu/include/rtw_cmd.h
index 3532dd1..2b53f58 100644
--- a/drivers/staging/rtl8188eu/include/rtw_cmd.h
+++ b/drivers/staging/rtl8188eu/include/rtw_cmd.h
@@ -40,7 +40,7 @@ struct cmd_obj {
 
 struct cmd_priv {
struct completion cmd_queue_comp;
-   struct semaphore terminate_cmdthread_sema;
+   struct completion terminate_cmdthread_comp;
struct __queue cmd_queue;
u8 cmdthd_running;
struct adapter *padapter;
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c 
b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index a696d2b..c494845 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -762,7 +762,7 @@ static int rtw_start_drv_threads(struct adapter *padapter)
err = PTR_ERR(padapter->cmdThread);
else
/* wait for cmd_thread to run */
-   _rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+   
wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
return err;
 }
@@ -774,7 +774,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
/* Below is to terminate rtw_cmd_thread & event_thread... */
complete(&padapter->cmdpriv.cmd_queue_comp);
if (padapter->cmdThread)
-   _rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+   
wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
 }
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 3/4] rtl8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex

2016-06-05 Thread Binoy Jayan
The semaphore 'lock' in pwrctrl_priv is a simple mutex, so it should
be written as one. Semaphores are going away in the future.
_enter_pwrlock was using down_interruptible(), so the lock could be broken
by sending a signal. This could be a bug, because nothing checks the return
code here. Hence, using mutex_lock instead of the interruptible version.
Also, remove the now unused wrappers _init_pwrlock, _enter_pwrlock,
_exit_pwrlock and _rtw_down_sema.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c  | 20 ++--
 drivers/staging/rtl8188eu/include/osdep_service.h |  3 +--
 drivers/staging/rtl8188eu/include/rtw_event.h |  1 +
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 ---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c   |  8 
 6 files changed, 17 insertions(+), 39 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c 
b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
index 59c6d8a..0b70fe7 100644
--- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
@@ -38,7 +38,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
LeaveAllPowerSaveMode(padapter);
 
DBG_88E("==> rtw_hw_suspend\n");
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
pwrpriv->bips_processing = true;
/* s1. */
if (pnetdev) {
@@ -73,7 +73,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
pwrpriv->rf_pwrstate = rf_off;
pwrpriv->bips_processing = false;
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
return 0;
 
@@ -90,12 +90,12 @@ static int rtw_hw_resume(struct adapter *padapter)
 
/* system resume */
DBG_88E("==> rtw_hw_resume\n");
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
pwrpriv->bips_processing = true;
rtw_reset_drv_sw(padapter);
 
if (pm_netdev_open(pnetdev, false) != 0) {
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
goto error_exit;
}
 
@@ -113,7 +113,7 @@ static int rtw_hw_resume(struct adapter *padapter)
pwrpriv->rf_pwrstate = rf_on;
pwrpriv->bips_processing = false;
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
 
return 0;
@@ -138,7 +138,7 @@ void ips_enter(struct adapter *padapter)
return;
}
 
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
 
pwrpriv->bips_processing = true;
 
@@ -159,7 +159,7 @@ void ips_enter(struct adapter *padapter)
}
pwrpriv->bips_processing = false;
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 int ips_leave(struct adapter *padapter)
@@ -171,7 +171,7 @@ int ips_leave(struct adapter *padapter)
int keyid;
 
 
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
 
if ((pwrpriv->rf_pwrstate == rf_off) && (!pwrpriv->bips_processing)) {
pwrpriv->bips_processing = true;
@@ -205,7 +205,7 @@ int ips_leave(struct adapter *padapter)
pwrpriv->bpower_saving = false;
}
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
return result;
 }
@@ -504,7 +504,7 @@ void rtw_init_pwrctrl_priv(struct adapter *padapter)
 {
struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
 
-   _init_pwrlock(&pwrctrlpriv->lock);
+   mutex_init(&pwrctrlpriv->mutex_lock);
pwrctrlpriv->rf_pwrstate = rf_on;
pwrctrlpriv->ips_enter_cnts = 0;
pwrctrlpriv->ips_leave_cnts = 0;
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h 
b/drivers/staging/rtl8188eu/include/osdep_service.h
index 5475956..c53c9ea 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -78,8 +79,6 @@ u8 *_rtw_malloc(u32 sz);
 
 void *rtw_malloc2d(int h, int w, int size);
 
-u32  _rtw_down_sema(struct semaphore *sema);
-
 void _rtw_init_queue(struct __queue *pqueue);
 
 struct rtw_netdev_priv_indicator {
diff --git a/drivers/staging/rtl8188eu/include/rtw_event.h 
b/drivers/staging/rtl8188eu/include/rtw_event.h
index 5c34e56..0dc63f2 100644
--- a/drivers/staging/rtl8188eu/include/rtw_event.h
+++ b/drivers/staging/rtl8188eu/include/rtw_event.h
@@ -19,6 +19,7 @@
 
 #include 
 #include 
+#include

[PATCH v2 0/4] *** rtl8188eu: Replace semaphores with mutexes or completions ***

2016-06-05 Thread Binoy Jayan
Hi,

These are a set of patches [v2] which removes semaphores from:

drivers/staging/rtl8188eu

These are part of a bigger effort to eliminate all semaphores 
from the linux kernel.

They build correctly (individually and as a whole).
NB: I have not tested this as I do not have the following hardware:

"Realtek RTL8188EU Wireless LAN NIC driver"

Incorporated changes w.r.t. review comments:
 - Changed changelog in patch 3/4

Thanks,
Binoy

Binoy Jayan (4):
  irtl8188eu: Replace semaphore cmd_queue_sema with completion
  rtl8188eu: Replace semaphore terminate_cmdthread_sema with completion
  rtl8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex
  rtl8188eu: Remove unused semaphores

 drivers/staging/rtl8188eu/core/rtw_cmd.c  | 12 ++--
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c  | 20 ++--
 drivers/staging/rtl8188eu/core/rtw_xmit.c |  4 
 drivers/staging/rtl8188eu/include/osdep_service.h |  4 +---
 drivers/staging/rtl8188eu/include/rtw_cmd.h   |  4 ++--
 drivers/staging/rtl8188eu/include/rtw_event.h |  2 +-
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +
 drivers/staging/rtl8188eu/include/rtw_xmit.h  |  3 ---
 drivers/staging/rtl8188eu/os_dep/os_intfs.c   |  6 +++---
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 ---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c   |  8 
 11 files changed, 28 insertions(+), 59 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 4/4] rtl8188eu: Remove unused semaphores

2016-06-05 Thread Binoy Jayan
The semaphores xmit_sema, terminate_xmitthread_sema and tx_retevt
have no users, hence remove all references to them.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/rtl8188eu/core/rtw_xmit.c | 4 
 drivers/staging/rtl8188eu/include/osdep_service.h | 1 -
 drivers/staging/rtl8188eu/include/rtw_event.h | 1 -
 drivers/staging/rtl8188eu/include/rtw_xmit.h  | 3 ---
 4 files changed, 9 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c 
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index e0a5567..1e1b6d8 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -57,8 +57,6 @@ s32   _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct 
adapter *padapter)
/*  We don't need to memset padapter->XXX to zero, because adapter is 
allocated by vzalloc(). */
 
spin_lock_init(&pxmitpriv->lock);
-   sema_init(&pxmitpriv->xmit_sema, 0);
-   sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
 
/*
Please insert all the queue initializaiton using _rtw_init_queue below
@@ -199,8 +197,6 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct 
adapter *padapter)
 
pxmitpriv->txirp_cnt = 1;
 
-   sema_init(&(pxmitpriv->tx_retevt), 0);
-
/* per AC pending irp */
pxmitpriv->beq_cnt = 0;
pxmitpriv->bkq_cnt = 0;
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h 
b/drivers/staging/rtl8188eu/include/osdep_service.h
index c53c9ea..6f6a8f8 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -35,7 +35,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/staging/rtl8188eu/include/rtw_event.h 
b/drivers/staging/rtl8188eu/include/rtw_event.h
index 0dc63f2..2a45581 100644
--- a/drivers/staging/rtl8188eu/include/rtw_event.h
+++ b/drivers/staging/rtl8188eu/include/rtw_event.h
@@ -18,7 +18,6 @@
 #include 
 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/drivers/staging/rtl8188eu/include/rtw_xmit.h 
b/drivers/staging/rtl8188eu/include/rtw_xmit.h
index a0853ba..7895008 100644
--- a/drivers/staging/rtl8188eu/include/rtw_xmit.h
+++ b/drivers/staging/rtl8188eu/include/rtw_xmit.h
@@ -263,8 +263,6 @@ struct agg_pkt_info {
 
 struct xmit_priv {
spinlock_t lock;
-   struct semaphore xmit_sema;
-   struct semaphore terminate_xmitthread_sema;
struct __queue be_pending;
struct __queue bk_pending;
struct __queue vi_pending;
@@ -289,7 +287,6 @@ struct  xmit_priv {
u8  wmm_para_seq[4];/* sequence for wmm ac parameter strength
 * from large to small. it's value is 0->vo,
 * 1->vi, 2->be, 3->bk. */
-   struct semaphore tx_retevt;/* all tx return event; */
u8  txirp_cnt;/*  */
struct tasklet_struct xmit_tasklet;
/* per AC pending irp */
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/4] irtl8188eu: Replace semaphore cmd_queue_sema with completion

2016-06-05 Thread Binoy Jayan
The semaphore 'cmd_queue_sema' is used as completion,
so convert it to struct completion.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c| 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 7748523..a2937e7 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -27,7 +27,7 @@ No irqsave is necessary.
 
 int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
-   sema_init(&(pcmdpriv->cmd_queue_sema), 0);
+   init_completion(&pcmdpriv->cmd_queue_comp);
sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
 
_rtw_init_queue(&(pcmdpriv->cmd_queue));
@@ -122,7 +122,7 @@ u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct 
cmd_obj *cmd_obj)
res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
 
if (res == _SUCCESS)
-   up(&pcmdpriv->cmd_queue_sema);
+   complete(&pcmdpriv->cmd_queue_comp);
 
 exit:
 
@@ -167,7 +167,7 @@ int rtw_cmd_thread(void *context)
RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x 
rtw_cmd_thread \n"));
 
while (1) {
-   if (_rtw_down_sema(&pcmdpriv->cmd_queue_sema) == _FAIL)
+   if 
(wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp))
break;
 
if (padapter->bDriverStopped ||
diff --git a/drivers/staging/rtl8188eu/include/rtw_cmd.h 
b/drivers/staging/rtl8188eu/include/rtw_cmd.h
index 08ca592..3532dd1 100644
--- a/drivers/staging/rtl8188eu/include/rtw_cmd.h
+++ b/drivers/staging/rtl8188eu/include/rtw_cmd.h
@@ -39,7 +39,7 @@ struct cmd_obj {
 };
 
 struct cmd_priv {
-   struct semaphore cmd_queue_sema;
+   struct completion cmd_queue_comp;
struct semaphore terminate_cmdthread_sema;
struct __queue cmd_queue;
u8 cmdthd_running;
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c 
b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index ae2caff..a696d2b 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -772,7 +772,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n"));
 
/* Below is to terminate rtw_cmd_thread & event_thread... */
-   up(&padapter->cmdpriv.cmd_queue_sema);
+   complete(&padapter->cmdpriv.cmd_queue_comp);
if (padapter->cmdThread)
_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 4/4] staging: r8188eu: Remove unused semaphores

2016-06-05 Thread Binoy Jayan
The semaphores xmit_sema, terminate_xmitthread_sema and tx_retevt
have no users, hence remove all references to them.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
Acked-by: Larry Finger 
---
 drivers/staging/rtl8188eu/core/rtw_xmit.c | 4 
 drivers/staging/rtl8188eu/include/osdep_service.h | 1 -
 drivers/staging/rtl8188eu/include/rtw_event.h | 1 -
 drivers/staging/rtl8188eu/include/rtw_xmit.h  | 3 ---
 4 files changed, 9 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c 
b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index e0a5567..1e1b6d8 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -57,8 +57,6 @@ s32   _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct 
adapter *padapter)
/*  We don't need to memset padapter->XXX to zero, because adapter is 
allocated by vzalloc(). */
 
spin_lock_init(&pxmitpriv->lock);
-   sema_init(&pxmitpriv->xmit_sema, 0);
-   sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
 
/*
Please insert all the queue initializaiton using _rtw_init_queue below
@@ -199,8 +197,6 @@ s32 _rtw_init_xmit_priv(struct xmit_priv *pxmitpriv, struct 
adapter *padapter)
 
pxmitpriv->txirp_cnt = 1;
 
-   sema_init(&(pxmitpriv->tx_retevt), 0);
-
/* per AC pending irp */
pxmitpriv->beq_cnt = 0;
pxmitpriv->bkq_cnt = 0;
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h 
b/drivers/staging/rtl8188eu/include/osdep_service.h
index c53c9ea..6f6a8f8 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -35,7 +35,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/staging/rtl8188eu/include/rtw_event.h 
b/drivers/staging/rtl8188eu/include/rtw_event.h
index 0dc63f2..2a45581 100644
--- a/drivers/staging/rtl8188eu/include/rtw_event.h
+++ b/drivers/staging/rtl8188eu/include/rtw_event.h
@@ -18,7 +18,6 @@
 #include 
 
 #include 
-#include 
 #include 
 #include 
 
diff --git a/drivers/staging/rtl8188eu/include/rtw_xmit.h 
b/drivers/staging/rtl8188eu/include/rtw_xmit.h
index a0853ba..7895008 100644
--- a/drivers/staging/rtl8188eu/include/rtw_xmit.h
+++ b/drivers/staging/rtl8188eu/include/rtw_xmit.h
@@ -263,8 +263,6 @@ struct agg_pkt_info {
 
 struct xmit_priv {
spinlock_t lock;
-   struct semaphore xmit_sema;
-   struct semaphore terminate_xmitthread_sema;
struct __queue be_pending;
struct __queue bk_pending;
struct __queue vi_pending;
@@ -289,7 +287,6 @@ struct  xmit_priv {
u8  wmm_para_seq[4];/* sequence for wmm ac parameter strength
 * from large to small. it's value is 0->vo,
 * 1->vi, 2->be, 3->bk. */
-   struct semaphore tx_retevt;/* all tx return event; */
u8  txirp_cnt;/*  */
struct tasklet_struct xmit_tasklet;
/* per AC pending irp */
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 1/4] staging: r8188eu: Replace semaphore cmd_queue_sema with completion

2016-06-05 Thread Binoy Jayan
The semaphore 'cmd_queue_sema' is used as completion,
so convert it to struct completion.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
Acked-by: Larry Finger 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c| 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 7748523..a2937e7 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -27,7 +27,7 @@ No irqsave is necessary.
 
 int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
-   sema_init(&(pcmdpriv->cmd_queue_sema), 0);
+   init_completion(&pcmdpriv->cmd_queue_comp);
sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
 
_rtw_init_queue(&(pcmdpriv->cmd_queue));
@@ -122,7 +122,7 @@ u32 rtw_enqueue_cmd(struct cmd_priv *pcmdpriv, struct 
cmd_obj *cmd_obj)
res = _rtw_enqueue_cmd(&pcmdpriv->cmd_queue, cmd_obj);
 
if (res == _SUCCESS)
-   up(&pcmdpriv->cmd_queue_sema);
+   complete(&pcmdpriv->cmd_queue_comp);
 
 exit:
 
@@ -167,7 +167,7 @@ int rtw_cmd_thread(void *context)
RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x 
rtw_cmd_thread \n"));
 
while (1) {
-   if (_rtw_down_sema(&pcmdpriv->cmd_queue_sema) == _FAIL)
+   if 
(wait_for_completion_interruptible(&pcmdpriv->cmd_queue_comp))
break;
 
if (padapter->bDriverStopped ||
diff --git a/drivers/staging/rtl8188eu/include/rtw_cmd.h 
b/drivers/staging/rtl8188eu/include/rtw_cmd.h
index 08ca592..3532dd1 100644
--- a/drivers/staging/rtl8188eu/include/rtw_cmd.h
+++ b/drivers/staging/rtl8188eu/include/rtw_cmd.h
@@ -39,7 +39,7 @@ struct cmd_obj {
 };
 
 struct cmd_priv {
-   struct semaphore cmd_queue_sema;
+   struct completion cmd_queue_comp;
struct semaphore terminate_cmdthread_sema;
struct __queue cmd_queue;
u8 cmdthd_running;
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c 
b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index ae2caff..a696d2b 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -772,7 +772,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n"));
 
/* Below is to terminate rtw_cmd_thread & event_thread... */
-   up(&padapter->cmdpriv.cmd_queue_sema);
+   complete(&padapter->cmdpriv.cmd_queue_comp);
if (padapter->cmdThread)
_rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 2/4] staging: r8188eu: Replace semaphore terminate_cmdthread_sema with completion

2016-06-05 Thread Binoy Jayan
The semaphore 'terminate_cmdthread_sema' is used as completion,
so convert it to struct completion.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
Acked-by: Larry Finger 
---
 drivers/staging/rtl8188eu/core/rtw_cmd.c| 6 +++---
 drivers/staging/rtl8188eu/include/rtw_cmd.h | 2 +-
 drivers/staging/rtl8188eu/os_dep/os_intfs.c | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c 
b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index a2937e7..9e12588 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -28,7 +28,7 @@ No irqsave is necessary.
 int rtw_init_cmd_priv(struct cmd_priv *pcmdpriv)
 {
init_completion(&pcmdpriv->cmd_queue_comp);
-   sema_init(&(pcmdpriv->terminate_cmdthread_sema), 0);
+   init_completion(&pcmdpriv->terminate_cmdthread_comp);
 
_rtw_init_queue(&(pcmdpriv->cmd_queue));
return _SUCCESS;
@@ -162,7 +162,7 @@ int rtw_cmd_thread(void *context)
allow_signal(SIGTERM);
 
pcmdpriv->cmdthd_running = true;
-   up(&pcmdpriv->terminate_cmdthread_sema);
+   complete(&pcmdpriv->terminate_cmdthread_comp);
 
RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, ("start r871x 
rtw_cmd_thread \n"));
 
@@ -234,7 +234,7 @@ _next:
rtw_free_cmd_obj(pcmd);
}
 
-   up(&pcmdpriv->terminate_cmdthread_sema);
+   complete(&pcmdpriv->terminate_cmdthread_comp);
 
 
complete_and_exit(NULL, 0);
diff --git a/drivers/staging/rtl8188eu/include/rtw_cmd.h 
b/drivers/staging/rtl8188eu/include/rtw_cmd.h
index 3532dd1..2b53f58 100644
--- a/drivers/staging/rtl8188eu/include/rtw_cmd.h
+++ b/drivers/staging/rtl8188eu/include/rtw_cmd.h
@@ -40,7 +40,7 @@ struct cmd_obj {
 
 struct cmd_priv {
struct completion cmd_queue_comp;
-   struct semaphore terminate_cmdthread_sema;
+   struct completion terminate_cmdthread_comp;
struct __queue cmd_queue;
u8 cmdthd_running;
struct adapter *padapter;
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c 
b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index a696d2b..c494845 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -762,7 +762,7 @@ static int rtw_start_drv_threads(struct adapter *padapter)
err = PTR_ERR(padapter->cmdThread);
else
/* wait for cmd_thread to run */
-   _rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+   
wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
return err;
 }
@@ -774,7 +774,7 @@ void rtw_stop_drv_threads(struct adapter *padapter)
/* Below is to terminate rtw_cmd_thread & event_thread... */
complete(&padapter->cmdpriv.cmd_queue_comp);
if (padapter->cmdThread)
-   _rtw_down_sema(&padapter->cmdpriv.terminate_cmdthread_sema);
+   
wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
 
 }
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 3/4] staging: r8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex

2016-06-05 Thread Binoy Jayan
The semaphore 'lock' in pwrctrl_priv is a simple mutex, so it should
be written as one. Semaphores are going away in the future.
_enter_pwrlock was using down_interruptible(), so the lock could be broken
by sending a signal. This could be a bug, because nothing checks the return
code here. Hence, using mutex_lock instead of the interruptible version.
Also, remove the now unused wrappers _init_pwrlock, _enter_pwrlock,
_exit_pwrlock and _rtw_down_sema.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
Acked-by: Larry Finger 
---
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c  | 20 ++--
 drivers/staging/rtl8188eu/include/osdep_service.h |  3 +--
 drivers/staging/rtl8188eu/include/rtw_event.h |  1 +
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 ---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c   |  8 
 6 files changed, 17 insertions(+), 39 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c 
b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
index 59c6d8a..0b70fe7 100644
--- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
@@ -38,7 +38,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
LeaveAllPowerSaveMode(padapter);
 
DBG_88E("==> rtw_hw_suspend\n");
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
pwrpriv->bips_processing = true;
/* s1. */
if (pnetdev) {
@@ -73,7 +73,7 @@ static int rtw_hw_suspend(struct adapter *padapter)
pwrpriv->rf_pwrstate = rf_off;
pwrpriv->bips_processing = false;
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
return 0;
 
@@ -90,12 +90,12 @@ static int rtw_hw_resume(struct adapter *padapter)
 
/* system resume */
DBG_88E("==> rtw_hw_resume\n");
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
pwrpriv->bips_processing = true;
rtw_reset_drv_sw(padapter);
 
if (pm_netdev_open(pnetdev, false) != 0) {
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
goto error_exit;
}
 
@@ -113,7 +113,7 @@ static int rtw_hw_resume(struct adapter *padapter)
pwrpriv->rf_pwrstate = rf_on;
pwrpriv->bips_processing = false;
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
 
return 0;
@@ -138,7 +138,7 @@ void ips_enter(struct adapter *padapter)
return;
}
 
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
 
pwrpriv->bips_processing = true;
 
@@ -159,7 +159,7 @@ void ips_enter(struct adapter *padapter)
}
pwrpriv->bips_processing = false;
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 int ips_leave(struct adapter *padapter)
@@ -171,7 +171,7 @@ int ips_leave(struct adapter *padapter)
int keyid;
 
 
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
 
if ((pwrpriv->rf_pwrstate == rf_off) && (!pwrpriv->bips_processing)) {
pwrpriv->bips_processing = true;
@@ -205,7 +205,7 @@ int ips_leave(struct adapter *padapter)
pwrpriv->bpower_saving = false;
}
 
-   _exit_pwrlock(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
return result;
 }
@@ -504,7 +504,7 @@ void rtw_init_pwrctrl_priv(struct adapter *padapter)
 {
struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
 
-   _init_pwrlock(&pwrctrlpriv->lock);
+   mutex_init(&pwrctrlpriv->mutex_lock);
pwrctrlpriv->rf_pwrstate = rf_on;
pwrctrlpriv->ips_enter_cnts = 0;
pwrctrlpriv->ips_leave_cnts = 0;
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h 
b/drivers/staging/rtl8188eu/include/osdep_service.h
index 5475956..c53c9ea 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -78,8 +79,6 @@ u8 *_rtw_malloc(u32 sz);
 
 void *rtw_malloc2d(int h, int w, int size);
 
-u32  _rtw_down_sema(struct semaphore *sema);
-
 void _rtw_init_queue(struct __queue *pqueue);
 
 struct rtw_netdev_priv_indicator {
diff --git a/drivers/staging/rtl8188eu/include/rtw_event.h 
b/drivers/staging/rtl8188eu/include/rtw_event.h
index 5c34e56..0dc63f2 100644
--- a/drivers/staging/rtl8188eu/include/rtw_event.h
+++ b/drivers/staging/rtl8188eu/include/rtw_event.h
@@ -19,6 +19,7 @@
 
 #include

[PATCH v3 0/4] *** staging: r8188eu: Replace semaphores with mutexes or completions ***

2016-06-05 Thread Binoy Jayan
Hi,

These are a set of patches [v3] which removes semaphores from:

drivers/staging/rtl8188eu

These are part of a bigger effort to eliminate all semaphores 
from the linux kernel.

They build correctly (individually and as a whole).
NB: I have not tested this as I do not have the following hardware:

"Realtek RTL8188EU Wireless LAN NIC driver"

Incorporated changes w.r.t. review comments
 - Changed changelog in patch 3/4
 - Changed subject line to have driver name r8188eu
 - Removed misplaced 'i' in subject of patch 1/4

Thanks,
Binoy

Binoy Jayan (4):
  staging: r8188eu: Replace semaphore cmd_queue_sema with completion
  staging: r8188eu: Replace semaphore terminate_cmdthread_sema with
completion
  staging: r8188eu: pwrctrl_priv: Replace semaphore 'lock' with mutex
  staging: r8188eu: Remove unused semaphores

 drivers/staging/rtl8188eu/core/rtw_cmd.c  | 12 ++--
 drivers/staging/rtl8188eu/core/rtw_pwrctrl.c  | 20 ++--
 drivers/staging/rtl8188eu/core/rtw_xmit.c |  4 
 drivers/staging/rtl8188eu/include/osdep_service.h |  4 +---
 drivers/staging/rtl8188eu/include/rtw_cmd.h   |  4 ++--
 drivers/staging/rtl8188eu/include/rtw_event.h |  2 +-
 drivers/staging/rtl8188eu/include/rtw_pwrctrl.h   | 17 +
 drivers/staging/rtl8188eu/include/rtw_xmit.h  |  3 ---
 drivers/staging/rtl8188eu/os_dep/os_intfs.c   |  6 +++---
 drivers/staging/rtl8188eu/os_dep/osdep_service.c  |  7 ---
 drivers/staging/rtl8188eu/os_dep/usb_intf.c   |  8 
 11 files changed, 28 insertions(+), 59 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: r8723au: pwrctrl_priv: Replace semaphore lock with mutex

2016-06-08 Thread Binoy Jayan
The semaphore 'lock' in pwrctrl_priv is a simple mutex, so it should
be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/rtl8723au/core/rtw_pwrctrl.c| 11 ++-
 drivers/staging/rtl8723au/include/rtw_pwrctrl.h |  3 ++-
 drivers/staging/rtl8723au/os_dep/usb_intf.c | 11 ++-
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_pwrctrl.c 
b/drivers/staging/rtl8723au/core/rtw_pwrctrl.c
index 7488a10..2d43958 100644
--- a/drivers/staging/rtl8723au/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8723au/core/rtw_pwrctrl.c
@@ -14,6 +14,7 @@
  
**/
 #define _RTW_PWRCTRL_C_
 
+#include 
 #include 
 #include 
 #include 
@@ -27,7 +28,7 @@ void ips_enter23a(struct rtw_adapter *padapter)
 {
struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
 
-   down(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
 
pwrpriv->bips_processing = true;
 
@@ -50,7 +51,7 @@ void ips_enter23a(struct rtw_adapter *padapter)
}
pwrpriv->bips_processing = false;
 
-   up(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 int ips_leave23a(struct rtw_adapter *padapter)
@@ -61,7 +62,7 @@ int ips_leave23a(struct rtw_adapter *padapter)
int result = _SUCCESS;
int keyid;
 
-   down(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
 
if (pwrpriv->rf_pwrstate == rf_off && !pwrpriv->bips_processing) {
pwrpriv->bips_processing = true;
@@ -106,7 +107,7 @@ int ips_leave23a(struct rtw_adapter *padapter)
pwrpriv->bpower_saving = false;
}
 
-   up(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
return result;
 }
@@ -423,7 +424,7 @@ void rtw_init_pwrctrl_priv23a(struct rtw_adapter *padapter)
 {
struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
 
-   sema_init(&pwrctrlpriv->lock, 1);
+   mutex_init(&pwrctrlpriv->mutex_lock);
pwrctrlpriv->rf_pwrstate = rf_on;
pwrctrlpriv->ips_enter23a_cnts = 0;
pwrctrlpriv->ips_leave23a_cnts = 0;
diff --git a/drivers/staging/rtl8723au/include/rtw_pwrctrl.h 
b/drivers/staging/rtl8723au/include/rtw_pwrctrl.h
index 599fed9..699b9f3 100644
--- a/drivers/staging/rtl8723au/include/rtw_pwrctrl.h
+++ b/drivers/staging/rtl8723au/include/rtw_pwrctrl.h
@@ -15,6 +15,7 @@
 #ifndef __RTW_PWRCTRL_H_
 #define __RTW_PWRCTRL_H_
 
+#include 
 #include 
 #include 
 
@@ -149,7 +150,7 @@ enum { /*  for ips_mode */
 };
 
 struct pwrctrl_priv {
-   struct semaphore lock;
+   struct mutex mutex_lock;
volatile u8 rpwm; /* requested power state for fw */
volatile u8 cpwm; /* fw current power state. updated when 1.
   * read from HCPWM 2. driver lowers power level
diff --git a/drivers/staging/rtl8723au/os_dep/usb_intf.c 
b/drivers/staging/rtl8723au/os_dep/usb_intf.c
index cf83eff..fa7dda5 100644
--- a/drivers/staging/rtl8723au/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8723au/os_dep/usb_intf.c
@@ -14,6 +14,7 @@
  
**/
 #define _HCI_INTF_C_
 
+#include 
 #include 
 #include 
 #include 
@@ -291,7 +292,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, 
pm_message_t message)
rtw_cancel_all_timer23a(padapter);
LeaveAllPowerSaveMode23a(padapter);
 
-   down(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
/* padapter->net_closed = true; */
/* s1. */
if (pnetdev) {
@@ -321,7 +322,7 @@ static int rtw_suspend(struct usb_interface *pusb_intf, 
pm_message_t message)
rtw_free_network_queue23a(padapter);
 
rtw_dev_unload(padapter);
-   up(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 
if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
rtw_cfg80211_indicate_scan_done(
@@ -353,20 +354,20 @@ static int rtw_resume(struct usb_interface *pusb_intf)
pnetdev = padapter->pnetdev;
pwrpriv = &padapter->pwrctrlpriv;
 
-   down(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
rtw_reset_drv_sw23a(padapter);
pwrpriv->bkeepfwalive = false;
 
DBG_8723A("bkeepfwalive(%x)\n", pwrpriv->bkeepfwalive);
if (pm_netdev_open23a(pnetdev, true) != 0) {
-   up(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
goto exit;
}
 
netif_device_attach(pnetdev);
netif_carrier_on(pnetdev);
 
-   up(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mut

[PATCH 2/2] staging: r8723au: Remove unused semaphores

2016-06-08 Thread Binoy Jayan
The semaphores xmit_sema, terminate_xmitthread_sema, tx_retevt and
io_req have no users, hence remove all references to them.
Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/rtl8723au/core/rtw_xmit.c | 4 
 drivers/staging/rtl8723au/include/osdep_service.h | 1 -
 drivers/staging/rtl8723au/include/rtw_io.h| 2 --
 drivers/staging/rtl8723au/include/rtw_xmit.h  | 5 -
 4 files changed, 12 deletions(-)

diff --git a/drivers/staging/rtl8723au/core/rtw_xmit.c 
b/drivers/staging/rtl8723au/core/rtw_xmit.c
index 3de40cf..003576d 100644
--- a/drivers/staging/rtl8723au/core/rtw_xmit.c
+++ b/drivers/staging/rtl8723au/core/rtw_xmit.c
@@ -60,8 +60,6 @@ int _rtw_init_xmit_priv23a(struct xmit_priv *pxmitpriv,
 
spin_lock_init(&pxmitpriv->lock);
spin_lock_init(&pxmitpriv->lock_sctx);
-   sema_init(&pxmitpriv->xmit_sema, 0);
-   sema_init(&pxmitpriv->terminate_xmitthread_sema, 0);
 
pxmitpriv->adapter = padapter;
 
@@ -177,8 +175,6 @@ int _rtw_init_xmit_priv23a(struct xmit_priv *pxmitpriv,
for (i = 0; i < 4; i ++)
pxmitpriv->wmm_para_seq[i] = i;
 
-   sema_init(&pxmitpriv->tx_retevt, 0);
-
pxmitpriv->ack_tx = false;
mutex_init(&pxmitpriv->ack_tx_mutex);
rtw_sctx_init23a(&pxmitpriv->ack_tx_ops, 0);
diff --git a/drivers/staging/rtl8723au/include/osdep_service.h 
b/drivers/staging/rtl8723au/include/osdep_service.h
index 98250b1..33ecb9c 100644
--- a/drivers/staging/rtl8723au/include/osdep_service.h
+++ b/drivers/staging/rtl8723au/include/osdep_service.h
@@ -33,7 +33,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
diff --git a/drivers/staging/rtl8723au/include/rtw_io.h 
b/drivers/staging/rtl8723au/include/rtw_io.h
index c8119e2..d875e9e 100644
--- a/drivers/staging/rtl8723au/include/rtw_io.h
+++ b/drivers/staging/rtl8723au/include/rtw_io.h
@@ -20,7 +20,6 @@
 #include 
 
 #include 
-#include 
 #include 
 /* include  */
 #include 
@@ -105,7 +104,6 @@ struct io_req {
u32 command;
u32 status;
u8  *pbuf;
-   struct semaphoresema;
 
void (*_async_io_callback)(struct rtw_adapter *padater, struct io_req 
*pio_req, u8 *cnxt);
u8 *cnxt;
diff --git a/drivers/staging/rtl8723au/include/rtw_xmit.h 
b/drivers/staging/rtl8723au/include/rtw_xmit.h
index 2b7d6d0..24f326b 100644
--- a/drivers/staging/rtl8723au/include/rtw_xmit.h
+++ b/drivers/staging/rtl8723au/include/rtw_xmit.h
@@ -275,9 +275,6 @@ struct agg_pkt_info {
 struct xmit_priv {
spinlock_t  lock;
 
-   struct semaphorexmit_sema;
-   struct semaphoreterminate_xmitthread_sema;
-
struct rtw_queuebe_pending;
struct rtw_queuebk_pending;
struct rtw_queuevi_pending;
@@ -310,8 +307,6 @@ struct  xmit_priv {
 * 2->be, 3->bk.
 */
 
-   struct semaphoretx_retevt;/* all tx return event; */
-
struct tasklet_struct xmit_tasklet;
 
struct rtw_queue free_xmitbuf_queue;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/2] *** r8723au: Replace semaphore lock with mutex ***

2016-06-08 Thread Binoy Jayan
Hi,

These are a set of patches which removes semaphores from:

drivers/staging/rtl8723au

These are part of a bigger effort to eliminate all semaphores 
from the linux kernel.

They build correctly (individually and as a whole).
NB: I have not tested this as I do not have the following hardware:

R8723AU
"Realtek RTL8723AU Wireless LAN NIC driver"

Thanks,
Binoy

Binoy Jayan (2):
  staging: r8723au: pwrctrl_priv: Replace semaphore lock with mutex
  staging: r8723au: Remove unused semaphores

 drivers/staging/rtl8723au/core/rtw_pwrctrl.c  | 11 ++-
 drivers/staging/rtl8723au/core/rtw_xmit.c |  4 
 drivers/staging/rtl8723au/include/osdep_service.h |  1 -
 drivers/staging/rtl8723au/include/rtw_io.h|  2 --
 drivers/staging/rtl8723au/include/rtw_pwrctrl.h   |  3 ++-
 drivers/staging/rtl8723au/include/rtw_xmit.h  |  5 -
 drivers/staging/rtl8723au/os_dep/usb_intf.c   | 11 ++-
 7 files changed, 14 insertions(+), 23 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/2] staging: lustre: lloop_device: Replace semaphore lo_sem with completion

2016-06-08 Thread Binoy Jayan
The semaphore 'lo_sem' in lloop_device is used as completion, so it
should be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/lustre/lustre/llite/lloop.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/lloop.c 
b/drivers/staging/lustre/lustre/llite/lloop.c
index 813a9a3..90b31ba 100644
--- a/drivers/staging/lustre/lustre/llite/lloop.c
+++ b/drivers/staging/lustre/lustre/llite/lloop.c
@@ -131,7 +131,7 @@ struct lloop_device {
struct bio  *lo_bio;
struct bio  *lo_biotail;
int lo_state;
-   struct semaphorelo_sem;
+   struct completion   lo_comp;
struct mutexlo_ctl_mutex;
atomic_t lo_pending;
wait_queue_head_t lo_bh_wait;
@@ -423,9 +423,9 @@ static int loop_thread(void *data)
lo->lo_pvec.ldp_offsets = lo->lo_requests[0].lrd_offsets;
 
/*
-* up sem, we are running
+* signal completion, we are running
 */
-   up(&lo->lo_sem);
+   complete(&lo->lo_comp);
 
for (;;) {
wait_event(lo->lo_bh_wait, loop_active(lo));
@@ -466,7 +466,7 @@ static int loop_thread(void *data)
cl_env_put(env, &refcheck);
 
 out:
-   up(&lo->lo_sem);
+   complete(&lo->lo_comp);
return ret;
 }
 
@@ -539,7 +539,7 @@ static int loop_set_fd(struct lloop_device *lo, struct file 
*unused,
set_blocksize(bdev, lo->lo_blocksize);
 
kthread_run(loop_thread, lo, "lloop%d", lo->lo_number);
-   down(&lo->lo_sem);
+   wait_for_completion(&lo->lo_comp);
return 0;
 
 out:
@@ -568,7 +568,7 @@ static int loop_clr_fd(struct lloop_device *lo, struct 
block_device *bdev,
spin_unlock_irq(&lo->lo_lock);
wake_up(&lo->lo_bh_wait);
 
-   down(&lo->lo_sem);
+   wait_for_completion(&lo->lo_comp);
lo->lo_backing_file = NULL;
lo->lo_device = NULL;
lo->lo_offset = 0;
@@ -821,7 +821,7 @@ static int __init lloop_init(void)
goto out_mem4;
 
mutex_init(&lo->lo_ctl_mutex);
-   sema_init(&lo->lo_sem, 0);
+   init_completion(&lo->lo_comp);
init_waitqueue_head(&lo->lo_bh_wait);
lo->lo_number = i;
spin_lock_init(&lo->lo_lock);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/2] staging: lustre: lnet: Replace semaphore ln_rc_signal with completion

2016-06-08 Thread Binoy Jayan
The semaphore ln_rc_signal is used as completion, so convert it to
struct completion.  Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/lustre/include/linux/lnet/lib-types.h | 3 ++-
 drivers/staging/lustre/lnet/lnet/router.c | 9 +
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/lnet/lib-types.h 
b/drivers/staging/lustre/include/linux/lnet/lib-types.h
index 24c4a08..7967b01 100644
--- a/drivers/staging/lustre/include/linux/lnet/lib-types.h
+++ b/drivers/staging/lustre/include/linux/lnet/lib-types.h
@@ -38,6 +38,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "types.h"
 #include "lnetctl.h"
@@ -610,7 +611,7 @@ typedef struct {
/* rcd ready for free */
struct list_head  ln_rcd_zombie;
/* serialise startup/shutdown */
-   struct semaphore  ln_rc_signal;
+   struct completion ln_rc_signal;
 
struct mutex  ln_api_mutex;
struct mutex  ln_lnd_mutex;
diff --git a/drivers/staging/lustre/lnet/lnet/router.c 
b/drivers/staging/lustre/lnet/lnet/router.c
index b01dc42..0635432 100644
--- a/drivers/staging/lustre/lnet/lnet/router.c
+++ b/drivers/staging/lustre/lnet/lnet/router.c
@@ -18,6 +18,7 @@
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
+#include 
 #include "../../include/linux/lnet/lib-lnet.h"
 
 #define LNET_NRB_TINY_MIN  512 /* min value for each CPT */
@@ -1065,7 +1066,7 @@ lnet_router_checker_start(void)
return -EINVAL;
}
 
-   sema_init(&the_lnet.ln_rc_signal, 0);
+   init_completion(&the_lnet.ln_rc_signal);
 
rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh);
if (rc) {
@@ -1079,7 +1080,7 @@ lnet_router_checker_start(void)
rc = PTR_ERR(task);
CERROR("Can't start router checker thread: %d\n", rc);
/* block until event callback signals exit */
-   down(&the_lnet.ln_rc_signal);
+   wait_for_completion(&the_lnet.ln_rc_signal);
rc = LNetEQFree(the_lnet.ln_rc_eqh);
LASSERT(!rc);
the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
@@ -1112,7 +1113,7 @@ lnet_router_checker_stop(void)
wake_up(&the_lnet.ln_rc_waitq);
 
/* block until event callback signals exit */
-   down(&the_lnet.ln_rc_signal);
+   wait_for_completion(&the_lnet.ln_rc_signal);
LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
 
rc = LNetEQFree(the_lnet.ln_rc_eqh);
@@ -1295,7 +1296,7 @@ rescan:
lnet_prune_rc_data(1); /* wait for UNLINK */
 
the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
-   up(&the_lnet.ln_rc_signal);
+   complete(&the_lnet.ln_rc_signal);
/* The unlink event callback will signal final completion */
return 0;
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/2] *** staging: lustre: Replace semaphore lock with mutex ***

2016-06-08 Thread Binoy Jayan
Hi,

These are a set of patches which removes semaphores from:

drivers/staging/lustre  (lnet)

These are part of a bigger effort to eliminate all semaphores 
from the linux kernel.

They build correctly (individually and as a whole).

Thanks,
Binoy


Binoy Jayan (2):
  staging: lustre: lloop_device: Replace semaphore lo_sem with
completion
  staging: lustre: lnet: Replace semaphore ln_rc_signal with completion

 drivers/staging/lustre/include/linux/lnet/lib-types.h |  3 ++-
 drivers/staging/lustre/lnet/lnet/router.c |  9 +
 drivers/staging/lustre/lustre/llite/lloop.c   | 14 +++---
 3 files changed, 14 insertions(+), 12 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 0/7] *** staging: wilc1000: Replace semaphores with mutexes or completions ***

2016-06-13 Thread Binoy Jayan
Hi,

These are a set of patches which removes semaphores from:

drivers/staging/wilc1000

These are part of a bigger effort to eliminate all semaphores
from the linux kernel.

They build correctly (individually and as a whole).

NB: The changes are untested

Thanks,
Binoy

Binoy Jayan (7):
  staging: wilc1000: Replace semaphore txq_event with completion
  staging: wilc1000: Replace semaphore txq_add_to_head_cs with mutex
  staging: wilc1000: Replace semaphore cfg_event with completion
  staging: wilc1000: Replace semaphore sync_event with completion
  staging: wilc1000: Replace semaphore close_exit_sync with completion
  staging: wilc1000: message_queue: Replace semaphore sem with
completion
  staging: wilc1000: Remove unused inclusion of semaphore header

 drivers/staging/wilc1000/TODO |  1 -
 drivers/staging/wilc1000/linux_wlan.c | 45 ++-
 drivers/staging/wilc1000/wilc_msgqueue.c  | 13 
 drivers/staging/wilc1000/wilc_msgqueue.h  |  4 +--
 drivers/staging/wilc1000/wilc_wfi_netdevice.h | 13 
 drivers/staging/wilc1000/wilc_wlan.c  | 35 +++--
 drivers/staging/wilc1000/wilc_wlan.h  |  2 +-
 drivers/staging/wilc1000/wilc_wlan_if.h   |  1 -
 8 files changed, 52 insertions(+), 62 deletions(-)

-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 2/7] staging: wilc1000: Replace semaphore txq_add_to_head_cs with mutex

2016-06-13 Thread Binoy Jayan
The semaphore 'txq_add_to_head_cs' is a simple mutex, so it should be
written as one. Semaphores are going away in the future. Also, removing
the timeout scenario as the error handling code does not propagate the
timeout properly.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/linux_wlan.c |  4 ++--
 drivers/staging/wilc1000/wilc_wfi_netdevice.h |  3 ++-
 drivers/staging/wilc1000/wilc_wlan.c  | 11 ---
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 90f906d..a933551 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -20,7 +20,7 @@
 #include 
 #include 
 #include 
-
+#include 
 #include 
 #include 
 
@@ -679,7 +679,7 @@ static int wlan_init_locks(struct net_device *dev)
mutex_init(&wl->rxq_cs);
 
spin_lock_init(&wl->txq_spinlock);
-   sema_init(&wl->txq_add_to_head_cs, 1);
+   mutex_init(&wl->txq_add_to_head_cs);
 
init_completion(&wl->txq_event);
 
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 12d7c7b..239cd43 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -43,6 +43,7 @@
 #include "wilc_wlan.h"
 #include 
 #include 
+#include 
 
 #define FLOW_CONTROL_LOWER_THRESHOLD   128
 #define FLOW_CONTROL_UPPER_THRESHOLD   256
@@ -171,7 +172,7 @@ struct wilc {
struct wilc_vif *vif[NUM_CONCURRENT_IFC];
u8 open_ifcs;
 
-   struct semaphore txq_add_to_head_cs;
+   struct mutex txq_add_to_head_cs;
spinlock_t txq_spinlock;
 
struct mutex rxq_cs;
diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 1a57135..9afbe8d 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -99,9 +99,7 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
unsigned long flags;
struct wilc *wilc = vif->wilc;
 
-   if (wilc_lock_timeout(wilc, &wilc->txq_add_to_head_cs,
-   CFG_PKTS_TIMEOUT))
-   return -1;
+   mutex_lock(&wilc->txq_add_to_head_cs);
 
spin_lock_irqsave(&wilc->txq_spinlock, flags);
 
@@ -119,7 +117,7 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
wilc->txq_entries += 1;
 
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
-   up(&wilc->txq_add_to_head_cs);
+   mutex_unlock(&wilc->txq_add_to_head_cs);
complete(&wilc->txq_event);
 
return 0;
@@ -573,8 +571,7 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 
*txq_count)
if (wilc->quit)
break;
 
-   wilc_lock_timeout(wilc, &wilc->txq_add_to_head_cs,
-   CFG_PKTS_TIMEOUT);
+   mutex_lock(&wilc->txq_add_to_head_cs);
wilc_wlan_txq_filter_dup_tcp_ack(dev);
tqe = wilc_wlan_txq_get_first(wilc);
i = 0;
@@ -755,7 +752,7 @@ _end_:
if (ret != 1)
break;
} while (0);
-   up(&wilc->txq_add_to_head_cs);
+   mutex_unlock(&wilc->txq_add_to_head_cs);
 
wilc->txq_exit = 1;
*txq_count = wilc->txq_entries;
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 6/7] staging: wilc1000: message_queue: Replace semaphore sem with completion

2016-06-13 Thread Binoy Jayan
The semaphore 'sem' is used as completion, so convert it to a
struct completion type.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/wilc_msgqueue.c | 13 +++--
 drivers/staging/wilc1000/wilc_msgqueue.h |  4 ++--
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_msgqueue.c 
b/drivers/staging/wilc1000/wilc_msgqueue.c
index 6cb894e..80c9631 100644
--- a/drivers/staging/wilc1000/wilc_msgqueue.c
+++ b/drivers/staging/wilc1000/wilc_msgqueue.c
@@ -3,6 +3,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*!
  *  @authorsyounan
@@ -13,7 +14,7 @@
 int wilc_mq_create(struct message_queue *mq)
 {
spin_lock_init(&mq->lock);
-   sema_init(&mq->sem, 0);
+   init_completion(&mq->comp);
INIT_LIST_HEAD(&mq->msg_list);
mq->recv_count = 0;
mq->exiting = false;
@@ -34,7 +35,7 @@ int wilc_mq_destroy(struct message_queue *mq)
 
/* Release any waiting receiver thread. */
while (mq->recv_count > 0) {
-   up(&mq->sem);
+   complete(&mq->comp);
mq->recv_count--;
}
 
@@ -85,7 +86,7 @@ int wilc_mq_send(struct message_queue *mq,
 
spin_unlock_irqrestore(&mq->lock, flags);
 
-   up(&mq->sem);
+   complete(&mq->comp);
 
return 0;
 }
@@ -112,19 +113,19 @@ int wilc_mq_recv(struct message_queue *mq,
mq->recv_count++;
spin_unlock_irqrestore(&mq->lock, flags);
 
-   down(&mq->sem);
+   wait_for_completion(&mq->comp);
spin_lock_irqsave(&mq->lock, flags);
 
if (list_empty(&mq->msg_list)) {
spin_unlock_irqrestore(&mq->lock, flags);
-   up(&mq->sem);
+   complete(&mq->comp);
return -EFAULT;
}
/* check buffer size */
msg = list_first_entry(&mq->msg_list, struct message, list);
if (recv_buf_size < msg->len) {
spin_unlock_irqrestore(&mq->lock, flags);
-   up(&mq->sem);
+   complete(&mq->comp);
return -EOVERFLOW;
}
 
diff --git a/drivers/staging/wilc1000/wilc_msgqueue.h 
b/drivers/staging/wilc1000/wilc_msgqueue.h
index 846a484..a7a2e55 100644
--- a/drivers/staging/wilc1000/wilc_msgqueue.h
+++ b/drivers/staging/wilc1000/wilc_msgqueue.h
@@ -1,7 +1,7 @@
 #ifndef __WILC_MSG_QUEUE_H__
 #define __WILC_MSG_QUEUE_H__
 
-#include 
+#include 
 #include 
 
 struct message {
@@ -11,7 +11,7 @@ struct message {
 };
 
 struct message_queue {
-   struct semaphore sem;
+   struct completion comp;
spinlock_t lock;
bool exiting;
u32 recv_count;
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 3/7] staging: wilc1000: Replace semaphore cfg_event with completion

2016-06-13 Thread Binoy Jayan
The semaphore 'cfg_event' is used as completion, so convert
it to a struct completion type.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/linux_wlan.c |  2 +-
 drivers/staging/wilc1000/wilc_wfi_netdevice.h |  2 +-
 drivers/staging/wilc1000/wilc_wlan.c  | 16 +---
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index a933551..81a469a 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -683,7 +683,7 @@ static int wlan_init_locks(struct net_device *dev)
 
init_completion(&wl->txq_event);
 
-   sema_init(&wl->cfg_event, 0);
+   init_completion(&wl->cfg_event);
sema_init(&wl->sync_event, 0);
init_completion(&wl->txq_thread_started);
 
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 239cd43..5fbc07c 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -178,7 +178,7 @@ struct wilc {
struct mutex rxq_cs;
struct mutex hif_cs;
 
-   struct semaphore cfg_event;
+   struct completion cfg_event;
struct semaphore sync_event;
struct completion txq_event;
struct completion txq_thread_started;
diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 9afbe8d..2d6eb43 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -310,7 +310,7 @@ static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, 
u8 *buffer,
netdev_dbg(vif->ndev, "Adding config packet ...\n");
if (wilc->quit) {
netdev_dbg(vif->ndev, "Return due to clear function\n");
-   up(&wilc->cfg_event);
+   complete(&wilc->cfg_event);
return 0;
}
 
@@ -769,7 +769,7 @@ static void wilc_wlan_handle_rxq(struct wilc *wilc)
 
do {
if (wilc->quit) {
-   up(&wilc->cfg_event);
+   complete(&wilc->cfg_event);
break;
}
rqe = wilc_wlan_rxq_remove(wilc);
@@ -820,7 +820,7 @@ static void wilc_wlan_handle_rxq(struct wilc *wilc)
wilc_wlan_cfg_indicate_rx(wilc, 
&buffer[pkt_offset + offset], pkt_len, &rsp);
if (rsp.type == WILC_CFG_RSP) {
if (wilc->cfg_seq_no == 
rsp.seq_no)
-   up(&wilc->cfg_event);
+   
complete(&wilc->cfg_event);
} else if (rsp.type == 
WILC_CFG_RSP_STATUS) {
wilc_mac_indicate(wilc, 
WILC_MAC_INDICATE_STATUS);
 
@@ -1228,11 +1228,12 @@ int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, 
u16 wid, u8 *buffer,
if (wilc_wlan_cfg_commit(vif, WILC_CFG_SET, drv_handler))
ret_size = 0;
 
-   if (wilc_lock_timeout(wilc, &wilc->cfg_event,
-   CFG_PKTS_TIMEOUT)) {
+   if (!wait_for_completion_timeout(&wilc->cfg_event,
+   msecs_to_jiffies(CFG_PKTS_TIMEOUT))) {
netdev_dbg(vif->ndev, "Set Timed Out\n");
ret_size = 0;
}
+
wilc->cfg_frame_in_use = 0;
wilc->cfg_frame_offset = 0;
wilc->cfg_seq_no += 1;
@@ -1246,6 +1247,7 @@ int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, 
u16 wid, int commit,
 {
u32 offset;
int ret_size;
+
struct wilc *wilc = vif->wilc;
 
if (wilc->cfg_frame_in_use)
@@ -1265,8 +1267,8 @@ int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, 
u16 wid, int commit,
if (wilc_wlan_cfg_commit(vif, WILC_CFG_QUERY, drv_handler))
ret_size = 0;
 
-   if (wilc_lock_timeout(wilc, &wilc->cfg_event,
-   CFG_PKTS_TIMEOUT)) {
+   if (!wait_for_completion_timeout(&wilc->cfg_event,
+   msecs_to_jiffies(CFG_PKTS_TIMEOUT))) {
netdev_dbg(vif->ndev, "Get Timed Out\n");
ret_size = 0;
}
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 1/7] staging: wilc1000: Replace semaphore txq_event with completion

2016-06-13 Thread Binoy Jayan
The semaphore 'txq_event' is used as completion, so convert it
to a struct completion type.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/linux_wlan.c | 8 
 drivers/staging/wilc1000/wilc_wfi_netdevice.h | 3 ++-
 drivers/staging/wilc1000/wilc_wlan.c  | 8 +---
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 4f93c11..90f906d 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -316,7 +316,7 @@ static int linux_wlan_txq_task(void *vp)
 
complete(&wl->txq_thread_started);
while (1) {
-   down(&wl->txq_event);
+   wait_for_completion(&wl->txq_event);
 
if (wl->close) {
complete(&wl->txq_thread_started);
@@ -650,7 +650,7 @@ void wilc1000_wlan_deinit(struct net_device *dev)
mutex_unlock(&wl->hif_cs);
}
if (&wl->txq_event)
-   up(&wl->txq_event);
+   wait_for_completion(&wl->txq_event);
 
wlan_deinitialize_threads(dev);
deinit_irq(dev);
@@ -681,7 +681,7 @@ static int wlan_init_locks(struct net_device *dev)
spin_lock_init(&wl->txq_spinlock);
sema_init(&wl->txq_add_to_head_cs, 1);
 
-   sema_init(&wl->txq_event, 0);
+   init_completion(&wl->txq_event);
 
sema_init(&wl->cfg_event, 0);
sema_init(&wl->sync_event, 0);
@@ -738,7 +738,7 @@ static void wlan_deinitialize_threads(struct net_device 
*dev)
wl->close = 1;
 
if (&wl->txq_event)
-   up(&wl->txq_event);
+   complete(&wl->txq_event);
 
if (wl->txq_thread) {
kthread_stop(wl->txq_thread);
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 3a561df6..12d7c7b 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -42,6 +42,7 @@
 #include "host_interface.h"
 #include "wilc_wlan.h"
 #include 
+#include 
 
 #define FLOW_CONTROL_LOWER_THRESHOLD   128
 #define FLOW_CONTROL_UPPER_THRESHOLD   256
@@ -178,7 +179,7 @@ struct wilc {
 
struct semaphore cfg_event;
struct semaphore sync_event;
-   struct semaphore txq_event;
+   struct completion txq_event;
struct completion txq_thread_started;
 
struct task_struct *txq_thread;
diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 11e16d5..1a57135 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -1,3 +1,4 @@
+#include 
 #include "wilc_wlan_if.h"
 #include "wilc_wlan.h"
 #include "wilc_wfi_netdevice.h"
@@ -89,7 +90,7 @@ static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
 
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
 
-   up(&wilc->txq_event);
+   complete(&wilc->txq_event);
 }
 
 static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
@@ -119,7 +120,7 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
 
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
up(&wilc->txq_add_to_head_cs);
-   up(&wilc->txq_event);
+   complete(&wilc->txq_event);
 
return 0;
 }
@@ -287,7 +288,8 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct 
net_device *dev)
spin_unlock_irqrestore(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
 
while (dropped > 0) {
-   wilc_lock_timeout(wilc, &wilc->txq_event, 1);
+   wait_for_completion_timeout(&wilc->txq_event,
+   msecs_to_jiffies(1));
dropped--;
}
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 4/7] staging: wilc1000: Replace semaphore sync_event with completion

2016-06-13 Thread Binoy Jayan
The semaphore 'sync_event' is used as completion, so convert
it to a struct completion type. Also, return -ETIME if the return
value of wait_for_completion_timeout is 0.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/linux_wlan.c | 10 +-
 drivers/staging/wilc1000/wilc_wfi_netdevice.h |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 81a469a..39fe350 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -241,7 +241,7 @@ void wilc_mac_indicate(struct wilc *wilc, int flag)
  (unsigned char *)&status, 4);
if (wilc->mac_status == WILC_MAC_STATUS_INIT) {
wilc->mac_status = status;
-   up(&wilc->sync_event);
+   complete(&wilc->sync_event);
} else {
wilc->mac_status = status;
}
@@ -386,9 +386,9 @@ static int linux_wlan_start_firmware(struct net_device *dev)
if (ret < 0)
return ret;
 
-   ret = wilc_lock_timeout(wilc, &wilc->sync_event, 5000);
-   if (ret)
-   return ret;
+   if (!wait_for_completion_timeout(&wilc->sync_event,
+   msecs_to_jiffies(5000)))
+   return -ETIME;
 
return 0;
 }
@@ -684,7 +684,7 @@ static int wlan_init_locks(struct net_device *dev)
init_completion(&wl->txq_event);
 
init_completion(&wl->cfg_event);
-   sema_init(&wl->sync_event, 0);
+   init_completion(&wl->sync_event);
init_completion(&wl->txq_thread_started);
 
return 0;
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 5fbc07c..5cc6a82 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -179,7 +179,7 @@ struct wilc {
struct mutex hif_cs;
 
struct completion cfg_event;
-   struct semaphore sync_event;
+   struct completion sync_event;
struct completion txq_event;
struct completion txq_thread_started;
 
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 5/7] staging: wilc1000: Replace semaphore close_exit_sync with completion

2016-06-13 Thread Binoy Jayan
The semaphore 'close_exit_sync' is used as completion, so convert
it to a struct completion type.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/linux_wlan.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 39fe350..ac537c7 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -31,7 +31,7 @@ static struct notifier_block g_dev_notifier = {
.notifier_call = dev_state_ev_handler
 };
 
-static struct semaphore close_exit_sync;
+static struct completion close_exit_sync;
 
 static int wlan_deinit_locks(struct net_device *dev);
 static void wlan_deinitialize_threads(struct net_device *dev);
@@ -1088,7 +1088,7 @@ int wilc_mac_close(struct net_device *ndev)
WILC_WFI_deinit_mon_interface();
}
 
-   up(&close_exit_sync);
+   complete(&close_exit_sync);
vif->mac_opened = 0;
 
return 0;
@@ -1232,7 +1232,8 @@ void wilc_netdev_cleanup(struct wilc *wilc)
}
 
if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) {
-   wilc_lock_timeout(wilc, &close_exit_sync, 5 * 1000);
+   wait_for_completion_timeout(&close_exit_sync,
+   msecs_to_jiffies(5000));
 
for (i = 0; i < NUM_CONCURRENT_IFC; i++)
if (wilc->vif[i]->ndev)
@@ -1258,7 +1259,7 @@ int wilc_netdev_init(struct wilc **wilc, struct device 
*dev, int io_type,
struct net_device *ndev;
struct wilc *wl;
 
-   sema_init(&close_exit_sync, 0);
+   init_completion(&close_exit_sync);
 
wl = kzalloc(sizeof(*wl), GFP_KERNEL);
if (!wl)
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH 7/7] staging: wilc1000: Remove unused inclusion of semaphore header

2016-06-13 Thread Binoy Jayan
Remove unused inclusions of semaphore header and remove the same
from the todo list. Also remove the now unused wrapper 'wilc_lock_timeout'.
Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/TODO |  1 -
 drivers/staging/wilc1000/linux_wlan.c | 12 
 drivers/staging/wilc1000/wilc_wfi_netdevice.h |  3 +--
 drivers/staging/wilc1000/wilc_wlan.h  |  2 +-
 drivers/staging/wilc1000/wilc_wlan_if.h   |  1 -
 5 files changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/wilc1000/TODO b/drivers/staging/wilc1000/TODO
index 95199d8..83e66b2 100644
--- a/drivers/staging/wilc1000/TODO
+++ b/drivers/staging/wilc1000/TODO
@@ -3,7 +3,6 @@ TODO:
 - remove OS wrapper functions
 - remove custom debug and tracing functions
 - rework comments and function headers(also coding style)
-- replace all semaphores with mutexes or completions
 - make spi and sdio components coexist in one build
 - turn compile-time platform configuration (BEAGLE_BOARD,
   PANDA_BOARD, PLAT_WMS8304, PLAT_RK, CUSTOMER_PLATFORM, ...)
diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index ac537c7..66c1dd7 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 
 static int dev_state_ev_handler(struct notifier_block *this,
@@ -221,17 +220,6 @@ static void deinit_irq(struct net_device *dev)
}
 }
 
-int wilc_lock_timeout(struct wilc *nic, void *vp, u32 timeout)
-{
-   /* FIXME: replace with mutex_lock or wait_for_completion */
-   int error = -1;
-
-   if (vp)
-   error = down_timeout(vp,
-msecs_to_jiffies(timeout));
-   return error;
-}
-
 void wilc_mac_indicate(struct wilc *wilc, int flag)
 {
int status;
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 5cc6a82..b1db761 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -131,7 +131,7 @@ struct wilc_priv {
struct wilc_wfi_key *wilc_gtk[MAX_NUM_STA];
struct wilc_wfi_key *wilc_ptk[MAX_NUM_STA];
u8 wilc_groupkey;
-   /* semaphores */
+   /* locks */
struct mutex scan_req_lock;
/*  */
bool gbAutoRateAdjusted;
@@ -225,7 +225,6 @@ int wilc1000_wlan_init(struct net_device *dev, struct 
wilc_vif *vif);
 
 void wilc_frmw_to_linux(struct wilc *wilc, u8 *buff, u32 size, u32 pkt_offset);
 void wilc_mac_indicate(struct wilc *wilc, int flag);
-int wilc_lock_timeout(struct wilc *wilc, void *, u32 timeout);
 void wilc_netdev_cleanup(struct wilc *wilc);
 int wilc_netdev_init(struct wilc **wilc, struct device *, int io_type, int 
gpio,
 const struct wilc_hif_func *ops);
diff --git a/drivers/staging/wilc1000/wilc_wlan.h 
b/drivers/staging/wilc1000/wilc_wlan.h
index 30e5312..de6c4dd 100644
--- a/drivers/staging/wilc1000/wilc_wlan.h
+++ b/drivers/staging/wilc1000/wilc_wlan.h
@@ -192,7 +192,7 @@
 
 #define ENABLE_RX_VMM  (SEL_VMM_TBL1 | EN_VMM)
 #define ENABLE_TX_VMM  (SEL_VMM_TBL0 | EN_VMM)
-/*time for expiring the semaphores of cfg packets*/
+/*time for expiring the completion of cfg packets*/
 #define CFG_PKTS_TIMEOUT   2000
 /
  *
diff --git a/drivers/staging/wilc1000/wilc_wlan_if.h 
b/drivers/staging/wilc1000/wilc_wlan_if.h
index 410bfc0..439ac6f 100644
--- a/drivers/staging/wilc1000/wilc_wlan_if.h
+++ b/drivers/staging/wilc1000/wilc_wlan_if.h
@@ -10,7 +10,6 @@
 #ifndef WILC_WLAN_IF_H
 #define WILC_WLAN_IF_H
 
-#include 
 #include 
 
 /
-- 
2.7.4

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: gdm724x: Replace semaphore netlink with mutex

2016-06-13 Thread Binoy Jayan
Replace semaphore netlink_mutex with mutex. Semaphores are
going away in the future.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/gdm724x/netlink_k.c | 12 ++--
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/gdm724x/netlink_k.c 
b/drivers/staging/gdm724x/netlink_k.c
index a0232e8..57db83d 100644
--- a/drivers/staging/gdm724x/netlink_k.c
+++ b/drivers/staging/gdm724x/netlink_k.c
@@ -21,13 +21,7 @@
 
 #include "netlink_k.h"
 
-#if defined(DEFINE_MUTEX)
-static DEFINE_MUTEX(netlink_mutex);
-#else
-static struct semaphore netlink_mutex;
-#define mutex_lock(x)  down(x)
-#define mutex_unlock(x)up(x)
-#endif
+static struct mutex netlink_mutex;
 
 #define ND_MAX_GROUP   30
 #define ND_IFINDEX_LEN sizeof(int)
@@ -96,9 +90,7 @@ struct sock *netlink_init(int unit,
.input  = netlink_rcv,
};
 
-#if !defined(DEFINE_MUTEX)
-   init_MUTEX(&netlink_mutex);
-#endif
+   mutex_init(&netlink_mutex);
 
sock = netlink_kernel_create(&init_net, unit, &cfg);
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 0/7] *** staging: wilc1000: Replace semaphores with mutexes or completions ***

2016-06-13 Thread Binoy Jayan
On 13 June 2016 at 19:59, Arnd Bergmann  wrote:
> On Monday, June 13, 2016 4:07:32 PM CEST Binoy Jayan wrote:
>> Hi,
>>
>> These are a set of patches which removes semaphores from:
>>
>> drivers/staging/wilc1000
>>
>> These are part of a bigger effort to eliminate all semaphores
>> from the linux kernel.
>>
>> They build correctly (individually and as a whole).
>>
>> NB: The changes are untested
>>
>
> Most of these look really good, but I've commented on what I think
> should be done differently, most importantly using a work_queue
> rather than a completion to replace the semaphore in patch 6.
>
> Maybe you can resend the first five patches after addressing
> my comments so we can get those tested and queued already while
> you look into reworking patch 6. Let me know if that one ends up
> being more complicated than I thought so we can come up with
> a different approach.
>
> Arnd

Thank you for reviewing the patches thoroughly. I overlooked the
problem with using
completion directly. Thank you for pointing that out. As you have
suggested, I'll rework
on the first 5 patches and work on the last one.

Binoy
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 0/5] *** staging: wilc1000: Replace semaphores with mutexes or completions ***

2016-06-14 Thread Binoy Jayan
These are a set of patches [v2] which removes semaphores from:

drivers/staging/wilc1000

These are part of a bigger effort to eliminate all semaphores
from the linux kernel.

They build correctly (individually and as a whole).

NB: The changes are untested

Changes w.r.t. review comments on v1

1. Whitespace removed in patch 3
2. Removed semaphore 'close_exit_sync'
3. To rework on patch 6 and send in a seperate patch series

Binoy Jayan (5):
  staging: wilc1000: Replace semaphore txq_event with completion
  staging: wilc1000: Replace semaphore txq_add_to_head_cs with mutex
  staging: wilc1000: Replace semaphore cfg_event with completion
  staging: wilc1000: Replace semaphore sync_event with completion
  staging: wilc1000: Remove semaphore close_exit_sync

 drivers/staging/wilc1000/linux_wlan.c | 31 ++--
 drivers/staging/wilc1000/wilc_wfi_netdevice.h | 10 
 drivers/staging/wilc1000/wilc_wlan.c  | 34 +--
 3 files changed, 35 insertions(+), 40 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/5] staging: wilc1000: Replace semaphore txq_event with completion

2016-06-14 Thread Binoy Jayan
The semaphore 'txq_event' is used as completion, so convert it
to a struct completion type.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/linux_wlan.c | 8 
 drivers/staging/wilc1000/wilc_wfi_netdevice.h | 3 ++-
 drivers/staging/wilc1000/wilc_wlan.c  | 8 +---
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 4f93c11..90f906d 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -316,7 +316,7 @@ static int linux_wlan_txq_task(void *vp)
 
complete(&wl->txq_thread_started);
while (1) {
-   down(&wl->txq_event);
+   wait_for_completion(&wl->txq_event);
 
if (wl->close) {
complete(&wl->txq_thread_started);
@@ -650,7 +650,7 @@ void wilc1000_wlan_deinit(struct net_device *dev)
mutex_unlock(&wl->hif_cs);
}
if (&wl->txq_event)
-   up(&wl->txq_event);
+   wait_for_completion(&wl->txq_event);
 
wlan_deinitialize_threads(dev);
deinit_irq(dev);
@@ -681,7 +681,7 @@ static int wlan_init_locks(struct net_device *dev)
spin_lock_init(&wl->txq_spinlock);
sema_init(&wl->txq_add_to_head_cs, 1);
 
-   sema_init(&wl->txq_event, 0);
+   init_completion(&wl->txq_event);
 
sema_init(&wl->cfg_event, 0);
sema_init(&wl->sync_event, 0);
@@ -738,7 +738,7 @@ static void wlan_deinitialize_threads(struct net_device 
*dev)
wl->close = 1;
 
if (&wl->txq_event)
-   up(&wl->txq_event);
+   complete(&wl->txq_event);
 
if (wl->txq_thread) {
kthread_stop(wl->txq_thread);
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 3a561df6..12d7c7b 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -42,6 +42,7 @@
 #include "host_interface.h"
 #include "wilc_wlan.h"
 #include 
+#include 
 
 #define FLOW_CONTROL_LOWER_THRESHOLD   128
 #define FLOW_CONTROL_UPPER_THRESHOLD   256
@@ -178,7 +179,7 @@ struct wilc {
 
struct semaphore cfg_event;
struct semaphore sync_event;
-   struct semaphore txq_event;
+   struct completion txq_event;
struct completion txq_thread_started;
 
struct task_struct *txq_thread;
diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 11e16d5..1a57135 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -1,3 +1,4 @@
+#include 
 #include "wilc_wlan_if.h"
 #include "wilc_wlan.h"
 #include "wilc_wfi_netdevice.h"
@@ -89,7 +90,7 @@ static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
 
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
 
-   up(&wilc->txq_event);
+   complete(&wilc->txq_event);
 }
 
 static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
@@ -119,7 +120,7 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
 
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
up(&wilc->txq_add_to_head_cs);
-   up(&wilc->txq_event);
+   complete(&wilc->txq_event);
 
return 0;
 }
@@ -287,7 +288,8 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct 
net_device *dev)
spin_unlock_irqrestore(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
 
while (dropped > 0) {
-   wilc_lock_timeout(wilc, &wilc->txq_event, 1);
+   wait_for_completion_timeout(&wilc->txq_event,
+   msecs_to_jiffies(1));
dropped--;
}
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 0/5] *** staging: wilc1000: Replace semaphores with mutexes or completions ***

2016-06-14 Thread Binoy Jayan
These are a set of patches [v3] which removes semaphores from:

drivers/staging/wilc1000

These are part of a bigger effort to eliminate all semaphores
from the linux kernel.

They build correctly (individually and as a whole).

NB: The changes are untested

Changes w.r.t. review comments on v1

1. Whitespace removed in patch 3
2. Removed semaphore 'close_exit_sync'
3. To rework on patch 6 and send in a seperate patch series

Binoy Jayan (5):
  staging: wilc1000: Replace semaphore txq_event with completion
  staging: wilc1000: Replace semaphore txq_add_to_head_cs with mutex
  staging: wilc1000: Replace semaphore cfg_event with completion
  staging: wilc1000: Replace semaphore sync_event with completion
  staging: wilc1000: Remove semaphore close_exit_sync

 drivers/staging/wilc1000/linux_wlan.c | 31 ++--
 drivers/staging/wilc1000/wilc_wfi_netdevice.h | 10 
 drivers/staging/wilc1000/wilc_wlan.c  | 34 +--
 3 files changed, 35 insertions(+), 40 deletions(-)

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 1/5] staging: wilc1000: Replace semaphore txq_event with completion

2016-06-14 Thread Binoy Jayan
The semaphore 'txq_event' is used as completion, so convert it
to a struct completion type.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/wilc1000/linux_wlan.c | 8 
 drivers/staging/wilc1000/wilc_wfi_netdevice.h | 3 ++-
 drivers/staging/wilc1000/wilc_wlan.c  | 8 +---
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 4f93c11..90f906d 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -316,7 +316,7 @@ static int linux_wlan_txq_task(void *vp)
 
complete(&wl->txq_thread_started);
while (1) {
-   down(&wl->txq_event);
+   wait_for_completion(&wl->txq_event);
 
if (wl->close) {
complete(&wl->txq_thread_started);
@@ -650,7 +650,7 @@ void wilc1000_wlan_deinit(struct net_device *dev)
mutex_unlock(&wl->hif_cs);
}
if (&wl->txq_event)
-   up(&wl->txq_event);
+   wait_for_completion(&wl->txq_event);
 
wlan_deinitialize_threads(dev);
deinit_irq(dev);
@@ -681,7 +681,7 @@ static int wlan_init_locks(struct net_device *dev)
spin_lock_init(&wl->txq_spinlock);
sema_init(&wl->txq_add_to_head_cs, 1);
 
-   sema_init(&wl->txq_event, 0);
+   init_completion(&wl->txq_event);
 
sema_init(&wl->cfg_event, 0);
sema_init(&wl->sync_event, 0);
@@ -738,7 +738,7 @@ static void wlan_deinitialize_threads(struct net_device 
*dev)
wl->close = 1;
 
if (&wl->txq_event)
-   up(&wl->txq_event);
+   complete(&wl->txq_event);
 
if (wl->txq_thread) {
kthread_stop(wl->txq_thread);
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 3a561df6..12d7c7b 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -42,6 +42,7 @@
 #include "host_interface.h"
 #include "wilc_wlan.h"
 #include 
+#include 
 
 #define FLOW_CONTROL_LOWER_THRESHOLD   128
 #define FLOW_CONTROL_UPPER_THRESHOLD   256
@@ -178,7 +179,7 @@ struct wilc {
 
struct semaphore cfg_event;
struct semaphore sync_event;
-   struct semaphore txq_event;
+   struct completion txq_event;
struct completion txq_thread_started;
 
struct task_struct *txq_thread;
diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 11e16d5..1a57135 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -1,3 +1,4 @@
+#include 
 #include "wilc_wlan_if.h"
 #include "wilc_wlan.h"
 #include "wilc_wfi_netdevice.h"
@@ -89,7 +90,7 @@ static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
 
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
 
-   up(&wilc->txq_event);
+   complete(&wilc->txq_event);
 }
 
 static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
@@ -119,7 +120,7 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
 
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
up(&wilc->txq_add_to_head_cs);
-   up(&wilc->txq_event);
+   complete(&wilc->txq_event);
 
return 0;
 }
@@ -287,7 +288,8 @@ static int wilc_wlan_txq_filter_dup_tcp_ack(struct 
net_device *dev)
spin_unlock_irqrestore(&wilc->txq_spinlock, wilc->txq_spinlock_flags);
 
while (dropped > 0) {
-   wilc_lock_timeout(wilc, &wilc->txq_event, 1);
+   wait_for_completion_timeout(&wilc->txq_event,
+   msecs_to_jiffies(1));
dropped--;
}
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 2/5] staging: wilc1000: Replace semaphore txq_add_to_head_cs with mutex

2016-06-14 Thread Binoy Jayan
The semaphore 'txq_add_to_head_cs' is a simple mutex, so it should be
written as one. Semaphores are going away in the future. Also, removing
the timeout scenario as the error handling code does not propagate the
timeout properly.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/wilc1000/linux_wlan.c |  4 ++--
 drivers/staging/wilc1000/wilc_wfi_netdevice.h |  3 ++-
 drivers/staging/wilc1000/wilc_wlan.c  | 11 ---
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 90f906d..a933551 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -20,7 +20,7 @@
 #include 
 #include 
 #include 
-
+#include 
 #include 
 #include 
 
@@ -679,7 +679,7 @@ static int wlan_init_locks(struct net_device *dev)
mutex_init(&wl->rxq_cs);
 
spin_lock_init(&wl->txq_spinlock);
-   sema_init(&wl->txq_add_to_head_cs, 1);
+   mutex_init(&wl->txq_add_to_head_cs);
 
init_completion(&wl->txq_event);
 
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 12d7c7b..239cd43 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -43,6 +43,7 @@
 #include "wilc_wlan.h"
 #include 
 #include 
+#include 
 
 #define FLOW_CONTROL_LOWER_THRESHOLD   128
 #define FLOW_CONTROL_UPPER_THRESHOLD   256
@@ -171,7 +172,7 @@ struct wilc {
struct wilc_vif *vif[NUM_CONCURRENT_IFC];
u8 open_ifcs;
 
-   struct semaphore txq_add_to_head_cs;
+   struct mutex txq_add_to_head_cs;
spinlock_t txq_spinlock;
 
struct mutex rxq_cs;
diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 1a57135..9afbe8d 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -99,9 +99,7 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
unsigned long flags;
struct wilc *wilc = vif->wilc;
 
-   if (wilc_lock_timeout(wilc, &wilc->txq_add_to_head_cs,
-   CFG_PKTS_TIMEOUT))
-   return -1;
+   mutex_lock(&wilc->txq_add_to_head_cs);
 
spin_lock_irqsave(&wilc->txq_spinlock, flags);
 
@@ -119,7 +117,7 @@ static int wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
wilc->txq_entries += 1;
 
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
-   up(&wilc->txq_add_to_head_cs);
+   mutex_unlock(&wilc->txq_add_to_head_cs);
complete(&wilc->txq_event);
 
return 0;
@@ -573,8 +571,7 @@ int wilc_wlan_handle_txq(struct net_device *dev, u32 
*txq_count)
if (wilc->quit)
break;
 
-   wilc_lock_timeout(wilc, &wilc->txq_add_to_head_cs,
-   CFG_PKTS_TIMEOUT);
+   mutex_lock(&wilc->txq_add_to_head_cs);
wilc_wlan_txq_filter_dup_tcp_ack(dev);
tqe = wilc_wlan_txq_get_first(wilc);
i = 0;
@@ -755,7 +752,7 @@ _end_:
if (ret != 1)
break;
} while (0);
-   up(&wilc->txq_add_to_head_cs);
+   mutex_unlock(&wilc->txq_add_to_head_cs);
 
wilc->txq_exit = 1;
*txq_count = wilc->txq_entries;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 4/5] staging: wilc1000: Replace semaphore sync_event with completion

2016-06-14 Thread Binoy Jayan
The semaphore 'sync_event' is used as completion, so convert
it to a struct completion type. Also, return -ETIME if the return
value of wait_for_completion_timeout is 0.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/wilc1000/linux_wlan.c | 10 +-
 drivers/staging/wilc1000/wilc_wfi_netdevice.h |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 81a469a..39fe350 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -241,7 +241,7 @@ void wilc_mac_indicate(struct wilc *wilc, int flag)
  (unsigned char *)&status, 4);
if (wilc->mac_status == WILC_MAC_STATUS_INIT) {
wilc->mac_status = status;
-   up(&wilc->sync_event);
+   complete(&wilc->sync_event);
} else {
wilc->mac_status = status;
}
@@ -386,9 +386,9 @@ static int linux_wlan_start_firmware(struct net_device *dev)
if (ret < 0)
return ret;
 
-   ret = wilc_lock_timeout(wilc, &wilc->sync_event, 5000);
-   if (ret)
-   return ret;
+   if (!wait_for_completion_timeout(&wilc->sync_event,
+   msecs_to_jiffies(5000)))
+   return -ETIME;
 
return 0;
 }
@@ -684,7 +684,7 @@ static int wlan_init_locks(struct net_device *dev)
init_completion(&wl->txq_event);
 
init_completion(&wl->cfg_event);
-   sema_init(&wl->sync_event, 0);
+   init_completion(&wl->sync_event);
init_completion(&wl->txq_thread_started);
 
return 0;
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 5fbc07c..5cc6a82 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -179,7 +179,7 @@ struct wilc {
struct mutex hif_cs;
 
struct completion cfg_event;
-   struct semaphore sync_event;
+   struct completion sync_event;
struct completion txq_event;
struct completion txq_thread_started;
 
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 5/5] staging: wilc1000: Remove semaphore close_exit_sync

2016-06-14 Thread Binoy Jayan
The semaphore 'close_exit_sync' does not serve any purpose other
than delaying the deregistration of the device which it is trying
to protect from shared access. 'up' is called only when a subdevice
is closed and not when it is opened. So, the semaphore count only
goes up when the device is used.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/wilc1000/linux_wlan.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 39fe350..f87a30f 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -31,8 +31,6 @@ static struct notifier_block g_dev_notifier = {
.notifier_call = dev_state_ev_handler
 };
 
-static struct semaphore close_exit_sync;
-
 static int wlan_deinit_locks(struct net_device *dev);
 static void wlan_deinitialize_threads(struct net_device *dev);
 
@@ -1088,7 +1086,6 @@ int wilc_mac_close(struct net_device *ndev)
WILC_WFI_deinit_mon_interface();
}
 
-   up(&close_exit_sync);
vif->mac_opened = 0;
 
return 0;
@@ -1232,8 +1229,6 @@ void wilc_netdev_cleanup(struct wilc *wilc)
}
 
if (wilc && (wilc->vif[0]->ndev || wilc->vif[1]->ndev)) {
-   wilc_lock_timeout(wilc, &close_exit_sync, 5 * 1000);
-
for (i = 0; i < NUM_CONCURRENT_IFC; i++)
if (wilc->vif[i]->ndev)
if (vif[i]->mac_opened)
@@ -1258,8 +1253,6 @@ int wilc_netdev_init(struct wilc **wilc, struct device 
*dev, int io_type,
struct net_device *ndev;
struct wilc *wl;
 
-   sema_init(&close_exit_sync, 0);
-
wl = kzalloc(sizeof(*wl), GFP_KERNEL);
if (!wl)
return -ENOMEM;
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 3/5] staging: wilc1000: Replace semaphore cfg_event with completion

2016-06-14 Thread Binoy Jayan
The semaphore 'cfg_event' is used as completion, so convert
it to a struct completion type.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/wilc1000/linux_wlan.c |  2 +-
 drivers/staging/wilc1000/wilc_wfi_netdevice.h |  2 +-
 drivers/staging/wilc1000/wilc_wlan.c  | 15 ---
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index a933551..81a469a 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -683,7 +683,7 @@ static int wlan_init_locks(struct net_device *dev)
 
init_completion(&wl->txq_event);
 
-   sema_init(&wl->cfg_event, 0);
+   init_completion(&wl->cfg_event);
sema_init(&wl->sync_event, 0);
init_completion(&wl->txq_thread_started);
 
diff --git a/drivers/staging/wilc1000/wilc_wfi_netdevice.h 
b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
index 239cd43..5fbc07c 100644
--- a/drivers/staging/wilc1000/wilc_wfi_netdevice.h
+++ b/drivers/staging/wilc1000/wilc_wfi_netdevice.h
@@ -178,7 +178,7 @@ struct wilc {
struct mutex rxq_cs;
struct mutex hif_cs;
 
-   struct semaphore cfg_event;
+   struct completion cfg_event;
struct semaphore sync_event;
struct completion txq_event;
struct completion txq_thread_started;
diff --git a/drivers/staging/wilc1000/wilc_wlan.c 
b/drivers/staging/wilc1000/wilc_wlan.c
index 9afbe8d..19a5809 100644
--- a/drivers/staging/wilc1000/wilc_wlan.c
+++ b/drivers/staging/wilc1000/wilc_wlan.c
@@ -310,7 +310,7 @@ static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, 
u8 *buffer,
netdev_dbg(vif->ndev, "Adding config packet ...\n");
if (wilc->quit) {
netdev_dbg(vif->ndev, "Return due to clear function\n");
-   up(&wilc->cfg_event);
+   complete(&wilc->cfg_event);
return 0;
}
 
@@ -769,7 +769,7 @@ static void wilc_wlan_handle_rxq(struct wilc *wilc)
 
do {
if (wilc->quit) {
-   up(&wilc->cfg_event);
+   complete(&wilc->cfg_event);
break;
}
rqe = wilc_wlan_rxq_remove(wilc);
@@ -820,7 +820,7 @@ static void wilc_wlan_handle_rxq(struct wilc *wilc)
wilc_wlan_cfg_indicate_rx(wilc, 
&buffer[pkt_offset + offset], pkt_len, &rsp);
if (rsp.type == WILC_CFG_RSP) {
if (wilc->cfg_seq_no == 
rsp.seq_no)
-   up(&wilc->cfg_event);
+   
complete(&wilc->cfg_event);
} else if (rsp.type == 
WILC_CFG_RSP_STATUS) {
wilc_mac_indicate(wilc, 
WILC_MAC_INDICATE_STATUS);
 
@@ -1228,11 +1228,12 @@ int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, 
u16 wid, u8 *buffer,
if (wilc_wlan_cfg_commit(vif, WILC_CFG_SET, drv_handler))
ret_size = 0;
 
-   if (wilc_lock_timeout(wilc, &wilc->cfg_event,
-   CFG_PKTS_TIMEOUT)) {
+   if (!wait_for_completion_timeout(&wilc->cfg_event,
+   msecs_to_jiffies(CFG_PKTS_TIMEOUT))) {
netdev_dbg(vif->ndev, "Set Timed Out\n");
ret_size = 0;
}
+
wilc->cfg_frame_in_use = 0;
wilc->cfg_frame_offset = 0;
wilc->cfg_seq_no += 1;
@@ -1265,8 +1266,8 @@ int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, 
u16 wid, int commit,
if (wilc_wlan_cfg_commit(vif, WILC_CFG_QUERY, drv_handler))
ret_size = 0;
 
-   if (wilc_lock_timeout(wilc, &wilc->cfg_event,
-   CFG_PKTS_TIMEOUT)) {
+   if (!wait_for_completion_timeout(&wilc->cfg_event,
+   msecs_to_jiffies(CFG_PKTS_TIMEOUT))) {
netdev_dbg(vif->ndev, "Get Timed Out\n");
ret_size = 0;
}
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2] staging: gdm724x: Replace semaphore netlink with mutex

2016-06-14 Thread Binoy Jayan
Replace semaphore netlink_mutex with mutex. Semaphores are
going away in the future.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/gdm724x/netlink_k.c | 11 +--
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/drivers/staging/gdm724x/netlink_k.c 
b/drivers/staging/gdm724x/netlink_k.c
index a0232e8..abe2425 100644
--- a/drivers/staging/gdm724x/netlink_k.c
+++ b/drivers/staging/gdm724x/netlink_k.c
@@ -14,6 +14,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -21,13 +22,7 @@
 
 #include "netlink_k.h"
 
-#if defined(DEFINE_MUTEX)
 static DEFINE_MUTEX(netlink_mutex);
-#else
-static struct semaphore netlink_mutex;
-#define mutex_lock(x)  down(x)
-#define mutex_unlock(x)up(x)
-#endif
 
 #define ND_MAX_GROUP   30
 #define ND_IFINDEX_LEN sizeof(int)
@@ -96,10 +91,6 @@ struct sock *netlink_init(int unit,
.input  = netlink_rcv,
};
 
-#if !defined(DEFINE_MUTEX)
-   init_MUTEX(&netlink_mutex);
-#endif
-
sock = netlink_kernel_create(&init_net, unit, &cfg);
 
if (sock)
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] staging: unisys: visorbus: Replace semaphore with mutex

2016-06-19 Thread Binoy Jayan
The semaphore 'visordriver_callback_lock' is a simple mutex, so
it should be written as one. Semaphores are going away in the future.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/unisys/include/visorbus.h   |  3 ++-
 drivers/staging/unisys/visorbus/visorbus_main.c | 14 +++---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/unisys/include/visorbus.h 
b/drivers/staging/unisys/include/visorbus.h
index 9baf1ec..38edca8 100644
--- a/drivers/staging/unisys/include/visorbus.h
+++ b/drivers/staging/unisys/include/visorbus.h
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "periodic_work.h"
 #include "channel.h"
@@ -159,7 +160,7 @@ struct visor_device {
struct list_head list_all;
struct periodic_work *periodic_work;
bool being_removed;
-   struct semaphore visordriver_callback_lock;
+   struct mutex visordriver_callback_lock;
bool pausing;
bool resuming;
u32 chipset_bus_no;
diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c 
b/drivers/staging/unisys/visorbus/visorbus_main.c
index 3a147db..93996a5 100644
--- a/drivers/staging/unisys/visorbus/visorbus_main.c
+++ b/drivers/staging/unisys/visorbus/visorbus_main.c
@@ -544,10 +544,10 @@ dev_periodic_work(void *xdev)
struct visor_device *dev = xdev;
struct visor_driver *drv = to_visor_driver(dev->device.driver);
 
-   down(&dev->visordriver_callback_lock);
+   mutex_lock(&dev->visordriver_callback_lock);
if (drv->channel_interrupt)
drv->channel_interrupt(dev);
-   up(&dev->visordriver_callback_lock);
+   mutex_unlock(&dev->visordriver_callback_lock);
if (!visor_periodic_work_nextperiod(dev->periodic_work))
put_device(&dev->device);
 }
@@ -588,7 +588,7 @@ visordriver_probe_device(struct device *xdev)
if (!drv->probe)
return -ENODEV;
 
-   down(&dev->visordriver_callback_lock);
+   mutex_lock(&dev->visordriver_callback_lock);
dev->being_removed = false;
 
res = drv->probe(dev);
@@ -598,7 +598,7 @@ visordriver_probe_device(struct device *xdev)
fix_vbus_dev_info(dev);
}
 
-   up(&dev->visordriver_callback_lock);
+   mutex_unlock(&dev->visordriver_callback_lock);
return res;
 }
 
@@ -614,11 +614,11 @@ visordriver_remove_device(struct device *xdev)
 
dev = to_visor_device(xdev);
drv = to_visor_driver(xdev->driver);
-   down(&dev->visordriver_callback_lock);
+   mutex_lock(&dev->visordriver_callback_lock);
dev->being_removed = true;
if (drv->remove)
drv->remove(dev);
-   up(&dev->visordriver_callback_lock);
+   mutex_unlock(&dev->visordriver_callback_lock);
dev_stop_periodic_work(dev);
 
put_device(&dev->device);
@@ -778,7 +778,7 @@ create_visor_device(struct visor_device *dev)
POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, chipset_dev_no, chipset_bus_no,
 POSTCODE_SEVERITY_INFO);
 
-   sema_init(&dev->visordriver_callback_lock, 1);  /* unlocked */
+   mutex_init(&dev->visordriver_callback_lock);
dev->device.bus = &visorbus_type;
dev->device.groups = visorbus_channel_groups;
device_initialize(&dev->device);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 1/2] staging: wilc1000: message_queue: Move code to host interface

2016-06-20 Thread Binoy Jayan
Move the contents of wilc_msgqueue.c and wilc_msgqueue.h into
host_interface.c, remove 'wilc_msgqueue.c' and 'wilc_msgqueue.h'.
This is done so as to restructure the implementation of the kthread
'hostIFthread' using a work queue.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/wilc1000/Makefile |   1 -
 drivers/staging/wilc1000/host_interface.c | 163 +-
 drivers/staging/wilc1000/wilc_msgqueue.c  | 144 --
 drivers/staging/wilc1000/wilc_msgqueue.h  |  28 -
 4 files changed, 162 insertions(+), 174 deletions(-)
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.c
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.h

diff --git a/drivers/staging/wilc1000/Makefile 
b/drivers/staging/wilc1000/Makefile
index acc3f3e..d226283 100644
--- a/drivers/staging/wilc1000/Makefile
+++ b/drivers/staging/wilc1000/Makefile
@@ -6,7 +6,6 @@ ccflags-y += -DFIRMWARE_1002=\"atmel/wilc1002_firmware.bin\" \
 ccflags-y += -I$(src)/ -DWILC_ASIC_A0 -DWILC_DEBUGFS
 
 wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \
-   wilc_msgqueue.o \
coreconfigurator.o host_interface.o \
wilc_wlan_cfg.o wilc_debugfs.o \
wilc_wlan.o
diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index 9535842..494345b 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -3,11 +3,13 @@
 #include 
 #include 
 #include 
+#include 
 #include "host_interface.h"
+#include 
+#include 
 #include "coreconfigurator.h"
 #include "wilc_wlan.h"
 #include "wilc_wlan_if.h"
-#include "wilc_msgqueue.h"
 #include 
 #include "wilc_wfi_netdevice.h"
 
@@ -57,6 +59,20 @@
 #define TCP_ACK_FILTER_LINK_SPEED_THRESH   54
 #define DEFAULT_LINK_SPEED 72
 
+struct message {
+   void *buf;
+   u32 len;
+   struct list_head list;
+};
+
+struct message_queue {
+   struct semaphore sem;
+   spinlock_t lock;
+   bool exiting;
+   u32 recv_count;
+   struct list_head msg_list;
+};
+
 struct host_if_wpa_attr {
u8 *key;
const u8 *mac_addr;
@@ -264,6 +280,151 @@ static struct wilc_vif *join_req_vif;
 static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
 static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent);
+static int wilc_mq_create(struct message_queue *mq);
+static int wilc_mq_send(struct message_queue *mq,
+const void *send_buf, u32 send_buf_size);
+static int wilc_mq_recv(struct message_queue *mq,
+void *recv_buf, u32 recv_buf_size, u32 *recv_len);
+static int wilc_mq_destroy(struct message_queue *mq);
+
+/*!
+ *  @authorsyounan
+ *  @date  1 Sep 2010
+ *  @note  copied from FLO glue implementatuion
+ *  @version   1.0
+ */
+static int wilc_mq_create(struct message_queue *mq)
+{
+   spin_lock_init(&mq->lock);
+   sema_init(&mq->sem, 0);
+   INIT_LIST_HEAD(&mq->msg_list);
+   mq->recv_count = 0;
+   mq->exiting = false;
+   return 0;
+}
+
+/*!
+ *  @authorsyounan
+ *  @date  1 Sep 2010
+ *  @note  copied from FLO glue implementatuion
+ *  @version   1.0
+ */
+static int wilc_mq_destroy(struct message_queue *mq)
+{
+   struct message *msg;
+
+   mq->exiting = true;
+
+   /* Release any waiting receiver thread. */
+   while (mq->recv_count > 0) {
+   up(&mq->sem);
+   mq->recv_count--;
+   }
+
+   while (!list_empty(&mq->msg_list)) {
+   msg = list_first_entry(&mq->msg_list, struct message, list);
+   list_del(&msg->list);
+   kfree(msg->buf);
+   }
+
+   return 0;
+}
+
+/*!
+ *  @authorsyounan
+ *  @date  1 Sep 2010
+ *  @note  copied from FLO glue implementatuion
+ *  @version   1.0
+ */
+static int wilc_mq_send(struct message_queue *mq,
+const void *send_buf, u32 send_buf_size)
+{
+   unsigned long flags;
+   struct message *new_msg = NULL;
+
+   if (!mq || (send_buf_size == 0) || !send_buf)
+   return -EINVAL;
+
+   if (mq->exiting)
+   return -EFAULT;
+
+   /* construct a new message */
+   new_msg = kmalloc(sizeof(*new_msg), GFP_ATOMIC);
+   if (!new_msg)
+   return -ENOMEM;
+
+   new_msg->len = send_buf_size;
+   INIT_LIST_HEAD(&new_msg->list);
+   new_msg->buf = kmemdup(send_buf, send_buf_size, GFP_ATOMIC);
+   

[PATCH v2 0/2] *** staging: wilc1000: Replace semaphores ***

2016-06-20 Thread Binoy Jayan
This is the second patch series for 'wilc1000'. The original patch series
consisted 7 patches of which only the first 5 are good. The patch 6 and 7
are being worked on in this series in a different way.

This patch series removes the semaphore 'sem' in 'wilc1000' and also
restructures the implementation of kthread / message_queue logic with
a create_singlethread_workqueue() / queue_work() setup.

These are part of a bigger effort to eliminate all semaphores
from the linux kernel.

They build correctly (individually and as a whole).

NB: The changes are untested

Rework on the review comments by Arnd w.r.t. v1 for patch 2:

struct message_queue can be removed since
 - after the workqueue conversion, mq->sem is no longer needed
 - recv_count is not needed, it just counts the number of entries in the list
 - struct wilc' pointer can be retrieved from the host_if_msg, (vif->wilc)
 - the message list is not needed because we always look only at the
   first entry, except in wilc_mq_destroy(), but it would be better
   to just call destroy_workqueue(), which also drains the remaining work.
 - the exiting flag is also handled by destroy_workqueue()   
 - with everything else gone, the spinlock is also not needed any more.

Do 'kfree' only at the end of 'host_if_work' 

wilc_initialized is always '1' so the conditional 'wilc_mq_send'
in 'hostIFthread' can be removed.

A connect command (HOST_IF_MSG_CONNECT) does not complete while scan is 
ongoing. 
So, the special handling of this command needs to be preserved.

Use create_singlethread_workqueue() instead of alloc_workqueue(), so that
we stay closer to the current behavior by having the thread run only
on one CPU at a time and not having a 'dedicated' thread for each.

Split the patch to seperate interface changes to 'wilc_mq_send'
No easy way found to split the patch to change the interface
'wilc_mq_send' and to 'wilc_enqueue_cmd' as the parameters 
'mq' 'send_buf' and 'send_buf_size' itself are part of the message
queue implementation.


Binoy Jayan (2):
  staging: wilc1000: message_queue: Move code to host interface
  staging: wilc1000: Replace kthread with workqueue for host interface

 drivers/staging/wilc1000/Makefile |   1 -
 drivers/staging/wilc1000/TODO |   5 +
 drivers/staging/wilc1000/host_interface.c | 417 +++---
 drivers/staging/wilc1000/wilc_msgqueue.c  | 144 ---
 drivers/staging/wilc1000/wilc_msgqueue.h  |  28 --
 5 files changed, 216 insertions(+), 379 deletions(-)
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.c
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.h

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v2 2/2] staging: wilc1000: Replace kthread with workqueue for host interface

2016-06-20 Thread Binoy Jayan
Deconstruct the kthread / message_queue logic, replacing it with
create_singlethread_workqueue() / queue_work() setup, by adding a
'struct work_struct' to 'struct host_if_msg'. The current kthread
hostIFthread() is converted to a work queue helper with the name
'host_if_work'.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
---
 drivers/staging/wilc1000/TODO |   5 +
 drivers/staging/wilc1000/host_interface.c | 542 +++---
 2 files changed, 198 insertions(+), 349 deletions(-)

diff --git a/drivers/staging/wilc1000/TODO b/drivers/staging/wilc1000/TODO
index 95199d8..ec93b2e 100644
--- a/drivers/staging/wilc1000/TODO
+++ b/drivers/staging/wilc1000/TODO
@@ -4,6 +4,11 @@ TODO:
 - remove custom debug and tracing functions
 - rework comments and function headers(also coding style)
 - replace all semaphores with mutexes or completions
+- Move handling for each individual members of 'union message_body' out
+  into a separate 'struct work_struct' and completely remove the multiplexer
+  that is currently part of host_if_work(), allowing movement of the
+  implementation of each message handler into the callsite of the function
+  that currently queues the 'host_if_msg'.
 - make spi and sdio components coexist in one build
 - turn compile-time platform configuration (BEAGLE_BOARD,
   PANDA_BOARD, PLAT_WMS8304, PLAT_RK, CUSTOMER_PLATFORM, ...)
diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index 494345b..92d4561 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "host_interface.h"
 #include 
 #include 
@@ -59,20 +60,6 @@
 #define TCP_ACK_FILTER_LINK_SPEED_THRESH   54
 #define DEFAULT_LINK_SPEED 72
 
-struct message {
-   void *buf;
-   u32 len;
-   struct list_head list;
-};
-
-struct message_queue {
-   struct semaphore sem;
-   spinlock_t lock;
-   bool exiting;
-   u32 recv_count;
-   struct list_head msg_list;
-};
-
 struct host_if_wpa_attr {
u8 *key;
const u8 *mac_addr;
@@ -211,6 +198,7 @@ struct host_if_msg {
u16 id;
union message_body body;
struct wilc_vif *vif;
+   struct work_struct work;
 };
 
 struct join_bss_param {
@@ -245,8 +233,7 @@ struct join_bss_param {
 static struct host_if_drv *terminated_handle;
 bool wilc_optaining_ip;
 static u8 P2P_LISTEN_STATE;
-static struct task_struct *hif_thread_handler;
-static struct message_queue hif_msg_q;
+static struct workqueue_struct *hif_workqueue;
 static struct completion hif_thread_comp;
 static struct completion hif_driver_comp;
 static struct completion hif_wait_response;
@@ -280,55 +267,8 @@ static struct wilc_vif *join_req_vif;
 static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
 static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent);
-static int wilc_mq_create(struct message_queue *mq);
-static int wilc_mq_send(struct message_queue *mq,
-const void *send_buf, u32 send_buf_size);
-static int wilc_mq_recv(struct message_queue *mq,
-void *recv_buf, u32 recv_buf_size, u32 *recv_len);
-static int wilc_mq_destroy(struct message_queue *mq);
-
-/*!
- *  @authorsyounan
- *  @date  1 Sep 2010
- *  @note  copied from FLO glue implementatuion
- *  @version   1.0
- */
-static int wilc_mq_create(struct message_queue *mq)
-{
-   spin_lock_init(&mq->lock);
-   sema_init(&mq->sem, 0);
-   INIT_LIST_HEAD(&mq->msg_list);
-   mq->recv_count = 0;
-   mq->exiting = false;
-   return 0;
-}
-
-/*!
- *  @authorsyounan
- *  @date  1 Sep 2010
- *  @note  copied from FLO glue implementatuion
- *  @version   1.0
- */
-static int wilc_mq_destroy(struct message_queue *mq)
-{
-   struct message *msg;
-
-   mq->exiting = true;
-
-   /* Release any waiting receiver thread. */
-   while (mq->recv_count > 0) {
-   up(&mq->sem);
-   mq->recv_count--;
-   }
-
-   while (!list_empty(&mq->msg_list)) {
-   msg = list_first_entry(&mq->msg_list, struct message, list);
-   list_del(&msg->list);
-   kfree(msg->buf);
-   }
-
-   return 0;
-}
+static int wilc_enqueue_cmd(struct host_if_msg *msg);
+static void host_if_work(struct work_struct *work);
 
 /*!
  *  @authorsyounan
@@ -336,95 +276,19 @@ static int wilc_mq_destroy(struct message_queue *mq)
  *  @note  copied from FLO glue implementatuion
  *  @version   1.0
  */
-static int wilc_mq_s

[PATCH v3 0/3] *** staging: wilc1000: Replace semaphores ***

2016-06-22 Thread Binoy Jayan
This patchset [v3] is part of the second patch series for 'wilc1000'.
The original patch series consisted 7 patches of which only the first 5
are good. The patch 6 and 7 are being worked on in this series
in a different way.

This patch series removes the semaphore 'sem' in 'wilc1000' and also
restructures the implementation of kthread / message_queue logic with
a create_singlethread_workqueue() / queue_work() setup.

These are part of a bigger effort to eliminate all semaphores
from the linux kernel.

They build correctly (individually and as a whole).

NB: The changes are untested

Discussion carried forward from previous patchset [v2]

Rework on the review comments by Arnd w.r.t. v1

struct message_queue can be removed since
 - after the workqueue conversion, mq->sem is no longer needed
 - recv_count is not needed, it just counts the number of entries in the list
 - struct wilc' pointer can be retrieved from the host_if_msg, (vif->wilc)
 - the message list is not needed because we always look only at the
   first entry, except in wilc_mq_destroy(), but it would be better
   to just call destroy_workqueue(), which also drains the remaining work.
 - the exiting flag is also handled by destroy_workqueue()   
 - with everything else gone, the spinlock is also not needed any more.

Do 'kfree' only at the end of 'host_if_work' 

wilc_initialized is always '1' so the conditional 'wilc_mq_send'
in 'hostIFthread' can be removed.

A connect command (HOST_IF_MSG_CONNECT) does not complete while scan is 
ongoing. 
So, the special handling of this command needs to be preserved.

Use create_singlethread_workqueue() instead of alloc_workqueue(), so that
we stay closer to the current behavior by having the thread run only
on one CPU at a time and not having a 'dedicated' thread for each.

Split the patch to seperate interface changes to 'wilc_mq_send'
No easy way found to split the patch to change the interface
'wilc_mq_send' and to 'wilc_enqueue_cmd' as the parameters 
'mq' 'send_buf' and 'send_buf_size' itself are part of the message
queue implementation.

New changes in v3

Rework on the review comments by Arnd w.r.t. v2
 - Removed forward declaration for wilc_enqueue_cmd
 - Change the interface 'wilc_mq_send' in a different patch
 - Avoid change in indentation in host_if_work and move it to
   a different patch

Cannot remove forward declaraition for 'host_if_work'
   since there is a mutual dependency.

Binoy

Binoy Jayan (3):
  staging: wilc1000: message_queue: Move code to host interface
  staging: wilc1000: Replace kthread with workqueue for host interface
  staging: wilc1000: Change interface wilc_mq_send to wilc_enqueue_cmd

 drivers/staging/wilc1000/Makefile |   1 -
 drivers/staging/wilc1000/TODO |   5 +
 drivers/staging/wilc1000/host_interface.c | 395 +++---
 drivers/staging/wilc1000/wilc_msgqueue.c  | 144 ---
 drivers/staging/wilc1000/wilc_msgqueue.h  |  28 ---
 5 files changed, 204 insertions(+), 369 deletions(-)
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.c
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.h

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v3 2/3] staging: wilc1000: Replace kthread with workqueue for host interface

2016-06-22 Thread Binoy Jayan
Deconstruct the kthread / message_queue logic, replacing it with
create_singlethread_workqueue() / queue_work() setup, by adding a
'struct work_struct' to 'struct host_if_msg'. The current kthread
hostIFthread() is converted to a work queue helper with the name
'host_if_work'.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/TODO |   5 +
 drivers/staging/wilc1000/host_interface.c | 282 --
 2 files changed, 75 insertions(+), 212 deletions(-)

diff --git a/drivers/staging/wilc1000/TODO b/drivers/staging/wilc1000/TODO
index 95199d8..ec93b2e 100644
--- a/drivers/staging/wilc1000/TODO
+++ b/drivers/staging/wilc1000/TODO
@@ -4,6 +4,11 @@ TODO:
 - remove custom debug and tracing functions
 - rework comments and function headers(also coding style)
 - replace all semaphores with mutexes or completions
+- Move handling for each individual members of 'union message_body' out
+  into a separate 'struct work_struct' and completely remove the multiplexer
+  that is currently part of host_if_work(), allowing movement of the
+  implementation of each message handler into the callsite of the function
+  that currently queues the 'host_if_msg'.
 - make spi and sdio components coexist in one build
 - turn compile-time platform configuration (BEAGLE_BOARD,
   PANDA_BOARD, PLAT_WMS8304, PLAT_RK, CUSTOMER_PLATFORM, ...)
diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index 2d250c6..242c3d7 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "host_interface.h"
 #include 
 #include 
@@ -211,6 +212,7 @@ struct host_if_msg {
u16 id;
union message_body body;
struct wilc_vif *vif;
+   struct work_struct work;
 };
 
 struct join_bss_param {
@@ -245,7 +247,7 @@ struct join_bss_param {
 static struct host_if_drv *terminated_handle;
 bool wilc_optaining_ip;
 static u8 P2P_LISTEN_STATE;
-static struct task_struct *hif_thread_handler;
+static struct workqueue_struct *hif_workqueue;
 static struct message_queue hif_msg_q;
 static struct completion hif_thread_comp;
 static struct completion hif_driver_comp;
@@ -280,55 +282,7 @@ static struct wilc_vif *join_req_vif;
 static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
 static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent);
-static int wilc_mq_create(struct message_queue *mq);
-static int wilc_mq_send(struct message_queue *mq,
-const void *send_buf, u32 send_buf_size);
-static int wilc_mq_recv(struct message_queue *mq,
-void *recv_buf, u32 recv_buf_size, u32 *recv_len);
-static int wilc_mq_destroy(struct message_queue *mq);
-
-/*!
- *  @authorsyounan
- *  @date  1 Sep 2010
- *  @note  copied from FLO glue implementatuion
- *  @version   1.0
- */
-static int wilc_mq_create(struct message_queue *mq)
-{
-   spin_lock_init(&mq->lock);
-   sema_init(&mq->sem, 0);
-   INIT_LIST_HEAD(&mq->msg_list);
-   mq->recv_count = 0;
-   mq->exiting = false;
-   return 0;
-}
-
-/*!
- *  @authorsyounan
- *  @date  1 Sep 2010
- *  @note  copied from FLO glue implementatuion
- *  @version   1.0
- */
-static int wilc_mq_destroy(struct message_queue *mq)
-{
-   struct message *msg;
-
-   mq->exiting = true;
-
-   /* Release any waiting receiver thread. */
-   while (mq->recv_count > 0) {
-   up(&mq->sem);
-   mq->recv_count--;
-   }
-
-   while (!list_empty(&mq->msg_list)) {
-   msg = list_first_entry(&mq->msg_list, struct message, list);
-   list_del(&msg->list);
-   kfree(msg->buf);
-   }
-
-   return 0;
-}
+static void host_if_work(struct work_struct *work);
 
 /*!
  *  @authorsyounan
@@ -339,92 +293,17 @@ static int wilc_mq_destroy(struct message_queue *mq)
 static int wilc_mq_send(struct message_queue *mq,
const void *send_buf, u32 send_buf_size)
 {
-   unsigned long flags;
-   struct message *new_msg = NULL;
+   struct host_if_msg *new_msg;
 
-   if (!mq || (send_buf_size == 0) || !send_buf)
-   return -EINVAL;
-
-   if (mq->exiting)
-   return -EFAULT;
-
-   /* construct a new message */
-   new_msg = kmalloc(sizeof(*new_msg), GFP_ATOMIC);
+   new_msg = kmemdup(send_buf, sizeof(*new_msg), GFP_ATOMIC);
if (!new_msg)
return -ENOMEM;
 
-   new_msg->len = send_buf_size;
-   INIT_LIST_HEAD(&new_msg->list);
-  

[PATCH v3 1/3] staging: wilc1000: message_queue: Move code to host interface

2016-06-22 Thread Binoy Jayan
Move the contents of wilc_msgqueue.c and wilc_msgqueue.h into
host_interface.c, remove 'wilc_msgqueue.c' and 'wilc_msgqueue.h'.
This is done so as to restructure the implementation of the kthread
'hostIFthread' using a work queue.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/Makefile |   1 -
 drivers/staging/wilc1000/host_interface.c | 163 +-
 drivers/staging/wilc1000/wilc_msgqueue.c  | 144 --
 drivers/staging/wilc1000/wilc_msgqueue.h  |  28 -
 4 files changed, 162 insertions(+), 174 deletions(-)
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.c
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.h

diff --git a/drivers/staging/wilc1000/Makefile 
b/drivers/staging/wilc1000/Makefile
index acc3f3e..d226283 100644
--- a/drivers/staging/wilc1000/Makefile
+++ b/drivers/staging/wilc1000/Makefile
@@ -6,7 +6,6 @@ ccflags-y += -DFIRMWARE_1002=\"atmel/wilc1002_firmware.bin\" \
 ccflags-y += -I$(src)/ -DWILC_ASIC_A0 -DWILC_DEBUGFS
 
 wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \
-   wilc_msgqueue.o \
coreconfigurator.o host_interface.o \
wilc_wlan_cfg.o wilc_debugfs.o \
wilc_wlan.o
diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index 9535842..2d250c6 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -3,11 +3,13 @@
 #include 
 #include 
 #include 
+#include 
 #include "host_interface.h"
+#include 
+#include 
 #include "coreconfigurator.h"
 #include "wilc_wlan.h"
 #include "wilc_wlan_if.h"
-#include "wilc_msgqueue.h"
 #include 
 #include "wilc_wfi_netdevice.h"
 
@@ -57,6 +59,20 @@
 #define TCP_ACK_FILTER_LINK_SPEED_THRESH   54
 #define DEFAULT_LINK_SPEED 72
 
+struct message {
+   void *buf;
+   u32 len;
+   struct list_head list;
+};
+
+struct message_queue {
+   struct semaphore sem;
+   spinlock_t lock;
+   bool exiting;
+   u32 recv_count;
+   struct list_head msg_list;
+};
+
 struct host_if_wpa_attr {
u8 *key;
const u8 *mac_addr;
@@ -264,6 +280,151 @@ static struct wilc_vif *join_req_vif;
 static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
 static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent);
+static int wilc_mq_create(struct message_queue *mq);
+static int wilc_mq_send(struct message_queue *mq,
+const void *send_buf, u32 send_buf_size);
+static int wilc_mq_recv(struct message_queue *mq,
+void *recv_buf, u32 recv_buf_size, u32 *recv_len);
+static int wilc_mq_destroy(struct message_queue *mq);
+
+/*!
+ *  @authorsyounan
+ *  @date  1 Sep 2010
+ *  @note  copied from FLO glue implementatuion
+ *  @version   1.0
+ */
+static int wilc_mq_create(struct message_queue *mq)
+{
+   spin_lock_init(&mq->lock);
+   sema_init(&mq->sem, 0);
+   INIT_LIST_HEAD(&mq->msg_list);
+   mq->recv_count = 0;
+   mq->exiting = false;
+   return 0;
+}
+
+/*!
+ *  @authorsyounan
+ *  @date  1 Sep 2010
+ *  @note  copied from FLO glue implementatuion
+ *  @version   1.0
+ */
+static int wilc_mq_destroy(struct message_queue *mq)
+{
+   struct message *msg;
+
+   mq->exiting = true;
+
+   /* Release any waiting receiver thread. */
+   while (mq->recv_count > 0) {
+   up(&mq->sem);
+   mq->recv_count--;
+   }
+
+   while (!list_empty(&mq->msg_list)) {
+   msg = list_first_entry(&mq->msg_list, struct message, list);
+   list_del(&msg->list);
+   kfree(msg->buf);
+   }
+
+   return 0;
+}
+
+/*!
+ *  @authorsyounan
+ *  @date  1 Sep 2010
+ *  @note  copied from FLO glue implementatuion
+ *  @version   1.0
+ */
+static int wilc_mq_send(struct message_queue *mq,
+   const void *send_buf, u32 send_buf_size)
+{
+   unsigned long flags;
+   struct message *new_msg = NULL;
+
+   if (!mq || (send_buf_size == 0) || !send_buf)
+   return -EINVAL;
+
+   if (mq->exiting)
+   return -EFAULT;
+
+   /* construct a new message */
+   new_msg = kmalloc(sizeof(*new_msg), GFP_ATOMIC);
+   if (!new_msg)
+   return -ENOMEM;
+
+   new_msg->len = send_buf_size;
+   INIT_LIST_HEAD(&new_msg->list);
+   new_msg->buf = kmemdup(send_buf, send_buf_size, GFP_ATOMIC);
+   if (!new_msg->buf) {
+   

[PATCH v3 3/3] staging: wilc1000: Change interface wilc_mq_send to wilc_enqueue_cmd

2016-06-22 Thread Binoy Jayan
Replace the interface 'wilc_mq_send' with 'wilc_enqueue_cmd'
and remove the now unused structures 'message' and 'message_queue'.
Restructure switch statement in the work queue helper function
host_if_work and remove unwanted indentation.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/host_interface.c | 332 ++
 1 file changed, 158 insertions(+), 174 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index 242c3d7..8ba48c2 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -60,20 +60,6 @@
 #define TCP_ACK_FILTER_LINK_SPEED_THRESH   54
 #define DEFAULT_LINK_SPEED 72
 
-struct message {
-   void *buf;
-   u32 len;
-   struct list_head list;
-};
-
-struct message_queue {
-   struct semaphore sem;
-   spinlock_t lock;
-   bool exiting;
-   u32 recv_count;
-   struct list_head msg_list;
-};
-
 struct host_if_wpa_attr {
u8 *key;
const u8 *mac_addr;
@@ -290,12 +276,11 @@ static void host_if_work(struct work_struct *work);
  *  @note  copied from FLO glue implementatuion
  *  @version   1.0
  */
-static int wilc_mq_send(struct message_queue *mq,
-   const void *send_buf, u32 send_buf_size)
+static int wilc_enqueue_cmd(struct host_if_msg *msg)
 {
struct host_if_msg *new_msg;
 
-   new_msg = kmemdup(send_buf, sizeof(*new_msg), GFP_ATOMIC);
+   new_msg = kmemdup(msg, sizeof(*new_msg), GFP_ATOMIC);
if (!new_msg)
return -ENOMEM;
 
@@ -2404,7 +2389,7 @@ static void ListenTimerCB(unsigned long arg)
msg.vif = vif;
msg.body.remain_on_ch.id = vif->hif_drv->remain_on_ch.id;
 
-   result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+   result = wilc_enqueue_cmd(&msg);
if (result)
netdev_err(vif->ndev, "wilc_mq_send fail\n");
 }
@@ -2514,160 +2499,159 @@ static void host_if_work(struct work_struct *work)
 
if (msg->id == HOST_IF_MSG_CONNECT &&
msg->vif->hif_drv->usr_scan_req.scan_result) {
-   wilc_mq_send(&hif_msg_q, msg, sizeof(struct host_if_msg));
+   wilc_enqueue_cmd(msg);
usleep_range(2 * 1000, 2 * 1000);
-   } else {
-
-   switch (msg->id) {
-   case HOST_IF_MSG_SCAN:
-   handle_scan(msg->vif, &msg->body.scan_info);
-   break;
-
-   case HOST_IF_MSG_CONNECT:
-   Handle_Connect(msg->vif, &msg->body.con_info);
-   break;
+   goto free_msg;
+   }
+   switch (msg->id) {
+   case HOST_IF_MSG_SCAN:
+   handle_scan(msg->vif, &msg->body.scan_info);
+   break;
 
-   case HOST_IF_MSG_RCVD_NTWRK_INFO:
-   Handle_RcvdNtwrkInfo(msg->vif, &msg->body.net_info);
-   break;
+   case HOST_IF_MSG_CONNECT:
+   Handle_Connect(msg->vif, &msg->body.con_info);
+   break;
 
-   case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
-   Handle_RcvdGnrlAsyncInfo(msg->vif,
-&msg->body.async_info);
-   break;
+   case HOST_IF_MSG_RCVD_NTWRK_INFO:
+   Handle_RcvdNtwrkInfo(msg->vif, &msg->body.net_info);
+   break;
 
-   case HOST_IF_MSG_KEY:
-   Handle_Key(msg->vif, &msg->body.key_info);
-   break;
+   case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
+   Handle_RcvdGnrlAsyncInfo(msg->vif,
+&msg->body.async_info);
+   break;
 
-   case HOST_IF_MSG_CFG_PARAMS:
-   handle_cfg_param(msg->vif, &msg->body.cfg_info);
-   break;
+   case HOST_IF_MSG_KEY:
+   Handle_Key(msg->vif, &msg->body.key_info);
+   break;
 
-   case HOST_IF_MSG_SET_CHANNEL:
-   handle_set_channel(msg->vif, &msg->body.channel_info);
-   break;
+   case HOST_IF_MSG_CFG_PARAMS:
+   handle_cfg_param(msg->vif, &msg->body.cfg_info);
+   break;
 
-   case HOST_IF_MSG_DISCONNECT:
-   Handle_Disconnect(msg->vif);
-   break;
+   case HOST_IF_MSG_SET_CHANNEL:
+   handle_set_channel(msg->vif, &msg->body.channel_info);
+   break;
 
-   case HOST_IF_MSG_RCVD_SCAN_COMPLETE:
-   del_timer(&msg->vif

[PATCH v4 1/3] staging: wilc1000: message_queue: Move code to host interface

2016-06-22 Thread Binoy Jayan
Move the contents of wilc_msgqueue.c and wilc_msgqueue.h into
host_interface.c, remove 'wilc_msgqueue.c' and 'wilc_msgqueue.h'.
This is done so as to restructure the implementation of the kthread
'hostIFthread' using a work queue.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/Makefile |   1 -
 drivers/staging/wilc1000/host_interface.c | 163 +-
 drivers/staging/wilc1000/wilc_msgqueue.c  | 144 --
 drivers/staging/wilc1000/wilc_msgqueue.h  |  28 -
 4 files changed, 162 insertions(+), 174 deletions(-)
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.c
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.h

diff --git a/drivers/staging/wilc1000/Makefile 
b/drivers/staging/wilc1000/Makefile
index acc3f3e..d226283 100644
--- a/drivers/staging/wilc1000/Makefile
+++ b/drivers/staging/wilc1000/Makefile
@@ -6,7 +6,6 @@ ccflags-y += -DFIRMWARE_1002=\"atmel/wilc1002_firmware.bin\" \
 ccflags-y += -I$(src)/ -DWILC_ASIC_A0 -DWILC_DEBUGFS
 
 wilc1000-objs := wilc_wfi_cfgoperations.o linux_wlan.o linux_mon.o \
-   wilc_msgqueue.o \
coreconfigurator.o host_interface.o \
wilc_wlan_cfg.o wilc_debugfs.o \
wilc_wlan.o
diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index 9535842..2d250c6 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -3,11 +3,13 @@
 #include 
 #include 
 #include 
+#include 
 #include "host_interface.h"
+#include 
+#include 
 #include "coreconfigurator.h"
 #include "wilc_wlan.h"
 #include "wilc_wlan_if.h"
-#include "wilc_msgqueue.h"
 #include 
 #include "wilc_wfi_netdevice.h"
 
@@ -57,6 +59,20 @@
 #define TCP_ACK_FILTER_LINK_SPEED_THRESH   54
 #define DEFAULT_LINK_SPEED 72
 
+struct message {
+   void *buf;
+   u32 len;
+   struct list_head list;
+};
+
+struct message_queue {
+   struct semaphore sem;
+   spinlock_t lock;
+   bool exiting;
+   u32 recv_count;
+   struct list_head msg_list;
+};
+
 struct host_if_wpa_attr {
u8 *key;
const u8 *mac_addr;
@@ -264,6 +280,151 @@ static struct wilc_vif *join_req_vif;
 static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
 static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent);
+static int wilc_mq_create(struct message_queue *mq);
+static int wilc_mq_send(struct message_queue *mq,
+const void *send_buf, u32 send_buf_size);
+static int wilc_mq_recv(struct message_queue *mq,
+void *recv_buf, u32 recv_buf_size, u32 *recv_len);
+static int wilc_mq_destroy(struct message_queue *mq);
+
+/*!
+ *  @authorsyounan
+ *  @date  1 Sep 2010
+ *  @note  copied from FLO glue implementatuion
+ *  @version   1.0
+ */
+static int wilc_mq_create(struct message_queue *mq)
+{
+   spin_lock_init(&mq->lock);
+   sema_init(&mq->sem, 0);
+   INIT_LIST_HEAD(&mq->msg_list);
+   mq->recv_count = 0;
+   mq->exiting = false;
+   return 0;
+}
+
+/*!
+ *  @authorsyounan
+ *  @date  1 Sep 2010
+ *  @note  copied from FLO glue implementatuion
+ *  @version   1.0
+ */
+static int wilc_mq_destroy(struct message_queue *mq)
+{
+   struct message *msg;
+
+   mq->exiting = true;
+
+   /* Release any waiting receiver thread. */
+   while (mq->recv_count > 0) {
+   up(&mq->sem);
+   mq->recv_count--;
+   }
+
+   while (!list_empty(&mq->msg_list)) {
+   msg = list_first_entry(&mq->msg_list, struct message, list);
+   list_del(&msg->list);
+   kfree(msg->buf);
+   }
+
+   return 0;
+}
+
+/*!
+ *  @authorsyounan
+ *  @date  1 Sep 2010
+ *  @note  copied from FLO glue implementatuion
+ *  @version   1.0
+ */
+static int wilc_mq_send(struct message_queue *mq,
+   const void *send_buf, u32 send_buf_size)
+{
+   unsigned long flags;
+   struct message *new_msg = NULL;
+
+   if (!mq || (send_buf_size == 0) || !send_buf)
+   return -EINVAL;
+
+   if (mq->exiting)
+   return -EFAULT;
+
+   /* construct a new message */
+   new_msg = kmalloc(sizeof(*new_msg), GFP_ATOMIC);
+   if (!new_msg)
+   return -ENOMEM;
+
+   new_msg->len = send_buf_size;
+   INIT_LIST_HEAD(&new_msg->list);
+   new_msg->buf = kmemdup(send_buf, send_buf_size, GFP_ATOMIC);
+   if (!new_msg->buf) {
+   

[PATCH v4 0/3] *** staging: wilc1000: Replace semaphores ***

2016-06-22 Thread Binoy Jayan
Hi,

Thank you Arnd for patiently reviewing this patch series multiple times and
apologies to everyone for spamming you inboxes with a patch (v3) that does
not even build. It was due to an uncommited change in my git repo before
generating the patch. It is corrected in v4.

This patchset [v4] is part of the second patch series for 'wilc1000'.
The original patch series consisted 7 patches of which only the first 5
are good. The patch 6 and 7 are being worked on in this series
in a different way.

This patch series removes the semaphore 'sem' in 'wilc1000' and also
restructures the implementation of kthread / message_queue logic with
a create_singlethread_workqueue() / queue_work() setup.

These are part of a bigger effort to eliminate all semaphores
from the linux kernel.

They build correctly (individually and as a whole).

NB: The changes are untested

Discussion carried forward from previous patchset [v2]

Rework on the review comments by Arnd w.r.t. v1

struct message_queue can be removed since
 - after the workqueue conversion, mq->sem is no longer needed
 - recv_count is not needed, it just counts the number of entries in the list
 - struct wilc' pointer can be retrieved from the host_if_msg, (vif->wilc)
 - the message list is not needed because we always look only at the
   first entry, except in wilc_mq_destroy(), but it would be better
   to just call destroy_workqueue(), which also drains the remaining work.
 - the exiting flag is also handled by destroy_workqueue()   
 - with everything else gone, the spinlock is also not needed any more.

Do 'kfree' only at the end of 'host_if_work' 

wilc_initialized is always '1' so the conditional 'wilc_mq_send'
in 'hostIFthread' can be removed.

A connect command (HOST_IF_MSG_CONNECT) does not complete while scan is 
ongoing. 
So, the special handling of this command needs to be preserved.

Use create_singlethread_workqueue() instead of alloc_workqueue(), so that
we stay closer to the current behavior by having the thread run only
on one CPU at a time and not having a 'dedicated' thread for each.

Split the patch to seperate interface changes to 'wilc_mq_send'
No easy way found to split the patch to change the interface
'wilc_mq_send' and to 'wilc_enqueue_cmd' as the parameters 
'mq' 'send_buf' and 'send_buf_size' itself are part of the message
queue implementation.

New changes in v3

Rework on the review comments by Arnd w.r.t. v2
 - Remove forward declaration for wilc_enqueue_cmd
 - Change the interface 'wilc_mq_send' in a different patch
 - Avoid change in indentation in host_if_work and move it to
   a different patch

Cannot remove forward declaration of local function 'host_if_work'
   since there is a mutual dependency.

New changes in v4

Remove unused identifier 'hif_msg_q' which causes the build error.

Binoy

Binoy Jayan (3):
  staging: wilc1000: message_queue: Move code to host interface
  staging: wilc1000: Replace kthread with workqueue for host interface
  staging: wilc1000: Change interface wilc_mq_send to wilc_enqueue_cmd

 drivers/staging/wilc1000/Makefile |   1 -
 drivers/staging/wilc1000/TODO |   5 +
 drivers/staging/wilc1000/host_interface.c | 396 +++---
 drivers/staging/wilc1000/wilc_msgqueue.c  | 144 ---
 drivers/staging/wilc1000/wilc_msgqueue.h  |  28 ---
 5 files changed, 204 insertions(+), 370 deletions(-)
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.c
 delete mode 100644 drivers/staging/wilc1000/wilc_msgqueue.h

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH v4 3/3] staging: wilc1000: Change interface wilc_mq_send to wilc_enqueue_cmd

2016-06-22 Thread Binoy Jayan
Replace the interface 'wilc_mq_send' with 'wilc_enqueue_cmd'
and remove the now unused structures 'message' and 'message_queue'.
Restructure switch statement in the work queue helper function
host_if_work and remove unwanted indentation.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/host_interface.c | 333 ++
 1 file changed, 158 insertions(+), 175 deletions(-)

diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index 242c3d7..9c70318 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -60,20 +60,6 @@
 #define TCP_ACK_FILTER_LINK_SPEED_THRESH   54
 #define DEFAULT_LINK_SPEED 72
 
-struct message {
-   void *buf;
-   u32 len;
-   struct list_head list;
-};
-
-struct message_queue {
-   struct semaphore sem;
-   spinlock_t lock;
-   bool exiting;
-   u32 recv_count;
-   struct list_head msg_list;
-};
-
 struct host_if_wpa_attr {
u8 *key;
const u8 *mac_addr;
@@ -248,7 +234,6 @@ static struct host_if_drv *terminated_handle;
 bool wilc_optaining_ip;
 static u8 P2P_LISTEN_STATE;
 static struct workqueue_struct *hif_workqueue;
-static struct message_queue hif_msg_q;
 static struct completion hif_thread_comp;
 static struct completion hif_driver_comp;
 static struct completion hif_wait_response;
@@ -290,12 +275,11 @@ static void host_if_work(struct work_struct *work);
  *  @note  copied from FLO glue implementatuion
  *  @version   1.0
  */
-static int wilc_mq_send(struct message_queue *mq,
-   const void *send_buf, u32 send_buf_size)
+static int wilc_enqueue_cmd(struct host_if_msg *msg)
 {
struct host_if_msg *new_msg;
 
-   new_msg = kmemdup(send_buf, sizeof(*new_msg), GFP_ATOMIC);
+   new_msg = kmemdup(msg, sizeof(*new_msg), GFP_ATOMIC);
if (!new_msg)
return -ENOMEM;
 
@@ -2404,7 +2388,7 @@ static void ListenTimerCB(unsigned long arg)
msg.vif = vif;
msg.body.remain_on_ch.id = vif->hif_drv->remain_on_ch.id;
 
-   result = wilc_mq_send(&hif_msg_q, &msg, sizeof(struct host_if_msg));
+   result = wilc_enqueue_cmd(&msg);
if (result)
netdev_err(vif->ndev, "wilc_mq_send fail\n");
 }
@@ -2514,160 +2498,159 @@ static void host_if_work(struct work_struct *work)
 
if (msg->id == HOST_IF_MSG_CONNECT &&
msg->vif->hif_drv->usr_scan_req.scan_result) {
-   wilc_mq_send(&hif_msg_q, msg, sizeof(struct host_if_msg));
+   wilc_enqueue_cmd(msg);
usleep_range(2 * 1000, 2 * 1000);
-   } else {
-
-   switch (msg->id) {
-   case HOST_IF_MSG_SCAN:
-   handle_scan(msg->vif, &msg->body.scan_info);
-   break;
-
-   case HOST_IF_MSG_CONNECT:
-   Handle_Connect(msg->vif, &msg->body.con_info);
-   break;
+   goto free_msg;
+   }
+   switch (msg->id) {
+   case HOST_IF_MSG_SCAN:
+   handle_scan(msg->vif, &msg->body.scan_info);
+   break;
 
-   case HOST_IF_MSG_RCVD_NTWRK_INFO:
-   Handle_RcvdNtwrkInfo(msg->vif, &msg->body.net_info);
-   break;
+   case HOST_IF_MSG_CONNECT:
+   Handle_Connect(msg->vif, &msg->body.con_info);
+   break;
 
-   case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
-   Handle_RcvdGnrlAsyncInfo(msg->vif,
-&msg->body.async_info);
-   break;
+   case HOST_IF_MSG_RCVD_NTWRK_INFO:
+   Handle_RcvdNtwrkInfo(msg->vif, &msg->body.net_info);
+   break;
 
-   case HOST_IF_MSG_KEY:
-   Handle_Key(msg->vif, &msg->body.key_info);
-   break;
+   case HOST_IF_MSG_RCVD_GNRL_ASYNC_INFO:
+   Handle_RcvdGnrlAsyncInfo(msg->vif,
+&msg->body.async_info);
+   break;
 
-   case HOST_IF_MSG_CFG_PARAMS:
-   handle_cfg_param(msg->vif, &msg->body.cfg_info);
-   break;
+   case HOST_IF_MSG_KEY:
+   Handle_Key(msg->vif, &msg->body.key_info);
+   break;
 
-   case HOST_IF_MSG_SET_CHANNEL:
-   handle_set_channel(msg->vif, &msg->body.channel_info);
-   break;
+   case HOST_IF_MSG_CFG_PARAMS:
+   handle_cfg_param(msg->vif, &msg->body.cfg_info);
+   break;
 
-   case HOST_IF

[PATCH v4 2/3] staging: wilc1000: Replace kthread with workqueue for host interface

2016-06-22 Thread Binoy Jayan
Deconstruct the kthread / message_queue logic, replacing it with
create_singlethread_workqueue() / queue_work() setup, by adding a
'struct work_struct' to 'struct host_if_msg'. The current kthread
hostIFthread() is converted to a work queue helper with the name
'host_if_work'.

Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/TODO |   5 +
 drivers/staging/wilc1000/host_interface.c | 282 --
 2 files changed, 75 insertions(+), 212 deletions(-)

diff --git a/drivers/staging/wilc1000/TODO b/drivers/staging/wilc1000/TODO
index 95199d8..ec93b2e 100644
--- a/drivers/staging/wilc1000/TODO
+++ b/drivers/staging/wilc1000/TODO
@@ -4,6 +4,11 @@ TODO:
 - remove custom debug and tracing functions
 - rework comments and function headers(also coding style)
 - replace all semaphores with mutexes or completions
+- Move handling for each individual members of 'union message_body' out
+  into a separate 'struct work_struct' and completely remove the multiplexer
+  that is currently part of host_if_work(), allowing movement of the
+  implementation of each message handler into the callsite of the function
+  that currently queues the 'host_if_msg'.
 - make spi and sdio components coexist in one build
 - turn compile-time platform configuration (BEAGLE_BOARD,
   PANDA_BOARD, PLAT_WMS8304, PLAT_RK, CUSTOMER_PLATFORM, ...)
diff --git a/drivers/staging/wilc1000/host_interface.c 
b/drivers/staging/wilc1000/host_interface.c
index 2d250c6..242c3d7 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "host_interface.h"
 #include 
 #include 
@@ -211,6 +212,7 @@ struct host_if_msg {
u16 id;
union message_body body;
struct wilc_vif *vif;
+   struct work_struct work;
 };
 
 struct join_bss_param {
@@ -245,7 +247,7 @@ struct join_bss_param {
 static struct host_if_drv *terminated_handle;
 bool wilc_optaining_ip;
 static u8 P2P_LISTEN_STATE;
-static struct task_struct *hif_thread_handler;
+static struct workqueue_struct *hif_workqueue;
 static struct message_queue hif_msg_q;
 static struct completion hif_thread_comp;
 static struct completion hif_driver_comp;
@@ -280,55 +282,7 @@ static struct wilc_vif *join_req_vif;
 static void *host_int_ParseJoinBssParam(struct network_info *ptstrNetworkInfo);
 static int host_int_get_ipaddress(struct wilc_vif *vif, u8 *ip_addr, u8 idx);
 static s32 Handle_ScanDone(struct wilc_vif *vif, enum scan_event enuEvent);
-static int wilc_mq_create(struct message_queue *mq);
-static int wilc_mq_send(struct message_queue *mq,
-const void *send_buf, u32 send_buf_size);
-static int wilc_mq_recv(struct message_queue *mq,
-void *recv_buf, u32 recv_buf_size, u32 *recv_len);
-static int wilc_mq_destroy(struct message_queue *mq);
-
-/*!
- *  @authorsyounan
- *  @date  1 Sep 2010
- *  @note  copied from FLO glue implementatuion
- *  @version   1.0
- */
-static int wilc_mq_create(struct message_queue *mq)
-{
-   spin_lock_init(&mq->lock);
-   sema_init(&mq->sem, 0);
-   INIT_LIST_HEAD(&mq->msg_list);
-   mq->recv_count = 0;
-   mq->exiting = false;
-   return 0;
-}
-
-/*!
- *  @authorsyounan
- *  @date  1 Sep 2010
- *  @note  copied from FLO glue implementatuion
- *  @version   1.0
- */
-static int wilc_mq_destroy(struct message_queue *mq)
-{
-   struct message *msg;
-
-   mq->exiting = true;
-
-   /* Release any waiting receiver thread. */
-   while (mq->recv_count > 0) {
-   up(&mq->sem);
-   mq->recv_count--;
-   }
-
-   while (!list_empty(&mq->msg_list)) {
-   msg = list_first_entry(&mq->msg_list, struct message, list);
-   list_del(&msg->list);
-   kfree(msg->buf);
-   }
-
-   return 0;
-}
+static void host_if_work(struct work_struct *work);
 
 /*!
  *  @authorsyounan
@@ -339,92 +293,17 @@ static int wilc_mq_destroy(struct message_queue *mq)
 static int wilc_mq_send(struct message_queue *mq,
const void *send_buf, u32 send_buf_size)
 {
-   unsigned long flags;
-   struct message *new_msg = NULL;
+   struct host_if_msg *new_msg;
 
-   if (!mq || (send_buf_size == 0) || !send_buf)
-   return -EINVAL;
-
-   if (mq->exiting)
-   return -EFAULT;
-
-   /* construct a new message */
-   new_msg = kmalloc(sizeof(*new_msg), GFP_ATOMIC);
+   new_msg = kmemdup(send_buf, sizeof(*new_msg), GFP_ATOMIC);
if (!new_msg)
return -ENOMEM;
 
-   new_msg->len = send_buf_size;
-   INIT_LIST_HEAD(&new_msg->list);
-  

[PATCH] staging: wilc1000: txq_event: Fix coding error

2016-07-21 Thread Binoy Jayan
Fix incorrect usage of completion interface by replacing
'wait_for_completion' with 'complete'. This error was introduced
accidentally while replacing semaphores with mutexes.

Reported-by: Jiri Slaby 
Signed-off-by: Binoy Jayan 
---
 drivers/staging/wilc1000/linux_wlan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/wilc1000/linux_wlan.c 
b/drivers/staging/wilc1000/linux_wlan.c
index 3a66255..3221511 100644
--- a/drivers/staging/wilc1000/linux_wlan.c
+++ b/drivers/staging/wilc1000/linux_wlan.c
@@ -648,7 +648,7 @@ void wilc1000_wlan_deinit(struct net_device *dev)
mutex_unlock(&wl->hif_cs);
}
if (&wl->txq_event)
-   wait_for_completion(&wl->txq_event);
+   complete(&wl->txq_event);
 
wlan_deinitialize_threads(dev);
deinit_irq(dev);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


[PATCH] rtl8712: pwrctrl_priv: Replace semaphore lock with mutex

2016-08-21 Thread Binoy Jayan
The semaphore 'lock' in 'pwrctrl_priv' is used as a simple mutex, so it
should be written as one. Semaphores are going away in the future.
_enter_pwrlock was using down_interruptible(), so the lock could be broken
by sending a signal. This could be a bug, because nothing checks the return
code here. Hence, using mutex_lock instead of the interruptible version.
Removing the now unused _enter_pwrlock and _down_sema.

Signed-off-by: Binoy Jayan 
Reviewed-by: Arnd Bergmann 
Tested-by: Larry Finger 
---
 drivers/staging/rtl8712/osdep_service.h   |  7 ---
 drivers/staging/rtl8712/rtl8712_cmd.c | 10 +-
 drivers/staging/rtl8712/rtl871x_pwrctrl.c | 22 +++---
 drivers/staging/rtl8712/rtl871x_pwrctrl.h |  7 +--
 4 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/rtl8712/osdep_service.h 
b/drivers/staging/rtl8712/osdep_service.h
index ad041c9..c9ea50d 100644
--- a/drivers/staging/rtl8712/osdep_service.h
+++ b/drivers/staging/rtl8712/osdep_service.h
@@ -57,13 +57,6 @@ struct   __queue {
spin_lock_init(&((pqueue)->lock));  \
} while (0)
 
-static inline u32 _down_sema(struct semaphore *sema)
-{
-   if (down_interruptible(sema))
-   return _FAIL;
-   return _SUCCESS;
-}
-
 static inline u32 end_of_queue_search(struct list_head *head,
struct list_head *plist)
 {
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c 
b/drivers/staging/rtl8712/rtl8712_cmd.c
index 3877fcf..9f61583 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -264,9 +264,9 @@ static struct cmd_obj *cmd_hdl_filter(struct _adapter 
*padapter,
 */
if (padapter->pwrctrlpriv.pwr_mode > PS_MODE_ACTIVE) {
padapter->pwrctrlpriv.pwr_mode = PS_MODE_ACTIVE;
-   _enter_pwrlock(&(padapter->pwrctrlpriv.lock));
+   mutex_lock(&padapter->pwrctrlpriv.mutex_lock);
r8712_set_rpwm(padapter, PS_STATE_S4);
-   up(&(padapter->pwrctrlpriv.lock));
+   mutex_unlock(&padapter->pwrctrlpriv.mutex_lock);
}
pcmd_r = pcmd;
break;
@@ -395,10 +395,10 @@ _next:
}
if (pcmd->cmdcode == GEN_CMD_CODE(_SetPwrMode)) {
if (padapter->pwrctrlpriv.bSleep) {
-   _enter_pwrlock(&(padapter->
-  pwrctrlpriv.lock));
+   mutex_lock(&padapter->
+  pwrctrlpriv.mutex_lock);
r8712_set_rpwm(padapter, PS_STATE_S2);
-   up(&padapter->pwrctrlpriv.lock);
+   
mutex_unlock(&padapter->pwrctrlpriv.mutex_lock);
}
}
r8712_free_cmd_obj(pcmd);
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c 
b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
index 98a5e74..8d7ead6 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
@@ -103,14 +103,14 @@ void r8712_cpwm_int_hdl(struct _adapter *padapter,
if (pwrpriv->cpwm_tog == ((preportpwrstate->state) & 0x80))
return;
del_timer(&padapter->pwrctrlpriv.rpwm_check_timer);
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
pwrpriv->cpwm = (preportpwrstate->state) & 0xf;
if (pwrpriv->cpwm >= PS_STATE_S2) {
if (pwrpriv->alives & CMD_ALIVE)
complete(&(pcmdpriv->cmd_queue_comp));
}
pwrpriv->cpwm_tog = (preportpwrstate->state) & 0x80;
-   up(&pwrpriv->lock);
+   mutex_unlock(&pwrpriv->mutex_lock);
 }
 
 static inline void register_task_alive(struct pwrctrl_priv *pwrctrl, uint tag)
@@ -141,10 +141,10 @@ static void SetPSModeWorkItemCallback(struct work_struct 
*work)
struct _adapter *padapter = container_of(pwrpriv,
struct _adapter, pwrctrlpriv);
if (!pwrpriv->bSleep) {
-   _enter_pwrlock(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
r8712_set_rpwm(padapter, PS_STATE_S4);
-   up(&pwrpriv->lock);
+   mutex_lock(&pwrpriv->mutex_lock);
}
 }
 
@@ -155,11 +155,11 @@ static void rpwm_workitem_callback(struct work_struct 
*work)
struct _adapter *padapter = container_of(