|
3 | 3 |
|
4 | 4 | #include "igc_phy.h"
|
5 | 5 |
|
6 |
| -/* forward declaration */ |
7 |
| -static s32 igc_phy_setup_autoneg(struct igc_hw *hw); |
8 |
| -static s32 igc_wait_autoneg(struct igc_hw *hw); |
9 |
| - |
10 | 6 | /**
|
11 | 7 | * igc_check_reset_block - Check if PHY reset is blocked
|
12 | 8 | * @hw: pointer to the HW structure
|
@@ -207,100 +203,6 @@ s32 igc_phy_hw_reset(struct igc_hw *hw)
|
207 | 203 | return ret_val;
|
208 | 204 | }
|
209 | 205 |
|
210 |
| -/** |
211 |
| - * igc_copper_link_autoneg - Setup/Enable autoneg for copper link |
212 |
| - * @hw: pointer to the HW structure |
213 |
| - * |
214 |
| - * Performs initial bounds checking on autoneg advertisement parameter, then |
215 |
| - * configure to advertise the full capability. Setup the PHY to autoneg |
216 |
| - * and restart the negotiation process between the link partner. If |
217 |
| - * autoneg_wait_to_complete, then wait for autoneg to complete before exiting. |
218 |
| - */ |
219 |
| -static s32 igc_copper_link_autoneg(struct igc_hw *hw) |
220 |
| -{ |
221 |
| - struct igc_phy_info *phy = &hw->phy; |
222 |
| - u16 phy_ctrl; |
223 |
| - s32 ret_val; |
224 |
| - |
225 |
| - /* Perform some bounds checking on the autoneg advertisement |
226 |
| - * parameter. |
227 |
| - */ |
228 |
| - phy->autoneg_advertised &= phy->autoneg_mask; |
229 |
| - |
230 |
| - /* If autoneg_advertised is zero, we assume it was not defaulted |
231 |
| - * by the calling code so we set to advertise full capability. |
232 |
| - */ |
233 |
| - if (phy->autoneg_advertised == 0) |
234 |
| - phy->autoneg_advertised = phy->autoneg_mask; |
235 |
| - |
236 |
| - hw_dbg("Reconfiguring auto-neg advertisement params\n"); |
237 |
| - ret_val = igc_phy_setup_autoneg(hw); |
238 |
| - if (ret_val) { |
239 |
| - hw_dbg("Error Setting up Auto-Negotiation\n"); |
240 |
| - goto out; |
241 |
| - } |
242 |
| - hw_dbg("Restarting Auto-Neg\n"); |
243 |
| - |
244 |
| - /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
245 |
| - * the Auto Neg Restart bit in the PHY control register. |
246 |
| - */ |
247 |
| - ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl); |
248 |
| - if (ret_val) |
249 |
| - goto out; |
250 |
| - |
251 |
| - phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
252 |
| - ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl); |
253 |
| - if (ret_val) |
254 |
| - goto out; |
255 |
| - |
256 |
| - /* Does the user want to wait for Auto-Neg to complete here, or |
257 |
| - * check at a later time (for example, callback routine). |
258 |
| - */ |
259 |
| - if (phy->autoneg_wait_to_complete) { |
260 |
| - ret_val = igc_wait_autoneg(hw); |
261 |
| - if (ret_val) { |
262 |
| - hw_dbg("Error while waiting for autoneg to complete\n"); |
263 |
| - goto out; |
264 |
| - } |
265 |
| - } |
266 |
| - |
267 |
| - hw->mac.get_link_status = true; |
268 |
| - |
269 |
| -out: |
270 |
| - return ret_val; |
271 |
| -} |
272 |
| - |
273 |
| -/** |
274 |
| - * igc_wait_autoneg - Wait for auto-neg completion |
275 |
| - * @hw: pointer to the HW structure |
276 |
| - * |
277 |
| - * Waits for auto-negotiation to complete or for the auto-negotiation time |
278 |
| - * limit to expire, which ever happens first. |
279 |
| - */ |
280 |
| -static s32 igc_wait_autoneg(struct igc_hw *hw) |
281 |
| -{ |
282 |
| - u16 i, phy_status; |
283 |
| - s32 ret_val = 0; |
284 |
| - |
285 |
| - /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */ |
286 |
| - for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) { |
287 |
| - ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
288 |
| - if (ret_val) |
289 |
| - break; |
290 |
| - ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
291 |
| - if (ret_val) |
292 |
| - break; |
293 |
| - if (phy_status & MII_SR_AUTONEG_COMPLETE) |
294 |
| - break; |
295 |
| - msleep(100); |
296 |
| - } |
297 |
| - |
298 |
| - /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation |
299 |
| - * has completed. |
300 |
| - */ |
301 |
| - return ret_val; |
302 |
| -} |
303 |
| - |
304 | 206 | /**
|
305 | 207 | * igc_phy_setup_autoneg - Configure PHY for auto-negotiation
|
306 | 208 | * @hw: pointer to the HW structure
|
@@ -485,6 +387,100 @@ static s32 igc_phy_setup_autoneg(struct igc_hw *hw)
|
485 | 387 | return ret_val;
|
486 | 388 | }
|
487 | 389 |
|
| 390 | +/** |
| 391 | + * igc_wait_autoneg - Wait for auto-neg completion |
| 392 | + * @hw: pointer to the HW structure |
| 393 | + * |
| 394 | + * Waits for auto-negotiation to complete or for the auto-negotiation time |
| 395 | + * limit to expire, which ever happens first. |
| 396 | + */ |
| 397 | +static s32 igc_wait_autoneg(struct igc_hw *hw) |
| 398 | +{ |
| 399 | + u16 i, phy_status; |
| 400 | + s32 ret_val = 0; |
| 401 | + |
| 402 | + /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */ |
| 403 | + for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) { |
| 404 | + ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
| 405 | + if (ret_val) |
| 406 | + break; |
| 407 | + ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status); |
| 408 | + if (ret_val) |
| 409 | + break; |
| 410 | + if (phy_status & MII_SR_AUTONEG_COMPLETE) |
| 411 | + break; |
| 412 | + msleep(100); |
| 413 | + } |
| 414 | + |
| 415 | + /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation |
| 416 | + * has completed. |
| 417 | + */ |
| 418 | + return ret_val; |
| 419 | +} |
| 420 | + |
| 421 | +/** |
| 422 | + * igc_copper_link_autoneg - Setup/Enable autoneg for copper link |
| 423 | + * @hw: pointer to the HW structure |
| 424 | + * |
| 425 | + * Performs initial bounds checking on autoneg advertisement parameter, then |
| 426 | + * configure to advertise the full capability. Setup the PHY to autoneg |
| 427 | + * and restart the negotiation process between the link partner. If |
| 428 | + * autoneg_wait_to_complete, then wait for autoneg to complete before exiting. |
| 429 | + */ |
| 430 | +static s32 igc_copper_link_autoneg(struct igc_hw *hw) |
| 431 | +{ |
| 432 | + struct igc_phy_info *phy = &hw->phy; |
| 433 | + u16 phy_ctrl; |
| 434 | + s32 ret_val; |
| 435 | + |
| 436 | + /* Perform some bounds checking on the autoneg advertisement |
| 437 | + * parameter. |
| 438 | + */ |
| 439 | + phy->autoneg_advertised &= phy->autoneg_mask; |
| 440 | + |
| 441 | + /* If autoneg_advertised is zero, we assume it was not defaulted |
| 442 | + * by the calling code so we set to advertise full capability. |
| 443 | + */ |
| 444 | + if (phy->autoneg_advertised == 0) |
| 445 | + phy->autoneg_advertised = phy->autoneg_mask; |
| 446 | + |
| 447 | + hw_dbg("Reconfiguring auto-neg advertisement params\n"); |
| 448 | + ret_val = igc_phy_setup_autoneg(hw); |
| 449 | + if (ret_val) { |
| 450 | + hw_dbg("Error Setting up Auto-Negotiation\n"); |
| 451 | + goto out; |
| 452 | + } |
| 453 | + hw_dbg("Restarting Auto-Neg\n"); |
| 454 | + |
| 455 | + /* Restart auto-negotiation by setting the Auto Neg Enable bit and |
| 456 | + * the Auto Neg Restart bit in the PHY control register. |
| 457 | + */ |
| 458 | + ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl); |
| 459 | + if (ret_val) |
| 460 | + goto out; |
| 461 | + |
| 462 | + phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG); |
| 463 | + ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl); |
| 464 | + if (ret_val) |
| 465 | + goto out; |
| 466 | + |
| 467 | + /* Does the user want to wait for Auto-Neg to complete here, or |
| 468 | + * check at a later time (for example, callback routine). |
| 469 | + */ |
| 470 | + if (phy->autoneg_wait_to_complete) { |
| 471 | + ret_val = igc_wait_autoneg(hw); |
| 472 | + if (ret_val) { |
| 473 | + hw_dbg("Error while waiting for autoneg to complete\n"); |
| 474 | + goto out; |
| 475 | + } |
| 476 | + } |
| 477 | + |
| 478 | + hw->mac.get_link_status = true; |
| 479 | + |
| 480 | +out: |
| 481 | + return ret_val; |
| 482 | +} |
| 483 | + |
488 | 484 | /**
|
489 | 485 | * igc_setup_copper_link - Configure copper link settings
|
490 | 486 | * @hw: pointer to the HW structure
|
|
0 commit comments