~ubuntu-branches/ubuntu/utopic/xen/utopic

« back to all changes in this revision

Viewing changes to xen/drivers/net/e1000/e1000_hw.c

  • Committer: Bazaar Package Importer
  • Author(s): Bastian Blank
  • Date: 2010-05-06 15:47:38 UTC
  • mto: (1.3.1) (15.1.1 sid) (4.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100506154738-agoz0rlafrh1fnq7
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

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