staging: ks7010: abstract connection status
authorTobin C. Harding <me@tobin.cc>
Thu, 27 Apr 2017 01:25:19 +0000 (11:25 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 28 Apr 2017 09:47:26 +0000 (11:47 +0200)
Host interface connection status is handled using a 32 bit type. Top
byte is used as for FORCE_DISCONNECT status, low bits are used for
connect/disconnect status. Driver masks and checks integers to
ascertain status. If functions are defined to do the masking and
equality check then the details of how the status integer is used are
abstracted away. This makes the code easier to read. Also future
updates to the status handling will be easier because the code is in
one place.

Driver currently uses the CONNECT_STATUS and DISCONNECT_STATUS as
values, as apposed to opaque values. Because of this driver code
checks for equality with CONNECT_STATUS and DISCONNECT_STATUS as
apposed to negating a single check (ie 'foo != CONNECT_STATUS). In
order to maintain the current functionality we define two separate
functions is_connect_status() and is_disconnect_status().

Add functions to abstract the status integer check. Update all sites
that do the check manually to use the newly defined functions.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/ks7010/ks7010_sdio.c
drivers/staging/ks7010/ks_hostif.c
drivers/staging/ks7010/ks_wlan.h
drivers/staging/ks7010/ks_wlan_net.c

index ec11799..e36c1d0 100644 (file)
@@ -172,7 +172,7 @@ static void _ks_wlan_hw_power_save(struct ks_wlan_private *priv)
        if (priv->reg.operation_mode != MODE_INFRASTRUCTURE)
                return;
 
-       if ((priv->connect_status & CONNECT_STATUS_MASK) != CONNECT_STATUS)
+       if (!is_connect_status(priv->connect_status))
                return;
 
        if (priv->dev_state != DEVICE_STATE_SLEEP)
index 4821029..3f2fd6c 100644 (file)
@@ -99,7 +99,7 @@ int ks_wlan_do_power_save(struct ks_wlan_private *priv)
 {
        DPRINTK(4, "psstatus.status=%d\n", atomic_read(&priv->psstatus.status));
 
-       if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS)
+       if (is_connect_status(priv->connect_status))
                hostif_sme_enqueue(priv, SME_POW_MNGMT_REQUEST);
        else
                priv->dev_state = DEVICE_STATE_READY;
@@ -116,7 +116,7 @@ int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info_t *ap_info)
        DPRINTK(3, "\n");
        ap = &priv->current_ap;
 
-       if ((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS) {
+       if (is_disconnect_status(priv->connect_status)) {
                memset(ap, 0, sizeof(struct local_ap_t));
                return -EPERM;
        }
@@ -183,7 +183,7 @@ int get_current_ap(struct ks_wlan_private *priv, struct link_ap_info_t *ap_info)
        wrqu.data.length = 0;
        wrqu.data.flags = 0;
        wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-       if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
+       if (is_connect_status(priv->connect_status)) {
                memcpy(wrqu.ap_addr.sa_data,
                       priv->current_ap.bssid, ETH_ALEN);
                DPRINTK(3,
@@ -744,7 +744,7 @@ void hostif_start_confirm(struct ks_wlan_private *priv)
        wrqu.data.length = 0;
        wrqu.data.flags = 0;
        wrqu.ap_addr.sa_family = ARPHRD_ETHER;
-       if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
+       if (is_connect_status(priv->connect_status)) {
                eth_zero_addr(wrqu.ap_addr.sa_data);
                DPRINTK(3, "IWEVENT: disconnect\n");
                wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
@@ -791,8 +791,8 @@ void hostif_connect_indication(struct ks_wlan_private *priv)
        }
 
        get_current_ap(priv, (struct link_ap_info_t *)priv->rxp);
-       if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS &&
-           (old_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS) {
+       if (is_connect_status(priv->connect_status) &&
+           is_disconnect_status(old_status)) {
                /* for power save */
                atomic_set(&priv->psstatus.snooze_guard, 0);
                atomic_set(&priv->psstatus.confirm_wait, 0);
@@ -802,8 +802,8 @@ void hostif_connect_indication(struct ks_wlan_private *priv)
        wrqu0.data.length = 0;
        wrqu0.data.flags = 0;
        wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
-       if ((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS &&
-           (old_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
+       if (is_disconnect_status(priv->connect_status) &&
+           is_connect_status(old_status)) {
                eth_zero_addr(wrqu0.ap_addr.sa_data);
                DPRINTK(3, "IWEVENT: disconnect\n");
                DPRINTK(3, "disconnect :: scan_ind_count=%d\n",
@@ -860,7 +860,7 @@ void hostif_stop_confirm(struct ks_wlan_private *priv)
                priv->dev_state = DEVICE_STATE_READY;
 
        /* disconnect indication */
-       if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
+       if (is_connect_status(priv->connect_status)) {
                netif_carrier_off(netdev);
                tmp = FORCE_DISCONNECT & priv->connect_status;
                priv->connect_status = tmp | DISCONNECT_STATUS;
@@ -869,8 +869,8 @@ void hostif_stop_confirm(struct ks_wlan_private *priv)
                wrqu0.data.length = 0;
                wrqu0.data.flags = 0;
                wrqu0.ap_addr.sa_family = ARPHRD_ETHER;
-               if ((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS &&
-                   (old_status & CONNECT_STATUS_MASK) == CONNECT_STATUS) {
+               if (is_disconnect_status(priv->connect_status) &&
+                   is_connect_status(old_status)) {
                        eth_zero_addr(wrqu0.ap_addr.sa_data);
                        DPRINTK(3, "IWEVENT: disconnect\n");
                        netdev_info(netdev, "IWEVENT: disconnect\n");
@@ -1132,7 +1132,7 @@ int hostif_data_request(struct ks_wlan_private *priv, struct sk_buff *skb)
                goto err_kfree_skb;
        }
 
-       if (((priv->connect_status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS) ||
+       if (is_disconnect_status(priv->connect_status) ||
            (priv->connect_status & FORCE_DISCONNECT) ||
            priv->wpa.mic_failure.stop) {
                DPRINTK(3, " DISCONNECT\n");
index eb15db9..a246539 100644 (file)
@@ -508,5 +508,7 @@ struct ks_wlan_private {
 
 int ks_wlan_net_start(struct net_device *dev);
 int ks_wlan_net_stop(struct net_device *dev);
+bool is_connect_status(u32 status);
+bool is_disconnect_status(u32 status);
 
 #endif /* _KS_WLAN_H */
index 0ef52c8..18e2d1f 100644 (file)
@@ -253,10 +253,11 @@ static int ks_wlan_get_freq(struct net_device *dev,
                return -EPERM;
 
        /* for SLEEP MODE */
-       if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS)
+       if (is_connect_status(priv->connect_status))
                f = (int)priv->current_ap.channel;
-               else
+       else
                f = (int)priv->reg.channel;
+
        fwrq->m = frequency_list[f - 1] * 100000;
        fwrq->e = 1;
 
@@ -395,7 +396,7 @@ static int ks_wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
                return -EPERM;
 
        /* for SLEEP MODE */
-       if ((priv->connect_status & CONNECT_STATUS_MASK) == CONNECT_STATUS)
+       if (is_connect_status(priv->connect_status))
                memcpy(awrq->sa_data, priv->current_ap.bssid, ETH_ALEN);
        else
                eth_zero_addr(awrq->sa_data);
@@ -3032,3 +3033,23 @@ int ks_wlan_net_stop(struct net_device *dev)
 
        return 0;
 }
+
+/**
+ * is_connect_status() - return true if status is 'connected'
+ * @status: high bit is used as FORCE_DISCONNECT, low bits used for
+ *     connect status.
+ */
+bool is_connect_status(u32 status)
+{
+       return (status & CONNECT_STATUS_MASK) == CONNECT_STATUS;
+}
+
+/**
+ * is_disconnect_status() - return true if status is 'disconnected'
+ * @status: high bit is used as FORCE_DISCONNECT, low bits used for
+ *     disconnect status.
+ */
+bool is_disconnect_status(u32 status)
+{
+       return (status & CONNECT_STATUS_MASK) == DISCONNECT_STATUS;
+}