diff mbox series

[v2,49/55] staging: wfx: simplify hif_set_template_frame() usage

Message ID 20191217161318.31402-50-Jerome.Pouiller@silabs.com (mailing list archive)
State Not Applicable
Delegated to: Johannes Berg
Headers show
Series Improve wfx driver | expand

Commit Message

Jérôme Pouiller Dec. 17, 2019, 4:15 p.m. UTC
From: Jérôme Pouiller <jerome.pouiller@silabs.com>

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>
---
 drivers/staging/wfx/hif_tx_mib.h | 11 ++++++++++-
 drivers/staging/wfx/scan.c       |  7 +------
 drivers/staging/wfx/sta.c        | 29 +++++++----------------------
 3 files changed, 18 insertions(+), 29 deletions(-)
diff mbox series

Patch

diff --git a/drivers/staging/wfx/hif_tx_mib.h b/drivers/staging/wfx/hif_tx_mib.h
index d77765f75f10..b1eeda2a3ab3 100644
--- a/drivers/staging/wfx/hif_tx_mib.h
+++ b/drivers/staging/wfx/hif_tx_mib.h
@@ -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));
 }
diff --git a/drivers/staging/wfx/scan.c b/drivers/staging/wfx/scan.c
index 8b184efad0cf..c82c04ff5d06 100644
--- a/drivers/staging/wfx/scan.c
+++ b/drivers/staging/wfx/scan.c
@@ -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;
 }
diff --git a/drivers/staging/wfx/sta.c b/drivers/staging/wfx/sta.c
index 19ca13543a25..ba3e81fd477b 100644
--- a/drivers/staging/wfx/sta.c
+++ b/drivers/staging/wfx/sta.c
@@ -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)