Commit 54bcb3d1 authored by Dmitry Bogdanov's avatar Dmitry Bogdanov Committed by David S. Miller

net: aquantia: add vlan id to rx flow filters

The VLAN filter (VLAN id) is compared against 16 filters.
VLAN id must be accompanied by mask 0xF000. That is to distinguish
VLAN filter from L2 Ethertype filter with UserPriority since both
User Priority and VLAN ID are passed in the same 'vlan' parameter.
Flow type may be any as  it is not matched for VLAN filter.
Due to fixed order of the rules in the NIC, the location 0-15 are
reserved for vlan filters.

Example:
To add a rule that directs packets from VLAN 2001 to queue 5:
ethtool -N <ethX> flow-type ip4 vlan 2001 m 0xF000 action 5 loc 0
Signed-off-by: default avatarDmitry Bogdanov <dmitry.bogdanov@aquantia.com>
Signed-off-by: default avatarIgor Russkikh <igor.russkikh@aquantia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a6ed6f22
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/if_vlan.h>
#include "ver.h" #include "ver.h"
#include "aq_cfg.h" #include "aq_cfg.h"
#include "aq_utils.h" #include "aq_utils.h"
......
...@@ -119,6 +119,29 @@ static int aq_check_approve_fl3l4(struct aq_nic_s *aq_nic, ...@@ -119,6 +119,29 @@ static int aq_check_approve_fl3l4(struct aq_nic_s *aq_nic,
return 0; return 0;
} }
static int __must_check
aq_check_approve_fvlan(struct aq_nic_s *aq_nic,
struct aq_hw_rx_fltrs_s *rx_fltrs,
struct ethtool_rx_flow_spec *fsp)
{
if (fsp->location < AQ_RX_FIRST_LOC_FVLANID ||
fsp->location > AQ_RX_LAST_LOC_FVLANID) {
netdev_err(aq_nic->ndev,
"ethtool: location must be in range [%d, %d]",
AQ_RX_FIRST_LOC_FVLANID,
AQ_RX_LAST_LOC_FVLANID);
return -EINVAL;
}
if (fsp->ring_cookie > aq_nic->aq_nic_cfg.num_rss_queues) {
netdev_err(aq_nic->ndev,
"ethtool: queue number must be in range [0, %d]",
aq_nic->aq_nic_cfg.num_rss_queues - 1);
return -EINVAL;
}
return 0;
}
static int __must_check static int __must_check
aq_check_filter(struct aq_nic_s *aq_nic, aq_check_filter(struct aq_nic_s *aq_nic,
struct ethtool_rx_flow_spec *fsp) struct ethtool_rx_flow_spec *fsp)
...@@ -127,7 +150,14 @@ aq_check_filter(struct aq_nic_s *aq_nic, ...@@ -127,7 +150,14 @@ aq_check_filter(struct aq_nic_s *aq_nic,
struct aq_hw_rx_fltrs_s *rx_fltrs = aq_get_hw_rx_fltrs(aq_nic); struct aq_hw_rx_fltrs_s *rx_fltrs = aq_get_hw_rx_fltrs(aq_nic);
if (fsp->flow_type & FLOW_EXT) { if (fsp->flow_type & FLOW_EXT) {
err = -EOPNOTSUPP; if (be16_to_cpu(fsp->m_ext.vlan_tci) == VLAN_VID_MASK) {
err = aq_check_approve_fvlan(aq_nic, rx_fltrs, fsp);
} else {
netdev_err(aq_nic->ndev,
"ethtool: invalid vlan mask 0x%x specified",
be16_to_cpu(fsp->m_ext.vlan_tci));
err = -EINVAL;
}
} else { } else {
switch (fsp->flow_type & ~FLOW_EXT) { switch (fsp->flow_type & ~FLOW_EXT) {
case ETHER_FLOW: case ETHER_FLOW:
...@@ -229,6 +259,42 @@ aq_check_rule(struct aq_nic_s *aq_nic, ...@@ -229,6 +259,42 @@ aq_check_rule(struct aq_nic_s *aq_nic,
return err; return err;
} }
static int aq_set_data_fvlan(struct aq_nic_s *aq_nic,
struct aq_rx_filter *aq_rx_fltr,
struct aq_rx_filter_vlan *aq_vlans, bool add)
{
const struct ethtool_rx_flow_spec *fsp = &aq_rx_fltr->aq_fsp;
int location = fsp->location - AQ_RX_FIRST_LOC_FVLANID;
memset(&aq_vlans[location], 0, sizeof(aq_vlans[location]));
if (!add)
return 0;
aq_vlans[location].location = location;
aq_vlans[location].vlan_id = be16_to_cpu(fsp->h_ext.vlan_tci)
& VLAN_VID_MASK;
aq_vlans[location].queue = fsp->ring_cookie & 0x1FU;
aq_vlans[location].enable = 1U;
return 0;
}
static int aq_add_del_fvlan(struct aq_nic_s *aq_nic,
struct aq_rx_filter *aq_rx_fltr, bool add)
{
const struct aq_hw_ops *aq_hw_ops = aq_nic->aq_hw_ops;
if (unlikely(!aq_hw_ops->hw_filter_vlan_set))
return -EOPNOTSUPP;
aq_set_data_fvlan(aq_nic,
aq_rx_fltr,
aq_nic->aq_hw_rx_fltrs.fl2.aq_vlans,
add);
return aq_filters_vlans_update(aq_nic);
}
static int aq_set_data_fl3l4(struct aq_nic_s *aq_nic, static int aq_set_data_fl3l4(struct aq_nic_s *aq_nic,
struct aq_rx_filter *aq_rx_fltr, struct aq_rx_filter *aq_rx_fltr,
struct aq_rx_filter_l3l4 *data, bool add) struct aq_rx_filter_l3l4 *data, bool add)
...@@ -354,7 +420,13 @@ static int aq_add_del_rule(struct aq_nic_s *aq_nic, ...@@ -354,7 +420,13 @@ static int aq_add_del_rule(struct aq_nic_s *aq_nic,
int err = -EINVAL; int err = -EINVAL;
if (aq_rx_fltr->aq_fsp.flow_type & FLOW_EXT) { if (aq_rx_fltr->aq_fsp.flow_type & FLOW_EXT) {
err = -EOPNOTSUPP; if (be16_to_cpu(aq_rx_fltr->aq_fsp.m_ext.vlan_tci)
== VLAN_VID_MASK) {
aq_rx_fltr->type = aq_rx_filter_vlan;
err = aq_add_del_fvlan(aq_nic, aq_rx_fltr, add);
} else {
err = -EINVAL;
}
} else { } else {
switch (aq_rx_fltr->aq_fsp.flow_type & ~FLOW_EXT) { switch (aq_rx_fltr->aq_fsp.flow_type & ~FLOW_EXT) {
case ETHER_FLOW: case ETHER_FLOW:
...@@ -573,3 +645,19 @@ int aq_reapply_rxnfc_all_rules(struct aq_nic_s *aq_nic) ...@@ -573,3 +645,19 @@ int aq_reapply_rxnfc_all_rules(struct aq_nic_s *aq_nic)
err_exit: err_exit:
return err; return err;
} }
int aq_filters_vlans_update(struct aq_nic_s *aq_nic)
{
const struct aq_hw_ops *aq_hw_ops = aq_nic->aq_hw_ops;
struct aq_hw_s *aq_hw = aq_nic->aq_hw;
int err = 0;
if (unlikely(!aq_hw_ops->hw_filter_vlan_set))
return -EOPNOTSUPP;
err = aq_hw_ops->hw_filter_vlan_set(aq_hw,
aq_nic->aq_hw_rx_fltrs.fl2.aq_vlans
);
return err;
}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "aq_nic.h" #include "aq_nic.h"
enum aq_rx_filter_type { enum aq_rx_filter_type {
aq_rx_filter_vlan,
aq_rx_filter_l3l4 aq_rx_filter_l3l4
}; };
...@@ -27,5 +28,6 @@ int aq_get_rxnfc_all_rules(struct aq_nic_s *aq_nic, struct ethtool_rxnfc *cmd, ...@@ -27,5 +28,6 @@ int aq_get_rxnfc_all_rules(struct aq_nic_s *aq_nic, struct ethtool_rxnfc *cmd,
u32 *rule_locs); u32 *rule_locs);
int aq_clear_rxnfc_all_rules(struct aq_nic_s *aq_nic); int aq_clear_rxnfc_all_rules(struct aq_nic_s *aq_nic);
int aq_reapply_rxnfc_all_rules(struct aq_nic_s *aq_nic); int aq_reapply_rxnfc_all_rules(struct aq_nic_s *aq_nic);
int aq_filters_vlans_update(struct aq_nic_s *aq_nic);
#endif /* AQ_FILTERS_H */ #endif /* AQ_FILTERS_H */
...@@ -18,9 +18,13 @@ ...@@ -18,9 +18,13 @@
#include "aq_rss.h" #include "aq_rss.h"
#include "hw_atl/hw_atl_utils.h" #include "hw_atl/hw_atl_utils.h"
#define AQ_RX_FIRST_LOC_FVLANID 0U
#define AQ_RX_LAST_LOC_FVLANID 15U
#define AQ_RX_FIRST_LOC_FL3L4 32U #define AQ_RX_FIRST_LOC_FL3L4 32U
#define AQ_RX_LAST_LOC_FL3L4 39U #define AQ_RX_LAST_LOC_FL3L4 39U
#define AQ_RX_MAX_RXNFC_LOC AQ_RX_LAST_LOC_FL3L4 #define AQ_RX_MAX_RXNFC_LOC AQ_RX_LAST_LOC_FL3L4
#define AQ_VLAN_MAX_FILTERS \
(AQ_RX_LAST_LOC_FVLANID - AQ_RX_FIRST_LOC_FVLANID + 1U)
/* NIC H/W capabilities */ /* NIC H/W capabilities */
struct aq_hw_caps_s { struct aq_hw_caps_s {
...@@ -194,6 +198,11 @@ struct aq_hw_ops { ...@@ -194,6 +198,11 @@ struct aq_hw_ops {
int (*hw_filter_l3l4_clear)(struct aq_hw_s *self, int (*hw_filter_l3l4_clear)(struct aq_hw_s *self,
struct aq_rx_filter_l3l4 *data); struct aq_rx_filter_l3l4 *data);
int (*hw_filter_vlan_set)(struct aq_hw_s *self,
struct aq_rx_filter_vlan *aq_vlans);
int (*hw_filter_vlan_ctrl)(struct aq_hw_s *self, bool enable);
int (*hw_multicast_list_set)(struct aq_hw_s *self, int (*hw_multicast_list_set)(struct aq_hw_s *self,
u8 ar_mac[AQ_HW_MULTICAST_ADDRESS_MAX] u8 ar_mac[AQ_HW_MULTICAST_ADDRESS_MAX]
[ETH_ALEN], [ETH_ALEN],
......
...@@ -61,6 +61,10 @@ struct aq_nic_cfg_s { ...@@ -61,6 +61,10 @@ struct aq_nic_cfg_s {
#define AQ_NIC_TCVEC2RING(_NIC_, _TC_, _VEC_) \ #define AQ_NIC_TCVEC2RING(_NIC_, _TC_, _VEC_) \
((_TC_) * AQ_CFG_TCS_MAX + (_VEC_)) ((_TC_) * AQ_CFG_TCS_MAX + (_VEC_))
struct aq_hw_rx_fl2 {
struct aq_rx_filter_vlan aq_vlans[AQ_VLAN_MAX_FILTERS];
};
struct aq_hw_rx_fl3l4 { struct aq_hw_rx_fl3l4 {
u8 active_ipv4; u8 active_ipv4;
u8 active_ipv6:2; u8 active_ipv6:2;
...@@ -70,6 +74,7 @@ struct aq_hw_rx_fl3l4 { ...@@ -70,6 +74,7 @@ struct aq_hw_rx_fl3l4 {
struct aq_hw_rx_fltrs_s { struct aq_hw_rx_fltrs_s {
struct hlist_head filter_list; struct hlist_head filter_list;
u16 active_filters; u16 active_filters;
struct aq_hw_rx_fl2 fl2;
struct aq_hw_rx_fl3l4 fl3l4; struct aq_hw_rx_fl3l4 fl3l4;
}; };
......
...@@ -1003,6 +1003,42 @@ static int hw_atl_b0_hw_fl3l4_set(struct aq_hw_s *self, ...@@ -1003,6 +1003,42 @@ static int hw_atl_b0_hw_fl3l4_set(struct aq_hw_s *self,
return aq_hw_err_from_flags(self); return aq_hw_err_from_flags(self);
} }
/**
* @brief Set VLAN filter table
* @details Configure VLAN filter table to accept (and assign the queue) traffic
* for the particular vlan ids.
* Note: use this function under vlan promisc mode not to lost the traffic
*
* @param aq_hw_s
* @param aq_rx_filter_vlan VLAN filter configuration
* @return 0 - OK, <0 - error
*/
static int hw_atl_b0_hw_vlan_set(struct aq_hw_s *self,
struct aq_rx_filter_vlan *aq_vlans)
{
int i;
for (i = 0; i < AQ_VLAN_MAX_FILTERS; i++) {
hw_atl_rpf_vlan_flr_en_set(self, 0U, i);
hw_atl_rpf_vlan_rxq_en_flr_set(self, 0U, i);
if (aq_vlans[i].enable) {
hw_atl_rpf_vlan_id_flr_set(self,
aq_vlans[i].vlan_id,
i);
hw_atl_rpf_vlan_flr_act_set(self, 1U, i);
hw_atl_rpf_vlan_flr_en_set(self, 1U, i);
if (aq_vlans[i].queue != 0xFF) {
hw_atl_rpf_vlan_rxq_flr_set(self,
aq_vlans[i].queue,
i);
hw_atl_rpf_vlan_rxq_en_flr_set(self, 1U, i);
}
}
}
return aq_hw_err_from_flags(self);
}
const struct aq_hw_ops hw_atl_ops_b0 = { const struct aq_hw_ops hw_atl_ops_b0 = {
.hw_set_mac_address = hw_atl_b0_hw_mac_addr_set, .hw_set_mac_address = hw_atl_b0_hw_mac_addr_set,
.hw_init = hw_atl_b0_hw_init, .hw_init = hw_atl_b0_hw_init,
...@@ -1028,6 +1064,7 @@ const struct aq_hw_ops hw_atl_ops_b0 = { ...@@ -1028,6 +1064,7 @@ const struct aq_hw_ops hw_atl_ops_b0 = {
.hw_ring_tx_init = hw_atl_b0_hw_ring_tx_init, .hw_ring_tx_init = hw_atl_b0_hw_ring_tx_init,
.hw_packet_filter_set = hw_atl_b0_hw_packet_filter_set, .hw_packet_filter_set = hw_atl_b0_hw_packet_filter_set,
.hw_filter_l3l4_set = hw_atl_b0_hw_fl3l4_set, .hw_filter_l3l4_set = hw_atl_b0_hw_fl3l4_set,
.hw_filter_vlan_set = hw_atl_b0_hw_vlan_set,
.hw_multicast_list_set = hw_atl_b0_hw_multicast_list_set, .hw_multicast_list_set = hw_atl_b0_hw_multicast_list_set,
.hw_interrupt_moderation_set = hw_atl_b0_hw_interrupt_moderation_set, .hw_interrupt_moderation_set = hw_atl_b0_hw_interrupt_moderation_set,
.hw_rss_set = hw_atl_b0_hw_rss_set, .hw_rss_set = hw_atl_b0_hw_rss_set,
......
...@@ -245,6 +245,13 @@ enum hw_atl_rx_action_with_traffic { ...@@ -245,6 +245,13 @@ enum hw_atl_rx_action_with_traffic {
HW_ATL_RX_HOST, HW_ATL_RX_HOST,
}; };
struct aq_rx_filter_vlan {
u8 enable;
u8 location;
u16 vlan_id;
u8 queue;
};
struct aq_rx_filter_l3l4 { struct aq_rx_filter_l3l4 {
u32 cmd; u32 cmd;
u8 location; u8 location;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment