16621Sbt150084 /* 26621Sbt150084 * CDDL HEADER START 36621Sbt150084 * 49353SSamuel.Tu@Sun.COM * Copyright(c) 2007-2009 Intel Corporation. All rights reserved. 56621Sbt150084 * The contents of this file are subject to the terms of the 66621Sbt150084 * Common Development and Distribution License (the "License"). 76621Sbt150084 * You may not use this file except in compliance with the License. 86621Sbt150084 * 98275SEric Cheng * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 108275SEric Cheng * or http://www.opensolaris.org/os/licensing. 116621Sbt150084 * See the License for the specific language governing permissions 126621Sbt150084 * and limitations under the License. 136621Sbt150084 * 148275SEric Cheng * When distributing Covered Code, include this CDDL HEADER in each 158275SEric Cheng * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 166621Sbt150084 * If applicable, add the following below this CDDL HEADER, with the 176621Sbt150084 * fields enclosed by brackets "[]" replaced with your own identifying 186621Sbt150084 * information: Portions Copyright [yyyy] [name of copyright owner] 196621Sbt150084 * 206621Sbt150084 * CDDL HEADER END 216621Sbt150084 */ 226621Sbt150084 236621Sbt150084 /* 248490SPaul.Guo@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 258275SEric Cheng * Use is subject to license terms. 266621Sbt150084 */ 276621Sbt150084 289353SSamuel.Tu@Sun.COM /* IntelVersion: 1.199 v2-7-8_2009-4-7 */ 296621Sbt150084 306621Sbt150084 #include "ixgbe_common.h" 316621Sbt150084 #include "ixgbe_api.h" 326621Sbt150084 336621Sbt150084 static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw); 346621Sbt150084 static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw); 356621Sbt150084 static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw); 366621Sbt150084 static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw); 376621Sbt150084 static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw); 386621Sbt150084 static void ixgbe_standby_eeprom(struct ixgbe_hw *hw); 396621Sbt150084 static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data, 406621Sbt150084 u16 count); 416621Sbt150084 static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count); 426621Sbt150084 static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec); 436621Sbt150084 static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec); 446621Sbt150084 static void ixgbe_release_eeprom(struct ixgbe_hw *hw); 456621Sbt150084 static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw); 466621Sbt150084 476621Sbt150084 static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr); 486621Sbt150084 496621Sbt150084 /* 506621Sbt150084 * ixgbe_init_ops_generic - Inits function ptrs 516621Sbt150084 * @hw: pointer to the hardware structure 526621Sbt150084 * 536621Sbt150084 * Initialize the function pointers. 546621Sbt150084 */ 556621Sbt150084 s32 566621Sbt150084 ixgbe_init_ops_generic(struct ixgbe_hw *hw) 576621Sbt150084 { 586621Sbt150084 struct ixgbe_eeprom_info *eeprom = &hw->eeprom; 596621Sbt150084 struct ixgbe_mac_info *mac = &hw->mac; 608490SPaul.Guo@Sun.COM u32 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 616621Sbt150084 626621Sbt150084 /* EEPROM */ 636621Sbt150084 eeprom->ops.init_params = &ixgbe_init_eeprom_params_generic; 648490SPaul.Guo@Sun.COM /* If EEPROM is valid (bit 8 = 1), use EERD otherwise use bit bang */ 658490SPaul.Guo@Sun.COM if (eec & (1 << 8)) 668490SPaul.Guo@Sun.COM eeprom->ops.read = &ixgbe_read_eeprom_generic; 678490SPaul.Guo@Sun.COM else 688490SPaul.Guo@Sun.COM eeprom->ops.read = &ixgbe_read_eeprom_bit_bang_generic; 696621Sbt150084 eeprom->ops.write = &ixgbe_write_eeprom_generic; 706621Sbt150084 eeprom->ops.validate_checksum = 716621Sbt150084 &ixgbe_validate_eeprom_checksum_generic; 726621Sbt150084 eeprom->ops.update_checksum = &ixgbe_update_eeprom_checksum_generic; 736621Sbt150084 746621Sbt150084 /* MAC */ 756621Sbt150084 mac->ops.init_hw = &ixgbe_init_hw_generic; 766621Sbt150084 mac->ops.reset_hw = NULL; 776621Sbt150084 mac->ops.start_hw = &ixgbe_start_hw_generic; 786621Sbt150084 mac->ops.clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic; 796621Sbt150084 mac->ops.get_media_type = NULL; 808490SPaul.Guo@Sun.COM mac->ops.get_supported_physical_layer = NULL; 819353SSamuel.Tu@Sun.COM mac->ops.enable_rx_dma = &ixgbe_enable_rx_dma_generic; 826621Sbt150084 mac->ops.get_mac_addr = &ixgbe_get_mac_addr_generic; 836621Sbt150084 mac->ops.stop_adapter = &ixgbe_stop_adapter_generic; 846621Sbt150084 mac->ops.get_bus_info = &ixgbe_get_bus_info_generic; 859353SSamuel.Tu@Sun.COM mac->ops.set_lan_id = &ixgbe_set_lan_id_multi_port_pcie; 866621Sbt150084 876621Sbt150084 /* LEDs */ 886621Sbt150084 mac->ops.led_on = &ixgbe_led_on_generic; 896621Sbt150084 mac->ops.led_off = &ixgbe_led_off_generic; 909353SSamuel.Tu@Sun.COM mac->ops.blink_led_start = &ixgbe_blink_led_start_generic; 919353SSamuel.Tu@Sun.COM mac->ops.blink_led_stop = &ixgbe_blink_led_stop_generic; 926621Sbt150084 936621Sbt150084 /* RAR, Multicast, VLAN */ 946621Sbt150084 mac->ops.set_rar = &ixgbe_set_rar_generic; 958490SPaul.Guo@Sun.COM mac->ops.clear_rar = &ixgbe_clear_rar_generic; 969353SSamuel.Tu@Sun.COM mac->ops.insert_mac_addr = NULL; 976621Sbt150084 mac->ops.set_vmdq = NULL; 988490SPaul.Guo@Sun.COM mac->ops.clear_vmdq = NULL; 996621Sbt150084 mac->ops.init_rx_addrs = &ixgbe_init_rx_addrs_generic; 1006621Sbt150084 mac->ops.update_uc_addr_list = &ixgbe_update_uc_addr_list_generic; 1016621Sbt150084 mac->ops.update_mc_addr_list = &ixgbe_update_mc_addr_list_generic; 1026621Sbt150084 mac->ops.enable_mc = &ixgbe_enable_mc_generic; 1036621Sbt150084 mac->ops.disable_mc = &ixgbe_disable_mc_generic; 1048490SPaul.Guo@Sun.COM mac->ops.clear_vfta = NULL; 1058490SPaul.Guo@Sun.COM mac->ops.set_vfta = NULL; 1068490SPaul.Guo@Sun.COM mac->ops.init_uta_tables = NULL; 1076621Sbt150084 1086621Sbt150084 /* Flow Control */ 1099353SSamuel.Tu@Sun.COM mac->ops.fc_enable = &ixgbe_fc_enable_generic; 1106621Sbt150084 1116621Sbt150084 /* Link */ 1126621Sbt150084 mac->ops.get_link_capabilities = NULL; 1136621Sbt150084 mac->ops.setup_link = NULL; 1146621Sbt150084 mac->ops.setup_link_speed = NULL; 1156621Sbt150084 mac->ops.check_link = NULL; 1166621Sbt150084 1176621Sbt150084 return (IXGBE_SUCCESS); 1186621Sbt150084 } 1196621Sbt150084 1206621Sbt150084 /* 1216621Sbt150084 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx 1226621Sbt150084 * @hw: pointer to hardware structure 1236621Sbt150084 * 1246621Sbt150084 * Starts the hardware by filling the bus info structure and media type, clears 1256621Sbt150084 * all on chip counters, initializes receive address registers, multicast 1266621Sbt150084 * table, VLAN filter table, calls routine to set up link and flow control 1276621Sbt150084 * settings, and leaves transmit and receive units disabled and uninitialized 1286621Sbt150084 */ 1296621Sbt150084 s32 1306621Sbt150084 ixgbe_start_hw_generic(struct ixgbe_hw *hw) 1316621Sbt150084 { 1326621Sbt150084 u32 ctrl_ext; 1336621Sbt150084 1346621Sbt150084 /* Set the media type */ 1356621Sbt150084 hw->phy.media_type = hw->mac.ops.get_media_type(hw); 1366621Sbt150084 1379353SSamuel.Tu@Sun.COM /* PHY ops initialization must be done in reset_hw() */ 1386621Sbt150084 1396621Sbt150084 /* Identify the PHY */ 1406621Sbt150084 hw->phy.ops.identify(hw); 1416621Sbt150084 1426621Sbt150084 /* Clear the VLAN filter table */ 1436621Sbt150084 hw->mac.ops.clear_vfta(hw); 1446621Sbt150084 1456621Sbt150084 /* Clear statistics registers */ 1466621Sbt150084 hw->mac.ops.clear_hw_cntrs(hw); 1476621Sbt150084 1486621Sbt150084 /* Set No Snoop Disable */ 1496621Sbt150084 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); 1506621Sbt150084 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS; 1516621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); 1526621Sbt150084 IXGBE_WRITE_FLUSH(hw); 1536621Sbt150084 1549353SSamuel.Tu@Sun.COM /* Setup flow control */ 1559353SSamuel.Tu@Sun.COM (void) ixgbe_setup_fc(hw, 0); 1569353SSamuel.Tu@Sun.COM 1576621Sbt150084 /* Clear adapter stopped flag */ 1588490SPaul.Guo@Sun.COM hw->adapter_stopped = false; 1596621Sbt150084 1606621Sbt150084 return (IXGBE_SUCCESS); 1616621Sbt150084 } 1626621Sbt150084 1636621Sbt150084 /* 1646621Sbt150084 * ixgbe_init_hw_generic - Generic hardware initialization 1656621Sbt150084 * @hw: pointer to hardware structure 1666621Sbt150084 * 1676621Sbt150084 * Initialize the hardware by resetting the hardware, filling the bus info 1686621Sbt150084 * structure and media type, clears all on chip counters, initializes receive 1696621Sbt150084 * address registers, multicast table, VLAN filter table, calls routine to set 1706621Sbt150084 * up link and flow control settings, and leaves transmit and receive units 1716621Sbt150084 * disabled and uninitialized 1726621Sbt150084 */ 1736621Sbt150084 s32 1746621Sbt150084 ixgbe_init_hw_generic(struct ixgbe_hw *hw) 1756621Sbt150084 { 1769353SSamuel.Tu@Sun.COM s32 status = IXGBE_SUCCESS; 1779353SSamuel.Tu@Sun.COM 1786621Sbt150084 /* Reset the hardware */ 1799353SSamuel.Tu@Sun.COM status = hw->mac.ops.reset_hw(hw); 1806621Sbt150084 1819353SSamuel.Tu@Sun.COM if (status == IXGBE_SUCCESS) { 1829353SSamuel.Tu@Sun.COM /* Start the HW */ 1839353SSamuel.Tu@Sun.COM status = hw->mac.ops.start_hw(hw); 1849353SSamuel.Tu@Sun.COM } 1856621Sbt150084 1869353SSamuel.Tu@Sun.COM return (status); 1876621Sbt150084 } 1886621Sbt150084 1896621Sbt150084 /* 1906621Sbt150084 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters 1916621Sbt150084 * @hw: pointer to hardware structure 1926621Sbt150084 * 1936621Sbt150084 * Clears all hardware statistics counters by reading them from the hardware 1946621Sbt150084 * Statistics counters are clear on read. 1956621Sbt150084 */ 1966621Sbt150084 s32 1976621Sbt150084 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw) 1986621Sbt150084 { 1996621Sbt150084 u16 i = 0; 2006621Sbt150084 2016621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_CRCERRS); 2026621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_ILLERRC); 2036621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_ERRBC); 2046621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MSPDC); 2056621Sbt150084 for (i = 0; i < 8; i++) 2066621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MPC(i)); 2076621Sbt150084 2086621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MLFC); 2096621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MRFC); 2106621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_RLEC); 2116621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_LXONTXC); 2126621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); 2139353SSamuel.Tu@Sun.COM if (hw->mac.type >= ixgbe_mac_82599EB) { 2149353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); 2159353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); 2169353SSamuel.Tu@Sun.COM } else { 2179353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_LXONRXC); 2189353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); 2199353SSamuel.Tu@Sun.COM } 2206621Sbt150084 2216621Sbt150084 for (i = 0; i < 8; i++) { 2226621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); 2236621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); 2249353SSamuel.Tu@Sun.COM if (hw->mac.type >= ixgbe_mac_82599EB) { 2259353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i)); 2269353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i)); 2279353SSamuel.Tu@Sun.COM } else { 2289353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); 2299353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); 2309353SSamuel.Tu@Sun.COM } 2316621Sbt150084 } 2329353SSamuel.Tu@Sun.COM if (hw->mac.type >= ixgbe_mac_82599EB) 2339353SSamuel.Tu@Sun.COM for (i = 0; i < 8; i++) 2349353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i)); 2356621Sbt150084 2366621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC64); 2376621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC127); 2386621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC255); 2396621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC511); 2406621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC1023); 2416621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC1522); 2426621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GPRC); 2436621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_BPRC); 2446621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MPRC); 2456621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GPTC); 2466621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GORCL); 2476621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GORCH); 2486621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GOTCL); 2496621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GOTCH); 2506621Sbt150084 for (i = 0; i < 8; i++) 2516621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_RNBC(i)); 2526621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_RUC); 2536621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_RFC); 2546621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_ROC); 2556621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_RJC); 2566621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MNGPRC); 2576621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MNGPDC); 2586621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MNGPTC); 2596621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_TORL); 2606621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_TORH); 2616621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_TPR); 2626621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_TPT); 2636621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC64); 2646621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC127); 2656621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC255); 2666621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC511); 2676621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC1023); 2686621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC1522); 2696621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MPTC); 2706621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_BPTC); 2716621Sbt150084 for (i = 0; i < 16; i++) { 2726621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_QPRC(i)); 2736621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_QBRC(i)); 2746621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_QPTC(i)); 2759353SSamuel.Tu@Sun.COM if (hw->mac.type >= ixgbe_mac_82599EB) { 2769353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_QBTC_L(i)); 2779353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); 2789353SSamuel.Tu@Sun.COM } else { 2799353SSamuel.Tu@Sun.COM (void) IXGBE_READ_REG(hw, IXGBE_QBTC(i)); 2809353SSamuel.Tu@Sun.COM } 2816621Sbt150084 } 2826621Sbt150084 2836621Sbt150084 return (IXGBE_SUCCESS); 2846621Sbt150084 } 2856621Sbt150084 2866621Sbt150084 /* 2878490SPaul.Guo@Sun.COM * ixgbe_read_pba_num_generic - Reads part number from EEPROM 2886621Sbt150084 * @hw: pointer to hardware structure 2896621Sbt150084 * @pba_num: stores the part number from the EEPROM 2906621Sbt150084 * 2916621Sbt150084 * Reads the part number from the EEPROM. 2926621Sbt150084 */ 2936621Sbt150084 s32 2946621Sbt150084 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num) 2956621Sbt150084 { 2966621Sbt150084 s32 ret_val; 2976621Sbt150084 u16 data; 2986621Sbt150084 2996621Sbt150084 DEBUGFUNC("ixgbe_read_pba_num_generic"); 3006621Sbt150084 3016621Sbt150084 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data); 3026621Sbt150084 if (ret_val) { 3036621Sbt150084 DEBUGOUT("NVM Read Error\n"); 3046621Sbt150084 return (ret_val); 3056621Sbt150084 } 3066621Sbt150084 *pba_num = (u32)(data << 16); 3076621Sbt150084 3086621Sbt150084 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data); 3096621Sbt150084 if (ret_val) { 3106621Sbt150084 DEBUGOUT("NVM Read Error\n"); 3116621Sbt150084 return (ret_val); 3126621Sbt150084 } 3136621Sbt150084 *pba_num |= data; 3146621Sbt150084 3156621Sbt150084 return (IXGBE_SUCCESS); 3166621Sbt150084 } 3176621Sbt150084 3186621Sbt150084 /* 3196621Sbt150084 * ixgbe_get_mac_addr_generic - Generic get MAC address 3206621Sbt150084 * @hw: pointer to hardware structure 3216621Sbt150084 * @mac_addr: Adapter MAC address 3226621Sbt150084 * 3236621Sbt150084 * Reads the adapter's MAC address from first Receive Address Register (RAR0) 3246621Sbt150084 * A reset of the adapter must be performed prior to calling this function 3256621Sbt150084 * in order for the MAC address to have been loaded from the EEPROM into RAR0 3266621Sbt150084 */ 3276621Sbt150084 s32 3286621Sbt150084 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr) 3296621Sbt150084 { 3306621Sbt150084 u32 rar_high; 3316621Sbt150084 u32 rar_low; 3326621Sbt150084 u16 i; 3336621Sbt150084 3346621Sbt150084 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0)); 3356621Sbt150084 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0)); 3366621Sbt150084 3376621Sbt150084 for (i = 0; i < 4; i++) 3386621Sbt150084 mac_addr[i] = (u8)(rar_low >> (i*8)); 3396621Sbt150084 3406621Sbt150084 for (i = 0; i < 2; i++) 3416621Sbt150084 mac_addr[i+4] = (u8)(rar_high >> (i*8)); 3426621Sbt150084 3436621Sbt150084 return (IXGBE_SUCCESS); 3446621Sbt150084 } 3456621Sbt150084 3466621Sbt150084 /* 3476621Sbt150084 * ixgbe_get_bus_info_generic - Generic set PCI bus info 3486621Sbt150084 * @hw: pointer to hardware structure 3496621Sbt150084 * 3506621Sbt150084 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure 3516621Sbt150084 */ 3526621Sbt150084 s32 3536621Sbt150084 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw) 3546621Sbt150084 { 3559353SSamuel.Tu@Sun.COM struct ixgbe_mac_info *mac = &hw->mac; 3566621Sbt150084 u16 link_status; 3576621Sbt150084 3586621Sbt150084 hw->bus.type = ixgbe_bus_type_pci_express; 3596621Sbt150084 3606621Sbt150084 /* Get the negotiated link width and speed from PCI config space */ 3616621Sbt150084 link_status = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_LINK_STATUS); 3626621Sbt150084 3636621Sbt150084 switch (link_status & IXGBE_PCI_LINK_WIDTH) { 3646621Sbt150084 case IXGBE_PCI_LINK_WIDTH_1: 3656621Sbt150084 hw->bus.width = ixgbe_bus_width_pcie_x1; 3666621Sbt150084 break; 3676621Sbt150084 case IXGBE_PCI_LINK_WIDTH_2: 3686621Sbt150084 hw->bus.width = ixgbe_bus_width_pcie_x2; 3696621Sbt150084 break; 3706621Sbt150084 case IXGBE_PCI_LINK_WIDTH_4: 3716621Sbt150084 hw->bus.width = ixgbe_bus_width_pcie_x4; 3726621Sbt150084 break; 3736621Sbt150084 case IXGBE_PCI_LINK_WIDTH_8: 3746621Sbt150084 hw->bus.width = ixgbe_bus_width_pcie_x8; 3756621Sbt150084 break; 3766621Sbt150084 default: 3776621Sbt150084 hw->bus.width = ixgbe_bus_width_unknown; 3786621Sbt150084 break; 3796621Sbt150084 } 3806621Sbt150084 3816621Sbt150084 switch (link_status & IXGBE_PCI_LINK_SPEED) { 3826621Sbt150084 case IXGBE_PCI_LINK_SPEED_2500: 3836621Sbt150084 hw->bus.speed = ixgbe_bus_speed_2500; 3846621Sbt150084 break; 3856621Sbt150084 case IXGBE_PCI_LINK_SPEED_5000: 3866621Sbt150084 hw->bus.speed = ixgbe_bus_speed_5000; 3876621Sbt150084 break; 3886621Sbt150084 default: 3896621Sbt150084 hw->bus.speed = ixgbe_bus_speed_unknown; 3906621Sbt150084 break; 3916621Sbt150084 } 3926621Sbt150084 3939353SSamuel.Tu@Sun.COM mac->ops.set_lan_id(hw); 3949353SSamuel.Tu@Sun.COM 3956621Sbt150084 return (IXGBE_SUCCESS); 3966621Sbt150084 } 3976621Sbt150084 3989353SSamuel.Tu@Sun.COM 3999353SSamuel.Tu@Sun.COM /* 4009353SSamuel.Tu@Sun.COM * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices 4019353SSamuel.Tu@Sun.COM * @hw: pointer to the HW structure 4029353SSamuel.Tu@Sun.COM * 4039353SSamuel.Tu@Sun.COM * Determines the LAN function id by reading memory-mapped registers 4049353SSamuel.Tu@Sun.COM * and swaps the port value if requested. 4059353SSamuel.Tu@Sun.COM */ 4069353SSamuel.Tu@Sun.COM void 4079353SSamuel.Tu@Sun.COM ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw) 4089353SSamuel.Tu@Sun.COM { 4099353SSamuel.Tu@Sun.COM struct ixgbe_bus_info *bus = &hw->bus; 4109353SSamuel.Tu@Sun.COM u32 reg; 4119353SSamuel.Tu@Sun.COM 4129353SSamuel.Tu@Sun.COM reg = IXGBE_READ_REG(hw, IXGBE_STATUS); 4139353SSamuel.Tu@Sun.COM bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT; 4149353SSamuel.Tu@Sun.COM bus->lan_id = bus->func; 4159353SSamuel.Tu@Sun.COM 4169353SSamuel.Tu@Sun.COM /* check for a port swap */ 4179353SSamuel.Tu@Sun.COM reg = IXGBE_READ_REG(hw, IXGBE_FACTPS); 4189353SSamuel.Tu@Sun.COM if (reg & IXGBE_FACTPS_LFS) 4199353SSamuel.Tu@Sun.COM bus->func ^= 0x1; 4209353SSamuel.Tu@Sun.COM } 4219353SSamuel.Tu@Sun.COM 4226621Sbt150084 /* 4236621Sbt150084 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units 4246621Sbt150084 * @hw: pointer to hardware structure 4256621Sbt150084 * 4266621Sbt150084 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts, 4276621Sbt150084 * disables transmit and receive units. The adapter_stopped flag is used by 4286621Sbt150084 * the shared code and drivers to determine if the adapter is in a stopped 4296621Sbt150084 * state and should not touch the hardware. 4306621Sbt150084 */ 4316621Sbt150084 s32 4326621Sbt150084 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw) 4336621Sbt150084 { 4346621Sbt150084 u32 number_of_queues; 4356621Sbt150084 u32 reg_val; 4366621Sbt150084 u16 i; 4376621Sbt150084 4386621Sbt150084 /* 4396621Sbt150084 * Set the adapter_stopped flag so other driver functions stop touching 4406621Sbt150084 * the hardware 4416621Sbt150084 */ 4428490SPaul.Guo@Sun.COM hw->adapter_stopped = true; 4436621Sbt150084 4446621Sbt150084 /* Disable the receive unit */ 4456621Sbt150084 reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL); 4466621Sbt150084 reg_val &= ~(IXGBE_RXCTRL_RXEN); 4476621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val); 4486621Sbt150084 IXGBE_WRITE_FLUSH(hw); 4496621Sbt150084 msec_delay(2); 4506621Sbt150084 4516621Sbt150084 /* Clear interrupt mask to stop from interrupts being generated */ 4526621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); 4536621Sbt150084 4546621Sbt150084 /* Clear any pending interrupts */ 4556621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_EICR); 4566621Sbt150084 4576621Sbt150084 /* Disable the transmit unit. Each queue must be disabled. */ 4586621Sbt150084 number_of_queues = hw->mac.max_tx_queues; 4596621Sbt150084 for (i = 0; i < number_of_queues; i++) { 4606621Sbt150084 reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); 4616621Sbt150084 if (reg_val & IXGBE_TXDCTL_ENABLE) { 4626621Sbt150084 reg_val &= ~IXGBE_TXDCTL_ENABLE; 4636621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val); 4646621Sbt150084 } 4656621Sbt150084 } 4666621Sbt150084 4676621Sbt150084 /* 4686621Sbt150084 * Prevent the PCI-E bus from from hanging by disabling PCI-E master 4696621Sbt150084 * access and verify no pending requests 4706621Sbt150084 */ 4716621Sbt150084 if (ixgbe_disable_pcie_master(hw) != IXGBE_SUCCESS) { 4726621Sbt150084 DEBUGOUT("PCI-E Master disable polling has failed.\n"); 4736621Sbt150084 } 4746621Sbt150084 4756621Sbt150084 return (IXGBE_SUCCESS); 4766621Sbt150084 } 4776621Sbt150084 4786621Sbt150084 /* 4796621Sbt150084 * ixgbe_led_on_generic - Turns on the software controllable LEDs. 4806621Sbt150084 * @hw: pointer to hardware structure 4816621Sbt150084 * @index: led number to turn on 4826621Sbt150084 */ 4836621Sbt150084 s32 4846621Sbt150084 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index) 4856621Sbt150084 { 4866621Sbt150084 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); 4876621Sbt150084 4886621Sbt150084 /* To turn on the LED, set mode to ON. */ 4896621Sbt150084 led_reg &= ~IXGBE_LED_MODE_MASK(index); 4906621Sbt150084 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index); 4916621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); 4926621Sbt150084 IXGBE_WRITE_FLUSH(hw); 4936621Sbt150084 4946621Sbt150084 return (IXGBE_SUCCESS); 4956621Sbt150084 } 4966621Sbt150084 4976621Sbt150084 /* 4986621Sbt150084 * ixgbe_led_off_generic - Turns off the software controllable LEDs. 4996621Sbt150084 * @hw: pointer to hardware structure 5006621Sbt150084 * @index: led number to turn off 5016621Sbt150084 */ 5026621Sbt150084 s32 5036621Sbt150084 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index) 5046621Sbt150084 { 5056621Sbt150084 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); 5066621Sbt150084 5076621Sbt150084 /* To turn off the LED, set mode to OFF. */ 5086621Sbt150084 led_reg &= ~IXGBE_LED_MODE_MASK(index); 5096621Sbt150084 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index); 5106621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); 5116621Sbt150084 IXGBE_WRITE_FLUSH(hw); 5126621Sbt150084 5136621Sbt150084 return (IXGBE_SUCCESS); 5146621Sbt150084 } 5156621Sbt150084 5166621Sbt150084 /* 5176621Sbt150084 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params 5186621Sbt150084 * @hw: pointer to hardware structure 5196621Sbt150084 * 5206621Sbt150084 * Initializes the EEPROM parameters ixgbe_eeprom_info within the 5216621Sbt150084 * ixgbe_hw struct in order to set up EEPROM access. 5226621Sbt150084 */ 5236621Sbt150084 s32 5246621Sbt150084 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw) 5256621Sbt150084 { 5266621Sbt150084 struct ixgbe_eeprom_info *eeprom = &hw->eeprom; 5276621Sbt150084 u32 eec; 5286621Sbt150084 u16 eeprom_size; 5296621Sbt150084 5306621Sbt150084 if (eeprom->type == ixgbe_eeprom_uninitialized) { 5316621Sbt150084 eeprom->type = ixgbe_eeprom_none; 5328490SPaul.Guo@Sun.COM /* 5338490SPaul.Guo@Sun.COM * Set default semaphore delay to 10ms which is a well 5348490SPaul.Guo@Sun.COM * tested value 5358490SPaul.Guo@Sun.COM */ 5368490SPaul.Guo@Sun.COM eeprom->semaphore_delay = 10; 5376621Sbt150084 5386621Sbt150084 /* 5396621Sbt150084 * Check for EEPROM present first. 5406621Sbt150084 * If not present leave as none 5416621Sbt150084 */ 5426621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 5436621Sbt150084 if (eec & IXGBE_EEC_PRES) { 5446621Sbt150084 eeprom->type = ixgbe_eeprom_spi; 5456621Sbt150084 5466621Sbt150084 /* 5476621Sbt150084 * SPI EEPROM is assumed here. This code would need to 5486621Sbt150084 * change if a future EEPROM is not SPI. 5496621Sbt150084 */ 5506621Sbt150084 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >> 5516621Sbt150084 IXGBE_EEC_SIZE_SHIFT); 5526621Sbt150084 eeprom->word_size = 1 << (eeprom_size + 5536621Sbt150084 IXGBE_EEPROM_WORD_SIZE_SHIFT); 5546621Sbt150084 } 5556621Sbt150084 5566621Sbt150084 if (eec & IXGBE_EEC_ADDR_SIZE) 5576621Sbt150084 eeprom->address_bits = 16; 5586621Sbt150084 else 5596621Sbt150084 eeprom->address_bits = 8; 5606621Sbt150084 DEBUGOUT3("Eeprom params: type = %d, size = %d, address bits: " 5616621Sbt150084 "%d\n", eeprom->type, eeprom->word_size, 5626621Sbt150084 eeprom->address_bits); 5636621Sbt150084 } 5646621Sbt150084 5656621Sbt150084 return (IXGBE_SUCCESS); 5666621Sbt150084 } 5676621Sbt150084 5686621Sbt150084 /* 5696621Sbt150084 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM 5706621Sbt150084 * @hw: pointer to hardware structure 5716621Sbt150084 * @offset: offset within the EEPROM to be written to 5726621Sbt150084 * @data: 16 bit word to be written to the EEPROM 5736621Sbt150084 * 5746621Sbt150084 * If ixgbe_eeprom_update_checksum is not called after this function, the 5756621Sbt150084 * EEPROM will most likely contain an invalid checksum. 5766621Sbt150084 */ 5776621Sbt150084 s32 5786621Sbt150084 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data) 5796621Sbt150084 { 5806621Sbt150084 s32 status; 5816621Sbt150084 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI; 5826621Sbt150084 5836621Sbt150084 hw->eeprom.ops.init_params(hw); 5846621Sbt150084 5856621Sbt150084 if (offset >= hw->eeprom.word_size) { 5866621Sbt150084 status = IXGBE_ERR_EEPROM; 5876621Sbt150084 goto out; 5886621Sbt150084 } 5896621Sbt150084 5906621Sbt150084 /* Prepare the EEPROM for writing */ 5916621Sbt150084 status = ixgbe_acquire_eeprom(hw); 5926621Sbt150084 5936621Sbt150084 if (status == IXGBE_SUCCESS) { 5946621Sbt150084 if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) { 5956621Sbt150084 ixgbe_release_eeprom(hw); 5966621Sbt150084 status = IXGBE_ERR_EEPROM; 5976621Sbt150084 } 5986621Sbt150084 } 5996621Sbt150084 6006621Sbt150084 if (status == IXGBE_SUCCESS) { 6016621Sbt150084 ixgbe_standby_eeprom(hw); 6026621Sbt150084 6036621Sbt150084 /* Send the WRITE ENABLE command (8 bit opcode ) */ 6046621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI, 6056621Sbt150084 IXGBE_EEPROM_OPCODE_BITS); 6066621Sbt150084 6076621Sbt150084 ixgbe_standby_eeprom(hw); 6086621Sbt150084 6096621Sbt150084 /* 6106621Sbt150084 * Some SPI eeproms use the 8th address bit embedded in the 6116621Sbt150084 * opcode 6126621Sbt150084 */ 6136621Sbt150084 if ((hw->eeprom.address_bits == 8) && (offset >= 128)) 6146621Sbt150084 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI; 6156621Sbt150084 6166621Sbt150084 /* Send the Write command (8-bit opcode + addr) */ 6176621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, write_opcode, 6186621Sbt150084 IXGBE_EEPROM_OPCODE_BITS); 6196621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2), 6206621Sbt150084 hw->eeprom.address_bits); 6216621Sbt150084 6226621Sbt150084 /* Send the data */ 6236621Sbt150084 data = (data >> 8) | (data << 8); 6246621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, data, 16); 6256621Sbt150084 ixgbe_standby_eeprom(hw); 6266621Sbt150084 6278490SPaul.Guo@Sun.COM msec_delay(hw->eeprom.semaphore_delay); 6286621Sbt150084 6296621Sbt150084 /* Done with writing - release the EEPROM */ 6306621Sbt150084 ixgbe_release_eeprom(hw); 6316621Sbt150084 } 6326621Sbt150084 6336621Sbt150084 out: 6346621Sbt150084 return (status); 6356621Sbt150084 } 6366621Sbt150084 6376621Sbt150084 /* 6386621Sbt150084 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang 6396621Sbt150084 * @hw: pointer to hardware structure 6406621Sbt150084 * @offset: offset within the EEPROM to be read 6416621Sbt150084 * @data: read 16 bit value from EEPROM 6426621Sbt150084 * 6436621Sbt150084 * Reads 16 bit value from EEPROM through bit-bang method 6446621Sbt150084 */ 6456621Sbt150084 s32 6466621Sbt150084 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, 6476621Sbt150084 u16 *data) 6486621Sbt150084 { 6496621Sbt150084 s32 status; 6506621Sbt150084 u16 word_in; 6516621Sbt150084 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI; 6526621Sbt150084 6536621Sbt150084 hw->eeprom.ops.init_params(hw); 6546621Sbt150084 6556621Sbt150084 if (offset >= hw->eeprom.word_size) { 6566621Sbt150084 status = IXGBE_ERR_EEPROM; 6576621Sbt150084 goto out; 6586621Sbt150084 } 6596621Sbt150084 6606621Sbt150084 /* Prepare the EEPROM for reading */ 6616621Sbt150084 status = ixgbe_acquire_eeprom(hw); 6626621Sbt150084 6636621Sbt150084 if (status == IXGBE_SUCCESS) { 6646621Sbt150084 if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) { 6656621Sbt150084 ixgbe_release_eeprom(hw); 6666621Sbt150084 status = IXGBE_ERR_EEPROM; 6676621Sbt150084 } 6686621Sbt150084 } 6696621Sbt150084 6706621Sbt150084 if (status == IXGBE_SUCCESS) { 6716621Sbt150084 ixgbe_standby_eeprom(hw); 6726621Sbt150084 6736621Sbt150084 /* 6746621Sbt150084 * Some SPI eeproms use the 8th address bit embedded in the 6756621Sbt150084 * opcode 6766621Sbt150084 */ 6776621Sbt150084 if ((hw->eeprom.address_bits == 8) && (offset >= 128)) 6786621Sbt150084 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI; 6796621Sbt150084 6806621Sbt150084 /* Send the READ command (opcode + addr) */ 6816621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, read_opcode, 6826621Sbt150084 IXGBE_EEPROM_OPCODE_BITS); 6836621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2), 6846621Sbt150084 hw->eeprom.address_bits); 6856621Sbt150084 6866621Sbt150084 /* Read the data. */ 6876621Sbt150084 word_in = ixgbe_shift_in_eeprom_bits(hw, 16); 6886621Sbt150084 *data = (word_in >> 8) | (word_in << 8); 6896621Sbt150084 6906621Sbt150084 /* End this read operation */ 6916621Sbt150084 ixgbe_release_eeprom(hw); 6926621Sbt150084 } 6936621Sbt150084 6946621Sbt150084 out: 6956621Sbt150084 return (status); 6966621Sbt150084 } 6976621Sbt150084 6986621Sbt150084 /* 6996621Sbt150084 * ixgbe_read_eeprom_generic - Read EEPROM word using EERD 7006621Sbt150084 * @hw: pointer to hardware structure 7016621Sbt150084 * @offset: offset of word in the EEPROM to read 7026621Sbt150084 * @data: word read from the EEPROM 7036621Sbt150084 * 7046621Sbt150084 * Reads a 16 bit word from the EEPROM using the EERD register. 7056621Sbt150084 */ 7066621Sbt150084 s32 7076621Sbt150084 ixgbe_read_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 *data) 7086621Sbt150084 { 7096621Sbt150084 u32 eerd; 7106621Sbt150084 s32 status; 7116621Sbt150084 7126621Sbt150084 hw->eeprom.ops.init_params(hw); 7136621Sbt150084 7146621Sbt150084 if (offset >= hw->eeprom.word_size) { 7156621Sbt150084 status = IXGBE_ERR_EEPROM; 7166621Sbt150084 goto out; 7176621Sbt150084 } 7186621Sbt150084 7196621Sbt150084 eerd = (offset << IXGBE_EEPROM_READ_ADDR_SHIFT) + 7206621Sbt150084 IXGBE_EEPROM_READ_REG_START; 7216621Sbt150084 7226621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd); 7236621Sbt150084 status = ixgbe_poll_eeprom_eerd_done(hw); 7246621Sbt150084 7259353SSamuel.Tu@Sun.COM if (status == IXGBE_SUCCESS) { 7266621Sbt150084 *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >> 7276621Sbt150084 IXGBE_EEPROM_READ_REG_DATA); 7289353SSamuel.Tu@Sun.COM } else { 7296621Sbt150084 DEBUGOUT("Eeprom read timed out\n"); 7309353SSamuel.Tu@Sun.COM } 7316621Sbt150084 7326621Sbt150084 out: 7336621Sbt150084 return (status); 7346621Sbt150084 } 7356621Sbt150084 7366621Sbt150084 /* 7376621Sbt150084 * ixgbe_poll_eeprom_eerd_done - Poll EERD status 7386621Sbt150084 * @hw: pointer to hardware structure 7396621Sbt150084 * 7406621Sbt150084 * Polls the status bit (bit 1) of the EERD to determine when the read is done. 7416621Sbt150084 */ 7426621Sbt150084 static s32 7436621Sbt150084 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw) 7446621Sbt150084 { 7456621Sbt150084 u32 i; 7466621Sbt150084 u32 reg; 7476621Sbt150084 s32 status = IXGBE_ERR_EEPROM; 7486621Sbt150084 7496621Sbt150084 for (i = 0; i < IXGBE_EERD_ATTEMPTS; i++) { 7506621Sbt150084 reg = IXGBE_READ_REG(hw, IXGBE_EERD); 7516621Sbt150084 if (reg & IXGBE_EEPROM_READ_REG_DONE) { 7526621Sbt150084 status = IXGBE_SUCCESS; 7536621Sbt150084 break; 7546621Sbt150084 } 7556621Sbt150084 usec_delay(5); 7566621Sbt150084 } 7576621Sbt150084 return (status); 7586621Sbt150084 } 7596621Sbt150084 7606621Sbt150084 /* 7616621Sbt150084 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang 7626621Sbt150084 * @hw: pointer to hardware structure 7636621Sbt150084 * 7646621Sbt150084 * Prepares EEPROM for access using bit-bang method. This function should 7656621Sbt150084 * be called before issuing a command to the EEPROM. 7666621Sbt150084 */ 7676621Sbt150084 static s32 7686621Sbt150084 ixgbe_acquire_eeprom(struct ixgbe_hw *hw) 7696621Sbt150084 { 7706621Sbt150084 s32 status = IXGBE_SUCCESS; 7716621Sbt150084 u32 eec; 7726621Sbt150084 u32 i; 7736621Sbt150084 7746621Sbt150084 if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != IXGBE_SUCCESS) 7756621Sbt150084 status = IXGBE_ERR_SWFW_SYNC; 7766621Sbt150084 7776621Sbt150084 if (status == IXGBE_SUCCESS) { 7786621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 7796621Sbt150084 7806621Sbt150084 /* Request EEPROM Access */ 7816621Sbt150084 eec |= IXGBE_EEC_REQ; 7826621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 7836621Sbt150084 7846621Sbt150084 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) { 7856621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 7866621Sbt150084 if (eec & IXGBE_EEC_GNT) 7876621Sbt150084 break; 7886621Sbt150084 usec_delay(5); 7896621Sbt150084 } 7906621Sbt150084 7916621Sbt150084 /* Release if grant not acquired */ 7926621Sbt150084 if (!(eec & IXGBE_EEC_GNT)) { 7936621Sbt150084 eec &= ~IXGBE_EEC_REQ; 7946621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 7956621Sbt150084 DEBUGOUT("Could not acquire EEPROM grant\n"); 7966621Sbt150084 7976621Sbt150084 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); 7986621Sbt150084 status = IXGBE_ERR_EEPROM; 7996621Sbt150084 } 8006621Sbt150084 } 8016621Sbt150084 8026621Sbt150084 /* Setup EEPROM for Read/Write */ 8036621Sbt150084 if (status == IXGBE_SUCCESS) { 8046621Sbt150084 /* Clear CS and SK */ 8056621Sbt150084 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK); 8066621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 8076621Sbt150084 IXGBE_WRITE_FLUSH(hw); 8086621Sbt150084 usec_delay(1); 8096621Sbt150084 } 8106621Sbt150084 return (status); 8116621Sbt150084 } 8126621Sbt150084 8136621Sbt150084 /* 8146621Sbt150084 * ixgbe_get_eeprom_semaphore - Get hardware semaphore 8156621Sbt150084 * @hw: pointer to hardware structure 8166621Sbt150084 * 8176621Sbt150084 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method 8186621Sbt150084 */ 8196621Sbt150084 static s32 8206621Sbt150084 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw) 8216621Sbt150084 { 8226621Sbt150084 s32 status = IXGBE_ERR_EEPROM; 8236621Sbt150084 u32 timeout; 8246621Sbt150084 u32 i; 8256621Sbt150084 u32 swsm; 8266621Sbt150084 8276621Sbt150084 /* Set timeout value based on size of EEPROM */ 8286621Sbt150084 timeout = hw->eeprom.word_size + 1; 8296621Sbt150084 8306621Sbt150084 /* Get SMBI software semaphore between device drivers first */ 8316621Sbt150084 for (i = 0; i < timeout; i++) { 8326621Sbt150084 /* 8336621Sbt150084 * If the SMBI bit is 0 when we read it, then the bit will be 8346621Sbt150084 * set and we have the semaphore 8356621Sbt150084 */ 8366621Sbt150084 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); 8376621Sbt150084 if (!(swsm & IXGBE_SWSM_SMBI)) { 8386621Sbt150084 status = IXGBE_SUCCESS; 8396621Sbt150084 break; 8406621Sbt150084 } 8416621Sbt150084 msec_delay(1); 8426621Sbt150084 } 8436621Sbt150084 8446621Sbt150084 /* Now get the semaphore between SW/FW through the SWESMBI bit */ 8456621Sbt150084 if (status == IXGBE_SUCCESS) { 8466621Sbt150084 for (i = 0; i < timeout; i++) { 8476621Sbt150084 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); 8486621Sbt150084 8496621Sbt150084 /* Set the SW EEPROM semaphore bit to request access */ 8506621Sbt150084 swsm |= IXGBE_SWSM_SWESMBI; 8516621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); 8526621Sbt150084 8536621Sbt150084 /* 8546621Sbt150084 * If we set the bit successfully then we got the 8556621Sbt150084 * semaphore. 8566621Sbt150084 */ 8576621Sbt150084 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); 8586621Sbt150084 if (swsm & IXGBE_SWSM_SWESMBI) 8596621Sbt150084 break; 8606621Sbt150084 8616621Sbt150084 usec_delay(50); 8626621Sbt150084 } 8636621Sbt150084 8646621Sbt150084 /* 8656621Sbt150084 * Release semaphores and return error if SW EEPROM semaphore 8666621Sbt150084 * was not granted because we don't have access to the EEPROM 8676621Sbt150084 */ 8686621Sbt150084 if (i >= timeout) { 8699353SSamuel.Tu@Sun.COM DEBUGOUT("SWESMBI Software EEPROM semaphore " 8706621Sbt150084 "not granted.\n"); 8716621Sbt150084 ixgbe_release_eeprom_semaphore(hw); 8726621Sbt150084 status = IXGBE_ERR_EEPROM; 8736621Sbt150084 } 8749353SSamuel.Tu@Sun.COM } else { 8759353SSamuel.Tu@Sun.COM DEBUGOUT("Software semaphore SMBI between device drivers " 8769353SSamuel.Tu@Sun.COM "not granted.\n"); 8776621Sbt150084 } 8786621Sbt150084 8796621Sbt150084 return (status); 8806621Sbt150084 } 8816621Sbt150084 8826621Sbt150084 /* 8836621Sbt150084 * ixgbe_release_eeprom_semaphore - Release hardware semaphore 8846621Sbt150084 * @hw: pointer to hardware structure 8856621Sbt150084 * 8866621Sbt150084 * This function clears hardware semaphore bits. 8876621Sbt150084 */ 8886621Sbt150084 static void 8896621Sbt150084 ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw) 8906621Sbt150084 { 8916621Sbt150084 u32 swsm; 8926621Sbt150084 8936621Sbt150084 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); 8946621Sbt150084 8956621Sbt150084 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */ 8966621Sbt150084 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI); 8976621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); 8986621Sbt150084 IXGBE_WRITE_FLUSH(hw); 8996621Sbt150084 } 9006621Sbt150084 9016621Sbt150084 /* 9026621Sbt150084 * ixgbe_ready_eeprom - Polls for EEPROM ready 9036621Sbt150084 * @hw: pointer to hardware structure 9046621Sbt150084 */ 9056621Sbt150084 static s32 9066621Sbt150084 ixgbe_ready_eeprom(struct ixgbe_hw *hw) 9076621Sbt150084 { 9086621Sbt150084 s32 status = IXGBE_SUCCESS; 9096621Sbt150084 u16 i; 9106621Sbt150084 u8 spi_stat_reg; 9116621Sbt150084 9126621Sbt150084 /* 9136621Sbt150084 * Read "Status Register" repeatedly until the LSB is cleared. The 9146621Sbt150084 * EEPROM will signal that the command has been completed by clearing 9156621Sbt150084 * bit 0 of the internal status register. If it's not cleared within 9166621Sbt150084 * 5 milliseconds, then error out. 9176621Sbt150084 */ 9186621Sbt150084 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) { 9196621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI, 9206621Sbt150084 IXGBE_EEPROM_OPCODE_BITS); 9216621Sbt150084 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8); 9226621Sbt150084 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI)) 9236621Sbt150084 break; 9246621Sbt150084 9256621Sbt150084 usec_delay(5); 9266621Sbt150084 ixgbe_standby_eeprom(hw); 9276621Sbt150084 }; 9286621Sbt150084 9296621Sbt150084 /* 9306621Sbt150084 * On some parts, SPI write time could vary from 0-20mSec on 3.3V 9316621Sbt150084 * devices (and only 0-5mSec on 5V devices) 9326621Sbt150084 */ 9336621Sbt150084 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) { 9346621Sbt150084 DEBUGOUT("SPI EEPROM Status error\n"); 9356621Sbt150084 status = IXGBE_ERR_EEPROM; 9366621Sbt150084 } 9376621Sbt150084 9386621Sbt150084 return (status); 9396621Sbt150084 } 9406621Sbt150084 9416621Sbt150084 /* 9426621Sbt150084 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state 9436621Sbt150084 * @hw: pointer to hardware structure 9446621Sbt150084 */ 9456621Sbt150084 static void 9466621Sbt150084 ixgbe_standby_eeprom(struct ixgbe_hw *hw) 9476621Sbt150084 { 9486621Sbt150084 u32 eec; 9496621Sbt150084 9506621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 9516621Sbt150084 9526621Sbt150084 /* Toggle CS to flush commands */ 9536621Sbt150084 eec |= IXGBE_EEC_CS; 9546621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 9556621Sbt150084 IXGBE_WRITE_FLUSH(hw); 9566621Sbt150084 usec_delay(1); 9576621Sbt150084 eec &= ~IXGBE_EEC_CS; 9586621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 9596621Sbt150084 IXGBE_WRITE_FLUSH(hw); 9606621Sbt150084 usec_delay(1); 9616621Sbt150084 } 9626621Sbt150084 9636621Sbt150084 /* 9646621Sbt150084 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM. 9656621Sbt150084 * @hw: pointer to hardware structure 9666621Sbt150084 * @data: data to send to the EEPROM 9676621Sbt150084 * @count: number of bits to shift out 9686621Sbt150084 */ 9696621Sbt150084 static void 9706621Sbt150084 ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data, 9716621Sbt150084 u16 count) 9726621Sbt150084 { 9736621Sbt150084 u32 eec; 9746621Sbt150084 u32 mask; 9756621Sbt150084 u32 i; 9766621Sbt150084 9776621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 9786621Sbt150084 9796621Sbt150084 /* 9806621Sbt150084 * Mask is used to shift "count" bits of "data" out to the EEPROM 9816621Sbt150084 * one bit at a time. Determine the starting bit based on count 9826621Sbt150084 */ 9836621Sbt150084 mask = 0x01 << (count - 1); 9846621Sbt150084 9856621Sbt150084 for (i = 0; i < count; i++) { 9866621Sbt150084 /* 9876621Sbt150084 * A "1" is shifted out to the EEPROM by setting bit "DI" to a 9886621Sbt150084 * "1", and then raising and then lowering the clock (the SK 9896621Sbt150084 * bit controls the clock input to the EEPROM). A "0" is 9906621Sbt150084 * shifted out to the EEPROM by setting "DI" to "0" and then 9916621Sbt150084 * raising and then lowering the clock. 9926621Sbt150084 */ 9936621Sbt150084 if (data & mask) 9946621Sbt150084 eec |= IXGBE_EEC_DI; 9956621Sbt150084 else 9966621Sbt150084 eec &= ~IXGBE_EEC_DI; 9976621Sbt150084 9986621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 9996621Sbt150084 IXGBE_WRITE_FLUSH(hw); 10006621Sbt150084 10016621Sbt150084 usec_delay(1); 10026621Sbt150084 10036621Sbt150084 ixgbe_raise_eeprom_clk(hw, &eec); 10046621Sbt150084 ixgbe_lower_eeprom_clk(hw, &eec); 10056621Sbt150084 10066621Sbt150084 /* 10076621Sbt150084 * Shift mask to signify next bit of data to shift in to the 10086621Sbt150084 * EEPROM 10096621Sbt150084 */ 10106621Sbt150084 mask = mask >> 1; 10116621Sbt150084 }; 10126621Sbt150084 10136621Sbt150084 /* We leave the "DI" bit set to "0" when we leave this routine. */ 10146621Sbt150084 eec &= ~IXGBE_EEC_DI; 10156621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 10166621Sbt150084 IXGBE_WRITE_FLUSH(hw); 10176621Sbt150084 } 10186621Sbt150084 10196621Sbt150084 /* 10206621Sbt150084 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM 10216621Sbt150084 * @hw: pointer to hardware structure 10226621Sbt150084 */ 10236621Sbt150084 static u16 10246621Sbt150084 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count) 10256621Sbt150084 { 10266621Sbt150084 u32 eec; 10276621Sbt150084 u32 i; 10286621Sbt150084 u16 data = 0; 10296621Sbt150084 10306621Sbt150084 /* 10316621Sbt150084 * In order to read a register from the EEPROM, we need to shift 10326621Sbt150084 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising 10336621Sbt150084 * the clock input to the EEPROM (setting the SK bit), and then reading 10346621Sbt150084 * the value of the "DO" bit. During this "shifting in" process the 10356621Sbt150084 * "DI" bit should always be clear. 10366621Sbt150084 */ 10376621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 10386621Sbt150084 10396621Sbt150084 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI); 10406621Sbt150084 10416621Sbt150084 for (i = 0; i < count; i++) { 10426621Sbt150084 data = data << 1; 10436621Sbt150084 ixgbe_raise_eeprom_clk(hw, &eec); 10446621Sbt150084 10456621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 10466621Sbt150084 10476621Sbt150084 eec &= ~(IXGBE_EEC_DI); 10486621Sbt150084 if (eec & IXGBE_EEC_DO) 10496621Sbt150084 data |= 1; 10506621Sbt150084 10516621Sbt150084 ixgbe_lower_eeprom_clk(hw, &eec); 10526621Sbt150084 } 10536621Sbt150084 10546621Sbt150084 return (data); 10556621Sbt150084 } 10566621Sbt150084 10576621Sbt150084 /* 10586621Sbt150084 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input. 10596621Sbt150084 * @hw: pointer to hardware structure 10606621Sbt150084 * @eec: EEC register's current value 10616621Sbt150084 */ 10626621Sbt150084 static void 10636621Sbt150084 ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec) 10646621Sbt150084 { 10656621Sbt150084 /* 10666621Sbt150084 * Raise the clock input to the EEPROM 10676621Sbt150084 * (setting the SK bit), then delay 10686621Sbt150084 */ 10696621Sbt150084 *eec = *eec | IXGBE_EEC_SK; 10706621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec); 10716621Sbt150084 IXGBE_WRITE_FLUSH(hw); 10726621Sbt150084 usec_delay(1); 10736621Sbt150084 } 10746621Sbt150084 10756621Sbt150084 /* 10766621Sbt150084 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input. 10776621Sbt150084 * @hw: pointer to hardware structure 10786621Sbt150084 * @eecd: EECD's current value 10796621Sbt150084 */ 10806621Sbt150084 static void 10816621Sbt150084 ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec) 10826621Sbt150084 { 10836621Sbt150084 /* 10846621Sbt150084 * Lower the clock input to the EEPROM (clearing the SK bit), then 10856621Sbt150084 * delay 10866621Sbt150084 */ 10876621Sbt150084 *eec = *eec & ~IXGBE_EEC_SK; 10886621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec); 10896621Sbt150084 IXGBE_WRITE_FLUSH(hw); 10906621Sbt150084 usec_delay(1); 10916621Sbt150084 } 10926621Sbt150084 10936621Sbt150084 /* 10946621Sbt150084 * ixgbe_release_eeprom - Release EEPROM, release semaphores 10956621Sbt150084 * @hw: pointer to hardware structure 10966621Sbt150084 */ 10976621Sbt150084 static void 10986621Sbt150084 ixgbe_release_eeprom(struct ixgbe_hw *hw) 10996621Sbt150084 { 11006621Sbt150084 u32 eec; 11016621Sbt150084 11026621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 11036621Sbt150084 11046621Sbt150084 eec |= IXGBE_EEC_CS; /* Pull CS high */ 11056621Sbt150084 eec &= ~IXGBE_EEC_SK; /* Lower SCK */ 11066621Sbt150084 11076621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 11086621Sbt150084 IXGBE_WRITE_FLUSH(hw); 11096621Sbt150084 11106621Sbt150084 usec_delay(1); 11116621Sbt150084 11126621Sbt150084 /* Stop requesting EEPROM access */ 11136621Sbt150084 eec &= ~IXGBE_EEC_REQ; 11146621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 11156621Sbt150084 11166621Sbt150084 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); 11176621Sbt150084 } 11186621Sbt150084 11196621Sbt150084 /* 11206621Sbt150084 * ixgbe_calc_eeprom_checksum - Calculates and returns the checksum 11216621Sbt150084 * @hw: pointer to hardware structure 11226621Sbt150084 */ 11236621Sbt150084 static u16 11246621Sbt150084 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw) 11256621Sbt150084 { 11266621Sbt150084 u16 i; 11276621Sbt150084 u16 j; 11286621Sbt150084 u16 checksum = 0; 11296621Sbt150084 u16 length = 0; 11306621Sbt150084 u16 pointer = 0; 11316621Sbt150084 u16 word = 0; 11326621Sbt150084 11336621Sbt150084 /* Include 0x0-0x3F in the checksum */ 11346621Sbt150084 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) { 11356621Sbt150084 if (hw->eeprom.ops.read(hw, i, &word) != IXGBE_SUCCESS) { 11366621Sbt150084 DEBUGOUT("EEPROM read failed\n"); 11376621Sbt150084 break; 11386621Sbt150084 } 11396621Sbt150084 checksum += word; 11406621Sbt150084 } 11416621Sbt150084 11426621Sbt150084 /* Include all data from pointers except for the fw pointer */ 11436621Sbt150084 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) { 11446621Sbt150084 hw->eeprom.ops.read(hw, i, &pointer); 11456621Sbt150084 11466621Sbt150084 /* Make sure the pointer seems valid */ 11476621Sbt150084 if (pointer != 0xFFFF && pointer != 0) { 11486621Sbt150084 hw->eeprom.ops.read(hw, pointer, &length); 11496621Sbt150084 11506621Sbt150084 if (length != 0xFFFF && length != 0) { 11516621Sbt150084 for (j = pointer+1; j <= pointer+length; j++) { 11526621Sbt150084 hw->eeprom.ops.read(hw, j, &word); 11536621Sbt150084 checksum += word; 11546621Sbt150084 } 11556621Sbt150084 } 11566621Sbt150084 } 11576621Sbt150084 } 11586621Sbt150084 11596621Sbt150084 checksum = (u16)IXGBE_EEPROM_SUM - checksum; 11606621Sbt150084 11616621Sbt150084 return (checksum); 11626621Sbt150084 } 11636621Sbt150084 11646621Sbt150084 /* 11656621Sbt150084 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum 11666621Sbt150084 * @hw: pointer to hardware structure 11676621Sbt150084 * @checksum_val: calculated checksum 11686621Sbt150084 * 11696621Sbt150084 * Performs checksum calculation and validates the EEPROM checksum. If the 11706621Sbt150084 * caller does not need checksum_val, the value can be NULL. 11716621Sbt150084 */ 11726621Sbt150084 s32 11736621Sbt150084 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw, 11746621Sbt150084 u16 *checksum_val) 11756621Sbt150084 { 11766621Sbt150084 s32 status; 11776621Sbt150084 u16 checksum; 11786621Sbt150084 u16 read_checksum = 0; 11796621Sbt150084 11806621Sbt150084 /* 11816621Sbt150084 * Read the first word from the EEPROM. If this times out or fails, do 11826621Sbt150084 * not continue or we could be in for a very long wait while every 11836621Sbt150084 * EEPROM read fails 11846621Sbt150084 */ 11856621Sbt150084 status = hw->eeprom.ops.read(hw, 0, &checksum); 11866621Sbt150084 11876621Sbt150084 if (status == IXGBE_SUCCESS) { 11886621Sbt150084 checksum = ixgbe_calc_eeprom_checksum(hw); 11896621Sbt150084 11906621Sbt150084 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum); 11916621Sbt150084 11926621Sbt150084 /* 11936621Sbt150084 * Verify read checksum from EEPROM is the same as 11946621Sbt150084 * calculated checksum 11956621Sbt150084 */ 11966621Sbt150084 if (read_checksum != checksum) 11976621Sbt150084 status = IXGBE_ERR_EEPROM_CHECKSUM; 11986621Sbt150084 11996621Sbt150084 /* If the user cares, return the calculated checksum */ 12006621Sbt150084 if (checksum_val) 12016621Sbt150084 *checksum_val = checksum; 12026621Sbt150084 } else { 12036621Sbt150084 DEBUGOUT("EEPROM read failed\n"); 12046621Sbt150084 } 12056621Sbt150084 12066621Sbt150084 return (status); 12076621Sbt150084 } 12086621Sbt150084 12096621Sbt150084 /* 12106621Sbt150084 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum 12116621Sbt150084 * @hw: pointer to hardware structure 12126621Sbt150084 */ 12136621Sbt150084 s32 12146621Sbt150084 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw) 12156621Sbt150084 { 12166621Sbt150084 s32 status; 12176621Sbt150084 u16 checksum; 12186621Sbt150084 12196621Sbt150084 /* 12206621Sbt150084 * Read the first word from the EEPROM. If this times out or fails, do 12216621Sbt150084 * not continue or we could be in for a very long wait while every 12226621Sbt150084 * EEPROM read fails 12236621Sbt150084 */ 12246621Sbt150084 status = hw->eeprom.ops.read(hw, 0, &checksum); 12256621Sbt150084 12266621Sbt150084 if (status == IXGBE_SUCCESS) { 12276621Sbt150084 checksum = ixgbe_calc_eeprom_checksum(hw); 12286621Sbt150084 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM, 12296621Sbt150084 checksum); 12306621Sbt150084 } else { 12316621Sbt150084 DEBUGOUT("EEPROM read failed\n"); 12326621Sbt150084 } 12336621Sbt150084 12346621Sbt150084 return (status); 12356621Sbt150084 } 12366621Sbt150084 12376621Sbt150084 /* 12386621Sbt150084 * ixgbe_validate_mac_addr - Validate MAC address 12396621Sbt150084 * @mac_addr: pointer to MAC address. 12406621Sbt150084 * 12416621Sbt150084 * Tests a MAC address to ensure it is a valid Individual Address 12426621Sbt150084 */ 12436621Sbt150084 s32 12446621Sbt150084 ixgbe_validate_mac_addr(u8 *mac_addr) 12456621Sbt150084 { 12466621Sbt150084 s32 status = IXGBE_SUCCESS; 12476621Sbt150084 12486621Sbt150084 /* Make sure it is not a multicast address */ 12496621Sbt150084 if (IXGBE_IS_MULTICAST(mac_addr)) { 12506621Sbt150084 DEBUGOUT("MAC address is multicast\n"); 12516621Sbt150084 status = IXGBE_ERR_INVALID_MAC_ADDR; 12526621Sbt150084 /* Not a broadcast address */ 12536621Sbt150084 } else if (IXGBE_IS_BROADCAST(mac_addr)) { 12546621Sbt150084 DEBUGOUT("MAC address is broadcast\n"); 12556621Sbt150084 status = IXGBE_ERR_INVALID_MAC_ADDR; 12566621Sbt150084 /* Reject the zero address */ 12576621Sbt150084 } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 && 12586621Sbt150084 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) { 12596621Sbt150084 DEBUGOUT("MAC address is all zeros\n"); 12606621Sbt150084 status = IXGBE_ERR_INVALID_MAC_ADDR; 12616621Sbt150084 } 12626621Sbt150084 return (status); 12636621Sbt150084 } 12646621Sbt150084 12656621Sbt150084 /* 12666621Sbt150084 * ixgbe_set_rar_generic - Set Rx address register 12676621Sbt150084 * @hw: pointer to hardware structure 12686621Sbt150084 * @index: Receive address register to write 12696621Sbt150084 * @addr: Address to put into receive address register 12706621Sbt150084 * @vmdq: VMDq "set" or "pool" index 12716621Sbt150084 * @enable_addr: set flag that address is active 12726621Sbt150084 * 12736621Sbt150084 * Puts an ethernet address into a receive address register. 12746621Sbt150084 */ 12756621Sbt150084 s32 12766621Sbt150084 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq, 12776621Sbt150084 u32 enable_addr) 12786621Sbt150084 { 12796621Sbt150084 u32 rar_low, rar_high; 12806621Sbt150084 u32 rar_entries = hw->mac.num_rar_entries; 12816621Sbt150084 12826621Sbt150084 /* setup VMDq pool selection before this RAR gets enabled */ 12836621Sbt150084 hw->mac.ops.set_vmdq(hw, index, vmdq); 12846621Sbt150084 12856621Sbt150084 /* Make sure we are using a valid rar index range */ 12866621Sbt150084 if (index < rar_entries) { 12876621Sbt150084 /* 12886621Sbt150084 * HW expects these in little endian so we reverse the byte 12896621Sbt150084 * order from network order (big endian) to little endian 12906621Sbt150084 */ 12916621Sbt150084 rar_low = ((u32)addr[0] | 12926621Sbt150084 ((u32)addr[1] << 8) | 12936621Sbt150084 ((u32)addr[2] << 16) | 12946621Sbt150084 ((u32)addr[3] << 24)); 12956621Sbt150084 /* 12966621Sbt150084 * Some parts put the VMDq setting in the extra RAH bits, 12976621Sbt150084 * so save everything except the lower 16 bits that hold part 12986621Sbt150084 * of the address and the address valid bit. 12996621Sbt150084 */ 13006621Sbt150084 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); 13016621Sbt150084 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV); 13026621Sbt150084 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8)); 13036621Sbt150084 13046621Sbt150084 if (enable_addr != 0) 13056621Sbt150084 rar_high |= IXGBE_RAH_AV; 13066621Sbt150084 13076621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low); 13086621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); 13096621Sbt150084 } else { 13108490SPaul.Guo@Sun.COM DEBUGOUT1("RAR index %d is out of range.\n", index); 13116621Sbt150084 } 13126621Sbt150084 13136621Sbt150084 return (IXGBE_SUCCESS); 13146621Sbt150084 } 13156621Sbt150084 13166621Sbt150084 /* 13178490SPaul.Guo@Sun.COM * ixgbe_clear_rar_generic - Remove Rx address register 13188490SPaul.Guo@Sun.COM * @hw: pointer to hardware structure 13198490SPaul.Guo@Sun.COM * @index: Receive address register to write 13208490SPaul.Guo@Sun.COM * 13218490SPaul.Guo@Sun.COM * Clears an ethernet address from a receive address register. 13228490SPaul.Guo@Sun.COM */ 13238490SPaul.Guo@Sun.COM s32 13248490SPaul.Guo@Sun.COM ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index) 13258490SPaul.Guo@Sun.COM { 13268490SPaul.Guo@Sun.COM u32 rar_high; 13278490SPaul.Guo@Sun.COM u32 rar_entries = hw->mac.num_rar_entries; 13288490SPaul.Guo@Sun.COM 13298490SPaul.Guo@Sun.COM /* Make sure we are using a valid rar index range */ 13308490SPaul.Guo@Sun.COM if (index < rar_entries) { 13318490SPaul.Guo@Sun.COM /* 13328490SPaul.Guo@Sun.COM * Some parts put the VMDq setting in the extra RAH bits, 13338490SPaul.Guo@Sun.COM * so save everything except the lower 16 bits that hold part 13348490SPaul.Guo@Sun.COM * of the address and the address valid bit. 13358490SPaul.Guo@Sun.COM */ 13368490SPaul.Guo@Sun.COM rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); 13378490SPaul.Guo@Sun.COM rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV); 13388490SPaul.Guo@Sun.COM 13398490SPaul.Guo@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0); 13408490SPaul.Guo@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); 13418490SPaul.Guo@Sun.COM } else { 13428490SPaul.Guo@Sun.COM DEBUGOUT1("RAR index %d is out of range.\n", index); 13438490SPaul.Guo@Sun.COM } 13448490SPaul.Guo@Sun.COM 13458490SPaul.Guo@Sun.COM /* clear VMDq pool/queue selection for this RAR */ 13468490SPaul.Guo@Sun.COM hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL); 13478490SPaul.Guo@Sun.COM 13488490SPaul.Guo@Sun.COM return (IXGBE_SUCCESS); 13498490SPaul.Guo@Sun.COM } 13508490SPaul.Guo@Sun.COM 13518490SPaul.Guo@Sun.COM /* 13526621Sbt150084 * ixgbe_init_rx_addrs_generic - Initializes receive address filters. 13536621Sbt150084 * @hw: pointer to hardware structure 13546621Sbt150084 * 13556621Sbt150084 * Places the MAC address in receive address register 0 and clears the rest 13566621Sbt150084 * of the receive address registers. Clears the multicast table. Assumes 13576621Sbt150084 * the receiver is in reset when the routine is called. 13586621Sbt150084 */ 13596621Sbt150084 s32 13606621Sbt150084 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw) 13616621Sbt150084 { 13626621Sbt150084 u32 i; 13636621Sbt150084 u32 rar_entries = hw->mac.num_rar_entries; 13646621Sbt150084 13656621Sbt150084 /* 13666621Sbt150084 * If the current mac address is valid, assume it is a software override 13676621Sbt150084 * to the permanent address. 13686621Sbt150084 * Otherwise, use the permanent address from the eeprom. 13696621Sbt150084 */ 13706621Sbt150084 if (ixgbe_validate_mac_addr(hw->mac.addr) == 13716621Sbt150084 IXGBE_ERR_INVALID_MAC_ADDR) { 13726621Sbt150084 /* Get the MAC address from the RAR0 for later reference */ 13736621Sbt150084 hw->mac.ops.get_mac_addr(hw, hw->mac.addr); 13746621Sbt150084 13756621Sbt150084 DEBUGOUT3(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ", 13766621Sbt150084 hw->mac.addr[0], hw->mac.addr[1], 13776621Sbt150084 hw->mac.addr[2]); 13786621Sbt150084 DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3], 13796621Sbt150084 hw->mac.addr[4], hw->mac.addr[5]); 13806621Sbt150084 } else { 13816621Sbt150084 /* Setup the receive address. */ 13826621Sbt150084 DEBUGOUT("Overriding MAC Address in RAR[0]\n"); 13836621Sbt150084 DEBUGOUT3(" New MAC Addr =%.2X %.2X %.2X ", 13846621Sbt150084 hw->mac.addr[0], hw->mac.addr[1], 13856621Sbt150084 hw->mac.addr[2]); 13866621Sbt150084 DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3], 13876621Sbt150084 hw->mac.addr[4], hw->mac.addr[5]); 13886621Sbt150084 13896621Sbt150084 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV); 13906621Sbt150084 } 13916621Sbt150084 hw->addr_ctrl.overflow_promisc = 0; 13926621Sbt150084 13936621Sbt150084 hw->addr_ctrl.rar_used_count = 1; 13946621Sbt150084 13956621Sbt150084 /* Zero out the other receive addresses. */ 13966621Sbt150084 DEBUGOUT1("Clearing RAR[1-%d]\n", rar_entries - 1); 13976621Sbt150084 for (i = 1; i < rar_entries; i++) { 13986621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0); 13996621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0); 14006621Sbt150084 } 14016621Sbt150084 14026621Sbt150084 /* Clear the MTA */ 14036621Sbt150084 hw->addr_ctrl.mta_in_use = 0; 14046621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type); 14056621Sbt150084 14066621Sbt150084 DEBUGOUT(" Clearing MTA\n"); 14076621Sbt150084 for (i = 0; i < hw->mac.mcft_size; i++) 14086621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0); 14096621Sbt150084 14109353SSamuel.Tu@Sun.COM (void) ixgbe_init_uta_tables(hw); 14118490SPaul.Guo@Sun.COM 14126621Sbt150084 return (IXGBE_SUCCESS); 14136621Sbt150084 } 14146621Sbt150084 14159353SSamuel.Tu@Sun.COM 14166621Sbt150084 /* 14176621Sbt150084 * ixgbe_add_uc_addr - Adds a secondary unicast address. 14186621Sbt150084 * @hw: pointer to hardware structure 14196621Sbt150084 * @addr: new address 14206621Sbt150084 * 14216621Sbt150084 * Adds it to unused receive address register or goes into promiscuous mode. 14226621Sbt150084 */ 14236621Sbt150084 void 14246621Sbt150084 ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq) 14256621Sbt150084 { 14266621Sbt150084 u32 rar_entries = hw->mac.num_rar_entries; 14276621Sbt150084 u32 rar; 14286621Sbt150084 14296621Sbt150084 DEBUGOUT6(" UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n", 14306621Sbt150084 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); 14316621Sbt150084 14326621Sbt150084 /* 14336621Sbt150084 * Place this address in the RAR if there is room, 14346621Sbt150084 * else put the controller into promiscuous mode 14356621Sbt150084 */ 14366621Sbt150084 if (hw->addr_ctrl.rar_used_count < rar_entries) { 14379353SSamuel.Tu@Sun.COM rar = hw->addr_ctrl.rar_used_count; 14386621Sbt150084 hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV); 14396621Sbt150084 DEBUGOUT1("Added a secondary address to RAR[%d]\n", rar); 14406621Sbt150084 hw->addr_ctrl.rar_used_count++; 14416621Sbt150084 } else { 14426621Sbt150084 hw->addr_ctrl.overflow_promisc++; 14436621Sbt150084 } 14446621Sbt150084 14456621Sbt150084 DEBUGOUT("ixgbe_add_uc_addr Complete\n"); 14466621Sbt150084 } 14476621Sbt150084 14486621Sbt150084 /* 14496621Sbt150084 * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses 14506621Sbt150084 * @hw: pointer to hardware structure 14516621Sbt150084 * @addr_list: the list of new addresses 14526621Sbt150084 * @addr_count: number of addresses 14536621Sbt150084 * @next: iterator function to walk the address list 14546621Sbt150084 * 14556621Sbt150084 * The given list replaces any existing list. Clears the secondary addrs from 14566621Sbt150084 * receive address registers. Uses unused receive address registers for the 14576621Sbt150084 * first secondary addresses, and falls back to promiscuous mode as needed. 14586621Sbt150084 * 14596621Sbt150084 * Drivers using secondary unicast addresses must set user_set_promisc when 14606621Sbt150084 * manually putting the device into promiscuous mode. 14616621Sbt150084 */ 14626621Sbt150084 s32 14636621Sbt150084 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list, 14646621Sbt150084 u32 addr_count, ixgbe_mc_addr_itr next) 14656621Sbt150084 { 14666621Sbt150084 u8 *addr; 14676621Sbt150084 u32 i; 14686621Sbt150084 u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc; 14696621Sbt150084 u32 uc_addr_in_use; 14706621Sbt150084 u32 fctrl; 14716621Sbt150084 u32 vmdq; 14726621Sbt150084 14736621Sbt150084 /* 14746621Sbt150084 * Clear accounting of old secondary address list, 14756621Sbt150084 * don't count RAR[0] 14766621Sbt150084 */ 14779353SSamuel.Tu@Sun.COM uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1; 14786621Sbt150084 hw->addr_ctrl.rar_used_count -= uc_addr_in_use; 14796621Sbt150084 hw->addr_ctrl.overflow_promisc = 0; 14806621Sbt150084 14816621Sbt150084 /* Zero out the other receive addresses */ 1482*9681SPaul.Guo@Sun.COM DEBUGOUT1("Clearing RAR[1-%d]\n", uc_addr_in_use); 1483*9681SPaul.Guo@Sun.COM for (i = 1; i <= uc_addr_in_use; i++) { 14846621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0); 14856621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0); 14866621Sbt150084 } 14876621Sbt150084 14886621Sbt150084 /* Add the new addresses */ 14896621Sbt150084 for (i = 0; i < addr_count; i++) { 14906621Sbt150084 DEBUGOUT(" Adding the secondary addresses:\n"); 14916621Sbt150084 addr = next(hw, &addr_list, &vmdq); 14926621Sbt150084 ixgbe_add_uc_addr(hw, addr, vmdq); 14936621Sbt150084 } 14946621Sbt150084 14956621Sbt150084 if (hw->addr_ctrl.overflow_promisc) { 14966621Sbt150084 /* enable promisc if not already in overflow or set by user */ 14976621Sbt150084 if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) { 14986621Sbt150084 DEBUGOUT(" Entering address overflow promisc mode\n"); 14996621Sbt150084 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); 15006621Sbt150084 fctrl |= IXGBE_FCTRL_UPE; 15016621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); 15026621Sbt150084 } 15036621Sbt150084 } else { 15046621Sbt150084 /* only disable if set by overflow, not by user */ 15056621Sbt150084 if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) { 15066621Sbt150084 DEBUGOUT(" Leaving address overflow promisc mode\n"); 15076621Sbt150084 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); 15086621Sbt150084 fctrl &= ~IXGBE_FCTRL_UPE; 15096621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); 15106621Sbt150084 } 15116621Sbt150084 } 15126621Sbt150084 15136621Sbt150084 DEBUGOUT("ixgbe_update_uc_addr_list_generic Complete\n"); 15146621Sbt150084 return (IXGBE_SUCCESS); 15156621Sbt150084 } 15166621Sbt150084 15176621Sbt150084 /* 15186621Sbt150084 * ixgbe_mta_vector - Determines bit-vector in multicast table to set 15196621Sbt150084 * @hw: pointer to hardware structure 15206621Sbt150084 * @mc_addr: the multicast address 15216621Sbt150084 * 15226621Sbt150084 * Extracts the 12 bits, from a multicast address, to determine which 15236621Sbt150084 * bit-vector to set in the multicast table. The hardware uses 12 bits, from 15246621Sbt150084 * incoming rx multicast addresses, to determine the bit-vector to check in 15256621Sbt150084 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set 15266621Sbt150084 * by the MO field of the MCSTCTRL. The MO field is set during initialization 15276621Sbt150084 * to mc_filter_type. 15286621Sbt150084 */ 15296621Sbt150084 static s32 15306621Sbt150084 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr) 15316621Sbt150084 { 15326621Sbt150084 u32 vector = 0; 15336621Sbt150084 15346621Sbt150084 switch (hw->mac.mc_filter_type) { 15356621Sbt150084 case 0: /* use bits [47:36] of the address */ 15366621Sbt150084 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4)); 15376621Sbt150084 break; 15386621Sbt150084 case 1: /* use bits [46:35] of the address */ 15396621Sbt150084 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5)); 15406621Sbt150084 break; 15416621Sbt150084 case 2: /* use bits [45:34] of the address */ 15426621Sbt150084 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6)); 15436621Sbt150084 break; 15446621Sbt150084 case 3: /* use bits [43:32] of the address */ 15456621Sbt150084 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8)); 15466621Sbt150084 break; 15476621Sbt150084 default: /* Invalid mc_filter_type */ 15486621Sbt150084 DEBUGOUT("MC filter type param set incorrectly\n"); 15496621Sbt150084 ASSERT(0); 15506621Sbt150084 break; 15516621Sbt150084 } 15526621Sbt150084 15536621Sbt150084 /* vector can only be 12-bits or boundary will be exceeded */ 15546621Sbt150084 vector &= 0xFFF; 15556621Sbt150084 return (vector); 15566621Sbt150084 } 15576621Sbt150084 15586621Sbt150084 /* 15596621Sbt150084 * ixgbe_set_mta - Set bit-vector in multicast table 15606621Sbt150084 * @hw: pointer to hardware structure 15616621Sbt150084 * @hash_value: Multicast address hash value 15626621Sbt150084 * 15636621Sbt150084 * Sets the bit-vector in the multicast table. 15646621Sbt150084 */ 15656621Sbt150084 void 15666621Sbt150084 ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr) 15676621Sbt150084 { 15686621Sbt150084 u32 vector; 15696621Sbt150084 u32 vector_bit; 15706621Sbt150084 u32 vector_reg; 15716621Sbt150084 u32 mta_reg; 15726621Sbt150084 15736621Sbt150084 hw->addr_ctrl.mta_in_use++; 15746621Sbt150084 15756621Sbt150084 vector = ixgbe_mta_vector(hw, mc_addr); 15766621Sbt150084 DEBUGOUT1(" bit-vector = 0x%03X\n", vector); 15776621Sbt150084 15786621Sbt150084 /* 15796621Sbt150084 * The MTA is a register array of 128 32-bit registers. It is treated 15806621Sbt150084 * like an array of 4096 bits. We want to set bit 15816621Sbt150084 * BitArray[vector_value]. So we figure out what register the bit is 15826621Sbt150084 * in, read it, OR in the new bit, then write back the new value. The 15836621Sbt150084 * register is determined by the upper 7 bits of the vector value and 15846621Sbt150084 * the bit within that register are determined by the lower 5 bits of 15856621Sbt150084 * the value. 15866621Sbt150084 */ 15876621Sbt150084 vector_reg = (vector >> 5) & 0x7F; 15886621Sbt150084 vector_bit = vector & 0x1F; 15896621Sbt150084 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); 15906621Sbt150084 mta_reg |= (1 << vector_bit); 15916621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); 15926621Sbt150084 } 15936621Sbt150084 15946621Sbt150084 /* 15956621Sbt150084 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses 15966621Sbt150084 * @hw: pointer to hardware structure 15976621Sbt150084 * @mc_addr_list: the list of new multicast addresses 15986621Sbt150084 * @mc_addr_count: number of addresses 15996621Sbt150084 * @next: iterator function to walk the multicast address list 16006621Sbt150084 * 16016621Sbt150084 * The given list replaces any existing list. Clears the MC addrs from receive 16026621Sbt150084 * address registers and the multicast table. Uses unused receive address 16036621Sbt150084 * registers for the first multicast addresses, and hashes the rest into the 16046621Sbt150084 * multicast table. 16056621Sbt150084 */ 16066621Sbt150084 s32 16076621Sbt150084 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list, 16086621Sbt150084 u32 mc_addr_count, ixgbe_mc_addr_itr next) 16096621Sbt150084 { 16106621Sbt150084 u32 i; 16116621Sbt150084 u32 vmdq; 16126621Sbt150084 16136621Sbt150084 /* 16146621Sbt150084 * Set the new number of MC addresses that we are being requested to 16156621Sbt150084 * use. 16166621Sbt150084 */ 16176621Sbt150084 hw->addr_ctrl.num_mc_addrs = mc_addr_count; 16186621Sbt150084 hw->addr_ctrl.mta_in_use = 0; 16196621Sbt150084 16206621Sbt150084 /* Clear the MTA */ 16216621Sbt150084 DEBUGOUT(" Clearing MTA\n"); 16226621Sbt150084 for (i = 0; i < hw->mac.mcft_size; i++) 16236621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0); 16246621Sbt150084 16256621Sbt150084 /* Add the new addresses */ 16266621Sbt150084 for (i = 0; i < mc_addr_count; i++) { 16276621Sbt150084 DEBUGOUT(" Adding the multicast addresses:\n"); 16289353SSamuel.Tu@Sun.COM ixgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq)); 16296621Sbt150084 } 16306621Sbt150084 16316621Sbt150084 /* Enable mta */ 16326621Sbt150084 if (hw->addr_ctrl.mta_in_use > 0) 16336621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, 16346621Sbt150084 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type); 16356621Sbt150084 16366621Sbt150084 DEBUGOUT("ixgbe_update_mc_addr_list_generic Complete\n"); 16376621Sbt150084 return (IXGBE_SUCCESS); 16386621Sbt150084 } 16396621Sbt150084 16406621Sbt150084 /* 16416621Sbt150084 * ixgbe_enable_mc_generic - Enable multicast address in RAR 16426621Sbt150084 * @hw: pointer to hardware structure 16436621Sbt150084 * 16446621Sbt150084 * Enables multicast address in RAR and the use of the multicast hash table. 16456621Sbt150084 */ 16466621Sbt150084 s32 16476621Sbt150084 ixgbe_enable_mc_generic(struct ixgbe_hw *hw) 16486621Sbt150084 { 16496621Sbt150084 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl; 16506621Sbt150084 16516621Sbt150084 if (a->mta_in_use > 0) 16526621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE | 16536621Sbt150084 hw->mac.mc_filter_type); 16546621Sbt150084 16556621Sbt150084 return (IXGBE_SUCCESS); 16566621Sbt150084 } 16576621Sbt150084 16586621Sbt150084 /* 16596621Sbt150084 * ixgbe_disable_mc_generic - Disable multicast address in RAR 16606621Sbt150084 * @hw: pointer to hardware structure 16616621Sbt150084 * 16626621Sbt150084 * Disables multicast address in RAR and the use of the multicast hash table. 16636621Sbt150084 */ 16646621Sbt150084 s32 16656621Sbt150084 ixgbe_disable_mc_generic(struct ixgbe_hw *hw) 16666621Sbt150084 { 16676621Sbt150084 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl; 16686621Sbt150084 16696621Sbt150084 if (a->mta_in_use > 0) 16706621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type); 16716621Sbt150084 16726621Sbt150084 return (IXGBE_SUCCESS); 16736621Sbt150084 } 16746621Sbt150084 16756621Sbt150084 /* 16769353SSamuel.Tu@Sun.COM * ixgbe_fc_enable_generic - Enable flow control 16779353SSamuel.Tu@Sun.COM * @hw: pointer to hardware structure 16789353SSamuel.Tu@Sun.COM * @packetbuf_num: packet buffer number (0-7) 16799353SSamuel.Tu@Sun.COM * 16809353SSamuel.Tu@Sun.COM * Enable flow control according to the current settings. 16819353SSamuel.Tu@Sun.COM */ 16829353SSamuel.Tu@Sun.COM s32 16839353SSamuel.Tu@Sun.COM ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num) 16849353SSamuel.Tu@Sun.COM { 16859353SSamuel.Tu@Sun.COM s32 ret_val = IXGBE_SUCCESS; 16869353SSamuel.Tu@Sun.COM u32 mflcn_reg, fccfg_reg; 16879353SSamuel.Tu@Sun.COM u32 reg; 16889353SSamuel.Tu@Sun.COM 16899353SSamuel.Tu@Sun.COM DEBUGFUNC("ixgbe_fc_enable_generic"); 16909353SSamuel.Tu@Sun.COM 16919353SSamuel.Tu@Sun.COM /* Negotiate the fc mode to use */ 16929353SSamuel.Tu@Sun.COM ret_val = ixgbe_fc_autoneg(hw); 16939353SSamuel.Tu@Sun.COM if (ret_val) 16949353SSamuel.Tu@Sun.COM goto out; 16959353SSamuel.Tu@Sun.COM 16969353SSamuel.Tu@Sun.COM /* Disable any previous flow control settings */ 16979353SSamuel.Tu@Sun.COM mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN); 16989353SSamuel.Tu@Sun.COM mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE); 16999353SSamuel.Tu@Sun.COM 17009353SSamuel.Tu@Sun.COM fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG); 17019353SSamuel.Tu@Sun.COM fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY); 17029353SSamuel.Tu@Sun.COM 17039353SSamuel.Tu@Sun.COM /* 17049353SSamuel.Tu@Sun.COM * The possible values of fc.current_mode are: 17059353SSamuel.Tu@Sun.COM * 0: Flow control is completely disabled 17069353SSamuel.Tu@Sun.COM * 1: Rx flow control is enabled (we can receive pause frames, 17079353SSamuel.Tu@Sun.COM * but not send pause frames). 17089353SSamuel.Tu@Sun.COM * 2: Tx flow control is enabled (we can send pause frames but 17099353SSamuel.Tu@Sun.COM * we do not support receiving pause frames). 17109353SSamuel.Tu@Sun.COM * 3: Both Rx and Tx flow control (symmetric) are enabled. 17119353SSamuel.Tu@Sun.COM * other: Invalid. 17129353SSamuel.Tu@Sun.COM */ 17139353SSamuel.Tu@Sun.COM switch (hw->fc.current_mode) { 17149353SSamuel.Tu@Sun.COM case ixgbe_fc_none: 17159353SSamuel.Tu@Sun.COM /* 17169353SSamuel.Tu@Sun.COM * Flow control is disabled by software override or autoneg. 17179353SSamuel.Tu@Sun.COM * The code below will actually disable it in the HW. 17189353SSamuel.Tu@Sun.COM */ 17199353SSamuel.Tu@Sun.COM break; 17209353SSamuel.Tu@Sun.COM case ixgbe_fc_rx_pause: 17219353SSamuel.Tu@Sun.COM /* 17229353SSamuel.Tu@Sun.COM * Rx Flow control is enabled and Tx Flow control is 17239353SSamuel.Tu@Sun.COM * disabled by software override. Since there really 17249353SSamuel.Tu@Sun.COM * isn't a way to advertise that we are capable of RX 17259353SSamuel.Tu@Sun.COM * Pause ONLY, we will advertise that we support both 17269353SSamuel.Tu@Sun.COM * symmetric and asymmetric Rx PAUSE. Later, we will 17279353SSamuel.Tu@Sun.COM * disable the adapter's ability to send PAUSE frames. 17289353SSamuel.Tu@Sun.COM */ 17299353SSamuel.Tu@Sun.COM mflcn_reg |= IXGBE_MFLCN_RFCE; 17309353SSamuel.Tu@Sun.COM break; 17319353SSamuel.Tu@Sun.COM case ixgbe_fc_tx_pause: 17329353SSamuel.Tu@Sun.COM /* 17339353SSamuel.Tu@Sun.COM * Tx Flow control is enabled, and Rx Flow control is 17349353SSamuel.Tu@Sun.COM * disabled by software override. 17359353SSamuel.Tu@Sun.COM */ 17369353SSamuel.Tu@Sun.COM fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X; 17379353SSamuel.Tu@Sun.COM break; 17389353SSamuel.Tu@Sun.COM case ixgbe_fc_full: 17399353SSamuel.Tu@Sun.COM /* Flow control (both Rx and Tx) is enabled by SW override. */ 17409353SSamuel.Tu@Sun.COM mflcn_reg |= IXGBE_MFLCN_RFCE; 17419353SSamuel.Tu@Sun.COM fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X; 17429353SSamuel.Tu@Sun.COM break; 17439353SSamuel.Tu@Sun.COM default: 17449353SSamuel.Tu@Sun.COM DEBUGOUT("Flow control param set incorrectly\n"); 17459353SSamuel.Tu@Sun.COM ret_val = -IXGBE_ERR_CONFIG; 17469353SSamuel.Tu@Sun.COM goto out; 17479353SSamuel.Tu@Sun.COM } 17489353SSamuel.Tu@Sun.COM 17499353SSamuel.Tu@Sun.COM /* Set 802.3x based flow control settings. */ 17509353SSamuel.Tu@Sun.COM mflcn_reg |= IXGBE_MFLCN_DPF; 17519353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg); 17529353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg); 17539353SSamuel.Tu@Sun.COM 17549353SSamuel.Tu@Sun.COM /* Set up and enable Rx high/low water mark thresholds, enable XON. */ 17559353SSamuel.Tu@Sun.COM if (hw->fc.current_mode & ixgbe_fc_tx_pause) { 17569353SSamuel.Tu@Sun.COM if (hw->fc.send_xon) { 17579353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), 17589353SSamuel.Tu@Sun.COM (hw->fc.low_water | IXGBE_FCRTL_XONE)); 17599353SSamuel.Tu@Sun.COM } else { 17609353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), 17619353SSamuel.Tu@Sun.COM hw->fc.low_water); 17629353SSamuel.Tu@Sun.COM } 17639353SSamuel.Tu@Sun.COM 17649353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), 17659353SSamuel.Tu@Sun.COM (hw->fc.high_water | IXGBE_FCRTH_FCEN)); 17669353SSamuel.Tu@Sun.COM } 17679353SSamuel.Tu@Sun.COM 17689353SSamuel.Tu@Sun.COM /* Configure pause time (2 TCs per register) */ 17699353SSamuel.Tu@Sun.COM reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num)); 17709353SSamuel.Tu@Sun.COM if ((packetbuf_num & 1) == 0) 17719353SSamuel.Tu@Sun.COM reg = (reg & 0xFFFF0000) | hw->fc.pause_time; 17729353SSamuel.Tu@Sun.COM else 17739353SSamuel.Tu@Sun.COM reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16); 17749353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg); 17759353SSamuel.Tu@Sun.COM 17769353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1)); 17779353SSamuel.Tu@Sun.COM 17789353SSamuel.Tu@Sun.COM out: 17799353SSamuel.Tu@Sun.COM return (ret_val); 17809353SSamuel.Tu@Sun.COM } 17819353SSamuel.Tu@Sun.COM 17829353SSamuel.Tu@Sun.COM /* 17839353SSamuel.Tu@Sun.COM * ixgbe_fc_autoneg - Configure flow control 17849353SSamuel.Tu@Sun.COM * @hw: pointer to hardware structure 17859353SSamuel.Tu@Sun.COM * 17869353SSamuel.Tu@Sun.COM * Compares our advertised flow control capabilities to those advertised by 17879353SSamuel.Tu@Sun.COM * our link partner, and determines the proper flow control mode to use. 17889353SSamuel.Tu@Sun.COM */ 17899353SSamuel.Tu@Sun.COM s32 17909353SSamuel.Tu@Sun.COM ixgbe_fc_autoneg(struct ixgbe_hw *hw) 17919353SSamuel.Tu@Sun.COM { 17929353SSamuel.Tu@Sun.COM s32 ret_val = IXGBE_SUCCESS; 17939353SSamuel.Tu@Sun.COM ixgbe_link_speed speed; 17949353SSamuel.Tu@Sun.COM u32 pcs_anadv_reg, pcs_lpab_reg, linkstat; 17959353SSamuel.Tu@Sun.COM bool link_up; 17969353SSamuel.Tu@Sun.COM 17979353SSamuel.Tu@Sun.COM DEBUGFUNC("ixgbe_fc_autoneg"); 17989353SSamuel.Tu@Sun.COM 17999353SSamuel.Tu@Sun.COM /* 18009353SSamuel.Tu@Sun.COM * AN should have completed when the cable was plugged in. 18019353SSamuel.Tu@Sun.COM * Look for reasons to bail out. Bail out if: 18029353SSamuel.Tu@Sun.COM * - FC autoneg is disabled, or if 18039353SSamuel.Tu@Sun.COM * - we don't have multispeed fiber, or if 18049353SSamuel.Tu@Sun.COM * - we're not running at 1G, or if 18059353SSamuel.Tu@Sun.COM * - link is not up, or if 18069353SSamuel.Tu@Sun.COM * - link is up but AN did not complete, or if 18079353SSamuel.Tu@Sun.COM * - link is up and AN completed but timed out 18089353SSamuel.Tu@Sun.COM * 18099353SSamuel.Tu@Sun.COM * Since we're being called from an LSC, link is already know to be up. 18109353SSamuel.Tu@Sun.COM * So use link_up_wait_to_complete=false. 18119353SSamuel.Tu@Sun.COM */ 18129353SSamuel.Tu@Sun.COM hw->mac.ops.check_link(hw, &speed, &link_up, false); 18139353SSamuel.Tu@Sun.COM linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA); 18149353SSamuel.Tu@Sun.COM 18159353SSamuel.Tu@Sun.COM if (hw->fc.disable_fc_autoneg || 18169353SSamuel.Tu@Sun.COM !hw->phy.multispeed_fiber || 18179353SSamuel.Tu@Sun.COM (speed != IXGBE_LINK_SPEED_1GB_FULL) || 18189353SSamuel.Tu@Sun.COM !link_up || 18199353SSamuel.Tu@Sun.COM ((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) || 18209353SSamuel.Tu@Sun.COM ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) { 18219353SSamuel.Tu@Sun.COM hw->fc.fc_was_autonegged = false; 18229353SSamuel.Tu@Sun.COM hw->fc.current_mode = hw->fc.requested_mode; 18239353SSamuel.Tu@Sun.COM DEBUGOUT("Autoneg FC was skipped.\n"); 18249353SSamuel.Tu@Sun.COM goto out; 18259353SSamuel.Tu@Sun.COM } 18269353SSamuel.Tu@Sun.COM 18279353SSamuel.Tu@Sun.COM /* 18289353SSamuel.Tu@Sun.COM * Read the AN advertisement and LP ability registers and resolve 18299353SSamuel.Tu@Sun.COM * local flow control settings accordingly 18309353SSamuel.Tu@Sun.COM */ 18319353SSamuel.Tu@Sun.COM pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); 18329353SSamuel.Tu@Sun.COM pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP); 18339353SSamuel.Tu@Sun.COM if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) && 18349353SSamuel.Tu@Sun.COM (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) { 18359353SSamuel.Tu@Sun.COM /* 18369353SSamuel.Tu@Sun.COM * Now we need to check if the user selected Rx ONLY 18379353SSamuel.Tu@Sun.COM * of pause frames. In this case, we had to advertise 18389353SSamuel.Tu@Sun.COM * FULL flow control because we could not advertise RX 18399353SSamuel.Tu@Sun.COM * ONLY. Hence, we must now check to see if we need to 18409353SSamuel.Tu@Sun.COM * turn OFF the TRANSMISSION of PAUSE frames. 18419353SSamuel.Tu@Sun.COM */ 18429353SSamuel.Tu@Sun.COM if (hw->fc.requested_mode == ixgbe_fc_full) { 18439353SSamuel.Tu@Sun.COM hw->fc.current_mode = ixgbe_fc_full; 18449353SSamuel.Tu@Sun.COM DEBUGOUT("Flow Control = FULL.\n"); 18459353SSamuel.Tu@Sun.COM } else { 18469353SSamuel.Tu@Sun.COM hw->fc.current_mode = ixgbe_fc_rx_pause; 18479353SSamuel.Tu@Sun.COM DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); 18489353SSamuel.Tu@Sun.COM } 18499353SSamuel.Tu@Sun.COM } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) && 18509353SSamuel.Tu@Sun.COM (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) && 18519353SSamuel.Tu@Sun.COM (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) && 18529353SSamuel.Tu@Sun.COM (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) { 18539353SSamuel.Tu@Sun.COM hw->fc.current_mode = ixgbe_fc_tx_pause; 18549353SSamuel.Tu@Sun.COM DEBUGOUT("Flow Control = TX PAUSE frames only.\n"); 18559353SSamuel.Tu@Sun.COM } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) && 18569353SSamuel.Tu@Sun.COM (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) && 18579353SSamuel.Tu@Sun.COM !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) && 18589353SSamuel.Tu@Sun.COM (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) { 18599353SSamuel.Tu@Sun.COM hw->fc.current_mode = ixgbe_fc_rx_pause; 18609353SSamuel.Tu@Sun.COM DEBUGOUT("Flow Control = RX PAUSE frames only.\n"); 18619353SSamuel.Tu@Sun.COM } else { 18629353SSamuel.Tu@Sun.COM hw->fc.current_mode = ixgbe_fc_none; 18639353SSamuel.Tu@Sun.COM DEBUGOUT("Flow Control = NONE.\n"); 18649353SSamuel.Tu@Sun.COM } 18659353SSamuel.Tu@Sun.COM 18669353SSamuel.Tu@Sun.COM /* Record that current_mode is the result of a successful autoneg */ 18679353SSamuel.Tu@Sun.COM hw->fc.fc_was_autonegged = true; 18689353SSamuel.Tu@Sun.COM 18699353SSamuel.Tu@Sun.COM out: 18709353SSamuel.Tu@Sun.COM return (ret_val); 18719353SSamuel.Tu@Sun.COM } 18729353SSamuel.Tu@Sun.COM 18739353SSamuel.Tu@Sun.COM /* 18749353SSamuel.Tu@Sun.COM * ixgbe_setup_fc - Set up flow control 18759353SSamuel.Tu@Sun.COM * @hw: pointer to hardware structure 18769353SSamuel.Tu@Sun.COM * 18779353SSamuel.Tu@Sun.COM * Called at init time to set up flow control. 18789353SSamuel.Tu@Sun.COM */ 18799353SSamuel.Tu@Sun.COM s32 18809353SSamuel.Tu@Sun.COM ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num) 18819353SSamuel.Tu@Sun.COM { 18829353SSamuel.Tu@Sun.COM s32 ret_val = IXGBE_SUCCESS; 18839353SSamuel.Tu@Sun.COM u32 reg; 18849353SSamuel.Tu@Sun.COM 18859353SSamuel.Tu@Sun.COM /* Validate the packetbuf configuration */ 18869353SSamuel.Tu@Sun.COM if (packetbuf_num < 0 || packetbuf_num > 7) { 18879353SSamuel.Tu@Sun.COM DEBUGOUT1("Invalid packet buffer number [%d], expected range is" 18889353SSamuel.Tu@Sun.COM " 0-7\n", packetbuf_num); 18899353SSamuel.Tu@Sun.COM ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; 18909353SSamuel.Tu@Sun.COM goto out; 18919353SSamuel.Tu@Sun.COM } 18929353SSamuel.Tu@Sun.COM 18939353SSamuel.Tu@Sun.COM /* 18949353SSamuel.Tu@Sun.COM * Validate the water mark configuration. Zero water marks are invalid 18959353SSamuel.Tu@Sun.COM * because it causes the controller to just blast out fc packets. 18969353SSamuel.Tu@Sun.COM */ 18979353SSamuel.Tu@Sun.COM if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) { 18989353SSamuel.Tu@Sun.COM DEBUGOUT("Invalid water mark configuration\n"); 18999353SSamuel.Tu@Sun.COM ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; 19009353SSamuel.Tu@Sun.COM goto out; 19019353SSamuel.Tu@Sun.COM } 19029353SSamuel.Tu@Sun.COM 19039353SSamuel.Tu@Sun.COM /* 19049353SSamuel.Tu@Sun.COM * Validate the requested mode. Strict IEEE mode does not allow 19059353SSamuel.Tu@Sun.COM * ixgbe_fc_rx_pause because it will cause us to fail at UNH. 19069353SSamuel.Tu@Sun.COM */ 19079353SSamuel.Tu@Sun.COM if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) { 19089353SSamuel.Tu@Sun.COM DEBUGOUT("ixgbe_fc_rx_pause not valid in strict IEEE mode\n"); 19099353SSamuel.Tu@Sun.COM ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS; 19109353SSamuel.Tu@Sun.COM goto out; 19119353SSamuel.Tu@Sun.COM } 19129353SSamuel.Tu@Sun.COM 19139353SSamuel.Tu@Sun.COM /* 19149353SSamuel.Tu@Sun.COM * 10gig parts do not have a word in the EEPROM to determine the 19159353SSamuel.Tu@Sun.COM * default flow control setting, so we explicitly set it to full. 19169353SSamuel.Tu@Sun.COM */ 19179353SSamuel.Tu@Sun.COM if (hw->fc.requested_mode == ixgbe_fc_default) 19189353SSamuel.Tu@Sun.COM hw->fc.requested_mode = ixgbe_fc_full; 19199353SSamuel.Tu@Sun.COM 19209353SSamuel.Tu@Sun.COM /* 19219353SSamuel.Tu@Sun.COM * Set up the 1G flow control advertisement registers so the HW will be 19229353SSamuel.Tu@Sun.COM * able to do fc autoneg once the cable is plugged in. If we end up 19239353SSamuel.Tu@Sun.COM * using 10g instead, this is harmless. 19249353SSamuel.Tu@Sun.COM */ 19259353SSamuel.Tu@Sun.COM reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA); 19269353SSamuel.Tu@Sun.COM 19279353SSamuel.Tu@Sun.COM /* 19289353SSamuel.Tu@Sun.COM * The possible values of fc.requested_mode are: 19299353SSamuel.Tu@Sun.COM * 0: Flow control is completely disabled 19309353SSamuel.Tu@Sun.COM * 1: Rx flow control is enabled (we can receive pause frames, 19319353SSamuel.Tu@Sun.COM * but not send pause frames). 19329353SSamuel.Tu@Sun.COM * 2: Tx flow control is enabled (we can send pause frames but 19339353SSamuel.Tu@Sun.COM * we do not support receiving pause frames). 19349353SSamuel.Tu@Sun.COM * 3: Both Rx and Tx flow control (symmetric) are enabled. 19359353SSamuel.Tu@Sun.COM * other: Invalid. 19369353SSamuel.Tu@Sun.COM */ 19379353SSamuel.Tu@Sun.COM switch (hw->fc.requested_mode) { 19389353SSamuel.Tu@Sun.COM case ixgbe_fc_none: 19399353SSamuel.Tu@Sun.COM /* Flow control completely disabled by software override. */ 19409353SSamuel.Tu@Sun.COM reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE); 19419353SSamuel.Tu@Sun.COM break; 19429353SSamuel.Tu@Sun.COM case ixgbe_fc_rx_pause: 19439353SSamuel.Tu@Sun.COM /* 19449353SSamuel.Tu@Sun.COM * Rx Flow control is enabled and Tx Flow control is 19459353SSamuel.Tu@Sun.COM * disabled by software override. Since there really 19469353SSamuel.Tu@Sun.COM * isn't a way to advertise that we are capable of RX 19479353SSamuel.Tu@Sun.COM * Pause ONLY, we will advertise that we support both 19489353SSamuel.Tu@Sun.COM * symmetric and asymmetric Rx PAUSE. Later, we will 19499353SSamuel.Tu@Sun.COM * disable the adapter's ability to send PAUSE frames. 19509353SSamuel.Tu@Sun.COM */ 19519353SSamuel.Tu@Sun.COM reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE); 19529353SSamuel.Tu@Sun.COM break; 19539353SSamuel.Tu@Sun.COM case ixgbe_fc_tx_pause: 19549353SSamuel.Tu@Sun.COM /* 19559353SSamuel.Tu@Sun.COM * Tx Flow control is enabled, and Rx Flow control is 19569353SSamuel.Tu@Sun.COM * disabled by software override. 19579353SSamuel.Tu@Sun.COM */ 19589353SSamuel.Tu@Sun.COM reg |= (IXGBE_PCS1GANA_ASM_PAUSE); 19599353SSamuel.Tu@Sun.COM reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE); 19609353SSamuel.Tu@Sun.COM break; 19619353SSamuel.Tu@Sun.COM case ixgbe_fc_full: 19629353SSamuel.Tu@Sun.COM /* Flow control (both Rx and Tx) is enabled by SW override. */ 19639353SSamuel.Tu@Sun.COM reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE); 19649353SSamuel.Tu@Sun.COM break; 19659353SSamuel.Tu@Sun.COM default: 19669353SSamuel.Tu@Sun.COM DEBUGOUT("Flow control param set incorrectly\n"); 19679353SSamuel.Tu@Sun.COM ret_val = -IXGBE_ERR_CONFIG; 19689353SSamuel.Tu@Sun.COM goto out; 19699353SSamuel.Tu@Sun.COM } 19709353SSamuel.Tu@Sun.COM 19719353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg); 19729353SSamuel.Tu@Sun.COM reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL); 19739353SSamuel.Tu@Sun.COM 19749353SSamuel.Tu@Sun.COM /* Enable and restart autoneg to inform the link partner */ 19759353SSamuel.Tu@Sun.COM reg |= IXGBE_PCS1GLCTL_AN_ENABLE | IXGBE_PCS1GLCTL_AN_RESTART; 19769353SSamuel.Tu@Sun.COM 19779353SSamuel.Tu@Sun.COM /* Disable AN timeout */ 19789353SSamuel.Tu@Sun.COM if (hw->fc.strict_ieee) 19799353SSamuel.Tu@Sun.COM reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN; 19809353SSamuel.Tu@Sun.COM 19819353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg); 19829353SSamuel.Tu@Sun.COM DEBUGOUT1("Set up FC; PCS1GLCTL = 0x%08X\n", reg); 19839353SSamuel.Tu@Sun.COM 19849353SSamuel.Tu@Sun.COM out: 19859353SSamuel.Tu@Sun.COM return (ret_val); 19869353SSamuel.Tu@Sun.COM } 19879353SSamuel.Tu@Sun.COM 19889353SSamuel.Tu@Sun.COM /* 19896621Sbt150084 * ixgbe_disable_pcie_master - Disable PCI-express master access 19906621Sbt150084 * @hw: pointer to hardware structure 19916621Sbt150084 * 19926621Sbt150084 * Disables PCI-Express master access and verifies there are no pending 19936621Sbt150084 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable 19946621Sbt150084 * bit hasn't caused the master requests to be disabled, else IXGBE_SUCCESS 19956621Sbt150084 * is returned signifying master requests disabled. 19966621Sbt150084 */ 19976621Sbt150084 s32 19986621Sbt150084 ixgbe_disable_pcie_master(struct ixgbe_hw *hw) 19996621Sbt150084 { 20008490SPaul.Guo@Sun.COM u32 i; 20018490SPaul.Guo@Sun.COM u32 reg_val; 20028490SPaul.Guo@Sun.COM u32 number_of_queues; 20036621Sbt150084 s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING; 20046621Sbt150084 20058490SPaul.Guo@Sun.COM /* Disable the receive unit by stopping each queue */ 20068490SPaul.Guo@Sun.COM number_of_queues = hw->mac.max_rx_queues; 20078490SPaul.Guo@Sun.COM for (i = 0; i < number_of_queues; i++) { 20088490SPaul.Guo@Sun.COM reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i)); 20098490SPaul.Guo@Sun.COM if (reg_val & IXGBE_RXDCTL_ENABLE) { 20108490SPaul.Guo@Sun.COM reg_val &= ~IXGBE_RXDCTL_ENABLE; 20118490SPaul.Guo@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val); 20128490SPaul.Guo@Sun.COM } 20138490SPaul.Guo@Sun.COM } 20148490SPaul.Guo@Sun.COM 20158490SPaul.Guo@Sun.COM reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL); 20168490SPaul.Guo@Sun.COM reg_val |= IXGBE_CTRL_GIO_DIS; 20178490SPaul.Guo@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val); 20186621Sbt150084 20196621Sbt150084 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) { 20206621Sbt150084 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) { 20216621Sbt150084 status = IXGBE_SUCCESS; 20226621Sbt150084 break; 20236621Sbt150084 } 20246621Sbt150084 usec_delay(100); 20256621Sbt150084 } 20266621Sbt150084 20276621Sbt150084 return (status); 20286621Sbt150084 } 20296621Sbt150084 20306621Sbt150084 /* 20316621Sbt150084 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore 20326621Sbt150084 * @hw: pointer to hardware structure 20336621Sbt150084 * @mask: Mask to specify which semaphore to acquire 20346621Sbt150084 * 20356621Sbt150084 * Acquires the SWFW semaphore thought the GSSR register for the specified 20366621Sbt150084 * function (CSR, PHY0, PHY1, EEPROM, Flash) 20376621Sbt150084 */ 20386621Sbt150084 s32 20396621Sbt150084 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask) 20406621Sbt150084 { 20416621Sbt150084 u32 gssr; 20426621Sbt150084 u32 swmask = mask; 20436621Sbt150084 u32 fwmask = mask << 5; 20446621Sbt150084 s32 timeout = 200; 20456621Sbt150084 20466621Sbt150084 while (timeout) { 20479353SSamuel.Tu@Sun.COM /* 20489353SSamuel.Tu@Sun.COM * SW EEPROM semaphore bit is used for access to all 20499353SSamuel.Tu@Sun.COM * SW_FW_SYNC/GSSR bits (not just EEPROM) 20509353SSamuel.Tu@Sun.COM */ 20516621Sbt150084 if (ixgbe_get_eeprom_semaphore(hw)) 20526621Sbt150084 return (-IXGBE_ERR_SWFW_SYNC); 20536621Sbt150084 20546621Sbt150084 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR); 20556621Sbt150084 if (!(gssr & (fwmask | swmask))) 20566621Sbt150084 break; 20576621Sbt150084 20586621Sbt150084 /* 20596621Sbt150084 * Firmware currently using resource (fwmask) or other software 20606621Sbt150084 * thread currently using resource (swmask) 20616621Sbt150084 */ 20626621Sbt150084 ixgbe_release_eeprom_semaphore(hw); 20636621Sbt150084 msec_delay(5); 20646621Sbt150084 timeout--; 20656621Sbt150084 } 20666621Sbt150084 20676621Sbt150084 if (!timeout) { 20689353SSamuel.Tu@Sun.COM DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n"); 20696621Sbt150084 return (-IXGBE_ERR_SWFW_SYNC); 20706621Sbt150084 } 20716621Sbt150084 20726621Sbt150084 gssr |= swmask; 20736621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr); 20746621Sbt150084 20756621Sbt150084 ixgbe_release_eeprom_semaphore(hw); 20766621Sbt150084 return (IXGBE_SUCCESS); 20776621Sbt150084 } 20786621Sbt150084 20796621Sbt150084 /* 20806621Sbt150084 * ixgbe_release_swfw_sync - Release SWFW semaphore 20816621Sbt150084 * @hw: pointer to hardware structure 20826621Sbt150084 * @mask: Mask to specify which semaphore to release 20836621Sbt150084 * 20846621Sbt150084 * Releases the SWFW semaphore thought the GSSR register for the specified 20856621Sbt150084 * function (CSR, PHY0, PHY1, EEPROM, Flash) 20866621Sbt150084 */ 20876621Sbt150084 void 20886621Sbt150084 ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask) 20896621Sbt150084 { 20906621Sbt150084 u32 gssr; 20916621Sbt150084 u32 swmask = mask; 20926621Sbt150084 20936621Sbt150084 (void) ixgbe_get_eeprom_semaphore(hw); 20946621Sbt150084 20956621Sbt150084 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR); 20966621Sbt150084 gssr &= ~swmask; 20976621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr); 20986621Sbt150084 20996621Sbt150084 ixgbe_release_eeprom_semaphore(hw); 21006621Sbt150084 } 21019353SSamuel.Tu@Sun.COM 21029353SSamuel.Tu@Sun.COM /* 21039353SSamuel.Tu@Sun.COM * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit 21049353SSamuel.Tu@Sun.COM * @hw: pointer to hardware structure 21059353SSamuel.Tu@Sun.COM * @regval: register value to write to RXCTRL 21069353SSamuel.Tu@Sun.COM * 21079353SSamuel.Tu@Sun.COM * Enables the Rx DMA unit 21089353SSamuel.Tu@Sun.COM */ 21099353SSamuel.Tu@Sun.COM s32 21109353SSamuel.Tu@Sun.COM ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval) 21119353SSamuel.Tu@Sun.COM { 21129353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval); 21139353SSamuel.Tu@Sun.COM 21149353SSamuel.Tu@Sun.COM return (IXGBE_SUCCESS); 21159353SSamuel.Tu@Sun.COM } 21169353SSamuel.Tu@Sun.COM 21179353SSamuel.Tu@Sun.COM /* 21189353SSamuel.Tu@Sun.COM * ixgbe_blink_led_start_generic - Blink LED based on index. 21199353SSamuel.Tu@Sun.COM * @hw: pointer to hardware structure 21209353SSamuel.Tu@Sun.COM * @index: led number to blink 21219353SSamuel.Tu@Sun.COM */ 21229353SSamuel.Tu@Sun.COM s32 21239353SSamuel.Tu@Sun.COM ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index) 21249353SSamuel.Tu@Sun.COM { 21259353SSamuel.Tu@Sun.COM ixgbe_link_speed speed = 0; 21269353SSamuel.Tu@Sun.COM bool link_up = 0; 21279353SSamuel.Tu@Sun.COM u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); 21289353SSamuel.Tu@Sun.COM u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); 21299353SSamuel.Tu@Sun.COM 21309353SSamuel.Tu@Sun.COM /* 21319353SSamuel.Tu@Sun.COM * Link must be up to auto-blink the LEDs; 21329353SSamuel.Tu@Sun.COM * Force it if link is down. 21339353SSamuel.Tu@Sun.COM */ 21349353SSamuel.Tu@Sun.COM hw->mac.ops.check_link(hw, &speed, &link_up, false); 21359353SSamuel.Tu@Sun.COM 21369353SSamuel.Tu@Sun.COM if (!link_up) { 21379353SSamuel.Tu@Sun.COM autoc_reg |= IXGBE_AUTOC_FLU; 21389353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg); 21399353SSamuel.Tu@Sun.COM msec_delay(10); 21409353SSamuel.Tu@Sun.COM } 21419353SSamuel.Tu@Sun.COM 21429353SSamuel.Tu@Sun.COM led_reg &= ~IXGBE_LED_MODE_MASK(index); 21439353SSamuel.Tu@Sun.COM led_reg |= IXGBE_LED_BLINK(index); 21449353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); 21459353SSamuel.Tu@Sun.COM IXGBE_WRITE_FLUSH(hw); 21469353SSamuel.Tu@Sun.COM 21479353SSamuel.Tu@Sun.COM return (IXGBE_SUCCESS); 21489353SSamuel.Tu@Sun.COM } 21499353SSamuel.Tu@Sun.COM 21509353SSamuel.Tu@Sun.COM /* 21519353SSamuel.Tu@Sun.COM * ixgbe_blink_led_stop_generic - Stop blinking LED based on index. 21529353SSamuel.Tu@Sun.COM * @hw: pointer to hardware structure 21539353SSamuel.Tu@Sun.COM * @index: led number to stop blinking 21549353SSamuel.Tu@Sun.COM */ 21559353SSamuel.Tu@Sun.COM s32 21569353SSamuel.Tu@Sun.COM ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index) 21579353SSamuel.Tu@Sun.COM { 21589353SSamuel.Tu@Sun.COM u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC); 21599353SSamuel.Tu@Sun.COM u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); 21609353SSamuel.Tu@Sun.COM 21619353SSamuel.Tu@Sun.COM autoc_reg &= ~IXGBE_AUTOC_FLU; 21629353SSamuel.Tu@Sun.COM autoc_reg |= IXGBE_AUTOC_AN_RESTART; 21639353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg); 21649353SSamuel.Tu@Sun.COM 21659353SSamuel.Tu@Sun.COM led_reg &= ~IXGBE_LED_MODE_MASK(index); 21669353SSamuel.Tu@Sun.COM led_reg &= ~IXGBE_LED_BLINK(index); 21679353SSamuel.Tu@Sun.COM led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index); 21689353SSamuel.Tu@Sun.COM IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); 21699353SSamuel.Tu@Sun.COM IXGBE_WRITE_FLUSH(hw); 21709353SSamuel.Tu@Sun.COM 21719353SSamuel.Tu@Sun.COM return (IXGBE_SUCCESS); 21729353SSamuel.Tu@Sun.COM } 2173