~ubuntu-branches/ubuntu/raring/ipxe/raring

« back to all changes in this revision

Viewing changes to src/drivers/net/igb/igb_phy.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-11-14 15:47:31 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20121114154731-jhuy5d1h2jw75qe9
Tags: 1.0.0+git-4.d6b0b76-0ubuntu1
* New upstream snapshot:
  - d/p/iscsi*.patch: Dropped - included in snapshot.
  - Refreshed all other patches.
* d/p/enable-https.patch: Enable HTTPS support (LP: #1025239).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 
3
 
  Intel(R) Gigabit Ethernet Linux driver
4
 
  Copyright(c) 2007-2009 Intel Corporation.
5
 
 
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
 
FILE_LICENCE ( GPL2_ONLY );
29
 
 
30
 
#include "igb.h"
31
 
 
32
 
static s32 igb_phy_setup_autoneg(struct e1000_hw *hw);
33
 
 
34
 
#if 0
35
 
/* Cable length tables */
36
 
static const u16 e1000_m88_cable_length_table[] =
37
 
        { 0, 50, 80, 110, 140, 140, E1000_CABLE_LENGTH_UNDEFINED };
38
 
#define M88E1000_CABLE_LENGTH_TABLE_SIZE \
39
 
                (sizeof(e1000_m88_cable_length_table) / \
40
 
                 sizeof(e1000_m88_cable_length_table[0]))
41
 
 
42
 
static const u16 e1000_igp_2_cable_length_table[] =
43
 
    { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
44
 
      0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
45
 
      6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
46
 
      21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
47
 
      40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
48
 
      60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
49
 
      83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
50
 
      104, 109, 114, 118, 121, 124};
51
 
#define IGP02E1000_CABLE_LENGTH_TABLE_SIZE \
52
 
                (sizeof(e1000_igp_2_cable_length_table) / \
53
 
                 sizeof(e1000_igp_2_cable_length_table[0]))
54
 
#endif
55
 
 
56
 
/**
57
 
 *  igb_check_reset_block_generic - Check if PHY reset is blocked
58
 
 *  @hw: pointer to the HW structure
59
 
 *
60
 
 *  Read the PHY management control register and check whether a PHY reset
61
 
 *  is blocked.  If a reset is not blocked return E1000_SUCCESS, otherwise
62
 
 *  return E1000_BLK_PHY_RESET (12).
63
 
 **/
64
 
s32 igb_check_reset_block_generic(struct e1000_hw *hw)
65
 
{
66
 
        u32 manc;
67
 
 
68
 
        DEBUGFUNC("igb_check_reset_block");
69
 
 
70
 
        manc = E1000_READ_REG(hw, E1000_MANC);
71
 
 
72
 
        return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
73
 
               E1000_BLK_PHY_RESET : E1000_SUCCESS;
74
 
}
75
 
 
76
 
/**
77
 
 *  igb_get_phy_id - Retrieve the PHY ID and revision
78
 
 *  @hw: pointer to the HW structure
79
 
 *
80
 
 *  Reads the PHY registers and stores the PHY ID and possibly the PHY
81
 
 *  revision in the hardware structure.
82
 
 **/
83
 
s32 igb_get_phy_id(struct e1000_hw *hw)
84
 
{
85
 
        struct e1000_phy_info *phy = &hw->phy;
86
 
        s32 ret_val = E1000_SUCCESS;
87
 
        u16 phy_id;
88
 
 
89
 
        DEBUGFUNC("igb_get_phy_id");
90
 
 
91
 
        if (!(phy->ops.read_reg))
92
 
                goto out;
93
 
 
94
 
                ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
95
 
                if (ret_val)
96
 
                        goto out;
97
 
 
98
 
                phy->id = (u32)(phy_id << 16);
99
 
                usec_delay(20);
100
 
                ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
101
 
                if (ret_val)
102
 
                        goto out;
103
 
 
104
 
                phy->id |= (u32)(phy_id & PHY_REVISION_MASK);
105
 
                phy->revision = (u32)(phy_id & ~PHY_REVISION_MASK);
106
 
 
107
 
out:
108
 
        return ret_val;
109
 
}
110
 
 
111
 
/**
112
 
 *  igb_phy_reset_dsp_generic - Reset PHY DSP
113
 
 *  @hw: pointer to the HW structure
114
 
 *
115
 
 *  Reset the digital signal processor.
116
 
 **/
117
 
s32 igb_phy_reset_dsp_generic(struct e1000_hw *hw)
118
 
{
119
 
        s32 ret_val = E1000_SUCCESS;
120
 
 
121
 
        DEBUGFUNC("igb_phy_reset_dsp_generic");
122
 
 
123
 
        if (!(hw->phy.ops.write_reg))
124
 
                goto out;
125
 
 
126
 
        ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xC1);
127
 
        if (ret_val)
128
 
                goto out;
129
 
 
130
 
        ret_val = hw->phy.ops.write_reg(hw, M88E1000_PHY_GEN_CONTROL, 0);
131
 
 
132
 
out:
133
 
        return ret_val;
134
 
}
135
 
 
136
 
/**
137
 
 *  igb_read_phy_reg_mdic - Read MDI control register
138
 
 *  @hw: pointer to the HW structure
139
 
 *  @offset: register offset to be read
140
 
 *  @data: pointer to the read data
141
 
 *
142
 
 *  Reads the MDI control register in the PHY at offset and stores the
143
 
 *  information read to data.
144
 
 **/
145
 
s32 igb_read_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 *data)
146
 
{
147
 
        struct e1000_phy_info *phy = &hw->phy;
148
 
        u32 i, mdic = 0;
149
 
        s32 ret_val = E1000_SUCCESS;
150
 
 
151
 
        DEBUGFUNC("igb_read_phy_reg_mdic");
152
 
 
153
 
        /*
154
 
         * Set up Op-code, Phy Address, and register offset in the MDI
155
 
         * Control register.  The MAC will take care of interfacing with the
156
 
         * PHY to retrieve the desired data.
157
 
         */
158
 
        mdic = ((offset << E1000_MDIC_REG_SHIFT) |
159
 
                (phy->addr << E1000_MDIC_PHY_SHIFT) |
160
 
                (E1000_MDIC_OP_READ));
161
 
 
162
 
        E1000_WRITE_REG(hw, E1000_MDIC, mdic);
163
 
 
164
 
        /*
165
 
         * Poll the ready bit to see if the MDI read completed
166
 
         * Increasing the time out as testing showed failures with
167
 
         * the lower time out
168
 
         */
169
 
        for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
170
 
                usec_delay(50);
171
 
                mdic = E1000_READ_REG(hw, E1000_MDIC);
172
 
                if (mdic & E1000_MDIC_READY)
173
 
                        break;
174
 
        }
175
 
        if (!(mdic & E1000_MDIC_READY)) {
176
 
                DEBUGOUT("MDI Read did not complete\n");
177
 
                ret_val = -E1000_ERR_PHY;
178
 
                goto out;
179
 
        }
180
 
        if (mdic & E1000_MDIC_ERROR) {
181
 
                DEBUGOUT("MDI Error\n");
182
 
                ret_val = -E1000_ERR_PHY;
183
 
                goto out;
184
 
        }
185
 
        *data = (u16) mdic;
186
 
 
187
 
out:
188
 
        return ret_val;
189
 
}
190
 
 
191
 
/**
192
 
 *  igb_write_phy_reg_mdic - Write MDI control register
193
 
 *  @hw: pointer to the HW structure
194
 
 *  @offset: register offset to write to
195
 
 *  @data: data to write to register at offset
196
 
 *
197
 
 *  Writes data to MDI control register in the PHY at offset.
198
 
 **/
199
 
s32 igb_write_phy_reg_mdic(struct e1000_hw *hw, u32 offset, u16 data)
200
 
{
201
 
        struct e1000_phy_info *phy = &hw->phy;
202
 
        u32 i, mdic = 0;
203
 
        s32 ret_val = E1000_SUCCESS;
204
 
 
205
 
        DEBUGFUNC("igb_write_phy_reg_mdic");
206
 
 
207
 
        /*
208
 
         * Set up Op-code, Phy Address, and register offset in the MDI
209
 
         * Control register.  The MAC will take care of interfacing with the
210
 
         * PHY to retrieve the desired data.
211
 
         */
212
 
        mdic = (((u32)data) |
213
 
                (offset << E1000_MDIC_REG_SHIFT) |
214
 
                (phy->addr << E1000_MDIC_PHY_SHIFT) |
215
 
                (E1000_MDIC_OP_WRITE));
216
 
 
217
 
        E1000_WRITE_REG(hw, E1000_MDIC, mdic);
218
 
 
219
 
        /*
220
 
         * Poll the ready bit to see if the MDI read completed
221
 
         * Increasing the time out as testing showed failures with
222
 
         * the lower time out
223
 
         */
224
 
        for (i = 0; i < (E1000_GEN_POLL_TIMEOUT * 3); i++) {
225
 
                usec_delay(50);
226
 
                mdic = E1000_READ_REG(hw, E1000_MDIC);
227
 
                if (mdic & E1000_MDIC_READY)
228
 
                        break;
229
 
        }
230
 
        if (!(mdic & E1000_MDIC_READY)) {
231
 
                DEBUGOUT("MDI Write did not complete\n");
232
 
                ret_val = -E1000_ERR_PHY;
233
 
                goto out;
234
 
        }
235
 
        if (mdic & E1000_MDIC_ERROR) {
236
 
                DEBUGOUT("MDI Error\n");
237
 
                ret_val = -E1000_ERR_PHY;
238
 
                goto out;
239
 
        }
240
 
 
241
 
out:
242
 
        return ret_val;
243
 
}
244
 
 
245
 
/**
246
 
 *  igb_read_phy_reg_i2c - Read PHY register using i2c
247
 
 *  @hw: pointer to the HW structure
248
 
 *  @offset: register offset to be read
249
 
 *  @data: pointer to the read data
250
 
 *
251
 
 *  Reads the PHY register at offset using the i2c interface and stores the
252
 
 *  retrieved information in data.
253
 
 **/
254
 
s32 igb_read_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 *data)
255
 
{
256
 
        struct e1000_phy_info *phy = &hw->phy;
257
 
        u32 i, i2ccmd = 0;
258
 
 
259
 
        DEBUGFUNC("igb_read_phy_reg_i2c");
260
 
 
261
 
        /*
262
 
         * Set up Op-code, Phy Address, and register address in the I2CCMD
263
 
         * register.  The MAC will take care of interfacing with the
264
 
         * PHY to retrieve the desired data.
265
 
         */
266
 
        i2ccmd = ((offset << E1000_I2CCMD_REG_ADDR_SHIFT) |
267
 
                  (phy->addr << E1000_I2CCMD_PHY_ADDR_SHIFT) |
268
 
                  (E1000_I2CCMD_OPCODE_READ));
269
 
 
270
 
        E1000_WRITE_REG(hw, E1000_I2CCMD, i2ccmd);
271
 
 
272
 
        /* Poll the ready bit to see if the I2C read completed */
273
 
        for (i = 0; i < E1000_I2CCMD_PHY_TIMEOUT; i++) {
274
 
                usec_delay(50);
275
 
                i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
276
 
                if (i2ccmd & E1000_I2CCMD_READY)
277
 
                        break;
278
 
        }
279
 
        if (!(i2ccmd & E1000_I2CCMD_READY)) {
280
 
                DEBUGOUT("I2CCMD Read did not complete\n");
281
 
                return -E1000_ERR_PHY;
282
 
        }
283
 
        if (i2ccmd & E1000_I2CCMD_ERROR) {
284
 
                DEBUGOUT("I2CCMD Error bit set\n");
285
 
                return -E1000_ERR_PHY;
286
 
        }
287
 
 
288
 
        /* Need to byte-swap the 16-bit value. */
289
 
        *data = ((i2ccmd >> 8) & 0x00FF) | ((i2ccmd << 8) & 0xFF00);
290
 
 
291
 
        return E1000_SUCCESS;
292
 
}
293
 
 
294
 
/**
295
 
 *  igb_write_phy_reg_i2c - Write PHY register using i2c
296
 
 *  @hw: pointer to the HW structure
297
 
 *  @offset: register offset to write to
298
 
 *  @data: data to write at register offset
299
 
 *
300
 
 *  Writes the data to PHY register at the offset using the i2c interface.
301
 
 **/
302
 
s32 igb_write_phy_reg_i2c(struct e1000_hw *hw, u32 offset, u16 data)
303
 
{
304
 
        struct e1000_phy_info *phy = &hw->phy;
305
 
        u32 i, i2ccmd = 0;
306
 
        u16 phy_data_swapped;
307
 
 
308
 
        DEBUGFUNC("igb_write_phy_reg_i2c");
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
 
        E1000_WRITE_REG(hw, 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
 
                usec_delay(50);
328
 
                i2ccmd = E1000_READ_REG(hw, E1000_I2CCMD);
329
 
                if (i2ccmd & E1000_I2CCMD_READY)
330
 
                        break;
331
 
        }
332
 
        if (!(i2ccmd & E1000_I2CCMD_READY)) {
333
 
                DEBUGOUT("I2CCMD Write did not complete\n");
334
 
                return -E1000_ERR_PHY;
335
 
        }
336
 
        if (i2ccmd & E1000_I2CCMD_ERROR) {
337
 
                DEBUGOUT("I2CCMD Error bit set\n");
338
 
                return -E1000_ERR_PHY;
339
 
        }
340
 
 
341
 
        return E1000_SUCCESS;
342
 
}
343
 
 
344
 
/**
345
 
 *  igb_read_phy_reg_m88 - Read m88 PHY register
346
 
 *  @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
 
 **/
354
 
s32 igb_read_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 *data)
355
 
{
356
 
        s32 ret_val = E1000_SUCCESS;
357
 
 
358
 
        DEBUGFUNC("igb_read_phy_reg_m88");
359
 
 
360
 
        if (!(hw->phy.ops.acquire))
361
 
                goto out;
362
 
 
363
 
        ret_val = hw->phy.ops.acquire(hw);
364
 
        if (ret_val)
365
 
                goto out;
366
 
 
367
 
        ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
368
 
                                          data);
369
 
 
370
 
        hw->phy.ops.release(hw);
371
 
 
372
 
out:
373
 
        return ret_val;
374
 
}
375
 
 
376
 
/**
377
 
 *  igb_write_phy_reg_m88 - Write m88 PHY register
378
 
 *  @hw: pointer to the HW structure
379
 
 *  @offset: register offset to write to
380
 
 *  @data: data to write at register offset
381
 
 *
382
 
 *  Acquires semaphore, if necessary, then writes the data to PHY register
383
 
 *  at the offset.  Release any acquired semaphores before exiting.
384
 
 **/
385
 
s32 igb_write_phy_reg_m88(struct e1000_hw *hw, u32 offset, u16 data)
386
 
{
387
 
        s32 ret_val = E1000_SUCCESS;
388
 
 
389
 
        DEBUGFUNC("igb_write_phy_reg_m88");
390
 
 
391
 
        if (!(hw->phy.ops.acquire))
392
 
                goto out;
393
 
 
394
 
        ret_val = hw->phy.ops.acquire(hw);
395
 
        if (ret_val)
396
 
                goto out;
397
 
 
398
 
        ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
399
 
                                           data);
400
 
 
401
 
        hw->phy.ops.release(hw);
402
 
 
403
 
out:
404
 
        return ret_val;
405
 
}
406
 
 
407
 
/**
408
 
 *  __igb_read_phy_reg_igp - Read igp PHY register
409
 
 *  @hw: pointer to the HW structure
410
 
 *  @offset: register offset to be read
411
 
 *  @data: pointer to the read data
412
 
 *  @locked: semaphore has already been acquired or not
413
 
 *
414
 
 *  Acquires semaphore, if necessary, then reads the PHY register at offset
415
 
 *  and stores the retrieved information in data.  Release any acquired
416
 
 *  semaphores before exiting.
417
 
 **/
418
 
static s32 __igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data,
419
 
                                    bool locked)
420
 
{
421
 
        s32 ret_val = E1000_SUCCESS;
422
 
 
423
 
        DEBUGFUNC("__igb_read_phy_reg_igp");
424
 
 
425
 
        if (!locked) {
426
 
                if (!(hw->phy.ops.acquire))
427
 
                        goto out;
428
 
 
429
 
                ret_val = hw->phy.ops.acquire(hw);
430
 
                if (ret_val)
431
 
                        goto out;
432
 
        }
433
 
 
434
 
        if (offset > MAX_PHY_MULTI_PAGE_REG) {
435
 
                ret_val = igb_write_phy_reg_mdic(hw,
436
 
                                                   IGP01E1000_PHY_PAGE_SELECT,
437
 
                                                   (u16)offset);
438
 
                if (ret_val)
439
 
                        goto release;
440
 
        }
441
 
 
442
 
        ret_val = igb_read_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
443
 
                                          data);
444
 
 
445
 
release:
446
 
        if (!locked)
447
 
                hw->phy.ops.release(hw);
448
 
out:
449
 
        return ret_val;
450
 
}
451
 
/**
452
 
 *  igb_read_phy_reg_igp - Read igp PHY register
453
 
 *  @hw: pointer to the HW structure
454
 
 *  @offset: register offset to be read
455
 
 *  @data: pointer to the read data
456
 
 *
457
 
 *  Acquires semaphore then reads the PHY register at offset and stores the
458
 
 *  retrieved information in data.
459
 
 *  Release the acquired semaphore before exiting.
460
 
 **/
461
 
s32 igb_read_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 *data)
462
 
{
463
 
        return __igb_read_phy_reg_igp(hw, offset, data, false);
464
 
}
465
 
 
466
 
/**
467
 
 *  igb_read_phy_reg_igp_locked - Read igp PHY register
468
 
 *  @hw: pointer to the HW structure
469
 
 *  @offset: register offset to be read
470
 
 *  @data: pointer to the read data
471
 
 *
472
 
 *  Reads the PHY register at offset and stores the retrieved information
473
 
 *  in data.  Assumes semaphore already acquired.
474
 
 **/
475
 
s32 igb_read_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 *data)
476
 
{
477
 
        return __igb_read_phy_reg_igp(hw, offset, data, true);
478
 
}
479
 
 
480
 
/**
481
 
 *  igb_write_phy_reg_igp - Write igp PHY register
482
 
 *  @hw: pointer to the HW structure
483
 
 *  @offset: register offset to write to
484
 
 *  @data: data to write at register offset
485
 
 *  @locked: semaphore has already been acquired or not
486
 
 *
487
 
 *  Acquires semaphore, if necessary, then writes the data to PHY register
488
 
 *  at the offset.  Release any acquired semaphores before exiting.
489
 
 **/
490
 
static s32 __igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data,
491
 
                                     bool locked)
492
 
{
493
 
        s32 ret_val = E1000_SUCCESS;
494
 
 
495
 
        DEBUGFUNC("igb_write_phy_reg_igp");
496
 
 
497
 
        if (!locked) {
498
 
                if (!(hw->phy.ops.acquire))
499
 
                        goto out;
500
 
 
501
 
                ret_val = hw->phy.ops.acquire(hw);
502
 
                if (ret_val)
503
 
                        goto out;
504
 
        }
505
 
 
506
 
        if (offset > MAX_PHY_MULTI_PAGE_REG) {
507
 
                ret_val = igb_write_phy_reg_mdic(hw,
508
 
                                                   IGP01E1000_PHY_PAGE_SELECT,
509
 
                                                   (u16)offset);
510
 
                if (ret_val)
511
 
                        goto release;
512
 
        }
513
 
 
514
 
        ret_val = igb_write_phy_reg_mdic(hw, MAX_PHY_REG_ADDRESS & offset,
515
 
                                           data);
516
 
 
517
 
release:
518
 
        if (!locked)
519
 
                hw->phy.ops.release(hw);
520
 
 
521
 
out:
522
 
        return ret_val;
523
 
}
524
 
 
525
 
/**
526
 
 *  igb_write_phy_reg_igp - Write igp PHY register
527
 
 *  @hw: pointer to the HW structure
528
 
 *  @offset: register offset to write to
529
 
 *  @data: data to write at register offset
530
 
 *
531
 
 *  Acquires semaphore then writes the data to PHY register
532
 
 *  at the offset.  Release any acquired semaphores before exiting.
533
 
 **/
534
 
s32 igb_write_phy_reg_igp(struct e1000_hw *hw, u32 offset, u16 data)
535
 
{
536
 
        return __igb_write_phy_reg_igp(hw, offset, data, false);
537
 
}
538
 
 
539
 
/**
540
 
 *  igb_write_phy_reg_igp_locked - Write igp PHY register
541
 
 *  @hw: pointer to the HW structure
542
 
 *  @offset: register offset to write to
543
 
 *  @data: data to write at register offset
544
 
 *
545
 
 *  Writes the data to PHY register at the offset.
546
 
 *  Assumes semaphore already acquired.
547
 
 **/
548
 
s32 igb_write_phy_reg_igp_locked(struct e1000_hw *hw, u32 offset, u16 data)
549
 
{
550
 
        return __igb_write_phy_reg_igp(hw, offset, data, true);
551
 
}
552
 
 
553
 
/**
554
 
 *  __igb_read_kmrn_reg - Read kumeran register
555
 
 *  @hw: pointer to the HW structure
556
 
 *  @offset: register offset to be read
557
 
 *  @data: pointer to the read data
558
 
 *  @locked: semaphore has already been acquired or not
559
 
 *
560
 
 *  Acquires semaphore, if necessary.  Then reads the PHY register at offset
561
 
 *  using the kumeran interface.  The information retrieved is stored in data.
562
 
 *  Release any acquired semaphores before exiting.
563
 
 **/
564
 
static s32 __igb_read_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 *data,
565
 
                                 bool locked)
566
 
{
567
 
        u32 kmrnctrlsta;
568
 
        s32 ret_val = E1000_SUCCESS;
569
 
 
570
 
        DEBUGFUNC("__igb_read_kmrn_reg");
571
 
 
572
 
        if (!locked) {
573
 
                if (!(hw->phy.ops.acquire))
574
 
                        goto out;
575
 
 
576
 
                ret_val = hw->phy.ops.acquire(hw);
577
 
                if (ret_val)
578
 
                        goto out;
579
 
        }
580
 
 
581
 
        kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
582
 
                       E1000_KMRNCTRLSTA_OFFSET) | E1000_KMRNCTRLSTA_REN;
583
 
        E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
584
 
 
585
 
        usec_delay(2);
586
 
 
587
 
        kmrnctrlsta = E1000_READ_REG(hw, E1000_KMRNCTRLSTA);
588
 
        *data = (u16)kmrnctrlsta;
589
 
 
590
 
        if (!locked)
591
 
                hw->phy.ops.release(hw);
592
 
 
593
 
out:
594
 
        return ret_val;
595
 
}
596
 
 
597
 
/**
598
 
 *  igb_read_kmrn_reg_generic -  Read kumeran register
599
 
 *  @hw: pointer to the HW structure
600
 
 *  @offset: register offset to be read
601
 
 *  @data: pointer to the read data
602
 
 *
603
 
 *  Acquires semaphore then reads the PHY register at offset using the
604
 
 *  kumeran interface.  The information retrieved is stored in data.
605
 
 *  Release the acquired semaphore before exiting.
606
 
 **/
607
 
s32 igb_read_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 *data)
608
 
{
609
 
        return __igb_read_kmrn_reg(hw, offset, data, false);
610
 
}
611
 
 
612
 
/**
613
 
 *  igb_read_kmrn_reg_locked -  Read kumeran register
614
 
 *  @hw: pointer to the HW structure
615
 
 *  @offset: register offset to be read
616
 
 *  @data: pointer to the read data
617
 
 *
618
 
 *  Reads the PHY register at offset using the kumeran interface.  The
619
 
 *  information retrieved is stored in data.
620
 
 *  Assumes semaphore already acquired.
621
 
 **/
622
 
s32 igb_read_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 *data)
623
 
{
624
 
        return __igb_read_kmrn_reg(hw, offset, data, true);
625
 
}
626
 
 
627
 
/**
628
 
 *  __igb_write_kmrn_reg - Write kumeran register
629
 
 *  @hw: pointer to the HW structure
630
 
 *  @offset: register offset to write to
631
 
 *  @data: data to write at register offset
632
 
 *  @locked: semaphore has already been acquired or not
633
 
 *
634
 
 *  Acquires semaphore, if necessary.  Then write the data to PHY register
635
 
 *  at the offset using the kumeran interface.  Release any acquired semaphores
636
 
 *  before exiting.
637
 
 **/
638
 
static s32 __igb_write_kmrn_reg(struct e1000_hw *hw, u32 offset, u16 data,
639
 
                                  bool locked)
640
 
{
641
 
        u32 kmrnctrlsta;
642
 
        s32 ret_val = E1000_SUCCESS;
643
 
 
644
 
        DEBUGFUNC("igb_write_kmrn_reg_generic");
645
 
 
646
 
        if (!locked) {
647
 
                if (!(hw->phy.ops.acquire))
648
 
                        goto out;
649
 
 
650
 
                ret_val = hw->phy.ops.acquire(hw);
651
 
                if (ret_val)
652
 
                        goto out;
653
 
        }
654
 
 
655
 
        kmrnctrlsta = ((offset << E1000_KMRNCTRLSTA_OFFSET_SHIFT) &
656
 
                       E1000_KMRNCTRLSTA_OFFSET) | data;
657
 
        E1000_WRITE_REG(hw, E1000_KMRNCTRLSTA, kmrnctrlsta);
658
 
 
659
 
        usec_delay(2);
660
 
 
661
 
        if (!locked)
662
 
                hw->phy.ops.release(hw);
663
 
 
664
 
out:
665
 
        return ret_val;
666
 
}
667
 
 
668
 
/**
669
 
 *  igb_write_kmrn_reg_generic -  Write kumeran register
670
 
 *  @hw: pointer to the HW structure
671
 
 *  @offset: register offset to write to
672
 
 *  @data: data to write at register offset
673
 
 *
674
 
 *  Acquires semaphore then writes the data to the PHY register at the offset
675
 
 *  using the kumeran interface.  Release the acquired semaphore before exiting.
676
 
 **/
677
 
s32 igb_write_kmrn_reg_generic(struct e1000_hw *hw, u32 offset, u16 data)
678
 
{
679
 
        return __igb_write_kmrn_reg(hw, offset, data, false);
680
 
}
681
 
 
682
 
/**
683
 
 *  igb_write_kmrn_reg_locked -  Write kumeran register
684
 
 *  @hw: pointer to the HW structure
685
 
 *  @offset: register offset to write to
686
 
 *  @data: data to write at register offset
687
 
 *
688
 
 *  Write the data to PHY register at the offset using the kumeran interface.
689
 
 *  Assumes semaphore already acquired.
690
 
 **/
691
 
s32 igb_write_kmrn_reg_locked(struct e1000_hw *hw, u32 offset, u16 data)
692
 
{
693
 
        return __igb_write_kmrn_reg(hw, offset, data, true);
694
 
}
695
 
 
696
 
/**
697
 
 *  igb_copper_link_setup_m88 - Setup m88 PHY's for copper link
698
 
 *  @hw: pointer to the HW structure
699
 
 *
700
 
 *  Sets up MDI/MDI-X and polarity for m88 PHY's.  If necessary, transmit clock
701
 
 *  and downshift values are set also.
702
 
 **/
703
 
s32 igb_copper_link_setup_m88(struct e1000_hw *hw)
704
 
{
705
 
        struct e1000_phy_info *phy = &hw->phy;
706
 
        s32 ret_val;
707
 
        u16 phy_data;
708
 
 
709
 
        DEBUGFUNC("igb_copper_link_setup_m88");
710
 
 
711
 
        if (phy->reset_disable) {
712
 
                ret_val = E1000_SUCCESS;
713
 
                goto out;
714
 
        }
715
 
 
716
 
        /* Enable CRS on TX. This must be set for half-duplex operation. */
717
 
        ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
718
 
        if (ret_val)
719
 
                goto out;
720
 
 
721
 
        phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
722
 
 
723
 
        /*
724
 
         * Options:
725
 
         *   MDI/MDI-X = 0 (default)
726
 
         *   0 - Auto for all speeds
727
 
         *   1 - MDI mode
728
 
         *   2 - MDI-X mode
729
 
         *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
730
 
         */
731
 
        phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
732
 
 
733
 
        switch (phy->mdix) {
734
 
        case 1:
735
 
                phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
736
 
                break;
737
 
        case 2:
738
 
                phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
739
 
                break;
740
 
        case 3:
741
 
                phy_data |= M88E1000_PSCR_AUTO_X_1000T;
742
 
                break;
743
 
        case 0:
744
 
        default:
745
 
                phy_data |= M88E1000_PSCR_AUTO_X_MODE;
746
 
                break;
747
 
        }
748
 
 
749
 
        /*
750
 
         * Options:
751
 
         *   disable_polarity_correction = 0 (default)
752
 
         *       Automatic Correction for Reversed Cable Polarity
753
 
         *   0 - Disabled
754
 
         *   1 - Enabled
755
 
         */
756
 
        phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
757
 
        if (phy->disable_polarity_correction == 1)
758
 
                phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
759
 
 
760
 
        ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
761
 
        if (ret_val)
762
 
                goto out;
763
 
 
764
 
        if (phy->revision < E1000_REVISION_4) {
765
 
                /*
766
 
                 * Force TX_CLK in the Extended PHY Specific Control Register
767
 
                 * to 25MHz clock.
768
 
                 */
769
 
                ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
770
 
                                             &phy_data);
771
 
                if (ret_val)
772
 
                        goto out;
773
 
 
774
 
                phy_data |= M88E1000_EPSCR_TX_CLK_25;
775
 
 
776
 
                if ((phy->revision == E1000_REVISION_2) &&
777
 
                    (phy->id == M88E1111_I_PHY_ID)) {
778
 
                        /* 82573L PHY - set the downshift counter to 5x. */
779
 
                        phy_data &= ~M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK;
780
 
                        phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
781
 
                } else {
782
 
                        /* Configure Master and Slave downshift values */
783
 
                        phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
784
 
                                     M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
785
 
                        phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
786
 
                                     M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
787
 
                }
788
 
                ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
789
 
                                             phy_data);
790
 
                if (ret_val)
791
 
                        goto out;
792
 
        }
793
 
 
794
 
        /* Commit the changes. */
795
 
        ret_val = phy->ops.commit(hw);
796
 
        if (ret_val) {
797
 
                DEBUGOUT("Error committing the PHY changes\n");
798
 
                goto out;
799
 
        }
800
 
 
801
 
out:
802
 
        return ret_val;
803
 
}
804
 
 
805
 
/**
806
 
 *  igb_copper_link_setup_igp - Setup igp PHY's for copper link
807
 
 *  @hw: pointer to the HW structure
808
 
 *
809
 
 *  Sets up LPLU, MDI/MDI-X, polarity, Smartspeed and Master/Slave config for
810
 
 *  igp PHY's.
811
 
 **/
812
 
s32 igb_copper_link_setup_igp(struct e1000_hw *hw)
813
 
{
814
 
        struct e1000_phy_info *phy = &hw->phy;
815
 
        s32 ret_val;
816
 
        u16 data;
817
 
 
818
 
        DEBUGFUNC("igb_copper_link_setup_igp");
819
 
 
820
 
        if (phy->reset_disable) {
821
 
                ret_val = E1000_SUCCESS;
822
 
                goto out;
823
 
        }
824
 
 
825
 
        ret_val = hw->phy.ops.reset(hw);
826
 
        if (ret_val) {
827
 
                DEBUGOUT("Error resetting the PHY.\n");
828
 
                goto out;
829
 
        }
830
 
 
831
 
        /*
832
 
         * Wait 100ms for MAC to configure PHY from NVM settings, to avoid
833
 
         * timeout issues when LFS is enabled.
834
 
         */
835
 
        msec_delay(100);
836
 
 
837
 
        /*
838
 
         * The NVM settings will configure LPLU in D3 for
839
 
         * non-IGP1 PHYs.
840
 
         */
841
 
        if (phy->type == e1000_phy_igp) {
842
 
                /* disable lplu d3 during driver init */
843
 
                ret_val = hw->phy.ops.set_d3_lplu_state(hw, false);
844
 
                if (ret_val) {
845
 
                        DEBUGOUT("Error Disabling LPLU D3\n");
846
 
                        goto out;
847
 
                }
848
 
        }
849
 
 
850
 
        /* disable lplu d0 during driver init */
851
 
        if (hw->phy.ops.set_d0_lplu_state) {
852
 
                ret_val = hw->phy.ops.set_d0_lplu_state(hw, false);
853
 
                if (ret_val) {
854
 
                        DEBUGOUT("Error Disabling LPLU D0\n");
855
 
                        goto out;
856
 
                }
857
 
        }
858
 
        /* Configure mdi-mdix settings */
859
 
        ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &data);
860
 
        if (ret_val)
861
 
                goto out;
862
 
 
863
 
        data &= ~IGP01E1000_PSCR_AUTO_MDIX;
864
 
 
865
 
        switch (phy->mdix) {
866
 
        case 1:
867
 
                data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
868
 
                break;
869
 
        case 2:
870
 
                data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
871
 
                break;
872
 
        case 0:
873
 
        default:
874
 
                data |= IGP01E1000_PSCR_AUTO_MDIX;
875
 
                break;
876
 
        }
877
 
        ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, data);
878
 
        if (ret_val)
879
 
                goto out;
880
 
 
881
 
        /* set auto-master slave resolution settings */
882
 
        if (hw->mac.autoneg) {
883
 
                /*
884
 
                 * when autonegotiation advertisement is only 1000Mbps then we
885
 
                 * should disable SmartSpeed and enable Auto MasterSlave
886
 
                 * resolution as hardware default.
887
 
                 */
888
 
                if (phy->autoneg_advertised == ADVERTISE_1000_FULL) {
889
 
                        /* Disable SmartSpeed */
890
 
                        ret_val = phy->ops.read_reg(hw,
891
 
                                                     IGP01E1000_PHY_PORT_CONFIG,
892
 
                                                     &data);
893
 
                        if (ret_val)
894
 
                                goto out;
895
 
 
896
 
                        data &= ~IGP01E1000_PSCFR_SMART_SPEED;
897
 
                        ret_val = phy->ops.write_reg(hw,
898
 
                                                     IGP01E1000_PHY_PORT_CONFIG,
899
 
                                                     data);
900
 
                        if (ret_val)
901
 
                                goto out;
902
 
 
903
 
                        /* Set auto Master/Slave resolution process */
904
 
                        ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
905
 
                        if (ret_val)
906
 
                                goto out;
907
 
 
908
 
                        data &= ~CR_1000T_MS_ENABLE;
909
 
                        ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
910
 
                        if (ret_val)
911
 
                                goto out;
912
 
                }
913
 
 
914
 
                ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL, &data);
915
 
                if (ret_val)
916
 
                        goto out;
917
 
 
918
 
                /* load defaults for future use */
919
 
                phy->original_ms_type = (data & CR_1000T_MS_ENABLE) ?
920
 
                        ((data & CR_1000T_MS_VALUE) ?
921
 
                        e1000_ms_force_master :
922
 
                        e1000_ms_force_slave) :
923
 
                        e1000_ms_auto;
924
 
 
925
 
                switch (phy->ms_type) {
926
 
                case e1000_ms_force_master:
927
 
                        data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
928
 
                        break;
929
 
                case e1000_ms_force_slave:
930
 
                        data |= CR_1000T_MS_ENABLE;
931
 
                        data &= ~(CR_1000T_MS_VALUE);
932
 
                        break;
933
 
                case e1000_ms_auto:
934
 
                        data &= ~CR_1000T_MS_ENABLE;
935
 
                default:
936
 
                        break;
937
 
                }
938
 
                ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL, data);
939
 
                if (ret_val)
940
 
                        goto out;
941
 
        }
942
 
 
943
 
out:
944
 
        return ret_val;
945
 
}
946
 
 
947
 
/**
948
 
 *  igb_copper_link_autoneg - Setup/Enable autoneg for copper link
949
 
 *  @hw: pointer to the HW structure
950
 
 *
951
 
 *  Performs initial bounds checking on autoneg advertisement parameter, then
952
 
 *  configure to advertise the full capability.  Setup the PHY to autoneg
953
 
 *  and restart the negotiation process between the link partner.  If
954
 
 *  autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
955
 
 **/
956
 
s32 igb_copper_link_autoneg(struct e1000_hw *hw)
957
 
{
958
 
        struct e1000_phy_info *phy = &hw->phy;
959
 
        s32 ret_val;
960
 
        u16 phy_ctrl;
961
 
 
962
 
        DEBUGFUNC("igb_copper_link_autoneg");
963
 
 
964
 
        /*
965
 
         * Perform some bounds checking on the autoneg advertisement
966
 
         * parameter.
967
 
         */
968
 
        phy->autoneg_advertised &= phy->autoneg_mask;
969
 
 
970
 
        /*
971
 
         * If autoneg_advertised is zero, we assume it was not defaulted
972
 
         * by the calling code so we set to advertise full capability.
973
 
         */
974
 
        if (phy->autoneg_advertised == 0)
975
 
                phy->autoneg_advertised = phy->autoneg_mask;
976
 
 
977
 
        DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
978
 
        ret_val = igb_phy_setup_autoneg(hw);
979
 
        if (ret_val) {
980
 
                DEBUGOUT("Error Setting up Auto-Negotiation\n");
981
 
                goto out;
982
 
        }
983
 
        DEBUGOUT("Restarting Auto-Neg\n");
984
 
 
985
 
        /*
986
 
         * Restart auto-negotiation by setting the Auto Neg Enable bit and
987
 
         * the Auto Neg Restart bit in the PHY control register.
988
 
         */
989
 
        ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
990
 
        if (ret_val)
991
 
                goto out;
992
 
 
993
 
        phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
994
 
        ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
995
 
        if (ret_val)
996
 
                goto out;
997
 
 
998
 
        /*
999
 
         * Does the user want to wait for Auto-Neg to complete here, or
1000
 
         * check at a later time (for example, callback routine).
1001
 
         */
1002
 
        if (phy->autoneg_wait_to_complete) {
1003
 
                ret_val = hw->mac.ops.wait_autoneg(hw);
1004
 
                if (ret_val) {
1005
 
                        DEBUGOUT("Error while waiting for "
1006
 
                                 "autoneg to complete\n");
1007
 
                        goto out;
1008
 
                }
1009
 
        }
1010
 
 
1011
 
        hw->mac.get_link_status = true;
1012
 
 
1013
 
out:
1014
 
        return ret_val;
1015
 
}
1016
 
 
1017
 
/**
1018
 
 *  igb_phy_setup_autoneg - Configure PHY for auto-negotiation
1019
 
 *  @hw: pointer to the HW structure
1020
 
 *
1021
 
 *  Reads the MII auto-neg advertisement register and/or the 1000T control
1022
 
 *  register and if the PHY is already setup for auto-negotiation, then
1023
 
 *  return successful.  Otherwise, setup advertisement and flow control to
1024
 
 *  the appropriate values for the wanted auto-negotiation.
1025
 
 **/
1026
 
static s32 igb_phy_setup_autoneg(struct e1000_hw *hw)
1027
 
{
1028
 
        struct e1000_phy_info *phy = &hw->phy;
1029
 
        s32 ret_val;
1030
 
        u16 mii_autoneg_adv_reg;
1031
 
        u16 mii_1000t_ctrl_reg = 0;
1032
 
 
1033
 
        DEBUGFUNC("igb_phy_setup_autoneg");
1034
 
 
1035
 
        phy->autoneg_advertised &= phy->autoneg_mask;
1036
 
 
1037
 
        /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1038
 
        ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
1039
 
        if (ret_val)
1040
 
                goto out;
1041
 
 
1042
 
        if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
1043
 
                /* Read the MII 1000Base-T Control Register (Address 9). */
1044
 
                ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
1045
 
                                            &mii_1000t_ctrl_reg);
1046
 
                if (ret_val)
1047
 
                        goto out;
1048
 
        }
1049
 
 
1050
 
        /*
1051
 
         * Need to parse both autoneg_advertised and fc and set up
1052
 
         * the appropriate PHY registers.  First we will parse for
1053
 
         * autoneg_advertised software override.  Since we can advertise
1054
 
         * a plethora of combinations, we need to check each bit
1055
 
         * individually.
1056
 
         */
1057
 
 
1058
 
        /*
1059
 
         * First we clear all the 10/100 mb speed bits in the Auto-Neg
1060
 
         * Advertisement Register (Address 4) and the 1000 mb speed bits in
1061
 
         * the  1000Base-T Control Register (Address 9).
1062
 
         */
1063
 
        mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS |
1064
 
                                 NWAY_AR_100TX_HD_CAPS |
1065
 
                                 NWAY_AR_10T_FD_CAPS   |
1066
 
                                 NWAY_AR_10T_HD_CAPS);
1067
 
        mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
1068
 
 
1069
 
        DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
1070
 
 
1071
 
        /* Do we want to advertise 10 Mb Half Duplex? */
1072
 
        if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
1073
 
                DEBUGOUT("Advertise 10mb Half duplex\n");
1074
 
                mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1075
 
        }
1076
 
 
1077
 
        /* Do we want to advertise 10 Mb Full Duplex? */
1078
 
        if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
1079
 
                DEBUGOUT("Advertise 10mb Full duplex\n");
1080
 
                mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1081
 
        }
1082
 
 
1083
 
        /* Do we want to advertise 100 Mb Half Duplex? */
1084
 
        if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
1085
 
                DEBUGOUT("Advertise 100mb Half duplex\n");
1086
 
                mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1087
 
        }
1088
 
 
1089
 
        /* Do we want to advertise 100 Mb Full Duplex? */
1090
 
        if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
1091
 
                DEBUGOUT("Advertise 100mb Full duplex\n");
1092
 
                mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1093
 
        }
1094
 
 
1095
 
        /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1096
 
        if (phy->autoneg_advertised & ADVERTISE_1000_HALF) {
1097
 
                DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
1098
 
        }
1099
 
        /* Do we want to advertise 1000 Mb Full Duplex? */
1100
 
        if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
1101
 
                DEBUGOUT("Advertise 1000mb Full duplex\n");
1102
 
                mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1103
 
        }
1104
 
 
1105
 
        /*
1106
 
         * Check for a software override of the flow control settings, and
1107
 
         * setup the PHY advertisement registers accordingly.  If
1108
 
         * auto-negotiation is enabled, then software will have to set the
1109
 
         * "PAUSE" bits to the correct value in the Auto-Negotiation
1110
 
         * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
1111
 
         * negotiation.
1112
 
         *
1113
 
         * The possible values of the "fc" parameter are:
1114
 
         *      0:  Flow control is completely disabled
1115
 
         *      1:  Rx flow control is enabled (we can receive pause frames
1116
 
         *          but not send pause frames).
1117
 
         *      2:  Tx flow control is enabled (we can send pause frames
1118
 
         *          but we do not support receiving pause frames).
1119
 
         *      3:  Both Rx and Tx flow control (symmetric) are enabled.
1120
 
         *  other:  No software override.  The flow control configuration
1121
 
         *          in the EEPROM is used.
1122
 
         */
1123
 
        switch (hw->fc.current_mode) {
1124
 
        case e1000_fc_none:
1125
 
                /*
1126
 
                 * Flow control (Rx & Tx) is completely disabled by a
1127
 
                 * software over-ride.
1128
 
                 */
1129
 
                mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1130
 
                break;
1131
 
        case e1000_fc_rx_pause:
1132
 
                /*
1133
 
                 * Rx Flow control is enabled, and Tx Flow control is
1134
 
                 * disabled, by a software over-ride.
1135
 
                 *
1136
 
                 * Since there really isn't a way to advertise that we are
1137
 
                 * capable of Rx Pause ONLY, we will advertise that we
1138
 
                 * support both symmetric and asymmetric Rx PAUSE.  Later
1139
 
                 * (in e1000_config_fc_after_link_up) we will disable the
1140
 
                 * hw's ability to send PAUSE frames.
1141
 
                 */
1142
 
                mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1143
 
                break;
1144
 
        case e1000_fc_tx_pause:
1145
 
                /*
1146
 
                 * Tx Flow control is enabled, and Rx Flow control is
1147
 
                 * disabled, by a software over-ride.
1148
 
                 */
1149
 
                mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1150
 
                mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1151
 
                break;
1152
 
        case e1000_fc_full:
1153
 
                /*
1154
 
                 * Flow control (both Rx and Tx) is enabled by a software
1155
 
                 * over-ride.
1156
 
                 */
1157
 
                mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1158
 
                break;
1159
 
        default:
1160
 
                DEBUGOUT("Flow control param set incorrectly\n");
1161
 
                ret_val = -E1000_ERR_CONFIG;
1162
 
                goto out;
1163
 
        }
1164
 
 
1165
 
        ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
1166
 
        if (ret_val)
1167
 
                goto out;
1168
 
 
1169
 
        DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1170
 
 
1171
 
        if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
1172
 
                ret_val = phy->ops.write_reg(hw,
1173
 
                                              PHY_1000T_CTRL,
1174
 
                                              mii_1000t_ctrl_reg);
1175
 
                if (ret_val)
1176
 
                        goto out;
1177
 
        }
1178
 
 
1179
 
out:
1180
 
        return ret_val;
1181
 
}
1182
 
 
1183
 
/**
1184
 
 *  igb_setup_copper_link_generic - Configure copper link settings
1185
 
 *  @hw: pointer to the HW structure
1186
 
 *
1187
 
 *  Calls the appropriate function to configure the link for auto-neg or forced
1188
 
 *  speed and duplex.  Then we check for link, once link is established calls
1189
 
 *  to configure collision distance and flow control are called.  If link is
1190
 
 *  not established, we return -E1000_ERR_PHY (-2).
1191
 
 **/
1192
 
s32 igb_setup_copper_link_generic(struct e1000_hw *hw)
1193
 
{
1194
 
        s32 ret_val;
1195
 
        bool link;
1196
 
 
1197
 
        DEBUGFUNC("igb_setup_copper_link_generic");
1198
 
 
1199
 
        if (hw->mac.autoneg) {
1200
 
                /*
1201
 
                 * Setup autoneg and flow control advertisement and perform
1202
 
                 * autonegotiation.
1203
 
                 */
1204
 
                ret_val = igb_copper_link_autoneg(hw);
1205
 
                if (ret_val)
1206
 
                        goto out;
1207
 
        } else {
1208
 
#if 0
1209
 
                /*
1210
 
                 * PHY will be set to 10H, 10F, 100H or 100F
1211
 
                 * depending on user settings.
1212
 
                 */
1213
 
                DEBUGOUT("Forcing Speed and Duplex\n");
1214
 
                ret_val = hw->phy.ops.force_speed_duplex(hw);
1215
 
                if (ret_val) {
1216
 
                        DEBUGOUT("Error Forcing Speed and Duplex\n");
1217
 
                        goto out;
1218
 
                }
1219
 
#endif
1220
 
        }
1221
 
 
1222
 
        /*
1223
 
         * Check link status. Wait up to 100 microseconds for link to become
1224
 
         * valid.
1225
 
         */
1226
 
        ret_val = igb_phy_has_link_generic(hw,
1227
 
                                             COPPER_LINK_UP_LIMIT,
1228
 
                                             10,
1229
 
                                             &link);
1230
 
        if (ret_val)
1231
 
                goto out;
1232
 
 
1233
 
        if (link) {
1234
 
                DEBUGOUT("Valid link established!!!\n");
1235
 
                igb_config_collision_dist_generic(hw);
1236
 
                ret_val = igb_config_fc_after_link_up_generic(hw);
1237
 
        } else {
1238
 
                DEBUGOUT("Unable to establish link!!!\n");
1239
 
        }
1240
 
 
1241
 
out:
1242
 
        return ret_val;
1243
 
}
1244
 
 
1245
 
#if 0
1246
 
/**
1247
 
 *  igb_phy_force_speed_duplex_igp - Force speed/duplex for igp PHY
1248
 
 *  @hw: pointer to the HW structure
1249
 
 *
1250
 
 *  Calls the PHY setup function to force speed and duplex.  Clears the
1251
 
 *  auto-crossover to force MDI manually.  Waits for link and returns
1252
 
 *  successful if link up is successful, else -E1000_ERR_PHY (-2).
1253
 
 **/
1254
 
s32 igb_phy_force_speed_duplex_igp(struct e1000_hw *hw)
1255
 
{
1256
 
        struct e1000_phy_info *phy = &hw->phy;
1257
 
        s32 ret_val;
1258
 
        u16 phy_data;
1259
 
        bool link;
1260
 
 
1261
 
        DEBUGFUNC("igb_phy_force_speed_duplex_igp");
1262
 
 
1263
 
        ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1264
 
        if (ret_val)
1265
 
                goto out;
1266
 
 
1267
 
        igb_phy_force_speed_duplex_setup(hw, &phy_data);
1268
 
 
1269
 
        ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1270
 
        if (ret_val)
1271
 
                goto out;
1272
 
 
1273
 
        /*
1274
 
         * Clear Auto-Crossover to force MDI manually.  IGP requires MDI
1275
 
         * forced whenever speed and duplex are forced.
1276
 
         */
1277
 
        ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
1278
 
        if (ret_val)
1279
 
                goto out;
1280
 
 
1281
 
        phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1282
 
        phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1283
 
 
1284
 
        ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
1285
 
        if (ret_val)
1286
 
                goto out;
1287
 
 
1288
 
        DEBUGOUT1("IGP PSCR: %X\n", phy_data);
1289
 
 
1290
 
        usec_delay(1);
1291
 
 
1292
 
        if (phy->autoneg_wait_to_complete) {
1293
 
                DEBUGOUT("Waiting for forced speed/duplex link on IGP phy.\n");
1294
 
 
1295
 
                ret_val = igb_phy_has_link_generic(hw,
1296
 
                                                     PHY_FORCE_LIMIT,
1297
 
                                                     100000,
1298
 
                                                     &link);
1299
 
                if (ret_val)
1300
 
                        goto out;
1301
 
 
1302
 
                if (!link) {
1303
 
                        DEBUGOUT("Link taking longer than expected.\n");
1304
 
                }
1305
 
                /* Try once more */
1306
 
                ret_val = igb_phy_has_link_generic(hw,
1307
 
                                                     PHY_FORCE_LIMIT,
1308
 
                                                     100000,
1309
 
                                                     &link);
1310
 
                if (ret_val)
1311
 
                        goto out;
1312
 
        }
1313
 
 
1314
 
out:
1315
 
        return ret_val;
1316
 
}
1317
 
#endif
1318
 
 
1319
 
#if 0
1320
 
/**
1321
 
 *  igb_phy_force_speed_duplex_m88 - Force speed/duplex for m88 PHY
1322
 
 *  @hw: pointer to the HW structure
1323
 
 *
1324
 
 *  Calls the PHY setup function to force speed and duplex.  Clears the
1325
 
 *  auto-crossover to force MDI manually.  Resets the PHY to commit the
1326
 
 *  changes.  If time expires while waiting for link up, we reset the DSP.
1327
 
 *  After reset, TX_CLK and CRS on Tx must be set.  Return successful upon
1328
 
 *  successful completion, else return corresponding error code.
1329
 
 **/
1330
 
s32 igb_phy_force_speed_duplex_m88(struct e1000_hw *hw)
1331
 
{
1332
 
        struct e1000_phy_info *phy = &hw->phy;
1333
 
        s32 ret_val;
1334
 
        u16 phy_data;
1335
 
        bool link;
1336
 
 
1337
 
        DEBUGFUNC("igb_phy_force_speed_duplex_m88");
1338
 
 
1339
 
        /*
1340
 
         * Clear Auto-Crossover to force MDI manually.  M88E1000 requires MDI
1341
 
         * forced whenever speed and duplex are forced.
1342
 
         */
1343
 
        ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1344
 
        if (ret_val)
1345
 
                goto out;
1346
 
 
1347
 
        phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1348
 
        ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1349
 
        if (ret_val)
1350
 
                goto out;
1351
 
 
1352
 
        DEBUGOUT1("M88E1000 PSCR: %X\n", phy_data);
1353
 
 
1354
 
        ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_data);
1355
 
        if (ret_val)
1356
 
                goto out;
1357
 
 
1358
 
        igb_phy_force_speed_duplex_setup(hw, &phy_data);
1359
 
 
1360
 
        ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_data);
1361
 
        if (ret_val)
1362
 
                goto out;
1363
 
 
1364
 
        /* Reset the phy to commit changes. */
1365
 
        ret_val = hw->phy.ops.commit(hw);
1366
 
        if (ret_val)
1367
 
                goto out;
1368
 
 
1369
 
        if (phy->autoneg_wait_to_complete) {
1370
 
                DEBUGOUT("Waiting for forced speed/duplex link on M88 phy.\n");
1371
 
 
1372
 
                ret_val = igb_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1373
 
                                                     100000, &link);
1374
 
                if (ret_val)
1375
 
                        goto out;
1376
 
 
1377
 
                if (!link) {
1378
 
                        /*
1379
 
                         * We didn't get link.
1380
 
                         * Reset the DSP and cross our fingers.
1381
 
                         */
1382
 
                        ret_val = phy->ops.write_reg(hw,
1383
 
                                                      M88E1000_PHY_PAGE_SELECT,
1384
 
                                                      0x001d);
1385
 
                        if (ret_val)
1386
 
                                goto out;
1387
 
                        ret_val = igb_phy_reset_dsp_generic(hw);
1388
 
                        if (ret_val)
1389
 
                                goto out;
1390
 
                }
1391
 
 
1392
 
                /* Try once more */
1393
 
                ret_val = igb_phy_has_link_generic(hw, PHY_FORCE_LIMIT,
1394
 
                                                     100000, &link);
1395
 
                if (ret_val)
1396
 
                        goto out;
1397
 
        }
1398
 
 
1399
 
        ret_val = phy->ops.read_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
1400
 
        if (ret_val)
1401
 
                goto out;
1402
 
 
1403
 
        /*
1404
 
         * Resetting the phy means we need to re-force TX_CLK in the
1405
 
         * Extended PHY Specific Control Register to 25MHz clock from
1406
 
         * the reset value of 2.5MHz.
1407
 
         */
1408
 
        phy_data |= M88E1000_EPSCR_TX_CLK_25;
1409
 
        ret_val = phy->ops.write_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
1410
 
        if (ret_val)
1411
 
                goto out;
1412
 
 
1413
 
        /*
1414
 
         * In addition, we must re-enable CRS on Tx for both half and full
1415
 
         * duplex.
1416
 
         */
1417
 
        ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
1418
 
        if (ret_val)
1419
 
                goto out;
1420
 
 
1421
 
        phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1422
 
        ret_val = phy->ops.write_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
1423
 
 
1424
 
out:
1425
 
        return ret_val;
1426
 
}
1427
 
#endif
1428
 
 
1429
 
#if 0
1430
 
/**
1431
 
 *  igb_phy_force_speed_duplex_ife - Force PHY speed & duplex
1432
 
 *  @hw: pointer to the HW structure
1433
 
 *
1434
 
 *  Forces the speed and duplex settings of the PHY.
1435
 
 *  This is a function pointer entry point only called by
1436
 
 *  PHY setup routines.
1437
 
 **/
1438
 
s32 igb_phy_force_speed_duplex_ife(struct e1000_hw *hw)
1439
 
{
1440
 
        struct e1000_phy_info *phy = &hw->phy;
1441
 
        s32 ret_val;
1442
 
        u16 data;
1443
 
        bool link;
1444
 
 
1445
 
        DEBUGFUNC("igb_phy_force_speed_duplex_ife");
1446
 
 
1447
 
        if (phy->type != e1000_phy_ife) {
1448
 
                ret_val = igb_phy_force_speed_duplex_igp(hw);
1449
 
                goto out;
1450
 
        }
1451
 
 
1452
 
        ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &data);
1453
 
        if (ret_val)
1454
 
                goto out;
1455
 
 
1456
 
        igb_phy_force_speed_duplex_setup(hw, &data);
1457
 
 
1458
 
        ret_val = phy->ops.write_reg(hw, PHY_CONTROL, data);
1459
 
        if (ret_val)
1460
 
                goto out;
1461
 
 
1462
 
        /* Disable MDI-X support for 10/100 */
1463
 
        ret_val = phy->ops.read_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
1464
 
        if (ret_val)
1465
 
                goto out;
1466
 
 
1467
 
        data &= ~IFE_PMC_AUTO_MDIX;
1468
 
        data &= ~IFE_PMC_FORCE_MDIX;
1469
 
 
1470
 
        ret_val = phy->ops.write_reg(hw, IFE_PHY_MDIX_CONTROL, data);
1471
 
        if (ret_val)
1472
 
                goto out;
1473
 
 
1474
 
        DEBUGOUT1("IFE PMC: %X\n", data);
1475
 
 
1476
 
        usec_delay(1);
1477
 
 
1478
 
        if (phy->autoneg_wait_to_complete) {
1479
 
                DEBUGOUT("Waiting for forced speed/duplex link on IFE phy.\n");
1480
 
 
1481
 
                ret_val = igb_phy_has_link_generic(hw,
1482
 
                                                     PHY_FORCE_LIMIT,
1483
 
                                                     100000,
1484
 
                                                     &link);
1485
 
                if (ret_val)
1486
 
                        goto out;
1487
 
 
1488
 
                if (!link) {
1489
 
                        DEBUGOUT("Link taking longer than expected.\n");
1490
 
                }
1491
 
                /* Try once more */
1492
 
                ret_val = igb_phy_has_link_generic(hw,
1493
 
                                                     PHY_FORCE_LIMIT,
1494
 
                                                     100000,
1495
 
                                                     &link);
1496
 
                if (ret_val)
1497
 
                        goto out;
1498
 
        }
1499
 
 
1500
 
out:
1501
 
        return ret_val;
1502
 
}
1503
 
#endif
1504
 
 
1505
 
#if 0
1506
 
/**
1507
 
 *  igb_phy_force_speed_duplex_setup - Configure forced PHY speed/duplex
1508
 
 *  @hw: pointer to the HW structure
1509
 
 *  @phy_ctrl: pointer to current value of PHY_CONTROL
1510
 
 *
1511
 
 *  Forces speed and duplex on the PHY by doing the following: disable flow
1512
 
 *  control, force speed/duplex on the MAC, disable auto speed detection,
1513
 
 *  disable auto-negotiation, configure duplex, configure speed, configure
1514
 
 *  the collision distance, write configuration to CTRL register.  The
1515
 
 *  caller must write to the PHY_CONTROL register for these settings to
1516
 
 *  take affect.
1517
 
 **/
1518
 
void igb_phy_force_speed_duplex_setup(struct e1000_hw *hw, u16 *phy_ctrl)
1519
 
{
1520
 
        struct e1000_mac_info *mac = &hw->mac;
1521
 
        u32 ctrl;
1522
 
 
1523
 
        DEBUGFUNC("igb_phy_force_speed_duplex_setup");
1524
 
 
1525
 
        /* Turn off flow control when forcing speed/duplex */
1526
 
        hw->fc.current_mode = e1000_fc_none;
1527
 
 
1528
 
        /* Force speed/duplex on the mac */
1529
 
        ctrl = E1000_READ_REG(hw, E1000_CTRL);
1530
 
        ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1531
 
        ctrl &= ~E1000_CTRL_SPD_SEL;
1532
 
 
1533
 
        /* Disable Auto Speed Detection */
1534
 
        ctrl &= ~E1000_CTRL_ASDE;
1535
 
 
1536
 
        /* Disable autoneg on the phy */
1537
 
        *phy_ctrl &= ~MII_CR_AUTO_NEG_EN;
1538
 
 
1539
 
        /* Forcing Full or Half Duplex? */
1540
 
        if (mac->forced_speed_duplex & E1000_ALL_HALF_DUPLEX) {
1541
 
                ctrl &= ~E1000_CTRL_FD;
1542
 
                *phy_ctrl &= ~MII_CR_FULL_DUPLEX;
1543
 
                DEBUGOUT("Half Duplex\n");
1544
 
        } else {
1545
 
                ctrl |= E1000_CTRL_FD;
1546
 
                *phy_ctrl |= MII_CR_FULL_DUPLEX;
1547
 
                DEBUGOUT("Full Duplex\n");
1548
 
        }
1549
 
 
1550
 
        /* Forcing 10mb or 100mb? */
1551
 
        if (mac->forced_speed_duplex & E1000_ALL_100_SPEED) {
1552
 
                ctrl |= E1000_CTRL_SPD_100;
1553
 
                *phy_ctrl |= MII_CR_SPEED_100;
1554
 
                *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1555
 
                DEBUGOUT("Forcing 100mb\n");
1556
 
        } else {
1557
 
                ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1558
 
                *phy_ctrl |= MII_CR_SPEED_10;
1559
 
                *phy_ctrl &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1560
 
                DEBUGOUT("Forcing 10mb\n");
1561
 
        }
1562
 
 
1563
 
        igb_config_collision_dist_generic(hw);
1564
 
 
1565
 
        E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
1566
 
}
1567
 
#endif
1568
 
 
1569
 
/**
1570
 
 *  igb_set_d3_lplu_state_generic - Sets low power link up state for D3
1571
 
 *  @hw: pointer to the HW structure
1572
 
 *  @active: boolean used to enable/disable lplu
1573
 
 *
1574
 
 *  Success returns 0, Failure returns 1
1575
 
 *
1576
 
 *  The low power link up (lplu) state is set to the power management level D3
1577
 
 *  and SmartSpeed is disabled when active is true, else clear lplu for D3
1578
 
 *  and enable Smartspeed.  LPLU and Smartspeed are mutually exclusive.  LPLU
1579
 
 *  is used during Dx states where the power conservation is most important.
1580
 
 *  During driver activity, SmartSpeed should be enabled so performance is
1581
 
 *  maintained.
1582
 
 **/
1583
 
s32 igb_set_d3_lplu_state_generic(struct e1000_hw *hw, bool active)
1584
 
{
1585
 
        struct e1000_phy_info *phy = &hw->phy;
1586
 
        s32 ret_val = E1000_SUCCESS;
1587
 
        u16 data;
1588
 
 
1589
 
        DEBUGFUNC("igb_set_d3_lplu_state_generic");
1590
 
 
1591
 
        if (!(hw->phy.ops.read_reg))
1592
 
                goto out;
1593
 
 
1594
 
        ret_val = phy->ops.read_reg(hw, IGP02E1000_PHY_POWER_MGMT, &data);
1595
 
        if (ret_val)
1596
 
                goto out;
1597
 
 
1598
 
        if (!active) {
1599
 
                data &= ~IGP02E1000_PM_D3_LPLU;
1600
 
                ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1601
 
                                             data);
1602
 
                if (ret_val)
1603
 
                        goto out;
1604
 
                /*
1605
 
                 * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
1606
 
                 * during Dx states where the power conservation is most
1607
 
                 * important.  During driver activity we should enable
1608
 
                 * SmartSpeed, so performance is maintained.
1609
 
                 */
1610
 
                if (phy->smart_speed == e1000_smart_speed_on) {
1611
 
                        ret_val = phy->ops.read_reg(hw,
1612
 
                                                    IGP01E1000_PHY_PORT_CONFIG,
1613
 
                                                    &data);
1614
 
                        if (ret_val)
1615
 
                                goto out;
1616
 
 
1617
 
                        data |= IGP01E1000_PSCFR_SMART_SPEED;
1618
 
                        ret_val = phy->ops.write_reg(hw,
1619
 
                                                     IGP01E1000_PHY_PORT_CONFIG,
1620
 
                                                     data);
1621
 
                        if (ret_val)
1622
 
                                goto out;
1623
 
                } else if (phy->smart_speed == e1000_smart_speed_off) {
1624
 
                        ret_val = phy->ops.read_reg(hw,
1625
 
                                                     IGP01E1000_PHY_PORT_CONFIG,
1626
 
                                                     &data);
1627
 
                        if (ret_val)
1628
 
                                goto out;
1629
 
 
1630
 
                        data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1631
 
                        ret_val = phy->ops.write_reg(hw,
1632
 
                                                     IGP01E1000_PHY_PORT_CONFIG,
1633
 
                                                     data);
1634
 
                        if (ret_val)
1635
 
                                goto out;
1636
 
                }
1637
 
        } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
1638
 
                   (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
1639
 
                   (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
1640
 
                data |= IGP02E1000_PM_D3_LPLU;
1641
 
                ret_val = phy->ops.write_reg(hw, IGP02E1000_PHY_POWER_MGMT,
1642
 
                                              data);
1643
 
                if (ret_val)
1644
 
                        goto out;
1645
 
 
1646
 
                /* When LPLU is enabled, we should disable SmartSpeed */
1647
 
                ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1648
 
                                             &data);
1649
 
                if (ret_val)
1650
 
                        goto out;
1651
 
 
1652
 
                data &= ~IGP01E1000_PSCFR_SMART_SPEED;
1653
 
                ret_val = phy->ops.write_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
1654
 
                                              data);
1655
 
        }
1656
 
 
1657
 
out:
1658
 
        return ret_val;
1659
 
}
1660
 
 
1661
 
/**
1662
 
 *  igb_check_downshift_generic - Checks whether a downshift in speed occurred
1663
 
 *  @hw: pointer to the HW structure
1664
 
 *
1665
 
 *  Success returns 0, Failure returns 1
1666
 
 *
1667
 
 *  A downshift is detected by querying the PHY link health.
1668
 
 **/
1669
 
s32 igb_check_downshift_generic(struct e1000_hw *hw)
1670
 
{
1671
 
        struct e1000_phy_info *phy = &hw->phy;
1672
 
        s32 ret_val;
1673
 
        u16 phy_data, offset, mask;
1674
 
 
1675
 
        DEBUGFUNC("igb_check_downshift_generic");
1676
 
 
1677
 
        switch (phy->type) {
1678
 
        case e1000_phy_m88:
1679
 
        case e1000_phy_gg82563:
1680
 
                offset  = M88E1000_PHY_SPEC_STATUS;
1681
 
                mask    = M88E1000_PSSR_DOWNSHIFT;
1682
 
                break;
1683
 
        case e1000_phy_igp_2:
1684
 
        case e1000_phy_igp:
1685
 
        case e1000_phy_igp_3:
1686
 
                offset  = IGP01E1000_PHY_LINK_HEALTH;
1687
 
                mask    = IGP01E1000_PLHR_SS_DOWNGRADE;
1688
 
                break;
1689
 
        default:
1690
 
                /* speed downshift not supported */
1691
 
                phy->speed_downgraded = false;
1692
 
                ret_val = E1000_SUCCESS;
1693
 
                goto out;
1694
 
        }
1695
 
 
1696
 
        ret_val = phy->ops.read_reg(hw, offset, &phy_data);
1697
 
 
1698
 
        if (!ret_val)
1699
 
                phy->speed_downgraded = (phy_data & mask) ? true : false;
1700
 
 
1701
 
out:
1702
 
        return ret_val;
1703
 
}
1704
 
 
1705
 
/**
1706
 
 *  igb_check_polarity_m88 - Checks the polarity.
1707
 
 *  @hw: pointer to the HW structure
1708
 
 *
1709
 
 *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1710
 
 *
1711
 
 *  Polarity is determined based on the PHY specific status register.
1712
 
 **/
1713
 
s32 igb_check_polarity_m88(struct e1000_hw *hw)
1714
 
{
1715
 
        struct e1000_phy_info *phy = &hw->phy;
1716
 
        s32 ret_val;
1717
 
        u16 data;
1718
 
 
1719
 
        DEBUGFUNC("igb_check_polarity_m88");
1720
 
 
1721
 
        ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &data);
1722
 
 
1723
 
        if (!ret_val)
1724
 
                phy->cable_polarity = (data & M88E1000_PSSR_REV_POLARITY)
1725
 
                                      ? e1000_rev_polarity_reversed
1726
 
                                      : e1000_rev_polarity_normal;
1727
 
 
1728
 
        return ret_val;
1729
 
}
1730
 
 
1731
 
/**
1732
 
 *  igb_check_polarity_igp - Checks the polarity.
1733
 
 *  @hw: pointer to the HW structure
1734
 
 *
1735
 
 *  Success returns 0, Failure returns -E1000_ERR_PHY (-2)
1736
 
 *
1737
 
 *  Polarity is determined based on the PHY port status register, and the
1738
 
 *  current speed (since there is no polarity at 100Mbps).
1739
 
 **/
1740
 
s32 igb_check_polarity_igp(struct e1000_hw *hw)
1741
 
{
1742
 
        struct e1000_phy_info *phy = &hw->phy;
1743
 
        s32 ret_val;
1744
 
        u16 data, offset, mask;
1745
 
 
1746
 
        DEBUGFUNC("igb_check_polarity_igp");
1747
 
 
1748
 
        /*
1749
 
         * Polarity is determined based on the speed of
1750
 
         * our connection.
1751
 
         */
1752
 
        ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
1753
 
        if (ret_val)
1754
 
                goto out;
1755
 
 
1756
 
        if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
1757
 
            IGP01E1000_PSSR_SPEED_1000MBPS) {
1758
 
                offset  = IGP01E1000_PHY_PCS_INIT_REG;
1759
 
                mask    = IGP01E1000_PHY_POLARITY_MASK;
1760
 
        } else {
1761
 
                /*
1762
 
                 * This really only applies to 10Mbps since
1763
 
                 * there is no polarity for 100Mbps (always 0).
1764
 
                 */
1765
 
                offset  = IGP01E1000_PHY_PORT_STATUS;
1766
 
                mask    = IGP01E1000_PSSR_POLARITY_REVERSED;
1767
 
        }
1768
 
 
1769
 
        ret_val = phy->ops.read_reg(hw, offset, &data);
1770
 
 
1771
 
        if (!ret_val)
1772
 
                phy->cable_polarity = (data & mask)
1773
 
                                      ? e1000_rev_polarity_reversed
1774
 
                                      : e1000_rev_polarity_normal;
1775
 
 
1776
 
out:
1777
 
        return ret_val;
1778
 
}
1779
 
 
1780
 
/**
1781
 
 *  igb_check_polarity_ife - Check cable polarity for IFE PHY
1782
 
 *  @hw: pointer to the HW structure
1783
 
 *
1784
 
 *  Polarity is determined on the polarity reversal feature being enabled.
1785
 
 **/
1786
 
s32 igb_check_polarity_ife(struct e1000_hw *hw)
1787
 
{
1788
 
        struct e1000_phy_info *phy = &hw->phy;
1789
 
        s32 ret_val;
1790
 
        u16 phy_data, offset, mask;
1791
 
 
1792
 
        DEBUGFUNC("igb_check_polarity_ife");
1793
 
 
1794
 
        /*
1795
 
         * Polarity is determined based on the reversal feature being enabled.
1796
 
         */
1797
 
        if (phy->polarity_correction) {
1798
 
                offset = IFE_PHY_EXTENDED_STATUS_CONTROL;
1799
 
                mask = IFE_PESC_POLARITY_REVERSED;
1800
 
        } else {
1801
 
                offset = IFE_PHY_SPECIAL_CONTROL;
1802
 
                mask = IFE_PSC_FORCE_POLARITY;
1803
 
        }
1804
 
 
1805
 
        ret_val = phy->ops.read_reg(hw, offset, &phy_data);
1806
 
 
1807
 
        if (!ret_val)
1808
 
                phy->cable_polarity = (phy_data & mask)
1809
 
                                       ? e1000_rev_polarity_reversed
1810
 
                                       : e1000_rev_polarity_normal;
1811
 
 
1812
 
        return ret_val;
1813
 
}
1814
 
 
1815
 
/**
1816
 
 *  igb_wait_autoneg_generic - Wait for auto-neg completion
1817
 
 *  @hw: pointer to the HW structure
1818
 
 *
1819
 
 *  Waits for auto-negotiation to complete or for the auto-negotiation time
1820
 
 *  limit to expire, which ever happens first.
1821
 
 **/
1822
 
s32 igb_wait_autoneg_generic(struct e1000_hw *hw)
1823
 
{
1824
 
        s32 ret_val = E1000_SUCCESS;
1825
 
        u16 i, phy_status;
1826
 
 
1827
 
        DEBUGFUNC("igb_wait_autoneg_generic");
1828
 
 
1829
 
        if (!(hw->phy.ops.read_reg))
1830
 
                return E1000_SUCCESS;
1831
 
 
1832
 
        /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
1833
 
        for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
1834
 
                ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1835
 
                if (ret_val)
1836
 
                        break;
1837
 
                ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1838
 
                if (ret_val)
1839
 
                        break;
1840
 
                if (phy_status & MII_SR_AUTONEG_COMPLETE)
1841
 
                        break;
1842
 
                msec_delay(100);
1843
 
        }
1844
 
 
1845
 
        /*
1846
 
         * PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
1847
 
         * has completed.
1848
 
         */
1849
 
        return ret_val;
1850
 
}
1851
 
 
1852
 
/**
1853
 
 *  igb_phy_has_link_generic - Polls PHY for link
1854
 
 *  @hw: pointer to the HW structure
1855
 
 *  @iterations: number of times to poll for link
1856
 
 *  @usec_interval: delay between polling attempts
1857
 
 *  @success: pointer to whether polling was successful or not
1858
 
 *
1859
 
 *  Polls the PHY status register for link, 'iterations' number of times.
1860
 
 **/
1861
 
s32 igb_phy_has_link_generic(struct e1000_hw *hw, u32 iterations,
1862
 
                               u32 usec_interval, bool *success)
1863
 
{
1864
 
        s32 ret_val = E1000_SUCCESS;
1865
 
        u16 i, phy_status;
1866
 
 
1867
 
        DEBUGFUNC("igb_phy_has_link_generic");
1868
 
 
1869
 
        if (!(hw->phy.ops.read_reg))
1870
 
                return E1000_SUCCESS;
1871
 
 
1872
 
        for (i = 0; i < iterations; i++) {
1873
 
                /*
1874
 
                 * Some PHYs require the PHY_STATUS register to be read
1875
 
                 * twice due to the link bit being sticky.  No harm doing
1876
 
                 * it across the board.
1877
 
                 */
1878
 
                ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1879
 
                if (ret_val) {
1880
 
                        /*
1881
 
                         * If the first read fails, another entity may have
1882
 
                         * ownership of the resources, wait and try again to
1883
 
                         * see if they have relinquished the resources yet.
1884
 
                         */
1885
 
                        usec_delay(usec_interval);
1886
 
                }
1887
 
                ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
1888
 
                if (ret_val)
1889
 
                        break;
1890
 
                if (phy_status & MII_SR_LINK_STATUS)
1891
 
                        break;
1892
 
                if (usec_interval >= 1000)
1893
 
                        msec_delay_irq(usec_interval/1000);
1894
 
                else
1895
 
                        usec_delay(usec_interval);
1896
 
        }
1897
 
 
1898
 
        *success = (i < iterations) ? true : false;
1899
 
 
1900
 
        return ret_val;
1901
 
}
1902
 
 
1903
 
#if 0
1904
 
/**
1905
 
 *  igb_get_cable_length_m88 - Determine cable length for m88 PHY
1906
 
 *  @hw: pointer to the HW structure
1907
 
 *
1908
 
 *  Reads the PHY specific status register to retrieve the cable length
1909
 
 *  information.  The cable length is determined by averaging the minimum and
1910
 
 *  maximum values to get the "average" cable length.  The m88 PHY has four
1911
 
 *  possible cable length values, which are:
1912
 
 *      Register Value          Cable Length
1913
 
 *      0                       < 50 meters
1914
 
 *      1                       50 - 80 meters
1915
 
 *      2                       80 - 110 meters
1916
 
 *      3                       110 - 140 meters
1917
 
 *      4                       > 140 meters
1918
 
 **/
1919
 
s32 igb_get_cable_length_m88(struct e1000_hw *hw)
1920
 
{
1921
 
        struct e1000_phy_info *phy = &hw->phy;
1922
 
        s32 ret_val;
1923
 
        u16 phy_data, index;
1924
 
 
1925
 
        DEBUGFUNC("igb_get_cable_length_m88");
1926
 
 
1927
 
        ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
1928
 
        if (ret_val)
1929
 
                goto out;
1930
 
 
1931
 
        index = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
1932
 
                M88E1000_PSSR_CABLE_LENGTH_SHIFT;
1933
 
        if (index >= M88E1000_CABLE_LENGTH_TABLE_SIZE - 1) {
1934
 
                ret_val = -E1000_ERR_PHY;
1935
 
                goto out;
1936
 
        }
1937
 
 
1938
 
        phy->min_cable_length = e1000_m88_cable_length_table[index];
1939
 
        phy->max_cable_length = e1000_m88_cable_length_table[index + 1];
1940
 
 
1941
 
        phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
1942
 
 
1943
 
out:
1944
 
        return ret_val;
1945
 
}
1946
 
 
1947
 
/**
1948
 
 *  igb_get_cable_length_igp_2 - Determine cable length for igp2 PHY
1949
 
 *  @hw: pointer to the HW structure
1950
 
 *
1951
 
 *  The automatic gain control (agc) normalizes the amplitude of the
1952
 
 *  received signal, adjusting for the attenuation produced by the
1953
 
 *  cable.  By reading the AGC registers, which represent the
1954
 
 *  combination of coarse and fine gain value, the value can be put
1955
 
 *  into a lookup table to obtain the approximate cable length
1956
 
 *  for each channel.
1957
 
 **/
1958
 
s32 igb_get_cable_length_igp_2(struct e1000_hw *hw)
1959
 
{
1960
 
        struct e1000_phy_info *phy = &hw->phy;
1961
 
        s32 ret_val = E1000_SUCCESS;
1962
 
        u16 phy_data, i, agc_value = 0;
1963
 
        u16 cur_agc_index, max_agc_index = 0;
1964
 
        u16 min_agc_index = IGP02E1000_CABLE_LENGTH_TABLE_SIZE - 1;
1965
 
        u16 agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
1966
 
                                                         {IGP02E1000_PHY_AGC_A,
1967
 
                                                          IGP02E1000_PHY_AGC_B,
1968
 
                                                          IGP02E1000_PHY_AGC_C,
1969
 
                                                          IGP02E1000_PHY_AGC_D};
1970
 
 
1971
 
        DEBUGFUNC("igb_get_cable_length_igp_2");
1972
 
 
1973
 
        /* Read the AGC registers for all channels */
1974
 
        for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
1975
 
                ret_val = phy->ops.read_reg(hw, agc_reg_array[i], &phy_data);
1976
 
                if (ret_val)
1977
 
                        goto out;
1978
 
 
1979
 
                /*
1980
 
                 * Getting bits 15:9, which represent the combination of
1981
 
                 * coarse and fine gain values.  The result is a number
1982
 
                 * that can be put into the lookup table to obtain the
1983
 
                 * approximate cable length.
1984
 
                 */
1985
 
                cur_agc_index = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
1986
 
                                IGP02E1000_AGC_LENGTH_MASK;
1987
 
 
1988
 
                /* Array index bound check. */
1989
 
                if ((cur_agc_index >= IGP02E1000_CABLE_LENGTH_TABLE_SIZE) ||
1990
 
                    (cur_agc_index == 0)) {
1991
 
                        ret_val = -E1000_ERR_PHY;
1992
 
                        goto out;
1993
 
                }
1994
 
 
1995
 
                /* Remove min & max AGC values from calculation. */
1996
 
                if (e1000_igp_2_cable_length_table[min_agc_index] >
1997
 
                    e1000_igp_2_cable_length_table[cur_agc_index])
1998
 
                        min_agc_index = cur_agc_index;
1999
 
                if (e1000_igp_2_cable_length_table[max_agc_index] <
2000
 
                    e1000_igp_2_cable_length_table[cur_agc_index])
2001
 
                        max_agc_index = cur_agc_index;
2002
 
 
2003
 
                agc_value += e1000_igp_2_cable_length_table[cur_agc_index];
2004
 
        }
2005
 
 
2006
 
        agc_value -= (e1000_igp_2_cable_length_table[min_agc_index] +
2007
 
                      e1000_igp_2_cable_length_table[max_agc_index]);
2008
 
        agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
2009
 
 
2010
 
        /* Calculate cable length with the error range of +/- 10 meters. */
2011
 
        phy->min_cable_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
2012
 
                                 (agc_value - IGP02E1000_AGC_RANGE) : 0;
2013
 
        phy->max_cable_length = agc_value + IGP02E1000_AGC_RANGE;
2014
 
 
2015
 
        phy->cable_length = (phy->min_cable_length + phy->max_cable_length) / 2;
2016
 
 
2017
 
out:
2018
 
        return ret_val;
2019
 
}
2020
 
#endif
2021
 
 
2022
 
/**
2023
 
 *  igb_get_phy_info_m88 - Retrieve PHY information
2024
 
 *  @hw: pointer to the HW structure
2025
 
 *
2026
 
 *  Valid for only copper links.  Read the PHY status register (sticky read)
2027
 
 *  to verify that link is up.  Read the PHY special control register to
2028
 
 *  determine the polarity and 10base-T extended distance.  Read the PHY
2029
 
 *  special status register to determine MDI/MDIx and current speed.  If
2030
 
 *  speed is 1000, then determine cable length, local and remote receiver.
2031
 
 **/
2032
 
s32 igb_get_phy_info_m88(struct e1000_hw *hw)
2033
 
{
2034
 
        struct e1000_phy_info *phy = &hw->phy;
2035
 
        s32  ret_val;
2036
 
        u16 phy_data;
2037
 
        bool link;
2038
 
 
2039
 
        DEBUGFUNC("igb_get_phy_info_m88");
2040
 
 
2041
 
        if (phy->media_type != e1000_media_type_copper) {
2042
 
                DEBUGOUT("Phy info is only valid for copper media\n");
2043
 
                ret_val = -E1000_ERR_CONFIG;
2044
 
                goto out;
2045
 
        }
2046
 
 
2047
 
        ret_val = igb_phy_has_link_generic(hw, 1, 0, &link);
2048
 
        if (ret_val)
2049
 
                goto out;
2050
 
 
2051
 
        if (!link) {
2052
 
                DEBUGOUT("Phy info is only valid if link is up\n");
2053
 
                ret_val = -E1000_ERR_CONFIG;
2054
 
                goto out;
2055
 
        }
2056
 
 
2057
 
        ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
2058
 
        if (ret_val)
2059
 
                goto out;
2060
 
 
2061
 
        phy->polarity_correction = (phy_data & M88E1000_PSCR_POLARITY_REVERSAL)
2062
 
                                   ? true : false;
2063
 
 
2064
 
        ret_val = igb_check_polarity_m88(hw);
2065
 
        if (ret_val)
2066
 
                goto out;
2067
 
 
2068
 
        ret_val = phy->ops.read_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
2069
 
        if (ret_val)
2070
 
                goto out;
2071
 
 
2072
 
        phy->is_mdix = (phy_data & M88E1000_PSSR_MDIX) ? true : false;
2073
 
 
2074
 
        if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
2075
 
#if 0
2076
 
                ret_val = hw->phy.ops.get_cable_length(hw);
2077
 
#endif
2078
 
                ret_val = -E1000_ERR_CONFIG;
2079
 
                if (ret_val)
2080
 
                        goto out;
2081
 
#if 0
2082
 
                ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &phy_data);
2083
 
                if (ret_val)
2084
 
                        goto out;
2085
 
 
2086
 
                phy->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS)
2087
 
                                ? e1000_1000t_rx_status_ok
2088
 
                                : e1000_1000t_rx_status_not_ok;
2089
 
 
2090
 
                phy->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS)
2091
 
                                 ? e1000_1000t_rx_status_ok
2092
 
                                 : e1000_1000t_rx_status_not_ok;
2093
 
#endif
2094
 
        } else {
2095
 
                /* Set values to "undefined" */
2096
 
                phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2097
 
                phy->local_rx = e1000_1000t_rx_status_undefined;
2098
 
                phy->remote_rx = e1000_1000t_rx_status_undefined;
2099
 
        }
2100
 
 
2101
 
out:
2102
 
        return ret_val;
2103
 
}
2104
 
 
2105
 
/**
2106
 
 *  igb_get_phy_info_igp - Retrieve igp PHY information
2107
 
 *  @hw: pointer to the HW structure
2108
 
 *
2109
 
 *  Read PHY status to determine if link is up.  If link is up, then
2110
 
 *  set/determine 10base-T extended distance and polarity correction.  Read
2111
 
 *  PHY port status to determine MDI/MDIx and speed.  Based on the speed,
2112
 
 *  determine on the cable length, local and remote receiver.
2113
 
 **/
2114
 
s32 igb_get_phy_info_igp(struct e1000_hw *hw)
2115
 
{
2116
 
        struct e1000_phy_info *phy = &hw->phy;
2117
 
        s32 ret_val;
2118
 
        u16 data;
2119
 
        bool link;
2120
 
 
2121
 
        DEBUGFUNC("igb_get_phy_info_igp");
2122
 
 
2123
 
        ret_val = igb_phy_has_link_generic(hw, 1, 0, &link);
2124
 
        if (ret_val)
2125
 
                goto out;
2126
 
 
2127
 
        if (!link) {
2128
 
                DEBUGOUT("Phy info is only valid if link is up\n");
2129
 
                ret_val = -E1000_ERR_CONFIG;
2130
 
                goto out;
2131
 
        }
2132
 
 
2133
 
        phy->polarity_correction = true;
2134
 
 
2135
 
        ret_val = igb_check_polarity_igp(hw);
2136
 
        if (ret_val)
2137
 
                goto out;
2138
 
 
2139
 
        ret_val = phy->ops.read_reg(hw, IGP01E1000_PHY_PORT_STATUS, &data);
2140
 
        if (ret_val)
2141
 
                goto out;
2142
 
 
2143
 
        phy->is_mdix = (data & IGP01E1000_PSSR_MDIX) ? true : false;
2144
 
 
2145
 
        if ((data & IGP01E1000_PSSR_SPEED_MASK) ==
2146
 
            IGP01E1000_PSSR_SPEED_1000MBPS) {
2147
 
#if 0
2148
 
                ret_val = phy->ops.get_cable_length(hw);
2149
 
#endif
2150
 
                ret_val = -E1000_ERR_CONFIG;
2151
 
                if (ret_val)
2152
 
                        goto out;
2153
 
#if 0
2154
 
                ret_val = phy->ops.read_reg(hw, PHY_1000T_STATUS, &data);
2155
 
                if (ret_val)
2156
 
                        goto out;
2157
 
 
2158
 
                phy->local_rx = (data & SR_1000T_LOCAL_RX_STATUS)
2159
 
                                ? e1000_1000t_rx_status_ok
2160
 
                                : e1000_1000t_rx_status_not_ok;
2161
 
 
2162
 
                phy->remote_rx = (data & SR_1000T_REMOTE_RX_STATUS)
2163
 
                                 ? e1000_1000t_rx_status_ok
2164
 
                                 : e1000_1000t_rx_status_not_ok;
2165
 
#endif
2166
 
        } else {
2167
 
                phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
2168
 
                phy->local_rx = e1000_1000t_rx_status_undefined;
2169
 
                phy->remote_rx = e1000_1000t_rx_status_undefined;
2170
 
        }
2171
 
 
2172
 
out:
2173
 
        return ret_val;
2174
 
}
2175
 
 
2176
 
/**
2177
 
 *  igb_phy_sw_reset_generic - PHY software reset
2178
 
 *  @hw: pointer to the HW structure
2179
 
 *
2180
 
 *  Does a software reset of the PHY by reading the PHY control register and
2181
 
 *  setting/write the control register reset bit to the PHY.
2182
 
 **/
2183
 
s32 igb_phy_sw_reset_generic(struct e1000_hw *hw)
2184
 
{
2185
 
        s32 ret_val = E1000_SUCCESS;
2186
 
        u16 phy_ctrl;
2187
 
 
2188
 
        DEBUGFUNC("igb_phy_sw_reset_generic");
2189
 
 
2190
 
        if (!(hw->phy.ops.read_reg))
2191
 
                goto out;
2192
 
 
2193
 
        ret_val = hw->phy.ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
2194
 
        if (ret_val)
2195
 
                goto out;
2196
 
 
2197
 
        phy_ctrl |= MII_CR_RESET;
2198
 
        ret_val = hw->phy.ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
2199
 
        if (ret_val)
2200
 
                goto out;
2201
 
 
2202
 
        usec_delay(1);
2203
 
 
2204
 
out:
2205
 
        return ret_val;
2206
 
}
2207
 
 
2208
 
/**
2209
 
 *  igb_phy_hw_reset_generic - PHY hardware reset
2210
 
 *  @hw: pointer to the HW structure
2211
 
 *
2212
 
 *  Verify the reset block is not blocking us from resetting.  Acquire
2213
 
 *  semaphore (if necessary) and read/set/write the device control reset
2214
 
 *  bit in the PHY.  Wait the appropriate delay time for the device to
2215
 
 *  reset and release the semaphore (if necessary).
2216
 
 **/
2217
 
s32 igb_phy_hw_reset_generic(struct e1000_hw *hw)
2218
 
{
2219
 
        struct e1000_phy_info *phy = &hw->phy;
2220
 
        s32 ret_val = E1000_SUCCESS;
2221
 
        u32 ctrl;
2222
 
 
2223
 
        DEBUGFUNC("igb_phy_hw_reset_generic");
2224
 
 
2225
 
        ret_val = phy->ops.check_reset_block(hw);
2226
 
        if (ret_val) {
2227
 
                ret_val = E1000_SUCCESS;
2228
 
                goto out;
2229
 
        }
2230
 
 
2231
 
        ret_val = phy->ops.acquire(hw);
2232
 
        if (ret_val)
2233
 
                goto out;
2234
 
 
2235
 
        ctrl = E1000_READ_REG(hw, E1000_CTRL);
2236
 
        E1000_WRITE_REG(hw, E1000_CTRL, ctrl | E1000_CTRL_PHY_RST);
2237
 
        E1000_WRITE_FLUSH(hw);
2238
 
 
2239
 
        usec_delay(phy->reset_delay_us);
2240
 
 
2241
 
        E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
2242
 
        E1000_WRITE_FLUSH(hw);
2243
 
 
2244
 
        usec_delay(150);
2245
 
 
2246
 
        phy->ops.release(hw);
2247
 
 
2248
 
        ret_val = phy->ops.get_cfg_done(hw);
2249
 
 
2250
 
out:
2251
 
        return ret_val;
2252
 
}
2253
 
 
2254
 
/**
2255
 
 *  igb_get_cfg_done_generic - Generic configuration done
2256
 
 *  @hw: pointer to the HW structure
2257
 
 *
2258
 
 *  Generic function to wait 10 milli-seconds for configuration to complete
2259
 
 *  and return success.
2260
 
 **/
2261
 
s32 igb_get_cfg_done_generic(struct e1000_hw *hw __unused)
2262
 
{
2263
 
        DEBUGFUNC("igb_get_cfg_done_generic");
2264
 
 
2265
 
        msec_delay_irq(10);
2266
 
 
2267
 
        return E1000_SUCCESS;
2268
 
}
2269
 
 
2270
 
/**
2271
 
 *  igb_phy_init_script_igp3 - Inits the IGP3 PHY
2272
 
 *  @hw: pointer to the HW structure
2273
 
 *
2274
 
 *  Initializes a Intel Gigabit PHY3 when an EEPROM is not present.
2275
 
 **/
2276
 
s32 igb_phy_init_script_igp3(struct e1000_hw *hw)
2277
 
{
2278
 
        DEBUGOUT("Running IGP 3 PHY init script\n");
2279
 
 
2280
 
        /* PHY init IGP 3 */
2281
 
        /* Enable rise/fall, 10-mode work in class-A */
2282
 
        hw->phy.ops.write_reg(hw, 0x2F5B, 0x9018);
2283
 
        /* Remove all caps from Replica path filter */
2284
 
        hw->phy.ops.write_reg(hw, 0x2F52, 0x0000);
2285
 
        /* Bias trimming for ADC, AFE and Driver (Default) */
2286
 
        hw->phy.ops.write_reg(hw, 0x2FB1, 0x8B24);
2287
 
        /* Increase Hybrid poly bias */
2288
 
        hw->phy.ops.write_reg(hw, 0x2FB2, 0xF8F0);
2289
 
        /* Add 4% to Tx amplitude in Gig mode */
2290
 
        hw->phy.ops.write_reg(hw, 0x2010, 0x10B0);
2291
 
        /* Disable trimming (TTT) */
2292
 
        hw->phy.ops.write_reg(hw, 0x2011, 0x0000);
2293
 
        /* Poly DC correction to 94.6% + 2% for all channels */
2294
 
        hw->phy.ops.write_reg(hw, 0x20DD, 0x249A);
2295
 
        /* ABS DC correction to 95.9% */
2296
 
        hw->phy.ops.write_reg(hw, 0x20DE, 0x00D3);
2297
 
        /* BG temp curve trim */
2298
 
        hw->phy.ops.write_reg(hw, 0x28B4, 0x04CE);
2299
 
        /* Increasing ADC OPAMP stage 1 currents to max */
2300
 
        hw->phy.ops.write_reg(hw, 0x2F70, 0x29E4);
2301
 
        /* Force 1000 ( required for enabling PHY regs configuration) */
2302
 
        hw->phy.ops.write_reg(hw, 0x0000, 0x0140);
2303
 
        /* Set upd_freq to 6 */
2304
 
        hw->phy.ops.write_reg(hw, 0x1F30, 0x1606);
2305
 
        /* Disable NPDFE */
2306
 
        hw->phy.ops.write_reg(hw, 0x1F31, 0xB814);
2307
 
        /* Disable adaptive fixed FFE (Default) */
2308
 
        hw->phy.ops.write_reg(hw, 0x1F35, 0x002A);
2309
 
        /* Enable FFE hysteresis */
2310
 
        hw->phy.ops.write_reg(hw, 0x1F3E, 0x0067);
2311
 
        /* Fixed FFE for short cable lengths */
2312
 
        hw->phy.ops.write_reg(hw, 0x1F54, 0x0065);
2313
 
        /* Fixed FFE for medium cable lengths */
2314
 
        hw->phy.ops.write_reg(hw, 0x1F55, 0x002A);
2315
 
        /* Fixed FFE for long cable lengths */
2316
 
        hw->phy.ops.write_reg(hw, 0x1F56, 0x002A);
2317
 
        /* Enable Adaptive Clip Threshold */
2318
 
        hw->phy.ops.write_reg(hw, 0x1F72, 0x3FB0);
2319
 
        /* AHT reset limit to 1 */
2320
 
        hw->phy.ops.write_reg(hw, 0x1F76, 0xC0FF);
2321
 
        /* Set AHT master delay to 127 msec */
2322
 
        hw->phy.ops.write_reg(hw, 0x1F77, 0x1DEC);
2323
 
        /* Set scan bits for AHT */
2324
 
        hw->phy.ops.write_reg(hw, 0x1F78, 0xF9EF);
2325
 
        /* Set AHT Preset bits */
2326
 
        hw->phy.ops.write_reg(hw, 0x1F79, 0x0210);
2327
 
        /* Change integ_factor of channel A to 3 */
2328
 
        hw->phy.ops.write_reg(hw, 0x1895, 0x0003);
2329
 
        /* Change prop_factor of channels BCD to 8 */
2330
 
        hw->phy.ops.write_reg(hw, 0x1796, 0x0008);
2331
 
        /* Change cg_icount + enable integbp for channels BCD */
2332
 
        hw->phy.ops.write_reg(hw, 0x1798, 0xD008);
2333
 
        /*
2334
 
         * Change cg_icount + enable integbp + change prop_factor_master
2335
 
         * to 8 for channel A
2336
 
         */
2337
 
        hw->phy.ops.write_reg(hw, 0x1898, 0xD918);
2338
 
        /* Disable AHT in Slave mode on channel A */
2339
 
        hw->phy.ops.write_reg(hw, 0x187A, 0x0800);
2340
 
        /*
2341
 
         * Enable LPLU and disable AN to 1000 in non-D0a states,
2342
 
         * Enable SPD+B2B
2343
 
         */
2344
 
        hw->phy.ops.write_reg(hw, 0x0019, 0x008D);
2345
 
        /* Enable restart AN on an1000_dis change */
2346
 
        hw->phy.ops.write_reg(hw, 0x001B, 0x2080);
2347
 
        /* Enable wh_fifo read clock in 10/100 modes */
2348
 
        hw->phy.ops.write_reg(hw, 0x0014, 0x0045);
2349
 
        /* Restart AN, Speed selection is 1000 */
2350
 
        hw->phy.ops.write_reg(hw, 0x0000, 0x1340);
2351
 
 
2352
 
        return E1000_SUCCESS;
2353
 
}
2354
 
 
2355
 
/**
2356
 
 *  igb_get_phy_type_from_id - Get PHY type from id
2357
 
 *  @phy_id: phy_id read from the phy
2358
 
 *
2359
 
 *  Returns the phy type from the id.
2360
 
 **/
2361
 
enum e1000_phy_type igb_get_phy_type_from_id(u32 phy_id)
2362
 
{
2363
 
        enum e1000_phy_type phy_type = e1000_phy_unknown;
2364
 
 
2365
 
        switch (phy_id) {
2366
 
        case M88E1000_I_PHY_ID:
2367
 
        case M88E1000_E_PHY_ID:
2368
 
        case M88E1111_I_PHY_ID:
2369
 
        case M88E1011_I_PHY_ID:
2370
 
                phy_type = e1000_phy_m88;
2371
 
                break;
2372
 
        case IGP01E1000_I_PHY_ID: /* IGP 1 & 2 share this */
2373
 
                phy_type = e1000_phy_igp_2;
2374
 
                break;
2375
 
        case GG82563_E_PHY_ID:
2376
 
                phy_type = e1000_phy_gg82563;
2377
 
                break;
2378
 
        case IGP03E1000_E_PHY_ID:
2379
 
                phy_type = e1000_phy_igp_3;
2380
 
                break;
2381
 
        case IFE_E_PHY_ID:
2382
 
        case IFE_PLUS_E_PHY_ID:
2383
 
        case IFE_C_E_PHY_ID:
2384
 
                phy_type = e1000_phy_ife;
2385
 
                break;
2386
 
        default:
2387
 
                phy_type = e1000_phy_unknown;
2388
 
                break;
2389
 
        }
2390
 
        return phy_type;
2391
 
}
2392
 
 
2393
 
/**
2394
 
 *  igb_determine_phy_address - Determines PHY address.
2395
 
 *  @hw: pointer to the HW structure
2396
 
 *
2397
 
 *  This uses a trial and error method to loop through possible PHY
2398
 
 *  addresses. It tests each by reading the PHY ID registers and
2399
 
 *  checking for a match.
2400
 
 **/
2401
 
s32 igb_determine_phy_address(struct e1000_hw *hw)
2402
 
{
2403
 
        s32 ret_val = -E1000_ERR_PHY_TYPE;
2404
 
        u32 phy_addr = 0;
2405
 
        u32 i;
2406
 
        enum e1000_phy_type phy_type = e1000_phy_unknown;
2407
 
 
2408
 
        hw->phy.id = phy_type;
2409
 
 
2410
 
        for (phy_addr = 0; phy_addr < E1000_MAX_PHY_ADDR; phy_addr++) {
2411
 
                hw->phy.addr = phy_addr;
2412
 
                i = 0;
2413
 
 
2414
 
                do {
2415
 
                        igb_get_phy_id(hw);
2416
 
                        phy_type = igb_get_phy_type_from_id(hw->phy.id);
2417
 
 
2418
 
                        /*
2419
 
                         * If phy_type is valid, break - we found our
2420
 
                         * PHY address
2421
 
                         */
2422
 
                        if (phy_type  != e1000_phy_unknown) {
2423
 
                                ret_val = E1000_SUCCESS;
2424
 
                                goto out;
2425
 
                        }
2426
 
                        msec_delay(1);
2427
 
                        i++;
2428
 
                } while (i < 10);
2429
 
        }
2430
 
 
2431
 
out:
2432
 
        return ret_val;
2433
 
}
2434
 
 
2435
 
/**
2436
 
 * igb_power_up_phy_copper - Restore copper link in case of PHY power down
2437
 
 * @hw: pointer to the HW structure
2438
 
 *
2439
 
 * In the case of a PHY power down to save power, or to turn off link during a
2440
 
 * driver unload, or wake on lan is not enabled, restore the link to previous
2441
 
 * settings.
2442
 
 **/
2443
 
void igb_power_up_phy_copper(struct e1000_hw *hw)
2444
 
{
2445
 
        u16 mii_reg = 0;
2446
 
 
2447
 
        /* The PHY will retain its settings across a power down/up cycle */
2448
 
        hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2449
 
        mii_reg &= ~MII_CR_POWER_DOWN;
2450
 
        hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2451
 
}
2452
 
 
2453
 
/**
2454
 
 * igb_power_down_phy_copper - Restore copper link in case of PHY power down
2455
 
 * @hw: pointer to the HW structure
2456
 
 *
2457
 
 * In the case of a PHY power down to save power, or to turn off link during a
2458
 
 * driver unload, or wake on lan is not enabled, restore the link to previous
2459
 
 * settings.
2460
 
 **/
2461
 
void igb_power_down_phy_copper(struct e1000_hw *hw)
2462
 
{
2463
 
        u16 mii_reg = 0;
2464
 
 
2465
 
        /* The PHY will retain its settings across a power down/up cycle */
2466
 
        hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
2467
 
        mii_reg |= MII_CR_POWER_DOWN;
2468
 
        hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
2469
 
        msec_delay(1);
2470
 
}