1 /* 2 * Copyright (C) 2015-2017 Netronome Systems, Inc. 3 * 4 * This software is dual licensed under the GNU General License Version 2, 5 * June 1991 as shown in the file COPYING in the top-level directory of this 6 * source tree or the BSD 2-Clause License provided below. You have the 7 * option to license this software under the complete terms of either license. 8 * 9 * The BSD 2-Clause License: 10 * 11 * Redistribution and use in source and binary forms, with or 12 * without modification, are permitted provided that the following 13 * conditions are met: 14 * 15 * 1. Redistributions of source code must retain the above 16 * copyright notice, this list of conditions and the following 17 * disclaimer. 18 * 19 * 2. Redistributions in binary form must reproduce the above 20 * copyright notice, this list of conditions and the following 21 * disclaimer in the documentation and/or other materials 22 * provided with the distribution. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31 * SOFTWARE. 32 */ 33 34 /* 35 * nfp_main.h 36 * Author: Jason McMullan <jason.mcmullan@netronome.com> 37 */ 38 39 #ifndef NFP_MAIN_H 40 #define NFP_MAIN_H 41 42 #include <linux/ethtool.h> 43 #include <linux/list.h> 44 #include <linux/types.h> 45 #include <linux/msi.h> 46 #include <linux/mutex.h> 47 #include <linux/pci.h> 48 #include <linux/workqueue.h> 49 #include <net/devlink.h> 50 51 struct dentry; 52 struct device; 53 struct pci_dev; 54 55 struct nfp_cpp; 56 struct nfp_cpp_area; 57 struct nfp_eth_table; 58 struct nfp_hwinfo; 59 struct nfp_mip; 60 struct nfp_net; 61 struct nfp_nsp_identify; 62 struct nfp_port; 63 struct nfp_rtsym; 64 struct nfp_rtsym_table; 65 struct nfp_shared_buf; 66 67 /** 68 * struct nfp_dumpspec - NFP FW dump specification structure 69 * @size: Size of the data 70 * @data: Sequence of TLVs, each being an instruction to dump some data 71 * from FW 72 */ 73 struct nfp_dumpspec { 74 u32 size; 75 u8 data[0]; 76 }; 77 78 /** 79 * struct nfp_pf - NFP PF-specific device structure 80 * @pdev: Backpointer to PCI device 81 * @cpp: Pointer to the CPP handle 82 * @app: Pointer to the APP handle 83 * @data_vnic_bar: Pointer to the CPP area for the data vNICs' BARs 84 * @ctrl_vnic_bar: Pointer to the CPP area for the ctrl vNIC's BAR 85 * @qc_area: Pointer to the CPP area for the queues 86 * @mac_stats_bar: Pointer to the CPP area for the MAC stats 87 * @mac_stats_mem: Pointer to mapped MAC stats area 88 * @vf_cfg_bar: Pointer to the CPP area for the VF configuration BAR 89 * @vf_cfg_mem: Pointer to mapped VF configuration area 90 * @vfcfg_tbl2_area: Pointer to the CPP area for the VF config table 91 * @vfcfg_tbl2: Pointer to mapped VF config table 92 * @mbox: RTSym of per-PCI PF mailbox (under devlink lock) 93 * @irq_entries: Array of MSI-X entries for all vNICs 94 * @limit_vfs: Number of VFs supported by firmware (~0 for PCI limit) 95 * @num_vfs: Number of SR-IOV VFs enabled 96 * @fw_loaded: Is the firmware loaded? 97 * @ctrl_vnic: Pointer to the control vNIC if available 98 * @mip: MIP handle 99 * @rtbl: RTsym table 100 * @hwinfo: HWInfo table 101 * @dumpspec: Debug dump specification 102 * @dump_flag: Store dump flag between set_dump and get_dump_flag 103 * @dump_len: Store dump length between set_dump and get_dump_flag 104 * @eth_tbl: NSP ETH table 105 * @nspi: NSP identification info 106 * @hwmon_dev: pointer to hwmon device 107 * @ddir: Per-device debugfs directory 108 * @max_data_vnics: Number of data vNICs app firmware supports 109 * @num_vnics: Number of vNICs spawned 110 * @vnics: Linked list of vNIC structures (struct nfp_net) 111 * @ports: Linked list of port structures (struct nfp_port) 112 * @wq: Workqueue for running works which need to grab @lock 113 * @port_refresh_work: Work entry for taking netdevs out 114 * @shared_bufs: Array of shared buffer structures if FW has any SBs 115 * @num_shared_bufs: Number of elements in @shared_bufs 116 * @lock: Protects all fields which may change after probe 117 */ 118 struct nfp_pf { 119 struct pci_dev *pdev; 120 121 struct nfp_cpp *cpp; 122 123 struct nfp_app *app; 124 125 struct nfp_cpp_area *data_vnic_bar; 126 struct nfp_cpp_area *ctrl_vnic_bar; 127 struct nfp_cpp_area *qc_area; 128 struct nfp_cpp_area *mac_stats_bar; 129 u8 __iomem *mac_stats_mem; 130 struct nfp_cpp_area *vf_cfg_bar; 131 u8 __iomem *vf_cfg_mem; 132 struct nfp_cpp_area *vfcfg_tbl2_area; 133 u8 __iomem *vfcfg_tbl2; 134 135 const struct nfp_rtsym *mbox; 136 137 struct msix_entry *irq_entries; 138 139 unsigned int limit_vfs; 140 unsigned int num_vfs; 141 142 bool fw_loaded; 143 144 struct nfp_net *ctrl_vnic; 145 146 const struct nfp_mip *mip; 147 struct nfp_rtsym_table *rtbl; 148 struct nfp_hwinfo *hwinfo; 149 struct nfp_dumpspec *dumpspec; 150 u32 dump_flag; 151 u32 dump_len; 152 struct nfp_eth_table *eth_tbl; 153 struct nfp_nsp_identify *nspi; 154 155 struct device *hwmon_dev; 156 157 struct dentry *ddir; 158 159 unsigned int max_data_vnics; 160 unsigned int num_vnics; 161 162 struct list_head vnics; 163 struct list_head ports; 164 165 struct workqueue_struct *wq; 166 struct work_struct port_refresh_work; 167 168 struct nfp_shared_buf *shared_bufs; 169 unsigned int num_shared_bufs; 170 171 struct mutex lock; 172 }; 173 174 extern struct pci_driver nfp_netvf_pci_driver; 175 176 extern const struct devlink_ops nfp_devlink_ops; 177 178 int nfp_net_pci_probe(struct nfp_pf *pf); 179 void nfp_net_pci_remove(struct nfp_pf *pf); 180 181 int nfp_hwmon_register(struct nfp_pf *pf); 182 void nfp_hwmon_unregister(struct nfp_pf *pf); 183 184 void 185 nfp_net_get_mac_addr(struct nfp_pf *pf, struct net_device *netdev, 186 struct nfp_port *port); 187 188 bool nfp_ctrl_tx(struct nfp_net *nn, struct sk_buff *skb); 189 190 int nfp_pf_rtsym_read_optional(struct nfp_pf *pf, const char *format, 191 unsigned int default_val); 192 u8 __iomem * 193 nfp_pf_map_rtsym(struct nfp_pf *pf, const char *name, const char *sym_fmt, 194 unsigned int min_size, struct nfp_cpp_area **area); 195 int nfp_mbox_cmd(struct nfp_pf *pf, u32 cmd, void *in_data, u64 in_length, 196 void *out_data, u64 out_length); 197 198 enum nfp_dump_diag { 199 NFP_DUMP_NSP_DIAG = 0, 200 }; 201 202 struct nfp_dumpspec * 203 nfp_net_dump_load_dumpspec(struct nfp_cpp *cpp, struct nfp_rtsym_table *rtbl); 204 s64 nfp_net_dump_calculate_size(struct nfp_pf *pf, struct nfp_dumpspec *spec, 205 u32 flag); 206 int nfp_net_dump_populate_buffer(struct nfp_pf *pf, struct nfp_dumpspec *spec, 207 struct ethtool_dump *dump_param, void *dest); 208 209 int nfp_shared_buf_register(struct nfp_pf *pf); 210 void nfp_shared_buf_unregister(struct nfp_pf *pf); 211 int nfp_shared_buf_pool_get(struct nfp_pf *pf, unsigned int sb, u16 pool_index, 212 struct devlink_sb_pool_info *pool_info); 213 int nfp_shared_buf_pool_set(struct nfp_pf *pf, unsigned int sb, 214 u16 pool_index, u32 size, 215 enum devlink_sb_threshold_type threshold_type); 216 #endif /* NFP_MAIN_H */ 217