2020-09-21 02:37:36 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
|
2016-08-10 05:03:22 -06:00
|
|
|
/*
|
2020-09-21 02:37:36 -06:00
|
|
|
* Copyright 2015-2020 Amazon.com, Inc. or its affiliates. All rights reserved.
|
2016-08-10 05:03:22 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
|
|
|
|
#include "ena_netdev.h"
|
|
|
|
|
|
|
|
struct ena_stats {
|
|
|
|
char name[ETH_GSTRING_LEN];
|
|
|
|
int stat_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ENA_STAT_ENA_COM_ENTRY(stat) { \
|
|
|
|
.name = #stat, \
|
2020-09-10 07:07:10 -06:00
|
|
|
.stat_offset = offsetof(struct ena_com_stats_admin, stat) / sizeof(u64) \
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ENA_STAT_ENTRY(stat, stat_type) { \
|
|
|
|
.name = #stat, \
|
2020-09-10 07:07:10 -06:00
|
|
|
.stat_offset = offsetof(struct ena_stats_##stat_type, stat) / sizeof(u64) \
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
#define ENA_STAT_HW_ENTRY(stat, stat_type) { \
|
|
|
|
.name = #stat, \
|
|
|
|
.stat_offset = offsetof(struct ena_admin_##stat_type, stat) / sizeof(u64) \
|
|
|
|
}
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
#define ENA_STAT_RX_ENTRY(stat) \
|
|
|
|
ENA_STAT_ENTRY(stat, rx)
|
|
|
|
|
|
|
|
#define ENA_STAT_TX_ENTRY(stat) \
|
|
|
|
ENA_STAT_ENTRY(stat, tx)
|
|
|
|
|
|
|
|
#define ENA_STAT_GLOBAL_ENTRY(stat) \
|
|
|
|
ENA_STAT_ENTRY(stat, dev)
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
#define ENA_STAT_ENI_ENTRY(stat) \
|
|
|
|
ENA_STAT_HW_ENTRY(stat, eni_stats)
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
static const struct ena_stats ena_stats_global_strings[] = {
|
|
|
|
ENA_STAT_GLOBAL_ENTRY(tx_timeout),
|
2017-10-17 01:33:58 -06:00
|
|
|
ENA_STAT_GLOBAL_ENTRY(suspend),
|
|
|
|
ENA_STAT_GLOBAL_ENTRY(resume),
|
2016-08-10 05:03:22 -06:00
|
|
|
ENA_STAT_GLOBAL_ENTRY(wd_expired),
|
|
|
|
ENA_STAT_GLOBAL_ENTRY(interface_up),
|
|
|
|
ENA_STAT_GLOBAL_ENTRY(interface_down),
|
|
|
|
ENA_STAT_GLOBAL_ENTRY(admin_q_pause),
|
|
|
|
};
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
static const struct ena_stats ena_stats_eni_strings[] = {
|
|
|
|
ENA_STAT_ENI_ENTRY(bw_in_allowance_exceeded),
|
|
|
|
ENA_STAT_ENI_ENTRY(bw_out_allowance_exceeded),
|
|
|
|
ENA_STAT_ENI_ENTRY(pps_allowance_exceeded),
|
|
|
|
ENA_STAT_ENI_ENTRY(conntrack_allowance_exceeded),
|
|
|
|
ENA_STAT_ENI_ENTRY(linklocal_allowance_exceeded),
|
|
|
|
};
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
static const struct ena_stats ena_stats_tx_strings[] = {
|
|
|
|
ENA_STAT_TX_ENTRY(cnt),
|
|
|
|
ENA_STAT_TX_ENTRY(bytes),
|
|
|
|
ENA_STAT_TX_ENTRY(queue_stop),
|
|
|
|
ENA_STAT_TX_ENTRY(queue_wakeup),
|
|
|
|
ENA_STAT_TX_ENTRY(dma_mapping_err),
|
|
|
|
ENA_STAT_TX_ENTRY(linearize),
|
|
|
|
ENA_STAT_TX_ENTRY(linearize_failed),
|
|
|
|
ENA_STAT_TX_ENTRY(napi_comp),
|
|
|
|
ENA_STAT_TX_ENTRY(tx_poll),
|
|
|
|
ENA_STAT_TX_ENTRY(doorbells),
|
|
|
|
ENA_STAT_TX_ENTRY(prepare_ctx_err),
|
|
|
|
ENA_STAT_TX_ENTRY(bad_req_id),
|
2018-10-11 02:26:20 -06:00
|
|
|
ENA_STAT_TX_ENTRY(llq_buffer_copy),
|
2017-10-17 01:33:59 -06:00
|
|
|
ENA_STAT_TX_ENTRY(missed_tx),
|
2020-05-03 03:52:16 -06:00
|
|
|
ENA_STAT_TX_ENTRY(unmask_interrupt),
|
2016-08-10 05:03:22 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ena_stats ena_stats_rx_strings[] = {
|
|
|
|
ENA_STAT_RX_ENTRY(cnt),
|
|
|
|
ENA_STAT_RX_ENTRY(bytes),
|
2019-06-03 08:43:28 -06:00
|
|
|
ENA_STAT_RX_ENTRY(rx_copybreak_pkt),
|
|
|
|
ENA_STAT_RX_ENTRY(csum_good),
|
2016-08-10 05:03:22 -06:00
|
|
|
ENA_STAT_RX_ENTRY(refil_partial),
|
|
|
|
ENA_STAT_RX_ENTRY(bad_csum),
|
|
|
|
ENA_STAT_RX_ENTRY(page_alloc_fail),
|
|
|
|
ENA_STAT_RX_ENTRY(skb_alloc_fail),
|
|
|
|
ENA_STAT_RX_ENTRY(dma_mapping_err),
|
|
|
|
ENA_STAT_RX_ENTRY(bad_desc_num),
|
2017-06-23 02:21:54 -06:00
|
|
|
ENA_STAT_RX_ENTRY(bad_req_id),
|
2017-06-11 06:42:48 -06:00
|
|
|
ENA_STAT_RX_ENTRY(empty_rx_ring),
|
2018-10-11 02:26:21 -06:00
|
|
|
ENA_STAT_RX_ENTRY(csum_unchecked),
|
2020-09-10 07:07:13 -06:00
|
|
|
ENA_STAT_RX_ENTRY(xdp_aborted),
|
|
|
|
ENA_STAT_RX_ENTRY(xdp_drop),
|
|
|
|
ENA_STAT_RX_ENTRY(xdp_pass),
|
|
|
|
ENA_STAT_RX_ENTRY(xdp_tx),
|
|
|
|
ENA_STAT_RX_ENTRY(xdp_invalid),
|
2016-08-10 05:03:22 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ena_stats ena_stats_ena_com_strings[] = {
|
|
|
|
ENA_STAT_ENA_COM_ENTRY(aborted_cmd),
|
|
|
|
ENA_STAT_ENA_COM_ENTRY(submitted_cmd),
|
|
|
|
ENA_STAT_ENA_COM_ENTRY(completed_cmd),
|
|
|
|
ENA_STAT_ENA_COM_ENTRY(out_of_space),
|
|
|
|
ENA_STAT_ENA_COM_ENTRY(no_completion),
|
|
|
|
};
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
#define ENA_STATS_ARRAY_GLOBAL ARRAY_SIZE(ena_stats_global_strings)
|
|
|
|
#define ENA_STATS_ARRAY_TX ARRAY_SIZE(ena_stats_tx_strings)
|
|
|
|
#define ENA_STATS_ARRAY_RX ARRAY_SIZE(ena_stats_rx_strings)
|
|
|
|
#define ENA_STATS_ARRAY_ENA_COM ARRAY_SIZE(ena_stats_ena_com_strings)
|
|
|
|
#define ENA_STATS_ARRAY_ENI(adapter) \
|
|
|
|
(ARRAY_SIZE(ena_stats_eni_strings) * (adapter)->eni_stats_supported)
|
2016-08-10 05:03:22 -06:00
|
|
|
|
|
|
|
static void ena_safe_update_stat(u64 *src, u64 *dst,
|
|
|
|
struct u64_stats_sync *syncp)
|
|
|
|
{
|
|
|
|
unsigned int start;
|
|
|
|
|
|
|
|
do {
|
|
|
|
start = u64_stats_fetch_begin_irq(syncp);
|
|
|
|
*(dst) = *src;
|
|
|
|
} while (u64_stats_fetch_retry_irq(syncp, start));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ena_queue_stats(struct ena_adapter *adapter, u64 **data)
|
|
|
|
{
|
|
|
|
const struct ena_stats *ena_stats;
|
|
|
|
struct ena_ring *ring;
|
|
|
|
|
|
|
|
u64 *ptr;
|
|
|
|
int i, j;
|
|
|
|
|
2020-09-10 07:07:12 -06:00
|
|
|
for (i = 0; i < adapter->num_io_queues + adapter->xdp_num_queues; i++) {
|
2016-08-10 05:03:22 -06:00
|
|
|
/* Tx stats */
|
|
|
|
ring = &adapter->tx_ring[i];
|
|
|
|
|
|
|
|
for (j = 0; j < ENA_STATS_ARRAY_TX; j++) {
|
|
|
|
ena_stats = &ena_stats_tx_strings[j];
|
|
|
|
|
2020-09-10 07:07:10 -06:00
|
|
|
ptr = (u64 *)&ring->tx_stats + ena_stats->stat_offset;
|
2016-08-10 05:03:22 -06:00
|
|
|
|
|
|
|
ena_safe_update_stat(ptr, (*data)++, &ring->syncp);
|
|
|
|
}
|
2020-09-10 07:07:12 -06:00
|
|
|
/* XDP TX queues don't have a RX queue counterpart */
|
|
|
|
if (!ENA_IS_XDP_INDEX(adapter, i)) {
|
|
|
|
/* Rx stats */
|
|
|
|
ring = &adapter->rx_ring[i];
|
2016-08-10 05:03:22 -06:00
|
|
|
|
2020-09-10 07:07:12 -06:00
|
|
|
for (j = 0; j < ENA_STATS_ARRAY_RX; j++) {
|
|
|
|
ena_stats = &ena_stats_rx_strings[j];
|
2016-08-10 05:03:22 -06:00
|
|
|
|
2020-09-10 07:07:12 -06:00
|
|
|
ptr = (u64 *)&ring->rx_stats +
|
|
|
|
ena_stats->stat_offset;
|
2016-08-10 05:03:22 -06:00
|
|
|
|
2020-09-10 07:07:12 -06:00
|
|
|
ena_safe_update_stat(ptr, (*data)++, &ring->syncp);
|
|
|
|
}
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ena_dev_admin_queue_stats(struct ena_adapter *adapter, u64 **data)
|
|
|
|
{
|
|
|
|
const struct ena_stats *ena_stats;
|
2020-07-21 07:38:07 -06:00
|
|
|
u64 *ptr;
|
2016-08-10 05:03:22 -06:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ENA_STATS_ARRAY_ENA_COM; i++) {
|
|
|
|
ena_stats = &ena_stats_ena_com_strings[i];
|
|
|
|
|
2020-09-10 07:07:10 -06:00
|
|
|
ptr = (u64 *)&adapter->ena_dev->admin_queue.stats +
|
|
|
|
ena_stats->stat_offset;
|
2016-08-10 05:03:22 -06:00
|
|
|
|
|
|
|
*(*data)++ = *ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
static void ena_get_stats(struct ena_adapter *adapter,
|
|
|
|
u64 *data,
|
|
|
|
bool eni_stats_needed)
|
2016-08-10 05:03:22 -06:00
|
|
|
{
|
|
|
|
const struct ena_stats *ena_stats;
|
|
|
|
u64 *ptr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
|
|
|
|
ena_stats = &ena_stats_global_strings[i];
|
|
|
|
|
2020-09-10 07:07:10 -06:00
|
|
|
ptr = (u64 *)&adapter->dev_stats + ena_stats->stat_offset;
|
2016-08-10 05:03:22 -06:00
|
|
|
|
|
|
|
ena_safe_update_stat(ptr, data++, &adapter->syncp);
|
|
|
|
}
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
if (eni_stats_needed) {
|
|
|
|
ena_update_hw_stats(adapter);
|
|
|
|
for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
|
|
|
|
ena_stats = &ena_stats_eni_strings[i];
|
|
|
|
|
|
|
|
ptr = (u64 *)&adapter->eni_stats +
|
|
|
|
ena_stats->stat_offset;
|
|
|
|
|
|
|
|
ena_safe_update_stat(ptr, data++, &adapter->syncp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
ena_queue_stats(adapter, &data);
|
|
|
|
ena_dev_admin_queue_stats(adapter, &data);
|
|
|
|
}
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
static void ena_get_ethtool_stats(struct net_device *netdev,
|
|
|
|
struct ethtool_stats *stats,
|
|
|
|
u64 *data)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
|
|
|
|
ena_get_stats(adapter, data, adapter->eni_stats_supported);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ena_get_sw_stats_count(struct ena_adapter *adapter)
|
|
|
|
{
|
|
|
|
return adapter->num_io_queues * (ENA_STATS_ARRAY_TX + ENA_STATS_ARRAY_RX)
|
2020-09-10 07:07:12 -06:00
|
|
|
+ adapter->xdp_num_queues * ENA_STATS_ARRAY_TX
|
2020-09-10 07:07:11 -06:00
|
|
|
+ ENA_STATS_ARRAY_GLOBAL + ENA_STATS_ARRAY_ENA_COM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ena_get_hw_stats_count(struct ena_adapter *adapter)
|
|
|
|
{
|
|
|
|
return ENA_STATS_ARRAY_ENI(adapter);
|
|
|
|
}
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
int ena_get_sset_count(struct net_device *netdev, int sset)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
|
2019-06-25 10:59:56 -06:00
|
|
|
if (sset != ETH_SS_STATS)
|
2016-08-10 05:03:22 -06:00
|
|
|
return -EOPNOTSUPP;
|
2019-06-25 10:59:56 -06:00
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
return ena_get_sw_stats_count(adapter) + ena_get_hw_stats_count(adapter);
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ena_queue_strings(struct ena_adapter *adapter, u8 **data)
|
|
|
|
{
|
|
|
|
const struct ena_stats *ena_stats;
|
2020-09-10 07:07:12 -06:00
|
|
|
bool is_xdp;
|
2016-08-10 05:03:22 -06:00
|
|
|
int i, j;
|
|
|
|
|
2020-09-10 07:07:12 -06:00
|
|
|
for (i = 0; i < adapter->num_io_queues + adapter->xdp_num_queues; i++) {
|
|
|
|
is_xdp = ENA_IS_XDP_INDEX(adapter, i);
|
2016-08-10 05:03:22 -06:00
|
|
|
/* Tx stats */
|
|
|
|
for (j = 0; j < ENA_STATS_ARRAY_TX; j++) {
|
|
|
|
ena_stats = &ena_stats_tx_strings[j];
|
|
|
|
|
|
|
|
snprintf(*data, ETH_GSTRING_LEN,
|
2020-09-10 07:07:12 -06:00
|
|
|
"queue_%u_%s_%s", i,
|
|
|
|
is_xdp ? "xdp_tx" : "tx", ena_stats->name);
|
2020-03-12 08:05:22 -06:00
|
|
|
(*data) += ETH_GSTRING_LEN;
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
|
2020-09-10 07:07:12 -06:00
|
|
|
if (!is_xdp) {
|
|
|
|
/* RX stats, in XDP there isn't a RX queue
|
|
|
|
* counterpart
|
|
|
|
*/
|
|
|
|
for (j = 0; j < ENA_STATS_ARRAY_RX; j++) {
|
|
|
|
ena_stats = &ena_stats_rx_strings[j];
|
|
|
|
|
|
|
|
snprintf(*data, ETH_GSTRING_LEN,
|
|
|
|
"queue_%u_rx_%s", i, ena_stats->name);
|
|
|
|
(*data) += ETH_GSTRING_LEN;
|
|
|
|
}
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ena_com_dev_strings(u8 **data)
|
|
|
|
{
|
|
|
|
const struct ena_stats *ena_stats;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ENA_STATS_ARRAY_ENA_COM; i++) {
|
|
|
|
ena_stats = &ena_stats_ena_com_strings[i];
|
|
|
|
|
|
|
|
snprintf(*data, ETH_GSTRING_LEN,
|
|
|
|
"ena_admin_q_%s", ena_stats->name);
|
|
|
|
(*data) += ETH_GSTRING_LEN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
static void ena_get_strings(struct ena_adapter *adapter,
|
|
|
|
u8 *data,
|
|
|
|
bool eni_stats_needed)
|
2016-08-10 05:03:22 -06:00
|
|
|
{
|
|
|
|
const struct ena_stats *ena_stats;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
|
|
|
|
ena_stats = &ena_stats_global_strings[i];
|
|
|
|
memcpy(data, ena_stats->name, ETH_GSTRING_LEN);
|
|
|
|
data += ETH_GSTRING_LEN;
|
|
|
|
}
|
2019-06-25 10:59:56 -06:00
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
if (eni_stats_needed) {
|
|
|
|
for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
|
|
|
|
ena_stats = &ena_stats_eni_strings[i];
|
|
|
|
memcpy(data, ena_stats->name, ETH_GSTRING_LEN);
|
|
|
|
data += ETH_GSTRING_LEN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
ena_queue_strings(adapter, &data);
|
|
|
|
ena_com_dev_strings(&data);
|
|
|
|
}
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
static void ena_get_ethtool_strings(struct net_device *netdev,
|
|
|
|
u32 sset,
|
|
|
|
u8 *data)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
|
|
|
|
if (sset != ETH_SS_STATS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ena_get_strings(adapter, data, adapter->eni_stats_supported);
|
|
|
|
}
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
static int ena_get_link_ksettings(struct net_device *netdev,
|
|
|
|
struct ethtool_link_ksettings *link_ksettings)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
struct ena_com_dev *ena_dev = adapter->ena_dev;
|
|
|
|
struct ena_admin_get_feature_link_desc *link;
|
|
|
|
struct ena_admin_get_feat_resp feat_resp;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = ena_com_get_link_params(ena_dev, &feat_resp);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
link = &feat_resp.u.link;
|
|
|
|
link_ksettings->base.speed = link->speed;
|
|
|
|
|
|
|
|
if (link->flags & ENA_ADMIN_GET_FEATURE_LINK_DESC_AUTONEG_MASK) {
|
|
|
|
ethtool_link_ksettings_add_link_mode(link_ksettings,
|
|
|
|
supported, Autoneg);
|
|
|
|
ethtool_link_ksettings_add_link_mode(link_ksettings,
|
|
|
|
supported, Autoneg);
|
|
|
|
}
|
|
|
|
|
|
|
|
link_ksettings->base.autoneg =
|
|
|
|
(link->flags & ENA_ADMIN_GET_FEATURE_LINK_DESC_AUTONEG_MASK) ?
|
|
|
|
AUTONEG_ENABLE : AUTONEG_DISABLE;
|
|
|
|
|
|
|
|
link_ksettings->base.duplex = DUPLEX_FULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ena_get_coalesce(struct net_device *net_dev,
|
|
|
|
struct ethtool_coalesce *coalesce)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(net_dev);
|
|
|
|
struct ena_com_dev *ena_dev = adapter->ena_dev;
|
|
|
|
|
2020-05-22 03:09:01 -06:00
|
|
|
if (!ena_com_interrupt_moderation_supported(ena_dev))
|
2016-08-10 05:03:22 -06:00
|
|
|
return -EOPNOTSUPP;
|
2019-09-16 05:31:35 -06:00
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
coalesce->tx_coalesce_usecs =
|
2019-09-16 05:31:35 -06:00
|
|
|
ena_com_get_nonadaptive_moderation_interval_tx(ena_dev) *
|
2016-08-10 05:03:22 -06:00
|
|
|
ena_dev->intr_delay_resolution;
|
2019-09-16 05:31:28 -06:00
|
|
|
|
2019-12-19 08:40:56 -07:00
|
|
|
coalesce->rx_coalesce_usecs =
|
|
|
|
ena_com_get_nonadaptive_moderation_interval_rx(ena_dev)
|
|
|
|
* ena_dev->intr_delay_resolution;
|
2019-09-16 05:31:28 -06:00
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
coalesce->use_adaptive_rx_coalesce =
|
|
|
|
ena_com_get_adaptive_moderation_enabled(ena_dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-22 03:08:57 -06:00
|
|
|
static void ena_update_tx_rings_nonadaptive_intr_moderation(struct ena_adapter *adapter)
|
2016-08-10 05:03:22 -06:00
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
val = ena_com_get_nonadaptive_moderation_interval_tx(adapter->ena_dev);
|
|
|
|
|
2019-10-06 06:33:23 -06:00
|
|
|
for (i = 0; i < adapter->num_io_queues; i++)
|
2016-08-10 05:03:22 -06:00
|
|
|
adapter->tx_ring[i].smoothed_interval = val;
|
|
|
|
}
|
|
|
|
|
2020-05-22 03:08:57 -06:00
|
|
|
static void ena_update_rx_rings_nonadaptive_intr_moderation(struct ena_adapter *adapter)
|
2019-09-16 05:31:28 -06:00
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
val = ena_com_get_nonadaptive_moderation_interval_rx(adapter->ena_dev);
|
|
|
|
|
2019-10-06 06:33:23 -06:00
|
|
|
for (i = 0; i < adapter->num_io_queues; i++)
|
2019-09-16 05:31:28 -06:00
|
|
|
adapter->rx_ring[i].smoothed_interval = val;
|
|
|
|
}
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
static int ena_set_coalesce(struct net_device *net_dev,
|
|
|
|
struct ethtool_coalesce *coalesce)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(net_dev);
|
|
|
|
struct ena_com_dev *ena_dev = adapter->ena_dev;
|
|
|
|
int rc;
|
|
|
|
|
2020-05-22 03:09:01 -06:00
|
|
|
if (!ena_com_interrupt_moderation_supported(ena_dev))
|
2016-08-10 05:03:22 -06:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
rc = ena_com_update_nonadaptive_moderation_interval_tx(ena_dev,
|
|
|
|
coalesce->tx_coalesce_usecs);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2020-05-22 03:08:57 -06:00
|
|
|
ena_update_tx_rings_nonadaptive_intr_moderation(adapter);
|
2016-08-10 05:03:22 -06:00
|
|
|
|
2019-09-16 05:31:28 -06:00
|
|
|
rc = ena_com_update_nonadaptive_moderation_interval_rx(ena_dev,
|
|
|
|
coalesce->rx_coalesce_usecs);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2016-08-10 05:03:22 -06:00
|
|
|
|
2020-05-22 03:08:57 -06:00
|
|
|
ena_update_rx_rings_nonadaptive_intr_moderation(adapter);
|
2016-08-10 05:03:22 -06:00
|
|
|
|
2019-12-19 08:40:56 -07:00
|
|
|
if (coalesce->use_adaptive_rx_coalesce &&
|
|
|
|
!ena_com_get_adaptive_moderation_enabled(ena_dev))
|
|
|
|
ena_com_enable_adaptive_moderation(ena_dev);
|
|
|
|
|
|
|
|
if (!coalesce->use_adaptive_rx_coalesce &&
|
|
|
|
ena_com_get_adaptive_moderation_enabled(ena_dev))
|
|
|
|
ena_com_disable_adaptive_moderation(ena_dev);
|
2016-08-10 05:03:22 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 ena_get_msglevel(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
|
|
|
|
return adapter->msg_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ena_set_msglevel(struct net_device *netdev, u32 value)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
|
|
|
|
adapter->msg_enable = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ena_get_drvinfo(struct net_device *dev,
|
|
|
|
struct ethtool_drvinfo *info)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(dev);
|
|
|
|
|
|
|
|
strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver));
|
|
|
|
strlcpy(info->bus_info, pci_name(adapter->pdev),
|
|
|
|
sizeof(info->bus_info));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ena_get_ringparam(struct net_device *netdev,
|
|
|
|
struct ethtool_ringparam *ring)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
|
2019-06-11 05:58:07 -06:00
|
|
|
ring->tx_max_pending = adapter->max_tx_ring_size;
|
|
|
|
ring->rx_max_pending = adapter->max_rx_ring_size;
|
2019-06-11 05:58:08 -06:00
|
|
|
ring->tx_pending = adapter->tx_ring[0].ring_size;
|
|
|
|
ring->rx_pending = adapter->rx_ring[0].ring_size;
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
|
2019-06-11 05:58:09 -06:00
|
|
|
static int ena_set_ringparam(struct net_device *netdev,
|
|
|
|
struct ethtool_ringparam *ring)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
u32 new_tx_size, new_rx_size;
|
|
|
|
|
|
|
|
new_tx_size = ring->tx_pending < ENA_MIN_RING_SIZE ?
|
|
|
|
ENA_MIN_RING_SIZE : ring->tx_pending;
|
|
|
|
new_tx_size = rounddown_pow_of_two(new_tx_size);
|
|
|
|
|
|
|
|
new_rx_size = ring->rx_pending < ENA_MIN_RING_SIZE ?
|
|
|
|
ENA_MIN_RING_SIZE : ring->rx_pending;
|
|
|
|
new_rx_size = rounddown_pow_of_two(new_rx_size);
|
|
|
|
|
|
|
|
if (new_tx_size == adapter->requested_tx_ring_size &&
|
|
|
|
new_rx_size == adapter->requested_rx_ring_size)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ena_update_queue_sizes(adapter, new_tx_size, new_rx_size);
|
|
|
|
}
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
static u32 ena_flow_hash_to_flow_type(u16 hash_fields)
|
|
|
|
{
|
|
|
|
u32 data = 0;
|
|
|
|
|
|
|
|
if (hash_fields & ENA_ADMIN_RSS_L2_DA)
|
|
|
|
data |= RXH_L2DA;
|
|
|
|
|
|
|
|
if (hash_fields & ENA_ADMIN_RSS_L3_DA)
|
|
|
|
data |= RXH_IP_DST;
|
|
|
|
|
|
|
|
if (hash_fields & ENA_ADMIN_RSS_L3_SA)
|
|
|
|
data |= RXH_IP_SRC;
|
|
|
|
|
|
|
|
if (hash_fields & ENA_ADMIN_RSS_L4_DP)
|
|
|
|
data |= RXH_L4_B_2_3;
|
|
|
|
|
|
|
|
if (hash_fields & ENA_ADMIN_RSS_L4_SP)
|
|
|
|
data |= RXH_L4_B_0_1;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u16 ena_flow_data_to_flow_hash(u32 hash_fields)
|
|
|
|
{
|
|
|
|
u16 data = 0;
|
|
|
|
|
|
|
|
if (hash_fields & RXH_L2DA)
|
|
|
|
data |= ENA_ADMIN_RSS_L2_DA;
|
|
|
|
|
|
|
|
if (hash_fields & RXH_IP_DST)
|
|
|
|
data |= ENA_ADMIN_RSS_L3_DA;
|
|
|
|
|
|
|
|
if (hash_fields & RXH_IP_SRC)
|
|
|
|
data |= ENA_ADMIN_RSS_L3_SA;
|
|
|
|
|
|
|
|
if (hash_fields & RXH_L4_B_2_3)
|
|
|
|
data |= ENA_ADMIN_RSS_L4_DP;
|
|
|
|
|
|
|
|
if (hash_fields & RXH_L4_B_0_1)
|
|
|
|
data |= ENA_ADMIN_RSS_L4_SP;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ena_get_rss_hash(struct ena_com_dev *ena_dev,
|
|
|
|
struct ethtool_rxnfc *cmd)
|
|
|
|
{
|
|
|
|
enum ena_admin_flow_hash_proto proto;
|
|
|
|
u16 hash_fields;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
cmd->data = 0;
|
|
|
|
|
|
|
|
switch (cmd->flow_type) {
|
|
|
|
case TCP_V4_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_TCP4;
|
|
|
|
break;
|
|
|
|
case UDP_V4_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_UDP4;
|
|
|
|
break;
|
|
|
|
case TCP_V6_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_TCP6;
|
|
|
|
break;
|
|
|
|
case UDP_V6_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_UDP6;
|
|
|
|
break;
|
|
|
|
case IPV4_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_IP4;
|
|
|
|
break;
|
|
|
|
case IPV6_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_IP6;
|
|
|
|
break;
|
|
|
|
case ETHER_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_NOT_IP;
|
|
|
|
break;
|
|
|
|
case AH_V4_FLOW:
|
|
|
|
case ESP_V4_FLOW:
|
|
|
|
case AH_V6_FLOW:
|
|
|
|
case ESP_V6_FLOW:
|
|
|
|
case SCTP_V4_FLOW:
|
|
|
|
case AH_ESP_V4_FLOW:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ena_com_get_hash_ctrl(ena_dev, proto, &hash_fields);
|
2017-06-23 02:21:50 -06:00
|
|
|
if (rc)
|
2016-08-10 05:03:22 -06:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
cmd->data = ena_flow_hash_to_flow_type(hash_fields);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ena_set_rss_hash(struct ena_com_dev *ena_dev,
|
|
|
|
struct ethtool_rxnfc *cmd)
|
|
|
|
{
|
|
|
|
enum ena_admin_flow_hash_proto proto;
|
|
|
|
u16 hash_fields;
|
|
|
|
|
|
|
|
switch (cmd->flow_type) {
|
|
|
|
case TCP_V4_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_TCP4;
|
|
|
|
break;
|
|
|
|
case UDP_V4_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_UDP4;
|
|
|
|
break;
|
|
|
|
case TCP_V6_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_TCP6;
|
|
|
|
break;
|
|
|
|
case UDP_V6_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_UDP6;
|
|
|
|
break;
|
|
|
|
case IPV4_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_IP4;
|
|
|
|
break;
|
|
|
|
case IPV6_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_IP6;
|
|
|
|
break;
|
|
|
|
case ETHER_FLOW:
|
|
|
|
proto = ENA_ADMIN_RSS_NOT_IP;
|
|
|
|
break;
|
|
|
|
case AH_V4_FLOW:
|
|
|
|
case ESP_V4_FLOW:
|
|
|
|
case AH_V6_FLOW:
|
|
|
|
case ESP_V6_FLOW:
|
|
|
|
case SCTP_V4_FLOW:
|
|
|
|
case AH_ESP_V4_FLOW:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hash_fields = ena_flow_data_to_flow_hash(cmd->data);
|
|
|
|
|
|
|
|
return ena_com_fill_hash_ctrl(ena_dev, proto, hash_fields);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ena_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
switch (info->cmd) {
|
|
|
|
case ETHTOOL_SRXFH:
|
|
|
|
rc = ena_set_rss_hash(adapter->ena_dev, info);
|
|
|
|
break;
|
|
|
|
case ETHTOOL_SRXCLSRLDEL:
|
|
|
|
case ETHTOOL_SRXCLSRLINS:
|
|
|
|
default:
|
|
|
|
netif_err(adapter, drv, netdev,
|
|
|
|
"Command parameter %d is not supported\n", info->cmd);
|
|
|
|
rc = -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2017-06-23 02:21:50 -06:00
|
|
|
return rc;
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ena_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *info,
|
|
|
|
u32 *rules)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
switch (info->cmd) {
|
|
|
|
case ETHTOOL_GRXRINGS:
|
2019-10-06 06:33:23 -06:00
|
|
|
info->data = adapter->num_io_queues;
|
2016-08-10 05:03:22 -06:00
|
|
|
rc = 0;
|
|
|
|
break;
|
|
|
|
case ETHTOOL_GRXFH:
|
|
|
|
rc = ena_get_rss_hash(adapter->ena_dev, info);
|
|
|
|
break;
|
|
|
|
case ETHTOOL_GRXCLSRLCNT:
|
|
|
|
case ETHTOOL_GRXCLSRULE:
|
|
|
|
case ETHTOOL_GRXCLSRLALL:
|
|
|
|
default:
|
|
|
|
netif_err(adapter, drv, netdev,
|
|
|
|
"Command parameter %d is not supported\n", info->cmd);
|
|
|
|
rc = -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2017-06-23 02:21:50 -06:00
|
|
|
return rc;
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static u32 ena_get_rxfh_indir_size(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
return ENA_RX_RSS_TABLE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 ena_get_rxfh_key_size(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
return ENA_HASH_KEY_SIZE;
|
|
|
|
}
|
|
|
|
|
2020-05-03 03:52:21 -06:00
|
|
|
static int ena_indirection_table_set(struct ena_adapter *adapter,
|
|
|
|
const u32 *indir)
|
|
|
|
{
|
|
|
|
struct ena_com_dev *ena_dev = adapter->ena_dev;
|
|
|
|
int i, rc;
|
|
|
|
|
|
|
|
for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++) {
|
|
|
|
rc = ena_com_indirect_table_fill_entry(ena_dev,
|
|
|
|
i,
|
|
|
|
ENA_IO_RXQ_IDX(indir[i]));
|
|
|
|
if (unlikely(rc)) {
|
|
|
|
netif_err(adapter, drv, adapter->netdev,
|
|
|
|
"Cannot fill indirect table (index is too large)\n");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ena_com_indirect_table_set(ena_dev);
|
|
|
|
if (rc) {
|
|
|
|
netif_err(adapter, drv, adapter->netdev,
|
|
|
|
"Cannot set indirect table\n");
|
|
|
|
return rc == -EPERM ? -EOPNOTSUPP : rc;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-02-11 08:17:47 -07:00
|
|
|
static int ena_indirection_table_get(struct ena_adapter *adapter, u32 *indir)
|
|
|
|
{
|
|
|
|
struct ena_com_dev *ena_dev = adapter->ena_dev;
|
|
|
|
int i, rc;
|
|
|
|
|
|
|
|
if (!indir)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rc = ena_com_indirect_table_get(ena_dev, indir);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* Our internal representation of the indices is: even indices
|
|
|
|
* for Tx and uneven indices for Rx. We need to convert the Rx
|
|
|
|
* indices to be consecutive
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++)
|
|
|
|
indir[i] = ENA_IO_RXQ_IDX_TO_COMBINED_IDX(indir[i]);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
|
|
|
|
u8 *hfunc)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
enum ena_admin_hash_functions ena_func;
|
|
|
|
u8 func;
|
|
|
|
int rc;
|
|
|
|
|
2020-02-11 08:17:47 -07:00
|
|
|
rc = ena_indirection_table_get(adapter, indir);
|
2016-08-10 05:03:22 -06:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2020-02-11 08:17:45 -07:00
|
|
|
/* We call this function in order to check if the device
|
|
|
|
* supports getting/setting the hash function.
|
|
|
|
*/
|
2020-05-03 03:52:12 -06:00
|
|
|
rc = ena_com_get_hash_function(adapter->ena_dev, &ena_func);
|
2020-02-11 08:17:45 -07:00
|
|
|
if (rc) {
|
2020-05-03 03:52:15 -06:00
|
|
|
if (rc == -EOPNOTSUPP)
|
2020-02-11 08:17:45 -07:00
|
|
|
rc = 0;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-05-03 03:52:12 -06:00
|
|
|
rc = ena_com_get_hash_key(adapter->ena_dev, key);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
switch (ena_func) {
|
|
|
|
case ENA_ADMIN_TOEPLITZ:
|
|
|
|
func = ETH_RSS_HASH_TOP;
|
|
|
|
break;
|
|
|
|
case ENA_ADMIN_CRC32:
|
2020-02-11 08:17:50 -07:00
|
|
|
func = ETH_RSS_HASH_CRC32;
|
2016-08-10 05:03:22 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
netif_err(adapter, drv, netdev,
|
|
|
|
"Command parameter is not supported\n");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hfunc)
|
|
|
|
*hfunc = func;
|
|
|
|
|
2020-05-03 03:52:12 -06:00
|
|
|
return 0;
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
|
|
|
|
const u8 *key, const u8 hfunc)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
struct ena_com_dev *ena_dev = adapter->ena_dev;
|
2020-05-03 03:52:12 -06:00
|
|
|
enum ena_admin_hash_functions func = 0;
|
2020-05-03 03:52:21 -06:00
|
|
|
int rc;
|
2016-08-10 05:03:22 -06:00
|
|
|
|
|
|
|
if (indir) {
|
2020-05-03 03:52:21 -06:00
|
|
|
rc = ena_indirection_table_set(adapter, indir);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (hfunc) {
|
2020-02-11 08:17:49 -07:00
|
|
|
case ETH_RSS_HASH_NO_CHANGE:
|
|
|
|
func = ena_com_get_current_hash_function(ena_dev);
|
|
|
|
break;
|
2016-08-10 05:03:22 -06:00
|
|
|
case ETH_RSS_HASH_TOP:
|
|
|
|
func = ENA_ADMIN_TOEPLITZ;
|
|
|
|
break;
|
2020-02-11 08:17:50 -07:00
|
|
|
case ETH_RSS_HASH_CRC32:
|
2016-08-10 05:03:22 -06:00
|
|
|
func = ENA_ADMIN_CRC32;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
netif_err(adapter, drv, netdev, "Unsupported hfunc %d\n",
|
|
|
|
hfunc);
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2020-05-03 03:52:12 -06:00
|
|
|
if (key || func) {
|
2016-08-10 05:03:22 -06:00
|
|
|
rc = ena_com_fill_hash_function(ena_dev, func, key,
|
|
|
|
ENA_HASH_KEY_SIZE,
|
|
|
|
0xFFFFFFFF);
|
|
|
|
if (unlikely(rc)) {
|
|
|
|
netif_err(adapter, drv, netdev, "Cannot fill key\n");
|
|
|
|
return rc == -EPERM ? -EOPNOTSUPP : rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ena_get_channels(struct net_device *netdev,
|
|
|
|
struct ethtool_channels *channels)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
|
2019-10-06 06:33:26 -06:00
|
|
|
channels->max_combined = adapter->max_num_io_queues;
|
2019-10-06 06:33:25 -06:00
|
|
|
channels->combined_count = adapter->num_io_queues;
|
2016-08-10 05:03:22 -06:00
|
|
|
}
|
|
|
|
|
2019-10-06 06:33:28 -06:00
|
|
|
static int ena_set_channels(struct net_device *netdev,
|
|
|
|
struct ethtool_channels *channels)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
u32 count = channels->combined_count;
|
|
|
|
/* The check for max value is already done in ethtool */
|
2019-12-10 06:12:13 -07:00
|
|
|
if (count < ENA_MIN_NUM_IO_QUEUES ||
|
|
|
|
(ena_xdp_present(adapter) &&
|
|
|
|
!ena_xdp_legal_queue_count(adapter, channels->combined_count)))
|
2019-10-06 06:33:28 -06:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ena_update_queue_count(adapter, count);
|
|
|
|
}
|
|
|
|
|
2016-08-10 05:03:22 -06:00
|
|
|
static int ena_get_tunable(struct net_device *netdev,
|
|
|
|
const struct ethtool_tunable *tuna, void *data)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
switch (tuna->id) {
|
|
|
|
case ETHTOOL_RX_COPYBREAK:
|
|
|
|
*(u32 *)data = adapter->rx_copybreak;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ena_set_tunable(struct net_device *netdev,
|
|
|
|
const struct ethtool_tunable *tuna,
|
|
|
|
const void *data)
|
|
|
|
{
|
|
|
|
struct ena_adapter *adapter = netdev_priv(netdev);
|
|
|
|
int ret = 0;
|
|
|
|
u32 len;
|
|
|
|
|
|
|
|
switch (tuna->id) {
|
|
|
|
case ETHTOOL_RX_COPYBREAK:
|
|
|
|
len = *(u32 *)data;
|
|
|
|
if (len > adapter->netdev->mtu) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
adapter->rx_copybreak = len;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ethtool_ops ena_ethtool_ops = {
|
2020-03-09 20:14:58 -06:00
|
|
|
.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
|
|
|
|
ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
|
2016-08-10 05:03:22 -06:00
|
|
|
.get_link_ksettings = ena_get_link_ksettings,
|
|
|
|
.get_drvinfo = ena_get_drvinfo,
|
|
|
|
.get_msglevel = ena_get_msglevel,
|
|
|
|
.set_msglevel = ena_set_msglevel,
|
|
|
|
.get_link = ethtool_op_get_link,
|
|
|
|
.get_coalesce = ena_get_coalesce,
|
|
|
|
.set_coalesce = ena_set_coalesce,
|
|
|
|
.get_ringparam = ena_get_ringparam,
|
2019-06-11 05:58:09 -06:00
|
|
|
.set_ringparam = ena_set_ringparam,
|
2016-08-10 05:03:22 -06:00
|
|
|
.get_sset_count = ena_get_sset_count,
|
2020-09-10 07:07:11 -06:00
|
|
|
.get_strings = ena_get_ethtool_strings,
|
2016-08-10 05:03:22 -06:00
|
|
|
.get_ethtool_stats = ena_get_ethtool_stats,
|
|
|
|
.get_rxnfc = ena_get_rxnfc,
|
|
|
|
.set_rxnfc = ena_set_rxnfc,
|
|
|
|
.get_rxfh_indir_size = ena_get_rxfh_indir_size,
|
|
|
|
.get_rxfh_key_size = ena_get_rxfh_key_size,
|
|
|
|
.get_rxfh = ena_get_rxfh,
|
|
|
|
.set_rxfh = ena_set_rxfh,
|
|
|
|
.get_channels = ena_get_channels,
|
2019-10-06 06:33:28 -06:00
|
|
|
.set_channels = ena_set_channels,
|
2016-08-10 05:03:22 -06:00
|
|
|
.get_tunable = ena_get_tunable,
|
|
|
|
.set_tunable = ena_set_tunable,
|
2020-02-11 08:17:42 -07:00
|
|
|
.get_ts_info = ethtool_op_get_ts_info,
|
2016-08-10 05:03:22 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
void ena_set_ethtool_ops(struct net_device *netdev)
|
|
|
|
{
|
|
|
|
netdev->ethtool_ops = &ena_ethtool_ops;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ena_dump_stats_ex(struct ena_adapter *adapter, u8 *buf)
|
|
|
|
{
|
|
|
|
struct net_device *netdev = adapter->netdev;
|
|
|
|
u8 *strings_buf;
|
|
|
|
u64 *data_buf;
|
|
|
|
int strings_num;
|
|
|
|
int i, rc;
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
strings_num = ena_get_sw_stats_count(adapter);
|
2016-08-10 05:03:22 -06:00
|
|
|
if (strings_num <= 0) {
|
|
|
|
netif_err(adapter, drv, netdev, "Can't get stats num\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 15:07:58 -06:00
|
|
|
strings_buf = devm_kcalloc(&adapter->pdev->dev,
|
|
|
|
ETH_GSTRING_LEN, strings_num,
|
2016-08-10 05:03:22 -06:00
|
|
|
GFP_ATOMIC);
|
|
|
|
if (!strings_buf) {
|
|
|
|
netif_err(adapter, drv, netdev,
|
2020-09-21 02:37:38 -06:00
|
|
|
"Failed to allocate strings_buf\n");
|
2016-08-10 05:03:22 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
treewide: devm_kzalloc() -> devm_kcalloc()
The devm_kzalloc() function has a 2-factor argument form, devm_kcalloc().
This patch replaces cases of:
devm_kzalloc(handle, a * b, gfp)
with:
devm_kcalloc(handle, a * b, gfp)
as well as handling cases of:
devm_kzalloc(handle, a * b * c, gfp)
with:
devm_kzalloc(handle, array3_size(a, b, c), gfp)
as it's slightly less ugly than:
devm_kcalloc(handle, array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
devm_kzalloc(handle, 4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
Some manual whitespace fixes were needed in this patch, as Coccinelle
really liked to write "=devm_kcalloc..." instead of "= devm_kcalloc...".
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
expression HANDLE;
type TYPE;
expression THING, E;
@@
(
devm_kzalloc(HANDLE,
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
devm_kzalloc(HANDLE,
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression HANDLE;
expression COUNT;
typedef u8;
typedef __u8;
@@
(
devm_kzalloc(HANDLE,
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(char) * COUNT
+ COUNT
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
expression HANDLE;
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
expression HANDLE;
identifier SIZE, COUNT;
@@
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression HANDLE;
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression HANDLE;
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
devm_kzalloc(HANDLE,
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
expression HANDLE;
identifier STRIDE, SIZE, COUNT;
@@
(
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
devm_kzalloc(HANDLE,
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression HANDLE;
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE,
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
devm_kzalloc(HANDLE,
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression HANDLE;
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
devm_kzalloc(HANDLE, sizeof(THING) * C2, ...)
|
devm_kzalloc(HANDLE, sizeof(TYPE) * C2, ...)
|
devm_kzalloc(HANDLE, C1 * C2 * C3, ...)
|
devm_kzalloc(HANDLE, C1 * C2, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * E2
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- (E1) * (E2)
+ E1, E2
, ...)
|
- devm_kzalloc
+ devm_kcalloc
(HANDLE,
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 15:07:58 -06:00
|
|
|
data_buf = devm_kcalloc(&adapter->pdev->dev,
|
|
|
|
strings_num, sizeof(u64),
|
2016-08-10 05:03:22 -06:00
|
|
|
GFP_ATOMIC);
|
|
|
|
if (!data_buf) {
|
|
|
|
netif_err(adapter, drv, netdev,
|
2020-09-10 07:07:11 -06:00
|
|
|
"Failed to allocate data buf\n");
|
2016-08-10 05:03:22 -06:00
|
|
|
devm_kfree(&adapter->pdev->dev, strings_buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-10 07:07:11 -06:00
|
|
|
ena_get_strings(adapter, strings_buf, false);
|
|
|
|
ena_get_stats(adapter, data_buf, false);
|
2016-08-10 05:03:22 -06:00
|
|
|
|
|
|
|
/* If there is a buffer, dump stats, otherwise print them to dmesg */
|
|
|
|
if (buf)
|
|
|
|
for (i = 0; i < strings_num; i++) {
|
|
|
|
rc = snprintf(buf, ETH_GSTRING_LEN + sizeof(u64),
|
|
|
|
"%s %llu\n",
|
|
|
|
strings_buf + i * ETH_GSTRING_LEN,
|
|
|
|
data_buf[i]);
|
|
|
|
buf += rc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for (i = 0; i < strings_num; i++)
|
|
|
|
netif_err(adapter, drv, netdev, "%s: %llu\n",
|
|
|
|
strings_buf + i * ETH_GSTRING_LEN,
|
|
|
|
data_buf[i]);
|
|
|
|
|
|
|
|
devm_kfree(&adapter->pdev->dev, strings_buf);
|
|
|
|
devm_kfree(&adapter->pdev->dev, data_buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ena_dump_stats_to_buf(struct ena_adapter *adapter, u8 *buf)
|
|
|
|
{
|
|
|
|
if (!buf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ena_dump_stats_ex(adapter, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ena_dump_stats_to_dmesg(struct ena_adapter *adapter)
|
|
|
|
{
|
|
|
|
ena_dump_stats_ex(adapter, NULL);
|
|
|
|
}
|