1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 /* Copyright (C) 2015-2018 Netronome Systems, Inc. */ 3 4 /* 5 * nfp_main.h 6 * Author: Jason McMullan <jason.mcmullan@netronome.com> 7 */ 8 9 #ifndef NFP_MAIN_H 10 #define NFP_MAIN_H 11 12 #include <linux/ethtool.h> 13 #include <linux/list.h> 14 #include <linux/types.h> 15 #include <linux/pci.h> 16 #include <linux/workqueue.h> 17 #include <net/devlink.h> 18 19 struct dentry; 20 struct device; 21 struct pci_dev; 22 23 struct nfp_cpp; 24 struct nfp_cpp_area; 25 struct nfp_eth_table; 26 struct nfp_hwinfo; 27 struct nfp_mip; 28 struct nfp_net; 29 struct nfp_nsp_identify; 30 struct nfp_port; 31 struct nfp_rtsym; 32 struct nfp_rtsym_table; 33 struct nfp_shared_buf; 34 35 /** 36 * struct nfp_dumpspec - NFP FW dump specification structure 37 * @size: Size of the data 38 * @data: Sequence of TLVs, each being an instruction to dump some data 39 * from FW 40 */ 41 struct nfp_dumpspec { 42 u32 size; 43 u8 data[]; 44 }; 45 46 /** 47 * struct nfp_pf - NFP PF-specific device structure 48 * @pdev: Backpointer to PCI device 49 * @dev_info: NFP ASIC params 50 * @cpp: Pointer to the CPP handle 51 * @app: Pointer to the APP handle 52 * @data_vnic_bar: Pointer to the CPP area for the data vNICs' BARs 53 * @ctrl_vnic_bar: Pointer to the CPP area for the ctrl vNIC's BAR 54 * @qc_area: Pointer to the CPP area for the queues 55 * @mac_stats_bar: Pointer to the CPP area for the MAC stats 56 * @mac_stats_mem: Pointer to mapped MAC stats area 57 * @vf_cfg_bar: Pointer to the CPP area for the VF configuration BAR 58 * @vf_cfg_mem: Pointer to mapped VF configuration area 59 * @vfcfg_tbl2_area: Pointer to the CPP area for the VF config table 60 * @vfcfg_tbl2: Pointer to mapped VF config table 61 * @mbox: RTSym of per-PCI PF mailbox (under devlink lock) 62 * @irq_entries: Array of MSI-X entries for all vNICs 63 * @limit_vfs: Number of VFs supported by firmware (~0 for PCI limit) 64 * @num_vfs: Number of SR-IOV VFs enabled 65 * @fw_loaded: Is the firmware loaded? 66 * @unload_fw_on_remove:Do we need to unload firmware on driver removal? 67 * @ctrl_vnic: Pointer to the control vNIC if available 68 * @mip: MIP handle 69 * @rtbl: RTsym table 70 * @hwinfo: HWInfo table 71 * @dumpspec: Debug dump specification 72 * @dump_flag: Store dump flag between set_dump and get_dump_flag 73 * @dump_len: Store dump length between set_dump and get_dump_flag 74 * @eth_tbl: NSP ETH table 75 * @nspi: NSP identification info 76 * @hwmon_dev: pointer to hwmon device 77 * @ddir: Per-device debugfs directory 78 * @max_data_vnics: Number of data vNICs app firmware supports 79 * @num_vnics: Number of vNICs spawned 80 * @vnics: Linked list of vNIC structures (struct nfp_net) 81 * @ports: Linked list of port structures (struct nfp_port) 82 * @wq: Workqueue for running works which need to grab @lock 83 * @port_refresh_work: Work entry for taking netdevs out 84 * @shared_bufs: Array of shared buffer structures if FW has any SBs 85 * @num_shared_bufs: Number of elements in @shared_bufs 86 * 87 * Fields which may change after proble are protected by devlink instance lock. 88 */ 89 struct nfp_pf { 90 struct pci_dev *pdev; 91 const struct nfp_dev_info *dev_info; 92 93 struct nfp_cpp *cpp; 94 95 struct nfp_app *app; 96 97 struct nfp_cpp_area *data_vnic_bar; 98 struct nfp_cpp_area *ctrl_vnic_bar; 99 struct nfp_cpp_area *qc_area; 100 struct nfp_cpp_area *mac_stats_bar; 101 u8 __iomem *mac_stats_mem; 102 struct nfp_cpp_area *vf_cfg_bar; 103 u8 __iomem *vf_cfg_mem; 104 struct nfp_cpp_area *vfcfg_tbl2_area; 105 u8 __iomem *vfcfg_tbl2; 106 107 const struct nfp_rtsym *mbox; 108 109 struct msix_entry *irq_entries; 110 111 unsigned int limit_vfs; 112 unsigned int num_vfs; 113 114 bool fw_loaded; 115 bool unload_fw_on_remove; 116 117 struct nfp_net *ctrl_vnic; 118 119 const struct nfp_mip *mip; 120 struct nfp_rtsym_table *rtbl; 121 struct nfp_hwinfo *hwinfo; 122 struct nfp_dumpspec *dumpspec; 123 u32 dump_flag; 124 u32 dump_len; 125 struct nfp_eth_table *eth_tbl; 126 struct nfp_nsp_identify *nspi; 127 128 struct device *hwmon_dev; 129 130 struct dentry *ddir; 131 132 unsigned int max_data_vnics; 133 unsigned int num_vnics; 134 135 struct list_head vnics; 136 struct list_head ports; 137 138 struct workqueue_struct *wq; 139 struct work_struct port_refresh_work; 140 141 struct nfp_shared_buf *shared_bufs; 142 unsigned int num_shared_bufs; 143 }; 144 145 extern struct pci_driver nfp_netvf_pci_driver; 146 147 extern const struct devlink_ops nfp_devlink_ops; 148 149 int nfp_net_pci_probe(struct nfp_pf *pf); 150 void nfp_net_pci_remove(struct nfp_pf *pf); 151 152 int nfp_hwmon_register(struct nfp_pf *pf); 153 void nfp_hwmon_unregister(struct nfp_pf *pf); 154 155 void 156 nfp_net_get_mac_addr(struct nfp_pf *pf, struct net_device *netdev, 157 struct nfp_port *port); 158 159 bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb); 160 161 int nfp_pf_rtsym_read_optional(struct nfp_pf *pf, const char *format, 162 unsigned int default_val); 163 int nfp_net_pf_get_app_id(struct nfp_pf *pf); 164 u8 __iomem * 165 nfp_pf_map_rtsym(struct nfp_pf *pf, const char *name, const char *sym_fmt, 166 unsigned int min_size, struct nfp_cpp_area **area); 167 int nfp_mbox_cmd(struct nfp_pf *pf, u32 cmd, void *in_data, u64 in_length, 168 void *out_data, u64 out_length); 169 int nfp_flash_update_common(struct nfp_pf *pf, const struct firmware *fw, 170 struct netlink_ext_ack *extack); 171 172 enum nfp_dump_diag { 173 NFP_DUMP_NSP_DIAG = 0, 174 }; 175 176 struct nfp_dumpspec * 177 nfp_net_dump_load_dumpspec(struct nfp_cpp *cpp, struct nfp_rtsym_table *rtbl); 178 s64 nfp_net_dump_calculate_size(struct nfp_pf *pf, struct nfp_dumpspec *spec, 179 u32 flag); 180 int nfp_net_dump_populate_buffer(struct nfp_pf *pf, struct nfp_dumpspec *spec, 181 struct ethtool_dump *dump_param, void *dest); 182 183 int nfp_shared_buf_register(struct nfp_pf *pf); 184 void nfp_shared_buf_unregister(struct nfp_pf *pf); 185 int nfp_shared_buf_pool_get(struct nfp_pf *pf, unsigned int sb, u16 pool_index, 186 struct devlink_sb_pool_info *pool_info); 187 int nfp_shared_buf_pool_set(struct nfp_pf *pf, unsigned int sb, 188 u16 pool_index, u32 size, 189 enum devlink_sb_threshold_type threshold_type); 190 191 int nfp_devlink_params_register(struct nfp_pf *pf); 192 void nfp_devlink_params_unregister(struct nfp_pf *pf); 193 194 unsigned int nfp_net_lr2speed(unsigned int linkrate); 195 unsigned int nfp_net_speed2lr(unsigned int speed); 196 #endif /* NFP_MAIN_H */ 197