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#include "e1000_hw.h"
34
35static int32_t e1000_setup_fiber_link(struct e1000_hw *hw);
36static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
37static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
38static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
39static int32_t e1000_force_mac_fc(struct e1000_hw *hw);
40static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
41static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
42static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count);
43static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
44static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
45static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
46static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
47static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count);
48static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw);
49static void e1000_setup_eeprom(struct e1000_hw *hw);
50static void e1000_standby_eeprom(struct e1000_hw *hw);
51static void e1000_clock_eeprom(struct e1000_hw *hw);
52static void e1000_cleanup_eeprom(struct e1000_hw *hw);
53static int32_t e1000_id_led_init(struct e1000_hw * hw);
54
55
56
57
58
59
60int32_t
61e1000_set_mac_type(struct e1000_hw *hw)
62{
63 DEBUGFUNC("e1000_set_mac_type");
64
65 switch (hw->device_id) {
66 case E1000_DEV_ID_82542:
67 switch (hw->revision_id) {
68 case E1000_82542_2_0_REV_ID:
69 hw->mac_type = e1000_82542_rev2_0;
70 break;
71 case E1000_82542_2_1_REV_ID:
72 hw->mac_type = e1000_82542_rev2_1;
73 break;
74 default:
75
76 return -E1000_ERR_MAC_TYPE;
77 }
78 break;
79 case E1000_DEV_ID_82543GC_FIBER:
80 case E1000_DEV_ID_82543GC_COPPER:
81 hw->mac_type = e1000_82543;
82 break;
83 case E1000_DEV_ID_82544EI_COPPER:
84 case E1000_DEV_ID_82544EI_FIBER:
85 case E1000_DEV_ID_82544GC_COPPER:
86 case E1000_DEV_ID_82544GC_LOM:
87 hw->mac_type = e1000_82544;
88 break;
89 case E1000_DEV_ID_82540EM:
90 case E1000_DEV_ID_82540EM_LOM:
91 hw->mac_type = e1000_82540;
92 break;
93 case E1000_DEV_ID_82545EM_COPPER:
94 case E1000_DEV_ID_82545EM_FIBER:
95 hw->mac_type = e1000_82545;
96 break;
97 case E1000_DEV_ID_82546EB_COPPER:
98 case E1000_DEV_ID_82546EB_FIBER:
99 hw->mac_type = e1000_82546;
100 break;
101 default:
102
103 return -E1000_ERR_MAC_TYPE;
104 }
105 return E1000_SUCCESS;
106}
107
108
109
110
111
112void
113e1000_reset_hw(struct e1000_hw *hw)
114{
115 uint32_t ctrl;
116 uint32_t ctrl_ext;
117 uint32_t icr;
118 uint32_t manc;
119
120 DEBUGFUNC("e1000_reset_hw");
121
122
123 if(hw->mac_type == e1000_82542_rev2_0) {
124 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
125 e1000_pci_clear_mwi(hw);
126 }
127
128
129 DEBUGOUT("Masking off all interrupts\n");
130 E1000_WRITE_REG(hw, IMC, 0xffffffff);
131
132
133
134
135
136 E1000_WRITE_REG(hw, RCTL, 0);
137 E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
138 E1000_WRITE_FLUSH(hw);
139
140
141 hw->tbi_compatibility_on = FALSE;
142
143
144
145
146 msec_delay(10);
147
148
149
150
151
152
153 DEBUGOUT("Issuing a global reset to MAC\n");
154 ctrl = E1000_READ_REG(hw, CTRL);
155
156 if(hw->mac_type > e1000_82543)
157 E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
158 else
159 E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
160
161
162 if(hw->mac_type < e1000_82540) {
163
164 udelay(10);
165 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
166 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
167 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
168 E1000_WRITE_FLUSH(hw);
169
170 msec_delay(2);
171 } else {
172
173 msec_delay(4);
174
175 manc = E1000_READ_REG(hw, MANC);
176 manc &= ~(E1000_MANC_ARP_EN);
177 E1000_WRITE_REG(hw, MANC, manc);
178 }
179
180
181 DEBUGOUT("Masking off all interrupts\n");
182 E1000_WRITE_REG(hw, IMC, 0xffffffff);
183
184
185 icr = E1000_READ_REG(hw, ICR);
186
187
188 if(hw->mac_type == e1000_82542_rev2_0) {
189 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
190 e1000_pci_set_mwi(hw);
191 }
192}
193
194
195
196
197
198
199
200
201
202
203
204
205int32_t
206e1000_init_hw(struct e1000_hw *hw)
207{
208 uint32_t ctrl, status;
209 uint32_t i;
210 int32_t ret_val;
211 uint16_t pcix_cmd_word;
212 uint16_t pcix_stat_hi_word;
213 uint16_t cmd_mmrbc;
214 uint16_t stat_mmrbc;
215
216 DEBUGFUNC("e1000_init_hw");
217
218
219 ret_val = e1000_id_led_init(hw);
220 if(ret_val < 0) {
221 DEBUGOUT("Error Initializing Identification LED\n");
222 return ret_val;
223 }
224
225
226 if(hw->mac_type != e1000_82543) {
227
228 hw->tbi_compatibility_en = FALSE;
229 }
230
231 if(hw->mac_type >= e1000_82543) {
232 status = E1000_READ_REG(hw, STATUS);
233 if(status & E1000_STATUS_TBIMODE) {
234 hw->media_type = e1000_media_type_fiber;
235
236 hw->tbi_compatibility_en = FALSE;
237 } else {
238 hw->media_type = e1000_media_type_copper;
239 }
240 } else {
241
242 hw->media_type = e1000_media_type_fiber;
243 }
244
245
246 DEBUGOUT("Initializing the IEEE VLAN\n");
247 E1000_WRITE_REG(hw, VET, 0);
248
249 e1000_clear_vfta(hw);
250
251
252 if(hw->mac_type == e1000_82542_rev2_0) {
253 DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
254 e1000_pci_clear_mwi(hw);
255 E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
256 E1000_WRITE_FLUSH(hw);
257 msec_delay(5);
258 }
259
260
261
262
263 e1000_init_rx_addrs(hw);
264
265
266 if(hw->mac_type == e1000_82542_rev2_0) {
267 E1000_WRITE_REG(hw, RCTL, 0);
268 E1000_WRITE_FLUSH(hw);
269 msec_delay(1);
270 if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
271 e1000_pci_set_mwi(hw);
272 }
273
274
275 DEBUGOUT("Zeroing the MTA\n");
276 for(i = 0; i < E1000_MC_TBL_SIZE; i++)
277 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
278
279
280
281
282
283 if(hw->dma_fairness) {
284 ctrl = E1000_READ_REG(hw, CTRL);
285 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
286 }
287
288
289 if(hw->bus_type == e1000_bus_type_pcix) {
290 e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
291 e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI, &pcix_stat_hi_word);
292 cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
293 PCIX_COMMAND_MMRBC_SHIFT;
294 stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
295 PCIX_STATUS_HI_MMRBC_SHIFT;
296 if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
297 stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
298 if(cmd_mmrbc > stat_mmrbc) {
299 pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
300 pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
301 e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
302 }
303 }
304
305
306 ret_val = e1000_setup_link(hw);
307
308
309 if(hw->mac_type > e1000_82544) {
310 ctrl = E1000_READ_REG(hw, TXDCTL);
311 ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
312 E1000_WRITE_REG(hw, TXDCTL, ctrl);
313 }
314
315
316
317
318
319
320 e1000_clear_hw_cntrs(hw);
321
322 return ret_val;
323}
324
325
326
327
328
329
330
331
332
333
334
335
336int32_t
337e1000_setup_link(struct e1000_hw *hw)
338{
339 uint32_t ctrl_ext;
340 int32_t ret_val;
341 uint16_t eeprom_data;
342
343 DEBUGFUNC("e1000_setup_link");
344
345
346
347
348
349
350
351
352
353 if(e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, &eeprom_data) < 0) {
354 DEBUGOUT("EEPROM Read Error\n");
355 return -E1000_ERR_EEPROM;
356 }
357
358 if(hw->fc == e1000_fc_default) {
359 if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
360 hw->fc = e1000_fc_none;
361 else if((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
362 EEPROM_WORD0F_ASM_DIR)
363 hw->fc = e1000_fc_tx_pause;
364 else
365 hw->fc = e1000_fc_full;
366 }
367
368
369
370
371
372 if(hw->mac_type == e1000_82542_rev2_0)
373 hw->fc &= (~e1000_fc_tx_pause);
374
375 if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
376 hw->fc &= (~e1000_fc_rx_pause);
377
378 hw->original_fc = hw->fc;
379
380 DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
381
382
383
384
385
386
387
388
389 if(hw->mac_type == e1000_82543) {
390 ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
391 SWDPIO__EXT_SHIFT);
392 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
393 }
394
395
396 ret_val = (hw->media_type == e1000_media_type_fiber) ?
397 e1000_setup_fiber_link(hw) :
398 e1000_setup_copper_link(hw);
399
400
401
402
403
404
405 DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
406
407 E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
408 E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
409 E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
410 E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
411
412
413
414
415
416
417
418 if(!(hw->fc & e1000_fc_tx_pause)) {
419 E1000_WRITE_REG(hw, FCRTL, 0);
420 E1000_WRITE_REG(hw, FCRTH, 0);
421 } else {
422
423
424
425 if(hw->fc_send_xon) {
426 E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
427 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
428 } else {
429 E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
430 E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
431 }
432 }
433 return ret_val;
434}
435
436
437
438
439
440
441
442
443
444
445static int32_t
446e1000_setup_fiber_link(struct e1000_hw *hw)
447{
448 uint32_t ctrl;
449 uint32_t status;
450 uint32_t txcw = 0;
451 uint32_t i;
452 uint32_t signal;
453 int32_t ret_val;
454
455 DEBUGFUNC("e1000_setup_fiber_link");
456
457
458
459
460
461 ctrl = E1000_READ_REG(hw, CTRL);
462 if(hw->mac_type > e1000_82544) signal = E1000_CTRL_SWDPIN1;
463 else signal = 0;
464
465
466 ctrl &= ~(E1000_CTRL_LRST);
467
468 e1000_config_collision_dist(hw);
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485 switch (hw->fc) {
486 case e1000_fc_none:
487
488 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
489 break;
490 case e1000_fc_rx_pause:
491
492
493
494
495
496
497 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
498 break;
499 case e1000_fc_tx_pause:
500
501
502
503 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
504 break;
505 case e1000_fc_full:
506
507 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
508 break;
509 default:
510 DEBUGOUT("Flow control param set incorrectly\n");
511 return -E1000_ERR_CONFIG;
512 break;
513 }
514
515
516
517
518
519
520
521 DEBUGOUT("Auto-negotiation enabled\n");
522
523 E1000_WRITE_REG(hw, TXCW, txcw);
524 E1000_WRITE_REG(hw, CTRL, ctrl);
525 E1000_WRITE_FLUSH(hw);
526
527 hw->txcw = txcw;
528 msec_delay(1);
529
530
531
532
533
534
535 if((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
536 DEBUGOUT("Looking for Link\n");
537 for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
538 msec_delay(10);
539 status = E1000_READ_REG(hw, STATUS);
540 if(status & E1000_STATUS_LU) break;
541 }
542 if(i == (LINK_UP_TIMEOUT / 10)) {
543
544
545
546
547
548 DEBUGOUT("Never got a valid link from auto-neg!!!\n");
549 hw->autoneg_failed = 1;
550 ret_val = e1000_check_for_link(hw);
551 if(ret_val < 0) {
552 DEBUGOUT("Error while checking for link\n");
553 return ret_val;
554 }
555 hw->autoneg_failed = 0;
556 } else {
557 hw->autoneg_failed = 0;
558 DEBUGOUT("Valid Link Found\n");
559 }
560 } else {
561 DEBUGOUT("No Signal Detected\n");
562 }
563 return 0;
564}
565
566
567
568
569
570
571static int32_t
572e1000_setup_copper_link(struct e1000_hw *hw)
573{
574 uint32_t ctrl;
575 int32_t ret_val;
576 uint16_t i;
577 uint16_t phy_data;
578
579 DEBUGFUNC("e1000_setup_copper_link");
580
581 ctrl = E1000_READ_REG(hw, CTRL);
582
583
584
585
586 if(hw->mac_type > e1000_82543) {
587 ctrl |= E1000_CTRL_SLU;
588 ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
589 E1000_WRITE_REG(hw, CTRL, ctrl);
590 } else {
591 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
592 E1000_WRITE_REG(hw, CTRL, ctrl);
593 e1000_phy_hw_reset(hw);
594 }
595
596
597 ret_val = e1000_detect_gig_phy(hw);
598 if(ret_val < 0) {
599 DEBUGOUT("Error, did not detect valid phy.\n");
600 return ret_val;
601 }
602 DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
603
604
605 if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
606 DEBUGOUT("PHY Read Error\n");
607 return -E1000_ERR_PHY;
608 }
609 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
610
611
612
613
614
615
616
617
618 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
619
620 switch (hw->mdix) {
621 case 1:
622 phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
623 break;
624 case 2:
625 phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
626 break;
627 case 3:
628 phy_data |= M88E1000_PSCR_AUTO_X_1000T;
629 break;
630 case 0:
631 default:
632 phy_data |= M88E1000_PSCR_AUTO_X_MODE;
633 break;
634 }
635
636
637
638
639
640
641
642 phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
643 if(hw->disable_polarity_correction == 1)
644 phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
645 if(e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
646 DEBUGOUT("PHY Write Error\n");
647 return -E1000_ERR_PHY;
648 }
649
650
651
652
653 if(e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data) < 0) {
654 DEBUGOUT("PHY Read Error\n");
655 return -E1000_ERR_PHY;
656 }
657 phy_data |= M88E1000_EPSCR_TX_CLK_25;
658
659 phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
660 M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
661 phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
662 M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
663 if(e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data) < 0) {
664 DEBUGOUT("PHY Write Error\n");
665 return -E1000_ERR_PHY;
666 }
667
668
669 ret_val = e1000_phy_reset(hw);
670 if(ret_val < 0) {
671 DEBUGOUT("Error Resetting the PHY\n");
672 return ret_val;
673 }
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690 if(hw->autoneg) {
691
692
693
694 hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
695
696
697
698
699 if(hw->autoneg_advertised == 0)
700 hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
701
702 DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
703 ret_val = e1000_phy_setup_autoneg(hw);
704 if(ret_val < 0) {
705 DEBUGOUT("Error Setting up Auto-Negotiation\n");
706 return ret_val;
707 }
708 DEBUGOUT("Restarting Auto-Neg\n");
709
710
711
712
713 if(e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
714 DEBUGOUT("PHY Read Error\n");
715 return -E1000_ERR_PHY;
716 }
717 phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
718 if(e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
719 DEBUGOUT("PHY Write Error\n");
720 return -E1000_ERR_PHY;
721 }
722
723
724
725
726 if(hw->wait_autoneg_complete) {
727 ret_val = e1000_wait_autoneg(hw);
728 if(ret_val < 0) {
729 DEBUGOUT("Error while waiting for autoneg to complete\n");
730 return ret_val;
731 }
732 }
733 } else {
734 DEBUGOUT("Forcing speed and duplex\n");
735 ret_val = e1000_phy_force_speed_duplex(hw);
736 if(ret_val < 0) {
737 DEBUGOUT("Error Forcing Speed and Duplex\n");
738 return ret_val;
739 }
740 }
741
742
743
744
745 for(i = 0; i < 10; i++) {
746 if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
747 DEBUGOUT("PHY Read Error\n");
748 return -E1000_ERR_PHY;
749 }
750 if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
751 DEBUGOUT("PHY Read Error\n");
752 return -E1000_ERR_PHY;
753 }
754 if(phy_data & MII_SR_LINK_STATUS) {
755
756
757
758
759
760
761
762
763 if(hw->mac_type >= e1000_82544) {
764 e1000_config_collision_dist(hw);
765 } else {
766 ret_val = e1000_config_mac_to_phy(hw);
767 if(ret_val < 0) {
768 DEBUGOUT("Error configuring MAC to PHY settings\n");
769 return ret_val;
770 }
771 }
772 ret_val = e1000_config_fc_after_link_up(hw);
773 if(ret_val < 0) {
774 DEBUGOUT("Error Configuring Flow Control\n");
775 return ret_val;
776 }
777 DEBUGOUT("Valid link established!!!\n");
778 return 0;
779 }
780 udelay(10);
781 }
782
783 DEBUGOUT("Unable to establish link!!!\n");
784 return 0;
785}
786
787
788
789
790
791
792int32_t
793e1000_phy_setup_autoneg(struct e1000_hw *hw)
794{
795 uint16_t mii_autoneg_adv_reg;
796 uint16_t mii_1000t_ctrl_reg;
797
798 DEBUGFUNC("e1000_phy_setup_autoneg");
799
800
801 if(e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg) < 0) {
802 DEBUGOUT("PHY Read Error\n");
803 return -E1000_ERR_PHY;
804 }
805
806
807 if(e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg) < 0) {
808 DEBUGOUT("PHY Read Error\n");
809 return -E1000_ERR_PHY;
810 }
811
812
813
814
815
816
817
818
819
820
821
822
823 mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
824 mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
825
826 DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
827
828
829 if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
830 DEBUGOUT("Advertise 10mb Half duplex\n");
831 mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
832 }
833
834
835 if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
836 DEBUGOUT("Advertise 10mb Full duplex\n");
837 mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
838 }
839
840
841 if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
842 DEBUGOUT("Advertise 100mb Half duplex\n");
843 mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
844 }
845
846
847 if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
848 DEBUGOUT("Advertise 100mb Full duplex\n");
849 mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
850 }
851
852
853 if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
854 DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
855 }
856
857
858 if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
859 DEBUGOUT("Advertise 1000mb Full duplex\n");
860 mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
861 }
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879 switch (hw->fc) {
880 case e1000_fc_none:
881
882
883
884 mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
885 break;
886 case e1000_fc_rx_pause:
887
888
889
890
891
892
893
894
895
896 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
897 break;
898 case e1000_fc_tx_pause:
899
900
901
902 mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
903 mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
904 break;
905 case e1000_fc_full:
906
907
908
909 mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
910 break;
911 default:
912 DEBUGOUT("Flow control param set incorrectly\n");
913 return -E1000_ERR_CONFIG;
914 }
915
916 if(e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg) < 0) {
917 DEBUGOUT("PHY Write Error\n");
918 return -E1000_ERR_PHY;
919 }
920
921 DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
922
923 if(e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg) < 0) {
924 DEBUGOUT("PHY Write Error\n");
925 return -E1000_ERR_PHY;
926 }
927 return 0;
928}
929
930
931
932
933
934
935static int32_t
936e1000_phy_force_speed_duplex(struct e1000_hw *hw)
937{
938 uint32_t ctrl;
939 int32_t ret_val;
940 uint16_t mii_ctrl_reg;
941 uint16_t mii_status_reg;
942 uint16_t phy_data;
943 uint16_t i;
944
945 DEBUGFUNC("e1000_phy_force_speed_duplex");
946
947
948 hw->fc = e1000_fc_none;
949
950 DEBUGOUT1("hw->fc = %d\n", hw->fc);
951
952
953 ctrl = E1000_READ_REG(hw, CTRL);
954
955
956 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
957 ctrl &= ~(DEVICE_SPEED_MASK);
958
959
960 ctrl &= ~E1000_CTRL_ASDE;
961
962
963 if(e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg) < 0) {
964 DEBUGOUT("PHY Read Error\n");
965 return -E1000_ERR_PHY;
966 }
967
968
969
970 mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
971
972
973 if(hw->forced_speed_duplex == e1000_100_full ||
974 hw->forced_speed_duplex == e1000_10_full) {
975
976
977
978 ctrl |= E1000_CTRL_FD;
979 mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
980 DEBUGOUT("Full Duplex\n");
981 } else {
982
983
984
985 ctrl &= ~E1000_CTRL_FD;
986 mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
987 DEBUGOUT("Half Duplex\n");
988 }
989
990
991 if(hw->forced_speed_duplex == e1000_100_full ||
992 hw->forced_speed_duplex == e1000_100_half) {
993
994 ctrl |= E1000_CTRL_SPD_100;
995 mii_ctrl_reg |= MII_CR_SPEED_100;
996 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
997 DEBUGOUT("Forcing 100mb ");
998 } else {
999
1000 ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
1001 mii_ctrl_reg |= MII_CR_SPEED_10;
1002 mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
1003 DEBUGOUT("Forcing 10mb ");
1004 }
1005
1006 e1000_config_collision_dist(hw);
1007
1008
1009 E1000_WRITE_REG(hw, CTRL, ctrl);
1010
1011
1012 if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
1013 DEBUGOUT("PHY Read Error\n");
1014 return -E1000_ERR_PHY;
1015 }
1016
1017
1018
1019
1020 phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
1021 if(e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
1022 DEBUGOUT("PHY Write Error\n");
1023 return -E1000_ERR_PHY;
1024 }
1025 DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
1026
1027
1028 mii_ctrl_reg |= MII_CR_RESET;
1029 if(e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg) < 0) {
1030 DEBUGOUT("PHY Write Error\n");
1031 return -E1000_ERR_PHY;
1032 }
1033 udelay(1);
1034
1035
1036
1037
1038
1039
1040
1041
1042 if(hw->wait_autoneg_complete) {
1043
1044 DEBUGOUT("Waiting for forced speed/duplex link.\n");
1045 mii_status_reg = 0;
1046
1047
1048 for(i = PHY_FORCE_TIME; i > 0; i--) {
1049
1050
1051
1052 if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1053 DEBUGOUT("PHY Read Error\n");
1054 return -E1000_ERR_PHY;
1055 }
1056 if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1057 DEBUGOUT("PHY Read Error\n");
1058 return -E1000_ERR_PHY;
1059 }
1060 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1061 msec_delay(100);
1062 }
1063 if(i == 0) {
1064
1065
1066 ret_val = e1000_phy_reset_dsp(hw);
1067 if(ret_val < 0) {
1068 DEBUGOUT("Error Resetting PHY DSP\n");
1069 return ret_val;
1070 }
1071 }
1072
1073 for(i = PHY_FORCE_TIME; i > 0; i--) {
1074 if(mii_status_reg & MII_SR_LINK_STATUS) break;
1075 msec_delay(100);
1076
1077
1078
1079 if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1080 DEBUGOUT("PHY Read Error\n");
1081 return -E1000_ERR_PHY;
1082 }
1083 if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1084 DEBUGOUT("PHY Read Error\n");
1085 return -E1000_ERR_PHY;
1086 }
1087 }
1088 }
1089
1090
1091
1092
1093
1094 if(e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data) < 0) {
1095 DEBUGOUT("PHY Read Error\n");
1096 return -E1000_ERR_PHY;
1097 }
1098 phy_data |= M88E1000_EPSCR_TX_CLK_25;
1099 if(e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data) < 0) {
1100 DEBUGOUT("PHY Write Error\n");
1101 return -E1000_ERR_PHY;
1102 }
1103
1104
1105
1106
1107 if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0) {
1108 DEBUGOUT("PHY Read Error\n");
1109 return -E1000_ERR_PHY;
1110 }
1111 phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
1112 if(e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data) < 0) {
1113 DEBUGOUT("PHY Write Error\n");
1114 return -E1000_ERR_PHY;
1115 }
1116 return 0;
1117}
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127void
1128e1000_config_collision_dist(struct e1000_hw *hw)
1129{
1130 uint32_t tctl;
1131
1132 tctl = E1000_READ_REG(hw, TCTL);
1133
1134 tctl &= ~E1000_TCTL_COLD;
1135 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
1136
1137 E1000_WRITE_REG(hw, TCTL, tctl);
1138 E1000_WRITE_FLUSH(hw);
1139}
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150static int32_t
1151e1000_config_mac_to_phy(struct e1000_hw *hw)
1152{
1153 uint32_t ctrl;
1154 uint16_t phy_data;
1155
1156 DEBUGFUNC("e1000_config_mac_to_phy");
1157
1158
1159
1160
1161 ctrl = E1000_READ_REG(hw, CTRL);
1162 ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
1163 ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
1164
1165
1166
1167
1168 if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
1169 DEBUGOUT("PHY Read Error\n");
1170 return -E1000_ERR_PHY;
1171 }
1172 if(phy_data & M88E1000_PSSR_DPLX) ctrl |= E1000_CTRL_FD;
1173 else ctrl &= ~E1000_CTRL_FD;
1174
1175 e1000_config_collision_dist(hw);
1176
1177
1178
1179
1180 if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
1181 ctrl |= E1000_CTRL_SPD_1000;
1182 else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
1183 ctrl |= E1000_CTRL_SPD_100;
1184
1185 E1000_WRITE_REG(hw, CTRL, ctrl);
1186 return 0;
1187}
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200static int32_t
1201e1000_force_mac_fc(struct e1000_hw *hw)
1202{
1203 uint32_t ctrl;
1204
1205 DEBUGFUNC("e1000_force_mac_fc");
1206
1207
1208 ctrl = E1000_READ_REG(hw, CTRL);
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228 switch (hw->fc) {
1229 case e1000_fc_none:
1230 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1231 break;
1232 case e1000_fc_rx_pause:
1233 ctrl &= (~E1000_CTRL_TFCE);
1234 ctrl |= E1000_CTRL_RFCE;
1235 break;
1236 case e1000_fc_tx_pause:
1237 ctrl &= (~E1000_CTRL_RFCE);
1238 ctrl |= E1000_CTRL_TFCE;
1239 break;
1240 case e1000_fc_full:
1241 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1242 break;
1243 default:
1244 DEBUGOUT("Flow control param set incorrectly\n");
1245 return -E1000_ERR_CONFIG;
1246 }
1247
1248
1249 if(hw->mac_type == e1000_82542_rev2_0)
1250 ctrl &= (~E1000_CTRL_TFCE);
1251
1252 E1000_WRITE_REG(hw, CTRL, ctrl);
1253 return 0;
1254}
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267int32_t
1268e1000_config_fc_after_link_up(struct e1000_hw *hw)
1269{
1270 int32_t ret_val;
1271 uint16_t mii_status_reg;
1272 uint16_t mii_nway_adv_reg;
1273 uint16_t mii_nway_lp_ability_reg;
1274 uint16_t speed;
1275 uint16_t duplex;
1276
1277 DEBUGFUNC("e1000_config_fc_after_link_up");
1278
1279
1280
1281
1282
1283 if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
1284 ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
1285 ret_val = e1000_force_mac_fc(hw);
1286 if(ret_val < 0) {
1287 DEBUGOUT("Error forcing flow control settings\n");
1288 return ret_val;
1289 }
1290 }
1291
1292
1293
1294
1295
1296
1297 if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
1298
1299
1300
1301
1302 if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1303 DEBUGOUT("PHY Read Error \n");
1304 return -E1000_ERR_PHY;
1305 }
1306 if(e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
1307 DEBUGOUT("PHY Read Error \n");
1308 return -E1000_ERR_PHY;
1309 }
1310
1311 if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
1312
1313
1314
1315
1316
1317
1318 if(e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
1319 DEBUGOUT("PHY Read Error\n");
1320 return -E1000_ERR_PHY;
1321 }
1322 if(e1000_read_phy_reg(hw, PHY_LP_ABILITY, &mii_nway_lp_ability_reg) < 0) {
1323 DEBUGOUT("PHY Read Error\n");
1324 return -E1000_ERR_PHY;
1325 }
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361 if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1362 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1363
1364
1365
1366
1367
1368
1369 if(hw->original_fc == e1000_fc_full) {
1370 hw->fc = e1000_fc_full;
1371 DEBUGOUT("Flow Control = FULL.\r\n");
1372 } else {
1373 hw->fc = e1000_fc_rx_pause;
1374 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1375 }
1376 }
1377
1378
1379
1380
1381
1382
1383
1384
1385 else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1386 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1387 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1388 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1389 hw->fc = e1000_fc_tx_pause;
1390 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
1391 }
1392
1393
1394
1395
1396
1397
1398
1399
1400 else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1401 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1402 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1403 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1404 hw->fc = e1000_fc_rx_pause;
1405 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1406 }
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427 else if(hw->original_fc == e1000_fc_none ||
1428 hw->original_fc == e1000_fc_tx_pause) {
1429 hw->fc = e1000_fc_none;
1430 DEBUGOUT("Flow Control = NONE.\r\n");
1431 } else {
1432 hw->fc = e1000_fc_rx_pause;
1433 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
1434 }
1435
1436
1437
1438
1439
1440 e1000_get_speed_and_duplex(hw, &speed, &duplex);
1441
1442 if(duplex == HALF_DUPLEX)
1443 hw->fc = e1000_fc_none;
1444
1445
1446
1447
1448 ret_val = e1000_force_mac_fc(hw);
1449 if(ret_val < 0) {
1450 DEBUGOUT("Error forcing flow control settings\n");
1451 return ret_val;
1452 }
1453 } else {
1454 DEBUGOUT("Copper PHY and Auto Neg has not completed.\r\n");
1455 }
1456 }
1457 return 0;
1458}
1459
1460
1461
1462
1463
1464
1465
1466
1467int32_t
1468e1000_check_for_link(struct e1000_hw *hw)
1469{
1470 uint32_t rxcw;
1471 uint32_t ctrl;
1472 uint32_t status;
1473 uint32_t rctl;
1474 uint32_t signal;
1475 int32_t ret_val;
1476 uint16_t phy_data;
1477 uint16_t lp_capability;
1478
1479 DEBUGFUNC("e1000_check_for_link");
1480
1481
1482
1483
1484
1485 if(hw->mac_type > e1000_82544) signal = E1000_CTRL_SWDPIN1;
1486 else signal = 0;
1487
1488 ctrl = E1000_READ_REG(hw, CTRL);
1489 status = E1000_READ_REG(hw, STATUS);
1490 rxcw = E1000_READ_REG(hw, RXCW);
1491
1492
1493
1494
1495
1496
1497
1498 if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
1499
1500
1501
1502
1503
1504 if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1505 DEBUGOUT("PHY Read Error\n");
1506 return -E1000_ERR_PHY;
1507 }
1508 if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1509 DEBUGOUT("PHY Read Error\n");
1510 return -E1000_ERR_PHY;
1511 }
1512
1513 if(phy_data & MII_SR_LINK_STATUS) {
1514 hw->get_link_status = FALSE;
1515 } else {
1516
1517 return 0;
1518 }
1519
1520
1521
1522
1523 if(!hw->autoneg) return -E1000_ERR_CONFIG;
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533 if(hw->mac_type >= e1000_82544)
1534 e1000_config_collision_dist(hw);
1535 else {
1536 ret_val = e1000_config_mac_to_phy(hw);
1537 if(ret_val < 0) {
1538 DEBUGOUT("Error configuring MAC to PHY settings\n");
1539 return ret_val;
1540 }
1541 }
1542
1543
1544
1545
1546
1547 ret_val = e1000_config_fc_after_link_up(hw);
1548 if(ret_val < 0) {
1549 DEBUGOUT("Error configuring flow control\n");
1550 return ret_val;
1551 }
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562 if(hw->tbi_compatibility_en) {
1563 if(e1000_read_phy_reg(hw, PHY_LP_ABILITY, &lp_capability) < 0) {
1564 DEBUGOUT("PHY Read Error\n");
1565 return -E1000_ERR_PHY;
1566 }
1567 if(lp_capability & (NWAY_LPAR_10T_HD_CAPS |
1568 NWAY_LPAR_10T_FD_CAPS |
1569 NWAY_LPAR_100TX_HD_CAPS |
1570 NWAY_LPAR_100TX_FD_CAPS |
1571 NWAY_LPAR_100T4_CAPS)) {
1572
1573
1574
1575 if(hw->tbi_compatibility_on) {
1576
1577 rctl = E1000_READ_REG(hw, RCTL);
1578 rctl &= ~E1000_RCTL_SBP;
1579 E1000_WRITE_REG(hw, RCTL, rctl);
1580 hw->tbi_compatibility_on = FALSE;
1581 }
1582 } else {
1583
1584
1585
1586
1587
1588 if(!hw->tbi_compatibility_on) {
1589 hw->tbi_compatibility_on = TRUE;
1590 rctl = E1000_READ_REG(hw, RCTL);
1591 rctl |= E1000_RCTL_SBP;
1592 E1000_WRITE_REG(hw, RCTL, rctl);
1593 }
1594 }
1595 }
1596 }
1597
1598
1599
1600
1601
1602
1603
1604 else if((hw->media_type == e1000_media_type_fiber) &&
1605 (!(status & E1000_STATUS_LU)) &&
1606 ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
1607 (!(rxcw & E1000_RXCW_C))) {
1608 if(hw->autoneg_failed == 0) {
1609 hw->autoneg_failed = 1;
1610 return 0;
1611 }
1612 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
1613
1614
1615 E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
1616
1617
1618 ctrl = E1000_READ_REG(hw, CTRL);
1619 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
1620 E1000_WRITE_REG(hw, CTRL, ctrl);
1621
1622
1623 ret_val = e1000_config_fc_after_link_up(hw);
1624 if(ret_val < 0) {
1625 DEBUGOUT("Error configuring flow control\n");
1626 return ret_val;
1627 }
1628 }
1629
1630
1631
1632
1633
1634 else if((hw->media_type == e1000_media_type_fiber) &&
1635 (ctrl & E1000_CTRL_SLU) &&
1636 (rxcw & E1000_RXCW_C)) {
1637 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
1638 E1000_WRITE_REG(hw, TXCW, hw->txcw);
1639 E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
1640 }
1641 return 0;
1642}
1643
1644
1645
1646
1647
1648
1649
1650
1651void
1652e1000_get_speed_and_duplex(struct e1000_hw *hw,
1653 uint16_t *speed,
1654 uint16_t *duplex)
1655{
1656 uint32_t status;
1657
1658 DEBUGFUNC("e1000_get_speed_and_duplex");
1659
1660 if(hw->mac_type >= e1000_82543) {
1661 status = E1000_READ_REG(hw, STATUS);
1662 if(status & E1000_STATUS_SPEED_1000) {
1663 *speed = SPEED_1000;
1664 DEBUGOUT("1000 Mbs, ");
1665 } else if(status & E1000_STATUS_SPEED_100) {
1666 *speed = SPEED_100;
1667 DEBUGOUT("100 Mbs, ");
1668 } else {
1669 *speed = SPEED_10;
1670 DEBUGOUT("10 Mbs, ");
1671 }
1672
1673 if(status & E1000_STATUS_FD) {
1674 *duplex = FULL_DUPLEX;
1675 DEBUGOUT("Full Duplex\r\n");
1676 } else {
1677 *duplex = HALF_DUPLEX;
1678 DEBUGOUT(" Half Duplex\r\n");
1679 }
1680 } else {
1681 DEBUGOUT("1000 Mbs, Full Duplex\r\n");
1682 *speed = SPEED_1000;
1683 *duplex = FULL_DUPLEX;
1684 }
1685}
1686
1687
1688
1689
1690
1691
1692int32_t
1693e1000_wait_autoneg(struct e1000_hw *hw)
1694{
1695 uint16_t i;
1696 uint16_t phy_data;
1697
1698 DEBUGFUNC("e1000_wait_autoneg");
1699 DEBUGOUT("Waiting for Auto-Neg to complete.\n");
1700
1701
1702 for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
1703
1704
1705
1706 if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1707 DEBUGOUT("PHY Read Error\n");
1708 return -E1000_ERR_PHY;
1709 }
1710 if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
1711 DEBUGOUT("PHY Read Error\n");
1712 return -E1000_ERR_PHY;
1713 }
1714 if(phy_data & MII_SR_AUTONEG_COMPLETE) {
1715 return 0;
1716 }
1717 msec_delay(100);
1718 }
1719 return 0;
1720}
1721
1722
1723
1724
1725
1726
1727
1728static void
1729e1000_raise_mdi_clk(struct e1000_hw *hw,
1730 uint32_t *ctrl)
1731{
1732
1733
1734
1735 E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
1736 E1000_WRITE_FLUSH(hw);
1737 udelay(2);
1738}
1739
1740
1741
1742
1743
1744
1745
1746static void
1747e1000_lower_mdi_clk(struct e1000_hw *hw,
1748 uint32_t *ctrl)
1749{
1750
1751
1752
1753 E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
1754 E1000_WRITE_FLUSH(hw);
1755 udelay(2);
1756}
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767static void
1768e1000_shift_out_mdi_bits(struct e1000_hw *hw,
1769 uint32_t data,
1770 uint16_t count)
1771{
1772 uint32_t ctrl;
1773 uint32_t mask;
1774
1775
1776
1777
1778
1779 mask = 0x01;
1780 mask <<= (count - 1);
1781
1782 ctrl = E1000_READ_REG(hw, CTRL);
1783
1784
1785 ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
1786
1787 while(mask) {
1788
1789
1790
1791
1792
1793 if(data & mask) ctrl |= E1000_CTRL_MDIO;
1794 else ctrl &= ~E1000_CTRL_MDIO;
1795
1796 E1000_WRITE_REG(hw, CTRL, ctrl);
1797 E1000_WRITE_FLUSH(hw);
1798
1799 udelay(2);
1800
1801 e1000_raise_mdi_clk(hw, &ctrl);
1802 e1000_lower_mdi_clk(hw, &ctrl);
1803
1804 mask = mask >> 1;
1805 }
1806}
1807
1808
1809
1810
1811
1812
1813
1814
1815static uint16_t
1816e1000_shift_in_mdi_bits(struct e1000_hw *hw)
1817{
1818 uint32_t ctrl;
1819 uint16_t data = 0;
1820 uint8_t i;
1821
1822
1823
1824
1825
1826
1827
1828
1829 ctrl = E1000_READ_REG(hw, CTRL);
1830
1831
1832 ctrl &= ~E1000_CTRL_MDIO_DIR;
1833 ctrl &= ~E1000_CTRL_MDIO;
1834
1835 E1000_WRITE_REG(hw, CTRL, ctrl);
1836 E1000_WRITE_FLUSH(hw);
1837
1838
1839
1840
1841
1842 e1000_raise_mdi_clk(hw, &ctrl);
1843 e1000_lower_mdi_clk(hw, &ctrl);
1844
1845 for(data = 0, i = 0; i < 16; i++) {
1846 data = data << 1;
1847 e1000_raise_mdi_clk(hw, &ctrl);
1848 ctrl = E1000_READ_REG(hw, CTRL);
1849
1850 if(ctrl & E1000_CTRL_MDIO) data |= 1;
1851 e1000_lower_mdi_clk(hw, &ctrl);
1852 }
1853
1854 e1000_raise_mdi_clk(hw, &ctrl);
1855 e1000_lower_mdi_clk(hw, &ctrl);
1856
1857 return data;
1858}
1859
1860
1861
1862
1863
1864
1865
1866int32_t
1867e1000_read_phy_reg(struct e1000_hw *hw,
1868 uint32_t reg_addr,
1869 uint16_t *phy_data)
1870{
1871 uint32_t i;
1872 uint32_t mdic = 0;
1873 const uint32_t phy_addr = 1;
1874
1875 DEBUGFUNC("e1000_read_phy_reg");
1876
1877 if(reg_addr > MAX_PHY_REG_ADDRESS) {
1878 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
1879 return -E1000_ERR_PARAM;
1880 }
1881
1882 if(hw->mac_type > e1000_82543) {
1883
1884
1885
1886
1887 mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
1888 (phy_addr << E1000_MDIC_PHY_SHIFT) |
1889 (E1000_MDIC_OP_READ));
1890
1891 E1000_WRITE_REG(hw, MDIC, mdic);
1892
1893
1894 for(i = 0; i < 64; i++) {
1895 udelay(10);
1896 mdic = E1000_READ_REG(hw, MDIC);
1897 if(mdic & E1000_MDIC_READY) break;
1898 }
1899 if(!(mdic & E1000_MDIC_READY)) {
1900 DEBUGOUT("MDI Read did not complete\n");
1901 return -E1000_ERR_PHY;
1902 }
1903 if(mdic & E1000_MDIC_ERROR) {
1904 DEBUGOUT("MDI Error\n");
1905 return -E1000_ERR_PHY;
1906 }
1907 *phy_data = (uint16_t) mdic;
1908 } else {
1909
1910
1911
1912
1913 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926 mdic = ((reg_addr) | (phy_addr << 5) |
1927 (PHY_OP_READ << 10) | (PHY_SOF << 12));
1928
1929 e1000_shift_out_mdi_bits(hw, mdic, 14);
1930
1931
1932
1933
1934
1935 *phy_data = e1000_shift_in_mdi_bits(hw);
1936 }
1937 return 0;
1938}
1939
1940
1941
1942
1943
1944
1945
1946
1947int32_t
1948e1000_write_phy_reg(struct e1000_hw *hw,
1949 uint32_t reg_addr,
1950 uint16_t phy_data)
1951{
1952 uint32_t i;
1953 uint32_t mdic = 0;
1954 const uint32_t phy_addr = 1;
1955
1956 DEBUGFUNC("e1000_write_phy_reg");
1957
1958 if(reg_addr > MAX_PHY_REG_ADDRESS) {
1959 DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
1960 return -E1000_ERR_PARAM;
1961 }
1962
1963 if(hw->mac_type > e1000_82543) {
1964
1965
1966
1967
1968 mdic = (((uint32_t) phy_data) |
1969 (reg_addr << E1000_MDIC_REG_SHIFT) |
1970 (phy_addr << E1000_MDIC_PHY_SHIFT) |
1971 (E1000_MDIC_OP_WRITE));
1972
1973 E1000_WRITE_REG(hw, MDIC, mdic);
1974
1975
1976 for(i = 0; i < 64; i++) {
1977 udelay(10);
1978 mdic = E1000_READ_REG(hw, MDIC);
1979 if(mdic & E1000_MDIC_READY) break;
1980 }
1981 if(!(mdic & E1000_MDIC_READY)) {
1982 DEBUGOUT("MDI Write did not complete\n");
1983 return -E1000_ERR_PHY;
1984 }
1985 } else {
1986
1987
1988
1989
1990
1991 e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
1992
1993
1994
1995
1996
1997
1998
1999 mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
2000 (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
2001 mdic <<= 16;
2002 mdic |= (uint32_t) phy_data;
2003
2004 e1000_shift_out_mdi_bits(hw, mdic, 32);
2005 }
2006 return 0;
2007}
2008
2009
2010
2011
2012
2013
2014void
2015e1000_phy_hw_reset(struct e1000_hw *hw)
2016{
2017 uint32_t ctrl;
2018 uint32_t ctrl_ext;
2019
2020 DEBUGFUNC("e1000_phy_hw_reset");
2021
2022 DEBUGOUT("Resetting Phy...\n");
2023
2024 if(hw->mac_type > e1000_82543) {
2025
2026
2027
2028 ctrl = E1000_READ_REG(hw, CTRL);
2029 E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
2030 E1000_WRITE_FLUSH(hw);
2031 msec_delay(10);
2032 E1000_WRITE_REG(hw, CTRL, ctrl);
2033 E1000_WRITE_FLUSH(hw);
2034 } else {
2035
2036
2037
2038 ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
2039 ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
2040 ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
2041 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2042 E1000_WRITE_FLUSH(hw);
2043 msec_delay(10);
2044 ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
2045 E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
2046 E1000_WRITE_FLUSH(hw);
2047 }
2048 udelay(150);
2049}
2050
2051
2052
2053
2054
2055
2056
2057
2058int32_t
2059e1000_phy_reset(struct e1000_hw *hw)
2060{
2061 uint16_t phy_data;
2062
2063 DEBUGFUNC("e1000_phy_reset");
2064
2065 if(e1000_read_phy_reg(hw, PHY_CTRL, &phy_data) < 0) {
2066 DEBUGOUT("PHY Read Error\n");
2067 return -E1000_ERR_PHY;
2068 }
2069 phy_data |= MII_CR_RESET;
2070 if(e1000_write_phy_reg(hw, PHY_CTRL, phy_data) < 0) {
2071 DEBUGOUT("PHY Write Error\n");
2072 return -E1000_ERR_PHY;
2073 }
2074 udelay(1);
2075 return 0;
2076}
2077
2078
2079
2080
2081
2082
2083int32_t
2084e1000_detect_gig_phy(struct e1000_hw *hw)
2085{
2086 uint16_t phy_id_high, phy_id_low;
2087 boolean_t match = FALSE;
2088
2089 DEBUGFUNC("e1000_detect_gig_phy");
2090
2091
2092 if(e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high) < 0) {
2093 DEBUGOUT("PHY Read Error\n");
2094 return -E1000_ERR_PHY;
2095 }
2096 hw->phy_id = (uint32_t) (phy_id_high << 16);
2097 udelay(2);
2098 if(e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low) < 0) {
2099 DEBUGOUT("PHY Read Error\n");
2100 return -E1000_ERR_PHY;
2101 }
2102 hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
2103
2104 switch(hw->mac_type) {
2105 case e1000_82543:
2106 if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
2107 break;
2108 case e1000_82544:
2109 if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
2110 break;
2111 case e1000_82540:
2112 case e1000_82545:
2113 case e1000_82546:
2114 if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
2115 break;
2116 default:
2117 DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
2118 return -E1000_ERR_CONFIG;
2119 }
2120 if(match) {
2121 DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
2122 return 0;
2123 }
2124 DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
2125 return -E1000_ERR_PHY;
2126}
2127
2128
2129
2130
2131
2132
2133static int32_t
2134e1000_phy_reset_dsp(struct e1000_hw *hw)
2135{
2136 int32_t ret_val = -E1000_ERR_PHY;
2137 DEBUGFUNC("e1000_phy_reset_dsp");
2138
2139 do {
2140 if(e1000_write_phy_reg(hw, 29, 0x001d) < 0) break;
2141 if(e1000_write_phy_reg(hw, 30, 0x00c1) < 0) break;
2142 if(e1000_write_phy_reg(hw, 30, 0x0000) < 0) break;
2143 ret_val = 0;
2144 } while(0);
2145
2146 if(ret_val < 0) DEBUGOUT("PHY Write Error\n");
2147 return ret_val;
2148}
2149
2150
2151
2152
2153
2154
2155
2156int32_t
2157e1000_phy_get_info(struct e1000_hw *hw,
2158 struct e1000_phy_info *phy_info)
2159{
2160 int32_t ret_val = -E1000_ERR_PHY;
2161 uint16_t phy_data;
2162
2163 DEBUGFUNC("e1000_phy_get_info");
2164
2165 phy_info->cable_length = e1000_cable_length_undefined;
2166 phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
2167 phy_info->cable_polarity = e1000_rev_polarity_undefined;
2168 phy_info->polarity_correction = e1000_polarity_reversal_undefined;
2169 phy_info->mdix_mode = e1000_auto_x_mode_undefined;
2170 phy_info->local_rx = e1000_1000t_rx_status_undefined;
2171 phy_info->remote_rx = e1000_1000t_rx_status_undefined;
2172
2173 if(hw->media_type != e1000_media_type_copper) {
2174 DEBUGOUT("PHY info is only valid for copper media\n");
2175 return -E1000_ERR_CONFIG;
2176 }
2177
2178 do {
2179 if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) break;
2180 if(e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) break;
2181 if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
2182 DEBUGOUT("PHY info is only valid if link is up\n");
2183 return -E1000_ERR_CONFIG;
2184 }
2185
2186 if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data) < 0)
2187 break;
2188 phy_info->extended_10bt_distance =
2189 (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
2190 M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
2191 phy_info->polarity_correction =
2192 (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
2193 M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
2194
2195 if(e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0)
2196 break;
2197 phy_info->cable_polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
2198 M88E1000_PSSR_REV_POLARITY_SHIFT;
2199 phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
2200 M88E1000_PSSR_MDIX_SHIFT;
2201 if(phy_data & M88E1000_PSSR_1000MBS) {
2202
2203
2204
2205 phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
2206 M88E1000_PSSR_CABLE_LENGTH_SHIFT);
2207 if(e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data) < 0)
2208 break;
2209 phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
2210 SR_1000T_LOCAL_RX_STATUS_SHIFT;
2211 phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
2212 SR_1000T_REMOTE_RX_STATUS_SHIFT;
2213 }
2214 ret_val = 0;
2215 } while(0);
2216
2217 if(ret_val < 0) DEBUGOUT("PHY Read Error\n");
2218 return ret_val;
2219}
2220
2221int32_t
2222e1000_validate_mdi_setting(struct e1000_hw *hw)
2223{
2224 DEBUGFUNC("e1000_validate_mdi_settings");
2225
2226 if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
2227 DEBUGOUT("Invalid MDI setting detected\n");
2228 hw->mdix = 1;
2229 return -E1000_ERR_CONFIG;
2230 }
2231 return 0;
2232}
2233
2234
2235
2236
2237
2238
2239
2240static void
2241e1000_raise_ee_clk(struct e1000_hw *hw,
2242 uint32_t *eecd)
2243{
2244
2245
2246
2247 *eecd = *eecd | E1000_EECD_SK;
2248 E1000_WRITE_REG(hw, EECD, *eecd);
2249 E1000_WRITE_FLUSH(hw);
2250 udelay(50);
2251}
2252
2253
2254
2255
2256
2257
2258
2259static void
2260e1000_lower_ee_clk(struct e1000_hw *hw,
2261 uint32_t *eecd)
2262{
2263
2264
2265
2266 *eecd = *eecd & ~E1000_EECD_SK;
2267 E1000_WRITE_REG(hw, EECD, *eecd);
2268 E1000_WRITE_FLUSH(hw);
2269 udelay(50);
2270}
2271
2272
2273
2274
2275
2276
2277
2278
2279static void
2280e1000_shift_out_ee_bits(struct e1000_hw *hw,
2281 uint16_t data,
2282 uint16_t count)
2283{
2284 uint32_t eecd;
2285 uint32_t mask;
2286
2287
2288
2289
2290
2291 mask = 0x01 << (count - 1);
2292 eecd = E1000_READ_REG(hw, EECD);
2293 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
2294 do {
2295
2296
2297
2298
2299
2300 eecd &= ~E1000_EECD_DI;
2301
2302 if(data & mask)
2303 eecd |= E1000_EECD_DI;
2304
2305 E1000_WRITE_REG(hw, EECD, eecd);
2306 E1000_WRITE_FLUSH(hw);
2307
2308 udelay(50);
2309
2310 e1000_raise_ee_clk(hw, &eecd);
2311 e1000_lower_ee_clk(hw, &eecd);
2312
2313 mask = mask >> 1;
2314
2315 } while(mask);
2316
2317
2318 eecd &= ~E1000_EECD_DI;
2319 E1000_WRITE_REG(hw, EECD, eecd);
2320}
2321
2322
2323
2324
2325
2326
2327static uint16_t
2328e1000_shift_in_ee_bits(struct e1000_hw *hw)
2329{
2330 uint32_t eecd;
2331 uint32_t i;
2332 uint16_t data;
2333
2334
2335
2336
2337
2338
2339
2340
2341 eecd = E1000_READ_REG(hw, EECD);
2342
2343 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
2344 data = 0;
2345
2346 for(i = 0; i < 16; i++) {
2347 data = data << 1;
2348 e1000_raise_ee_clk(hw, &eecd);
2349
2350 eecd = E1000_READ_REG(hw, EECD);
2351
2352 eecd &= ~(E1000_EECD_DI);
2353 if(eecd & E1000_EECD_DO)
2354 data |= 1;
2355
2356 e1000_lower_ee_clk(hw, &eecd);
2357 }
2358
2359 return data;
2360}
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370static void
2371e1000_setup_eeprom(struct e1000_hw *hw)
2372{
2373 uint32_t eecd;
2374
2375 eecd = E1000_READ_REG(hw, EECD);
2376
2377
2378 eecd &= ~(E1000_EECD_SK | E1000_EECD_DI);
2379 E1000_WRITE_REG(hw, EECD, eecd);
2380
2381
2382 eecd |= E1000_EECD_CS;
2383 E1000_WRITE_REG(hw, EECD, eecd);
2384}
2385
2386
2387
2388
2389
2390
2391static void
2392e1000_standby_eeprom(struct e1000_hw *hw)
2393{
2394 uint32_t eecd;
2395
2396 eecd = E1000_READ_REG(hw, EECD);
2397
2398
2399 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
2400 E1000_WRITE_REG(hw, EECD, eecd);
2401 E1000_WRITE_FLUSH(hw);
2402 udelay(50);
2403
2404
2405 eecd |= E1000_EECD_SK;
2406 E1000_WRITE_REG(hw, EECD, eecd);
2407 E1000_WRITE_FLUSH(hw);
2408 udelay(50);
2409
2410
2411 eecd |= E1000_EECD_CS;
2412 E1000_WRITE_REG(hw, EECD, eecd);
2413 E1000_WRITE_FLUSH(hw);
2414 udelay(50);
2415
2416
2417 eecd &= ~E1000_EECD_SK;
2418 E1000_WRITE_REG(hw, EECD, eecd);
2419 E1000_WRITE_FLUSH(hw);
2420 udelay(50);
2421}
2422
2423
2424
2425
2426
2427
2428static void
2429e1000_clock_eeprom(struct e1000_hw *hw)
2430{
2431 uint32_t eecd;
2432
2433 eecd = E1000_READ_REG(hw, EECD);
2434
2435
2436 eecd |= E1000_EECD_SK;
2437 E1000_WRITE_REG(hw, EECD, eecd);
2438 E1000_WRITE_FLUSH(hw);
2439 udelay(50);
2440
2441
2442 eecd &= ~E1000_EECD_SK;
2443 E1000_WRITE_REG(hw, EECD, eecd);
2444 E1000_WRITE_FLUSH(hw);
2445 udelay(50);
2446}
2447
2448
2449
2450
2451
2452
2453static void
2454e1000_cleanup_eeprom(struct e1000_hw *hw)
2455{
2456 uint32_t eecd;
2457
2458 eecd = E1000_READ_REG(hw, EECD);
2459
2460 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
2461
2462 E1000_WRITE_REG(hw, EECD, eecd);
2463
2464 e1000_clock_eeprom(hw);
2465}
2466
2467
2468
2469
2470
2471
2472
2473
2474int32_t
2475e1000_read_eeprom(struct e1000_hw *hw,
2476 uint16_t offset,
2477 uint16_t *data)
2478{
2479 uint32_t eecd;
2480 uint32_t i = 0;
2481 boolean_t large_eeprom = FALSE;
2482
2483 DEBUGFUNC("e1000_read_eeprom");
2484
2485
2486 if(hw->mac_type > e1000_82544) {
2487 eecd = E1000_READ_REG(hw, EECD);
2488 if(eecd & E1000_EECD_SIZE) large_eeprom = TRUE;
2489 eecd |= E1000_EECD_REQ;
2490 E1000_WRITE_REG(hw, EECD, eecd);
2491 eecd = E1000_READ_REG(hw, EECD);
2492 while((!(eecd & E1000_EECD_GNT)) && (i < 100)) {
2493 i++;
2494 udelay(5);
2495 eecd = E1000_READ_REG(hw, EECD);
2496 }
2497 if(!(eecd & E1000_EECD_GNT)) {
2498 eecd &= ~E1000_EECD_REQ;
2499 E1000_WRITE_REG(hw, EECD, eecd);
2500 DEBUGOUT("Could not acquire EEPROM grant\n");
2501 return -E1000_ERR_EEPROM;
2502 }
2503 }
2504
2505
2506 e1000_setup_eeprom(hw);
2507
2508
2509 e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE, 3);
2510 if(large_eeprom) {
2511
2512 e1000_shift_out_ee_bits(hw, offset, 8);
2513 } else {
2514
2515 e1000_shift_out_ee_bits(hw, offset, 6);
2516 }
2517
2518
2519 *data = e1000_shift_in_ee_bits(hw);
2520
2521
2522 e1000_standby_eeprom(hw);
2523
2524
2525 if(hw->mac_type > e1000_82544) {
2526 eecd = E1000_READ_REG(hw, EECD);
2527 eecd &= ~E1000_EECD_REQ;
2528 E1000_WRITE_REG(hw, EECD, eecd);
2529 }
2530
2531 return 0;
2532}
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543int32_t
2544e1000_validate_eeprom_checksum(struct e1000_hw *hw)
2545{
2546 uint16_t checksum = 0;
2547 uint16_t i, eeprom_data;
2548
2549 DEBUGFUNC("e1000_validate_eeprom_checksum");
2550
2551 for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
2552 if(e1000_read_eeprom(hw, i, &eeprom_data) < 0) {
2553 DEBUGOUT("EEPROM Read Error\n");
2554 return -E1000_ERR_EEPROM;
2555 }
2556 checksum += eeprom_data;
2557 }
2558
2559 if(checksum == (uint16_t) EEPROM_SUM) {
2560 return 0;
2561 } else {
2562 DEBUGOUT("EEPROM Checksum Invalid\n");
2563 return -E1000_ERR_EEPROM;
2564 }
2565}
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575int32_t
2576e1000_update_eeprom_checksum(struct e1000_hw *hw)
2577{
2578 uint16_t checksum = 0;
2579 uint16_t i, eeprom_data;
2580
2581 DEBUGFUNC("e1000_update_eeprom_checksum");
2582
2583 for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
2584 if(e1000_read_eeprom(hw, i, &eeprom_data) < 0) {
2585 DEBUGOUT("EEPROM Read Error\n");
2586 return -E1000_ERR_EEPROM;
2587 }
2588 checksum += eeprom_data;
2589 }
2590 checksum = (uint16_t) EEPROM_SUM - checksum;
2591 if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, checksum) < 0) {
2592 DEBUGOUT("EEPROM Write Error\n");
2593 return -E1000_ERR_EEPROM;
2594 }
2595 return 0;
2596}
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608int32_t
2609e1000_write_eeprom(struct e1000_hw *hw,
2610 uint16_t offset,
2611 uint16_t data)
2612{
2613 uint32_t eecd;
2614 uint32_t i = 0;
2615 int32_t status = 0;
2616 boolean_t large_eeprom = FALSE;
2617
2618 DEBUGFUNC("e1000_write_eeprom");
2619
2620
2621 if(hw->mac_type > e1000_82544) {
2622 eecd = E1000_READ_REG(hw, EECD);
2623 if(eecd & E1000_EECD_SIZE) large_eeprom = TRUE;
2624 eecd |= E1000_EECD_REQ;
2625 E1000_WRITE_REG(hw, EECD, eecd);
2626 eecd = E1000_READ_REG(hw, EECD);
2627 while((!(eecd & E1000_EECD_GNT)) && (i < 100)) {
2628 i++;
2629 udelay(5);
2630 eecd = E1000_READ_REG(hw, EECD);
2631 }
2632 if(!(eecd & E1000_EECD_GNT)) {
2633 eecd &= ~E1000_EECD_REQ;
2634 E1000_WRITE_REG(hw, EECD, eecd);
2635 DEBUGOUT("Could not acquire EEPROM grant\n");
2636 return -E1000_ERR_EEPROM;
2637 }
2638 }
2639
2640
2641 e1000_setup_eeprom(hw);
2642
2643
2644
2645
2646
2647 e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE, 5);
2648 if(large_eeprom)
2649 e1000_shift_out_ee_bits(hw, 0, 6);
2650 else
2651 e1000_shift_out_ee_bits(hw, 0, 4);
2652
2653
2654 e1000_standby_eeprom(hw);
2655
2656
2657 e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE, 3);
2658 if(large_eeprom)
2659
2660 e1000_shift_out_ee_bits(hw, offset, 8);
2661 else
2662
2663 e1000_shift_out_ee_bits(hw, offset, 6);
2664
2665
2666 e1000_shift_out_ee_bits(hw, data, 16);
2667
2668
2669
2670
2671 e1000_standby_eeprom(hw);
2672
2673
2674
2675
2676
2677 for(i = 0; i < 200; i++) {
2678 eecd = E1000_READ_REG(hw, EECD);
2679 if(eecd & E1000_EECD_DO) break;
2680 udelay(50);
2681 }
2682 if(i == 200) {
2683 DEBUGOUT("EEPROM Write did not complete\n");
2684 status = -E1000_ERR_EEPROM;
2685 }
2686
2687
2688 e1000_standby_eeprom(hw);
2689
2690
2691
2692
2693
2694 e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE, 5);
2695 if(large_eeprom)
2696 e1000_shift_out_ee_bits(hw, 0, 6);
2697 else
2698 e1000_shift_out_ee_bits(hw, 0, 4);
2699
2700
2701 e1000_cleanup_eeprom(hw);
2702
2703
2704 if(hw->mac_type > e1000_82544) {
2705 eecd = E1000_READ_REG(hw, EECD);
2706 eecd &= ~E1000_EECD_REQ;
2707 E1000_WRITE_REG(hw, EECD, eecd);
2708 }
2709
2710 return status;
2711}
2712
2713
2714
2715
2716
2717
2718
2719int32_t
2720e1000_read_part_num(struct e1000_hw *hw,
2721 uint32_t *part_num)
2722{
2723 uint16_t offset = EEPROM_PBA_BYTE_1;
2724 uint16_t eeprom_data;
2725
2726 DEBUGFUNC("e1000_read_part_num");
2727
2728
2729 if(e1000_read_eeprom(hw, offset, &eeprom_data) < 0) {
2730 DEBUGOUT("EEPROM Read Error\n");
2731 return -E1000_ERR_EEPROM;
2732 }
2733
2734 *part_num = (uint32_t) (eeprom_data << 16);
2735
2736
2737 if(e1000_read_eeprom(hw, ++offset, &eeprom_data) < 0) {
2738 DEBUGOUT("EEPROM Read Error\n");
2739 return -E1000_ERR_EEPROM;
2740 }
2741
2742 *part_num |= eeprom_data;
2743
2744 return 0;
2745}
2746
2747
2748
2749
2750
2751
2752
2753int32_t
2754e1000_read_mac_addr(struct e1000_hw * hw)
2755{
2756 uint16_t offset;
2757 uint16_t eeprom_data, i;
2758
2759 DEBUGFUNC("e1000_read_mac_addr");
2760
2761 for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
2762 offset = i >> 1;
2763 if(e1000_read_eeprom(hw, offset, &eeprom_data) < 0) {
2764 DEBUGOUT("EEPROM Read Error\n");
2765 return -E1000_ERR_EEPROM;
2766 }
2767 hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
2768 hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
2769 }
2770 if((hw->mac_type == e1000_82546) &&
2771 (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
2772 if(hw->perm_mac_addr[5] & 0x01)
2773 hw->perm_mac_addr[5] &= ~(0x01);
2774 else
2775 hw->perm_mac_addr[5] |= 0x01;
2776 }
2777 for(i = 0; i < NODE_ADDRESS_SIZE; i++)
2778 hw->mac_addr[i] = hw->perm_mac_addr[i];
2779 return 0;
2780}
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791void
2792e1000_init_rx_addrs(struct e1000_hw *hw)
2793{
2794 uint32_t i;
2795 uint32_t addr_low;
2796 uint32_t addr_high;
2797
2798 DEBUGFUNC("e1000_init_rx_addrs");
2799
2800
2801 DEBUGOUT("Programming MAC Address into RAR[0]\n");
2802 addr_low = (hw->mac_addr[0] |
2803 (hw->mac_addr[1] << 8) |
2804 (hw->mac_addr[2] << 16) | (hw->mac_addr[3] << 24));
2805
2806 addr_high = (hw->mac_addr[4] |
2807 (hw->mac_addr[5] << 8) | E1000_RAH_AV);
2808
2809 E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
2810 E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
2811
2812
2813 DEBUGOUT("Clearing RAR[1-15]\n");
2814 for(i = 1; i < E1000_RAR_ENTRIES; i++) {
2815 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
2816 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
2817 }
2818}
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833void
2834e1000_mc_addr_list_update(struct e1000_hw *hw,
2835 uint8_t *mc_addr_list,
2836 uint32_t mc_addr_count,
2837 uint32_t pad)
2838{
2839 uint32_t hash_value;
2840 uint32_t i;
2841 uint32_t rar_used_count = 1;
2842
2843 DEBUGFUNC("e1000_mc_addr_list_update");
2844
2845
2846 hw->num_mc_addrs = mc_addr_count;
2847
2848
2849 DEBUGOUT(" Clearing RAR[1-15]\n");
2850 for(i = rar_used_count; i < E1000_RAR_ENTRIES; i++) {
2851 E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
2852 E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
2853 }
2854
2855
2856 DEBUGOUT(" Clearing MTA\n");
2857 for(i = 0; i < E1000_NUM_MTA_REGISTERS; i++) {
2858 E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
2859 }
2860
2861
2862 for(i = 0; i < mc_addr_count; i++) {
2863 DEBUGOUT(" Adding the multicast addresses:\n");
2864 DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
2865 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
2866 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
2867 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
2868 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
2869 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
2870 mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
2871
2872 hash_value = e1000_hash_mc_addr(hw,
2873 mc_addr_list +
2874 (i * (ETH_LENGTH_OF_ADDRESS + pad)));
2875
2876 DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
2877
2878
2879
2880
2881 if(rar_used_count < E1000_RAR_ENTRIES) {
2882 e1000_rar_set(hw,
2883 mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
2884 rar_used_count);
2885 rar_used_count++;
2886 } else {
2887 e1000_mta_set(hw, hash_value);
2888 }
2889 }
2890 DEBUGOUT("MC Update Complete\n");
2891}
2892
2893
2894
2895
2896
2897
2898
2899uint32_t
2900e1000_hash_mc_addr(struct e1000_hw *hw,
2901 uint8_t *mc_addr)
2902{
2903 uint32_t hash_value = 0;
2904
2905
2906
2907
2908 switch (hw->mc_filter_type) {
2909
2910
2911
2912
2913 case 0:
2914
2915 hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
2916 break;
2917 case 1:
2918
2919 hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
2920 break;
2921 case 2:
2922
2923 hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
2924 break;
2925 case 3:
2926
2927 hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
2928 break;
2929 }
2930
2931 hash_value &= 0xFFF;
2932 return hash_value;
2933}
2934
2935
2936
2937
2938
2939
2940
2941void
2942e1000_mta_set(struct e1000_hw *hw,
2943 uint32_t hash_value)
2944{
2945 uint32_t hash_bit, hash_reg;
2946 uint32_t mta;
2947 uint32_t temp;
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957 hash_reg = (hash_value >> 5) & 0x7F;
2958 hash_bit = hash_value & 0x1F;
2959
2960 mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
2961
2962 mta |= (1 << hash_bit);
2963
2964
2965
2966
2967
2968 if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
2969 temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
2970 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
2971 E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
2972 } else {
2973 E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
2974 }
2975}
2976
2977
2978
2979
2980
2981
2982
2983
2984void
2985e1000_rar_set(struct e1000_hw *hw,
2986 uint8_t *addr,
2987 uint32_t index)
2988{
2989 uint32_t rar_low, rar_high;
2990
2991
2992
2993
2994 rar_low = ((uint32_t) addr[0] |
2995 ((uint32_t) addr[1] << 8) |
2996 ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
2997
2998 rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8) | E1000_RAH_AV);
2999
3000 E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
3001 E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
3002}
3003
3004
3005
3006
3007
3008
3009
3010
3011void
3012e1000_write_vfta(struct e1000_hw *hw,
3013 uint32_t offset,
3014 uint32_t value)
3015{
3016 uint32_t temp;
3017
3018 if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
3019 temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
3020 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
3021 E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
3022 } else {
3023 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
3024 }
3025}
3026
3027
3028
3029
3030
3031
3032void
3033e1000_clear_vfta(struct e1000_hw *hw)
3034{
3035 uint32_t offset;
3036
3037 for(offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
3038 E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
3039}
3040
3041static int32_t
3042e1000_id_led_init(struct e1000_hw * hw)
3043{
3044 uint32_t ledctl;
3045 const uint32_t ledctl_mask = 0x000000FF;
3046 const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
3047 const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
3048 uint16_t eeprom_data, i, temp;
3049 const uint16_t led_mask = 0x0F;
3050
3051 DEBUGFUNC("e1000_id_led_init");
3052
3053 if(hw->mac_type < e1000_82540) {
3054
3055 return 0;
3056 }
3057
3058 ledctl = E1000_READ_REG(hw, LEDCTL);
3059 hw->ledctl_default = ledctl;
3060 hw->ledctl_mode1 = hw->ledctl_default;
3061 hw->ledctl_mode2 = hw->ledctl_default;
3062
3063 if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, &eeprom_data) < 0) {
3064 DEBUGOUT("EEPROM Read Error\n");
3065 return -E1000_ERR_EEPROM;
3066 }
3067 if((eeprom_data== ID_LED_RESERVED_0000) ||
3068 (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
3069 for(i = 0; i < 4; i++) {
3070 temp = (eeprom_data >> (i << 2)) & led_mask;
3071 switch(temp) {
3072 case ID_LED_ON1_DEF2:
3073 case ID_LED_ON1_ON2:
3074 case ID_LED_ON1_OFF2:
3075 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
3076 hw->ledctl_mode1 |= ledctl_on << (i << 3);
3077 break;
3078 case ID_LED_OFF1_DEF2:
3079 case ID_LED_OFF1_ON2:
3080 case ID_LED_OFF1_OFF2:
3081 hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
3082 hw->ledctl_mode1 |= ledctl_off << (i << 3);
3083 break;
3084 default:
3085
3086 break;
3087 }
3088 switch(temp) {
3089 case ID_LED_DEF1_ON2:
3090 case ID_LED_ON1_ON2:
3091 case ID_LED_OFF1_ON2:
3092 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
3093 hw->ledctl_mode2 |= ledctl_on << (i << 3);
3094 break;
3095 case ID_LED_DEF1_OFF2:
3096 case ID_LED_ON1_OFF2:
3097 case ID_LED_OFF1_OFF2:
3098 hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
3099 hw->ledctl_mode2 |= ledctl_off << (i << 3);
3100 break;
3101 default:
3102
3103 break;
3104 }
3105 }
3106 return 0;
3107}
3108
3109
3110
3111
3112
3113
3114int32_t
3115e1000_setup_led(struct e1000_hw *hw)
3116{
3117 uint32_t ledctl;
3118
3119 DEBUGFUNC("e1000_setup_led");
3120
3121 switch(hw->device_id) {
3122 case E1000_DEV_ID_82542:
3123 case E1000_DEV_ID_82543GC_FIBER:
3124 case E1000_DEV_ID_82543GC_COPPER:
3125 case E1000_DEV_ID_82544EI_COPPER:
3126 case E1000_DEV_ID_82544EI_FIBER:
3127 case E1000_DEV_ID_82544GC_COPPER:
3128 case E1000_DEV_ID_82544GC_LOM:
3129
3130 break;
3131 case E1000_DEV_ID_82545EM_FIBER:
3132 case E1000_DEV_ID_82546EB_FIBER:
3133 ledctl = E1000_READ_REG(hw, LEDCTL);
3134
3135 hw->ledctl_default = ledctl;
3136
3137 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
3138 E1000_LEDCTL_LED0_BLINK |
3139 E1000_LEDCTL_LED0_MODE_MASK);
3140 ledctl |= (E1000_LEDCTL_MODE_LED_OFF << E1000_LEDCTL_LED0_MODE_SHIFT);
3141 E1000_WRITE_REG(hw, LEDCTL, ledctl);
3142 break;
3143 case E1000_DEV_ID_82540EM:
3144 case E1000_DEV_ID_82540EM_LOM:
3145 case E1000_DEV_ID_82545EM_COPPER:
3146 case E1000_DEV_ID_82546EB_COPPER:
3147 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
3148 break;
3149 default:
3150 DEBUGOUT("Invalid device ID\n");
3151 return -E1000_ERR_CONFIG;
3152 }
3153 return 0;
3154}
3155
3156
3157
3158
3159
3160
3161int32_t
3162e1000_cleanup_led(struct e1000_hw *hw)
3163{
3164 DEBUGFUNC("e1000_cleanup_led");
3165
3166 switch(hw->device_id) {
3167 case E1000_DEV_ID_82542:
3168 case E1000_DEV_ID_82543GC_FIBER:
3169 case E1000_DEV_ID_82543GC_COPPER:
3170 case E1000_DEV_ID_82544EI_COPPER:
3171 case E1000_DEV_ID_82544EI_FIBER:
3172 case E1000_DEV_ID_82544GC_COPPER:
3173 case E1000_DEV_ID_82544GC_LOM:
3174
3175 break;
3176 case E1000_DEV_ID_82540EM:
3177 case E1000_DEV_ID_82540EM_LOM:
3178 case E1000_DEV_ID_82545EM_COPPER:
3179 case E1000_DEV_ID_82545EM_FIBER:
3180 case E1000_DEV_ID_82546EB_COPPER:
3181 case E1000_DEV_ID_82546EB_FIBER:
3182
3183 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
3184 break;
3185 default:
3186 DEBUGOUT("Invalid device ID\n");
3187 return -E1000_ERR_CONFIG;
3188 }
3189 return 0;
3190}
3191
3192
3193
3194
3195
3196
3197int32_t
3198e1000_led_on(struct e1000_hw *hw)
3199{
3200 uint32_t ctrl;
3201
3202 DEBUGFUNC("e1000_led_on");
3203
3204 switch(hw->device_id) {
3205 case E1000_DEV_ID_82542:
3206 case E1000_DEV_ID_82543GC_FIBER:
3207 case E1000_DEV_ID_82543GC_COPPER:
3208 case E1000_DEV_ID_82544EI_FIBER:
3209 ctrl = E1000_READ_REG(hw, CTRL);
3210
3211 ctrl |= E1000_CTRL_SWDPIN0;
3212 ctrl |= E1000_CTRL_SWDPIO0;
3213 E1000_WRITE_REG(hw, CTRL, ctrl);
3214 break;
3215 case E1000_DEV_ID_82544EI_COPPER:
3216 case E1000_DEV_ID_82544GC_COPPER:
3217 case E1000_DEV_ID_82544GC_LOM:
3218 case E1000_DEV_ID_82545EM_FIBER:
3219 case E1000_DEV_ID_82546EB_FIBER:
3220 ctrl = E1000_READ_REG(hw, CTRL);
3221
3222 ctrl &= ~E1000_CTRL_SWDPIN0;
3223 ctrl |= E1000_CTRL_SWDPIO0;
3224 E1000_WRITE_REG(hw, CTRL, ctrl);
3225 break;
3226 case E1000_DEV_ID_82540EM:
3227 case E1000_DEV_ID_82540EM_LOM:
3228 case E1000_DEV_ID_82545EM_COPPER:
3229 case E1000_DEV_ID_82546EB_COPPER:
3230 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
3231 break;
3232 default:
3233 DEBUGOUT("Invalid device ID\n");
3234 return -E1000_ERR_CONFIG;
3235 }
3236 return 0;
3237}
3238
3239
3240
3241
3242
3243
3244int32_t
3245e1000_led_off(struct e1000_hw *hw)
3246{
3247 uint32_t ctrl;
3248
3249 DEBUGFUNC("e1000_led_off");
3250
3251 switch(hw->device_id) {
3252 case E1000_DEV_ID_82542:
3253 case E1000_DEV_ID_82543GC_FIBER:
3254 case E1000_DEV_ID_82543GC_COPPER:
3255 case E1000_DEV_ID_82544EI_FIBER:
3256 ctrl = E1000_READ_REG(hw, CTRL);
3257
3258 ctrl &= ~E1000_CTRL_SWDPIN0;
3259 ctrl |= E1000_CTRL_SWDPIO0;
3260 E1000_WRITE_REG(hw, CTRL, ctrl);
3261 break;
3262 case E1000_DEV_ID_82544EI_COPPER:
3263 case E1000_DEV_ID_82544GC_COPPER:
3264 case E1000_DEV_ID_82544GC_LOM:
3265 case E1000_DEV_ID_82545EM_FIBER:
3266 case E1000_DEV_ID_82546EB_FIBER:
3267 ctrl = E1000_READ_REG(hw, CTRL);
3268
3269 ctrl |= E1000_CTRL_SWDPIN0;
3270 ctrl |= E1000_CTRL_SWDPIO0;
3271 E1000_WRITE_REG(hw, CTRL, ctrl);
3272 break;
3273 case E1000_DEV_ID_82540EM:
3274 case E1000_DEV_ID_82540EM_LOM:
3275 case E1000_DEV_ID_82545EM_COPPER:
3276 case E1000_DEV_ID_82546EB_COPPER:
3277 E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
3278 break;
3279 default:
3280 DEBUGOUT("Invalid device ID\n");
3281 return -E1000_ERR_CONFIG;
3282 }
3283 return 0;
3284}
3285
3286
3287
3288
3289
3290
3291void
3292e1000_clear_hw_cntrs(struct e1000_hw *hw)
3293{
3294 volatile uint32_t temp;
3295
3296 temp = E1000_READ_REG(hw, CRCERRS);
3297 temp = E1000_READ_REG(hw, SYMERRS);
3298 temp = E1000_READ_REG(hw, MPC);
3299 temp = E1000_READ_REG(hw, SCC);
3300 temp = E1000_READ_REG(hw, ECOL);
3301 temp = E1000_READ_REG(hw, MCC);
3302 temp = E1000_READ_REG(hw, LATECOL);
3303 temp = E1000_READ_REG(hw, COLC);
3304 temp = E1000_READ_REG(hw, DC);
3305 temp = E1000_READ_REG(hw, SEC);
3306 temp = E1000_READ_REG(hw, RLEC);
3307 temp = E1000_READ_REG(hw, XONRXC);
3308 temp = E1000_READ_REG(hw, XONTXC);
3309 temp = E1000_READ_REG(hw, XOFFRXC);
3310 temp = E1000_READ_REG(hw, XOFFTXC);
3311 temp = E1000_READ_REG(hw, FCRUC);
3312 temp = E1000_READ_REG(hw, PRC64);
3313 temp = E1000_READ_REG(hw, PRC127);
3314 temp = E1000_READ_REG(hw, PRC255);
3315 temp = E1000_READ_REG(hw, PRC511);
3316 temp = E1000_READ_REG(hw, PRC1023);
3317 temp = E1000_READ_REG(hw, PRC1522);
3318 temp = E1000_READ_REG(hw, GPRC);
3319 temp = E1000_READ_REG(hw, BPRC);
3320 temp = E1000_READ_REG(hw, MPRC);
3321 temp = E1000_READ_REG(hw, GPTC);
3322 temp = E1000_READ_REG(hw, GORCL);
3323 temp = E1000_READ_REG(hw, GORCH);
3324 temp = E1000_READ_REG(hw, GOTCL);
3325 temp = E1000_READ_REG(hw, GOTCH);
3326 temp = E1000_READ_REG(hw, RNBC);
3327 temp = E1000_READ_REG(hw, RUC);
3328 temp = E1000_READ_REG(hw, RFC);
3329 temp = E1000_READ_REG(hw, ROC);
3330 temp = E1000_READ_REG(hw, RJC);
3331 temp = E1000_READ_REG(hw, TORL);
3332 temp = E1000_READ_REG(hw, TORH);
3333 temp = E1000_READ_REG(hw, TOTL);
3334 temp = E1000_READ_REG(hw, TOTH);
3335 temp = E1000_READ_REG(hw, TPR);
3336 temp = E1000_READ_REG(hw, TPT);
3337 temp = E1000_READ_REG(hw, PTC64);
3338 temp = E1000_READ_REG(hw, PTC127);
3339 temp = E1000_READ_REG(hw, PTC255);
3340 temp = E1000_READ_REG(hw, PTC511);
3341 temp = E1000_READ_REG(hw, PTC1023);
3342 temp = E1000_READ_REG(hw, PTC1522);
3343 temp = E1000_READ_REG(hw, MPTC);
3344 temp = E1000_READ_REG(hw, BPTC);
3345
3346 if(hw->mac_type < e1000_82543) return;
3347
3348 temp = E1000_READ_REG(hw, ALGNERRC);
3349 temp = E1000_READ_REG(hw, RXERRC);
3350 temp = E1000_READ_REG(hw, TNCRS);
3351 temp = E1000_READ_REG(hw, CEXTERR);
3352 temp = E1000_READ_REG(hw, TSCTC);
3353 temp = E1000_READ_REG(hw, TSCTFC);
3354
3355 if(hw->mac_type <= e1000_82544) return;
3356
3357 temp = E1000_READ_REG(hw, MGTPRC);
3358 temp = E1000_READ_REG(hw, MGTPDC);
3359 temp = E1000_READ_REG(hw, MGTPTC);
3360}
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372void
3373e1000_reset_adaptive(struct e1000_hw *hw)
3374{
3375 DEBUGFUNC("e1000_reset_adaptive");
3376
3377 if(hw->adaptive_ifs) {
3378 if(!hw->ifs_params_forced) {
3379 hw->current_ifs_val = 0;
3380 hw->ifs_min_val = IFS_MIN;
3381 hw->ifs_max_val = IFS_MAX;
3382 hw->ifs_step_size = IFS_STEP;
3383 hw->ifs_ratio = IFS_RATIO;
3384 }
3385 hw->in_ifs_mode = FALSE;
3386 E1000_WRITE_REG(hw, AIT, 0);
3387 } else {
3388 DEBUGOUT("Not in Adaptive IFS mode!\n");
3389 }
3390}
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400void
3401e1000_update_adaptive(struct e1000_hw *hw)
3402{
3403 DEBUGFUNC("e1000_update_adaptive");
3404
3405 if(hw->adaptive_ifs) {
3406 if((hw->collision_delta * hw->ifs_ratio) >
3407 hw->tx_packet_delta) {
3408 if(hw->tx_packet_delta > MIN_NUM_XMITS) {
3409 hw->in_ifs_mode = TRUE;
3410 if(hw->current_ifs_val < hw->ifs_max_val) {
3411 if(hw->current_ifs_val == 0)
3412 hw->current_ifs_val = hw->ifs_min_val;
3413 else
3414 hw->current_ifs_val += hw->ifs_step_size;
3415 E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
3416 }
3417 }
3418 } else {
3419 if((hw->in_ifs_mode == TRUE) &&
3420 (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
3421 hw->current_ifs_val = 0;
3422 hw->in_ifs_mode = FALSE;
3423 E1000_WRITE_REG(hw, AIT, 0);
3424 }
3425 }
3426 } else {
3427 DEBUGOUT("Not in Adaptive IFS mode!\n");
3428 }
3429}
3430
3431
3432
3433
3434
3435
3436
3437
3438void
3439e1000_tbi_adjust_stats(struct e1000_hw *hw,
3440 struct e1000_hw_stats *stats,
3441 uint32_t frame_len,
3442 uint8_t *mac_addr)
3443{
3444 uint64_t carry_bit;
3445
3446
3447 frame_len--;
3448
3449
3450
3451
3452
3453 stats->crcerrs--;
3454
3455 stats->gprc++;
3456
3457
3458 carry_bit = 0x80000000 & stats->gorcl;
3459 stats->gorcl += frame_len;
3460
3461
3462
3463
3464
3465
3466
3467 if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
3468 stats->gorch++;
3469
3470
3471
3472
3473 if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
3474
3475 stats->bprc++;
3476 else if(*mac_addr & 0x01)
3477
3478 stats->mprc++;
3479
3480 if(frame_len == hw->max_frame_size) {
3481
3482
3483
3484 if(stats->roc > 0)
3485 stats->roc--;
3486 }
3487
3488
3489
3490
3491 if(frame_len == 64) {
3492 stats->prc64++;
3493 stats->prc127--;
3494 } else if(frame_len == 127) {
3495 stats->prc127++;
3496 stats->prc255--;
3497 } else if(frame_len == 255) {
3498 stats->prc255++;
3499 stats->prc511--;
3500 } else if(frame_len == 511) {
3501 stats->prc511++;
3502 stats->prc1023--;
3503 } else if(frame_len == 1023) {
3504 stats->prc1023++;
3505 stats->prc1522--;
3506 } else if(frame_len == 1522) {
3507 stats->prc1522++;
3508 }
3509}
3510
3511
3512
3513
3514
3515
3516void
3517e1000_get_bus_info(struct e1000_hw *hw)
3518{
3519 uint32_t status;
3520
3521 if(hw->mac_type < e1000_82543) {
3522 hw->bus_type = e1000_bus_type_unknown;
3523 hw->bus_speed = e1000_bus_speed_unknown;
3524 hw->bus_width = e1000_bus_width_unknown;
3525 return;
3526 }
3527
3528 status = E1000_READ_REG(hw, STATUS);
3529 hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
3530 e1000_bus_type_pcix : e1000_bus_type_pci;
3531 if(hw->bus_type == e1000_bus_type_pci) {
3532 hw->bus_speed = (status & E1000_STATUS_PCI66) ?
3533 e1000_bus_speed_66 : e1000_bus_speed_33;
3534 } else {
3535 switch (status & E1000_STATUS_PCIX_SPEED) {
3536 case E1000_STATUS_PCIX_SPEED_66:
3537 hw->bus_speed = e1000_bus_speed_66;
3538 break;
3539 case E1000_STATUS_PCIX_SPEED_100:
3540 hw->bus_speed = e1000_bus_speed_100;
3541 break;
3542 case E1000_STATUS_PCIX_SPEED_133:
3543 hw->bus_speed = e1000_bus_speed_133;
3544 break;
3545 default:
3546 hw->bus_speed = e1000_bus_speed_reserved;
3547 break;
3548 }
3549 }
3550 hw->bus_width = (status & E1000_STATUS_BUS64) ?
3551 e1000_bus_width_64 : e1000_bus_width_32;
3552}
3553
3554
3555
3556
3557
3558
3559
3560uint32_t
3561e1000_read_reg_io(struct e1000_hw *hw,
3562 uint32_t offset)
3563{
3564 uint32_t io_addr = hw->io_base;
3565 uint32_t io_data = hw->io_base + 4;
3566
3567 e1000_io_write(hw, io_addr, offset);
3568 return e1000_io_read(hw, io_data);
3569}
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579void
3580e1000_write_reg_io(struct e1000_hw *hw,
3581 uint32_t offset,
3582 uint32_t value)
3583{
3584 uint32_t io_addr = hw->io_base;
3585 uint32_t io_data = hw->io_base + 4;
3586
3587 e1000_io_write(hw, io_addr, offset);
3588 e1000_io_write(hw, io_data, value);
3589}
3590
3591