162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 262306a36Sopenharmony_ci/* Copyright (C) 2015-2018 Netronome Systems, Inc. */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci/* 562306a36Sopenharmony_ci * nfp_main.h 662306a36Sopenharmony_ci * Author: Jason McMullan <jason.mcmullan@netronome.com> 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#ifndef NFP_MAIN_H 1062306a36Sopenharmony_ci#define NFP_MAIN_H 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <linux/ethtool.h> 1362306a36Sopenharmony_ci#include <linux/list.h> 1462306a36Sopenharmony_ci#include <linux/types.h> 1562306a36Sopenharmony_ci#include <linux/pci.h> 1662306a36Sopenharmony_ci#include <linux/workqueue.h> 1762306a36Sopenharmony_ci#include <net/devlink.h> 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_cistruct dentry; 2062306a36Sopenharmony_cistruct device; 2162306a36Sopenharmony_cistruct pci_dev; 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_cistruct nfp_cpp; 2462306a36Sopenharmony_cistruct nfp_cpp_area; 2562306a36Sopenharmony_cistruct nfp_eth_table; 2662306a36Sopenharmony_cistruct nfp_hwinfo; 2762306a36Sopenharmony_cistruct nfp_mip; 2862306a36Sopenharmony_cistruct nfp_net; 2962306a36Sopenharmony_cistruct nfp_nsp_identify; 3062306a36Sopenharmony_cistruct nfp_eth_media_buf; 3162306a36Sopenharmony_cistruct nfp_port; 3262306a36Sopenharmony_cistruct nfp_rtsym; 3362306a36Sopenharmony_cistruct nfp_rtsym_table; 3462306a36Sopenharmony_cistruct nfp_shared_buf; 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/** 3762306a36Sopenharmony_ci * struct nfp_dumpspec - NFP FW dump specification structure 3862306a36Sopenharmony_ci * @size: Size of the data 3962306a36Sopenharmony_ci * @data: Sequence of TLVs, each being an instruction to dump some data 4062306a36Sopenharmony_ci * from FW 4162306a36Sopenharmony_ci */ 4262306a36Sopenharmony_cistruct nfp_dumpspec { 4362306a36Sopenharmony_ci u32 size; 4462306a36Sopenharmony_ci u8 data[]; 4562306a36Sopenharmony_ci}; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/** 4862306a36Sopenharmony_ci * struct nfp_pf - NFP PF-specific device structure 4962306a36Sopenharmony_ci * @pdev: Backpointer to PCI device 5062306a36Sopenharmony_ci * @dev_info: NFP ASIC params 5162306a36Sopenharmony_ci * @cpp: Pointer to the CPP handle 5262306a36Sopenharmony_ci * @app: Pointer to the APP handle 5362306a36Sopenharmony_ci * @data_vnic_bar: Pointer to the CPP area for the data vNICs' BARs 5462306a36Sopenharmony_ci * @ctrl_vnic_bar: Pointer to the CPP area for the ctrl vNIC's BAR 5562306a36Sopenharmony_ci * @qc_area: Pointer to the CPP area for the queues 5662306a36Sopenharmony_ci * @mac_stats_bar: Pointer to the CPP area for the MAC stats 5762306a36Sopenharmony_ci * @mac_stats_mem: Pointer to mapped MAC stats area 5862306a36Sopenharmony_ci * @vf_cfg_bar: Pointer to the CPP area for the VF configuration BAR 5962306a36Sopenharmony_ci * @vf_cfg_mem: Pointer to mapped VF configuration area 6062306a36Sopenharmony_ci * @vfcfg_tbl2_area: Pointer to the CPP area for the VF config table 6162306a36Sopenharmony_ci * @vfcfg_tbl2: Pointer to mapped VF config table 6262306a36Sopenharmony_ci * @mbox: RTSym of per-PCI PF mailbox (under devlink lock) 6362306a36Sopenharmony_ci * @irq_entries: Array of MSI-X entries for all vNICs 6462306a36Sopenharmony_ci * @limit_vfs: Number of VFs supported by firmware (~0 for PCI limit) 6562306a36Sopenharmony_ci * @num_vfs: Number of SR-IOV VFs enabled 6662306a36Sopenharmony_ci * @fw_loaded: Is the firmware loaded? 6762306a36Sopenharmony_ci * @unload_fw_on_remove:Do we need to unload firmware on driver removal? 6862306a36Sopenharmony_ci * @ctrl_vnic: Pointer to the control vNIC if available 6962306a36Sopenharmony_ci * @mip: MIP handle 7062306a36Sopenharmony_ci * @rtbl: RTsym table 7162306a36Sopenharmony_ci * @hwinfo: HWInfo table 7262306a36Sopenharmony_ci * @dumpspec: Debug dump specification 7362306a36Sopenharmony_ci * @dump_flag: Store dump flag between set_dump and get_dump_flag 7462306a36Sopenharmony_ci * @dump_len: Store dump length between set_dump and get_dump_flag 7562306a36Sopenharmony_ci * @eth_tbl: NSP ETH table 7662306a36Sopenharmony_ci * @nspi: NSP identification info 7762306a36Sopenharmony_ci * @hwmon_dev: pointer to hwmon device 7862306a36Sopenharmony_ci * @ddir: Per-device debugfs directory 7962306a36Sopenharmony_ci * @max_data_vnics: Number of data vNICs app firmware supports 8062306a36Sopenharmony_ci * @num_vnics: Number of vNICs spawned 8162306a36Sopenharmony_ci * @vnics: Linked list of vNIC structures (struct nfp_net) 8262306a36Sopenharmony_ci * @ports: Linked list of port structures (struct nfp_port) 8362306a36Sopenharmony_ci * @wq: Workqueue for running works which need to grab @lock 8462306a36Sopenharmony_ci * @port_refresh_work: Work entry for taking netdevs out 8562306a36Sopenharmony_ci * @shared_bufs: Array of shared buffer structures if FW has any SBs 8662306a36Sopenharmony_ci * @num_shared_bufs: Number of elements in @shared_bufs 8762306a36Sopenharmony_ci * 8862306a36Sopenharmony_ci * Fields which may change after proble are protected by devlink instance lock. 8962306a36Sopenharmony_ci */ 9062306a36Sopenharmony_cistruct nfp_pf { 9162306a36Sopenharmony_ci struct pci_dev *pdev; 9262306a36Sopenharmony_ci const struct nfp_dev_info *dev_info; 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci struct nfp_cpp *cpp; 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci struct nfp_app *app; 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci struct nfp_cpp_area *data_vnic_bar; 9962306a36Sopenharmony_ci struct nfp_cpp_area *ctrl_vnic_bar; 10062306a36Sopenharmony_ci struct nfp_cpp_area *qc_area; 10162306a36Sopenharmony_ci struct nfp_cpp_area *mac_stats_bar; 10262306a36Sopenharmony_ci u8 __iomem *mac_stats_mem; 10362306a36Sopenharmony_ci struct nfp_cpp_area *vf_cfg_bar; 10462306a36Sopenharmony_ci u8 __iomem *vf_cfg_mem; 10562306a36Sopenharmony_ci struct nfp_cpp_area *vfcfg_tbl2_area; 10662306a36Sopenharmony_ci u8 __iomem *vfcfg_tbl2; 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci const struct nfp_rtsym *mbox; 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci struct msix_entry *irq_entries; 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci unsigned int limit_vfs; 11362306a36Sopenharmony_ci unsigned int num_vfs; 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci bool fw_loaded; 11662306a36Sopenharmony_ci bool unload_fw_on_remove; 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci struct nfp_net *ctrl_vnic; 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci const struct nfp_mip *mip; 12162306a36Sopenharmony_ci struct nfp_rtsym_table *rtbl; 12262306a36Sopenharmony_ci struct nfp_hwinfo *hwinfo; 12362306a36Sopenharmony_ci struct nfp_dumpspec *dumpspec; 12462306a36Sopenharmony_ci u32 dump_flag; 12562306a36Sopenharmony_ci u32 dump_len; 12662306a36Sopenharmony_ci struct nfp_eth_table *eth_tbl; 12762306a36Sopenharmony_ci struct nfp_nsp_identify *nspi; 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci struct device *hwmon_dev; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci struct dentry *ddir; 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci unsigned int max_data_vnics; 13462306a36Sopenharmony_ci unsigned int num_vnics; 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci struct list_head vnics; 13762306a36Sopenharmony_ci struct list_head ports; 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ci struct workqueue_struct *wq; 14062306a36Sopenharmony_ci struct work_struct port_refresh_work; 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci struct nfp_shared_buf *shared_bufs; 14362306a36Sopenharmony_ci unsigned int num_shared_bufs; 14462306a36Sopenharmony_ci}; 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ciextern struct pci_driver nfp_netvf_pci_driver; 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ciextern const struct devlink_ops nfp_devlink_ops; 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ciint nfp_net_pci_probe(struct nfp_pf *pf); 15162306a36Sopenharmony_civoid nfp_net_pci_remove(struct nfp_pf *pf); 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ciint nfp_hwmon_register(struct nfp_pf *pf); 15462306a36Sopenharmony_civoid nfp_hwmon_unregister(struct nfp_pf *pf); 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_civoid 15762306a36Sopenharmony_cinfp_net_get_mac_addr(struct nfp_pf *pf, struct net_device *netdev, 15862306a36Sopenharmony_ci struct nfp_port *port); 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_cibool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb); 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ciint nfp_pf_rtsym_read_optional(struct nfp_pf *pf, const char *format, 16362306a36Sopenharmony_ci unsigned int default_val); 16462306a36Sopenharmony_ciint nfp_net_pf_get_app_id(struct nfp_pf *pf); 16562306a36Sopenharmony_ciu8 __iomem * 16662306a36Sopenharmony_cinfp_pf_map_rtsym(struct nfp_pf *pf, const char *name, const char *sym_fmt, 16762306a36Sopenharmony_ci unsigned int min_size, struct nfp_cpp_area **area); 16862306a36Sopenharmony_ciint nfp_mbox_cmd(struct nfp_pf *pf, u32 cmd, void *in_data, u64 in_length, 16962306a36Sopenharmony_ci void *out_data, u64 out_length); 17062306a36Sopenharmony_ciint nfp_flash_update_common(struct nfp_pf *pf, const struct firmware *fw, 17162306a36Sopenharmony_ci struct netlink_ext_ack *extack); 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_cienum nfp_dump_diag { 17462306a36Sopenharmony_ci NFP_DUMP_NSP_DIAG = 0, 17562306a36Sopenharmony_ci}; 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_cistruct nfp_dumpspec * 17862306a36Sopenharmony_cinfp_net_dump_load_dumpspec(struct nfp_cpp *cpp, struct nfp_rtsym_table *rtbl); 17962306a36Sopenharmony_cis64 nfp_net_dump_calculate_size(struct nfp_pf *pf, struct nfp_dumpspec *spec, 18062306a36Sopenharmony_ci u32 flag); 18162306a36Sopenharmony_ciint nfp_net_dump_populate_buffer(struct nfp_pf *pf, struct nfp_dumpspec *spec, 18262306a36Sopenharmony_ci struct ethtool_dump *dump_param, void *dest); 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ciint nfp_shared_buf_register(struct nfp_pf *pf); 18562306a36Sopenharmony_civoid nfp_shared_buf_unregister(struct nfp_pf *pf); 18662306a36Sopenharmony_ciint nfp_shared_buf_pool_get(struct nfp_pf *pf, unsigned int sb, u16 pool_index, 18762306a36Sopenharmony_ci struct devlink_sb_pool_info *pool_info); 18862306a36Sopenharmony_ciint nfp_shared_buf_pool_set(struct nfp_pf *pf, unsigned int sb, 18962306a36Sopenharmony_ci u16 pool_index, u32 size, 19062306a36Sopenharmony_ci enum devlink_sb_threshold_type threshold_type); 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ciint nfp_devlink_params_register(struct nfp_pf *pf); 19362306a36Sopenharmony_civoid nfp_devlink_params_unregister(struct nfp_pf *pf); 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ciunsigned int nfp_net_lr2speed(unsigned int linkrate); 19662306a36Sopenharmony_ciunsigned int nfp_net_speed2lr(unsigned int speed); 19762306a36Sopenharmony_ci#endif /* NFP_MAIN_H */ 198