1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#include <common.h>
33#include <cpu_func.h>
34#include <dm.h>
35#include <errno.h>
36#include <memalign.h>
37#include <pci.h>
38#include "e1000.h"
39
40#define TOUT_LOOP 100000
41
42#ifdef CONFIG_DM_ETH
43#define virt_to_bus(devno, v) dm_pci_virt_to_mem(devno, (void *) (v))
44#define bus_to_phys(devno, a) dm_pci_mem_to_phys(devno, a)
45#else
46#define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v))
47#define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
48#endif
49
50#define E1000_DEFAULT_PCI_PBA 0x00000030
51#define E1000_DEFAULT_PCIE_PBA 0x000a0026
52
53
54
55
56#define E1000_BUFFER_ALIGN 128
57
58
59
60
61
62
63
64DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN);
65DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN);
66DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN);
67
68static int tx_tail;
69static int rx_tail, rx_last;
70#ifdef CONFIG_DM_ETH
71static int num_cards;
72#endif
73
74static struct pci_device_id e1000_supported[] = {
75 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542) },
76 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER) },
77 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER) },
78 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER) },
79 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER) },
80 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER) },
81 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM) },
82 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM) },
83 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER) },
84 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER) },
85 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER) },
86 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER) },
87 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER) },
88 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER) },
89 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM) },
90 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER) },
91 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF) },
92
93 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER) },
94 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER) },
95 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES) },
96 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER) },
97 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER) },
98 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER) },
99 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE) },
100 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL) },
101 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD) },
102 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER) },
103 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER) },
104 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES) },
105 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI) },
106 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E) },
107 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT) },
108 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L) },
109 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L) },
110 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3) },
111 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT) },
112 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT) },
113 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT) },
114 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT) },
115 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED) },
116 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED) },
117 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER) },
118 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_COPPER) },
119 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS) },
120 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES) },
121 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS) },
122 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_1000BASEKX) },
123
124 {}
125};
126
127
128static int e1000_setup_link(struct e1000_hw *hw);
129static int e1000_setup_fiber_link(struct e1000_hw *hw);
130static int e1000_setup_copper_link(struct e1000_hw *hw);
131static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
132static void e1000_config_collision_dist(struct e1000_hw *hw);
133static int e1000_config_mac_to_phy(struct e1000_hw *hw);
134static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
135static int e1000_check_for_link(struct e1000_hw *hw);
136static int e1000_wait_autoneg(struct e1000_hw *hw);
137static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
138 uint16_t * duplex);
139static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
140 uint16_t * phy_data);
141static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
142 uint16_t phy_data);
143static int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
144static int e1000_phy_reset(struct e1000_hw *hw);
145static int e1000_detect_gig_phy(struct e1000_hw *hw);
146static void e1000_set_media_type(struct e1000_hw *hw);
147
148static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
149static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
150static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
151
152#ifndef CONFIG_E1000_NO_NVM
153static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
154static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
155static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
156 uint16_t words,
157 uint16_t *data);
158
159
160
161
162
163
164void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
165{
166
167
168
169 *eecd = *eecd | E1000_EECD_SK;
170 E1000_WRITE_REG(hw, EECD, *eecd);
171 E1000_WRITE_FLUSH(hw);
172 udelay(50);
173}
174
175
176
177
178
179
180
181void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
182{
183
184
185
186 *eecd = *eecd & ~E1000_EECD_SK;
187 E1000_WRITE_REG(hw, EECD, *eecd);
188 E1000_WRITE_FLUSH(hw);
189 udelay(50);
190}
191
192
193
194
195
196
197
198
199static void
200e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
201{
202 uint32_t eecd;
203 uint32_t mask;
204
205
206
207
208
209 mask = 0x01 << (count - 1);
210 eecd = E1000_READ_REG(hw, EECD);
211 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
212 do {
213
214
215
216
217
218 eecd &= ~E1000_EECD_DI;
219
220 if (data & mask)
221 eecd |= E1000_EECD_DI;
222
223 E1000_WRITE_REG(hw, EECD, eecd);
224 E1000_WRITE_FLUSH(hw);
225
226 udelay(50);
227
228 e1000_raise_ee_clk(hw, &eecd);
229 e1000_lower_ee_clk(hw, &eecd);
230
231 mask = mask >> 1;
232
233 } while (mask);
234
235
236 eecd &= ~E1000_EECD_DI;
237 E1000_WRITE_REG(hw, EECD, eecd);
238}
239
240
241
242
243
244
245static uint16_t
246e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count)
247{
248 uint32_t eecd;
249 uint32_t i;
250 uint16_t data;
251
252
253
254
255
256
257
258
259 eecd = E1000_READ_REG(hw, EECD);
260
261 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
262 data = 0;
263
264 for (i = 0; i < count; i++) {
265 data = data << 1;
266 e1000_raise_ee_clk(hw, &eecd);
267
268 eecd = E1000_READ_REG(hw, EECD);
269
270 eecd &= ~(E1000_EECD_DI);
271 if (eecd & E1000_EECD_DO)
272 data |= 1;
273
274 e1000_lower_ee_clk(hw, &eecd);
275 }
276
277 return data;
278}
279
280
281
282
283
284
285void e1000_standby_eeprom(struct e1000_hw *hw)
286{
287 struct e1000_eeprom_info *eeprom = &hw->eeprom;
288 uint32_t eecd;
289
290 eecd = E1000_READ_REG(hw, EECD);
291
292 if (eeprom->type == e1000_eeprom_microwire) {
293 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
294 E1000_WRITE_REG(hw, EECD, eecd);
295 E1000_WRITE_FLUSH(hw);
296 udelay(eeprom->delay_usec);
297
298
299 eecd |= E1000_EECD_SK;
300 E1000_WRITE_REG(hw, EECD, eecd);
301 E1000_WRITE_FLUSH(hw);
302 udelay(eeprom->delay_usec);
303
304
305 eecd |= E1000_EECD_CS;
306 E1000_WRITE_REG(hw, EECD, eecd);
307 E1000_WRITE_FLUSH(hw);
308 udelay(eeprom->delay_usec);
309
310
311 eecd &= ~E1000_EECD_SK;
312 E1000_WRITE_REG(hw, EECD, eecd);
313 E1000_WRITE_FLUSH(hw);
314 udelay(eeprom->delay_usec);
315 } else if (eeprom->type == e1000_eeprom_spi) {
316
317 eecd |= E1000_EECD_CS;
318 E1000_WRITE_REG(hw, EECD, eecd);
319 E1000_WRITE_FLUSH(hw);
320 udelay(eeprom->delay_usec);
321 eecd &= ~E1000_EECD_CS;
322 E1000_WRITE_REG(hw, EECD, eecd);
323 E1000_WRITE_FLUSH(hw);
324 udelay(eeprom->delay_usec);
325 }
326}
327
328
329
330
331
332
333static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
334{
335 uint32_t eecd = 0;
336
337 DEBUGFUNC();
338
339 if (hw->mac_type == e1000_ich8lan)
340 return false;
341
342 if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) {
343 eecd = E1000_READ_REG(hw, EECD);
344
345
346 eecd = ((eecd >> 15) & 0x03);
347
348
349 if (eecd == 0x03)
350 return false;
351 }
352 return true;
353}
354
355
356
357
358
359
360
361
362
363int32_t e1000_acquire_eeprom(struct e1000_hw *hw)
364{
365 struct e1000_eeprom_info *eeprom = &hw->eeprom;
366 uint32_t eecd, i = 0;
367
368 DEBUGFUNC();
369
370 if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
371 return -E1000_ERR_SWFW_SYNC;
372 eecd = E1000_READ_REG(hw, EECD);
373
374 if (hw->mac_type != e1000_82573 && hw->mac_type != e1000_82574) {
375
376 if (hw->mac_type > e1000_82544) {
377 eecd |= E1000_EECD_REQ;
378 E1000_WRITE_REG(hw, EECD, eecd);
379 eecd = E1000_READ_REG(hw, EECD);
380 while ((!(eecd & E1000_EECD_GNT)) &&
381 (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
382 i++;
383 udelay(5);
384 eecd = E1000_READ_REG(hw, EECD);
385 }
386 if (!(eecd & E1000_EECD_GNT)) {
387 eecd &= ~E1000_EECD_REQ;
388 E1000_WRITE_REG(hw, EECD, eecd);
389 DEBUGOUT("Could not acquire EEPROM grant\n");
390 return -E1000_ERR_EEPROM;
391 }
392 }
393 }
394
395
396
397 if (eeprom->type == e1000_eeprom_microwire) {
398
399 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
400 E1000_WRITE_REG(hw, EECD, eecd);
401
402
403 eecd |= E1000_EECD_CS;
404 E1000_WRITE_REG(hw, EECD, eecd);
405 } else if (eeprom->type == e1000_eeprom_spi) {
406
407 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
408 E1000_WRITE_REG(hw, EECD, eecd);
409 udelay(1);
410 }
411
412 return E1000_SUCCESS;
413}
414
415
416
417
418
419
420
421
422static int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
423{
424 struct e1000_eeprom_info *eeprom = &hw->eeprom;
425 uint32_t eecd;
426 int32_t ret_val = E1000_SUCCESS;
427 uint16_t eeprom_size;
428
429 if (hw->mac_type == e1000_igb)
430 eecd = E1000_READ_REG(hw, I210_EECD);
431 else
432 eecd = E1000_READ_REG(hw, EECD);
433
434 DEBUGFUNC();
435
436 switch (hw->mac_type) {
437 case e1000_82542_rev2_0:
438 case e1000_82542_rev2_1:
439 case e1000_82543:
440 case e1000_82544:
441 eeprom->type = e1000_eeprom_microwire;
442 eeprom->word_size = 64;
443 eeprom->opcode_bits = 3;
444 eeprom->address_bits = 6;
445 eeprom->delay_usec = 50;
446 eeprom->use_eerd = false;
447 eeprom->use_eewr = false;
448 break;
449 case e1000_82540:
450 case e1000_82545:
451 case e1000_82545_rev_3:
452 case e1000_82546:
453 case e1000_82546_rev_3:
454 eeprom->type = e1000_eeprom_microwire;
455 eeprom->opcode_bits = 3;
456 eeprom->delay_usec = 50;
457 if (eecd & E1000_EECD_SIZE) {
458 eeprom->word_size = 256;
459 eeprom->address_bits = 8;
460 } else {
461 eeprom->word_size = 64;
462 eeprom->address_bits = 6;
463 }
464 eeprom->use_eerd = false;
465 eeprom->use_eewr = false;
466 break;
467 case e1000_82541:
468 case e1000_82541_rev_2:
469 case e1000_82547:
470 case e1000_82547_rev_2:
471 if (eecd & E1000_EECD_TYPE) {
472 eeprom->type = e1000_eeprom_spi;
473 eeprom->opcode_bits = 8;
474 eeprom->delay_usec = 1;
475 if (eecd & E1000_EECD_ADDR_BITS) {
476 eeprom->page_size = 32;
477 eeprom->address_bits = 16;
478 } else {
479 eeprom->page_size = 8;
480 eeprom->address_bits = 8;
481 }
482 } else {
483 eeprom->type = e1000_eeprom_microwire;
484 eeprom->opcode_bits = 3;
485 eeprom->delay_usec = 50;
486 if (eecd & E1000_EECD_ADDR_BITS) {
487 eeprom->word_size = 256;
488 eeprom->address_bits = 8;
489 } else {
490 eeprom->word_size = 64;
491 eeprom->address_bits = 6;
492 }
493 }
494 eeprom->use_eerd = false;
495 eeprom->use_eewr = false;
496 break;
497 case e1000_82571:
498 case e1000_82572:
499 eeprom->type = e1000_eeprom_spi;
500 eeprom->opcode_bits = 8;
501 eeprom->delay_usec = 1;
502 if (eecd & E1000_EECD_ADDR_BITS) {
503 eeprom->page_size = 32;
504 eeprom->address_bits = 16;
505 } else {
506 eeprom->page_size = 8;
507 eeprom->address_bits = 8;
508 }
509 eeprom->use_eerd = false;
510 eeprom->use_eewr = false;
511 break;
512 case e1000_82573:
513 case e1000_82574:
514 eeprom->type = e1000_eeprom_spi;
515 eeprom->opcode_bits = 8;
516 eeprom->delay_usec = 1;
517 if (eecd & E1000_EECD_ADDR_BITS) {
518 eeprom->page_size = 32;
519 eeprom->address_bits = 16;
520 } else {
521 eeprom->page_size = 8;
522 eeprom->address_bits = 8;
523 }
524 if (e1000_is_onboard_nvm_eeprom(hw) == false) {
525 eeprom->use_eerd = true;
526 eeprom->use_eewr = true;
527
528 eeprom->type = e1000_eeprom_flash;
529 eeprom->word_size = 2048;
530
531
532
533 eecd &= ~E1000_EECD_AUPDEN;
534 E1000_WRITE_REG(hw, EECD, eecd);
535 }
536 break;
537 case e1000_80003es2lan:
538 eeprom->type = e1000_eeprom_spi;
539 eeprom->opcode_bits = 8;
540 eeprom->delay_usec = 1;
541 if (eecd & E1000_EECD_ADDR_BITS) {
542 eeprom->page_size = 32;
543 eeprom->address_bits = 16;
544 } else {
545 eeprom->page_size = 8;
546 eeprom->address_bits = 8;
547 }
548 eeprom->use_eerd = true;
549 eeprom->use_eewr = false;
550 break;
551 case e1000_igb:
552
553 eeprom->type = e1000_eeprom_invm;
554 eeprom->opcode_bits = 8;
555 eeprom->delay_usec = 1;
556 eeprom->page_size = 32;
557 eeprom->address_bits = 16;
558 eeprom->use_eerd = true;
559 eeprom->use_eewr = false;
560 break;
561 default:
562 break;
563 }
564
565 if (eeprom->type == e1000_eeprom_spi ||
566 eeprom->type == e1000_eeprom_invm) {
567
568
569
570
571 if (hw->mac_type <= e1000_82547_rev_2) {
572
573 eeprom->word_size = 64;
574 ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1,
575 &eeprom_size);
576 if (ret_val)
577 return ret_val;
578 eeprom_size = (eeprom_size & EEPROM_SIZE_MASK)
579 >> EEPROM_SIZE_SHIFT;
580
581
582
583
584 if (eeprom_size)
585 eeprom_size++;
586 } else {
587 eeprom_size = (uint16_t)((eecd &
588 E1000_EECD_SIZE_EX_MASK) >>
589 E1000_EECD_SIZE_EX_SHIFT);
590 }
591
592 eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
593 }
594 return ret_val;
595}
596
597
598
599
600
601
602static int32_t
603e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
604{
605 uint32_t attempts = 100000;
606 uint32_t i, reg = 0;
607 int32_t done = E1000_ERR_EEPROM;
608
609 for (i = 0; i < attempts; i++) {
610 if (eerd == E1000_EEPROM_POLL_READ) {
611 if (hw->mac_type == e1000_igb)
612 reg = E1000_READ_REG(hw, I210_EERD);
613 else
614 reg = E1000_READ_REG(hw, EERD);
615 } else {
616 if (hw->mac_type == e1000_igb)
617 reg = E1000_READ_REG(hw, I210_EEWR);
618 else
619 reg = E1000_READ_REG(hw, EEWR);
620 }
621
622 if (reg & E1000_EEPROM_RW_REG_DONE) {
623 done = E1000_SUCCESS;
624 break;
625 }
626 udelay(5);
627 }
628
629 return done;
630}
631
632
633
634
635
636
637
638
639
640static int32_t
641e1000_read_eeprom_eerd(struct e1000_hw *hw,
642 uint16_t offset,
643 uint16_t words,
644 uint16_t *data)
645{
646 uint32_t i, eerd = 0;
647 int32_t error = 0;
648
649 for (i = 0; i < words; i++) {
650 eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
651 E1000_EEPROM_RW_REG_START;
652
653 if (hw->mac_type == e1000_igb)
654 E1000_WRITE_REG(hw, I210_EERD, eerd);
655 else
656 E1000_WRITE_REG(hw, EERD, eerd);
657
658 error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
659
660 if (error)
661 break;
662
663 if (hw->mac_type == e1000_igb) {
664 data[i] = (E1000_READ_REG(hw, I210_EERD) >>
665 E1000_EEPROM_RW_REG_DATA);
666 } else {
667 data[i] = (E1000_READ_REG(hw, EERD) >>
668 E1000_EEPROM_RW_REG_DATA);
669 }
670
671 }
672
673 return error;
674}
675
676void e1000_release_eeprom(struct e1000_hw *hw)
677{
678 uint32_t eecd;
679
680 DEBUGFUNC();
681
682 eecd = E1000_READ_REG(hw, EECD);
683
684 if (hw->eeprom.type == e1000_eeprom_spi) {
685 eecd |= E1000_EECD_CS;
686 eecd &= ~E1000_EECD_SK;
687
688 E1000_WRITE_REG(hw, EECD, eecd);
689
690 udelay(hw->eeprom.delay_usec);
691 } else if (hw->eeprom.type == e1000_eeprom_microwire) {
692
693
694
695 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
696
697 E1000_WRITE_REG(hw, EECD, eecd);
698
699
700 eecd |= E1000_EECD_SK;
701 E1000_WRITE_REG(hw, EECD, eecd);
702 E1000_WRITE_FLUSH(hw);
703 udelay(hw->eeprom.delay_usec);
704
705
706 eecd &= ~E1000_EECD_SK;
707 E1000_WRITE_REG(hw, EECD, eecd);
708 E1000_WRITE_FLUSH(hw);
709 udelay(hw->eeprom.delay_usec);
710 }
711
712
713 if (hw->mac_type > e1000_82544) {
714 eecd &= ~E1000_EECD_REQ;
715 E1000_WRITE_REG(hw, EECD, eecd);
716 }
717
718 e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
719}
720
721
722
723
724
725
726static int32_t
727e1000_spi_eeprom_ready(struct e1000_hw *hw)
728{
729 uint16_t retry_count = 0;
730 uint8_t spi_stat_reg;
731
732 DEBUGFUNC();
733
734
735
736
737
738
739 retry_count = 0;
740 do {
741 e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
742 hw->eeprom.opcode_bits);
743 spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
744 if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
745 break;
746
747 udelay(5);
748 retry_count += 5;
749
750 e1000_standby_eeprom(hw);
751 } while (retry_count < EEPROM_MAX_RETRY_SPI);
752
753
754
755
756 if (retry_count >= EEPROM_MAX_RETRY_SPI) {
757 DEBUGOUT("SPI EEPROM Status error\n");
758 return -E1000_ERR_EEPROM;
759 }
760
761 return E1000_SUCCESS;
762}
763
764
765
766
767
768
769
770
771static int32_t
772e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
773 uint16_t words, uint16_t *data)
774{
775 struct e1000_eeprom_info *eeprom = &hw->eeprom;
776 uint32_t i = 0;
777
778 DEBUGFUNC();
779
780
781 if (eeprom->word_size == 0)
782 e1000_init_eeprom_params(hw);
783
784
785
786
787 if ((offset >= eeprom->word_size) ||
788 (words > eeprom->word_size - offset) ||
789 (words == 0)) {
790 DEBUGOUT("\"words\" parameter out of bounds."
791 "Words = %d, size = %d\n", offset, eeprom->word_size);
792 return -E1000_ERR_EEPROM;
793 }
794
795
796
797
798
799 if (e1000_is_onboard_nvm_eeprom(hw) == true &&
800 hw->eeprom.use_eerd == false) {
801
802
803 if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
804 return -E1000_ERR_EEPROM;
805 }
806
807
808 if (eeprom->use_eerd == true)
809 return e1000_read_eeprom_eerd(hw, offset, words, data);
810
811
812
813 if (eeprom->type == e1000_eeprom_spi) {
814 uint16_t word_in;
815 uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
816
817 if (e1000_spi_eeprom_ready(hw)) {
818 e1000_release_eeprom(hw);
819 return -E1000_ERR_EEPROM;
820 }
821
822 e1000_standby_eeprom(hw);
823
824
825
826 if ((eeprom->address_bits == 8) && (offset >= 128))
827 read_opcode |= EEPROM_A8_OPCODE_SPI;
828
829
830 e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
831 e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2),
832 eeprom->address_bits);
833
834
835
836
837
838
839
840 for (i = 0; i < words; i++) {
841 word_in = e1000_shift_in_ee_bits(hw, 16);
842 data[i] = (word_in >> 8) | (word_in << 8);
843 }
844 } else if (eeprom->type == e1000_eeprom_microwire) {
845 for (i = 0; i < words; i++) {
846
847 e1000_shift_out_ee_bits(hw,
848 EEPROM_READ_OPCODE_MICROWIRE,
849 eeprom->opcode_bits);
850 e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
851 eeprom->address_bits);
852
853
854
855 data[i] = e1000_shift_in_ee_bits(hw, 16);
856 e1000_standby_eeprom(hw);
857 }
858 }
859
860
861 e1000_release_eeprom(hw);
862
863 return E1000_SUCCESS;
864}
865
866#ifndef CONFIG_DM_ETH
867
868
869
870
871
872
873
874
875
876
877
878
879static int32_t e1000_write_eeprom_srwr(struct e1000_hw *hw, uint16_t offset,
880 uint16_t words, uint16_t *data)
881{
882 struct e1000_eeprom_info *eeprom = &hw->eeprom;
883 uint32_t i, k, eewr = 0;
884 uint32_t attempts = 100000;
885 int32_t ret_val = 0;
886
887
888
889
890 if ((offset >= eeprom->word_size) ||
891 (words > (eeprom->word_size - offset)) || (words == 0)) {
892 DEBUGOUT("nvm parameter(s) out of bounds\n");
893 ret_val = -E1000_ERR_EEPROM;
894 goto out;
895 }
896
897 for (i = 0; i < words; i++) {
898 eewr = ((offset + i) << E1000_EEPROM_RW_ADDR_SHIFT)
899 | (data[i] << E1000_EEPROM_RW_REG_DATA) |
900 E1000_EEPROM_RW_REG_START;
901
902 E1000_WRITE_REG(hw, I210_EEWR, eewr);
903
904 for (k = 0; k < attempts; k++) {
905 if (E1000_EEPROM_RW_REG_DONE &
906 E1000_READ_REG(hw, I210_EEWR)) {
907 ret_val = 0;
908 break;
909 }
910 udelay(5);
911 }
912
913 if (ret_val) {
914 DEBUGOUT("Shadow RAM write EEWR timed out\n");
915 break;
916 }
917 }
918
919out:
920 return ret_val;
921}
922
923
924
925
926
927
928static int32_t e1000_pool_flash_update_done_i210(struct e1000_hw *hw)
929{
930 int32_t ret_val = -E1000_ERR_EEPROM;
931 uint32_t i, reg;
932
933 for (i = 0; i < E1000_FLUDONE_ATTEMPTS; i++) {
934 reg = E1000_READ_REG(hw, EECD);
935 if (reg & E1000_EECD_FLUDONE_I210) {
936 ret_val = 0;
937 break;
938 }
939 udelay(5);
940 }
941
942 return ret_val;
943}
944
945
946
947
948
949
950static int32_t e1000_update_flash_i210(struct e1000_hw *hw)
951{
952 int32_t ret_val = 0;
953 uint32_t flup;
954
955 ret_val = e1000_pool_flash_update_done_i210(hw);
956 if (ret_val == -E1000_ERR_EEPROM) {
957 DEBUGOUT("Flash update time out\n");
958 goto out;
959 }
960
961 flup = E1000_READ_REG(hw, EECD) | E1000_EECD_FLUPD_I210;
962 E1000_WRITE_REG(hw, EECD, flup);
963
964 ret_val = e1000_pool_flash_update_done_i210(hw);
965 if (ret_val)
966 DEBUGOUT("Flash update time out\n");
967 else
968 DEBUGOUT("Flash update complete\n");
969
970out:
971 return ret_val;
972}
973
974
975
976
977
978
979
980
981
982static int32_t e1000_update_eeprom_checksum_i210(struct e1000_hw *hw)
983{
984 int32_t ret_val = 0;
985 uint16_t checksum = 0;
986 uint16_t i, nvm_data;
987
988
989
990
991
992 ret_val = e1000_read_eeprom_eerd(hw, 0, 1, &nvm_data);
993 if (ret_val) {
994 DEBUGOUT("EEPROM read failed\n");
995 goto out;
996 }
997
998 if (!(e1000_get_hw_eeprom_semaphore(hw))) {
999
1000
1001
1002
1003
1004 for (i = 0; i < EEPROM_CHECKSUM_REG; i++) {
1005 ret_val = e1000_read_eeprom_eerd(hw, i, 1, &nvm_data);
1006 if (ret_val) {
1007 e1000_put_hw_eeprom_semaphore(hw);
1008 DEBUGOUT("EEPROM Read Error while updating checksum.\n");
1009 goto out;
1010 }
1011 checksum += nvm_data;
1012 }
1013 checksum = (uint16_t)EEPROM_SUM - checksum;
1014 ret_val = e1000_write_eeprom_srwr(hw, EEPROM_CHECKSUM_REG, 1,
1015 &checksum);
1016 if (ret_val) {
1017 e1000_put_hw_eeprom_semaphore(hw);
1018 DEBUGOUT("EEPROM Write Error while updating checksum.\n");
1019 goto out;
1020 }
1021
1022 e1000_put_hw_eeprom_semaphore(hw);
1023
1024 ret_val = e1000_update_flash_i210(hw);
1025 } else {
1026 ret_val = -E1000_ERR_SWFW_SYNC;
1027 }
1028
1029out:
1030 return ret_val;
1031}
1032#endif
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043static int e1000_validate_eeprom_checksum(struct e1000_hw *hw)
1044{
1045 uint16_t i, checksum, checksum_reg, *buf;
1046
1047 DEBUGFUNC();
1048
1049
1050 buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1));
1051 if (!buf) {
1052 E1000_ERR(hw, "Unable to allocate EEPROM buffer!\n");
1053 return -E1000_ERR_EEPROM;
1054 }
1055
1056
1057 if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) {
1058 E1000_ERR(hw, "Unable to read EEPROM!\n");
1059 return -E1000_ERR_EEPROM;
1060 }
1061
1062
1063 checksum = 0;
1064 for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
1065 checksum += buf[i];
1066 checksum = ((uint16_t)EEPROM_SUM) - checksum;
1067 checksum_reg = buf[i];
1068
1069
1070 if (checksum == checksum_reg)
1071 return 0;
1072
1073
1074 E1000_ERR(hw, "EEPROM checksum is incorrect!\n");
1075 E1000_ERR(hw, " ...register was 0x%04hx, calculated 0x%04hx\n",
1076 checksum_reg, checksum);
1077
1078 return -E1000_ERR_EEPROM;
1079}
1080#endif
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090static int32_t
1091e1000_set_phy_mode(struct e1000_hw *hw)
1092{
1093#ifndef CONFIG_E1000_NO_NVM
1094 int32_t ret_val;
1095 uint16_t eeprom_data;
1096
1097 DEBUGFUNC();
1098
1099 if ((hw->mac_type == e1000_82545_rev_3) &&
1100 (hw->media_type == e1000_media_type_copper)) {
1101 ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD,
1102 1, &eeprom_data);
1103 if (ret_val)
1104 return ret_val;
1105
1106 if ((eeprom_data != EEPROM_RESERVED_WORD) &&
1107 (eeprom_data & EEPROM_PHY_CLASS_A)) {
1108 ret_val = e1000_write_phy_reg(hw,
1109 M88E1000_PHY_PAGE_SELECT, 0x000B);
1110 if (ret_val)
1111 return ret_val;
1112 ret_val = e1000_write_phy_reg(hw,
1113 M88E1000_PHY_GEN_CONTROL, 0x8104);
1114 if (ret_val)
1115 return ret_val;
1116
1117 hw->phy_reset_disable = false;
1118 }
1119 }
1120#endif
1121 return E1000_SUCCESS;
1122}
1123
1124#ifndef CONFIG_E1000_NO_NVM
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135static int32_t
1136e1000_get_software_semaphore(struct e1000_hw *hw)
1137{
1138 int32_t timeout = hw->eeprom.word_size + 1;
1139 uint32_t swsm;
1140
1141 DEBUGFUNC();
1142
1143 if (hw->mac_type != e1000_80003es2lan && hw->mac_type != e1000_igb)
1144 return E1000_SUCCESS;
1145
1146 while (timeout) {
1147 swsm = E1000_READ_REG(hw, SWSM);
1148
1149
1150 if (!(swsm & E1000_SWSM_SMBI))
1151 break;
1152 mdelay(1);
1153 timeout--;
1154 }
1155
1156 if (!timeout) {
1157 DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
1158 return -E1000_ERR_RESET;
1159 }
1160
1161 return E1000_SUCCESS;
1162}
1163#endif
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173static void
1174e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
1175{
1176#ifndef CONFIG_E1000_NO_NVM
1177 uint32_t swsm;
1178
1179 DEBUGFUNC();
1180
1181 if (!hw->eeprom_semaphore_present)
1182 return;
1183
1184 swsm = E1000_READ_REG(hw, SWSM);
1185 if (hw->mac_type == e1000_80003es2lan || hw->mac_type == e1000_igb) {
1186
1187 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1188 } else
1189 swsm &= ~(E1000_SWSM_SWESMBI);
1190 E1000_WRITE_REG(hw, SWSM, swsm);
1191#endif
1192}
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205static int32_t
1206e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
1207{
1208#ifndef CONFIG_E1000_NO_NVM
1209 int32_t timeout;
1210 uint32_t swsm;
1211
1212 DEBUGFUNC();
1213
1214 if (!hw->eeprom_semaphore_present)
1215 return E1000_SUCCESS;
1216
1217 if (hw->mac_type == e1000_80003es2lan || hw->mac_type == e1000_igb) {
1218
1219 if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
1220 return -E1000_ERR_EEPROM;
1221 }
1222
1223
1224 timeout = hw->eeprom.word_size + 1;
1225 while (timeout) {
1226 swsm = E1000_READ_REG(hw, SWSM);
1227 swsm |= E1000_SWSM_SWESMBI;
1228 E1000_WRITE_REG(hw, SWSM, swsm);
1229
1230 swsm = E1000_READ_REG(hw, SWSM);
1231 if (swsm & E1000_SWSM_SWESMBI)
1232 break;
1233
1234 udelay(50);
1235 timeout--;
1236 }
1237
1238 if (!timeout) {
1239
1240 e1000_put_hw_eeprom_semaphore(hw);
1241 DEBUGOUT("Driver can't access the Eeprom - "
1242 "SWESMBI bit is set.\n");
1243 return -E1000_ERR_EEPROM;
1244 }
1245#endif
1246 return E1000_SUCCESS;
1247}
1248
1249
1250static int32_t
1251e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
1252{
1253 uint32_t swfw_sync = 0;
1254 uint32_t swmask = mask;
1255 uint32_t fwmask = mask << 16;
1256 int32_t timeout = 200;
1257
1258 DEBUGFUNC();
1259 while (timeout) {
1260 if (e1000_get_hw_eeprom_semaphore(hw))
1261 return -E1000_ERR_SWFW_SYNC;
1262
1263 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1264 if (!(swfw_sync & (fwmask | swmask)))
1265 break;
1266
1267
1268
1269 e1000_put_hw_eeprom_semaphore(hw);
1270 mdelay(5);
1271 timeout--;
1272 }
1273
1274 if (!timeout) {
1275 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
1276 return -E1000_ERR_SWFW_SYNC;
1277 }
1278
1279 swfw_sync |= swmask;
1280 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1281
1282 e1000_put_hw_eeprom_semaphore(hw);
1283 return E1000_SUCCESS;
1284}
1285
1286static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
1287{
1288 uint32_t swfw_sync = 0;
1289
1290 DEBUGFUNC();
1291 while (e1000_get_hw_eeprom_semaphore(hw))
1292 ;
1293
1294 swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
1295 swfw_sync &= ~mask;
1296 E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
1297
1298 e1000_put_hw_eeprom_semaphore(hw);
1299}
1300
1301static bool e1000_is_second_port(struct e1000_hw *hw)
1302{
1303 switch (hw->mac_type) {
1304 case e1000_80003es2lan:
1305 case e1000_82546:
1306 case e1000_82571:
1307 if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
1308 return true;
1309
1310 default:
1311 return false;
1312 }
1313}
1314
1315#ifndef CONFIG_E1000_NO_NVM
1316
1317
1318
1319
1320
1321
1322static int e1000_read_mac_addr_from_eeprom(struct e1000_hw *hw,
1323 unsigned char enetaddr[6])
1324{
1325 uint16_t offset;
1326 uint16_t eeprom_data;
1327 int i;
1328
1329 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
1330 offset = i >> 1;
1331 if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
1332 DEBUGOUT("EEPROM Read Error\n");
1333 return -E1000_ERR_EEPROM;
1334 }
1335 enetaddr[i] = eeprom_data & 0xff;
1336 enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
1337 }
1338
1339 return 0;
1340}
1341
1342
1343
1344
1345
1346
1347
1348static int e1000_read_mac_addr_from_regs(struct e1000_hw *hw,
1349 unsigned char enetaddr[6])
1350{
1351 uint16_t offset, tmp;
1352 uint32_t reg_data = 0;
1353 int i;
1354
1355 if (hw->mac_type != e1000_igb)
1356 return -E1000_ERR_MAC_TYPE;
1357
1358 for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
1359 offset = i >> 1;
1360
1361 if (offset == 0)
1362 reg_data = E1000_READ_REG_ARRAY(hw, RA, 0);
1363 else if (offset == 1)
1364 reg_data >>= 16;
1365 else if (offset == 2)
1366 reg_data = E1000_READ_REG_ARRAY(hw, RA, 1);
1367 tmp = reg_data & 0xffff;
1368
1369 enetaddr[i] = tmp & 0xff;
1370 enetaddr[i + 1] = (tmp >> 8) & 0xff;
1371 }
1372
1373 return 0;
1374}
1375
1376
1377
1378
1379
1380
1381
1382
1383static int e1000_read_mac_addr(struct e1000_hw *hw, unsigned char enetaddr[6])
1384{
1385 int ret_val;
1386
1387 if (hw->mac_type == e1000_igb) {
1388
1389 ret_val = e1000_read_mac_addr_from_regs(hw, enetaddr);
1390 } else {
1391 ret_val = e1000_read_mac_addr_from_eeprom(hw, enetaddr);
1392 }
1393 if (ret_val)
1394 return ret_val;
1395
1396
1397 if (e1000_is_second_port(hw))
1398 enetaddr[5] ^= 1;
1399
1400 return 0;
1401}
1402#endif
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413static void
1414e1000_init_rx_addrs(struct e1000_hw *hw, unsigned char enetaddr[6])
1415{
1416 uint32_t i;
1417 uint32_t addr_low;
1418 uint32_t addr_high;
1419
1420 DEBUGFUNC();
1421
1422
1423 DEBUGOUT("Programming MAC Address into RAR[0]\n");
1424 addr_low = (enetaddr[0] |
1425 (enetaddr[1] << 8) |
1426 (enetaddr[2] << 16) | (enetaddr[3] << 24));
1427
1428 addr_high = (enetaddr[4] | (enetaddr[5] << 8) | E1000_RAH_AV);
1429
1430 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
1431 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
1432
1433
1434 DEBUGOUT("Clearing RAR[1-15]\n");
1435 for (i = 1; i < E1000_RAR_ENTRIES; i++) {
1436 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
1437 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
1438 }
1439}
1440
1441
1442
1443
1444
1445
1446static void
1447e1000_clear_vfta(struct e1000_hw *hw)
1448{
1449 uint32_t offset;
1450
1451 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
1452 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
1453}
1454
1455
1456
1457
1458
1459
1460int32_t
1461e1000_set_mac_type(struct e1000_hw *hw)
1462{
1463 DEBUGFUNC();
1464
1465 switch (hw->device_id) {
1466 case E1000_DEV_ID_82542:
1467 switch (hw->revision_id) {
1468 case E1000_82542_2_0_REV_ID:
1469 hw->mac_type = e1000_82542_rev2_0;
1470 break;
1471 case E1000_82542_2_1_REV_ID:
1472 hw->mac_type = e1000_82542_rev2_1;
1473 break;
1474 default:
1475
1476 return -E1000_ERR_MAC_TYPE;
1477 }
1478 break;
1479 case E1000_DEV_ID_82543GC_FIBER:
1480 case E1000_DEV_ID_82543GC_COPPER:
1481 hw->mac_type = e1000_82543;
1482 break;
1483 case E1000_DEV_ID_82544EI_COPPER:
1484 case E1000_DEV_ID_82544EI_FIBER:
1485 case E1000_DEV_ID_82544GC_COPPER:
1486 case E1000_DEV_ID_82544GC_LOM:
1487 hw->mac_type = e1000_82544;
1488 break;
1489 case E1000_DEV_ID_82540EM:
1490 case E1000_DEV_ID_82540EM_LOM:
1491 case E1000_DEV_ID_82540EP:
1492 case E1000_DEV_ID_82540EP_LOM:
1493 case E1000_DEV_ID_82540EP_LP:
1494 hw->mac_type = e1000_82540;
1495 break;
1496 case E1000_DEV_ID_82545EM_COPPER:
1497 case E1000_DEV_ID_82545EM_FIBER:
1498 hw->mac_type = e1000_82545;
1499 break;
1500 case E1000_DEV_ID_82545GM_COPPER:
1501 case E1000_DEV_ID_82545GM_FIBER:
1502 case E1000_DEV_ID_82545GM_SERDES:
1503 hw->mac_type = e1000_82545_rev_3;
1504 break;
1505 case E1000_DEV_ID_82546EB_COPPER:
1506 case E1000_DEV_ID_82546EB_FIBER:
1507 case E1000_DEV_ID_82546EB_QUAD_COPPER:
1508 hw->mac_type = e1000_82546;
1509 break;
1510 case E1000_DEV_ID_82546GB_COPPER:
1511 case E1000_DEV_ID_82546GB_FIBER:
1512 case E1000_DEV_ID_82546GB_SERDES:
1513 case E1000_DEV_ID_82546GB_PCIE:
1514 case E1000_DEV_ID_82546GB_QUAD_COPPER:
1515 case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
1516 hw->mac_type = e1000_82546_rev_3;
1517 break;
1518 case E1000_DEV_ID_82541EI:
1519 case E1000_DEV_ID_82541EI_MOBILE:
1520 case E1000_DEV_ID_82541ER_LOM:
1521 hw->mac_type = e1000_82541;
1522 break;
1523 case E1000_DEV_ID_82541ER:
1524 case E1000_DEV_ID_82541GI:
1525 case E1000_DEV_ID_82541GI_LF:
1526 case E1000_DEV_ID_82541GI_MOBILE:
1527 hw->mac_type = e1000_82541_rev_2;
1528 break;
1529 case E1000_DEV_ID_82547EI:
1530 case E1000_DEV_ID_82547EI_MOBILE:
1531 hw->mac_type = e1000_82547;
1532 break;
1533 case E1000_DEV_ID_82547GI:
1534 hw->mac_type = e1000_82547_rev_2;
1535 break;
1536 case E1000_DEV_ID_82571EB_COPPER:
1537 case E1000_DEV_ID_82571EB_FIBER:
1538 case E1000_DEV_ID_82571EB_SERDES:
1539 case E1000_DEV_ID_82571EB_SERDES_DUAL:
1540 case E1000_DEV_ID_82571EB_SERDES_QUAD:
1541 case E1000_DEV_ID_82571EB_QUAD_COPPER:
1542 case E1000_DEV_ID_82571PT_QUAD_COPPER:
1543 case E1000_DEV_ID_82571EB_QUAD_FIBER:
1544 case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
1545 hw->mac_type = e1000_82571;
1546 break;
1547 case E1000_DEV_ID_82572EI_COPPER:
1548 case E1000_DEV_ID_82572EI_FIBER:
1549 case E1000_DEV_ID_82572EI_SERDES:
1550 case E1000_DEV_ID_82572EI:
1551 hw->mac_type = e1000_82572;
1552 break;
1553 case E1000_DEV_ID_82573E:
1554 case E1000_DEV_ID_82573E_IAMT:
1555 case E1000_DEV_ID_82573L:
1556 hw->mac_type = e1000_82573;
1557 break;
1558 case E1000_DEV_ID_82574L:
1559 hw->mac_type = e1000_82574;
1560 break;
1561 case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
1562 case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
1563 case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
1564 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
1565 hw->mac_type = e1000_80003es2lan;
1566 break;
1567 case E1000_DEV_ID_ICH8_IGP_M_AMT:
1568 case E1000_DEV_ID_ICH8_IGP_AMT:
1569 case E1000_DEV_ID_ICH8_IGP_C:
1570 case E1000_DEV_ID_ICH8_IFE:
1571 case E1000_DEV_ID_ICH8_IFE_GT:
1572 case E1000_DEV_ID_ICH8_IFE_G:
1573 case E1000_DEV_ID_ICH8_IGP_M:
1574 hw->mac_type = e1000_ich8lan;
1575 break;
1576 case PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED:
1577 case PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED:
1578 case PCI_DEVICE_ID_INTEL_I210_COPPER:
1579 case PCI_DEVICE_ID_INTEL_I211_COPPER:
1580 case PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS:
1581 case PCI_DEVICE_ID_INTEL_I210_SERDES:
1582 case PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS:
1583 case PCI_DEVICE_ID_INTEL_I210_1000BASEKX:
1584 hw->mac_type = e1000_igb;
1585 break;
1586 default:
1587
1588 return -E1000_ERR_MAC_TYPE;
1589 }
1590 return E1000_SUCCESS;
1591}
1592
1593
1594
1595
1596
1597
1598void
1599e1000_reset_hw(struct e1000_hw *hw)
1600{
1601 uint32_t ctrl;
1602 uint32_t ctrl_ext;
1603 uint32_t manc;
1604 uint32_t pba = 0;
1605 uint32_t reg;
1606
1607 DEBUGFUNC();
1608
1609
1610 if (hw->mac_type < e1000_82571)
1611 pba = E1000_DEFAULT_PCI_PBA;
1612 else
1613 pba = E1000_DEFAULT_PCIE_PBA;
1614
1615
1616 if (hw->mac_type == e1000_82542_rev2_0) {
1617 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1618#ifdef CONFIG_DM_ETH
1619 dm_pci_write_config16(hw->pdev, PCI_COMMAND,
1620 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1621#else
1622 pci_write_config_word(hw->pdev, PCI_COMMAND,
1623 hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1624#endif
1625 }
1626
1627
1628 DEBUGOUT("Masking off all interrupts\n");
1629 if (hw->mac_type == e1000_igb)
1630 E1000_WRITE_REG(hw, I210_IAM, 0);
1631 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1632
1633
1634
1635
1636
1637 E1000_WRITE_REG(hw, RCTL, 0);
1638 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
1639 E1000_WRITE_FLUSH(hw);
1640
1641
1642 hw->tbi_compatibility_on = false;
1643
1644
1645
1646
1647 mdelay(10);
1648
1649
1650
1651
1652
1653
1654 DEBUGOUT("Issuing a global reset to MAC\n");
1655 ctrl = E1000_READ_REG(hw, CTRL);
1656
1657 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
1658
1659
1660 if (hw->mac_type == e1000_igb) {
1661 mdelay(20);
1662 reg = E1000_READ_REG(hw, STATUS);
1663 if (reg & E1000_STATUS_PF_RST_DONE)
1664 DEBUGOUT("PF OK\n");
1665 reg = E1000_READ_REG(hw, I210_EECD);
1666 if (reg & E1000_EECD_AUTO_RD)
1667 DEBUGOUT("EEC OK\n");
1668 } else if (hw->mac_type < e1000_82540) {
1669
1670 udelay(10);
1671 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1672 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1673 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
1674 E1000_WRITE_FLUSH(hw);
1675
1676 mdelay(2);
1677 } else {
1678
1679 mdelay(4);
1680
1681 manc = E1000_READ_REG(hw, MANC);
1682 manc &= ~(E1000_MANC_ARP_EN);
1683 E1000_WRITE_REG(hw, MANC, manc);
1684 }
1685
1686
1687 DEBUGOUT("Masking off all interrupts\n");
1688 if (hw->mac_type == e1000_igb)
1689 E1000_WRITE_REG(hw, I210_IAM, 0);
1690 E1000_WRITE_REG(hw, IMC, 0xffffffff);
1691
1692
1693 E1000_READ_REG(hw, ICR);
1694
1695
1696 if (hw->mac_type == e1000_82542_rev2_0) {
1697#ifdef CONFIG_DM_ETH
1698 dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1699#else
1700 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1701#endif
1702 }
1703 if (hw->mac_type != e1000_igb)
1704 E1000_WRITE_REG(hw, PBA, pba);
1705}
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716static void
1717e1000_initialize_hardware_bits(struct e1000_hw *hw)
1718{
1719 if ((hw->mac_type >= e1000_82571) &&
1720 (!hw->initialize_hw_bits_disable)) {
1721
1722 uint32_t reg_ctrl, reg_ctrl_ext;
1723 uint32_t reg_tarc0, reg_tarc1;
1724 uint32_t reg_tctl;
1725 uint32_t reg_txdctl, reg_txdctl1;
1726
1727
1728 reg_tarc0 = E1000_READ_REG(hw, TARC0);
1729 reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
1730
1731
1732 reg_txdctl = E1000_READ_REG(hw, TXDCTL);
1733 reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
1734 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
1735
1736 reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
1737 reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
1738 E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
1739
1740
1741 switch (hw->mac_type) {
1742 case e1000_igb:
1743 return;
1744 case e1000_82571:
1745 case e1000_82572:
1746
1747 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1748 reg_tarc1 &= ~((1 << 30)|(1 << 29));
1749
1750
1751 reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
1752
1753
1754 reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
1755
1756
1757 reg_tctl = E1000_READ_REG(hw, TCTL);
1758 if (reg_tctl & E1000_TCTL_MULR)
1759 reg_tarc1 &= ~(1 << 28);
1760 else
1761 reg_tarc1 |= (1 << 28);
1762
1763 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1764 break;
1765 case e1000_82573:
1766 case e1000_82574:
1767 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1768 reg_ctrl_ext &= ~(1 << 23);
1769 reg_ctrl_ext |= (1 << 22);
1770
1771
1772 reg_ctrl = E1000_READ_REG(hw, CTRL);
1773 reg_ctrl &= ~(1 << 29);
1774
1775 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1776 E1000_WRITE_REG(hw, CTRL, reg_ctrl);
1777 break;
1778 case e1000_80003es2lan:
1779
1780 if ((hw->media_type == e1000_media_type_fiber)
1781 || (hw->media_type ==
1782 e1000_media_type_internal_serdes)) {
1783 reg_tarc0 &= ~(1 << 20);
1784 }
1785
1786
1787 reg_tctl = E1000_READ_REG(hw, TCTL);
1788 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1789 if (reg_tctl & E1000_TCTL_MULR)
1790 reg_tarc1 &= ~(1 << 28);
1791 else
1792 reg_tarc1 |= (1 << 28);
1793
1794 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1795 break;
1796 case e1000_ich8lan:
1797
1798 if ((hw->revision_id < 3) ||
1799 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1800 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
1801 reg_tarc0 |= ((1 << 29)|(1 << 28));
1802
1803 reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
1804 reg_ctrl_ext |= (1 << 22);
1805 E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
1806
1807
1808 reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
1809
1810
1811 reg_tctl = E1000_READ_REG(hw, TCTL);
1812 reg_tarc1 = E1000_READ_REG(hw, TARC1);
1813 if (reg_tctl & E1000_TCTL_MULR)
1814 reg_tarc1 &= ~(1 << 28);
1815 else
1816 reg_tarc1 |= (1 << 28);
1817
1818
1819 reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
1820
1821 E1000_WRITE_REG(hw, TARC1, reg_tarc1);
1822 break;
1823 default:
1824 break;
1825 }
1826
1827 E1000_WRITE_REG(hw, TARC0, reg_tarc0);
1828 }
1829}
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842static int
1843e1000_init_hw(struct e1000_hw *hw, unsigned char enetaddr[6])
1844{
1845 uint32_t ctrl;
1846 uint32_t i;
1847 int32_t ret_val;
1848 uint16_t pcix_cmd_word;
1849 uint16_t pcix_stat_hi_word;
1850 uint16_t cmd_mmrbc;
1851 uint16_t stat_mmrbc;
1852 uint32_t mta_size;
1853 uint32_t reg_data;
1854 uint32_t ctrl_ext;
1855 DEBUGFUNC();
1856
1857 if ((hw->mac_type == e1000_ich8lan) &&
1858 ((hw->revision_id < 3) ||
1859 ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
1860 (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
1861 reg_data = E1000_READ_REG(hw, STATUS);
1862 reg_data &= ~0x80000000;
1863 E1000_WRITE_REG(hw, STATUS, reg_data);
1864 }
1865
1866
1867
1868 e1000_set_media_type(hw);
1869
1870
1871
1872 e1000_initialize_hardware_bits(hw);
1873
1874
1875 DEBUGOUT("Initializing the IEEE VLAN\n");
1876
1877 if (hw->mac_type != e1000_ich8lan) {
1878 if (hw->mac_type < e1000_82545_rev_3)
1879 E1000_WRITE_REG(hw, VET, 0);
1880 e1000_clear_vfta(hw);
1881 }
1882
1883
1884 if (hw->mac_type == e1000_82542_rev2_0) {
1885 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
1886#ifdef CONFIG_DM_ETH
1887 dm_pci_write_config16(hw->pdev, PCI_COMMAND,
1888 hw->
1889 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1890#else
1891 pci_write_config_word(hw->pdev, PCI_COMMAND,
1892 hw->
1893 pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
1894#endif
1895 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
1896 E1000_WRITE_FLUSH(hw);
1897 mdelay(5);
1898 }
1899
1900
1901
1902
1903 e1000_init_rx_addrs(hw, enetaddr);
1904
1905
1906 if (hw->mac_type == e1000_82542_rev2_0) {
1907 E1000_WRITE_REG(hw, RCTL, 0);
1908 E1000_WRITE_FLUSH(hw);
1909 mdelay(1);
1910#ifdef CONFIG_DM_ETH
1911 dm_pci_write_config16(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1912#else
1913 pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
1914#endif
1915 }
1916
1917
1918 DEBUGOUT("Zeroing the MTA\n");
1919 mta_size = E1000_MC_TBL_SIZE;
1920 if (hw->mac_type == e1000_ich8lan)
1921 mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
1922 for (i = 0; i < mta_size; i++) {
1923 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
1924
1925
1926 E1000_WRITE_FLUSH(hw);
1927 }
1928
1929 switch (hw->mac_type) {
1930 case e1000_82545_rev_3:
1931 case e1000_82546_rev_3:
1932 case e1000_igb:
1933 break;
1934 default:
1935
1936 if (hw->bus_type == e1000_bus_type_pcix) {
1937#ifdef CONFIG_DM_ETH
1938 dm_pci_read_config16(hw->pdev, PCIX_COMMAND_REGISTER,
1939 &pcix_cmd_word);
1940 dm_pci_read_config16(hw->pdev, PCIX_STATUS_REGISTER_HI,
1941 &pcix_stat_hi_word);
1942#else
1943 pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1944 &pcix_cmd_word);
1945 pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
1946 &pcix_stat_hi_word);
1947#endif
1948 cmd_mmrbc =
1949 (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
1950 PCIX_COMMAND_MMRBC_SHIFT;
1951 stat_mmrbc =
1952 (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
1953 PCIX_STATUS_HI_MMRBC_SHIFT;
1954 if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
1955 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
1956 if (cmd_mmrbc > stat_mmrbc) {
1957 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
1958 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
1959#ifdef CONFIG_DM_ETH
1960 dm_pci_write_config16(hw->pdev, PCIX_COMMAND_REGISTER,
1961 pcix_cmd_word);
1962#else
1963 pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
1964 pcix_cmd_word);
1965#endif
1966 }
1967 }
1968 break;
1969 }
1970
1971
1972 if (hw->mac_type == e1000_ich8lan)
1973 mdelay(15);
1974 if (hw->mac_type == e1000_igb)
1975 mdelay(15);
1976
1977
1978 ret_val = e1000_setup_link(hw);
1979
1980
1981 if (hw->mac_type > e1000_82544) {
1982 ctrl = E1000_READ_REG(hw, TXDCTL);
1983 ctrl =
1984 (ctrl & ~E1000_TXDCTL_WTHRESH) |
1985 E1000_TXDCTL_FULL_TX_DESC_WB;
1986 E1000_WRITE_REG(hw, TXDCTL, ctrl);
1987 }
1988
1989
1990 if (hw->mac_type >= e1000_82571) {
1991 ctrl = E1000_READ_REG(hw, RXDCTL);
1992 ctrl =
1993 (ctrl & ~E1000_RXDCTL_WTHRESH) |
1994 E1000_RXDCTL_FULL_RX_DESC_WB;
1995 E1000_WRITE_REG(hw, RXDCTL, ctrl);
1996 }
1997
1998 switch (hw->mac_type) {
1999 default:
2000 break;
2001 case e1000_80003es2lan:
2002
2003 reg_data = E1000_READ_REG(hw, TCTL);
2004 reg_data |= E1000_TCTL_RTLC;
2005 E1000_WRITE_REG(hw, TCTL, reg_data);
2006
2007
2008 reg_data = E1000_READ_REG(hw, TCTL_EXT);
2009 reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
2010 reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
2011 E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
2012
2013
2014 reg_data = E1000_READ_REG(hw, TIPG);
2015 reg_data &= ~E1000_TIPG_IPGT_MASK;
2016 reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
2017 E1000_WRITE_REG(hw, TIPG, reg_data);
2018
2019 reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
2020 reg_data &= ~0x00100000;
2021 E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
2022
2023 case e1000_82571:
2024 case e1000_82572:
2025 case e1000_ich8lan:
2026 ctrl = E1000_READ_REG(hw, TXDCTL1);
2027 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
2028 | E1000_TXDCTL_FULL_TX_DESC_WB;
2029 E1000_WRITE_REG(hw, TXDCTL1, ctrl);
2030 break;
2031 case e1000_82573:
2032 case e1000_82574:
2033 reg_data = E1000_READ_REG(hw, GCR);
2034 reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
2035 E1000_WRITE_REG(hw, GCR, reg_data);
2036 case e1000_igb:
2037 break;
2038 }
2039
2040 if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
2041 hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
2042 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2043
2044
2045 ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
2046 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2047 }
2048
2049 return ret_val;
2050}
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063static int
2064e1000_setup_link(struct e1000_hw *hw)
2065{
2066 int32_t ret_val;
2067#ifndef CONFIG_E1000_NO_NVM
2068 uint32_t ctrl_ext;
2069 uint16_t eeprom_data;
2070#endif
2071
2072 DEBUGFUNC();
2073
2074
2075
2076 if (e1000_check_phy_reset_block(hw))
2077 return E1000_SUCCESS;
2078
2079#ifndef CONFIG_E1000_NO_NVM
2080
2081
2082
2083
2084
2085
2086
2087
2088 if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
2089 &eeprom_data) < 0) {
2090 DEBUGOUT("EEPROM Read Error\n");
2091 return -E1000_ERR_EEPROM;
2092 }
2093#endif
2094 if (hw->fc == e1000_fc_default) {
2095 switch (hw->mac_type) {
2096 case e1000_ich8lan:
2097 case e1000_82573:
2098 case e1000_82574:
2099 case e1000_igb:
2100 hw->fc = e1000_fc_full;
2101 break;
2102 default:
2103#ifndef CONFIG_E1000_NO_NVM
2104 ret_val = e1000_read_eeprom(hw,
2105 EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
2106 if (ret_val) {
2107 DEBUGOUT("EEPROM Read Error\n");
2108 return -E1000_ERR_EEPROM;
2109 }
2110 if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
2111 hw->fc = e1000_fc_none;
2112 else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
2113 EEPROM_WORD0F_ASM_DIR)
2114 hw->fc = e1000_fc_tx_pause;
2115 else
2116#endif
2117 hw->fc = e1000_fc_full;
2118 break;
2119 }
2120 }
2121
2122
2123
2124
2125
2126 if (hw->mac_type == e1000_82542_rev2_0)
2127 hw->fc &= (~e1000_fc_tx_pause);
2128
2129 if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
2130 hw->fc &= (~e1000_fc_rx_pause);
2131
2132 hw->original_fc = hw->fc;
2133
2134 DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
2135
2136#ifndef CONFIG_E1000_NO_NVM
2137
2138
2139
2140
2141
2142
2143
2144 if (hw->mac_type == e1000_82543) {
2145 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
2146 SWDPIO__EXT_SHIFT);
2147 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2148 }
2149#endif
2150
2151
2152 ret_val = (hw->media_type == e1000_media_type_fiber) ?
2153 e1000_setup_fiber_link(hw) : e1000_setup_copper_link(hw);
2154 if (ret_val < 0) {
2155 return ret_val;
2156 }
2157
2158
2159
2160
2161
2162
2163 DEBUGOUT("Initializing the Flow Control address, type"
2164 "and timer regs\n");
2165
2166
2167 if (hw->mac_type != e1000_ich8lan) {
2168 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
2169 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
2170 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
2171 }
2172
2173 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
2174
2175
2176
2177
2178
2179
2180
2181 if (!(hw->fc & e1000_fc_tx_pause)) {
2182 E1000_WRITE_REG(hw, FCRTL, 0);
2183 E1000_WRITE_REG(hw, FCRTH, 0);
2184 } else {
2185
2186
2187
2188 if (hw->fc_send_xon) {
2189 E1000_WRITE_REG(hw, FCRTL,
2190 (hw->fc_low_water | E1000_FCRTL_XONE));
2191 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
2192 } else {
2193 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
2194 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
2195 }
2196 }
2197 return ret_val;
2198}
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209static int
2210e1000_setup_fiber_link(struct e1000_hw *hw)
2211{
2212 uint32_t ctrl;
2213 uint32_t status;
2214 uint32_t txcw = 0;
2215 uint32_t i;
2216 uint32_t signal;
2217 int32_t ret_val;
2218
2219 DEBUGFUNC();
2220
2221
2222
2223
2224 ctrl = E1000_READ_REG(hw, CTRL);
2225 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
2226 signal = E1000_CTRL_SWDPIN1;
2227 else
2228 signal = 0;
2229
2230 printf("signal for %s is %x (ctrl %08x)!!!!\n", hw->name, signal,
2231 ctrl);
2232
2233 ctrl &= ~(E1000_CTRL_LRST);
2234
2235 e1000_config_collision_dist(hw);
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252 switch (hw->fc) {
2253 case e1000_fc_none:
2254
2255 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
2256 break;
2257 case e1000_fc_rx_pause:
2258
2259
2260
2261
2262
2263
2264 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2265 break;
2266 case e1000_fc_tx_pause:
2267
2268
2269
2270 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
2271 break;
2272 case e1000_fc_full:
2273
2274 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
2275 break;
2276 default:
2277 DEBUGOUT("Flow control param set incorrectly\n");
2278 return -E1000_ERR_CONFIG;
2279 break;
2280 }
2281
2282
2283
2284
2285
2286
2287
2288 DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
2289
2290 E1000_WRITE_REG(hw, TXCW, txcw);
2291 E1000_WRITE_REG(hw, CTRL, ctrl);
2292 E1000_WRITE_FLUSH(hw);
2293
2294 hw->txcw = txcw;
2295 mdelay(1);
2296
2297
2298
2299
2300
2301
2302 if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
2303 DEBUGOUT("Looking for Link\n");
2304 for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
2305 mdelay(10);
2306 status = E1000_READ_REG(hw, STATUS);
2307 if (status & E1000_STATUS_LU)
2308 break;
2309 }
2310 if (i == (LINK_UP_TIMEOUT / 10)) {
2311
2312
2313
2314
2315
2316 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
2317 hw->autoneg_failed = 1;
2318 ret_val = e1000_check_for_link(hw);
2319 if (ret_val < 0) {
2320 DEBUGOUT("Error while checking for link\n");
2321 return ret_val;
2322 }
2323 hw->autoneg_failed = 0;
2324 } else {
2325 hw->autoneg_failed = 0;
2326 DEBUGOUT("Valid Link Found\n");
2327 }
2328 } else {
2329 DEBUGOUT("No Signal Detected\n");
2330 return -E1000_ERR_NOLINK;
2331 }
2332 return 0;
2333}
2334
2335
2336
2337
2338
2339
2340static int32_t
2341e1000_copper_link_preconfig(struct e1000_hw *hw)
2342{
2343 uint32_t ctrl;
2344 int32_t ret_val;
2345 uint16_t phy_data;
2346
2347 DEBUGFUNC();
2348
2349 ctrl = E1000_READ_REG(hw, CTRL);
2350
2351
2352
2353
2354 if (hw->mac_type > e1000_82543) {
2355 ctrl |= E1000_CTRL_SLU;
2356 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
2357 E1000_WRITE_REG(hw, CTRL, ctrl);
2358 } else {
2359 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
2360 | E1000_CTRL_SLU);
2361 E1000_WRITE_REG(hw, CTRL, ctrl);
2362 ret_val = e1000_phy_hw_reset(hw);
2363 if (ret_val)
2364 return ret_val;
2365 }
2366
2367
2368 ret_val = e1000_detect_gig_phy(hw);
2369 if (ret_val) {
2370 DEBUGOUT("Error, did not detect valid phy.\n");
2371 return ret_val;
2372 }
2373 DEBUGOUT("Phy ID = %x\n", hw->phy_id);
2374
2375
2376 ret_val = e1000_set_phy_mode(hw);
2377 if (ret_val)
2378 return ret_val;
2379 if ((hw->mac_type == e1000_82545_rev_3) ||
2380 (hw->mac_type == e1000_82546_rev_3)) {
2381 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2382 &phy_data);
2383 phy_data |= 0x00000008;
2384 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
2385 phy_data);
2386 }
2387
2388 if (hw->mac_type <= e1000_82543 ||
2389 hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
2390 hw->mac_type == e1000_82541_rev_2
2391 || hw->mac_type == e1000_82547_rev_2)
2392 hw->phy_reset_disable = false;
2393
2394 return E1000_SUCCESS;
2395}
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411static int32_t
2412e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
2413{
2414 uint32_t phy_ctrl = 0;
2415 int32_t ret_val;
2416 uint16_t phy_data;
2417 DEBUGFUNC();
2418
2419 if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
2420 && hw->phy_type != e1000_phy_igp_3)
2421 return E1000_SUCCESS;
2422
2423
2424
2425
2426 if (hw->mac_type == e1000_82541_rev_2
2427 || hw->mac_type == e1000_82547_rev_2) {
2428 ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
2429 &phy_data);
2430 if (ret_val)
2431 return ret_val;
2432 } else if (hw->mac_type == e1000_ich8lan) {
2433
2434
2435
2436 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2437 } else {
2438 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2439 &phy_data);
2440 if (ret_val)
2441 return ret_val;
2442 }
2443
2444 if (!active) {
2445 if (hw->mac_type == e1000_82541_rev_2 ||
2446 hw->mac_type == e1000_82547_rev_2) {
2447 phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
2448 ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
2449 phy_data);
2450 if (ret_val)
2451 return ret_val;
2452 } else {
2453 if (hw->mac_type == e1000_ich8lan) {
2454 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
2455 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2456 } else {
2457 phy_data &= ~IGP02E1000_PM_D3_LPLU;
2458 ret_val = e1000_write_phy_reg(hw,
2459 IGP02E1000_PHY_POWER_MGMT, phy_data);
2460 if (ret_val)
2461 return ret_val;
2462 }
2463 }
2464
2465
2466
2467
2468
2469 if (hw->smart_speed == e1000_smart_speed_on) {
2470 ret_val = e1000_read_phy_reg(hw,
2471 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2472 if (ret_val)
2473 return ret_val;
2474
2475 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2476 ret_val = e1000_write_phy_reg(hw,
2477 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2478 if (ret_val)
2479 return ret_val;
2480 } else if (hw->smart_speed == e1000_smart_speed_off) {
2481 ret_val = e1000_read_phy_reg(hw,
2482 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2483 if (ret_val)
2484 return ret_val;
2485
2486 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2487 ret_val = e1000_write_phy_reg(hw,
2488 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2489 if (ret_val)
2490 return ret_val;
2491 }
2492
2493 } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
2494 || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
2495 (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
2496
2497 if (hw->mac_type == e1000_82541_rev_2 ||
2498 hw->mac_type == e1000_82547_rev_2) {
2499 phy_data |= IGP01E1000_GMII_FLEX_SPD;
2500 ret_val = e1000_write_phy_reg(hw,
2501 IGP01E1000_GMII_FIFO, phy_data);
2502 if (ret_val)
2503 return ret_val;
2504 } else {
2505 if (hw->mac_type == e1000_ich8lan) {
2506 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
2507 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2508 } else {
2509 phy_data |= IGP02E1000_PM_D3_LPLU;
2510 ret_val = e1000_write_phy_reg(hw,
2511 IGP02E1000_PHY_POWER_MGMT, phy_data);
2512 if (ret_val)
2513 return ret_val;
2514 }
2515 }
2516
2517
2518 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2519 &phy_data);
2520 if (ret_val)
2521 return ret_val;
2522
2523 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2524 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
2525 phy_data);
2526 if (ret_val)
2527 return ret_val;
2528 }
2529 return E1000_SUCCESS;
2530}
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546static int32_t
2547e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
2548{
2549 uint32_t phy_ctrl = 0;
2550 int32_t ret_val;
2551 uint16_t phy_data;
2552 DEBUGFUNC();
2553
2554 if (hw->mac_type <= e1000_82547_rev_2)
2555 return E1000_SUCCESS;
2556
2557 if (hw->mac_type == e1000_ich8lan) {
2558 phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
2559 } else if (hw->mac_type == e1000_igb) {
2560 phy_ctrl = E1000_READ_REG(hw, I210_PHY_CTRL);
2561 } else {
2562 ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
2563 &phy_data);
2564 if (ret_val)
2565 return ret_val;
2566 }
2567
2568 if (!active) {
2569 if (hw->mac_type == e1000_ich8lan) {
2570 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2571 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2572 } else if (hw->mac_type == e1000_igb) {
2573 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
2574 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2575 } else {
2576 phy_data &= ~IGP02E1000_PM_D0_LPLU;
2577 ret_val = e1000_write_phy_reg(hw,
2578 IGP02E1000_PHY_POWER_MGMT, phy_data);
2579 if (ret_val)
2580 return ret_val;
2581 }
2582
2583 if (hw->mac_type == e1000_igb)
2584 return E1000_SUCCESS;
2585
2586
2587
2588
2589
2590 if (hw->smart_speed == e1000_smart_speed_on) {
2591 ret_val = e1000_read_phy_reg(hw,
2592 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2593 if (ret_val)
2594 return ret_val;
2595
2596 phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
2597 ret_val = e1000_write_phy_reg(hw,
2598 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2599 if (ret_val)
2600 return ret_val;
2601 } else if (hw->smart_speed == e1000_smart_speed_off) {
2602 ret_val = e1000_read_phy_reg(hw,
2603 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2604 if (ret_val)
2605 return ret_val;
2606
2607 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2608 ret_val = e1000_write_phy_reg(hw,
2609 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2610 if (ret_val)
2611 return ret_val;
2612 }
2613
2614
2615 } else {
2616
2617 if (hw->mac_type == e1000_ich8lan) {
2618 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2619 E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
2620 } else if (hw->mac_type == e1000_igb) {
2621 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
2622 E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
2623 } else {
2624 phy_data |= IGP02E1000_PM_D0_LPLU;
2625 ret_val = e1000_write_phy_reg(hw,
2626 IGP02E1000_PHY_POWER_MGMT, phy_data);
2627 if (ret_val)
2628 return ret_val;
2629 }
2630
2631 if (hw->mac_type == e1000_igb)
2632 return E1000_SUCCESS;
2633
2634
2635 ret_val = e1000_read_phy_reg(hw,
2636 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2637 if (ret_val)
2638 return ret_val;
2639
2640 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2641 ret_val = e1000_write_phy_reg(hw,
2642 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2643 if (ret_val)
2644 return ret_val;
2645
2646 }
2647 return E1000_SUCCESS;
2648}
2649
2650
2651
2652
2653
2654
2655static int32_t
2656e1000_copper_link_igp_setup(struct e1000_hw *hw)
2657{
2658 uint32_t led_ctrl;
2659 int32_t ret_val;
2660 uint16_t phy_data;
2661
2662 DEBUGFUNC();
2663
2664 if (hw->phy_reset_disable)
2665 return E1000_SUCCESS;
2666
2667 ret_val = e1000_phy_reset(hw);
2668 if (ret_val) {
2669 DEBUGOUT("Error Resetting the PHY\n");
2670 return ret_val;
2671 }
2672
2673
2674 mdelay(15);
2675 if (hw->mac_type != e1000_ich8lan) {
2676
2677 led_ctrl = E1000_READ_REG(hw, LEDCTL);
2678 led_ctrl &= IGP_ACTIVITY_LED_MASK;
2679 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
2680 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
2681 }
2682
2683
2684 if (hw->phy_type == e1000_phy_igp) {
2685
2686 ret_val = e1000_set_d3_lplu_state(hw, false);
2687 if (ret_val) {
2688 DEBUGOUT("Error Disabling LPLU D3\n");
2689 return ret_val;
2690 }
2691 }
2692
2693
2694 ret_val = e1000_set_d0_lplu_state(hw, false);
2695 if (ret_val) {
2696 DEBUGOUT("Error Disabling LPLU D0\n");
2697 return ret_val;
2698 }
2699
2700 ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
2701 if (ret_val)
2702 return ret_val;
2703
2704 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
2705 hw->dsp_config_state = e1000_dsp_config_disabled;
2706
2707 phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
2708 | IGP01E1000_PSCR_FORCE_MDI_MDIX);
2709 hw->mdix = 1;
2710
2711 } else {
2712 hw->dsp_config_state = e1000_dsp_config_enabled;
2713 phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
2714
2715 switch (hw->mdix) {
2716 case 1:
2717 phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
2718 break;
2719 case 2:
2720 phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
2721 break;
2722 case 0:
2723 default:
2724 phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
2725 break;
2726 }
2727 }
2728 ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
2729 if (ret_val)
2730 return ret_val;
2731
2732
2733 if (hw->autoneg) {
2734 e1000_ms_type phy_ms_setting = hw->master_slave;
2735
2736 if (hw->ffe_config_state == e1000_ffe_config_active)
2737 hw->ffe_config_state = e1000_ffe_config_enabled;
2738
2739 if (hw->dsp_config_state == e1000_dsp_config_activated)
2740 hw->dsp_config_state = e1000_dsp_config_enabled;
2741
2742
2743
2744
2745 if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
2746
2747 ret_val = e1000_read_phy_reg(hw,
2748 IGP01E1000_PHY_PORT_CONFIG, &phy_data);
2749 if (ret_val)
2750 return ret_val;
2751 phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
2752 ret_val = e1000_write_phy_reg(hw,
2753 IGP01E1000_PHY_PORT_CONFIG, phy_data);
2754 if (ret_val)
2755 return ret_val;
2756
2757 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
2758 &phy_data);
2759 if (ret_val)
2760 return ret_val;
2761 phy_data &= ~CR_1000T_MS_ENABLE;
2762 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
2763 phy_data);
2764 if (ret_val)
2765 return ret_val;
2766 }
2767
2768 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
2769 if (ret_val)
2770 return ret_val;
2771
2772
2773 hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
2774 ((phy_data & CR_1000T_MS_VALUE) ?
2775 e1000_ms_force_master :
2776 e1000_ms_force_slave) :
2777 e1000_ms_auto;
2778
2779 switch (phy_ms_setting) {
2780 case e1000_ms_force_master:
2781 phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
2782 break;
2783 case e1000_ms_force_slave:
2784 phy_data |= CR_1000T_MS_ENABLE;
2785 phy_data &= ~(CR_1000T_MS_VALUE);
2786 break;
2787 case e1000_ms_auto:
2788 phy_data &= ~CR_1000T_MS_ENABLE;
2789 default:
2790 break;
2791 }
2792 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
2793 if (ret_val)
2794 return ret_val;
2795 }
2796
2797 return E1000_SUCCESS;
2798}
2799
2800
2801
2802
2803
2804
2805bool
2806e1000_check_mng_mode(struct e1000_hw *hw)
2807{
2808 uint32_t fwsm;
2809 DEBUGFUNC();
2810
2811 fwsm = E1000_READ_REG(hw, FWSM);
2812
2813 if (hw->mac_type == e1000_ich8lan) {
2814 if ((fwsm & E1000_FWSM_MODE_MASK) ==
2815 (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2816 return true;
2817 } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
2818 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
2819 return true;
2820
2821 return false;
2822}
2823
2824static int32_t
2825e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
2826{
2827 uint16_t swfw = E1000_SWFW_PHY0_SM;
2828 uint32_t reg_val;
2829 DEBUGFUNC();
2830
2831 if (e1000_is_second_port(hw))
2832 swfw = E1000_SWFW_PHY1_SM;
2833
2834 if (e1000_swfw_sync_acquire(hw, swfw))
2835 return -E1000_ERR_SWFW_SYNC;
2836
2837 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
2838 & E1000_KUMCTRLSTA_OFFSET) | data;
2839 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2840 udelay(2);
2841
2842 return E1000_SUCCESS;
2843}
2844
2845static int32_t
2846e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
2847{
2848 uint16_t swfw = E1000_SWFW_PHY0_SM;
2849 uint32_t reg_val;
2850 DEBUGFUNC();
2851
2852 if (e1000_is_second_port(hw))
2853 swfw = E1000_SWFW_PHY1_SM;
2854
2855 if (e1000_swfw_sync_acquire(hw, swfw)) {
2856 debug("%s[%i]\n", __func__, __LINE__);
2857 return -E1000_ERR_SWFW_SYNC;
2858 }
2859
2860
2861 reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
2862 E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
2863 E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
2864 udelay(2);
2865
2866
2867 reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
2868 *data = (uint16_t)reg_val;
2869
2870 return E1000_SUCCESS;
2871}
2872
2873
2874
2875
2876
2877
2878static int32_t
2879e1000_copper_link_ggp_setup(struct e1000_hw *hw)
2880{
2881 int32_t ret_val;
2882 uint16_t phy_data;
2883 uint32_t reg_data;
2884
2885 DEBUGFUNC();
2886
2887 if (!hw->phy_reset_disable) {
2888
2889 ret_val = e1000_read_phy_reg(hw,
2890 GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
2891 if (ret_val)
2892 return ret_val;
2893
2894 phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
2895
2896 phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
2897
2898 ret_val = e1000_write_phy_reg(hw,
2899 GG82563_PHY_MAC_SPEC_CTRL, phy_data);
2900 if (ret_val)
2901 return ret_val;
2902
2903
2904
2905
2906
2907
2908
2909
2910 ret_val = e1000_read_phy_reg(hw,
2911 GG82563_PHY_SPEC_CTRL, &phy_data);
2912 if (ret_val)
2913 return ret_val;
2914
2915 phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
2916
2917 switch (hw->mdix) {
2918 case 1:
2919 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
2920 break;
2921 case 2:
2922 phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
2923 break;
2924 case 0:
2925 default:
2926 phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
2927 break;
2928 }
2929
2930
2931
2932
2933
2934
2935
2936 phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
2937 ret_val = e1000_write_phy_reg(hw,
2938 GG82563_PHY_SPEC_CTRL, phy_data);
2939
2940 if (ret_val)
2941 return ret_val;
2942
2943
2944 ret_val = e1000_phy_reset(hw);
2945 if (ret_val) {
2946 DEBUGOUT("Error Resetting the PHY\n");
2947 return ret_val;
2948 }
2949 }
2950
2951 if (hw->mac_type == e1000_80003es2lan) {
2952
2953 ret_val = e1000_write_kmrn_reg(hw,
2954 E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
2955 E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
2956 | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
2957 if (ret_val)
2958 return ret_val;
2959
2960 ret_val = e1000_read_phy_reg(hw,
2961 GG82563_PHY_SPEC_CTRL_2, &phy_data);
2962 if (ret_val)
2963 return ret_val;
2964
2965 phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
2966 ret_val = e1000_write_phy_reg(hw,
2967 GG82563_PHY_SPEC_CTRL_2, phy_data);
2968
2969 if (ret_val)
2970 return ret_val;
2971
2972 reg_data = E1000_READ_REG(hw, CTRL_EXT);
2973 reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
2974 E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
2975
2976 ret_val = e1000_read_phy_reg(hw,
2977 GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
2978 if (ret_val)
2979 return ret_val;
2980
2981
2982
2983
2984
2985 if (e1000_check_mng_mode(hw) == false) {
2986
2987 phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
2988 ret_val = e1000_write_phy_reg(hw,
2989 GG82563_PHY_PWR_MGMT_CTRL, phy_data);
2990 if (ret_val)
2991 return ret_val;
2992
2993 ret_val = e1000_read_phy_reg(hw,
2994 GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
2995 if (ret_val)
2996 return ret_val;
2997
2998 phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
2999 ret_val = e1000_write_phy_reg(hw,
3000 GG82563_PHY_KMRN_MODE_CTRL, phy_data);
3001
3002 if (ret_val)
3003 return ret_val;
3004 }
3005
3006
3007
3008
3009 ret_val = e1000_read_phy_reg(hw,
3010 GG82563_PHY_INBAND_CTRL, &phy_data);
3011 if (ret_val)
3012 return ret_val;
3013 phy_data |= GG82563_ICR_DIS_PADDING;
3014 ret_val = e1000_write_phy_reg(hw,
3015 GG82563_PHY_INBAND_CTRL, phy_data);
3016 if (ret_val)
3017 return ret_val;
3018 }
3019 return E1000_SUCCESS;
3020}
3021
3022
3023
3024
3025
3026
3027static int32_t
3028e1000_copper_link_mgp_setup(struct e1000_hw *hw)
3029{
3030 int32_t ret_val;
3031 uint16_t phy_data;
3032
3033 DEBUGFUNC();
3034
3035 if (hw->phy_reset_disable)
3036 return E1000_SUCCESS;
3037
3038
3039 ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
3040 if (ret_val)
3041 return ret_val;
3042
3043 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
3044
3045
3046
3047
3048
3049
3050
3051
3052 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
3053
3054 switch (hw->mdix) {
3055 case 1:
3056 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
3057 break;
3058 case 2:
3059 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
3060 break;
3061 case 3:
3062 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
3063 break;
3064 case 0:
3065 default:
3066 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
3067 break;
3068 }
3069
3070
3071
3072
3073
3074
3075
3076 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
3077 ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
3078 if (ret_val)
3079 return ret_val;
3080
3081 if (hw->phy_revision < M88E1011_I_REV_4) {
3082
3083
3084
3085 ret_val = e1000_read_phy_reg(hw,
3086 M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
3087 if (ret_val)
3088 return ret_val;
3089
3090 phy_data |= M88E1000_EPSCR_TX_CLK_25;
3091
3092 if ((hw->phy_revision == E1000_REVISION_2) &&
3093 (hw->phy_id == M88E1111_I_PHY_ID)) {
3094
3095 phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
3096 phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
3097 ret_val = e1000_write_phy_reg(hw,
3098 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
3099 if (ret_val)
3100 return ret_val;
3101 } else {
3102
3103 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
3104 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
3105 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
3106 | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
3107 ret_val = e1000_write_phy_reg(hw,
3108 M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
3109 if (ret_val)
3110 return ret_val;
3111 }
3112 }
3113
3114
3115 ret_val = e1000_phy_reset(hw);
3116 if (ret_val) {
3117 DEBUGOUT("Error Resetting the PHY\n");
3118 return ret_val;
3119 }
3120
3121 return E1000_SUCCESS;
3122}
3123
3124
3125
3126
3127
3128
3129
3130static int32_t
3131e1000_copper_link_autoneg(struct e1000_hw *hw)
3132{
3133 int32_t ret_val;
3134 uint16_t phy_data;
3135
3136 DEBUGFUNC();
3137
3138
3139
3140
3141 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
3142
3143
3144
3145
3146 if (hw->autoneg_advertised == 0)
3147 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
3148
3149
3150 if (hw->phy_type == e1000_phy_ife)
3151 hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
3152
3153 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
3154 ret_val = e1000_phy_setup_autoneg(hw);
3155 if (ret_val) {
3156 DEBUGOUT("Error Setting up Auto-Negotiation\n");
3157 return ret_val;
3158 }
3159 DEBUGOUT("Restarting Auto-Neg\n");
3160
3161
3162
3163
3164 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
3165 if (ret_val)
3166 return ret_val;
3167
3168 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
3169 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
3170 if (ret_val)
3171 return ret_val;
3172
3173
3174
3175
3176
3177
3178
3179
3180 if (hw->wait_autoneg_complete) {
3181 ret_val = e1000_wait_autoneg(hw);
3182 if (ret_val) {
3183 DEBUGOUT("Error while waiting for autoneg"
3184 "to complete\n");
3185 return ret_val;
3186 }
3187 }
3188
3189 hw->get_link_status = true;
3190
3191 return E1000_SUCCESS;
3192}
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206static int32_t
3207e1000_copper_link_postconfig(struct e1000_hw *hw)
3208{
3209 int32_t ret_val;
3210 DEBUGFUNC();
3211
3212 if (hw->mac_type >= e1000_82544) {
3213 e1000_config_collision_dist(hw);
3214 } else {
3215 ret_val = e1000_config_mac_to_phy(hw);
3216 if (ret_val) {
3217 DEBUGOUT("Error configuring MAC to PHY settings\n");
3218 return ret_val;
3219 }
3220 }
3221 ret_val = e1000_config_fc_after_link_up(hw);
3222 if (ret_val) {
3223 DEBUGOUT("Error Configuring Flow Control\n");
3224 return ret_val;
3225 }
3226 return E1000_SUCCESS;
3227}
3228
3229
3230
3231
3232
3233
3234static int
3235e1000_setup_copper_link(struct e1000_hw *hw)
3236{
3237 int32_t ret_val;
3238 uint16_t i;
3239 uint16_t phy_data;
3240 uint16_t reg_data;
3241
3242 DEBUGFUNC();
3243
3244 switch (hw->mac_type) {
3245 case e1000_80003es2lan:
3246 case e1000_ich8lan:
3247
3248
3249
3250 ret_val = e1000_write_kmrn_reg(hw,
3251 GG82563_REG(0x34, 4), 0xFFFF);
3252 if (ret_val)
3253 return ret_val;
3254 ret_val = e1000_read_kmrn_reg(hw,
3255 GG82563_REG(0x34, 9), ®_data);
3256 if (ret_val)
3257 return ret_val;
3258 reg_data |= 0x3F;
3259 ret_val = e1000_write_kmrn_reg(hw,
3260 GG82563_REG(0x34, 9), reg_data);
3261 if (ret_val)
3262 return ret_val;
3263 default:
3264 break;
3265 }
3266
3267
3268 ret_val = e1000_copper_link_preconfig(hw);
3269 if (ret_val)
3270 return ret_val;
3271 switch (hw->mac_type) {
3272 case e1000_80003es2lan:
3273
3274 reg_data =
3275 E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
3276 reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
3277 ret_val = e1000_write_kmrn_reg(hw,
3278 E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
3279 if (ret_val)
3280 return ret_val;
3281 break;
3282 default:
3283 break;
3284 }
3285
3286 if (hw->phy_type == e1000_phy_igp ||
3287 hw->phy_type == e1000_phy_igp_3 ||
3288 hw->phy_type == e1000_phy_igp_2) {
3289 ret_val = e1000_copper_link_igp_setup(hw);
3290 if (ret_val)
3291 return ret_val;
3292 } else if (hw->phy_type == e1000_phy_m88 ||
3293 hw->phy_type == e1000_phy_igb) {
3294 ret_val = e1000_copper_link_mgp_setup(hw);
3295 if (ret_val)
3296 return ret_val;
3297 } else if (hw->phy_type == e1000_phy_gg82563) {
3298 ret_val = e1000_copper_link_ggp_setup(hw);
3299 if (ret_val)
3300 return ret_val;
3301 }
3302
3303
3304
3305
3306 ret_val = e1000_copper_link_autoneg(hw);
3307 if (ret_val)
3308 return ret_val;
3309
3310
3311
3312
3313 for (i = 0; i < 10; i++) {
3314 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3315 if (ret_val)
3316 return ret_val;
3317 ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
3318 if (ret_val)
3319 return ret_val;
3320
3321 if (phy_data & MII_SR_LINK_STATUS) {
3322
3323 ret_val = e1000_copper_link_postconfig(hw);
3324 if (ret_val)
3325 return ret_val;
3326
3327 DEBUGOUT("Valid link established!!!\n");
3328 return E1000_SUCCESS;
3329 }
3330 udelay(10);
3331 }
3332
3333 DEBUGOUT("Unable to establish link!!!\n");
3334 return E1000_SUCCESS;
3335}
3336
3337
3338
3339
3340
3341
3342int32_t
3343e1000_phy_setup_autoneg(struct e1000_hw *hw)
3344{
3345 int32_t ret_val;
3346 uint16_t mii_autoneg_adv_reg;
3347 uint16_t mii_1000t_ctrl_reg;
3348
3349 DEBUGFUNC();
3350
3351
3352 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
3353 if (ret_val)
3354 return ret_val;
3355
3356 if (hw->phy_type != e1000_phy_ife) {
3357
3358 ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
3359 &mii_1000t_ctrl_reg);
3360 if (ret_val)
3361 return ret_val;
3362 } else
3363 mii_1000t_ctrl_reg = 0;
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
3377 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
3378
3379 DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
3380
3381
3382 if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
3383 DEBUGOUT("Advertise 10mb Half duplex\n");
3384 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
3385 }
3386
3387
3388 if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
3389 DEBUGOUT("Advertise 10mb Full duplex\n");
3390 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
3391 }
3392
3393
3394 if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
3395 DEBUGOUT("Advertise 100mb Half duplex\n");
3396 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
3397 }
3398
3399
3400 if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
3401 DEBUGOUT("Advertise 100mb Full duplex\n");
3402 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
3403 }
3404
3405
3406 if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
3407 DEBUGOUT
3408 ("Advertise 1000mb Half duplex requested, request denied!\n");
3409 }
3410
3411
3412 if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
3413 DEBUGOUT("Advertise 1000mb Full duplex\n");
3414 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
3415 }
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433 switch (hw->fc) {
3434 case e1000_fc_none:
3435
3436
3437
3438 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3439 break;
3440 case e1000_fc_rx_pause:
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3451 break;
3452 case e1000_fc_tx_pause:
3453
3454
3455
3456 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
3457 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
3458 break;
3459 case e1000_fc_full:
3460
3461
3462
3463 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
3464 break;
3465 default:
3466 DEBUGOUT("Flow control param set incorrectly\n");
3467 return -E1000_ERR_CONFIG;
3468 }
3469
3470 ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
3471 if (ret_val)
3472 return ret_val;
3473
3474 DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
3475
3476 if (hw->phy_type != e1000_phy_ife) {
3477 ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
3478 mii_1000t_ctrl_reg);
3479 if (ret_val)
3480 return ret_val;
3481 }
3482
3483 return E1000_SUCCESS;
3484}
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494static void
3495e1000_config_collision_dist(struct e1000_hw *hw)
3496{
3497 uint32_t tctl, coll_dist;
3498
3499 DEBUGFUNC();
3500
3501 if (hw->mac_type < e1000_82543)
3502 coll_dist = E1000_COLLISION_DISTANCE_82542;
3503 else
3504 coll_dist = E1000_COLLISION_DISTANCE;
3505
3506 tctl = E1000_READ_REG(hw, TCTL);
3507
3508 tctl &= ~E1000_TCTL_COLD;
3509 tctl |= coll_dist << E1000_COLD_SHIFT;
3510
3511 E1000_WRITE_REG(hw, TCTL, tctl);
3512 E1000_WRITE_FLUSH(hw);
3513}
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524static int
3525e1000_config_mac_to_phy(struct e1000_hw *hw)
3526{
3527 uint32_t ctrl;
3528 uint16_t phy_data;
3529
3530 DEBUGFUNC();
3531
3532
3533
3534
3535 ctrl = E1000_READ_REG(hw, CTRL);
3536 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
3537 ctrl &= ~(E1000_CTRL_ILOS);
3538 ctrl |= (E1000_CTRL_SPD_SEL);
3539
3540
3541
3542
3543 if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
3544 DEBUGOUT("PHY Read Error\n");
3545 return -E1000_ERR_PHY;
3546 }
3547 if (phy_data & M88E1000_PSSR_DPLX)
3548 ctrl |= E1000_CTRL_FD;
3549 else
3550 ctrl &= ~E1000_CTRL_FD;
3551
3552 e1000_config_collision_dist(hw);
3553
3554
3555
3556
3557 if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
3558 ctrl |= E1000_CTRL_SPD_1000;
3559 else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
3560 ctrl |= E1000_CTRL_SPD_100;
3561
3562 E1000_WRITE_REG(hw, CTRL, ctrl);
3563 return 0;
3564}
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577static int
3578e1000_force_mac_fc(struct e1000_hw *hw)
3579{
3580 uint32_t ctrl;
3581
3582 DEBUGFUNC();
3583
3584
3585 ctrl = E1000_READ_REG(hw, CTRL);
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605 switch (hw->fc) {
3606 case e1000_fc_none:
3607 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
3608 break;
3609 case e1000_fc_rx_pause:
3610 ctrl &= (~E1000_CTRL_TFCE);
3611 ctrl |= E1000_CTRL_RFCE;
3612 break;
3613 case e1000_fc_tx_pause:
3614 ctrl &= (~E1000_CTRL_RFCE);
3615 ctrl |= E1000_CTRL_TFCE;
3616 break;
3617 case e1000_fc_full:
3618 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
3619 break;
3620 default:
3621 DEBUGOUT("Flow control param set incorrectly\n");
3622 return -E1000_ERR_CONFIG;
3623 }
3624
3625
3626 if (hw->mac_type == e1000_82542_rev2_0)
3627 ctrl &= (~E1000_CTRL_TFCE);
3628
3629 E1000_WRITE_REG(hw, CTRL, ctrl);
3630 return 0;
3631}
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644static int32_t
3645e1000_config_fc_after_link_up(struct e1000_hw *hw)
3646{
3647 int32_t ret_val;
3648 uint16_t mii_status_reg;
3649 uint16_t mii_nway_adv_reg;
3650 uint16_t mii_nway_lp_ability_reg;
3651 uint16_t speed;
3652 uint16_t duplex;
3653
3654 DEBUGFUNC();
3655
3656
3657
3658
3659
3660 if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
3661 || ((hw->media_type == e1000_media_type_internal_serdes)
3662 && (hw->autoneg_failed))
3663 || ((hw->media_type == e1000_media_type_copper)
3664 && (!hw->autoneg))) {
3665 ret_val = e1000_force_mac_fc(hw);
3666 if (ret_val < 0) {
3667 DEBUGOUT("Error forcing flow control settings\n");
3668 return ret_val;
3669 }
3670 }
3671
3672
3673
3674
3675
3676
3677 if (hw->media_type == e1000_media_type_copper) {
3678
3679
3680
3681
3682 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3683 DEBUGOUT("PHY Read Error\n");
3684 return -E1000_ERR_PHY;
3685 }
3686 if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
3687 DEBUGOUT("PHY Read Error\n");
3688 return -E1000_ERR_PHY;
3689 }
3690
3691 if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
3692
3693
3694
3695
3696
3697
3698 if (e1000_read_phy_reg
3699 (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
3700 DEBUGOUT("PHY Read Error\n");
3701 return -E1000_ERR_PHY;
3702 }
3703 if (e1000_read_phy_reg
3704 (hw, PHY_LP_ABILITY,
3705 &mii_nway_lp_ability_reg) < 0) {
3706 DEBUGOUT("PHY Read Error\n");
3707 return -E1000_ERR_PHY;
3708 }
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3745 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
3746
3747
3748
3749
3750
3751
3752 if (hw->original_fc == e1000_fc_full) {
3753 hw->fc = e1000_fc_full;
3754 DEBUGOUT("Flow Control = FULL.\r\n");
3755 } else {
3756 hw->fc = e1000_fc_rx_pause;
3757 DEBUGOUT
3758 ("Flow Control = RX PAUSE frames only.\r\n");
3759 }
3760 }
3761
3762
3763
3764
3765
3766
3767
3768
3769 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3770 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3771 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3772 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3773 {
3774 hw->fc = e1000_fc_tx_pause;
3775 DEBUGOUT
3776 ("Flow Control = TX PAUSE frames only.\r\n");
3777 }
3778
3779
3780
3781
3782
3783
3784
3785
3786 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
3787 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
3788 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
3789 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
3790 {
3791 hw->fc = e1000_fc_rx_pause;
3792 DEBUGOUT
3793 ("Flow Control = RX PAUSE frames only.\r\n");
3794 }
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815 else if (hw->original_fc == e1000_fc_none ||
3816 hw->original_fc == e1000_fc_tx_pause) {
3817 hw->fc = e1000_fc_none;
3818 DEBUGOUT("Flow Control = NONE.\r\n");
3819 } else {
3820 hw->fc = e1000_fc_rx_pause;
3821 DEBUGOUT
3822 ("Flow Control = RX PAUSE frames only.\r\n");
3823 }
3824
3825
3826
3827
3828
3829 e1000_get_speed_and_duplex(hw, &speed, &duplex);
3830
3831 if (duplex == HALF_DUPLEX)
3832 hw->fc = e1000_fc_none;
3833
3834
3835
3836
3837 ret_val = e1000_force_mac_fc(hw);
3838 if (ret_val < 0) {
3839 DEBUGOUT
3840 ("Error forcing flow control settings\n");
3841 return ret_val;
3842 }
3843 } else {
3844 DEBUGOUT
3845 ("Copper PHY and Auto Neg has not completed.\r\n");
3846 }
3847 }
3848 return E1000_SUCCESS;
3849}
3850
3851
3852
3853
3854
3855
3856
3857
3858static int
3859e1000_check_for_link(struct e1000_hw *hw)
3860{
3861 uint32_t rxcw;
3862 uint32_t ctrl;
3863 uint32_t status;
3864 uint32_t rctl;
3865 uint32_t signal;
3866 int32_t ret_val;
3867 uint16_t phy_data;
3868 uint16_t lp_capability;
3869
3870 DEBUGFUNC();
3871
3872
3873
3874
3875
3876 ctrl = E1000_READ_REG(hw, CTRL);
3877 if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
3878 signal = E1000_CTRL_SWDPIN1;
3879 else
3880 signal = 0;
3881
3882 status = E1000_READ_REG(hw, STATUS);
3883 rxcw = E1000_READ_REG(hw, RXCW);
3884 DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
3885
3886
3887
3888
3889
3890
3891
3892 if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
3893
3894
3895
3896
3897
3898 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3899 DEBUGOUT("PHY Read Error\n");
3900 return -E1000_ERR_PHY;
3901 }
3902 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
3903 DEBUGOUT("PHY Read Error\n");
3904 return -E1000_ERR_PHY;
3905 }
3906
3907 if (phy_data & MII_SR_LINK_STATUS) {
3908 hw->get_link_status = false;
3909 } else {
3910
3911 return -E1000_ERR_NOLINK;
3912 }
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922 if (hw->mac_type >= e1000_82544)
3923 e1000_config_collision_dist(hw);
3924 else {
3925 ret_val = e1000_config_mac_to_phy(hw);
3926 if (ret_val < 0) {
3927 DEBUGOUT
3928 ("Error configuring MAC to PHY settings\n");
3929 return ret_val;
3930 }
3931 }
3932
3933
3934
3935
3936
3937 ret_val = e1000_config_fc_after_link_up(hw);
3938 if (ret_val < 0) {
3939 DEBUGOUT("Error configuring flow control\n");
3940 return ret_val;
3941 }
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952 if (hw->tbi_compatibility_en) {
3953 if (e1000_read_phy_reg
3954 (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
3955 DEBUGOUT("PHY Read Error\n");
3956 return -E1000_ERR_PHY;
3957 }
3958 if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
3959 NWAY_LPAR_10T_FD_CAPS |
3960 NWAY_LPAR_100TX_HD_CAPS |
3961 NWAY_LPAR_100TX_FD_CAPS |
3962 NWAY_LPAR_100T4_CAPS)) {
3963
3964
3965
3966 if (hw->tbi_compatibility_on) {
3967
3968 rctl = E1000_READ_REG(hw, RCTL);
3969 rctl &= ~E1000_RCTL_SBP;
3970 E1000_WRITE_REG(hw, RCTL, rctl);
3971 hw->tbi_compatibility_on = false;
3972 }
3973 } else {
3974
3975
3976
3977
3978
3979 if (!hw->tbi_compatibility_on) {
3980 hw->tbi_compatibility_on = true;
3981 rctl = E1000_READ_REG(hw, RCTL);
3982 rctl |= E1000_RCTL_SBP;
3983 E1000_WRITE_REG(hw, RCTL, rctl);
3984 }
3985 }
3986 }
3987 }
3988
3989
3990
3991
3992
3993
3994
3995 else if ((hw->media_type == e1000_media_type_fiber) &&
3996 (!(status & E1000_STATUS_LU)) &&
3997 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
3998 (!(rxcw & E1000_RXCW_C))) {
3999 if (hw->autoneg_failed == 0) {
4000 hw->autoneg_failed = 1;
4001 return 0;
4002 }
4003 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
4004
4005
4006 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
4007
4008
4009 ctrl = E1000_READ_REG(hw, CTRL);
4010 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
4011 E1000_WRITE_REG(hw, CTRL, ctrl);
4012
4013
4014 ret_val = e1000_config_fc_after_link_up(hw);
4015 if (ret_val < 0) {
4016 DEBUGOUT("Error configuring flow control\n");
4017 return ret_val;
4018 }
4019 }
4020
4021
4022
4023
4024
4025 else if ((hw->media_type == e1000_media_type_fiber) &&
4026 (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
4027 DEBUGOUT
4028 ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
4029 E1000_WRITE_REG(hw, TXCW, hw->txcw);
4030 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
4031 }
4032 return 0;
4033}
4034
4035
4036
4037
4038
4039
4040static int32_t
4041e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
4042{
4043 int32_t ret_val = E1000_SUCCESS;
4044 uint32_t tipg;
4045 uint16_t reg_data;
4046
4047 DEBUGFUNC();
4048
4049 reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
4050 ret_val = e1000_write_kmrn_reg(hw,
4051 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
4052 if (ret_val)
4053 return ret_val;
4054
4055
4056 tipg = E1000_READ_REG(hw, TIPG);
4057 tipg &= ~E1000_TIPG_IPGT_MASK;
4058 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
4059 E1000_WRITE_REG(hw, TIPG, tipg);
4060
4061 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
4062
4063 if (ret_val)
4064 return ret_val;
4065
4066 if (duplex == HALF_DUPLEX)
4067 reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
4068 else
4069 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
4070
4071 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
4072
4073 return ret_val;
4074}
4075
4076static int32_t
4077e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
4078{
4079 int32_t ret_val = E1000_SUCCESS;
4080 uint16_t reg_data;
4081 uint32_t tipg;
4082
4083 DEBUGFUNC();
4084
4085 reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
4086 ret_val = e1000_write_kmrn_reg(hw,
4087 E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
4088 if (ret_val)
4089 return ret_val;
4090
4091
4092 tipg = E1000_READ_REG(hw, TIPG);
4093 tipg &= ~E1000_TIPG_IPGT_MASK;
4094 tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
4095 E1000_WRITE_REG(hw, TIPG, tipg);
4096
4097 ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, ®_data);
4098
4099 if (ret_val)
4100 return ret_val;
4101
4102 reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
4103 ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
4104
4105 return ret_val;
4106}
4107
4108
4109
4110
4111
4112
4113
4114
4115static int
4116e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
4117 uint16_t *duplex)
4118{
4119 uint32_t status;
4120 int32_t ret_val;
4121 uint16_t phy_data;
4122
4123 DEBUGFUNC();
4124
4125 if (hw->mac_type >= e1000_82543) {
4126 status = E1000_READ_REG(hw, STATUS);
4127 if (status & E1000_STATUS_SPEED_1000) {
4128 *speed = SPEED_1000;
4129 DEBUGOUT("1000 Mbs, ");
4130 } else if (status & E1000_STATUS_SPEED_100) {
4131 *speed = SPEED_100;
4132 DEBUGOUT("100 Mbs, ");
4133 } else {
4134 *speed = SPEED_10;
4135 DEBUGOUT("10 Mbs, ");
4136 }
4137
4138 if (status & E1000_STATUS_FD) {
4139 *duplex = FULL_DUPLEX;
4140 DEBUGOUT("Full Duplex\r\n");
4141 } else {
4142 *duplex = HALF_DUPLEX;
4143 DEBUGOUT(" Half Duplex\r\n");
4144 }
4145 } else {
4146 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
4147 *speed = SPEED_1000;
4148 *duplex = FULL_DUPLEX;
4149 }
4150
4151
4152
4153
4154
4155 if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
4156 ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
4157 if (ret_val)
4158 return ret_val;
4159
4160 if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
4161 *duplex = HALF_DUPLEX;
4162 else {
4163 ret_val = e1000_read_phy_reg(hw,
4164 PHY_LP_ABILITY, &phy_data);
4165 if (ret_val)
4166 return ret_val;
4167 if ((*speed == SPEED_100 &&
4168 !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
4169 || (*speed == SPEED_10
4170 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
4171 *duplex = HALF_DUPLEX;
4172 }
4173 }
4174
4175 if ((hw->mac_type == e1000_80003es2lan) &&
4176 (hw->media_type == e1000_media_type_copper)) {
4177 if (*speed == SPEED_1000)
4178 ret_val = e1000_configure_kmrn_for_1000(hw);
4179 else
4180 ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
4181 if (ret_val)
4182 return ret_val;
4183 }
4184 return E1000_SUCCESS;
4185}
4186
4187
4188
4189
4190
4191
4192static int
4193e1000_wait_autoneg(struct e1000_hw *hw)
4194{
4195 uint16_t i;
4196 uint16_t phy_data;
4197
4198 DEBUGFUNC();
4199 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
4200
4201
4202 for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
4203
4204
4205
4206 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4207 DEBUGOUT("PHY Read Error\n");
4208 return -E1000_ERR_PHY;
4209 }
4210 if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
4211 DEBUGOUT("PHY Read Error\n");
4212 return -E1000_ERR_PHY;
4213 }
4214 if (phy_data & MII_SR_AUTONEG_COMPLETE) {
4215 DEBUGOUT("Auto-Neg complete.\n");
4216 return 0;
4217 }
4218 mdelay(100);
4219 }
4220 DEBUGOUT("Auto-Neg timedout.\n");
4221 return -E1000_ERR_TIMEOUT;
4222}
4223
4224
4225
4226
4227
4228
4229
4230static void
4231e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4232{
4233
4234
4235
4236 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
4237 E1000_WRITE_FLUSH(hw);
4238 udelay(2);
4239}
4240
4241
4242
4243
4244
4245
4246
4247static void
4248e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
4249{
4250
4251
4252
4253 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
4254 E1000_WRITE_FLUSH(hw);
4255 udelay(2);
4256}
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267static void
4268e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
4269{
4270 uint32_t ctrl;
4271 uint32_t mask;
4272
4273
4274
4275
4276
4277 mask = 0x01;
4278 mask <<= (count - 1);
4279
4280 ctrl = E1000_READ_REG(hw, CTRL);
4281
4282
4283 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
4284
4285 while (mask) {
4286
4287
4288
4289
4290
4291 if (data & mask)
4292 ctrl |= E1000_CTRL_MDIO;
4293 else
4294 ctrl &= ~E1000_CTRL_MDIO;
4295
4296 E1000_WRITE_REG(hw, CTRL, ctrl);
4297 E1000_WRITE_FLUSH(hw);
4298
4299 udelay(2);
4300
4301 e1000_raise_mdi_clk(hw, &ctrl);
4302 e1000_lower_mdi_clk(hw, &ctrl);
4303
4304 mask = mask >> 1;
4305 }
4306}
4307
4308
4309
4310
4311
4312
4313
4314
4315static uint16_t
4316e1000_shift_in_mdi_bits(struct e1000_hw *hw)
4317{
4318 uint32_t ctrl;
4319 uint16_t data = 0;
4320 uint8_t i;
4321
4322
4323
4324
4325
4326
4327
4328
4329 ctrl = E1000_READ_REG(hw, CTRL);
4330
4331
4332 ctrl &= ~E1000_CTRL_MDIO_DIR;
4333 ctrl &= ~E1000_CTRL_MDIO;
4334
4335 E1000_WRITE_REG(hw, CTRL, ctrl);
4336 E1000_WRITE_FLUSH(hw);
4337
4338
4339
4340
4341
4342 e1000_raise_mdi_clk(hw, &ctrl);
4343 e1000_lower_mdi_clk(hw, &ctrl);
4344
4345 for (data = 0, i = 0; i < 16; i++) {
4346 data = data << 1;
4347 e1000_raise_mdi_clk(hw, &ctrl);
4348 ctrl = E1000_READ_REG(hw, CTRL);
4349
4350 if (ctrl & E1000_CTRL_MDIO)
4351 data |= 1;
4352 e1000_lower_mdi_clk(hw, &ctrl);
4353 }
4354
4355 e1000_raise_mdi_clk(hw, &ctrl);
4356 e1000_lower_mdi_clk(hw, &ctrl);
4357
4358 return data;
4359}
4360
4361
4362
4363
4364
4365
4366
4367static int
4368e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
4369{
4370 uint32_t i;
4371 uint32_t mdic = 0;
4372 const uint32_t phy_addr = 1;
4373
4374 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4375 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4376 return -E1000_ERR_PARAM;
4377 }
4378
4379 if (hw->mac_type > e1000_82543) {
4380
4381
4382
4383
4384 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
4385 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4386 (E1000_MDIC_OP_READ));
4387
4388 E1000_WRITE_REG(hw, MDIC, mdic);
4389
4390
4391 for (i = 0; i < 64; i++) {
4392 udelay(10);
4393 mdic = E1000_READ_REG(hw, MDIC);
4394 if (mdic & E1000_MDIC_READY)
4395 break;
4396 }
4397 if (!(mdic & E1000_MDIC_READY)) {
4398 DEBUGOUT("MDI Read did not complete\n");
4399 return -E1000_ERR_PHY;
4400 }
4401 if (mdic & E1000_MDIC_ERROR) {
4402 DEBUGOUT("MDI Error\n");
4403 return -E1000_ERR_PHY;
4404 }
4405 *phy_data = (uint16_t) mdic;
4406 } else {
4407
4408
4409
4410
4411 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424 mdic = ((reg_addr) | (phy_addr << 5) |
4425 (PHY_OP_READ << 10) | (PHY_SOF << 12));
4426
4427 e1000_shift_out_mdi_bits(hw, mdic, 14);
4428
4429
4430
4431
4432
4433 *phy_data = e1000_shift_in_mdi_bits(hw);
4434 }
4435 return 0;
4436}
4437
4438
4439
4440
4441
4442
4443
4444
4445static int
4446e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
4447{
4448 uint32_t i;
4449 uint32_t mdic = 0;
4450 const uint32_t phy_addr = 1;
4451
4452 if (reg_addr > MAX_PHY_REG_ADDRESS) {
4453 DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
4454 return -E1000_ERR_PARAM;
4455 }
4456
4457 if (hw->mac_type > e1000_82543) {
4458
4459
4460
4461
4462 mdic = (((uint32_t) phy_data) |
4463 (reg_addr << E1000_MDIC_REG_SHIFT) |
4464 (phy_addr << E1000_MDIC_PHY_SHIFT) |
4465 (E1000_MDIC_OP_WRITE));
4466
4467 E1000_WRITE_REG(hw, MDIC, mdic);
4468
4469
4470 for (i = 0; i < 64; i++) {
4471 udelay(10);
4472 mdic = E1000_READ_REG(hw, MDIC);
4473 if (mdic & E1000_MDIC_READY)
4474 break;
4475 }
4476 if (!(mdic & E1000_MDIC_READY)) {
4477 DEBUGOUT("MDI Write did not complete\n");
4478 return -E1000_ERR_PHY;
4479 }
4480 } else {
4481
4482
4483
4484
4485
4486 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
4487
4488
4489
4490
4491
4492
4493
4494 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
4495 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
4496 mdic <<= 16;
4497 mdic |= (uint32_t) phy_data;
4498
4499 e1000_shift_out_mdi_bits(hw, mdic, 32);
4500 }
4501 return 0;
4502}
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515int32_t
4516e1000_check_phy_reset_block(struct e1000_hw *hw)
4517{
4518 uint32_t manc = 0;
4519 uint32_t fwsm = 0;
4520
4521 if (hw->mac_type == e1000_ich8lan) {
4522 fwsm = E1000_READ_REG(hw, FWSM);
4523 return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
4524 : E1000_BLK_PHY_RESET;
4525 }
4526
4527 if (hw->mac_type > e1000_82547_rev_2)
4528 manc = E1000_READ_REG(hw, MANC);
4529 return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
4530 E1000_BLK_PHY_RESET : E1000_SUCCESS;
4531}
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542static int32_t
4543e1000_get_phy_cfg_done(struct e1000_hw *hw)
4544{
4545 int32_t timeout = PHY_CFG_TIMEOUT;
4546 uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
4547
4548 DEBUGFUNC();
4549
4550 switch (hw->mac_type) {
4551 default:
4552 mdelay(10);
4553 break;
4554
4555 case e1000_80003es2lan:
4556
4557 if (e1000_is_second_port(hw))
4558 cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
4559
4560
4561 case e1000_82571:
4562 case e1000_82572:
4563 case e1000_igb:
4564 while (timeout) {
4565 if (hw->mac_type == e1000_igb) {
4566 if (E1000_READ_REG(hw, I210_EEMNGCTL) & cfg_mask)
4567 break;
4568 } else {
4569 if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
4570 break;
4571 }
4572 mdelay(1);
4573 timeout--;
4574 }
4575 if (!timeout) {
4576 DEBUGOUT("MNG configuration cycle has not "
4577 "completed.\n");
4578 return -E1000_ERR_RESET;
4579 }
4580 break;
4581 }
4582
4583 return E1000_SUCCESS;
4584}
4585
4586
4587
4588
4589
4590
4591int32_t
4592e1000_phy_hw_reset(struct e1000_hw *hw)
4593{
4594 uint16_t swfw = E1000_SWFW_PHY0_SM;
4595 uint32_t ctrl, ctrl_ext;
4596 uint32_t led_ctrl;
4597 int32_t ret_val;
4598
4599 DEBUGFUNC();
4600
4601
4602
4603 ret_val = e1000_check_phy_reset_block(hw);
4604 if (ret_val)
4605 return E1000_SUCCESS;
4606
4607 DEBUGOUT("Resetting Phy...\n");
4608
4609 if (hw->mac_type > e1000_82543) {
4610 if (e1000_is_second_port(hw))
4611 swfw = E1000_SWFW_PHY1_SM;
4612
4613 if (e1000_swfw_sync_acquire(hw, swfw)) {
4614 DEBUGOUT("Unable to acquire swfw sync\n");
4615 return -E1000_ERR_SWFW_SYNC;
4616 }
4617
4618
4619
4620
4621 ctrl = E1000_READ_REG(hw, CTRL);
4622 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
4623 E1000_WRITE_FLUSH(hw);
4624
4625 if (hw->mac_type < e1000_82571)
4626 udelay(10);
4627 else
4628 udelay(100);
4629
4630 E1000_WRITE_REG(hw, CTRL, ctrl);
4631 E1000_WRITE_FLUSH(hw);
4632
4633 if (hw->mac_type >= e1000_82571)
4634 mdelay(10);
4635
4636 } else {
4637
4638
4639
4640 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
4641 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
4642 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
4643 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4644 E1000_WRITE_FLUSH(hw);
4645 mdelay(10);
4646 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
4647 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
4648 E1000_WRITE_FLUSH(hw);
4649 }
4650 udelay(150);
4651
4652 if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
4653
4654 led_ctrl = E1000_READ_REG(hw, LEDCTL);
4655 led_ctrl &= IGP_ACTIVITY_LED_MASK;
4656 led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
4657 E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
4658 }
4659
4660 e1000_swfw_sync_release(hw, swfw);
4661
4662
4663 ret_val = e1000_get_phy_cfg_done(hw);
4664 if (ret_val != E1000_SUCCESS)
4665 return ret_val;
4666
4667 return ret_val;
4668}
4669
4670
4671
4672
4673
4674
4675static void
4676e1000_phy_init_script(struct e1000_hw *hw)
4677{
4678 uint32_t ret_val;
4679 uint16_t phy_saved_data;
4680 DEBUGFUNC();
4681
4682 if (hw->phy_init_script) {
4683 mdelay(20);
4684
4685
4686
4687 ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
4688
4689
4690 e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
4691
4692 mdelay(20);
4693
4694 e1000_write_phy_reg(hw, 0x0000, 0x0140);
4695
4696 mdelay(5);
4697
4698 switch (hw->mac_type) {
4699 case e1000_82541:
4700 case e1000_82547:
4701 e1000_write_phy_reg(hw, 0x1F95, 0x0001);
4702
4703 e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
4704
4705 e1000_write_phy_reg(hw, 0x1F79, 0x0018);
4706
4707 e1000_write_phy_reg(hw, 0x1F30, 0x1600);
4708
4709 e1000_write_phy_reg(hw, 0x1F31, 0x0014);
4710
4711 e1000_write_phy_reg(hw, 0x1F32, 0x161C);
4712
4713 e1000_write_phy_reg(hw, 0x1F94, 0x0003);
4714
4715 e1000_write_phy_reg(hw, 0x1F96, 0x003F);
4716
4717 e1000_write_phy_reg(hw, 0x2010, 0x0008);
4718 break;
4719
4720 case e1000_82541_rev_2:
4721 case e1000_82547_rev_2:
4722 e1000_write_phy_reg(hw, 0x1F73, 0x0099);
4723 break;
4724 default:
4725 break;
4726 }
4727
4728 e1000_write_phy_reg(hw, 0x0000, 0x3300);
4729
4730 mdelay(20);
4731
4732
4733 if (!ret_val)
4734 e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
4735
4736 if (hw->mac_type == e1000_82547) {
4737 uint16_t fused, fine, coarse;
4738
4739
4740 e1000_read_phy_reg(hw,
4741 IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
4742
4743 if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
4744 e1000_read_phy_reg(hw,
4745 IGP01E1000_ANALOG_FUSE_STATUS, &fused);
4746
4747 fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
4748 coarse = fused
4749 & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
4750
4751 if (coarse >
4752 IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
4753 coarse -=
4754 IGP01E1000_ANALOG_FUSE_COARSE_10;
4755 fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
4756 } else if (coarse
4757 == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
4758 fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
4759
4760 fused = (fused
4761 & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
4762 (fine
4763 & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
4764 (coarse
4765 & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
4766
4767 e1000_write_phy_reg(hw,
4768 IGP01E1000_ANALOG_FUSE_CONTROL, fused);
4769 e1000_write_phy_reg(hw,
4770 IGP01E1000_ANALOG_FUSE_BYPASS,
4771 IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
4772 }
4773 }
4774 }
4775}
4776
4777
4778
4779
4780
4781
4782
4783
4784int32_t
4785e1000_phy_reset(struct e1000_hw *hw)
4786{
4787 int32_t ret_val;
4788 uint16_t phy_data;
4789
4790 DEBUGFUNC();
4791
4792
4793
4794 ret_val = e1000_check_phy_reset_block(hw);
4795 if (ret_val)
4796 return E1000_SUCCESS;
4797
4798 switch (hw->phy_type) {
4799 case e1000_phy_igp:
4800 case e1000_phy_igp_2:
4801 case e1000_phy_igp_3:
4802 case e1000_phy_ife:
4803 case e1000_phy_igb:
4804 ret_val = e1000_phy_hw_reset(hw);
4805 if (ret_val)
4806 return ret_val;
4807 break;
4808 default:
4809 ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
4810 if (ret_val)
4811 return ret_val;
4812
4813 phy_data |= MII_CR_RESET;
4814 ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
4815 if (ret_val)
4816 return ret_val;
4817
4818 udelay(1);
4819 break;
4820 }
4821
4822 if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
4823 e1000_phy_init_script(hw);
4824
4825 return E1000_SUCCESS;
4826}
4827
4828static int e1000_set_phy_type (struct e1000_hw *hw)
4829{
4830 DEBUGFUNC ();
4831
4832 if (hw->mac_type == e1000_undefined)
4833 return -E1000_ERR_PHY_TYPE;
4834
4835 switch (hw->phy_id) {
4836 case M88E1000_E_PHY_ID:
4837 case M88E1000_I_PHY_ID:
4838 case M88E1011_I_PHY_ID:
4839 case M88E1111_I_PHY_ID:
4840 hw->phy_type = e1000_phy_m88;
4841 break;
4842 case IGP01E1000_I_PHY_ID:
4843 if (hw->mac_type == e1000_82541 ||
4844 hw->mac_type == e1000_82541_rev_2 ||
4845 hw->mac_type == e1000_82547 ||
4846 hw->mac_type == e1000_82547_rev_2) {
4847 hw->phy_type = e1000_phy_igp;
4848 break;
4849 }
4850 case IGP03E1000_E_PHY_ID:
4851 hw->phy_type = e1000_phy_igp_3;
4852 break;
4853 case IFE_E_PHY_ID:
4854 case IFE_PLUS_E_PHY_ID:
4855 case IFE_C_E_PHY_ID:
4856 hw->phy_type = e1000_phy_ife;
4857 break;
4858 case GG82563_E_PHY_ID:
4859 if (hw->mac_type == e1000_80003es2lan) {
4860 hw->phy_type = e1000_phy_gg82563;
4861 break;
4862 }
4863 case BME1000_E_PHY_ID:
4864 hw->phy_type = e1000_phy_bm;
4865 break;
4866 case I210_I_PHY_ID:
4867 hw->phy_type = e1000_phy_igb;
4868 break;
4869
4870 default:
4871
4872 hw->phy_type = e1000_phy_undefined;
4873 return -E1000_ERR_PHY_TYPE;
4874 }
4875
4876 return E1000_SUCCESS;
4877}
4878
4879
4880
4881
4882
4883
4884static int32_t
4885e1000_detect_gig_phy(struct e1000_hw *hw)
4886{
4887 int32_t phy_init_status, ret_val;
4888 uint16_t phy_id_high, phy_id_low;
4889 bool match = false;
4890
4891 DEBUGFUNC();
4892
4893
4894
4895
4896 if (hw->mac_type == e1000_82571 ||
4897 hw->mac_type == e1000_82572) {
4898 hw->phy_id = IGP01E1000_I_PHY_ID;
4899 hw->phy_type = e1000_phy_igp_2;
4900 return E1000_SUCCESS;
4901 }
4902
4903
4904
4905
4906
4907
4908
4909 if (hw->mac_type == e1000_80003es2lan)
4910 hw->phy_type = e1000_phy_gg82563;
4911
4912
4913 ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
4914 if (ret_val)
4915 return ret_val;
4916
4917 hw->phy_id = (uint32_t) (phy_id_high << 16);
4918 udelay(20);
4919 ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
4920 if (ret_val)
4921 return ret_val;
4922
4923 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
4924 hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
4925
4926 switch (hw->mac_type) {
4927 case e1000_82543:
4928 if (hw->phy_id == M88E1000_E_PHY_ID)
4929 match = true;
4930 break;
4931 case e1000_82544:
4932 if (hw->phy_id == M88E1000_I_PHY_ID)
4933 match = true;
4934 break;
4935 case e1000_82540:
4936 case e1000_82545:
4937 case e1000_82545_rev_3:
4938 case e1000_82546:
4939 case e1000_82546_rev_3:
4940 if (hw->phy_id == M88E1011_I_PHY_ID)
4941 match = true;
4942 break;
4943 case e1000_82541:
4944 case e1000_82541_rev_2:
4945 case e1000_82547:
4946 case e1000_82547_rev_2:
4947 if(hw->phy_id == IGP01E1000_I_PHY_ID)
4948 match = true;
4949
4950 break;
4951 case e1000_82573:
4952 if (hw->phy_id == M88E1111_I_PHY_ID)
4953 match = true;
4954 break;
4955 case e1000_82574:
4956 if (hw->phy_id == BME1000_E_PHY_ID)
4957 match = true;
4958 break;
4959 case e1000_80003es2lan:
4960 if (hw->phy_id == GG82563_E_PHY_ID)
4961 match = true;
4962 break;
4963 case e1000_ich8lan:
4964 if (hw->phy_id == IGP03E1000_E_PHY_ID)
4965 match = true;
4966 if (hw->phy_id == IFE_E_PHY_ID)
4967 match = true;
4968 if (hw->phy_id == IFE_PLUS_E_PHY_ID)
4969 match = true;
4970 if (hw->phy_id == IFE_C_E_PHY_ID)
4971 match = true;
4972 break;
4973 case e1000_igb:
4974 if (hw->phy_id == I210_I_PHY_ID)
4975 match = true;
4976 break;
4977 default:
4978 DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
4979 return -E1000_ERR_CONFIG;
4980 }
4981
4982 phy_init_status = e1000_set_phy_type(hw);
4983
4984 if ((match) && (phy_init_status == E1000_SUCCESS)) {
4985 DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
4986 return 0;
4987 }
4988 DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
4989 return -E1000_ERR_PHY;
4990}
4991
4992
4993
4994
4995
4996
4997void
4998e1000_set_media_type(struct e1000_hw *hw)
4999{
5000 uint32_t status;
5001
5002 DEBUGFUNC();
5003
5004 if (hw->mac_type != e1000_82543) {
5005
5006 hw->tbi_compatibility_en = false;
5007 }
5008
5009 switch (hw->device_id) {
5010 case E1000_DEV_ID_82545GM_SERDES:
5011 case E1000_DEV_ID_82546GB_SERDES:
5012 case E1000_DEV_ID_82571EB_SERDES:
5013 case E1000_DEV_ID_82571EB_SERDES_DUAL:
5014 case E1000_DEV_ID_82571EB_SERDES_QUAD:
5015 case E1000_DEV_ID_82572EI_SERDES:
5016 case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
5017 hw->media_type = e1000_media_type_internal_serdes;
5018 break;
5019 default:
5020 switch (hw->mac_type) {
5021 case e1000_82542_rev2_0:
5022 case e1000_82542_rev2_1:
5023 hw->media_type = e1000_media_type_fiber;
5024 break;
5025 case e1000_ich8lan:
5026 case e1000_82573:
5027 case e1000_82574:
5028 case e1000_igb:
5029
5030
5031
5032 hw->media_type = e1000_media_type_copper;
5033 break;
5034 default:
5035 status = E1000_READ_REG(hw, STATUS);
5036 if (status & E1000_STATUS_TBIMODE) {
5037 hw->media_type = e1000_media_type_fiber;
5038
5039 hw->tbi_compatibility_en = false;
5040 } else {
5041 hw->media_type = e1000_media_type_copper;
5042 }
5043 break;
5044 }
5045 }
5046}
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056static int
5057e1000_sw_init(struct e1000_hw *hw)
5058{
5059 int result;
5060
5061
5062#ifdef CONFIG_DM_ETH
5063 dm_pci_read_config16(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
5064 dm_pci_read_config16(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
5065 dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
5066 &hw->subsystem_vendor_id);
5067 dm_pci_read_config16(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
5068
5069 dm_pci_read_config8(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
5070 dm_pci_read_config16(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
5071#else
5072 pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
5073 pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
5074 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
5075 &hw->subsystem_vendor_id);
5076 pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
5077
5078 pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
5079 pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
5080#endif
5081
5082
5083 result = e1000_set_mac_type(hw);
5084 if (result) {
5085 E1000_ERR(hw, "Unknown MAC Type\n");
5086 return result;
5087 }
5088
5089 switch (hw->mac_type) {
5090 default:
5091 break;
5092 case e1000_82541:
5093 case e1000_82547:
5094 case e1000_82541_rev_2:
5095 case e1000_82547_rev_2:
5096 hw->phy_init_script = 1;
5097 break;
5098 }
5099
5100
5101 hw->fc_high_water = E1000_FC_HIGH_THRESH;
5102 hw->fc_low_water = E1000_FC_LOW_THRESH;
5103 hw->fc_pause_time = E1000_FC_PAUSE_TIME;
5104 hw->fc_send_xon = 1;
5105
5106
5107 hw->tbi_compatibility_en = true;
5108 e1000_set_media_type(hw);
5109
5110 if (hw->mac_type >= e1000_82543) {
5111 uint32_t status = E1000_READ_REG(hw, STATUS);
5112
5113 if (status & E1000_STATUS_TBIMODE) {
5114 DEBUGOUT("fiber interface\n");
5115 hw->media_type = e1000_media_type_fiber;
5116 } else {
5117 DEBUGOUT("copper interface\n");
5118 hw->media_type = e1000_media_type_copper;
5119 }
5120 } else {
5121 hw->media_type = e1000_media_type_fiber;
5122 }
5123
5124 hw->wait_autoneg_complete = true;
5125 if (hw->mac_type < e1000_82543)
5126 hw->report_tx_early = 0;
5127 else
5128 hw->report_tx_early = 1;
5129
5130 return E1000_SUCCESS;
5131}
5132
5133void
5134fill_rx(struct e1000_hw *hw)
5135{
5136 struct e1000_rx_desc *rd;
5137 unsigned long flush_start, flush_end;
5138
5139 rx_last = rx_tail;
5140 rd = rx_base + rx_tail;
5141 rx_tail = (rx_tail + 1) % 8;
5142 memset(rd, 0, 16);
5143 rd->buffer_addr = cpu_to_le64((unsigned long)packet);
5144
5145
5146
5147
5148
5149
5150 invalidate_dcache_range((unsigned long)packet,
5151 (unsigned long)packet + 4096);
5152
5153 flush_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
5154 flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5155 flush_dcache_range(flush_start, flush_end);
5156
5157 E1000_WRITE_REG(hw, RDT, rx_tail);
5158}
5159
5160
5161
5162
5163
5164
5165
5166
5167static void
5168e1000_configure_tx(struct e1000_hw *hw)
5169{
5170 unsigned long tctl;
5171 unsigned long tipg, tarc;
5172 uint32_t ipgr1, ipgr2;
5173
5174 E1000_WRITE_REG(hw, TDBAL, lower_32_bits((unsigned long)tx_base));
5175 E1000_WRITE_REG(hw, TDBAH, upper_32_bits((unsigned long)tx_base));
5176
5177 E1000_WRITE_REG(hw, TDLEN, 128);
5178
5179
5180 E1000_WRITE_REG(hw, TDH, 0);
5181 E1000_WRITE_REG(hw, TDT, 0);
5182 tx_tail = 0;
5183
5184
5185 if (hw->mac_type <= e1000_82547_rev_2 &&
5186 (hw->media_type == e1000_media_type_fiber ||
5187 hw->media_type == e1000_media_type_internal_serdes))
5188 tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
5189 else
5190 tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
5191
5192
5193 switch (hw->mac_type) {
5194 case e1000_82542_rev2_0:
5195 case e1000_82542_rev2_1:
5196 tipg = DEFAULT_82542_TIPG_IPGT;
5197 ipgr1 = DEFAULT_82542_TIPG_IPGR1;
5198 ipgr2 = DEFAULT_82542_TIPG_IPGR2;
5199 break;
5200 case e1000_80003es2lan:
5201 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
5202 ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
5203 break;
5204 default:
5205 ipgr1 = DEFAULT_82543_TIPG_IPGR1;
5206 ipgr2 = DEFAULT_82543_TIPG_IPGR2;
5207 break;
5208 }
5209 tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
5210 tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
5211 E1000_WRITE_REG(hw, TIPG, tipg);
5212
5213 tctl = E1000_READ_REG(hw, TCTL);
5214 tctl &= ~E1000_TCTL_CT;
5215 tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
5216 (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
5217
5218 if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
5219 tarc = E1000_READ_REG(hw, TARC0);
5220
5221
5222
5223 } else if (hw->mac_type == e1000_80003es2lan) {
5224 tarc = E1000_READ_REG(hw, TARC0);
5225 tarc |= 1;
5226 E1000_WRITE_REG(hw, TARC0, tarc);
5227 tarc = E1000_READ_REG(hw, TARC1);
5228 tarc |= 1;
5229 E1000_WRITE_REG(hw, TARC1, tarc);
5230 }
5231
5232
5233 e1000_config_collision_dist(hw);
5234
5235 hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
5236
5237
5238 if (hw->mac_type < e1000_82543)
5239 hw->txd_cmd |= E1000_TXD_CMD_RPS;
5240 else
5241 hw->txd_cmd |= E1000_TXD_CMD_RS;
5242
5243
5244 if (hw->mac_type == e1000_igb) {
5245 E1000_WRITE_REG(hw, TCTL_EXT, 0x42 << 10);
5246
5247 uint32_t reg_txdctl = E1000_READ_REG(hw, TXDCTL);
5248 reg_txdctl |= 1 << 25;
5249 E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
5250 mdelay(20);
5251 }
5252
5253
5254
5255 E1000_WRITE_REG(hw, TCTL, tctl);
5256
5257
5258}
5259
5260
5261
5262
5263
5264static void
5265e1000_setup_rctl(struct e1000_hw *hw)
5266{
5267 uint32_t rctl;
5268
5269 rctl = E1000_READ_REG(hw, RCTL);
5270
5271 rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
5272
5273 rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO
5274 | E1000_RCTL_RDMTS_HALF;
5275
5276
5277 if (hw->tbi_compatibility_on == 1)
5278 rctl |= E1000_RCTL_SBP;
5279 else
5280 rctl &= ~E1000_RCTL_SBP;
5281
5282 rctl &= ~(E1000_RCTL_SZ_4096);
5283 rctl |= E1000_RCTL_SZ_2048;
5284 rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
5285 E1000_WRITE_REG(hw, RCTL, rctl);
5286}
5287
5288
5289
5290
5291
5292
5293
5294static void
5295e1000_configure_rx(struct e1000_hw *hw)
5296{
5297 unsigned long rctl, ctrl_ext;
5298 rx_tail = 0;
5299
5300
5301 rctl = E1000_READ_REG(hw, RCTL);
5302 E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
5303 if (hw->mac_type >= e1000_82540) {
5304
5305
5306#define MAX_INTS_PER_SEC 8000
5307#define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
5308 E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
5309 }
5310
5311 if (hw->mac_type >= e1000_82571) {
5312 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
5313
5314 ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
5315 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
5316 E1000_WRITE_FLUSH(hw);
5317 }
5318
5319 E1000_WRITE_REG(hw, RDBAL, lower_32_bits((unsigned long)rx_base));
5320 E1000_WRITE_REG(hw, RDBAH, upper_32_bits((unsigned long)rx_base));
5321
5322 E1000_WRITE_REG(hw, RDLEN, 128);
5323
5324
5325 E1000_WRITE_REG(hw, RDH, 0);
5326 E1000_WRITE_REG(hw, RDT, 0);
5327
5328
5329 if (hw->mac_type == e1000_igb) {
5330
5331 uint32_t reg_rxdctl = E1000_READ_REG(hw, RXDCTL);
5332 reg_rxdctl |= 1 << 25;
5333 E1000_WRITE_REG(hw, RXDCTL, reg_rxdctl);
5334 mdelay(20);
5335 }
5336
5337 E1000_WRITE_REG(hw, RCTL, rctl);
5338
5339 fill_rx(hw);
5340}
5341
5342
5343
5344
5345static int
5346_e1000_poll(struct e1000_hw *hw)
5347{
5348 struct e1000_rx_desc *rd;
5349 unsigned long inval_start, inval_end;
5350 uint32_t len;
5351
5352
5353 rd = rx_base + rx_last;
5354
5355
5356 inval_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
5357 inval_end = inval_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
5358 invalidate_dcache_range(inval_start, inval_end);
5359
5360 if (!(rd->status & E1000_RXD_STAT_DD))
5361 return 0;
5362
5363
5364 len = le16_to_cpu(rd->length);
5365 invalidate_dcache_range((unsigned long)packet,
5366 (unsigned long)packet +
5367 roundup(len, ARCH_DMA_MINALIGN));
5368 return len;
5369}
5370
5371static int _e1000_transmit(struct e1000_hw *hw, void *txpacket, int length)
5372{
5373 void *nv_packet = (void *)txpacket;
5374 struct e1000_tx_desc *txp;
5375 int i = 0;
5376 unsigned long flush_start, flush_end;
5377
5378 txp = tx_base + tx_tail;
5379 tx_tail = (tx_tail + 1) % 8;
5380
5381 txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
5382 txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
5383 txp->upper.data = 0;
5384
5385
5386 flush_dcache_range((unsigned long)nv_packet,
5387 (unsigned long)nv_packet +
5388 roundup(length, ARCH_DMA_MINALIGN));
5389
5390 flush_start = ((unsigned long)txp) & ~(ARCH_DMA_MINALIGN - 1);
5391 flush_end = flush_start + roundup(sizeof(*txp), ARCH_DMA_MINALIGN);
5392 flush_dcache_range(flush_start, flush_end);
5393
5394 E1000_WRITE_REG(hw, TDT, tx_tail);
5395
5396 E1000_WRITE_FLUSH(hw);
5397 while (1) {
5398 invalidate_dcache_range(flush_start, flush_end);
5399 if (le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)
5400 break;
5401 if (i++ > TOUT_LOOP) {
5402 DEBUGOUT("e1000: tx timeout\n");
5403 return 0;
5404 }
5405 udelay(10);
5406 }
5407 return 1;
5408}
5409
5410static void
5411_e1000_disable(struct e1000_hw *hw)
5412{
5413
5414 E1000_WRITE_REG(hw, RCTL, 0);
5415 E1000_WRITE_REG(hw, TCTL, 0);
5416
5417
5418 E1000_WRITE_REG(hw, TDH, 0);
5419 E1000_WRITE_REG(hw, TDT, 0);
5420
5421
5422 E1000_WRITE_REG(hw, RDH, 0);
5423 E1000_WRITE_REG(hw, RDT, 0);
5424
5425 mdelay(10);
5426}
5427
5428
5429static inline int
5430e1000_reset(struct e1000_hw *hw, unsigned char enetaddr[6])
5431{
5432 e1000_reset_hw(hw);
5433 if (hw->mac_type >= e1000_82544)
5434 E1000_WRITE_REG(hw, WUC, 0);
5435
5436 return e1000_init_hw(hw, enetaddr);
5437}
5438
5439static int
5440_e1000_init(struct e1000_hw *hw, unsigned char enetaddr[6])
5441{
5442 int ret_val = 0;
5443
5444 ret_val = e1000_reset(hw, enetaddr);
5445 if (ret_val < 0) {
5446 if ((ret_val == -E1000_ERR_NOLINK) ||
5447 (ret_val == -E1000_ERR_TIMEOUT)) {
5448 E1000_ERR(hw, "Valid Link not detected: %d\n", ret_val);
5449 } else {
5450 E1000_ERR(hw, "Hardware Initialization Failed\n");
5451 }
5452 return ret_val;
5453 }
5454 e1000_configure_tx(hw);
5455 e1000_setup_rctl(hw);
5456 e1000_configure_rx(hw);
5457 return 0;
5458}
5459
5460
5461
5462
5463
5464
5465void e1000_get_bus_type(struct e1000_hw *hw)
5466{
5467 uint32_t status;
5468
5469 switch (hw->mac_type) {
5470 case e1000_82542_rev2_0:
5471 case e1000_82542_rev2_1:
5472 hw->bus_type = e1000_bus_type_pci;
5473 break;
5474 case e1000_82571:
5475 case e1000_82572:
5476 case e1000_82573:
5477 case e1000_82574:
5478 case e1000_80003es2lan:
5479 case e1000_ich8lan:
5480 case e1000_igb:
5481 hw->bus_type = e1000_bus_type_pci_express;
5482 break;
5483 default:
5484 status = E1000_READ_REG(hw, STATUS);
5485 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
5486 e1000_bus_type_pcix : e1000_bus_type_pci;
5487 break;
5488 }
5489}
5490
5491#ifndef CONFIG_DM_ETH
5492
5493static LIST_HEAD(e1000_hw_list);
5494#endif
5495
5496#ifdef CONFIG_DM_ETH
5497static int e1000_init_one(struct e1000_hw *hw, int cardnum,
5498 struct udevice *devno, unsigned char enetaddr[6])
5499#else
5500static int e1000_init_one(struct e1000_hw *hw, int cardnum, pci_dev_t devno,
5501 unsigned char enetaddr[6])
5502#endif
5503{
5504 u32 val;
5505
5506
5507#ifdef CONFIG_DM_ETH
5508 hw->pdev = devno;
5509#else
5510 hw->pdev = devno;
5511#endif
5512 hw->cardnum = cardnum;
5513
5514
5515#ifdef CONFIG_DM_ETH
5516 dm_pci_read_config32(devno, PCI_BASE_ADDRESS_0, &val);
5517#else
5518 pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val);
5519#endif
5520 E1000_DBG(hw, "iobase 0x%08x\n", val & 0xfffffff0);
5521
5522
5523 val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
5524#ifdef CONFIG_DM_ETH
5525 dm_pci_write_config32(devno, PCI_COMMAND, val);
5526#else
5527 pci_write_config_dword(devno, PCI_COMMAND, val);
5528#endif
5529
5530
5531#ifdef CONFIG_DM_ETH
5532 dm_pci_read_config32(devno, PCI_COMMAND, &val);
5533#else
5534 pci_read_config_dword(devno, PCI_COMMAND, &val);
5535#endif
5536 if (!(val & PCI_COMMAND_MEMORY)) {
5537 E1000_ERR(hw, "Can't enable I/O memory\n");
5538 return -ENOSPC;
5539 }
5540 if (!(val & PCI_COMMAND_MASTER)) {
5541 E1000_ERR(hw, "Can't enable bus-mastering\n");
5542 return -EPERM;
5543 }
5544
5545
5546 hw->fc = e1000_fc_default;
5547 hw->original_fc = e1000_fc_default;
5548 hw->autoneg_failed = 0;
5549 hw->autoneg = 1;
5550 hw->get_link_status = true;
5551#ifndef CONFIG_E1000_NO_NVM
5552 hw->eeprom_semaphore_present = true;
5553#endif
5554#ifdef CONFIG_DM_ETH
5555 hw->hw_addr = dm_pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5556 PCI_REGION_MEM);
5557#else
5558 hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
5559 PCI_REGION_MEM);
5560#endif
5561 hw->mac_type = e1000_undefined;
5562
5563
5564 if (e1000_sw_init(hw) < 0) {
5565 E1000_ERR(hw, "Software init failed\n");
5566 return -EIO;
5567 }
5568 if (e1000_check_phy_reset_block(hw))
5569 E1000_ERR(hw, "PHY Reset is blocked!\n");
5570
5571
5572 e1000_reset_hw(hw);
5573
5574#ifndef CONFIG_E1000_NO_NVM
5575
5576 if (e1000_init_eeprom_params(hw)) {
5577 E1000_ERR(hw, "EEPROM is invalid!\n");
5578 return -EINVAL;
5579 }
5580 if ((E1000_READ_REG(hw, I210_EECD) & E1000_EECD_FLUPD) &&
5581 e1000_validate_eeprom_checksum(hw))
5582 return -ENXIO;
5583 e1000_read_mac_addr(hw, enetaddr);
5584#endif
5585 e1000_get_bus_type(hw);
5586
5587#ifndef CONFIG_E1000_NO_NVM
5588 printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
5589 enetaddr[0], enetaddr[1], enetaddr[2],
5590 enetaddr[3], enetaddr[4], enetaddr[5]);
5591#else
5592 memset(enetaddr, 0, 6);
5593 printf("e1000: no NVM\n");
5594#endif
5595
5596 return 0;
5597}
5598
5599
5600static void e1000_name(char *str, int cardnum)
5601{
5602 sprintf(str, "e1000#%u", cardnum);
5603}
5604
5605#ifndef CONFIG_DM_ETH
5606
5607
5608
5609static int e1000_transmit(struct eth_device *nic, void *txpacket, int length)
5610{
5611 struct e1000_hw *hw = nic->priv;
5612
5613 return _e1000_transmit(hw, txpacket, length);
5614}
5615
5616
5617
5618
5619static void
5620e1000_disable(struct eth_device *nic)
5621{
5622 struct e1000_hw *hw = nic->priv;
5623
5624 _e1000_disable(hw);
5625}
5626
5627
5628
5629
5630static int
5631e1000_init(struct eth_device *nic, bd_t *bis)
5632{
5633 struct e1000_hw *hw = nic->priv;
5634
5635 return _e1000_init(hw, nic->enetaddr);
5636}
5637
5638static int
5639e1000_poll(struct eth_device *nic)
5640{
5641 struct e1000_hw *hw = nic->priv;
5642 int len;
5643
5644 len = _e1000_poll(hw);
5645 if (len) {
5646 net_process_received_packet((uchar *)packet, len);
5647 fill_rx(hw);
5648 }
5649
5650 return len ? 1 : 0;
5651}
5652
5653static int e1000_write_hwaddr(struct eth_device *dev)
5654{
5655#ifndef CONFIG_E1000_NO_NVM
5656 unsigned char *mac = dev->enetaddr;
5657 unsigned char current_mac[6];
5658 struct e1000_hw *hw = dev->priv;
5659 uint16_t data[3];
5660 int ret_val, i;
5661
5662 DEBUGOUT("%s: mac=%pM\n", __func__, mac);
5663
5664 memset(current_mac, 0, 6);
5665
5666
5667
5668
5669 ret_val = e1000_read_mac_addr_from_eeprom(hw, current_mac);
5670 DEBUGOUT("%s: current mac=%pM\n", __func__, current_mac);
5671
5672
5673
5674
5675 if (!ret_val && memcmp(current_mac, mac, 6) == 0)
5676 return 0;
5677
5678 for (i = 0; i < 3; ++i)
5679 data[i] = mac[i * 2 + 1] << 8 | mac[i * 2];
5680
5681 ret_val = e1000_write_eeprom_srwr(hw, 0x0, 3, data);
5682
5683 if (!ret_val)
5684 ret_val = e1000_update_eeprom_checksum_i210(hw);
5685
5686 return ret_val;
5687#else
5688 return 0;
5689#endif
5690}
5691
5692
5693
5694
5695
5696int
5697e1000_initialize(bd_t * bis)
5698{
5699 unsigned int i;
5700 pci_dev_t devno;
5701 int ret;
5702
5703 DEBUGFUNC();
5704
5705
5706 for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) {
5707
5708
5709
5710
5711 struct eth_device *nic = malloc(sizeof(*nic));
5712 struct e1000_hw *hw = malloc(sizeof(*hw));
5713 if (!nic || !hw) {
5714 printf("e1000#%u: Out of Memory!\n", i);
5715 free(nic);
5716 free(hw);
5717 continue;
5718 }
5719
5720
5721 memset(nic, 0, sizeof(*nic));
5722 memset(hw, 0, sizeof(*hw));
5723 nic->priv = hw;
5724
5725
5726 e1000_name(nic->name, i);
5727 hw->name = nic->name;
5728
5729 ret = e1000_init_one(hw, i, devno, nic->enetaddr);
5730 if (ret)
5731 continue;
5732 list_add_tail(&hw->list_node, &e1000_hw_list);
5733
5734 hw->nic = nic;
5735
5736
5737 nic->init = e1000_init;
5738 nic->recv = e1000_poll;
5739 nic->send = e1000_transmit;
5740 nic->halt = e1000_disable;
5741 nic->write_hwaddr = e1000_write_hwaddr;
5742 eth_register(nic);
5743 }
5744
5745 return i;
5746}
5747
5748struct e1000_hw *e1000_find_card(unsigned int cardnum)
5749{
5750 struct e1000_hw *hw;
5751
5752 list_for_each_entry(hw, &e1000_hw_list, list_node)
5753 if (hw->cardnum == cardnum)
5754 return hw;
5755
5756 return NULL;
5757}
5758#endif
5759
5760#ifdef CONFIG_CMD_E1000
5761static int do_e1000(cmd_tbl_t *cmdtp, int flag,
5762 int argc, char * const argv[])
5763{
5764 unsigned char *mac = NULL;
5765#ifdef CONFIG_DM_ETH
5766 struct eth_pdata *plat;
5767 struct udevice *dev;
5768 char name[30];
5769 int ret;
5770#endif
5771#if !defined(CONFIG_DM_ETH) || defined(CONFIG_E1000_SPI)
5772 struct e1000_hw *hw;
5773#endif
5774 int cardnum;
5775
5776 if (argc < 3) {
5777 cmd_usage(cmdtp);
5778 return 1;
5779 }
5780
5781
5782 cardnum = simple_strtoul(argv[1], NULL, 10);
5783#ifdef CONFIG_DM_ETH
5784 e1000_name(name, cardnum);
5785 ret = uclass_get_device_by_name(UCLASS_ETH, name, &dev);
5786 if (!ret) {
5787 plat = dev_get_platdata(dev);
5788 mac = plat->enetaddr;
5789 }
5790#else
5791 hw = e1000_find_card(cardnum);
5792 if (hw)
5793 mac = hw->nic->enetaddr;
5794#endif
5795 if (!mac) {
5796 printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
5797 return 1;
5798 }
5799
5800 if (!strcmp(argv[2], "print-mac-address")) {
5801 printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
5802 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
5803 return 0;
5804 }
5805
5806#ifdef CONFIG_E1000_SPI
5807#ifdef CONFIG_DM_ETH
5808 hw = dev_get_priv(dev);
5809#endif
5810
5811 if (!strcmp(argv[2], "spi"))
5812 return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
5813#endif
5814
5815 cmd_usage(cmdtp);
5816 return 1;
5817}
5818
5819U_BOOT_CMD(
5820 e1000, 7, 0, do_e1000,
5821 "Intel e1000 controller management",
5822 "<card#> print-mac-address\n"
5823#ifdef CONFIG_E1000_SPI
5824 "e1000 <card#> spi show [<offset> [<length>]]\n"
5825 "e1000 <card#> spi dump <addr> <offset> <length>\n"
5826 "e1000 <card#> spi program <addr> <offset> <length>\n"
5827 "e1000 <card#> spi checksum [update]\n"
5828#endif
5829 " - Manage the Intel E1000 PCI device"
5830);
5831#endif
5832
5833#ifdef CONFIG_DM_ETH
5834static int e1000_eth_start(struct udevice *dev)
5835{
5836 struct eth_pdata *plat = dev_get_platdata(dev);
5837 struct e1000_hw *hw = dev_get_priv(dev);
5838
5839 return _e1000_init(hw, plat->enetaddr);
5840}
5841
5842static void e1000_eth_stop(struct udevice *dev)
5843{
5844 struct e1000_hw *hw = dev_get_priv(dev);
5845
5846 _e1000_disable(hw);
5847}
5848
5849static int e1000_eth_send(struct udevice *dev, void *packet, int length)
5850{
5851 struct e1000_hw *hw = dev_get_priv(dev);
5852 int ret;
5853
5854 ret = _e1000_transmit(hw, packet, length);
5855
5856 return ret ? 0 : -ETIMEDOUT;
5857}
5858
5859static int e1000_eth_recv(struct udevice *dev, int flags, uchar **packetp)
5860{
5861 struct e1000_hw *hw = dev_get_priv(dev);
5862 int len;
5863
5864 len = _e1000_poll(hw);
5865 if (len)
5866 *packetp = packet;
5867
5868 return len ? len : -EAGAIN;
5869}
5870
5871static int e1000_free_pkt(struct udevice *dev, uchar *packet, int length)
5872{
5873 struct e1000_hw *hw = dev_get_priv(dev);
5874
5875 fill_rx(hw);
5876
5877 return 0;
5878}
5879
5880static int e1000_eth_probe(struct udevice *dev)
5881{
5882 struct eth_pdata *plat = dev_get_platdata(dev);
5883 struct e1000_hw *hw = dev_get_priv(dev);
5884 int ret;
5885
5886 hw->name = dev->name;
5887 ret = e1000_init_one(hw, trailing_strtol(dev->name),
5888 dev, plat->enetaddr);
5889 if (ret < 0) {
5890 printf(pr_fmt("failed to initialize card: %d\n"), ret);
5891 return ret;
5892 }
5893
5894 return 0;
5895}
5896
5897static int e1000_eth_bind(struct udevice *dev)
5898{
5899 char name[20];
5900
5901
5902
5903
5904
5905
5906
5907 e1000_name(name, num_cards++);
5908
5909 return device_set_name(dev, name);
5910}
5911
5912static const struct eth_ops e1000_eth_ops = {
5913 .start = e1000_eth_start,
5914 .send = e1000_eth_send,
5915 .recv = e1000_eth_recv,
5916 .stop = e1000_eth_stop,
5917 .free_pkt = e1000_free_pkt,
5918};
5919
5920static const struct udevice_id e1000_eth_ids[] = {
5921 { .compatible = "intel,e1000" },
5922 { }
5923};
5924
5925U_BOOT_DRIVER(eth_e1000) = {
5926 .name = "eth_e1000",
5927 .id = UCLASS_ETH,
5928 .of_match = e1000_eth_ids,
5929 .bind = e1000_eth_bind,
5930 .probe = e1000_eth_probe,
5931 .ops = &e1000_eth_ops,
5932 .priv_auto_alloc_size = sizeof(struct e1000_hw),
5933 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
5934};
5935
5936U_BOOT_PCI_DEVICE(eth_e1000, e1000_supported);
5937#endif
5938