162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci#ifndef _FUNETH_H 462306a36Sopenharmony_ci#define _FUNETH_H 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#include <uapi/linux/if_ether.h> 762306a36Sopenharmony_ci#include <uapi/linux/net_tstamp.h> 862306a36Sopenharmony_ci#include <linux/mutex.h> 962306a36Sopenharmony_ci#include <linux/seqlock.h> 1062306a36Sopenharmony_ci#include <linux/xarray.h> 1162306a36Sopenharmony_ci#include <net/devlink.h> 1262306a36Sopenharmony_ci#include "fun_dev.h" 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#define ADMIN_SQE_SIZE SZ_128 1562306a36Sopenharmony_ci#define ADMIN_CQE_SIZE SZ_64 1662306a36Sopenharmony_ci#define ADMIN_RSP_MAX_LEN (ADMIN_CQE_SIZE - sizeof(struct fun_cqe_info)) 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#define FUN_MAX_MTU 9024 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#define SQ_DEPTH 512U 2162306a36Sopenharmony_ci#define CQ_DEPTH 1024U 2262306a36Sopenharmony_ci#define RQ_DEPTH (512U / (PAGE_SIZE / 4096)) 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#define CQ_INTCOAL_USEC 10 2562306a36Sopenharmony_ci#define CQ_INTCOAL_NPKT 16 2662306a36Sopenharmony_ci#define SQ_INTCOAL_USEC 10 2762306a36Sopenharmony_ci#define SQ_INTCOAL_NPKT 16 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#define INVALID_LPORT 0xffff 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#define FUN_PORT_CAP_PAUSE_MASK (FUN_PORT_CAP_TX_PAUSE | FUN_PORT_CAP_RX_PAUSE) 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_cistruct fun_vport_info { 3462306a36Sopenharmony_ci u8 mac[ETH_ALEN]; 3562306a36Sopenharmony_ci u16 vlan; 3662306a36Sopenharmony_ci __be16 vlan_proto; 3762306a36Sopenharmony_ci u8 qos; 3862306a36Sopenharmony_ci u8 spoofchk:1; 3962306a36Sopenharmony_ci u8 trusted:1; 4062306a36Sopenharmony_ci unsigned int max_rate; 4162306a36Sopenharmony_ci}; 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci/* "subclass" of fun_dev for Ethernet functions */ 4462306a36Sopenharmony_cistruct fun_ethdev { 4562306a36Sopenharmony_ci struct fun_dev fdev; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci /* the function's network ports */ 4862306a36Sopenharmony_ci struct net_device **netdevs; 4962306a36Sopenharmony_ci unsigned int num_ports; 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci /* configuration for the function's virtual ports */ 5262306a36Sopenharmony_ci unsigned int num_vports; 5362306a36Sopenharmony_ci struct fun_vport_info *vport_info; 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci struct mutex state_mutex; /* nests inside RTNL if both taken */ 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci unsigned int nsqs_per_port; 5862306a36Sopenharmony_ci}; 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_cistatic inline struct fun_ethdev *to_fun_ethdev(struct fun_dev *p) 6162306a36Sopenharmony_ci{ 6262306a36Sopenharmony_ci return container_of(p, struct fun_ethdev, fdev); 6362306a36Sopenharmony_ci} 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_cistruct fun_qset { 6662306a36Sopenharmony_ci struct funeth_rxq **rxqs; 6762306a36Sopenharmony_ci struct funeth_txq **txqs; 6862306a36Sopenharmony_ci struct funeth_txq **xdpqs; 6962306a36Sopenharmony_ci unsigned int nrxqs; 7062306a36Sopenharmony_ci unsigned int ntxqs; 7162306a36Sopenharmony_ci unsigned int nxdpqs; 7262306a36Sopenharmony_ci unsigned int rxq_start; 7362306a36Sopenharmony_ci unsigned int txq_start; 7462306a36Sopenharmony_ci unsigned int xdpq_start; 7562306a36Sopenharmony_ci unsigned int cq_depth; 7662306a36Sopenharmony_ci unsigned int rq_depth; 7762306a36Sopenharmony_ci unsigned int sq_depth; 7862306a36Sopenharmony_ci int state; 7962306a36Sopenharmony_ci}; 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci/* Per netdevice driver state, i.e., netdev_priv. */ 8262306a36Sopenharmony_cistruct funeth_priv { 8362306a36Sopenharmony_ci struct fun_dev *fdev; 8462306a36Sopenharmony_ci struct pci_dev *pdev; 8562306a36Sopenharmony_ci struct net_device *netdev; 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci struct funeth_rxq * __rcu *rxqs; 8862306a36Sopenharmony_ci struct funeth_txq **txqs; 8962306a36Sopenharmony_ci struct funeth_txq * __rcu *xdpqs; 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci struct xarray irqs; 9262306a36Sopenharmony_ci unsigned int num_tx_irqs; 9362306a36Sopenharmony_ci unsigned int num_rx_irqs; 9462306a36Sopenharmony_ci unsigned int rx_irq_ofst; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci unsigned int lane_attrs; 9762306a36Sopenharmony_ci u16 lport; 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci /* link settings */ 10062306a36Sopenharmony_ci u64 port_caps; 10162306a36Sopenharmony_ci u64 advertising; 10262306a36Sopenharmony_ci u64 lp_advertising; 10362306a36Sopenharmony_ci unsigned int link_speed; 10462306a36Sopenharmony_ci u8 xcvr_type; 10562306a36Sopenharmony_ci u8 active_fc; 10662306a36Sopenharmony_ci u8 active_fec; 10762306a36Sopenharmony_ci u8 link_down_reason; 10862306a36Sopenharmony_ci seqcount_t link_seq; 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci u32 msg_enable; 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci unsigned int num_xdpqs; 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci /* ethtool, etc. config parameters */ 11562306a36Sopenharmony_ci unsigned int sq_depth; 11662306a36Sopenharmony_ci unsigned int rq_depth; 11762306a36Sopenharmony_ci unsigned int cq_depth; 11862306a36Sopenharmony_ci unsigned int cq_irq_db; 11962306a36Sopenharmony_ci u8 tx_coal_usec; 12062306a36Sopenharmony_ci u8 tx_coal_count; 12162306a36Sopenharmony_ci u8 rx_coal_usec; 12262306a36Sopenharmony_ci u8 rx_coal_count; 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci struct hwtstamp_config hwtstamp_cfg; 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci /* cumulative queue stats from earlier queue instances */ 12762306a36Sopenharmony_ci u64 tx_packets; 12862306a36Sopenharmony_ci u64 tx_bytes; 12962306a36Sopenharmony_ci u64 tx_dropped; 13062306a36Sopenharmony_ci u64 rx_packets; 13162306a36Sopenharmony_ci u64 rx_bytes; 13262306a36Sopenharmony_ci u64 rx_dropped; 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci /* RSS */ 13562306a36Sopenharmony_ci unsigned int rss_hw_id; 13662306a36Sopenharmony_ci enum fun_eth_hash_alg hash_algo; 13762306a36Sopenharmony_ci u8 rss_key[FUN_ETH_RSS_MAX_KEY_SIZE]; 13862306a36Sopenharmony_ci unsigned int indir_table_nentries; 13962306a36Sopenharmony_ci u32 indir_table[FUN_ETH_RSS_MAX_INDIR_ENT]; 14062306a36Sopenharmony_ci dma_addr_t rss_dma_addr; 14162306a36Sopenharmony_ci void *rss_cfg; 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci /* DMA area for port stats */ 14462306a36Sopenharmony_ci dma_addr_t stats_dma_addr; 14562306a36Sopenharmony_ci __be64 *stats; 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci struct bpf_prog *xdp_prog; 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci struct devlink_port dl_port; 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci /* kTLS state */ 15262306a36Sopenharmony_ci unsigned int ktls_id; 15362306a36Sopenharmony_ci atomic64_t tx_tls_add; 15462306a36Sopenharmony_ci atomic64_t tx_tls_del; 15562306a36Sopenharmony_ci atomic64_t tx_tls_resync; 15662306a36Sopenharmony_ci}; 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_civoid fun_set_ethtool_ops(struct net_device *netdev); 15962306a36Sopenharmony_ciint fun_port_write_cmd(struct funeth_priv *fp, int key, u64 data); 16062306a36Sopenharmony_ciint fun_port_read_cmd(struct funeth_priv *fp, int key, u64 *data); 16162306a36Sopenharmony_ciint fun_create_and_bind_tx(struct funeth_priv *fp, u32 sqid); 16262306a36Sopenharmony_ciint fun_replace_queues(struct net_device *dev, struct fun_qset *newqs, 16362306a36Sopenharmony_ci struct netlink_ext_ack *extack); 16462306a36Sopenharmony_ciint fun_change_num_queues(struct net_device *dev, unsigned int ntx, 16562306a36Sopenharmony_ci unsigned int nrx); 16662306a36Sopenharmony_civoid fun_set_ring_count(struct net_device *netdev, unsigned int ntx, 16762306a36Sopenharmony_ci unsigned int nrx); 16862306a36Sopenharmony_ciint fun_config_rss(struct net_device *dev, int algo, const u8 *key, 16962306a36Sopenharmony_ci const u32 *qtable, u8 op); 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci#endif /* _FUNETH_H */ 172