Skip to contentSkip to conversation

cfg80211/nl80211: rename packet pattern related structures and enums

PATCH Superseded Bing Zhao 3 participants 11 messages May 23, 2013 – Jun 12, 2013

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Bing Zhao

author
#0 lore raw

PATCH v2 1/2 cfg80211/nl80211: rename packet pattern related structures and enums

From: Amitkumar Karwar <[email protected]>

Currently packet patterns and it's enum/structures are used only for WoWLAN feature. As we intend to reuse them for new feature packet coalesce, they are renamed in this patch.

Older names are kept for backward compatibility purpose.

---
v2: more details about the renames in commit log (Luis R. Rodriguez)
don't break the API with existing applications (Johannes Berg)

 drivers/net/wireless/ath/ath9k/main.c   |  2 +-
 drivers/net/wireless/mwifiex/cfg80211.c |  3 +--
 drivers/net/wireless/ti/wlcore/main.c   | 10 ++++----
 include/net/cfg80211.h                  |  6 ++---
 include/uapi/linux/nl80211.h            | 45 ++++++++++++++++++++-------------
 net/wireless/nl80211.c                  | 34 ++++++++++++-------------
 6 files changed, 53 insertions(+), 47 deletions(-)
drivers/net/wireless/ath/ath9k/main.c +1 -1
index 6963862..57e290e 100644
@@ -2123,7 +2123,7 @@ static void ath9k_wow_add_pattern(struct ath_softc *sc,
 {
 	struct ath_hw *ah = sc->sc_ah;
 	struct ath9k_wow_pattern *wow_pattern = NULL;
-	struct cfg80211_wowlan_trig_pkt_pattern *patterns = wowlan->patterns;
+	struct cfg80211_pkt_pattern *patterns = wowlan->patterns;
 	int mask_len;
 	s8 i = 0;
 
drivers/net/wireless/mwifiex/cfg80211.c +1 -2
index d3c8ece..7a06f51 100644
@@ -2250,8 +2250,7 @@ EXPORT_SYMBOL_GPL(mwifiex_del_virtual_intf);
 
 #ifdef CONFIG_PM
 static bool
-mwifiex_is_pattern_supported(struct cfg80211_wowlan_trig_pkt_pattern *pat,
-			     s8 *byte_seq)
+mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq)
 {
 	int j, k, valid_byte_cnt = 0;
 	bool dont_care_byte = false;
drivers/net/wireless/ti/wlcore/main.c +5 -5
index 953111a..db3653f 100644
@@ -1328,7 +1328,7 @@ static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
 
 #ifdef CONFIG_PM
 static int
-wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern *p)
+wl1271_validate_wowlan_pattern(struct cfg80211_pkt_pattern *p)
 {
 	int num_fields = 0, in_field = 0, fields_size = 0;
 	int i, pattern_len = 0;
@@ -1471,9 +1471,9 @@ void wl1271_rx_filter_flatten_fields(struct wl12xx_rx_filter *filter,
  * Allocates an RX filter returned through f
  * which needs to be freed using rx_filter_free()
  */
-static int wl1271_convert_wowlan_pattern_to_rx_filter(
-	struct cfg80211_wowlan_trig_pkt_pattern *p,
-	struct wl12xx_rx_filter **f)
+static int
+wl1271_convert_wowlan_pattern_to_rx_filter(struct cfg80211_pkt_pattern *p,
+					   struct wl12xx_rx_filter **f)
 {
 	int i, j, ret = 0;
 	struct wl12xx_rx_filter *filter;
@@ -1575,7 +1575,7 @@ static int wl1271_configure_wowlan(struct wl1271 *wl,
 
 	/* Translate WoWLAN patterns into filters */
 	for (i = 0; i < wow->n_patterns; i++) {
-		struct cfg80211_wowlan_trig_pkt_pattern *p;
+		struct cfg80211_pkt_pattern *p;
 		struct wl12xx_rx_filter *filter = NULL;
 
 		p = &wow->patterns[i];
include/net/cfg80211.h +3 -3
index 32a2f1b..4585b63 100644
@@ -1661,7 +1661,7 @@ struct cfg80211_pmksa {
 };
 
 /**
- * struct cfg80211_wowlan_trig_pkt_pattern - packet pattern
+ * struct cfg80211_pkt_pattern - packet pattern
  * @mask: bitmask where to match pattern and where to ignore bytes,
  *	one bit per byte, in same format as nl80211
  * @pattern: bytes to match where bitmask is 1
@@ -1671,7 +1671,7 @@ struct cfg80211_pmksa {
  * Internal note: @mask and @pattern are allocated in one chunk of
  * memory, free @mask only!
  */
-struct cfg80211_wowlan_trig_pkt_pattern {
+struct cfg80211_pkt_pattern {
 	u8 *mask, *pattern;
 	int pattern_len;
 	int pkt_offset;
@@ -1733,7 +1733,7 @@ struct cfg80211_wowlan {
 	bool any, disconnect, magic_pkt, gtk_rekey_failure,
 	     eap_identity_req, four_way_handshake,
 	     rfkill_release;
-	struct cfg80211_wowlan_trig_pkt_pattern *patterns;
+	struct cfg80211_pkt_pattern *patterns;
 	struct cfg80211_wowlan_tcp *tcp;
 	int n_patterns;
 };
include/uapi/linux/nl80211.h +27 -18

88 lines not on this page · raw message

net/wireless/nl80211.c +16 -18
index 5f10f7a..5f640de 100644
@@ -1014,7 +1014,7 @@ static int nl80211_send_wowlan(struct sk_buff *msg,
 		return -ENOBUFS;
 
 	if (dev->wiphy.wowlan.n_patterns) {
-		struct nl80211_wowlan_pattern_support pat = {
+		struct nl80211_pattern_support pat = {
 			.max_patterns = dev->wiphy.wowlan.n_patterns,
 			.min_pattern_len = dev->wiphy.wowlan.pattern_min_len,
 			.max_pattern_len = dev->wiphy.wowlan.pattern_max_len,
@@ -7570,12 +7570,11 @@ static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
 		if (!nl_pat)
 			return -ENOBUFS;
 		pat_len = rdev->wowlan->patterns[i].pattern_len;
-		if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
-			    DIV_ROUND_UP(pat_len, 8),
+		if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
 			    rdev->wowlan->patterns[i].mask) ||
-		    nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
-			    pat_len, rdev->wowlan->patterns[i].pattern) ||
-		    nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
+		    nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
+			    rdev->wowlan->patterns[i].pattern) ||
+		    nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
 				rdev->wowlan->patterns[i].pkt_offset))
 			return -ENOBUFS;
 		nla_nest_end(msg, nl_pat);
@@ -7915,7 +7914,7 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
 		struct nlattr *pat;
 		int n_patterns = 0;
 		int rem, pat_len, mask_len, pkt_offset;
-		struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
+		struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
 
 		nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
 				    rem)
@@ -7934,26 +7933,25 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
 
 		nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
 				    rem) {
-			nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
-				  nla_data(pat), nla_len(pat), NULL);
+			nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
+				  nla_len(pat), NULL);
 			err = -EINVAL;
-			if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
-			    !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
+			if (!pat_tb[NL80211_PKTPAT_MASK] ||
+			    !pat_tb[NL80211_PKTPAT_PATTERN])
 				goto error;
-			pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
+			pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
 			mask_len = DIV_ROUND_UP(pat_len, 8);
-			if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
-			    mask_len)
+			if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
 				goto error;
 			if (pat_len > wowlan->pattern_max_len ||
 			    pat_len < wowlan->pattern_min_len)
 				goto error;
 
-			if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
+			if (!pat_tb[NL80211_PKTPAT_OFFSET])
 				pkt_offset = 0;
 			else
 				pkt_offset = nla_get_u32(
-					pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
+					pat_tb[NL80211_PKTPAT_OFFSET]);
 			if (pkt_offset > wowlan->max_pkt_offset)
 				goto error;
 			new_triggers.patterns[i].pkt_offset = pkt_offset;
@@ -7967,11 +7965,11 @@ static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
 			new_triggers.patterns[i].pattern =
 				new_triggers.patterns[i].mask + mask_len;
 			memcpy(new_triggers.patterns[i].mask,
-			       nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
+			       nla_data(pat_tb[NL80211_PKTPAT_MASK]),
 			       mask_len);
 			new_triggers.patterns[i].pattern_len = pat_len;
 			memcpy(new_triggers.patterns[i].pattern,
-			       nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
+			       nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
 			       pat_len);
 			i++;
 		}
Signature · 1 line
1.8.0
author
#1 lore raw

PATCH v2 2/2 cfg80211/nl80211: Add packet coalesce support

From: Amitkumar Karwar <[email protected]>

In most cases, host that receives IPv4 and IPv6 multicast/broadcast packets does not do anything with these packets. Therefore the reception of these unwanted packets causes unnecessary processing and power consumption.

Packet coalesce feature helps to reduce number of received interrupts to host by buffering these packets in firmware/hardware for some predefined time. Received interrupt will be generated when one of the following events occur.
a) Expiration of hardware timer whose expiration time is set to maximum coalescing delay of matching coalesce rule.
b) Coalescing buffer in hardware reaches it's limit.
c) Packet doesn't match any of the configured coalesce rules.

This patch adds set/get configuration support for packet coalesce. User needs to configure following parameters for creating a coalesce rule.
a) Maximum coalescing delay
b) List of packet patterns which needs to be matched
c) Condition for coalescence. pattern 'match' or 'no match' Multiple such rules can be created.

This feature needs to be advertised during driver initialization. Drivers are supposed to do required firmware/hardware settings based on user configuration.

---
v2: add documentation in nl80211.h and elabiration of "coalesce"
in commit log (Luis R. Rodriguez)

 include/net/cfg80211.h       |  51 +++++++++
 include/uapi/linux/nl80211.h |  82 ++++++++++++-
 net/wireless/core.c          |   2 +
 net/wireless/core.h          |  22 ++++
 net/wireless/nl80211.c       | 265 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 419 insertions(+), 3 deletions(-)
include/net/cfg80211.h +51 -0
index 4585b63..dcbf125 100644
@@ -1739,6 +1739,35 @@ struct cfg80211_wowlan {
 };
 
 /**
+ * struct cfg80211_coalesce_rules - Coalesce rule parameters
+ *
+ * This structure defines coalesce rule for the device.
+ * @delay: maximum coalescing delay in msecs.
+ * @condition: condition for packet coalescence.
+ *	i.e. pattern 'match' or 'no match'
+ * @patterns: array of packet patterns
+ * @n_patterns: number of patterns
+ */
+struct cfg80211_coalesce_rules {
+	int delay;
+	u8 condition;
+	struct cfg80211_pkt_pattern *patterns;
+	int n_patterns;
+};
+
+/**
+ * struct cfg80211_coalesce - Packet coalescing settings
+ *
+ * This structure defines coalescing settings.
+ * @rules: array of coalesce rules
+ * @n_rules: number of rules
+ */
+struct cfg80211_coalesce {
+	struct cfg80211_coalesce_rules **rules;
+	int n_rules;
+};
+
+/**
  * struct cfg80211_wowlan_wakeup - wakeup report
  * @disconnect: woke up by getting disconnected
  * @magic_pkt: woke up by receiving magic packet
@@ -2024,6 +2053,7 @@ struct cfg80211_update_ft_ies_params {
  *	driver can take the most appropriate actions.
  * @crit_proto_stop: Indicates critical protocol no longer needs increased link
  *	reliability. This operation can not fail.
+ * @set_coalesce: Set coalesce parameters.
  */
 struct cfg80211_ops {
 	int	(*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
@@ -2259,6 +2289,8 @@ struct cfg80211_ops {
 				    u16 duration);
 	void	(*crit_proto_stop)(struct wiphy *wiphy,
 				   struct wireless_dev *wdev);
+	int	(*set_coalesce)(struct wiphy *wiphy,
+				struct cfg80211_coalesce_rules *rule);
 };
 
 /*
@@ -2483,6 +2515,23 @@ struct wiphy_wowlan_support {
 };
 
 /**
+ * struct wiphy_coalesce_support - coalesce support data
+ * @n_rules: maximum number of coalesce rules
+ * @n_patterns: number of supported patterns
+ *	(see nl80211.h for the pattern definition)
+ * @pattern_max_len: maximum length of each pattern
+ * @pattern_min_len: minimum length of each pattern
+ * @max_pkt_offset: maximum Rx packet offset
+ */
+struct wiphy_coalesce_support {
+	int n_rules;
+	int n_patterns;
+	int pattern_max_len;
+	int pattern_min_len;
+	int max_pkt_offset;
+};
+
+/**
  * struct wiphy - wireless hardware description
  * @reg_notifier: the driver's regulatory notification callback,
  *	note that if your driver uses wiphy_apply_custom_regulatory()
@@ -2589,6 +2638,7 @@ struct wiphy_wowlan_support {
  *	802.11-2012 8.4.2.29 for the defined fields.
  * @extended_capabilities_mask: mask of the valid values
  * @extended_capabilities_len: length of the extended capabilities
+ * @wiphy_coalesce_support coalesce: coalesce support information
  */
 struct wiphy {
 	/* assign these fields before you register the wiphy */
@@ -2697,6 +2747,7 @@ struct wiphy {
 	const struct iw_handler_def *wext;
 #endif
 
+	struct wiphy_coalesce_support coalesce;
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
include/uapi/linux/nl80211.h +79 -3

142 lines not on this page · raw message

net/wireless/core.c +2 -0
index 68f0c96..72a41da 100644
@@ -737,6 +737,8 @@ void wiphy_unregister(struct wiphy *wiphy)
 	if (rdev->wowlan && rdev->ops->set_wakeup)
 		rdev_set_wakeup(rdev, false);
 	cfg80211_rdev_free_wowlan(rdev);
+
+	cfg80211_rdev_free_coalesce(rdev);
 }
 EXPORT_SYMBOL(wiphy_unregister);
 
net/wireless/core.h +22 -0
index fd35dae..a0feff6 100644
@@ -91,6 +91,8 @@ struct cfg80211_registered_device {
 	/* netlink port which started critical protocol (0 means not started) */
 	u32 crit_proto_nlportid;
 
+	struct cfg80211_coalesce *coalesce;
+
 	/* must be last because of the way we do wiphy_priv(),
 	 * and it should at least be aligned to NETDEV_ALIGN */
 	struct wiphy wiphy __aligned(NETDEV_ALIGN);
@@ -119,6 +121,26 @@ cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev)
 	kfree(rdev->wowlan);
 }
 
+static inline void
+cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
+{
+	int i, j;
+	struct cfg80211_coalesce_rules *rule;
+
+	if (!rdev->coalesce)
+		return;
+
+	for (i = 0; i < rdev->coalesce->n_rules; i++) {
+		rule = rdev->coalesce->rules[i];
+		for (j = 0; j < rule->n_patterns; j++)
+			kfree(rule->patterns[j].mask);
+		kfree(rule->patterns);
+		kfree(rule);
+	}
+	kfree(rdev->coalesce->rules);
+	kfree(rdev->coalesce);
+}
+
 extern struct workqueue_struct *cfg80211_wq;
 extern struct mutex cfg80211_mutex;
 extern struct list_head cfg80211_rdev_list;
net/wireless/nl80211.c +265 -0

295 lines not on this page · raw message

Signature · 1 line
1.8.0
maintainer
#9 lore raw
In reply to Bing Zhao
Quoted 1 line · Bing Zhao

-enum nl80211_wowlan_packet_pattern_attr {

I think you missed a #define for this?

include/uapi/linux/nl80211.h enum nl80211_wowlan_packet_pattern_attr { · line 3093

Quoted 2 lines
include/uapi/linux/nl80211.h +2 -0
+/* only for backward compatibility */
+#define __NL80211_WOWLAN_PKTPAT_INVALID __NL80211_INVALID,

that , at the end looks like a copy/paste error, but in fact shouldn't it be "__NL80211_PKTPAT_INVALID" anyway?

Quoted 2 lines

* that is part of %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED in the
* capability information given by the kernel to userspace.

Should this be updated?

johannes

maintainer
#2 lore raw

Re: [PATCH v2 2/2] cfg80211/nl80211: Add packet coalesce support

In reply to Bing Zhao

Some smallish things.

Quoted 4 lines

In most cases, host that receives IPv4 and IPv6 multicast/broadcast packets does not do anything with these packets. Therefore the reception of these unwanted packets causes unnecessary processing and power consumption.

This is curious, you already discard those that you don't care about by way of multicast filtering, no? What's the added advantage here? Would you coalesce interrupts for those packets that pass the filter(s)? But those packets are packets that the host cares about, no?

include/net/cfg80211.h struct cfg80211_wowlan { · line 1753

Quoted 13 lines

/**
+ * struct cfg80211_coalesce_rules - Coalesce rule parameters
+ *
+ * This structure defines coalesce rule for the device.
+ * @delay: maximum coalescing delay in msecs.
+ * @condition: condition for packet coalescence.
+ * i.e. pattern 'match' or 'no match'
+ * @patterns: array of packet patterns
+ * @n_patterns: number of patterns
+ */

include/net/cfg80211.h +3 -0
+struct cfg80211_coalesce_rules {
+	int delay;
+	u8 condition;

seems like "condition" should be of some enum type? presumably an nl80211 enum type that userspace can use?

include/net/cfg80211.h struct cfg80211_wowlan { · line 1754

Quoted 1 line
include/net/cfg80211.h +1 -0
+	struct cfg80211_pkt_pattern *patterns;

const?

include/net/cfg80211.h struct cfg80211_wowlan { · line 1768

Quoted 4 lines
include/net/cfg80211.h +4 -0
+struct cfg80211_coalesce {
+	struct cfg80211_coalesce_rules **rules;
+	int n_rules;
+};

I think you can pass these as two function arguments rather than a separate struct.

include/uapi/linux/nl80211.h enum nl80211_cqm_rssi_threshold_event { · line 3068

Quoted 8 lines
include/uapi/linux/nl80211.h +0 -1
@@ -3027,7 +3063,6 @@ enum nl80211_cqm_rssi_threshold_event {
 	NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
 };
 
-
 /**
  * enum nl80211_tx_power_setting - TX power adjustment
  * @NL80211_TX_POWER_AUTOMATIC: automatically determine transmit power

seems spurious :)

Quoted 7 lines

* This struct is carried in %NL80211_WOWLAN_TRIG_PKT_PATTERN when
- * that is part of %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED in the
- * capability information given by the kernel to userspace.
+ * that is part of %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED or in
+ * %NL80211_ATTR_COALESCE_RULE_PKT_PATTERN when that is part of
+ * %NL80211_ATTR_COALESCE_RULE in the capability information given
+ * by the kernel to userspace.

Ah, I think here you're updating what I asked about before.

Quoted 2 lines

+ * @NL80211_ATTR_COALESCE_RULE_CONDITION: condition for packet coalescence.
+ * i.e. pattern 'match' or 'no match'

I'm sure the condition attribute isn't a string, so this should say which enum to take the value from?

Quoted 3 lines

+ * @NL80211_FEATURE_PACKET_COALESCE: This driver support packet coalescing
+ * feature. Packets are buffered in firmware based on configured rules
+ * to reduce unwanted packet or interrupt to host.

I don't think you need this, since you have this:

Quoted 1 line

+ struct wiphy_coalesce_support coalesce;

Actually, you should probably make that a pointer, then it can be NULL for drivers not supporting it, and static const for those that do. Means you should make it a const pointer, of course.

Userspace can tell by checking if the support is advertised.

net/wireless/core.h cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev) · line 125

Quoted 2 lines
net/wireless/core.h +2 -0
+static inline void
+cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)

That's fairly big, would prefer not to inline it.

net/wireless/nl80211.c static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) · line 8140

Quoted 11 lines
net/wireless/nl80211.c +11 -0
+static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
+{
+	struct cfg80211_registered_device *rdev = info->user_ptr[0];
+	struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE];
+	struct wiphy_coalesce_support *coalesce = &rdev->wiphy.coalesce;
+	struct cfg80211_coalesce_rules new_rule = {};
+	struct cfg80211_coalesce_rules *nrule;
+	int err, i;
+
+	if (!(rdev->wiphy.features & NL80211_FEATURE_PACKET_COALESCE))
+		return -EOPNOTSUPP;

Then this should check the coalesce pointer of course, which can then be NULL.

net/wireless/nl80211.c static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) · line 8158

Quoted 8 lines
net/wireless/nl80211.c +8 -0
+	if (!rdev->coalesce) {
+		rdev->coalesce = kzalloc(sizeof(*rdev->coalesce), GFP_KERNEL);
+		rdev->coalesce->rules = kcalloc(coalesce->n_rules,
+						sizeof(void *), GFP_KERNEL);
+	}
+
+	if (rdev->coalesce->n_rules >= coalesce->n_rules)
+		return -EOPNOTSUPP;

This is bad. You leave rdev->coalesce assigned, but it's completely invalid data. IMHO you should use a temporary variable and only assign it when it's fully parsed, freeing it if not. That way, you also don't kill old values when new invalid values are parsed.

net/wireless/nl80211.c static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) · line 8169

Quoted 3 lines
net/wireless/nl80211.c +3 -0
+	new_rule.delay = nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
+	new_rule.condition =
+		nla_get_u8(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);

Needs sanity checking, what if userspace passes the value 17? Does that mean anything? :)

Quoted 7 lines
net/wireless/nl80211.c +7 -0
+		nla_for_each_nested(pat,
+				    tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
+				    rem) {
+			nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
+				  nla_len(pat), NULL);
+			err = -EINVAL;
+			if (!pat_tb[NL80211_PKTPAT_MASK] ||

net/wireless/nl80211.c static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) · line 8209

Quoted 10 lines
net/wireless/nl80211.c +10 -0
+			    !pat_tb[NL80211_PKTPAT_PATTERN])
+				goto error;
+			pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
+			mask_len = DIV_ROUND_UP(pat_len, 8);
+			if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) !=
+			    mask_len)
+				goto error;
+			if (pat_len > coalesce->pattern_max_len ||
+			    pat_len < coalesce->pattern_min_len)
+				goto error;

I wonder if any of this could be refactored with WoWLAN? Not really sure though, maybe not.

net/wireless/nl80211.c static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) · line 8249

Quoted 5 lines
net/wireless/nl80211.c +5 -0
+	err = rdev->ops->set_coalesce(&rdev->wiphy, nrule);
+	if (err)
+		goto error;
+
+	rdev->coalesce->rules[rdev->coalesce->n_rules++] = nrule;

Wait ... you can't delete old rules, only add new ones? I think I'm confused, I thought the SET command was going to overwrite all old rules?

johannes

#10 lore raw
In reply to Johannes Berg

Hi Johannes,

Thanks for your comments.

Quoted 4 lines
Quoted 2 lines

-enum nl80211_wowlan_packet_pattern_attr {

I think you missed a #define for this?

It's not used anywhere in iw or kernel code.

Quoted 6 lines

include/uapi/linux/nl80211.h enum nl80211_wowlan_packet_pattern_attr { · line 3093

Quoted 3 lines
include/uapi/linux/nl80211.h +2 -0
+/* only for backward compatibility */
+#define __NL80211_WOWLAN_PKTPAT_INVALID __NL80211_INVALID,

that , at the end looks like a copy/paste error, but in fact shouldn't it be "__NL80211_PKTPAT_INVALID" anyway?

Thanks for pointing this out. We will correct it in updated version.

Quoted 6 lines
Quoted 4 lines

* that is part of %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED in the
* capability information given by the kernel to userspace.

Should this be updated?

It has been updated after adding coalesce support in 2/2 patch.

Thanks,
Amitkumar Karwar

Quoted 2 lines

johannes

#3 lore raw

RE: [PATCH v2 2/2] cfg80211/nl80211: Add packet coalesce support

In reply to Johannes Berg

Hi Johannes,

Quoted 11 lines

Some smallish things.

Quoted 4 lines

In most cases, host that receives IPv4 and IPv6 multicast/broadcast packets does not do anything with these packets. Therefore the reception of these unwanted packets causes unnecessary processing and power consumption.

This is curious, you already discard those that you don't care about by way of multicast filtering, no? What's the added advantage here? Would you coalesce interrupts for those packets that pass the filter(s)?

Yes. we don't want to simply discard those packets, because few of them may be useful for the host.
The advantage here is instead of getting random per packet receive interrupts, host receives multiple buffered packets with a single receive interrupt.

Quoted 2 lines

But
those packets are packets that the host cares about, no?

The assumption is filters are designed in such a way that specified delay in packet processing is acceptable for those packets.

Quoted 17 lines
Quoted 11 lines

/**
+ * struct cfg80211_coalesce_rules - Coalesce rule parameters
+ *
+ * This structure defines coalesce rule for the device.
+ * @delay: maximum coalescing delay in msecs.
+ * @condition: condition for packet coalescence.
+ * i.e. pattern 'match' or 'no match'
+ * @patterns: array of packet patterns
+ * @n_patterns: number of patterns
+ */

include/net/cfg80211.h struct cfg80211_wowlan { · line 1753

Quoted 3 lines
include/net/cfg80211.h +3 -0
+struct cfg80211_coalesce_rules {
+	int delay;
+	u8 condition;

seems like "condition" should be of some enum type? presumably an nl80211 enum type that userspace can use?

Sure. We will add an enum for "condition".

Quoted 4 lines

include/net/cfg80211.h struct cfg80211_wowlan { · line 1754

Quoted 2 lines
include/net/cfg80211.h +1 -0
+	struct cfg80211_pkt_pattern *patterns;

const?

This can not be a const. It points to an array of patterns. Runtime while adding new rule, buffer is allocated based on number of patterns configured by user and information is filled.

Quoted 8 lines

include/net/cfg80211.h struct cfg80211_wowlan { · line 1768

Quoted 5 lines
include/net/cfg80211.h +4 -0
+struct cfg80211_coalesce {
+	struct cfg80211_coalesce_rules **rules;
+	int n_rules;
+};

I think you can pass these as two function arguments rather than a separate struct.

This is our global structure for coalesce configuration. We just save it's pointer in rdev structure. It is allocated when user adds first coalesce rule. rdev->coalesce is NULL when user clears the setting.

Quoted 11 lines

include/uapi/linux/nl80211.h enum nl80211_cqm_rssi_threshold_event { · line 3068

Quoted 9 lines
include/uapi/linux/nl80211.h +0 -1
@@ -3027,7 +3063,6 @@ enum nl80211_cqm_rssi_threshold_event {
 	NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
 };
 
-
 /**
  * enum nl80211_tx_power_setting - TX power adjustment
  * @NL80211_TX_POWER_AUTOMATIC: automatically determine transmit power

seems spurious :)

Ok. We will revert the change.

Quoted 9 lines
Quoted 8 lines

* This struct is carried in %NL80211_WOWLAN_TRIG_PKT_PATTERN when
- * that is part of %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED in the
- * capability information given by the kernel to userspace.
+ * that is part of %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED or in
+ * %NL80211_ATTR_COALESCE_RULE_PKT_PATTERN when that is part of
+ * %NL80211_ATTR_COALESCE_RULE in the capability information given
+ * by the kernel to userspace.

Quoted 8 lines

Ah, I think here you're updating what I asked about before.

Quoted 1 line

+ * @NL80211_ATTR_COALESCE_RULE_CONDITION: condition for packet

coalescence.

Quoted 1 line

+ * i.e. pattern 'match' or 'no match'

I'm sure the condition attribute isn't a string, so this should say which enum to take the value from?

Sure. We will update the description using newly added enum for "condition".

Quoted 9 lines
Quoted 2 lines

+ * @NL80211_FEATURE_PACKET_COALESCE: This driver support packet

coalescing

Quoted 2 lines

+ * feature. Packets are buffered in firmware based on configured rules
+ * to reduce unwanted packet or interrupt to host.

I don't think you need this, since you have this:

Quoted 1 line

+ struct wiphy_coalesce_support coalesce;

We will get rid of this flag.

Quoted 6 lines

Actually, you should probably make that a pointer, then it can be NULL for drivers not supporting it, and static const for those that do. Means you should make it a const pointer, of course.

Userspace can tell by checking if the support is advertised.

We will use following condition to check if driver is not supporting the feature. (wowlan code does the same thing)

"if (!dev->wiphy.coalesce.n_patterns || !dev->wiphy.coalesce.n_rules)"

Quoted 6 lines

net/wireless/core.h cfg80211_rdev_free_wowlan(struct cfg80211_registered_device *rdev) · line 125

Quoted 4 lines
net/wireless/core.h +2 -0
+static inline void
+cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)

That's fairly big, would prefer not to inline it.

Ack, thanks.

Quoted 17 lines
Quoted 2 lines

+static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info

*info)

net/wireless/nl80211.c static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) · line 8140

Quoted 10 lines
net/wireless/nl80211.c +10 -0
+{
+	struct cfg80211_registered_device *rdev = info->user_ptr[0];
+	struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE];
+	struct wiphy_coalesce_support *coalesce = &rdev->wiphy.coalesce;
+	struct cfg80211_coalesce_rules new_rule = {};
+	struct cfg80211_coalesce_rules *nrule;
+	int err, i;
+
+	if (!(rdev->wiphy.features & NL80211_FEATURE_PACKET_COALESCE))
+		return -EOPNOTSUPP;

Then this should check the coalesce pointer of course, which can then be NULL.

Quoted 13 lines

net/wireless/nl80211.c static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) · line 8158

Quoted 8 lines
net/wireless/nl80211.c +8 -0
+	if (!rdev->coalesce) {
+		rdev->coalesce = kzalloc(sizeof(*rdev->coalesce), GFP_KERNEL);
+		rdev->coalesce->rules = kcalloc(coalesce->n_rules,
+						sizeof(void *), GFP_KERNEL);
+	}
+
+	if (rdev->coalesce->n_rules >= coalesce->n_rules)
+		return -EOPNOTSUPP;

This is bad. You leave rdev->coalesce assigned, but it's completely invalid data. IMHO you should use a temporary variable and only assign it when it's fully parsed, freeing it if not. That way, you also don't kill old values when new invalid values are parsed.

"iw coalesce add" command adds one coalesce rule at a time. "iw coalesce disable" command removes all configured rules.

"rdev->coalesce" will be created while adding first rule. "if (!rdev->coalesce)" condition will be false for further rules.

"if (rdev->coalesce->n_rules >= coalesce->n_rules)" condition becomes true when number of configured rules becomes equal to number of supported rules advertised by the driver. So we can't accommodate new rule in this case.

Therefore we don't leave rdev->coalesce assigned with invalid data.

We are already using 'new_rule' as a temporary variable for storing new rule information and freeing it in failure cases (similar to wowlan code).

Quoted 7 lines

net/wireless/nl80211.c static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) · line 8169

Quoted 4 lines
net/wireless/nl80211.c +3 -0
+	new_rule.delay = nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
+	new_rule.condition =
+		nla_get_u8(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);

Needs sanity checking, what if userspace passes the value 17? Does that mean anything? :)

Ack. We will add sanity check to allow only valid enum values.

Quoted 13 lines
Quoted 13 lines
net/wireless/nl80211.c +12 -0
+		nla_for_each_nested(pat,
+				    tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
+				    rem) {
+			nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
+				  nla_len(pat), NULL);
+			err = -EINVAL;
+			if (!pat_tb[NL80211_PKTPAT_MASK] ||
+			    !pat_tb[NL80211_PKTPAT_PATTERN])
+				goto error;
+			pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
+			mask_len = DIV_ROUND_UP(pat_len, 8);
+			if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) !=
Quoted 8 lines

net/wireless/nl80211.c static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) · line 8209

Quoted 5 lines
net/wireless/nl80211.c +5 -0
+			    mask_len)
+				goto error;
+			if (pat_len > coalesce->pattern_max_len ||
+			    pat_len < coalesce->pattern_min_len)
+				goto error;

I wonder if any of this could be refactored with WoWLAN? Not really sure though, maybe not.

Refactoring is little difficult here. We need to define new structure for pattern specific support variables (n_patterns, pattern_max_len, pattern_min_len, max_pkt_offset) which can be passed to a common routine created after refactoring. This will affect readability at many other places due to following replacements. wiphy.wowlan.pattern_min_len -> wiphy.wowlan.pattern.pattern_min_len
wiphy.coalesce.pattern_min_len -> wiphy.coalesce.pattern.pattern_min_len
and so on.

Quoted 10 lines

net/wireless/nl80211.c static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) · line 8249

Quoted 6 lines
net/wireless/nl80211.c +5 -0
+	err = rdev->ops->set_coalesce(&rdev->wiphy, nrule);
+	if (err)
+		goto error;
+
+	rdev->coalesce->rules[rdev->coalesce->n_rules++] = nrule;

Wait ... you can't delete old rules, only add new ones? I think I'm confused, I thought the SET command was going to overwrite all old rules?

SET command either adds new coalesce rule or removes all existing rules. Corresponding iw commands are 'add' and 'disable'

Please let me know if you want any specific modifications in the code/logic.

Thanks,
Amitkumar Karwar

Quoted 2 lines

johannes

maintainer
#4 lore raw

Re: [PATCH v2 2/2] cfg80211/nl80211: Add packet coalesce support

Hi,

sorry for the late reply. I did see you sent another version, but wanted to comment here anyway.

Quoted 9 lines
Quoted 3 lines

This is curious, you already discard those that you don't care about by way of multicast filtering, no? What's the added advantage here? Would you coalesce interrupts for those packets that pass the filter(s)?

Yes. we don't want to simply discard those packets, because few of them may be useful for the host.
The advantage here is instead of getting random per packet receive interrupts, host receives multiple buffered packets with a single receive interrupt.

I guess that makes some sense.

Quoted 10 lines
Quoted 5 lines

Actually, you should probably make that a pointer, then it can be NULL for drivers not supporting it, and static const for those that do. Means you should make it a const pointer, of course.

Userspace can tell by checking if the support is advertised.

We will use following condition to check if driver is not supporting the feature. (wowlan code does the same thing)

"if (!dev->wiphy.coalesce.n_patterns || !dev->wiphy.coalesce.n_rules)"

Hmm. I think wowlan should probably be changed though, no need to make the struct larger just for this, right? Not all drivers are going to support it.

For WoWLAN I'm going to apply this:
http://p.sipsolutions.net/fa808e0722a7624a.txt

Quoted 7 lines
Quoted 4 lines

This is bad. You leave rdev->coalesce assigned, but it's completely invalid data. IMHO you should use a temporary variable and only assign it when it's fully parsed, freeing it if not. That way, you also don't kill old values when new invalid values are parsed.

"iw coalesce add" command adds one coalesce rule at a time. "iw coalesce disable" command removes all configured rules.

Can you please change this to "iw coalesce set" and make it set all the rules in one? Otherwise you're going to have very awkward races and need to always clear etc. The code would also be easier, though obviously you'd need to be able to specify multiple rules at the same time.

johannes

#5 lore raw

RE: [PATCH v2 2/2] cfg80211/nl80211: Add packet coalesce support

Hi Johannes,

Quoted 28 lines

Hi,

sorry for the late reply. I did see you sent another version, but wanted to comment here anyway.

Quoted 1 line
Quoted 1 line

This is curious, you already discard those that you don't care about

by

Quoted 8 lines
Quoted 2 lines

way of multicast filtering, no? What's the added advantage here? Would you coalesce interrupts for those packets that pass the filter(s)?

Yes. we don't want to simply discard those packets, because few of them may be useful for the host.
The advantage here is instead of getting random per packet receive interrupts, host receives multiple buffered packets with a single receive interrupt.

I guess that makes some sense.

Quoted 2 lines
Quoted 2 lines

Actually, you should probably make that a pointer, then it can be NULL for drivers not supporting it, and static const for those that do.

Means

Quoted 7 lines
Quoted 3 lines

you should make it a const pointer, of course.

Userspace can tell by checking if the support is advertised.

We will use following condition to check if driver is not supporting the feature. (wowlan code does the same thing)

Quoted 9 lines
Quoted 1 line

"if (!dev->wiphy.coalesce.n_patterns || !dev->wiphy.coalesce.n_rules)"

Hmm. I think wowlan should probably be changed though, no need to make the struct larger just for this, right? Not all drivers are going to support it.

For WoWLAN I'm going to apply this:
http://p.sipsolutions.net/fa808e0722a7624a.txt

This looks good. We don't need to unnecessarily allocate space in wiphy. We will make similar changes for coalesce.

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

This is bad. You leave rdev->coalesce assigned, but it's completely invalid data. IMHO you should use a temporary variable and only assign it when it's fully parsed, freeing it if not. That way, you also don't kill old values when new invalid values are parsed.

"iw coalesce add" command adds one coalesce rule at a time. "iw coalesce disable" command removes all configured rules.

Can you please change this to "iw coalesce set" and make it set all the rules in one?

"iw coalesce add" was used, because command for adding multiple rules at the same time will be a bit lengthy(user will need to enter multiple lists of packet patterns) and syntax check in iw will also need some efforts.

Quoted 3 lines

Otherwise you're going to have very awkward races and need to always clear etc. The code would also be easier, though obviously you'd need to be able to specify multiple rules at the same time.

For "iw coalesce set" also user needs to always clear the settings using "iw coalesce disable". Also similar to "coalesce set", for "coalesce add" we clear the settings and free allocations while unloading the driver.

Please let us know if you prefer "coalesce set" over "coalesce add".

Thanks,
Amit

Quoted 2 lines

johannes

author
#6 lore raw

RE: [PATCH v2 2/2] cfg80211/nl80211: Add packet coalesce support

Hi Johannes,

Quoted 11 lines
Quoted 2 lines

Can you please change this to "iw coalesce set" and make it set all the rules in one?

"iw coalesce add" was used, because command for adding multiple rules at the same time will be a bit lengthy(user will need to enter multiple lists of packet patterns) and syntax check in iw will also need some efforts.

Quoted 3 lines

Otherwise you're going to have very awkward races and need to always clear etc. The code would also be easier, though obviously you'd need to be able to specify multiple rules at the same time.

Quoted 5 lines

For "iw coalesce set" also user needs to always clear the settings using "iw coalesce disable". Also similar to "coalesce set", for "coalesce add" we clear the settings and free allocations while unloading the driver.

Please let us know if you prefer "coalesce set" over "coalesce add".

Could you please confirm your preference for "coalesce set" over "coalesce add"?

Thanks,
Bing

maintainer
#7 lore raw

Re: [PATCH v2 2/2] cfg80211/nl80211: Add packet coalesce support

In reply to Amitkumar Karwar
Quoted 4 lines · Amitkumar Karwar

"iw coalesce add" was used, because command for adding multiple rules at the same time will be a bit lengthy(user will need to enter multiple lists of packet patterns) and syntax check in iw will also need some efforts.

I think that this is so much unlike all other nl80211 settings where they're either refused or replace previous ones entirely that I would rather not have it. Take connecting for instance, wext allowed you to set all parameters one by one, etc. This is a bit similar. Also, this disallows doing checks on the entire configuration easily.

Personally, I see iw as a bit of a test tool so I'm not too concerned about its sometimes odd command line, but I know giving it lots of things can be awkward. For TCP wakeup, I've made it parse a small file, maybe that's an option here as well?

Quoted 10 lines
Quoted 3 lines

Otherwise you're going to have very awkward races and need to always clear etc. The code would also be easier, though obviously you'd need to be able to specify multiple rules at the same time.

For "iw coalesce set" also user needs to always clear the settings using "iw coalesce disable". Also similar to "coalesce set", for "coalesce add" we clear the settings and free allocations while unloading the driver.

Please let us know if you prefer "coalesce set" over "coalesce add".

I would much prefer just having set/clear over piecewise configuration.

johannes

author
#8 lore raw

RE: [PATCH v2 2/2] cfg80211/nl80211: Add packet coalesce support

SGkgSm9oYW5uZXMsDQoNCj4gUGVyc29uYWxseSwgSSBzZWUgaXcgYXMgYSBiaXQgb2YgYSB0ZXN0 IHRvb2wgc28gSSdtIG5vdCB0b28gY29uY2VybmVkDQo+IGFib3V0IGl0cyBzb21ldGltZXMgb2Rk IGNvbW1hbmQgbGluZSwgYnV0IEkga25vdyBnaXZpbmcgaXQgbG90cyBvZg0KPiB0aGluZ3MgY2Fu IGJlIGF3a3dhcmQuIEZvciBUQ1Agd2FrZXVwLCBJJ3ZlIG1hZGUgaXQgcGFyc2UgYSBzbWFsbCBm aWxlLA0KPiBtYXliZSB0aGF0J3MgYW4gb3B0aW9uIGhlcmUgYXMgd2VsbD8NCg0KWWVzLCB3ZSBj YW4gcGFyc2UgYSBjb25maWd1cmUgZmlsZSBhcyB3ZWxsLiBUaGFua3MgZm9yIHRoZSBoaW50Lg0K DQo+ID4gUGxlYXNlIGxldCB1cyBrbm93IGlmIHlvdSBwcmVmZXIgImNvYWxlc2NlIHNldCIgb3Zl ciAiY29hbGVzY2UgYWRkIi4NCj4gDQo+IEkgd291bGQgbXVjaCBwcmVmZXIganVzdCBoYXZpbmcg c2V0L2NsZWFyIG92ZXIgcGllY2V3aXNlIGNvbmZpZ3VyYXRpb24uDQoNCk9LLiBXZSB3aWxsIHRh a2Ugc2V0L2NsZWFyIGFwcHJvYWNoIGluIHYzLg0KDQpUaGFua3MsDQpCaW5nDQo=