linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 mac80211-next 0/7] introduce individual TWT support in AP mode
@ 2021-08-09 17:28 Lorenzo Bianconi
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 1/7] mac80211: add twt ie in ieee80211_mgmt structure Lorenzo Bianconi
                   ` (6 more replies)
  0 siblings, 7 replies; 10+ messages in thread
From: Lorenzo Bianconi @ 2021-08-09 17:28 UTC (permalink / raw)
  To: nbd, johannes; +Cc: linux-wireless, lorenzo.bianconi, ryder.lee, chui-hao.chiu

Introduce TWT action frames parsing support to mac80211.
Currently just individual TWT agreement are support in AP mode.
Whenever the AP receives a TWT action frame from an associated client,
after performing sanity checks, it will notify the underlay driver with
requested parameters in order to check if they are supported and if there
is enough room for a new agreement. The hw is expected to set agreement
result and report it to mac80211.
The two following drv callbacks have been added to mac80211:
- add_twt_setup (mandatory)
- twt_teardown_request (optional)

mac80211 will send an action frame reply according to the result
reported by the driver/fw.
Add individual TWT support to mt7915 in AP mode.

Changes since v1:
- fix rcu unbalance in mt7915/debugfs.c

Changes since rfc:
- run ieee80211_s1g_status_h_twt only for failed twt action frames
- change add_twt_setup return value from int to void

Lorenzo Bianconi (7):
  mac80211: add twt ie in ieee80211_mgmt structure
  mac80211: introduce individual TWT support in AP mode.
  mt76: mt7915: introduce __mt7915_get_tsf routine
  mt76: mt7915: introduce mt7915_mcu_twt_agrt_update mcu command
  mt76: mt7915: introduce mt7915_mac_add_twt_setup routine
  mt76: mt7915: enable twt responder capability
  mt76: mt7915: add twt_stats knob in debugfs

 .../wireless/mediatek/mt76/mt7915/debugfs.c   |  28 +++
 .../net/wireless/mediatek/mt76/mt7915/init.c  |   3 +
 .../net/wireless/mediatek/mt76/mt7915/mac.c   | 185 ++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7915/main.c  |  39 +++-
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   |  50 +++++
 .../net/wireless/mediatek/mt76/mt7915/mcu.h   |   9 +
 .../wireless/mediatek/mt76/mt7915/mt7915.h    |  39 +++-
 include/linux/ieee80211.h                     |  67 ++++++
 include/net/mac80211.h                        |  13 ++
 net/mac80211/driver-ops.h                     |  24 +++
 net/mac80211/ieee80211_i.h                    |   5 +
 net/mac80211/iface.c                          |  13 ++
 net/mac80211/rx.c                             |  54 +++++
 net/mac80211/s1g.c                            | 198 ++++++++++++++++++
 net/mac80211/status.c                         |  34 ++-
 15 files changed, 754 insertions(+), 7 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 mac80211-next 1/7] mac80211: add twt ie in ieee80211_mgmt structure
  2021-08-09 17:28 [PATCH v2 mac80211-next 0/7] introduce individual TWT support in AP mode Lorenzo Bianconi
@ 2021-08-09 17:28 ` Lorenzo Bianconi
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 2/7] mac80211: introduce individual TWT support in AP mode Lorenzo Bianconi
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Lorenzo Bianconi @ 2021-08-09 17:28 UTC (permalink / raw)
  To: nbd, johannes; +Cc: linux-wireless, lorenzo.bianconi, ryder.lee, chui-hao.chiu

Introduce TWT definitions and TWT Information element structure
in ieee80211.h

Tested-by: Peter Chiu <chui-hao.chiu@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 include/linux/ieee80211.h | 67 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index a6730072d13a..57bcec44c00f 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -1088,6 +1088,53 @@ struct ieee80211_ext {
 	} u;
 } __packed __aligned(2);
 
+#define IEEE80211_TWT_CONTROL_NDP			BIT(0)
+#define IEEE80211_TWT_CONTROL_RESP_MODE			BIT(1)
+#define IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST	BIT(2)
+#define IEEE80211_TWT_CONTROL_RX_DISABLED		BIT(4)
+#define IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT		BIT(5)
+
+#define IEEE80211_TWT_REQTYPE_REQUEST			BIT(0)
+#define IEEE80211_TWT_REQTYPE_SETUP_CMD			GENMASK(3, 1)
+#define IEEE80211_TWT_REQTYPE_TRIGGER			BIT(4)
+#define IEEE80211_TWT_REQTYPE_IMPLICIT			BIT(5)
+#define IEEE80211_TWT_REQTYPE_FLOWTYPE			BIT(6)
+#define IEEE80211_TWT_REQTYPE_FLOWID			GENMASK(9, 7)
+#define IEEE80211_TWT_REQTYPE_WAKE_INT_EXP		GENMASK(14, 10)
+#define IEEE80211_TWT_REQTYPE_PROTECTION		BIT(15)
+
+enum ieee80211_twt_setup_cmd {
+	TWT_SETUP_CMD_REQUEST,
+	TWT_SETUP_CMD_SUGGEST,
+	TWT_SETUP_CMD_DEMAND,
+	TWT_SETUP_CMD_GROUPING,
+	TWT_SETUP_CMD_ACCEPT,
+	TWT_SETUP_CMD_ALTERNATE,
+	TWT_SETUP_CMD_DICTATE,
+	TWT_SETUP_CMD_REJECT,
+};
+
+struct ieee80211_twt_params {
+	u8 control;
+	__le16 req_type;
+	__le64 twt;
+	u8 min_twt_dur;
+	__le16 mantissa;
+	u8 channel;
+} __packed;
+
+struct ieee80211_twt_setup {
+	u8 dialog_token;
+	u8 element_id;
+	u8 length;
+	u8 params[0];
+} __packed;
+
+#define IEEE80211_TWT_IND_SETUP_SIZE		\
+	(IEEE80211_MIN_ACTION_SIZE + 1 +	\
+	 sizeof(struct ieee80211_twt_setup) +	\
+	 sizeof(struct ieee80211_twt_params))
+
 struct ieee80211_mgmt {
 	__le16 frame_control;
 	__le16 duration;
@@ -1252,6 +1299,10 @@ struct ieee80211_mgmt {
 					__le16 toa_error;
 					u8 variable[0];
 				} __packed ftm;
+				struct {
+					u8 action_code;
+					u8 variable[0];
+				} __packed s1g;
 			} u;
 		} __packed action;
 	} u;
@@ -2881,6 +2932,7 @@ enum ieee80211_eid {
 	WLAN_EID_AID_RESPONSE = 211,
 	WLAN_EID_S1G_BCN_COMPAT = 213,
 	WLAN_EID_S1G_SHORT_BCN_INTERVAL = 214,
+	WLAN_EID_S1G_TWT = 216,
 	WLAN_EID_S1G_CAPABILITIES = 217,
 	WLAN_EID_VENDOR_SPECIFIC = 221,
 	WLAN_EID_QOS_PARAMETER = 222,
@@ -2950,6 +3002,7 @@ enum ieee80211_category {
 	WLAN_CATEGORY_FST = 18,
 	WLAN_CATEGORY_UNPROT_DMG = 20,
 	WLAN_CATEGORY_VHT = 21,
+	WLAN_CATEGORY_S1G = 22,
 	WLAN_CATEGORY_VENDOR_SPECIFIC_PROTECTED = 126,
 	WLAN_CATEGORY_VENDOR_SPECIFIC = 127,
 };
@@ -3023,6 +3076,20 @@ enum ieee80211_key_len {
 	WLAN_KEY_LEN_BIP_GMAC_256 = 32,
 };
 
+enum ieee80211_s1g_actioncode {
+	WLAN_S1G_AID_SWITCH_REQUEST,
+	WLAN_S1G_AID_SWITCH_RESPONSE,
+	WLAN_S1G_SYNC_CONTROL,
+	WLAN_S1G_STA_INFO_ANNOUNCE,
+	WLAN_S1G_EDCA_PARAM_SET,
+	WLAN_S1G_EL_OPERATION,
+	WLAN_S1G_TWT_SETUP,
+	WLAN_S1G_TWT_TEARDOWN,
+	WLAN_S1G_SECT_GROUP_ID_LIST,
+	WLAN_S1G_SECT_ID_FEEDBACK,
+	WLAN_S1G_TWT_INFORMATION = 11,
+};
+
 #define IEEE80211_WEP_IV_LEN		4
 #define IEEE80211_WEP_ICV_LEN		4
 #define IEEE80211_CCMP_HDR_LEN		8
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 mac80211-next 2/7] mac80211: introduce individual TWT support in AP mode.
  2021-08-09 17:28 [PATCH v2 mac80211-next 0/7] introduce individual TWT support in AP mode Lorenzo Bianconi
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 1/7] mac80211: add twt ie in ieee80211_mgmt structure Lorenzo Bianconi
@ 2021-08-09 17:28 ` Lorenzo Bianconi
  2021-08-17 11:34   ` Johannes Berg
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 3/7] mt76: mt7915: introduce __mt7915_get_tsf routine Lorenzo Bianconi
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 10+ messages in thread
From: Lorenzo Bianconi @ 2021-08-09 17:28 UTC (permalink / raw)
  To: nbd, johannes; +Cc: linux-wireless, lorenzo.bianconi, ryder.lee, chui-hao.chiu

Introduce TWT action frames parsing support to mac80211.
Currently just individual TWT agreement are support in AP mode.
Whenever the AP receives a TWT action frame from an associated client,
after performing sanity checks, it will notify the underlay driver with
requested parameters in order to check if they are supported and if there
is enough room for a new agreement. The hw is expected to set agreement
result and report it to mac80211.
The two following drv callbacks have been added to mac80211:
- add_twt_setup (mandatory)
- twt_teardown_request (optional)

mac80211 will send an action frame reply according to the result
reported by the driver/fw.

Tested-by: Peter Chiu <chui-hao.chiu@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 include/net/mac80211.h     |  13 +++
 net/mac80211/driver-ops.h  |  24 +++++
 net/mac80211/ieee80211_i.h |   5 +
 net/mac80211/iface.c       |  13 +++
 net/mac80211/rx.c          |  54 ++++++++++
 net/mac80211/s1g.c         | 198 +++++++++++++++++++++++++++++++++++++
 net/mac80211/status.c      |  34 ++++++-
 7 files changed, 340 insertions(+), 1 deletion(-)

diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index d8a1d09a2141..ecf7c2aea171 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -3919,6 +3919,13 @@ struct ieee80211_prep_tx_info {
  * @set_sar_specs: Update the SAR (TX power) settings.
  * @sta_set_decap_offload: Called to notify the driver when a station is allowed
  *	to use rx decapsulation offload
+ * @add_twt_setup: Update hw with TWT agreement parameters received from the peer.
+ *	This callback allows the hw to check if requested parameters
+ *	are supported and if there is enough room for a new agreement.
+ *	The hw is expected to set agreement result in the req_type field of
+ *	agrt_resp structure.
+ * @twt_teardown_request: Update the hw with TWT teardown request received
+ *	from the peer.
  */
 struct ieee80211_ops {
 	void (*tx)(struct ieee80211_hw *hw,
@@ -4242,6 +4249,12 @@ struct ieee80211_ops {
 	void (*sta_set_decap_offload)(struct ieee80211_hw *hw,
 				      struct ieee80211_vif *vif,
 				      struct ieee80211_sta *sta, bool enabled);
+	void (*add_twt_setup)(struct ieee80211_hw *hw,
+			      struct ieee80211_sta *sta,
+			      struct ieee80211_twt_params *agrt_req,
+			      struct ieee80211_twt_params *agrt_resp);
+	void (*twt_teardown_request)(struct ieee80211_hw *hw,
+				     struct ieee80211_sta *sta, u8 flowid);
 };
 
 /**
diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index bcb7cc06db3d..7adf7809d003 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -1447,4 +1447,28 @@ static inline void drv_sta_set_decap_offload(struct ieee80211_local *local,
 	trace_drv_return_void(local);
 }
 
+static inline void drv_add_twt_setup(struct ieee80211_local *local,
+				     struct ieee80211_sub_if_data *sdata,
+				     struct ieee80211_sta *sta,
+				     struct ieee80211_twt_params *agrt_req,
+				     struct ieee80211_twt_params *agrt_resp)
+{
+	might_sleep();
+	check_sdata_in_driver(sdata);
+
+	local->ops->add_twt_setup(&local->hw, sta, agrt_req, agrt_resp);
+}
+
+static inline void drv_twt_teardown_request(struct ieee80211_local *local,
+					    struct ieee80211_sub_if_data *sdata,
+					    struct ieee80211_sta *sta,
+					    u8 flowid)
+{
+	might_sleep();
+	check_sdata_in_driver(sdata);
+
+	if (local->ops->twt_teardown_request)
+		local->ops->twt_teardown_request(&local->hw, sta, flowid);
+}
+
 #endif /* __MAC80211_DRIVER_OPS */
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 22549b95d1aa..895581a8b621 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -2068,6 +2068,11 @@ ieee80211_he_op_ie_to_bss_conf(struct ieee80211_vif *vif,
 
 /* S1G */
 void ieee80211_s1g_sta_rate_init(struct sta_info *sta);
+bool ieee80211_s1g_is_twt_setup(struct sk_buff *skb);
+void ieee80211_s1g_rx_h_twt(struct ieee80211_sub_if_data *sdata,
+			    struct sk_buff *skb);
+void ieee80211_s1g_status_h_twt(struct ieee80211_sub_if_data *sdata,
+				struct sk_buff *skb);
 
 /* Spectrum management */
 void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 1e5e9fc45523..1bf24251ba3d 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -1381,6 +1381,19 @@ static void ieee80211_iface_process_skb(struct ieee80211_local *local,
 			WARN_ON(1);
 			break;
 		}
+	} else if (ieee80211_is_action(mgmt->frame_control) &&
+		   mgmt->u.action.category == WLAN_CATEGORY_S1G) {
+		switch (mgmt->u.action.u.s1g.action_code) {
+		case WLAN_S1G_TWT_TEARDOWN:
+		case WLAN_S1G_TWT_SETUP:
+			if (skb->pkt_type == IEEE80211_TX_STATUS_MSG)
+				ieee80211_s1g_status_h_twt(sdata, skb);
+			else
+				ieee80211_s1g_rx_h_twt(sdata, skb);
+			break;
+		default:
+			break;
+		}
 	} else if (ieee80211_is_ext(mgmt->frame_control)) {
 		if (sdata->vif.type == NL80211_IFTYPE_STATION)
 			ieee80211_sta_rx_queued_ext(sdata, skb);
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 771921c057e8..345de0e5e4fa 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -3206,6 +3206,50 @@ ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
 	return RX_CONTINUE;
 }
 
+static ieee80211_rx_result debug_noinline
+ieee80211_rx_h_twt(struct ieee80211_rx_data *rx)
+{
+	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)rx->skb->data;
+	struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
+	struct ieee80211_sub_if_data *sdata = rx->sdata;
+	const struct ieee80211_sband_iftype_data *iftd;
+	struct ieee80211_supported_band *sband;
+
+	/* TWT actions are only supported in AP for the moment */
+	if (sdata->vif.type != NL80211_IFTYPE_AP)
+		return RX_CONTINUE;
+
+	sband = rx->local->hw.wiphy->bands[status->band];
+	iftd = ieee80211_get_sband_iftype_data(sband, sdata->vif.type);
+	if (!iftd)
+		return RX_CONTINUE;
+
+	if (!rx->local->ops->add_twt_setup)
+		return RX_CONTINUE;
+
+	if (!(iftd->he_cap.he_cap_elem.mac_cap_info[0] &
+	      IEEE80211_HE_MAC_CAP0_TWT_RES))
+		return RX_CONTINUE;
+
+	if (!rx->sta)
+		return RX_CONTINUE;
+
+	switch (mgmt->u.action.u.s1g.action_code) {
+	case WLAN_S1G_TWT_SETUP:
+		if (rx->skb->len < IEEE80211_TWT_IND_SETUP_SIZE)
+			break;
+		return RX_QUEUED;
+	case WLAN_S1G_TWT_TEARDOWN:
+		if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE + 2)
+			break;
+		return RX_QUEUED;
+	default:
+		break;
+	}
+
+	return RX_CONTINUE;
+}
+
 static ieee80211_rx_result debug_noinline
 ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
 {
@@ -3485,6 +3529,16 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
 		    !mesh_path_sel_is_hwmp(sdata))
 			break;
 		goto queue;
+	case WLAN_CATEGORY_S1G:
+		switch (mgmt->u.action.u.s1g.action_code) {
+		case WLAN_S1G_TWT_SETUP:
+		case WLAN_S1G_TWT_TEARDOWN:
+			if (ieee80211_rx_h_twt(rx) != RX_CONTINUE)
+				goto queue;
+		default:
+			break;
+		}
+		break;
 	}
 
 	return RX_CONTINUE;
diff --git a/net/mac80211/s1g.c b/net/mac80211/s1g.c
index c33f332b049a..053dc3fafc41 100644
--- a/net/mac80211/s1g.c
+++ b/net/mac80211/s1g.c
@@ -6,6 +6,7 @@
 #include <linux/ieee80211.h>
 #include <net/mac80211.h>
 #include "ieee80211_i.h"
+#include "driver-ops.h"
 
 void ieee80211_s1g_sta_rate_init(struct sta_info *sta)
 {
@@ -14,3 +15,200 @@ void ieee80211_s1g_sta_rate_init(struct sta_info *sta)
 	sta->rx_stats.last_rate =
 			STA_STATS_FIELD(TYPE, STA_STATS_RATE_TYPE_S1G);
 }
+
+bool ieee80211_s1g_is_twt_setup(struct sk_buff *skb)
+{
+	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
+
+	if (likely(!ieee80211_is_action(mgmt->frame_control)))
+		return false;
+
+	if (likely(mgmt->u.action.category != WLAN_CATEGORY_S1G))
+		return false;
+
+	return mgmt->u.action.u.s1g.action_code == WLAN_S1G_TWT_SETUP;
+}
+
+static int
+ieee80211_s1g_send_twt_setup(struct ieee80211_sub_if_data *sdata,
+			     const u8 *da, const u8 *bssid, u8 dialog_token,
+			     struct ieee80211_twt_params *params)
+{
+	struct ieee80211_local *local = sdata->local;
+	struct ieee80211_twt_setup *twt;
+	struct ieee80211_mgmt *mgmt;
+	struct sk_buff *skb;
+
+	skb = dev_alloc_skb(local->hw.extra_tx_headroom +
+			    IEEE80211_TWT_IND_SETUP_SIZE);
+	if (!skb)
+		return -ENOMEM;
+
+	skb_reserve(skb, local->hw.extra_tx_headroom);
+	mgmt = skb_put_zero(skb, IEEE80211_TWT_IND_SETUP_SIZE);
+	mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
+					  IEEE80211_STYPE_ACTION);
+	memcpy(mgmt->da, da, ETH_ALEN);
+	memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
+	memcpy(mgmt->bssid, bssid, ETH_ALEN);
+
+	mgmt->u.action.category = WLAN_CATEGORY_S1G;
+	mgmt->u.action.u.s1g.action_code = WLAN_S1G_TWT_SETUP;
+
+	twt = (struct ieee80211_twt_setup *)mgmt->u.action.u.s1g.variable;
+	twt->dialog_token = dialog_token;
+	twt->element_id = WLAN_EID_S1G_TWT;
+	twt->length = sizeof(struct ieee80211_twt_params);
+
+	memcpy(twt->params, params, twt->length);
+
+	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
+					IEEE80211_TX_CTL_REQ_TX_STATUS;
+	ieee80211_tx_skb(sdata, skb);
+
+	return 0;
+}
+
+static int
+ieee80211_s1g_send_twt_teardown(struct ieee80211_sub_if_data *sdata,
+				const u8 *da, const u8 *bssid, u8 flowid)
+{
+	struct ieee80211_local *local = sdata->local;
+	struct ieee80211_mgmt *mgmt;
+	struct sk_buff *skb;
+	u8 *id;
+
+	skb = dev_alloc_skb(local->hw.extra_tx_headroom +
+			    IEEE80211_MIN_ACTION_SIZE + 2);
+	if (!skb)
+		return -ENOMEM;
+
+	skb_reserve(skb, local->hw.extra_tx_headroom);
+	mgmt = skb_put_zero(skb, IEEE80211_MIN_ACTION_SIZE + 2);
+	mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
+					  IEEE80211_STYPE_ACTION);
+	memcpy(mgmt->da, da, ETH_ALEN);
+	memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
+	memcpy(mgmt->bssid, bssid, ETH_ALEN);
+
+	mgmt->u.action.category = WLAN_CATEGORY_S1G;
+	mgmt->u.action.u.s1g.action_code = WLAN_S1G_TWT_TEARDOWN;
+	id = (u8 *)mgmt->u.action.u.s1g.variable;
+	*id = flowid;
+
+	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
+					IEEE80211_TX_CTL_REQ_TX_STATUS;
+	ieee80211_tx_skb(sdata, skb);
+
+	return 0;
+}
+
+static int
+ieee80211_s1g_rx_h_twt_setup(struct ieee80211_sub_if_data *sdata,
+			     struct sta_info *sta, struct sk_buff *skb)
+{
+	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
+	struct ieee80211_twt_params *agrt_req, agrt_resp;
+	struct ieee80211_twt_setup *twt;
+
+	twt = (struct ieee80211_twt_setup *)mgmt->u.action.u.s1g.variable;
+	if (twt->element_id != WLAN_EID_S1G_TWT)
+		return -EINVAL;
+
+	agrt_req = (struct ieee80211_twt_params *)twt->params;
+
+	/* broadcast TWT not supported yet */
+	if (agrt_req->control & IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST)
+		return -EINVAL;
+
+	drv_add_twt_setup(sdata->local, sdata, &sta->sta, agrt_req,
+			  &agrt_resp);
+
+	return ieee80211_s1g_send_twt_setup(sdata, mgmt->sa, sdata->vif.addr,
+					    twt->dialog_token, &agrt_resp);
+}
+
+static int
+ieee80211_s1g_status_twt_setup(struct ieee80211_sub_if_data *sdata,
+			       struct sta_info *sta, struct sk_buff *skb)
+{
+	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
+	struct ieee80211_twt_params *agrt_resp;
+	struct ieee80211_twt_setup *twt;
+	u8 flowid;
+
+	twt = (struct ieee80211_twt_setup *)mgmt->u.action.u.s1g.variable;
+	agrt_resp = (struct ieee80211_twt_params *)twt->params;
+	flowid = FIELD_GET(IEEE80211_TWT_REQTYPE_FLOWID,
+			   le16_to_cpu(agrt_resp->req_type));
+
+	drv_twt_teardown_request(sdata->local, sdata, &sta->sta, flowid);
+
+	return ieee80211_s1g_send_twt_teardown(sdata, mgmt->sa,
+					       sdata->vif.addr, flowid);
+}
+
+static int
+ieee80211_s1g_rx_h_twt_teardown(struct ieee80211_sub_if_data *sdata,
+				struct sta_info *sta, struct sk_buff *skb)
+{
+	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
+
+	drv_twt_teardown_request(sdata->local, sdata, &sta->sta,
+				 mgmt->u.action.u.s1g.variable[0]);
+
+	return 0;
+}
+
+void ieee80211_s1g_rx_h_twt(struct ieee80211_sub_if_data *sdata,
+			    struct sk_buff *skb)
+{
+	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
+	struct ieee80211_local *local = sdata->local;
+	struct sta_info *sta;
+
+	mutex_lock(&local->sta_mtx);
+
+	sta = sta_info_get_bss(sdata, mgmt->sa);
+	if (!sta)
+		goto out;
+
+	switch (mgmt->u.action.u.s1g.action_code) {
+	case WLAN_S1G_TWT_SETUP:
+		ieee80211_s1g_rx_h_twt_setup(sdata, sta, skb);
+		break;
+	case WLAN_S1G_TWT_TEARDOWN:
+		ieee80211_s1g_rx_h_twt_teardown(sdata, sta, skb);
+		break;
+	default:
+		break;
+	}
+
+out:
+	mutex_unlock(&local->sta_mtx);
+}
+
+void ieee80211_s1g_status_h_twt(struct ieee80211_sub_if_data *sdata,
+				struct sk_buff *skb)
+{
+	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
+	struct ieee80211_local *local = sdata->local;
+	struct sta_info *sta;
+
+	mutex_lock(&local->sta_mtx);
+
+	sta = sta_info_get_bss(sdata, mgmt->da);
+	if (!sta)
+		goto out;
+
+	switch (mgmt->u.action.u.s1g.action_code) {
+	case WLAN_S1G_TWT_SETUP:
+		ieee80211_s1g_status_twt_setup(sdata, sta, skb);
+		break;
+	default:
+		break;
+	}
+
+out:
+	mutex_unlock(&local->sta_mtx);
+}
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
index bae321ff77f6..2c4e7ef21869 100644
--- a/net/mac80211/status.c
+++ b/net/mac80211/status.c
@@ -17,6 +17,33 @@
 #include "led.h"
 #include "wme.h"
 
+static struct sk_buff *
+ieee80211_tx_queue_skb(struct ieee80211_hw *hw,
+		       struct ieee80211_tx_status *status,
+		       bool monitor)
+{
+	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(status->skb);
+	struct sk_buff *skb = status->skb;
+	struct sta_info *sta;
+
+	if (!status->sta)
+		goto out;
+
+	if (likely(!ieee80211_s1g_is_twt_setup(skb)))
+		goto out;
+
+	if (info->flags & IEEE80211_TX_STAT_ACK)
+		goto out; /* nothing to do */
+
+	sta = container_of(status->sta, struct sta_info, sta);
+	skb->pkt_type = IEEE80211_TX_STATUS_MSG;
+	skb_queue_tail(&sta->sdata->skb_queue, skb);
+	skb = monitor ? skb_clone(skb, GFP_ATOMIC) : NULL;
+	ieee80211_queue_work(hw, &sta->sdata->work);
+
+out:
+	return skb;
+}
 
 void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
 				 struct sk_buff *skb)
@@ -1046,13 +1073,18 @@ static void __ieee80211_tx_status(struct ieee80211_hw *hw,
 	 * with this test...
 	 */
 	if (!local->monitors && (!send_to_cooked || !local->cooked_mntrs)) {
-		if (status->free_list)
+		skb = ieee80211_tx_queue_skb(hw, status, false);
+		if (skb && status->free_list)
 			list_add_tail(&skb->list, status->free_list);
 		else
 			dev_kfree_skb(skb);
 		return;
 	}
 
+	skb = ieee80211_tx_queue_skb(hw, status, true);
+	if (!skb)
+		return;
+
 	/* send to monitor interfaces */
 	ieee80211_tx_monitor(local, skb, sband, retry_count, shift,
 			     send_to_cooked, status);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 mac80211-next 3/7] mt76: mt7915: introduce __mt7915_get_tsf routine
  2021-08-09 17:28 [PATCH v2 mac80211-next 0/7] introduce individual TWT support in AP mode Lorenzo Bianconi
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 1/7] mac80211: add twt ie in ieee80211_mgmt structure Lorenzo Bianconi
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 2/7] mac80211: introduce individual TWT support in AP mode Lorenzo Bianconi
@ 2021-08-09 17:28 ` Lorenzo Bianconi
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 4/7] mt76: mt7915: introduce mt7915_mcu_twt_agrt_update mcu command Lorenzo Bianconi
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Lorenzo Bianconi @ 2021-08-09 17:28 UTC (permalink / raw)
  To: nbd, johannes; +Cc: linux-wireless, lorenzo.bianconi, ryder.lee, chui-hao.chiu

Introduce an unlocked verion of mt7915_get_tsf routine.
This is a preliminary patch to add TWT support to mt7915.

Tested-by: Peter Chiu <chui-hao.chiu@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 .../net/wireless/mediatek/mt76/mt7915/main.c  | 20 ++++++++++++++-----
 .../wireless/mediatek/mt76/mt7915/mt7915.h    |  2 +-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
index 48b5e2051bad..fa4fd04affd8 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -789,10 +789,8 @@ mt7915_get_stats(struct ieee80211_hw *hw,
 	return 0;
 }
 
-static u64
-mt7915_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
+u64 __mt7915_get_tsf(struct ieee80211_hw *hw, struct mt7915_vif *mvif)
 {
-	struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
 	struct mt7915_dev *dev = mt7915_hw_dev(hw);
 	struct mt7915_phy *phy = mt7915_hw_phy(hw);
 	bool band = phy != &dev->phy;
@@ -802,7 +800,7 @@ mt7915_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 	} tsf;
 	u16 n;
 
-	mutex_lock(&dev->mt76.mutex);
+	lockdep_assert_held(&dev->mt76.mutex);
 
 	n = mvif->omac_idx > HW_BSSID_MAX ? HW_BSSID_0 : mvif->omac_idx;
 	/* TSF software read */
@@ -811,9 +809,21 @@ mt7915_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 	tsf.t32[0] = mt76_rr(dev, MT_LPON_UTTR0(band));
 	tsf.t32[1] = mt76_rr(dev, MT_LPON_UTTR1(band));
 
+	return tsf.t64;
+}
+
+static u64
+mt7915_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
+{
+	struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv;
+	struct mt7915_dev *dev = mt7915_hw_dev(hw);
+	u64 ret;
+
+	mutex_lock(&dev->mt76.mutex);
+	ret = __mt7915_get_tsf(hw, mvif);
 	mutex_unlock(&dev->mt76.mutex);
 
-	return tsf.t64;
+	return ret;
 }
 
 static void
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
index a6b5b300d415..068ef0f881b8 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
@@ -271,7 +271,7 @@ extern const struct ieee80211_ops mt7915_ops;
 extern const struct mt76_testmode_ops mt7915_testmode_ops;
 
 u32 mt7915_reg_map(struct mt7915_dev *dev, u32 addr);
-
+u64 __mt7915_get_tsf(struct ieee80211_hw *hw, struct mt7915_vif *mvif);
 int mt7915_register_device(struct mt7915_dev *dev);
 void mt7915_unregister_device(struct mt7915_dev *dev);
 int mt7915_eeprom_init(struct mt7915_dev *dev);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 mac80211-next 4/7] mt76: mt7915: introduce mt7915_mcu_twt_agrt_update mcu command
  2021-08-09 17:28 [PATCH v2 mac80211-next 0/7] introduce individual TWT support in AP mode Lorenzo Bianconi
                   ` (2 preceding siblings ...)
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 3/7] mt76: mt7915: introduce __mt7915_get_tsf routine Lorenzo Bianconi
@ 2021-08-09 17:28 ` Lorenzo Bianconi
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 5/7] mt76: mt7915: introduce mt7915_mac_add_twt_setup routine Lorenzo Bianconi
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 10+ messages in thread
From: Lorenzo Bianconi @ 2021-08-09 17:28 UTC (permalink / raw)
  To: nbd, johannes; +Cc: linux-wireless, lorenzo.bianconi, ryder.lee, chui-hao.chiu

This is a preliminary patch to add TWT support to mt7915

Tested-by: Peter Chiu <chui-hao.chiu@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 .../net/wireless/mediatek/mt76/mt7915/mcu.c   | 50 +++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7915/mcu.h   |  9 ++++
 .../wireless/mediatek/mt76/mt7915/mt7915.h    | 19 +++++++
 3 files changed, 78 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
index f84c49969479..2266bc1c0de0 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c
@@ -3904,3 +3904,53 @@ int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif,
 
 	return ret;
 }
+
+#define TWT_AGRT_TRIGGER	BIT(0)
+#define TWT_AGRT_ANNOUNCE	BIT(1)
+#define TWT_AGRT_PROTECT	BIT(2)
+
+int mt7915_mcu_twt_agrt_update(struct mt7915_dev *dev,
+			       struct mt7915_vif *mvif,
+			       struct mt7915_twt_flow *flow,
+			       int cmd)
+{
+	struct {
+		u8 tbl_idx;
+		u8 cmd;
+		u8 own_mac_idx;
+		u8 flowid; /* 0xff for group id */
+		__le16 peer_id; /* specify the peer_id (msb=0)
+				 * or group_id (msb=1)
+				 */
+		u8 duration; /* 256 us */
+		u8 bss_idx;
+		__le64 start_tsf;
+		__le16 mantissa;
+		u8 exponent;
+		u8 is_ap;
+		u8 agrt_params;
+		u8 rsv[23];
+	} __packed req = {
+		.tbl_idx = flow->id,
+		.cmd = cmd,
+		.own_mac_idx = mvif->omac_idx,
+		.flowid = flow->id,
+		.peer_id = cpu_to_le16(flow->wcid),
+		.duration = flow->duration,
+		.bss_idx = mvif->idx,
+		.start_tsf = cpu_to_le64(flow->tsf),
+		.mantissa = flow->mantissa,
+		.exponent = flow->exp,
+		.is_ap = true,
+	};
+
+	if (flow->protection)
+		req.agrt_params |= TWT_AGRT_PROTECT;
+	if (!flow->flowtype)
+		req.agrt_params |= TWT_AGRT_ANNOUNCE;
+	if (flow->trigger)
+		req.agrt_params |= TWT_AGRT_TRIGGER;
+
+	return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TWT_AGRT_UPDATE),
+				 &req, sizeof(req), true);
+}
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
index baa27dab0499..f4ba343b9413 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.h
@@ -276,6 +276,7 @@ enum {
 	MCU_EXT_CMD_MWDS_SUPPORT = 0x80,
 	MCU_EXT_CMD_SET_SER_TRIGGER = 0x81,
 	MCU_EXT_CMD_SCS_CTRL = 0x82,
+	MCU_EXT_CMD_TWT_AGRT_UPDATE = 0x94,
 	MCU_EXT_CMD_FW_DBG_CTRL = 0x95,
 	MCU_EXT_CMD_SET_RDD_TH = 0x9d,
 	MCU_EXT_CMD_SET_SPR = 0xa8,
@@ -284,6 +285,14 @@ enum {
 	MCU_EXT_CMD_PHY_STAT_INFO = 0xad,
 };
 
+enum {
+	MCU_TWT_AGRT_ADD,
+	MCU_TWT_AGRT_MODIFY,
+	MCU_TWT_AGRT_DELETE,
+	MCU_TWT_AGRT_TEARDOWN,
+	MCU_TWT_AGRT_GET_TSF,
+};
+
 enum {
 	MCU_WA_PARAM_CMD_QUERY,
 	MCU_WA_PARAM_CMD_SET,
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
index 068ef0f881b8..ad97980275a3 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
@@ -67,6 +67,21 @@ struct mt7915_sta_key_conf {
 	u8 key[16];
 };
 
+struct mt7915_twt_flow {
+	struct list_head list;
+	u64 start_tsf;
+	u64 tsf;
+	u32 duration;
+	u16 wcid;
+	__le16 mantissa;
+	u8 exp;
+	u8 id;
+	u8 protection:1;
+	u8 flowtype:1;
+	u8 trigger:1;
+	u8 sched:1;
+};
+
 struct mt7915_sta {
 	struct mt76_wcid wcid; /* must be first */
 
@@ -284,6 +299,10 @@ int mt7915_dma_init(struct mt7915_dev *dev);
 void mt7915_dma_prefetch(struct mt7915_dev *dev);
 void mt7915_dma_cleanup(struct mt7915_dev *dev);
 int mt7915_mcu_init(struct mt7915_dev *dev);
+int mt7915_mcu_twt_agrt_update(struct mt7915_dev *dev,
+			       struct mt7915_vif *mvif,
+			       struct mt7915_twt_flow *flow,
+			       int cmd);
 int mt7915_mcu_add_dev_info(struct mt7915_phy *phy,
 			    struct ieee80211_vif *vif, bool enable);
 int mt7915_mcu_add_bss_info(struct mt7915_phy *phy,
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 mac80211-next 5/7] mt76: mt7915: introduce mt7915_mac_add_twt_setup routine
  2021-08-09 17:28 [PATCH v2 mac80211-next 0/7] introduce individual TWT support in AP mode Lorenzo Bianconi
                   ` (3 preceding siblings ...)
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 4/7] mt76: mt7915: introduce mt7915_mcu_twt_agrt_update mcu command Lorenzo Bianconi
@ 2021-08-09 17:28 ` Lorenzo Bianconi
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 6/7] mt76: mt7915: enable twt responder capability Lorenzo Bianconi
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 7/7] mt76: mt7915: add twt_stats knob in debugfs Lorenzo Bianconi
  6 siblings, 0 replies; 10+ messages in thread
From: Lorenzo Bianconi @ 2021-08-09 17:28 UTC (permalink / raw)
  To: nbd, johannes; +Cc: linux-wireless, lorenzo.bianconi, ryder.lee, chui-hao.chiu

Introduce individual TWT support to mt7915 in AP mode.
Implement the two following mac80211 callbacks:
- add_twt_setup
- twt_teardown_request

Tested-by: Peter Chiu <chui-hao.chiu@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 .../net/wireless/mediatek/mt76/mt7915/init.c  |   1 +
 .../net/wireless/mediatek/mt76/mt7915/mac.c   | 185 ++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7915/main.c  |  19 ++
 .../wireless/mediatek/mt76/mt7915/mt7915.h    |  18 ++
 4 files changed, 223 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
index 906dacef5bdf..3ed48542e122 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
@@ -790,6 +790,7 @@ int mt7915_register_device(struct mt7915_dev *dev)
 	INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7915_mac_work);
 	INIT_LIST_HEAD(&dev->sta_rc_list);
 	INIT_LIST_HEAD(&dev->sta_poll_list);
+	INIT_LIST_HEAD(&dev->twt_list);
 	spin_lock_init(&dev->sta_poll_lock);
 
 	init_waitqueue_head(&dev->reset_wait);
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
index f8a81ea9b2bd..88e5d28545ca 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mac.c
@@ -6,6 +6,7 @@
 #include "mt7915.h"
 #include "../dma.h"
 #include "mac.h"
+#include "mcu.h"
 
 #define to_rssi(field, rxv)	((FIELD_GET(field, rxv) - 220) / 2)
 
@@ -2093,3 +2094,187 @@ int mt7915_dfs_init_radar_detector(struct mt7915_phy *phy)
 	mt7915_dfs_stop_radar_detector(phy);
 	return 0;
 }
+
+static int
+mt7915_mac_twt_duration_align(int duration)
+{
+	return duration << 8;
+}
+
+static u64
+mt7915_mac_twt_sched_list_add(struct mt7915_dev *dev,
+			      struct mt7915_twt_flow *flow)
+{
+	struct mt7915_twt_flow *iter, *iter_next;
+	u32 duration = flow->duration << 8;
+	u64 start_tsf;
+
+	iter = list_first_entry_or_null(&dev->twt_list,
+					struct mt7915_twt_flow, list);
+	if (!iter || !iter->sched || iter->start_tsf > duration) {
+		/* add flow as first entry in the list */
+		list_add(&flow->list, &dev->twt_list);
+		return 0;
+	}
+
+	list_for_each_entry_safe(iter, iter_next, &dev->twt_list, list) {
+		start_tsf = iter->start_tsf +
+			    mt7915_mac_twt_duration_align(iter->duration);
+		if (list_is_last(&iter->list, &dev->twt_list))
+			break;
+
+		if (!iter_next->sched ||
+		    iter_next->start_tsf > start_tsf + duration) {
+			list_add(&flow->list, &iter->list);
+			goto out;
+		}
+	}
+
+	/* add flow as last entry in the list */
+	list_add_tail(&flow->list, &dev->twt_list);
+out:
+	return start_tsf;
+}
+
+static int mt7915_mac_check_twt_req(struct ieee80211_twt_params *req)
+{
+	u64 interval, duration = req->min_twt_dur << 8;
+	u16 mantissa = le16_to_cpu(req->mantissa);
+	u8 exp;
+
+	/* only individual agreement supported */
+	if (req->control & IEEE80211_TWT_CONTROL_NEG_TYPE_BROADCAST)
+		return -EOPNOTSUPP;
+
+	/* only 256us unit supported */
+	if (req->control & IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT)
+		return -EOPNOTSUPP;
+
+	/* explicit agreement not supported */
+	if (!(req->req_type & cpu_to_le16(IEEE80211_TWT_REQTYPE_IMPLICIT)))
+		return -EOPNOTSUPP;
+
+	exp = FIELD_GET(IEEE80211_TWT_REQTYPE_WAKE_INT_EXP,
+			le16_to_cpu(req->req_type));
+
+	interval = (u64)mantissa << exp;
+	if (interval < duration)
+		return -EOPNOTSUPP;
+
+	return 0;
+}
+
+void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
+			      struct ieee80211_sta *sta,
+			      struct ieee80211_twt_params *agrt_req,
+			      struct ieee80211_twt_params *agrt_resp)
+{
+	enum ieee80211_twt_setup_cmd setup_cmd = TWT_SETUP_CMD_REJECT;
+	struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
+	u16 req_type, mantissa = le16_to_cpu(agrt_req->mantissa);
+	enum ieee80211_twt_setup_cmd sta_setup_cmd;
+	struct mt7915_dev *dev = mt7915_hw_dev(hw);
+	struct mt7915_twt_flow *flow;
+	int flowid;
+	u8 exp;
+
+	/* init common fields */
+	memset(agrt_resp, 0, sizeof(*agrt_resp));
+	agrt_resp->control |=
+		(agrt_req->control & IEEE80211_TWT_CONTROL_WAKE_DUR_UNIT) |
+		(agrt_req->control & IEEE80211_TWT_CONTROL_RX_DISABLED);
+
+	req_type = le16_to_cpu(agrt_req->req_type) &
+		   ~IEEE80211_TWT_REQTYPE_REQUEST;
+
+	agrt_resp->twt = agrt_req->twt;
+	agrt_resp->min_twt_dur = agrt_req->min_twt_dur;
+	agrt_resp->mantissa = agrt_req->mantissa;
+	agrt_resp->channel = agrt_req->channel;
+
+	if (mt7915_mac_check_twt_req(agrt_req))
+		goto out;
+
+	mutex_lock(&dev->mt76.mutex);
+
+	if (dev->n_twt_agrt == MT7915_MAX_TWT_AGRT)
+		goto unlock;
+
+	if (hweight8(msta->twt.flowid_mask) == ARRAY_SIZE(msta->twt.flow))
+		goto unlock;
+
+	flowid = ffs(~msta->twt.flowid_mask) - 1;
+
+	req_type &= ~IEEE80211_TWT_REQTYPE_FLOWID;
+	req_type |= FIELD_PREP(IEEE80211_TWT_REQTYPE_FLOWID, flowid);
+
+	exp = FIELD_GET(IEEE80211_TWT_REQTYPE_WAKE_INT_EXP,
+			le16_to_cpu(agrt_req->req_type));
+	sta_setup_cmd = FIELD_GET(IEEE80211_TWT_REQTYPE_SETUP_CMD,
+				  le16_to_cpu(agrt_req->req_type));
+
+	flow = &msta->twt.flow[flowid];
+	memset(flow, 0, sizeof(*flow));
+	INIT_LIST_HEAD(&flow->list);
+	flow->wcid = msta->wcid.idx;
+	flow->id = flowid;
+	flow->duration = agrt_req->min_twt_dur;
+	flow->mantissa = agrt_req->mantissa;
+	flow->exp = exp;
+	flow->protection = !!(req_type & IEEE80211_TWT_REQTYPE_PROTECTION);
+	flow->flowtype = !!(req_type & IEEE80211_TWT_REQTYPE_FLOWTYPE);
+	flow->trigger = !!(req_type & IEEE80211_TWT_REQTYPE_TRIGGER);
+
+	if (sta_setup_cmd == TWT_SETUP_CMD_REQUEST ||
+	    sta_setup_cmd == TWT_SETUP_CMD_SUGGEST) {
+		u64 flow_tsf, curr_tsf, interval = (u64)mantissa << exp;
+
+		flow->sched = true;
+		flow->start_tsf = mt7915_mac_twt_sched_list_add(dev, flow);
+		curr_tsf = __mt7915_get_tsf(hw, msta->vif);
+		flow_tsf = curr_tsf + interval -
+			   (curr_tsf - flow->start_tsf) % interval;
+		agrt_resp->twt = cpu_to_le64(flow_tsf);
+	} else {
+		list_add_tail(&flow->list, &dev->twt_list);
+	}
+	flow->tsf = le64_to_cpu(agrt_resp->twt);
+
+	if (mt7915_mcu_twt_agrt_update(dev, msta->vif, flow, MCU_TWT_AGRT_ADD))
+		goto unlock;
+
+	setup_cmd = TWT_SETUP_CMD_ACCEPT;
+	msta->twt.flowid_mask |= BIT(flowid);
+	dev->n_twt_agrt++;
+
+unlock:
+	mutex_unlock(&dev->mt76.mutex);
+out:
+	req_type &= ~IEEE80211_TWT_REQTYPE_SETUP_CMD;
+	req_type |= FIELD_PREP(IEEE80211_TWT_REQTYPE_SETUP_CMD, setup_cmd);
+	agrt_resp->req_type = cpu_to_le16(req_type);
+}
+
+void mt7915_mac_twt_teardown_flow(struct mt7915_dev *dev,
+				  struct mt7915_sta *msta,
+				  u8 flowid)
+{
+	struct mt7915_twt_flow *flow;
+
+	lockdep_assert_held(&dev->mt76.mutex);
+
+	if (flowid >= ARRAY_SIZE(msta->twt.flow))
+		return;
+
+	if (!(msta->twt.flowid_mask & BIT(flowid)))
+		return;
+
+	flow = &msta->twt.flow[flowid];
+	if (mt7915_mcu_twt_agrt_update(dev, msta->vif, flow,
+				       MCU_TWT_AGRT_DELETE))
+		return;
+
+	list_del_init(&flow->list);
+	msta->twt.flowid_mask &= ~BIT(flowid);
+	dev->n_twt_agrt--;
+}
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/main.c b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
index fa4fd04affd8..c8492ce3be07 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -640,6 +640,7 @@ void mt7915_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 {
 	struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76);
 	struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
+	int i;
 
 	mt7915_mcu_add_sta_adv(dev, vif, sta, false);
 	mt7915_mcu_add_sta(dev, vif, sta, false);
@@ -647,6 +648,9 @@ void mt7915_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 	mt7915_mac_wtbl_update(dev, msta->wcid.idx,
 			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
 
+	for (i = 0; i < ARRAY_SIZE(msta->twt.flow); i++)
+		mt7915_mac_twt_teardown_flow(dev, msta, i);
+
 	spin_lock_bh(&dev->sta_poll_lock);
 	if (!list_empty(&msta->poll_list))
 		list_del_init(&msta->poll_list);
@@ -1038,6 +1042,19 @@ static void mt7915_sta_set_decap_offload(struct ieee80211_hw *hw,
 	mt7915_mcu_sta_update_hdr_trans(dev, vif, sta);
 }
 
+static void
+mt7915_twt_teardown_request(struct ieee80211_hw *hw,
+			    struct ieee80211_sta *sta,
+			    u8 flowid)
+{
+	struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv;
+	struct mt7915_dev *dev = mt7915_hw_dev(hw);
+
+	mutex_lock(&dev->mt76.mutex);
+	mt7915_mac_twt_teardown_flow(dev, msta, flowid);
+	mutex_unlock(&dev->mt76.mutex);
+}
+
 const struct ieee80211_ops mt7915_ops = {
 	.tx = mt7915_tx,
 	.start = mt7915_start,
@@ -1073,6 +1090,8 @@ const struct ieee80211_ops mt7915_ops = {
 	.sta_statistics = mt7915_sta_statistics,
 	.sta_set_4addr = mt7915_sta_set_4addr,
 	.sta_set_decap_offload = mt7915_sta_set_decap_offload,
+	.add_twt_setup = mt7915_mac_add_twt_setup,
+	.twt_teardown_request = mt7915_twt_teardown_request,
 	CFG80211_TESTMODE_CMD(mt76_testmode_cmd)
 	CFG80211_TESTMODE_DUMP(mt76_testmode_dump)
 #ifdef CONFIG_MAC80211_DEBUGFS
diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
index ad97980275a3..eebf6a383ff9 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
@@ -41,6 +41,9 @@
 
 #define MT7915_SKU_RATE_NUM		161
 
+#define MT7915_MAX_TWT_AGRT		16
+#define MT7915_MAX_STA_TWT_AGRT		8
+
 struct mt7915_vif;
 struct mt7915_sta;
 struct mt7915_dfs_pulse;
@@ -96,6 +99,11 @@ struct mt7915_sta {
 	unsigned long ampdu_state;
 
 	struct mt7915_sta_key_conf bip;
+
+	struct {
+		u8 flowid_mask;
+		struct mt7915_twt_flow flow[MT7915_MAX_STA_TWT_AGRT];
+	} twt;
 };
 struct mt7915_vif {
 	u16 idx;
@@ -192,6 +200,7 @@ struct mt7915_dev {
 
 	struct list_head sta_rc_list;
 	struct list_head sta_poll_list;
+	struct list_head twt_list;
 	spinlock_t sta_poll_lock;
 
 	u32 hw_pattern;
@@ -202,6 +211,8 @@ struct mt7915_dev {
 	bool ibf;
 
 	void *cal;
+
+	u8 n_twt_agrt;
 };
 
 enum {
@@ -414,6 +425,13 @@ void mt7915_mac_work(struct work_struct *work);
 void mt7915_mac_reset_work(struct work_struct *work);
 void mt7915_mac_sta_rc_work(struct work_struct *work);
 int mt7915_mmio_init(struct mt76_dev *mdev, void __iomem *mem_base, int irq);
+void mt7915_mac_twt_teardown_flow(struct mt7915_dev *dev,
+				  struct mt7915_sta *msta,
+				  u8 flowid);
+void mt7915_mac_add_twt_setup(struct ieee80211_hw *hw,
+			      struct ieee80211_sta *sta,
+			      struct ieee80211_twt_params *agrt_req,
+			      struct ieee80211_twt_params *agrt_resp);
 int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
 			  enum mt76_txq_id qid, struct mt76_wcid *wcid,
 			  struct ieee80211_sta *sta,
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 mac80211-next 6/7] mt76: mt7915: enable twt responder capability
  2021-08-09 17:28 [PATCH v2 mac80211-next 0/7] introduce individual TWT support in AP mode Lorenzo Bianconi
                   ` (4 preceding siblings ...)
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 5/7] mt76: mt7915: introduce mt7915_mac_add_twt_setup routine Lorenzo Bianconi
@ 2021-08-09 17:28 ` Lorenzo Bianconi
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 7/7] mt76: mt7915: add twt_stats knob in debugfs Lorenzo Bianconi
  6 siblings, 0 replies; 10+ messages in thread
From: Lorenzo Bianconi @ 2021-08-09 17:28 UTC (permalink / raw)
  To: nbd, johannes; +Cc: linux-wireless, lorenzo.bianconi, ryder.lee, chui-hao.chiu

Enable TWT support in AP mode

Tested-by: Peter Chiu <chui-hao.chiu@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/mt7915/init.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/init.c b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
index 3ed48542e122..b554de8e7100 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/init.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/init.c
@@ -666,6 +666,8 @@ mt7915_init_he_caps(struct mt7915_phy *phy, enum nl80211_band band,
 
 		switch (i) {
 		case NL80211_IFTYPE_AP:
+			he_cap_elem->mac_cap_info[0] |=
+				IEEE80211_HE_MAC_CAP0_TWT_RES;
 			he_cap_elem->mac_cap_info[2] |=
 				IEEE80211_HE_MAC_CAP2_BSR;
 			he_cap_elem->mac_cap_info[4] |=
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 mac80211-next 7/7] mt76: mt7915: add twt_stats knob in debugfs
  2021-08-09 17:28 [PATCH v2 mac80211-next 0/7] introduce individual TWT support in AP mode Lorenzo Bianconi
                   ` (5 preceding siblings ...)
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 6/7] mt76: mt7915: enable twt responder capability Lorenzo Bianconi
@ 2021-08-09 17:28 ` Lorenzo Bianconi
  6 siblings, 0 replies; 10+ messages in thread
From: Lorenzo Bianconi @ 2021-08-09 17:28 UTC (permalink / raw)
  To: nbd, johannes; +Cc: linux-wireless, lorenzo.bianconi, ryder.lee, chui-hao.chiu

Introduce twt_stats knob in debugfs in order to dump established
agreements

Tested-by: Peter Chiu <chui-hao.chiu@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 .../wireless/mediatek/mt76/mt7915/debugfs.c   | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
index 1a48b09d0cb7..c54239e84243 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7915/debugfs.c
@@ -335,6 +335,32 @@ mt7915_read_rate_txpower(struct seq_file *s, void *data)
 	return 0;
 }
 
+static int
+mt7915_twt_stats(struct seq_file *s, void *data)
+{
+	struct mt7915_dev *dev = dev_get_drvdata(s->private);
+	struct mt7915_twt_flow *iter;
+
+	rcu_read_lock();
+
+	seq_puts(s, "     wcid |       id |    flags |      exp | mantissa");
+	seq_puts(s, " | duration |            tsf |\n");
+	list_for_each_entry_rcu(iter, &dev->twt_list, list)
+		seq_printf(s,
+			"%9d | %8d | %5c%c%c%c | %8d | %8d | %8d | %14lld |\n",
+			iter->wcid, iter->id,
+			iter->sched ? 's' : 'u',
+			iter->protection ? 'p' : '-',
+			iter->trigger ? 't' : '-',
+			iter->flowtype ? '-' : 'a',
+			iter->exp, iter->mantissa,
+			iter->duration, iter->tsf);
+
+	rcu_read_unlock();
+
+	return 0;
+}
+
 int mt7915_init_debugfs(struct mt7915_dev *dev)
 {
 	struct dentry *dir;
@@ -352,6 +378,8 @@ int mt7915_init_debugfs(struct mt7915_dev *dev)
 	debugfs_create_file("implicit_txbf", 0600, dir, dev,
 			    &fops_implicit_txbf);
 	debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern);
+	debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir,
+				    mt7915_twt_stats);
 	/* test knobs */
 	debugfs_create_file("radar_trigger", 0200, dir, dev,
 			    &fops_radar_trigger);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 mac80211-next 2/7] mac80211: introduce individual TWT support in AP mode.
  2021-08-09 17:28 ` [PATCH v2 mac80211-next 2/7] mac80211: introduce individual TWT support in AP mode Lorenzo Bianconi
@ 2021-08-17 11:34   ` Johannes Berg
  2021-08-17 12:09     ` Lorenzo Bianconi
  0 siblings, 1 reply; 10+ messages in thread
From: Johannes Berg @ 2021-08-17 11:34 UTC (permalink / raw)
  To: Lorenzo Bianconi, nbd
  Cc: linux-wireless, lorenzo.bianconi, ryder.lee, chui-hao.chiu

> 
> +static inline void drv_add_twt_setup(struct ieee80211_local *local,
> +				     struct ieee80211_sub_if_data *sdata,
> +				     struct ieee80211_sta *sta,
> +				     struct ieee80211_twt_params *agrt_req,
> +				     struct ieee80211_twt_params *agrt_resp)
> +{
> +	might_sleep();
> +	check_sdata_in_driver(sdata);
> +
> +	local->ops->add_twt_setup(&local->hw, sta, agrt_req, agrt_resp);
> +}
> +
> +static inline void drv_twt_teardown_request(struct ieee80211_local *local,
> +					    struct ieee80211_sub_if_data *sdata,
> +					    struct ieee80211_sta *sta,
> +					    u8 flowid)
> +{
> +	might_sleep();
> +	check_sdata_in_driver(sdata);
> +
> +	if (local->ops->twt_teardown_request)
> +		local->ops->twt_teardown_request(&local->hw, sta, flowid);
> +}

These should have tracing.

> +++ b/net/mac80211/iface.c
> @@ -1381,6 +1381,19 @@ static void ieee80211_iface_process_skb(struct ieee80211_local *local,
>  			WARN_ON(1);
>  			break;
>  		}
> +	} else if (ieee80211_is_action(mgmt->frame_control) &&
> +		   mgmt->u.action.category == WLAN_CATEGORY_S1G) {
> +		switch (mgmt->u.action.u.s1g.action_code) {
> +		case WLAN_S1G_TWT_TEARDOWN:
> +		case WLAN_S1G_TWT_SETUP:
> +			if (skb->pkt_type == IEEE80211_TX_STATUS_MSG)
> +				ieee80211_s1g_status_h_twt(sdata, skb);
> +			else
> +				ieee80211_s1g_rx_h_twt(sdata, skb);


I *really* don't like what you're doing here with the sdata->skb_queue,
which we only ever use for RX today.

We have today ieee80211_mgd_conn_tx_status() that gets called at the
right place, so you should add stuff there, and perhaps it needs to
queue things, or mark a separate TWT data structure before queueing the
work, or something else - but please don't use the RX skb_queue.

> 
> +static ieee80211_rx_result debug_noinline
> +ieee80211_rx_h_twt(struct ieee80211_rx_data *rx)

Please rename this - it's not actually an rx_h_ that's called through
the normal RX handler stuff, it's just a sub-function for the action RX
handler.

It also doesn't need the rx_result, it can just be bool/int.

> +	case WLAN_CATEGORY_S1G:
> +		switch (mgmt->u.action.u.s1g.action_code) {
> +		case WLAN_S1G_TWT_SETUP:
> +		case WLAN_S1G_TWT_TEARDOWN:
> +			if (ieee80211_rx_h_twt(rx) != RX_CONTINUE)
> +				goto queue;


(see here)

> +		default:

Also missing a "fallthrough" annotation or such.

> +
> +static int
> +ieee80211_s1g_rx_h_twt_teardown(struct ieee80211_sub_if_data *sdata,
> +				struct sta_info *sta, struct sk_buff *skb)
> +{
> +	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
> +
> +	drv_twt_teardown_request(sdata->local, sdata, &sta->sta,
> +				 mgmt->u.action.u.s1g.variable[0]);
> +
> +	return 0;

Evidently, this cannot fail, so needs no return value.

> +void ieee80211_s1g_rx_h_twt(struct ieee80211_sub_if_data *sdata,
> +			    struct sk_buff *skb)

again, not a real RX handler

> +{
> +	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
> +	struct ieee80211_local *local = sdata->local;
> +	struct sta_info *sta;
> +
> +	mutex_lock(&local->sta_mtx);
> +
> +	sta = sta_info_get_bss(sdata, mgmt->sa);
> +	if (!sta)
> +		goto out;
> +
> +	switch (mgmt->u.action.u.s1g.action_code) {
> +	case WLAN_S1G_TWT_SETUP:
> +		ieee80211_s1g_rx_h_twt_setup(sdata, sta, skb);

You're completely ignoring the return value. That's probably fine in the
-ENOMEM case, but the other cases you should still send a response. Just
like the driver callback is void because it should just fill in the
response to the other side (even in the failure cases).

johannes


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 mac80211-next 2/7] mac80211: introduce individual TWT support in AP mode.
  2021-08-17 11:34   ` Johannes Berg
@ 2021-08-17 12:09     ` Lorenzo Bianconi
  0 siblings, 0 replies; 10+ messages in thread
From: Lorenzo Bianconi @ 2021-08-17 12:09 UTC (permalink / raw)
  To: Johannes Berg
  Cc: Lorenzo Bianconi, nbd, linux-wireless, ryder.lee, chui-hao.chiu

[-- Attachment #1: Type: text/plain, Size: 4140 bytes --]

> > 
> > +static inline void drv_add_twt_setup(struct ieee80211_local *local,
> > +				     struct ieee80211_sub_if_data *sdata,
> > +				     struct ieee80211_sta *sta,
> > +				     struct ieee80211_twt_params *agrt_req,
> > +				     struct ieee80211_twt_params *agrt_resp)
> > +{
> > +	might_sleep();
> > +	check_sdata_in_driver(sdata);
> > +
> > +	local->ops->add_twt_setup(&local->hw, sta, agrt_req, agrt_resp);
> > +}
> > +
> > +static inline void drv_twt_teardown_request(struct ieee80211_local *local,
> > +					    struct ieee80211_sub_if_data *sdata,
> > +					    struct ieee80211_sta *sta,
> > +					    u8 flowid)
> > +{
> > +	might_sleep();
> > +	check_sdata_in_driver(sdata);
> > +
> > +	if (local->ops->twt_teardown_request)
> > +		local->ops->twt_teardown_request(&local->hw, sta, flowid);
> > +}
> 
> These should have tracing.

ack, I will add tracing in v3

> 
> > +++ b/net/mac80211/iface.c
> > @@ -1381,6 +1381,19 @@ static void ieee80211_iface_process_skb(struct ieee80211_local *local,
> >  			WARN_ON(1);
> >  			break;
> >  		}
> > +	} else if (ieee80211_is_action(mgmt->frame_control) &&
> > +		   mgmt->u.action.category == WLAN_CATEGORY_S1G) {
> > +		switch (mgmt->u.action.u.s1g.action_code) {
> > +		case WLAN_S1G_TWT_TEARDOWN:
> > +		case WLAN_S1G_TWT_SETUP:
> > +			if (skb->pkt_type == IEEE80211_TX_STATUS_MSG)
> > +				ieee80211_s1g_status_h_twt(sdata, skb);
> > +			else
> > +				ieee80211_s1g_rx_h_twt(sdata, skb);
> 
> 
> I *really* don't like what you're doing here with the sdata->skb_queue,
> which we only ever use for RX today.
> 
> We have today ieee80211_mgd_conn_tx_status() that gets called at the
> right place, so you should add stuff there, and perhaps it needs to
> queue things, or mark a separate TWT data structure before queueing the
> work, or something else - but please don't use the RX skb_queue.

ack, I will review/work on ieee80211_mgd_conn_tx_status() in v3

> 
> > 
> > +static ieee80211_rx_result debug_noinline
> > +ieee80211_rx_h_twt(struct ieee80211_rx_data *rx)
> 
> Please rename this - it's not actually an rx_h_ that's called through
> the normal RX handler stuff, it's just a sub-function for the action RX
> handler.
> 
> It also doesn't need the rx_result, it can just be bool/int.

ack, naming is hard :)

> 
> > +	case WLAN_CATEGORY_S1G:
> > +		switch (mgmt->u.action.u.s1g.action_code) {
> > +		case WLAN_S1G_TWT_SETUP:
> > +		case WLAN_S1G_TWT_TEARDOWN:
> > +			if (ieee80211_rx_h_twt(rx) != RX_CONTINUE)
> > +				goto queue;
> 
> 
> (see here)
> 
> > +		default:
> 
> Also missing a "fallthrough" annotation or such.

ack, I will fix it

> 
> > +
> > +static int
> > +ieee80211_s1g_rx_h_twt_teardown(struct ieee80211_sub_if_data *sdata,
> > +				struct sta_info *sta, struct sk_buff *skb)
> > +{
> > +	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
> > +
> > +	drv_twt_teardown_request(sdata->local, sdata, &sta->sta,
> > +				 mgmt->u.action.u.s1g.variable[0]);
> > +
> > +	return 0;
> 
> Evidently, this cannot fail, so needs no return value.

ack, I will fix it

> 
> > +void ieee80211_s1g_rx_h_twt(struct ieee80211_sub_if_data *sdata,
> > +			    struct sk_buff *skb)
> 
> again, not a real RX handler

ack, I will fix it

> 
> > +{
> > +	struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
> > +	struct ieee80211_local *local = sdata->local;
> > +	struct sta_info *sta;
> > +
> > +	mutex_lock(&local->sta_mtx);
> > +
> > +	sta = sta_info_get_bss(sdata, mgmt->sa);
> > +	if (!sta)
> > +		goto out;
> > +
> > +	switch (mgmt->u.action.u.s1g.action_code) {
> > +	case WLAN_S1G_TWT_SETUP:
> > +		ieee80211_s1g_rx_h_twt_setup(sdata, sta, skb);
> 
> You're completely ignoring the return value. That's probably fine in the
> -ENOMEM case, but the other cases you should still send a response. Just
> like the driver callback is void because it should just fill in the
> response to the other side (even in the failure cases).

ack, I will fix it in v3

Regards,
Lorenzo

> 
> johannes
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-08-17 12:09 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-09 17:28 [PATCH v2 mac80211-next 0/7] introduce individual TWT support in AP mode Lorenzo Bianconi
2021-08-09 17:28 ` [PATCH v2 mac80211-next 1/7] mac80211: add twt ie in ieee80211_mgmt structure Lorenzo Bianconi
2021-08-09 17:28 ` [PATCH v2 mac80211-next 2/7] mac80211: introduce individual TWT support in AP mode Lorenzo Bianconi
2021-08-17 11:34   ` Johannes Berg
2021-08-17 12:09     ` Lorenzo Bianconi
2021-08-09 17:28 ` [PATCH v2 mac80211-next 3/7] mt76: mt7915: introduce __mt7915_get_tsf routine Lorenzo Bianconi
2021-08-09 17:28 ` [PATCH v2 mac80211-next 4/7] mt76: mt7915: introduce mt7915_mcu_twt_agrt_update mcu command Lorenzo Bianconi
2021-08-09 17:28 ` [PATCH v2 mac80211-next 5/7] mt76: mt7915: introduce mt7915_mac_add_twt_setup routine Lorenzo Bianconi
2021-08-09 17:28 ` [PATCH v2 mac80211-next 6/7] mt76: mt7915: enable twt responder capability Lorenzo Bianconi
2021-08-09 17:28 ` [PATCH v2 mac80211-next 7/7] mt76: mt7915: add twt_stats knob in debugfs Lorenzo Bianconi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).