1 /****************************************************************************** 2 3 Copyright (c) 2013-2015, 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 "ixl.h" 40 #include "ixl_pf_qmgr.h" 41 42 #define VF_FLAG_ENABLED 0x01 43 #define VF_FLAG_SET_MAC_CAP 0x02 44 #define VF_FLAG_VLAN_CAP 0x04 45 #define VF_FLAG_PROMISC_CAP 0x08 46 #define VF_FLAG_MAC_ANTI_SPOOF 0x10 47 48 #define IXL_PF_STATE_EMPR_RESETTING (1 << 0) 49 50 struct ixl_vf { 51 struct ixl_vsi vsi; 52 uint32_t vf_flags; 53 54 uint8_t mac[ETHER_ADDR_LEN]; 55 uint16_t vf_num; 56 uint32_t version; 57 58 struct ixl_pf_qtag qtag; 59 struct sysctl_ctx_list ctx; 60 }; 61 62 /* Physical controller structure */ 63 struct ixl_pf { 64 struct i40e_hw hw; 65 struct i40e_osdep osdep; 66 device_t dev; 67 struct ixl_vsi vsi; 68 69 struct resource *pci_mem; 70 struct resource *msix_mem; 71 72 /* 73 * Interrupt resources: this set is 74 * either used for legacy, or for Link 75 * when doing MSIX 76 */ 77 void *tag; 78 struct resource *res; 79 80 struct callout timer; 81 int msix; 82 #ifdef IXL_IW 83 int iw_msix; 84 bool iw_enabled; 85 #endif 86 int if_flags; 87 int state; 88 bool init_in_progress; 89 u8 supported_speeds; 90 91 struct ixl_pf_qmgr qmgr; 92 struct ixl_pf_qtag qtag; 93 94 /* Tunable values */ 95 bool enable_msix; 96 int max_queues; 97 int ringsz; 98 bool enable_tx_fc_filter; 99 int dynamic_rx_itr; 100 int dynamic_tx_itr; 101 int tx_itr; 102 int rx_itr; 103 104 struct mtx pf_mtx; 105 106 u32 qbase; 107 u32 admvec; 108 struct task adminq; 109 struct taskqueue *tq; 110 111 bool link_up; 112 u32 link_speed; 113 int advertised_speed; 114 int fc; /* link flow ctrl setting */ 115 enum ixl_dbg_mask dbg_mask; 116 bool has_i2c; 117 118 /* Misc stats maintained by the driver */ 119 u64 watchdog_events; 120 u64 admin_irq; 121 122 /* Statistics from hw */ 123 struct i40e_hw_port_stats stats; 124 struct i40e_hw_port_stats stats_offsets; 125 bool stat_offsets_loaded; 126 127 /* SR-IOV */ 128 struct ixl_vf *vfs; 129 int num_vfs; 130 uint16_t veb_seid; 131 struct task vflr_task; 132 int vc_debug_lvl; 133 }; 134 135 /* 136 * Defines used for NVM update ioctls. 137 * This value is used in the Solaris tool, too. 138 */ 139 #define I40E_NVM_ACCESS \ 140 (((((((('E' << 4) + '1') << 4) + 'K') << 4) + 'G') << 4) | 5) 141 142 #define IXL_DEFAULT_PHY_INT_MASK \ 143 ((~(I40E_AQ_EVENT_LINK_UPDOWN | I40E_AQ_EVENT_MODULE_QUAL_FAIL \ 144 | I40E_AQ_EVENT_MEDIA_NA)) & 0x3FF) 145 146 /*** Sysctl help messages; displayed with "sysctl -d" ***/ 147 148 #define IXL_SYSCTL_HELP_SET_ADVERTISE \ 149 "\nControl advertised link speed.\n" \ 150 "Flags:\n" \ 151 "\t 0x1 - advertise 100M\n" \ 152 "\t 0x2 - advertise 1G\n" \ 153 "\t 0x4 - advertise 10G\n" \ 154 "\t 0x8 - advertise 20G\n" \ 155 "\t0x10 - advertise 25G\n" \ 156 "\t0x20 - advertise 40G\n\n" \ 157 "Set to 0 to disable link.\n" \ 158 "Use \"sysctl -x\" to view flags properly." 159 160 #define IXL_SYSCTL_HELP_FC \ 161 "\nSet flow control mode using the values below.\n" \ 162 "\t0 - off\n" \ 163 "\t1 - rx pause\n" \ 164 "\t2 - tx pause\n" \ 165 "\t3 - tx and rx pause" 166 167 #define IXL_SYSCTL_HELP_LINK_STATUS \ 168 "\nExecutes a \"Get Link Status\" command on the Admin Queue, and displays" \ 169 " the response." \ 170 171 static char *ixl_fc_string[6] = { 172 "None", 173 "Rx", 174 "Tx", 175 "Full", 176 "Priority", 177 "Default" 178 }; 179 180 static MALLOC_DEFINE(M_IXL, "ixl", "ixl driver allocations"); 181 182 /*** Functions / Macros ***/ 183 /* Adjust the level here to 10 or over to print stats messages */ 184 #define I40E_VC_DEBUG(p, level, ...) \ 185 do { \ 186 if (level < 10) \ 187 ixl_dbg(p, IXL_DBG_IOV_VC, ##__VA_ARGS__); \ 188 } while (0) 189 190 #define i40e_send_vf_nack(pf, vf, op, st) \ 191 ixl_send_vf_nack_msg((pf), (vf), (op), (st), __FILE__, __LINE__) 192 193 #define IXL_PF_LOCK_INIT(_sc, _name) \ 194 mtx_init(&(_sc)->pf_mtx, _name, "IXL PF Lock", MTX_DEF) 195 #define IXL_PF_LOCK(_sc) mtx_lock(&(_sc)->pf_mtx) 196 #define IXL_PF_UNLOCK(_sc) mtx_unlock(&(_sc)->pf_mtx) 197 #define IXL_PF_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->pf_mtx) 198 #define IXL_PF_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->pf_mtx, MA_OWNED) 199 200 /* Debug printing */ 201 #define ixl_dbg(p, m, s, ...) ixl_debug_core(p, m, s, ##__VA_ARGS__) 202 void ixl_debug_core(struct ixl_pf *, enum ixl_dbg_mask, char *, ...); 203 204 /* For stats sysctl naming */ 205 #define QUEUE_NAME_LEN 32 206 207 /* For netmap(4) compatibility */ 208 #define ixl_disable_intr(vsi) ixl_disable_rings_intr(vsi) 209 210 /* 211 * PF-only function declarations 212 */ 213 214 void ixl_set_busmaster(device_t); 215 void ixl_set_msix_enable(device_t); 216 int ixl_setup_interface(device_t, struct ixl_vsi *); 217 void ixl_print_nvm_cmd(device_t, struct i40e_nvm_access *); 218 char * ixl_aq_speed_to_str(enum i40e_aq_link_speed); 219 220 void ixl_handle_que(void *context, int pending); 221 222 void ixl_init(void *); 223 void ixl_local_timer(void *); 224 void ixl_register_vlan(void *, struct ifnet *, u16); 225 void ixl_unregister_vlan(void *, struct ifnet *, u16); 226 void ixl_intr(void *); 227 void ixl_msix_que(void *); 228 void ixl_msix_adminq(void *); 229 void ixl_do_adminq(void *, int); 230 231 int ixl_res_alloc_cmp(const void *, const void *); 232 char * ixl_switch_res_type_string(u8); 233 char * ixl_switch_element_string(struct sbuf *, 234 struct i40e_aqc_switch_config_element_resp *); 235 void ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *, 236 struct sysctl_oid_list *, struct i40e_hw_port_stats *); 237 void ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *, 238 struct sysctl_oid_list *, 239 struct i40e_eth_stats *); 240 241 void ixl_media_status(struct ifnet *, struct ifmediareq *); 242 int ixl_media_change(struct ifnet *); 243 int ixl_ioctl(struct ifnet *, u_long, caddr_t); 244 245 void ixl_enable_queue(struct i40e_hw *, int); 246 void ixl_disable_queue(struct i40e_hw *, int); 247 void ixl_enable_intr0(struct i40e_hw *); 248 void ixl_disable_intr0(struct i40e_hw *); 249 void ixl_nvm_version_str(struct i40e_hw *hw, struct sbuf *buf); 250 void ixl_stat_update48(struct i40e_hw *, u32, u32, bool, 251 u64 *, u64 *); 252 void ixl_stat_update32(struct i40e_hw *, u32, bool, 253 u64 *, u64 *); 254 255 void ixl_stop(struct ixl_pf *); 256 void ixl_add_vsi_sysctls(struct ixl_pf *pf, struct ixl_vsi *vsi, struct sysctl_ctx_list *ctx, const char *sysctl_name); 257 int ixl_get_hw_capabilities(struct ixl_pf *); 258 void ixl_link_up_msg(struct ixl_pf *); 259 void ixl_update_link_status(struct ixl_pf *); 260 int ixl_allocate_pci_resources(struct ixl_pf *); 261 int ixl_setup_stations(struct ixl_pf *); 262 int ixl_switch_config(struct ixl_pf *); 263 void ixl_stop_locked(struct ixl_pf *); 264 int ixl_teardown_hw_structs(struct ixl_pf *); 265 int ixl_reset(struct ixl_pf *); 266 void ixl_init_locked(struct ixl_pf *); 267 void ixl_set_rss_key(struct ixl_pf *); 268 void ixl_set_rss_pctypes(struct ixl_pf *); 269 void ixl_set_rss_hlut(struct ixl_pf *); 270 int ixl_setup_adminq_msix(struct ixl_pf *); 271 int ixl_setup_adminq_tq(struct ixl_pf *); 272 int ixl_teardown_adminq_msix(struct ixl_pf *); 273 void ixl_configure_intr0_msix(struct ixl_pf *); 274 void ixl_configure_queue_intr_msix(struct ixl_pf *); 275 void ixl_free_adminq_tq(struct ixl_pf *); 276 int ixl_setup_legacy(struct ixl_pf *); 277 int ixl_init_msix(struct ixl_pf *); 278 void ixl_configure_itr(struct ixl_pf *); 279 void ixl_configure_legacy(struct ixl_pf *); 280 void ixl_free_pci_resources(struct ixl_pf *); 281 void ixl_link_event(struct ixl_pf *, struct i40e_arq_event_info *); 282 void ixl_config_rss(struct ixl_pf *); 283 int ixl_set_advertised_speeds(struct ixl_pf *, int); 284 void ixl_get_initial_advertised_speeds(struct ixl_pf *); 285 void ixl_print_nvm_version(struct ixl_pf *pf); 286 void ixl_add_device_sysctls(struct ixl_pf *); 287 void ixl_handle_mdd_event(struct ixl_pf *); 288 void ixl_add_hw_stats(struct ixl_pf *); 289 void ixl_update_stats_counters(struct ixl_pf *); 290 void ixl_pf_reset_stats(struct ixl_pf *); 291 void ixl_get_bus_info(struct ixl_pf *pf); 292 int ixl_aq_get_link_status(struct ixl_pf *, 293 struct i40e_aqc_get_link_status *); 294 295 int ixl_handle_nvmupd_cmd(struct ixl_pf *, struct ifdrv *); 296 void ixl_handle_empr_reset(struct ixl_pf *); 297 int ixl_rebuild_hw_structs_after_reset(struct ixl_pf *); 298 299 void ixl_set_queue_rx_itr(struct ixl_queue *); 300 void ixl_set_queue_tx_itr(struct ixl_queue *); 301 302 void ixl_add_filter(struct ixl_vsi *, u8 *, s16 vlan); 303 void ixl_del_filter(struct ixl_vsi *, u8 *, s16 vlan); 304 void ixl_reconfigure_filters(struct ixl_vsi *vsi); 305 306 int ixl_disable_rings(struct ixl_vsi *); 307 int ixl_disable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 308 int ixl_disable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 309 int ixl_disable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16); 310 311 int ixl_enable_rings(struct ixl_vsi *); 312 int ixl_enable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 313 int ixl_enable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 314 int ixl_enable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16); 315 316 void ixl_update_eth_stats(struct ixl_vsi *); 317 void ixl_cap_txcsum_tso(struct ixl_vsi *, struct ifnet *, int); 318 int ixl_initialize_vsi(struct ixl_vsi *); 319 void ixl_add_ifmedia(struct ixl_vsi *, u64); 320 int ixl_setup_queue_msix(struct ixl_vsi *); 321 int ixl_setup_queue_tqs(struct ixl_vsi *); 322 int ixl_teardown_queue_msix(struct ixl_vsi *); 323 void ixl_free_queue_tqs(struct ixl_vsi *); 324 void ixl_enable_intr(struct ixl_vsi *); 325 void ixl_disable_rings_intr(struct ixl_vsi *); 326 void ixl_set_promisc(struct ixl_vsi *); 327 void ixl_add_multi(struct ixl_vsi *); 328 void ixl_del_multi(struct ixl_vsi *); 329 void ixl_setup_vlan_filters(struct ixl_vsi *); 330 void ixl_init_filters(struct ixl_vsi *); 331 void ixl_add_hw_filters(struct ixl_vsi *, int, int); 332 void ixl_del_hw_filters(struct ixl_vsi *, int); 333 struct ixl_mac_filter * 334 ixl_find_filter(struct ixl_vsi *, u8 *, s16); 335 void ixl_add_mc_filter(struct ixl_vsi *, u8 *); 336 void ixl_free_mac_filters(struct ixl_vsi *vsi); 337 void ixl_update_vsi_stats(struct ixl_vsi *); 338 void ixl_vsi_reset_stats(struct ixl_vsi *); 339 340 /* 341 * I2C Function prototypes 342 */ 343 int ixl_find_i2c_interface(struct ixl_pf *); 344 s32 ixl_read_i2c_byte(struct ixl_pf *pf, u8 byte_offset, 345 u8 dev_addr, u8 *data); 346 s32 ixl_write_i2c_byte(struct ixl_pf *pf, u8 byte_offset, 347 u8 dev_addr, u8 data); 348 349 #endif /* _IXL_PF_H_ */ 350