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