staging: wfx: simplify hif_set_template_frame() usage
authorJérôme Pouiller <jerome.pouiller@silabs.com>
Tue, 17 Dec 2019 16:15:34 +0000 (16:15 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Dec 2019 14:56:30 +0000 (15:56 +0100)
The structure hif_mib_template_frame come from hardware API. It is not
intended to be manipulated in upper layers of the driver.

In add, the current code for hif_set_template_frame() is dumb. All the
difficult task is left to the caller. So, there is code to factorize
here.

Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
Link: https://lore.kernel.org/r/20191217161318.31402-50-Jerome.Pouiller@silabs.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/wfx/hif_tx_mib.h
drivers/staging/wfx/scan.c
drivers/staging/wfx/sta.c

index d77765f..b1eeda2 100644 (file)
@@ -130,8 +130,17 @@ static inline int hif_set_operational_mode(struct wfx_dev *wdev,
 }
 
 static inline int hif_set_template_frame(struct wfx_vif *wvif,
-                                        struct hif_mib_template_frame *arg)
+                                        struct sk_buff *skb,
+                                        u8 frame_type, int init_rate)
 {
+       struct hif_mib_template_frame *arg;
+
+       skb_push(skb, 4);
+       arg = (struct hif_mib_template_frame *)skb->data;
+       skb_pull(skb, 4);
+       arg->init_rate = init_rate;
+       arg->frame_type = frame_type;
+       arg->frame_length = cpu_to_le16(skb->len);
        return hif_write_mib(wvif->wdev, wvif->id, HIF_MIB_ID_TEMPLATE_FRAME,
                             arg, sizeof(*arg));
 }
index 8b184ef..c82c04f 100644 (file)
@@ -52,7 +52,6 @@ static int wfx_scan_start(struct wfx_vif *wvif,
 static int update_probe_tmpl(struct wfx_vif *wvif,
                             struct cfg80211_scan_request *req)
 {
-       struct hif_mib_template_frame *tmpl;
        struct sk_buff *skb;
 
        skb = ieee80211_probereq_get(wvif->wdev->hw, wvif->vif->addr,
@@ -61,11 +60,7 @@ static int update_probe_tmpl(struct wfx_vif *wvif,
                return -ENOMEM;
 
        skb_put_data(skb, req->ie, req->ie_len);
-       skb_push(skb, 4);
-       tmpl = (struct hif_mib_template_frame *)skb->data;
-       tmpl->frame_type = HIF_TMPLT_PRBREQ;
-       tmpl->frame_length = cpu_to_le16(skb->len - 4);
-       hif_set_template_frame(wvif, tmpl);
+       hif_set_template_frame(wvif, skb, HIF_TMPLT_PRBREQ, 0);
        dev_kfree_skb(skb);
        return 0;
 }
index 19ca135..ba3e81f 100644 (file)
@@ -831,32 +831,20 @@ static int wfx_update_beaconing(struct wfx_vif *wvif)
 
 static int wfx_upload_beacon(struct wfx_vif *wvif)
 {
-       int ret = 0;
-       struct sk_buff *skb = NULL;
+       struct sk_buff *skb;
        struct ieee80211_mgmt *mgmt;
-       struct hif_mib_template_frame *p;
 
        if (wvif->vif->type == NL80211_IFTYPE_STATION ||
            wvif->vif->type == NL80211_IFTYPE_MONITOR ||
            wvif->vif->type == NL80211_IFTYPE_UNSPECIFIED)
-               goto done;
+               return 0;
 
        skb = ieee80211_beacon_get(wvif->wdev->hw, wvif->vif);
-
        if (!skb)
                return -ENOMEM;
+       hif_set_template_frame(wvif, skb, HIF_TMPLT_BCN,
+                              API_RATE_INDEX_B_1MBPS);
 
-       p = (struct hif_mib_template_frame *) skb_push(skb, 4);
-       p->frame_type = HIF_TMPLT_BCN;
-       p->init_rate = API_RATE_INDEX_B_1MBPS; /* 1Mbps DSSS */
-       p->frame_length = cpu_to_le16(skb->len - 4);
-
-       ret = hif_set_template_frame(wvif, p);
-
-       skb_pull(skb, 4);
-
-       if (ret)
-               goto done;
        /* TODO: Distill probe resp; remove TIM and any other beacon-specific
         * IEs
         */
@@ -864,14 +852,11 @@ static int wfx_upload_beacon(struct wfx_vif *wvif)
        mgmt->frame_control =
                cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP);
 
-       p->frame_type = HIF_TMPLT_PRBRES;
-
-       ret = hif_set_template_frame(wvif, p);
+       hif_set_template_frame(wvif, skb, HIF_TMPLT_PRBRES,
+                              API_RATE_INDEX_B_1MBPS);
        wfx_fwd_probe_req(wvif, false);
-
-done:
        dev_kfree_skb(skb);
-       return ret;
+       return 0;
 }
 
 static int wfx_is_ht(const struct wfx_ht_info *ht_info)