162306a36Sopenharmony_ci/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright 2008 - 2016 Freescale Semiconductor Inc. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef __DPAA_H 762306a36Sopenharmony_ci#define __DPAA_H 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/netdevice.h> 1062306a36Sopenharmony_ci#include <linux/refcount.h> 1162306a36Sopenharmony_ci#include <net/xdp.h> 1262306a36Sopenharmony_ci#include <soc/fsl/qman.h> 1362306a36Sopenharmony_ci#include <soc/fsl/bman.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include "fman.h" 1662306a36Sopenharmony_ci#include "mac.h" 1762306a36Sopenharmony_ci#include "dpaa_eth_trace.h" 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* Number of prioritised traffic classes */ 2062306a36Sopenharmony_ci#define DPAA_TC_NUM 4 2162306a36Sopenharmony_ci/* Number of Tx queues per traffic class */ 2262306a36Sopenharmony_ci#define DPAA_TC_TXQ_NUM NR_CPUS 2362306a36Sopenharmony_ci/* Total number of Tx queues */ 2462306a36Sopenharmony_ci#define DPAA_ETH_TXQ_NUM (DPAA_TC_NUM * DPAA_TC_TXQ_NUM) 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/* More detailed FQ types - used for fine-grained WQ assignments */ 2762306a36Sopenharmony_cienum dpaa_fq_type { 2862306a36Sopenharmony_ci FQ_TYPE_RX_DEFAULT = 1, /* Rx Default FQs */ 2962306a36Sopenharmony_ci FQ_TYPE_RX_ERROR, /* Rx Error FQs */ 3062306a36Sopenharmony_ci FQ_TYPE_RX_PCD, /* Rx Parse Classify Distribute FQs */ 3162306a36Sopenharmony_ci FQ_TYPE_TX, /* "Real" Tx FQs */ 3262306a36Sopenharmony_ci FQ_TYPE_TX_CONFIRM, /* Tx default Conf FQ (actually an Rx FQ) */ 3362306a36Sopenharmony_ci FQ_TYPE_TX_CONF_MQ, /* Tx conf FQs (one for each Tx FQ) */ 3462306a36Sopenharmony_ci FQ_TYPE_TX_ERROR, /* Tx Error FQs (these are actually Rx FQs) */ 3562306a36Sopenharmony_ci}; 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_cistruct dpaa_fq { 3862306a36Sopenharmony_ci struct qman_fq fq_base; 3962306a36Sopenharmony_ci struct list_head list; 4062306a36Sopenharmony_ci struct net_device *net_dev; 4162306a36Sopenharmony_ci bool init; 4262306a36Sopenharmony_ci u32 fqid; 4362306a36Sopenharmony_ci u32 flags; 4462306a36Sopenharmony_ci u16 channel; 4562306a36Sopenharmony_ci u8 wq; 4662306a36Sopenharmony_ci enum dpaa_fq_type fq_type; 4762306a36Sopenharmony_ci struct xdp_rxq_info xdp_rxq; 4862306a36Sopenharmony_ci}; 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_cistruct dpaa_fq_cbs { 5162306a36Sopenharmony_ci struct qman_fq rx_defq; 5262306a36Sopenharmony_ci struct qman_fq tx_defq; 5362306a36Sopenharmony_ci struct qman_fq rx_errq; 5462306a36Sopenharmony_ci struct qman_fq tx_errq; 5562306a36Sopenharmony_ci struct qman_fq egress_ern; 5662306a36Sopenharmony_ci}; 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_cistruct dpaa_priv; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_cistruct dpaa_bp { 6162306a36Sopenharmony_ci /* used in the DMA mapping operations */ 6262306a36Sopenharmony_ci struct dpaa_priv *priv; 6362306a36Sopenharmony_ci /* current number of buffers in the buffer pool alloted to each CPU */ 6462306a36Sopenharmony_ci int __percpu *percpu_count; 6562306a36Sopenharmony_ci /* all buffers allocated for this pool have this raw size */ 6662306a36Sopenharmony_ci size_t raw_size; 6762306a36Sopenharmony_ci /* all buffers in this pool have this same usable size */ 6862306a36Sopenharmony_ci size_t size; 6962306a36Sopenharmony_ci /* the buffer pools are initialized with config_count buffers for each 7062306a36Sopenharmony_ci * CPU; at runtime the number of buffers per CPU is constantly brought 7162306a36Sopenharmony_ci * back to this level 7262306a36Sopenharmony_ci */ 7362306a36Sopenharmony_ci u16 config_count; 7462306a36Sopenharmony_ci u8 bpid; 7562306a36Sopenharmony_ci struct bman_pool *pool; 7662306a36Sopenharmony_ci /* bpool can be seeded before use by this cb */ 7762306a36Sopenharmony_ci int (*seed_cb)(struct dpaa_bp *); 7862306a36Sopenharmony_ci /* bpool can be emptied before freeing by this cb */ 7962306a36Sopenharmony_ci void (*free_buf_cb)(const struct dpaa_bp *, struct bm_buffer *); 8062306a36Sopenharmony_ci refcount_t refs; 8162306a36Sopenharmony_ci}; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_cistruct dpaa_rx_errors { 8462306a36Sopenharmony_ci u64 dme; /* DMA Error */ 8562306a36Sopenharmony_ci u64 fpe; /* Frame Physical Error */ 8662306a36Sopenharmony_ci u64 fse; /* Frame Size Error */ 8762306a36Sopenharmony_ci u64 phe; /* Header Error */ 8862306a36Sopenharmony_ci}; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci/* Counters for QMan ERN frames - one counter per rejection code */ 9162306a36Sopenharmony_cistruct dpaa_ern_cnt { 9262306a36Sopenharmony_ci u64 cg_tdrop; /* Congestion group taildrop */ 9362306a36Sopenharmony_ci u64 wred; /* WRED congestion */ 9462306a36Sopenharmony_ci u64 err_cond; /* Error condition */ 9562306a36Sopenharmony_ci u64 early_window; /* Order restoration, frame too early */ 9662306a36Sopenharmony_ci u64 late_window; /* Order restoration, frame too late */ 9762306a36Sopenharmony_ci u64 fq_tdrop; /* FQ taildrop */ 9862306a36Sopenharmony_ci u64 fq_retired; /* FQ is retired */ 9962306a36Sopenharmony_ci u64 orp_zero; /* ORP disabled */ 10062306a36Sopenharmony_ci}; 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_cistruct dpaa_napi_portal { 10362306a36Sopenharmony_ci struct napi_struct napi; 10462306a36Sopenharmony_ci struct qman_portal *p; 10562306a36Sopenharmony_ci bool down; 10662306a36Sopenharmony_ci int xdp_act; 10762306a36Sopenharmony_ci}; 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_cistruct dpaa_percpu_priv { 11062306a36Sopenharmony_ci struct net_device *net_dev; 11162306a36Sopenharmony_ci struct dpaa_napi_portal np; 11262306a36Sopenharmony_ci u64 in_interrupt; 11362306a36Sopenharmony_ci u64 tx_confirm; 11462306a36Sopenharmony_ci /* fragmented (non-linear) skbuffs received from the stack */ 11562306a36Sopenharmony_ci u64 tx_frag_skbuffs; 11662306a36Sopenharmony_ci struct rtnl_link_stats64 stats; 11762306a36Sopenharmony_ci struct dpaa_rx_errors rx_errors; 11862306a36Sopenharmony_ci struct dpaa_ern_cnt ern_cnt; 11962306a36Sopenharmony_ci}; 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_cistruct dpaa_buffer_layout { 12262306a36Sopenharmony_ci u16 priv_data_size; 12362306a36Sopenharmony_ci}; 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci/* Information to be used on the Tx confirmation path. Stored just 12662306a36Sopenharmony_ci * before the start of the transmit buffer. Maximum size allowed 12762306a36Sopenharmony_ci * is DPAA_TX_PRIV_DATA_SIZE bytes. 12862306a36Sopenharmony_ci */ 12962306a36Sopenharmony_cistruct dpaa_eth_swbp { 13062306a36Sopenharmony_ci struct sk_buff *skb; 13162306a36Sopenharmony_ci struct xdp_frame *xdpf; 13262306a36Sopenharmony_ci}; 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_cistruct dpaa_priv { 13562306a36Sopenharmony_ci struct dpaa_percpu_priv __percpu *percpu_priv; 13662306a36Sopenharmony_ci struct dpaa_bp *dpaa_bp; 13762306a36Sopenharmony_ci /* Store here the needed Tx headroom for convenience and speed 13862306a36Sopenharmony_ci * (even though it can be computed based on the fields of buf_layout) 13962306a36Sopenharmony_ci */ 14062306a36Sopenharmony_ci u16 tx_headroom; 14162306a36Sopenharmony_ci struct net_device *net_dev; 14262306a36Sopenharmony_ci struct mac_device *mac_dev; 14362306a36Sopenharmony_ci struct device *rx_dma_dev; 14462306a36Sopenharmony_ci struct device *tx_dma_dev; 14562306a36Sopenharmony_ci struct qman_fq *egress_fqs[DPAA_ETH_TXQ_NUM]; 14662306a36Sopenharmony_ci struct qman_fq *conf_fqs[DPAA_ETH_TXQ_NUM]; 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci u16 channel; 14962306a36Sopenharmony_ci struct list_head dpaa_fq_list; 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci u8 num_tc; 15262306a36Sopenharmony_ci bool keygen_in_use; 15362306a36Sopenharmony_ci u32 msg_enable; /* net_device message level */ 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci struct { 15662306a36Sopenharmony_ci /* All egress queues to a given net device belong to one 15762306a36Sopenharmony_ci * (and the same) congestion group. 15862306a36Sopenharmony_ci */ 15962306a36Sopenharmony_ci struct qman_cgr cgr; 16062306a36Sopenharmony_ci /* If congested, when it began. Used for performance stats. */ 16162306a36Sopenharmony_ci u32 congestion_start_jiffies; 16262306a36Sopenharmony_ci /* Number of jiffies the Tx port was congested. */ 16362306a36Sopenharmony_ci u32 congested_jiffies; 16462306a36Sopenharmony_ci /* Counter for the number of times the CGR 16562306a36Sopenharmony_ci * entered congestion state 16662306a36Sopenharmony_ci */ 16762306a36Sopenharmony_ci u32 cgr_congested_count; 16862306a36Sopenharmony_ci } cgr_data; 16962306a36Sopenharmony_ci /* Use a per-port CGR for ingress traffic. */ 17062306a36Sopenharmony_ci bool use_ingress_cgr; 17162306a36Sopenharmony_ci struct qman_cgr ingress_cgr; 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci struct dpaa_buffer_layout buf_layout[2]; 17462306a36Sopenharmony_ci u16 rx_headroom; 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci bool tx_tstamp; /* Tx timestamping enabled */ 17762306a36Sopenharmony_ci bool rx_tstamp; /* Rx timestamping enabled */ 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci struct bpf_prog *xdp_prog; 18062306a36Sopenharmony_ci}; 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci/* from dpaa_ethtool.c */ 18362306a36Sopenharmony_ciextern const struct ethtool_ops dpaa_ethtool_ops; 18462306a36Sopenharmony_ci 18562306a36Sopenharmony_ci/* from dpaa_eth_sysfs.c */ 18662306a36Sopenharmony_civoid dpaa_eth_sysfs_remove(struct device *dev); 18762306a36Sopenharmony_civoid dpaa_eth_sysfs_init(struct device *dev); 18862306a36Sopenharmony_ci#endif /* __DPAA_H */ 189