OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [net/] [e1000/] [e1000_hw.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*******************************************************************************
2
 
3
 
4
  Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
5
 
6
  This program is free software; you can redistribute it and/or modify it
7
  under the terms of the GNU General Public License as published by the Free
8
  Software Foundation; either version 2 of the License, or (at your option)
9
  any later version.
10
 
11
  This program is distributed in the hope that it will be useful, but WITHOUT
12
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14
  more details.
15
 
16
  You should have received a copy of the GNU General Public License along with
17
  this program; if not, write to the Free Software Foundation, Inc., 59
18
  Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
 
20
  The full GNU General Public License is included in this distribution in the
21
  file called LICENSE.
22
 
23
  Contact Information:
24
  Linux NICS <linux.nics@intel.com>
25
  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
 
27
*******************************************************************************/
28
 
29
/* e1000_hw.c
30
 * Shared functions for accessing and configuring the MAC
31
 */
32
 
33
#include "e1000_hw.h"
34
 
35
static int32_t e1000_set_phy_type(struct e1000_hw *hw);
36
static void e1000_phy_init_script(struct e1000_hw *hw);
37
static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
38
static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
39
static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
40
static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
41
static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
42
static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
43
static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
44
static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
45
                                     uint16_t count);
46
static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
47
static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
48
static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
49
                                      uint16_t words, uint16_t *data);
50
static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
51
                                            uint16_t offset, uint16_t words,
52
                                            uint16_t *data);
53
static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
54
static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
55
static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
56
static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
57
                                    uint16_t count);
58
static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
59
                                      uint16_t phy_data);
60
static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
61
                                     uint16_t *phy_data);
62
static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
63
static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
64
static void e1000_release_eeprom(struct e1000_hw *hw);
65
static void e1000_standby_eeprom(struct e1000_hw *hw);
66
static int32_t e1000_id_led_init(struct e1000_hw * hw);
67
static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
68
 
69
/* IGP cable length table */
70
static const
71
uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
72
    { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
73
      5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
74
      25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
75
      40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
76
      60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
77
      90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
78
      100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
79
      110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
80
 
81
 
82
/******************************************************************************
83
 * Set the phy type member in the hw struct.
84
 *
85
 * hw - Struct containing variables accessed by shared code
86
 *****************************************************************************/
87
int32_t
88
e1000_set_phy_type(struct e1000_hw *hw)
89
{
90
    DEBUGFUNC("e1000_set_phy_type");
91
 
92
    switch(hw->phy_id) {
93
    case M88E1000_E_PHY_ID:
94
    case M88E1000_I_PHY_ID:
95
    case M88E1011_I_PHY_ID:
96
        hw->phy_type = e1000_phy_m88;
97
        break;
98
    case IGP01E1000_I_PHY_ID:
99
        if(hw->mac_type == e1000_82541 ||
100
           hw->mac_type == e1000_82541_rev_2 ||
101
           hw->mac_type == e1000_82547 ||
102
           hw->mac_type == e1000_82547_rev_2) {
103
            hw->phy_type = e1000_phy_igp;
104
            break;
105
        }
106
        /* Fall Through */
107
    default:
108
        /* Should never have loaded on this device */
109
        hw->phy_type = e1000_phy_undefined;
110
        return -E1000_ERR_PHY_TYPE;
111
    }
112
 
113
    return E1000_SUCCESS;
114
}
115
 
116
/******************************************************************************
117
 * IGP phy init script - initializes the GbE PHY
118
 *
119
 * hw - Struct containing variables accessed by shared code
120
 *****************************************************************************/
121
static void
122
e1000_phy_init_script(struct e1000_hw *hw)
123
{
124
    DEBUGFUNC("e1000_phy_init_script");
125
 
126
    if(hw->phy_init_script) {
127
        msec_delay(20);
128
 
129
        e1000_write_phy_reg(hw,0x0000,0x0140);
130
 
131
        msec_delay(5);
132
 
133
        if(hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547) {
134
            e1000_write_phy_reg(hw, 0x1F95, 0x0001);
135
 
136
            e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
137
 
138
            e1000_write_phy_reg(hw, 0x1F79, 0x0018);
139
 
140
            e1000_write_phy_reg(hw, 0x1F30, 0x1600);
141
 
142
            e1000_write_phy_reg(hw, 0x1F31, 0x0014);
143
 
144
            e1000_write_phy_reg(hw, 0x1F32, 0x161C);
145
 
146
            e1000_write_phy_reg(hw, 0x1F94, 0x0003);
147
 
148
            e1000_write_phy_reg(hw, 0x1F96, 0x003F);
149
 
150
            e1000_write_phy_reg(hw, 0x2010, 0x0008);
151
        } else {
152
            e1000_write_phy_reg(hw, 0x1F73, 0x0099);
153
        }
154
 
155
        e1000_write_phy_reg(hw, 0x0000, 0x3300);
156
 
157
        if(hw->mac_type == e1000_82547) {
158
            uint16_t fused, fine, coarse;
159
 
160
            /* Move to analog registers page */
161
            e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
162
 
163
            if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
164
                e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
165
 
166
                fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
167
                coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
168
 
169
                if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
170
                    coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
171
                    fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
172
                } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
173
                    fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
174
 
175
                fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
176
                        (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
177
                        (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
178
 
179
                e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
180
                e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
181
                                    IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
182
            }
183
        }
184
    }
185
}
186
 
187
/******************************************************************************
188
 * Set the mac type member in the hw struct.
189
 *
190
 * hw - Struct containing variables accessed by shared code
191
 *****************************************************************************/
192
int32_t
193
e1000_set_mac_type(struct e1000_hw *hw)
194
{
195
    DEBUGFUNC("e1000_set_mac_type");
196
 
197
    switch (hw->device_id) {
198
    case E1000_DEV_ID_82542:
199
        switch (hw->revision_id) {
200
        case E1000_82542_2_0_REV_ID:
201
            hw->mac_type = e1000_82542_rev2_0;
202
            break;
203
        case E1000_82542_2_1_REV_ID:
204
            hw->mac_type = e1000_82542_rev2_1;
205
            break;
206
        default:
207
            /* Invalid 82542 revision ID */
208
            return -E1000_ERR_MAC_TYPE;
209
        }
210
        break;
211
    case E1000_DEV_ID_82543GC_FIBER:
212
    case E1000_DEV_ID_82543GC_COPPER:
213
        hw->mac_type = e1000_82543;
214
        break;
215
    case E1000_DEV_ID_82544EI_COPPER:
216
    case E1000_DEV_ID_82544EI_FIBER:
217
    case E1000_DEV_ID_82544GC_COPPER:
218
    case E1000_DEV_ID_82544GC_LOM:
219
        hw->mac_type = e1000_82544;
220
        break;
221
    case E1000_DEV_ID_82540EM:
222
    case E1000_DEV_ID_82540EM_LOM:
223
    case E1000_DEV_ID_82540EP:
224
    case E1000_DEV_ID_82540EP_LOM:
225
    case E1000_DEV_ID_82540EP_LP:
226
        hw->mac_type = e1000_82540;
227
        break;
228
    case E1000_DEV_ID_82545EM_COPPER:
229
    case E1000_DEV_ID_82545EM_FIBER:
230
        hw->mac_type = e1000_82545;
231
        break;
232
    case E1000_DEV_ID_82545GM_COPPER:
233
    case E1000_DEV_ID_82545GM_FIBER:
234
    case E1000_DEV_ID_82545GM_SERDES:
235
        hw->mac_type = e1000_82545_rev_3;
236
        break;
237
    case E1000_DEV_ID_82546EB_COPPER:
238
    case E1000_DEV_ID_82546EB_FIBER:
239
    case E1000_DEV_ID_82546EB_QUAD_COPPER:
240
        hw->mac_type = e1000_82546;
241
        break;
242
    case E1000_DEV_ID_82546GB_COPPER:
243
    case E1000_DEV_ID_82546GB_FIBER:
244
    case E1000_DEV_ID_82546GB_SERDES:
245
        hw->mac_type = e1000_82546_rev_3;
246
        break;
247
    case E1000_DEV_ID_82541EI:
248
    case E1000_DEV_ID_82541EI_MOBILE:
249
        hw->mac_type = e1000_82541;
250
        break;
251
    case E1000_DEV_ID_82541ER:
252
    case E1000_DEV_ID_82541GI:
253
    case E1000_DEV_ID_82541GI_MOBILE:
254
        hw->mac_type = e1000_82541_rev_2;
255
        break;
256
    case E1000_DEV_ID_82547EI:
257
        hw->mac_type = e1000_82547;
258
        break;
259
    case E1000_DEV_ID_82547GI:
260
        hw->mac_type = e1000_82547_rev_2;
261
        break;
262
    default:
263
        /* Should never have loaded on this device */
264
        return -E1000_ERR_MAC_TYPE;
265
    }
266
 
267
    return E1000_SUCCESS;
268
}
269
 
270
/*****************************************************************************
271
 * Set media type and TBI compatibility.
272
 *
273
 * hw - Struct containing variables accessed by shared code
274
 * **************************************************************************/
275
void
276
e1000_set_media_type(struct e1000_hw *hw)
277
{
278
    uint32_t status;
279
 
280
    DEBUGFUNC("e1000_set_media_type");
281
 
282
    if(hw->mac_type != e1000_82543) {
283
        /* tbi_compatibility is only valid on 82543 */
284
        hw->tbi_compatibility_en = FALSE;
285
    }
286
 
287
    switch (hw->device_id) {
288
    case E1000_DEV_ID_82545GM_SERDES:
289
    case E1000_DEV_ID_82546GB_SERDES:
290
        hw->media_type = e1000_media_type_internal_serdes;
291
        break;
292
    default:
293
        if(hw->mac_type >= e1000_82543) {
294
            status = E1000_READ_REG(hw, STATUS);
295
            if(status & E1000_STATUS_TBIMODE) {
296
                hw->media_type = e1000_media_type_fiber;
297
                /* tbi_compatibility not valid on fiber */
298
                hw->tbi_compatibility_en = FALSE;
299
            } else {
300
                hw->media_type = e1000_media_type_copper;
301
            }
302
        } else {
303
            /* This is an 82542 (fiber only) */
304
            hw->media_type = e1000_media_type_fiber;
305
        }
306
    }
307
}
308
 
309
/******************************************************************************
310
 * Reset the transmit and receive units; mask and clear all interrupts.
311
 *
312
 * hw - Struct containing variables accessed by shared code
313
 *****************************************************************************/
314
int32_t
315
e1000_reset_hw(struct e1000_hw *hw)
316
{
317
    uint32_t ctrl;
318
    uint32_t ctrl_ext;
319
    uint32_t icr;
320
    uint32_t manc;
321
    uint32_t led_ctrl;
322
 
323
    DEBUGFUNC("e1000_reset_hw");
324
 
325
    /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
326
    if(hw->mac_type == e1000_82542_rev2_0) {
327
        DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
328
        e1000_pci_clear_mwi(hw);
329
    }
330
 
331
    /* Clear interrupt mask to stop board from generating interrupts */
332
    DEBUGOUT("Masking off all interrupts\n");
333
    E1000_WRITE_REG(hw, IMC, 0xffffffff);
334
 
335
    /* Disable the Transmit and Receive units.  Then delay to allow
336
     * any pending transactions to complete before we hit the MAC with
337
     * the global reset.
338
     */
339
    E1000_WRITE_REG(hw, RCTL, 0);
340
    E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
341
    E1000_WRITE_FLUSH(hw);
342
 
343
    /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
344
    hw->tbi_compatibility_on = FALSE;
345
 
346
    /* Delay to allow any outstanding PCI transactions to complete before
347
     * resetting the device
348
     */
349
    msec_delay(10);
350
 
351
    ctrl = E1000_READ_REG(hw, CTRL);
352
 
353
    /* Must reset the PHY before resetting the MAC */
354
    if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
355
        E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
356
        msec_delay(5);
357
    }
358
 
359
    /* Issue a global reset to the MAC.  This will reset the chip's
360
     * transmit, receive, DMA, and link units.  It will not effect
361
     * the current PCI configuration.  The global reset bit is self-
362
     * clearing, and should clear within a microsecond.
363
     */
364
    DEBUGOUT("Issuing a global reset to MAC\n");
365
 
366
    switch(hw->mac_type) {
367
        case e1000_82544:
368
        case e1000_82540:
369
        case e1000_82545:
370
        case e1000_82546:
371
        case e1000_82541:
372
        case e1000_82541_rev_2:
373
            /* These controllers can't ack the 64-bit write when issuing the
374
             * reset, so use IO-mapping as a workaround to issue the reset */
375
            E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
376
            break;
377
        case e1000_82545_rev_3:
378
        case e1000_82546_rev_3:
379
            /* Reset is performed on a shadow of the control register */
380
            E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
381
            break;
382
        default:
383
            E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
384
            break;
385
    }
386
 
387
    /* After MAC reset, force reload of EEPROM to restore power-on settings to
388
     * device.  Later controllers reload the EEPROM automatically, so just wait
389
     * for reload to complete.
390
     */
391
    switch(hw->mac_type) {
392
        case e1000_82542_rev2_0:
393
        case e1000_82542_rev2_1:
394
        case e1000_82543:
395
        case e1000_82544:
396
            /* Wait for reset to complete */
397
            udelay(10);
398
            ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
399
            ctrl_ext |= E1000_CTRL_EXT_EE_RST;
400
            E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
401
            E1000_WRITE_FLUSH(hw);
402
            /* Wait for EEPROM reload */
403
            msec_delay(2);
404
            break;
405
        case e1000_82541:
406
        case e1000_82541_rev_2:
407
        case e1000_82547:
408
        case e1000_82547_rev_2:
409
            /* Wait for EEPROM reload */
410
            msec_delay(20);
411
            break;
412
        default:
413
            /* Wait for EEPROM reload (it happens automatically) */
414
            msec_delay(5);
415
            break;
416
    }
417
 
418
    /* Disable HW ARPs on ASF enabled adapters */
419
    if(hw->mac_type >= e1000_82540) {
420
        manc = E1000_READ_REG(hw, MANC);
421
        manc &= ~(E1000_MANC_ARP_EN);
422
        E1000_WRITE_REG(hw, MANC, manc);
423
    }
424
 
425
    if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
426
        e1000_phy_init_script(hw);
427
 
428
        /* Configure activity LED after PHY reset */
429
        led_ctrl = E1000_READ_REG(hw, LEDCTL);
430
        led_ctrl &= IGP_ACTIVITY_LED_MASK;
431
        led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
432
        E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
433
    }
434
 
435
    /* Clear interrupt mask to stop board from generating interrupts */
436
    DEBUGOUT("Masking off all interrupts\n");
437
    E1000_WRITE_REG(hw, IMC, 0xffffffff);
438
 
439
    /* Clear any pending interrupt events. */
440
    icr = E1000_READ_REG(hw, ICR);
441
 
442
    /* If MWI was previously enabled, reenable it. */
443
    if(hw->mac_type == e1000_82542_rev2_0) {
444
        if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
445
            e1000_pci_set_mwi(hw);
446
    }
447
 
448
    return E1000_SUCCESS;
449
}
450
 
451
/******************************************************************************
452
 * Performs basic configuration of the adapter.
453
 *
454
 * hw - Struct containing variables accessed by shared code
455
 *
456
 * Assumes that the controller has previously been reset and is in a
457
 * post-reset uninitialized state. Initializes the receive address registers,
458
 * multicast table, and VLAN filter table. Calls routines to setup link
459
 * configuration and flow control settings. Clears all on-chip counters. Leaves
460
 * the transmit and receive units disabled and uninitialized.
461
 *****************************************************************************/
462
int32_t
463
e1000_init_hw(struct e1000_hw *hw)
464
{
465
    uint32_t ctrl;
466
    uint32_t i;
467
    int32_t ret_val;
468
    uint16_t pcix_cmd_word;
469
    uint16_t pcix_stat_hi_word;
470
    uint16_t cmd_mmrbc;
471
    uint16_t stat_mmrbc;
472
 
473
    DEBUGFUNC("e1000_init_hw");
474
 
475
    /* Initialize Identification LED */
476
    if((ret_val = e1000_id_led_init(hw))) {
477
        DEBUGOUT("Error Initializing Identification LED\n");
478
        return ret_val;
479
    }
480
 
481
    /* Set the media type and TBI compatibility */
482
    e1000_set_media_type(hw);
483
 
484
    /* Disabling VLAN filtering. */
485
    DEBUGOUT("Initializing the IEEE VLAN\n");
486
    E1000_WRITE_REG(hw, VET, 0);
487
 
488
    e1000_clear_vfta(hw);
489
 
490
    /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
491
    if(hw->mac_type == e1000_82542_rev2_0) {
492
        DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
493
        e1000_pci_clear_mwi(hw);
494
        E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
495
        E1000_WRITE_FLUSH(hw);
496
        msec_delay(5);
497
    }
498
 
499
    /* Setup the receive address. This involves initializing all of the Receive
500
     * Address Registers (RARs 0 - 15).
501
     */
502
    e1000_init_rx_addrs(hw);
503
 
504
    /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
505
    if(hw->mac_type == e1000_82542_rev2_0) {
506
        E1000_WRITE_REG(hw, RCTL, 0);
507
        E1000_WRITE_FLUSH(hw);
508
        msec_delay(1);
509
        if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
510
            e1000_pci_set_mwi(hw);
511
    }
512
 
513
    /* Zero out the Multicast HASH table */
514
    DEBUGOUT("Zeroing the MTA\n");
515
    for(i = 0; i < E1000_MC_TBL_SIZE; i++)
516
        E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
517
 
518
    /* Set the PCI priority bit correctly in the CTRL register.  This
519
     * determines if the adapter gives priority to receives, or if it
520
     * gives equal priority to transmits and receives.
521
     */
522
    if(hw->dma_fairness) {
523
        ctrl = E1000_READ_REG(hw, CTRL);
524
        E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
525
    }
526
 
527
    switch(hw->mac_type) {
528
    case e1000_82545_rev_3:
529
    case e1000_82546_rev_3:
530
        break;
531
    default:
532
        /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
533
        if(hw->bus_type == e1000_bus_type_pcix) {
534
            e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
535
            e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
536
                &pcix_stat_hi_word);
537
            cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
538
                PCIX_COMMAND_MMRBC_SHIFT;
539
            stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
540
                PCIX_STATUS_HI_MMRBC_SHIFT;
541
            if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
542
                stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
543
            if(cmd_mmrbc > stat_mmrbc) {
544
                pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
545
                pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
546
                e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
547
                    &pcix_cmd_word);
548
            }
549
        }
550
        break;
551
    }
552
 
553
    /* Call a subroutine to configure the link and setup flow control. */
554
    ret_val = e1000_setup_link(hw);
555
 
556
    /* Set the transmit descriptor write-back policy */
557
    if(hw->mac_type > e1000_82544) {
558
        ctrl = E1000_READ_REG(hw, TXDCTL);
559
        ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
560
        E1000_WRITE_REG(hw, TXDCTL, ctrl);
561
    }
562
 
563
    /* Clear all of the statistics registers (clear on read).  It is
564
     * important that we do this after we have tried to establish link
565
     * because the symbol error count will increment wildly if there
566
     * is no link.
567
     */
568
    e1000_clear_hw_cntrs(hw);
569
 
570
    return ret_val;
571
}
572
 
573
/******************************************************************************
574
 * Adjust SERDES output amplitude based on EEPROM setting.
575
 *
576
 * hw - Struct containing variables accessed by shared code.
577
 *****************************************************************************/
578
static int32_t
579
e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
580
{
581
    uint16_t eeprom_data;
582
    int32_t  ret_val;
583
 
584
    DEBUGFUNC("e1000_adjust_serdes_amplitude");
585
 
586
    if(hw->media_type != e1000_media_type_internal_serdes)
587
        return E1000_SUCCESS;
588
 
589
    switch(hw->mac_type) {
590
    case e1000_82545_rev_3:
591
    case e1000_82546_rev_3:
592
        break;
593
    default:
594
        return E1000_SUCCESS;
595
    }
596
 
597
    if ((ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1,
598
                                     &eeprom_data))) {
599
        return ret_val;
600
    }
601
 
602
    if(eeprom_data != EEPROM_RESERVED_WORD) {
603
        /* Adjust SERDES output amplitude only. */
604
        eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
605
        if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL,
606
                                          eeprom_data)))
607
            return ret_val;
608
    }
609
 
610
    return E1000_SUCCESS;
611
}
612
 
613
/******************************************************************************
614
 * Configures flow control and link settings.
615
 *
616
 * hw - Struct containing variables accessed by shared code
617
 *
618
 * Determines which flow control settings to use. Calls the apropriate media-
619
 * specific link configuration function. Configures the flow control settings.
620
 * Assuming the adapter has a valid link partner, a valid link should be
621
 * established. Assumes the hardware has previously been reset and the
622
 * transmitter and receiver are not enabled.
623
 *****************************************************************************/
624
int32_t
625
e1000_setup_link(struct e1000_hw *hw)
626
{
627
    uint32_t ctrl_ext;
628
    int32_t ret_val;
629
    uint16_t eeprom_data;
630
 
631
    DEBUGFUNC("e1000_setup_link");
632
 
633
    /* Read and store word 0x0F of the EEPROM. This word contains bits
634
     * that determine the hardware's default PAUSE (flow control) mode,
635
     * a bit that determines whether the HW defaults to enabling or
636
     * disabling auto-negotiation, and the direction of the
637
     * SW defined pins. If there is no SW over-ride of the flow
638
     * control setting, then the variable hw->fc will
639
     * be initialized based on a value in the EEPROM.
640
     */
641
    if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data) < 0) {
642
        DEBUGOUT("EEPROM Read Error\n");
643
        return -E1000_ERR_EEPROM;
644
    }
645
 
646
    if(hw->fc == e1000_fc_default) {
647
        if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
648
            hw->fc = e1000_fc_none;
649
        else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
650
                EEPROM_WORD0F_ASM_DIR)
651
            hw->fc = e1000_fc_tx_pause;
652
        else
653
            hw->fc = e1000_fc_full;
654
    }
655
 
656
    /* We want to save off the original Flow Control configuration just
657
     * in case we get disconnected and then reconnected into a different
658
     * hub or switch with different Flow Control capabilities.
659
     */
660
    if(hw->mac_type == e1000_82542_rev2_0)
661
        hw->fc &= (~e1000_fc_tx_pause);
662
 
663
    if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
664
        hw->fc &= (~e1000_fc_rx_pause);
665
 
666
    hw->original_fc = hw->fc;
667
 
668
    DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
669
 
670
    /* Take the 4 bits from EEPROM word 0x0F that determine the initial
671
     * polarity value for the SW controlled pins, and setup the
672
     * Extended Device Control reg with that info.
673
     * This is needed because one of the SW controlled pins is used for
674
     * signal detection.  So this should be done before e1000_setup_pcs_link()
675
     * or e1000_phy_setup() is called.
676
     */
677
    if(hw->mac_type == e1000_82543) {
678
        ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
679
                    SWDPIO__EXT_SHIFT);
680
        E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
681
    }
682
 
683
    /* Call the necessary subroutine to configure the link. */
684
    ret_val = (hw->media_type == e1000_media_type_copper) ?
685
              e1000_setup_copper_link(hw) :
686
              e1000_setup_fiber_serdes_link(hw);
687
 
688
    /* Initialize the flow control address, type, and PAUSE timer
689
     * registers to their default values.  This is done even if flow
690
     * control is disabled, because it does not hurt anything to
691
     * initialize these registers.
692
     */
693
    DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
694
 
695
    E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
696
    E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
697
    E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
698
    E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
699
 
700
    /* Set the flow control receive threshold registers.  Normally,
701
     * these registers will be set to a default threshold that may be
702
     * adjusted later by the driver's runtime code.  However, if the
703
     * ability to transmit pause frames in not enabled, then these
704
     * registers will be set to 0.
705
     */
706
    if(!(hw->fc & e1000_fc_tx_pause)) {
707
        E1000_WRITE_REG(hw, FCRTL, 0);
708
        E1000_WRITE_REG(hw, FCRTH, 0);
709
    } else {
710
        /* We need to set up the Receive Threshold high and low water marks
711
         * as well as (optionally) enabling the transmission of XON frames.
712
         */
713
        if(hw->fc_send_xon) {
714
            E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
715
            E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
716
        } else {
717
            E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
718
            E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
719
        }
720
    }
721
    return ret_val;
722
}
723
 
724
/******************************************************************************
725
 * Sets up link for a fiber based or serdes based adapter
726
 *
727
 * hw - Struct containing variables accessed by shared code
728
 *
729
 * Manipulates Physical Coding Sublayer functions in order to configure
730
 * link. Assumes the hardware has been previously reset and the transmitter
731
 * and receiver are not enabled.
732
 *****************************************************************************/
733
static int32_t
734
e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
735
{
736
    uint32_t ctrl;
737
    uint32_t status;
738
    uint32_t txcw = 0;
739
    uint32_t i;
740
    uint32_t signal = 0;
741
    int32_t ret_val;
742
 
743
    DEBUGFUNC("e1000_setup_fiber_serdes_link");
744
 
745
    /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
746
     * set when the optics detect a signal. On older adapters, it will be
747
     * cleared when there is a signal.  This applies to fiber media only.
748
     * If we're on serdes media, adjust the output amplitude to value set in
749
     * the EEPROM.
750
     */
751
    ctrl = E1000_READ_REG(hw, CTRL);
752
    if(hw->media_type == e1000_media_type_fiber)
753
        signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
754
 
755
    if((ret_val = e1000_adjust_serdes_amplitude(hw)))
756
        return ret_val;
757
 
758
    /* Take the link out of reset */
759
    ctrl &= ~(E1000_CTRL_LRST);
760
 
761
    /* Adjust VCO speed to improve BER performance */
762
    if((ret_val = e1000_set_vco_speed(hw)))
763
        return ret_val;
764
 
765
    e1000_config_collision_dist(hw);
766
 
767
    /* Check for a software override of the flow control settings, and setup
768
     * the device accordingly.  If auto-negotiation is enabled, then software
769
     * will have to set the "PAUSE" bits to the correct value in the Tranmsit
770
     * Config Word Register (TXCW) and re-start auto-negotiation.  However, if
771
     * auto-negotiation is disabled, then software will have to manually
772
     * configure the two flow control enable bits in the CTRL register.
773
     *
774
     * The possible values of the "fc" parameter are:
775
     *      0:  Flow control is completely disabled
776
     *      1:  Rx flow control is enabled (we can receive pause frames, but
777
     *          not send pause frames).
778
     *      2:  Tx flow control is enabled (we can send pause frames but we do
779
     *          not support receiving pause frames).
780
     *      3:  Both Rx and TX flow control (symmetric) are enabled.
781
     */
782
    switch (hw->fc) {
783
    case e1000_fc_none:
784
        /* Flow control is completely disabled by a software over-ride. */
785
        txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
786
        break;
787
    case e1000_fc_rx_pause:
788
        /* RX Flow control is enabled and TX Flow control is disabled by a
789
         * software over-ride. Since there really isn't a way to advertise
790
         * that we are capable of RX Pause ONLY, we will advertise that we
791
         * support both symmetric and asymmetric RX PAUSE. Later, we will
792
         *  disable the adapter's ability to send PAUSE frames.
793
         */
794
        txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
795
        break;
796
    case e1000_fc_tx_pause:
797
        /* TX Flow control is enabled, and RX Flow control is disabled, by a
798
         * software over-ride.
799
         */
800
        txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
801
        break;
802
    case e1000_fc_full:
803
        /* Flow control (both RX and TX) is enabled by a software over-ride. */
804
        txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
805
        break;
806
    default:
807
        DEBUGOUT("Flow control param set incorrectly\n");
808
        return -E1000_ERR_CONFIG;
809
        break;
810
    }
811
 
812
    /* Since auto-negotiation is enabled, take the link out of reset (the link
813
     * will be in reset, because we previously reset the chip). This will
814
     * restart auto-negotiation.  If auto-neogtiation is successful then the
815
     * link-up status bit will be set and the flow control enable bits (RFCE
816
     * and TFCE) will be set according to their negotiated value.
817
     */
818
    DEBUGOUT("Auto-negotiation enabled\n");
819
 
820
    E1000_WRITE_REG(hw, TXCW, txcw);
821
    E1000_WRITE_REG(hw, CTRL, ctrl);
822
    E1000_WRITE_FLUSH(hw);
823
 
824
    hw->txcw = txcw;
825
    msec_delay(1);
826
 
827
    /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
828
     * indication in the Device Status Register.  Time-out if a link isn't
829
     * seen in 500 milliseconds seconds (Auto-negotiation should complete in
830
     * less than 500 milliseconds even if the other end is doing it in SW).
831
     * For internal serdes, we just assume a signal is present, then poll.
832
     */
833
    if(hw->media_type == e1000_media_type_internal_serdes ||
834
       (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
835
        DEBUGOUT("Looking for Link\n");
836
        for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
837
            msec_delay(10);
838
            status = E1000_READ_REG(hw, STATUS);
839
            if(status & E1000_STATUS_LU) break;
840
        }
841
        if(i == (LINK_UP_TIMEOUT / 10)) {
842
            DEBUGOUT("Never got a valid link from auto-neg!!!\n");
843
            hw->autoneg_failed = 1;
844
            /* AutoNeg failed to achieve a link, so we'll call
845
             * e1000_check_for_link. This routine will force the link up if
846
             * we detect a signal. This will allow us to communicate with
847
             * non-autonegotiating link partners.
848
             */
849
            if((ret_val = e1000_check_for_link(hw))) {
850
                DEBUGOUT("Error while checking for link\n");
851
                return ret_val;
852
            }
853
            hw->autoneg_failed = 0;
854
        } else {
855
            hw->autoneg_failed = 0;
856
            DEBUGOUT("Valid Link Found\n");
857
        }
858
    } else {
859
        DEBUGOUT("No Signal Detected\n");
860
    }
861
    return E1000_SUCCESS;
862
}
863
 
864
/******************************************************************************
865
* Detects which PHY is present and the speed and duplex
866
*
867
* hw - Struct containing variables accessed by shared code
868
******************************************************************************/
869
static int32_t
870
e1000_setup_copper_link(struct e1000_hw *hw)
871
{
872
    uint32_t ctrl;
873
    uint32_t led_ctrl;
874
    int32_t ret_val;
875
    uint16_t i;
876
    uint16_t phy_data;
877
 
878
    DEBUGFUNC("e1000_setup_copper_link");
879
 
880
    ctrl = E1000_READ_REG(hw, CTRL);
881
    /* With 82543, we need to force speed and duplex on the MAC equal to what
882
     * the PHY speed and duplex configuration is. In addition, we need to
883
     * perform a hardware reset on the PHY to take it out of reset.
884
     */
885
    if(hw->mac_type > e1000_82543) {
886
        ctrl |= E1000_CTRL_SLU;
887
        ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
888
        E1000_WRITE_REG(hw, CTRL, ctrl);
889
    } else {
890
        ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
891
        E1000_WRITE_REG(hw, CTRL, ctrl);
892
        e1000_phy_hw_reset(hw);
893
    }
894
 
895
    /* Make sure we have a valid PHY */
896
    if((ret_val = e1000_detect_gig_phy(hw))) {
897
        DEBUGOUT("Error, did not detect valid phy.\n");
898
        return ret_val;
899
    }
900
    DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
901
 
902
    if(hw->mac_type <= e1000_82543 ||
903
       hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
904
       hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
905
        hw->phy_reset_disable = FALSE;
906
 
907
    if(!hw->phy_reset_disable) {
908
        if (hw->phy_type == e1000_phy_igp) {
909
 
910
            if((ret_val = e1000_phy_reset(hw))) {
911
                DEBUGOUT("Error Resetting the PHY\n");
912
                return ret_val;
913
            }
914
 
915
            /* Wait 10ms for MAC to configure PHY from eeprom settings */
916
            msec_delay(15);
917
 
918
            /* Configure activity LED after PHY reset */
919
            led_ctrl = E1000_READ_REG(hw, LEDCTL);
920
            led_ctrl &= IGP_ACTIVITY_LED_MASK;
921
            led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
922
            E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
923
 
924
            /* disable lplu d3 during driver init */
925
            if((ret_val = e1000_set_d3_lplu_state(hw, FALSE))) {
926
                DEBUGOUT("Error Disabling LPLU D3\n");
927
                return ret_val;
928
            }
929
 
930
            /* Configure mdi-mdix settings */
931
            if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
932
                                             &phy_data)))
933
                return ret_val;
934
 
935
            if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
936
                hw->dsp_config_state = e1000_dsp_config_disabled;
937
                /* Force MDI for IGP B-0 PHY */
938
                phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX |
939
                              IGP01E1000_PSCR_FORCE_MDI_MDIX);
940
                hw->mdix = 1;
941
 
942
            } else {
943
                hw->dsp_config_state = e1000_dsp_config_enabled;
944
                phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
945
 
946
                switch (hw->mdix) {
947
                case 1:
948
                    phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
949
                    break;
950
                case 2:
951
                    phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
952
                    break;
953
                case 0:
954
                default:
955
                    phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
956
                    break;
957
                }
958
            }
959
            if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
960
                                              phy_data)))
961
                return ret_val;
962
 
963
            /* set auto-master slave resolution settings */
964
            if(hw->autoneg) {
965
                e1000_ms_type phy_ms_setting = hw->master_slave;
966
 
967
                if(hw->ffe_config_state == e1000_ffe_config_active)
968
                    hw->ffe_config_state = e1000_ffe_config_enabled;
969
 
970
                if(hw->dsp_config_state == e1000_dsp_config_activated)
971
                    hw->dsp_config_state = e1000_dsp_config_enabled;
972
 
973
                /* when autonegotiation advertisment is only 1000Mbps then we
974
                 * should disable SmartSpeed and enable Auto MasterSlave
975
                 * resolution as hardware default. */
976
                if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
977
                    /* Disable SmartSpeed */
978
                    if((ret_val = e1000_read_phy_reg(hw,
979
                                                    IGP01E1000_PHY_PORT_CONFIG,
980
                                                    &phy_data)))
981
                        return ret_val;
982
                    phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
983
                    if((ret_val = e1000_write_phy_reg(hw,
984
                                                     IGP01E1000_PHY_PORT_CONFIG,
985
                                                     phy_data)))
986
                        return ret_val;
987
                    /* Set auto Master/Slave resolution process */
988
                    if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
989
                                                     &phy_data)))
990
                        return ret_val;
991
                    phy_data &= ~CR_1000T_MS_ENABLE;
992
                    if((ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
993
                                                      phy_data)))
994
                        return ret_val;
995
                }
996
 
997
                if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
998
                                                 &phy_data)))
999
                    return ret_val;
1000
 
1001
                /* load defaults for future use */
1002
                hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
1003
                                            ((phy_data & CR_1000T_MS_VALUE) ?
1004
                                             e1000_ms_force_master :
1005
                                             e1000_ms_force_slave) :
1006
                                             e1000_ms_auto;
1007
 
1008
                switch (phy_ms_setting) {
1009
                case e1000_ms_force_master:
1010
                    phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
1011
                    break;
1012
                case e1000_ms_force_slave:
1013
                    phy_data |= CR_1000T_MS_ENABLE;
1014
                    phy_data &= ~(CR_1000T_MS_VALUE);
1015
                    break;
1016
                case e1000_ms_auto:
1017
                    phy_data &= ~CR_1000T_MS_ENABLE;
1018
                default:
1019
                    break;
1020
                }
1021
                if((ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
1022
                                                  phy_data)))
1023
                    return ret_val;
1024
            }
1025
        } else {
1026
            /* Enable CRS on TX. This must be set for half-duplex operation. */
1027
            if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1028
                                             &phy_data)))
1029
                return ret_val;
1030
 
1031
            phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1032
 
1033
            /* Options:
1034
             *   MDI/MDI-X = 0 (default)
1035
             *   0 - Auto for all speeds
1036
             *   1 - MDI mode
1037
             *   2 - MDI-X mode
1038
             *   3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
1039
             */
1040
            phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1041
 
1042
            switch (hw->mdix) {
1043
            case 1:
1044
                phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
1045
                break;
1046
            case 2:
1047
                phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
1048
                break;
1049
            case 3:
1050
                phy_data |= M88E1000_PSCR_AUTO_X_1000T;
1051
                break;
1052
            case 0:
1053
            default:
1054
                phy_data |= M88E1000_PSCR_AUTO_X_MODE;
1055
                break;
1056
            }
1057
 
1058
            /* Options:
1059
             *   disable_polarity_correction = 0 (default)
1060
             *       Automatic Correction for Reversed Cable Polarity
1061
             *   0 - Disabled
1062
             *   1 - Enabled
1063
             */
1064
            phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
1065
            if(hw->disable_polarity_correction == 1)
1066
                phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
1067
            if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1068
                                              phy_data)))
1069
                return ret_val;
1070
 
1071
            /* Force TX_CLK in the Extended PHY Specific Control Register
1072
             * to 25MHz clock.
1073
             */
1074
            if((ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1075
                                             &phy_data)))
1076
                return ret_val;
1077
 
1078
            phy_data |= M88E1000_EPSCR_TX_CLK_25;
1079
 
1080
            if (hw->phy_revision < M88E1011_I_REV_4) {
1081
                /* Configure Master and Slave downshift values */
1082
                phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
1083
                              M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
1084
                phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
1085
                             M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
1086
                if((ret_val = e1000_write_phy_reg(hw,
1087
                                                  M88E1000_EXT_PHY_SPEC_CTRL,
1088
                                                  phy_data)))
1089
                    return ret_val;
1090
            }
1091
 
1092
            /* SW Reset the PHY so all changes take effect */
1093
            if((ret_val = e1000_phy_reset(hw))) {
1094
                DEBUGOUT("Error Resetting the PHY\n");
1095
                return ret_val;
1096
            }
1097
        }
1098
 
1099
        /* Options:
1100
         *   autoneg = 1 (default)
1101
         *      PHY will advertise value(s) parsed from
1102
         *      autoneg_advertised and fc
1103
         *   autoneg = 0
1104
         *      PHY will be set to 10H, 10F, 100H, or 100F
1105
         *      depending on value parsed from forced_speed_duplex.
1106
         */
1107
 
1108
        /* Is autoneg enabled?  This is enabled by default or by software
1109
         * override.  If so, call e1000_phy_setup_autoneg routine to parse the
1110
         * autoneg_advertised and fc options. If autoneg is NOT enabled, then
1111
         * the user should have provided a speed/duplex override.  If so, then
1112
         * call e1000_phy_force_speed_duplex to parse and set this up.
1113
         */
1114
        if(hw->autoneg) {
1115
            /* Perform some bounds checking on the hw->autoneg_advertised
1116
             * parameter.  If this variable is zero, then set it to the default.
1117
             */
1118
            hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
1119
 
1120
            /* If autoneg_advertised is zero, we assume it was not defaulted
1121
             * by the calling code so we set to advertise full capability.
1122
             */
1123
            if(hw->autoneg_advertised == 0)
1124
                hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
1125
 
1126
            DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
1127
            if((ret_val = e1000_phy_setup_autoneg(hw))) {
1128
                DEBUGOUT("Error Setting up Auto-Negotiation\n");
1129
                return ret_val;
1130
            }
1131
            DEBUGOUT("Restarting Auto-Neg\n");
1132
 
1133
            /* Restart auto-negotiation by setting the Auto Neg Enable bit and
1134
             * the Auto Neg Restart bit in the PHY control register.
1135
             */
1136
            if((ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data)))
1137
                return ret_val;
1138
 
1139
            phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
1140
            if((ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data)))
1141
                return ret_val;
1142
 
1143
            /* Does the user want to wait for Auto-Neg to complete here, or
1144
             * check at a later time (for example, callback routine).
1145
             */
1146
            if(hw->wait_autoneg_complete) {
1147
                if((ret_val = e1000_wait_autoneg(hw))) {
1148
                    DEBUGOUT("Error while waiting for autoneg to complete\n");
1149
                    return ret_val;
1150
                }
1151
            }
1152
            hw->get_link_status = TRUE;
1153
        } else {
1154
            DEBUGOUT("Forcing speed and duplex\n");
1155
            if((ret_val = e1000_phy_force_speed_duplex(hw))) {
1156
                DEBUGOUT("Error Forcing Speed and Duplex\n");
1157
                return ret_val;
1158
            }
1159
        }
1160
    } /* !hw->phy_reset_disable */
1161
 
1162
    /* Check link status. Wait up to 100 microseconds for link to become
1163
     * valid.
1164
     */
1165
    for(i = 0; i < 10; i++) {
1166
        if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
1167
            return ret_val;
1168
        if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
1169
            return ret_val;
1170
 
1171
        if(phy_data & MII_SR_LINK_STATUS) {
1172
            /* We have link, so we need to finish the config process:
1173
             *   1) Set up the MAC to the current PHY speed/duplex
1174
             *      if we are on 82543.  If we
1175
             *      are on newer silicon, we only need to configure
1176
             *      collision distance in the Transmit Control Register.
1177
             *   2) Set up flow control on the MAC to that established with
1178
             *      the link partner.
1179
             */
1180
            if(hw->mac_type >= e1000_82544) {
1181
                e1000_config_collision_dist(hw);
1182
            } else {
1183
                if((ret_val = e1000_config_mac_to_phy(hw))) {
1184
                    DEBUGOUT("Error configuring MAC to PHY settings\n");
1185
                    return ret_val;
1186
                }
1187
            }
1188
            if((ret_val = e1000_config_fc_after_link_up(hw))) {
1189
                DEBUGOUT("Error Configuring Flow Control\n");
1190
                return ret_val;
1191
            }
1192
            DEBUGOUT("Valid link established!!!\n");
1193
 
1194
            if(hw->phy_type == e1000_phy_igp) {
1195
                if((ret_val = e1000_config_dsp_after_link_change(hw, TRUE))) {
1196
                    DEBUGOUT("Error Configuring DSP after link up\n");
1197
                    return ret_val;
1198
                }
1199
            }
1200
            DEBUGOUT("Valid link established!!!\n");
1201
            return E1000_SUCCESS;
1202
        }
1203
        udelay(10);
1204
    }
1205
 
1206
    DEBUGOUT("Unable to establish link!!!\n");
1207
    return E1000_SUCCESS;
1208
}
1209
 
1210
/******************************************************************************
1211
* Configures PHY autoneg and flow control advertisement settings
1212
*
1213
* hw - Struct containing variables accessed by shared code
1214
******************************************************************************/
1215
int32_t
1216
e1000_phy_setup_autoneg(struct e1000_hw *hw)
1217
{
1218
    int32_t ret_val;
1219
    uint16_t mii_autoneg_adv_reg;
1220
    uint16_t mii_1000t_ctrl_reg;
1221
 
1222
    DEBUGFUNC("e1000_phy_setup_autoneg");
1223
 
1224
    /* Read the MII Auto-Neg Advertisement Register (Address 4). */
1225
    if((ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
1226
                                     &mii_autoneg_adv_reg)))
1227
        return ret_val;
1228
 
1229
    /* Read the MII 1000Base-T Control Register (Address 9). */
1230
    if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg)))
1231
        return ret_val;
1232
 
1233
    /* Need to parse both autoneg_advertised and fc and set up
1234
     * the appropriate PHY registers.  First we will parse for
1235
     * autoneg_advertised software override.  Since we can advertise
1236
     * a plethora of combinations, we need to check each bit
1237
     * individually.
1238
     */
1239
 
1240
    /* First we clear all the 10/100 mb speed bits in the Auto-Neg
1241
     * Advertisement Register (Address 4) and the 1000 mb speed bits in
1242
     * the  1000Base-T Control Register (Address 9).
1243
     */
1244
    mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
1245
    mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
1246
 
1247
    DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
1248
 
1249
    /* Do we want to advertise 10 Mb Half Duplex? */
1250
    if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
1251
        DEBUGOUT("Advertise 10mb Half duplex\n");
1252
        mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
1253
    }
1254
 
1255
    /* Do we want to advertise 10 Mb Full Duplex? */
1256
    if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
1257
        DEBUGOUT("Advertise 10mb Full duplex\n");
1258
        mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
1259
    }
1260
 
1261
    /* Do we want to advertise 100 Mb Half Duplex? */
1262
    if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
1263
        DEBUGOUT("Advertise 100mb Half duplex\n");
1264
        mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
1265
    }
1266
 
1267
    /* Do we want to advertise 100 Mb Full Duplex? */
1268
    if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
1269
        DEBUGOUT("Advertise 100mb Full duplex\n");
1270
        mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
1271
    }
1272
 
1273
    /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
1274
    if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
1275
        DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
1276
    }
1277
 
1278
    /* Do we want to advertise 1000 Mb Full Duplex? */
1279
    if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
1280
        DEBUGOUT("Advertise 1000mb Full duplex\n");
1281
        mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
1282
    }
1283
 
1284
    /* Check for a software override of the flow control settings, and
1285
     * setup the PHY advertisement registers accordingly.  If
1286
     * auto-negotiation is enabled, then software will have to set the
1287
     * "PAUSE" bits to the correct value in the Auto-Negotiation
1288
     * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
1289
     *
1290
     * The possible values of the "fc" parameter are:
1291
     *      0:  Flow control is completely disabled
1292
     *      1:  Rx flow control is enabled (we can receive pause frames
1293
     *          but not send pause frames).
1294
     *      2:  Tx flow control is enabled (we can send pause frames
1295
     *          but we do not support receiving pause frames).
1296
     *      3:  Both Rx and TX flow control (symmetric) are enabled.
1297
     *  other:  No software override.  The flow control configuration
1298
     *          in the EEPROM is used.
1299
     */
1300
    switch (hw->fc) {
1301
    case e1000_fc_none: /* 0 */
1302
        /* Flow control (RX & TX) is completely disabled by a
1303
         * software over-ride.
1304
         */
1305
        mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1306
        break;
1307
    case e1000_fc_rx_pause: /* 1 */
1308
        /* RX Flow control is enabled, and TX Flow control is
1309
         * disabled, by a software over-ride.
1310
         */
1311
        /* Since there really isn't a way to advertise that we are
1312
         * capable of RX Pause ONLY, we will advertise that we
1313
         * support both symmetric and asymmetric RX PAUSE.  Later
1314
         * (in e1000_config_fc_after_link_up) we will disable the
1315
         *hw's ability to send PAUSE frames.
1316
         */
1317
        mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1318
        break;
1319
    case e1000_fc_tx_pause: /* 2 */
1320
        /* TX Flow control is enabled, and RX Flow control is
1321
         * disabled, by a software over-ride.
1322
         */
1323
        mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
1324
        mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
1325
        break;
1326
    case e1000_fc_full: /* 3 */
1327
        /* Flow control (both RX and TX) is enabled by a software
1328
         * over-ride.
1329
         */
1330
        mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
1331
        break;
1332
    default:
1333
        DEBUGOUT("Flow control param set incorrectly\n");
1334
        return -E1000_ERR_CONFIG;
1335
    }
1336
 
1337
    if((ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV,
1338
                                      mii_autoneg_adv_reg)))
1339
        return ret_val;
1340
 
1341
    DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
1342
 
1343
    if((ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg)))
1344
        return ret_val;
1345
 
1346
    return E1000_SUCCESS;
1347
}
1348
 
1349
/******************************************************************************
1350
* Force PHY speed and duplex settings to hw->forced_speed_duplex
1351
*
1352
* hw - Struct containing variables accessed by shared code
1353
******************************************************************************/
1354
static int32_t
1355
e1000_phy_force_speed_duplex(struct e1000_hw *hw)
1356
{
1357
    uint32_t ctrl;
1358
    int32_t ret_val;
1359
    uint16_t mii_ctrl_reg;
1360
    uint16_t mii_status_reg;
1361
    uint16_t phy_data;
1362
    uint16_t i;
1363
 
1364
    DEBUGFUNC("e1000_phy_force_speed_duplex");
1365
 
1366
    /* Turn off Flow control if we are forcing speed and duplex. */
1367
    hw->fc = e1000_fc_none;
1368
 
1369
    DEBUGOUT1("hw->fc = %d\n", hw->fc);
1370
 
1371
    /* Read the Device Control Register. */
1372
    ctrl = E1000_READ_REG(hw, CTRL);
1373
 
1374
    /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
1375
    ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1376
    ctrl &= ~(DEVICE_SPEED_MASK);
1377
 
1378
    /* Clear the Auto Speed Detect Enable bit. */
1379
    ctrl &= ~E1000_CTRL_ASDE;
1380
 
1381
    /* Read the MII Control Register. */
1382
    if((ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg)))
1383
        return ret_val;
1384
 
1385
    /* We need to disable autoneg in order to force link and duplex. */
1386
 
1387
    mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
1388
 
1389
    /* Are we forcing Full or Half Duplex? */
1390
    if(hw->forced_speed_duplex == e1000_100_full ||
1391
       hw->forced_speed_duplex == e1000_10_full) {
1392
        /* We want to force full duplex so we SET the full duplex bits in the
1393
         * Device and MII Control Registers.
1394
         */
1395
        ctrl |= E1000_CTRL_FD;
1396
        mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
1397
        DEBUGOUT("Full Duplex\n");
1398
    } else {
1399
        /* We want to force half duplex so we CLEAR the full duplex bits in
1400
         * the Device and MII Control Registers.
1401
         */
1402
        ctrl &= ~E1000_CTRL_FD;
1403
        mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
1404
        DEBUGOUT("Half Duplex\n");
1405
    }
1406
 
1407
    /* Are we forcing 100Mbps??? */
1408
    if(hw->forced_speed_duplex == e1000_100_full ||
1409
       hw->forced_speed_duplex == e1000_100_half) {
1410
        /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
1411
        ctrl |= E1000_CTRL_SPD_100;
1412
        mii_ctrl_reg |= MII_CR_SPEED_100;
1413
        mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
1414
        DEBUGOUT("Forcing 100mb ");
1415
    } else {
1416
        /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
1417
        ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1418
        mii_ctrl_reg |= MII_CR_SPEED_10;
1419
        mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1420
        DEBUGOUT("Forcing 10mb ");
1421
    }
1422
 
1423
    e1000_config_collision_dist(hw);
1424
 
1425
    /* Write the configured values back to the Device Control Reg. */
1426
    E1000_WRITE_REG(hw, CTRL, ctrl);
1427
 
1428
    if (hw->phy_type == e1000_phy_m88) {
1429
        if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1430
                                         &phy_data)))
1431
            return ret_val;
1432
 
1433
        /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
1434
         * forced whenever speed are duplex are forced.
1435
         */
1436
        phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1437
        if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1438
                                          phy_data)))
1439
            return ret_val;
1440
 
1441
        DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1442
 
1443
        /* Need to reset the PHY or these changes will be ignored */
1444
        mii_ctrl_reg |= MII_CR_RESET;
1445
    } else {
1446
        /* Clear Auto-Crossover to force MDI manually.  IGP requires MDI
1447
         * forced whenever speed or duplex are forced.
1448
         */
1449
        if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
1450
                                         &phy_data)))
1451
            return ret_val;
1452
 
1453
        phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
1454
        phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
1455
 
1456
        if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL,
1457
                                          phy_data)))
1458
            return ret_val;
1459
    }
1460
 
1461
    /* Write back the modified PHY MII control register. */
1462
    if((ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg)))
1463
        return ret_val;
1464
 
1465
    udelay(1);
1466
 
1467
    /* The wait_autoneg_complete flag may be a little misleading here.
1468
     * Since we are forcing speed and duplex, Auto-Neg is not enabled.
1469
     * But we do want to delay for a period while forcing only so we
1470
     * don't generate false No Link messages.  So we will wait here
1471
     * only if the user has set wait_autoneg_complete to 1, which is
1472
     * the default.
1473
     */
1474
    if(hw->wait_autoneg_complete) {
1475
        /* We will wait for autoneg to complete. */
1476
        DEBUGOUT("Waiting for forced speed/duplex link.\n");
1477
        mii_status_reg = 0;
1478
 
1479
        /* We will wait for autoneg to complete or 4.5 seconds to expire. */
1480
        for(i = PHY_FORCE_TIME; i > 0; i--) {
1481
            /* Read the MII Status Register and wait for Auto-Neg Complete bit
1482
             * to be set.
1483
             */
1484
            if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg)))
1485
                return ret_val;
1486
 
1487
            if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg)))
1488
                return ret_val;
1489
 
1490
            if(mii_status_reg & MII_SR_LINK_STATUS) break;
1491
            msec_delay(100);
1492
        }
1493
        if((i == 0) && (hw->phy_type == e1000_phy_m88)) {
1494
            /* We didn't get link.  Reset the DSP and wait again for link. */
1495
            if((ret_val = e1000_phy_reset_dsp(hw))) {
1496
                DEBUGOUT("Error Resetting PHY DSP\n");
1497
                return ret_val;
1498
            }
1499
        }
1500
        /* This loop will early-out if the link condition has been met.  */
1501
        for(i = PHY_FORCE_TIME; i > 0; i--) {
1502
            if(mii_status_reg & MII_SR_LINK_STATUS) break;
1503
            msec_delay(100);
1504
            /* Read the MII Status Register and wait for Auto-Neg Complete bit
1505
             * to be set.
1506
             */
1507
            if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg)))
1508
                return ret_val;
1509
 
1510
            if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg)))
1511
                return ret_val;
1512
        }
1513
    }
1514
 
1515
    if (hw->phy_type == e1000_phy_m88) {
1516
        /* Because we reset the PHY above, we need to re-force TX_CLK in the
1517
         * Extended PHY Specific Control Register to 25MHz clock.  This value
1518
         * defaults back to a 2.5MHz clock when the PHY is reset.
1519
         */
1520
        if((ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1521
                                         &phy_data)))
1522
            return ret_val;
1523
 
1524
        phy_data |= M88E1000_EPSCR_TX_CLK_25;
1525
        if((ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
1526
                                          phy_data)))
1527
            return ret_val;
1528
 
1529
        /* In addition, because of the s/w reset above, we need to enable CRS on
1530
         * TX.  This must be set for both full and half duplex operation.
1531
         */
1532
        if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1533
                                         &phy_data)))
1534
            return ret_val;
1535
 
1536
        phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1537
        if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
1538
                                          phy_data)))
1539
            return ret_val;
1540
 
1541
        /* Polarity reversal workaround for forced 10F/10H links. */
1542
        if(hw->mac_type <= e1000_82544 &&
1543
           (hw->forced_speed_duplex == e1000_10_full ||
1544
            hw->forced_speed_duplex == e1000_10_half)) {
1545
            if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
1546
                                              0x0019)))
1547
                return ret_val;
1548
            if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
1549
                                              0x8F0F)))
1550
                return ret_val;
1551
            /* IEEE requirement is 150ms */
1552
            msec_delay(200);
1553
            if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
1554
                                              0x0019)))
1555
                return ret_val;
1556
            if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL,
1557
                                              0x8F00)))
1558
                return ret_val;
1559
        }
1560
    }
1561
    return E1000_SUCCESS;
1562
}
1563
 
1564
/******************************************************************************
1565
* Sets the collision distance in the Transmit Control register
1566
*
1567
* hw - Struct containing variables accessed by shared code
1568
*
1569
* Link should have been established previously. Reads the speed and duplex
1570
* information from the Device Status register.
1571
******************************************************************************/
1572
void
1573
e1000_config_collision_dist(struct e1000_hw *hw)
1574
{
1575
    uint32_t tctl;
1576
 
1577
    DEBUGFUNC("e1000_config_collision_dist");
1578
 
1579
    tctl = E1000_READ_REG(hw, TCTL);
1580
 
1581
    tctl &= ~E1000_TCTL_COLD;
1582
    tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1583
 
1584
    E1000_WRITE_REG(hw, TCTL, tctl);
1585
    E1000_WRITE_FLUSH(hw);
1586
}
1587
 
1588
/******************************************************************************
1589
* Sets MAC speed and duplex settings to reflect the those in the PHY
1590
*
1591
* hw - Struct containing variables accessed by shared code
1592
* mii_reg - data to write to the MII control register
1593
*
1594
* The contents of the PHY register containing the needed information need to
1595
* be passed in.
1596
******************************************************************************/
1597
static int32_t
1598
e1000_config_mac_to_phy(struct e1000_hw *hw)
1599
{
1600
    uint32_t ctrl;
1601
    int32_t ret_val;
1602
    uint16_t phy_data;
1603
 
1604
    DEBUGFUNC("e1000_config_mac_to_phy");
1605
 
1606
    /* Read the Device Control Register and set the bits to Force Speed
1607
     * and Duplex.
1608
     */
1609
    ctrl = E1000_READ_REG(hw, CTRL);
1610
    ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1611
    ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1612
 
1613
    /* Set up duplex in the Device Control and Transmit Control
1614
     * registers depending on negotiated values.
1615
     */
1616
    if (hw->phy_type == e1000_phy_igp) {
1617
        if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
1618
                                         &phy_data)))
1619
            return ret_val;
1620
 
1621
        if(phy_data & IGP01E1000_PSSR_FULL_DUPLEX) ctrl |= E1000_CTRL_FD;
1622
        else ctrl &= ~E1000_CTRL_FD;
1623
 
1624
        e1000_config_collision_dist(hw);
1625
 
1626
        /* Set up speed in the Device Control register depending on
1627
         * negotiated values.
1628
         */
1629
        if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
1630
           IGP01E1000_PSSR_SPEED_1000MBPS)
1631
            ctrl |= E1000_CTRL_SPD_1000;
1632
        else if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
1633
                IGP01E1000_PSSR_SPEED_100MBPS)
1634
            ctrl |= E1000_CTRL_SPD_100;
1635
    } else {
1636
        if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
1637
                                         &phy_data)))
1638
            return ret_val;
1639
 
1640
        if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
1641
        else ctrl &= ~E1000_CTRL_FD;
1642
 
1643
        e1000_config_collision_dist(hw);
1644
 
1645
        /* Set up speed in the Device Control register depending on
1646
         * negotiated values.
1647
         */
1648
        if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1649
            ctrl |= E1000_CTRL_SPD_1000;
1650
        else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1651
            ctrl |= E1000_CTRL_SPD_100;
1652
    }
1653
    /* Write the configured values back to the Device Control Reg. */
1654
    E1000_WRITE_REG(hw, CTRL, ctrl);
1655
    return E1000_SUCCESS;
1656
}
1657
 
1658
/******************************************************************************
1659
 * Forces the MAC's flow control settings.
1660
 *
1661
 * hw - Struct containing variables accessed by shared code
1662
 *
1663
 * Sets the TFCE and RFCE bits in the device control register to reflect
1664
 * the adapter settings. TFCE and RFCE need to be explicitly set by
1665
 * software when a Copper PHY is used because autonegotiation is managed
1666
 * by the PHY rather than the MAC. Software must also configure these
1667
 * bits when link is forced on a fiber connection.
1668
 *****************************************************************************/
1669
int32_t
1670
e1000_force_mac_fc(struct e1000_hw *hw)
1671
{
1672
    uint32_t ctrl;
1673
 
1674
    DEBUGFUNC("e1000_force_mac_fc");
1675
 
1676
    /* Get the current configuration of the Device Control Register */
1677
    ctrl = E1000_READ_REG(hw, CTRL);
1678
 
1679
    /* Because we didn't get link via the internal auto-negotiation
1680
     * mechanism (we either forced link or we got link via PHY
1681
     * auto-neg), we have to manually enable/disable transmit an
1682
     * receive flow control.
1683
     *
1684
     * The "Case" statement below enables/disable flow control
1685
     * according to the "hw->fc" parameter.
1686
     *
1687
     * The possible values of the "fc" parameter are:
1688
     *      0:  Flow control is completely disabled
1689
     *      1:  Rx flow control is enabled (we can receive pause
1690
     *          frames but not send pause frames).
1691
     *      2:  Tx flow control is enabled (we can send pause frames
1692
     *          frames but we do not receive pause frames).
1693
     *      3:  Both Rx and TX flow control (symmetric) is enabled.
1694
     *  other:  No other values should be possible at this point.
1695
     */
1696
 
1697
    switch (hw->fc) {
1698
    case e1000_fc_none:
1699
        ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1700
        break;
1701
    case e1000_fc_rx_pause:
1702
        ctrl &= (~E1000_CTRL_TFCE);
1703
        ctrl |= E1000_CTRL_RFCE;
1704
        break;
1705
    case e1000_fc_tx_pause:
1706
        ctrl &= (~E1000_CTRL_RFCE);
1707
        ctrl |= E1000_CTRL_TFCE;
1708
        break;
1709
    case e1000_fc_full:
1710
        ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1711
        break;
1712
    default:
1713
        DEBUGOUT("Flow control param set incorrectly\n");
1714
        return -E1000_ERR_CONFIG;
1715
    }
1716
 
1717
    /* Disable TX Flow Control for 82542 (rev 2.0) */
1718
    if(hw->mac_type == e1000_82542_rev2_0)
1719
        ctrl &= (~E1000_CTRL_TFCE);
1720
 
1721
    E1000_WRITE_REG(hw, CTRL, ctrl);
1722
    return E1000_SUCCESS;
1723
}
1724
 
1725
/******************************************************************************
1726
 * Configures flow control settings after link is established
1727
 *
1728
 * hw - Struct containing variables accessed by shared code
1729
 *
1730
 * Should be called immediately after a valid link has been established.
1731
 * Forces MAC flow control settings if link was forced. When in MII/GMII mode
1732
 * and autonegotiation is enabled, the MAC flow control settings will be set
1733
 * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
1734
 * and RFCE bits will be automaticaly set to the negotiated flow control mode.
1735
 *****************************************************************************/
1736
int32_t
1737
e1000_config_fc_after_link_up(struct e1000_hw *hw)
1738
{
1739
    int32_t ret_val;
1740
    uint16_t mii_status_reg;
1741
    uint16_t mii_nway_adv_reg;
1742
    uint16_t mii_nway_lp_ability_reg;
1743
    uint16_t speed;
1744
    uint16_t duplex;
1745
 
1746
    DEBUGFUNC("e1000_config_fc_after_link_up");
1747
 
1748
    /* Check for the case where we have fiber media and auto-neg failed
1749
     * so we had to force link.  In this case, we need to force the
1750
     * configuration of the MAC to match the "fc" parameter.
1751
     */
1752
    if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1753
       ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
1754
       ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
1755
        if((ret_val = e1000_force_mac_fc(hw))) {
1756
            DEBUGOUT("Error forcing flow control settings\n");
1757
            return ret_val;
1758
        }
1759
    }
1760
 
1761
    /* Check for the case where we have copper media and auto-neg is
1762
     * enabled.  In this case, we need to check and see if Auto-Neg
1763
     * has completed, and if so, how the PHY and link partner has
1764
     * flow control configured.
1765
     */
1766
    if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
1767
        /* Read the MII Status Register and check to see if AutoNeg
1768
         * has completed.  We read this twice because this reg has
1769
         * some "sticky" (latched) bits.
1770
         */
1771
        if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg)))
1772
            return ret_val;
1773
        if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg)))
1774
            return ret_val;
1775
 
1776
        if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1777
            /* The AutoNeg process has completed, so we now need to
1778
             * read both the Auto Negotiation Advertisement Register
1779
             * (Address 4) and the Auto_Negotiation Base Page Ability
1780
             * Register (Address 5) to determine how flow control was
1781
             * negotiated.
1782
             */
1783
            if((ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
1784
                                             &mii_nway_adv_reg)))
1785
                return ret_val;
1786
            if((ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
1787
                                             &mii_nway_lp_ability_reg)))
1788
                return ret_val;
1789
 
1790
            /* Two bits in the Auto Negotiation Advertisement Register
1791
             * (Address 4) and two bits in the Auto Negotiation Base
1792
             * Page Ability Register (Address 5) determine flow control
1793
             * for both the PHY and the link partner.  The following
1794
             * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1795
             * 1999, describes these PAUSE resolution bits and how flow
1796
             * control is determined based upon these settings.
1797
             * NOTE:  DC = Don't Care
1798
             *
1799
             *   LOCAL DEVICE  |   LINK PARTNER
1800
             * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1801
             *-------|---------|-------|---------|--------------------
1802
             *   0   |    0    |  DC   |   DC    | e1000_fc_none
1803
             *   0   |    1    |   0   |   DC    | e1000_fc_none
1804
             *   0   |    1    |   1   |    0    | e1000_fc_none
1805
             *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
1806
             *   1   |    0    |   0   |   DC    | e1000_fc_none
1807
             *   1   |   DC    |   1   |   DC    | e1000_fc_full
1808
             *   1   |    1    |   0   |    0    | e1000_fc_none
1809
             *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
1810
             *
1811
             */
1812
            /* Are both PAUSE bits set to 1?  If so, this implies
1813
             * Symmetric Flow Control is enabled at both ends.  The
1814
             * ASM_DIR bits are irrelevant per the spec.
1815
             *
1816
             * For Symmetric Flow Control:
1817
             *
1818
             *   LOCAL DEVICE  |   LINK PARTNER
1819
             * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1820
             *-------|---------|-------|---------|--------------------
1821
             *   1   |   DC    |   1   |   DC    | e1000_fc_full
1822
             *
1823
             */
1824
            if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1825
               (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1826
                /* Now we need to check if the user selected RX ONLY
1827
                 * of pause frames.  In this case, we had to advertise
1828
                 * FULL flow control because we could not advertise RX
1829
                 * ONLY. Hence, we must now check to see if we need to
1830
                 * turn OFF  the TRANSMISSION of PAUSE frames.
1831
                 */
1832
                if(hw->original_fc == e1000_fc_full) {
1833
                    hw->fc = e1000_fc_full;
1834
                    DEBUGOUT("Flow Control = FULL.\r\n");
1835
                } else {
1836
                    hw->fc = e1000_fc_rx_pause;
1837
                    DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1838
                }
1839
            }
1840
            /* For receiving PAUSE frames ONLY.
1841
             *
1842
             *   LOCAL DEVICE  |   LINK PARTNER
1843
             * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1844
             *-------|---------|-------|---------|--------------------
1845
             *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
1846
             *
1847
             */
1848
            else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1849
                    (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1850
                    (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1851
                    (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1852
                hw->fc = e1000_fc_tx_pause;
1853
                DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
1854
            }
1855
            /* For transmitting PAUSE frames ONLY.
1856
             *
1857
             *   LOCAL DEVICE  |   LINK PARTNER
1858
             * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1859
             *-------|---------|-------|---------|--------------------
1860
             *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
1861
             *
1862
             */
1863
            else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1864
                    (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1865
                    !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1866
                    (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1867
                hw->fc = e1000_fc_rx_pause;
1868
                DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1869
            }
1870
            /* Per the IEEE spec, at this point flow control should be
1871
             * disabled.  However, we want to consider that we could
1872
             * be connected to a legacy switch that doesn't advertise
1873
             * desired flow control, but can be forced on the link
1874
             * partner.  So if we advertised no flow control, that is
1875
             * what we will resolve to.  If we advertised some kind of
1876
             * receive capability (Rx Pause Only or Full Flow Control)
1877
             * and the link partner advertised none, we will configure
1878
             * ourselves to enable Rx Flow Control only.  We can do
1879
             * this safely for two reasons:  If the link partner really
1880
             * didn't want flow control enabled, and we enable Rx, no
1881
             * harm done since we won't be receiving any PAUSE frames
1882
             * anyway.  If the intent on the link partner was to have
1883
             * flow control enabled, then by us enabling RX only, we
1884
             * can at least receive pause frames and process them.
1885
             * This is a good idea because in most cases, since we are
1886
             * predominantly a server NIC, more times than not we will
1887
             * be asked to delay transmission of packets than asking
1888
             * our link partner to pause transmission of frames.
1889
             */
1890
            else if((hw->original_fc == e1000_fc_none ||
1891
                     hw->original_fc == e1000_fc_tx_pause) ||
1892
                    hw->fc_strict_ieee) {
1893
                hw->fc = e1000_fc_none;
1894
                DEBUGOUT("Flow Control = NONE.\r\n");
1895
            } else {
1896
                hw->fc = e1000_fc_rx_pause;
1897
                DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1898
            }
1899
 
1900
            /* Now we need to do one last check...  If we auto-
1901
             * negotiated to HALF DUPLEX, flow control should not be
1902
             * enabled per IEEE 802.3 spec.
1903
             */
1904
            if((ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex))) {
1905
                DEBUGOUT("Error getting link speed and duplex\n");
1906
                return ret_val;
1907
            }
1908
 
1909
            if(duplex == HALF_DUPLEX)
1910
                hw->fc = e1000_fc_none;
1911
 
1912
            /* Now we call a subroutine to actually force the MAC
1913
             * controller to use the correct flow control settings.
1914
             */
1915
            if((ret_val = e1000_force_mac_fc(hw))) {
1916
                DEBUGOUT("Error forcing flow control settings\n");
1917
                return ret_val;
1918
            }
1919
        } else {
1920
            DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
1921
        }
1922
    }
1923
    return E1000_SUCCESS;
1924
}
1925
 
1926
/******************************************************************************
1927
 * Checks to see if the link status of the hardware has changed.
1928
 *
1929
 * hw - Struct containing variables accessed by shared code
1930
 *
1931
 * Called by any function that needs to check the link status of the adapter.
1932
 *****************************************************************************/
1933
int32_t
1934
e1000_check_for_link(struct e1000_hw *hw)
1935
{
1936
    uint32_t rxcw;
1937
    uint32_t ctrl;
1938
    uint32_t status;
1939
    uint32_t rctl;
1940
    uint32_t signal = 0;
1941
    int32_t ret_val;
1942
    uint16_t phy_data;
1943
 
1944
    DEBUGFUNC("e1000_check_for_link");
1945
 
1946
    /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
1947
     * set when the optics detect a signal. On older adapters, it will be
1948
     * cleared when there is a signal.  This applies to fiber media only.
1949
     */
1950
    if(hw->media_type == e1000_media_type_fiber)
1951
        signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
1952
 
1953
    ctrl = E1000_READ_REG(hw, CTRL);
1954
    status = E1000_READ_REG(hw, STATUS);
1955
    rxcw = E1000_READ_REG(hw, RXCW);
1956
 
1957
    /* If we have a copper PHY then we only want to go out to the PHY
1958
     * registers to see if Auto-Neg has completed and/or if our link
1959
     * status has changed.  The get_link_status flag will be set if we
1960
     * receive a Link Status Change interrupt or we have Rx Sequence
1961
     * Errors.
1962
     */
1963
    if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
1964
        /* First we want to see if the MII Status Register reports
1965
         * link.  If so, then we want to get the current speed/duplex
1966
         * of the PHY.
1967
         * Read the register twice since the link bit is sticky.
1968
         */
1969
        if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
1970
            return ret_val;
1971
        if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
1972
            return ret_val;
1973
 
1974
        if(phy_data & MII_SR_LINK_STATUS) {
1975
            hw->get_link_status = FALSE;
1976
            /* Check if there was DownShift, must be checked immediately after
1977
             * link-up */
1978
            e1000_check_downshift(hw);
1979
 
1980
        } else {
1981
            /* No link detected */
1982
            e1000_config_dsp_after_link_change(hw, FALSE);
1983
            return 0;
1984
        }
1985
 
1986
        /* If we are forcing speed/duplex, then we simply return since
1987
         * we have already determined whether we have link or not.
1988
         */
1989
        if(!hw->autoneg) return -E1000_ERR_CONFIG;
1990
 
1991
        /* optimize the dsp settings for the igp phy */
1992
        e1000_config_dsp_after_link_change(hw, TRUE);
1993
 
1994
        /* We have a M88E1000 PHY and Auto-Neg is enabled.  If we
1995
         * have Si on board that is 82544 or newer, Auto
1996
         * Speed Detection takes care of MAC speed/duplex
1997
         * configuration.  So we only need to configure Collision
1998
         * Distance in the MAC.  Otherwise, we need to force
1999
         * speed/duplex on the MAC to the current PHY speed/duplex
2000
         * settings.
2001
         */
2002
        if(hw->mac_type >= e1000_82544)
2003
            e1000_config_collision_dist(hw);
2004
        else {
2005
            if((ret_val = e1000_config_mac_to_phy(hw))) {
2006
                DEBUGOUT("Error configuring MAC to PHY settings\n");
2007
                return ret_val;
2008
            }
2009
        }
2010
 
2011
        /* Configure Flow Control now that Auto-Neg has completed. First, we
2012
         * need to restore the desired flow control settings because we may
2013
         * have had to re-autoneg with a different link partner.
2014
         */
2015
        if((ret_val = e1000_config_fc_after_link_up(hw))) {
2016
            DEBUGOUT("Error configuring flow control\n");
2017
            return ret_val;
2018
        }
2019
 
2020
        /* At this point we know that we are on copper and we have
2021
         * auto-negotiated link.  These are conditions for checking the link
2022
         * partner capability register.  We use the link speed to determine if
2023
         * TBI compatibility needs to be turned on or off.  If the link is not
2024
         * at gigabit speed, then TBI compatibility is not needed.  If we are
2025
         * at gigabit speed, we turn on TBI compatibility.
2026
         */
2027
        if(hw->tbi_compatibility_en) {
2028
            uint16_t speed, duplex;
2029
            e1000_get_speed_and_duplex(hw, &speed, &duplex);
2030
            if(speed != SPEED_1000) {
2031
                /* If link speed is not set to gigabit speed, we do not need
2032
                 * to enable TBI compatibility.
2033
                 */
2034
                if(hw->tbi_compatibility_on) {
2035
                    /* If we previously were in the mode, turn it off. */
2036
                    rctl = E1000_READ_REG(hw, RCTL);
2037
                    rctl &= ~E1000_RCTL_SBP;
2038
                    E1000_WRITE_REG(hw, RCTL, rctl);
2039
                    hw->tbi_compatibility_on = FALSE;
2040
                }
2041
            } else {
2042
                /* If TBI compatibility is was previously off, turn it on. For
2043
                 * compatibility with a TBI link partner, we will store bad
2044
                 * packets. Some frames have an additional byte on the end and
2045
                 * will look like CRC errors to to the hardware.
2046
                 */
2047
                if(!hw->tbi_compatibility_on) {
2048
                    hw->tbi_compatibility_on = TRUE;
2049
                    rctl = E1000_READ_REG(hw, RCTL);
2050
                    rctl |= E1000_RCTL_SBP;
2051
                    E1000_WRITE_REG(hw, RCTL, rctl);
2052
                }
2053
            }
2054
        }
2055
    }
2056
    /* If we don't have link (auto-negotiation failed or link partner cannot
2057
     * auto-negotiate), the cable is plugged in (we have signal), and our
2058
     * link partner is not trying to auto-negotiate with us (we are receiving
2059
     * idles or data), we need to force link up. We also need to give
2060
     * auto-negotiation time to complete, in case the cable was just plugged
2061
     * in. The autoneg_failed flag does this.
2062
     */
2063
    else if((((hw->media_type == e1000_media_type_fiber) &&
2064
            ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
2065
            (hw->media_type == e1000_media_type_internal_serdes)) &&
2066
            (!(status & E1000_STATUS_LU)) &&
2067
            (!(rxcw & E1000_RXCW_C))) {
2068
        if(hw->autoneg_failed == 0) {
2069
            hw->autoneg_failed = 1;
2070
            return 0;
2071
        }
2072
        DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
2073
 
2074
        /* Disable auto-negotiation in the TXCW register */
2075
        E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
2076
 
2077
        /* Force link-up and also force full-duplex. */
2078
        ctrl = E1000_READ_REG(hw, CTRL);
2079
        ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
2080
        E1000_WRITE_REG(hw, CTRL, ctrl);
2081
 
2082
        /* Configure Flow Control after forcing link up. */
2083
        if((ret_val = e1000_config_fc_after_link_up(hw))) {
2084
            DEBUGOUT("Error configuring flow control\n");
2085
            return ret_val;
2086
        }
2087
    }
2088
    /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
2089
     * auto-negotiation in the TXCW register and disable forced link in the
2090
     * Device Control register in an attempt to auto-negotiate with our link
2091
     * partner.
2092
     */
2093
    else if(((hw->media_type == e1000_media_type_fiber) ||
2094
             (hw->media_type == e1000_media_type_internal_serdes)) &&
2095
              (ctrl & E1000_CTRL_SLU) &&
2096
              (rxcw & E1000_RXCW_C)) {
2097
        DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
2098
        E1000_WRITE_REG(hw, TXCW, hw->txcw);
2099
        E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
2100
 
2101
        hw->serdes_link_down = FALSE;
2102
    }
2103
    /* If we force link for non-auto-negotiation switch, check link status
2104
     * based on MAC synchronization for internal serdes media type.
2105
     */
2106
    else if((hw->media_type == e1000_media_type_internal_serdes) &&
2107
            !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2108
        /* SYNCH bit and IV bit are sticky. */
2109
        udelay(10);
2110
        if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
2111
            if(!(rxcw & E1000_RXCW_IV)) {
2112
                hw->serdes_link_down = FALSE;
2113
                DEBUGOUT("SERDES: Link is up.\n");
2114
            }
2115
        } else {
2116
            hw->serdes_link_down = TRUE;
2117
            DEBUGOUT("SERDES: Link is down.\n");
2118
        }
2119
    }
2120
    if((hw->media_type == e1000_media_type_internal_serdes) &&
2121
       (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
2122
        hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
2123
    }
2124
    return E1000_SUCCESS;
2125
}
2126
 
2127
/******************************************************************************
2128
 * Detects the current speed and duplex settings of the hardware.
2129
 *
2130
 * hw - Struct containing variables accessed by shared code
2131
 * speed - Speed of the connection
2132
 * duplex - Duplex setting of the connection
2133
 *****************************************************************************/
2134
int32_t
2135
e1000_get_speed_and_duplex(struct e1000_hw *hw,
2136
                           uint16_t *speed,
2137
                           uint16_t *duplex)
2138
{
2139
    uint32_t status;
2140
    int32_t ret_val;
2141
    uint16_t phy_data;
2142
 
2143
    DEBUGFUNC("e1000_get_speed_and_duplex");
2144
 
2145
    if(hw->mac_type >= e1000_82543) {
2146
        status = E1000_READ_REG(hw, STATUS);
2147
        if(status & E1000_STATUS_SPEED_1000) {
2148
            *speed = SPEED_1000;
2149
            DEBUGOUT("1000 Mbs, ");
2150
        } else if(status & E1000_STATUS_SPEED_100) {
2151
            *speed = SPEED_100;
2152
            DEBUGOUT("100 Mbs, ");
2153
        } else {
2154
            *speed = SPEED_10;
2155
            DEBUGOUT("10 Mbs, ");
2156
        }
2157
 
2158
        if(status & E1000_STATUS_FD) {
2159
            *duplex = FULL_DUPLEX;
2160
            DEBUGOUT("Full Duplex\r\n");
2161
        } else {
2162
            *duplex = HALF_DUPLEX;
2163
            DEBUGOUT(" Half Duplex\r\n");
2164
        }
2165
    } else {
2166
        DEBUGOUT("1000 Mbs, Full Duplex\r\n");
2167
        *speed = SPEED_1000;
2168
        *duplex = FULL_DUPLEX;
2169
    }
2170
 
2171
    /* IGP01 PHY may advertise full duplex operation after speed downgrade even
2172
     * if it is operating at half duplex.  Here we set the duplex settings to
2173
     * match the duplex in the link partner's capabilities.
2174
     */
2175
    if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
2176
        if((ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data)))
2177
            return ret_val;
2178
 
2179
        if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
2180
            *duplex = HALF_DUPLEX;
2181
        else {
2182
            if((ret_val == e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data)))
2183
                return ret_val;
2184
            if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
2185
               (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
2186
                *duplex = HALF_DUPLEX;
2187
        }
2188
    }
2189
 
2190
    return E1000_SUCCESS;
2191
}
2192
 
2193
/******************************************************************************
2194
* Blocks until autoneg completes or times out (~4.5 seconds)
2195
*
2196
* hw - Struct containing variables accessed by shared code
2197
******************************************************************************/
2198
int32_t
2199
e1000_wait_autoneg(struct e1000_hw *hw)
2200
{
2201
    int32_t ret_val;
2202
    uint16_t i;
2203
    uint16_t phy_data;
2204
 
2205
    DEBUGFUNC("e1000_wait_autoneg");
2206
    DEBUGOUT("Waiting for Auto-Neg to complete.\n");
2207
 
2208
    /* We will wait for autoneg to complete or 4.5 seconds to expire. */
2209
    for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
2210
        /* Read the MII Status Register and wait for Auto-Neg
2211
         * Complete bit to be set.
2212
         */
2213
        if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
2214
            return ret_val;
2215
        if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
2216
            return ret_val;
2217
        if(phy_data & MII_SR_AUTONEG_COMPLETE) {
2218
            return E1000_SUCCESS;
2219
        }
2220
        msec_delay(100);
2221
    }
2222
    return E1000_SUCCESS;
2223
}
2224
 
2225
/******************************************************************************
2226
* Raises the Management Data Clock
2227
*
2228
* hw - Struct containing variables accessed by shared code
2229
* ctrl - Device control register's current value
2230
******************************************************************************/
2231
static void
2232
e1000_raise_mdi_clk(struct e1000_hw *hw,
2233
                    uint32_t *ctrl)
2234
{
2235
    /* Raise the clock input to the Management Data Clock (by setting the MDC
2236
     * bit), and then delay 10 microseconds.
2237
     */
2238
    E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
2239
    E1000_WRITE_FLUSH(hw);
2240
    udelay(10);
2241
}
2242
 
2243
/******************************************************************************
2244
* Lowers the Management Data Clock
2245
*
2246
* hw - Struct containing variables accessed by shared code
2247
* ctrl - Device control register's current value
2248
******************************************************************************/
2249
static void
2250
e1000_lower_mdi_clk(struct e1000_hw *hw,
2251
                    uint32_t *ctrl)
2252
{
2253
    /* Lower the clock input to the Management Data Clock (by clearing the MDC
2254
     * bit), and then delay 10 microseconds.
2255
     */
2256
    E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
2257
    E1000_WRITE_FLUSH(hw);
2258
    udelay(10);
2259
}
2260
 
2261
/******************************************************************************
2262
* Shifts data bits out to the PHY
2263
*
2264
* hw - Struct containing variables accessed by shared code
2265
* data - Data to send out to the PHY
2266
* count - Number of bits to shift out
2267
*
2268
* Bits are shifted out in MSB to LSB order.
2269
******************************************************************************/
2270
static void
2271
e1000_shift_out_mdi_bits(struct e1000_hw *hw,
2272
                         uint32_t data,
2273
                         uint16_t count)
2274
{
2275
    uint32_t ctrl;
2276
    uint32_t mask;
2277
 
2278
    /* We need to shift "count" number of bits out to the PHY. So, the value
2279
     * in the "data" parameter will be shifted out to the PHY one bit at a
2280
     * time. In order to do this, "data" must be broken down into bits.
2281
     */
2282
    mask = 0x01;
2283
    mask <<= (count - 1);
2284
 
2285
    ctrl = E1000_READ_REG(hw, CTRL);
2286
 
2287
    /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
2288
    ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
2289
 
2290
    while(mask) {
2291
        /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
2292
         * then raising and lowering the Management Data Clock. A "0" is
2293
         * shifted out to the PHY by setting the MDIO bit to "0" and then
2294
         * raising and lowering the clock.
2295
         */
2296
        if(data & mask) ctrl |= E1000_CTRL_MDIO;
2297
        else ctrl &= ~E1000_CTRL_MDIO;
2298
 
2299
        E1000_WRITE_REG(hw, CTRL, ctrl);
2300
        E1000_WRITE_FLUSH(hw);
2301
 
2302
        udelay(10);
2303
 
2304
        e1000_raise_mdi_clk(hw, &ctrl);
2305
        e1000_lower_mdi_clk(hw, &ctrl);
2306
 
2307
        mask = mask >> 1;
2308
    }
2309
}
2310
 
2311
/******************************************************************************
2312
* Shifts data bits in from the PHY
2313
*
2314
* hw - Struct containing variables accessed by shared code
2315
*
2316
* Bits are shifted in in MSB to LSB order.
2317
******************************************************************************/
2318
static uint16_t
2319
e1000_shift_in_mdi_bits(struct e1000_hw *hw)
2320
{
2321
    uint32_t ctrl;
2322
    uint16_t data = 0;
2323
    uint8_t i;
2324
 
2325
    /* In order to read a register from the PHY, we need to shift in a total
2326
     * of 18 bits from the PHY. The first two bit (turnaround) times are used
2327
     * to avoid contention on the MDIO pin when a read operation is performed.
2328
     * These two bits are ignored by us and thrown away. Bits are "shifted in"
2329
     * by raising the input to the Management Data Clock (setting the MDC bit),
2330
     * and then reading the value of the MDIO bit.
2331
     */
2332
    ctrl = E1000_READ_REG(hw, CTRL);
2333
 
2334
    /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
2335
    ctrl &= ~E1000_CTRL_MDIO_DIR;
2336
    ctrl &= ~E1000_CTRL_MDIO;
2337
 
2338
    E1000_WRITE_REG(hw, CTRL, ctrl);
2339
    E1000_WRITE_FLUSH(hw);
2340
 
2341
    /* Raise and Lower the clock before reading in the data. This accounts for
2342
     * the turnaround bits. The first clock occurred when we clocked out the
2343
     * last bit of the Register Address.
2344
     */
2345
    e1000_raise_mdi_clk(hw, &ctrl);
2346
    e1000_lower_mdi_clk(hw, &ctrl);
2347
 
2348
    for(data = 0, i = 0; i < 16; i++) {
2349
        data = data << 1;
2350
        e1000_raise_mdi_clk(hw, &ctrl);
2351
        ctrl = E1000_READ_REG(hw, CTRL);
2352
        /* Check to see if we shifted in a "1". */
2353
        if(ctrl & E1000_CTRL_MDIO) data |= 1;
2354
        e1000_lower_mdi_clk(hw, &ctrl);
2355
    }
2356
 
2357
    e1000_raise_mdi_clk(hw, &ctrl);
2358
    e1000_lower_mdi_clk(hw, &ctrl);
2359
 
2360
    return data;
2361
}
2362
 
2363
/*****************************************************************************
2364
* Reads the value from a PHY register, if the value is on a specific non zero
2365
* page, sets the page first.
2366
* hw - Struct containing variables accessed by shared code
2367
* reg_addr - address of the PHY register to read
2368
******************************************************************************/
2369
int32_t
2370
e1000_read_phy_reg(struct e1000_hw *hw,
2371
                   uint32_t reg_addr,
2372
                   uint16_t *phy_data)
2373
{
2374
    uint32_t ret_val;
2375
 
2376
    DEBUGFUNC("e1000_read_phy_reg");
2377
 
2378
    if(hw->phy_type == e1000_phy_igp &&
2379
       (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2380
        if((ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2381
                                             (uint16_t)reg_addr)))
2382
            return ret_val;
2383
    }
2384
 
2385
    ret_val = e1000_read_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
2386
                                    phy_data);
2387
 
2388
    return ret_val;
2389
}
2390
 
2391
int32_t
2392
e1000_read_phy_reg_ex(struct e1000_hw *hw,
2393
                      uint32_t reg_addr,
2394
                      uint16_t *phy_data)
2395
{
2396
    uint32_t i;
2397
    uint32_t mdic = 0;
2398
    const uint32_t phy_addr = 1;
2399
 
2400
    DEBUGFUNC("e1000_read_phy_reg_ex");
2401
 
2402
    if(reg_addr > MAX_PHY_REG_ADDRESS) {
2403
        DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2404
        return -E1000_ERR_PARAM;
2405
    }
2406
 
2407
    if(hw->mac_type > e1000_82543) {
2408
        /* Set up Op-code, Phy Address, and register address in the MDI
2409
         * Control register.  The MAC will take care of interfacing with the
2410
         * PHY to retrieve the desired data.
2411
         */
2412
        mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
2413
                (phy_addr << E1000_MDIC_PHY_SHIFT) |
2414
                (E1000_MDIC_OP_READ));
2415
 
2416
        E1000_WRITE_REG(hw, MDIC, mdic);
2417
 
2418
        /* Poll the ready bit to see if the MDI read completed */
2419
        for(i = 0; i < 64; i++) {
2420
            udelay(50);
2421
            mdic = E1000_READ_REG(hw, MDIC);
2422
            if(mdic & E1000_MDIC_READY) break;
2423
        }
2424
        if(!(mdic & E1000_MDIC_READY)) {
2425
            DEBUGOUT("MDI Read did not complete\n");
2426
            return -E1000_ERR_PHY;
2427
        }
2428
        if(mdic & E1000_MDIC_ERROR) {
2429
            DEBUGOUT("MDI Error\n");
2430
            return -E1000_ERR_PHY;
2431
        }
2432
        *phy_data = (uint16_t) mdic;
2433
    } else {
2434
        /* We must first send a preamble through the MDIO pin to signal the
2435
         * beginning of an MII instruction.  This is done by sending 32
2436
         * consecutive "1" bits.
2437
         */
2438
        e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2439
 
2440
        /* Now combine the next few fields that are required for a read
2441
         * operation.  We use this method instead of calling the
2442
         * e1000_shift_out_mdi_bits routine five different times. The format of
2443
         * a MII read instruction consists of a shift out of 14 bits and is
2444
         * defined as follows:
2445
         *    <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
2446
         * followed by a shift in of 18 bits.  This first two bits shifted in
2447
         * are TurnAround bits used to avoid contention on the MDIO pin when a
2448
         * READ operation is performed.  These two bits are thrown away
2449
         * followed by a shift in of 16 bits which contains the desired data.
2450
         */
2451
        mdic = ((reg_addr) | (phy_addr << 5) |
2452
                (PHY_OP_READ << 10) | (PHY_SOF << 12));
2453
 
2454
        e1000_shift_out_mdi_bits(hw, mdic, 14);
2455
 
2456
        /* Now that we've shifted out the read command to the MII, we need to
2457
         * "shift in" the 16-bit value (18 total bits) of the requested PHY
2458
         * register address.
2459
         */
2460
        *phy_data = e1000_shift_in_mdi_bits(hw);
2461
    }
2462
    return E1000_SUCCESS;
2463
}
2464
 
2465
/******************************************************************************
2466
* Writes a value to a PHY register
2467
*
2468
* hw - Struct containing variables accessed by shared code
2469
* reg_addr - address of the PHY register to write
2470
* data - data to write to the PHY
2471
******************************************************************************/
2472
int32_t
2473
e1000_write_phy_reg(struct e1000_hw *hw,
2474
                    uint32_t reg_addr,
2475
                    uint16_t phy_data)
2476
{
2477
    uint32_t ret_val;
2478
 
2479
    DEBUGFUNC("e1000_write_phy_reg");
2480
 
2481
    if(hw->phy_type == e1000_phy_igp &&
2482
       (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
2483
        if((ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
2484
                                             (uint16_t)reg_addr)))
2485
            return ret_val;
2486
    }
2487
 
2488
    ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT & reg_addr,
2489
                                     phy_data);
2490
 
2491
    return ret_val;
2492
}
2493
 
2494
int32_t
2495
e1000_write_phy_reg_ex(struct e1000_hw *hw,
2496
                    uint32_t reg_addr,
2497
                    uint16_t phy_data)
2498
{
2499
    uint32_t i;
2500
    uint32_t mdic = 0;
2501
    const uint32_t phy_addr = 1;
2502
 
2503
    DEBUGFUNC("e1000_write_phy_reg_ex");
2504
 
2505
    if(reg_addr > MAX_PHY_REG_ADDRESS) {
2506
        DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
2507
        return -E1000_ERR_PARAM;
2508
    }
2509
 
2510
    if(hw->mac_type > e1000_82543) {
2511
        /* Set up Op-code, Phy Address, register address, and data intended
2512
         * for the PHY register in the MDI Control register.  The MAC will take
2513
         * care of interfacing with the PHY to send the desired data.
2514
         */
2515
        mdic = (((uint32_t) phy_data) |
2516
                (reg_addr << E1000_MDIC_REG_SHIFT) |
2517
                (phy_addr << E1000_MDIC_PHY_SHIFT) |
2518
                (E1000_MDIC_OP_WRITE));
2519
 
2520
        E1000_WRITE_REG(hw, MDIC, mdic);
2521
 
2522
        /* Poll the ready bit to see if the MDI read completed */
2523
        for(i = 0; i < 640; i++) {
2524
            udelay(5);
2525
            mdic = E1000_READ_REG(hw, MDIC);
2526
            if(mdic & E1000_MDIC_READY) break;
2527
        }
2528
        if(!(mdic & E1000_MDIC_READY)) {
2529
            DEBUGOUT("MDI Write did not complete\n");
2530
            return -E1000_ERR_PHY;
2531
        }
2532
    } else {
2533
        /* We'll need to use the SW defined pins to shift the write command
2534
         * out to the PHY. We first send a preamble to the PHY to signal the
2535
         * beginning of the MII instruction.  This is done by sending 32
2536
         * consecutive "1" bits.
2537
         */
2538
        e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
2539
 
2540
        /* Now combine the remaining required fields that will indicate a
2541
         * write operation. We use this method instead of calling the
2542
         * e1000_shift_out_mdi_bits routine for each field in the command. The
2543
         * format of a MII write instruction is as follows:
2544
         * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
2545
         */
2546
        mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2547
                (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2548
        mdic <<= 16;
2549
        mdic |= (uint32_t) phy_data;
2550
 
2551
        e1000_shift_out_mdi_bits(hw, mdic, 32);
2552
    }
2553
 
2554
    return E1000_SUCCESS;
2555
}
2556
 
2557
/******************************************************************************
2558
* Returns the PHY to the power-on reset state
2559
*
2560
* hw - Struct containing variables accessed by shared code
2561
******************************************************************************/
2562
void
2563
e1000_phy_hw_reset(struct e1000_hw *hw)
2564
{
2565
    uint32_t ctrl, ctrl_ext;
2566
    uint32_t led_ctrl;
2567
 
2568
    DEBUGFUNC("e1000_phy_hw_reset");
2569
 
2570
    DEBUGOUT("Resetting Phy...\n");
2571
 
2572
    if(hw->mac_type > e1000_82543) {
2573
        /* Read the device control register and assert the E1000_CTRL_PHY_RST
2574
         * bit. Then, take it out of reset.
2575
         */
2576
        ctrl = E1000_READ_REG(hw, CTRL);
2577
        E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2578
        E1000_WRITE_FLUSH(hw);
2579
        msec_delay(10);
2580
        E1000_WRITE_REG(hw, CTRL, ctrl);
2581
        E1000_WRITE_FLUSH(hw);
2582
    } else {
2583
        /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
2584
         * bit to put the PHY into reset. Then, take it out of reset.
2585
         */
2586
        ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2587
        ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2588
        ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2589
        E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2590
        E1000_WRITE_FLUSH(hw);
2591
        msec_delay(10);
2592
        ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2593
        E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2594
        E1000_WRITE_FLUSH(hw);
2595
    }
2596
    udelay(150);
2597
 
2598
    if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2599
        /* Configure activity LED after PHY reset */
2600
        led_ctrl = E1000_READ_REG(hw, LEDCTL);
2601
        led_ctrl &= IGP_ACTIVITY_LED_MASK;
2602
        led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2603
        E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2604
    }
2605
}
2606
 
2607
/******************************************************************************
2608
* Resets the PHY
2609
*
2610
* hw - Struct containing variables accessed by shared code
2611
*
2612
* Sets bit 15 of the MII Control regiser
2613
******************************************************************************/
2614
int32_t
2615
e1000_phy_reset(struct e1000_hw *hw)
2616
{
2617
    int32_t ret_val;
2618
    uint16_t phy_data;
2619
 
2620
    DEBUGFUNC("e1000_phy_reset");
2621
 
2622
    if(hw->mac_type != e1000_82541_rev_2) {
2623
        if((ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data)))
2624
            return ret_val;
2625
 
2626
        phy_data |= MII_CR_RESET;
2627
        if((ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data)))
2628
            return ret_val;
2629
 
2630
        udelay(1);
2631
    } else e1000_phy_hw_reset(hw);
2632
 
2633
    if(hw->phy_type == e1000_phy_igp)
2634
        e1000_phy_init_script(hw);
2635
 
2636
    return E1000_SUCCESS;
2637
}
2638
 
2639
/******************************************************************************
2640
* Probes the expected PHY address for known PHY IDs
2641
*
2642
* hw - Struct containing variables accessed by shared code
2643
******************************************************************************/
2644
int32_t
2645
e1000_detect_gig_phy(struct e1000_hw *hw)
2646
{
2647
    int32_t phy_init_status, ret_val;
2648
    uint16_t phy_id_high, phy_id_low;
2649
    boolean_t match = FALSE;
2650
 
2651
    DEBUGFUNC("e1000_detect_gig_phy");
2652
 
2653
    /* Read the PHY ID Registers to identify which PHY is onboard. */
2654
    if((ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high)))
2655
        return ret_val;
2656
 
2657
    hw->phy_id = (uint32_t) (phy_id_high << 16);
2658
    udelay(20);
2659
    if((ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low)))
2660
        return ret_val;
2661
 
2662
    hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2663
    hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
2664
 
2665
    switch(hw->mac_type) {
2666
    case e1000_82543:
2667
        if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
2668
        break;
2669
    case e1000_82544:
2670
        if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
2671
        break;
2672
    case e1000_82540:
2673
    case e1000_82545:
2674
    case e1000_82545_rev_3:
2675
    case e1000_82546:
2676
    case e1000_82546_rev_3:
2677
        if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
2678
        break;
2679
    case e1000_82541:
2680
    case e1000_82541_rev_2:
2681
    case e1000_82547:
2682
    case e1000_82547_rev_2:
2683
        if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
2684
        break;
2685
    default:
2686
        DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
2687
        return -E1000_ERR_CONFIG;
2688
    }
2689
    phy_init_status = e1000_set_phy_type(hw);
2690
 
2691
    if ((match) && (phy_init_status == E1000_SUCCESS)) {
2692
        DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
2693
        return E1000_SUCCESS;
2694
    }
2695
    DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
2696
    return -E1000_ERR_PHY;
2697
}
2698
 
2699
/******************************************************************************
2700
* Resets the PHY's DSP
2701
*
2702
* hw - Struct containing variables accessed by shared code
2703
******************************************************************************/
2704
static int32_t
2705
e1000_phy_reset_dsp(struct e1000_hw *hw)
2706
{
2707
    int32_t ret_val;
2708
    DEBUGFUNC("e1000_phy_reset_dsp");
2709
 
2710
    do {
2711
        if((ret_val = e1000_write_phy_reg(hw, 29, 0x001d))) break;
2712
        if((ret_val = e1000_write_phy_reg(hw, 30, 0x00c1))) break;
2713
        if((ret_val = e1000_write_phy_reg(hw, 30, 0x0000))) break;
2714
        ret_val = E1000_SUCCESS;
2715
    } while(0);
2716
 
2717
    return ret_val;
2718
}
2719
 
2720
/******************************************************************************
2721
* Get PHY information from various PHY registers for igp PHY only.
2722
*
2723
* hw - Struct containing variables accessed by shared code
2724
* phy_info - PHY information structure
2725
******************************************************************************/
2726
int32_t
2727
e1000_phy_igp_get_info(struct e1000_hw *hw,
2728
                       struct e1000_phy_info *phy_info)
2729
{
2730
    int32_t ret_val;
2731
    uint16_t phy_data, polarity, min_length, max_length, average;
2732
 
2733
    DEBUGFUNC("e1000_phy_igp_get_info");
2734
 
2735
    /* The downshift status is checked only once, after link is established,
2736
     * and it stored in the hw->speed_downgraded parameter. */
2737
    phy_info->downshift = hw->speed_downgraded;
2738
 
2739
    /* IGP01E1000 does not need to support it. */
2740
    phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
2741
 
2742
    /* IGP01E1000 always correct polarity reversal */
2743
    phy_info->polarity_correction = e1000_polarity_reversal_enabled;
2744
 
2745
    /* Check polarity status */
2746
    if((ret_val = e1000_check_polarity(hw, &polarity)))
2747
        return ret_val;
2748
 
2749
    phy_info->cable_polarity = polarity;
2750
 
2751
    if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
2752
                                     &phy_data)))
2753
        return ret_val;
2754
 
2755
    phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
2756
                          IGP01E1000_PSSR_MDIX_SHIFT;
2757
 
2758
    if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
2759
       IGP01E1000_PSSR_SPEED_1000MBPS) {
2760
        /* Local/Remote Receiver Information are only valid at 1000 Mbps */
2761
        if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data)))
2762
            return ret_val;
2763
 
2764
        phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2765
                             SR_1000T_LOCAL_RX_STATUS_SHIFT;
2766
        phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2767
                              SR_1000T_REMOTE_RX_STATUS_SHIFT;
2768
 
2769
        /* Get cable length */
2770
        if((ret_val = e1000_get_cable_length(hw, &min_length, &max_length)))
2771
            return ret_val;
2772
 
2773
        /* transalte to old method */
2774
        average = (max_length + min_length) / 2;
2775
 
2776
        if(average <= e1000_igp_cable_length_50)
2777
            phy_info->cable_length = e1000_cable_length_50;
2778
        else if(average <= e1000_igp_cable_length_80)
2779
            phy_info->cable_length = e1000_cable_length_50_80;
2780
        else if(average <= e1000_igp_cable_length_110)
2781
            phy_info->cable_length = e1000_cable_length_80_110;
2782
        else if(average <= e1000_igp_cable_length_140)
2783
            phy_info->cable_length = e1000_cable_length_110_140;
2784
        else
2785
            phy_info->cable_length = e1000_cable_length_140;
2786
    }
2787
 
2788
    return E1000_SUCCESS;
2789
}
2790
 
2791
/******************************************************************************
2792
* Get PHY information from various PHY registers fot m88 PHY only.
2793
*
2794
* hw - Struct containing variables accessed by shared code
2795
* phy_info - PHY information structure
2796
******************************************************************************/
2797
int32_t
2798
e1000_phy_m88_get_info(struct e1000_hw *hw,
2799
                       struct e1000_phy_info *phy_info)
2800
{
2801
    int32_t ret_val;
2802
    uint16_t phy_data, polarity;
2803
 
2804
    DEBUGFUNC("e1000_phy_m88_get_info");
2805
 
2806
    /* The downshift status is checked only once, after link is established,
2807
     * and it stored in the hw->speed_downgraded parameter. */
2808
    phy_info->downshift = hw->speed_downgraded;
2809
 
2810
    if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data)))
2811
        return ret_val;
2812
 
2813
    phy_info->extended_10bt_distance =
2814
        (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
2815
        M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
2816
    phy_info->polarity_correction =
2817
        (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
2818
        M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
2819
 
2820
    /* Check polarity status */
2821
    if((ret_val = e1000_check_polarity(hw, &polarity)))
2822
        return ret_val;
2823
 
2824
    phy_info->cable_polarity = polarity;
2825
 
2826
    if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data)))
2827
        return ret_val;
2828
 
2829
    phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
2830
                          M88E1000_PSSR_MDIX_SHIFT;
2831
 
2832
    if(phy_data & M88E1000_PSSR_1000MBS) {
2833
        /* Cable Length Estimation and Local/Remote Receiver Informatoion
2834
         * are only valid at 1000 Mbps
2835
         */
2836
        phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
2837
                                  M88E1000_PSSR_CABLE_LENGTH_SHIFT);
2838
 
2839
        if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data)))
2840
            return ret_val;
2841
 
2842
        phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2843
                             SR_1000T_LOCAL_RX_STATUS_SHIFT;
2844
 
2845
        phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2846
                              SR_1000T_REMOTE_RX_STATUS_SHIFT;
2847
    }
2848
 
2849
    return E1000_SUCCESS;
2850
}
2851
 
2852
/******************************************************************************
2853
* Get PHY information from various PHY registers
2854
*
2855
* hw - Struct containing variables accessed by shared code
2856
* phy_info - PHY information structure
2857
******************************************************************************/
2858
int32_t
2859
e1000_phy_get_info(struct e1000_hw *hw,
2860
                   struct e1000_phy_info *phy_info)
2861
{
2862
    int32_t ret_val;
2863
    uint16_t phy_data;
2864
 
2865
    DEBUGFUNC("e1000_phy_get_info");
2866
 
2867
    phy_info->cable_length = e1000_cable_length_undefined;
2868
    phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
2869
    phy_info->cable_polarity = e1000_rev_polarity_undefined;
2870
    phy_info->downshift = e1000_downshift_undefined;
2871
    phy_info->polarity_correction = e1000_polarity_reversal_undefined;
2872
    phy_info->mdix_mode = e1000_auto_x_mode_undefined;
2873
    phy_info->local_rx = e1000_1000t_rx_status_undefined;
2874
    phy_info->remote_rx = e1000_1000t_rx_status_undefined;
2875
 
2876
    if(hw->media_type != e1000_media_type_copper) {
2877
        DEBUGOUT("PHY info is only valid for copper media\n");
2878
        return -E1000_ERR_CONFIG;
2879
    }
2880
 
2881
    if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
2882
        return ret_val;
2883
 
2884
    if((ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data)))
2885
        return ret_val;
2886
 
2887
    if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
2888
        DEBUGOUT("PHY info is only valid if link is up\n");
2889
        return -E1000_ERR_CONFIG;
2890
    }
2891
 
2892
    if(hw->phy_type == e1000_phy_igp)
2893
        return e1000_phy_igp_get_info(hw, phy_info);
2894
    else
2895
        return e1000_phy_m88_get_info(hw, phy_info);
2896
}
2897
 
2898
int32_t
2899
e1000_validate_mdi_setting(struct e1000_hw *hw)
2900
{
2901
    DEBUGFUNC("e1000_validate_mdi_settings");
2902
 
2903
    if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
2904
        DEBUGOUT("Invalid MDI setting detected\n");
2905
        hw->mdix = 1;
2906
        return -E1000_ERR_CONFIG;
2907
    }
2908
    return E1000_SUCCESS;
2909
}
2910
 
2911
 
2912
/******************************************************************************
2913
 * Sets up eeprom variables in the hw struct.  Must be called after mac_type
2914
 * is configured.
2915
 *
2916
 * hw - Struct containing variables accessed by shared code
2917
 *****************************************************************************/
2918
void
2919
e1000_init_eeprom_params(struct e1000_hw *hw)
2920
{
2921
    struct e1000_eeprom_info *eeprom = &hw->eeprom;
2922
    uint32_t eecd = E1000_READ_REG(hw, EECD);
2923
    uint16_t eeprom_size;
2924
 
2925
    DEBUGFUNC("e1000_init_eeprom_params");
2926
 
2927
    switch (hw->mac_type) {
2928
    case e1000_82542_rev2_0:
2929
    case e1000_82542_rev2_1:
2930
    case e1000_82543:
2931
    case e1000_82544:
2932
        eeprom->type = e1000_eeprom_microwire;
2933
        eeprom->word_size = 64;
2934
        eeprom->opcode_bits = 3;
2935
        eeprom->address_bits = 6;
2936
        eeprom->delay_usec = 50;
2937
        break;
2938
    case e1000_82540:
2939
    case e1000_82545:
2940
    case e1000_82545_rev_3:
2941
    case e1000_82546:
2942
    case e1000_82546_rev_3:
2943
        eeprom->type = e1000_eeprom_microwire;
2944
        eeprom->opcode_bits = 3;
2945
        eeprom->delay_usec = 50;
2946
        if(eecd & E1000_EECD_SIZE) {
2947
            eeprom->word_size = 256;
2948
            eeprom->address_bits = 8;
2949
        } else {
2950
            eeprom->word_size = 64;
2951
            eeprom->address_bits = 6;
2952
        }
2953
        break;
2954
    case e1000_82541:
2955
    case e1000_82541_rev_2:
2956
    case e1000_82547:
2957
    case e1000_82547_rev_2:
2958
        if (eecd & E1000_EECD_TYPE) {
2959
            eeprom->type = e1000_eeprom_spi;
2960
            eeprom->opcode_bits = 8;
2961
            eeprom->delay_usec = 1;
2962
            if (eecd & E1000_EECD_ADDR_BITS) {
2963
                eeprom->page_size = 32;
2964
                eeprom->address_bits = 16;
2965
            } else {
2966
                eeprom->page_size = 8;
2967
                eeprom->address_bits = 8;
2968
            }
2969
        } else {
2970
            eeprom->type = e1000_eeprom_microwire;
2971
            eeprom->opcode_bits = 3;
2972
            eeprom->delay_usec = 50;
2973
            if (eecd & E1000_EECD_ADDR_BITS) {
2974
                eeprom->word_size = 256;
2975
                eeprom->address_bits = 8;
2976
            } else {
2977
                eeprom->word_size = 64;
2978
                eeprom->address_bits = 6;
2979
            }
2980
        }
2981
        break;
2982
    default:
2983
        eeprom->type = e1000_eeprom_spi;
2984
        eeprom->opcode_bits = 8;
2985
        eeprom->delay_usec = 1;
2986
        if (eecd & E1000_EECD_ADDR_BITS) {
2987
            eeprom->page_size = 32;
2988
            eeprom->address_bits = 16;
2989
        } else {
2990
            eeprom->page_size = 8;
2991
            eeprom->address_bits = 8;
2992
        }
2993
        break;
2994
    }
2995
 
2996
    if (eeprom->type == e1000_eeprom_spi) {
2997
        eeprom->word_size = 64;
2998
        if (e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size) == 0) {
2999
            eeprom_size &= EEPROM_SIZE_MASK;
3000
 
3001
            switch (eeprom_size) {
3002
            case EEPROM_SIZE_16KB:
3003
                eeprom->word_size = 8192;
3004
                break;
3005
            case EEPROM_SIZE_8KB:
3006
                eeprom->word_size = 4096;
3007
                break;
3008
            case EEPROM_SIZE_4KB:
3009
                eeprom->word_size = 2048;
3010
                break;
3011
            case EEPROM_SIZE_2KB:
3012
                eeprom->word_size = 1024;
3013
                break;
3014
            case EEPROM_SIZE_1KB:
3015
                eeprom->word_size = 512;
3016
                break;
3017
            case EEPROM_SIZE_512B:
3018
                eeprom->word_size = 256;
3019
                break;
3020
            case EEPROM_SIZE_128B:
3021
            default:
3022
                eeprom->word_size = 64;
3023
                break;
3024
            }
3025
        }
3026
    }
3027
}
3028
 
3029
/******************************************************************************
3030
 * Raises the EEPROM's clock input.
3031
 *
3032
 * hw - Struct containing variables accessed by shared code
3033
 * eecd - EECD's current value
3034
 *****************************************************************************/
3035
static void
3036
e1000_raise_ee_clk(struct e1000_hw *hw,
3037
                   uint32_t *eecd)
3038
{
3039
    /* Raise the clock input to the EEPROM (by setting the SK bit), and then
3040
     * wait <delay> microseconds.
3041
     */
3042
    *eecd = *eecd | E1000_EECD_SK;
3043
    E1000_WRITE_REG(hw, EECD, *eecd);
3044
    E1000_WRITE_FLUSH(hw);
3045
    udelay(hw->eeprom.delay_usec);
3046
}
3047
 
3048
/******************************************************************************
3049
 * Lowers the EEPROM's clock input.
3050
 *
3051
 * hw - Struct containing variables accessed by shared code
3052
 * eecd - EECD's current value
3053
 *****************************************************************************/
3054
static void
3055
e1000_lower_ee_clk(struct e1000_hw *hw,
3056
                   uint32_t *eecd)
3057
{
3058
    /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
3059
     * wait 50 microseconds.
3060
     */
3061
    *eecd = *eecd & ~E1000_EECD_SK;
3062
    E1000_WRITE_REG(hw, EECD, *eecd);
3063
    E1000_WRITE_FLUSH(hw);
3064
    udelay(hw->eeprom.delay_usec);
3065
}
3066
 
3067
/******************************************************************************
3068
 * Shift data bits out to the EEPROM.
3069
 *
3070
 * hw - Struct containing variables accessed by shared code
3071
 * data - data to send to the EEPROM
3072
 * count - number of bits to shift out
3073
 *****************************************************************************/
3074
static void
3075
e1000_shift_out_ee_bits(struct e1000_hw *hw,
3076
                        uint16_t data,
3077
                        uint16_t count)
3078
{
3079
    struct e1000_eeprom_info *eeprom = &hw->eeprom;
3080
    uint32_t eecd;
3081
    uint32_t mask;
3082
 
3083
    /* We need to shift "count" bits out to the EEPROM. So, value in the
3084
     * "data" parameter will be shifted out to the EEPROM one bit at a time.
3085
     * In order to do this, "data" must be broken down into bits.
3086
     */
3087
    mask = 0x01 << (count - 1);
3088
    eecd = E1000_READ_REG(hw, EECD);
3089
    if (eeprom->type == e1000_eeprom_microwire) {
3090
        eecd &= ~E1000_EECD_DO;
3091
    } else if (eeprom->type == e1000_eeprom_spi) {
3092
        eecd |= E1000_EECD_DO;
3093
    }
3094
    do {
3095
        /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
3096
         * and then raising and then lowering the clock (the SK bit controls
3097
         * the clock input to the EEPROM).  A "0" is shifted out to the EEPROM
3098
         * by setting "DI" to "0" and then raising and then lowering the clock.
3099
         */
3100
        eecd &= ~E1000_EECD_DI;
3101
 
3102
        if(data & mask)
3103
            eecd |= E1000_EECD_DI;
3104
 
3105
        E1000_WRITE_REG(hw, EECD, eecd);
3106
        E1000_WRITE_FLUSH(hw);
3107
 
3108
        udelay(eeprom->delay_usec);
3109
 
3110
        e1000_raise_ee_clk(hw, &eecd);
3111
        e1000_lower_ee_clk(hw, &eecd);
3112
 
3113
        mask = mask >> 1;
3114
 
3115
    } while(mask);
3116
 
3117
    /* We leave the "DI" bit set to "0" when we leave this routine. */
3118
    eecd &= ~E1000_EECD_DI;
3119
    E1000_WRITE_REG(hw, EECD, eecd);
3120
}
3121
 
3122
/******************************************************************************
3123
 * Shift data bits in from the EEPROM
3124
 *
3125
 * hw - Struct containing variables accessed by shared code
3126
 *****************************************************************************/
3127
static uint16_t
3128
e1000_shift_in_ee_bits(struct e1000_hw *hw,
3129
                       uint16_t count)
3130
{
3131
    uint32_t eecd;
3132
    uint32_t i;
3133
    uint16_t data;
3134
 
3135
    /* In order to read a register from the EEPROM, we need to shift 'count'
3136
     * bits in from the EEPROM. Bits are "shifted in" by raising the clock
3137
     * input to the EEPROM (setting the SK bit), and then reading the value of
3138
     * the "DO" bit.  During this "shifting in" process the "DI" bit should
3139
     * always be clear.
3140
     */
3141
 
3142
    eecd = E1000_READ_REG(hw, EECD);
3143
 
3144
    eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
3145
    data = 0;
3146
 
3147
    for(i = 0; i < count; i++) {
3148
        data = data << 1;
3149
        e1000_raise_ee_clk(hw, &eecd);
3150
 
3151
        eecd = E1000_READ_REG(hw, EECD);
3152
 
3153
        eecd &= ~(E1000_EECD_DI);
3154
        if(eecd & E1000_EECD_DO)
3155
            data |= 1;
3156
 
3157
        e1000_lower_ee_clk(hw, &eecd);
3158
    }
3159
 
3160
    return data;
3161
}
3162
 
3163
/******************************************************************************
3164
 * Prepares EEPROM for access
3165
 *
3166
 * hw - Struct containing variables accessed by shared code
3167
 *
3168
 * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
3169
 * function should be called before issuing a command to the EEPROM.
3170
 *****************************************************************************/
3171
static int32_t
3172
e1000_acquire_eeprom(struct e1000_hw *hw)
3173
{
3174
    struct e1000_eeprom_info *eeprom = &hw->eeprom;
3175
    uint32_t eecd, i=0;
3176
 
3177
    DEBUGFUNC("e1000_acquire_eeprom");
3178
 
3179
    eecd = E1000_READ_REG(hw, EECD);
3180
 
3181
    /* Request EEPROM Access */
3182
    if(hw->mac_type > e1000_82544) {
3183
        eecd |= E1000_EECD_REQ;
3184
        E1000_WRITE_REG(hw, EECD, eecd);
3185
        eecd = E1000_READ_REG(hw, EECD);
3186
        while((!(eecd & E1000_EECD_GNT)) &&
3187
              (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
3188
            i++;
3189
            udelay(5);
3190
            eecd = E1000_READ_REG(hw, EECD);
3191
        }
3192
        if(!(eecd & E1000_EECD_GNT)) {
3193
            eecd &= ~E1000_EECD_REQ;
3194
            E1000_WRITE_REG(hw, EECD, eecd);
3195
            DEBUGOUT("Could not acquire EEPROM grant\n");
3196
            return -E1000_ERR_EEPROM;
3197
        }
3198
    }
3199
 
3200
    /* Setup EEPROM for Read/Write */
3201
 
3202
    if (eeprom->type == e1000_eeprom_microwire) {
3203
        /* Clear SK and DI */
3204
        eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
3205
        E1000_WRITE_REG(hw, EECD, eecd);
3206
 
3207
        /* Set CS */
3208
        eecd |= E1000_EECD_CS;
3209
        E1000_WRITE_REG(hw, EECD, eecd);
3210
    } else if (eeprom->type == e1000_eeprom_spi) {
3211
        /* Clear SK and CS */
3212
        eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3213
        E1000_WRITE_REG(hw, EECD, eecd);
3214
        udelay(1);
3215
    }
3216
 
3217
    return E1000_SUCCESS;
3218
}
3219
 
3220
/******************************************************************************
3221
 * Returns EEPROM to a "standby" state
3222
 *
3223
 * hw - Struct containing variables accessed by shared code
3224
 *****************************************************************************/
3225
static void
3226
e1000_standby_eeprom(struct e1000_hw *hw)
3227
{
3228
    struct e1000_eeprom_info *eeprom = &hw->eeprom;
3229
    uint32_t eecd;
3230
 
3231
    eecd = E1000_READ_REG(hw, EECD);
3232
 
3233
    if(eeprom->type == e1000_eeprom_microwire) {
3234
        eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
3235
        E1000_WRITE_REG(hw, EECD, eecd);
3236
        E1000_WRITE_FLUSH(hw);
3237
        udelay(eeprom->delay_usec);
3238
 
3239
        /* Clock high */
3240
        eecd |= E1000_EECD_SK;
3241
        E1000_WRITE_REG(hw, EECD, eecd);
3242
        E1000_WRITE_FLUSH(hw);
3243
        udelay(eeprom->delay_usec);
3244
 
3245
        /* Select EEPROM */
3246
        eecd |= E1000_EECD_CS;
3247
        E1000_WRITE_REG(hw, EECD, eecd);
3248
        E1000_WRITE_FLUSH(hw);
3249
        udelay(eeprom->delay_usec);
3250
 
3251
        /* Clock low */
3252
        eecd &= ~E1000_EECD_SK;
3253
        E1000_WRITE_REG(hw, EECD, eecd);
3254
        E1000_WRITE_FLUSH(hw);
3255
        udelay(eeprom->delay_usec);
3256
    } else if(eeprom->type == e1000_eeprom_spi) {
3257
        /* Toggle CS to flush commands */
3258
        eecd |= E1000_EECD_CS;
3259
        E1000_WRITE_REG(hw, EECD, eecd);
3260
        E1000_WRITE_FLUSH(hw);
3261
        udelay(eeprom->delay_usec);
3262
        eecd &= ~E1000_EECD_CS;
3263
        E1000_WRITE_REG(hw, EECD, eecd);
3264
        E1000_WRITE_FLUSH(hw);
3265
        udelay(eeprom->delay_usec);
3266
    }
3267
}
3268
 
3269
/******************************************************************************
3270
 * Terminates a command by inverting the EEPROM's chip select pin
3271
 *
3272
 * hw - Struct containing variables accessed by shared code
3273
 *****************************************************************************/
3274
static void
3275
e1000_release_eeprom(struct e1000_hw *hw)
3276
{
3277
    uint32_t eecd;
3278
 
3279
    DEBUGFUNC("e1000_release_eeprom");
3280
 
3281
    eecd = E1000_READ_REG(hw, EECD);
3282
 
3283
    if (hw->eeprom.type == e1000_eeprom_spi) {
3284
        eecd |= E1000_EECD_CS;  /* Pull CS high */
3285
        eecd &= ~E1000_EECD_SK; /* Lower SCK */
3286
 
3287
        E1000_WRITE_REG(hw, EECD, eecd);
3288
 
3289
        udelay(hw->eeprom.delay_usec);
3290
    } else if(hw->eeprom.type == e1000_eeprom_microwire) {
3291
        /* cleanup eeprom */
3292
 
3293
        /* CS on Microwire is active-high */
3294
        eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
3295
 
3296
        E1000_WRITE_REG(hw, EECD, eecd);
3297
 
3298
        /* Rising edge of clock */
3299
        eecd |= E1000_EECD_SK;
3300
        E1000_WRITE_REG(hw, EECD, eecd);
3301
        E1000_WRITE_FLUSH(hw);
3302
        udelay(hw->eeprom.delay_usec);
3303
 
3304
        /* Falling edge of clock */
3305
        eecd &= ~E1000_EECD_SK;
3306
        E1000_WRITE_REG(hw, EECD, eecd);
3307
        E1000_WRITE_FLUSH(hw);
3308
        udelay(hw->eeprom.delay_usec);
3309
    }
3310
 
3311
    /* Stop requesting EEPROM access */
3312
    if(hw->mac_type > e1000_82544) {
3313
        eecd &= ~E1000_EECD_REQ;
3314
        E1000_WRITE_REG(hw, EECD, eecd);
3315
    }
3316
}
3317
 
3318
/******************************************************************************
3319
 * Reads a 16 bit word from the EEPROM.
3320
 *
3321
 * hw - Struct containing variables accessed by shared code
3322
 *****************************************************************************/
3323
int32_t
3324
e1000_spi_eeprom_ready(struct e1000_hw *hw)
3325
{
3326
    uint16_t retry_count = 0;
3327
    uint8_t spi_stat_reg;
3328
 
3329
    DEBUGFUNC("e1000_spi_eeprom_ready");
3330
 
3331
    /* Read "Status Register" repeatedly until the LSB is cleared.  The
3332
     * EEPROM will signal that the command has been completed by clearing
3333
     * bit 0 of the internal status register.  If it's not cleared within
3334
     * 5 milliseconds, then error out.
3335
     */
3336
    retry_count = 0;
3337
    do {
3338
        e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
3339
                                hw->eeprom.opcode_bits);
3340
        spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
3341
        if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
3342
            break;
3343
 
3344
        udelay(5);
3345
        retry_count += 5;
3346
 
3347
    } while(retry_count < EEPROM_MAX_RETRY_SPI);
3348
 
3349
    /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
3350
     * only 0-5mSec on 5V devices)
3351
     */
3352
    if(retry_count >= EEPROM_MAX_RETRY_SPI) {
3353
        DEBUGOUT("SPI EEPROM Status error\n");
3354
        return -E1000_ERR_EEPROM;
3355
    }
3356
 
3357
    return E1000_SUCCESS;
3358
}
3359
 
3360
/******************************************************************************
3361
 * Reads a 16 bit word from the EEPROM.
3362
 *
3363
 * hw - Struct containing variables accessed by shared code
3364
 * offset - offset of  word in the EEPROM to read
3365
 * data - word read from the EEPROM
3366
 * words - number of words to read
3367
 *****************************************************************************/
3368
int32_t
3369
e1000_read_eeprom(struct e1000_hw *hw,
3370
                  uint16_t offset,
3371
                  uint16_t words,
3372
                  uint16_t *data)
3373
{
3374
    struct e1000_eeprom_info *eeprom = &hw->eeprom;
3375
    uint32_t i = 0;
3376
 
3377
    DEBUGFUNC("e1000_read_eeprom");
3378
 
3379
    /* A check for invalid values:  offset too large, too many words, and not
3380
     * enough words.
3381
     */
3382
    if((offset > eeprom->word_size) || (words > eeprom->word_size - offset) ||
3383
       (words == 0)) {
3384
        DEBUGOUT("\"words\" parameter out of bounds\n");
3385
        return -E1000_ERR_EEPROM;
3386
    }
3387
 
3388
    /* Prepare the EEPROM for reading  */
3389
    if(e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3390
        return -E1000_ERR_EEPROM;
3391
 
3392
    if(eeprom->type == e1000_eeprom_spi) {
3393
        uint16_t word_in;
3394
        uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
3395
 
3396
        if(e1000_spi_eeprom_ready(hw)) {
3397
            e1000_release_eeprom(hw);
3398
            return -E1000_ERR_EEPROM;
3399
        }
3400
 
3401
        e1000_standby_eeprom(hw);
3402
 
3403
        /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3404
        if((eeprom->address_bits == 8) && (offset >= 128))
3405
            read_opcode |= EEPROM_A8_OPCODE_SPI;
3406
 
3407
        /* Send the READ command (opcode + addr)  */
3408
        e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
3409
        e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
3410
 
3411
        /* Read the data.  The address of the eeprom internally increments with
3412
         * each byte (spi) being read, saving on the overhead of eeprom setup
3413
         * and tear-down.  The address counter will roll over if reading beyond
3414
         * the size of the eeprom, thus allowing the entire memory to be read
3415
         * starting from any offset. */
3416
        for (i = 0; i < words; i++) {
3417
            word_in = e1000_shift_in_ee_bits(hw, 16);
3418
            data[i] = (word_in >> 8) | (word_in << 8);
3419
        }
3420
    } else if(eeprom->type == e1000_eeprom_microwire) {
3421
        for (i = 0; i < words; i++) {
3422
            /* Send the READ command (opcode + addr)  */
3423
            e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
3424
                                    eeprom->opcode_bits);
3425
            e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
3426
                                    eeprom->address_bits);
3427
 
3428
            /* Read the data.  For microwire, each word requires the overhead
3429
             * of eeprom setup and tear-down. */
3430
            data[i] = e1000_shift_in_ee_bits(hw, 16);
3431
            e1000_standby_eeprom(hw);
3432
        }
3433
    }
3434
 
3435
    /* End this read operation */
3436
    e1000_release_eeprom(hw);
3437
 
3438
    return E1000_SUCCESS;
3439
}
3440
 
3441
/******************************************************************************
3442
 * Verifies that the EEPROM has a valid checksum
3443
 *
3444
 * hw - Struct containing variables accessed by shared code
3445
 *
3446
 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
3447
 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
3448
 * valid.
3449
 *****************************************************************************/
3450
int32_t
3451
e1000_validate_eeprom_checksum(struct e1000_hw *hw)
3452
{
3453
    uint16_t checksum = 0;
3454
    uint16_t i, eeprom_data;
3455
 
3456
    DEBUGFUNC("e1000_validate_eeprom_checksum");
3457
 
3458
    for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
3459
        if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3460
            DEBUGOUT("EEPROM Read Error\n");
3461
            return -E1000_ERR_EEPROM;
3462
        }
3463
        checksum += eeprom_data;
3464
    }
3465
 
3466
    if(checksum == (uint16_t) EEPROM_SUM)
3467
        return E1000_SUCCESS;
3468
    else {
3469
        DEBUGOUT("EEPROM Checksum Invalid\n");
3470
        return -E1000_ERR_EEPROM;
3471
    }
3472
}
3473
 
3474
/******************************************************************************
3475
 * Calculates the EEPROM checksum and writes it to the EEPROM
3476
 *
3477
 * hw - Struct containing variables accessed by shared code
3478
 *
3479
 * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
3480
 * Writes the difference to word offset 63 of the EEPROM.
3481
 *****************************************************************************/
3482
int32_t
3483
e1000_update_eeprom_checksum(struct e1000_hw *hw)
3484
{
3485
    uint16_t checksum = 0;
3486
    uint16_t i, eeprom_data;
3487
 
3488
    DEBUGFUNC("e1000_update_eeprom_checksum");
3489
 
3490
    for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
3491
        if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
3492
            DEBUGOUT("EEPROM Read Error\n");
3493
            return -E1000_ERR_EEPROM;
3494
        }
3495
        checksum += eeprom_data;
3496
    }
3497
    checksum = (uint16_t) EEPROM_SUM - checksum;
3498
    if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
3499
        DEBUGOUT("EEPROM Write Error\n");
3500
        return -E1000_ERR_EEPROM;
3501
    }
3502
    return E1000_SUCCESS;
3503
}
3504
 
3505
/******************************************************************************
3506
 * Parent function for writing words to the different EEPROM types.
3507
 *
3508
 * hw - Struct containing variables accessed by shared code
3509
 * offset - offset within the EEPROM to be written to
3510
 * words - number of words to write
3511
 * data - 16 bit word to be written to the EEPROM
3512
 *
3513
 * If e1000_update_eeprom_checksum is not called after this function, the
3514
 * EEPROM will most likely contain an invalid checksum.
3515
 *****************************************************************************/
3516
int32_t
3517
e1000_write_eeprom(struct e1000_hw *hw,
3518
                   uint16_t offset,
3519
                   uint16_t words,
3520
                   uint16_t *data)
3521
{
3522
    struct e1000_eeprom_info *eeprom = &hw->eeprom;
3523
    int32_t status = 0;
3524
 
3525
    DEBUGFUNC("e1000_write_eeprom");
3526
 
3527
    /* A check for invalid values:  offset too large, too many words, and not
3528
     * enough words.
3529
     */
3530
    if((offset > eeprom->word_size) || (words > eeprom->word_size - offset) ||
3531
       (words == 0)) {
3532
        DEBUGOUT("\"words\" parameter out of bounds\n");
3533
        return -E1000_ERR_EEPROM;
3534
    }
3535
 
3536
    /* Prepare the EEPROM for writing  */
3537
    if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
3538
        return -E1000_ERR_EEPROM;
3539
 
3540
    if(eeprom->type == e1000_eeprom_microwire) {
3541
        status = e1000_write_eeprom_microwire(hw, offset, words, data);
3542
    } else {
3543
        status = e1000_write_eeprom_spi(hw, offset, words, data);
3544
        msec_delay(10);
3545
    }
3546
 
3547
    /* Done with writing */
3548
    e1000_release_eeprom(hw);
3549
 
3550
    return status;
3551
}
3552
 
3553
/******************************************************************************
3554
 * Writes a 16 bit word to a given offset in an SPI EEPROM.
3555
 *
3556
 * hw - Struct containing variables accessed by shared code
3557
 * offset - offset within the EEPROM to be written to
3558
 * words - number of words to write
3559
 * data - pointer to array of 8 bit words to be written to the EEPROM
3560
 *
3561
 *****************************************************************************/
3562
int32_t
3563
e1000_write_eeprom_spi(struct e1000_hw *hw,
3564
                       uint16_t offset,
3565
                       uint16_t words,
3566
                       uint16_t *data)
3567
{
3568
    struct e1000_eeprom_info *eeprom = &hw->eeprom;
3569
    uint16_t widx = 0;
3570
 
3571
    DEBUGFUNC("e1000_write_eeprom_spi");
3572
 
3573
    while (widx < words) {
3574
        uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
3575
 
3576
        if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
3577
 
3578
        e1000_standby_eeprom(hw);
3579
 
3580
        /*  Send the WRITE ENABLE command (8 bit opcode )  */
3581
        e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
3582
                                    eeprom->opcode_bits);
3583
 
3584
        e1000_standby_eeprom(hw);
3585
 
3586
        /* Some SPI eeproms use the 8th address bit embedded in the opcode */
3587
        if((eeprom->address_bits == 8) && (offset >= 128))
3588
            write_opcode |= EEPROM_A8_OPCODE_SPI;
3589
 
3590
        /* Send the Write command (8-bit opcode + addr) */
3591
        e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
3592
 
3593
        e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
3594
                                eeprom->address_bits);
3595
 
3596
        /* Send the data */
3597
 
3598
        /* Loop to allow for up to whole page write (32 bytes) of eeprom */
3599
        while (widx < words) {
3600
            uint16_t word_out = data[widx];
3601
            word_out = (word_out >> 8) | (word_out << 8);
3602
            e1000_shift_out_ee_bits(hw, word_out, 16);
3603
            widx++;
3604
 
3605
            /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
3606
             * operation, while the smaller eeproms are capable of an 8-byte
3607
             * PAGE WRITE operation.  Break the inner loop to pass new address
3608
             */
3609
            if((((offset + widx)*2) % eeprom->page_size) == 0) {
3610
                e1000_standby_eeprom(hw);
3611
                break;
3612
            }
3613
        }
3614
    }
3615
 
3616
    return E1000_SUCCESS;
3617
}
3618
 
3619
/******************************************************************************
3620
 * Writes a 16 bit word to a given offset in a Microwire EEPROM.
3621
 *
3622
 * hw - Struct containing variables accessed by shared code
3623
 * offset - offset within the EEPROM to be written to
3624
 * words - number of words to write
3625
 * data - pointer to array of 16 bit words to be written to the EEPROM
3626
 *
3627
 *****************************************************************************/
3628
int32_t
3629
e1000_write_eeprom_microwire(struct e1000_hw *hw,
3630
                             uint16_t offset,
3631
                             uint16_t words,
3632
                             uint16_t *data)
3633
{
3634
    struct e1000_eeprom_info *eeprom = &hw->eeprom;
3635
    uint32_t eecd;
3636
    uint16_t words_written = 0;
3637
    uint16_t i = 0;
3638
 
3639
    DEBUGFUNC("e1000_write_eeprom_microwire");
3640
 
3641
    /* Send the write enable command to the EEPROM (3-bit opcode plus
3642
     * 6/8-bit dummy address beginning with 11).  It's less work to include
3643
     * the 11 of the dummy address as part of the opcode than it is to shift
3644
     * it over the correct number of bits for the address.  This puts the
3645
     * EEPROM into write/erase mode.
3646
     */
3647
    e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
3648
                            (uint16_t)(eeprom->opcode_bits + 2));
3649
 
3650
    e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
3651
 
3652
    /* Prepare the EEPROM */
3653
    e1000_standby_eeprom(hw);
3654
 
3655
    while (words_written < words) {
3656
        /* Send the Write command (3-bit opcode + addr) */
3657
        e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
3658
                                eeprom->opcode_bits);
3659
 
3660
        e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
3661
                                eeprom->address_bits);
3662
 
3663
        /* Send the data */
3664
        e1000_shift_out_ee_bits(hw, data[words_written], 16);
3665
 
3666
        /* Toggle the CS line.  This in effect tells the EEPROM to execute
3667
         * the previous command.
3668
         */
3669
        e1000_standby_eeprom(hw);
3670
 
3671
        /* Read DO repeatedly until it is high (equal to '1').  The EEPROM will
3672
         * signal that the command has been completed by raising the DO signal.
3673
         * If DO does not go high in 10 milliseconds, then error out.
3674
         */
3675
        for(i = 0; i < 200; i++) {
3676
            eecd = E1000_READ_REG(hw, EECD);
3677
            if(eecd & E1000_EECD_DO) break;
3678
            udelay(50);
3679
        }
3680
        if(i == 200) {
3681
            DEBUGOUT("EEPROM Write did not complete\n");
3682
            return -E1000_ERR_EEPROM;
3683
        }
3684
 
3685
        /* Recover from write */
3686
        e1000_standby_eeprom(hw);
3687
 
3688
        words_written++;
3689
    }
3690
 
3691
    /* Send the write disable command to the EEPROM (3-bit opcode plus
3692
     * 6/8-bit dummy address beginning with 10).  It's less work to include
3693
     * the 10 of the dummy address as part of the opcode than it is to shift
3694
     * it over the correct number of bits for the address.  This takes the
3695
     * EEPROM out of write/erase mode.
3696
     */
3697
    e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
3698
                            (uint16_t)(eeprom->opcode_bits + 2));
3699
 
3700
    e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
3701
 
3702
    return E1000_SUCCESS;
3703
}
3704
 
3705
/******************************************************************************
3706
 * Reads the adapter's part number from the EEPROM
3707
 *
3708
 * hw - Struct containing variables accessed by shared code
3709
 * part_num - Adapter's part number
3710
 *****************************************************************************/
3711
int32_t
3712
e1000_read_part_num(struct e1000_hw *hw,
3713
                    uint32_t *part_num)
3714
{
3715
    uint16_t offset = EEPROM_PBA_BYTE_1;
3716
    uint16_t eeprom_data;
3717
 
3718
    DEBUGFUNC("e1000_read_part_num");
3719
 
3720
    /* Get word 0 from EEPROM */
3721
    if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
3722
        DEBUGOUT("EEPROM Read Error\n");
3723
        return -E1000_ERR_EEPROM;
3724
    }
3725
    /* Save word 0 in upper half of part_num */
3726
    *part_num = (uint32_t) (eeprom_data << 16);
3727
 
3728
    /* Get word 1 from EEPROM */
3729
    if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
3730
        DEBUGOUT("EEPROM Read Error\n");
3731
        return -E1000_ERR_EEPROM;
3732
    }
3733
    /* Save word 1 in lower half of part_num */
3734
    *part_num |= eeprom_data;
3735
 
3736
    return E1000_SUCCESS;
3737
}
3738
 
3739
/******************************************************************************
3740
 * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
3741
 * second function of dual function devices
3742
 *
3743
 * hw - Struct containing variables accessed by shared code
3744
 *****************************************************************************/
3745
int32_t
3746
e1000_read_mac_addr(struct e1000_hw * hw)
3747
{
3748
    uint16_t offset;
3749
    uint16_t eeprom_data, i;
3750
 
3751
    DEBUGFUNC("e1000_read_mac_addr");
3752
 
3753
    for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
3754
        offset = i >> 1;
3755
        if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
3756
            DEBUGOUT("EEPROM Read Error\n");
3757
            return -E1000_ERR_EEPROM;
3758
        }
3759
        hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
3760
        hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
3761
    }
3762
    if(((hw->mac_type == e1000_82546) || (hw->mac_type == e1000_82546_rev_3)) &&
3763
       (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1))
3764
            hw->perm_mac_addr[5] ^= 0x01;
3765
 
3766
    for(i = 0; i < NODE_ADDRESS_SIZE; i++)
3767
        hw->mac_addr[i] = hw->perm_mac_addr[i];
3768
    return E1000_SUCCESS;
3769
}
3770
 
3771
/******************************************************************************
3772
 * Initializes receive address filters.
3773
 *
3774
 * hw - Struct containing variables accessed by shared code
3775
 *
3776
 * Places the MAC address in receive address register 0 and clears the rest
3777
 * of the receive addresss registers. Clears the multicast table. Assumes
3778
 * the receiver is in reset when the routine is called.
3779
 *****************************************************************************/
3780
void
3781
e1000_init_rx_addrs(struct e1000_hw *hw)
3782
{
3783
    uint32_t i;
3784
 
3785
    DEBUGFUNC("e1000_init_rx_addrs");
3786
 
3787
    /* Setup the receive address. */
3788
    DEBUGOUT("Programming MAC Address into RAR[0]\n");
3789
 
3790
    e1000_rar_set(hw, hw->mac_addr, 0);
3791
 
3792
    /* Zero out the other 15 receive addresses. */
3793
    DEBUGOUT("Clearing RAR[1-15]\n");
3794
    for(i = 1; i < E1000_RAR_ENTRIES; i++) {
3795
        E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
3796
        E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
3797
    }
3798
}
3799
 
3800
/******************************************************************************
3801
 * Updates the MAC's list of multicast addresses.
3802
 *
3803
 * hw - Struct containing variables accessed by shared code
3804
 * mc_addr_list - the list of new multicast addresses
3805
 * mc_addr_count - number of addresses
3806
 * pad - number of bytes between addresses in the list
3807
 * rar_used_count - offset where to start adding mc addresses into the RAR's
3808
 *
3809
 * The given list replaces any existing list. Clears the last 15 receive
3810
 * address registers and the multicast table. Uses receive address registers
3811
 * for the first 15 multicast addresses, and hashes the rest into the
3812
 * multicast table.
3813
 *****************************************************************************/
3814
void
3815
e1000_mc_addr_list_update(struct e1000_hw *hw,
3816
                          uint8_t *mc_addr_list,
3817
                          uint32_t mc_addr_count,
3818
                          uint32_t pad,
3819
                          uint32_t rar_used_count)
3820
{
3821
    uint32_t hash_value;
3822
    uint32_t i;
3823
 
3824
    DEBUGFUNC("e1000_mc_addr_list_update");
3825
 
3826
    /* Set the new number of MC addresses that we are being requested to use. */
3827
    hw->num_mc_addrs = mc_addr_count;
3828
 
3829
    /* Clear RAR[1-15] */
3830
    DEBUGOUT(" Clearing RAR[1-15]\n");
3831
    for(i = rar_used_count; i < E1000_RAR_ENTRIES; i++) {
3832
        E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
3833
        E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
3834
    }
3835
 
3836
    /* Clear the MTA */
3837
    DEBUGOUT(" Clearing MTA\n");
3838
    for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++) {
3839
        E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
3840
    }
3841
 
3842
    /* Add the new addresses */
3843
    for(i = 0; i < mc_addr_count; i++) {
3844
        DEBUGOUT(" Adding the multicast addresses:\n");
3845
        DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
3846
                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
3847
                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
3848
                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
3849
                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
3850
                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
3851
                  mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
3852
 
3853
        hash_value = e1000_hash_mc_addr(hw,
3854
                                        mc_addr_list +
3855
                                        (i * (ETH_LENGTH_OF_ADDRESS + pad)));
3856
 
3857
        DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
3858
 
3859
        /* Place this multicast address in the RAR if there is room, *
3860
         * else put it in the MTA
3861
         */
3862
        if(rar_used_count < E1000_RAR_ENTRIES) {
3863
            e1000_rar_set(hw,
3864
                          mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
3865
                          rar_used_count);
3866
            rar_used_count++;
3867
        } else {
3868
            e1000_mta_set(hw, hash_value);
3869
        }
3870
    }
3871
    DEBUGOUT("MC Update Complete\n");
3872
}
3873
 
3874
/******************************************************************************
3875
 * Hashes an address to determine its location in the multicast table
3876
 *
3877
 * hw - Struct containing variables accessed by shared code
3878
 * mc_addr - the multicast address to hash
3879
 *****************************************************************************/
3880
uint32_t
3881
e1000_hash_mc_addr(struct e1000_hw *hw,
3882
                   uint8_t *mc_addr)
3883
{
3884
    uint32_t hash_value = 0;
3885
 
3886
    /* The portion of the address that is used for the hash table is
3887
     * determined by the mc_filter_type setting.
3888
     */
3889
    switch (hw->mc_filter_type) {
3890
    /* [0] [1] [2] [3] [4] [5]
3891
     * 01  AA  00  12  34  56
3892
     * LSB                 MSB
3893
     */
3894
    case 0:
3895
        /* [47:36] i.e. 0x563 for above example address */
3896
        hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
3897
        break;
3898
    case 1:
3899
        /* [46:35] i.e. 0xAC6 for above example address */
3900
        hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
3901
        break;
3902
    case 2:
3903
        /* [45:34] i.e. 0x5D8 for above example address */
3904
        hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
3905
        break;
3906
    case 3:
3907
        /* [43:32] i.e. 0x634 for above example address */
3908
        hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
3909
        break;
3910
    }
3911
 
3912
    hash_value &= 0xFFF;
3913
    return hash_value;
3914
}
3915
 
3916
/******************************************************************************
3917
 * Sets the bit in the multicast table corresponding to the hash value.
3918
 *
3919
 * hw - Struct containing variables accessed by shared code
3920
 * hash_value - Multicast address hash value
3921
 *****************************************************************************/
3922
void
3923
e1000_mta_set(struct e1000_hw *hw,
3924
              uint32_t hash_value)
3925
{
3926
    uint32_t hash_bit, hash_reg;
3927
    uint32_t mta;
3928
    uint32_t temp;
3929
 
3930
    /* The MTA is a register array of 128 32-bit registers.
3931
     * It is treated like an array of 4096 bits.  We want to set
3932
     * bit BitArray[hash_value]. So we figure out what register
3933
     * the bit is in, read it, OR in the new bit, then write
3934
     * back the new value.  The register is determined by the
3935
     * upper 7 bits of the hash value and the bit within that
3936
     * register are determined by the lower 5 bits of the value.
3937
     */
3938
    hash_reg = (hash_value >> 5) & 0x7F;
3939
    hash_bit = hash_value & 0x1F;
3940
 
3941
    mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
3942
 
3943
    mta |= (1 << hash_bit);
3944
 
3945
    /* If we are on an 82544 and we are trying to write an odd offset
3946
     * in the MTA, save off the previous entry before writing and
3947
     * restore the old value after writing.
3948
     */
3949
    if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
3950
        temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
3951
        E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
3952
        E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
3953
    } else {
3954
        E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
3955
    }
3956
}
3957
 
3958
/******************************************************************************
3959
 * Puts an ethernet address into a receive address register.
3960
 *
3961
 * hw - Struct containing variables accessed by shared code
3962
 * addr - Address to put into receive address register
3963
 * index - Receive address register to write
3964
 *****************************************************************************/
3965
void
3966
e1000_rar_set(struct e1000_hw *hw,
3967
              uint8_t *addr,
3968
              uint32_t index)
3969
{
3970
    uint32_t rar_low, rar_high;
3971
 
3972
    /* HW expects these in little endian so we reverse the byte order
3973
     * from network order (big endian) to little endian
3974
     */
3975
    rar_low = ((uint32_t) addr[0] |
3976
               ((uint32_t) addr[1] << 8) |
3977
               ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
3978
 
3979
    rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
3980
 
3981
    E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
3982
    E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
3983
}
3984
 
3985
/******************************************************************************
3986
 * Writes a value to the specified offset in the VLAN filter table.
3987
 *
3988
 * hw - Struct containing variables accessed by shared code
3989
 * offset - Offset in VLAN filer table to write
3990
 * value - Value to write into VLAN filter table
3991
 *****************************************************************************/
3992
void
3993
e1000_write_vfta(struct e1000_hw *hw,
3994
                 uint32_t offset,
3995
                 uint32_t value)
3996
{
3997
    uint32_t temp;
3998
 
3999
    if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
4000
        temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
4001
        E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4002
        E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
4003
    } else {
4004
        E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
4005
    }
4006
}
4007
 
4008
/******************************************************************************
4009
 * Clears the VLAN filer table
4010
 *
4011
 * hw - Struct containing variables accessed by shared code
4012
 *****************************************************************************/
4013
void
4014
e1000_clear_vfta(struct e1000_hw *hw)
4015
{
4016
    uint32_t offset;
4017
 
4018
    for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
4019
        E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
4020
}
4021
 
4022
static int32_t
4023
e1000_id_led_init(struct e1000_hw * hw)
4024
{
4025
    uint32_t ledctl;
4026
    const uint32_t ledctl_mask = 0x000000FF;
4027
    const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
4028
    const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
4029
    uint16_t eeprom_data, i, temp;
4030
    const uint16_t led_mask = 0x0F;
4031
 
4032
    DEBUGFUNC("e1000_id_led_init");
4033
 
4034
    if(hw->mac_type < e1000_82540) {
4035
        /* Nothing to do */
4036
        return E1000_SUCCESS;
4037
    }
4038
 
4039
    ledctl = E1000_READ_REG(hw, LEDCTL);
4040
    hw->ledctl_default = ledctl;
4041
    hw->ledctl_mode1 = hw->ledctl_default;
4042
    hw->ledctl_mode2 = hw->ledctl_default;
4043
 
4044
    if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
4045
        DEBUGOUT("EEPROM Read Error\n");
4046
        return -E1000_ERR_EEPROM;
4047
    }
4048
    if((eeprom_data== ID_LED_RESERVED_0000) ||
4049
       (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
4050
    for(i = 0; i < 4; i++) {
4051
        temp = (eeprom_data >> (i << 2)) & led_mask;
4052
        switch(temp) {
4053
        case ID_LED_ON1_DEF2:
4054
        case ID_LED_ON1_ON2:
4055
        case ID_LED_ON1_OFF2:
4056
            hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4057
            hw->ledctl_mode1 |= ledctl_on << (i << 3);
4058
            break;
4059
        case ID_LED_OFF1_DEF2:
4060
        case ID_LED_OFF1_ON2:
4061
        case ID_LED_OFF1_OFF2:
4062
            hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
4063
            hw->ledctl_mode1 |= ledctl_off << (i << 3);
4064
            break;
4065
        default:
4066
            /* Do nothing */
4067
            break;
4068
        }
4069
        switch(temp) {
4070
        case ID_LED_DEF1_ON2:
4071
        case ID_LED_ON1_ON2:
4072
        case ID_LED_OFF1_ON2:
4073
            hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4074
            hw->ledctl_mode2 |= ledctl_on << (i << 3);
4075
            break;
4076
        case ID_LED_DEF1_OFF2:
4077
        case ID_LED_ON1_OFF2:
4078
        case ID_LED_OFF1_OFF2:
4079
            hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
4080
            hw->ledctl_mode2 |= ledctl_off << (i << 3);
4081
            break;
4082
        default:
4083
            /* Do nothing */
4084
            break;
4085
        }
4086
    }
4087
    return E1000_SUCCESS;
4088
}
4089
 
4090
/******************************************************************************
4091
 * Prepares SW controlable LED for use and saves the current state of the LED.
4092
 *
4093
 * hw - Struct containing variables accessed by shared code
4094
 *****************************************************************************/
4095
int32_t
4096
e1000_setup_led(struct e1000_hw *hw)
4097
{
4098
    uint32_t ledctl;
4099
    int32_t ret_val = E1000_SUCCESS;
4100
 
4101
    DEBUGFUNC("e1000_setup_led");
4102
 
4103
    switch(hw->mac_type) {
4104
    case e1000_82542_rev2_0:
4105
    case e1000_82542_rev2_1:
4106
    case e1000_82543:
4107
    case e1000_82544:
4108
        /* No setup necessary */
4109
        break;
4110
    case e1000_82541:
4111
    case e1000_82547:
4112
    case e1000_82541_rev_2:
4113
    case e1000_82547_rev_2:
4114
        /* Turn off PHY Smart Power Down (if enabled) */
4115
        if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
4116
                                         &hw->phy_spd_default)))
4117
            return ret_val;
4118
        if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4119
                                          (uint16_t)(hw->phy_spd_default &
4120
                                          ~IGP01E1000_GMII_SPD))))
4121
            return ret_val;
4122
        /* Fall Through */
4123
    default:
4124
        if(hw->media_type == e1000_media_type_fiber) {
4125
            ledctl = E1000_READ_REG(hw, LEDCTL);
4126
            /* Save current LEDCTL settings */
4127
            hw->ledctl_default = ledctl;
4128
            /* Turn off LED0 */
4129
            ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
4130
                        E1000_LEDCTL_LED0_BLINK |
4131
                        E1000_LEDCTL_LED0_MODE_MASK);
4132
            ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
4133
                       E1000_LEDCTL_LED0_MODE_SHIFT);
4134
            E1000_WRITE_REG(hw, LEDCTL, ledctl);
4135
        } else if(hw->media_type == e1000_media_type_copper)
4136
            E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4137
        break;
4138
    }
4139
 
4140
    return E1000_SUCCESS;
4141
}
4142
 
4143
/******************************************************************************
4144
 * Restores the saved state of the SW controlable LED.
4145
 *
4146
 * hw - Struct containing variables accessed by shared code
4147
 *****************************************************************************/
4148
int32_t
4149
e1000_cleanup_led(struct e1000_hw *hw)
4150
{
4151
    int32_t ret_val = E1000_SUCCESS;
4152
 
4153
    DEBUGFUNC("e1000_cleanup_led");
4154
 
4155
    switch(hw->mac_type) {
4156
    case e1000_82542_rev2_0:
4157
    case e1000_82542_rev2_1:
4158
    case e1000_82543:
4159
    case e1000_82544:
4160
        /* No cleanup necessary */
4161
        break;
4162
    case e1000_82541:
4163
    case e1000_82547:
4164
    case e1000_82541_rev_2:
4165
    case e1000_82547_rev_2:
4166
        /* Turn on PHY Smart Power Down (if previously enabled) */
4167
        if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
4168
                                          hw->phy_spd_default)))
4169
            return ret_val;
4170
        /* Fall Through */
4171
    default:
4172
        /* Restore LEDCTL settings */
4173
        E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
4174
        break;
4175
    }
4176
 
4177
    return E1000_SUCCESS;
4178
}
4179
 
4180
/******************************************************************************
4181
 * Turns on the software controllable LED
4182
 *
4183
 * hw - Struct containing variables accessed by shared code
4184
 *****************************************************************************/
4185
int32_t
4186
e1000_led_on(struct e1000_hw *hw)
4187
{
4188
    uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4189
 
4190
    DEBUGFUNC("e1000_led_on");
4191
 
4192
    switch(hw->mac_type) {
4193
    case e1000_82542_rev2_0:
4194
    case e1000_82542_rev2_1:
4195
    case e1000_82543:
4196
        /* Set SW Defineable Pin 0 to turn on the LED */
4197
        ctrl |= E1000_CTRL_SWDPIN0;
4198
        ctrl |= E1000_CTRL_SWDPIO0;
4199
        break;
4200
    case e1000_82544:
4201
        if(hw->media_type == e1000_media_type_fiber) {
4202
            /* Set SW Defineable Pin 0 to turn on the LED */
4203
            ctrl |= E1000_CTRL_SWDPIN0;
4204
            ctrl |= E1000_CTRL_SWDPIO0;
4205
        } else {
4206
            /* Clear SW Defineable Pin 0 to turn on the LED */
4207
            ctrl &= ~E1000_CTRL_SWDPIN0;
4208
            ctrl |= E1000_CTRL_SWDPIO0;
4209
        }
4210
        break;
4211
    default:
4212
        if(hw->media_type == e1000_media_type_fiber) {
4213
            /* Clear SW Defineable Pin 0 to turn on the LED */
4214
            ctrl &= ~E1000_CTRL_SWDPIN0;
4215
            ctrl |= E1000_CTRL_SWDPIO0;
4216
        } else if(hw->media_type == e1000_media_type_copper) {
4217
            E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
4218
            return E1000_SUCCESS;
4219
        }
4220
        break;
4221
    }
4222
 
4223
    E1000_WRITE_REG(hw, CTRL, ctrl);
4224
 
4225
    return E1000_SUCCESS;
4226
}
4227
 
4228
/******************************************************************************
4229
 * Turns off the software controllable LED
4230
 *
4231
 * hw - Struct containing variables accessed by shared code
4232
 *****************************************************************************/
4233
int32_t
4234
e1000_led_off(struct e1000_hw *hw)
4235
{
4236
    uint32_t ctrl = E1000_READ_REG(hw, CTRL);
4237
 
4238
    DEBUGFUNC("e1000_led_off");
4239
 
4240
    switch(hw->mac_type) {
4241
    case e1000_82542_rev2_0:
4242
    case e1000_82542_rev2_1:
4243
    case e1000_82543:
4244
        /* Clear SW Defineable Pin 0 to turn off the LED */
4245
        ctrl &= ~E1000_CTRL_SWDPIN0;
4246
        ctrl |= E1000_CTRL_SWDPIO0;
4247
        break;
4248
    case e1000_82544:
4249
        if(hw->media_type == e1000_media_type_fiber) {
4250
            /* Clear SW Defineable Pin 0 to turn off the LED */
4251
            ctrl &= ~E1000_CTRL_SWDPIN0;
4252
            ctrl |= E1000_CTRL_SWDPIO0;
4253
        } else {
4254
            /* Set SW Defineable Pin 0 to turn off the LED */
4255
            ctrl |= E1000_CTRL_SWDPIN0;
4256
            ctrl |= E1000_CTRL_SWDPIO0;
4257
        }
4258
        break;
4259
    default:
4260
        if(hw->media_type == e1000_media_type_fiber) {
4261
            /* Set SW Defineable Pin 0 to turn off the LED */
4262
            ctrl |= E1000_CTRL_SWDPIN0;
4263
            ctrl |= E1000_CTRL_SWDPIO0;
4264
        } else if(hw->media_type == e1000_media_type_copper) {
4265
            E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
4266
            return E1000_SUCCESS;
4267
        }
4268
        break;
4269
    }
4270
 
4271
    E1000_WRITE_REG(hw, CTRL, ctrl);
4272
 
4273
    return E1000_SUCCESS;
4274
}
4275
 
4276
/******************************************************************************
4277
 * Clears all hardware statistics counters.
4278
 *
4279
 * hw - Struct containing variables accessed by shared code
4280
 *****************************************************************************/
4281
void
4282
e1000_clear_hw_cntrs(struct e1000_hw *hw)
4283
{
4284
    volatile uint32_t temp;
4285
 
4286
    temp = E1000_READ_REG(hw, CRCERRS);
4287
    temp = E1000_READ_REG(hw, SYMERRS);
4288
    temp = E1000_READ_REG(hw, MPC);
4289
    temp = E1000_READ_REG(hw, SCC);
4290
    temp = E1000_READ_REG(hw, ECOL);
4291
    temp = E1000_READ_REG(hw, MCC);
4292
    temp = E1000_READ_REG(hw, LATECOL);
4293
    temp = E1000_READ_REG(hw, COLC);
4294
    temp = E1000_READ_REG(hw, DC);
4295
    temp = E1000_READ_REG(hw, SEC);
4296
    temp = E1000_READ_REG(hw, RLEC);
4297
    temp = E1000_READ_REG(hw, XONRXC);
4298
    temp = E1000_READ_REG(hw, XONTXC);
4299
    temp = E1000_READ_REG(hw, XOFFRXC);
4300
    temp = E1000_READ_REG(hw, XOFFTXC);
4301
    temp = E1000_READ_REG(hw, FCRUC);
4302
    temp = E1000_READ_REG(hw, PRC64);
4303
    temp = E1000_READ_REG(hw, PRC127);
4304
    temp = E1000_READ_REG(hw, PRC255);
4305
    temp = E1000_READ_REG(hw, PRC511);
4306
    temp = E1000_READ_REG(hw, PRC1023);
4307
    temp = E1000_READ_REG(hw, PRC1522);
4308
    temp = E1000_READ_REG(hw, GPRC);
4309
    temp = E1000_READ_REG(hw, BPRC);
4310
    temp = E1000_READ_REG(hw, MPRC);
4311
    temp = E1000_READ_REG(hw, GPTC);
4312
    temp = E1000_READ_REG(hw, GORCL);
4313
    temp = E1000_READ_REG(hw, GORCH);
4314
    temp = E1000_READ_REG(hw, GOTCL);
4315
    temp = E1000_READ_REG(hw, GOTCH);
4316
    temp = E1000_READ_REG(hw, RNBC);
4317
    temp = E1000_READ_REG(hw, RUC);
4318
    temp = E1000_READ_REG(hw, RFC);
4319
    temp = E1000_READ_REG(hw, ROC);
4320
    temp = E1000_READ_REG(hw, RJC);
4321
    temp = E1000_READ_REG(hw, TORL);
4322
    temp = E1000_READ_REG(hw, TORH);
4323
    temp = E1000_READ_REG(hw, TOTL);
4324
    temp = E1000_READ_REG(hw, TOTH);
4325
    temp = E1000_READ_REG(hw, TPR);
4326
    temp = E1000_READ_REG(hw, TPT);
4327
    temp = E1000_READ_REG(hw, PTC64);
4328
    temp = E1000_READ_REG(hw, PTC127);
4329
    temp = E1000_READ_REG(hw, PTC255);
4330
    temp = E1000_READ_REG(hw, PTC511);
4331
    temp = E1000_READ_REG(hw, PTC1023);
4332
    temp = E1000_READ_REG(hw, PTC1522);
4333
    temp = E1000_READ_REG(hw, MPTC);
4334
    temp = E1000_READ_REG(hw, BPTC);
4335
 
4336
    if(hw->mac_type < e1000_82543) return;
4337
 
4338
    temp = E1000_READ_REG(hw, ALGNERRC);
4339
    temp = E1000_READ_REG(hw, RXERRC);
4340
    temp = E1000_READ_REG(hw, TNCRS);
4341
    temp = E1000_READ_REG(hw, CEXTERR);
4342
    temp = E1000_READ_REG(hw, TSCTC);
4343
    temp = E1000_READ_REG(hw, TSCTFC);
4344
 
4345
    if(hw->mac_type <= e1000_82544) return;
4346
 
4347
    temp = E1000_READ_REG(hw, MGTPRC);
4348
    temp = E1000_READ_REG(hw, MGTPDC);
4349
    temp = E1000_READ_REG(hw, MGTPTC);
4350
}
4351
 
4352
/******************************************************************************
4353
 * Resets Adaptive IFS to its default state.
4354
 *
4355
 * hw - Struct containing variables accessed by shared code
4356
 *
4357
 * Call this after e1000_init_hw. You may override the IFS defaults by setting
4358
 * hw->ifs_params_forced to TRUE. However, you must initialize hw->
4359
 * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
4360
 * before calling this function.
4361
 *****************************************************************************/
4362
void
4363
e1000_reset_adaptive(struct e1000_hw *hw)
4364
{
4365
    DEBUGFUNC("e1000_reset_adaptive");
4366
 
4367
    if(hw->adaptive_ifs) {
4368
        if(!hw->ifs_params_forced) {
4369
            hw->current_ifs_val = 0;
4370
            hw->ifs_min_val = IFS_MIN;
4371
            hw->ifs_max_val = IFS_MAX;
4372
            hw->ifs_step_size = IFS_STEP;
4373
            hw->ifs_ratio = IFS_RATIO;
4374
        }
4375
        hw->in_ifs_mode = FALSE;
4376
        E1000_WRITE_REG(hw, AIT, 0);
4377
    } else {
4378
        DEBUGOUT("Not in Adaptive IFS mode!\n");
4379
    }
4380
}
4381
 
4382
/******************************************************************************
4383
 * Called during the callback/watchdog routine to update IFS value based on
4384
 * the ratio of transmits to collisions.
4385
 *
4386
 * hw - Struct containing variables accessed by shared code
4387
 * tx_packets - Number of transmits since last callback
4388
 * total_collisions - Number of collisions since last callback
4389
 *****************************************************************************/
4390
void
4391
e1000_update_adaptive(struct e1000_hw *hw)
4392
{
4393
    DEBUGFUNC("e1000_update_adaptive");
4394
 
4395
    if(hw->adaptive_ifs) {
4396
        if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
4397
            if(hw->tx_packet_delta > MIN_NUM_XMITS) {
4398
                hw->in_ifs_mode = TRUE;
4399
                if(hw->current_ifs_val < hw->ifs_max_val) {
4400
                    if(hw->current_ifs_val == 0)
4401
                        hw->current_ifs_val = hw->ifs_min_val;
4402
                    else
4403
                        hw->current_ifs_val += hw->ifs_step_size;
4404
                    E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
4405
                }
4406
            }
4407
        } else {
4408
            if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
4409
                hw->current_ifs_val = 0;
4410
                hw->in_ifs_mode = FALSE;
4411
                E1000_WRITE_REG(hw, AIT, 0);
4412
            }
4413
        }
4414
    } else {
4415
        DEBUGOUT("Not in Adaptive IFS mode!\n");
4416
    }
4417
}
4418
 
4419
/******************************************************************************
4420
 * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
4421
 *
4422
 * hw - Struct containing variables accessed by shared code
4423
 * frame_len - The length of the frame in question
4424
 * mac_addr - The Ethernet destination address of the frame in question
4425
 *****************************************************************************/
4426
void
4427
e1000_tbi_adjust_stats(struct e1000_hw *hw,
4428
                       struct e1000_hw_stats *stats,
4429
                       uint32_t frame_len,
4430
                       uint8_t *mac_addr)
4431
{
4432
    uint64_t carry_bit;
4433
 
4434
    /* First adjust the frame length. */
4435
    frame_len--;
4436
    /* We need to adjust the statistics counters, since the hardware
4437
     * counters overcount this packet as a CRC error and undercount
4438
     * the packet as a good packet
4439
     */
4440
    /* This packet should not be counted as a CRC error.    */
4441
    stats->crcerrs--;
4442
    /* This packet does count as a Good Packet Received.    */
4443
    stats->gprc++;
4444
 
4445
    /* Adjust the Good Octets received counters             */
4446
    carry_bit = 0x80000000 & stats->gorcl;
4447
    stats->gorcl += frame_len;
4448
    /* If the high bit of Gorcl (the low 32 bits of the Good Octets
4449
     * Received Count) was one before the addition,
4450
     * AND it is zero after, then we lost the carry out,
4451
     * need to add one to Gorch (Good Octets Received Count High).
4452
     * This could be simplified if all environments supported
4453
     * 64-bit integers.
4454
     */
4455
    if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
4456
        stats->gorch++;
4457
    /* Is this a broadcast or multicast?  Check broadcast first,
4458
     * since the test for a multicast frame will test positive on
4459
     * a broadcast frame.
4460
     */
4461
    if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
4462
        /* Broadcast packet */
4463
        stats->bprc++;
4464
    else if(*mac_addr & 0x01)
4465
        /* Multicast packet */
4466
        stats->mprc++;
4467
 
4468
    if(frame_len == hw->max_frame_size) {
4469
        /* In this case, the hardware has overcounted the number of
4470
         * oversize frames.
4471
         */
4472
        if(stats->roc > 0)
4473
            stats->roc--;
4474
    }
4475
 
4476
    /* Adjust the bin counters when the extra byte put the frame in the
4477
     * wrong bin. Remember that the frame_len was adjusted above.
4478
     */
4479
    if(frame_len == 64) {
4480
        stats->prc64++;
4481
        stats->prc127--;
4482
    } else if(frame_len == 127) {
4483
        stats->prc127++;
4484
        stats->prc255--;
4485
    } else if(frame_len == 255) {
4486
        stats->prc255++;
4487
        stats->prc511--;
4488
    } else if(frame_len == 511) {
4489
        stats->prc511++;
4490
        stats->prc1023--;
4491
    } else if(frame_len == 1023) {
4492
        stats->prc1023++;
4493
        stats->prc1522--;
4494
    } else if(frame_len == 1522) {
4495
        stats->prc1522++;
4496
    }
4497
}
4498
 
4499
/******************************************************************************
4500
 * Gets the current PCI bus type, speed, and width of the hardware
4501
 *
4502
 * hw - Struct containing variables accessed by shared code
4503
 *****************************************************************************/
4504
void
4505
e1000_get_bus_info(struct e1000_hw *hw)
4506
{
4507
    uint32_t status;
4508
 
4509
    if(hw->mac_type < e1000_82543) {
4510
        hw->bus_type = e1000_bus_type_unknown;
4511
        hw->bus_speed = e1000_bus_speed_unknown;
4512
        hw->bus_width = e1000_bus_width_unknown;
4513
        return;
4514
    }
4515
 
4516
    status = E1000_READ_REG(hw, STATUS);
4517
    hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
4518
                   e1000_bus_type_pcix : e1000_bus_type_pci;
4519
 
4520
    if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
4521
        hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
4522
                        e1000_bus_speed_66 : e1000_bus_speed_120;
4523
    } else if(hw->bus_type == e1000_bus_type_pci) {
4524
        hw->bus_speed = (status & E1000_STATUS_PCI66) ?
4525
                        e1000_bus_speed_66 : e1000_bus_speed_33;
4526
    } else {
4527
        switch (status & E1000_STATUS_PCIX_SPEED) {
4528
        case E1000_STATUS_PCIX_SPEED_66:
4529
            hw->bus_speed = e1000_bus_speed_66;
4530
            break;
4531
        case E1000_STATUS_PCIX_SPEED_100:
4532
            hw->bus_speed = e1000_bus_speed_100;
4533
            break;
4534
        case E1000_STATUS_PCIX_SPEED_133:
4535
            hw->bus_speed = e1000_bus_speed_133;
4536
            break;
4537
        default:
4538
            hw->bus_speed = e1000_bus_speed_reserved;
4539
            break;
4540
        }
4541
    }
4542
    hw->bus_width = (status & E1000_STATUS_BUS64) ?
4543
                    e1000_bus_width_64 : e1000_bus_width_32;
4544
}
4545
/******************************************************************************
4546
 * Reads a value from one of the devices registers using port I/O (as opposed
4547
 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4548
 *
4549
 * hw - Struct containing variables accessed by shared code
4550
 * offset - offset to read from
4551
 *****************************************************************************/
4552
uint32_t
4553
e1000_read_reg_io(struct e1000_hw *hw,
4554
                  uint32_t offset)
4555
{
4556
    unsigned long io_addr = hw->io_base;
4557
    unsigned long io_data = hw->io_base + 4;
4558
 
4559
    e1000_io_write(hw, io_addr, offset);
4560
    return e1000_io_read(hw, io_data);
4561
}
4562
 
4563
/******************************************************************************
4564
 * Writes a value to one of the devices registers using port I/O (as opposed to
4565
 * memory mapped I/O). Only 82544 and newer devices support port I/O.
4566
 *
4567
 * hw - Struct containing variables accessed by shared code
4568
 * offset - offset to write to
4569
 * value - value to write
4570
 *****************************************************************************/
4571
void
4572
e1000_write_reg_io(struct e1000_hw *hw,
4573
                   uint32_t offset,
4574
                   uint32_t value)
4575
{
4576
    unsigned long io_addr = hw->io_base;
4577
    unsigned long io_data = hw->io_base + 4;
4578
 
4579
    e1000_io_write(hw, io_addr, offset);
4580
    e1000_io_write(hw, io_data, value);
4581
}
4582
 
4583
 
4584
/******************************************************************************
4585
 * Estimates the cable length.
4586
 *
4587
 * hw - Struct containing variables accessed by shared code
4588
 * min_length - The estimated minimum length
4589
 * max_length - The estimated maximum length
4590
 *
4591
 * returns: - E1000_ERR_XXX
4592
 *            E1000_SUCCESS
4593
 *
4594
 * This function always returns a ranged length (minimum & maximum).
4595
 * So for M88 phy's, this function interprets the one value returned from the
4596
 * register to the minimum and maximum range.
4597
 * For IGP phy's, the function calculates the range by the AGC registers.
4598
 *****************************************************************************/
4599
int32_t
4600
e1000_get_cable_length(struct e1000_hw *hw,
4601
                       uint16_t *min_length,
4602
                       uint16_t *max_length)
4603
{
4604
    int32_t ret_val;
4605
    uint16_t agc_value = 0;
4606
    uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
4607
    uint16_t i, phy_data;
4608
 
4609
    DEBUGFUNC("e1000_get_cable_length");
4610
 
4611
    *min_length = *max_length = 0;
4612
 
4613
    /* Use old method for Phy older than IGP */
4614
    if(hw->phy_type == e1000_phy_m88) {
4615
        if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4616
                                         &phy_data)))
4617
            return ret_val;
4618
 
4619
        /* Convert the enum value to ranged values */
4620
        switch((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
4621
               M88E1000_PSSR_CABLE_LENGTH_SHIFT) {
4622
        case e1000_cable_length_50:
4623
            *min_length = 0;
4624
            *max_length = e1000_igp_cable_length_50;
4625
            break;
4626
        case e1000_cable_length_50_80:
4627
            *min_length = e1000_igp_cable_length_50;
4628
            *max_length = e1000_igp_cable_length_80;
4629
            break;
4630
        case e1000_cable_length_80_110:
4631
            *min_length = e1000_igp_cable_length_80;
4632
            *max_length = e1000_igp_cable_length_110;
4633
            break;
4634
        case e1000_cable_length_110_140:
4635
            *min_length = e1000_igp_cable_length_110;
4636
            *max_length = e1000_igp_cable_length_140;
4637
            break;
4638
        case e1000_cable_length_140:
4639
            *min_length = e1000_igp_cable_length_140;
4640
            *max_length = e1000_igp_cable_length_170;
4641
            break;
4642
        default:
4643
            return -E1000_ERR_PHY;
4644
            break;
4645
        }
4646
    } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
4647
        uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4648
                                                         {IGP01E1000_PHY_AGC_A,
4649
                                                          IGP01E1000_PHY_AGC_B,
4650
                                                          IGP01E1000_PHY_AGC_C,
4651
                                                          IGP01E1000_PHY_AGC_D};
4652
        /* Read the AGC registers for all channels */
4653
        for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4654
 
4655
            if((ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data)))
4656
                return ret_val;
4657
 
4658
            cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
4659
 
4660
            /* Array bound check. */
4661
            if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
4662
               (cur_agc == 0))
4663
                return -E1000_ERR_PHY;
4664
 
4665
            agc_value += cur_agc;
4666
 
4667
            /* Update minimal AGC value. */
4668
            if(min_agc > cur_agc)
4669
                min_agc = cur_agc;
4670
        }
4671
 
4672
        /* Remove the minimal AGC result for length < 50m */
4673
        if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
4674
            agc_value -= min_agc;
4675
 
4676
            /* Get the average length of the remaining 3 channels */
4677
            agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
4678
        } else {
4679
            /* Get the average length of all the 4 channels. */
4680
            agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
4681
        }
4682
 
4683
        /* Set the range of the calculated length. */
4684
        *min_length = ((e1000_igp_cable_length_table[agc_value] -
4685
                       IGP01E1000_AGC_RANGE) > 0) ?
4686
                       (e1000_igp_cable_length_table[agc_value] -
4687
                       IGP01E1000_AGC_RANGE) : 0;
4688
        *max_length = e1000_igp_cable_length_table[agc_value] +
4689
                      IGP01E1000_AGC_RANGE;
4690
    }
4691
 
4692
    return E1000_SUCCESS;
4693
}
4694
 
4695
/******************************************************************************
4696
 * Check the cable polarity
4697
 *
4698
 * hw - Struct containing variables accessed by shared code
4699
 * polarity - output parameter : 0 - Polarity is not reversed
4700
 *                               1 - Polarity is reversed.
4701
 *
4702
 * returns: - E1000_ERR_XXX
4703
 *            E1000_SUCCESS
4704
 *
4705
 * For phy's older then IGP, this function simply reads the polarity bit in the
4706
 * Phy Status register.  For IGP phy's, this bit is valid only if link speed is
4707
 * 10 Mbps.  If the link speed is 100 Mbps there is no polarity so this bit will
4708
 * return 0.  If the link speed is 1000 Mbps the polarity status is in the
4709
 * IGP01E1000_PHY_PCS_INIT_REG.
4710
 *****************************************************************************/
4711
int32_t
4712
e1000_check_polarity(struct e1000_hw *hw,
4713
                     uint16_t *polarity)
4714
{
4715
    int32_t ret_val;
4716
    uint16_t phy_data;
4717
 
4718
    DEBUGFUNC("e1000_check_polarity");
4719
 
4720
    if(hw->phy_type == e1000_phy_m88) {
4721
        /* return the Polarity bit in the Status register. */
4722
        if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4723
                                         &phy_data)))
4724
            return ret_val;
4725
        *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
4726
                    M88E1000_PSSR_REV_POLARITY_SHIFT;
4727
    } else if(hw->phy_type == e1000_phy_igp) {
4728
        /* Read the Status register to check the speed */
4729
        if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
4730
                                         &phy_data)))
4731
            return ret_val;
4732
 
4733
        /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
4734
         * find the polarity status */
4735
        if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
4736
           IGP01E1000_PSSR_SPEED_1000MBPS) {
4737
 
4738
            /* Read the GIG initialization PCS register (0x00B4) */
4739
            if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
4740
                                             &phy_data)))
4741
                return ret_val;
4742
 
4743
            /* Check the polarity bits */
4744
            *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
4745
        } else {
4746
            /* For 10 Mbps, read the polarity bit in the status register. (for
4747
             * 100 Mbps this bit is always 0) */
4748
            *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
4749
        }
4750
    }
4751
    return E1000_SUCCESS;
4752
}
4753
 
4754
/******************************************************************************
4755
 * Check if Downshift occured
4756
 *
4757
 * hw - Struct containing variables accessed by shared code
4758
 * downshift - output parameter : 0 - No Downshift ocured.
4759
 *                                1 - Downshift ocured.
4760
 *
4761
 * returns: - E1000_ERR_XXX
4762
 *            E1000_SUCCESS
4763
 *
4764
 * For phy's older then IGP, this function reads the Downshift bit in the Phy
4765
 * Specific Status register.  For IGP phy's, it reads the Downgrade bit in the
4766
 * Link Health register.  In IGP this bit is latched high, so the driver must
4767
 * read it immediately after link is established.
4768
 *****************************************************************************/
4769
int32_t
4770
e1000_check_downshift(struct e1000_hw *hw)
4771
{
4772
    int32_t ret_val;
4773
    uint16_t phy_data;
4774
 
4775
    DEBUGFUNC("e1000_check_downshift");
4776
 
4777
    if(hw->phy_type == e1000_phy_igp) {
4778
        if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
4779
                                         &phy_data)))
4780
            return ret_val;
4781
 
4782
        hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
4783
    }
4784
    else if(hw->phy_type == e1000_phy_m88) {
4785
        if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
4786
                                         &phy_data)))
4787
            return ret_val;
4788
 
4789
        hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
4790
                               M88E1000_PSSR_DOWNSHIFT_SHIFT;
4791
    }
4792
    return E1000_SUCCESS;
4793
}
4794
 
4795
/*****************************************************************************
4796
 *
4797
 * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
4798
 * gigabit link is achieved to improve link quality.
4799
 *
4800
 * hw: Struct containing variables accessed by shared code
4801
 *
4802
 * returns: - E1000_ERR_PHY if fail to read/write the PHY
4803
 *            E1000_SUCCESS at any other case.
4804
 *
4805
 ****************************************************************************/
4806
 
4807
int32_t
4808
e1000_config_dsp_after_link_change(struct e1000_hw *hw,
4809
                                   boolean_t link_up)
4810
{
4811
    int32_t ret_val;
4812
    uint16_t phy_data, speed, duplex, i;
4813
    uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
4814
                                        {IGP01E1000_PHY_AGC_PARAM_A,
4815
                                        IGP01E1000_PHY_AGC_PARAM_B,
4816
                                        IGP01E1000_PHY_AGC_PARAM_C,
4817
                                        IGP01E1000_PHY_AGC_PARAM_D};
4818
    uint16_t min_length, max_length;
4819
 
4820
    DEBUGFUNC("e1000_config_dsp_after_link_change");
4821
 
4822
    if(hw->phy_type != e1000_phy_igp)
4823
        return E1000_SUCCESS;
4824
 
4825
    if(link_up) {
4826
        if((ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex))) {
4827
            DEBUGOUT("Error getting link speed and duplex\n");
4828
            return ret_val;
4829
        }
4830
 
4831
        if(speed == SPEED_1000) {
4832
 
4833
            e1000_get_cable_length(hw, &min_length, &max_length);
4834
 
4835
            if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
4836
                min_length >= e1000_igp_cable_length_50) {
4837
 
4838
                for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4839
                    if((ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
4840
                                                     &phy_data)))
4841
                        return ret_val;
4842
 
4843
                    phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
4844
 
4845
                    if((ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
4846
                                                      phy_data)))
4847
                        return ret_val;
4848
                }
4849
                hw->dsp_config_state = e1000_dsp_config_activated;
4850
            }
4851
 
4852
            if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
4853
               (min_length < e1000_igp_cable_length_50)) {
4854
 
4855
                uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
4856
                uint32_t idle_errs = 0;
4857
 
4858
                /* clear previous idle error counts */
4859
                if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
4860
                                                 &phy_data)))
4861
                    return ret_val;
4862
 
4863
                for(i = 0; i < ffe_idle_err_timeout; i++) {
4864
                    udelay(1000);
4865
                    if((ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
4866
                                                     &phy_data)))
4867
                        return ret_val;
4868
 
4869
                    idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
4870
                    if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
4871
                        hw->ffe_config_state = e1000_ffe_config_active;
4872
 
4873
                        if((ret_val = e1000_write_phy_reg(hw,
4874
                                    IGP01E1000_PHY_DSP_FFE,
4875
                                    IGP01E1000_PHY_DSP_FFE_CM_CP)))
4876
                            return ret_val;
4877
                        break;
4878
                    }
4879
 
4880
                    if(idle_errs)
4881
                        ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
4882
                }
4883
            }
4884
        }
4885
    } else {
4886
        if(hw->dsp_config_state == e1000_dsp_config_activated) {
4887
            if((ret_val = e1000_write_phy_reg(hw, 0x0000,
4888
                IGP01E1000_IEEE_FORCE_GIGA)))
4889
                return ret_val;
4890
            for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
4891
                if((ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
4892
                                                 &phy_data)))
4893
                    return ret_val;
4894
 
4895
                phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
4896
                phy_data |=  IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
4897
 
4898
                if((ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i],
4899
                                                  phy_data)))
4900
                    return ret_val;
4901
            }
4902
 
4903
            if((ret_val = e1000_write_phy_reg(hw, 0x0000,
4904
                                              IGP01E1000_IEEE_RESTART_AUTONEG)))
4905
                return ret_val;
4906
 
4907
            hw->dsp_config_state = e1000_dsp_config_enabled;
4908
        }
4909
 
4910
        if(hw->ffe_config_state == e1000_ffe_config_active) {
4911
            if((ret_val = e1000_write_phy_reg(hw, 0x0000,
4912
                                              IGP01E1000_IEEE_FORCE_GIGA)))
4913
                return ret_val;
4914
            if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
4915
                                              IGP01E1000_PHY_DSP_FFE_DEFAULT)))
4916
                return ret_val;
4917
 
4918
            if((ret_val = e1000_write_phy_reg(hw, 0x0000,
4919
                                              IGP01E1000_IEEE_RESTART_AUTONEG)))
4920
                return ret_val;
4921
        hw->ffe_config_state = e1000_ffe_config_enabled;
4922
        }
4923
    }
4924
    return E1000_SUCCESS;
4925
}
4926
 
4927
/*****************************************************************************
4928
 *
4929
 * This function sets the lplu state according to the active flag.  When
4930
 * activating lplu this function also disables smart speed and vise versa.
4931
 * lplu will not be activated unless the device autonegotiation advertisment
4932
 * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
4933
 * hw: Struct containing variables accessed by shared code
4934
 * active - true to enable lplu false to disable lplu.
4935
 *
4936
 * returns: - E1000_ERR_PHY if fail to read/write the PHY
4937
 *            E1000_SUCCESS at any other case.
4938
 *
4939
 ****************************************************************************/
4940
 
4941
int32_t
4942
e1000_set_d3_lplu_state(struct e1000_hw *hw,
4943
                        boolean_t active)
4944
{
4945
    int32_t ret_val;
4946
    uint16_t phy_data;
4947
    DEBUGFUNC("e1000_set_d3_lplu_state");
4948
 
4949
    if(!((hw->mac_type == e1000_82541_rev_2) ||
4950
         (hw->mac_type == e1000_82547_rev_2)))
4951
        return E1000_SUCCESS;
4952
 
4953
    /* During driver activity LPLU should not be used or it will attain link
4954
     * from the lowest speeds starting from 10Mbps. The capability is used for
4955
     * Dx transitions and states */
4956
    if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data)))
4957
        return ret_val;
4958
 
4959
    if(!active) {
4960
        phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
4961
        if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data)))
4962
            return ret_val;
4963
 
4964
        /* LPLU and SmartSpeed are mutually exclusive.  LPLU is used during
4965
         * Dx states where the power conservation is most important.  During
4966
         * driver activity we should enable SmartSpeed, so performance is
4967
         * maintained. */
4968
        if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
4969
                                         &phy_data)))
4970
            return ret_val;
4971
 
4972
        phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
4973
        if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
4974
                                          phy_data)))
4975
            return ret_val;
4976
 
4977
    } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
4978
              (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
4979
              (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
4980
 
4981
        phy_data |= IGP01E1000_GMII_FLEX_SPD;
4982
        if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data)))
4983
            return ret_val;
4984
 
4985
        /* When LPLU is enabled we should disable SmartSpeed */
4986
        if((ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
4987
                                         &phy_data)))
4988
            return ret_val;
4989
 
4990
        phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
4991
        if((ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
4992
                                          phy_data)))
4993
            return ret_val;
4994
 
4995
    }
4996
    return E1000_SUCCESS;
4997
}
4998
 
4999
/******************************************************************************
5000
 * Change VCO speed register to improve Bit Error Rate performance of SERDES.
5001
 *
5002
 * hw - Struct containing variables accessed by shared code
5003
 *****************************************************************************/
5004
static int32_t
5005
e1000_set_vco_speed(struct e1000_hw *hw)
5006
{
5007
    int32_t  ret_val;
5008
    uint16_t default_page = 0;
5009
    uint16_t phy_data;
5010
 
5011
    DEBUGFUNC("e1000_set_vco_speed");
5012
 
5013
    switch(hw->mac_type) {
5014
    case e1000_82545_rev_3:
5015
    case e1000_82546_rev_3:
5016
       break;
5017
    default:
5018
        return E1000_SUCCESS;
5019
    }
5020
 
5021
    /* Set PHY register 30, page 5, bit 8 to 0 */
5022
 
5023
    if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
5024
                                     &default_page)))
5025
        return ret_val;
5026
 
5027
    if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005)))
5028
        return ret_val;
5029
 
5030
    if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data)))
5031
        return ret_val;
5032
 
5033
    phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
5034
    if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data)))
5035
        return ret_val;
5036
 
5037
    /* Set PHY register 30, page 4, bit 11 to 1 */
5038
 
5039
    if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004)))
5040
        return ret_val;
5041
 
5042
    if((ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data)))
5043
        return ret_val;
5044
 
5045
    phy_data |= M88E1000_PHY_VCO_REG_BIT11;
5046
    if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data)))
5047
        return ret_val;
5048
 
5049
    if((ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT,
5050
                                      default_page)))
5051
        return ret_val;
5052
 
5053
    return E1000_SUCCESS;
5054
}
5055
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.