~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/net/ixgbe/ixgbe_common.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*******************************************************************************
2
2
 
3
3
  Intel 10 Gigabit PCI Express Linux driver
4
 
  Copyright(c) 1999 - 2010 Intel Corporation.
 
4
  Copyright(c) 1999 - 2011 Intel Corporation.
5
5
 
6
6
  This program is free software; you can redistribute it and/or modify it
7
7
  under the terms and conditions of the GNU General Public License,
46
46
static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
47
47
static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
48
48
 
49
 
static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index);
50
 
static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index);
51
49
static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
52
 
static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq);
 
50
static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw);
 
51
static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw);
 
52
static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw);
 
53
static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw);
 
54
static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
 
55
                              u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm);
53
56
static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num);
 
57
static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg);
 
58
static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
 
59
                                             u16 words, u16 *data);
 
60
static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
 
61
                                             u16 words, u16 *data);
 
62
static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
 
63
                                                 u16 offset);
54
64
 
55
65
/**
56
66
 *  ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
93
103
}
94
104
 
95
105
/**
 
106
 *  ixgbe_start_hw_gen2 - Init sequence for common device family
 
107
 *  @hw: pointer to hw structure
 
108
 *
 
109
 * Performs the init sequence common to the second generation
 
110
 * of 10 GbE devices.
 
111
 * Devices in the second generation:
 
112
 *     82599
 
113
 *     X540
 
114
 **/
 
115
s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
 
116
{
 
117
        u32 i;
 
118
        u32 regval;
 
119
 
 
120
        /* Clear the rate limiters */
 
121
        for (i = 0; i < hw->mac.max_tx_queues; i++) {
 
122
                IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
 
123
                IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
 
124
        }
 
125
        IXGBE_WRITE_FLUSH(hw);
 
126
 
 
127
        /* Disable relaxed ordering */
 
128
        for (i = 0; i < hw->mac.max_tx_queues; i++) {
 
129
                regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
 
130
                regval &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN;
 
131
                IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
 
132
        }
 
133
 
 
134
        for (i = 0; i < hw->mac.max_rx_queues; i++) {
 
135
                regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
 
136
                regval &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN |
 
137
                                        IXGBE_DCA_RXCTRL_DESC_HSRO_EN);
 
138
                IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
 
139
        }
 
140
 
 
141
        return 0;
 
142
}
 
143
 
 
144
/**
96
145
 *  ixgbe_init_hw_generic - Generic hardware initialization
97
146
 *  @hw: pointer to hardware structure
98
147
 *
139
188
        IXGBE_READ_REG(hw, IXGBE_MRFC);
140
189
        IXGBE_READ_REG(hw, IXGBE_RLEC);
141
190
        IXGBE_READ_REG(hw, IXGBE_LXONTXC);
142
 
        IXGBE_READ_REG(hw, IXGBE_LXONRXC);
143
191
        IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
144
 
        IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
 
192
        if (hw->mac.type >= ixgbe_mac_82599EB) {
 
193
                IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
 
194
                IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
 
195
        } else {
 
196
                IXGBE_READ_REG(hw, IXGBE_LXONRXC);
 
197
                IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
 
198
        }
145
199
 
146
200
        for (i = 0; i < 8; i++) {
147
201
                IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
148
 
                IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
149
202
                IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
150
 
                IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
 
203
                if (hw->mac.type >= ixgbe_mac_82599EB) {
 
204
                        IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
 
205
                        IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
 
206
                } else {
 
207
                        IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
 
208
                        IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
 
209
                }
151
210
        }
152
 
 
 
211
        if (hw->mac.type >= ixgbe_mac_82599EB)
 
212
                for (i = 0; i < 8; i++)
 
213
                        IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
153
214
        IXGBE_READ_REG(hw, IXGBE_PRC64);
154
215
        IXGBE_READ_REG(hw, IXGBE_PRC127);
155
216
        IXGBE_READ_REG(hw, IXGBE_PRC255);
187
248
        IXGBE_READ_REG(hw, IXGBE_BPTC);
188
249
        for (i = 0; i < 16; i++) {
189
250
                IXGBE_READ_REG(hw, IXGBE_QPRC(i));
190
 
                IXGBE_READ_REG(hw, IXGBE_QBRC(i));
191
251
                IXGBE_READ_REG(hw, IXGBE_QPTC(i));
192
 
                IXGBE_READ_REG(hw, IXGBE_QBTC(i));
 
252
                if (hw->mac.type >= ixgbe_mac_82599EB) {
 
253
                        IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
 
254
                        IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
 
255
                        IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
 
256
                        IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
 
257
                        IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
 
258
                } else {
 
259
                        IXGBE_READ_REG(hw, IXGBE_QBRC(i));
 
260
                        IXGBE_READ_REG(hw, IXGBE_QBTC(i));
 
261
                }
 
262
        }
 
263
 
 
264
        if (hw->mac.type == ixgbe_mac_X540) {
 
265
                if (hw->phy.id == 0)
 
266
                        hw->phy.ops.identify(hw);
 
267
                hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECL, &i);
 
268
                hw->phy.ops.read_reg(hw, 0x3, IXGBE_PCRC8ECH, &i);
 
269
                hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECL, &i);
 
270
                hw->phy.ops.read_reg(hw, 0x3, IXGBE_LDPCECH, &i);
193
271
        }
194
272
 
195
273
        return 0;
432
510
        reg_val &= ~(IXGBE_RXCTRL_RXEN);
433
511
        IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
434
512
        IXGBE_WRITE_FLUSH(hw);
435
 
        msleep(2);
 
513
        usleep_range(2000, 4000);
436
514
 
437
515
        /* Clear interrupt mask to stop from interrupts being generated */
438
516
        IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
454
532
         * Prevent the PCI-E bus from from hanging by disabling PCI-E master
455
533
         * access and verify no pending requests
456
534
         */
457
 
        if (ixgbe_disable_pcie_master(hw) != 0)
458
 
                hw_dbg(hw, "PCI-E Master disable polling has failed.\n");
 
535
        ixgbe_disable_pcie_master(hw);
459
536
 
460
537
        return 0;
461
538
}
514
591
                /* Set default semaphore delay to 10ms which is a well
515
592
                 * tested value */
516
593
                eeprom->semaphore_delay = 10;
 
594
                /* Clear EEPROM page size, it will be initialized as needed */
 
595
                eeprom->word_page_size = 0;
517
596
 
518
597
                /*
519
598
                 * Check for EEPROM present first.
546
625
}
547
626
 
548
627
/**
 
628
 *  ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang
 
629
 *  @hw: pointer to hardware structure
 
630
 *  @offset: offset within the EEPROM to write
 
631
 *  @words: number of words
 
632
 *  @data: 16 bit word(s) to write to EEPROM
 
633
 *
 
634
 *  Reads 16 bit word(s) from EEPROM through bit-bang method
 
635
 **/
 
636
s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
 
637
                                               u16 words, u16 *data)
 
638
{
 
639
        s32 status = 0;
 
640
        u16 i, count;
 
641
 
 
642
        hw->eeprom.ops.init_params(hw);
 
643
 
 
644
        if (words == 0) {
 
645
                status = IXGBE_ERR_INVALID_ARGUMENT;
 
646
                goto out;
 
647
        }
 
648
 
 
649
        if (offset + words > hw->eeprom.word_size) {
 
650
                status = IXGBE_ERR_EEPROM;
 
651
                goto out;
 
652
        }
 
653
 
 
654
        /*
 
655
         * The EEPROM page size cannot be queried from the chip. We do lazy
 
656
         * initialization. It is worth to do that when we write large buffer.
 
657
         */
 
658
        if ((hw->eeprom.word_page_size == 0) &&
 
659
            (words > IXGBE_EEPROM_PAGE_SIZE_MAX))
 
660
                ixgbe_detect_eeprom_page_size_generic(hw, offset);
 
661
 
 
662
        /*
 
663
         * We cannot hold synchronization semaphores for too long
 
664
         * to avoid other entity starvation. However it is more efficient
 
665
         * to read in bursts than synchronizing access for each word.
 
666
         */
 
667
        for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
 
668
                count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
 
669
                         IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
 
670
                status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i,
 
671
                                                            count, &data[i]);
 
672
 
 
673
                if (status != 0)
 
674
                        break;
 
675
        }
 
676
 
 
677
out:
 
678
        return status;
 
679
}
 
680
 
 
681
/**
 
682
 *  ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM
 
683
 *  @hw: pointer to hardware structure
 
684
 *  @offset: offset within the EEPROM to be written to
 
685
 *  @words: number of word(s)
 
686
 *  @data: 16 bit word(s) to be written to the EEPROM
 
687
 *
 
688
 *  If ixgbe_eeprom_update_checksum is not called after this function, the
 
689
 *  EEPROM will most likely contain an invalid checksum.
 
690
 **/
 
691
static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
 
692
                                              u16 words, u16 *data)
 
693
{
 
694
        s32 status;
 
695
        u16 word;
 
696
        u16 page_size;
 
697
        u16 i;
 
698
        u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
 
699
 
 
700
        /* Prepare the EEPROM for writing  */
 
701
        status = ixgbe_acquire_eeprom(hw);
 
702
 
 
703
        if (status == 0) {
 
704
                if (ixgbe_ready_eeprom(hw) != 0) {
 
705
                        ixgbe_release_eeprom(hw);
 
706
                        status = IXGBE_ERR_EEPROM;
 
707
                }
 
708
        }
 
709
 
 
710
        if (status == 0) {
 
711
                for (i = 0; i < words; i++) {
 
712
                        ixgbe_standby_eeprom(hw);
 
713
 
 
714
                        /*  Send the WRITE ENABLE command (8 bit opcode )  */
 
715
                        ixgbe_shift_out_eeprom_bits(hw,
 
716
                                                  IXGBE_EEPROM_WREN_OPCODE_SPI,
 
717
                                                  IXGBE_EEPROM_OPCODE_BITS);
 
718
 
 
719
                        ixgbe_standby_eeprom(hw);
 
720
 
 
721
                        /*
 
722
                         * Some SPI eeproms use the 8th address bit embedded
 
723
                         * in the opcode
 
724
                         */
 
725
                        if ((hw->eeprom.address_bits == 8) &&
 
726
                            ((offset + i) >= 128))
 
727
                                write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
 
728
 
 
729
                        /* Send the Write command (8-bit opcode + addr) */
 
730
                        ixgbe_shift_out_eeprom_bits(hw, write_opcode,
 
731
                                                    IXGBE_EEPROM_OPCODE_BITS);
 
732
                        ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
 
733
                                                    hw->eeprom.address_bits);
 
734
 
 
735
                        page_size = hw->eeprom.word_page_size;
 
736
 
 
737
                        /* Send the data in burst via SPI*/
 
738
                        do {
 
739
                                word = data[i];
 
740
                                word = (word >> 8) | (word << 8);
 
741
                                ixgbe_shift_out_eeprom_bits(hw, word, 16);
 
742
 
 
743
                                if (page_size == 0)
 
744
                                        break;
 
745
 
 
746
                                /* do not wrap around page */
 
747
                                if (((offset + i) & (page_size - 1)) ==
 
748
                                    (page_size - 1))
 
749
                                        break;
 
750
                        } while (++i < words);
 
751
 
 
752
                        ixgbe_standby_eeprom(hw);
 
753
                        usleep_range(10000, 20000);
 
754
                }
 
755
                /* Done with writing - release the EEPROM */
 
756
                ixgbe_release_eeprom(hw);
 
757
        }
 
758
 
 
759
        return status;
 
760
}
 
761
 
 
762
/**
549
763
 *  ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
550
764
 *  @hw: pointer to hardware structure
551
765
 *  @offset: offset within the EEPROM to be written to
557
771
s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
558
772
{
559
773
        s32 status;
560
 
        u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
561
774
 
562
775
        hw->eeprom.ops.init_params(hw);
563
776
 
566
779
                goto out;
567
780
        }
568
781
 
569
 
        /* Prepare the EEPROM for writing  */
 
782
        status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data);
 
783
 
 
784
out:
 
785
        return status;
 
786
}
 
787
 
 
788
/**
 
789
 *  ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang
 
790
 *  @hw: pointer to hardware structure
 
791
 *  @offset: offset within the EEPROM to be read
 
792
 *  @words: number of word(s)
 
793
 *  @data: read 16 bit words(s) from EEPROM
 
794
 *
 
795
 *  Reads 16 bit word(s) from EEPROM through bit-bang method
 
796
 **/
 
797
s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
 
798
                                              u16 words, u16 *data)
 
799
{
 
800
        s32 status = 0;
 
801
        u16 i, count;
 
802
 
 
803
        hw->eeprom.ops.init_params(hw);
 
804
 
 
805
        if (words == 0) {
 
806
                status = IXGBE_ERR_INVALID_ARGUMENT;
 
807
                goto out;
 
808
        }
 
809
 
 
810
        if (offset + words > hw->eeprom.word_size) {
 
811
                status = IXGBE_ERR_EEPROM;
 
812
                goto out;
 
813
        }
 
814
 
 
815
        /*
 
816
         * We cannot hold synchronization semaphores for too long
 
817
         * to avoid other entity starvation. However it is more efficient
 
818
         * to read in bursts than synchronizing access for each word.
 
819
         */
 
820
        for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
 
821
                count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
 
822
                         IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
 
823
 
 
824
                status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i,
 
825
                                                           count, &data[i]);
 
826
 
 
827
                if (status != 0)
 
828
                        break;
 
829
        }
 
830
 
 
831
out:
 
832
        return status;
 
833
}
 
834
 
 
835
/**
 
836
 *  ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang
 
837
 *  @hw: pointer to hardware structure
 
838
 *  @offset: offset within the EEPROM to be read
 
839
 *  @words: number of word(s)
 
840
 *  @data: read 16 bit word(s) from EEPROM
 
841
 *
 
842
 *  Reads 16 bit word(s) from EEPROM through bit-bang method
 
843
 **/
 
844
static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
 
845
                                             u16 words, u16 *data)
 
846
{
 
847
        s32 status;
 
848
        u16 word_in;
 
849
        u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
 
850
        u16 i;
 
851
 
 
852
        /* Prepare the EEPROM for reading  */
570
853
        status = ixgbe_acquire_eeprom(hw);
571
854
 
572
855
        if (status == 0) {
577
860
        }
578
861
 
579
862
        if (status == 0) {
580
 
                ixgbe_standby_eeprom(hw);
581
 
 
582
 
                /*  Send the WRITE ENABLE command (8 bit opcode )  */
583
 
                ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
584
 
                                            IXGBE_EEPROM_OPCODE_BITS);
585
 
 
586
 
                ixgbe_standby_eeprom(hw);
587
 
 
588
 
                /*
589
 
                 * Some SPI eeproms use the 8th address bit embedded in the
590
 
                 * opcode
591
 
                 */
592
 
                if ((hw->eeprom.address_bits == 8) && (offset >= 128))
593
 
                        write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
594
 
 
595
 
                /* Send the Write command (8-bit opcode + addr) */
596
 
                ixgbe_shift_out_eeprom_bits(hw, write_opcode,
597
 
                                            IXGBE_EEPROM_OPCODE_BITS);
598
 
                ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
599
 
                                            hw->eeprom.address_bits);
600
 
 
601
 
                /* Send the data */
602
 
                data = (data >> 8) | (data << 8);
603
 
                ixgbe_shift_out_eeprom_bits(hw, data, 16);
604
 
                ixgbe_standby_eeprom(hw);
605
 
 
606
 
                msleep(hw->eeprom.semaphore_delay);
607
 
                /* Done with writing - release the EEPROM */
 
863
                for (i = 0; i < words; i++) {
 
864
                        ixgbe_standby_eeprom(hw);
 
865
                        /*
 
866
                         * Some SPI eeproms use the 8th address bit embedded
 
867
                         * in the opcode
 
868
                         */
 
869
                        if ((hw->eeprom.address_bits == 8) &&
 
870
                            ((offset + i) >= 128))
 
871
                                read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
 
872
 
 
873
                        /* Send the READ command (opcode + addr) */
 
874
                        ixgbe_shift_out_eeprom_bits(hw, read_opcode,
 
875
                                                    IXGBE_EEPROM_OPCODE_BITS);
 
876
                        ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
 
877
                                                    hw->eeprom.address_bits);
 
878
 
 
879
                        /* Read the data. */
 
880
                        word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
 
881
                        data[i] = (word_in >> 8) | (word_in << 8);
 
882
                }
 
883
 
 
884
                /* End this read operation */
608
885
                ixgbe_release_eeprom(hw);
609
886
        }
610
887
 
611
 
out:
612
888
        return status;
613
889
}
614
890
 
621
897
 *  Reads 16 bit value from EEPROM through bit-bang method
622
898
 **/
623
899
s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
624
 
                                       u16 *data)
 
900
                                       u16 *data)
625
901
{
626
902
        s32 status;
627
 
        u16 word_in;
628
 
        u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
629
 
 
630
 
        hw->eeprom.ops.init_params(hw);
631
 
 
632
 
        if (offset >= hw->eeprom.word_size) {
633
 
                status = IXGBE_ERR_EEPROM;
634
 
                goto out;
635
 
        }
636
 
 
637
 
        /* Prepare the EEPROM for reading  */
638
 
        status = ixgbe_acquire_eeprom(hw);
639
 
 
640
 
        if (status == 0) {
641
 
                if (ixgbe_ready_eeprom(hw) != 0) {
642
 
                        ixgbe_release_eeprom(hw);
643
 
                        status = IXGBE_ERR_EEPROM;
 
903
 
 
904
        hw->eeprom.ops.init_params(hw);
 
905
 
 
906
        if (offset >= hw->eeprom.word_size) {
 
907
                status = IXGBE_ERR_EEPROM;
 
908
                goto out;
 
909
        }
 
910
 
 
911
        status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
 
912
 
 
913
out:
 
914
        return status;
 
915
}
 
916
 
 
917
/**
 
918
 *  ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD
 
919
 *  @hw: pointer to hardware structure
 
920
 *  @offset: offset of word in the EEPROM to read
 
921
 *  @words: number of word(s)
 
922
 *  @data: 16 bit word(s) from the EEPROM
 
923
 *
 
924
 *  Reads a 16 bit word(s) from the EEPROM using the EERD register.
 
925
 **/
 
926
s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
 
927
                                   u16 words, u16 *data)
 
928
{
 
929
        u32 eerd;
 
930
        s32 status = 0;
 
931
        u32 i;
 
932
 
 
933
        hw->eeprom.ops.init_params(hw);
 
934
 
 
935
        if (words == 0) {
 
936
                status = IXGBE_ERR_INVALID_ARGUMENT;
 
937
                goto out;
 
938
        }
 
939
 
 
940
        if (offset >= hw->eeprom.word_size) {
 
941
                status = IXGBE_ERR_EEPROM;
 
942
                goto out;
 
943
        }
 
944
 
 
945
        for (i = 0; i < words; i++) {
 
946
                eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) +
 
947
                       IXGBE_EEPROM_RW_REG_START;
 
948
 
 
949
                IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
 
950
                status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
 
951
 
 
952
                if (status == 0) {
 
953
                        data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
 
954
                                   IXGBE_EEPROM_RW_REG_DATA);
 
955
                } else {
 
956
                        hw_dbg(hw, "Eeprom read timed out\n");
 
957
                        goto out;
644
958
                }
645
959
        }
646
 
 
647
 
        if (status == 0) {
648
 
                ixgbe_standby_eeprom(hw);
649
 
 
650
 
                /*
651
 
                 * Some SPI eeproms use the 8th address bit embedded in the
652
 
                 * opcode
653
 
                 */
654
 
                if ((hw->eeprom.address_bits == 8) && (offset >= 128))
655
 
                        read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
656
 
 
657
 
                /* Send the READ command (opcode + addr) */
658
 
                ixgbe_shift_out_eeprom_bits(hw, read_opcode,
659
 
                                            IXGBE_EEPROM_OPCODE_BITS);
660
 
                ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
661
 
                                            hw->eeprom.address_bits);
662
 
 
663
 
                /* Read the data. */
664
 
                word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
665
 
                *data = (word_in >> 8) | (word_in << 8);
666
 
 
667
 
                /* End this read operation */
668
 
                ixgbe_release_eeprom(hw);
669
 
        }
670
 
 
 
960
out:
 
961
        return status;
 
962
}
 
963
 
 
964
/**
 
965
 *  ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size
 
966
 *  @hw: pointer to hardware structure
 
967
 *  @offset: offset within the EEPROM to be used as a scratch pad
 
968
 *
 
969
 *  Discover EEPROM page size by writing marching data at given offset.
 
970
 *  This function is called only when we are writing a new large buffer
 
971
 *  at given offset so the data would be overwritten anyway.
 
972
 **/
 
973
static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
 
974
                                                 u16 offset)
 
975
{
 
976
        u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX];
 
977
        s32 status = 0;
 
978
        u16 i;
 
979
 
 
980
        for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++)
 
981
                data[i] = i;
 
982
 
 
983
        hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX;
 
984
        status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset,
 
985
                                             IXGBE_EEPROM_PAGE_SIZE_MAX, data);
 
986
        hw->eeprom.word_page_size = 0;
 
987
        if (status != 0)
 
988
                goto out;
 
989
 
 
990
        status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
 
991
        if (status != 0)
 
992
                goto out;
 
993
 
 
994
        /*
 
995
         * When writing in burst more than the actual page size
 
996
         * EEPROM address wraps around current page.
 
997
         */
 
998
        hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0];
 
999
 
 
1000
        hw_dbg(hw, "Detected EEPROM page size = %d words.",
 
1001
               hw->eeprom.word_page_size);
671
1002
out:
672
1003
        return status;
673
1004
}
682
1013
 **/
683
1014
s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
684
1015
{
685
 
        u32 eerd;
686
 
        s32 status;
 
1016
        return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data);
 
1017
}
 
1018
 
 
1019
/**
 
1020
 *  ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR
 
1021
 *  @hw: pointer to hardware structure
 
1022
 *  @offset: offset of  word in the EEPROM to write
 
1023
 *  @words: number of words
 
1024
 *  @data: word(s) write to the EEPROM
 
1025
 *
 
1026
 *  Write a 16 bit word(s) to the EEPROM using the EEWR register.
 
1027
 **/
 
1028
s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
 
1029
                                    u16 words, u16 *data)
 
1030
{
 
1031
        u32 eewr;
 
1032
        s32 status = 0;
 
1033
        u16 i;
687
1034
 
688
1035
        hw->eeprom.ops.init_params(hw);
689
1036
 
 
1037
        if (words == 0) {
 
1038
                status = IXGBE_ERR_INVALID_ARGUMENT;
 
1039
                goto out;
 
1040
        }
 
1041
 
690
1042
        if (offset >= hw->eeprom.word_size) {
691
1043
                status = IXGBE_ERR_EEPROM;
692
1044
                goto out;
693
1045
        }
694
1046
 
695
 
        eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) +
696
 
               IXGBE_EEPROM_RW_REG_START;
697
 
 
698
 
        IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
699
 
        status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
700
 
 
701
 
        if (status == 0)
702
 
                *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
703
 
                         IXGBE_EEPROM_RW_REG_DATA);
704
 
        else
705
 
                hw_dbg(hw, "Eeprom read timed out\n");
 
1047
        for (i = 0; i < words; i++) {
 
1048
                eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
 
1049
                       (data[i] << IXGBE_EEPROM_RW_REG_DATA) |
 
1050
                       IXGBE_EEPROM_RW_REG_START;
 
1051
 
 
1052
                status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
 
1053
                if (status != 0) {
 
1054
                        hw_dbg(hw, "Eeprom write EEWR timed out\n");
 
1055
                        goto out;
 
1056
                }
 
1057
 
 
1058
                IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
 
1059
 
 
1060
                status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
 
1061
                if (status != 0) {
 
1062
                        hw_dbg(hw, "Eeprom write EEWR timed out\n");
 
1063
                        goto out;
 
1064
                }
 
1065
        }
706
1066
 
707
1067
out:
708
1068
        return status;
709
1069
}
710
1070
 
711
1071
/**
 
1072
 *  ixgbe_write_eewr_generic - Write EEPROM word using EEWR
 
1073
 *  @hw: pointer to hardware structure
 
1074
 *  @offset: offset of  word in the EEPROM to write
 
1075
 *  @data: word write to the EEPROM
 
1076
 *
 
1077
 *  Write a 16 bit word to the EEPROM using the EEWR register.
 
1078
 **/
 
1079
s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
 
1080
{
 
1081
        return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data);
 
1082
}
 
1083
 
 
1084
/**
712
1085
 *  ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
713
1086
 *  @hw: pointer to hardware structure
714
1087
 *  @ee_reg: EEPROM flag for polling
716
1089
 *  Polls the status bit (bit 1) of the EERD or EEWR to determine when the
717
1090
 *  read or write is done respectively.
718
1091
 **/
719
 
s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
 
1092
static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
720
1093
{
721
1094
        u32 i;
722
1095
        u32 reg;
747
1120
static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
748
1121
{
749
1122
        s32 status = 0;
750
 
        u32 eec = 0;
 
1123
        u32 eec;
751
1124
        u32 i;
752
1125
 
753
 
        if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
 
1126
        if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
754
1127
                status = IXGBE_ERR_SWFW_SYNC;
755
1128
 
756
1129
        if (status == 0) {
773
1146
                        IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
774
1147
                        hw_dbg(hw, "Could not acquire EEPROM grant\n");
775
1148
 
776
 
                        ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
 
1149
                        hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
777
1150
                        status = IXGBE_ERR_EEPROM;
778
1151
                }
779
 
        }
780
1152
 
781
 
        /* Setup EEPROM for Read/Write */
782
 
        if (status == 0) {
783
 
                /* Clear CS and SK */
784
 
                eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
785
 
                IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
786
 
                IXGBE_WRITE_FLUSH(hw);
787
 
                udelay(1);
 
1153
                /* Setup EEPROM for Read/Write */
 
1154
                if (status == 0) {
 
1155
                        /* Clear CS and SK */
 
1156
                        eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
 
1157
                        IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
 
1158
                        IXGBE_WRITE_FLUSH(hw);
 
1159
                        udelay(1);
 
1160
                }
788
1161
        }
789
1162
        return status;
790
1163
}
798
1171
static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
799
1172
{
800
1173
        s32 status = IXGBE_ERR_EEPROM;
801
 
        u32 timeout;
 
1174
        u32 timeout = 2000;
802
1175
        u32 i;
803
1176
        u32 swsm;
804
1177
 
805
 
        /* Set timeout value based on size of EEPROM */
806
 
        timeout = hw->eeprom.word_size + 1;
807
 
 
808
1178
        /* Get SMBI software semaphore between device drivers first */
809
1179
        for (i = 0; i < timeout; i++) {
810
1180
                /*
816
1186
                        status = 0;
817
1187
                        break;
818
1188
                }
819
 
                msleep(1);
 
1189
                udelay(50);
 
1190
        }
 
1191
 
 
1192
        if (i == timeout) {
 
1193
                hw_dbg(hw, "Driver can't access the Eeprom - SMBI Semaphore "
 
1194
                       "not granted.\n");
 
1195
                /*
 
1196
                 * this release is particularly important because our attempts
 
1197
                 * above to get the semaphore may have succeeded, and if there
 
1198
                 * was a timeout, we should unconditionally clear the semaphore
 
1199
                 * bits to free the driver to make progress
 
1200
                 */
 
1201
                ixgbe_release_eeprom_semaphore(hw);
 
1202
 
 
1203
                udelay(50);
 
1204
                /*
 
1205
                 * one last try
 
1206
                 * If the SMBI bit is 0 when we read it, then the bit will be
 
1207
                 * set and we have the semaphore
 
1208
                 */
 
1209
                swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
 
1210
                if (!(swsm & IXGBE_SWSM_SMBI))
 
1211
                        status = 0;
820
1212
        }
821
1213
 
822
1214
        /* Now get the semaphore between SW/FW through the SWESMBI bit */
844
1236
                 * was not granted because we don't have access to the EEPROM
845
1237
                 */
846
1238
                if (i >= timeout) {
847
 
                        hw_dbg(hw, "Driver can't access the Eeprom - Semaphore "
 
1239
                        hw_dbg(hw, "SWESMBI Software EEPROM semaphore "
848
1240
                               "not granted.\n");
849
1241
                        ixgbe_release_eeprom_semaphore(hw);
850
1242
                        status = IXGBE_ERR_EEPROM;
851
1243
                }
 
1244
        } else {
 
1245
                hw_dbg(hw, "Software semaphore SMBI between device drivers "
 
1246
                       "not granted.\n");
852
1247
        }
853
1248
 
854
1249
        return status;
1080
1475
        eec &= ~IXGBE_EEC_REQ;
1081
1476
        IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1082
1477
 
1083
 
        ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
 
1478
        hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
 
1479
 
 
1480
        /*
 
1481
         * Delay before attempt to obtain semaphore again to allow FW
 
1482
         * access. semaphore_delay is in ms we need us for usleep_range
 
1483
         */
 
1484
        usleep_range(hw->eeprom.semaphore_delay * 1000,
 
1485
                     hw->eeprom.semaphore_delay * 2000);
1084
1486
}
1085
1487
 
1086
1488
/**
1087
 
 *  ixgbe_calc_eeprom_checksum - Calculates and returns the checksum
 
1489
 *  ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
1088
1490
 *  @hw: pointer to hardware structure
1089
1491
 **/
1090
1492
u16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
1190
1592
        if (status == 0) {
1191
1593
                checksum = hw->eeprom.ops.calc_checksum(hw);
1192
1594
                status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
1193
 
                                            checksum);
 
1595
                                              checksum);
1194
1596
        } else {
1195
1597
                hw_dbg(hw, "EEPROM read failed\n");
1196
1598
        }
1238
1640
        u32 rar_low, rar_high;
1239
1641
        u32 rar_entries = hw->mac.num_rar_entries;
1240
1642
 
 
1643
        /* Make sure we are using a valid rar index range */
 
1644
        if (index >= rar_entries) {
 
1645
                hw_dbg(hw, "RAR index %d is out of range.\n", index);
 
1646
                return IXGBE_ERR_INVALID_ARGUMENT;
 
1647
        }
 
1648
 
1241
1649
        /* setup VMDq pool selection before this RAR gets enabled */
1242
1650
        hw->mac.ops.set_vmdq(hw, index, vmdq);
1243
1651
 
1244
 
        /* Make sure we are using a valid rar index range */
1245
 
        if (index < rar_entries) {
1246
 
                /*
1247
 
                 * HW expects these in little endian so we reverse the byte
1248
 
                 * order from network order (big endian) to little endian
1249
 
                 */
1250
 
                rar_low = ((u32)addr[0] |
1251
 
                           ((u32)addr[1] << 8) |
1252
 
                           ((u32)addr[2] << 16) |
1253
 
                           ((u32)addr[3] << 24));
1254
 
                /*
1255
 
                 * Some parts put the VMDq setting in the extra RAH bits,
1256
 
                 * so save everything except the lower 16 bits that hold part
1257
 
                 * of the address and the address valid bit.
1258
 
                 */
1259
 
                rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1260
 
                rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1261
 
                rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
1262
 
 
1263
 
                if (enable_addr != 0)
1264
 
                        rar_high |= IXGBE_RAH_AV;
1265
 
 
1266
 
                IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1267
 
                IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1268
 
        } else {
1269
 
                hw_dbg(hw, "RAR index %d is out of range.\n", index);
1270
 
                return IXGBE_ERR_RAR_INDEX;
1271
 
        }
 
1652
        /*
 
1653
         * HW expects these in little endian so we reverse the byte
 
1654
         * order from network order (big endian) to little endian
 
1655
         */
 
1656
        rar_low = ((u32)addr[0] |
 
1657
                   ((u32)addr[1] << 8) |
 
1658
                   ((u32)addr[2] << 16) |
 
1659
                   ((u32)addr[3] << 24));
 
1660
        /*
 
1661
         * Some parts put the VMDq setting in the extra RAH bits,
 
1662
         * so save everything except the lower 16 bits that hold part
 
1663
         * of the address and the address valid bit.
 
1664
         */
 
1665
        rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
 
1666
        rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
 
1667
        rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
 
1668
 
 
1669
        if (enable_addr != 0)
 
1670
                rar_high |= IXGBE_RAH_AV;
 
1671
 
 
1672
        IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
 
1673
        IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1272
1674
 
1273
1675
        return 0;
1274
1676
}
1286
1688
        u32 rar_entries = hw->mac.num_rar_entries;
1287
1689
 
1288
1690
        /* Make sure we are using a valid rar index range */
1289
 
        if (index < rar_entries) {
1290
 
                /*
1291
 
                 * Some parts put the VMDq setting in the extra RAH bits,
1292
 
                 * so save everything except the lower 16 bits that hold part
1293
 
                 * of the address and the address valid bit.
1294
 
                 */
1295
 
                rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1296
 
                rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1297
 
 
1298
 
                IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1299
 
                IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1300
 
        } else {
 
1691
        if (index >= rar_entries) {
1301
1692
                hw_dbg(hw, "RAR index %d is out of range.\n", index);
1302
 
                return IXGBE_ERR_RAR_INDEX;
 
1693
                return IXGBE_ERR_INVALID_ARGUMENT;
1303
1694
        }
1304
1695
 
 
1696
        /*
 
1697
         * Some parts put the VMDq setting in the extra RAH bits,
 
1698
         * so save everything except the lower 16 bits that hold part
 
1699
         * of the address and the address valid bit.
 
1700
         */
 
1701
        rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
 
1702
        rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
 
1703
 
 
1704
        IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
 
1705
        IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
 
1706
 
1305
1707
        /* clear VMDq pool/queue selection for this RAR */
1306
1708
        hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1307
1709
 
1309
1711
}
1310
1712
 
1311
1713
/**
1312
 
 *  ixgbe_enable_rar - Enable Rx address register
1313
 
 *  @hw: pointer to hardware structure
1314
 
 *  @index: index into the RAR table
1315
 
 *
1316
 
 *  Enables the select receive address register.
1317
 
 **/
1318
 
static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index)
1319
 
{
1320
 
        u32 rar_high;
1321
 
 
1322
 
        rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1323
 
        rar_high |= IXGBE_RAH_AV;
1324
 
        IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1325
 
}
1326
 
 
1327
 
/**
1328
 
 *  ixgbe_disable_rar - Disable Rx address register
1329
 
 *  @hw: pointer to hardware structure
1330
 
 *  @index: index into the RAR table
1331
 
 *
1332
 
 *  Disables the select receive address register.
1333
 
 **/
1334
 
static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index)
1335
 
{
1336
 
        u32 rar_high;
1337
 
 
1338
 
        rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1339
 
        rar_high &= (~IXGBE_RAH_AV);
1340
 
        IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1341
 
}
1342
 
 
1343
 
/**
1344
1714
 *  ixgbe_init_rx_addrs_generic - Initializes receive address filters.
1345
1715
 *  @hw: pointer to hardware structure
1346
1716
 *
1386
1756
        }
1387
1757
 
1388
1758
        /* Clear the MTA */
1389
 
        hw->addr_ctrl.mc_addr_in_rar_count = 0;
1390
1759
        hw->addr_ctrl.mta_in_use = 0;
1391
1760
        IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1392
1761
 
1401
1770
}
1402
1771
 
1403
1772
/**
1404
 
 *  ixgbe_add_uc_addr - Adds a secondary unicast address.
1405
 
 *  @hw: pointer to hardware structure
1406
 
 *  @addr: new address
1407
 
 *
1408
 
 *  Adds it to unused receive address register or goes into promiscuous mode.
1409
 
 **/
1410
 
static void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
1411
 
{
1412
 
        u32 rar_entries = hw->mac.num_rar_entries;
1413
 
        u32 rar;
1414
 
 
1415
 
        hw_dbg(hw, " UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
1416
 
                  addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
1417
 
 
1418
 
        /*
1419
 
         * Place this address in the RAR if there is room,
1420
 
         * else put the controller into promiscuous mode
1421
 
         */
1422
 
        if (hw->addr_ctrl.rar_used_count < rar_entries) {
1423
 
                rar = hw->addr_ctrl.rar_used_count -
1424
 
                      hw->addr_ctrl.mc_addr_in_rar_count;
1425
 
                hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
1426
 
                hw_dbg(hw, "Added a secondary address to RAR[%d]\n", rar);
1427
 
                hw->addr_ctrl.rar_used_count++;
1428
 
        } else {
1429
 
                hw->addr_ctrl.overflow_promisc++;
1430
 
        }
1431
 
 
1432
 
        hw_dbg(hw, "ixgbe_add_uc_addr Complete\n");
1433
 
}
1434
 
 
1435
 
/**
1436
 
 *  ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
1437
 
 *  @hw: pointer to hardware structure
1438
 
 *  @netdev: pointer to net device structure
1439
 
 *
1440
 
 *  The given list replaces any existing list.  Clears the secondary addrs from
1441
 
 *  receive address registers.  Uses unused receive address registers for the
1442
 
 *  first secondary addresses, and falls back to promiscuous mode as needed.
1443
 
 *
1444
 
 *  Drivers using secondary unicast addresses must set user_set_promisc when
1445
 
 *  manually putting the device into promiscuous mode.
1446
 
 **/
1447
 
s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw,
1448
 
                                      struct net_device *netdev)
1449
 
{
1450
 
        u32 i;
1451
 
        u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
1452
 
        u32 uc_addr_in_use;
1453
 
        u32 fctrl;
1454
 
        struct netdev_hw_addr *ha;
1455
 
 
1456
 
        /*
1457
 
         * Clear accounting of old secondary address list,
1458
 
         * don't count RAR[0]
1459
 
         */
1460
 
        uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
1461
 
        hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
1462
 
        hw->addr_ctrl.overflow_promisc = 0;
1463
 
 
1464
 
        /* Zero out the other receive addresses */
1465
 
        hw_dbg(hw, "Clearing RAR[1-%d]\n", uc_addr_in_use + 1);
1466
 
        for (i = 0; i < uc_addr_in_use; i++) {
1467
 
                IXGBE_WRITE_REG(hw, IXGBE_RAL(1+i), 0);
1468
 
                IXGBE_WRITE_REG(hw, IXGBE_RAH(1+i), 0);
1469
 
        }
1470
 
 
1471
 
        /* Add the new addresses */
1472
 
        netdev_for_each_uc_addr(ha, netdev) {
1473
 
                hw_dbg(hw, " Adding the secondary addresses:\n");
1474
 
                ixgbe_add_uc_addr(hw, ha->addr, 0);
1475
 
        }
1476
 
 
1477
 
        if (hw->addr_ctrl.overflow_promisc) {
1478
 
                /* enable promisc if not already in overflow or set by user */
1479
 
                if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
1480
 
                        hw_dbg(hw, " Entering address overflow promisc mode\n");
1481
 
                        fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1482
 
                        fctrl |= IXGBE_FCTRL_UPE;
1483
 
                        IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
1484
 
                        hw->addr_ctrl.uc_set_promisc = true;
1485
 
                }
1486
 
        } else {
1487
 
                /* only disable if set by overflow, not by user */
1488
 
                if ((old_promisc_setting && hw->addr_ctrl.uc_set_promisc) &&
1489
 
                   !(hw->addr_ctrl.user_set_promisc)) {
1490
 
                        hw_dbg(hw, " Leaving address overflow promisc mode\n");
1491
 
                        fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
1492
 
                        fctrl &= ~IXGBE_FCTRL_UPE;
1493
 
                        IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
1494
 
                        hw->addr_ctrl.uc_set_promisc = false;
1495
 
                }
1496
 
        }
1497
 
 
1498
 
        hw_dbg(hw, "ixgbe_update_uc_addr_list_generic Complete\n");
1499
 
        return 0;
1500
 
}
1501
 
 
1502
 
/**
1503
1773
 *  ixgbe_mta_vector - Determines bit-vector in multicast table to set
1504
1774
 *  @hw: pointer to hardware structure
1505
1775
 *  @mc_addr: the multicast address
1550
1820
        u32 vector;
1551
1821
        u32 vector_bit;
1552
1822
        u32 vector_reg;
1553
 
        u32 mta_reg;
1554
1823
 
1555
1824
        hw->addr_ctrl.mta_in_use++;
1556
1825
 
1568
1837
         */
1569
1838
        vector_reg = (vector >> 5) & 0x7F;
1570
1839
        vector_bit = vector & 0x1F;
1571
 
        mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg));
1572
 
        mta_reg |= (1 << vector_bit);
1573
 
        IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg);
 
1840
        hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
1574
1841
}
1575
1842
 
1576
1843
/**
1596
1863
        hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
1597
1864
        hw->addr_ctrl.mta_in_use = 0;
1598
1865
 
1599
 
        /* Clear the MTA */
 
1866
        /* Clear mta_shadow */
1600
1867
        hw_dbg(hw, " Clearing MTA\n");
1601
 
        for (i = 0; i < hw->mac.mcft_size; i++)
1602
 
                IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
 
1868
        memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
1603
1869
 
1604
 
        /* Add the new addresses */
 
1870
        /* Update mta shadow */
1605
1871
        netdev_for_each_mc_addr(ha, netdev) {
1606
1872
                hw_dbg(hw, " Adding the multicast addresses:\n");
1607
1873
                ixgbe_set_mta(hw, ha->addr);
1608
1874
        }
1609
1875
 
1610
1876
        /* Enable mta */
 
1877
        for (i = 0; i < hw->mac.mcft_size; i++)
 
1878
                IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
 
1879
                                      hw->mac.mta_shadow[i]);
 
1880
 
1611
1881
        if (hw->addr_ctrl.mta_in_use > 0)
1612
1882
                IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
1613
1883
                                IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
1624
1894
 **/
1625
1895
s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
1626
1896
{
1627
 
        u32 i;
1628
 
        u32 rar_entries = hw->mac.num_rar_entries;
1629
1897
        struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
1630
1898
 
1631
 
        if (a->mc_addr_in_rar_count > 0)
1632
 
                for (i = (rar_entries - a->mc_addr_in_rar_count);
1633
 
                     i < rar_entries; i++)
1634
 
                        ixgbe_enable_rar(hw, i);
1635
 
 
1636
1899
        if (a->mta_in_use > 0)
1637
1900
                IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
1638
1901
                                hw->mac.mc_filter_type);
1648
1911
 **/
1649
1912
s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
1650
1913
{
1651
 
        u32 i;
1652
 
        u32 rar_entries = hw->mac.num_rar_entries;
1653
1914
        struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
1654
1915
 
1655
 
        if (a->mc_addr_in_rar_count > 0)
1656
 
                for (i = (rar_entries - a->mc_addr_in_rar_count);
1657
 
                     i < rar_entries; i++)
1658
 
                        ixgbe_disable_rar(hw, i);
1659
 
 
1660
1916
        if (a->mta_in_use > 0)
1661
1917
                IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1662
1918
 
1685
1941
#endif /* CONFIG_DCB */
1686
1942
        /* Negotiate the fc mode to use */
1687
1943
        ret_val = ixgbe_fc_autoneg(hw);
1688
 
        if (ret_val)
 
1944
        if (ret_val == IXGBE_ERR_FLOW_CONTROL)
1689
1945
                goto out;
1690
1946
 
1691
1947
        /* Disable any previous flow control settings */
1703
1959
         * 2: Tx flow control is enabled (we can send pause frames but
1704
1960
         *    we do not support receiving pause frames).
1705
1961
         * 3: Both Rx and Tx flow control (symmetric) are enabled.
 
1962
#ifdef CONFIG_DCB
1706
1963
         * 4: Priority Flow Control is enabled.
 
1964
#endif
1707
1965
         * other: Invalid.
1708
1966
         */
1709
1967
        switch (hw->fc.current_mode) {
1791
2049
 **/
1792
2050
s32 ixgbe_fc_autoneg(struct ixgbe_hw *hw)
1793
2051
{
1794
 
        s32 ret_val = 0;
 
2052
        s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
1795
2053
        ixgbe_link_speed speed;
1796
 
        u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
1797
 
        u32 links2, anlp1_reg, autoc_reg, links;
1798
2054
        bool link_up;
1799
2055
 
 
2056
        if (hw->fc.disable_fc_autoneg)
 
2057
                goto out;
 
2058
 
1800
2059
        /*
1801
2060
         * AN should have completed when the cable was plugged in.
1802
2061
         * Look for reasons to bail out.  Bail out if:
1807
2066
         * So use link_up_wait_to_complete=false.
1808
2067
         */
1809
2068
        hw->mac.ops.check_link(hw, &speed, &link_up, false);
1810
 
 
1811
 
        if (hw->fc.disable_fc_autoneg || (!link_up)) {
 
2069
        if (!link_up) {
 
2070
                ret_val = IXGBE_ERR_FLOW_CONTROL;
 
2071
                goto out;
 
2072
        }
 
2073
 
 
2074
        switch (hw->phy.media_type) {
 
2075
        /* Autoneg flow control on fiber adapters */
 
2076
        case ixgbe_media_type_fiber:
 
2077
                if (speed == IXGBE_LINK_SPEED_1GB_FULL)
 
2078
                        ret_val = ixgbe_fc_autoneg_fiber(hw);
 
2079
                break;
 
2080
 
 
2081
        /* Autoneg flow control on backplane adapters */
 
2082
        case ixgbe_media_type_backplane:
 
2083
                ret_val = ixgbe_fc_autoneg_backplane(hw);
 
2084
                break;
 
2085
 
 
2086
        /* Autoneg flow control on copper adapters */
 
2087
        case ixgbe_media_type_copper:
 
2088
                if (ixgbe_device_supports_autoneg_fc(hw) == 0)
 
2089
                        ret_val = ixgbe_fc_autoneg_copper(hw);
 
2090
                break;
 
2091
 
 
2092
        default:
 
2093
                break;
 
2094
        }
 
2095
 
 
2096
out:
 
2097
        if (ret_val == 0) {
 
2098
                hw->fc.fc_was_autonegged = true;
 
2099
        } else {
1812
2100
                hw->fc.fc_was_autonegged = false;
1813
2101
                hw->fc.current_mode = hw->fc.requested_mode;
 
2102
        }
 
2103
        return ret_val;
 
2104
}
 
2105
 
 
2106
/**
 
2107
 *  ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
 
2108
 *  @hw: pointer to hardware structure
 
2109
 *
 
2110
 *  Enable flow control according on 1 gig fiber.
 
2111
 **/
 
2112
static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
 
2113
{
 
2114
        u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
 
2115
        s32 ret_val;
 
2116
 
 
2117
        /*
 
2118
         * On multispeed fiber at 1g, bail out if
 
2119
         * - link is up but AN did not complete, or if
 
2120
         * - link is up and AN completed but timed out
 
2121
         */
 
2122
 
 
2123
        linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
 
2124
        if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
 
2125
            ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
 
2126
                ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
1814
2127
                goto out;
1815
2128
        }
1816
2129
 
 
2130
        pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
 
2131
        pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
 
2132
 
 
2133
        ret_val =  ixgbe_negotiate_fc(hw, pcs_anadv_reg,
 
2134
                               pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
 
2135
                               IXGBE_PCS1GANA_ASM_PAUSE,
 
2136
                               IXGBE_PCS1GANA_SYM_PAUSE,
 
2137
                               IXGBE_PCS1GANA_ASM_PAUSE);
 
2138
 
 
2139
out:
 
2140
        return ret_val;
 
2141
}
 
2142
 
 
2143
/**
 
2144
 *  ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
 
2145
 *  @hw: pointer to hardware structure
 
2146
 *
 
2147
 *  Enable flow control according to IEEE clause 37.
 
2148
 **/
 
2149
static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
 
2150
{
 
2151
        u32 links2, anlp1_reg, autoc_reg, links;
 
2152
        s32 ret_val;
 
2153
 
1817
2154
        /*
1818
2155
         * On backplane, bail out if
1819
2156
         * - backplane autoneg was not completed, or if
1820
2157
         * - we are 82599 and link partner is not AN enabled
1821
2158
         */
1822
 
        if (hw->phy.media_type == ixgbe_media_type_backplane) {
1823
 
                links = IXGBE_READ_REG(hw, IXGBE_LINKS);
1824
 
                if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
1825
 
                        hw->fc.fc_was_autonegged = false;
1826
 
                        hw->fc.current_mode = hw->fc.requested_mode;
1827
 
                        goto out;
1828
 
                }
1829
 
 
1830
 
                if (hw->mac.type == ixgbe_mac_82599EB) {
1831
 
                        links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
1832
 
                        if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
1833
 
                                hw->fc.fc_was_autonegged = false;
1834
 
                                hw->fc.current_mode = hw->fc.requested_mode;
1835
 
                                goto out;
1836
 
                        }
1837
 
                }
1838
 
        }
1839
 
 
1840
 
        /*
1841
 
         * On multispeed fiber at 1g, bail out if
1842
 
         * - link is up but AN did not complete, or if
1843
 
         * - link is up and AN completed but timed out
1844
 
         */
1845
 
        if (hw->phy.multispeed_fiber && (speed == IXGBE_LINK_SPEED_1GB_FULL)) {
1846
 
                linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
1847
 
                if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
1848
 
                    ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
1849
 
                        hw->fc.fc_was_autonegged = false;
1850
 
                        hw->fc.current_mode = hw->fc.requested_mode;
1851
 
                        goto out;
1852
 
                }
1853
 
        }
1854
 
 
1855
 
        /*
1856
 
         * Bail out on
1857
 
         * - copper or CX4 adapters
1858
 
         * - fiber adapters running at 10gig
1859
 
         */
1860
 
        if ((hw->phy.media_type == ixgbe_media_type_copper) ||
1861
 
             (hw->phy.media_type == ixgbe_media_type_cx4) ||
1862
 
             ((hw->phy.media_type == ixgbe_media_type_fiber) &&
1863
 
             (speed == IXGBE_LINK_SPEED_10GB_FULL))) {
 
2159
        links = IXGBE_READ_REG(hw, IXGBE_LINKS);
 
2160
        if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
1864
2161
                hw->fc.fc_was_autonegged = false;
1865
2162
                hw->fc.current_mode = hw->fc.requested_mode;
 
2163
                ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
1866
2164
                goto out;
1867
2165
        }
1868
2166
 
 
2167
        if (hw->mac.type == ixgbe_mac_82599EB) {
 
2168
                links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
 
2169
                if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
 
2170
                        hw->fc.fc_was_autonegged = false;
 
2171
                        hw->fc.current_mode = hw->fc.requested_mode;
 
2172
                        ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
 
2173
                        goto out;
 
2174
                }
 
2175
        }
1869
2176
        /*
1870
 
         * Read the AN advertisement and LP ability registers and resolve
 
2177
         * Read the 10g AN autoc and LP ability registers and resolve
1871
2178
         * local flow control settings accordingly
1872
2179
         */
1873
 
        if ((speed == IXGBE_LINK_SPEED_1GB_FULL) &&
1874
 
            (hw->phy.media_type != ixgbe_media_type_backplane)) {
1875
 
                pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
1876
 
                pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
1877
 
                if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1878
 
                    (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE)) {
1879
 
                        /*
1880
 
                         * Now we need to check if the user selected Rx ONLY
1881
 
                         * of pause frames.  In this case, we had to advertise
1882
 
                         * FULL flow control because we could not advertise RX
1883
 
                         * ONLY. Hence, we must now check to see if we need to
1884
 
                         * turn OFF the TRANSMISSION of PAUSE frames.
1885
 
                         */
1886
 
                        if (hw->fc.requested_mode == ixgbe_fc_full) {
1887
 
                                hw->fc.current_mode = ixgbe_fc_full;
1888
 
                                hw_dbg(hw, "Flow Control = FULL.\n");
1889
 
                        } else {
1890
 
                                hw->fc.current_mode = ixgbe_fc_rx_pause;
1891
 
                                hw_dbg(hw, "Flow Control=RX PAUSE only\n");
1892
 
                        }
1893
 
                } else if (!(pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1894
 
                           (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1895
 
                           (pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1896
 
                           (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
1897
 
                        hw->fc.current_mode = ixgbe_fc_tx_pause;
1898
 
                        hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1899
 
                } else if ((pcs_anadv_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1900
 
                           (pcs_anadv_reg & IXGBE_PCS1GANA_ASM_PAUSE) &&
1901
 
                           !(pcs_lpab_reg & IXGBE_PCS1GANA_SYM_PAUSE) &&
1902
 
                           (pcs_lpab_reg & IXGBE_PCS1GANA_ASM_PAUSE)) {
1903
 
                        hw->fc.current_mode = ixgbe_fc_rx_pause;
1904
 
                        hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
1905
 
                } else {
1906
 
                        hw->fc.current_mode = ixgbe_fc_none;
1907
 
                        hw_dbg(hw, "Flow Control = NONE.\n");
1908
 
                }
1909
 
        }
1910
 
 
1911
 
        if (hw->phy.media_type == ixgbe_media_type_backplane) {
 
2180
        autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
 
2181
        anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
 
2182
 
 
2183
        ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
 
2184
                anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
 
2185
                IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
 
2186
 
 
2187
out:
 
2188
        return ret_val;
 
2189
}
 
2190
 
 
2191
/**
 
2192
 *  ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
 
2193
 *  @hw: pointer to hardware structure
 
2194
 *
 
2195
 *  Enable flow control according to IEEE clause 37.
 
2196
 **/
 
2197
static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
 
2198
{
 
2199
        u16 technology_ability_reg = 0;
 
2200
        u16 lp_technology_ability_reg = 0;
 
2201
 
 
2202
        hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
 
2203
                             MDIO_MMD_AN,
 
2204
                             &technology_ability_reg);
 
2205
        hw->phy.ops.read_reg(hw, MDIO_AN_LPA,
 
2206
                             MDIO_MMD_AN,
 
2207
                             &lp_technology_ability_reg);
 
2208
 
 
2209
        return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
 
2210
                                  (u32)lp_technology_ability_reg,
 
2211
                                  IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
 
2212
                                  IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
 
2213
}
 
2214
 
 
2215
/**
 
2216
 *  ixgbe_negotiate_fc - Negotiate flow control
 
2217
 *  @hw: pointer to hardware structure
 
2218
 *  @adv_reg: flow control advertised settings
 
2219
 *  @lp_reg: link partner's flow control settings
 
2220
 *  @adv_sym: symmetric pause bit in advertisement
 
2221
 *  @adv_asm: asymmetric pause bit in advertisement
 
2222
 *  @lp_sym: symmetric pause bit in link partner advertisement
 
2223
 *  @lp_asm: asymmetric pause bit in link partner advertisement
 
2224
 *
 
2225
 *  Find the intersection between advertised settings and link partner's
 
2226
 *  advertised settings
 
2227
 **/
 
2228
static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
 
2229
                              u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
 
2230
{
 
2231
        if ((!(adv_reg)) ||  (!(lp_reg)))
 
2232
                return IXGBE_ERR_FC_NOT_NEGOTIATED;
 
2233
 
 
2234
        if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
1912
2235
                /*
1913
 
                 * Read the 10g AN autoc and LP ability registers and resolve
1914
 
                 * local flow control settings accordingly
 
2236
                 * Now we need to check if the user selected Rx ONLY
 
2237
                 * of pause frames.  In this case, we had to advertise
 
2238
                 * FULL flow control because we could not advertise RX
 
2239
                 * ONLY. Hence, we must now check to see if we need to
 
2240
                 * turn OFF the TRANSMISSION of PAUSE frames.
1915
2241
                 */
1916
 
                autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1917
 
                anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
1918
 
 
1919
 
                if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1920
 
                    (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE)) {
1921
 
                        /*
1922
 
                         * Now we need to check if the user selected Rx ONLY
1923
 
                         * of pause frames.  In this case, we had to advertise
1924
 
                         * FULL flow control because we could not advertise RX
1925
 
                         * ONLY. Hence, we must now check to see if we need to
1926
 
                         * turn OFF the TRANSMISSION of PAUSE frames.
1927
 
                         */
1928
 
                        if (hw->fc.requested_mode == ixgbe_fc_full) {
1929
 
                                hw->fc.current_mode = ixgbe_fc_full;
1930
 
                                hw_dbg(hw, "Flow Control = FULL.\n");
1931
 
                        } else {
1932
 
                                hw->fc.current_mode = ixgbe_fc_rx_pause;
1933
 
                                hw_dbg(hw, "Flow Control=RX PAUSE only\n");
1934
 
                        }
1935
 
                } else if (!(autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1936
 
                           (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
1937
 
                           (anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
1938
 
                           (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
1939
 
                        hw->fc.current_mode = ixgbe_fc_tx_pause;
1940
 
                        hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
1941
 
                } else if ((autoc_reg & IXGBE_AUTOC_SYM_PAUSE) &&
1942
 
                           (autoc_reg & IXGBE_AUTOC_ASM_PAUSE) &&
1943
 
                           !(anlp1_reg & IXGBE_ANLP1_SYM_PAUSE) &&
1944
 
                           (anlp1_reg & IXGBE_ANLP1_ASM_PAUSE)) {
 
2242
                if (hw->fc.requested_mode == ixgbe_fc_full) {
 
2243
                        hw->fc.current_mode = ixgbe_fc_full;
 
2244
                        hw_dbg(hw, "Flow Control = FULL.\n");
 
2245
                } else {
1945
2246
                        hw->fc.current_mode = ixgbe_fc_rx_pause;
1946
 
                        hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
1947
 
                } else {
1948
 
                        hw->fc.current_mode = ixgbe_fc_none;
1949
 
                        hw_dbg(hw, "Flow Control = NONE.\n");
 
2247
                        hw_dbg(hw, "Flow Control=RX PAUSE frames only\n");
1950
2248
                }
 
2249
        } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
 
2250
                   (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
 
2251
                hw->fc.current_mode = ixgbe_fc_tx_pause;
 
2252
                hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
 
2253
        } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
 
2254
                   !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
 
2255
                hw->fc.current_mode = ixgbe_fc_rx_pause;
 
2256
                hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
 
2257
        } else {
 
2258
                hw->fc.current_mode = ixgbe_fc_none;
 
2259
                hw_dbg(hw, "Flow Control = NONE.\n");
1951
2260
        }
1952
 
        /* Record that current_mode is the result of a successful autoneg */
1953
 
        hw->fc.fc_was_autonegged = true;
1954
 
 
1955
 
out:
1956
 
        return ret_val;
 
2261
        return 0;
1957
2262
}
1958
2263
 
1959
2264
/**
1965
2270
static s32 ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
1966
2271
{
1967
2272
        s32 ret_val = 0;
1968
 
        u32 reg;
 
2273
        u32 reg = 0, reg_bp = 0;
 
2274
        u16 reg_cu = 0;
1969
2275
 
1970
2276
#ifdef CONFIG_DCB
1971
2277
        if (hw->fc.requested_mode == ixgbe_fc_pfc) {
1973
2279
                goto out;
1974
2280
        }
1975
2281
 
1976
 
#endif
 
2282
#endif /* CONFIG_DCB */
1977
2283
        /* Validate the packetbuf configuration */
1978
2284
        if (packetbuf_num < 0 || packetbuf_num > 7) {
1979
2285
                hw_dbg(hw, "Invalid packet buffer number [%d], expected range "
2011
2317
                hw->fc.requested_mode = ixgbe_fc_full;
2012
2318
 
2013
2319
        /*
2014
 
         * Set up the 1G flow control advertisement registers so the HW will be
2015
 
         * able to do fc autoneg once the cable is plugged in.  If we end up
2016
 
         * using 10g instead, this is harmless.
 
2320
         * Set up the 1G and 10G flow control advertisement registers so the
 
2321
         * HW will be able to do fc autoneg once the cable is plugged in.  If
 
2322
         * we link at 10G, the 1G advertisement is harmless and vice versa.
2017
2323
         */
2018
 
        reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
 
2324
 
 
2325
        switch (hw->phy.media_type) {
 
2326
        case ixgbe_media_type_fiber:
 
2327
        case ixgbe_media_type_backplane:
 
2328
                reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
 
2329
                reg_bp = IXGBE_READ_REG(hw, IXGBE_AUTOC);
 
2330
                break;
 
2331
 
 
2332
        case ixgbe_media_type_copper:
 
2333
                hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
 
2334
                                        MDIO_MMD_AN, &reg_cu);
 
2335
                break;
 
2336
 
 
2337
        default:
 
2338
                ;
 
2339
        }
2019
2340
 
2020
2341
        /*
2021
2342
         * The possible values of fc.requested_mode are:
2034
2355
        case ixgbe_fc_none:
2035
2356
                /* Flow control completely disabled by software override. */
2036
2357
                reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
 
2358
                if (hw->phy.media_type == ixgbe_media_type_backplane)
 
2359
                        reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
 
2360
                                    IXGBE_AUTOC_ASM_PAUSE);
 
2361
                else if (hw->phy.media_type == ixgbe_media_type_copper)
 
2362
                        reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
2037
2363
                break;
2038
2364
        case ixgbe_fc_rx_pause:
2039
2365
                /*
2045
2371
                 * disable the adapter's ability to send PAUSE frames.
2046
2372
                 */
2047
2373
                reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
 
2374
                if (hw->phy.media_type == ixgbe_media_type_backplane)
 
2375
                        reg_bp |= (IXGBE_AUTOC_SYM_PAUSE |
 
2376
                                   IXGBE_AUTOC_ASM_PAUSE);
 
2377
                else if (hw->phy.media_type == ixgbe_media_type_copper)
 
2378
                        reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
2048
2379
                break;
2049
2380
        case ixgbe_fc_tx_pause:
2050
2381
                /*
2053
2384
                 */
2054
2385
                reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
2055
2386
                reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
 
2387
                if (hw->phy.media_type == ixgbe_media_type_backplane) {
 
2388
                        reg_bp |= (IXGBE_AUTOC_ASM_PAUSE);
 
2389
                        reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE);
 
2390
                } else if (hw->phy.media_type == ixgbe_media_type_copper) {
 
2391
                        reg_cu |= (IXGBE_TAF_ASM_PAUSE);
 
2392
                        reg_cu &= ~(IXGBE_TAF_SYM_PAUSE);
 
2393
                }
2056
2394
                break;
2057
2395
        case ixgbe_fc_full:
2058
2396
                /* Flow control (both Rx and Tx) is enabled by SW override. */
2059
2397
                reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2060
 
                break;
2061
 
#ifdef CONFIG_DCB
2062
 
        case ixgbe_fc_pfc:
2063
 
                goto out;
2064
 
                break;
2065
 
#endif /* CONFIG_DCB */
2066
 
        default:
2067
 
                hw_dbg(hw, "Flow control param set incorrectly\n");
2068
 
                ret_val = IXGBE_ERR_CONFIG;
2069
 
                goto out;
2070
 
                break;
2071
 
        }
2072
 
 
2073
 
        IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
2074
 
        reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
2075
 
 
2076
 
        /* Disable AN timeout */
2077
 
        if (hw->fc.strict_ieee)
2078
 
                reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
2079
 
 
2080
 
        IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
2081
 
        hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
2082
 
 
2083
 
        /*
2084
 
         * Set up the 10G flow control advertisement registers so the HW
2085
 
         * can do fc autoneg once the cable is plugged in.  If we end up
2086
 
         * using 1g instead, this is harmless.
2087
 
         */
2088
 
        reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2089
 
 
2090
 
        /*
2091
 
         * The possible values of fc.requested_mode are:
2092
 
         * 0: Flow control is completely disabled
2093
 
         * 1: Rx flow control is enabled (we can receive pause frames,
2094
 
         *    but not send pause frames).
2095
 
         * 2: Tx flow control is enabled (we can send pause frames but
2096
 
         *    we do not support receiving pause frames).
2097
 
         * 3: Both Rx and Tx flow control (symmetric) are enabled.
2098
 
         * other: Invalid.
2099
 
         */
2100
 
        switch (hw->fc.requested_mode) {
2101
 
        case ixgbe_fc_none:
2102
 
                /* Flow control completely disabled by software override. */
2103
 
                reg &= ~(IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
2104
 
                break;
2105
 
        case ixgbe_fc_rx_pause:
2106
 
                /*
2107
 
                 * Rx Flow control is enabled and Tx Flow control is
2108
 
                 * disabled by software override. Since there really
2109
 
                 * isn't a way to advertise that we are capable of RX
2110
 
                 * Pause ONLY, we will advertise that we support both
2111
 
                 * symmetric and asymmetric Rx PAUSE.  Later, we will
2112
 
                 * disable the adapter's ability to send PAUSE frames.
2113
 
                 */
2114
 
                reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
2115
 
                break;
2116
 
        case ixgbe_fc_tx_pause:
2117
 
                /*
2118
 
                 * Tx Flow control is enabled, and Rx Flow control is
2119
 
                 * disabled by software override.
2120
 
                 */
2121
 
                reg |= (IXGBE_AUTOC_ASM_PAUSE);
2122
 
                reg &= ~(IXGBE_AUTOC_SYM_PAUSE);
2123
 
                break;
2124
 
        case ixgbe_fc_full:
2125
 
                /* Flow control (both Rx and Tx) is enabled by SW override. */
2126
 
                reg |= (IXGBE_AUTOC_SYM_PAUSE | IXGBE_AUTOC_ASM_PAUSE);
2127
 
                break;
2128
 
#ifdef CONFIG_DCB
2129
 
        case ixgbe_fc_pfc:
2130
 
                goto out;
2131
 
                break;
2132
 
#endif /* CONFIG_DCB */
2133
 
        default:
2134
 
                hw_dbg(hw, "Flow control param set incorrectly\n");
2135
 
                ret_val = IXGBE_ERR_CONFIG;
2136
 
                goto out;
2137
 
                break;
2138
 
        }
2139
 
        /*
2140
 
         * AUTOC restart handles negotiation of 1G and 10G. There is
2141
 
         * no need to set the PCS1GCTL register.
2142
 
         */
2143
 
        reg |= IXGBE_AUTOC_AN_RESTART;
2144
 
        IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg);
 
2398
                if (hw->phy.media_type == ixgbe_media_type_backplane)
 
2399
                        reg_bp |= (IXGBE_AUTOC_SYM_PAUSE |
 
2400
                                   IXGBE_AUTOC_ASM_PAUSE);
 
2401
                else if (hw->phy.media_type == ixgbe_media_type_copper)
 
2402
                        reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
 
2403
                break;
 
2404
#ifdef CONFIG_DCB
 
2405
        case ixgbe_fc_pfc:
 
2406
                goto out;
 
2407
                break;
 
2408
#endif /* CONFIG_DCB */
 
2409
        default:
 
2410
                hw_dbg(hw, "Flow control param set incorrectly\n");
 
2411
                ret_val = IXGBE_ERR_CONFIG;
 
2412
                goto out;
 
2413
                break;
 
2414
        }
 
2415
 
 
2416
        if (hw->mac.type != ixgbe_mac_X540) {
 
2417
                /*
 
2418
                 * Enable auto-negotiation between the MAC & PHY;
 
2419
                 * the MAC will advertise clause 37 flow control.
 
2420
                 */
 
2421
                IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
 
2422
                reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
 
2423
 
 
2424
                /* Disable AN timeout */
 
2425
                if (hw->fc.strict_ieee)
 
2426
                        reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
 
2427
 
 
2428
                IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
 
2429
                hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
 
2430
        }
 
2431
 
 
2432
        /*
 
2433
         * AUTOC restart handles negotiation of 1G and 10G on backplane
 
2434
         * and copper. There is no need to set the PCS1GCTL register.
 
2435
         *
 
2436
         */
 
2437
        if (hw->phy.media_type == ixgbe_media_type_backplane) {
 
2438
                reg_bp |= IXGBE_AUTOC_AN_RESTART;
 
2439
                IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_bp);
 
2440
        } else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
 
2441
                    (ixgbe_device_supports_autoneg_fc(hw) == 0)) {
 
2442
                hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
 
2443
                                      MDIO_MMD_AN, reg_cu);
 
2444
        }
 
2445
 
2145
2446
        hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
2146
 
 
2147
2447
out:
2148
2448
        return ret_val;
2149
2449
}
2159
2459
 **/
2160
2460
s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
2161
2461
{
 
2462
        struct ixgbe_adapter *adapter = hw->back;
2162
2463
        u32 i;
2163
2464
        u32 reg_val;
2164
2465
        u32 number_of_queues;
2165
 
        s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
 
2466
        s32 status = 0;
 
2467
        u16 dev_status = 0;
 
2468
 
 
2469
        /* Just jump out if bus mastering is already disabled */
 
2470
        if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
 
2471
                goto out;
2166
2472
 
2167
2473
        /* Disable the receive unit by stopping each queue */
2168
2474
        number_of_queues = hw->mac.max_rx_queues;
2179
2485
        IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
2180
2486
 
2181
2487
        for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2182
 
                if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) {
2183
 
                        status = 0;
 
2488
                if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
 
2489
                        goto check_device_status;
 
2490
                udelay(100);
 
2491
        }
 
2492
 
 
2493
        hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n");
 
2494
        status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
 
2495
 
 
2496
        /*
 
2497
         * Before proceeding, make sure that the PCIe block does not have
 
2498
         * transactions pending.
 
2499
         */
 
2500
check_device_status:
 
2501
        for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
 
2502
                pci_read_config_word(adapter->pdev, IXGBE_PCI_DEVICE_STATUS,
 
2503
                                                         &dev_status);
 
2504
                if (!(dev_status & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
2184
2505
                        break;
2185
 
                }
2186
2506
                udelay(100);
2187
2507
        }
2188
2508
 
 
2509
        if (i == IXGBE_PCI_MASTER_DISABLE_TIMEOUT)
 
2510
                hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n");
 
2511
        else
 
2512
                goto out;
 
2513
 
 
2514
        /*
 
2515
         * Two consecutive resets are required via CTRL.RST per datasheet
 
2516
         * 5.2.5.3.2 Master Disable.  We set a flag to inform the reset routine
 
2517
         * of this need.  The first reset prevents new master requests from
 
2518
         * being issued by our device.  We then must wait 1usec for any
 
2519
         * remaining completions from the PCIe bus to trickle in, and then reset
 
2520
         * again to clear out any effects they may have had on our device.
 
2521
         */
 
2522
         hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
 
2523
 
 
2524
out:
2189
2525
        return status;
2190
2526
}
2191
2527
 
2195
2531
 *  @hw: pointer to hardware structure
2196
2532
 *  @mask: Mask to specify which semaphore to acquire
2197
2533
 *
2198
 
 *  Acquires the SWFW semaphore thought the GSSR register for the specified
 
2534
 *  Acquires the SWFW semaphore through the GSSR register for the specified
2199
2535
 *  function (CSR, PHY0, PHY1, EEPROM, Flash)
2200
2536
 **/
2201
2537
s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2206
2542
        s32 timeout = 200;
2207
2543
 
2208
2544
        while (timeout) {
 
2545
                /*
 
2546
                 * SW EEPROM semaphore bit is used for access to all
 
2547
                 * SW_FW_SYNC/GSSR bits (not just EEPROM)
 
2548
                 */
2209
2549
                if (ixgbe_get_eeprom_semaphore(hw))
2210
2550
                        return IXGBE_ERR_SWFW_SYNC;
2211
2551
 
2218
2558
                 * thread currently using resource (swmask)
2219
2559
                 */
2220
2560
                ixgbe_release_eeprom_semaphore(hw);
2221
 
                msleep(5);
 
2561
                usleep_range(5000, 10000);
2222
2562
                timeout--;
2223
2563
        }
2224
2564
 
2225
2565
        if (!timeout) {
2226
 
                hw_dbg(hw, "Driver can't access resource, GSSR timeout.\n");
 
2566
                hw_dbg(hw, "Driver can't access resource, SW_FW_SYNC timeout.\n");
2227
2567
                return IXGBE_ERR_SWFW_SYNC;
2228
2568
        }
2229
2569
 
2239
2579
 *  @hw: pointer to hardware structure
2240
2580
 *  @mask: Mask to specify which semaphore to release
2241
2581
 *
2242
 
 *  Releases the SWFW semaphore thought the GSSR register for the specified
 
2582
 *  Releases the SWFW semaphore through the GSSR register for the specified
2243
2583
 *  function (CSR, PHY0, PHY1, EEPROM, Flash)
2244
2584
 **/
2245
2585
void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
2292
2632
                autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2293
2633
                autoc_reg |= IXGBE_AUTOC_FLU;
2294
2634
                IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
2295
 
                msleep(10);
 
2635
                usleep_range(10000, 20000);
2296
2636
        }
2297
2637
 
2298
2638
        led_reg &= ~IXGBE_LED_MODE_MASK(index);
2427
2767
        u32 mpsar_lo, mpsar_hi;
2428
2768
        u32 rar_entries = hw->mac.num_rar_entries;
2429
2769
 
2430
 
        if (rar < rar_entries) {
2431
 
                mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2432
 
                mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2433
 
 
2434
 
                if (!mpsar_lo && !mpsar_hi)
2435
 
                        goto done;
2436
 
 
2437
 
                if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
2438
 
                        if (mpsar_lo) {
2439
 
                                IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
2440
 
                                mpsar_lo = 0;
2441
 
                        }
2442
 
                        if (mpsar_hi) {
2443
 
                                IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
2444
 
                                mpsar_hi = 0;
2445
 
                        }
2446
 
                } else if (vmdq < 32) {
2447
 
                        mpsar_lo &= ~(1 << vmdq);
2448
 
                        IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
2449
 
                } else {
2450
 
                        mpsar_hi &= ~(1 << (vmdq - 32));
2451
 
                        IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
2452
 
                }
2453
 
 
2454
 
                /* was that the last pool using this rar? */
2455
 
                if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
2456
 
                        hw->mac.ops.clear_rar(hw, rar);
 
2770
        /* Make sure we are using a valid rar index range */
 
2771
        if (rar >= rar_entries) {
 
2772
                hw_dbg(hw, "RAR index %d is out of range.\n", rar);
 
2773
                return IXGBE_ERR_INVALID_ARGUMENT;
 
2774
        }
 
2775
 
 
2776
        mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
 
2777
        mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
 
2778
 
 
2779
        if (!mpsar_lo && !mpsar_hi)
 
2780
                goto done;
 
2781
 
 
2782
        if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
 
2783
                if (mpsar_lo) {
 
2784
                        IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
 
2785
                        mpsar_lo = 0;
 
2786
                }
 
2787
                if (mpsar_hi) {
 
2788
                        IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
 
2789
                        mpsar_hi = 0;
 
2790
                }
 
2791
        } else if (vmdq < 32) {
 
2792
                mpsar_lo &= ~(1 << vmdq);
 
2793
                IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
2457
2794
        } else {
2458
 
                hw_dbg(hw, "RAR index %d is out of range.\n", rar);
 
2795
                mpsar_hi &= ~(1 << (vmdq - 32));
 
2796
                IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
2459
2797
        }
2460
2798
 
 
2799
        /* was that the last pool using this rar? */
 
2800
        if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
 
2801
                hw->mac.ops.clear_rar(hw, rar);
2461
2802
done:
2462
2803
        return 0;
2463
2804
}
2473
2814
        u32 mpsar;
2474
2815
        u32 rar_entries = hw->mac.num_rar_entries;
2475
2816
 
2476
 
        if (rar < rar_entries) {
2477
 
                if (vmdq < 32) {
2478
 
                        mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2479
 
                        mpsar |= 1 << vmdq;
2480
 
                        IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
2481
 
                } else {
2482
 
                        mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2483
 
                        mpsar |= 1 << (vmdq - 32);
2484
 
                        IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
2485
 
                }
 
2817
        /* Make sure we are using a valid rar index range */
 
2818
        if (rar >= rar_entries) {
 
2819
                hw_dbg(hw, "RAR index %d is out of range.\n", rar);
 
2820
                return IXGBE_ERR_INVALID_ARGUMENT;
 
2821
        }
 
2822
 
 
2823
        if (vmdq < 32) {
 
2824
                mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
 
2825
                mpsar |= 1 << vmdq;
 
2826
                IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
2486
2827
        } else {
2487
 
                hw_dbg(hw, "RAR index %d is out of range.\n", rar);
 
2828
                mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
 
2829
                mpsar |= 1 << (vmdq - 32);
 
2830
                IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
2488
2831
        }
2489
2832
        return 0;
2490
2833
}
2497
2840
{
2498
2841
        int i;
2499
2842
 
2500
 
 
2501
2843
        for (i = 0; i < 128; i++)
2502
2844
                IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
2503
2845
 
2726
3068
 *  Reads the links register to determine if link is up and the current speed
2727
3069
 **/
2728
3070
s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
2729
 
                               bool *link_up, bool link_up_wait_to_complete)
 
3071
                                 bool *link_up, bool link_up_wait_to_complete)
2730
3072
{
2731
 
        u32 links_reg;
 
3073
        u32 links_reg, links_orig;
2732
3074
        u32 i;
2733
3075
 
 
3076
        /* clear the old state */
 
3077
        links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
 
3078
 
2734
3079
        links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
 
3080
 
 
3081
        if (links_orig != links_reg) {
 
3082
                hw_dbg(hw, "LINKS changed from %08X to %08X\n",
 
3083
                       links_orig, links_reg);
 
3084
        }
 
3085
 
2735
3086
        if (link_up_wait_to_complete) {
2736
3087
                for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
2737
3088
                        if (links_reg & IXGBE_LINKS_UP) {
2754
3105
            IXGBE_LINKS_SPEED_10G_82599)
2755
3106
                *speed = IXGBE_LINK_SPEED_10GB_FULL;
2756
3107
        else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
2757
 
                 IXGBE_LINKS_SPEED_1G_82599)
 
3108
                 IXGBE_LINKS_SPEED_1G_82599)
2758
3109
                *speed = IXGBE_LINK_SPEED_1GB_FULL;
2759
 
        else
 
3110
        else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
 
3111
                 IXGBE_LINKS_SPEED_100_82599)
2760
3112
                *speed = IXGBE_LINK_SPEED_100_FULL;
 
3113
        else
 
3114
                *speed = IXGBE_LINK_SPEED_UNKNOWN;
2761
3115
 
2762
3116
        /* if link is down, zero out the current_mode */
2763
3117
        if (*link_up == false) {
2814
3168
}
2815
3169
 
2816
3170
/**
 
3171
 *  ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow
 
3172
 *  control
 
3173
 *  @hw: pointer to hardware structure
 
3174
 *
 
3175
 *  There are several phys that do not support autoneg flow control. This
 
3176
 *  function check the device id to see if the associated phy supports
 
3177
 *  autoneg flow control.
 
3178
 **/
 
3179
static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
 
3180
{
 
3181
 
 
3182
        switch (hw->device_id) {
 
3183
        case IXGBE_DEV_ID_X540T:
 
3184
                return 0;
 
3185
        case IXGBE_DEV_ID_82599_T3_LOM:
 
3186
                return 0;
 
3187
        default:
 
3188
                return IXGBE_ERR_FC_NOT_SUPPORTED;
 
3189
        }
 
3190
}
 
3191
 
 
3192
/**
2817
3193
 *  ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
2818
3194
 *  @hw: pointer to hardware structure
2819
3195
 *  @enable: enable or disable switch for anti-spoofing
2876
3252
                pfvfspoof &= ~(1 << vf_target_shift);
2877
3253
        IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
2878
3254
}
 
3255
 
 
3256
/**
 
3257
 *  ixgbe_get_device_caps_generic - Get additional device capabilities
 
3258
 *  @hw: pointer to hardware structure
 
3259
 *  @device_caps: the EEPROM word with the extra device capabilities
 
3260
 *
 
3261
 *  This function will read the EEPROM location for the device capabilities,
 
3262
 *  and return the word through device_caps.
 
3263
 **/
 
3264
s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps)
 
3265
{
 
3266
        hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
 
3267
 
 
3268
        return 0;
 
3269
}