28 #include <linux/pci.h>
30 #include <linux/sched.h>
36 #define IXGBE_82599_MAX_TX_QUEUES 128
37 #define IXGBE_82599_MAX_RX_QUEUES 128
38 #define IXGBE_82599_RAR_ENTRIES 128
39 #define IXGBE_82599_MC_TBL_SIZE 128
40 #define IXGBE_82599_VFT_TBL_SIZE 128
41 #define IXGBE_82599_RX_PB_SIZE 512
43 static void ixgbe_disable_tx_laser_multispeed_fiber(
struct ixgbe_hw *
hw);
44 static void ixgbe_enable_tx_laser_multispeed_fiber(
struct ixgbe_hw *
hw);
45 static void ixgbe_flap_tx_laser_multispeed_fiber(
struct ixgbe_hw *
hw);
46 static s32 ixgbe_setup_mac_link_multispeed_fiber(
struct ixgbe_hw *
hw,
49 bool autoneg_wait_to_complete);
50 static s32 ixgbe_setup_mac_link_smartspeed(
struct ixgbe_hw *
hw,
53 bool autoneg_wait_to_complete);
55 bool autoneg_wait_to_complete);
59 bool autoneg_wait_to_complete);
63 bool autoneg_wait_to_complete);
64 static s32 ixgbe_verify_fw_version_82599(
struct ixgbe_hw *
hw);
65 static bool ixgbe_verify_lesm_fw_enabled_82599(
struct ixgbe_hw *
hw);
67 static void ixgbe_init_mac_link_ops_82599(
struct ixgbe_hw *
hw)
73 mac->
ops.disable_tx_laser =
74 &ixgbe_disable_tx_laser_multispeed_fiber;
75 mac->
ops.enable_tx_laser =
76 &ixgbe_enable_tx_laser_multispeed_fiber;
77 mac->
ops.flap_tx_laser = &ixgbe_flap_tx_laser_multispeed_fiber;
79 mac->
ops.disable_tx_laser =
NULL;
80 mac->
ops.enable_tx_laser =
NULL;
84 if (hw->
phy.multispeed_fiber) {
86 mac->
ops.setup_link = &ixgbe_setup_mac_link_multispeed_fiber;
88 if ((mac->
ops.get_media_type(hw) ==
92 !ixgbe_verify_lesm_fw_enabled_82599(hw))
93 mac->
ops.setup_link = &ixgbe_setup_mac_link_smartspeed;
95 mac->
ops.setup_link = &ixgbe_setup_mac_link_82599;
99 static s32 ixgbe_setup_sfp_modules_82599(
struct ixgbe_hw *hw)
107 ixgbe_init_mac_link_ops_82599(hw);
117 ret_val = hw->
mac.ops.acquire_swfw_sync(hw,
124 hw->
eeprom.ops.read(hw, ++data_offset, &data_value);
125 while (data_value != 0xffff) {
128 hw->
eeprom.ops.read(hw, ++data_offset, &data_value);
138 hw->
eeprom.semaphore_delay * 2000);
146 for (i = 0; i < 10; i++) {
153 hw_dbg(hw,
"sfp module setup not complete\n");
168 static s32 ixgbe_get_invariants_82599(
struct ixgbe_hw *hw)
172 ixgbe_init_mac_link_ops_82599(hw);
193 static s32 ixgbe_init_phy_ops_82599(
struct ixgbe_hw *hw)
200 ret_val = phy->
ops.identify(hw);
203 ixgbe_init_mac_link_ops_82599(hw);
207 mac->
ops.setup_link = &ixgbe_setup_copper_link_82599;
208 mac->
ops.get_link_capabilities =
213 switch (hw->
phy.type) {
217 phy->
ops.get_firmware_version =
235 static s32 ixgbe_get_link_capabilities_82599(
struct ixgbe_hw *hw,
257 if (hw->
mac.orig_link_settings_stored)
258 autoc = hw->
mac.orig_autoc;
265 *negotiation =
false;
270 *negotiation =
false;
280 *negotiation =
false;
297 if (autoc & IXGBE_AUTOC_KR_SUPP)
299 if (autoc & IXGBE_AUTOC_KX4_SUPP)
301 if (autoc & IXGBE_AUTOC_KX_SUPP)
308 *negotiation =
false;
317 if (hw->
phy.multispeed_fiber) {
338 switch (hw->
phy.type) {
390 static s32 ixgbe_start_mac_link_82599(
struct ixgbe_hw *hw,
391 bool autoneg_wait_to_complete)
404 if (autoneg_wait_to_complete) {
405 if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
407 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
409 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
420 hw_dbg(hw,
"Autoneg did not complete.\n");
439 static void ixgbe_disable_tx_laser_multispeed_fiber(
struct ixgbe_hw *hw)
458 static void ixgbe_enable_tx_laser_multispeed_fiber(
struct ixgbe_hw *hw)
481 static void ixgbe_flap_tx_laser_multispeed_fiber(
struct ixgbe_hw *hw)
483 if (hw->
mac.autotry_restart) {
484 ixgbe_disable_tx_laser_multispeed_fiber(hw);
485 ixgbe_enable_tx_laser_multispeed_fiber(hw);
486 hw->
mac.autotry_restart =
false;
499 static s32 ixgbe_setup_mac_link_multispeed_fiber(
struct ixgbe_hw *hw,
502 bool autoneg_wait_to_complete)
514 status = hw->
mac.ops.get_link_capabilities(hw, &link_speed,
530 status = hw->
mac.ops.check_link(hw, &link_speed, &link_up,
535 if ((link_speed == IXGBE_LINK_SPEED_10GB_FULL) && link_up)
546 status = ixgbe_setup_mac_link_82599(hw,
547 IXGBE_LINK_SPEED_10GB_FULL,
549 autoneg_wait_to_complete);
554 hw->
mac.ops.flap_tx_laser(hw);
561 for (i = 0; i < 5; i++) {
566 status = hw->
mac.ops.check_link(hw, &link_speed,
582 status = hw->
mac.ops.check_link(hw, &link_speed, &link_up,
587 if ((link_speed == IXGBE_LINK_SPEED_1GB_FULL) && link_up)
599 status = ixgbe_setup_mac_link_82599(hw,
600 IXGBE_LINK_SPEED_1GB_FULL,
602 autoneg_wait_to_complete);
607 hw->
mac.ops.flap_tx_laser(hw);
613 status = hw->
mac.ops.check_link(hw, &link_speed, &link_up,
628 status = ixgbe_setup_mac_link_multispeed_fiber(hw,
631 autoneg_wait_to_complete);
635 hw->
phy.autoneg_advertised = 0;
637 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
640 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
655 static s32 ixgbe_setup_mac_link_smartspeed(
struct ixgbe_hw *hw,
657 bool autoneg_wait_to_complete)
662 bool link_up =
false;
666 hw->
phy.autoneg_advertised = 0;
668 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
671 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
685 hw->
phy.smart_speed_active =
false;
687 status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
688 autoneg_wait_to_complete);
698 for (i = 0; i < 5; i++) {
702 status = hw->
mac.ops.check_link(hw, &link_speed,
716 if (((autoc_reg & IXGBE_AUTOC_KR_SUPP) == 0) ||
721 hw->
phy.smart_speed_active =
true;
722 status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
723 autoneg_wait_to_complete);
733 for (i = 0; i < 6; i++) {
737 status = hw->
mac.ops.check_link(hw, &link_speed,
747 hw->
phy.smart_speed_active =
false;
748 status = ixgbe_setup_mac_link_82599(hw, speed, autoneg,
749 autoneg_wait_to_complete);
752 if (link_up && (link_speed == IXGBE_LINK_SPEED_1GB_FULL))
753 hw_dbg(hw,
"Smartspeed has downgraded the link speed from "
754 "the maximum advertised\n");
767 static s32 ixgbe_setup_mac_link_82599(
struct ixgbe_hw *hw,
769 bool autoneg_wait_to_complete)
774 u32 start_autoc = autoc;
784 status = hw->
mac.ops.get_link_capabilities(hw, &link_capabilities,
789 speed &= link_capabilities;
797 if (hw->
mac.orig_link_settings_stored)
798 orig_autoc = hw->
mac.orig_autoc;
807 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
808 if (orig_autoc & IXGBE_AUTOC_KX4_SUPP)
810 if ((orig_autoc & IXGBE_AUTOC_KR_SUPP) &&
811 (hw->
phy.smart_speed_active ==
false))
814 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
820 if ((speed == IXGBE_LINK_SPEED_10GB_FULL) &&
822 autoc &= ~IXGBE_AUTOC_LMS_MASK;
828 if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
830 autoc &= ~IXGBE_AUTOC_LMS_MASK;
838 if (autoc != start_autoc) {
844 if (autoneg_wait_to_complete) {
859 hw_dbg(hw,
"Autoneg did not "
882 static s32 ixgbe_setup_copper_link_82599(
struct ixgbe_hw *hw,
885 bool autoneg_wait_to_complete)
890 status = hw->
phy.ops.setup_link_speed(hw, speed, autoneg,
891 autoneg_wait_to_complete);
893 ixgbe_start_mac_link_82599(hw, autoneg_wait_to_complete);
906 static s32 ixgbe_reset_hw_82599(
struct ixgbe_hw *hw)
911 bool link_up =
false;
914 status = hw->
mac.ops.stop_adapter(hw);
924 status = hw->
phy.ops.init(hw);
930 if (hw->
phy.sfp_setup_needed) {
931 status = hw->
mac.ops.setup_sfp(hw);
932 hw->
phy.sfp_setup_needed =
false;
939 if (hw->
phy.reset_disable ==
false && hw->
phy.ops.reset !=
NULL)
940 hw->
phy.ops.reset(hw);
951 hw->
mac.ops.check_link(hw, &link_speed, &link_up,
false);
961 for (i = 0; i < 10; i++) {
970 hw_dbg(hw,
"Reset polling failed to complete.\n");
992 if (hw->
mac.orig_link_settings_stored ==
false) {
993 hw->
mac.orig_autoc = autoc;
994 hw->
mac.orig_autoc2 = autoc2;
995 hw->
mac.orig_link_settings_stored =
true;
997 if (autoc != hw->
mac.orig_autoc)
1002 (hw->
mac.orig_autoc2 & IXGBE_AUTOC2_UPPER_MASK)) {
1003 autoc2 &= ~IXGBE_AUTOC2_UPPER_MASK;
1004 autoc2 |= (hw->
mac.orig_autoc2 &
1011 hw->
mac.ops.get_mac_addr(hw, hw->
mac.perm_addr);
1018 hw->
mac.num_rar_entries = 128;
1019 hw->
mac.ops.init_rx_addrs(hw);
1022 hw->
mac.ops.get_san_mac_addr(hw, hw->
mac.san_addr);
1026 hw->
mac.ops.set_rar(hw, hw->
mac.num_rar_entries - 1,
1030 hw->
mac.san_mac_rar_index = hw->
mac.num_rar_entries - 1;
1033 hw->
mac.num_rar_entries--;
1037 hw->
mac.ops.get_wwn_prefix(hw, &hw->
mac.wwnn_prefix,
1038 &hw->
mac.wwpn_prefix);
1064 if (i >= IXGBE_FDIRCMD_CMD_POLL) {
1065 hw_dbg(hw,
"Flow Director previous command isn't complete, "
1066 "aborting table re-initialization.\n");
1104 if (i >= IXGBE_FDIR_INIT_DONE_POLL) {
1105 hw_dbg(hw,
"Flow Director Signature poll time exceeded!\n");
1124 static void ixgbe_fdir_enable_82599(
struct ixgbe_hw *hw,
u32 fdirctrl)
1154 if (i >= IXGBE_FDIR_INIT_DONE_POLL)
1155 hw_dbg(hw,
"Flow Director poll time exceeded!\n");
1177 ixgbe_fdir_enable_82599(hw, fdirctrl);
1207 ixgbe_fdir_enable_82599(hw, fdirctrl);
1217 #define IXGBE_ATR_COMMON_HASH_KEY \
1218 (IXGBE_ATR_BUCKET_HASH_KEY & IXGBE_ATR_SIGNATURE_HASH_KEY)
1219 #define IXGBE_COMPUTE_SIG_HASH_ITERATION(_n) \
1222 if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << n)) \
1223 common_hash ^= lo_hash_dword >> n; \
1224 else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
1225 bucket_hash ^= lo_hash_dword >> n; \
1226 else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << n)) \
1227 sig_hash ^= lo_hash_dword << (16 - n); \
1228 if (IXGBE_ATR_COMMON_HASH_KEY & (0x01 << (n + 16))) \
1229 common_hash ^= hi_hash_dword >> n; \
1230 else if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
1231 bucket_hash ^= hi_hash_dword >> n; \
1232 else if (IXGBE_ATR_SIGNATURE_HASH_KEY & (0x01 << (n + 16))) \
1233 sig_hash ^= hi_hash_dword << (16 - n); \
1249 u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
1250 u32 sig_hash = 0, bucket_hash = 0, common_hash = 0;
1259 lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
1262 hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
1272 lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
1292 bucket_hash ^= common_hash;
1295 sig_hash ^= common_hash << 16;
1299 return sig_hash ^ bucket_hash;
1330 hw_dbg(hw,
" Error on flow type input\n");
1344 fdirhashcmd = (
u64)fdircmd << 32;
1345 fdirhashcmd |= ixgbe_atr_compute_sig_hash_82599(input, common);
1348 hw_dbg(hw,
"Tx Queue=%x hash=%x\n", queue, (
u32)fdirhashcmd);
1353 #define IXGBE_COMPUTE_BKT_HASH_ITERATION(_n) \
1356 if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << n)) \
1357 bucket_hash ^= lo_hash_dword >> n; \
1358 if (IXGBE_ATR_BUCKET_HASH_KEY & (0x01 << (n + 16))) \
1359 bucket_hash ^= hi_hash_dword >> n; \
1377 u32 hi_hash_dword, lo_hash_dword, flow_vm_vlan;
1378 u32 bucket_hash = 0;
1409 lo_hash_dword = (hi_hash_dword >> 16) | (hi_hash_dword << 16);
1412 hi_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan >> 16);
1422 lo_hash_dword ^= flow_vm_vlan ^ (flow_vm_vlan << 16);
1445 input->
formatted.bkt_hash = bucket_hash & 0x1FFF;
1462 mask = ((mask & 0x55555555) << 1) | ((mask & 0xAAAAAAAA) >> 1);
1463 mask = ((mask & 0x33333333) << 2) | ((mask & 0xCCCCCCCC) >> 2);
1464 mask = ((mask & 0x0F0F0F0F) << 4) | ((mask & 0xF0F0F0F0) >> 4);
1465 return ((mask & 0x00FF00FF) << 8) | ((mask & 0xFF00FF00) >> 8);
1475 #define IXGBE_STORE_AS_BE32(_value) \
1476 (((u32)(_value) >> 24) | (((u32)(_value) & 0x00FF0000) >> 8) | \
1477 (((u32)(_value) & 0x0000FF00) << 8) | ((u32)(_value) << 24))
1479 #define IXGBE_WRITE_REG_BE32(a, reg, value) \
1480 IXGBE_WRITE_REG((a), (reg), IXGBE_STORE_AS_BE32(ntohl(value)))
1482 #define IXGBE_STORE_AS_BE16(_value) \
1483 ntohs(((u16)(_value) >> 8) | ((u16)(_value) << 8))
1504 hw_dbg(hw,
" bucket hash should always be 0 in mask\n");
1507 switch (input_mask->
formatted.vm_pool & 0x7F) {
1513 hw_dbg(hw,
" Error on vm pool mask\n");
1522 hw_dbg(hw,
" Error on src/dst port mask\n");
1528 hw_dbg(hw,
" Error on flow type mask\n");
1547 hw_dbg(hw,
" Error on VLAN mask\n");
1551 switch (input_mask->
formatted.flex_bytes & 0xFFFF) {
1558 hw_dbg(hw,
" Error on flexible byte mask\n");
1566 fdirtcpm = ixgbe_get_fdirtcpm_82599(input_mask);
1585 u32 fdirport, fdirvlan, fdirhash, fdircmd;
1658 for (retry_count = 10;
retry_count; retry_count--) {
1698 *val = (
u8)core_ctl;
1711 static s32 ixgbe_write_analog_reg8_82599(
struct ixgbe_hw *hw,
u32 reg,
u8 val)
1715 core_ctl = (reg << 8) | val;
1731 static s32 ixgbe_start_hw_82599(
struct ixgbe_hw *hw)
1744 hw->
mac.autotry_restart =
true;
1748 ret_val = ixgbe_verify_fw_version_82599(hw);
1761 static s32 ixgbe_identify_phy_82599(
struct ixgbe_hw *hw)
1795 static u32 ixgbe_get_supported_physical_layer_82599(
struct ixgbe_hw *hw)
1803 u16 ext_ability = 0;
1804 u8 comp_codes_10g = 0;
1805 u8 comp_codes_1g = 0;
1807 hw->
phy.ops.identify(hw);
1809 switch (hw->
phy.type) {
1825 switch (autoc & IXGBE_AUTOC_LMS_MASK) {
1854 if (autoc & IXGBE_AUTOC_KX_SUPP)
1856 if (autoc & IXGBE_AUTOC_KX4_SUPP)
1858 if (autoc & IXGBE_AUTOC_KR_SUPP)
1871 hw->
phy.ops.identify_sfp(hw);
1875 switch (hw->
phy.type) {
1888 hw->
phy.ops.read_i2c_eeprom(hw,
1890 hw->
phy.ops.read_i2c_eeprom(hw,
1904 return physical_layer;
1922 hw->
mac.ops.disable_rx_buff(hw);
1926 hw->
mac.ops.enable_rx_buff(hw);
1941 static s32 ixgbe_verify_fw_version_82599(
struct ixgbe_hw *hw)
1944 u16 fw_offset, fw_ptp_cfg_offset;
1950 goto fw_version_out;
1956 if ((fw_offset == 0) || (fw_offset == 0xFFFF))
1957 goto fw_version_out;
1960 hw->
eeprom.ops.read(hw, (fw_offset +
1962 &fw_ptp_cfg_offset);
1964 if ((fw_ptp_cfg_offset == 0) || (fw_ptp_cfg_offset == 0xFFFF))
1965 goto fw_version_out;
1968 hw->
eeprom.ops.read(hw, (fw_ptp_cfg_offset +
1972 if (fw_version > 0x5)
1986 static bool ixgbe_verify_lesm_fw_enabled_82599(
struct ixgbe_hw *hw)
1988 bool lesm_enabled =
false;
1989 u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
1995 if ((status != 0) ||
1996 (fw_offset == 0) || (fw_offset == 0xFFFF))
2000 status = hw->
eeprom.ops.read(hw, (fw_offset +
2002 &fw_lesm_param_offset);
2004 if ((status != 0) ||
2005 (fw_lesm_param_offset == 0) || (fw_lesm_param_offset == 0xFFFF))
2009 status = hw->
eeprom.ops.read(hw, (fw_lesm_param_offset +
2013 if ((status == 0) &&
2015 lesm_enabled =
true;
2018 return lesm_enabled;
2064 static s32 ixgbe_read_eeprom_82599(
struct ixgbe_hw *hw,
2085 .reset_hw = &ixgbe_reset_hw_82599,
2086 .start_hw = &ixgbe_start_hw_82599,
2088 .get_media_type = &ixgbe_get_media_type_82599,
2089 .get_supported_physical_layer = &ixgbe_get_supported_physical_layer_82599,
2090 .enable_rx_dma = &ixgbe_enable_rx_dma_82599,
2100 .read_analog_reg8 = &ixgbe_read_analog_reg8_82599,
2101 .write_analog_reg8 = &ixgbe_write_analog_reg8_82599,
2102 .setup_link = &ixgbe_setup_mac_link_82599,
2105 .get_link_capabilities = &ixgbe_get_link_capabilities_82599,
2124 .setup_sfp = &ixgbe_setup_sfp_modules_82599,
2136 .read = &ixgbe_read_eeprom_82599,
2137 .read_buffer = &ixgbe_read_eeprom_buffer_82599,
2146 .identify = &ixgbe_identify_phy_82599,
2148 .init = &ixgbe_init_phy_ops_82599,
2163 .get_invariants = &ixgbe_get_invariants_82599,
2164 .mac_ops = &mac_ops_82599,
2165 .eeprom_ops = &eeprom_ops_82599,
2166 .phy_ops = &phy_ops_82599,