18c2ecf20Sopenharmony_ci/* Copyright 2008 - 2016 Freescale Semiconductor Inc. 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 48c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 58c2ecf20Sopenharmony_ci * * Redistributions of source code must retain the above copyright 68c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 78c2ecf20Sopenharmony_ci * * Redistributions in binary form must reproduce the above copyright 88c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 98c2ecf20Sopenharmony_ci * documentation and/or other materials provided with the distribution. 108c2ecf20Sopenharmony_ci * * Neither the name of Freescale Semiconductor nor the 118c2ecf20Sopenharmony_ci * names of its contributors may be used to endorse or promote products 128c2ecf20Sopenharmony_ci * derived from this software without specific prior written permission. 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * ALTERNATIVELY, this software may be distributed under the terms of the 158c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") as published by the Free Software 168c2ecf20Sopenharmony_ci * Foundation, either version 2 of that License or (at your option) any 178c2ecf20Sopenharmony_ci * later version. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY 208c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 218c2ecf20Sopenharmony_ci * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 228c2ecf20Sopenharmony_ci * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY 238c2ecf20Sopenharmony_ci * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 248c2ecf20Sopenharmony_ci * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 258c2ecf20Sopenharmony_ci * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 268c2ecf20Sopenharmony_ci * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 278c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 288c2ecf20Sopenharmony_ci * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 298c2ecf20Sopenharmony_ci */ 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#ifndef __DPAA_H 328c2ecf20Sopenharmony_ci#define __DPAA_H 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 358c2ecf20Sopenharmony_ci#include <linux/refcount.h> 368c2ecf20Sopenharmony_ci#include <soc/fsl/qman.h> 378c2ecf20Sopenharmony_ci#include <soc/fsl/bman.h> 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#include "fman.h" 408c2ecf20Sopenharmony_ci#include "mac.h" 418c2ecf20Sopenharmony_ci#include "dpaa_eth_trace.h" 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* Number of prioritised traffic classes */ 448c2ecf20Sopenharmony_ci#define DPAA_TC_NUM 4 458c2ecf20Sopenharmony_ci/* Number of Tx queues per traffic class */ 468c2ecf20Sopenharmony_ci#define DPAA_TC_TXQ_NUM NR_CPUS 478c2ecf20Sopenharmony_ci/* Total number of Tx queues */ 488c2ecf20Sopenharmony_ci#define DPAA_ETH_TXQ_NUM (DPAA_TC_NUM * DPAA_TC_TXQ_NUM) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci/* More detailed FQ types - used for fine-grained WQ assignments */ 518c2ecf20Sopenharmony_cienum dpaa_fq_type { 528c2ecf20Sopenharmony_ci FQ_TYPE_RX_DEFAULT = 1, /* Rx Default FQs */ 538c2ecf20Sopenharmony_ci FQ_TYPE_RX_ERROR, /* Rx Error FQs */ 548c2ecf20Sopenharmony_ci FQ_TYPE_RX_PCD, /* Rx Parse Classify Distribute FQs */ 558c2ecf20Sopenharmony_ci FQ_TYPE_TX, /* "Real" Tx FQs */ 568c2ecf20Sopenharmony_ci FQ_TYPE_TX_CONFIRM, /* Tx default Conf FQ (actually an Rx FQ) */ 578c2ecf20Sopenharmony_ci FQ_TYPE_TX_CONF_MQ, /* Tx conf FQs (one for each Tx FQ) */ 588c2ecf20Sopenharmony_ci FQ_TYPE_TX_ERROR, /* Tx Error FQs (these are actually Rx FQs) */ 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistruct dpaa_fq { 628c2ecf20Sopenharmony_ci struct qman_fq fq_base; 638c2ecf20Sopenharmony_ci struct list_head list; 648c2ecf20Sopenharmony_ci struct net_device *net_dev; 658c2ecf20Sopenharmony_ci bool init; 668c2ecf20Sopenharmony_ci u32 fqid; 678c2ecf20Sopenharmony_ci u32 flags; 688c2ecf20Sopenharmony_ci u16 channel; 698c2ecf20Sopenharmony_ci u8 wq; 708c2ecf20Sopenharmony_ci enum dpaa_fq_type fq_type; 718c2ecf20Sopenharmony_ci}; 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistruct dpaa_fq_cbs { 748c2ecf20Sopenharmony_ci struct qman_fq rx_defq; 758c2ecf20Sopenharmony_ci struct qman_fq tx_defq; 768c2ecf20Sopenharmony_ci struct qman_fq rx_errq; 778c2ecf20Sopenharmony_ci struct qman_fq tx_errq; 788c2ecf20Sopenharmony_ci struct qman_fq egress_ern; 798c2ecf20Sopenharmony_ci}; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistruct dpaa_priv; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistruct dpaa_bp { 848c2ecf20Sopenharmony_ci /* used in the DMA mapping operations */ 858c2ecf20Sopenharmony_ci struct dpaa_priv *priv; 868c2ecf20Sopenharmony_ci /* current number of buffers in the buffer pool alloted to each CPU */ 878c2ecf20Sopenharmony_ci int __percpu *percpu_count; 888c2ecf20Sopenharmony_ci /* all buffers allocated for this pool have this raw size */ 898c2ecf20Sopenharmony_ci size_t raw_size; 908c2ecf20Sopenharmony_ci /* all buffers in this pool have this same usable size */ 918c2ecf20Sopenharmony_ci size_t size; 928c2ecf20Sopenharmony_ci /* the buffer pools are initialized with config_count buffers for each 938c2ecf20Sopenharmony_ci * CPU; at runtime the number of buffers per CPU is constantly brought 948c2ecf20Sopenharmony_ci * back to this level 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci u16 config_count; 978c2ecf20Sopenharmony_ci u8 bpid; 988c2ecf20Sopenharmony_ci struct bman_pool *pool; 998c2ecf20Sopenharmony_ci /* bpool can be seeded before use by this cb */ 1008c2ecf20Sopenharmony_ci int (*seed_cb)(struct dpaa_bp *); 1018c2ecf20Sopenharmony_ci /* bpool can be emptied before freeing by this cb */ 1028c2ecf20Sopenharmony_ci void (*free_buf_cb)(const struct dpaa_bp *, struct bm_buffer *); 1038c2ecf20Sopenharmony_ci refcount_t refs; 1048c2ecf20Sopenharmony_ci}; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistruct dpaa_rx_errors { 1078c2ecf20Sopenharmony_ci u64 dme; /* DMA Error */ 1088c2ecf20Sopenharmony_ci u64 fpe; /* Frame Physical Error */ 1098c2ecf20Sopenharmony_ci u64 fse; /* Frame Size Error */ 1108c2ecf20Sopenharmony_ci u64 phe; /* Header Error */ 1118c2ecf20Sopenharmony_ci}; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/* Counters for QMan ERN frames - one counter per rejection code */ 1148c2ecf20Sopenharmony_cistruct dpaa_ern_cnt { 1158c2ecf20Sopenharmony_ci u64 cg_tdrop; /* Congestion group taildrop */ 1168c2ecf20Sopenharmony_ci u64 wred; /* WRED congestion */ 1178c2ecf20Sopenharmony_ci u64 err_cond; /* Error condition */ 1188c2ecf20Sopenharmony_ci u64 early_window; /* Order restoration, frame too early */ 1198c2ecf20Sopenharmony_ci u64 late_window; /* Order restoration, frame too late */ 1208c2ecf20Sopenharmony_ci u64 fq_tdrop; /* FQ taildrop */ 1218c2ecf20Sopenharmony_ci u64 fq_retired; /* FQ is retired */ 1228c2ecf20Sopenharmony_ci u64 orp_zero; /* ORP disabled */ 1238c2ecf20Sopenharmony_ci}; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistruct dpaa_napi_portal { 1268c2ecf20Sopenharmony_ci struct napi_struct napi; 1278c2ecf20Sopenharmony_ci struct qman_portal *p; 1288c2ecf20Sopenharmony_ci bool down; 1298c2ecf20Sopenharmony_ci}; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_cistruct dpaa_percpu_priv { 1328c2ecf20Sopenharmony_ci struct net_device *net_dev; 1338c2ecf20Sopenharmony_ci struct dpaa_napi_portal np; 1348c2ecf20Sopenharmony_ci u64 in_interrupt; 1358c2ecf20Sopenharmony_ci u64 tx_confirm; 1368c2ecf20Sopenharmony_ci /* fragmented (non-linear) skbuffs received from the stack */ 1378c2ecf20Sopenharmony_ci u64 tx_frag_skbuffs; 1388c2ecf20Sopenharmony_ci struct rtnl_link_stats64 stats; 1398c2ecf20Sopenharmony_ci struct dpaa_rx_errors rx_errors; 1408c2ecf20Sopenharmony_ci struct dpaa_ern_cnt ern_cnt; 1418c2ecf20Sopenharmony_ci}; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistruct dpaa_buffer_layout { 1448c2ecf20Sopenharmony_ci u16 priv_data_size; 1458c2ecf20Sopenharmony_ci}; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_cistruct dpaa_priv { 1488c2ecf20Sopenharmony_ci struct dpaa_percpu_priv __percpu *percpu_priv; 1498c2ecf20Sopenharmony_ci struct dpaa_bp *dpaa_bp; 1508c2ecf20Sopenharmony_ci /* Store here the needed Tx headroom for convenience and speed 1518c2ecf20Sopenharmony_ci * (even though it can be computed based on the fields of buf_layout) 1528c2ecf20Sopenharmony_ci */ 1538c2ecf20Sopenharmony_ci u16 tx_headroom; 1548c2ecf20Sopenharmony_ci struct net_device *net_dev; 1558c2ecf20Sopenharmony_ci struct mac_device *mac_dev; 1568c2ecf20Sopenharmony_ci struct device *rx_dma_dev; 1578c2ecf20Sopenharmony_ci struct device *tx_dma_dev; 1588c2ecf20Sopenharmony_ci struct qman_fq *egress_fqs[DPAA_ETH_TXQ_NUM]; 1598c2ecf20Sopenharmony_ci struct qman_fq *conf_fqs[DPAA_ETH_TXQ_NUM]; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci u16 channel; 1628c2ecf20Sopenharmony_ci struct list_head dpaa_fq_list; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci u8 num_tc; 1658c2ecf20Sopenharmony_ci bool keygen_in_use; 1668c2ecf20Sopenharmony_ci u32 msg_enable; /* net_device message level */ 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci struct { 1698c2ecf20Sopenharmony_ci /* All egress queues to a given net device belong to one 1708c2ecf20Sopenharmony_ci * (and the same) congestion group. 1718c2ecf20Sopenharmony_ci */ 1728c2ecf20Sopenharmony_ci struct qman_cgr cgr; 1738c2ecf20Sopenharmony_ci /* If congested, when it began. Used for performance stats. */ 1748c2ecf20Sopenharmony_ci u32 congestion_start_jiffies; 1758c2ecf20Sopenharmony_ci /* Number of jiffies the Tx port was congested. */ 1768c2ecf20Sopenharmony_ci u32 congested_jiffies; 1778c2ecf20Sopenharmony_ci /* Counter for the number of times the CGR 1788c2ecf20Sopenharmony_ci * entered congestion state 1798c2ecf20Sopenharmony_ci */ 1808c2ecf20Sopenharmony_ci u32 cgr_congested_count; 1818c2ecf20Sopenharmony_ci } cgr_data; 1828c2ecf20Sopenharmony_ci /* Use a per-port CGR for ingress traffic. */ 1838c2ecf20Sopenharmony_ci bool use_ingress_cgr; 1848c2ecf20Sopenharmony_ci struct qman_cgr ingress_cgr; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci struct dpaa_buffer_layout buf_layout[2]; 1878c2ecf20Sopenharmony_ci u16 rx_headroom; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_ci bool tx_tstamp; /* Tx timestamping enabled */ 1908c2ecf20Sopenharmony_ci bool rx_tstamp; /* Rx timestamping enabled */ 1918c2ecf20Sopenharmony_ci}; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci/* from dpaa_ethtool.c */ 1948c2ecf20Sopenharmony_ciextern const struct ethtool_ops dpaa_ethtool_ops; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci/* from dpaa_eth_sysfs.c */ 1978c2ecf20Sopenharmony_civoid dpaa_eth_sysfs_remove(struct device *dev); 1988c2ecf20Sopenharmony_civoid dpaa_eth_sysfs_init(struct device *dev); 1998c2ecf20Sopenharmony_ci#endif /* __DPAA_H */ 200