4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "ixgbe/ixgbe_type.h"
35 #include "ixgbe/ixgbe_82599.h"
36 #include "ixgbe/ixgbe_api.h"
37 #include "ixgbe/ixgbe_common.h"
38 #include "ixgbe/ixgbe_phy.h"
39 #include "ixgbe_bypass_defines.h"
40 #include "ixgbe_bypass.h"
43 * ixgbe_set_fiber_fixed_speed - Set module link speed for fixed fiber
44 * @hw: pointer to hardware structure
45 * @speed: link speed to set
47 * We set the module speed differently for fixed fiber. For other
48 * multi-speed devices we don't have an error value so here if we
49 * detect an error we just log it and exit.
52 ixgbe_set_fiber_fixed_speed(struct ixgbe_hw *hw, ixgbe_link_speed speed)
58 case IXGBE_LINK_SPEED_10GB_FULL:
59 /* one bit mask same as setting on */
60 rs = IXGBE_SFF_SOFT_RS_SELECT_10G;
62 case IXGBE_LINK_SPEED_1GB_FULL:
63 rs = IXGBE_SFF_SOFT_RS_SELECT_1G;
66 DEBUGOUT("Invalid fixed module speed\n");
71 status = hw->phy.ops.read_i2c_byte(hw, IXGBE_SFF_SFF_8472_OSCB,
72 IXGBE_I2C_EEPROM_DEV_ADDR2,
75 DEBUGOUT("Failed to read Rx Rate Select RS0\n");
79 eeprom_data = (eeprom_data & ~IXGBE_SFF_SOFT_RS_SELECT_MASK) & rs;
81 status = hw->phy.ops.write_i2c_byte(hw, IXGBE_SFF_SFF_8472_OSCB,
82 IXGBE_I2C_EEPROM_DEV_ADDR2,
85 DEBUGOUT("Failed to write Rx Rate Select RS0\n");
90 status = hw->phy.ops.read_i2c_byte(hw, IXGBE_SFF_SFF_8472_ESCB,
91 IXGBE_I2C_EEPROM_DEV_ADDR2,
94 DEBUGOUT("Failed to read Rx Rate Select RS1\n");
98 eeprom_data = (eeprom_data & ~IXGBE_SFF_SOFT_RS_SELECT_MASK) & rs;
100 status = hw->phy.ops.write_i2c_byte(hw, IXGBE_SFF_SFF_8472_ESCB,
101 IXGBE_I2C_EEPROM_DEV_ADDR2,
104 DEBUGOUT("Failed to write Rx Rate Select RS1\n");
112 * ixgbe_setup_mac_link_multispeed_fixed_fiber - Set MAC link speed
113 * @hw: pointer to hardware structure
114 * @speed: new link speed
115 * @autoneg: true if autonegotiation enabled
116 * @autoneg_wait_to_complete: true when waiting for completion is needed
118 * Set the link speed in the AUTOC register and restarts link.
121 ixgbe_setup_mac_link_multispeed_fixed_fiber(struct ixgbe_hw *hw,
122 ixgbe_link_speed speed, bool autoneg,
123 bool autoneg_wait_to_complete)
125 s32 status = IXGBE_SUCCESS;
126 ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
127 ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
129 u32 esdp_reg = IXGBE_READ_REG(hw, IXGBE_ESDP);
131 bool link_up = false;
136 /* Mask off requested but non-supported speeds */
137 status = ixgbe_get_link_capabilities(hw, &link_speed, &negotiation);
138 if (status != IXGBE_SUCCESS)
144 * Try each speed one by one, highest priority first. We do this in
145 * software because 10gb fiber doesn't support speed autonegotiation.
147 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
149 highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL;
151 /* If we already have link at this speed, just jump out */
152 status = ixgbe_check_link(hw, &link_speed, &link_up, false);
153 if (status != IXGBE_SUCCESS)
156 if ((link_speed == IXGBE_LINK_SPEED_10GB_FULL) && link_up)
158 /* Set the module link speed */
159 ixgbe_set_fiber_fixed_speed(hw, IXGBE_LINK_SPEED_10GB_FULL);
161 /* Set the module link speed */
162 esdp_reg |= (IXGBE_ESDP_SDP5_DIR | IXGBE_ESDP_SDP5);
163 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp_reg);
164 IXGBE_WRITE_FLUSH(hw);
166 /* Allow module to change analog characteristics (1G->10G) */
169 status = ixgbe_setup_mac_link_82599(hw,
170 IXGBE_LINK_SPEED_10GB_FULL,
172 autoneg_wait_to_complete);
173 if (status != IXGBE_SUCCESS)
176 /* Flap the tx laser if it has not already been done */
177 ixgbe_flap_tx_laser(hw);
180 * Wait for the controller to acquire link. Per IEEE 802.3ap,
181 * Section 73.10.2, we may have to wait up to 500ms if KR is
182 * attempted. 82599 uses the same timing for 10g SFI.
184 for (i = 0; i < 5; i++) {
185 /* Wait for the link partner to also set speed */
188 /* If we have link, just jump out */
189 status = ixgbe_check_link(hw, &link_speed,
191 if (status != IXGBE_SUCCESS)
199 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
201 if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
202 highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
204 /* If we already have link at this speed, just jump out */
205 status = ixgbe_check_link(hw, &link_speed, &link_up, false);
206 if (status != IXGBE_SUCCESS)
209 if ((link_speed == IXGBE_LINK_SPEED_1GB_FULL) && link_up)
212 /* Set the module link speed */
213 ixgbe_set_fiber_fixed_speed(hw, IXGBE_LINK_SPEED_1GB_FULL);
215 /* Allow module to change analog characteristics (10G->1G) */
218 status = ixgbe_setup_mac_link_82599(hw,
219 IXGBE_LINK_SPEED_1GB_FULL,
221 autoneg_wait_to_complete);
222 if (status != IXGBE_SUCCESS)
225 /* Flap the tx laser if it has not already been done */
226 ixgbe_flap_tx_laser(hw);
228 /* Wait for the link partner to also set speed */
231 /* If we have link, just jump out */
232 status = ixgbe_check_link(hw, &link_speed, &link_up, false);
233 if (status != IXGBE_SUCCESS)
241 * We didn't get link. Configure back to the highest speed we tried,
242 * (if there was more than one). We call ourselves back with just the
243 * single highest speed that the user requested.
246 status = ixgbe_setup_mac_link_multispeed_fixed_fiber(hw,
247 highest_link_speed, autoneg, autoneg_wait_to_complete);
250 /* Set autoneg_advertised value based on input link speed */
251 hw->phy.autoneg_advertised = 0;
253 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
254 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
256 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
257 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
263 * Wrapper around ND functions to support BYPASS nic.
266 ixgbe_bypass_init_shared_code(struct ixgbe_hw *hw)
268 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
269 hw->mac.type = ixgbe_mac_82599EB;
272 return (ixgbe_init_shared_code(hw));
275 static enum ixgbe_media_type
276 ixgbe_bypass_get_media_type(struct ixgbe_hw *hw)
278 enum ixgbe_media_type media_type;
282 if (hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
283 media_type = ixgbe_media_type_fiber;
285 media_type = ixgbe_get_media_type_82599(hw);
291 ixgbe_bypass_init_hw(struct ixgbe_hw *hw)
295 if ((rc = ixgbe_init_hw(hw)) == 0 &&
296 hw->device_id == IXGBE_DEV_ID_82599_BYPASS) {
298 hw->mac.ops.setup_link =
299 &ixgbe_setup_mac_link_multispeed_fixed_fiber;
301 hw->mac.ops.get_media_type = &ixgbe_bypass_get_media_type;
303 hw->mac.ops.disable_tx_laser = NULL;
304 hw->mac.ops.enable_tx_laser = NULL;
305 hw->mac.ops.flap_tx_laser = NULL;