1 /****************************************************************************** 2 3 Copyright (c) 2013-2018, Intel Corporation 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 9 1. Redistributions of source code must retain the above copyright notice, 10 this list of conditions and the following disclaimer. 11 12 2. Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 3. Neither the name of the Intel Corporation nor the names of its 17 contributors may be used to endorse or promote products derived from 18 this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 POSSIBILITY OF SUCH DAMAGE. 31 32 ******************************************************************************/ 33 /*$FreeBSD$*/ 34 35 36 #ifndef _IXL_PF_H_ 37 #define _IXL_PF_H_ 38 39 #include "i40e_dcb.h" 40 41 #include "ixl.h" 42 #include "ixl_pf_qmgr.h" 43 44 #define VF_FLAG_ENABLED 0x01 45 #define VF_FLAG_SET_MAC_CAP 0x02 46 #define VF_FLAG_VLAN_CAP 0x04 47 #define VF_FLAG_PROMISC_CAP 0x08 48 #define VF_FLAG_MAC_ANTI_SPOOF 0x10 49 50 #define IXL_ICR0_CRIT_ERR_MASK \ 51 (I40E_PFINT_ICR0_PCI_EXCEPTION_MASK | \ 52 I40E_PFINT_ICR0_ECC_ERR_MASK | \ 53 I40E_PFINT_ICR0_PE_CRITERR_MASK) 54 55 /* VF Interrupts */ 56 #define IXL_VPINT_LNKLSTN_REG(hw, vector, vf_num) \ 57 I40E_VPINT_LNKLSTN(((vector) - 1) + \ 58 (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num))) 59 60 #define IXL_VFINT_DYN_CTLN_REG(hw, vector, vf_num) \ 61 I40E_VFINT_DYN_CTLN(((vector) - 1) + \ 62 (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num))) 63 64 enum ixl_fw_mode { 65 IXL_FW_MODE_NORMAL, 66 IXL_FW_MODE_RECOVERY, 67 IXL_FW_MODE_UEMPR 68 }; 69 70 enum ixl_i2c_access_method_t { 71 IXL_I2C_ACCESS_METHOD_BEST_AVAILABLE = 0, 72 IXL_I2C_ACCESS_METHOD_BIT_BANG_I2CPARAMS = 1, 73 IXL_I2C_ACCESS_METHOD_REGISTER_I2CCMD = 2, 74 IXL_I2C_ACCESS_METHOD_AQ = 3, 75 IXL_I2C_ACCESS_METHOD_TYPE_LENGTH = 4 76 }; 77 78 /* Used in struct ixl_pf's state field */ 79 enum ixl_pf_state { 80 IXL_PF_STATE_RECOVERY_MODE = (1 << 0), 81 IXL_PF_STATE_ADAPTER_RESETTING = (1 << 1), 82 IXL_PF_STATE_MDD_PENDING = (1 << 2), 83 IXL_PF_STATE_PF_RESET_REQ = (1 << 3), 84 IXL_PF_STATE_VF_RESET_REQ = (1 << 4), 85 IXL_PF_STATE_PF_CRIT_ERR = (1 << 5), 86 IXL_PF_STATE_CORE_RESET_REQ = (1 << 6), 87 IXL_PF_STATE_GLOB_RESET_REQ = (1 << 7), 88 IXL_PF_STATE_EMP_RESET_REQ = (1 << 8), 89 IXL_PF_STATE_FW_LLDP_DISABLED = (1 << 9), 90 }; 91 92 #define IXL_PF_IN_RECOVERY_MODE(pf) \ 93 ((atomic_load_acq_32(&pf->state) & IXL_PF_STATE_RECOVERY_MODE) != 0) 94 95 96 struct ixl_vf { 97 struct ixl_vsi vsi; 98 u32 vf_flags; 99 u32 num_mdd_events; 100 101 u8 mac[ETHER_ADDR_LEN]; 102 u16 vf_num; 103 struct virtchnl_version_info version; 104 105 struct ixl_pf_qtag qtag; 106 }; 107 108 /* Physical controller structure */ 109 struct ixl_pf { 110 struct ixl_vsi vsi; 111 112 struct i40e_hw hw; 113 struct i40e_osdep osdep; 114 device_t dev; 115 116 struct resource *pci_mem; 117 118 #ifdef IXL_IW 119 int iw_msix; 120 bool iw_enabled; 121 #endif 122 u32 state; 123 u8 supported_speeds; 124 125 struct ixl_pf_qmgr qmgr; 126 struct ixl_pf_qtag qtag; 127 128 char admin_mtx_name[16]; /* name of the admin mutex */ 129 struct mtx admin_mtx; /* mutex to protect the admin timer */ 130 struct callout admin_timer; /* timer to trigger admin task */ 131 132 /* Tunable values */ 133 #ifdef IXL_DEBUG_FC 134 bool enable_tx_fc_filter; 135 #endif 136 #ifdef IXL_DEBUG 137 bool recovery_mode; 138 #endif 139 int dynamic_rx_itr; 140 int dynamic_tx_itr; 141 int tx_itr; 142 int rx_itr; 143 int enable_vf_loopback; 144 145 bool link_up; 146 int advertised_speed; 147 int fc; /* link flow ctrl setting */ 148 enum ixl_dbg_mask dbg_mask; 149 bool has_i2c; 150 151 /* Misc stats maintained by the driver */ 152 u64 admin_irq; 153 154 /* Statistics from hw */ 155 struct i40e_hw_port_stats stats; 156 struct i40e_hw_port_stats stats_offsets; 157 bool stat_offsets_loaded; 158 159 /* I2C access methods */ 160 enum ixl_i2c_access_method_t i2c_access_method; 161 s32 (*read_i2c_byte)(struct ixl_pf *pf, u8 byte_offset, 162 u8 dev_addr, u8 *data); 163 s32 (*write_i2c_byte)(struct ixl_pf *pf, u8 byte_offset, 164 u8 dev_addr, u8 data); 165 166 /* SR-IOV */ 167 struct ixl_vf *vfs; 168 int num_vfs; 169 uint16_t veb_seid; 170 int vc_debug_lvl; 171 }; 172 173 /* 174 * Defines used for NVM update ioctls. 175 * This value is used in the Solaris tool, too. 176 */ 177 #define I40E_NVM_ACCESS \ 178 (((((((('E' << 4) + '1') << 4) + 'K') << 4) + 'G') << 4) | 5) 179 180 #define IXL_DEFAULT_PHY_INT_MASK \ 181 ((~(I40E_AQ_EVENT_LINK_UPDOWN | I40E_AQ_EVENT_MODULE_QUAL_FAIL \ 182 | I40E_AQ_EVENT_MEDIA_NA)) & 0x3FF) 183 184 /*** Sysctl help messages; displayed with "sysctl -d" ***/ 185 186 #define IXL_SYSCTL_HELP_SET_ADVERTISE \ 187 "\nControl advertised link speed.\n" \ 188 "Flags:\n" \ 189 "\t 0x1 - advertise 100M\n" \ 190 "\t 0x2 - advertise 1G\n" \ 191 "\t 0x4 - advertise 10G\n" \ 192 "\t 0x8 - advertise 20G\n" \ 193 "\t0x10 - advertise 25G\n" \ 194 "\t0x20 - advertise 40G\n\n" \ 195 "Set to 0 to disable link.\n" \ 196 "Use \"sysctl -x\" to view flags properly." 197 198 #define IXL_SYSCTL_HELP_SUPPORTED_SPEED \ 199 "\nSupported link speeds.\n" \ 200 "Flags:\n" \ 201 "\t 0x1 - 100M\n" \ 202 "\t 0x2 - 1G\n" \ 203 "\t 0x4 - 10G\n" \ 204 "\t 0x8 - 20G\n" \ 205 "\t0x10 - 25G\n" \ 206 "\t0x20 - 40G\n\n" \ 207 "Use \"sysctl -x\" to view flags properly." 208 209 #define IXL_SYSCTL_HELP_FC \ 210 "\nSet flow control mode using the values below.\n" \ 211 "\t0 - off\n" \ 212 "\t1 - rx pause\n" \ 213 "\t2 - tx pause\n" \ 214 "\t3 - tx and rx pause" 215 216 #define IXL_SYSCTL_HELP_LINK_STATUS \ 217 "\nExecutes a \"Get Link Status\" command on the Admin Queue, and displays" \ 218 " the response." 219 220 #define IXL_SYSCTL_HELP_FW_LLDP \ 221 "\nFW LLDP engine:\n" \ 222 "\t0 - disable\n" \ 223 "\t1 - enable\n" 224 225 #define IXL_SYSCTL_HELP_READ_I2C \ 226 "\nRead a byte from I2C bus\n" \ 227 "Input: 32-bit value\n" \ 228 "\tbits 0-7: device address (0xA0 or 0xA2)\n" \ 229 "\tbits 8-15: offset (0-255)\n" \ 230 "\tbits 16-31: unused\n" \ 231 "Output: 8-bit value read" 232 233 #define IXL_SYSCTL_HELP_WRITE_I2C \ 234 "\nWrite a byte to the I2C bus\n" \ 235 "Input: 32-bit value\n" \ 236 "\tbits 0-7: device address (0xA0 or 0xA2)\n" \ 237 "\tbits 8-15: offset (0-255)\n" \ 238 "\tbits 16-23: value to write\n" \ 239 "\tbits 24-31: unused\n" \ 240 "Output: 8-bit value written" 241 242 #define IXL_SYSCTL_HELP_I2C_METHOD \ 243 "\nI2C access method that driver will use:\n" \ 244 "\t0 - best available method\n" \ 245 "\t1 - bit bang via I2CPARAMS register\n" \ 246 "\t2 - register read/write via I2CCMD register\n" \ 247 "\t3 - Use Admin Queue command (best)\n" \ 248 "Using the Admin Queue is only supported on 710 devices with FW version 1.7 or higher" 249 250 #define IXL_SYSCTL_HELP_VF_LOOPBACK \ 251 "\nDetermines mode that embedded device switch will use when SR-IOV is initialized:\n" \ 252 "\t0 - Disable (VEPA)\n" \ 253 "\t1 - Enable (VEB)\n" \ 254 "Enabling this will allow VFs in separate VMs to communicate over the hardware bridge." 255 256 MALLOC_DECLARE(M_IXL); 257 258 /*** Functions / Macros ***/ 259 /* Adjust the level here to 10 or over to print stats messages */ 260 #define I40E_VC_DEBUG(p, level, ...) \ 261 do { \ 262 if (level < 10) \ 263 ixl_dbg(p, IXL_DBG_IOV_VC, ##__VA_ARGS__); \ 264 } while (0) 265 266 #define i40e_send_vf_nack(pf, vf, op, st) \ 267 ixl_send_vf_nack_msg((pf), (vf), (op), (st), __FILE__, __LINE__) 268 269 /* Debug printing */ 270 #define ixl_dbg(pf, m, s, ...) ixl_debug_core((pf)->dev, (pf)->dbg_mask, m, s, ##__VA_ARGS__) 271 #define ixl_dbg_info(pf, s, ...) ixl_debug_core((pf)->dev, (pf)->dbg_mask, IXL_DBG_INFO, s, ##__VA_ARGS__) 272 #define ixl_dbg_filter(pf, s, ...) ixl_debug_core((pf)->dev, (pf)->dbg_mask, IXL_DBG_FILTER, s, ##__VA_ARGS__) 273 #define ixl_dbg_iov(pf, s, ...) ixl_debug_core((pf)->dev, (pf)->dbg_mask, IXL_DBG_IOV, s, ##__VA_ARGS__) 274 275 /* PF-only function declarations */ 276 int ixl_setup_interface(device_t, struct ixl_pf *); 277 void ixl_print_nvm_cmd(device_t, struct i40e_nvm_access *); 278 279 void ixl_handle_que(void *context, int pending); 280 281 void ixl_init(void *); 282 void ixl_local_timer(void *); 283 void ixl_register_vlan(void *, struct ifnet *, u16); 284 void ixl_unregister_vlan(void *, struct ifnet *, u16); 285 int ixl_intr(void *); 286 int ixl_msix_que(void *); 287 int ixl_msix_adminq(void *); 288 void ixl_do_adminq(void *, int); 289 290 int ixl_res_alloc_cmp(const void *, const void *); 291 const char * ixl_switch_res_type_string(u8); 292 void ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *, 293 struct sysctl_oid_list *, struct i40e_hw_port_stats *); 294 295 void ixl_media_status(struct ifnet *, struct ifmediareq *); 296 int ixl_media_change(struct ifnet *); 297 int ixl_ioctl(struct ifnet *, u_long, caddr_t); 298 299 void ixl_enable_queue(struct i40e_hw *, int); 300 void ixl_disable_queue(struct i40e_hw *, int); 301 void ixl_enable_intr0(struct i40e_hw *); 302 void ixl_disable_intr0(struct i40e_hw *); 303 void ixl_nvm_version_str(struct i40e_hw *hw, struct sbuf *buf); 304 void ixl_stat_update48(struct i40e_hw *, u32, u32, bool, 305 u64 *, u64 *); 306 void ixl_stat_update32(struct i40e_hw *, u32, bool, 307 u64 *, u64 *); 308 309 void ixl_stop(struct ixl_pf *); 310 void ixl_vsi_add_sysctls(struct ixl_vsi *, const char *, bool); 311 int ixl_get_hw_capabilities(struct ixl_pf *); 312 void ixl_link_up_msg(struct ixl_pf *); 313 void ixl_update_link_status(struct ixl_pf *); 314 int ixl_setup_stations(struct ixl_pf *); 315 int ixl_switch_config(struct ixl_pf *); 316 void ixl_stop_locked(struct ixl_pf *); 317 int ixl_teardown_hw_structs(struct ixl_pf *); 318 void ixl_init_locked(struct ixl_pf *); 319 void ixl_set_rss_key(struct ixl_pf *); 320 void ixl_set_rss_pctypes(struct ixl_pf *); 321 void ixl_set_rss_hlut(struct ixl_pf *); 322 int ixl_setup_adminq_msix(struct ixl_pf *); 323 int ixl_setup_adminq_tq(struct ixl_pf *); 324 void ixl_teardown_adminq_msix(struct ixl_pf *); 325 void ixl_configure_intr0_msix(struct ixl_pf *); 326 void ixl_configure_queue_intr_msix(struct ixl_pf *); 327 void ixl_free_adminq_tq(struct ixl_pf *); 328 int ixl_setup_legacy(struct ixl_pf *); 329 int ixl_init_msix(struct ixl_pf *); 330 void ixl_configure_tx_itr(struct ixl_pf *); 331 void ixl_configure_rx_itr(struct ixl_pf *); 332 void ixl_configure_itr(struct ixl_pf *); 333 void ixl_configure_legacy(struct ixl_pf *); 334 void ixl_free_pci_resources(struct ixl_pf *); 335 void ixl_link_event(struct ixl_pf *, struct i40e_arq_event_info *); 336 void ixl_config_rss(struct ixl_pf *); 337 int ixl_set_advertised_speeds(struct ixl_pf *, int, bool); 338 void ixl_set_initial_advertised_speeds(struct ixl_pf *); 339 void ixl_print_nvm_version(struct ixl_pf *pf); 340 void ixl_add_sysctls_recovery_mode(struct ixl_pf *); 341 void ixl_add_device_sysctls(struct ixl_pf *); 342 void ixl_handle_mdd_event(struct ixl_pf *); 343 void ixl_add_hw_stats(struct ixl_pf *); 344 void ixl_update_stats_counters(struct ixl_pf *); 345 void ixl_pf_reset_stats(struct ixl_pf *); 346 void ixl_get_bus_info(struct ixl_pf *pf); 347 int ixl_aq_get_link_status(struct ixl_pf *, 348 struct i40e_aqc_get_link_status *); 349 350 int ixl_handle_nvmupd_cmd(struct ixl_pf *, struct ifdrv *); 351 int ixl_handle_i2c_eeprom_read_cmd(struct ixl_pf *, struct ifreq *ifr); 352 353 int ixl_setup_hmc(struct ixl_pf *); 354 void ixl_shutdown_hmc(struct ixl_pf *); 355 void ixl_handle_empr_reset(struct ixl_pf *); 356 int ixl_prepare_for_reset(struct ixl_pf *pf, bool is_up); 357 int ixl_rebuild_hw_structs_after_reset(struct ixl_pf *, bool is_up); 358 int ixl_pf_reset(struct ixl_pf *); 359 360 void ixl_set_queue_rx_itr(struct ixl_rx_queue *); 361 void ixl_set_queue_tx_itr(struct ixl_tx_queue *); 362 363 void ixl_add_filter(struct ixl_vsi *, const u8 *, s16 vlan); 364 void ixl_del_filter(struct ixl_vsi *, const u8 *, s16 vlan); 365 void ixl_reconfigure_filters(struct ixl_vsi *vsi); 366 367 int ixl_disable_rings(struct ixl_pf *, struct ixl_vsi *, struct ixl_pf_qtag *); 368 int ixl_disable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 369 int ixl_disable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 370 int ixl_disable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16); 371 372 int ixl_enable_rings(struct ixl_vsi *); 373 int ixl_enable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 374 int ixl_enable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 375 int ixl_enable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16); 376 377 void ixl_update_eth_stats(struct ixl_vsi *); 378 void ixl_cap_txcsum_tso(struct ixl_vsi *, struct ifnet *, int); 379 int ixl_initialize_vsi(struct ixl_vsi *); 380 void ixl_add_ifmedia(struct ifmedia *, u64); 381 int ixl_setup_queue_msix(struct ixl_vsi *); 382 int ixl_setup_queue_tqs(struct ixl_vsi *); 383 int ixl_teardown_queue_msix(struct ixl_vsi *); 384 void ixl_free_queue_tqs(struct ixl_vsi *); 385 void ixl_enable_intr(struct ixl_vsi *); 386 void ixl_disable_rings_intr(struct ixl_vsi *); 387 void ixl_set_promisc(struct ixl_vsi *); 388 void ixl_add_multi(struct ixl_vsi *); 389 int ixl_del_multi(struct ixl_vsi *); 390 void ixl_setup_vlan_filters(struct ixl_vsi *); 391 void ixl_init_filters(struct ixl_vsi *); 392 void ixl_add_hw_filters(struct ixl_vsi *, int, int); 393 void ixl_del_hw_filters(struct ixl_vsi *, int); 394 void ixl_del_default_hw_filters(struct ixl_vsi *); 395 struct ixl_mac_filter * 396 ixl_find_filter(struct ixl_vsi *, const u8 *, s16); 397 void ixl_add_mc_filter(struct ixl_vsi *, u8 *); 398 void ixl_free_mac_filters(struct ixl_vsi *vsi); 399 void ixl_update_vsi_stats(struct ixl_vsi *); 400 void ixl_vsi_reset_stats(struct ixl_vsi *); 401 402 void ixl_vsi_free_queues(struct ixl_vsi *vsi); 403 404 void ixl_if_init(if_ctx_t ctx); 405 void ixl_if_stop(if_ctx_t ctx); 406 407 /* 408 * I2C Function prototypes 409 */ 410 int ixl_find_i2c_interface(struct ixl_pf *); 411 s32 ixl_read_i2c_byte_bb(struct ixl_pf *pf, u8 byte_offset, 412 u8 dev_addr, u8 *data); 413 s32 ixl_write_i2c_byte_bb(struct ixl_pf *pf, u8 byte_offset, 414 u8 dev_addr, u8 data); 415 s32 ixl_read_i2c_byte_reg(struct ixl_pf *pf, u8 byte_offset, 416 u8 dev_addr, u8 *data); 417 s32 ixl_write_i2c_byte_reg(struct ixl_pf *pf, u8 byte_offset, 418 u8 dev_addr, u8 data); 419 s32 ixl_read_i2c_byte_aq(struct ixl_pf *pf, u8 byte_offset, 420 u8 dev_addr, u8 *data); 421 s32 ixl_write_i2c_byte_aq(struct ixl_pf *pf, u8 byte_offset, 422 u8 dev_addr, u8 data); 423 424 u64 ixl_max_aq_speed_to_value(u8); 425 int ixl_attach_get_link_status(struct ixl_pf *); 426 int ixl_sysctl_set_flowcntl(SYSCTL_HANDLER_ARGS); 427 428 #endif /* _IXL_PF_H_ */ 429