blob: 83b706c460b3e639ba188268da438bb6cf473843 [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Alexander Duyck86d5d382009-02-06 23:23:12 +00004 Copyright(c) 2007-2009 Intel Corporation.
Auke Kok9d5c8242008-01-24 02:22:38 -08005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/if_ether.h>
29#include <linux/delay.h>
30
31#include "e1000_mac.h"
32#include "e1000_phy.h"
33
Auke Kok9d5c8242008-01-24 02:22:38 -080034static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
35static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
36 u16 *phy_ctrl);
37static s32 igb_wait_autoneg(struct e1000_hw *hw);
38
39/* Cable length tables */
40static const u16 e1000_m88_cable_length_table[] =
41 { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
Alexander Duyck2553bb22009-10-05 06:35:42 +000042#define M88E1000_CABLE_LENGTH_TABLE_SIZE \
43 (sizeof(e1000_m88_cable_length_table) / \
44 sizeof(e1000_m88_cable_length_table[0]))
Auke Kok9d5c8242008-01-24 02:22:38 -080045
46static const u16 e1000_igp_2_cable_length_table[] =
47 { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
48 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
49 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
50 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
51 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
52 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
53 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
54 104, 109, 114, 118, 121, 124};
55#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
56 (sizeof(e1000_igp_2_cable_length_table) / \
57 sizeof(e1000_igp_2_cable_length_table[0]))
58
59/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070060 * igb_check_reset_block - Check if PHY reset is blocked
Auke Kok9d5c8242008-01-24 02:22:38 -080061 * @hw: pointer to the HW structure
62 *
63 * Read the PHY management control register and check whether a PHY reset
64 * is blocked. If a reset is not blocked return 0, otherwise
65 * return E1000_BLK_PHY_RESET (12).
66 **/
67s32 igb_check_reset_block(struct e1000_hw *hw)
68{
69 u32 manc;
70
71 manc = rd32(E1000_MANC);
72
73 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
74 E1000_BLK_PHY_RESET : 0;
75}
76
77/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070078 * igb_get_phy_id - Retrieve the PHY ID and revision
Auke Kok9d5c8242008-01-24 02:22:38 -080079 * @hw: pointer to the HW structure
80 *
81 * Reads the PHY registers and stores the PHY ID and possibly the PHY
82 * revision in the hardware structure.
83 **/
84s32 igb_get_phy_id(struct e1000_hw *hw)
85{
86 struct e1000_phy_info *phy = &hw->phy;
87 s32 ret_val = 0;
88 u16 phy_id;
89
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000090 ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080091 if (ret_val)
92 goto out;
93
94 phy->id = (u32)(phy_id << 16);
95 udelay(20);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +000096 ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
Auke Kok9d5c8242008-01-24 02:22:38 -080097 if (ret_val)
98 goto out;
99
100 phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
101 phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
102
103out:
104 return ret_val;
105}
106
107/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700108 * igb_phy_reset_dsp - Reset PHY DSP
Auke Kok9d5c8242008-01-24 02:22:38 -0800109 * @hw: pointer to the HW structure
110 *
111 * Reset the digital signal processor.
112 **/
113static s32 igb_phy_reset_dsp(struct e1000_hw *hw)
114{
Alexander Duyck2553bb22009-10-05 06:35:42 +0000115 s32 ret_val = 0;
116
117 if (!(hw->phy.ops.write_reg))
118 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800119
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000120 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
Auke Kok9d5c8242008-01-24 02:22:38 -0800121 if (ret_val)
122 goto out;
123
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000124 ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800125
126out:
127 return ret_val;
128}
129
130/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700131 * igb_read_phy_reg_mdic - Read MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800132 * @hw: pointer to the HW structure
133 * @offset: register offset to be read
134 * @data: pointer to the read data
135 *
136 * Reads the MDI control regsiter in the PHY at offset and stores the
137 * information read to data.
138 **/
139static s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
140{
141 struct e1000_phy_info *phy = &hw->phy;
142 u32 i, mdic = 0;
143 s32 ret_val = 0;
144
145 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700146 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800147 ret_val = -E1000_ERR_PARAM;
148 goto out;
149 }
150
151 /*
152 * Set up Op-code, Phy Address, and register offset in the MDI
153 * Control register. The MAC will take care of interfacing with the
154 * PHY to retrieve the desired data.
155 */
156 mdic = ((offset << E1000_MDIC_REG_SHIFT) |
157 (phy->addr << E1000_MDIC_PHY_SHIFT) |
158 (E1000_MDIC_OP_READ));
159
160 wr32(E1000_MDIC, mdic);
161
162 /*
163 * Poll the ready bit to see if the MDI read completed
164 * Increasing the time out as testing showed failures with
165 * the lower time out
166 */
167 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
168 udelay(50);
169 mdic = rd32(E1000_MDIC);
170 if (mdic & E1000_MDIC_READY)
171 break;
172 }
173 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700174 hw_dbg("MDI Read did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800175 ret_val = -E1000_ERR_PHY;
176 goto out;
177 }
178 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700179 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800180 ret_val = -E1000_ERR_PHY;
181 goto out;
182 }
183 *data = (u16) mdic;
184
185out:
186 return ret_val;
187}
188
189/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700190 * igb_write_phy_reg_mdic - Write MDI control register
Auke Kok9d5c8242008-01-24 02:22:38 -0800191 * @hw: pointer to the HW structure
192 * @offset: register offset to write to
193 * @data: data to write to register at offset
194 *
195 * Writes data to MDI control register in the PHY at offset.
196 **/
197static s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
198{
199 struct e1000_phy_info *phy = &hw->phy;
200 u32 i, mdic = 0;
201 s32 ret_val = 0;
202
203 if (offset > MAX_PHY_REG_ADDRESS) {
Auke Kok652fff32008-06-27 11:00:18 -0700204 hw_dbg("PHY Address %d is out of range\n", offset);
Auke Kok9d5c8242008-01-24 02:22:38 -0800205 ret_val = -E1000_ERR_PARAM;
206 goto out;
207 }
208
209 /*
210 * Set up Op-code, Phy Address, and register offset in the MDI
211 * Control register. The MAC will take care of interfacing with the
212 * PHY to retrieve the desired data.
213 */
214 mdic = (((u32)data) |
215 (offset << E1000_MDIC_REG_SHIFT) |
216 (phy->addr << E1000_MDIC_PHY_SHIFT) |
217 (E1000_MDIC_OP_WRITE));
218
219 wr32(E1000_MDIC, mdic);
220
221 /*
222 * Poll the ready bit to see if the MDI read completed
223 * Increasing the time out as testing showed failures with
224 * the lower time out
225 */
226 for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
227 udelay(50);
228 mdic = rd32(E1000_MDIC);
229 if (mdic & E1000_MDIC_READY)
230 break;
231 }
232 if (!(mdic & E1000_MDIC_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -0700233 hw_dbg("MDI Write did not complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800234 ret_val = -E1000_ERR_PHY;
235 goto out;
236 }
237 if (mdic & E1000_MDIC_ERROR) {
Auke Kok652fff32008-06-27 11:00:18 -0700238 hw_dbg("MDI Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800239 ret_val = -E1000_ERR_PHY;
240 goto out;
241 }
242
243out:
244 return ret_val;
245}
246
247/**
Alexander Duyckbf6f7a92009-10-05 06:32:27 +0000248 * igb_read_phy_reg_i2c - Read PHY register using i2c
249 * @hw: pointer to the HW structure
250 * @offset: register offset to be read
251 * @data: pointer to the read data
252 *
253 * Reads the PHY register at offset using the i2c interface and stores the
254 * retrieved information in data.
255 **/
256s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
257{
258 struct e1000_phy_info *phy = &hw->phy;
259 u32 i, i2ccmd = 0;
260
261
262 /*
263 * Set up Op-code, Phy Address, and register address in the I2CCMD
264 * register. The MAC will take care of interfacing with the
265 * PHY to retrieve the desired data.
266 */
267 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
268 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
269 (E1000_I2CCMD_OPCODE_READ));
270
271 wr32(E1000_I2CCMD, i2ccmd);
272
273 /* Poll the ready bit to see if the I2C read completed */
274 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
275 udelay(50);
276 i2ccmd = rd32(E1000_I2CCMD);
277 if (i2ccmd & E1000_I2CCMD_READY)
278 break;
279 }
280 if (!(i2ccmd & E1000_I2CCMD_READY)) {
281 hw_dbg("I2CCMD Read did not complete\n");
282 return -E1000_ERR_PHY;
283 }
284 if (i2ccmd & E1000_I2CCMD_ERROR) {
285 hw_dbg("I2CCMD Error bit set\n");
286 return -E1000_ERR_PHY;
287 }
288
289 /* Need to byte-swap the 16-bit value. */
290 *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
291
292 return 0;
293}
294
295/**
296 * igb_write_phy_reg_i2c - Write PHY register using i2c
297 * @hw: pointer to the HW structure
298 * @offset: register offset to write to
299 * @data: data to write at register offset
300 *
301 * Writes the data to PHY register at the offset using the i2c interface.
302 **/
303s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
304{
305 struct e1000_phy_info *phy = &hw->phy;
306 u32 i, i2ccmd = 0;
307 u16 phy_data_swapped;
308
309
310 /* Swap the data bytes for the I2C interface */
311 phy_data_swapped = ((data >> 8) & 0x00FF) | ((data << 8) & 0xFF00);
312
313 /*
314 * Set up Op-code, Phy Address, and register address in the I2CCMD
315 * register. The MAC will take care of interfacing with the
316 * PHY to retrieve the desired data.
317 */
318 i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
319 (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
320 E1000_I2CCMD_OPCODE_WRITE |
321 phy_data_swapped);
322
323 wr32(E1000_I2CCMD, i2ccmd);
324
325 /* Poll the ready bit to see if the I2C read completed */
326 for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
327 udelay(50);
328 i2ccmd = rd32(E1000_I2CCMD);
329 if (i2ccmd & E1000_I2CCMD_READY)
330 break;
331 }
332 if (!(i2ccmd & E1000_I2CCMD_READY)) {
333 hw_dbg("I2CCMD Write did not complete\n");
334 return -E1000_ERR_PHY;
335 }
336 if (i2ccmd & E1000_I2CCMD_ERROR) {
337 hw_dbg("I2CCMD Error bit set\n");
338 return -E1000_ERR_PHY;
339 }
340
341 return 0;
342}
343
344/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700345 * igb_read_phy_reg_igp - Read igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800346 * @hw: pointer to the HW structure
347 * @offset: register offset to be read
348 * @data: pointer to the read data
349 *
350 * Acquires semaphore, if necessary, then reads the PHY register at offset
351 * and storing the retrieved information in data. Release any acquired
352 * semaphores before exiting.
353 **/
354s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
355{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000356 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800357
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000358 if (!(hw->phy.ops.acquire))
359 goto out;
360
361 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800362 if (ret_val)
363 goto out;
364
365 if (offset > MAX_PHY_MULTI_PAGE_REG) {
366 ret_val = igb_write_phy_reg_mdic(hw,
367 IGP01E1000_PHY_PAGE_SELECT,
368 (u16)offset);
369 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000370 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800371 goto out;
372 }
373 }
374
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000375 ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
376 data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800377
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000378 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800379
380out:
381 return ret_val;
382}
383
384/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700385 * igb_write_phy_reg_igp - Write igp PHY register
Auke Kok9d5c8242008-01-24 02:22:38 -0800386 * @hw: pointer to the HW structure
387 * @offset: register offset to write to
388 * @data: data to write at register offset
389 *
390 * Acquires semaphore, if necessary, then writes the data to PHY register
391 * at the offset. Release any acquired semaphores before exiting.
392 **/
393s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
394{
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000395 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -0800396
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000397 if (!(hw->phy.ops.acquire))
398 goto out;
399
400 ret_val = hw->phy.ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800401 if (ret_val)
402 goto out;
403
404 if (offset > MAX_PHY_MULTI_PAGE_REG) {
405 ret_val = igb_write_phy_reg_mdic(hw,
406 IGP01E1000_PHY_PAGE_SELECT,
407 (u16)offset);
408 if (ret_val) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000409 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800410 goto out;
411 }
412 }
413
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000414 ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
Auke Kok9d5c8242008-01-24 02:22:38 -0800415 data);
416
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000417 hw->phy.ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800418
419out:
420 return ret_val;
421}
422
423/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700424 * igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800425 * @hw: pointer to the HW structure
426 *
427 * Sets up MDI/MDI-X and polarity for m88 PHY's. If necessary, transmit clock
428 * and downshift values are set also.
429 **/
430s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
431{
432 struct e1000_phy_info *phy = &hw->phy;
433 s32 ret_val;
434 u16 phy_data;
435
436 if (phy->reset_disable) {
437 ret_val = 0;
438 goto out;
439 }
440
441 /* Enable CRS on TX. This must be set for half-duplex operation. */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000442 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800443 if (ret_val)
444 goto out;
445
446 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
447
448 /*
449 * Options:
450 * MDI/MDI-X = 0 (default)
451 * 0 - Auto for all speeds
452 * 1 - MDI mode
453 * 2 - MDI-X mode
454 * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
455 */
456 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
457
458 switch (phy->mdix) {
459 case 1:
460 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
461 break;
462 case 2:
463 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
464 break;
465 case 3:
466 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
467 break;
468 case 0:
469 default:
470 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
471 break;
472 }
473
474 /*
475 * Options:
476 * disable_polarity_correction = 0 (default)
477 * Automatic Correction for Reversed Cable Polarity
478 * 0 - Disabled
479 * 1 - Enabled
480 */
481 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
482 if (phy->disable_polarity_correction == 1)
483 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
484
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000485 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800486 if (ret_val)
487 goto out;
488
489 if (phy->revision < E1000_REVISION_4) {
490 /*
491 * Force TX_CLK in the Extended PHY Specific Control Register
492 * to 25MHz clock.
493 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000494 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800495 &phy_data);
496 if (ret_val)
497 goto out;
498
499 phy_data |= M88E1000_EPSCR_TX_CLK_25;
500
501 if ((phy->revision == E1000_REVISION_2) &&
502 (phy->id == M88E1111_I_PHY_ID)) {
503 /* 82573L PHY - set the downshift counter to 5x. */
504 phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
505 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
506 } else {
507 /* Configure Master and Slave downshift values */
508 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
509 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
510 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
511 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
512 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000513 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800514 phy_data);
515 if (ret_val)
516 goto out;
517 }
518
519 /* Commit the changes. */
520 ret_val = igb_phy_sw_reset(hw);
521 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700522 hw_dbg("Error committing the PHY changes\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800523 goto out;
524 }
525
526out:
527 return ret_val;
528}
529
530/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700531 * igb_copper_link_setup_igp - Setup igp PHY's for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800532 * @hw: pointer to the HW structure
533 *
534 * Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
535 * igp PHY's.
536 **/
537s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
538{
539 struct e1000_phy_info *phy = &hw->phy;
540 s32 ret_val;
541 u16 data;
542
543 if (phy->reset_disable) {
544 ret_val = 0;
545 goto out;
546 }
547
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000548 ret_val = phy->ops.reset(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -0800549 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700550 hw_dbg("Error resetting the PHY.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800551 goto out;
552 }
553
Alexander Duycka6a60562009-03-31 20:38:38 +0000554 /*
555 * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
556 * timeout issues when LFS is enabled.
557 */
558 msleep(100);
Auke Kok9d5c8242008-01-24 02:22:38 -0800559
560 /*
561 * The NVM settings will configure LPLU in D3 for
562 * non-IGP1 PHYs.
563 */
564 if (phy->type == e1000_phy_igp) {
565 /* disable lplu d3 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000566 if (phy->ops.set_d3_lplu_state)
567 ret_val = phy->ops.set_d3_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800568 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700569 hw_dbg("Error Disabling LPLU D3\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800570 goto out;
571 }
572 }
573
574 /* disable lplu d0 during driver init */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000575 ret_val = phy->ops.set_d0_lplu_state(hw, false);
Auke Kok9d5c8242008-01-24 02:22:38 -0800576 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700577 hw_dbg("Error Disabling LPLU D0\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800578 goto out;
579 }
580 /* Configure mdi-mdix settings */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000581 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800582 if (ret_val)
583 goto out;
584
585 data &= ~IGP01E1000_PSCR_AUTO_MDIX;
586
587 switch (phy->mdix) {
588 case 1:
589 data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
590 break;
591 case 2:
592 data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
593 break;
594 case 0:
595 default:
596 data |= IGP01E1000_PSCR_AUTO_MDIX;
597 break;
598 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000599 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800600 if (ret_val)
601 goto out;
602
603 /* set auto-master slave resolution settings */
604 if (hw->mac.autoneg) {
605 /*
606 * when autonegotiation advertisement is only 1000Mbps then we
607 * should disable SmartSpeed and enable Auto MasterSlave
608 * resolution as hardware default.
609 */
610 if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
611 /* Disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000612 ret_val = phy->ops.read_reg(hw,
613 IGP01E1000_PHY_PORT_CONFIG,
614 &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800615 if (ret_val)
616 goto out;
617
618 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000619 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -0800620 IGP01E1000_PHY_PORT_CONFIG,
621 data);
622 if (ret_val)
623 goto out;
624
625 /* Set auto Master/Slave resolution process */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000626 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800627 if (ret_val)
628 goto out;
629
630 data &= ~CR_1000T_MS_ENABLE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000631 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800632 if (ret_val)
633 goto out;
634 }
635
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000636 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800637 if (ret_val)
638 goto out;
639
640 /* load defaults for future use */
641 phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
642 ((data & CR_1000T_MS_VALUE) ?
643 e1000_ms_force_master :
644 e1000_ms_force_slave) :
645 e1000_ms_auto;
646
647 switch (phy->ms_type) {
648 case e1000_ms_force_master:
649 data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
650 break;
651 case e1000_ms_force_slave:
652 data |= CR_1000T_MS_ENABLE;
653 data &= ~(CR_1000T_MS_VALUE);
654 break;
655 case e1000_ms_auto:
656 data &= ~CR_1000T_MS_ENABLE;
657 default:
658 break;
659 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000660 ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800661 if (ret_val)
662 goto out;
663 }
664
665out:
666 return ret_val;
667}
668
669/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700670 * igb_copper_link_autoneg - Setup/Enable autoneg for copper link
Auke Kok9d5c8242008-01-24 02:22:38 -0800671 * @hw: pointer to the HW structure
672 *
673 * Performs initial bounds checking on autoneg advertisement parameter, then
674 * configure to advertise the full capability. Setup the PHY to autoneg
675 * and restart the negotiation process between the link partner. If
676 * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
677 **/
Alexander Duyck81fadd82009-10-05 06:35:03 +0000678static s32 igb_copper_link_autoneg(struct e1000_hw *hw)
Auke Kok9d5c8242008-01-24 02:22:38 -0800679{
680 struct e1000_phy_info *phy = &hw->phy;
681 s32 ret_val;
682 u16 phy_ctrl;
683
684 /*
685 * Perform some bounds checking on the autoneg advertisement
686 * parameter.
687 */
688 phy->autoneg_advertised &= phy->autoneg_mask;
689
690 /*
691 * If autoneg_advertised is zero, we assume it was not defaulted
692 * by the calling code so we set to advertise full capability.
693 */
694 if (phy->autoneg_advertised == 0)
695 phy->autoneg_advertised = phy->autoneg_mask;
696
Auke Kok652fff32008-06-27 11:00:18 -0700697 hw_dbg("Reconfiguring auto-neg advertisement params\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800698 ret_val = igb_phy_setup_autoneg(hw);
699 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700700 hw_dbg("Error Setting up Auto-Negotiation\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800701 goto out;
702 }
Auke Kok652fff32008-06-27 11:00:18 -0700703 hw_dbg("Restarting Auto-Neg\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800704
705 /*
706 * Restart auto-negotiation by setting the Auto Neg Enable bit and
707 * the Auto Neg Restart bit in the PHY control register.
708 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000709 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800710 if (ret_val)
711 goto out;
712
713 phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000714 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -0800715 if (ret_val)
716 goto out;
717
718 /*
719 * Does the user want to wait for Auto-Neg to complete here, or
720 * check at a later time (for example, callback routine).
721 */
722 if (phy->autoneg_wait_to_complete) {
723 ret_val = igb_wait_autoneg(hw);
724 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700725 hw_dbg("Error while waiting for "
726 "autoneg to complete\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800727 goto out;
728 }
729 }
730
731 hw->mac.get_link_status = true;
732
733out:
734 return ret_val;
735}
736
737/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700738 * igb_phy_setup_autoneg - Configure PHY for auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -0800739 * @hw: pointer to the HW structure
740 *
741 * Reads the MII auto-neg advertisement register and/or the 1000T control
742 * register and if the PHY is already setup for auto-negotiation, then
743 * return successful. Otherwise, setup advertisement and flow control to
744 * the appropriate values for the wanted auto-negotiation.
745 **/
746static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
747{
748 struct e1000_phy_info *phy = &hw->phy;
749 s32 ret_val;
750 u16 mii_autoneg_adv_reg;
751 u16 mii_1000t_ctrl_reg = 0;
752
753 phy->autoneg_advertised &= phy->autoneg_mask;
754
755 /* Read the MII Auto-Neg Advertisement Register (Address 4). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000756 ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800757 if (ret_val)
758 goto out;
759
760 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
761 /* Read the MII 1000Base-T Control Register (Address 9). */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000762 ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
Auke Kok9d5c8242008-01-24 02:22:38 -0800763 &mii_1000t_ctrl_reg);
764 if (ret_val)
765 goto out;
766 }
767
768 /*
769 * Need to parse both autoneg_advertised and fc and set up
770 * the appropriate PHY registers. First we will parse for
771 * autoneg_advertised software override. Since we can advertise
772 * a plethora of combinations, we need to check each bit
773 * individually.
774 */
775
776 /*
777 * First we clear all the 10/100 mb speed bits in the Auto-Neg
778 * Advertisement Register (Address 4) and the 1000 mb speed bits in
779 * the 1000Base-T Control Register (Address 9).
780 */
781 mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
782 NWAY_AR_100TX_HD_CAPS |
783 NWAY_AR_10T_FD_CAPS |
784 NWAY_AR_10T_HD_CAPS);
785 mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
786
Auke Kok652fff32008-06-27 11:00:18 -0700787 hw_dbg("autoneg_advertised %x\n", phy->autoneg_advertised);
Auke Kok9d5c8242008-01-24 02:22:38 -0800788
789 /* Do we want to advertise 10 Mb Half Duplex? */
790 if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700791 hw_dbg("Advertise 10mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800792 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
793 }
794
795 /* Do we want to advertise 10 Mb Full Duplex? */
796 if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700797 hw_dbg("Advertise 10mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800798 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
799 }
800
801 /* Do we want to advertise 100 Mb Half Duplex? */
802 if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
Auke Kok652fff32008-06-27 11:00:18 -0700803 hw_dbg("Advertise 100mb Half duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800804 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
805 }
806
807 /* Do we want to advertise 100 Mb Full Duplex? */
808 if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700809 hw_dbg("Advertise 100mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800810 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
811 }
812
813 /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
814 if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
Auke Kok652fff32008-06-27 11:00:18 -0700815 hw_dbg("Advertise 1000mb Half duplex request denied!\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800816
817 /* Do we want to advertise 1000 Mb Full Duplex? */
818 if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
Auke Kok652fff32008-06-27 11:00:18 -0700819 hw_dbg("Advertise 1000mb Full duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800820 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
821 }
822
823 /*
824 * Check for a software override of the flow control settings, and
825 * setup the PHY advertisement registers accordingly. If
826 * auto-negotiation is enabled, then software will have to set the
827 * "PAUSE" bits to the correct value in the Auto-Negotiation
828 * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
829 * negotiation.
830 *
831 * The possible values of the "fc" parameter are:
832 * 0: Flow control is completely disabled
833 * 1: Rx flow control is enabled (we can receive pause frames
834 * but not send pause frames).
835 * 2: Tx flow control is enabled (we can send pause frames
836 * but we do not support receiving pause frames).
837 * 3: Both Rx and TX flow control (symmetric) are enabled.
838 * other: No software override. The flow control configuration
839 * in the EEPROM is used.
840 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000841 switch (hw->fc.current_mode) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800842 case e1000_fc_none:
843 /*
844 * Flow control (RX & TX) is completely disabled by a
845 * software over-ride.
846 */
847 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
848 break;
849 case e1000_fc_rx_pause:
850 /*
851 * RX Flow control is enabled, and TX Flow control is
852 * disabled, by a software over-ride.
853 *
854 * Since there really isn't a way to advertise that we are
855 * capable of RX Pause ONLY, we will advertise that we
856 * support both symmetric and asymmetric RX PAUSE. Later
857 * (in e1000_config_fc_after_link_up) we will disable the
858 * hw's ability to send PAUSE frames.
859 */
860 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
861 break;
862 case e1000_fc_tx_pause:
863 /*
864 * TX Flow control is enabled, and RX Flow control is
865 * disabled, by a software over-ride.
866 */
867 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
868 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
869 break;
870 case e1000_fc_full:
871 /*
872 * Flow control (both RX and TX) is enabled by a software
873 * over-ride.
874 */
875 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
876 break;
877 default:
Auke Kok652fff32008-06-27 11:00:18 -0700878 hw_dbg("Flow control param set incorrectly\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800879 ret_val = -E1000_ERR_CONFIG;
880 goto out;
881 }
882
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000883 ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800884 if (ret_val)
885 goto out;
886
Auke Kok652fff32008-06-27 11:00:18 -0700887 hw_dbg("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800888
889 if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000890 ret_val = phy->ops.write_reg(hw,
891 PHY_1000T_CTRL,
892 mii_1000t_ctrl_reg);
Auke Kok9d5c8242008-01-24 02:22:38 -0800893 if (ret_val)
894 goto out;
895 }
896
897out:
898 return ret_val;
899}
900
901/**
Alexander Duyck81fadd82009-10-05 06:35:03 +0000902 * igb_setup_copper_link - Configure copper link settings
903 * @hw: pointer to the HW structure
904 *
905 * Calls the appropriate function to configure the link for auto-neg or forced
906 * speed and duplex. Then we check for link, once link is established calls
907 * to configure collision distance and flow control are called. If link is
908 * not established, we return -E1000_ERR_PHY (-2).
909 **/
910s32 igb_setup_copper_link(struct e1000_hw *hw)
911{
912 s32 ret_val;
913 bool link;
914
915
916 if (hw->mac.autoneg) {
917 /*
918 * Setup autoneg and flow control advertisement and perform
919 * autonegotiation.
920 */
921 ret_val = igb_copper_link_autoneg(hw);
922 if (ret_val)
923 goto out;
924 } else {
925 /*
926 * PHY will be set to 10H, 10F, 100H or 100F
927 * depending on user settings.
928 */
929 hw_dbg("Forcing Speed and Duplex\n");
930 ret_val = hw->phy.ops.force_speed_duplex(hw);
931 if (ret_val) {
932 hw_dbg("Error Forcing Speed and Duplex\n");
933 goto out;
934 }
935 }
936
937 /*
938 * Check link status. Wait up to 100 microseconds for link to become
939 * valid.
940 */
941 ret_val = igb_phy_has_link(hw,
942 COPPER_LINK_UP_LIMIT,
943 10,
944 &link);
945 if (ret_val)
946 goto out;
947
948 if (link) {
949 hw_dbg("Valid link established!!!\n");
950 igb_config_collision_dist(hw);
951 ret_val = igb_config_fc_after_link_up(hw);
952 } else {
953 hw_dbg("Unable to establish link!!!\n");
954 }
955
956out:
957 return ret_val;
958}
959
960/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700961 * igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
Auke Kok9d5c8242008-01-24 02:22:38 -0800962 * @hw: pointer to the HW structure
963 *
964 * Calls the PHY setup function to force speed and duplex. Clears the
965 * auto-crossover to force MDI manually. Waits for link and returns
966 * successful if link up is successful, else -E1000_ERR_PHY (-2).
967 **/
968s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
969{
970 struct e1000_phy_info *phy = &hw->phy;
971 s32 ret_val;
972 u16 phy_data;
973 bool link;
974
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000975 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800976 if (ret_val)
977 goto out;
978
979 igb_phy_force_speed_duplex_setup(hw, &phy_data);
980
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000981 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800982 if (ret_val)
983 goto out;
984
985 /*
986 * Clear Auto-Crossover to force MDI manually. IGP requires MDI
987 * forced whenever speed and duplex are forced.
988 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000989 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800990 if (ret_val)
991 goto out;
992
993 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
994 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
995
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000996 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800997 if (ret_val)
998 goto out;
999
Auke Kok652fff32008-06-27 11:00:18 -07001000 hw_dbg("IGP PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001001
1002 udelay(1);
1003
1004 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001005 hw_dbg("Waiting for forced speed/duplex link on IGP phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001006
1007 ret_val = igb_phy_has_link(hw,
1008 PHY_FORCE_LIMIT,
1009 100000,
1010 &link);
1011 if (ret_val)
1012 goto out;
1013
1014 if (!link)
Auke Kok652fff32008-06-27 11:00:18 -07001015 hw_dbg("Link taking longer than expected.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001016
1017 /* Try once more */
1018 ret_val = igb_phy_has_link(hw,
1019 PHY_FORCE_LIMIT,
1020 100000,
1021 &link);
1022 if (ret_val)
1023 goto out;
1024 }
1025
1026out:
1027 return ret_val;
1028}
1029
1030/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001031 * igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001032 * @hw: pointer to the HW structure
1033 *
1034 * Calls the PHY setup function to force speed and duplex. Clears the
1035 * auto-crossover to force MDI manually. Resets the PHY to commit the
1036 * changes. If time expires while waiting for link up, we reset the DSP.
1037 * After reset, TX_CLK and CRS on TX must be set. Return successful upon
1038 * successful completion, else return corresponding error code.
1039 **/
1040s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1041{
1042 struct e1000_phy_info *phy = &hw->phy;
1043 s32 ret_val;
1044 u16 phy_data;
1045 bool link;
1046
1047 /*
1048 * Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1049 * forced whenever speed and duplex are forced.
1050 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001051 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001052 if (ret_val)
1053 goto out;
1054
1055 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001056 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001057 if (ret_val)
1058 goto out;
1059
Auke Kok652fff32008-06-27 11:00:18 -07001060 hw_dbg("M88E1000 PSCR: %X\n", phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001061
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001062 ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001063 if (ret_val)
1064 goto out;
1065
1066 igb_phy_force_speed_duplex_setup(hw, &phy_data);
1067
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001068 ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001069 if (ret_val)
1070 goto out;
1071
Alexander Duyck2553bb22009-10-05 06:35:42 +00001072 /* Reset the phy to commit changes. */
1073 ret_val = igb_phy_sw_reset(hw);
1074 if (ret_val)
1075 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -08001076
1077 if (phy->autoneg_wait_to_complete) {
Auke Kok652fff32008-06-27 11:00:18 -07001078 hw_dbg("Waiting for forced speed/duplex link on M88 phy.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001079
Alexander Duyck2553bb22009-10-05 06:35:42 +00001080 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT, 100000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001081 if (ret_val)
1082 goto out;
1083
1084 if (!link) {
1085 /*
1086 * We didn't get link.
1087 * Reset the DSP and cross our fingers.
1088 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001089 ret_val = phy->ops.write_reg(hw,
Alexander Duyck2553bb22009-10-05 06:35:42 +00001090 M88E1000_PHY_PAGE_SELECT,
1091 0x001d);
Auke Kok9d5c8242008-01-24 02:22:38 -08001092 if (ret_val)
1093 goto out;
1094 ret_val = igb_phy_reset_dsp(hw);
1095 if (ret_val)
1096 goto out;
1097 }
1098
1099 /* Try once more */
1100 ret_val = igb_phy_has_link(hw, PHY_FORCE_LIMIT,
Alexander Duyck2553bb22009-10-05 06:35:42 +00001101 100000, &link);
Auke Kok9d5c8242008-01-24 02:22:38 -08001102 if (ret_val)
1103 goto out;
1104 }
1105
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001106 ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001107 if (ret_val)
1108 goto out;
1109
1110 /*
1111 * Resetting the phy means we need to re-force TX_CLK in the
1112 * Extended PHY Specific Control Register to 25MHz clock from
1113 * the reset value of 2.5MHz.
1114 */
1115 phy_data |= M88E1000_EPSCR_TX_CLK_25;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001116 ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001117 if (ret_val)
1118 goto out;
1119
1120 /*
1121 * In addition, we must re-enable CRS on Tx for both half and full
1122 * duplex.
1123 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001124 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001125 if (ret_val)
1126 goto out;
1127
1128 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001129 ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001130
1131out:
1132 return ret_val;
1133}
1134
1135/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001136 * igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001137 * @hw: pointer to the HW structure
1138 * @phy_ctrl: pointer to current value of PHY_CONTROL
1139 *
1140 * Forces speed and duplex on the PHY by doing the following: disable flow
1141 * control, force speed/duplex on the MAC, disable auto speed detection,
1142 * disable auto-negotiation, configure duplex, configure speed, configure
1143 * the collision distance, write configuration to CTRL register. The
1144 * caller must write to the PHY_CONTROL register for these settings to
1145 * take affect.
1146 **/
1147static void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw,
1148 u16 *phy_ctrl)
1149{
1150 struct e1000_mac_info *mac = &hw->mac;
1151 u32 ctrl;
1152
1153 /* Turn off flow control when forcing speed/duplex */
Alexander Duyck0cce1192009-07-23 18:10:24 +00001154 hw->fc.current_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -08001155
1156 /* Force speed/duplex on the mac */
1157 ctrl = rd32(E1000_CTRL);
1158 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1159 ctrl &= ~E1000_CTRL_SPD_SEL;
1160
1161 /* Disable Auto Speed Detection */
1162 ctrl &= ~E1000_CTRL_ASDE;
1163
1164 /* Disable autoneg on the phy */
1165 *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1166
1167 /* Forcing Full or Half Duplex? */
1168 if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1169 ctrl &= ~E1000_CTRL_FD;
1170 *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001171 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001172 } else {
1173 ctrl |= E1000_CTRL_FD;
1174 *phy_ctrl |= MII_CR_FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001175 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001176 }
1177
1178 /* Forcing 10mb or 100mb? */
1179 if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1180 ctrl |= E1000_CTRL_SPD_100;
1181 *phy_ctrl |= MII_CR_SPEED_100;
1182 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
Auke Kok652fff32008-06-27 11:00:18 -07001183 hw_dbg("Forcing 100mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001184 } else {
1185 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1186 *phy_ctrl |= MII_CR_SPEED_10;
1187 *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
Auke Kok652fff32008-06-27 11:00:18 -07001188 hw_dbg("Forcing 10mb\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001189 }
1190
1191 igb_config_collision_dist(hw);
1192
1193 wr32(E1000_CTRL, ctrl);
1194}
1195
1196/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001197 * igb_set_d3_lplu_state - Sets low power link up state for D3
Auke Kok9d5c8242008-01-24 02:22:38 -08001198 * @hw: pointer to the HW structure
1199 * @active: boolean used to enable/disable lplu
1200 *
1201 * Success returns 0, Failure returns 1
1202 *
1203 * The low power link up (lplu) state is set to the power management level D3
1204 * and SmartSpeed is disabled when active is true, else clear lplu for D3
1205 * and enable Smartspeed. LPLU and Smartspeed are mutually exclusive. LPLU
1206 * is used during Dx states where the power conservation is most important.
1207 * During driver activity, SmartSpeed should be enabled so performance is
1208 * maintained.
1209 **/
1210s32 igb_set_d3_lplu_state(struct e1000_hw *hw, bool active)
1211{
1212 struct e1000_phy_info *phy = &hw->phy;
Alexander Duyck2553bb22009-10-05 06:35:42 +00001213 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001214 u16 data;
1215
Alexander Duyck2553bb22009-10-05 06:35:42 +00001216 if (!(hw->phy.ops.read_reg))
1217 goto out;
1218
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001219 ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001220 if (ret_val)
1221 goto out;
1222
1223 if (!active) {
1224 data &= ~IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001225 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001226 data);
1227 if (ret_val)
1228 goto out;
1229 /*
1230 * LPLU and SmartSpeed are mutually exclusive. LPLU is used
1231 * during Dx states where the power conservation is most
1232 * important. During driver activity we should enable
1233 * SmartSpeed, so performance is maintained.
1234 */
1235 if (phy->smart_speed == e1000_smart_speed_on) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001236 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001237 IGP01E1000_PHY_PORT_CONFIG,
1238 &data);
1239 if (ret_val)
1240 goto out;
1241
1242 data |= IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001243 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001244 IGP01E1000_PHY_PORT_CONFIG,
1245 data);
1246 if (ret_val)
1247 goto out;
1248 } else if (phy->smart_speed == e1000_smart_speed_off) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001249 ret_val = phy->ops.read_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001250 IGP01E1000_PHY_PORT_CONFIG,
1251 &data);
1252 if (ret_val)
1253 goto out;
1254
1255 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001256 ret_val = phy->ops.write_reg(hw,
Auke Kok9d5c8242008-01-24 02:22:38 -08001257 IGP01E1000_PHY_PORT_CONFIG,
1258 data);
1259 if (ret_val)
1260 goto out;
1261 }
1262 } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1263 (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1264 (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1265 data |= IGP02E1000_PM_D3_LPLU;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001266 ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
Auke Kok9d5c8242008-01-24 02:22:38 -08001267 data);
1268 if (ret_val)
1269 goto out;
1270
1271 /* When LPLU is enabled, we should disable SmartSpeed */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001272 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001273 &data);
1274 if (ret_val)
1275 goto out;
1276
1277 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001278 ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
Auke Kok9d5c8242008-01-24 02:22:38 -08001279 data);
1280 }
1281
1282out:
1283 return ret_val;
1284}
1285
1286/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001287 * igb_check_downshift - Checks whether a downshift in speed occured
Auke Kok9d5c8242008-01-24 02:22:38 -08001288 * @hw: pointer to the HW structure
1289 *
1290 * Success returns 0, Failure returns 1
1291 *
1292 * A downshift is detected by querying the PHY link health.
1293 **/
1294s32 igb_check_downshift(struct e1000_hw *hw)
1295{
1296 struct e1000_phy_info *phy = &hw->phy;
1297 s32 ret_val;
1298 u16 phy_data, offset, mask;
1299
1300 switch (phy->type) {
1301 case e1000_phy_m88:
1302 case e1000_phy_gg82563:
1303 offset = M88E1000_PHY_SPEC_STATUS;
1304 mask = M88E1000_PSSR_DOWNSHIFT;
1305 break;
1306 case e1000_phy_igp_2:
1307 case e1000_phy_igp:
1308 case e1000_phy_igp_3:
1309 offset = IGP01E1000_PHY_LINK_HEALTH;
1310 mask = IGP01E1000_PLHR_SS_DOWNGRADE;
1311 break;
1312 default:
1313 /* speed downshift not supported */
1314 phy->speed_downgraded = false;
1315 ret_val = 0;
1316 goto out;
1317 }
1318
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001319 ret_val = phy->ops.read_reg(hw, offset, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001320
1321 if (!ret_val)
1322 phy->speed_downgraded = (phy_data & mask) ? true : false;
1323
1324out:
1325 return ret_val;
1326}
1327
1328/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001329 * igb_check_polarity_m88 - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001330 * @hw: pointer to the HW structure
1331 *
1332 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1333 *
1334 * Polarity is determined based on the PHY specific status register.
1335 **/
1336static s32 igb_check_polarity_m88(struct e1000_hw *hw)
1337{
1338 struct e1000_phy_info *phy = &hw->phy;
1339 s32 ret_val;
1340 u16 data;
1341
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001342 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001343
1344 if (!ret_val)
1345 phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1346 ? e1000_rev_polarity_reversed
1347 : e1000_rev_polarity_normal;
1348
1349 return ret_val;
1350}
1351
1352/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001353 * igb_check_polarity_igp - Checks the polarity.
Auke Kok9d5c8242008-01-24 02:22:38 -08001354 * @hw: pointer to the HW structure
1355 *
1356 * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1357 *
1358 * Polarity is determined based on the PHY port status register, and the
1359 * current speed (since there is no polarity at 100Mbps).
1360 **/
1361static s32 igb_check_polarity_igp(struct e1000_hw *hw)
1362{
1363 struct e1000_phy_info *phy = &hw->phy;
1364 s32 ret_val;
1365 u16 data, offset, mask;
1366
1367 /*
1368 * Polarity is determined based on the speed of
1369 * our connection.
1370 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001371 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001372 if (ret_val)
1373 goto out;
1374
1375 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1376 IGP01E1000_PSSR_SPEED_1000MBPS) {
1377 offset = IGP01E1000_PHY_PCS_INIT_REG;
1378 mask = IGP01E1000_PHY_POLARITY_MASK;
1379 } else {
1380 /*
1381 * This really only applies to 10Mbps since
1382 * there is no polarity for 100Mbps (always 0).
1383 */
1384 offset = IGP01E1000_PHY_PORT_STATUS;
1385 mask = IGP01E1000_PSSR_POLARITY_REVERSED;
1386 }
1387
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001388 ret_val = phy->ops.read_reg(hw, offset, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001389
1390 if (!ret_val)
1391 phy->cable_polarity = (data & mask)
1392 ? e1000_rev_polarity_reversed
1393 : e1000_rev_polarity_normal;
1394
1395out:
1396 return ret_val;
1397}
1398
1399/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001400 * igb_wait_autoneg - Wait for auto-neg compeletion
Auke Kok9d5c8242008-01-24 02:22:38 -08001401 * @hw: pointer to the HW structure
1402 *
1403 * Waits for auto-negotiation to complete or for the auto-negotiation time
1404 * limit to expire, which ever happens first.
1405 **/
1406static s32 igb_wait_autoneg(struct e1000_hw *hw)
1407{
1408 s32 ret_val = 0;
1409 u16 i, phy_status;
1410
1411 /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1412 for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001413 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001414 if (ret_val)
1415 break;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001416 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001417 if (ret_val)
1418 break;
1419 if (phy_status & MII_SR_AUTONEG_COMPLETE)
1420 break;
1421 msleep(100);
1422 }
1423
1424 /*
1425 * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1426 * has completed.
1427 */
1428 return ret_val;
1429}
1430
1431/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001432 * igb_phy_has_link - Polls PHY for link
Auke Kok9d5c8242008-01-24 02:22:38 -08001433 * @hw: pointer to the HW structure
1434 * @iterations: number of times to poll for link
1435 * @usec_interval: delay between polling attempts
1436 * @success: pointer to whether polling was successful or not
1437 *
1438 * Polls the PHY status register for link, 'iterations' number of times.
1439 **/
1440s32 igb_phy_has_link(struct e1000_hw *hw, u32 iterations,
1441 u32 usec_interval, bool *success)
1442{
1443 s32 ret_val = 0;
1444 u16 i, phy_status;
1445
1446 for (i = 0; i < iterations; i++) {
1447 /*
1448 * Some PHYs require the PHY_STATUS register to be read
1449 * twice due to the link bit being sticky. No harm doing
1450 * it across the board.
1451 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001452 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Alexander Duyckab576382009-10-05 06:35:23 +00001453 if (ret_val) {
1454 /*
1455 * If the first read fails, another entity may have
1456 * ownership of the resources, wait and try again to
1457 * see if they have relinquished the resources yet.
1458 */
1459 udelay(usec_interval);
1460 }
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001461 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
Auke Kok9d5c8242008-01-24 02:22:38 -08001462 if (ret_val)
1463 break;
1464 if (phy_status & MII_SR_LINK_STATUS)
1465 break;
1466 if (usec_interval >= 1000)
1467 mdelay(usec_interval/1000);
1468 else
1469 udelay(usec_interval);
1470 }
1471
1472 *success = (i < iterations) ? true : false;
1473
1474 return ret_val;
1475}
1476
1477/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001478 * igb_get_cable_length_m88 - Determine cable length for m88 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001479 * @hw: pointer to the HW structure
1480 *
1481 * Reads the PHY specific status register to retrieve the cable length
1482 * information. The cable length is determined by averaging the minimum and
1483 * maximum values to get the "average" cable length. The m88 PHY has four
1484 * possible cable length values, which are:
1485 * Register Value Cable Length
1486 * 0 < 50 meters
1487 * 1 50 - 80 meters
1488 * 2 80 - 110 meters
1489 * 3 110 - 140 meters
1490 * 4 > 140 meters
1491 **/
1492s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1493{
1494 struct e1000_phy_info *phy = &hw->phy;
1495 s32 ret_val;
1496 u16 phy_data, index;
1497
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001498 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001499 if (ret_val)
1500 goto out;
1501
1502 index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1503 M88E1000_PSSR_CABLE_LENGTH_SHIFT;
Alexander Duyck2553bb22009-10-05 06:35:42 +00001504 if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1505 ret_val = -E1000_ERR_PHY;
1506 goto out;
1507 }
1508
Auke Kok9d5c8242008-01-24 02:22:38 -08001509 phy->min_cable_length = e1000_m88_cable_length_table[index];
Alexander Duyck2553bb22009-10-05 06:35:42 +00001510 phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
Auke Kok9d5c8242008-01-24 02:22:38 -08001511
1512 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1513
1514out:
1515 return ret_val;
1516}
1517
1518/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001519 * igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001520 * @hw: pointer to the HW structure
1521 *
1522 * The automatic gain control (agc) normalizes the amplitude of the
1523 * received signal, adjusting for the attenuation produced by the
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001524 * cable. By reading the AGC registers, which represent the
1525 * combination of coarse and fine gain value, the value can be put
Auke Kok9d5c8242008-01-24 02:22:38 -08001526 * into a lookup table to obtain the approximate cable length
1527 * for each channel.
1528 **/
1529s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1530{
1531 struct e1000_phy_info *phy = &hw->phy;
1532 s32 ret_val = 0;
1533 u16 phy_data, i, agc_value = 0;
1534 u16 cur_agc_index, max_agc_index = 0;
1535 u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1536 u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1537 {IGP02E1000_PHY_AGC_A,
1538 IGP02E1000_PHY_AGC_B,
1539 IGP02E1000_PHY_AGC_C,
1540 IGP02E1000_PHY_AGC_D};
1541
1542 /* Read the AGC registers for all channels */
1543 for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001544 ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001545 if (ret_val)
1546 goto out;
1547
1548 /*
1549 * Getting bits 15:9, which represent the combination of
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001550 * coarse and fine gain values. The result is a number
Auke Kok9d5c8242008-01-24 02:22:38 -08001551 * that can be put into the lookup table to obtain the
1552 * approximate cable length.
1553 */
1554 cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1555 IGP02E1000_AGC_LENGTH_MASK;
1556
1557 /* Array index bound check. */
1558 if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1559 (cur_agc_index == 0)) {
1560 ret_val = -E1000_ERR_PHY;
1561 goto out;
1562 }
1563
1564 /* Remove min & max AGC values from calculation. */
1565 if (e1000_igp_2_cable_length_table[min_agc_index] >
1566 e1000_igp_2_cable_length_table[cur_agc_index])
1567 min_agc_index = cur_agc_index;
1568 if (e1000_igp_2_cable_length_table[max_agc_index] <
1569 e1000_igp_2_cable_length_table[cur_agc_index])
1570 max_agc_index = cur_agc_index;
1571
1572 agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
1573 }
1574
1575 agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
1576 e1000_igp_2_cable_length_table[max_agc_index]);
1577 agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
1578
1579 /* Calculate cable length with the error range of +/- 10 meters. */
1580 phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
1581 (agc_value - IGP02E1000_AGC_RANGE) : 0;
1582 phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
1583
1584 phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1585
1586out:
1587 return ret_val;
1588}
1589
1590/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001591 * igb_get_phy_info_m88 - Retrieve PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001592 * @hw: pointer to the HW structure
1593 *
1594 * Valid for only copper links. Read the PHY status register (sticky read)
1595 * to verify that link is up. Read the PHY special control register to
1596 * determine the polarity and 10base-T extended distance. Read the PHY
1597 * special status register to determine MDI/MDIx and current speed. If
1598 * speed is 1000, then determine cable length, local and remote receiver.
1599 **/
1600s32 igb_get_phy_info_m88(struct e1000_hw *hw)
1601{
1602 struct e1000_phy_info *phy = &hw->phy;
1603 s32 ret_val;
1604 u16 phy_data;
1605 bool link;
1606
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001607 if (phy->media_type != e1000_media_type_copper) {
Auke Kok652fff32008-06-27 11:00:18 -07001608 hw_dbg("Phy info is only valid for copper media\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001609 ret_val = -E1000_ERR_CONFIG;
1610 goto out;
1611 }
1612
1613 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1614 if (ret_val)
1615 goto out;
1616
1617 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001618 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001619 ret_val = -E1000_ERR_CONFIG;
1620 goto out;
1621 }
1622
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001623 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001624 if (ret_val)
1625 goto out;
1626
1627 phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001628 ? true : false;
Auke Kok9d5c8242008-01-24 02:22:38 -08001629
1630 ret_val = igb_check_polarity_m88(hw);
1631 if (ret_val)
1632 goto out;
1633
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001634 ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001635 if (ret_val)
1636 goto out;
1637
1638 phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
1639
1640 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001641 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001642 if (ret_val)
1643 goto out;
1644
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001645 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001646 if (ret_val)
1647 goto out;
1648
1649 phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
1650 ? e1000_1000t_rx_status_ok
1651 : e1000_1000t_rx_status_not_ok;
1652
1653 phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
1654 ? e1000_1000t_rx_status_ok
1655 : e1000_1000t_rx_status_not_ok;
1656 } else {
1657 /* Set values to "undefined" */
1658 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1659 phy->local_rx = e1000_1000t_rx_status_undefined;
1660 phy->remote_rx = e1000_1000t_rx_status_undefined;
1661 }
1662
1663out:
1664 return ret_val;
1665}
1666
1667/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001668 * igb_get_phy_info_igp - Retrieve igp PHY information
Auke Kok9d5c8242008-01-24 02:22:38 -08001669 * @hw: pointer to the HW structure
1670 *
1671 * Read PHY status to determine if link is up. If link is up, then
1672 * set/determine 10base-T extended distance and polarity correction. Read
1673 * PHY port status to determine MDI/MDIx and speed. Based on the speed,
1674 * determine on the cable length, local and remote receiver.
1675 **/
1676s32 igb_get_phy_info_igp(struct e1000_hw *hw)
1677{
1678 struct e1000_phy_info *phy = &hw->phy;
1679 s32 ret_val;
1680 u16 data;
1681 bool link;
1682
1683 ret_val = igb_phy_has_link(hw, 1, 0, &link);
1684 if (ret_val)
1685 goto out;
1686
1687 if (!link) {
Auke Kok652fff32008-06-27 11:00:18 -07001688 hw_dbg("Phy info is only valid if link is up\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001689 ret_val = -E1000_ERR_CONFIG;
1690 goto out;
1691 }
1692
1693 phy->polarity_correction = true;
1694
1695 ret_val = igb_check_polarity_igp(hw);
1696 if (ret_val)
1697 goto out;
1698
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001699 ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001700 if (ret_val)
1701 goto out;
1702
1703 phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
1704
1705 if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1706 IGP01E1000_PSSR_SPEED_1000MBPS) {
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001707 ret_val = phy->ops.get_cable_length(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001708 if (ret_val)
1709 goto out;
1710
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001711 ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001712 if (ret_val)
1713 goto out;
1714
1715 phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
1716 ? e1000_1000t_rx_status_ok
1717 : e1000_1000t_rx_status_not_ok;
1718
1719 phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
1720 ? e1000_1000t_rx_status_ok
1721 : e1000_1000t_rx_status_not_ok;
1722 } else {
1723 phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
1724 phy->local_rx = e1000_1000t_rx_status_undefined;
1725 phy->remote_rx = e1000_1000t_rx_status_undefined;
1726 }
1727
1728out:
1729 return ret_val;
1730}
1731
1732/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001733 * igb_phy_sw_reset - PHY software reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001734 * @hw: pointer to the HW structure
1735 *
1736 * Does a software reset of the PHY by reading the PHY control register and
1737 * setting/write the control register reset bit to the PHY.
1738 **/
1739s32 igb_phy_sw_reset(struct e1000_hw *hw)
1740{
Alexander Duyckd3147372009-09-14 08:23:13 +00001741 s32 ret_val = 0;
Auke Kok9d5c8242008-01-24 02:22:38 -08001742 u16 phy_ctrl;
1743
Alexander Duyckd3147372009-09-14 08:23:13 +00001744 if (!(hw->phy.ops.read_reg))
1745 goto out;
1746
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001747 ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001748 if (ret_val)
1749 goto out;
1750
1751 phy_ctrl |= MII_CR_RESET;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001752 ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
Auke Kok9d5c8242008-01-24 02:22:38 -08001753 if (ret_val)
1754 goto out;
1755
1756 udelay(1);
1757
1758out:
1759 return ret_val;
1760}
1761
1762/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001763 * igb_phy_hw_reset - PHY hardware reset
Auke Kok9d5c8242008-01-24 02:22:38 -08001764 * @hw: pointer to the HW structure
1765 *
1766 * Verify the reset block is not blocking us from resetting. Acquire
1767 * semaphore (if necessary) and read/set/write the device control reset
1768 * bit in the PHY. Wait the appropriate delay time for the device to
1769 * reset and relase the semaphore (if necessary).
1770 **/
1771s32 igb_phy_hw_reset(struct e1000_hw *hw)
1772{
1773 struct e1000_phy_info *phy = &hw->phy;
1774 s32 ret_val;
1775 u32 ctrl;
1776
1777 ret_val = igb_check_reset_block(hw);
1778 if (ret_val) {
1779 ret_val = 0;
1780 goto out;
1781 }
1782
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001783 ret_val = phy->ops.acquire(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001784 if (ret_val)
1785 goto out;
1786
1787 ctrl = rd32(E1000_CTRL);
1788 wr32(E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
1789 wrfl();
1790
1791 udelay(phy->reset_delay_us);
1792
1793 wr32(E1000_CTRL, ctrl);
1794 wrfl();
1795
1796 udelay(150);
1797
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001798 phy->ops.release(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001799
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001800 ret_val = phy->ops.get_cfg_done(hw);
Auke Kok9d5c8242008-01-24 02:22:38 -08001801
1802out:
1803 return ret_val;
1804}
1805
Auke Kok9d5c8242008-01-24 02:22:38 -08001806/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001807 * igb_phy_init_script_igp3 - Inits the IGP3 PHY
Auke Kok9d5c8242008-01-24 02:22:38 -08001808 * @hw: pointer to the HW structure
1809 *
1810 * Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
1811 **/
1812s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
1813{
Auke Kok652fff32008-06-27 11:00:18 -07001814 hw_dbg("Running IGP 3 PHY init script\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001815
1816 /* PHY init IGP 3 */
1817 /* Enable rise/fall, 10-mode work in class-A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001818 hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
Auke Kok9d5c8242008-01-24 02:22:38 -08001819 /* Remove all caps from Replica path filter */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001820 hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001821 /* Bias trimming for ADC, AFE and Driver (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001822 hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
Auke Kok9d5c8242008-01-24 02:22:38 -08001823 /* Increase Hybrid poly bias */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001824 hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001825 /* Add 4% to TX amplitude in Giga mode */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001826 hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001827 /* Disable trimming (TTT) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001828 hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001829 /* Poly DC correction to 94.6% + 2% for all channels */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001830 hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001831 /* ABS DC correction to 95.9% */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001832 hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
Auke Kok9d5c8242008-01-24 02:22:38 -08001833 /* BG temp curve trim */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001834 hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
Auke Kok9d5c8242008-01-24 02:22:38 -08001835 /* Increasing ADC OPAMP stage 1 currents to max */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001836 hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
Auke Kok9d5c8242008-01-24 02:22:38 -08001837 /* Force 1000 ( required for enabling PHY regs configuration) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001838 hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
Auke Kok9d5c8242008-01-24 02:22:38 -08001839 /* Set upd_freq to 6 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001840 hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
Auke Kok9d5c8242008-01-24 02:22:38 -08001841 /* Disable NPDFE */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001842 hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
Auke Kok9d5c8242008-01-24 02:22:38 -08001843 /* Disable adaptive fixed FFE (Default) */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001844 hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001845 /* Enable FFE hysteresis */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001846 hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
Auke Kok9d5c8242008-01-24 02:22:38 -08001847 /* Fixed FFE for short cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001848 hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
Auke Kok9d5c8242008-01-24 02:22:38 -08001849 /* Fixed FFE for medium cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001850 hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001851 /* Fixed FFE for long cable lengths */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001852 hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
Auke Kok9d5c8242008-01-24 02:22:38 -08001853 /* Enable Adaptive Clip Threshold */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001854 hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
Auke Kok9d5c8242008-01-24 02:22:38 -08001855 /* AHT reset limit to 1 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001856 hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
Auke Kok9d5c8242008-01-24 02:22:38 -08001857 /* Set AHT master delay to 127 msec */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001858 hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
Auke Kok9d5c8242008-01-24 02:22:38 -08001859 /* Set scan bits for AHT */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001860 hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
Auke Kok9d5c8242008-01-24 02:22:38 -08001861 /* Set AHT Preset bits */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001862 hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
Auke Kok9d5c8242008-01-24 02:22:38 -08001863 /* Change integ_factor of channel A to 3 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001864 hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
Auke Kok9d5c8242008-01-24 02:22:38 -08001865 /* Change prop_factor of channels BCD to 8 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001866 hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
Auke Kok9d5c8242008-01-24 02:22:38 -08001867 /* Change cg_icount + enable integbp for channels BCD */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001868 hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
Auke Kok9d5c8242008-01-24 02:22:38 -08001869 /*
1870 * Change cg_icount + enable integbp + change prop_factor_master
1871 * to 8 for channel A
1872 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001873 hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
Auke Kok9d5c8242008-01-24 02:22:38 -08001874 /* Disable AHT in Slave mode on channel A */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001875 hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
Auke Kok9d5c8242008-01-24 02:22:38 -08001876 /*
1877 * Enable LPLU and disable AN to 1000 in non-D0a states,
1878 * Enable SPD+B2B
1879 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001880 hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
Auke Kok9d5c8242008-01-24 02:22:38 -08001881 /* Enable restart AN on an1000_dis change */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001882 hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
Auke Kok9d5c8242008-01-24 02:22:38 -08001883 /* Enable wh_fifo read clock in 10/100 modes */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001884 hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
Auke Kok9d5c8242008-01-24 02:22:38 -08001885 /* Restart AN, Speed selection is 1000 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +00001886 hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
Auke Kok9d5c8242008-01-24 02:22:38 -08001887
1888 return 0;
1889}
1890