ich8lan.c 130 KB
Newer Older
1
2
3
/*******************************************************************************

  Intel PRO/1000 Linux driver
Bruce Allan's avatar
Bruce Allan committed
4
  Copyright(c) 1999 - 2013 Intel Corporation.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

  This program is free software; you can redistribute it and/or modify it
  under the terms and conditions of the GNU General Public License,
  version 2, as published by the Free Software Foundation.

  This program is distributed in the hope it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

  The full GNU General Public License is included in this distribution in
  the file called "COPYING".

  Contact Information:
  Linux NICS <linux.nics@intel.com>
  e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497

*******************************************************************************/

29
/* 82562G 10/100 Network Connection
30
31
32
33
34
35
36
37
38
39
40
 * 82562G-2 10/100 Network Connection
 * 82562GT 10/100 Network Connection
 * 82562GT-2 10/100 Network Connection
 * 82562V 10/100 Network Connection
 * 82562V-2 10/100 Network Connection
 * 82566DC-2 Gigabit Network Connection
 * 82566DC Gigabit Network Connection
 * 82566DM-2 Gigabit Network Connection
 * 82566DM Gigabit Network Connection
 * 82566MC Gigabit Network Connection
 * 82566MM Gigabit Network Connection
41
42
 * 82567LM Gigabit Network Connection
 * 82567LF Gigabit Network Connection
43
 * 82567V Gigabit Network Connection
44
45
46
 * 82567LM-2 Gigabit Network Connection
 * 82567LF-2 Gigabit Network Connection
 * 82567V-2 Gigabit Network Connection
47
48
 * 82567LF-3 Gigabit Network Connection
 * 82567LM-3 Gigabit Network Connection
49
 * 82567LM-4 Gigabit Network Connection
50
51
52
53
 * 82577LM Gigabit Network Connection
 * 82577LC Gigabit Network Connection
 * 82578DM Gigabit Network Connection
 * 82578DC Gigabit Network Connection
54
55
 * 82579LM Gigabit Network Connection
 * 82579V Gigabit Network Connection
56
57
58
59
60
61
62
63
 */

#include "e1000.h"

/* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
/* Offset 04h HSFSTS */
union ich8_hws_flash_status {
	struct ich8_hsfsts {
64
65
66
67
68
69
70
71
72
		u16 flcdone:1;	/* bit 0 Flash Cycle Done */
		u16 flcerr:1;	/* bit 1 Flash Cycle Error */
		u16 dael:1;	/* bit 2 Direct Access error Log */
		u16 berasesz:2;	/* bit 4:3 Sector Erase Size */
		u16 flcinprog:1;	/* bit 5 flash cycle in Progress */
		u16 reserved1:2;	/* bit 13:6 Reserved */
		u16 reserved2:6;	/* bit 13:6 Reserved */
		u16 fldesvalid:1;	/* bit 14 Flash Descriptor Valid */
		u16 flockdn:1;	/* bit 15 Flash Config Lock-Down */
73
74
75
76
77
78
79
80
	} hsf_status;
	u16 regval;
};

/* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
/* Offset 06h FLCTL */
union ich8_hws_flash_ctrl {
	struct ich8_hsflctl {
81
82
83
84
85
		u16 flcgo:1;	/* 0 Flash Cycle Go */
		u16 flcycle:2;	/* 2:1 Flash Cycle */
		u16 reserved:5;	/* 7:3 Reserved  */
		u16 fldbcount:2;	/* 9:8 Flash Data Byte Count */
		u16 flockdn:6;	/* 15:10 Reserved */
86
87
88
89
90
91
92
	} hsf_ctrl;
	u16 regval;
};

/* ICH Flash Region Access Permissions */
union ich8_hws_flash_regacc {
	struct ich8_flracc {
93
94
95
96
		u32 grra:8;	/* 0:7 GbE region Read Access */
		u32 grwa:8;	/* 8:15 GbE region Write Access */
		u32 gmrag:8;	/* 23:16 GbE Master Read Access Grant */
		u32 gmwag:8;	/* 31:24 GbE Master Write Access Grant */
97
98
99
100
	} hsf_flregacc;
	u16 regval;
};

101
102
103
/* ICH Flash Protected Region */
union ich8_flash_protected_range {
	struct ich8_pr {
Bruce Allan's avatar
Bruce Allan committed
104
105
106
107
108
109
		u32 base:13;	/* 0:12 Protected Range Base */
		u32 reserved1:2;	/* 13:14 Reserved */
		u32 rpe:1;	/* 15 Read Protection Enable */
		u32 limit:13;	/* 16:28 Protected Range Limit */
		u32 reserved2:2;	/* 29:30 Reserved */
		u32 wpe:1;	/* 31 Write Protection Enable */
110
111
112
113
	} range;
	u32 regval;
};

114
115
116
117
118
static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
						u32 offset, u8 byte);
119
120
static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
					 u8 *data);
121
122
123
124
125
static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
					 u16 *data);
static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
					 u8 size, u16 *data);
static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
126
127
128
129
130
131
132
133
static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
134
static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
135
static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
136
static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
137
static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
138
static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
139
140
static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
141
static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
Bruce Allan's avatar
Bruce Allan committed
142
static void e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
143
static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
144
static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
145
static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168

static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
{
	return readw(hw->flash_address + reg);
}

static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
{
	return readl(hw->flash_address + reg);
}

static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
{
	writew(val, hw->flash_address + reg);
}

static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
{
	writel(val, hw->flash_address + reg);
}

#define er16flash(reg)		__er16flash(hw, (reg))
#define er32flash(reg)		__er32flash(hw, (reg))
169
170
#define ew16flash(reg, val)	__ew16flash(hw, (reg), (val))
#define ew32flash(reg, val)	__ew32flash(hw, (reg), (val))
171

172
173
174
175
176
177
178
179
180
181
182
/**
 *  e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
 *  @hw: pointer to the HW structure
 *
 *  Test access to the PHY registers by reading the PHY ID registers.  If
 *  the PHY ID is already known (e.g. resume path) compare it with known ID,
 *  otherwise assume the read PHY ID is correct if it is valid.
 *
 *  Assumes the sw/fw/hw semaphore is already acquired.
 **/
static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
183
{
184
185
186
187
188
189
	u16 phy_reg = 0;
	u32 phy_id = 0;
	s32 ret_val;
	u16 retry_count;

	for (retry_count = 0; retry_count < 2; retry_count++) {
190
		ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
191
192
193
194
		if (ret_val || (phy_reg == 0xFFFF))
			continue;
		phy_id = (u32)(phy_reg << 16);

195
		ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
196
197
198
199
200
201
202
		if (ret_val || (phy_reg == 0xFFFF)) {
			phy_id = 0;
			continue;
		}
		phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
		break;
	}
203
204
205
206

	if (hw->phy.id) {
		if (hw->phy.id == phy_id)
			return true;
207
208
209
	} else if (phy_id) {
		hw->phy.id = phy_id;
		hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
210
211
212
		return true;
	}

213
	/* In case the PHY needs to be in mdio slow mode,
214
215
216
217
218
219
220
221
222
	 * set slow mode and try to get the PHY id again.
	 */
	hw->phy.ops.release(hw);
	ret_val = e1000_set_mdio_slow_mode_hv(hw);
	if (!ret_val)
		ret_val = e1000e_get_phy_id(hw);
	hw->phy.ops.acquire(hw);

	return !ret_val;
223
224
225
226
227
228
229
230
231
232
233
234
235
}

/**
 *  e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
 *  @hw: pointer to the HW structure
 *
 *  Workarounds/flow necessary for PHY initialization during driver load
 *  and resume paths.
 **/
static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
{
	u32 mac_reg, fwsm = er32(FWSM);
	s32 ret_val;
Bruce Allan's avatar
Bruce Allan committed
236
	u16 phy_reg;
237

238
239
240
241
242
	/* Gate automatic PHY configuration by hardware on managed and
	 * non-managed 82579 and newer adapters.
	 */
	e1000_gate_hw_phy_config_ich8lan(hw, true);

243
244
245
	ret_val = hw->phy.ops.acquire(hw);
	if (ret_val) {
		e_dbg("Failed to initialize PHY flow\n");
246
		goto out;
247
248
	}

249
	/* The MAC-PHY interconnect may be in SMBus mode.  If the PHY is
250
251
252
253
	 * inaccessible and resetting the PHY is not blocked, toggle the
	 * LANPHYPC Value bit to force the interconnect to PCIe mode.
	 */
	switch (hw->mac.type) {
Bruce Allan's avatar
Bruce Allan committed
254
255
256
257
	case e1000_pch_lpt:
		if (e1000_phy_is_accessible_pchlan(hw))
			break;

258
		/* Before toggling LANPHYPC, see if PHY is accessible by
Bruce Allan's avatar
Bruce Allan committed
259
260
261
262
263
264
265
		 * forcing MAC to SMBus mode first.
		 */
		mac_reg = er32(CTRL_EXT);
		mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
		ew32(CTRL_EXT, mac_reg);

		/* fall-through */
266
	case e1000_pch2lan:
Bruce Allan's avatar
Bruce Allan committed
267
268
269
270
271
272
273
274
275
276
277
278
		if (e1000_phy_is_accessible_pchlan(hw)) {
			if (hw->mac.type == e1000_pch_lpt) {
				/* Unforce SMBus mode in PHY */
				e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
				phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
				e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);

				/* Unforce SMBus mode in MAC */
				mac_reg = er32(CTRL_EXT);
				mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
				ew32(CTRL_EXT, mac_reg);
			}
279
			break;
Bruce Allan's avatar
Bruce Allan committed
280
		}
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

		/* fall-through */
	case e1000_pchlan:
		if ((hw->mac.type == e1000_pchlan) &&
		    (fwsm & E1000_ICH_FWSM_FW_VALID))
			break;

		if (hw->phy.ops.check_reset_block(hw)) {
			e_dbg("Required LANPHYPC toggle blocked by ME\n");
			break;
		}

		e_dbg("Toggling LANPHYPC\n");

		/* Set Phy Config Counter to 50msec */
		mac_reg = er32(FEXTNVM3);
		mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
		mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
		ew32(FEXTNVM3, mac_reg);

301
302
303
304
305
306
307
308
309
		if (hw->mac.type == e1000_pch_lpt) {
			/* Toggling LANPHYPC brings the PHY out of SMBus mode
			 * So ensure that the MAC is also out of SMBus mode
			 */
			mac_reg = er32(CTRL_EXT);
			mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
			ew32(CTRL_EXT, mac_reg);
		}

310
311
312
313
314
315
		/* Toggle LANPHYPC Value bit */
		mac_reg = er32(CTRL);
		mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
		mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
		ew32(CTRL, mac_reg);
		e1e_flush();
316
		usleep_range(10, 20);
317
318
319
		mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
		ew32(CTRL, mac_reg);
		e1e_flush();
Bruce Allan's avatar
Bruce Allan committed
320
321
322
323
324
325
326
327
328
		if (hw->mac.type < e1000_pch_lpt) {
			msleep(50);
		} else {
			u16 count = 20;
			do {
				usleep_range(5000, 10000);
			} while (!(er32(CTRL_EXT) &
				   E1000_CTRL_EXT_LPCD) && count--);
		}
329
330
331
332
333
334
335
		break;
	default:
		break;
	}

	hw->phy.ops.release(hw);

336
	/* Reset the PHY before any access to it.  Doing so, ensures
337
338
339
340
341
342
	 * that the PHY is in a known good state before we read/write
	 * PHY registers.  The generic reset is sufficient here,
	 * because we haven't determined the PHY type yet.
	 */
	ret_val = e1000e_phy_hw_reset_generic(hw);

343
out:
344
345
346
347
348
349
350
351
	/* Ungate automatic PHY configuration on non-managed 82579 */
	if ((hw->mac.type == e1000_pch2lan) &&
	    !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
		usleep_range(10000, 20000);
		e1000_gate_hw_phy_config_ich8lan(hw, false);
	}

	return ret_val;
352
353
}

354
355
356
357
358
359
360
361
362
/**
 *  e1000_init_phy_params_pchlan - Initialize PHY function pointers
 *  @hw: pointer to the HW structure
 *
 *  Initialize family-specific PHY parameters and function pointers.
 **/
static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
{
	struct e1000_phy_info *phy = &hw->phy;
363
	s32 ret_val;
364

Bruce Allan's avatar
Bruce Allan committed
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
	phy->addr = 1;
	phy->reset_delay_us = 100;

	phy->ops.set_page = e1000_set_page_igp;
	phy->ops.read_reg = e1000_read_phy_reg_hv;
	phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
	phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
	phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
	phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
	phy->ops.write_reg = e1000_write_phy_reg_hv;
	phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
	phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
	phy->ops.power_up = e1000_power_up_phy_copper;
	phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
	phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
380

381
	phy->id = e1000_phy_unknown;
382

383
384
385
	ret_val = e1000_init_phy_workarounds_pchlan(hw);
	if (ret_val)
		return ret_val;
386

387
388
389
390
391
392
393
394
395
396
	if (phy->id == e1000_phy_unknown)
		switch (hw->mac.type) {
		default:
			ret_val = e1000e_get_phy_id(hw);
			if (ret_val)
				return ret_val;
			if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
				break;
			/* fall-through */
		case e1000_pch2lan:
Bruce Allan's avatar
Bruce Allan committed
397
		case e1000_pch_lpt:
398
			/* In case the PHY needs to be in mdio slow mode,
399
400
401
402
403
404
405
406
			 * set slow mode and try to get the PHY id again.
			 */
			ret_val = e1000_set_mdio_slow_mode_hv(hw);
			if (ret_val)
				return ret_val;
			ret_val = e1000e_get_phy_id(hw);
			if (ret_val)
				return ret_val;
407
			break;
408
		}
409
410
	phy->type = e1000e_get_phy_type_from_id(phy->id);

411
412
	switch (phy->type) {
	case e1000_phy_82577:
413
	case e1000_phy_82579:
Bruce Allan's avatar
Bruce Allan committed
414
	case e1000_phy_i217:
415
416
		phy->ops.check_polarity = e1000_check_polarity_82577;
		phy->ops.force_speed_duplex =
417
		    e1000_phy_force_speed_duplex_82577;
418
		phy->ops.get_cable_length = e1000_get_cable_length_82577;
419
420
		phy->ops.get_info = e1000_get_phy_info_82577;
		phy->ops.commit = e1000e_phy_sw_reset;
421
		break;
422
423
424
425
426
427
428
429
430
	case e1000_phy_82578:
		phy->ops.check_polarity = e1000_check_polarity_m88;
		phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
		phy->ops.get_cable_length = e1000e_get_cable_length_m88;
		phy->ops.get_info = e1000e_get_phy_info_m88;
		break;
	default:
		ret_val = -E1000_ERR_PHY;
		break;
431
432
433
434
435
	}

	return ret_val;
}

436
437
438
439
440
441
442
443
444
445
446
447
/**
 *  e1000_init_phy_params_ich8lan - Initialize PHY function pointers
 *  @hw: pointer to the HW structure
 *
 *  Initialize family-specific PHY parameters and function pointers.
 **/
static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
{
	struct e1000_phy_info *phy = &hw->phy;
	s32 ret_val;
	u16 i = 0;

Bruce Allan's avatar
Bruce Allan committed
448
449
	phy->addr = 1;
	phy->reset_delay_us = 100;
450

Bruce Allan's avatar
Bruce Allan committed
451
452
	phy->ops.power_up = e1000_power_up_phy_copper;
	phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
453

454
	/* We may need to do this twice - once for IGP and if that fails,
455
456
457
458
	 * we'll set BM func pointers and try again
	 */
	ret_val = e1000e_determine_phy_address(hw);
	if (ret_val) {
459
		phy->ops.write_reg = e1000e_write_phy_reg_bm;
Bruce Allan's avatar
Bruce Allan committed
460
		phy->ops.read_reg = e1000e_read_phy_reg_bm;
461
		ret_val = e1000e_determine_phy_address(hw);
Bruce Allan's avatar
Bruce Allan committed
462
463
		if (ret_val) {
			e_dbg("Cannot determine PHY addr. Erroring out\n");
464
			return ret_val;
Bruce Allan's avatar
Bruce Allan committed
465
		}
466
467
	}

468
469
470
	phy->id = 0;
	while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
	       (i++ < 100)) {
471
		usleep_range(1000, 2000);
472
473
474
475
476
477
478
479
480
481
		ret_val = e1000e_get_phy_id(hw);
		if (ret_val)
			return ret_val;
	}

	/* Verify phy id */
	switch (phy->id) {
	case IGP03E1000_E_PHY_ID:
		phy->type = e1000_phy_igp_3;
		phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
482
483
		phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
		phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
484
485
486
		phy->ops.get_info = e1000e_get_phy_info_igp;
		phy->ops.check_polarity = e1000_check_polarity_igp;
		phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
487
488
489
490
491
492
		break;
	case IFE_E_PHY_ID:
	case IFE_PLUS_E_PHY_ID:
	case IFE_C_E_PHY_ID:
		phy->type = e1000_phy_ife;
		phy->autoneg_mask = E1000_ALL_NOT_GIG;
493
494
495
		phy->ops.get_info = e1000_get_phy_info_ife;
		phy->ops.check_polarity = e1000_check_polarity_ife;
		phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
496
		break;
497
498
499
	case BME1000_E_PHY_ID:
		phy->type = e1000_phy_bm;
		phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
500
501
502
		phy->ops.read_reg = e1000e_read_phy_reg_bm;
		phy->ops.write_reg = e1000e_write_phy_reg_bm;
		phy->ops.commit = e1000e_phy_sw_reset;
503
504
505
		phy->ops.get_info = e1000e_get_phy_info_m88;
		phy->ops.check_polarity = e1000_check_polarity_m88;
		phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
506
		break;
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
	default:
		return -E1000_ERR_PHY;
		break;
	}

	return 0;
}

/**
 *  e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
 *  @hw: pointer to the HW structure
 *
 *  Initialize family-specific NVM parameters and function
 *  pointers.
 **/
static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
{
	struct e1000_nvm_info *nvm = &hw->nvm;
	struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
526
	u32 gfpreg, sector_base_addr, sector_end_addr;
527
528
	u16 i;

529
	/* Can't read flash registers if the register set isn't mapped. */
530
	if (!hw->flash_address) {
531
		e_dbg("ERROR: Flash registers not mapped\n");
532
533
534
535
536
537
538
		return -E1000_ERR_CONFIG;
	}

	nvm->type = e1000_nvm_flash_sw;

	gfpreg = er32flash(ICH_FLASH_GFPREG);

539
	/* sector_X_addr is a "sector"-aligned address (4096 bytes)
540
	 * Add 1 to sector_end_addr since this sector is included in
541
542
	 * the overall size.
	 */
543
544
545
546
547
548
	sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
	sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;

	/* flash_base_addr is byte-aligned */
	nvm->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;

549
	/* find total size of the NVM, then cut in half since the total
550
551
	 * size represents two separate NVM banks.
	 */
552
553
	nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
				<< FLASH_SECTOR_ADDR_SHIFT);
554
555
556
557
558
559
560
561
	nvm->flash_bank_size /= 2;
	/* Adjust to word count */
	nvm->flash_bank_size /= sizeof(u16);

	nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;

	/* Clear shadow ram */
	for (i = 0; i < nvm->word_size; i++) {
562
		dev_spec->shadow_ram[i].modified = false;
Bruce Allan's avatar
Bruce Allan committed
563
		dev_spec->shadow_ram[i].value = 0xFFFF;
564
565
566
567
568
569
570
571
572
573
574
575
	}

	return 0;
}

/**
 *  e1000_init_mac_params_ich8lan - Initialize MAC function pointers
 *  @hw: pointer to the HW structure
 *
 *  Initialize family-specific MAC parameters and function
 *  pointers.
 **/
576
static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
577
578
579
580
{
	struct e1000_mac_info *mac = &hw->mac;

	/* Set media type function pointer */
581
	hw->phy.media_type = e1000_media_type_copper;
582
583
584
585
586
587
588

	/* Set mta register count */
	mac->mta_reg_count = 32;
	/* Set rar entry count */
	mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
	if (mac->type == e1000_ich8lan)
		mac->rar_entry_count--;
589
590
591
592
	/* FWSM register */
	mac->has_fwsm = true;
	/* ARC subsystem not supported */
	mac->arc_subsystem_valid = false;
593
594
	/* Adaptive IFS supported */
	mac->adaptive_ifs = true;
595

Bruce Allan's avatar
Bruce Allan committed
596
	/* LED and other operations */
597
598
599
600
	switch (mac->type) {
	case e1000_ich8lan:
	case e1000_ich9lan:
	case e1000_ich10lan:
601
602
		/* check management mode */
		mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
603
		/* ID LED init */
604
		mac->ops.id_led_init = e1000e_id_led_init_generic;
605
606
		/* blink LED */
		mac->ops.blink_led = e1000e_blink_led_generic;
607
608
609
610
611
612
613
614
		/* setup LED */
		mac->ops.setup_led = e1000e_setup_led_generic;
		/* cleanup LED */
		mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
		/* turn on/off LED */
		mac->ops.led_on = e1000_led_on_ich8lan;
		mac->ops.led_off = e1000_led_off_ich8lan;
		break;
615
	case e1000_pch2lan:
616
617
618
		mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
		mac->ops.rar_set = e1000_rar_set_pch2lan;
		/* fall-through */
Bruce Allan's avatar
Bruce Allan committed
619
	case e1000_pch_lpt:
620
	case e1000_pchlan:
621
622
		/* check management mode */
		mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
623
624
625
626
627
628
629
630
631
632
633
634
635
636
		/* ID LED init */
		mac->ops.id_led_init = e1000_id_led_init_pchlan;
		/* setup LED */
		mac->ops.setup_led = e1000_setup_led_pchlan;
		/* cleanup LED */
		mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
		/* turn on/off LED */
		mac->ops.led_on = e1000_led_on_pchlan;
		mac->ops.led_off = e1000_led_off_pchlan;
		break;
	default:
		break;
	}

Bruce Allan's avatar
Bruce Allan committed
637
638
639
	if (mac->type == e1000_pch_lpt) {
		mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
		mac->ops.rar_set = e1000_rar_set_pch_lpt;
640
641
		mac->ops.setup_physical_interface =
		    e1000_setup_copper_link_pch_lpt;
Bruce Allan's avatar
Bruce Allan committed
642
643
	}

644
645
	/* Enable PCS Lock-loss workaround for ICH8 */
	if (mac->type == e1000_ich8lan)
646
		e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
647
648
649
650

	return 0;
}

651
652
653
654
655
656
657
658
659
660
661
662
/**
 *  __e1000_access_emi_reg_locked - Read/write EMI register
 *  @hw: pointer to the HW structure
 *  @addr: EMI address to program
 *  @data: pointer to value to read/write from/to the EMI address
 *  @read: boolean flag to indicate read or write
 *
 *  This helper function assumes the SW/FW/HW Semaphore is already acquired.
 **/
static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
					 u16 *data, bool read)
{
663
	s32 ret_val;
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684

	ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
	if (ret_val)
		return ret_val;

	if (read)
		ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
	else
		ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);

	return ret_val;
}

/**
 *  e1000_read_emi_reg_locked - Read Extended Management Interface register
 *  @hw: pointer to the HW structure
 *  @addr: EMI address to program
 *  @data: value to be read from the EMI address
 *
 *  Assumes the SW/FW/HW Semaphore is already acquired.
 **/
685
s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
686
687
688
689
690
691
692
693
694
695
696
697
{
	return __e1000_access_emi_reg_locked(hw, addr, data, true);
}

/**
 *  e1000_write_emi_reg_locked - Write Extended Management Interface register
 *  @hw: pointer to the HW structure
 *  @addr: EMI address to program
 *  @data: value to be written to the EMI address
 *
 *  Assumes the SW/FW/HW Semaphore is already acquired.
 **/
698
s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
699
700
701
702
{
	return __e1000_access_emi_reg_locked(hw, addr, &data, false);
}

703
704
705
706
/**
 *  e1000_set_eee_pchlan - Enable/disable EEE support
 *  @hw: pointer to the HW structure
 *
707
708
709
 *  Enable/disable EEE based on setting in dev_spec structure, the duplex of
 *  the link and the EEE capabilities of the link partner.  The LPI Control
 *  register bits will remain set only if/when link is up.
710
711
712
 **/
static s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
{
Bruce Allan's avatar
Bruce Allan committed
713
	struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
714
	s32 ret_val;
715
	u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
716

717
718
719
720
721
722
723
724
725
726
727
728
	switch (hw->phy.type) {
	case e1000_phy_82579:
		lpa = I82579_EEE_LP_ABILITY;
		pcs_status = I82579_EEE_PCS_STATUS;
		adv_addr = I82579_EEE_ADVERTISEMENT;
		break;
	case e1000_phy_i217:
		lpa = I217_EEE_LP_ABILITY;
		pcs_status = I217_EEE_PCS_STATUS;
		adv_addr = I217_EEE_ADVERTISEMENT;
		break;
	default:
729
		return 0;
730
	}
731

732
	ret_val = hw->phy.ops.acquire(hw);
733
	if (ret_val)
734
		return ret_val;
735

736
	ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
Bruce Allan's avatar
Bruce Allan committed
737
	if (ret_val)
738
739
740
741
742
743
744
		goto release;

	/* Clear bits that enable EEE in various speeds */
	lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;

	/* Enable EEE if not disabled by user */
	if (!dev_spec->eee_disable) {
Bruce Allan's avatar
Bruce Allan committed
745
		/* Save off link partner's EEE ability */
746
		ret_val = e1000_read_emi_reg_locked(hw, lpa,
747
						    &dev_spec->eee_lp_ability);
Bruce Allan's avatar
Bruce Allan committed
748
749
750
		if (ret_val)
			goto release;

751
752
753
754
755
		/* Read EEE advertisement */
		ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
		if (ret_val)
			goto release;

756
		/* Enable EEE only for speeds in which the link partner is
757
		 * EEE capable and for which we advertise EEE.
Bruce Allan's avatar
Bruce Allan committed
758
		 */
759
		if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
760
761
			lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;

762
		if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
763
764
			e1e_rphy_locked(hw, MII_LPA, &data);
			if (data & LPA_100FULL)
765
766
767
768
769
770
771
772
773
				lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
			else
				/* EEE is not supported in 100Half, so ignore
				 * partner's EEE in 100 ability if full-duplex
				 * is not advertised.
				 */
				dev_spec->eee_lp_ability &=
				    ~I82579_EEE_100_SUPPORTED;
		}
Bruce Allan's avatar
Bruce Allan committed
774
775
	}

776
777
778
779
780
	/* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
	ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
	if (ret_val)
		goto release;

781
782
783
784
785
	ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
release:
	hw->phy.ops.release(hw);

	return ret_val;
786
787
}

788
789
790
791
792
793
794
795
/**
 *  e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
 *  @hw:   pointer to the HW structure
 *  @link: link up bool flag
 *
 *  When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
 *  preventing further DMA write requests.  Workaround the issue by disabling
 *  the de-assertion of the clock request when in 1Gpbs mode.
796
797
 *  Also, set appropriate Tx re-transmission timeouts for 10 and 100Half link
 *  speeds in order to avoid Tx hangs.
798
799
800
801
 **/
static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
{
	u32 fextnvm6 = er32(FEXTNVM6);
802
	u32 status = er32(STATUS);
803
	s32 ret_val = 0;
804
	u16 reg;
805

806
	if (link && (status & E1000_STATUS_SPEED_1000)) {
807
808
809
810
811
812
		ret_val = hw->phy.ops.acquire(hw);
		if (ret_val)
			return ret_val;

		ret_val =
		    e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
813
						&reg);
814
815
816
817
818
819
		if (ret_val)
			goto release;

		ret_val =
		    e1000e_write_kmrn_reg_locked(hw,
						 E1000_KMRNCTRLSTA_K1_CONFIG,
820
						 reg &
821
822
823
824
825
826
827
828
829
830
831
						 ~E1000_KMRNCTRLSTA_K1_ENABLE);
		if (ret_val)
			goto release;

		usleep_range(10, 20);

		ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);

		ret_val =
		    e1000e_write_kmrn_reg_locked(hw,
						 E1000_KMRNCTRLSTA_K1_CONFIG,
832
						 reg);
833
834
835
836
release:
		hw->phy.ops.release(hw);
	} else {
		/* clear FEXTNVM6 bit 8 on link down or 10/100 */
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
		fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;

		if (!link || ((status & E1000_STATUS_SPEED_100) &&
			      (status & E1000_STATUS_FD)))
			goto update_fextnvm6;

		ret_val = e1e_rphy(hw, I217_INBAND_CTRL, &reg);
		if (ret_val)
			return ret_val;

		/* Clear link status transmit timeout */
		reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;

		if (status & E1000_STATUS_SPEED_100) {
			/* Set inband Tx timeout to 5x10us for 100Half */
			reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;

			/* Do not extend the K1 entry latency for 100Half */
			fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
		} else {
			/* Set inband Tx timeout to 50x10us for 10Full/Half */
			reg |= 50 <<
			    I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;

			/* Extend the K1 entry latency for 10 Mbps */
			fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
		}

		ret_val = e1e_wphy(hw, I217_INBAND_CTRL, reg);
		if (ret_val)
			return ret_val;

update_fextnvm6:
		ew32(FEXTNVM6, fextnvm6);
871
872
873
874
875
	}

	return ret_val;
}

876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
/**
 *  e1000_platform_pm_pch_lpt - Set platform power management values
 *  @hw: pointer to the HW structure
 *  @link: bool indicating link status
 *
 *  Set the Latency Tolerance Reporting (LTR) values for the "PCIe-like"
 *  GbE MAC in the Lynx Point PCH based on Rx buffer size and link speed
 *  when link is up (which must not exceed the maximum latency supported
 *  by the platform), otherwise specify there is no LTR requirement.
 *  Unlike true-PCIe devices which set the LTR maximum snoop/no-snoop
 *  latencies in the LTR Extended Capability Structure in the PCIe Extended
 *  Capability register set, on this device LTR is set by writing the
 *  equivalent snoop/no-snoop latencies in the LTRV register in the MAC and
 *  set the SEND bit to send an Intel On-chip System Fabric sideband (IOSF-SB)
 *  message to the PMC.
 **/
static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
{
	u32 reg = link << (E1000_LTRV_REQ_SHIFT + E1000_LTRV_NOSNOOP_SHIFT) |
	    link << E1000_LTRV_REQ_SHIFT | E1000_LTRV_SEND;
	u16 lat_enc = 0;	/* latency encoded */

	if (link) {
		u16 speed, duplex, scale = 0;
		u16 max_snoop, max_nosnoop;
		u16 max_ltr_enc;	/* max LTR latency encoded */
		s64 lat_ns;	/* latency (ns) */
		s64 value;
		u32 rxa;

		if (!hw->adapter->max_frame_size) {
			e_dbg("max_frame_size not set.\n");
			return -E1000_ERR_CONFIG;
		}

		hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
		if (!speed) {
			e_dbg("Speed not set.\n");
			return -E1000_ERR_CONFIG;
		}

		/* Rx Packet Buffer Allocation size (KB) */
		rxa = er32(PBA) & E1000_PBA_RXA_MASK;

		/* Determine the maximum latency tolerated by the device.
		 *
		 * Per the PCIe spec, the tolerated latencies are encoded as
		 * a 3-bit encoded scale (only 0-5 are valid) multiplied by
		 * a 10-bit value (0-1023) to provide a range from 1 ns to
		 * 2^25*(2^10-1) ns.  The scale is encoded as 0=2^0ns,
		 * 1=2^5ns, 2=2^10ns,...5=2^25ns.
		 */
		lat_ns = ((s64)rxa * 1024 -
			  (2 * (s64)hw->adapter->max_frame_size)) * 8 * 1000;
		if (lat_ns < 0)
			lat_ns = 0;
		else
			do_div(lat_ns, speed);

		value = lat_ns;
		while (value > PCI_LTR_VALUE_MASK) {
			scale++;
			value = DIV_ROUND_UP(value, (1 << 5));
		}
		if (scale > E1000_LTRV_SCALE_MAX) {
			e_dbg("Invalid LTR latency scale %d\n", scale);
			return -E1000_ERR_CONFIG;
		}
		lat_enc = (u16)((scale << PCI_LTR_SCALE_SHIFT) | value);

		/* Determine the maximum latency tolerated by the platform */
		pci_read_config_word(hw->adapter->pdev, E1000_PCI_LTR_CAP_LPT,
				     &max_snoop);
		pci_read_config_word(hw->adapter->pdev,
				     E1000_PCI_LTR_CAP_LPT + 2, &max_nosnoop);
		max_ltr_enc = max_t(u16, max_snoop, max_nosnoop);

		if (lat_enc > max_ltr_enc)
			lat_enc = max_ltr_enc;
	}

	/* Set Snoop and No-Snoop latencies the same */
	reg |= lat_enc | (lat_enc << E1000_LTRV_NOSNOOP_SHIFT);
	ew32(LTRV, reg);

	return 0;
}

964
965
966
967
968
969
970
971
972
973
974
975
976
/**
 *  e1000_check_for_copper_link_ich8lan - Check for link (Copper)
 *  @hw: pointer to the HW structure
 *
 *  Checks to see of the link status of the hardware has changed.  If a
 *  change in link status has been detected, then we read the PHY registers
 *  to get the current speed/duplex if link exists.
 **/
static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
{
	struct e1000_mac_info *mac = &hw->mac;
	s32 ret_val;
	bool link;
977
	u16 phy_reg;
978

979
	/* We only want to go out to the PHY registers to see if Auto-Neg
980
981
982
983
	 * has completed and/or if our link status has changed.  The
	 * get_link_status flag is set upon receiving a Link Status
	 * Change or Rx Sequence Error interrupt.
	 */
984
985
	if (!mac->get_link_status)
		return 0;
986

987
	/* First we want to see if the MII Status Register reports
988
989
990
991
992
	 * link.  If so, then we want to get the current speed/duplex
	 * of the PHY.
	 */
	ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
	if (ret_val)
993
		return ret_val;
994

995
996
997
	if (hw->mac.type == e1000_pchlan) {
		ret_val = e1000_k1_gig_workaround_hv(hw, link);
		if (ret_val)
998
			return ret_val;
999
1000
	}

1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
	/* When connected at 10Mbps half-duplex, 82579 parts are excessively
	 * aggressive resulting in many collisions. To avoid this, increase
	 * the IPG and reduce Rx latency in the PHY.
	 */
	if ((hw->mac.type == e1000_pch2lan) && link) {
		u32 reg;
		reg = er32(STATUS);
		if (!(reg & (E1000_STATUS_FD | E1000_STATUS_SPEED_MASK))) {
			reg = er32(TIPG);
			reg &= ~E1000_TIPG_IPGT_MASK;
			reg |= 0xFF;
			ew32(TIPG, reg);

			/* Reduce Rx latency in analog PHY */
			ret_val = hw->phy.ops.acquire(hw);
			if (ret_val)
				return ret_val;

			ret_val =
			    e1000_write_emi_reg_locked(hw, I82579_RX_CONFIG, 0);

			hw->phy.ops.release(hw);

			if (ret_val)
				return ret_val;
		}
	}

1029
1030
	/* Work-around I218 hang issue */
	if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
1031
1032
1033
	    (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
	    (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM3) ||
	    (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3)) {
1034
1035
1036
1037
1038
		ret_val = e1000_k1_workaround_lpt_lp(hw, link);
		if (ret_val)
			return ret_val;
	}

1039
1040
1041
1042
1043
1044
1045
1046
1047
	if (hw->mac.type == e1000_pch_lpt) {
		/* Set platform power management values for
		 * Latency Tolerance Reporting (LTR)
		 */
		ret_val = e1000_platform_pm_pch_lpt(hw, link);
		if (ret_val)
			return ret_val;
	}

Bruce Allan's avatar
Bruce Allan committed
1048
1049
1050
	/* Clear link partner's EEE ability */
	hw->dev_spec.ich8lan.eee_lp_ability = 0;

1051
	if (!link)
Bruce Allan's avatar
Bruce Allan committed
1052
		return 0;	/* No link detected */
1053
1054
1055

	mac->get_link_status = false;

1056
1057
	switch (hw->mac.type) {
	case e1000_pch2lan:
1058
1059
		ret_val = e1000_k1_workaround_lv(hw);
		if (ret_val)
1060
			return ret_val;
1061
1062
1063
1064
1065
		/* fall-thru */
	case e1000_pchlan:
		if (hw->phy.type == e1000_phy_82578) {
			ret_val = e1000_link_stall_workaround_hv(hw);
			if (ret_val)
1066
				return ret_val;
1067
1068
		}

1069
		/* Workaround for PCHx parts in half-duplex:
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
		 * Set the number of preambles removed from the packet
		 * when it is passed from the PHY to the MAC to prevent
		 * the MAC from misinterpreting the packet type.
		 */
		e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
		phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;

		if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
			phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);

		e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
		break;
	default:
		break;
1084
1085
	}

1086
	/* Check if there was DownShift, must be checked
1087
1088
1089
1090
	 * immediately after link-up
	 */
	e1000e_check_downshift(hw);

1091
1092
1093
	/* Enable/Disable EEE after link up */
	ret_val = e1000_set_eee_pchlan(hw);
	if (ret_val)
1094
		return ret_val;
1095

1096
	/* If we are forcing speed/duplex, then we simply return since
1097
1098
	 * we have already determined whether we have link or not.
	 */
1099
1100
	if (!mac->autoneg)
		return -E1000_ERR_CONFIG;
1101

1102
	/* Auto-Neg is enabled.  Auto Speed Detection takes care
1103
1104
1105
	 * of MAC speed/duplex configuration.  So we only need to
	 * configure Collision Distance in the MAC.
	 */
1106
	mac->ops.config_collision_dist(hw);
1107

1108
	/* Configure Flow Control now that Auto-Neg has completed.
1109
1110
1111
1112
1113
1114
	 * First, we need to restore the desired flow control
	 * settings because we may have had to re-autoneg with a
	 * different link partner.
	 */
	ret_val = e1000e_config_fc_after_link_up(hw);
	if (ret_val)
1115
		e_dbg("Error configuring flow control\n");
1116
1117
1118
1119

	return ret_val;
}

Jeff Kirsher's avatar
Jeff Kirsher committed
1120
static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
1121
1122
1123
1124
{
	struct e1000_hw *hw = &adapter->hw;
	s32 rc;

1125
	rc = e1000_init_mac_params_ich8lan(hw);
1126
1127
1128
1129
1130
1131
1132
	if (rc)
		return rc;

	rc = e1000_init_nvm_params_ich8lan(hw);
	if (rc)
		return rc;

1133
1134
1135
1136
	switch (hw->mac.type) {
	case e1000_ich8lan:
	case e1000_ich9lan:
	case e1000_ich10lan:
1137
		rc = e1000_init_phy_params_ich8lan(hw);
1138
1139
1140
		break;
	case e1000_pchlan:
	case e1000_pch2lan:
Bruce Allan's avatar
Bruce Allan committed
1141
	case e1000_pch_lpt:
1142
1143
1144
1145
1146
		rc = e1000_init_phy_params_pchlan(hw);
		break;
	default:
		break;
	}
1147
1148
1149
	if (rc)
		return rc;

1150
	/* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
1151
1152
1153
1154
1155
	 * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
	 */
	if ((adapter->hw.phy.type == e1000_phy_ife) ||
	    ((adapter->hw.mac.type >= e1000_pch2lan) &&
	     (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
1156
1157
		adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
		adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
1158
1159

		hw->mac.ops.blink_led = NULL;
1160
1161
	}

1162
	if ((adapter->hw.mac.type == e1000_ich8lan) &&
1163
	    (adapter->hw.phy.type != e1000_phy_ife))
1164
1165
		adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;

1166
1167
1168
1169
1170
	/* Enable workaround for 82579 w/ ME enabled */
	if ((adapter->hw.mac.type == e1000_pch2lan) &&
	    (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
		adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;

1171
1172
1173
	return 0;
}

1174
1175
static DEFINE_MUTEX(nvm_mutex);

1176
1177
1178
1179
1180
1181
/**
 *  e1000_acquire_nvm_ich8lan - Acquire NVM mutex
 *  @hw: pointer to the HW structure
 *
 *  Acquires the mutex for performing NVM operations.
 **/
1182
static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
{
	mutex_lock(&nvm_mutex);

	return 0;
}

/**
 *  e1000_release_nvm_ich8lan - Release NVM mutex
 *  @hw: pointer to the HW structure
 *
 *  Releases the mutex used while performing NVM operations.
 **/
1195
static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
1196
1197
1198
1199
{
	mutex_unlock(&nvm_mutex);
}

1200
1201
1202
1203
/**
 *  e1000_acquire_swflag_ich8lan - Acquire software control flag
 *  @hw: pointer to the HW structure
 *
1204
1205
 *  Acquires the software control flag for performing PHY and select
 *  MAC CSR accesses.
1206
1207
1208
 **/
static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
{
1209
1210
	u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
	s32 ret_val = 0;
1211

1212
1213
	if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
			     &hw->adapter->state)) {
1214
		e_dbg("contention for Phy access\n");
1215
1216
		return -E1000_ERR_PHY;
	}
1217

1218
1219
	while (timeout) {
		extcnf_ctrl = er32(EXTCNF_CTRL);
1220
1221
		if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
			break;
1222

1223
1224
1225
1226
1227
		mdelay(1);
		timeout--;
	}

	if (!timeout) {
1228
		e_dbg("SW has already locked the resource.\n");
1229
1230
1231
1232
		ret_val = -E1000_ERR_CONFIG;
		goto out;
	}

1233
	timeout = SW_FLAG_TIMEOUT;
1234
1235
1236
1237
1238
1239
1240
1241

	extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
	ew32(EXTCNF_CTRL, extcnf_ctrl);

	while (timeout) {
		extcnf_ctrl = er32(EXTCNF_CTRL);
		if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
			break;
1242

1243
1244
1245
1246
1247
		mdelay(1);
		timeout--;
	}

	if (!timeout) {
1248
		e_dbg("Failed to acquire the semaphore, FW or HW has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
1249
		      er32(FWSM), extcnf_ctrl);
1250
1251
		extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
		ew32(EXTCNF_CTRL, extcnf_ctrl);
1252
1253
		ret_val = -E1000_ERR_CONFIG;
		goto out;
1254
1255
	}

1256
1257
out:
	if (ret_val)
1258
		clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
1259
1260

	return ret_val;
1261
1262
1263
1264
1265
1266
}

/**
 *  e1000_release_swflag_ich8lan - Release software control flag
 *  @hw: pointer to the HW structure
 *
1267
1268
 *  Releases the software control flag for performing PHY and select
 *  MAC CSR accesses.
1269
1270
1271
1272
1273
1274
 **/
static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
{
	u32 extcnf_ctrl;

	extcnf_ctrl = er32(EXTCNF_CTRL);
1275
1276
1277
1278
1279
1280
1281

	if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
		extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
		ew32(EXTCNF_CTRL, extcnf_ctrl);
	} else {
		e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
	}
1282

1283
	clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
1284
1285
}

1286
1287
1288
1289
/**
 *  e1000_check_mng_mode_ich8lan - Checks management mode
 *  @hw: pointer to the HW structure
 *
1290
 *  This checks if the adapter has any manageability enabled.
1291
1292
1293
1294
1295
 *  This is a function pointer entry point only called by read/write
 *  routines for the PHY and NVM parts.
 **/
static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
{
1296
1297
1298
	u32 fwsm;

	fwsm = er32(FWSM);
1299
1300
1301
	return ((fwsm & E1000_ICH_FWSM_FW_VALID) &&
		((fwsm & E1000_FWSM_MODE_MASK) ==
		 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT)));
1302
}
1303

1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
/**
 *  e1000_check_mng_mode_pchlan - Checks management mode
 *  @hw: pointer to the HW structure
 *
 *  This checks if the adapter has iAMT enabled.
 *  This is a function pointer entry point only called by read/write
 *  routines for the PHY and NVM parts.
 **/
static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
{
	u32 fwsm;

	fwsm = er32(FWSM);
	return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
1318
	    (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
1319
1320
}

1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
/**
 *  e1000_rar_set_pch2lan - Set receive address register
 *  @hw: pointer to the HW structure
 *  @addr: pointer to the receive address
 *  @index: receive address array register
 *
 *  Sets the receive address array register at index to the address passed
 *  in by addr.  For 82579, RAR[0] is the base address register that is to
 *  contain the MAC address but RAR[1-6] are reserved for manageability (ME).
 *  Use SHRA[0-3] in place of those reserved for ME.
 **/
static void e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
{
	u32 rar_low, rar_high;

1336
	/* HW expects these in little endian so we reverse the byte order
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
	 * from network order (big endian) to little endian
	 */
	rar_low = ((u32)addr[0] |
		   ((u32)addr[1] << 8) |
		   ((u32)addr[2] << 16) | ((u32)addr[3] << 24));

	rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));

	/* If MAC address zero, no need to set the AV bit */
	if (rar_low || rar_high)
		rar_high |= E1000_RAH_AV;

	if (index == 0) {
		ew32(RAL(index), rar_low);
		e1e_flush();
		ew32(RAH(index), rar_high);
		e1e_flush();
		return;
	}

	if (index < hw->mac.rar_entry_count) {
		s32 ret_val;

		ret_val = e1000_acquire_swflag_ich8lan(hw);
		if (ret_val)
			goto out;

		ew32(SHRAL(index - 1), rar_low);
		e1e_flush();
		ew32(SHRAH(index - 1), rar_high);
		e1e_flush();

		e1000_release_swflag_ich8lan(hw);

		/* verify the register updates */
		if ((er32(SHRAL(index - 1)) == rar_low) &&
		    (er32(SHRAH(index - 1)) == rar_high))
			return;

		e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
		      (index - 1), er32(FWSM));
	}

out:
	e_dbg("Failed to write receive address at index %d\n", index);
}

Bruce Allan's avatar
Bruce Allan committed
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
/**
 *  e1000_rar_set_pch_lpt - Set receive address registers
 *  @hw: pointer to the HW structure
 *  @addr: pointer to the receive address
 *  @index: receive address array register
 *