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 34 35 #ifndef _IXL_PF_H_ 36 #define _IXL_PF_H_ 37 38 #include "i40e_dcb.h" 39 40 #include "ixl.h" 41 #include "ixl_pf_qmgr.h" 42 43 #define VF_FLAG_ENABLED 0x01 44 #define VF_FLAG_SET_MAC_CAP 0x02 45 #define VF_FLAG_VLAN_CAP 0x04 46 #define VF_FLAG_PROMISC_CAP 0x08 47 #define VF_FLAG_MAC_ANTI_SPOOF 0x10 48 #define VF_FLAG_INITIALIZED 0x20 49 50 #define IXL_VF_MAX_MAC_FILTERS 18 51 #define IXL_VF_MAX_VLAN_FILTERS 16 52 53 #define IXL_ICR0_CRIT_ERR_MASK \ 54 (I40E_PFINT_ICR0_PCI_EXCEPTION_MASK | \ 55 I40E_PFINT_ICR0_ECC_ERR_MASK | \ 56 I40E_PFINT_ICR0_PE_CRITERR_MASK) 57 58 /* VF Interrupts */ 59 #define IXL_VPINT_LNKLSTN_REG(hw, vector, vf_num) \ 60 I40E_VPINT_LNKLSTN(((vector) - 1) + \ 61 (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num))) 62 63 #define IXL_VFINT_DYN_CTLN_REG(hw, vector, vf_num) \ 64 I40E_VFINT_DYN_CTLN(((vector) - 1) + \ 65 (((hw)->func_caps.num_msix_vectors_vf - 1) * (vf_num))) 66 67 enum ixl_fw_mode { 68 IXL_FW_MODE_NORMAL, 69 IXL_FW_MODE_RECOVERY, 70 IXL_FW_MODE_UEMPR 71 }; 72 73 enum ixl_i2c_access_method_t { 74 IXL_I2C_ACCESS_METHOD_BEST_AVAILABLE = 0, 75 IXL_I2C_ACCESS_METHOD_BIT_BANG_I2CPARAMS = 1, 76 IXL_I2C_ACCESS_METHOD_REGISTER_I2CCMD = 2, 77 IXL_I2C_ACCESS_METHOD_AQ = 3, 78 IXL_I2C_ACCESS_METHOD_TYPE_LENGTH = 4 79 }; 80 81 /* Used in struct ixl_pf's state field */ 82 enum ixl_state { 83 IXL_STATE_RECOVERY_MODE = 0, 84 IXL_STATE_RESETTING = 1, 85 IXL_STATE_MDD_PENDING = 2, 86 IXL_STATE_PF_RESET_REQ = 3, 87 IXL_STATE_VF_RESET_REQ = 4, 88 IXL_STATE_PF_CRIT_ERR = 5, 89 IXL_STATE_CORE_RESET_REQ = 6, 90 IXL_STATE_GLOB_RESET_REQ = 7, 91 IXL_STATE_EMP_RESET_REQ = 8, 92 IXL_STATE_FW_LLDP_DISABLED = 9, 93 IXL_STATE_EEE_ENABLED = 10, 94 IXL_STATE_LINK_ACTIVE_ON_DOWN = 11, 95 IXL_STATE_LINK_POLLING = 12, 96 }; 97 98 #define IXL_PF_IN_RECOVERY_MODE(pf) \ 99 ixl_test_state(&pf->state, IXL_STATE_RECOVERY_MODE) 100 101 #define IXL_PF_IS_RESETTING(pf) \ 102 ixl_test_state(&pf->state, IXL_STATE_RESETTING) 103 104 struct ixl_vf { 105 struct ixl_vsi vsi; 106 u32 vf_flags; 107 u64 mdd_tx_events; 108 u64 mdd_rx_events; 109 struct timeval last_mdd_log; 110 bool mdd_blocked; 111 bool mdd_event_pending; 112 bool mdd_reset_pending; 113 114 u8 mac[ETHER_ADDR_LEN]; 115 u8 mac_filters[IXL_VF_MAX_MAC_FILTERS][ETHER_ADDR_LEN]; 116 u16 num_mac_filters; 117 u16 default_vlan; 118 u16 vf_num; 119 struct virtchnl_version_info version; 120 121 struct ixl_pf_qtag qtag; 122 }; 123 124 /* Physical controller structure */ 125 struct ixl_pf { 126 struct ixl_vsi vsi; 127 128 struct i40e_hw hw; 129 struct i40e_osdep osdep; 130 device_t dev; 131 132 struct resource *pci_mem; 133 134 #ifdef IXL_IW 135 int iw_msix; 136 bool iw_enabled; 137 #endif 138 u32 state; 139 u8 supported_speeds; 140 bool led_active; 141 bool led_phy_controlled; 142 u16 led_phy_addr; 143 u32 led_status; 144 145 struct ixl_pf_qmgr qmgr; 146 struct ixl_pf_qtag qtag; 147 148 char admin_mtx_name[16]; /* name of the admin mutex */ 149 struct mtx admin_mtx; /* mutex to protect the admin timer */ 150 struct callout admin_timer; /* timer to trigger admin task */ 151 152 /* Tunable values */ 153 #ifdef IXL_DEBUG_FC 154 bool enable_tx_fc_filter; 155 #endif 156 #ifdef IXL_DEBUG 157 bool recovery_mode; 158 #endif 159 int dynamic_rx_itr; 160 int dynamic_tx_itr; 161 int tx_itr; 162 int rx_itr; 163 int enable_vf_loopback; 164 int mdd_auto_reset_vf; 165 166 bool link_up; 167 int advertised_speed; 168 int fc; /* link flow ctrl setting */ 169 enum ixl_dbg_mask dbg_mask; 170 bool has_i2c; 171 172 /* Misc stats maintained by the driver */ 173 u64 admin_irq; 174 175 /* Statistics from hw */ 176 struct i40e_hw_port_stats stats; 177 struct i40e_hw_port_stats stats_offsets; 178 bool stat_offsets_loaded; 179 180 /* I2C access methods */ 181 enum ixl_i2c_access_method_t i2c_access_method; 182 s32 (*read_i2c_byte)(struct ixl_pf *pf, u8 byte_offset, 183 u8 dev_addr, u8 *data); 184 s32 (*write_i2c_byte)(struct ixl_pf *pf, u8 byte_offset, 185 u8 dev_addr, u8 data); 186 187 /* SR-IOV */ 188 struct ixl_vf *vfs; 189 int num_vfs; 190 bool iov_attached; 191 uint16_t veb_seid; 192 int vc_debug_lvl; 193 194 sbintime_t link_poll_start; 195 }; 196 197 /* 198 * Defines used for NVM update ioctls. 199 * This value is used in the Solaris tool, too. 200 */ 201 #define I40E_NVM_ACCESS \ 202 (((((((('E' << 4) + '1') << 4) + 'K') << 4) + 'G') << 4) | 5) 203 204 #define IXL_DEFAULT_PHY_INT_MASK \ 205 ((~(I40E_AQ_EVENT_LINK_UPDOWN | I40E_AQ_EVENT_MODULE_QUAL_FAIL \ 206 | I40E_AQ_EVENT_MEDIA_NA)) & 0x3FF) 207 208 /*** Sysctl help messages; displayed with "sysctl -d" ***/ 209 210 #define IXL_SYSCTL_HELP_SET_ADVERTISE \ 211 "\nControl advertised link speed.\n" \ 212 "Flags:\n" \ 213 "\t 0x1 - advertise 100M\n" \ 214 "\t 0x2 - advertise 1G\n" \ 215 "\t 0x4 - advertise 10G\n" \ 216 "\t 0x8 - advertise 20G\n" \ 217 "\t0x10 - advertise 25G\n" \ 218 "\t0x20 - advertise 40G\n" \ 219 "\t0x40 - advertise 2.5G\n" \ 220 "\t0x80 - advertise 5G\n\n" \ 221 "Set to 0 to disable link.\n" \ 222 "Use \"sysctl -x\" to view flags properly." 223 224 #define IXL_SYSCTL_HELP_SUPPORTED_SPEED \ 225 "\nSupported link speeds.\n" \ 226 "Flags:\n" \ 227 "\t 0x1 - 100M\n" \ 228 "\t 0x2 - 1G\n" \ 229 "\t 0x4 - 10G\n" \ 230 "\t 0x8 - 20G\n" \ 231 "\t0x10 - 25G\n" \ 232 "\t0x20 - 40G\n" \ 233 "\t0x40 - 2.5G\n" \ 234 "\t0x80 - 5G\n\n" \ 235 "Use \"sysctl -x\" to view flags properly." 236 237 #define IXL_SYSCTL_HELP_FC \ 238 "\nSet flow control mode using the values below.\n" \ 239 "\t0 - off\n" \ 240 "\t1 - rx pause\n" \ 241 "\t2 - tx pause\n" \ 242 "\t3 - tx and rx pause" 243 244 #define IXL_SYSCTL_HELP_LINK_STATUS \ 245 "\nExecutes a \"Get Link Status\" command on the Admin Queue, and displays" \ 246 " the response." 247 248 #define IXL_SYSCTL_HELP_FW_LLDP \ 249 "\nFW LLDP engine:\n" \ 250 "\t0 - disable\n" \ 251 "\t1 - enable\n" 252 253 #define IXL_SYSCTL_HELP_SET_LINK_ACTIVE \ 254 "\nKeep link active after setting interface down:\n" \ 255 "\t0 - disable\n" \ 256 "\t1 - enable\n" 257 258 #define IXL_SYSCTL_HELP_READ_I2C \ 259 "\nRead a byte from I2C bus\n" \ 260 "Input: 32-bit value\n" \ 261 "\tbits 0-7: device address (0xA0 or 0xA2)\n" \ 262 "\tbits 8-15: offset (0-255)\n" \ 263 "\tbits 16-31: unused\n" \ 264 "Output: 8-bit value read" 265 266 #define IXL_SYSCTL_HELP_WRITE_I2C \ 267 "\nWrite a byte to the I2C bus\n" \ 268 "Input: 32-bit value\n" \ 269 "\tbits 0-7: device address (0xA0 or 0xA2)\n" \ 270 "\tbits 8-15: offset (0-255)\n" \ 271 "\tbits 16-23: value to write\n" \ 272 "\tbits 24-31: unused\n" \ 273 "Output: 8-bit value written" 274 275 #define IXL_SYSCTL_HELP_I2C_METHOD \ 276 "\nI2C access method that driver will use:\n" \ 277 "\t0 - best available method\n" \ 278 "\t1 - bit bang via I2CPARAMS register\n" \ 279 "\t2 - register read/write via I2CCMD register\n" \ 280 "\t3 - Use Admin Queue command (best)\n" \ 281 "Using the Admin Queue is only supported on 710 devices with FW version 1.7 or higher" 282 283 #define IXL_SYSCTL_HELP_VF_LOOPBACK \ 284 "\nDetermines mode that embedded device switch will use when SR-IOV is initialized:\n" \ 285 "\t0 - Disable (VEPA)\n" \ 286 "\t1 - Enable (VEB)\n" \ 287 "Enabling this will allow VFs in separate VMs to communicate over the hardware bridge." 288 289 /*** Functions / Macros ***/ 290 /* Adjust the level here to 10 or over to print stats messages */ 291 #define I40E_VC_DEBUG(p, level, ...) \ 292 do { \ 293 if (level < 10) \ 294 ixl_dbg(p, IXL_DBG_IOV_VC, ##__VA_ARGS__); \ 295 } while (0) 296 297 #define i40e_send_vf_nack(pf, vf, op, st) \ 298 ixl_send_vf_nack_msg((pf), (vf), (op), (st), __FILE__, __LINE__) 299 300 /* Debug printing */ 301 #define ixl_dbg(pf, m, s, ...) ixl_debug_core((pf)->dev, (pf)->dbg_mask, m, s, ##__VA_ARGS__) 302 #define ixl_dbg_info(pf, s, ...) ixl_debug_core((pf)->dev, (pf)->dbg_mask, IXL_DBG_INFO, s, ##__VA_ARGS__) 303 #define ixl_dbg_filter(pf, s, ...) ixl_debug_core((pf)->dev, (pf)->dbg_mask, IXL_DBG_FILTER, s, ##__VA_ARGS__) 304 #define ixl_dbg_iov(pf, s, ...) ixl_debug_core((pf)->dev, (pf)->dbg_mask, IXL_DBG_IOV, s, ##__VA_ARGS__) 305 #define ixl_dbg_link(pf, s, ...) ixl_debug_core((pf)->dev, (pf)->dbg_mask, IXL_DBG_LINK, s, ##__VA_ARGS__) 306 307 /* PF-only function declarations */ 308 void ixl_set_state(volatile u32 *s, enum ixl_state bit); 309 void ixl_clear_state(volatile u32 *s, enum ixl_state bit); 310 bool ixl_test_state(volatile u32 *s, enum ixl_state bit); 311 u32 ixl_testandset_state(volatile u32 *s, enum ixl_state bit); 312 int ixl_setup_interface(device_t, struct ixl_pf *); 313 void ixl_print_nvm_cmd(device_t, struct i40e_nvm_access *); 314 315 void ixl_handle_que(void *context, int pending); 316 317 void ixl_init(void *); 318 void ixl_register_vlan(void *, if_t, u16); 319 void ixl_unregister_vlan(void *, if_t, u16); 320 int ixl_intr(void *); 321 int ixl_msix_que(void *); 322 int ixl_msix_adminq(void *); 323 void ixl_do_adminq(void *, int); 324 325 int ixl_res_alloc_cmp(const void *, const void *); 326 const char * ixl_switch_res_type_string(u8); 327 void ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *, 328 struct sysctl_oid_list *, struct i40e_hw_port_stats *); 329 330 void ixl_media_status(if_t, struct ifmediareq *); 331 int ixl_media_change(if_t); 332 int ixl_ioctl(if_t, u_long, caddr_t); 333 334 void ixl_enable_queue(struct i40e_hw *, int); 335 void ixl_disable_queue(struct i40e_hw *, int); 336 void ixl_enable_intr0(struct i40e_hw *); 337 void ixl_disable_intr0(struct i40e_hw *); 338 void ixl_nvm_version_str(struct i40e_hw *hw, struct sbuf *buf); 339 void ixl_stat_update64(struct i40e_hw *, u32, bool, 340 u64 *, u64 *); 341 void ixl_stat_update48(struct i40e_hw *, u32, bool, 342 u64 *, u64 *); 343 void ixl_stat_update32(struct i40e_hw *, u32, bool, 344 u64 *, u64 *); 345 346 void ixl_stop(struct ixl_pf *); 347 void ixl_vsi_add_sysctls(struct ixl_vsi *, const char *, bool); 348 int ixl_get_hw_capabilities(struct ixl_pf *); 349 void ixl_link_up_msg(struct ixl_pf *); 350 void ixl_update_link_status(struct ixl_pf *); 351 int ixl_setup_stations(struct ixl_pf *); 352 int ixl_switch_config(struct ixl_pf *); 353 void ixl_stop_locked(struct ixl_pf *); 354 int ixl_teardown_hw_structs(struct ixl_pf *); 355 void ixl_init_locked(struct ixl_pf *); 356 void ixl_set_rss_key(struct ixl_pf *); 357 void ixl_set_rss_pctypes(struct ixl_pf *); 358 void ixl_set_rss_hlut(struct ixl_pf *); 359 int ixl_setup_adminq_msix(struct ixl_pf *); 360 int ixl_setup_adminq_tq(struct ixl_pf *); 361 void ixl_teardown_adminq_msix(struct ixl_pf *); 362 void ixl_configure_intr0_msix(struct ixl_pf *); 363 void ixl_configure_queue_intr_msix(struct ixl_pf *); 364 void ixl_free_adminq_tq(struct ixl_pf *); 365 int ixl_setup_legacy(struct ixl_pf *); 366 int ixl_init_msix(struct ixl_pf *); 367 void ixl_configure_tx_itr(struct ixl_pf *); 368 void ixl_configure_rx_itr(struct ixl_pf *); 369 void ixl_configure_itr(struct ixl_pf *); 370 void ixl_configure_legacy(struct ixl_pf *); 371 void ixl_free_pci_resources(struct ixl_pf *); 372 void ixl_link_event(struct ixl_pf *, struct i40e_arq_event_info *); 373 void ixl_config_rss(struct ixl_pf *); 374 int ixl_set_advertised_speeds(struct ixl_pf *, int, bool); 375 void ixl_set_initial_advertised_speeds(struct ixl_pf *); 376 void ixl_print_nvm_version(struct ixl_pf *pf); 377 void ixl_add_sysctls_recovery_mode(struct ixl_pf *); 378 void ixl_add_device_sysctls(struct ixl_pf *); 379 void ixl_handle_mdd_event(struct ixl_pf *); 380 void ixl_add_hw_stats(struct ixl_pf *); 381 void ixl_update_stats_counters(struct ixl_pf *); 382 void ixl_pf_reset_stats(struct ixl_pf *); 383 void ixl_get_bus_info(struct ixl_pf *pf); 384 int ixl_aq_get_link_status(struct ixl_pf *, 385 struct i40e_aqc_get_link_status *); 386 void ixl_set_link(struct ixl_pf *, bool); 387 388 int ixl_handle_nvmupd_cmd(struct ixl_pf *, struct ifdrv *); 389 int ixl_handle_i2c_eeprom_read_cmd(struct ixl_pf *, struct ifreq *ifr); 390 391 int ixl_setup_hmc(struct ixl_pf *); 392 void ixl_shutdown_hmc(struct ixl_pf *); 393 void ixl_handle_empr_reset(struct ixl_pf *); 394 int ixl_prepare_for_reset(struct ixl_pf *pf, bool is_up); 395 int ixl_rebuild_hw_structs_after_reset(struct ixl_pf *, bool is_up); 396 void ixl_led_restore(struct ixl_pf *pf); 397 int ixl_pf_reset(struct ixl_pf *); 398 399 #ifdef PCI_IOV 400 void ixl_notify_vfs_reset(struct ixl_pf *); 401 int ixl_quiesce_vfs_for_reset(struct ixl_pf *); 402 int ixl_rebuild_vfs_after_reset(struct ixl_pf *); 403 int ixl_reset_vf_on_mdd(struct ixl_pf *, uint16_t); 404 #endif 405 406 void ixl_set_queue_rx_itr(struct ixl_rx_queue *); 407 void ixl_set_queue_tx_itr(struct ixl_tx_queue *); 408 409 void ixl_add_filter(struct ixl_vsi *, const u8 *, s16 vlan); 410 void ixl_del_filter(struct ixl_vsi *, const u8 *, s16 vlan); 411 void ixl_add_vlan_filters(struct ixl_vsi *, const u8 *); 412 void ixl_del_all_vlan_filters(struct ixl_vsi *, const u8 *); 413 void ixl_reconfigure_filters(struct ixl_vsi *vsi); 414 415 int ixl_disable_rings(struct ixl_pf *, struct ixl_vsi *, struct ixl_pf_qtag *); 416 int ixl_disable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 417 int ixl_disable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 418 int ixl_disable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16); 419 420 int ixl_enable_rings(struct ixl_vsi *); 421 int ixl_enable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 422 int ixl_enable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 423 int ixl_enable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16); 424 425 void ixl_update_eth_stats(struct ixl_vsi *); 426 void ixl_cap_txcsum_tso(struct ixl_vsi *, if_t, int); 427 int ixl_initialize_vsi(struct ixl_vsi *); 428 void ixl_add_ifmedia(struct ifmedia *, u64); 429 int ixl_setup_queue_msix(struct ixl_vsi *); 430 int ixl_setup_queue_tqs(struct ixl_vsi *); 431 int ixl_teardown_queue_msix(struct ixl_vsi *); 432 void ixl_free_queue_tqs(struct ixl_vsi *); 433 void ixl_enable_intr(struct ixl_vsi *); 434 void ixl_disable_rings_intr(struct ixl_vsi *); 435 void ixl_set_promisc(struct ixl_vsi *); 436 void ixl_add_multi(struct ixl_vsi *); 437 void ixl_del_multi(struct ixl_vsi *, bool); 438 void ixl_setup_vlan_filters(struct ixl_vsi *); 439 void ixl_init_filters(struct ixl_vsi *); 440 void ixl_free_filters(struct ixl_ftl_head *); 441 void ixl_add_hw_filters(struct ixl_vsi *, struct ixl_ftl_head *, int); 442 void ixl_del_hw_filters(struct ixl_vsi *, struct ixl_ftl_head *, int); 443 void ixl_del_default_hw_filters(struct ixl_vsi *); 444 struct ixl_mac_filter * 445 ixl_find_filter(struct ixl_ftl_head *, const u8 *, s16); 446 void ixl_update_vsi_stats(struct ixl_vsi *); 447 void ixl_vsi_reset_stats(struct ixl_vsi *); 448 449 void ixl_vsi_free_queues(struct ixl_vsi *vsi); 450 451 void ixl_if_init(if_ctx_t ctx); 452 void ixl_if_stop(if_ctx_t ctx); 453 454 /* 455 * I2C Function prototypes 456 */ 457 int ixl_find_i2c_interface(struct ixl_pf *); 458 s32 ixl_read_i2c_byte_bb(struct ixl_pf *pf, u8 byte_offset, 459 u8 dev_addr, u8 *data); 460 s32 ixl_write_i2c_byte_bb(struct ixl_pf *pf, u8 byte_offset, 461 u8 dev_addr, u8 data); 462 s32 ixl_read_i2c_byte_reg(struct ixl_pf *pf, u8 byte_offset, 463 u8 dev_addr, u8 *data); 464 s32 ixl_write_i2c_byte_reg(struct ixl_pf *pf, u8 byte_offset, 465 u8 dev_addr, u8 data); 466 s32 ixl_read_i2c_byte_aq(struct ixl_pf *pf, u8 byte_offset, 467 u8 dev_addr, u8 *data); 468 s32 ixl_write_i2c_byte_aq(struct ixl_pf *pf, u8 byte_offset, 469 u8 dev_addr, u8 data); 470 471 u64 ixl_max_aq_speed_to_value(u8); 472 int ixl_attach_get_link_status(struct ixl_pf *); 473 int ixl_sysctl_set_flowcntl(SYSCTL_HANDLER_ARGS); 474 475 #endif /* _IXL_PF_H_ */ 476