Skip to content

Commit

Permalink
cfg80211/nl80211: Add packet coalesce support
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Amitkumar Karwar <akarwar@marvell.com>
Signed-off-by: Bing Zhao <bzhao@marvell.com>
[fix kernel-doc, change free function, fix copy/paste error]
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
  • Loading branch information
Amitkumar Karwar authored and jmberg-intel committed Jul 16, 2013
1 parent a144f37 commit be29b99
Show file tree
Hide file tree
Showing 6 changed files with 463 additions and 2 deletions.
54 changes: 54 additions & 0 deletions include/net/cfg80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,35 @@ struct cfg80211_wowlan {
int n_patterns;
};

/**
* 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.
* see &enum nl80211_coalesce_condition.
* @patterns: array of packet patterns
* @n_patterns: number of patterns
*/
struct cfg80211_coalesce_rules {
int delay;
enum nl80211_coalesce_condition 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
Expand Down Expand Up @@ -2076,6 +2105,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);
Expand Down Expand Up @@ -2311,6 +2341,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 *coalesce);
};

/*
Expand Down Expand Up @@ -2536,6 +2568,25 @@ struct wiphy_wowlan_support {
const struct wiphy_wowlan_tcp_support *tcp;
};

/**
* struct wiphy_coalesce_support - coalesce support data
* @n_rules: maximum number of coalesce rules
* @max_delay: maximum supported coalescing delay in msecs
* @n_patterns: number of supported patterns in a rule
* (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 max_delay;
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,
Expand Down Expand Up @@ -2646,6 +2697,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
* @coalesce: packet coalescing support information
*/
struct wiphy {
/* assign these fields before you register the wiphy */
Expand Down Expand Up @@ -2755,6 +2807,8 @@ struct wiphy {
const struct iw_handler_def *wext;
#endif

const struct wiphy_coalesce_support *coalesce;

char priv[0] __aligned(NETDEV_ALIGN);
};

Expand Down
90 changes: 88 additions & 2 deletions include/uapi/linux/nl80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,31 @@
* interfaces that a given device supports.
*/

/**
* DOC: packet coalesce support
*
* 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.
*
* 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.
*/

/**
* enum nl80211_commands - supported nl80211 commands
*
Expand Down Expand Up @@ -648,6 +673,9 @@
* @NL80211_CMD_CRIT_PROTOCOL_STOP: Indicates the connection reliability can
* return back to normal.
*
* @NL80211_CMD_GET_COALESCE: Get currently supported coalesce rules.
* @NL80211_CMD_SET_COALESCE: Configure coalesce rules or clear existing rules.
*
* @NL80211_CMD_MAX: highest used command number
* @__NL80211_CMD_AFTER_LAST: internal use
*/
Expand Down Expand Up @@ -810,6 +838,9 @@ enum nl80211_commands {
NL80211_CMD_CRIT_PROTOCOL_START,
NL80211_CMD_CRIT_PROTOCOL_STOP,

NL80211_CMD_GET_COALESCE,
NL80211_CMD_SET_COALESCE,

/* add new commands above here */

/* used to define NL80211_CMD_MAX below */
Expand Down Expand Up @@ -1436,6 +1467,8 @@ enum nl80211_commands {
* allowed to be used with the first @NL80211_CMD_SET_STATION command to
* update a TDLS peer STA entry.
*
* @NL80211_ATTR_COALESCE_RULE: Coalesce rule information.
*
* @NL80211_ATTR_MAX: highest attribute number currently defined
* @__NL80211_ATTR_AFTER_LAST: internal use
*/
Expand Down Expand Up @@ -1736,6 +1769,8 @@ enum nl80211_attrs {

NL80211_ATTR_PEER_AID,

NL80211_ATTR_COALESCE_RULE,

/* add attributes here, update the policy in nl80211.c */

__NL80211_ATTR_AFTER_LAST,
Expand Down Expand Up @@ -3098,8 +3133,10 @@ enum nl80211_packet_pattern_attr {
* @max_pkt_offset: maximum Rx packet offset
*
* 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.
*/
struct nl80211_pattern_support {
__u32 max_patterns;
Expand Down Expand Up @@ -3317,6 +3354,55 @@ enum nl80211_wowlan_tcp_attrs {
MAX_NL80211_WOWLAN_TCP = NUM_NL80211_WOWLAN_TCP - 1
};

/**
* struct nl80211_coalesce_rule_support - coalesce rule support information
* @max_rules: maximum number of rules supported
* @pat: packet pattern support information
* @max_delay: maximum supported coalescing delay in msecs
*
* This struct is carried in %NL80211_ATTR_COALESCE_RULE in the
* capability information given by the kernel to userspace.
*/
struct nl80211_coalesce_rule_support {
__u32 max_rules;
struct nl80211_pattern_support pat;
__u32 max_delay;
} __attribute__((packed));

/**
* enum nl80211_attr_coalesce_rule - coalesce rule attribute
* @__NL80211_COALESCE_RULE_INVALID: invalid number for nested attribute
* @NL80211_ATTR_COALESCE_RULE_DELAY: delay in msecs used for packet coalescing
* @NL80211_ATTR_COALESCE_RULE_CONDITION: condition for packet coalescence,
* see &enum nl80211_coalesce_condition.
* @NL80211_ATTR_COALESCE_RULE_PKT_PATTERN: packet offset, pattern is matched
* after these fixed number of bytes of received packet
* @NUM_NL80211_ATTR_COALESCE_RULE: number of attributes
* @NL80211_ATTR_COALESCE_RULE_MAX: max attribute number
*/
enum nl80211_attr_coalesce_rule {
__NL80211_COALESCE_RULE_INVALID,
NL80211_ATTR_COALESCE_RULE_DELAY,
NL80211_ATTR_COALESCE_RULE_CONDITION,
NL80211_ATTR_COALESCE_RULE_PKT_PATTERN,

/* keep last */
NUM_NL80211_ATTR_COALESCE_RULE,
NL80211_ATTR_COALESCE_RULE_MAX = NUM_NL80211_ATTR_COALESCE_RULE - 1
};

/**
* enum nl80211_coalesce_condition - coalesce rule conditions
* @NL80211_COALESCE_CONDITION_MATCH: coalaesce Rx packets when patterns
* in a rule are matched.
* @NL80211_COALESCE_CONDITION_NO_MATCH: coalesce Rx packets when patterns
* in a rule are not matched.
*/
enum nl80211_coalesce_condition {
NL80211_COALESCE_CONDITION_MATCH,
NL80211_COALESCE_CONDITION_NO_MATCH
};

/**
* enum nl80211_iface_limit_attrs - limit attributes
* @NL80211_IFACE_LIMIT_UNSPEC: (reserved)
Expand Down
9 changes: 9 additions & 0 deletions net/wireless/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,14 @@ int wiphy_register(struct wiphy *wiphy)
return -EINVAL;
#endif

if (WARN_ON(wiphy->coalesce &&
(!wiphy->coalesce->n_rules ||
!wiphy->coalesce->n_patterns) &&
(!wiphy->coalesce->pattern_min_len ||
wiphy->coalesce->pattern_min_len >
wiphy->coalesce->pattern_max_len)))
return -EINVAL;

if (WARN_ON(wiphy->ap_sme_capa &&
!(wiphy->flags & WIPHY_FLAG_HAVE_AP_SME)))
return -EINVAL;
Expand Down Expand Up @@ -668,6 +676,7 @@ void wiphy_unregister(struct wiphy *wiphy)
rdev_set_wakeup(rdev, false);
#endif
cfg80211_rdev_free_wowlan(rdev);
cfg80211_rdev_free_coalesce(rdev);
}
EXPORT_SYMBOL(wiphy_unregister);

Expand Down
2 changes: 2 additions & 0 deletions net/wireless/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,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);
Expand Down
Loading

0 comments on commit be29b99

Please sign in to comment.