igc: Fixes to NFC support code
Subsystems (2)
cover igc: Fixes to NFC support code
Hi all,
Previous patch series [1-4] addressed issues with IGC filtering support individually (MAC address, VLAN priority, and ethertype filtering). This patch series fixes issues with the Network Flow Classification (NFC) support, which is built on top of those individual filters.
This series is organized as follows:
* Initial patches (1 to 4) do trivial code cleanup like remove unused code, useless wrappers, simplify logic, etc.
* Midsection patches (5 to 8) refactor the NFC support code to improve code reuse and organization. It also makes some upcoming bug fixes simpler.
* The rest of the series (9 to 19) fixes multiple bugs related to rules insertion, overwrite, and restoration as well as other issues like memory leak and locking.
Best regards,
Andre
[1] https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20200318230102.36952-1-andre.guedes at intel.com/
[2] https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20200403181743.23447-1-andre.guedes at intel.com/
[3] https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20200407210711.24371-1-andre.guedes at intel.com/
[4] https://patchwork.ozlabs.org/project/intel-wired-lan/cover/20200411002834.13916-1-andre.guedes at intel.com/
Andre Guedes (19):
igc: Remove unused field from igc_nfc_filter
igc: Get rid of igc_max_channels()
igc: Cleanup _get|set_rxnfc ethtool ops
igc: Early return in igc_get_ethtool_nfc_entry()
igc: Add 'igc_ethtool_' prefix to functions in igc_ethtool.c
igc: Align terms used in NFC support code
igc: Change byte order in struct igc_nfc_filter
igc: Refactor igc_ethtool_add_nfc_rule()
igc: Fix 'sw_idx' type in struct igc_nfc_rule
igc: Fix locking issue when retrieving NFC rules
igc: Fix NFC rule overwrite cases
igc: Fix NFC rules with multicast addresses
igc: Fix NFC rules restoration
igc: Refactor igc_ethtool_update_nfc_rule()
igc: Fix NFC rules leak when driver is unloaded
igc: Fix NFC rule validation
igc: Change return type from igc_disable_nfc_rule()
igc: Change adapter->nfc_rule_lock to mutex
igc: Remove igc_nfc_rule_exit()
drivers/net/ethernet/intel/igc/igc.h | 57 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 608 ++++++++----------- drivers/net/ethernet/intel/igc/igc_main.c | 257 +++++--- 3 files changed, 469 insertions(+), 453 deletions(-)
Signature · 1 line
2.26.0
PATCH 1/19 igc: Remove unused field from igc_nfc_filter
The 'cookie' field is not used anywhere in the code so this patch removes it from struct igc_nfc_filter.
--- drivers/net/ethernet/intel/igc/igc.h | 1 - 1 file changed, 1 deletion(-)
drivers/net/ethernet/intel/igc/igc.h +0 -1
@@ -470,7 +470,6 @@ struct igc_nfc_input {struct igc_nfc_filter {struct hlist_node nfc_node;struct igc_nfc_input filter; -unsigned long cookie;u16 sw_idx;u16 action; };
Signature · 1 line
2.26.0
Brown
PATCH 1/19 igc: Remove unused field from igc_nfc_filter
Quoted 7 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 01/19] igc: Remove unused field fromigc_nfc_filter
Quoted 7 lines
The 'cookie' field is not used anywhere in the code so this patch removes it from struct
igc_nfc_filter.Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc.h | 1 - 1 file changed, 1 deletion(-)
PATCH 2/19 igc: Get rid of igc_max_channels()
In reply to Andre GuedesThe local function igc_max_channels() is a pointless wrapper around igc_get_max_rss_queues(). This patch removes it and updates the callers accordingly. It also does some cleanup on igc_get_max_rss_queues().
--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 9 ++------- drivers/net/ethernet/intel/igc/igc_main.c | 7 +------ 2 files changed, 3 insertions(+), 13 deletions(-)
drivers/net/ethernet/intel/igc/igc_ethtool.c +2 -7
@@ -1508,18 +1508,13 @@ static int igc_set_rxfh(struct net_device *netdev, const u32 *indir,return 0 ; } -static unsigned int igc_max_channels (struct igc_adapter *adapter) -{ -return igc_get_max_rss_queues (adapter); -} -static void igc_get_channels (struct net_device *netdev,struct ethtool_channels *ch) {struct igc_adapter *adapter =netdev_priv (netdev);/* Report maximum channels */ - ch->max_combined =igc_max_channels (adapter); + ch->max_combined =igc_get_max_rss_queues (adapter);/* Report info for other vector */ if (adapter->flags &IGC_FLAG_HAS_MSIX ) {
@@ -1546,7 +1541,7 @@ static int igc_set_channels(struct net_device *netdev,return -EINVAL ;/* Verify the number of channels doesn't exceed hw limits */ - max_combined =igc_max_channels (adapter); + max_combined =igc_get_max_rss_queues (adapter);if (count > max_combined)return -EINVAL ;
drivers/net/ethernet/intel/igc/igc_main.c +1 -6
@@ -2732,12 +2732,7 @@ void igc_set_flag_queue_pairs(struct igc_adapter *adapter,unsigned int igc_get_max_rss_queues (struct igc_adapter *adapter) { -unsigned int max_rss_queues; - -/* Determine the maximum number of RSS queues supported. */ - max_rss_queues =IGC_MAX_RX_QUEUES ; - -return max_rss_queues; +return IGC_MAX_RX_QUEUES ; }static void igc_init_queue_configuration (struct igc_adapter *adapter)
Signature · 1 line
2.26.0
Brown
PATCH 2/19 igc: Get rid of igc_max_channels()
Quoted 10 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 02/19] igc: Get rid ofigc_max_channels()The local function
igc_max_channels()is a pointless wrapper aroundigc_get_max_rss_queues(). This patch removes it and updates the callers accordingly. It also does some cleanup onigc_get_max_rss_queues().
Quoted 6 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 9 ++------- drivers/net/ethernet/intel/igc/igc_main.c | 7 +------ 2 files changed, 3 insertions(+), 13 deletions(-)
PATCH 3/19 igc: Cleanup _get|set_rxnfc ethtool ops
In reply to Andre GuedesThis patch does a trivial change in igc_ethtool_get_rxnfc() and igc_ethtool_set_rxnfc() to simplify their logic.
--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 33 ++++++-------------- 1 file changed, 10 insertions(+), 23 deletions(-)
drivers/net/ethernet/intel/igc/igc_ethtool.c +10 -23
@@ -1055,31 +1055,23 @@ static int igc_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, u32 *rule_locs) {struct igc_adapter *adapter =netdev_priv (dev); -int ret = -EOPNOTSUPP ;switch (cmd->cmd) {case ETHTOOL_GRXRINGS : cmd->data = adapter->num_rx_queues; - ret =0 ; -break ; +return 0 ;case ETHTOOL_GRXCLSRLCNT : cmd->rule_cnt = adapter->nfc_filter_count; - ret =0 ; -break ; +return 0 ;case ETHTOOL_GRXCLSRULE : - ret =igc_get_ethtool_nfc_entry (adapter, cmd); -break ; +return igc_get_ethtool_nfc_entry (adapter, cmd);case ETHTOOL_GRXCLSRLALL : - ret =igc_get_ethtool_nfc_all (adapter, cmd, rule_locs); -break ; +return igc_get_ethtool_nfc_all (adapter, cmd, rule_locs);case ETHTOOL_GRXFH : - ret =igc_get_rss_hash_opts (adapter, cmd); -break ; +return igc_get_rss_hash_opts (adapter, cmd);default : -break ; +return -EOPNOTSUPP ; } - -return ret; }#define UDP_RSS_FLAGS (IGC_FLAG_RSS_FIELD_IPV4_UDP | \
@@ -1418,22 +1410,17 @@ static int igc_del_ethtool_nfc_entry(struct igc_adapter *adapter,static int igc_set_rxnfc (struct net_device *dev,struct ethtool_rxnfc *cmd) {struct igc_adapter *adapter =netdev_priv (dev); -int ret = -EOPNOTSUPP ;switch (cmd->cmd) {case ETHTOOL_SRXFH : - ret =igc_set_rss_hash_opt (adapter, cmd); -break ; +return igc_set_rss_hash_opt (adapter, cmd);case ETHTOOL_SRXCLSRLINS : - ret =igc_add_ethtool_nfc_entry (adapter, cmd); -break ; +return igc_add_ethtool_nfc_entry (adapter, cmd);case ETHTOOL_SRXCLSRLDEL : - ret =igc_del_ethtool_nfc_entry (adapter, cmd); +return igc_del_ethtool_nfc_entry (adapter, cmd);default : -break ; +return -EOPNOTSUPP ; } - -return ret; }void igc_write_rss_indir_tbl (struct igc_adapter *adapter)
Signature · 1 line
2.26.0
Brown
PATCH 3/19 igc: Cleanup _get|set_rxnfc ethtool ops
Quoted 7 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 03/19] igc: Cleanup _get|set_rxnfc ethtool ops
Quoted 8 lines
This patch does a trivial change in
igc_ethtool_get_rxnfc()andigc_ethtool_set_rxnfc()to simplify their logic.Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 33 ++++++-------------- 1 file changed, 10 insertions(+), 23 deletions(-)
PATCH 4/19 igc: Early return in igc_get_ethtool_nfc_entry()
In reply to Andre GuedesThis patch re-writes the second half of igc_ethtool_get_nfc_entry() to follow the 'return early' pattern seen in other parts of the driver and removes some duplicate comments.
--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 58 ++++++++++---------- 1 file changed, 28 insertions(+), 30 deletions(-)
drivers/net/ethernet/intel/igc/igc_ethtool.c +28 -30
@@ -945,38 +945,36 @@ static int igc_get_ethtool_nfc_entry(struct igc_adapter *adapter,if (!rule || fsp->location != rule->sw_idx)return -EINVAL ; -if (rule->filter.match_flags) { - fsp->flow_type =ETHER_FLOW ; - fsp->ring_cookie = rule->action; -if (rule->filter.match_flags &IGC_FILTER_FLAG_ETHER_TYPE ) { - fsp->h_u.ether_spec.h_proto = rule->filter.etype; - fsp->m_u.ether_spec.h_proto =ETHER_TYPE_FULL_MASK ; - } -if (rule->filter.match_flags &IGC_FILTER_FLAG_VLAN_TCI ) { - fsp->flow_type |=FLOW_EXT ; - fsp->h_ext.vlan_tci = rule->filter.vlan_tci; - fsp->m_ext.vlan_tci =htons (VLAN_PRIO_MASK ); - } -if (rule->filter.match_flags &IGC_FILTER_FLAG_DST_MAC_ADDR ) { -ether_addr_copy (fsp->h_u.ether_spec.h_dest, - rule->filter.dst_addr); -/* As we only support matching by the full -* mask, return the mask to userspace -*/ -eth_broadcast_addr (fsp->m_u.ether_spec.h_dest); - } -if (rule->filter.match_flags &IGC_FILTER_FLAG_SRC_MAC_ADDR ) { -ether_addr_copy (fsp->h_u.ether_spec.h_source, - rule->filter.src_addr); -/* As we only support matching by the full -* mask, return the mask to userspace -*/ -eth_broadcast_addr (fsp->m_u.ether_spec.h_source); - } +if (!rule->filter.match_flags) +return -EINVAL ; -return 0 ; + fsp->flow_type =ETHER_FLOW ; + fsp->ring_cookie = rule->action; + +if (rule->filter.match_flags &IGC_FILTER_FLAG_ETHER_TYPE ) { + fsp->h_u.ether_spec.h_proto = rule->filter.etype; + fsp->m_u.ether_spec.h_proto =ETHER_TYPE_FULL_MASK ; } -return -EINVAL ; + +if (rule->filter.match_flags &IGC_FILTER_FLAG_VLAN_TCI ) { + fsp->flow_type |=FLOW_EXT ; + fsp->h_ext.vlan_tci = rule->filter.vlan_tci; + fsp->m_ext.vlan_tci =htons (VLAN_PRIO_MASK ); + } + +if (rule->filter.match_flags &IGC_FILTER_FLAG_DST_MAC_ADDR ) { +ether_addr_copy (fsp->h_u.ether_spec.h_dest, + rule->filter.dst_addr); +eth_broadcast_addr (fsp->m_u.ether_spec.h_dest); + } + +if (rule->filter.match_flags &IGC_FILTER_FLAG_SRC_MAC_ADDR ) { +ether_addr_copy (fsp->h_u.ether_spec.h_source, + rule->filter.src_addr); +eth_broadcast_addr (fsp->m_u.ether_spec.h_source); + } + +return 0 ; } static int igc_get_ethtool_nfc_all(struct igc_adapter *adapter,
Signature · 1 line
2.26.0
Brown
PATCH 4/19 igc: Early return in igc_get_ethtool_nfc_entry()
Quoted 7 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 04/19] igc: Early return inigc_get_ethtool_nfc_entry()
Quoted 9 lines
This patch re-writes the second half of
igc_ethtool_get_nfc_entry()to follow the 'return early' pattern seen in other parts of the driver and removes some duplicate comments.Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 58 ++++++++++---------- 1 file changed, 28 insertions(+), 30 deletions(-)
PATCH 5/19 igc: Add 'igc_ethtool_' prefix to functions in igc_ethtool.c
In reply to Andre GuedesThis patch adds the prefix 'igc_ethtool_' to all functions defined in igc_ethtool.c so they align with the name convention already followed by other parts of the driver (e.g. igc_tsn, igc_ptp). Also, this avoids some name clashing with functions added to igc_main.c by upcoming patches in this series. No functionality is changed by this patch, just function renaming.
--- drivers/net/ethernet/intel/igc/igc.h | 3 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 215 ++++++++++--------- drivers/net/ethernet/intel/igc/igc_main.c | 2 +- 3 files changed, 112 insertions(+), 108 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +1 -2
@@ -16,8 +16,7 @@#include "igc_hw.h" -/* forward declaration */ -void igc_set_ethtool_ops (struct net_device *); +void igc_ethtool_set_ops (struct net_device *);/* Transmit and receive queues */ #define IGC_MAX_RX_QUEUES 4
drivers/net/ethernet/intel/igc/igc_ethtool.c +110 -105
493 lines not on this page · raw message
drivers/net/ethernet/intel/igc/igc_main.c +1 -1
@@ -4935,7 +4935,7 @@ static int igc_probe(struct pci_dev *pdev, hw->hw_addr = adapter->io_addr; netdev->netdev_ops = &igc_netdev_ops; -igc_set_ethtool_ops (netdev); +igc_ethtool_set_ops (netdev); netdev->watchdog_timeo =5 *HZ ; netdev->mem_start =pci_resource_start (pdev,0 );
Signature · 1 line
2.26.0
Brown
PATCH 5/19 igc: Add 'igc_ethtool_' prefix to functions in igc_ethtool.c
Quoted 14 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 05/19] igc: Add 'igc_ethtool_' prefix to functions inigc_ethtool.cThis patch adds the prefix '
igc_ethtool_' to all functions defined inigc_ethtool.cso they align with the name convention already followed by other parts of the driver (e.g.igc_tsn,igc_ptp). Also, this avoids some name clashing with functions added toigc_main.cby upcoming patches in this series. No functionality is changed by this patch, just function renaming.
Quoted 7 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc.h | 3 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 215 ++++++++++--------- drivers/net/ethernet/intel/igc/igc_main.c | 2 +- 3 files changed, 112 insertions(+), 108 deletions(-)
PATCH 6/19 igc: Align terms used in NFC support code
In reply to Andre GuedesThe Network Flow Classification (NFC) support code from IGC driver uses terms such as 'rule', 'filter', 'entry', 'input' interchangeably when referring to NFC rules, making it harder to follow the code. This patch renames IGC's internal APIs, structs, and variables so we stick with the term 'rule' since this is the term used in ethtool APIs. It also removes some not applicable comments along the way. No functionality is changed by this patch.
--- drivers/net/ethernet/intel/igc/igc.h | 29 ++-- drivers/net/ethernet/intel/igc/igc_ethtool.c | 160 +++++++++---------- drivers/net/ethernet/intel/igc/igc_main.c | 42 ++--- 3 files changed, 114 insertions(+), 117 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +14 -15
@@ -187,12 +187,12 @@ struct igc_adapter {u32 rss_queues;u32 rss_indir_tbl_init; -/* RX network flow classification support */ -struct hlist_head nfc_filter_list; -unsigned int nfc_filter_count; - -/* lock for RX network flow classification filter */ -spinlock_t nfc_lock; +/* Any access to elements in nfc_rule_list is protected by the +* nfc_rule_lock. +*/ +spinlock_t nfc_rule_lock; +struct hlist_head nfc_rule_list; +unsigned int nfc_rule_count;u8 rss_indir_tbl[IGC_RETA_SIZE ];
@@ -453,7 +453,7 @@ enum igc_filter_match_flags { };/* RX network flow classification data structure */ -struct igc_nfc_input { +struct igc_nfc_filter {/* Byte layout in order, all values with MSB first: * match_flags - 1 byte * etype - 2 bytes
@@ -466,14 +466,14 @@ struct igc_nfc_input {u8 dst_addr[ETH_ALEN ]; }; -struct igc_nfc_filter { +struct igc_nfc_rule {struct hlist_node nfc_node; -struct igc_nfc_input filter; +struct igc_nfc_filter filter;u16 sw_idx;u16 action; }; -#define IGC_MAX_RXNFC_FILTERS 16 +#define IGC_MAX_RXNFC_RULES 16/* igc_desc_unused - calculate if we have unused descriptors */ static inline u16 igc_desc_unused (const struct igc_ring *ring)
@@ -549,12 +549,11 @@ static inline s32 igc_read_phy_reg(struct igc_hw *hw, u32 offset, u16 *data)return 0 ; } -/* forward declaration */ void igc_reinit_locked (struct igc_adapter *); -int igc_add_filter (struct igc_adapter *adapter, -struct igc_nfc_filter *input); -int igc_erase_filter (struct igc_adapter *adapter, -struct igc_nfc_filter *input); +int igc_enable_nfc_rule (struct igc_adapter *adapter, +const struct igc_nfc_rule *rule); +int igc_disable_nfc_rule (struct igc_adapter *adapter, +const struct igc_nfc_rule *rule);void igc_ptp_init (struct igc_adapter *adapter);void igc_ptp_reset (struct igc_adapter *adapter);
drivers/net/ethernet/intel/igc/igc_ethtool.c +79 -81
334 lines not on this page · raw message
drivers/net/ethernet/intel/igc/igc_main.c +21 -21
91 lines not on this page · raw message
Signature · 1 line
2.26.0
Brown
PATCH 6/19 igc: Align terms used in NFC support code
Quoted 15 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 06/19] igc: Align terms used in NFC support codeThe Network Flow Classification (NFC) support code from IGC driver uses terms such as 'rule', 'filter', 'entry', 'input' interchangeably when referring to NFC rules, making it harder to follow the code. This patch renames IGC's internal APIs, structs, and variables so we stick with the term 'rule' since this is the term used in ethtool APIs. It also removes some not applicable comments along the way. No functionality is changed by this patch.
Quoted 7 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc.h | 29 ++-- drivers/net/ethernet/intel/igc/igc_ethtool.c | 160 +++++++++---------- drivers/net/ethernet/intel/igc/igc_main.c | 42 ++--- 3 files changed, 114 insertions(+), 117 deletions(-)
PATCH 7/19 igc: Change byte order in struct igc_nfc_filter
In reply to Andre GuedesEvery time we access the 'etype' and 'vlan_tci' fields from struct igc_nfc_filter to enable or disable filters in hardware we have to convert them from big endian to host order so it makes more sense to simply have these fields in host order.
The byte order conversion should take place in igc_ethtool_get_nfc_ rule() and igc_ethtool_add_nfc_rule(), which are called by .get_rxnfc and .set_rxnfc ethtool ops, since ethtool subsystem is the one who deals with them in big endian order.
--- drivers/net/ethernet/intel/igc/igc.h | 10 ++------ drivers/net/ethernet/intel/igc/igc_ethtool.c | 25 +++++++++----------- 2 files changed, 13 insertions(+), 22 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +2 -8
@@ -452,16 +452,10 @@ enum igc_filter_match_flags { IGC_FILTER_FLAG_DST_MAC_ADDR = 0x8, }; -/* RX network flow classification data structure */ struct igc_nfc_filter { -/* Byte layout in order, all values with MSB first: -* match_flags - 1 byte -* etype - 2 bytes -* vlan_tci - 2 bytes -*/ u8 match_flags; -__be16 etype; -__be16 vlan_tci; +u16 etype; +u16 vlan_tci;u8 src_addr[ETH_ALEN ];u8 dst_addr[ETH_ALEN ]; };
drivers/net/ethernet/intel/igc/igc_ethtool.c +11 -14
@@ -954,13 +954,13 @@ static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter, fsp->ring_cookie = rule->action;if (rule->filter.match_flags &IGC_FILTER_FLAG_ETHER_TYPE ) { - fsp->h_u.ether_spec.h_proto = rule->filter.etype; + fsp->h_u.ether_spec.h_proto =htons (rule->filter.etype); fsp->m_u.ether_spec.h_proto =ETHER_TYPE_FULL_MASK ; }if (rule->filter.match_flags &IGC_FILTER_FLAG_VLAN_TCI ) { fsp->flow_type |=FLOW_EXT ; - fsp->h_ext.vlan_tci = rule->filter.vlan_tci; + fsp->h_ext.vlan_tci =htons (rule->filter.vlan_tci); fsp->m_ext.vlan_tci =htons (VLAN_PRIO_MASK ); }
@@ -1183,9 +1183,8 @@ int igc_enable_nfc_rule(struct igc_adapter *adapter,int err = -EINVAL ;if (rule->filter.match_flags &IGC_FILTER_FLAG_ETHER_TYPE ) { -u16 etype =ntohs (rule->filter.etype); - - err =igc_add_etype_filter (adapter, etype, rule->action); + err =igc_add_etype_filter (adapter, rule->filter.etype, + rule->action);if (err)return err; }
@@ -1205,8 +1204,9 @@ int igc_enable_nfc_rule(struct igc_adapter *adapter, }if (rule->filter.match_flags &IGC_FILTER_FLAG_VLAN_TCI ) { -int prio = (ntohs (rule->filter.vlan_tci) &VLAN_PRIO_MASK ) +int prio = (rule->filter.vlan_tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ; + err =igc_add_vlan_prio_filter (adapter, prio, rule->action);if (err)return err;
@@ -1218,14 +1218,11 @@ int igc_enable_nfc_rule(struct igc_adapter *adapter,int igc_disable_nfc_rule (struct igc_adapter *adapter,const struct igc_nfc_rule *rule) { -if (rule->filter.match_flags &IGC_FILTER_FLAG_ETHER_TYPE ) { -u16 etype =ntohs (rule->filter.etype); - -igc_del_etype_filter (adapter, etype); - } +if (rule->filter.match_flags &IGC_FILTER_FLAG_ETHER_TYPE ) +igc_del_etype_filter (adapter, rule->filter.etype);if (rule->filter.match_flags &IGC_FILTER_FLAG_VLAN_TCI ) { -int prio = (ntohs (rule->filter.vlan_tci) &VLAN_PRIO_MASK ) +int prio = (rule->filter.vlan_tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ;igc_del_vlan_prio_filter (adapter, prio); }
@@ -1325,7 +1322,7 @@ static int igc_ethtool_add_nfc_rule(struct igc_adapter *adapter,return -ENOMEM ;if (fsp->m_u.ether_spec.h_proto ==ETHER_TYPE_FULL_MASK ) { - rule->filter.etype = fsp->h_u.ether_spec.h_proto; + rule->filter.etype =ntohs (fsp->h_u.ether_spec.h_proto); rule->filter.match_flags =IGC_FILTER_FLAG_ETHER_TYPE ; }
@@ -1357,7 +1354,7 @@ static int igc_ethtool_add_nfc_rule(struct igc_adapter *adapter, err = -EOPNOTSUPP ; goto err_out; } - rule->filter.vlan_tci = fsp->h_ext.vlan_tci; + rule->filter.vlan_tci =ntohs (fsp->h_ext.vlan_tci); rule->filter.match_flags |=IGC_FILTER_FLAG_VLAN_TCI ; }
Signature · 1 line
2.26.0
Brown
PATCH 7/19 igc: Change byte order in struct igc_nfc_filter
Quoted 17 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 07/19] igc: Change byte order in structigc_nfc_filterEvery time we access the 'etype' and '
vlan_tci' fields from structigc_nfc_filterto enable or disable filters in hardware we have to convert them from big endian to host order so it makes more sense to simply have these fields in host order.The byte order conversion should take place in
igc_ethtool_get_nfc_rule()andigc_ethtool_add_nfc_rule(), which are called by .get_rxnfc and .set_rxnfc ethtool ops, since ethtool subsystem is the one who deals with them in big endian order.
Quoted 6 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc.h | 10 ++------ drivers/net/ethernet/intel/igc/igc_ethtool.c | 25 +++++++++----------- 2 files changed, 13 insertions(+), 22 deletions(-)
PATCH 8/19 igc: Refactor igc_ethtool_add_nfc_rule()
In reply to Andre GuedesCurrent implementation of igc_ethtool_add_nfc_rule() is quite long and a bit convoluted so this patch does a code refactoring to improve the code.
Code related to NFC rule object initialization is refactored out to the local helper function igc_ethtool_init_nfc_rule(). Likewise, code related to NFC rule validation is refactored out to another local helper, igc_ethtool_is_nfc_rule_valid().
RX_CLS_FLOW_DISC check is removed since it is redundant. The macro is defined as the max value fsp->ring_cookie can have, so checking if fsp->ring_cookie >= adapter->num_rx_queues is already sufficient.
Finally, some log messages are improved or added, and obvious comments are removed.
--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 150 ++++++++++++------- 1 file changed, 92 insertions(+), 58 deletions(-)
drivers/net/ethernet/intel/igc/igc_ethtool.c +92 -58
@@ -1271,9 +1271,6 @@ static int igc_ethtool_update_nfc_rule(struct igc_adapter *adapter,if (!input)return err; -/* initialize node */ -INIT_HLIST_NODE (&input->nfc_node); -/* add filter to the list */ if (parent)hlist_add_behind (&input->nfc_node, &parent->nfc_node);
@@ -1286,41 +1283,19 @@ static int igc_ethtool_update_nfc_rule(struct igc_adapter *adapter,return 0 ; } -static int igc_ethtool_add_nfc_rule (struct igc_adapter *adapter, -struct ethtool_rxnfc *cmd) +static void igc_ethtool_init_nfc_rule (struct igc_nfc_rule *rule, +const struct ethtool_rx_flow_spec *fsp) { -struct net_device *netdev = adapter->netdev; -struct ethtool_rx_flow_spec *fsp = - (struct ethtool_rx_flow_spec *)&cmd->fs; -struct igc_nfc_rule *rule, *tmp; -int err =0 ; - -if (!(netdev->hw_features &NETIF_F_NTUPLE )) -return -EOPNOTSUPP ; +INIT_HLIST_NODE (&rule->nfc_node); -/* Don't allow programming if the action is a queue greater than -* the number of online Rx queues. -*/ -if (fsp->ring_cookie ==RX_CLS_FLOW_DISC || - fsp->ring_cookie >= adapter->num_rx_queues) { -netdev_err (netdev, -"ethtool -N: The specified action is invalid" ); -return -EINVAL ; - } + rule->action = fsp->ring_cookie; + rule->sw_idx = fsp->location; -/* Don't allow indexes to exist outside of available space */ -if (fsp->location >=IGC_MAX_RXNFC_RULES ) { -netdev_err (netdev,"Location out of range" ); -return -EINVAL ; +if ((fsp->flow_type &FLOW_EXT ) && fsp->m_ext.vlan_tci) { + rule->filter.vlan_tci =ntohs (fsp->h_ext.vlan_tci); + rule->filter.match_flags |=IGC_FILTER_FLAG_VLAN_TCI ; } -if ((fsp->flow_type & ~FLOW_EXT ) !=ETHER_FLOW ) -return -EINVAL ; - - rule =kzalloc (sizeof (*rule),GFP_KERNEL ); -if (!rule) -return -ENOMEM ; -if (fsp->m_u.ether_spec.h_proto ==ETHER_TYPE_FULL_MASK ) { rule->filter.etype =ntohs (fsp->h_u.ether_spec.h_proto); rule->filter.match_flags =IGC_FILTER_FLAG_ETHER_TYPE ;
@@ -1340,51 +1315,110 @@ static int igc_ethtool_add_nfc_rule(struct igc_adapter *adapter,ether_addr_copy (rule->filter.dst_addr, fsp->h_u.ether_spec.h_dest); } +} -if (rule->filter.match_flags &IGC_FILTER_FLAG_DST_MAC_ADDR && - rule->filter.match_flags &IGC_FILTER_FLAG_SRC_MAC_ADDR ) { -netdev_dbg (netdev,"Filters with both dst and src are not supported" ); - err = -EOPNOTSUPP ; - goto err_out; - } +/** +* igc_ethtool_check_nfc_rule() - Check if NFC rule is valid. +* @adapter: Pointer to adapter. +* @rule: Rule under evaluation. +* +* Rules with both destination and source MAC addresses are considered invalid +* since the driver doesn't support them. +* +* Also, if there is already another rule with the same filter, @rule is +* considered invalid. +* +* Context: Expects adapter->nfc_rule_lock to be held by caller. +* +* Return: 0 in case of success, negative errno code otherwise. +*/ +static int igc_ethtool_check_nfc_rule (struct igc_adapter *adapter, +struct igc_nfc_rule *rule) +{ +struct net_device *dev = adapter->netdev; +u8 flags = rule->filter.match_flags; +struct igc_nfc_rule *tmp; -if ((fsp->flow_type &FLOW_EXT ) && fsp->m_ext.vlan_tci) { -if (fsp->m_ext.vlan_tci !=htons (VLAN_PRIO_MASK )) { -netdev_dbg (netdev,"VLAN mask not supported" ); - err = -EOPNOTSUPP ; - goto err_out; - } - rule->filter.vlan_tci =ntohs (fsp->h_ext.vlan_tci); - rule->filter.match_flags |=IGC_FILTER_FLAG_VLAN_TCI ; +if (!flags) { +netdev_dbg (dev,"Rule with no match" ); +return -EINVAL ; } - rule->action = fsp->ring_cookie; - rule->sw_idx = fsp->location; - -spin_lock (&adapter->nfc_rule_lock); +if (flags &IGC_FILTER_FLAG_DST_MAC_ADDR && + flags &IGC_FILTER_FLAG_SRC_MAC_ADDR ) { +netdev_dbg (dev,"Filters with both dst and src are not supported" ); +return -EOPNOTSUPP ; + }hlist_for_each_entry (tmp, &adapter->nfc_rule_list, nfc_node) {if (!memcmp (&rule->filter, &tmp->filter,sizeof (rule->filter))) { - err = -EEXIST ; -netdev_err (netdev, -"ethtool: this filter is already set" ); - goto err_out_w_lock; +netdev_dbg (dev,"Rule already exists" ); +return -EEXIST ; } } +return 0 ; +} + +static int igc_ethtool_add_nfc_rule (struct igc_adapter *adapter, +struct ethtool_rxnfc *cmd) +{ +struct net_device *netdev = adapter->netdev; +struct ethtool_rx_flow_spec *fsp = + (struct ethtool_rx_flow_spec *)&cmd->fs; +struct igc_nfc_rule *rule; +int err; + +if (!(netdev->hw_features &NETIF_F_NTUPLE )) { +netdev_dbg (netdev,"N-tuple filters disabled" ); +return -EOPNOTSUPP ; + } + +if ((fsp->flow_type & ~FLOW_EXT ) !=ETHER_FLOW ) { +netdev_dbg (netdev,"Only ethernet flow type is supported" ); +return -EOPNOTSUPP ; + } + +if ((fsp->flow_type &FLOW_EXT ) && + fsp->m_ext.vlan_tci !=htons (VLAN_PRIO_MASK )) { +netdev_dbg (netdev,"VLAN mask not supported" ); +return -EOPNOTSUPP ; + } + +if (fsp->ring_cookie >= adapter->num_rx_queues) { +netdev_dbg (netdev,"Invalid action" ); +return -EINVAL ; + } + +if (fsp->location >=IGC_MAX_RXNFC_RULES ) { +netdev_dbg (netdev,"Invalid location" ); +return -EINVAL ; + } + + rule =kzalloc (sizeof (*rule),GFP_KERNEL ); +if (!rule) +return -ENOMEM ; + +igc_ethtool_init_nfc_rule (rule, fsp); + +spin_lock (&adapter->nfc_rule_lock); + + err =igc_ethtool_check_nfc_rule (adapter, rule); +if (err) + goto err; + err =igc_enable_nfc_rule (adapter, rule);if (err) - goto err_out_w_lock; + goto err;igc_ethtool_update_nfc_rule (adapter, rule, rule->sw_idx);spin_unlock (&adapter->nfc_rule_lock);return 0 ; -err_out_w_lock: +err:spin_unlock (&adapter->nfc_rule_lock); -err_out:kfree (rule);return err; }
Signature · 1 line
2.26.0
Brown
PATCH 8/19 igc: Refactor igc_ethtool_add_nfc_rule()
Quoted 20 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 08/19] igc: Refactorigc_ethtool_add_nfc_rule()Current implementation of
igc_ethtool_add_nfc_rule()is quite long and a bit convoluted so this patch does a code refactoring to improve the code.Code related to NFC rule object initialization is refactored out to the local helper function
igc_ethtool_init_nfc_rule(). Likewise, code related to NFC rule validation is refactored out to another local helper,igc_ethtool_is_nfc_rule_valid().
RX_CLS_FLOW_DISCcheck is removed since it is redundant. The macro is defined as the max valuefsp->ring_cookiecan have, so checking iffsp->ring_cookie>=adapter->num_rx_queuesis already sufficient.
Quoted 8 lines
Finally, some log messages are improved or added, and obvious comments are removed.
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 150 ++++++++++++------- 1 file changed, 92 insertions(+), 58 deletions(-)
PATCH 9/19 igc: Fix 'sw_idx' type in struct igc_nfc_rule
In reply to Andre GuedesThe 'sw_idx' field from 'struct igc_nfc_rule' is u16 type but it is assigned an u32 value in igc_ethtool_init_nfc_rule(). This patch changes 'sw_idx' type to u32 so they match. Also, it makes more sense to call this field 'location' since it holds the NFC rule location.
--- drivers/net/ethernet/intel/igc/igc.h | 2 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +1 -1
@@ -463,7 +463,7 @@ struct igc_nfc_filter {struct igc_nfc_rule {struct hlist_node nfc_node;struct igc_nfc_filter filter; -u16 sw_idx; +u32 location;u16 action; };
drivers/net/ethernet/intel/igc/igc_ethtool.c +8 -8
@@ -940,11 +940,11 @@ static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter, cmd->data =IGC_MAX_RXNFC_RULES ;hlist_for_each_entry (rule, &adapter->nfc_rule_list, nfc_node) { -if (fsp->location <= rule->sw_idx) +if (fsp->location <= rule->location)break ; } -if (!rule || fsp->location != rule->sw_idx) +if (!rule || fsp->location != rule->location)return -EINVAL ;if (!rule->filter.match_flags)
@@ -991,7 +991,7 @@ static int igc_ethtool_get_nfc_rules(struct igc_adapter *adapter,hlist_for_each_entry (rule, &adapter->nfc_rule_list, nfc_node) {if (cnt == cmd->rule_cnt)return -EMSGSIZE ; - rule_locs[cnt] = rule->sw_idx; + rule_locs[cnt] = rule->location; cnt++; }
@@ -1240,7 +1240,7 @@ int igc_disable_nfc_rule(struct igc_adapter *adapter,static int igc_ethtool_update_nfc_rule (struct igc_adapter *adapter,struct igc_nfc_rule *input, -u16 sw_idx) +u32 location) {struct igc_nfc_rule *rule, *parent;int err = -EINVAL ;
@@ -1250,13 +1250,13 @@ static int igc_ethtool_update_nfc_rule(struct igc_adapter *adapter,hlist_for_each_entry (rule, &adapter->nfc_rule_list, nfc_node) {/* hash found, or no matching entry */ -if (rule->sw_idx >= sw_idx) +if (rule->location >= location)break ; parent = rule; }/* if there is an old rule occupying our place remove it */ -if (rule && rule->sw_idx == sw_idx) { +if (rule && rule->location == location) {if (!input) err =igc_disable_nfc_rule (adapter, rule);
@@ -1289,7 +1289,7 @@ static void igc_ethtool_init_nfc_rule(struct igc_nfc_rule *rule,INIT_HLIST_NODE (&rule->nfc_node); rule->action = fsp->ring_cookie; - rule->sw_idx = fsp->location; + rule->location = fsp->location;if ((fsp->flow_type &FLOW_EXT ) && fsp->m_ext.vlan_tci) { rule->filter.vlan_tci =ntohs (fsp->h_ext.vlan_tci);
@@ -1412,7 +1412,7 @@ static int igc_ethtool_add_nfc_rule(struct igc_adapter *adapter,if (err) goto err; -igc_ethtool_update_nfc_rule (adapter, rule, rule->sw_idx); +igc_ethtool_update_nfc_rule (adapter, rule, rule->location);spin_unlock (&adapter->nfc_rule_lock);return 0 ;
Signature · 1 line
2.26.0
Brown
PATCH 9/19 igc: Fix 'sw_idx' type in struct igc_nfc_rule
Quoted 12 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 09/19] igc: Fix 'sw_idx' type in structigc_nfc_ruleThe '
sw_idx' field from 'structigc_nfc_rule' is u16 type but it is assigned an u32 value inigc_ethtool_init_nfc_rule(). This patch changes 'sw_idx' type to u32 so they match. Also, it makes more sense to call this field 'location' since it holds the NFC rule location.
Quoted 6 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc.h | 2 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-)
PATCH 10/19 igc: Fix locking issue when retrieving NFC rules
In reply to Andre GuedesAccess to NFC rules stored in adapter->nfc_rule_list is protect by adapter->nfc_rule_lock. The functions igc_ethtool_get_nfc_rule() and igc_ethtool_get_nfc_rules() are missing to hold the lock while accessing rule objects.
--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/igc/igc_ethtool.c +16 -3
@@ -939,16 +939,18 @@ static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter, cmd->data =IGC_MAX_RXNFC_RULES ; +spin_lock (&adapter->nfc_rule_lock); +hlist_for_each_entry (rule, &adapter->nfc_rule_list, nfc_node) {if (fsp->location <= rule->location)break ; }if (!rule || fsp->location != rule->location) -return -EINVAL ; + goto out;if (!rule->filter.match_flags) -return -EINVAL ; + goto out; fsp->flow_type =ETHER_FLOW ; fsp->ring_cookie = rule->action;
@@ -976,7 +978,12 @@ static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter,eth_broadcast_addr (fsp->m_u.ether_spec.h_source); } +spin_unlock (&adapter->nfc_rule_lock);return 0 ; + +out: +spin_unlock (&adapter->nfc_rule_lock); +return -EINVAL ; } static int igc_ethtool_get_nfc_rules(struct igc_adapter *adapter,
@@ -988,13 +995,19 @@ static int igc_ethtool_get_nfc_rules(struct igc_adapter *adapter, cmd->data =IGC_MAX_RXNFC_RULES ; +spin_lock (&adapter->nfc_rule_lock); +hlist_for_each_entry (rule, &adapter->nfc_rule_list, nfc_node) { -if (cnt == cmd->rule_cnt) +if (cnt == cmd->rule_cnt) { +spin_unlock (&adapter->nfc_rule_lock);return -EMSGSIZE ; + } rule_locs[cnt] = rule->location; cnt++; } +spin_unlock (&adapter->nfc_rule_lock); + cmd->rule_cnt = cnt;return 0 ;
Signature · 1 line
2.26.0
Brown
PATCH 10/19 igc: Fix locking issue when retrieving NFC rules
Quoted 12 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 10/19] igc: Fix locking issue when retrieving NFC rulesAccess to NFC rules stored in
adapter->nfc_rule_listis protect byadapter->nfc_rule_lock. The functionsigc_ethtool_get_nfc_rule()andigc_ethtool_get_nfc_rules()are missing to hold the lock while accessing rule objects.
Quoted 5 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
PATCH 11/19 igc: Fix NFC rule overwrite cases
In reply to Andre GuedesWhen the 'loc' argument is passed in ethtool, the input rule overwrites any rule present in that location. In this situation we must disable the old rule otherwise it is left enabled in hardware. This patch fixes the issue by always calling igc_disable_nfc_rule() when deleting the old rule, no matter the value of 'input' argument.
--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/ethernet/intel/igc/igc_ethtool.c +1 -2
@@ -1270,8 +1270,7 @@ static int igc_ethtool_update_nfc_rule(struct igc_adapter *adapter,/* if there is an old rule occupying our place remove it */ if (rule && rule->location == location) { -if (!input) - err =igc_disable_nfc_rule (adapter, rule); + err =igc_disable_nfc_rule (adapter, rule);hlist_del (&rule->nfc_node);kfree (rule);
Signature · 1 line
2.26.0
Brown
PATCH 11/19 igc: Fix NFC rule overwrite cases
Quoted 12 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 11/19] igc: Fix NFC rule overwrite casesWhen the 'loc' argument is passed in ethtool, the input rule overwrites any rule present in that location. In this situation we must disable the old rule otherwise it is left enabled in hardware. This patch fixes the issue by always calling
igc_disable_nfc_rule()when deleting the old rule, no matter the value of 'input' argument.
Quoted 5 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
PATCH 12/19 igc: Fix NFC rules with multicast addresses
In reply to Andre GuedesMulticast MAC addresses are valid address for NFC rules but igc_add_mac_filter() is currently rejecting them. In fact, the I225 controller doesn't impose any constraint on the address value so this patch gets rid of the address validation check in MAC filter APIs.
--- drivers/net/ethernet/intel/igc/igc_main.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +0 -6
@@ -2250,9 +2250,6 @@ int igc_add_mac_filter(struct igc_adapter *adapter,struct net_device *dev = adapter->netdev;int index; -if (!is_valid_ether_addr (addr)) -return -EINVAL ; - index =igc_find_mac_filter (adapter, type, addr);if (index >=0 ) goto update_filter;
@@ -2284,9 +2281,6 @@ int igc_del_mac_filter(struct igc_adapter *adapter,struct net_device *dev = adapter->netdev;int index; -if (!is_valid_ether_addr (addr)) -return -EINVAL ; - index =igc_find_mac_filter (adapter, type, addr);if (index <0 )return -ENOENT ;
Signature · 1 line
2.26.0
Brown
PATCH 12/19 igc: Fix NFC rules with multicast addresses
Quoted 12 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 12/19] igc: Fix NFC rules with multicast addressesMulticast MAC addresses are valid address for NFC rules but
igc_add_mac_filter()is currently rejecting them. In fact, the I225 controller doesn't impose any constraint on the address value so this patch gets rid of the address validation check in MAC filter APIs.
Quoted 5 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 6 ------ 1 file changed, 6 deletions(-)
PATCH 13/19 igc: Fix NFC rules restoration
In reply to Andre GuedesWhen network interface is brought up, the driver re-enables the NFC rules previously configured. However, this is done in reverse order the rules were added and hardware filters are configured differently.
For example, consider the following rules:
$ ethtool -N eth0 flow-type ether dst 00:00:00:00:00:AA queue 0 $ ethtool -N eth0 flow-type ether dst 00:00:00:00:00:BB queue 1 $ ethtool -N eth0 flow-type ether dst 00:00:00:00:00:CC queue 2 $ ethtool -N eth0 flow-type ether dst 00:00:00:00:00:DD queue 3
RAL/RAH registers are configure so filter index 1 has address ending with AA, filter index 2 has address ending in BB, and so on.
If we bring the interface down and up again, RAL/RAH registers are configured so filter index 1 has address ending in DD, filter index 2 has CC, and so on. IOW, in reverse order we had before bringing the interface down.
This issue can be fixed by traversing adapter->nfc_rule_list in backwards when restoring the rules. Since hlist doesn't support backwards traversal, this patch replaces it by list_head and fixes igc_restore_nfc_rules() accordingly.
--- drivers/net/ethernet/intel/igc/igc.h | 4 ++-- drivers/net/ethernet/intel/igc/igc_ethtool.c | 19 ++++++++----------- drivers/net/ethernet/intel/igc/igc_main.c | 16 +++++++++------- 3 files changed, 19 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +2 -2
@@ -191,7 +191,7 @@ struct igc_adapter {* nfc_rule_lock. */ spinlock_t nfc_rule_lock; -struct hlist_head nfc_rule_list; +struct list_head nfc_rule_list;unsigned int nfc_rule_count;u8 rss_indir_tbl[IGC_RETA_SIZE ];
@@ -461,7 +461,7 @@ struct igc_nfc_filter { };struct igc_nfc_rule { -struct hlist_node nfc_node; +struct list_head list;struct igc_nfc_filter filter;u32 location;u16 action;
drivers/net/ethernet/intel/igc/igc_ethtool.c +8 -11
@@ -941,7 +941,7 @@ static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter,spin_lock (&adapter->nfc_rule_lock); -hlist_for_each_entry (rule, &adapter->nfc_rule_list, nfc_node) { +list_for_each_entry (rule, &adapter->nfc_rule_list, list) {if (fsp->location <= rule->location)break ; }
@@ -997,7 +997,7 @@ static int igc_ethtool_get_nfc_rules(struct igc_adapter *adapter,spin_lock (&adapter->nfc_rule_lock); -hlist_for_each_entry (rule, &adapter->nfc_rule_list, nfc_node) { +list_for_each_entry (rule, &adapter->nfc_rule_list, list) {if (cnt == cmd->rule_cnt) {spin_unlock (&adapter->nfc_rule_lock);return -EMSGSIZE ;
@@ -1261,7 +1261,7 @@ static int igc_ethtool_update_nfc_rule(struct igc_adapter *adapter, parent =NULL ; rule =NULL ; -hlist_for_each_entry (rule, &adapter->nfc_rule_list, nfc_node) { +list_for_each_entry (rule, &adapter->nfc_rule_list, list) {/* hash found, or no matching entry */ if (rule->location >= location)break ;
@@ -1272,7 +1272,7 @@ static int igc_ethtool_update_nfc_rule(struct igc_adapter *adapter,if (rule && rule->location == location) { err =igc_disable_nfc_rule (adapter, rule); -hlist_del (&rule->nfc_node); +list_del (&rule->list);kfree (rule); adapter->nfc_rule_count--; }
@@ -1283,11 +1283,8 @@ static int igc_ethtool_update_nfc_rule(struct igc_adapter *adapter,if (!input)return err; -/* add filter to the list */ -if (parent) -hlist_add_behind (&input->nfc_node, &parent->nfc_node); -else -hlist_add_head (&input->nfc_node, &adapter->nfc_rule_list); +list_add (&input->list, parent ? &parent->list : + &adapter->nfc_rule_list);/* update counts */ adapter->nfc_rule_count++;
@@ -1298,7 +1295,7 @@ static int igc_ethtool_update_nfc_rule(struct igc_adapter *adapter,static void igc_ethtool_init_nfc_rule (struct igc_nfc_rule *rule,const struct ethtool_rx_flow_spec *fsp) { -INIT_HLIST_NODE (&rule->nfc_node); +INIT_LIST_HEAD (&rule->list); rule->action = fsp->ring_cookie; rule->location = fsp->location;
@@ -1362,7 +1359,7 @@ static int igc_ethtool_check_nfc_rule(struct igc_adapter *adapter,return -EOPNOTSUPP ; } -hlist_for_each_entry (tmp, &adapter->nfc_rule_list, nfc_node) { +list_for_each_entry (tmp, &adapter->nfc_rule_list, list) {if (!memcmp (&rule->filter, &tmp->filter,sizeof (rule->filter))) {netdev_dbg (dev,"Rule already exists" );
drivers/net/ethernet/intel/igc/igc_main.c +9 -7
@@ -2181,7 +2181,7 @@ static void igc_restore_nfc_rules(struct igc_adapter *adapter)spin_lock (&adapter->nfc_rule_lock); -hlist_for_each_entry (rule, &adapter->nfc_rule_list, nfc_node) +list_for_each_entry_reverse (rule, &adapter->nfc_rule_list, list)igc_enable_nfc_rule (adapter, rule);spin_unlock (&adapter->nfc_rule_lock);
@@ -3420,6 +3420,9 @@ static int igc_sw_init(struct igc_adapter *adapter) adapter->min_frame_size =ETH_ZLEN +ETH_FCS_LEN ;spin_lock_init (&adapter->nfc_rule_lock); +INIT_LIST_HEAD (&adapter->nfc_rule_list); + adapter->nfc_rule_count =0 ; +spin_lock_init (&adapter->stats64_lock);/* Assume MSI-X interrupts, will be checked during IRQ allocation */ adapter->flags |=IGC_FLAG_HAS_MSIX ;
@@ -3652,7 +3655,7 @@ static void igc_nfc_rule_exit(struct igc_adapter *adapter)spin_lock (&adapter->nfc_rule_lock); -hlist_for_each_entry (rule, &adapter->nfc_rule_list, nfc_node) +list_for_each_entry (rule, &adapter->nfc_rule_list, list)igc_disable_nfc_rule (adapter, rule);spin_unlock (&adapter->nfc_rule_lock);
@@ -3827,14 +3830,13 @@ static int igc_set_features(struct net_device *netdev,return 0 ;if (!(features &NETIF_F_NTUPLE )) { -struct hlist_node *node2; -struct igc_nfc_rule *rule; +struct igc_nfc_rule *rule, *tmp;spin_lock (&adapter->nfc_rule_lock); -hlist_for_each_entry_safe (rule, node2, - &adapter->nfc_rule_list, nfc_node) { +list_for_each_entry_safe (rule, tmp, + &adapter->nfc_rule_list, list) {igc_disable_nfc_rule (adapter, rule); -hlist_del (&rule->nfc_node); +list_del (&rule->list);kfree (rule); }spin_unlock (&adapter->nfc_rule_lock);
Signature · 1 line
2.26.0
Brown
PATCH 13/19 igc: Fix NFC rules restoration
Quoted 30 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 13/19] igc: Fix NFC rules restorationWhen network interface is brought up, the driver re-enables the NFC rules previously configured. However, this is done in reverse order the rules were added and hardware filters are configured differently.
For example, consider the following rules:
$ ethtool -N eth0 flow-type ether dst 00:00:00:00:00:AA queue 0 $ ethtool -N eth0 flow-type ether dst 00:00:00:00:00:BB queue 1 $ ethtool -N eth0 flow-type ether dst 00:00:00:00:00:CC queue 2 $ ethtool -N eth0 flow-type ether dst 00:00:00:00:00:DD queue 3RAL/RAH registers are configure so filter index 1 has address ending with AA, filter index 2 has address ending in BB, and so on.
If we bring the interface down and up again, RAL/RAH registers are configured so filter index 1 has address ending in DD, filter index 2 has CC, and so on. IOW, in reverse order we had before bringing the interface down.
This issue can be fixed by traversing
adapter->nfc_rule_listin backwards when restoring the rules. Since hlist doesn't support backwards traversal, this patch replaces it bylist_headand fixesigc_restore_nfc_rules()accordingly.
Quoted 7 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc.h | 4 ++-- drivers/net/ethernet/intel/igc/igc_ethtool.c | 19 ++++++++----------- drivers/net/ethernet/intel/igc/igc_main.c | 16 +++++++++------- 3 files changed, 19 insertions(+), 20 deletions(-)
PATCH 14/19 igc: Refactor igc_ethtool_update_nfc_rule()
In reply to Andre GuedesCurrent implementation of igc_ethtool_update_nfc_rule() is a bit convoluted since it handles too many things: rule lookup, deletion and addition. This patch breaks it into three functions so we simplify the code and improve code reuse.
Code related to rule lookup is refactored out to a new function called igc_get_nfc_rule().
Code related to rule addition is refactored out to a new function called igc_add_nfc_rule(). This function enables the rule in hardware and adds it to the adapter's list.
Code related to rule deletion is refactored out to a new function called igc_del_nfc_rule(). This function disables the rule in hardware, removes it from adapter's list, and deletes it.
As a byproduct of this refactoring, igc_enable_nfc_rule() and igc_disable_nfc_rule() are moved to igc_main.c since they are not used in igc_ethtool.c anymore, and igc_restore_nfc_rules() and igc_nfc_rule_ exit() are moved around to avoid forward declaration.
Also, since this patch already touches igc_ethtool_get_nfc_rule(), it takes the opportunity to remove the 'match_flags' check. Empty flags are not allowed to be added so no need to check that.
--- drivers/net/ethernet/intel/igc/igc.h | 18 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 138 ++----------- drivers/net/ethernet/intel/igc/igc_main.c | 205 ++++++++++++++++--- 3 files changed, 195 insertions(+), 166 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +4 -14
@@ -232,16 +232,6 @@ void igc_write_rss_indir_tbl(struct igc_adapter *adapter);bool igc_has_link (struct igc_adapter *adapter);void igc_reset (struct igc_adapter *adapter);int igc_set_spd_dplx (struct igc_adapter *adapter,u32 spd,u8 dplx); -int igc_add_mac_filter (struct igc_adapter *adapter, -enum igc_mac_filter_type type,const u8 *addr, -int queue); -int igc_del_mac_filter (struct igc_adapter *adapter, -enum igc_mac_filter_type type,const u8 *addr); -int igc_add_vlan_prio_filter (struct igc_adapter *adapter,int prio, -int queue); -void igc_del_vlan_prio_filter (struct igc_adapter *adapter,int prio); -int igc_add_etype_filter (struct igc_adapter *adapter,u16 etype,int queue); -int igc_del_etype_filter (struct igc_adapter *adapter,u16 etype);void igc_update_stats (struct igc_adapter *adapter);/* igc_dump declarations */
@@ -544,10 +534,10 @@ static inline s32 igc_read_phy_reg(struct igc_hw *hw, u32 offset, u16 *data) }void igc_reinit_locked (struct igc_adapter *); -int igc_enable_nfc_rule (struct igc_adapter *adapter, -const struct igc_nfc_rule *rule); -int igc_disable_nfc_rule (struct igc_adapter *adapter, -const struct igc_nfc_rule *rule); +struct igc_nfc_rule *igc_get_nfc_rule (struct igc_adapter *adapter, +u32 location); +int igc_add_nfc_rule (struct igc_adapter *adapter,struct igc_nfc_rule *rule); +void igc_del_nfc_rule (struct igc_adapter *adapter,struct igc_nfc_rule *rule);void igc_ptp_init (struct igc_adapter *adapter);void igc_ptp_reset (struct igc_adapter *adapter);
drivers/net/ethernet/intel/igc/igc_ethtool.c +19 -119
174 lines not on this page · raw message
drivers/net/ethernet/intel/igc/igc_main.c +172 -33
259 lines not on this page · raw message
Signature · 1 line
2.26.0
Brown
PATCH 14/19 igc: Refactor igc_ethtool_update_nfc_rule()
Quoted 32 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 14/19] igc: Refactorigc_ethtool_update_nfc_rule()Current implementation of
igc_ethtool_update_nfc_rule()is a bit convoluted since it handles too many things: rule lookup, deletion and addition. This patch breaks it into three functions so we simplify the code and improve code reuse.Code related to rule lookup is refactored out to a new function called
igc_get_nfc_rule().Code related to rule addition is refactored out to a new function called
igc_add_nfc_rule(). This function enables the rule in hardware and adds it to the adapter's list.Code related to rule deletion is refactored out to a new function called
igc_del_nfc_rule(). This function disables the rule in hardware, removes it from adapter's list, and deletes it.As a byproduct of this refactoring,
igc_enable_nfc_rule()andigc_disable_nfc_rule()are moved toigc_main.csince they are not used inigc_ethtool.canymore, andigc_restore_nfc_rules()andigc_nfc_rule_exit()are moved around to avoid forward declaration.Also, since this patch already touches
igc_ethtool_get_nfc_rule(), it takes the opportunity to remove the 'match_flags' check. Empty flags are not allowed to be added so no need to check that.
Quoted 7 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc.h | 18 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 138 ++----------- drivers/net/ethernet/intel/igc/igc_main.c | 205 ++++++++++++++++--- 3 files changed, 195 insertions(+), 166 deletions(-)
PATCH 15/19 igc: Fix NFC rules leak when driver is unloaded
In reply to Andre GuedesIf we have RFC rules in adapter->nfc_rule_list when the IGC driver is unloaded, all rules are leaked. This patch fixes the issue by introducing the helper igc_flush_nfc_rules() and calling it in igc_remove(). It also updates igc_set_features() so is reuses the new helper instead of re-implementing it.
--- drivers/net/ethernet/intel/igc/igc_main.c | 29 +++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +16 -13
@@ -2545,6 +2545,18 @@ void igc_del_nfc_rule(struct igc_adapter *adapter, struct igc_nfc_rule *rule)kfree (rule); } +static void igc_flush_nfc_rules (struct igc_adapter *adapter) +{ +struct igc_nfc_rule *rule, *tmp; + +spin_lock (&adapter->nfc_rule_lock); + +list_for_each_entry_safe (rule, tmp, &adapter->nfc_rule_list, list) +igc_del_nfc_rule (adapter, rule); + +spin_unlock (&adapter->nfc_rule_lock); +} +/** * igc_add_nfc_rule() - Add NFC rule. * @adapter: Pointer to adapter.
@@ -3968,19 +3980,8 @@ static int igc_set_features(struct net_device *netdev,if (!(changed & (NETIF_F_RXALL |NETIF_F_NTUPLE )))return 0 ; -if (!(features &NETIF_F_NTUPLE )) { -struct igc_nfc_rule *rule, *tmp; - -spin_lock (&adapter->nfc_rule_lock); -list_for_each_entry_safe (rule, tmp, - &adapter->nfc_rule_list, list) { -igc_disable_nfc_rule (adapter, rule); -list_del (&rule->list); -kfree (rule); - } -spin_unlock (&adapter->nfc_rule_lock); - adapter->nfc_rule_count =0 ; - } +if (!(features &NETIF_F_NTUPLE )) +igc_flush_nfc_rules (adapter); netdev->features = features;
@@ -5250,6 +5251,8 @@ static void igc_remove(struct pci_dev *pdev)pm_runtime_get_noresume (&pdev->dev); +igc_flush_nfc_rules (adapter); +igc_ptp_stop (adapter);set_bit (__IGC_DOWN, &adapter->state);
Signature · 1 line
2.26.0
Brown
PATCH 15/19 igc: Fix NFC rules leak when driver is unloaded
Quoted 13 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 15/19] igc: Fix NFC rules leak when driver is unloadedIf we have RFC rules in
adapter->nfc_rule_listwhen the IGC driver is unloaded, all rules are leaked. This patch fixes the issue by introducing the helperigc_flush_nfc_rules()and calling it inigc_remove(). It also updatesigc_set_features()so is reuses the new helper instead of re-implementing it.
Quoted 5 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 29 +++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-)
PATCH 16/19 igc: Fix NFC rule validation
In reply to Andre GuedesIf we try to overwrite an existing rule with the same filter but different action, we get EEXIST error as shown below.
$ ethtool -N eth0 flow-type ether dst <MACADDR> action 1 loc 10 $ ethtool -N eth0 flow-type ether dst <MACADDR> action 2 loc 10 rmgr: Cannot insert RX class rule: File exists
The second command is expected to overwrite the previous rule in location 10 and succeed.
This patch fixes igc_ethtool_check_nfc_rule() so it also checks the rules location. In case they match, the rule under evaluation should not be considered invalid.
--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/igc/igc_ethtool.c +4 -3
@@ -1225,8 +1225,8 @@ static void igc_ethtool_init_nfc_rule(struct igc_nfc_rule *rule,* Rules with both destination and source MAC addresses are considered invalid * since the driver doesn't support them. * -* Also, if there is already another rule with the same filter, @rule is -* considered invalid. +* Also, if there is already another rule with the same filter in a different +* location, @rule is considered invalid. * * Context: Expects adapter->nfc_rule_lock to be held by caller. *
@@ -1252,7 +1252,8 @@ static int igc_ethtool_check_nfc_rule(struct igc_adapter *adapter,list_for_each_entry (tmp, &adapter->nfc_rule_list, list) {if (!memcmp (&rule->filter, &tmp->filter, -sizeof (rule->filter))) { +sizeof (rule->filter)) && + tmp->location != rule->location) {netdev_dbg (dev,"Rule already exists" );return -EEXIST ; }
Signature · 1 line
2.26.0
Brown
PATCH 16/19 igc: Fix NFC rule validation
Quoted 16 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 16/19] igc: Fix NFC rule validationIf we try to overwrite an existing rule with the same filter but different action, we get EEXIST error as shown below.
$ ethtool -N eth0 flow-type ether dst <MACADDR> action 1 loc 10 $ ethtool -N eth0 flow-type ether dst <MACADDR> action 2 loc 10 rmgr: Cannot insert RX class rule: File existsThe second command is expected to overwrite the previous rule in location 10 and succeed.
Quoted 9 lines
This patch fixes
igc_ethtool_check_nfc_rule()so it also checks the rules location. In case they match, the rule under evaluation should not be considered invalid.Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_ethtool.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
PATCH 17/19 igc: Change return type from igc_disable_nfc_rule()
In reply to Andre GuedesNone of igc_disable_nfc_rule() callers actually check its returning value. A closer look at why this function would fail shows that the only situation is when we try to delete an ethertype or mac filter that doesn't exist.
That situation is very unlikely so we can change igc_del_etype_filter() and igc_del_mac_filter() logic to "if the filter doesn't exist, we are done", and keep the logic in igc_disable_nfc_rule() callers simple.
--- drivers/net/ethernet/intel/igc/igc_main.c | 26 ++++++++--------------- 1 file changed, 9 insertions(+), 17 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +9 -17
@@ -2260,18 +2260,16 @@ static int igc_add_mac_filter(struct igc_adapter *adapter,* @adapter: Pointer to adapter where the filter should be deleted from * @type: MAC address filter type (source or destination) * @addr: MAC address -* -* Return: 0 in case of success, negative errno code otherwise. */ -static int igc_del_mac_filter (struct igc_adapter *adapter, -enum igc_mac_filter_type type,const u8 *addr) +static void igc_del_mac_filter (struct igc_adapter *adapter, +enum igc_mac_filter_type type,const u8 *addr) {struct net_device *dev = adapter->netdev;int index; index =igc_find_mac_filter (adapter, type, addr);if (index <0 ) -return -ENOENT ; +return ;if (index ==0 ) {/* If this is the default filter, we don't actually delete it.
@@ -2289,8 +2287,6 @@ static int igc_del_mac_filter(struct igc_adapter *adapter,igc_clear_mac_filter_hw (adapter, index); } - -return 0 ; }/**
@@ -2421,23 +2417,20 @@ static int igc_find_etype_filter(struct igc_adapter *adapter, u16 etype)* igc_del_etype_filter() - Delete ethertype filter. * @adapter: Pointer to adapter where the filter should be deleted from. * @etype: Ethertype value. -* -* Return: 0 in case of success, negative errno code otherwise. */ -static int igc_del_etype_filter (struct igc_adapter *adapter,u16 etype) +static void igc_del_etype_filter (struct igc_adapter *adapter,u16 etype) {struct igc_hw *hw = &adapter->hw;int index; index =igc_find_etype_filter (adapter, etype);if (index <0 ) -return -ENOENT ; +return ;wr32 (IGC_ETQF (index),0 );netdev_dbg (adapter->netdev,"Delete ethertype filter: etype %04x" , etype); -return 0 ; } static int igc_enable_nfc_rule(struct igc_adapter *adapter,
@@ -2478,8 +2471,8 @@ static int igc_enable_nfc_rule(struct igc_adapter *adapter,return 0 ; } -static int igc_disable_nfc_rule (struct igc_adapter *adapter, -const struct igc_nfc_rule *rule) +static void igc_disable_nfc_rule (struct igc_adapter *adapter, +const struct igc_nfc_rule *rule) {if (rule->filter.match_flags &IGC_FILTER_FLAG_ETHER_TYPE )igc_del_etype_filter (adapter, rule->filter.etype);
@@ -2498,8 +2491,6 @@ static int igc_disable_nfc_rule(struct igc_adapter *adapter,if (rule->filter.match_flags &IGC_FILTER_FLAG_DST_MAC_ADDR )igc_del_mac_filter (adapter,IGC_MAC_FILTER_TYPE_DST , rule->filter.dst_addr); - -return 0 ; }/**
@@ -2624,7 +2615,8 @@ static int igc_uc_unsync(struct net_device *netdev, const unsigned char *addr) {struct igc_adapter *adapter =netdev_priv (netdev); -return igc_del_mac_filter (adapter,IGC_MAC_FILTER_TYPE_DST , addr); +igc_del_mac_filter (adapter,IGC_MAC_FILTER_TYPE_DST , addr); +return 0 ; }/**
Signature · 1 line
2.26.0
Brown
PATCH 17/19 igc: Change return type from igc_disable_nfc_rule()
Quoted 12 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 17/19] igc: Change return type fromigc_disable_nfc_rule()None of
igc_disable_nfc_rule()callers actually check its returning value. A closer look at why this function would fail shows that the only situation is when we try to delete an ethertype or mac filter that doesn't exist.
Quoted 9 lines
That situation is very unlikely so we can change
igc_del_etype_filter()andigc_del_mac_filter()logic to "if the filter doesn't exist, we are done", and keep the logic inigc_disable_nfc_rule()callers simple.Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 26 ++++++++--------------- 1 file changed, 9 insertions(+), 17 deletions(-)
PATCH 18/19 igc: Change adapter->nfc_rule_lock to mutex
In reply to Andre GuedesThis patch changes adapter->nfc_rule_lock type from spin_lock to mutex so we avoid unnecessary busy waiting on lock contention.
A closer look at the execution context of NFC rule API users shows that all of them run in process context. The API users are: ethtool ops, igc_configure(), called when interface is brought up by user or reset workequeue thread, igc_down(), called when interface is brought down, and igc_remove(), called when driver is unloaded.
---
Note that checkpatch.pl reports an issue with this patch. The issue is a false positive. There is a comment right above that line referring to the lock.
Here is the report:
CHECK: struct mutex definition without comment #31: FILE: drivers/net/ethernet/intel/igc/igc.h:193:
+ struct mutex nfc_rule_lock;
--- drivers/net/ethernet/intel/igc/igc.h | 2 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 24 ++++++++++---------- drivers/net/ethernet/intel/igc/igc_main.c | 14 ++++++------ 3 files changed, 20 insertions(+), 20 deletions(-)
drivers/net/ethernet/intel/igc/igc.h +1 -1
@@ -190,7 +190,7 @@ struct igc_adapter {/* Any access to elements in nfc_rule_list is protected by the * nfc_rule_lock. */ -spinlock_t nfc_rule_lock; +struct mutex nfc_rule_lock;struct list_head nfc_rule_list;unsigned int nfc_rule_count;
drivers/net/ethernet/intel/igc/igc_ethtool.c +12 -12
@@ -939,7 +939,7 @@ static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter, cmd->data =IGC_MAX_RXNFC_RULES ; -spin_lock (&adapter->nfc_rule_lock); +mutex_lock (&adapter->nfc_rule_lock); rule =igc_get_nfc_rule (adapter, fsp->location);if (!rule)
@@ -971,11 +971,11 @@ static int igc_ethtool_get_nfc_rule(struct igc_adapter *adapter,eth_broadcast_addr (fsp->m_u.ether_spec.h_source); } -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock);return 0 ; out: -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock);return -EINVAL ; }
@@ -988,18 +988,18 @@ static int igc_ethtool_get_nfc_rules(struct igc_adapter *adapter, cmd->data =IGC_MAX_RXNFC_RULES ; -spin_lock (&adapter->nfc_rule_lock); +mutex_lock (&adapter->nfc_rule_lock);list_for_each_entry (rule, &adapter->nfc_rule_list, list) {if (cnt == cmd->rule_cnt) { -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock);return -EMSGSIZE ; } rule_locs[cnt] = rule->location; cnt++; } -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock); cmd->rule_cnt = cnt;
@@ -1303,7 +1303,7 @@ static int igc_ethtool_add_nfc_rule(struct igc_adapter *adapter,igc_ethtool_init_nfc_rule (rule, fsp); -spin_lock (&adapter->nfc_rule_lock); +mutex_lock (&adapter->nfc_rule_lock); err =igc_ethtool_check_nfc_rule (adapter, rule);if (err)
@@ -1317,11 +1317,11 @@ static int igc_ethtool_add_nfc_rule(struct igc_adapter *adapter,if (err) goto err; -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock);return 0 ; err: -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock);kfree (rule);return err; }
@@ -1333,17 +1333,17 @@ static int igc_ethtool_del_nfc_rule(struct igc_adapter *adapter, (struct ethtool_rx_flow_spec *)&cmd->fs;struct igc_nfc_rule *rule; -spin_lock (&adapter->nfc_rule_lock); +mutex_lock (&adapter->nfc_rule_lock); rule =igc_get_nfc_rule (adapter, fsp->location);if (!rule) { -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock);return -EINVAL ; }igc_del_nfc_rule (adapter, rule); -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock);return 0 ; }
drivers/net/ethernet/intel/igc/igc_main.c +7 -7
@@ -2540,12 +2540,12 @@ static void igc_flush_nfc_rules(struct igc_adapter *adapter) {struct igc_nfc_rule *rule, *tmp; -spin_lock (&adapter->nfc_rule_lock); +mutex_lock (&adapter->nfc_rule_lock);list_for_each_entry_safe (rule, tmp, &adapter->nfc_rule_list, list)igc_del_nfc_rule (adapter, rule); -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock); }/**
@@ -2584,24 +2584,24 @@ static void igc_restore_nfc_rules(struct igc_adapter *adapter) {struct igc_nfc_rule *rule; -spin_lock (&adapter->nfc_rule_lock); +mutex_lock (&adapter->nfc_rule_lock);list_for_each_entry_reverse (rule, &adapter->nfc_rule_list, list)igc_enable_nfc_rule (adapter, rule); -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock); }static void igc_nfc_rule_exit (struct igc_adapter *adapter) {struct igc_nfc_rule *rule; -spin_lock (&adapter->nfc_rule_lock); +mutex_lock (&adapter->nfc_rule_lock);list_for_each_entry (rule, &adapter->nfc_rule_list, list)igc_disable_nfc_rule (adapter, rule); -spin_unlock (&adapter->nfc_rule_lock); +mutex_unlock (&adapter->nfc_rule_lock); }static int igc_uc_sync (struct net_device *netdev,const unsigned char *addr)
@@ -3574,7 +3574,7 @@ static int igc_sw_init(struct igc_adapter *adapter)VLAN_HLEN ; adapter->min_frame_size =ETH_ZLEN +ETH_FCS_LEN ; -spin_lock_init (&adapter->nfc_rule_lock); +mutex_init (&adapter->nfc_rule_lock);INIT_LIST_HEAD (&adapter->nfc_rule_list); adapter->nfc_rule_count =0 ;
Signature · 1 line
2.26.0
Brown
PATCH 18/19 igc: Change adapter->nfc_rule_lock to mutex
Quoted 23 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 18/19] igc: Changeadapter->nfc_rule_lockto mutexThis patch changes
adapter->nfc_rule_locktype fromspin_lockto mutex so we avoid unnecessary busy waiting on lock contention.A closer look at the execution context of NFC rule API users shows that all of them run in process context. The API users are: ethtool ops,
igc_configure(), called when interface is brought up by user or reset workequeue thread,igc_down(), called when interface is brought down, andigc_remove(), called when driver is unloaded.Signed-off-by Andre Guedes <[email protected]>---
Note that checkpatch.pl reports an issue with this patch. The issue is a false positive. There is a comment right above that line referring to the lock.Here is the report:
Quoted 9 lines
CHECK: struct mutex definition without comment #31: FILE:
drivers/net/ethernet/intel/igc/igc.h:193:
+ struct mutexnfc_rule_lock;--- drivers/net/ethernet/intel/igc/igc.h | 2 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 24 ++++++++++---------- drivers/net/ethernet/intel/igc/igc_main.c | 14 ++++++------ 3 files changed, 20 insertions(+), 20 deletions(-)
Brown
PATCH 18/19 igc: Change adapter->nfc_rule_lock to mutex
In reply to Andre GuedesQuoted 23 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 18/19] igc: Changeadapter->nfc_rule_lockto mutexThis patch changes
adapter->nfc_rule_locktype fromspin_lockto mutex so we avoid unnecessary busy waiting on lock contention.A closer look at the execution context of NFC rule API users shows that all of them run in process context. The API users are: ethtool ops,
igc_configure(), called when interface is brought up by user or reset workequeue thread,igc_down(), called when interface is brought down, andigc_remove(), called when driver is unloaded.Signed-off-by Andre Guedes <[email protected]>---
Note that checkpatch.pl reports an issue with this patch. The issue is a false positive. There is a comment right above that line referring to the lock.Here is the report:
Quoted 9 lines
CHECK: struct mutex definition without comment #31: FILE:
drivers/net/ethernet/intel/igc/igc.h:193:
+ struct mutexnfc_rule_lock;--- drivers/net/ethernet/intel/igc/igc.h | 2 +- drivers/net/ethernet/intel/igc/igc_ethtool.c | 24 ++++++++++---------- drivers/net/ethernet/intel/igc/igc_main.c | 14 ++++++------ 3 files changed, 20 insertions(+), 20 deletions(-)
Checkpatch complains about not having a comment with the mutex:
---------------------------------------------------------
u1322:[0]/usr/src/kernels/next-queue> git format-patch $item -1 --stdout|./scripts/checkpatch.pl -
CHECK: struct mutex definition without comment
#31: FILE: drivers/net/ethernet/intel/igc/igc.h:193:
+ struct mutex nfc_rule_lock;
total: 0 errors, 0 warnings, 1 checks, 141 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
Your patch has style problems, please review.
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
u1322:[0]/usr/src/kernels/next-queue>
---------------------------------------------------------
Aside from that ...
PATCH 19/19 igc: Remove igc_nfc_rule_exit()
In reply to Andre GuedesDuring igc_down(), we call igc_nfc_rule_exit() which traverse the NFC rule list disabling filters one by one. Later on in igc_down() flow we issue an hardware reset which also clear all filters. Since we already reset the hardware, we don't actually need to disable each filter manually. In order to simplify the code, this patch removes igc_nfc_rule() altogether.
--- drivers/net/ethernet/intel/igc/igc_main.c | 14 -------------- 1 file changed, 14 deletions(-)
drivers/net/ethernet/intel/igc/igc_main.c +0 -14
@@ -2592,18 +2592,6 @@ static void igc_restore_nfc_rules(struct igc_adapter *adapter)mutex_unlock (&adapter->nfc_rule_lock); } -static void igc_nfc_rule_exit (struct igc_adapter *adapter) -{ -struct igc_nfc_rule *rule; - -mutex_lock (&adapter->nfc_rule_lock); - -list_for_each_entry (rule, &adapter->nfc_rule_list, list) -igc_disable_nfc_rule (adapter, rule); - -mutex_unlock (&adapter->nfc_rule_lock); -} -static int igc_uc_sync (struct net_device *netdev,const unsigned char *addr) {struct igc_adapter *adapter =netdev_priv (netdev);
@@ -3822,8 +3810,6 @@ void igc_down(struct igc_adapter *adapter)wr32 (IGC_RCTL , rctl & ~IGC_RCTL_EN );/* flush and sleep below */ -igc_nfc_rule_exit (adapter); -/* set trans_start so we don't get spurious watchdogs during reset */ netif_trans_update (netdev);
Signature · 1 line
2.26.0
Brown
PATCH 19/19 igc: Remove igc_nfc_rule_exit()
Quoted 13 lines
From: Intel-wired-lan <[email protected]> On Behalf Of Andre Guedes
Sent: Friday, April 24, 2020 1:16 PM
To: intel-wired-lan at lists.osuosl.org
Subject: [Intel-wired-lan] [PATCH 19/19] igc: Removeigc_nfc_rule_exit()During
igc_down(), we calligc_nfc_rule_exit()which traverse the NFC rule list disabling filters one by one. Later on inigc_down()flow we issue an hardware reset which also clear all filters. Since we already reset the hardware, we don't actually need to disable each filter manually. In order to simplify the code, this patch removesigc_nfc_rule()altogether.
Quoted 5 lines
Signed-off-by Andre Guedes <[email protected]>--- drivers/net/ethernet/intel/igc/igc_main.c | 14 -------------- 1 file changed, 14 deletions(-)