// SPDX-License-Identifier: GPL-2.0-only /**************************************************************************** * Driver for Solarflare network controllers and boards * Copyright 2022 Advanced Micro Devices, 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.
*/
WARN_ON(!list_empty(&cnt->users)); /* We'd like to synchronize_rcu() here, but unfortunately we aren't * removing the element from the hashtable (it's not clear that's a * safe thing to do in an rhashtable_free_and_destroy free_fn), so * threads could still be obtaining new pointers to *cnt if they can * race against this function at all.
*/
flush_work(&cnt->work);
EFX_WARN_ON_PARANOID(spin_is_locked(&cnt->lock));
kfree(cnt);
}
/* Only call this in init failure teardown. * Normal exit should fini instead as there may be entries in the table.
*/ void efx_tc_destroy_counters(struct efx_nic *efx)
{
rhashtable_destroy(&efx->tc->counter_ht);
rhashtable_destroy(&efx->tc->counter_id_ht);
}
list_for_each_entry(act, &cnt->users, count_user) {
encap = act->encap_md; if (!encap) continue; if (!encap->neigh) /* can't happen */ continue; if (time_after_eq(encap->neigh->used, touched)) continue;
encap->neigh->used = touched; /* We have passed traffic using this ARP entry, so * indicate to the ARP cache that it's still active
*/ if (encap->neigh->dst_ip)
n = neigh_lookup(&arp_tbl, &encap->neigh->dst_ip,
encap->neigh->egdev); else #if IS_ENABLED(CONFIG_IPV6)
n = neigh_lookup(ipv6_stub->nd_tbl,
&encap->neigh->dst_ip6,
encap->neigh->egdev); #else
n = NULL; #endif if (!n) continue;
rc = efx_mae_allocate_counter(efx, cnt); if (rc) goto fail1;
INIT_LIST_HEAD(&cnt->users);
rc = rhashtable_insert_fast(&efx->tc->counter_ht, &cnt->linkage,
efx_tc_counter_ht_params); if (rc) goto fail2; return cnt;
fail2: /* If we get here, it implies that we couldn't insert into the table, * which in turn probably means that the fw_id was already taken. * In that case, it's unclear whether we really 'own' the fw_id; but * the firmware seemed to think we did, so it's proper to free it.
*/
rc2 = efx_mae_free_counter(efx, cnt); if (rc2)
netif_warn(efx, hw, efx->net_dev, "Failed to free MAE counter %u, rc %d\n",
cnt->fw_id, rc2);
fail1:
kfree(cnt); return ERR_PTR(rc > 0 ? -EIO : rc);
}
void efx_tc_flower_release_counter(struct efx_nic *efx, struct efx_tc_counter *cnt)
{ int rc;
rhashtable_remove_fast(&efx->tc->counter_ht, &cnt->linkage,
efx_tc_counter_ht_params);
rc = efx_mae_free_counter(efx, cnt); if (rc)
netif_warn(efx, hw, efx->net_dev, "Failed to free MAE counter %u, rc %d\n",
cnt->fw_id, rc);
WARN_ON(!list_empty(&cnt->users)); /* This doesn't protect counter updates coming in arbitrarily long * after we deleted the counter. The RCU just ensures that we won't * free the counter while another thread has a pointer to it. * Ensuring we don't update the wrong counter if the ID gets re-used * is handled by the generation count.
*/
synchronize_rcu();
flush_work(&cnt->work);
EFX_WARN_ON_PARANOID(spin_is_locked(&cnt->lock));
kfree(cnt);
}
rcu_read_lock(); /* Protect against deletion of 'cnt' */
cnt = efx_tc_flower_find_counter_by_fw_id(efx, counter_type, counter_idx); if (!cnt) { /* This can legitimately happen when a counter is removed, * with updates for the counter still in-flight; however this * should be an infrequent occurrence.
*/ if (net_ratelimit())
netif_dbg(efx, drv, efx->net_dev, "Got update for unwanted MAE counter %u type %u\n",
counter_idx, counter_type); goto out;
}
spin_lock_bh(&cnt->lock); if ((s32)mark - (s32)cnt->gen < 0) { /* This counter update packet is from before the counter was * allocated; thus it must be for a previous counter with * the same ID that has since been freed, and it should be * ignored.
*/
} else { /* Update latest seen generation count. This ensures that * even a long-lived counter won't start getting ignored if * the generation count wraps around, unless it somehow * manages to go 1<<31 generations without an update.
*/
cnt->gen = mark; /* update counter values */
cnt->packets += packets;
cnt->bytes += bytes;
cnt->touched = jiffies;
}
spin_unlock_bh(&cnt->lock);
schedule_work(&cnt->work);
out:
rcu_read_unlock();
}
ident = TCV2_HDR_BYTE(data, IDENTIFIER); switch (ident) { case ERF_SC_PACKETISER_HEADER_IDENTIFIER_AR:
type = EFX_TC_COUNTER_TYPE_AR; break; case ERF_SC_PACKETISER_HEADER_IDENTIFIER_CT:
type = EFX_TC_COUNTER_TYPE_CT; break; case ERF_SC_PACKETISER_HEADER_IDENTIFIER_OR:
type = EFX_TC_COUNTER_TYPE_OR; break; default: if (net_ratelimit())
netif_err(efx, drv, efx->net_dev, "ignored v2 MAE counter packet (bad identifier %u" "), counters may be inaccurate\n", ident); return EFX_TC_COUNTER_TYPE_MAX;
}
header_offset = TCV2_HDR_BYTE(data, HEADER_OFFSET); /* mae_counter_format.h implies that this offset is fixed, since it * carries on with SOP-based LBNs for the fields in this header
*/ if (header_offset != ERF_SC_PACKETISER_HEADER_HEADER_OFFSET_DEFAULT) { if (net_ratelimit())
netif_err(efx, drv, efx->net_dev, "choked on v2 MAE counter packet (bad header_offset %u" "), counters may be inaccurate\n", header_offset); return EFX_TC_COUNTER_TYPE_MAX;
}
payload_offset = TCV2_HDR_BYTE(data, PAYLOAD_OFFSET);
n_counters = le16_to_cpu(TCV2_HDR_WORD(data, COUNT));
for (i = 0; i < n_counters; i++) { constvoid *counter_idx_p, *packet_count_p, *byte_count_p;
u64 packet_count, byte_count;
u32 counter_idx;
/* 24-bit field with 32-bit alignment */
counter_idx_p = TCV2_PKT_PTR(data, payload_offset, i, COUNTER_INDEX);
BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_COUNTER_INDEX_WIDTH != 24);
BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_COUNTER_INDEX_LBN & 31);
counter_idx = le32_to_cpu(*(const __le32 *)counter_idx_p) & 0xffffff; /* 48-bit field with 16-bit alignment */
packet_count_p = TCV2_PKT_PTR(data, payload_offset, i, PACKET_COUNT);
BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_PACKET_COUNT_WIDTH != 48);
BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_PACKET_COUNT_LBN & 15);
packet_count = efx_tc_read48((const __le16 *)packet_count_p); /* 48-bit field with 16-bit alignment */
byte_count_p = TCV2_PKT_PTR(data, payload_offset, i, BYTE_COUNT);
BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_BYTE_COUNT_WIDTH != 48);
BUILD_BUG_ON(ERF_SC_PACKETISER_PAYLOAD_BYTE_COUNT_LBN & 15);
byte_count = efx_tc_read48((const __le16 *)byte_count_p);
if (type == EFX_TC_COUNTER_TYPE_CT) { /* CT counters are 1-bit saturating counters to update * the lastuse time in CT stats. A received CT counter * should have packet counter to 0 and only LSB bit on * in byte counter.
*/ if (packet_count || byte_count != 1)
netdev_warn_once(efx->net_dev, "CT counter with inconsistent state (%llu, %llu)\n",
packet_count, byte_count); /* Do not increment the driver's byte counter */
byte_count = 0;
}
/* We always swallow the packet, whether successful or not, since it's not * a network packet and shouldn't ever be forwarded to the stack. * @mark is the generation count for counter allocations.
*/ staticbool efx_tc_rx(struct efx_rx_queue *rx_queue, u32 mark)
{ struct efx_channel *channel = efx_rx_queue_channel(rx_queue); struct efx_rx_buffer *rx_buf = efx_rx_buffer(rx_queue,
channel->rx_pkt_index); const u8 *data = efx_rx_buf_va(rx_buf); struct efx_nic *efx = rx_queue->efx; enum efx_tc_counter_type type;
u8 version;
/* version is always first byte of packet */
version = *data; switch (version) { case 1:
type = EFX_TC_COUNTER_TYPE_AR;
efx_tc_rx_version_1(efx, data, mark); break; case ERF_SC_PACKETISER_HEADER_VERSION_VALUE: // 2
type = efx_tc_rx_version_2(efx, data, mark); break; default: if (net_ratelimit())
netif_err(efx, drv, efx->net_dev, "choked on MAE counter packet (bad version %u" "); counters may be inaccurate\n",
version); goto out;
}
if (type < EFX_TC_COUNTER_TYPE_MAX) { /* Update seen_gen unconditionally, to avoid a missed wakeup if * we race with efx_mae_stop_counters().
*/
efx->tc->seen_gen[type] = mark; if (efx->tc->flush_counters &&
(s32)(efx->tc->flush_gen[type] - mark) <= 0)
wake_up(&efx->tc->flush_wq);
}
out:
efx_free_rx_buffers(rx_queue, rx_buf, 1);
channel->rx_pkt_n_frags = 0; returntrue;
}
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.