Skip to content

Commit b2bb7b7

Browse files
Ben Hutchingsdavem330
authored andcommitted
sfc: Implement ethtool RX NFC rules API instead of n-tuple API
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1a6281a commit b2bb7b7

1 file changed

Lines changed: 149 additions & 39 deletions

File tree

‎drivers/net/ethernet/sfc/ethtool.c‎

Lines changed: 149 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,58 @@ static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags)
818818
return efx_reset(efx, rc);
819819
}
820820

821+
static int efx_ethtool_get_class_rule(struct efx_nic *efx,
822+
struct ethtool_rx_flow_spec *rule)
823+
{
824+
struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
825+
struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
826+
struct efx_filter_spec spec;
827+
u16 vid;
828+
u8 proto;
829+
int rc;
830+
831+
rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL,
832+
rule->location, &spec);
833+
if (rc)
834+
return rc;
835+
836+
if (spec.dmaq_id == 0xfff)
837+
rule->ring_cookie = RX_CLS_FLOW_DISC;
838+
else
839+
rule->ring_cookie = spec.dmaq_id;
840+
841+
rc = efx_filter_get_eth_local(&spec, &vid,
842+
rule->h_u.ether_spec.h_dest);
843+
if (rc == 0) {
844+
rule->flow_type = ETHER_FLOW;
845+
memset(rule->m_u.ether_spec.h_dest, ~0, ETH_ALEN);
846+
if (vid != EFX_FILTER_VID_UNSPEC) {
847+
rule->flow_type |= FLOW_EXT;
848+
rule->h_ext.vlan_tci = htons(vid);
849+
rule->m_ext.vlan_tci = htons(0xfff);
850+
}
851+
return 0;
852+
}
853+
854+
rc = efx_filter_get_ipv4_local(&spec, &proto,
855+
&ip_entry->ip4dst, &ip_entry->pdst);
856+
if (rc != 0) {
857+
rc = efx_filter_get_ipv4_full(
858+
&spec, &proto, &ip_entry->ip4src, &ip_entry->psrc,
859+
&ip_entry->ip4dst, &ip_entry->pdst);
860+
EFX_WARN_ON_PARANOID(rc);
861+
ip_mask->ip4src = ~0;
862+
ip_mask->psrc = ~0;
863+
}
864+
rule->flow_type = (proto == IPPROTO_TCP) ? TCP_V4_FLOW : UDP_V4_FLOW;
865+
ip_mask->ip4dst = ~0;
866+
ip_mask->pdst = ~0;
867+
return rc;
868+
}
869+
821870
static int
822871
efx_ethtool_get_rxnfc(struct net_device *net_dev,
823-
struct ethtool_rxnfc *info, u32 *rules __always_unused)
872+
struct ethtool_rxnfc *info, u32 *rule_locs)
824873
{
825874
struct efx_nic *efx = netdev_priv(net_dev);
826875

@@ -862,84 +911,123 @@ efx_ethtool_get_rxnfc(struct net_device *net_dev,
862911
return 0;
863912
}
864913

914+
case ETHTOOL_GRXCLSRLCNT:
915+
info->data = efx_filter_get_rx_id_limit(efx);
916+
if (info->data == 0)
917+
return -EOPNOTSUPP;
918+
info->data |= RX_CLS_LOC_SPECIAL;
919+
info->rule_cnt =
920+
efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL);
921+
return 0;
922+
923+
case ETHTOOL_GRXCLSRULE:
924+
if (efx_filter_get_rx_id_limit(efx) == 0)
925+
return -EOPNOTSUPP;
926+
return efx_ethtool_get_class_rule(efx, &info->fs);
927+
928+
case ETHTOOL_GRXCLSRLALL: {
929+
s32 rc;
930+
info->data = efx_filter_get_rx_id_limit(efx);
931+
if (info->data == 0)
932+
return -EOPNOTSUPP;
933+
rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL,
934+
rule_locs, info->rule_cnt);
935+
if (rc < 0)
936+
return rc;
937+
info->rule_cnt = rc;
938+
return 0;
939+
}
940+
865941
default:
866942
return -EOPNOTSUPP;
867943
}
868944
}
869945

870-
static int efx_ethtool_set_rx_ntuple(struct net_device *net_dev,
871-
struct ethtool_rx_ntuple *ntuple)
946+
static int efx_ethtool_set_class_rule(struct efx_nic *efx,
947+
struct ethtool_rx_flow_spec *rule)
872948
{
873-
struct efx_nic *efx = netdev_priv(net_dev);
874-
struct ethtool_tcpip4_spec *ip_entry = &ntuple->fs.h_u.tcp_ip4_spec;
875-
struct ethtool_tcpip4_spec *ip_mask = &ntuple->fs.m_u.tcp_ip4_spec;
876-
struct ethhdr *mac_entry = &ntuple->fs.h_u.ether_spec;
877-
struct ethhdr *mac_mask = &ntuple->fs.m_u.ether_spec;
878-
struct efx_filter_spec filter;
949+
struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec;
950+
struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec;
951+
struct ethhdr *mac_entry = &rule->h_u.ether_spec;
952+
struct ethhdr *mac_mask = &rule->m_u.ether_spec;
953+
struct efx_filter_spec spec;
879954
int rc;
880955

881-
/* Range-check action */
882-
if (ntuple->fs.action < ETHTOOL_RXNTUPLE_ACTION_CLEAR ||
883-
ntuple->fs.action >= (s32)efx->n_rx_channels)
956+
/* Check that user wants us to choose the location */
957+
if (rule->location != RX_CLS_LOC_ANY &&
958+
rule->location != RX_CLS_LOC_FIRST &&
959+
rule->location != RX_CLS_LOC_LAST)
884960
return -EINVAL;
885961

886-
if (~ntuple->fs.data_mask)
962+
/* Range-check ring_cookie */
963+
if (rule->ring_cookie >= efx->n_rx_channels &&
964+
rule->ring_cookie != RX_CLS_FLOW_DISC)
887965
return -EINVAL;
888966

889-
efx_filter_init_rx(&filter, EFX_FILTER_PRI_MANUAL, 0,
890-
(ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP) ?
891-
0xfff : ntuple->fs.action);
967+
/* Check for unsupported extensions */
968+
if ((rule->flow_type & FLOW_EXT) &&
969+
(rule->m_ext.vlan_etype | rule->m_ext.data[0] |
970+
rule->m_ext.data[1]))
971+
return -EINVAL;
972+
973+
efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL,
974+
(rule->location == RX_CLS_LOC_FIRST) ?
975+
EFX_FILTER_FLAG_RX_OVERRIDE_IP : 0,
976+
(rule->ring_cookie == RX_CLS_FLOW_DISC) ?
977+
0xfff : rule->ring_cookie);
892978

893-
switch (ntuple->fs.flow_type) {
979+
switch (rule->flow_type) {
894980
case TCP_V4_FLOW:
895981
case UDP_V4_FLOW: {
896-
u8 proto = (ntuple->fs.flow_type == TCP_V4_FLOW ?
982+
u8 proto = (rule->flow_type == TCP_V4_FLOW ?
897983
IPPROTO_TCP : IPPROTO_UDP);
898984

899985
/* Must match all of destination, */
900-
if (ip_mask->ip4dst | ip_mask->pdst)
986+
if ((__force u32)~ip_mask->ip4dst |
987+
(__force u16)~ip_mask->pdst)
901988
return -EINVAL;
902989
/* all or none of source, */
903990
if ((ip_mask->ip4src | ip_mask->psrc) &&
904991
((__force u32)~ip_mask->ip4src |
905992
(__force u16)~ip_mask->psrc))
906993
return -EINVAL;
907994
/* and nothing else */
908-
if ((u8)~ip_mask->tos | (u16)~ntuple->fs.vlan_tag_mask)
995+
if (ip_mask->tos | rule->m_ext.vlan_tci)
909996
return -EINVAL;
910997

911-
if (!ip_mask->ip4src)
912-
rc = efx_filter_set_ipv4_full(&filter, proto,
998+
if (ip_mask->ip4src)
999+
rc = efx_filter_set_ipv4_full(&spec, proto,
9131000
ip_entry->ip4dst,
9141001
ip_entry->pdst,
9151002
ip_entry->ip4src,
9161003
ip_entry->psrc);
9171004
else
918-
rc = efx_filter_set_ipv4_local(&filter, proto,
1005+
rc = efx_filter_set_ipv4_local(&spec, proto,
9191006
ip_entry->ip4dst,
9201007
ip_entry->pdst);
9211008
if (rc)
9221009
return rc;
9231010
break;
9241011
}
9251012

926-
case ETHER_FLOW:
927-
/* Must match all of destination, */
928-
if (!is_zero_ether_addr(mac_mask->h_dest))
1013+
case ETHER_FLOW | FLOW_EXT:
1014+
/* Must match all or none of VID */
1015+
if (rule->m_ext.vlan_tci != htons(0xfff) &&
1016+
rule->m_ext.vlan_tci != 0)
9291017
return -EINVAL;
930-
/* all or none of VID, */
931-
if (ntuple->fs.vlan_tag_mask != 0xf000 &&
932-
ntuple->fs.vlan_tag_mask != 0xffff)
1018+
case ETHER_FLOW:
1019+
/* Must match all of destination */
1020+
if (!is_broadcast_ether_addr(mac_mask->h_dest))
9331021
return -EINVAL;
9341022
/* and nothing else */
935-
if (!is_broadcast_ether_addr(mac_mask->h_source) ||
936-
mac_mask->h_proto != htons(0xffff))
1023+
if (!is_zero_ether_addr(mac_mask->h_source) ||
1024+
mac_mask->h_proto)
9371025
return -EINVAL;
9381026

9391027
rc = efx_filter_set_eth_local(
940-
&filter,
941-
(ntuple->fs.vlan_tag_mask == 0xf000) ?
942-
ntuple->fs.vlan_tag : EFX_FILTER_VID_UNSPEC,
1028+
&spec,
1029+
(rule->flow_type & FLOW_EXT && rule->m_ext.vlan_tci) ?
1030+
ntohs(rule->h_ext.vlan_tci) : EFX_FILTER_VID_UNSPEC,
9431031
mac_entry->h_dest);
9441032
if (rc)
9451033
return rc;
@@ -949,11 +1037,33 @@ static int efx_ethtool_set_rx_ntuple(struct net_device *net_dev,
9491037
return -EINVAL;
9501038
}
9511039

952-
if (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_CLEAR)
953-
return efx_filter_remove_filter(efx, &filter);
1040+
rc = efx_filter_insert_filter(efx, &spec, true);
1041+
if (rc < 0)
1042+
return rc;
9541043

955-
rc = efx_filter_insert_filter(efx, &filter, true);
956-
return rc < 0 ? rc : 0;
1044+
rule->location = rc;
1045+
return 0;
1046+
}
1047+
1048+
static int efx_ethtool_set_rxnfc(struct net_device *net_dev,
1049+
struct ethtool_rxnfc *info)
1050+
{
1051+
struct efx_nic *efx = netdev_priv(net_dev);
1052+
1053+
if (efx_filter_get_rx_id_limit(efx) == 0)
1054+
return -EOPNOTSUPP;
1055+
1056+
switch (info->cmd) {
1057+
case ETHTOOL_SRXCLSRLINS:
1058+
return efx_ethtool_set_class_rule(efx, &info->fs);
1059+
1060+
case ETHTOOL_SRXCLSRLDEL:
1061+
return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL,
1062+
info->fs.location);
1063+
1064+
default:
1065+
return -EOPNOTSUPP;
1066+
}
9571067
}
9581068

9591069
static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev)
@@ -1007,7 +1117,7 @@ const struct ethtool_ops efx_ethtool_ops = {
10071117
.set_wol = efx_ethtool_set_wol,
10081118
.reset = efx_ethtool_reset,
10091119
.get_rxnfc = efx_ethtool_get_rxnfc,
1010-
.set_rx_ntuple = efx_ethtool_set_rx_ntuple,
1120+
.set_rxnfc = efx_ethtool_set_rxnfc,
10111121
.get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
10121122
.get_rxfh_indir = efx_ethtool_get_rxfh_indir,
10131123
.set_rxfh_indir = efx_ethtool_set_rxfh_indir,

0 commit comments

Comments
 (0)