// SPDX-License-Identifier: GPL-2.0-only /**************************************************************************** * Driver for Solarflare network controllers and boards * Copyright 2019 Solarflare Communications Inc. * Copyright 2020-2022 Xilinx Inc. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 as published * by the Free Software Foundation, incorporated herein by reference.
*/
/* Constructs an mport selector from an mport ID, because they're not the same */ void efx_mae_mport_mport(struct efx_nic *efx __always_unused, u32 mport_id, u32 *out)
{
efx_dword_t mport;
netif_dbg(efx, drv, efx->net_dev, "Draining counters:\n"); /* Only process received generation counts */ for (i = 0; (i < (outlen / 4)) && (i < EFX_TC_COUNTER_TYPE_MAX); i++) {
efx->tc->flush_gen[i] = MCDI_ARRAY_DWORD(outbuf,
MAE_COUNTERS_STREAM_STOP_V2_OUT_GENERATION_COUNT,
i);
netif_dbg(efx, drv, efx->net_dev, "\ttype %u, awaiting gen %u\n", i,
efx->tc->flush_gen[i]);
}
efx->tc->flush_counters = true;
/* Drain can take up to 2 seconds owing to FWRIVERHD-2884; whatever * timeout we use, that delay is added to unload on nonresponsive * hardware, so 2500ms seems like a reasonable compromise.
*/ if (!wait_event_timeout(efx->tc->flush_wq,
efx_mae_counters_flushed(efx->tc->flush_gen,
efx->tc->seen_gen),
msecs_to_jiffies(2500)))
netif_warn(efx, drv, efx->net_dev, "Failed to drain counters RXQ, FW may be unhappy\n");
int efx_mae_get_tables(struct efx_nic *efx)
{ int rc;
efx->tc->meta_ct.hooked = false; if (efx_mae_check_table_exists(efx, TABLE_ID_CONNTRACK_TABLE)) {
rc = efx_mae_table_get_desc(efx, &efx->tc->meta_ct.desc,
TABLE_ID_CONNTRACK_TABLE); if (rc) {
pci_info(efx->pci_dev, "FW does not support conntrack desc rc %d\n",
rc); return 0;
}
rc = efx_mae_table_hook_ct(efx, &efx->tc->meta_ct); if (rc) {
pci_info(efx->pci_dev, "FW does not support conntrack hook rc %d\n",
rc); return 0;
}
} else {
pci_info(efx->pci_dev, "FW does not support conntrack table\n");
} return 0;
}
/* AR and OR caps MCDIs have identical layout, so we are using the * same code for both.
*/
BUILD_BUG_ON(MC_CMD_MAE_GET_AR_CAPS_OUT_LEN(MAE_NUM_FIELDS) <
MC_CMD_MAE_GET_OR_CAPS_OUT_LEN(MAE_NUM_FIELDS));
BUILD_BUG_ON(MC_CMD_MAE_GET_AR_CAPS_IN_LEN);
BUILD_BUG_ON(MC_CMD_MAE_GET_OR_CAPS_IN_LEN);
rc = efx_mcdi_rpc(efx, cmd, NULL, 0, outbuf, sizeof(outbuf), &outlen); if (rc) return rc;
BUILD_BUG_ON(MC_CMD_MAE_GET_AR_CAPS_OUT_COUNT_OFST !=
MC_CMD_MAE_GET_OR_CAPS_OUT_COUNT_OFST);
count = MCDI_DWORD(outbuf, MAE_GET_AR_CAPS_OUT_COUNT);
memset(field_support, MAE_FIELD_UNSUPPORTED, MAE_NUM_FIELDS);
BUILD_BUG_ON(MC_CMD_MAE_GET_AR_CAPS_OUT_FIELD_FLAGS_OFST !=
MC_CMD_MAE_GET_OR_CAPS_OUT_FIELD_FLAGS_OFST);
caps = _MCDI_DWORD(outbuf, MAE_GET_AR_CAPS_OUT_FIELD_FLAGS); /* We're only interested in the support status enum, not any other * flags, so just extract that from each entry.
*/ for (i = 0; i < count; i++) if (i * sizeof(*outbuf) + MC_CMD_MAE_GET_AR_CAPS_OUT_FIELD_FLAGS_OFST < outlen)
field_support[i] = EFX_DWORD_FIELD(caps[i], MAE_FIELD_FLAGS_SUPPORT_STATUS); return 0;
}
int efx_mae_get_caps(struct efx_nic *efx, struct mae_caps *caps)
{ int rc;
staticconstchar *mask_type_name(enum mask_type typ)
{ switch (typ) { case MASK_ONES: return"all-1s"; case MASK_ZEROES: return"all-0s"; case MASK_PREFIX: return"prefix"; case MASK_OTHER: return"arbitrary"; default: /* can't happen */ return"unknown";
}
}
/* Checks a (big-endian) bytestring is a bit prefix */ staticenum mask_type classify_mask(const u8 *mask, size_t len)
{ bool zeroes = true; /* All bits seen so far are zeroes */ bool ones = true; /* All bits seen so far are ones */ bool prefix = true; /* Valid prefix so far */
size_t i;
for (i = 0; i < len; i++) { if (ones) { if (!is_prefix_byte(mask[i]))
prefix = false;
} elseif (mask[i]) {
prefix = false;
} if (mask[i] != 0xff)
ones = false; if (mask[i])
zeroes = false;
} if (ones) return MASK_ONES; if (zeroes) return MASK_ZEROES; if (prefix) return MASK_PREFIX; return MASK_OTHER;
}
staticint efx_mae_match_check_cap_typ(u8 support, enum mask_type typ)
{ switch (support) { case MAE_FIELD_UNSUPPORTED: case MAE_FIELD_SUPPORTED_MATCH_NEVER: if (typ == MASK_ZEROES) return 0; return -EOPNOTSUPP; case MAE_FIELD_SUPPORTED_MATCH_OPTIONAL: if (typ == MASK_ZEROES) return 0;
fallthrough; case MAE_FIELD_SUPPORTED_MATCH_ALWAYS: if (typ == MASK_ONES) return 0; return -EINVAL; case MAE_FIELD_SUPPORTED_MATCH_PREFIX: if (typ == MASK_OTHER) return -EOPNOTSUPP; return 0; case MAE_FIELD_SUPPORTED_MATCH_MASK: return 0; default: return -EIO;
}
}
/* Validate field mask against hardware capabilities. Captures caller's 'rc' */ #define CHECK(_mcdi, _field) ({ \ enum mask_type typ = classify_mask((const u8 *)&mask->_field, \ sizeof(mask->_field)); \
\
rc = efx_mae_match_check_cap_typ(supported_fields[MAE_FIELD_ ## _mcdi],\
typ); \ if (rc) \
NL_SET_ERR_MSG_FMT_MOD(extack, \ "No support for %s mask in field %s", \
mask_type_name(typ), #_field); \
rc; \
}) /* Booleans need special handling */ #define CHECK_BIT(_mcdi, _field) ({ \ enum mask_type typ = mask->_field ? MASK_ONES : MASK_ZEROES; \
\
rc = efx_mae_match_check_cap_typ(supported_fields[MAE_FIELD_ ## _mcdi],\
typ); \ if (rc) \
NL_SET_ERR_MSG_FMT_MOD(extack, \ "No support for %s mask in field %s", \
mask_type_name(typ), #_field); \
rc; \
})
/* Check for _PREFIX assumes big-endian, so we need to convert */
ingress_port_mask_type = classify_mask((const u8 *)&ingress_port, sizeof(ingress_port));
rc = efx_mae_match_check_cap_typ(supported_fields[MAE_FIELD_INGRESS_PORT],
ingress_port_mask_type); if (rc) {
NL_SET_ERR_MSG_FMT_MOD(extack, "No support for %s mask in field ingress_port",
mask_type_name(ingress_port_mask_type)); return rc;
} if (CHECK(ETHER_TYPE, eth_proto) ||
CHECK(VLAN0_TCI, vlan_tci[0]) ||
CHECK(VLAN0_PROTO, vlan_proto[0]) ||
CHECK(VLAN1_TCI, vlan_tci[1]) ||
CHECK(VLAN1_PROTO, vlan_proto[1]) ||
CHECK(ETH_SADDR, eth_saddr) ||
CHECK(ETH_DADDR, eth_daddr) ||
CHECK(IP_PROTO, ip_proto) ||
CHECK(IP_TOS, ip_tos) ||
CHECK(IP_TTL, ip_ttl) ||
CHECK(SRC_IP4, src_ip) ||
CHECK(DST_IP4, dst_ip) || #ifdef CONFIG_IPV6
CHECK(SRC_IP6, src_ip6) ||
CHECK(DST_IP6, dst_ip6) || #endif
CHECK(L4_SPORT, l4_sport) ||
CHECK(L4_DPORT, l4_dport) ||
CHECK(TCP_FLAGS, tcp_flags) ||
CHECK_BIT(TCP_SYN_FIN_RST, tcp_syn_fin_rst) ||
CHECK_BIT(IS_IP_FRAG, ip_frag) ||
CHECK_BIT(IP_FIRST_FRAG, ip_firstfrag) ||
CHECK_BIT(DO_CT, ct_state_trk) ||
CHECK_BIT(CT_HIT, ct_state_est) ||
CHECK(CT_MARK, ct_mark) ||
CHECK(CT_DOMAIN, ct_zone) ||
CHECK(RECIRC_ID, recirc_id)) return rc; /* Matches on outer fields are done in a separate hardware table, * the Outer Rule table. Thus the Action Rule merely does an * exact match on Outer Rule ID if any outer field matches are * present. The exception is the VNI/VSID (enc_keyid), which is * available to the Action Rule match iff the Outer Rule matched * (and thus identified the encap protocol to use to extract it).
*/ if (efx_tc_match_is_encap(mask)) {
rc = efx_mae_match_check_cap_typ(
supported_fields[MAE_FIELD_OUTER_RULE_ID],
MASK_ONES); if (rc) {
NL_SET_ERR_MSG_MOD(extack, "No support for encap rule ID matches"); return rc;
} if (CHECK(ENC_VNET_ID, enc_keyid)) return rc;
} elseif (mask->enc_keyid) {
NL_SET_ERR_MSG_MOD(extack, "Match on enc_keyid requires other encap fields"); return -EINVAL;
} return 0;
}
/* Checks for match fields not supported in LHS Outer Rules */ #define UNSUPPORTED(_field) ({ \ enum mask_type typ = classify_mask((const u8 *)&mask->_field, \ sizeof(mask->_field)); \
\ if (typ != MASK_ZEROES) { \
NL_SET_ERR_MSG_MOD(extack, "Unsupported match field "#_field);\
rc = -EOPNOTSUPP; \
} \
rc; \
}) #define UNSUPPORTED_BIT(_field) ({ \ if (mask->_field) { \
NL_SET_ERR_MSG_MOD(extack, "Unsupported match field "#_field);\
rc = -EOPNOTSUPP; \
} \
rc; \
})
/* LHS rules are (normally) inserted in the Outer Rule table, which means * they use ENC_ fields in hardware to match regular (not enc_) fields from * &struct efx_tc_match_fields.
*/ int efx_mae_match_check_caps_lhs(struct efx_nic *efx, conststruct efx_tc_match_fields *mask, struct netlink_ext_ack *extack)
{ const u8 *supported_fields = efx->tc->caps->outer_rule_fields;
__be32 ingress_port = cpu_to_be32(mask->ingress_port); enum mask_type ingress_port_mask_type; int rc;
/* Check for _PREFIX assumes big-endian, so we need to convert */
ingress_port_mask_type = classify_mask((const u8 *)&ingress_port, sizeof(ingress_port));
rc = efx_mae_match_check_cap_typ(supported_fields[MAE_FIELD_INGRESS_PORT],
ingress_port_mask_type); if (rc) {
NL_SET_ERR_MSG_FMT_MOD(extack, "No support for %s mask in field %s",
mask_type_name(ingress_port_mask_type), "ingress_port"); return rc;
} if (CHECK(ENC_ETHER_TYPE, eth_proto) ||
CHECK(ENC_VLAN0_TCI, vlan_tci[0]) ||
CHECK(ENC_VLAN0_PROTO, vlan_proto[0]) ||
CHECK(ENC_VLAN1_TCI, vlan_tci[1]) ||
CHECK(ENC_VLAN1_PROTO, vlan_proto[1]) ||
CHECK(ENC_ETH_SADDR, eth_saddr) ||
CHECK(ENC_ETH_DADDR, eth_daddr) ||
CHECK(ENC_IP_PROTO, ip_proto) ||
CHECK(ENC_IP_TOS, ip_tos) ||
CHECK(ENC_IP_TTL, ip_ttl) ||
CHECK_BIT(ENC_IP_FRAG, ip_frag) ||
UNSUPPORTED_BIT(ip_firstfrag) ||
CHECK(ENC_SRC_IP4, src_ip) ||
CHECK(ENC_DST_IP4, dst_ip) || #ifdef CONFIG_IPV6
CHECK(ENC_SRC_IP6, src_ip6) ||
CHECK(ENC_DST_IP6, dst_ip6) || #endif
CHECK(ENC_L4_SPORT, l4_sport) ||
CHECK(ENC_L4_DPORT, l4_dport) ||
UNSUPPORTED(tcp_flags) ||
CHECK_BIT(TCP_SYN_FIN_RST, tcp_syn_fin_rst)) return rc; if (efx_tc_match_is_encap(mask)) { /* can't happen; disallowed for local rules, translated * for foreign rules.
*/
NL_SET_ERR_MSG_MOD(extack, "Unexpected encap match in LHS rule"); return -EOPNOTSUPP;
} if (UNSUPPORTED(enc_keyid) || /* Can't filter on conntrack in LHS rules */
UNSUPPORTED_BIT(ct_state_trk) ||
UNSUPPORTED_BIT(ct_state_est) ||
UNSUPPORTED(ct_mark) ||
UNSUPPORTED(recirc_id)) return rc; return 0;
} #undef UNSUPPORTED #undef CHECK_BIT #undef CHECK
#define CHECK(_mcdi) ({ \
rc = efx_mae_match_check_cap_typ(supported_fields[MAE_FIELD_ ## _mcdi],\
MASK_ONES); \ if (rc) \
NL_SET_ERR_MSG_FMT_MOD(extack, \ "No support for field %s", #_mcdi); \
rc; \
}) /* Checks that the fields needed for encap-rule matches are supported by the * MAE. All the fields are exact-match, except possibly ENC_IP_TOS.
*/ int efx_mae_check_encap_match_caps(struct efx_nic *efx, bool ipv6,
u8 ip_tos_mask, __be16 udp_sport_mask, struct netlink_ext_ack *extack)
{
u8 *supported_fields = efx->tc->caps->outer_rule_fields; enum mask_type typ; int rc;
if (CHECK(ENC_ETHER_TYPE)) return rc; if (ipv6) { if (CHECK(ENC_SRC_IP6) ||
CHECK(ENC_DST_IP6)) return rc;
} else { if (CHECK(ENC_SRC_IP4) ||
CHECK(ENC_DST_IP4)) return rc;
} if (CHECK(ENC_L4_DPORT) ||
CHECK(ENC_IP_PROTO)) return rc;
typ = classify_mask((const u8 *)&udp_sport_mask, sizeof(udp_sport_mask));
rc = efx_mae_match_check_cap_typ(supported_fields[MAE_FIELD_ENC_L4_SPORT],
typ); if (rc) {
NL_SET_ERR_MSG_FMT_MOD(extack, "No support for %s mask in field %s",
mask_type_name(typ), "enc_src_port"); return rc;
}
typ = classify_mask(&ip_tos_mask, sizeof(ip_tos_mask));
rc = efx_mae_match_check_cap_typ(supported_fields[MAE_FIELD_ENC_IP_TOS],
typ); if (rc) {
NL_SET_ERR_MSG_FMT_MOD(extack, "No support for %s mask in field %s",
mask_type_name(typ), "enc_ip_tos"); return rc;
} return 0;
} #undef CHECK
int efx_mae_check_encap_type_supported(struct efx_nic *efx, enum efx_encap_type typ)
{ unsignedint bit;
switch (typ & EFX_ENCAP_TYPES_MASK) { case EFX_ENCAP_TYPE_VXLAN:
bit = MC_CMD_MAE_GET_CAPS_OUT_ENCAP_TYPE_VXLAN_LBN; break; case EFX_ENCAP_TYPE_GENEVE:
bit = MC_CMD_MAE_GET_CAPS_OUT_ENCAP_TYPE_GENEVE_LBN; break; default: return -EOPNOTSUPP;
} if (efx->tc->caps->encap_types & BIT(bit)) return 0; return -EOPNOTSUPP;
}
int efx_mae_allocate_counter(struct efx_nic *efx, struct efx_tc_counter *cnt)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_COUNTER_ALLOC_OUT_LEN(1));
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_COUNTER_ALLOC_V2_IN_LEN);
size_t outlen; int rc;
if (!cnt) return -EINVAL;
MCDI_SET_DWORD(inbuf, MAE_COUNTER_ALLOC_V2_IN_REQUESTED_COUNT, 1);
MCDI_SET_DWORD(inbuf, MAE_COUNTER_ALLOC_V2_IN_COUNTER_TYPE, cnt->type);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_COUNTER_ALLOC, inbuf, sizeof(inbuf),
outbuf, sizeof(outbuf), &outlen); if (rc) return rc; /* pcol says this can't happen, since count is 1 */ if (outlen < sizeof(outbuf)) return -EIO;
cnt->fw_id = MCDI_DWORD(outbuf, MAE_COUNTER_ALLOC_OUT_COUNTER_ID);
cnt->gen = MCDI_DWORD(outbuf, MAE_COUNTER_ALLOC_OUT_GENERATION_COUNT); return 0;
}
int efx_mae_free_counter(struct efx_nic *efx, struct efx_tc_counter *cnt)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_COUNTER_FREE_OUT_LEN(1));
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_COUNTER_FREE_V2_IN_LEN);
size_t outlen; int rc;
MCDI_SET_DWORD(inbuf, MAE_COUNTER_FREE_V2_IN_COUNTER_ID_COUNT, 1);
MCDI_SET_DWORD(inbuf, MAE_COUNTER_FREE_V2_IN_FREE_COUNTER_ID, cnt->fw_id);
MCDI_SET_DWORD(inbuf, MAE_COUNTER_FREE_V2_IN_COUNTER_TYPE, cnt->type);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_COUNTER_FREE, inbuf, sizeof(inbuf),
outbuf, sizeof(outbuf), &outlen); if (rc) return rc; /* pcol says this can't happen, since count is 1 */ if (outlen < sizeof(outbuf)) return -EIO; /* FW freed a different ID than we asked for, should also never happen. * Warn because it means we've now got a different idea to the FW of * what counters exist, which could cause mayhem later.
*/ if (WARN_ON(MCDI_DWORD(outbuf, MAE_COUNTER_FREE_OUT_FREED_COUNTER_ID) !=
cnt->fw_id)) return -EIO; return 0;
}
staticint efx_mae_encap_type_to_mae_type(enum efx_encap_type type)
{ switch (type & EFX_ENCAP_TYPES_MASK) { case EFX_ENCAP_TYPE_NONE: return MAE_MCDI_ENCAP_TYPE_NONE; case EFX_ENCAP_TYPE_VXLAN: return MAE_MCDI_ENCAP_TYPE_VXLAN; case EFX_ENCAP_TYPE_GENEVE: return MAE_MCDI_ENCAP_TYPE_GENEVE; default: return -EOPNOTSUPP;
}
}
int efx_mae_allocate_encap_md(struct efx_nic *efx, struct efx_tc_encap_action *encap)
{
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_ENCAP_HEADER_ALLOC_IN_LEN(EFX_TC_MAX_ENCAP_HDR));
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_LEN);
size_t inlen, outlen; int rc;
int efx_mae_free_encap_md(struct efx_nic *efx, struct efx_tc_encap_action *encap)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_ENCAP_HEADER_FREE_OUT_LEN(1));
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_ENCAP_HEADER_FREE_IN_LEN(1));
size_t outlen; int rc;
MCDI_SET_DWORD(inbuf, MAE_ENCAP_HEADER_FREE_IN_EH_ID, encap->fw_id);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_ENCAP_HEADER_FREE, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); if (rc) return rc; if (outlen < sizeof(outbuf)) return -EIO; /* FW freed a different ID than we asked for, should also never happen. * Warn because it means we've now got a different idea to the FW of * what encap_mds exist, which could cause mayhem later.
*/ if (WARN_ON(MCDI_DWORD(outbuf, MAE_ENCAP_HEADER_FREE_OUT_FREED_EH_ID) != encap->fw_id)) return -EIO; /* We're probably about to free @encap, but let's just make sure its * fw_id is blatted so that it won't look valid if it leaks out.
*/
encap->fw_id = MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_NULL; return 0;
}
if (!outbuf) return -ENOMEM; do {
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_MPORT_READ_JOURNAL, inbuf, sizeof(inbuf), outbuf,
MCDI_MPORT_JOURNAL_LEN, &outlen); if (rc) goto fail; if (outlen < MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_MPORT_DESC_DATA_OFST) {
rc = -EIO; goto fail;
}
count = MCDI_DWORD(outbuf, MAE_MPORT_READ_JOURNAL_OUT_MPORT_DESC_COUNT); if (!count) continue; /* not break; we want to look at MORE flag */
stride = MCDI_DWORD(outbuf, MAE_MPORT_READ_JOURNAL_OUT_SIZEOF_MPORT_DESC); if (stride < MAE_MPORT_DESC_LEN) {
rc = -EIO; goto fail;
} if (outlen < MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_LEN(count * stride)) {
rc = -EIO; goto fail;
}
for (i = 0; i < count; i++) { struct mae_mport_desc *d;
d = kzalloc(sizeof(*d), GFP_KERNEL); if (!d) {
rc = -ENOMEM; goto fail;
}
desc = (efx_dword_t *)
_MCDI_PTR(outbuf, MC_CMD_MAE_MPORT_READ_JOURNAL_OUT_MPORT_DESC_DATA_OFST +
i * stride);
d->mport_id = MCDI_STRUCT_DWORD(desc, MAE_MPORT_DESC_MPORT_ID);
d->flags = MCDI_STRUCT_DWORD(desc, MAE_MPORT_DESC_FLAGS);
d->caller_flags = MCDI_STRUCT_DWORD(desc,
MAE_MPORT_DESC_CALLER_FLAGS);
d->mport_type = MCDI_STRUCT_DWORD(desc,
MAE_MPORT_DESC_MPORT_TYPE); switch (d->mport_type) { case MAE_MPORT_DESC_MPORT_TYPE_NET_PORT:
d->port_idx = MCDI_STRUCT_DWORD(desc,
MAE_MPORT_DESC_NET_PORT_IDX); break; case MAE_MPORT_DESC_MPORT_TYPE_ALIAS:
d->alias_mport_id = MCDI_STRUCT_DWORD(desc,
MAE_MPORT_DESC_ALIAS_DELIVER_MPORT_ID); break; case MAE_MPORT_DESC_MPORT_TYPE_VNIC:
d->vnic_client_type = MCDI_STRUCT_DWORD(desc,
MAE_MPORT_DESC_VNIC_CLIENT_TYPE);
d->interface_idx = MCDI_STRUCT_DWORD(desc,
MAE_MPORT_DESC_VNIC_FUNCTION_INTERFACE);
d->pf_idx = MCDI_STRUCT_WORD(desc,
MAE_MPORT_DESC_VNIC_FUNCTION_PF_IDX);
d->vf_idx = MCDI_STRUCT_WORD(desc,
MAE_MPORT_DESC_VNIC_FUNCTION_VF_IDX); break; default: /* Unknown mport_type, just accept it */ break;
}
rc = efx_mae_process_mport(efx, d); /* Any failure will be due to memory allocation faiure, * so there is no point to try subsequent entries.
*/ if (rc) goto fail;
}
} while (MCDI_FIELD(outbuf, MAE_MPORT_READ_JOURNAL_OUT, MORE) &&
!WARN_ON(!count));
fail:
kfree(outbuf); return rc;
}
/** * efx_mae_allocate_pedit_mac() - allocate pedit MAC address in HW. * @efx: NIC we're installing a pedit MAC address on * @ped: pedit MAC action to be installed * * Attempts to install @ped in HW and populates its id with an index of this * entry in the firmware MAC address table on success. * * Return: negative value on error, 0 in success.
*/ int efx_mae_allocate_pedit_mac(struct efx_nic *efx, struct efx_tc_mac_pedit_action *ped)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_LEN);
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_MAC_ADDR_ALLOC_IN_LEN);
size_t outlen; int rc;
/** * efx_mae_free_pedit_mac() - free pedit MAC address in HW. * @efx: NIC we're installing a pedit MAC address on * @ped: pedit MAC action that needs to be freed * * Frees @ped in HW, check that firmware did not free a different one and clears * the id (which denotes the index of the entry in the MAC address table).
*/ void efx_mae_free_pedit_mac(struct efx_nic *efx, struct efx_tc_mac_pedit_action *ped)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_MAC_ADDR_FREE_OUT_LEN(1));
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_MAC_ADDR_FREE_IN_LEN(1));
size_t outlen; int rc;
MCDI_SET_DWORD(inbuf, MAE_MAC_ADDR_FREE_IN_MAC_ID, ped->fw_id);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_MAC_ADDR_FREE, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); if (rc || outlen < sizeof(outbuf)) return; /* FW freed a different ID than we asked for, should also never happen. * Warn because it means we've now got a different idea to the FW of * what MAC addresses exist, which could cause mayhem later.
*/ if (WARN_ON(MCDI_DWORD(outbuf, MAE_MAC_ADDR_FREE_OUT_FREED_MAC_ID) != ped->fw_id)) return; /* We're probably about to free @ped, but let's just make sure its * fw_id is blatted so that it won't look valid if it leaks out.
*/
ped->fw_id = MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL;
}
int efx_mae_alloc_action_set(struct efx_nic *efx, struct efx_tc_action_set *act)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_ACTION_SET_ALLOC_OUT_LEN);
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_ACTION_SET_ALLOC_IN_LEN);
size_t outlen; int rc;
if (act->src_mac)
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_SRC_MAC_ID,
act->src_mac->fw_id); else
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_SRC_MAC_ID,
MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
if (act->dst_mac)
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID,
act->dst_mac->fw_id); else
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_DST_MAC_ID,
MC_CMD_MAE_MAC_ADDR_ALLOC_OUT_MAC_ID_NULL);
if (act->count && !WARN_ON(!act->count->cnt))
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_COUNTER_ID,
act->count->cnt->fw_id); else
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_COUNTER_ID,
MC_CMD_MAE_COUNTER_ALLOC_OUT_COUNTER_ID_NULL);
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_COUNTER_LIST_ID,
MC_CMD_MAE_COUNTER_LIST_ALLOC_OUT_COUNTER_LIST_ID_NULL); if (act->vlan_push) {
MCDI_SET_WORD_BE(inbuf, MAE_ACTION_SET_ALLOC_IN_VLAN0_TCI_BE,
act->vlan_tci[0]);
MCDI_SET_WORD_BE(inbuf, MAE_ACTION_SET_ALLOC_IN_VLAN0_PROTO_BE,
act->vlan_proto[0]);
} if (act->vlan_push >= 2) {
MCDI_SET_WORD_BE(inbuf, MAE_ACTION_SET_ALLOC_IN_VLAN1_TCI_BE,
act->vlan_tci[1]);
MCDI_SET_WORD_BE(inbuf, MAE_ACTION_SET_ALLOC_IN_VLAN1_PROTO_BE,
act->vlan_proto[1]);
} if (act->encap_md)
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID,
act->encap_md->fw_id); else
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_ENCAP_HEADER_ID,
MC_CMD_MAE_ENCAP_HEADER_ALLOC_OUT_ENCAP_HEADER_ID_NULL); if (act->deliver)
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_ALLOC_IN_DELIVER,
act->dest_mport);
BUILD_BUG_ON(MAE_MPORT_SELECTOR_NULL);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_ACTION_SET_ALLOC, inbuf, sizeof(inbuf),
outbuf, sizeof(outbuf), &outlen); if (rc) return rc; if (outlen < sizeof(outbuf)) return -EIO;
act->fw_id = MCDI_DWORD(outbuf, MAE_ACTION_SET_ALLOC_OUT_AS_ID); /* We rely on the high bit of AS IDs always being clear. * The firmware API guarantees this, but let's check it ourselves.
*/ if (WARN_ON_ONCE(efx_mae_asl_id(act->fw_id))) {
efx_mae_free_action_set(efx, act->fw_id); return -EIO;
} return 0;
}
int efx_mae_free_action_set(struct efx_nic *efx, u32 fw_id)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_ACTION_SET_FREE_OUT_LEN(1));
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_ACTION_SET_FREE_IN_LEN(1));
size_t outlen; int rc;
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_FREE_IN_AS_ID, fw_id);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_ACTION_SET_FREE, inbuf, sizeof(inbuf),
outbuf, sizeof(outbuf), &outlen); if (rc) return rc; if (outlen < sizeof(outbuf)) return -EIO; /* FW freed a different ID than we asked for, should never happen. * Warn because it means we've now got a different idea to the FW of * what action-sets exist, which could cause mayhem later.
*/ if (WARN_ON(MCDI_DWORD(outbuf, MAE_ACTION_SET_FREE_OUT_FREED_AS_ID) != fw_id)) return -EIO; return 0;
}
int efx_mae_alloc_action_set_list(struct efx_nic *efx, struct efx_tc_action_set_list *acts)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_ACTION_SET_LIST_ALLOC_OUT_LEN); struct efx_tc_action_set *act;
size_t inlen, outlen, i = 0;
efx_dword_t *inbuf; int rc;
list_for_each_entry(act, &acts->list, list)
i++; if (i == 0) return -EINVAL; if (i == 1) { /* Don't wrap an ASL around a single AS, just use the AS_ID * directly. ASLs are a more limited resource.
*/
act = list_first_entry(&acts->list, struct efx_tc_action_set, list);
acts->fw_id = act->fw_id; return 0;
} if (i > MC_CMD_MAE_ACTION_SET_LIST_ALLOC_IN_AS_IDS_MAXNUM_MCDI2) return -EOPNOTSUPP; /* Too many actions */
inlen = MC_CMD_MAE_ACTION_SET_LIST_ALLOC_IN_LEN(i);
inbuf = kzalloc(inlen, GFP_KERNEL); if (!inbuf) return -ENOMEM;
i = 0;
list_for_each_entry(act, &acts->list, list) {
MCDI_SET_ARRAY_DWORD(inbuf, MAE_ACTION_SET_LIST_ALLOC_IN_AS_IDS,
i, act->fw_id);
i++;
}
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_LIST_ALLOC_IN_COUNT, i);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_ACTION_SET_LIST_ALLOC, inbuf, inlen,
outbuf, sizeof(outbuf), &outlen); if (rc) goto out_free; if (outlen < sizeof(outbuf)) {
rc = -EIO; goto out_free;
}
acts->fw_id = MCDI_DWORD(outbuf, MAE_ACTION_SET_LIST_ALLOC_OUT_ASL_ID); /* We rely on the high bit of ASL IDs always being set. * The firmware API guarantees this, but let's check it ourselves.
*/ if (WARN_ON_ONCE(!efx_mae_asl_id(acts->fw_id))) {
efx_mae_free_action_set_list(efx, acts);
rc = -EIO;
}
out_free:
kfree(inbuf); return rc;
}
int efx_mae_free_action_set_list(struct efx_nic *efx, struct efx_tc_action_set_list *acts)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_ACTION_SET_LIST_FREE_OUT_LEN(1));
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_ACTION_SET_LIST_FREE_IN_LEN(1));
size_t outlen; int rc;
/* If this is just an AS_ID with no ASL wrapper, then there is * nothing for us to free. (The AS will be freed later.)
*/ if (efx_mae_asl_id(acts->fw_id)) {
MCDI_SET_DWORD(inbuf, MAE_ACTION_SET_LIST_FREE_IN_ASL_ID,
acts->fw_id);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_ACTION_SET_LIST_FREE, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); if (rc) return rc; if (outlen < sizeof(outbuf)) return -EIO; /* FW freed a different ID than we asked for, should never happen. * Warn because it means we've now got a different idea to the FW of * what action-set-lists exist, which could cause mayhem later.
*/ if (WARN_ON(MCDI_DWORD(outbuf, MAE_ACTION_SET_LIST_FREE_OUT_FREED_ASL_ID) != acts->fw_id)) return -EIO;
} /* We're probably about to free @acts, but let's just make sure its * fw_id is blatted so that it won't look valid if it leaks out.
*/
acts->fw_id = MC_CMD_MAE_ACTION_SET_LIST_ALLOC_OUT_ACTION_SET_LIST_ID_NULL; return 0;
}
int efx_mae_register_encap_match(struct efx_nic *efx, struct efx_tc_encap_match *encap)
{
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_OUTER_RULE_INSERT_IN_LEN(MAE_ENC_FIELD_PAIRS_LEN));
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_OUTER_RULE_INSERT_OUT_LEN);
MCDI_DECLARE_STRUCT_PTR(match_crit);
size_t outlen; int rc;
rc = efx_mae_encap_type_to_mae_type(encap->tun_type); if (rc < 0) return rc;
match_crit = _MCDI_DWORD(inbuf, MAE_OUTER_RULE_INSERT_IN_FIELD_MATCH_CRITERIA); /* The struct contains IP src and dst, and udp dport. * So we actually need to filter on IP src and dst, L4 dport, and * ipproto == udp.
*/
MCDI_SET_DWORD(inbuf, MAE_OUTER_RULE_INSERT_IN_ENCAP_TYPE, rc); #ifdef CONFIG_IPV6 if (encap->src_ip | encap->dst_ip) { #endif
MCDI_STRUCT_SET_DWORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_SRC_IP4_BE,
encap->src_ip);
MCDI_STRUCT_SET_DWORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_SRC_IP4_BE_MASK,
~(__be32)0);
MCDI_STRUCT_SET_DWORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_DST_IP4_BE,
encap->dst_ip);
MCDI_STRUCT_SET_DWORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_DST_IP4_BE_MASK,
~(__be32)0);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_ETHER_TYPE_BE,
htons(ETH_P_IP)); #ifdef CONFIG_IPV6
} else {
memcpy(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_SRC_IP6_BE),
&encap->src_ip6, sizeof(encap->src_ip6));
memset(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_SRC_IP6_BE_MASK),
0xff, sizeof(encap->src_ip6));
memcpy(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_DST_IP6_BE),
&encap->dst_ip6, sizeof(encap->dst_ip6));
memset(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_DST_IP6_BE_MASK),
0xff, sizeof(encap->dst_ip6));
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_ETHER_TYPE_BE,
htons(ETH_P_IPV6));
} #endif
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_ETHER_TYPE_BE_MASK,
~(__be16)0);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_L4_DPORT_BE,
encap->udp_dport);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_L4_DPORT_BE_MASK,
~(__be16)0);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_L4_DPORT_BE,
encap->udp_sport);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_L4_DPORT_BE_MASK,
encap->udp_sport_mask);
MCDI_STRUCT_SET_BYTE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_IP_PROTO, IPPROTO_UDP);
MCDI_STRUCT_SET_BYTE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_IP_PROTO_MASK, ~0);
MCDI_STRUCT_SET_BYTE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_IP_TOS,
encap->ip_tos);
MCDI_STRUCT_SET_BYTE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_IP_TOS_MASK,
encap->ip_tos_mask);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_OUTER_RULE_INSERT, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); if (rc) return rc; if (outlen < sizeof(outbuf)) return -EIO;
encap->fw_id = MCDI_DWORD(outbuf, MAE_OUTER_RULE_INSERT_OUT_OR_ID); return 0;
}
int efx_mae_unregister_encap_match(struct efx_nic *efx, struct efx_tc_encap_match *encap)
{
MCDI_DECLARE_BUF(outbuf, MC_CMD_MAE_OUTER_RULE_REMOVE_OUT_LEN(1));
MCDI_DECLARE_BUF(inbuf, MC_CMD_MAE_OUTER_RULE_REMOVE_IN_LEN(1));
size_t outlen; int rc;
MCDI_SET_DWORD(inbuf, MAE_OUTER_RULE_REMOVE_IN_OR_ID, encap->fw_id);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_OUTER_RULE_REMOVE, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); if (rc) return rc; if (outlen < sizeof(outbuf)) return -EIO; /* FW freed a different ID than we asked for, should also never happen. * Warn because it means we've now got a different idea to the FW of * what encap_mds exist, which could cause mayhem later.
*/ if (WARN_ON(MCDI_DWORD(outbuf, MAE_OUTER_RULE_REMOVE_OUT_REMOVED_OR_ID) != encap->fw_id)) return -EIO; /* We're probably about to free @encap, but let's just make sure its * fw_id is blatted so that it won't look valid if it leaks out.
*/
encap->fw_id = MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OUTER_RULE_ID_NULL; return 0;
}
staticint efx_mae_populate_lhs_match_criteria(MCDI_DECLARE_STRUCT_PTR(match_crit), conststruct efx_tc_match *match)
{ if (match->mask.ingress_port) { if (~match->mask.ingress_port) return -EOPNOTSUPP;
MCDI_STRUCT_SET_DWORD(match_crit,
MAE_ENC_FIELD_PAIRS_INGRESS_MPORT_SELECTOR,
match->value.ingress_port);
}
MCDI_STRUCT_SET_DWORD(match_crit, MAE_ENC_FIELD_PAIRS_INGRESS_MPORT_SELECTOR_MASK,
match->mask.ingress_port);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_ETHER_TYPE_BE,
match->value.eth_proto);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_ETHER_TYPE_BE_MASK,
match->mask.eth_proto);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_VLAN0_TCI_BE,
match->value.vlan_tci[0]);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_VLAN0_TCI_BE_MASK,
match->mask.vlan_tci[0]);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_VLAN0_PROTO_BE,
match->value.vlan_proto[0]);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_VLAN0_PROTO_BE_MASK,
match->mask.vlan_proto[0]);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_VLAN1_TCI_BE,
match->value.vlan_tci[1]);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_VLAN1_TCI_BE_MASK,
match->mask.vlan_tci[1]);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_VLAN1_PROTO_BE,
match->value.vlan_proto[1]);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_VLAN1_PROTO_BE_MASK,
match->mask.vlan_proto[1]);
memcpy(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_ETH_SADDR_BE),
match->value.eth_saddr, ETH_ALEN);
memcpy(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_ETH_SADDR_BE_MASK),
match->mask.eth_saddr, ETH_ALEN);
memcpy(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_ETH_DADDR_BE),
match->value.eth_daddr, ETH_ALEN);
memcpy(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_ETH_DADDR_BE_MASK),
match->mask.eth_daddr, ETH_ALEN);
MCDI_STRUCT_SET_BYTE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_IP_PROTO,
match->value.ip_proto);
MCDI_STRUCT_SET_BYTE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_IP_PROTO_MASK,
match->mask.ip_proto);
MCDI_STRUCT_SET_BYTE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_IP_TOS,
match->value.ip_tos);
MCDI_STRUCT_SET_BYTE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_IP_TOS_MASK,
match->mask.ip_tos);
MCDI_STRUCT_SET_BYTE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_IP_TTL,
match->value.ip_ttl);
MCDI_STRUCT_SET_BYTE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_IP_TTL_MASK,
match->mask.ip_ttl);
MCDI_STRUCT_POPULATE_BYTE_1(match_crit,
MAE_ENC_FIELD_PAIRS_ENC_VLAN_FLAGS,
MAE_ENC_FIELD_PAIRS_ENC_IP_FRAG,
match->value.ip_frag);
MCDI_STRUCT_POPULATE_BYTE_1(match_crit,
MAE_ENC_FIELD_PAIRS_ENC_VLAN_FLAGS_MASK,
MAE_ENC_FIELD_PAIRS_ENC_IP_FRAG_MASK,
match->mask.ip_frag);
MCDI_STRUCT_SET_DWORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_SRC_IP4_BE,
match->value.src_ip);
MCDI_STRUCT_SET_DWORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_SRC_IP4_BE_MASK,
match->mask.src_ip);
MCDI_STRUCT_SET_DWORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_DST_IP4_BE,
match->value.dst_ip);
MCDI_STRUCT_SET_DWORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_DST_IP4_BE_MASK,
match->mask.dst_ip); #ifdef CONFIG_IPV6
memcpy(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_SRC_IP6_BE),
&match->value.src_ip6, sizeof(struct in6_addr));
memcpy(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_SRC_IP6_BE_MASK),
&match->mask.src_ip6, sizeof(struct in6_addr));
memcpy(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_DST_IP6_BE),
&match->value.dst_ip6, sizeof(struct in6_addr));
memcpy(MCDI_STRUCT_PTR(match_crit, MAE_ENC_FIELD_PAIRS_ENC_DST_IP6_BE_MASK),
&match->mask.dst_ip6, sizeof(struct in6_addr)); #endif
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_L4_SPORT_BE,
match->value.l4_sport);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_L4_SPORT_BE_MASK,
match->mask.l4_sport);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_L4_DPORT_BE,
match->value.l4_dport);
MCDI_STRUCT_SET_WORD_BE(match_crit, MAE_ENC_FIELD_PAIRS_ENC_L4_DPORT_BE_MASK,
match->mask.l4_dport); /* No enc-keys in LHS rules. Caps check should have caught this; any * enc-keys from an fLHS should have been translated to regular keys * and any EM should be a pseudo (we're an OR so can't have a direct * EM with another OR).
*/ if (WARN_ON_ONCE(match->encap && !match->encap->type)) return -EOPNOTSUPP; if (WARN_ON_ONCE(match->mask.enc_src_ip)) return -EOPNOTSUPP; if (WARN_ON_ONCE(match->mask.enc_dst_ip)) return -EOPNOTSUPP; #ifdef CONFIG_IPV6 if (WARN_ON_ONCE(!ipv6_addr_any(&match->mask.enc_src_ip6))) return -EOPNOTSUPP; if (WARN_ON_ONCE(!ipv6_addr_any(&match->mask.enc_dst_ip6))) return -EOPNOTSUPP; #endif if (WARN_ON_ONCE(match->mask.enc_ip_tos)) return -EOPNOTSUPP; if (WARN_ON_ONCE(match->mask.enc_ip_ttl)) return -EOPNOTSUPP; if (WARN_ON_ONCE(match->mask.enc_sport)) return -EOPNOTSUPP; if (WARN_ON_ONCE(match->mask.enc_dport)) return -EOPNOTSUPP; if (WARN_ON_ONCE(match->mask.enc_keyid)) return -EOPNOTSUPP; return 0;
}
MCDI_SET_DWORD(inbuf, MAE_OUTER_RULE_REMOVE_IN_OR_ID, rule->fw_id);
rc = efx_mcdi_rpc(efx, MC_CMD_MAE_OUTER_RULE_REMOVE, inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); if (rc) return rc; if (outlen < sizeof(outbuf)) return -EIO; /* FW freed a different ID than we asked for, should also never happen. * Warn because it means we've now got a different idea to the FW of * what encap_mds exist, which could cause mayhem later.
*/ if (WARN_ON(MCDI_DWORD(outbuf, MAE_OUTER_RULE_REMOVE_OUT_REMOVED_OR_ID) != rule->fw_id)) return -EIO; /* We're probably about to free @rule, but let's just make sure its * fw_id is blatted so that it won't look valid if it leaks out.
*/
rule->fw_id = MC_CMD_MAE_OUTER_RULE_INSERT_OUT_OUTER_RULE_ID_NULL; return 0;
}
int efx_mae_remove_lhs_rule(struct efx_nic *efx, struct efx_tc_lhs_rule *rule)
{ if (rule->is_ar) return efx_mae_delete_rule(efx, rule->fw_id); return efx_mae_remove_lhs_outer_rule(efx, rule);
}
/* Populating is done by taking each byte of @value in turn and storing * it in the appropriate bits of @row. @value must be big-endian; we * convert it to little-endianness as we go.
*/ staticint efx_mae_table_populate(struct efx_tc_table_field_fmt field,
__le32 *row, size_t row_bits, void *value, size_t value_size)
{ unsignedint i;
/* For now only scheme 0 is supported for any field, so we check here * (rather than, say, in calling code, which knows the semantics and * could in principle encode for other schemes).
*/ if (field.scheme) return -EOPNOTSUPP; if (DIV_ROUND_UP(field.width, 8) != value_size) return -EINVAL; if (field.lbn + field.width > row_bits) return -EINVAL; for (i = 0; i < value_size; i++) { unsignedint bn = field.lbn + i * 8; unsignedint wn = bn / 32;
u64 v;
v = ((u8 *)value)[value_size - i - 1];
v <<= (bn % 32);
row[wn] |= cpu_to_le32(v & 0xffffffff); if (wn * 32 < row_bits)
row[wn + 1] |= cpu_to_le32(v >> 32);
} return 0;
}
staticint efx_mae_table_populate_bool(struct efx_tc_table_field_fmt field,
__le32 *row, size_t row_bits, bool value)
{
u8 v = value ? 1 : 0;
staticint efx_mae_table_populate_ipv4(struct efx_tc_table_field_fmt field,
__le32 *row, size_t row_bits, __be32 value)
{ /* IPv4 is placed in the first 4 bytes of an IPv6-sized field */ struct in6_addr v = {};
/* We adjust value_size here since just 3 bytes will be copied, and * the pointer to the value is set discarding the first byte which is * the most significant byte for a big-endian 4-bytes value.
*/ return efx_mae_table_populate(field, row, row_bits, ((void *)&v) + 1, sizeof(v) - 1);
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.23Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.