Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
@@ -0,0 +1,11 @@
# SPDX-License-Identifier: GPL-2.0-only
menuconfig FSL_DPAA_ETH
tristate "DPAA Ethernet"
depends on FSL_DPAA && FSL_FMAN
select PHYLINK
select PCS_LYNX
help
Data Path Acceleration Architecture Ethernet driver,
supporting the Freescale QorIQ chips.
Depends on Freescale Buffer Manager and Queue Manager
driver and Frame Manager Driver.
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: GPL-2.0
#
# Makefile for the Freescale DPAA Ethernet controllers
#
# Include FMan headers
FMAN = $(srctree)/drivers/net/ethernet/freescale/fman
ccflags-y += -I$(FMAN)
obj-$(CONFIG_FSL_DPAA_ETH) += fsl_dpa.o
fsl_dpa-objs += dpaa_eth.o dpaa_ethtool.o dpaa_eth_sysfs.o
CFLAGS_dpaa_eth.o := -I$(src)
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,196 @@
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later */
/*
* Copyright 2008 - 2016 Freescale Semiconductor Inc.
*/
#ifndef __DPAA_H
#define __DPAA_H
#include <linux/netdevice.h>
#include <linux/refcount.h>
#include <net/xdp.h>
#include <soc/fsl/qman.h>
#include <soc/fsl/bman.h>
#include "fman.h"
#include "mac.h"
#include "dpaa_eth_trace.h"
/* Number of prioritised traffic classes */
#define DPAA_TC_NUM 4
/* More detailed FQ types - used for fine-grained WQ assignments */
enum dpaa_fq_type {
FQ_TYPE_RX_DEFAULT = 1, /* Rx Default FQs */
FQ_TYPE_RX_ERROR, /* Rx Error FQs */
FQ_TYPE_RX_PCD, /* Rx Parse Classify Distribute FQs */
FQ_TYPE_TX, /* "Real" Tx FQs */
FQ_TYPE_TX_CONFIRM, /* Tx default Conf FQ (actually an Rx FQ) */
FQ_TYPE_TX_CONF_MQ, /* Tx conf FQs (one for each Tx FQ) */
FQ_TYPE_TX_ERROR, /* Tx Error FQs (these are actually Rx FQs) */
};
struct dpaa_fq {
struct qman_fq fq_base;
struct list_head list;
struct net_device *net_dev;
bool init;
u32 fqid;
u32 flags;
u16 channel;
u8 wq;
enum dpaa_fq_type fq_type;
struct xdp_rxq_info xdp_rxq;
};
struct dpaa_fq_cbs {
struct qman_fq rx_defq;
struct qman_fq tx_defq;
struct qman_fq rx_errq;
struct qman_fq tx_errq;
struct qman_fq egress_ern;
};
struct dpaa_priv;
struct dpaa_bp {
/* used in the DMA mapping operations */
struct dpaa_priv *priv;
/* current number of buffers in the buffer pool alloted to each CPU */
int __percpu *percpu_count;
/* all buffers allocated for this pool have this raw size */
size_t raw_size;
/* all buffers in this pool have this same usable size */
size_t size;
/* the buffer pools are initialized with config_count buffers for each
* CPU; at runtime the number of buffers per CPU is constantly brought
* back to this level
*/
u16 config_count;
u8 bpid;
struct bman_pool *pool;
/* bpool can be seeded before use by this cb */
int (*seed_cb)(struct dpaa_bp *);
/* bpool can be emptied before freeing by this cb */
void (*free_buf_cb)(const struct dpaa_bp *, struct bm_buffer *);
refcount_t refs;
};
struct dpaa_rx_errors {
u64 dme; /* DMA Error */
u64 fpe; /* Frame Physical Error */
u64 fse; /* Frame Size Error */
u64 phe; /* Header Error */
};
/* Counters for QMan ERN frames - one counter per rejection code */
struct dpaa_ern_cnt {
u64 cg_tdrop; /* Congestion group taildrop */
u64 wred; /* WRED congestion */
u64 err_cond; /* Error condition */
u64 early_window; /* Order restoration, frame too early */
u64 late_window; /* Order restoration, frame too late */
u64 fq_tdrop; /* FQ taildrop */
u64 fq_retired; /* FQ is retired */
u64 orp_zero; /* ORP disabled */
};
struct dpaa_napi_portal {
struct napi_struct napi;
struct qman_portal *p;
bool down;
int xdp_act;
};
struct dpaa_percpu_priv {
struct net_device *net_dev;
struct dpaa_napi_portal np;
u64 in_interrupt;
u64 tx_confirm;
/* fragmented (non-linear) skbuffs received from the stack */
u64 tx_frag_skbuffs;
struct rtnl_link_stats64 stats;
struct dpaa_rx_errors rx_errors;
struct dpaa_ern_cnt ern_cnt;
};
struct dpaa_buffer_layout {
u16 priv_data_size;
};
/* Information to be used on the Tx confirmation path. Stored just
* before the start of the transmit buffer. Maximum size allowed
* is DPAA_TX_PRIV_DATA_SIZE bytes.
*/
struct dpaa_eth_swbp {
struct sk_buff *skb;
struct xdp_frame *xdpf;
};
struct dpaa_priv {
struct dpaa_percpu_priv __percpu *percpu_priv;
struct dpaa_bp *dpaa_bp;
/* Store here the needed Tx headroom for convenience and speed
* (even though it can be computed based on the fields of buf_layout)
*/
u16 tx_headroom;
struct net_device *net_dev;
struct mac_device *mac_dev;
struct device *rx_dma_dev;
struct device *tx_dma_dev;
struct qman_fq **egress_fqs;
struct qman_fq **conf_fqs;
u16 channel;
struct list_head dpaa_fq_list;
u8 num_tc;
bool keygen_in_use;
u32 msg_enable; /* net_device message level */
struct {
/* All egress queues to a given net device belong to one
* (and the same) congestion group.
*/
struct qman_cgr cgr;
/* If congested, when it began. Used for performance stats. */
u32 congestion_start_jiffies;
/* Number of jiffies the Tx port was congested. */
u32 congested_jiffies;
/* Counter for the number of times the CGR
* entered congestion state
*/
u32 cgr_congested_count;
} cgr_data;
/* Use a per-port CGR for ingress traffic. */
bool use_ingress_cgr;
struct qman_cgr ingress_cgr;
struct dpaa_buffer_layout buf_layout[2];
u16 rx_headroom;
bool tx_tstamp; /* Tx timestamping enabled */
bool rx_tstamp; /* Rx timestamping enabled */
struct bpf_prog *xdp_prog;
};
/* from dpaa_ethtool.c */
extern const struct ethtool_ops dpaa_ethtool_ops;
/* from dpaa_eth_sysfs.c */
void dpaa_eth_sysfs_remove(struct device *dev);
void dpaa_eth_sysfs_init(struct device *dev);
static inline size_t dpaa_num_txqs_per_tc(void)
{
return num_possible_cpus();
}
/* Total number of Tx queues */
static inline size_t dpaa_max_num_txqs(void)
{
return DPAA_TC_NUM * dpaa_num_txqs_per_tc();
}
#endif /* __DPAA_H */
@@ -0,0 +1,138 @@
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later
/*
* Copyright 2008 - 2016 Freescale Semiconductor Inc.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/io.h>
#include <linux/of_net.h>
#include "dpaa_eth.h"
#include "mac.h"
static ssize_t dpaa_eth_show_addr(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
struct mac_device *mac_dev = priv->mac_dev;
if (mac_dev)
return sprintf(buf, "%llx",
(unsigned long long)mac_dev->res->start);
else
return sprintf(buf, "none");
}
static ssize_t dpaa_eth_show_fqids(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
struct dpaa_fq *prev = NULL;
char *prevstr = NULL;
struct dpaa_fq *tmp;
struct dpaa_fq *fq;
u32 first_fqid = 0;
u32 last_fqid = 0;
ssize_t bytes = 0;
char *str;
list_for_each_entry_safe(fq, tmp, &priv->dpaa_fq_list, list) {
switch (fq->fq_type) {
case FQ_TYPE_RX_DEFAULT:
str = "Rx default";
break;
case FQ_TYPE_RX_ERROR:
str = "Rx error";
break;
case FQ_TYPE_RX_PCD:
str = "Rx PCD";
break;
case FQ_TYPE_TX_CONFIRM:
str = "Tx default confirmation";
break;
case FQ_TYPE_TX_CONF_MQ:
str = "Tx confirmation (mq)";
break;
case FQ_TYPE_TX_ERROR:
str = "Tx error";
break;
case FQ_TYPE_TX:
str = "Tx";
break;
default:
str = "Unknown";
}
if (prev && (abs(fq->fqid - prev->fqid) != 1 ||
str != prevstr)) {
if (last_fqid == first_fqid)
bytes += sprintf(buf + bytes,
"%s: %d\n", prevstr, prev->fqid);
else
bytes += sprintf(buf + bytes,
"%s: %d - %d\n", prevstr,
first_fqid, last_fqid);
}
if (prev && abs(fq->fqid - prev->fqid) == 1 &&
str == prevstr) {
last_fqid = fq->fqid;
} else {
first_fqid = fq->fqid;
last_fqid = fq->fqid;
}
prev = fq;
prevstr = str;
}
if (prev) {
if (last_fqid == first_fqid)
bytes += sprintf(buf + bytes, "%s: %d\n", prevstr,
prev->fqid);
else
bytes += sprintf(buf + bytes, "%s: %d - %d\n", prevstr,
first_fqid, last_fqid);
}
return bytes;
}
static ssize_t dpaa_eth_show_bpids(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
ssize_t bytes = 0;
bytes += snprintf(buf + bytes, PAGE_SIZE - bytes, "%u\n",
priv->dpaa_bp->bpid);
return bytes;
}
static struct device_attribute dpaa_eth_attrs[] = {
__ATTR(device_addr, 0444, dpaa_eth_show_addr, NULL),
__ATTR(fqids, 0444, dpaa_eth_show_fqids, NULL),
__ATTR(bpids, 0444, dpaa_eth_show_bpids, NULL),
};
void dpaa_eth_sysfs_init(struct device *dev)
{
int i;
for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++)
if (device_create_file(dev, &dpaa_eth_attrs[i])) {
dev_err(dev, "Error creating sysfs file\n");
while (i > 0)
device_remove_file(dev, &dpaa_eth_attrs[--i]);
return;
}
}
void dpaa_eth_sysfs_remove(struct device *dev)
{
int i;
for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++)
device_remove_file(dev, &dpaa_eth_attrs[i]);
}
@@ -0,0 +1,115 @@
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later */
/*
* Copyright 2013-2015 Freescale Semiconductor Inc.
*/
#undef TRACE_SYSTEM
#define TRACE_SYSTEM dpaa_eth
#if !defined(_DPAA_ETH_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
#define _DPAA_ETH_TRACE_H
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include "dpaa_eth.h"
#include <linux/tracepoint.h>
#define fd_format_name(format) { qm_fd_##format, #format }
#define fd_format_list \
fd_format_name(contig), \
fd_format_name(sg)
/* This is used to declare a class of events.
* individual events of this type will be defined below.
*/
/* Store details about a frame descriptor and the FQ on which it was
* transmitted/received.
*/
DECLARE_EVENT_CLASS(dpaa_eth_fd,
/* Trace function prototype */
TP_PROTO(struct net_device *netdev,
struct qman_fq *fq,
const struct qm_fd *fd),
/* Repeat argument list here */
TP_ARGS(netdev, fq, fd),
/* A structure containing the relevant information we want to record.
* Declare name and type for each normal element, name, type and size
* for arrays. Use __string for variable length strings.
*/
TP_STRUCT__entry(
__field(u32, fqid)
__field(u64, fd_addr)
__field(u8, fd_format)
__field(u16, fd_offset)
__field(u32, fd_length)
__field(u32, fd_status)
__string(name, netdev->name)
),
/* The function that assigns values to the above declared fields */
TP_fast_assign(
__entry->fqid = fq->fqid;
__entry->fd_addr = qm_fd_addr_get64(fd);
__entry->fd_format = qm_fd_get_format(fd);
__entry->fd_offset = qm_fd_get_offset(fd);
__entry->fd_length = qm_fd_get_length(fd);
__entry->fd_status = __be32_to_cpu(fd->status);
__assign_str(name);
),
/* This is what gets printed when the trace event is triggered */
TP_printk("[%s] fqid=%d, fd: addr=0x%llx, format=%s, off=%u, len=%u, status=0x%08x",
__get_str(name), __entry->fqid, __entry->fd_addr,
__print_symbolic(__entry->fd_format, fd_format_list),
__entry->fd_offset, __entry->fd_length, __entry->fd_status)
);
/* Now declare events of the above type. Format is:
* DEFINE_EVENT(class, name, proto, args), with proto and args same as for class
*/
/* Tx (egress) fd */
DEFINE_EVENT(dpaa_eth_fd, dpaa_tx_fd,
TP_PROTO(struct net_device *netdev,
struct qman_fq *fq,
const struct qm_fd *fd),
TP_ARGS(netdev, fq, fd)
);
/* Rx fd */
DEFINE_EVENT(dpaa_eth_fd, dpaa_rx_fd,
TP_PROTO(struct net_device *netdev,
struct qman_fq *fq,
const struct qm_fd *fd),
TP_ARGS(netdev, fq, fd)
);
/* Tx confirmation fd */
DEFINE_EVENT(dpaa_eth_fd, dpaa_tx_conf_fd,
TP_PROTO(struct net_device *netdev,
struct qman_fq *fq,
const struct qm_fd *fd),
TP_ARGS(netdev, fq, fd)
);
/* If only one event of a certain type needs to be declared, use TRACE_EVENT().
* The syntax is the same as for DECLARE_EVENT_CLASS().
*/
#endif /* _DPAA_ETH_TRACE_H */
/* This must be outside ifdef _DPAA_ETH_TRACE_H */
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH .
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE dpaa_eth_trace
#include <trace/define_trace.h>
@@ -0,0 +1,535 @@
// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later
/*
* Copyright 2008 - 2016 Freescale Semiconductor Inc.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/string.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/net_tstamp.h>
#include <linux/fsl/ptp_qoriq.h>
#include "dpaa_eth.h"
#include "mac.h"
static const char dpaa_stats_percpu[][ETH_GSTRING_LEN] = {
"interrupts",
"rx packets",
"tx packets",
"tx confirm",
"tx S/G",
"tx error",
"rx error",
"rx dropped",
"tx dropped",
};
static char dpaa_stats_global[][ETH_GSTRING_LEN] = {
/* dpa rx errors */
"rx dma error",
"rx frame physical error",
"rx frame size error",
"rx header error",
/* demultiplexing errors */
"qman cg_tdrop",
"qman wred",
"qman error cond",
"qman early window",
"qman late window",
"qman fq tdrop",
"qman fq retired",
"qman orp disabled",
/* congestion related stats */
"congestion time (ms)",
"entered congestion",
"congested (0/1)"
};
#define DPAA_STATS_PERCPU_LEN ARRAY_SIZE(dpaa_stats_percpu)
#define DPAA_STATS_GLOBAL_LEN ARRAY_SIZE(dpaa_stats_global)
static int dpaa_get_link_ksettings(struct net_device *net_dev,
struct ethtool_link_ksettings *cmd)
{
struct dpaa_priv *priv = netdev_priv(net_dev);
struct mac_device *mac_dev = priv->mac_dev;
return phylink_ethtool_ksettings_get(mac_dev->phylink, cmd);
}
static int dpaa_set_link_ksettings(struct net_device *net_dev,
const struct ethtool_link_ksettings *cmd)
{
struct dpaa_priv *priv = netdev_priv(net_dev);
struct mac_device *mac_dev = priv->mac_dev;
return phylink_ethtool_ksettings_set(mac_dev->phylink, cmd);
}
static void dpaa_get_drvinfo(struct net_device *net_dev,
struct ethtool_drvinfo *drvinfo)
{
strscpy(drvinfo->driver, KBUILD_MODNAME,
sizeof(drvinfo->driver));
strscpy(drvinfo->bus_info, dev_name(net_dev->dev.parent->parent),
sizeof(drvinfo->bus_info));
}
static u32 dpaa_get_msglevel(struct net_device *net_dev)
{
return ((struct dpaa_priv *)netdev_priv(net_dev))->msg_enable;
}
static void dpaa_set_msglevel(struct net_device *net_dev,
u32 msg_enable)
{
((struct dpaa_priv *)netdev_priv(net_dev))->msg_enable = msg_enable;
}
static int dpaa_nway_reset(struct net_device *net_dev)
{
struct dpaa_priv *priv = netdev_priv(net_dev);
struct mac_device *mac_dev = priv->mac_dev;
return phylink_ethtool_nway_reset(mac_dev->phylink);
}
static void dpaa_get_pauseparam(struct net_device *net_dev,
struct ethtool_pauseparam *epause)
{
struct dpaa_priv *priv = netdev_priv(net_dev);
struct mac_device *mac_dev = priv->mac_dev;
phylink_ethtool_get_pauseparam(mac_dev->phylink, epause);
}
static int dpaa_set_pauseparam(struct net_device *net_dev,
struct ethtool_pauseparam *epause)
{
struct dpaa_priv *priv = netdev_priv(net_dev);
struct mac_device *mac_dev = priv->mac_dev;
return phylink_ethtool_set_pauseparam(mac_dev->phylink, epause);
}
static int dpaa_get_sset_count(struct net_device *net_dev, int type)
{
unsigned int total_stats, num_stats;
num_stats = num_online_cpus() + 1;
total_stats = num_stats * (DPAA_STATS_PERCPU_LEN + 1) +
DPAA_STATS_GLOBAL_LEN;
switch (type) {
case ETH_SS_STATS:
return total_stats;
default:
return -EOPNOTSUPP;
}
}
static void copy_stats(struct dpaa_percpu_priv *percpu_priv, int num_cpus,
int crr_cpu, u64 bp_count, u64 *data)
{
int num_values = num_cpus + 1;
int crr = 0;
/* update current CPU's stats and also add them to the total values */
data[crr * num_values + crr_cpu] = percpu_priv->in_interrupt;
data[crr++ * num_values + num_cpus] += percpu_priv->in_interrupt;
data[crr * num_values + crr_cpu] = percpu_priv->stats.rx_packets;
data[crr++ * num_values + num_cpus] += percpu_priv->stats.rx_packets;
data[crr * num_values + crr_cpu] = percpu_priv->stats.tx_packets;
data[crr++ * num_values + num_cpus] += percpu_priv->stats.tx_packets;
data[crr * num_values + crr_cpu] = percpu_priv->tx_confirm;
data[crr++ * num_values + num_cpus] += percpu_priv->tx_confirm;
data[crr * num_values + crr_cpu] = percpu_priv->tx_frag_skbuffs;
data[crr++ * num_values + num_cpus] += percpu_priv->tx_frag_skbuffs;
data[crr * num_values + crr_cpu] = percpu_priv->stats.tx_errors;
data[crr++ * num_values + num_cpus] += percpu_priv->stats.tx_errors;
data[crr * num_values + crr_cpu] = percpu_priv->stats.rx_errors;
data[crr++ * num_values + num_cpus] += percpu_priv->stats.rx_errors;
data[crr * num_values + crr_cpu] = percpu_priv->stats.rx_dropped;
data[crr++ * num_values + num_cpus] += percpu_priv->stats.rx_dropped;
data[crr * num_values + crr_cpu] = percpu_priv->stats.tx_dropped;
data[crr++ * num_values + num_cpus] += percpu_priv->stats.tx_dropped;
data[crr * num_values + crr_cpu] = bp_count;
data[crr++ * num_values + num_cpus] += bp_count;
}
static void dpaa_get_ethtool_stats(struct net_device *net_dev,
struct ethtool_stats *stats, u64 *data)
{
struct dpaa_percpu_priv *percpu_priv;
struct dpaa_rx_errors rx_errors;
unsigned int num_cpus, offset;
u64 bp_count, cg_time, cg_num;
struct dpaa_ern_cnt ern_cnt;
struct dpaa_bp *dpaa_bp;
struct dpaa_priv *priv;
int total_stats, i;
bool cg_status;
total_stats = dpaa_get_sset_count(net_dev, ETH_SS_STATS);
priv = netdev_priv(net_dev);
num_cpus = num_online_cpus();
memset(&bp_count, 0, sizeof(bp_count));
memset(&rx_errors, 0, sizeof(struct dpaa_rx_errors));
memset(&ern_cnt, 0, sizeof(struct dpaa_ern_cnt));
memset(data, 0, total_stats * sizeof(u64));
for_each_online_cpu(i) {
percpu_priv = per_cpu_ptr(priv->percpu_priv, i);
dpaa_bp = priv->dpaa_bp;
if (!dpaa_bp->percpu_count)
continue;
bp_count = *(per_cpu_ptr(dpaa_bp->percpu_count, i));
rx_errors.dme += percpu_priv->rx_errors.dme;
rx_errors.fpe += percpu_priv->rx_errors.fpe;
rx_errors.fse += percpu_priv->rx_errors.fse;
rx_errors.phe += percpu_priv->rx_errors.phe;
ern_cnt.cg_tdrop += percpu_priv->ern_cnt.cg_tdrop;
ern_cnt.wred += percpu_priv->ern_cnt.wred;
ern_cnt.err_cond += percpu_priv->ern_cnt.err_cond;
ern_cnt.early_window += percpu_priv->ern_cnt.early_window;
ern_cnt.late_window += percpu_priv->ern_cnt.late_window;
ern_cnt.fq_tdrop += percpu_priv->ern_cnt.fq_tdrop;
ern_cnt.fq_retired += percpu_priv->ern_cnt.fq_retired;
ern_cnt.orp_zero += percpu_priv->ern_cnt.orp_zero;
copy_stats(percpu_priv, num_cpus, i, bp_count, data);
}
offset = (num_cpus + 1) * (DPAA_STATS_PERCPU_LEN + 1);
memcpy(data + offset, &rx_errors, sizeof(struct dpaa_rx_errors));
offset += sizeof(struct dpaa_rx_errors) / sizeof(u64);
memcpy(data + offset, &ern_cnt, sizeof(struct dpaa_ern_cnt));
/* gather congestion related counters */
cg_num = 0;
cg_status = false;
cg_time = jiffies_to_msecs(priv->cgr_data.congested_jiffies);
if (qman_query_cgr_congested(&priv->cgr_data.cgr, &cg_status) == 0) {
cg_num = priv->cgr_data.cgr_congested_count;
/* reset congestion stats (like QMan API does */
priv->cgr_data.congested_jiffies = 0;
priv->cgr_data.cgr_congested_count = 0;
}
offset += sizeof(struct dpaa_ern_cnt) / sizeof(u64);
data[offset++] = cg_time;
data[offset++] = cg_num;
data[offset++] = cg_status;
}
static void dpaa_get_strings(struct net_device *net_dev, u32 stringset,
u8 *data)
{
unsigned int i, j, num_cpus;
num_cpus = num_online_cpus();
for (i = 0; i < DPAA_STATS_PERCPU_LEN; i++) {
for (j = 0; j < num_cpus; j++)
ethtool_sprintf(&data, "%s [CPU %d]",
dpaa_stats_percpu[i], j);
ethtool_sprintf(&data, "%s [TOTAL]", dpaa_stats_percpu[i]);
}
for (i = 0; i < num_cpus; i++)
ethtool_sprintf(&data, "bpool [CPU %d]", i);
ethtool_puts(&data, "bpool [TOTAL]");
for (i = 0; i < DPAA_STATS_GLOBAL_LEN; i++)
ethtool_puts(&data, dpaa_stats_global[i]);
}
static int dpaa_get_rxfh_fields(struct net_device *dev,
struct ethtool_rxfh_fields *cmd)
{
struct dpaa_priv *priv = netdev_priv(dev);
cmd->data = 0;
switch (cmd->flow_type) {
case TCP_V4_FLOW:
case TCP_V6_FLOW:
case UDP_V4_FLOW:
case UDP_V6_FLOW:
if (priv->keygen_in_use)
cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
fallthrough;
case IPV4_FLOW:
case IPV6_FLOW:
case SCTP_V4_FLOW:
case SCTP_V6_FLOW:
case AH_ESP_V4_FLOW:
case AH_ESP_V6_FLOW:
case AH_V4_FLOW:
case AH_V6_FLOW:
case ESP_V4_FLOW:
case ESP_V6_FLOW:
if (priv->keygen_in_use)
cmd->data |= RXH_IP_SRC | RXH_IP_DST;
break;
default:
cmd->data = 0;
break;
}
return 0;
}
static void dpaa_set_hash(struct net_device *net_dev, bool enable)
{
struct mac_device *mac_dev;
struct fman_port *rxport;
struct dpaa_priv *priv;
priv = netdev_priv(net_dev);
mac_dev = priv->mac_dev;
rxport = mac_dev->port[0];
fman_port_use_kg_hash(rxport, enable);
priv->keygen_in_use = enable;
}
static int dpaa_set_rxfh_fields(struct net_device *dev,
const struct ethtool_rxfh_fields *nfc,
struct netlink_ext_ack *extack)
{
int ret = -EINVAL;
/* we support hashing on IPv4/v6 src/dest IP and L4 src/dest port */
if (nfc->data &
~(RXH_IP_SRC | RXH_IP_DST | RXH_L4_B_0_1 | RXH_L4_B_2_3))
return -EINVAL;
switch (nfc->flow_type) {
case TCP_V4_FLOW:
case TCP_V6_FLOW:
case UDP_V4_FLOW:
case UDP_V6_FLOW:
case IPV4_FLOW:
case IPV6_FLOW:
case SCTP_V4_FLOW:
case SCTP_V6_FLOW:
case AH_ESP_V4_FLOW:
case AH_ESP_V6_FLOW:
case AH_V4_FLOW:
case AH_V6_FLOW:
case ESP_V4_FLOW:
case ESP_V6_FLOW:
dpaa_set_hash(dev, !!nfc->data);
ret = 0;
break;
default:
break;
}
return ret;
}
static int dpaa_get_ts_info(struct net_device *net_dev,
struct kernel_ethtool_ts_info *info)
{
struct device *dev = net_dev->dev.parent;
struct device_node *mac_node = dev->of_node;
struct device_node *fman_node = NULL, *ptp_node = NULL;
struct platform_device *ptp_dev = NULL;
struct ptp_qoriq *ptp = NULL;
info->phc_index = -1;
fman_node = of_get_parent(mac_node);
if (fman_node) {
ptp_node = of_parse_phandle(fman_node, "ptimer-handle", 0);
of_node_put(fman_node);
}
if (ptp_node) {
ptp_dev = of_find_device_by_node(ptp_node);
of_node_put(ptp_node);
}
if (ptp_dev) {
ptp = platform_get_drvdata(ptp_dev);
put_device(&ptp_dev->dev);
}
if (ptp)
info->phc_index = ptp->phc_index;
info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
SOF_TIMESTAMPING_RX_HARDWARE |
SOF_TIMESTAMPING_RAW_HARDWARE;
info->tx_types = (1 << HWTSTAMP_TX_OFF) |
(1 << HWTSTAMP_TX_ON);
info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
(1 << HWTSTAMP_FILTER_ALL);
return 0;
}
static int dpaa_get_coalesce(struct net_device *dev,
struct ethtool_coalesce *c,
struct kernel_ethtool_coalesce *kernel_coal,
struct netlink_ext_ack *extack)
{
struct qman_portal *portal;
u32 period;
u8 thresh;
portal = qman_get_affine_portal(smp_processor_id());
qman_portal_get_iperiod(portal, &period);
qman_dqrr_get_ithresh(portal, &thresh);
c->rx_coalesce_usecs = period;
c->rx_max_coalesced_frames = thresh;
return 0;
}
static int dpaa_set_coalesce(struct net_device *dev,
struct ethtool_coalesce *c,
struct kernel_ethtool_coalesce *kernel_coal,
struct netlink_ext_ack *extack)
{
const cpumask_t *cpus = qman_affine_cpus();
struct qman_portal *portal;
u32 period, prev_period;
u8 thresh, prev_thresh;
bool *needs_revert;
int cpu, res;
needs_revert = kzalloc_objs(bool, num_possible_cpus());
if (!needs_revert)
return -ENOMEM;
period = c->rx_coalesce_usecs;
thresh = c->rx_max_coalesced_frames;
/* save previous values */
portal = qman_get_affine_portal(smp_processor_id());
qman_portal_get_iperiod(portal, &prev_period);
qman_dqrr_get_ithresh(portal, &prev_thresh);
/* set new values */
for_each_cpu_and(cpu, cpus, cpu_online_mask) {
portal = qman_get_affine_portal(cpu);
res = qman_portal_set_iperiod(portal, period);
if (res)
goto revert_values;
res = qman_dqrr_set_ithresh(portal, thresh);
if (res) {
qman_portal_set_iperiod(portal, prev_period);
goto revert_values;
}
needs_revert[cpu] = true;
}
kfree(needs_revert);
return 0;
revert_values:
/* restore previous values */
for_each_cpu_and(cpu, cpus, cpu_online_mask) {
if (!needs_revert[cpu])
continue;
portal = qman_get_affine_portal(cpu);
/* previous values will not fail, ignore return value */
qman_portal_set_iperiod(portal, prev_period);
qman_dqrr_set_ithresh(portal, prev_thresh);
}
kfree(needs_revert);
return res;
}
static void dpaa_get_pause_stats(struct net_device *net_dev,
struct ethtool_pause_stats *s)
{
struct dpaa_priv *priv = netdev_priv(net_dev);
struct mac_device *mac_dev = priv->mac_dev;
if (mac_dev->get_pause_stats)
mac_dev->get_pause_stats(mac_dev->fman_mac, s);
}
static void dpaa_get_rmon_stats(struct net_device *net_dev,
struct ethtool_rmon_stats *s,
const struct ethtool_rmon_hist_range **ranges)
{
struct dpaa_priv *priv = netdev_priv(net_dev);
struct mac_device *mac_dev = priv->mac_dev;
if (mac_dev->get_rmon_stats)
mac_dev->get_rmon_stats(mac_dev->fman_mac, s, ranges);
}
static void dpaa_get_eth_ctrl_stats(struct net_device *net_dev,
struct ethtool_eth_ctrl_stats *s)
{
struct dpaa_priv *priv = netdev_priv(net_dev);
struct mac_device *mac_dev = priv->mac_dev;
if (mac_dev->get_eth_ctrl_stats)
mac_dev->get_eth_ctrl_stats(mac_dev->fman_mac, s);
}
static void dpaa_get_eth_mac_stats(struct net_device *net_dev,
struct ethtool_eth_mac_stats *s)
{
struct dpaa_priv *priv = netdev_priv(net_dev);
struct mac_device *mac_dev = priv->mac_dev;
if (mac_dev->get_eth_mac_stats)
mac_dev->get_eth_mac_stats(mac_dev->fman_mac, s);
}
const struct ethtool_ops dpaa_ethtool_ops = {
.supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
ETHTOOL_COALESCE_RX_MAX_FRAMES,
.get_drvinfo = dpaa_get_drvinfo,
.get_msglevel = dpaa_get_msglevel,
.set_msglevel = dpaa_set_msglevel,
.nway_reset = dpaa_nway_reset,
.get_pauseparam = dpaa_get_pauseparam,
.set_pauseparam = dpaa_set_pauseparam,
.get_link = ethtool_op_get_link,
.get_sset_count = dpaa_get_sset_count,
.get_ethtool_stats = dpaa_get_ethtool_stats,
.get_strings = dpaa_get_strings,
.get_link_ksettings = dpaa_get_link_ksettings,
.set_link_ksettings = dpaa_set_link_ksettings,
.get_rxfh_fields = dpaa_get_rxfh_fields,
.set_rxfh_fields = dpaa_set_rxfh_fields,
.get_ts_info = dpaa_get_ts_info,
.get_coalesce = dpaa_get_coalesce,
.set_coalesce = dpaa_set_coalesce,
.get_pause_stats = dpaa_get_pause_stats,
.get_rmon_stats = dpaa_get_rmon_stats,
.get_eth_ctrl_stats = dpaa_get_eth_ctrl_stats,
.get_eth_mac_stats = dpaa_get_eth_mac_stats,
};