1 /* $OpenBSD: ixgbe.h,v 1.8 2012/01/20 14:48:49 mikeb Exp $ */ 2 3 /****************************************************************************** 4 5 Copyright (c) 2001-2008, Intel Corporation 6 All rights reserved. 7 8 Redistribution and use in source and binary forms, with or without 9 modification, are permitted provided that the following conditions are met: 10 11 1. Redistributions of source code must retain the above copyright notice, 12 this list of conditions and the following disclaimer. 13 14 2. Redistributions in binary form must reproduce the above copyright 15 notice, this list of conditions and the following disclaimer in the 16 documentation and/or other materials provided with the distribution. 17 18 3. Neither the name of the Intel Corporation nor the names of its 19 contributors may be used to endorse or promote products derived from 20 this software without specific prior written permission. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 POSSIBILITY OF SUCH DAMAGE. 33 34 ******************************************************************************/ 35 /*$FreeBSD: src/sys/dev/ixgbe/ixgbe_osdep.h,v 1.4 2008/05/16 18:46:30 jfv Exp $*/ 36 37 #ifndef _IXGBE_H_ 38 #define _IXGBE_H_ 39 40 #include "bpfilter.h" 41 #include "vlan.h" 42 43 #include <sys/param.h> 44 #include <sys/systm.h> 45 #include <sys/sockio.h> 46 #include <sys/mbuf.h> 47 #include <sys/malloc.h> 48 #include <sys/kernel.h> 49 #include <sys/device.h> 50 #include <sys/socket.h> 51 #include <sys/timeout.h> 52 #include <sys/pool.h> 53 #include <sys/rwlock.h> 54 #include <sys/workq.h> 55 56 #include <net/if.h> 57 #include <net/if_arp.h> 58 #include <net/bpf.h> 59 #include <net/if_dl.h> 60 #include <net/if_media.h> 61 62 #include <netinet/in_systm.h> 63 #include <netinet/in.h> 64 #include <netinet/if_ether.h> 65 #include <netinet/ip.h> 66 #include <netinet/ip6.h> 67 #include <netinet/tcp.h> 68 #include <netinet/udp.h> 69 70 #if NBPFILTER > 0 71 #include <net/bpf.h> 72 #endif 73 74 #if NVLAN > 0 75 #include <net/if_types.h> 76 #include <net/if_vlan_var.h> 77 #endif 78 79 #include <uvm/uvm_extern.h> 80 81 #include <dev/rndvar.h> 82 83 #include <dev/pci/pcireg.h> 84 #include <dev/pci/pcivar.h> 85 #include <dev/pci/pcidevs.h> 86 #include <dev/pci/ixgbe_type.h> 87 88 #define DBG 0 89 #define MSGOUT(S, A, B) printf(S "\n", A, B) 90 #define DEBUGFUNC(F) DEBUGOUT(F); 91 #if DBG 92 #define DEBUGOUT(S) printf(S) 93 #define DEBUGOUT1(S,A) printf(S,A) 94 #define DEBUGOUT2(S,A,B) printf(S,A,B) 95 #define DEBUGOUT3(S,A,B,C) printf(S,A,B,C) 96 #define DEBUGOUT6(S,A,B,C,D,E,F) printf(S,A,B,C,D,E,F) 97 #define DEBUGOUT7(S,A,B,C,D,E,F,G) printf(S,A,B,C,D,E,F,G) 98 #else 99 #define DEBUGOUT(S) 100 #define DEBUGOUT1(S,A) 101 #define DEBUGOUT2(S,A,B) 102 #define DEBUGOUT3(S,A,B,C) 103 #define DEBUGOUT6(S,A,B,C,D,E,F) 104 #define DEBUGOUT7(S,A,B,C,D,E,F,G) 105 #endif 106 107 #define FALSE 0 108 #define TRUE 1 109 #define CMD_MEM_WRT_INVALIDATE 0x0010 /* BIT_4 */ 110 #define PCI_COMMAND_REGISTER PCIR_COMMAND 111 112 /* Compat glue */ 113 #define PCIR_BAR(_x) (0x10 + (_x) * 4) 114 #define roundup2(size, unit) (((size) + (unit) - 1) & ~((unit) - 1)) 115 #define usec_delay(x) delay(x) 116 #define msec_delay(x) delay(1000 * (x)) 117 118 /* This is needed by the shared code */ 119 struct ixgbe_hw; 120 121 struct ixgbe_osdep { 122 bus_dma_tag_t os_dmat; 123 bus_space_tag_t os_memt; 124 bus_space_handle_t os_memh; 125 126 bus_size_t os_memsize; 127 bus_addr_t os_membase; 128 129 void *os_sc; 130 struct pci_attach_args os_pa; 131 }; 132 133 extern uint16_t ixgbe_read_pci_cfg(struct ixgbe_hw *, uint32_t); 134 #define IXGBE_READ_PCIE_WORD ixgbe_read_pci_cfg 135 136 extern void ixgbe_write_pci_cfg(struct ixgbe_hw *, uint32_t, uint16_t); 137 #define IXGBE_WRITE_PCIE_WORD ixgbe_write_pci_cfg 138 139 #define IXGBE_WRITE_FLUSH(a) \ 140 IXGBE_READ_REG(a, IXGBE_STATUS) 141 #define IXGBE_READ_REG(a, reg) \ 142 bus_space_read_4(((struct ixgbe_osdep *)(a)->back)->os_memt, \ 143 ((struct ixgbe_osdep *)(a)->back)->os_memh, reg) 144 #define IXGBE_WRITE_REG(a, reg, value) \ 145 bus_space_write_4(((struct ixgbe_osdep *)(a)->back)->os_memt, \ 146 ((struct ixgbe_osdep *)(a)->back)->os_memh, reg, value) 147 #define IXGBE_READ_REG_ARRAY(a, reg, offset) \ 148 bus_space_read_4(((struct ixgbe_osdep *)(a)->back)->os_memt, \ 149 ((struct ixgbe_osdep *)(a)->back)->os_memh, (reg + ((offset) << 2))) 150 #define IXGBE_WRITE_REG_ARRAY(a, reg, offset, value) \ 151 bus_space_write_4(((struct ixgbe_osdep *)(a)->back)->os_memt, \ 152 ((struct ixgbe_osdep *)(a)->back)->os_memh, (reg + ((offset) << 2)), value) 153 154 #define IXGBE_WRITE_REG64(hw, reg, value) \ 155 do { \ 156 IXGBE_WRITE_REG(hw, reg, (uint32_t) value); \ 157 IXGBE_WRITE_REG(hw, reg + 4, (uint32_t) (value >> 32)); \ 158 } while (0) 159 160 uint32_t ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw); 161 162 int32_t ixgbe_init_ops_generic(struct ixgbe_hw *hw); 163 int32_t ixgbe_init_hw_generic(struct ixgbe_hw *hw); 164 int32_t ixgbe_start_hw_generic(struct ixgbe_hw *hw); 165 int32_t ixgbe_start_hw_gen2(struct ixgbe_hw *hw); 166 int32_t ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw); 167 int32_t ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, uint32_t *pba_num); 168 int32_t ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, uint8_t *pba_num, 169 uint32_t pba_num_size); 170 int32_t ixgbe_read_pba_length_generic(struct ixgbe_hw *hw, uint32_t *pba_num_size); 171 int32_t ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, uint8_t *mac_addr); 172 int32_t ixgbe_get_bus_info_generic(struct ixgbe_hw *hw); 173 void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw); 174 int32_t ixgbe_stop_adapter_generic(struct ixgbe_hw *hw); 175 176 int32_t ixgbe_led_on_generic(struct ixgbe_hw *hw, uint32_t index); 177 int32_t ixgbe_led_off_generic(struct ixgbe_hw *hw, uint32_t index); 178 179 int32_t ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw); 180 int32_t ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, uint16_t offset, uint16_t data); 181 int32_t ixgbe_read_eerd_generic(struct ixgbe_hw *hw, uint16_t offset, uint16_t *data); 182 int32_t ixgbe_write_eewr_generic(struct ixgbe_hw *hw, uint16_t offset, uint16_t data); 183 int32_t ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, uint16_t offset, 184 uint16_t *data); 185 uint16_t ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw); 186 int32_t ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw, 187 uint16_t *checksum_val); 188 int32_t ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw); 189 int32_t ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, uint32_t ee_reg); 190 191 int32_t ixgbe_set_rar_generic(struct ixgbe_hw *hw, uint32_t index, uint8_t *addr, uint32_t vmdq, 192 uint32_t enable_addr); 193 int32_t ixgbe_clear_rar_generic(struct ixgbe_hw *hw, uint32_t index); 194 int32_t ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw); 195 int32_t ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, uint8_t *mc_addr_list, 196 uint32_t mc_addr_count, 197 ixgbe_mc_addr_itr func); 198 int32_t ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, uint8_t *addr_list, 199 uint32_t addr_count, ixgbe_mc_addr_itr func); 200 int32_t ixgbe_enable_mc_generic(struct ixgbe_hw *hw); 201 int32_t ixgbe_disable_mc_generic(struct ixgbe_hw *hw); 202 int32_t ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, uint32_t regval); 203 204 int32_t ixgbe_setup_fc(struct ixgbe_hw *hw, int32_t packetbuf_num); 205 int32_t ixgbe_fc_enable_generic(struct ixgbe_hw *hw, int32_t packtetbuf_num); 206 int32_t ixgbe_fc_autoneg(struct ixgbe_hw *hw); 207 208 int32_t ixgbe_validate_mac_addr(uint8_t *mac_addr); 209 int32_t ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, uint16_t mask); 210 void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, uint16_t mask); 211 int32_t ixgbe_disable_pcie_master(struct ixgbe_hw *hw); 212 213 int32_t ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, uint32_t index); 214 int32_t ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, uint32_t index); 215 216 int32_t ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, uint8_t *san_mac_addr); 217 int32_t ixgbe_set_san_mac_addr_generic(struct ixgbe_hw *hw, uint8_t *san_mac_addr); 218 219 int32_t ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, uint32_t rar, uint32_t vmdq); 220 int32_t ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, uint32_t rar, uint32_t vmdq); 221 int32_t ixgbe_insert_mac_addr_generic(struct ixgbe_hw *hw, uint8_t *addr, uint32_t vmdq); 222 int32_t ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw); 223 int32_t ixgbe_set_vfta_generic(struct ixgbe_hw *hw, uint32_t vlan, 224 uint32_t vind, int vlan_on); 225 int32_t ixgbe_clear_vfta_generic(struct ixgbe_hw *hw); 226 227 int32_t ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, 228 ixgbe_link_speed *speed, 229 int *link_up, int link_up_wait_to_complete); 230 231 int32_t ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, uint16_t *wwnn_prefix, 232 uint16_t *wwpn_prefix); 233 234 int32_t ixgbe_get_fcoe_boot_status_generic(struct ixgbe_hw *hw, uint16_t *bs); 235 void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, int enable, int pf); 236 void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, int enable, int vf); 237 int32_t ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, uint16_t *device_caps); 238 void ixgbe_enable_relaxed_ordering_gen2(struct ixgbe_hw *hw); 239 240 /* API */ 241 void ixgbe_add_uc_addr(struct ixgbe_hw *hw, uint8_t *addr, uint32_t vmdq); 242 void ixgbe_set_mta(struct ixgbe_hw *hw, uint8_t *mc_addr); 243 244 int32_t ixgbe_reinit_fdir_tables_82599(struct ixgbe_hw *hw); 245 int32_t ixgbe_init_fdir_signature_82599(struct ixgbe_hw *hw, uint32_t pballoc); 246 int32_t ixgbe_init_fdir_perfect_82599(struct ixgbe_hw *hw, uint32_t pballoc); 247 int32_t ixgbe_fdir_add_perfect_filter_82599(struct ixgbe_hw *hw, 248 union ixgbe_atr_input *input, 249 struct ixgbe_atr_input_masks *masks, 250 uint16_t soft_id, 251 uint8_t queue); 252 uint32_t ixgbe_atr_compute_hash_82599(union ixgbe_atr_input *input, uint32_t key); 253 254 int32_t ixgbe_init_ops_82598(struct ixgbe_hw *hw); 255 int32_t ixgbe_init_ops_82599(struct ixgbe_hw *hw); 256 257 /* PHY */ 258 int32_t ixgbe_init_phy_ops_generic(struct ixgbe_hw *hw); 259 int ixgbe_validate_phy_addr(struct ixgbe_hw *hw, uint32_t phy_addr); 260 enum ixgbe_phy_type ixgbe_get_phy_type_from_id(uint32_t phy_id); 261 int32_t ixgbe_get_phy_id(struct ixgbe_hw *hw); 262 int32_t ixgbe_identify_phy_generic(struct ixgbe_hw *hw); 263 int32_t ixgbe_reset_phy_generic(struct ixgbe_hw *hw); 264 int32_t ixgbe_read_phy_reg_generic(struct ixgbe_hw *hw, uint32_t reg_addr, 265 uint32_t device_type, uint16_t *phy_data); 266 int32_t ixgbe_write_phy_reg_generic(struct ixgbe_hw *hw, uint32_t reg_addr, 267 uint32_t device_type, uint16_t phy_data); 268 int32_t ixgbe_setup_phy_link_generic(struct ixgbe_hw *hw); 269 int32_t ixgbe_setup_phy_link_speed_generic(struct ixgbe_hw *hw, 270 ixgbe_link_speed speed, 271 int autoneg, 272 int autoneg_wait_to_complete); 273 int32_t ixgbe_get_copper_link_capabilities_generic(struct ixgbe_hw *hw, 274 ixgbe_link_speed *speed, 275 int *autoneg); 276 277 /* PHY specific */ 278 int32_t ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, 279 ixgbe_link_speed *speed, 280 int *link_up); 281 int32_t ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw); 282 int32_t ixgbe_get_phy_firmware_version_tnx(struct ixgbe_hw *hw, 283 uint16_t *firmware_version); 284 int32_t ixgbe_get_phy_firmware_version_generic(struct ixgbe_hw *hw, 285 uint16_t *firmware_version); 286 287 int32_t ixgbe_reset_phy_nl(struct ixgbe_hw *hw); 288 int32_t ixgbe_identify_sfp_module_generic(struct ixgbe_hw *hw); 289 int32_t ixgbe_get_sfp_init_sequence_offsets(struct ixgbe_hw *hw, 290 uint16_t *list_offset, 291 uint16_t *data_offset); 292 int32_t ixgbe_tn_check_overtemp(struct ixgbe_hw *hw); 293 int32_t ixgbe_read_i2c_byte_generic(struct ixgbe_hw *hw, uint8_t byte_offset, 294 uint8_t dev_addr, uint8_t *data); 295 int32_t ixgbe_write_i2c_byte_generic(struct ixgbe_hw *hw, uint8_t byte_offset, 296 uint8_t dev_addr, uint8_t data); 297 int32_t ixgbe_read_i2c_eeprom_generic(struct ixgbe_hw *hw, uint8_t byte_offset, 298 uint8_t *eeprom_data); 299 int32_t ixgbe_write_i2c_eeprom_generic(struct ixgbe_hw *hw, uint8_t byte_offset, 300 uint8_t eeprom_data); 301 302 /* MBX */ 303 int32_t ixgbe_read_mbx(struct ixgbe_hw *, uint32_t *, uint16_t, uint16_t); 304 int32_t ixgbe_write_mbx(struct ixgbe_hw *, uint32_t *, uint16_t, uint16_t); 305 int32_t ixgbe_read_posted_mbx(struct ixgbe_hw *, uint32_t *, uint16_t, uint16_t); 306 int32_t ixgbe_write_posted_mbx(struct ixgbe_hw *, uint32_t *, uint16_t, uint16_t); 307 int32_t ixgbe_check_for_msg(struct ixgbe_hw *, uint16_t); 308 int32_t ixgbe_check_for_ack(struct ixgbe_hw *, uint16_t); 309 int32_t ixgbe_check_for_rst(struct ixgbe_hw *, uint16_t); 310 void ixgbe_init_mbx_ops_generic(struct ixgbe_hw *hw); 311 void ixgbe_init_mbx_params_vf(struct ixgbe_hw *); 312 void ixgbe_init_mbx_params_pf(struct ixgbe_hw *); 313 314 #endif /* _IXGBE_H_ */ 315