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 int if_flags; 83 int state; 84 85 struct ixl_pf_qmgr qmgr; 86 struct ixl_pf_qtag qtag; 87 88 /* Tunable values */ 89 bool enable_msix; 90 int max_queues; 91 int ringsz; 92 bool enable_tx_fc_filter; 93 int dynamic_rx_itr; 94 int dynamic_tx_itr; 95 int tx_itr; 96 int rx_itr; 97 98 struct mtx pf_mtx; 99 100 u32 qbase; 101 u32 admvec; 102 struct task adminq; 103 struct taskqueue *tq; 104 105 bool link_up; 106 u32 link_speed; 107 int advertised_speed; 108 int fc; /* link flow ctrl setting */ 109 enum ixl_dbg_mask dbg_mask; 110 111 /* Misc stats maintained by the driver */ 112 u64 watchdog_events; 113 u64 admin_irq; 114 115 /* Statistics from hw */ 116 struct i40e_hw_port_stats stats; 117 struct i40e_hw_port_stats stats_offsets; 118 bool stat_offsets_loaded; 119 120 /* SR-IOV */ 121 struct ixl_vf *vfs; 122 int num_vfs; 123 uint16_t veb_seid; 124 struct task vflr_task; 125 int vc_debug_lvl; 126 }; 127 128 /* 129 * Defines used for NVM update ioctls. 130 * This value is used in the Solaris tool, too. 131 */ 132 #define I40E_NVM_ACCESS \ 133 (((((((('E' << 4) + '1') << 4) + 'K') << 4) + 'G') << 4) | 5) 134 135 #define IXL_DEFAULT_PHY_INT_MASK \ 136 ((~(I40E_AQ_EVENT_LINK_UPDOWN | I40E_AQ_EVENT_MODULE_QUAL_FAIL \ 137 | I40E_AQ_EVENT_MEDIA_NA)) & 0x3FF) 138 139 /*** Sysctl help messages; displayed with "sysctl -d" ***/ 140 141 #define IXL_SYSCTL_HELP_SET_ADVERTISE \ 142 "\nControl advertised link speed.\n" \ 143 "Flags:\n" \ 144 "\t 0x1 - advertise 100M\n" \ 145 "\t 0x2 - advertise 1G\n" \ 146 "\t 0x4 - advertise 10G\n" \ 147 "\t 0x8 - advertise 20G\n" \ 148 "\t0x10 - advertise 40G\n\n" \ 149 "Set to 0 to disable link." 150 151 #define IXL_SYSCTL_HELP_FC \ 152 "\nSet flow control mode using the values below.\n" \ 153 "\t0 - off\n" \ 154 "\t1 - rx pause\n" \ 155 "\t2 - tx pause\n" \ 156 "\t3 - tx and rx pause" 157 158 #define IXL_SYSCTL_HELP_LINK_STATUS \ 159 "\nExecutes a \"Get Link Status\" command on the Admin Queue, and displays" \ 160 " the response." \ 161 162 static char *ixl_fc_string[6] = { 163 "None", 164 "Rx", 165 "Tx", 166 "Full", 167 "Priority", 168 "Default" 169 }; 170 171 static MALLOC_DEFINE(M_IXL, "ixl", "ixl driver allocations"); 172 173 /*** Functions / Macros ***/ 174 #define I40E_VC_DEBUG(pf, level, ...) \ 175 do { \ 176 if ((pf)->vc_debug_lvl >= (level)) \ 177 device_printf((pf)->dev, __VA_ARGS__); \ 178 } while (0) 179 180 #define i40e_send_vf_nack(pf, vf, op, st) \ 181 ixl_send_vf_nack_msg((pf), (vf), (op), (st), __FILE__, __LINE__) 182 183 #define IXL_PF_LOCK_INIT(_sc, _name) \ 184 mtx_init(&(_sc)->pf_mtx, _name, "IXL PF Lock", MTX_DEF) 185 #define IXL_PF_LOCK(_sc) mtx_lock(&(_sc)->pf_mtx) 186 #define IXL_PF_UNLOCK(_sc) mtx_unlock(&(_sc)->pf_mtx) 187 #define IXL_PF_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->pf_mtx) 188 #define IXL_PF_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->pf_mtx, MA_OWNED) 189 190 /* For stats sysctl naming */ 191 #define QUEUE_NAME_LEN 32 192 193 /* 194 * PF-only function declarations 195 */ 196 197 void ixl_set_busmaster(device_t); 198 int ixl_setup_interface(device_t, struct ixl_vsi *); 199 void ixl_print_nvm_cmd(device_t, struct i40e_nvm_access *); 200 201 void ixl_handle_que(void *context, int pending); 202 203 void ixl_init(void *); 204 void ixl_local_timer(void *); 205 void ixl_register_vlan(void *, struct ifnet *, u16); 206 void ixl_unregister_vlan(void *, struct ifnet *, u16); 207 void ixl_intr(void *); 208 void ixl_msix_que(void *); 209 void ixl_msix_adminq(void *); 210 void ixl_do_adminq(void *, int); 211 212 int ixl_res_alloc_cmp(const void *, const void *); 213 char * ixl_switch_res_type_string(u8); 214 char * ixl_switch_element_string(struct sbuf *, 215 struct i40e_aqc_switch_config_element_resp *); 216 void ixl_add_sysctls_mac_stats(struct sysctl_ctx_list *, 217 struct sysctl_oid_list *, struct i40e_hw_port_stats *); 218 void ixl_add_sysctls_eth_stats(struct sysctl_ctx_list *, 219 struct sysctl_oid_list *, 220 struct i40e_eth_stats *); 221 222 void ixl_media_status(struct ifnet *, struct ifmediareq *); 223 int ixl_media_change(struct ifnet *); 224 int ixl_ioctl(struct ifnet *, u_long, caddr_t); 225 226 void ixl_enable_adminq(struct i40e_hw *); 227 void ixl_get_bus_info(struct i40e_hw *, device_t); 228 void ixl_disable_adminq(struct i40e_hw *); 229 void ixl_enable_queue(struct i40e_hw *, int); 230 void ixl_disable_queue(struct i40e_hw *, int); 231 void ixl_enable_legacy(struct i40e_hw *); 232 void ixl_disable_legacy(struct i40e_hw *); 233 void ixl_nvm_version_str(struct i40e_hw *hw, struct sbuf *buf); 234 void ixl_stat_update48(struct i40e_hw *, u32, u32, bool, 235 u64 *, u64 *); 236 void ixl_stat_update32(struct i40e_hw *, u32, bool, 237 u64 *, u64 *); 238 239 void ixl_stop(struct ixl_pf *); 240 void ixl_add_vsi_sysctls(struct ixl_pf *pf, struct ixl_vsi *vsi, struct sysctl_ctx_list *ctx, const char *sysctl_name); 241 int ixl_get_hw_capabilities(struct ixl_pf *); 242 void ixl_update_link_status(struct ixl_pf *); 243 int ixl_allocate_pci_resources(struct ixl_pf *); 244 int ixl_setup_stations(struct ixl_pf *); 245 int ixl_switch_config(struct ixl_pf *); 246 void ixl_stop_locked(struct ixl_pf *); 247 int ixl_teardown_hw_structs(struct ixl_pf *); 248 int ixl_reset(struct ixl_pf *); 249 void ixl_init_locked(struct ixl_pf *); 250 void ixl_set_rss_key(struct ixl_pf *); 251 void ixl_set_rss_pctypes(struct ixl_pf *); 252 void ixl_set_rss_hlut(struct ixl_pf *); 253 int ixl_setup_adminq_msix(struct ixl_pf *); 254 int ixl_setup_adminq_tq(struct ixl_pf *); 255 int ixl_teardown_adminq_msix(struct ixl_pf *); 256 void ixl_configure_intr0_msix(struct ixl_pf *); 257 void ixl_configure_queue_intr_msix(struct ixl_pf *); 258 void ixl_free_adminq_tq(struct ixl_pf *); 259 int ixl_assign_vsi_legacy(struct ixl_pf *); 260 int ixl_init_msix(struct ixl_pf *); 261 void ixl_configure_itr(struct ixl_pf *); 262 void ixl_configure_legacy(struct ixl_pf *); 263 void ixl_free_pci_resources(struct ixl_pf *); 264 void ixl_link_event(struct ixl_pf *, struct i40e_arq_event_info *); 265 void ixl_config_rss(struct ixl_pf *); 266 int ixl_set_advertised_speeds(struct ixl_pf *, int); 267 void ixl_get_initial_advertised_speeds(struct ixl_pf *); 268 void ixl_print_nvm_version(struct ixl_pf *pf); 269 void ixl_add_device_sysctls(struct ixl_pf *); 270 void ixl_handle_mdd_event(struct ixl_pf *); 271 void ixl_add_hw_stats(struct ixl_pf *); 272 void ixl_update_stats_counters(struct ixl_pf *); 273 void ixl_pf_reset_stats(struct ixl_pf *); 274 void ixl_dbg(struct ixl_pf *, enum ixl_dbg_mask, char *, ...); 275 276 int ixl_handle_nvmupd_cmd(struct ixl_pf *, struct ifdrv *); 277 void ixl_handle_empr_reset(struct ixl_pf *); 278 int ixl_rebuild_hw_structs_after_reset(struct ixl_pf *); 279 280 void ixl_set_queue_rx_itr(struct ixl_queue *); 281 void ixl_set_queue_tx_itr(struct ixl_queue *); 282 283 void ixl_add_filter(struct ixl_vsi *, u8 *, s16 vlan); 284 void ixl_del_filter(struct ixl_vsi *, u8 *, s16 vlan); 285 void ixl_reconfigure_filters(struct ixl_vsi *vsi); 286 287 int ixl_disable_rings(struct ixl_vsi *); 288 int ixl_disable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 289 int ixl_disable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 290 int ixl_disable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16); 291 292 int ixl_enable_rings(struct ixl_vsi *); 293 int ixl_enable_tx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 294 int ixl_enable_rx_ring(struct ixl_pf *, struct ixl_pf_qtag *, u16); 295 int ixl_enable_ring(struct ixl_pf *pf, struct ixl_pf_qtag *, u16); 296 297 void ixl_update_eth_stats(struct ixl_vsi *); 298 void ixl_disable_intr(struct ixl_vsi *); 299 void ixl_cap_txcsum_tso(struct ixl_vsi *, struct ifnet *, int); 300 int ixl_initialize_vsi(struct ixl_vsi *); 301 void ixl_add_ifmedia(struct ixl_vsi *, u32); 302 int ixl_setup_queue_msix(struct ixl_vsi *); 303 int ixl_setup_queue_tqs(struct ixl_vsi *); 304 int ixl_teardown_queue_msix(struct ixl_vsi *); 305 void ixl_free_queue_tqs(struct ixl_vsi *); 306 void ixl_enable_intr(struct ixl_vsi *); 307 void ixl_disable_rings_intr(struct ixl_vsi *); 308 void ixl_set_promisc(struct ixl_vsi *); 309 void ixl_add_multi(struct ixl_vsi *); 310 void ixl_del_multi(struct ixl_vsi *); 311 void ixl_setup_vlan_filters(struct ixl_vsi *); 312 void ixl_init_filters(struct ixl_vsi *); 313 void ixl_add_hw_filters(struct ixl_vsi *, int, int); 314 void ixl_del_hw_filters(struct ixl_vsi *, int); 315 struct ixl_mac_filter * 316 ixl_find_filter(struct ixl_vsi *, u8 *, s16); 317 void ixl_add_mc_filter(struct ixl_vsi *, u8 *); 318 void ixl_free_mac_filters(struct ixl_vsi *vsi); 319 void ixl_update_vsi_stats(struct ixl_vsi *); 320 void ixl_vsi_reset_stats(struct ixl_vsi *); 321 322 #endif /* _IXL_PF_H_ */ 323