blob: 97f6fae48d1d71f60241d0a30b895de80127ca00 [file] [log] [blame]
Carolyn Wybornye52c0f92014-04-11 01:46:06 +00001/* Intel(R) Gigabit Ethernet Linux driver
2 * Copyright(c) 2007-2014 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, see <http://www.gnu.org/licenses/>.
15 *
16 * The full GNU General Public License is included in this distribution in
17 * the file called "COPYING".
18 *
19 * Contact Information:
20 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
21 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
22 */
Auke Kok9d5c8242008-01-24 02:22:38 -080023
24#include <linux/if_ether.h>
25#include <linux/delay.h>
26#include <linux/pci.h>
27#include <linux/netdevice.h>
Tobias Klauser58d14d42011-07-03 23:50:15 +000028#include <linux/etherdevice.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080029
30#include "e1000_mac.h"
31
32#include "igb.h"
33
34static s32 igb_set_default_fc(struct e1000_hw *hw);
35static s32 igb_set_fc_watermarks(struct e1000_hw *hw);
Auke Kok9d5c8242008-01-24 02:22:38 -080036
Auke Kok9d5c8242008-01-24 02:22:38 -080037/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070038 * igb_get_bus_info_pcie - Get PCIe bus information
Auke Kok9d5c8242008-01-24 02:22:38 -080039 * @hw: pointer to the HW structure
40 *
41 * Determines and stores the system bus information for a particular
42 * network interface. The following bus information is determined and stored:
43 * bus speed, bus width, type (PCIe), and PCIe function.
44 **/
45s32 igb_get_bus_info_pcie(struct e1000_hw *hw)
46{
47 struct e1000_bus_info *bus = &hw->bus;
48 s32 ret_val;
Alexander Duyck5e8427e2008-12-10 01:09:53 -080049 u32 reg;
50 u16 pcie_link_status;
Auke Kok9d5c8242008-01-24 02:22:38 -080051
52 bus->type = e1000_bus_type_pci_express;
Auke Kok9d5c8242008-01-24 02:22:38 -080053
54 ret_val = igb_read_pcie_cap_reg(hw,
Alexander Duyckff846f52010-04-27 01:02:40 +000055 PCI_EXP_LNKSTA,
56 &pcie_link_status);
57 if (ret_val) {
Auke Kok9d5c8242008-01-24 02:22:38 -080058 bus->width = e1000_bus_width_unknown;
Alexander Duyckff846f52010-04-27 01:02:40 +000059 bus->speed = e1000_bus_speed_unknown;
60 } else {
61 switch (pcie_link_status & PCI_EXP_LNKSTA_CLS) {
62 case PCI_EXP_LNKSTA_CLS_2_5GB:
63 bus->speed = e1000_bus_speed_2500;
64 break;
65 case PCI_EXP_LNKSTA_CLS_5_0GB:
66 bus->speed = e1000_bus_speed_5000;
67 break;
68 default:
69 bus->speed = e1000_bus_speed_unknown;
70 break;
71 }
72
Auke Kok9d5c8242008-01-24 02:22:38 -080073 bus->width = (enum e1000_bus_width)((pcie_link_status &
Alexander Duyckff846f52010-04-27 01:02:40 +000074 PCI_EXP_LNKSTA_NLW) >>
75 PCI_EXP_LNKSTA_NLW_SHIFT);
76 }
Auke Kok9d5c8242008-01-24 02:22:38 -080077
Alexander Duyck5e8427e2008-12-10 01:09:53 -080078 reg = rd32(E1000_STATUS);
79 bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
Auke Kok9d5c8242008-01-24 02:22:38 -080080
81 return 0;
82}
83
84/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070085 * igb_clear_vfta - Clear VLAN filter table
Auke Kok9d5c8242008-01-24 02:22:38 -080086 * @hw: pointer to the HW structure
87 *
88 * Clears the register array which contains the VLAN filter table by
89 * setting all the values to 0.
90 **/
91void igb_clear_vfta(struct e1000_hw *hw)
92{
93 u32 offset;
94
Alexander Duyck832e8212016-01-06 23:10:30 -080095 for (offset = E1000_VLAN_FILTER_TBL_SIZE; offset--;)
96 hw->mac.ops.write_vfta(hw, offset, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -080097}
98
99/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700100 * igb_write_vfta - Write value to VLAN filter table
Auke Kok9d5c8242008-01-24 02:22:38 -0800101 * @hw: pointer to the HW structure
102 * @offset: register offset in VLAN filter table
103 * @value: register value written to VLAN filter table
104 *
105 * Writes value at the given offset in the register array which stores
106 * the VLAN filter table.
107 **/
Alexander Duyck832e8212016-01-06 23:10:30 -0800108void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Auke Kok9d5c8242008-01-24 02:22:38 -0800109{
Alexander Duyck832e8212016-01-06 23:10:30 -0800110 struct igb_adapter *adapter = hw->back;
111
Auke Kok9d5c8242008-01-24 02:22:38 -0800112 array_wr32(E1000_VFTA, offset, value);
113 wrfl();
Auke Kok9d5c8242008-01-24 02:22:38 -0800114
Alexander Duyck832e8212016-01-06 23:10:30 -0800115 adapter->shadow_vfta[offset] = value;
Carolyn Wyborny1128c752011-10-14 00:13:49 +0000116}
117
Auke Kok9d5c8242008-01-24 02:22:38 -0800118/**
Alexander Duyck5ac16652009-07-23 18:09:12 +0000119 * igb_init_rx_addrs - Initialize receive address's
120 * @hw: pointer to the HW structure
121 * @rar_count: receive address registers
122 *
123 * Setups the receive address registers by setting the base receive address
124 * register to the devices MAC address and clearing all the other receive
125 * address registers to 0.
126 **/
127void igb_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
128{
129 u32 i;
130 u8 mac_addr[ETH_ALEN] = {0};
131
132 /* Setup the receive address */
133 hw_dbg("Programming MAC Address into RAR[0]\n");
134
135 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
136
137 /* Zero out the other (rar_entry_count - 1) receive addresses */
138 hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
139 for (i = 1; i < rar_count; i++)
140 hw->mac.ops.rar_set(hw, mac_addr, i);
141}
142
143/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800144 * igb_vfta_set - enable or disable vlan in VLAN filter table
145 * @hw: pointer to the HW structure
Alexander Duyck832e8212016-01-06 23:10:30 -0800146 * @vlan: VLAN id to add or remove
147 * @vlan_on: if true add filter, if false remove
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800148 *
149 * Sets or clears a bit in the VLAN filter table array based on VLAN id
150 * and if we are adding or removing the filter
151 **/
Alexander Duyck832e8212016-01-06 23:10:30 -0800152s32 igb_vfta_set(struct e1000_hw *hw, u32 vlan, bool vlan_on)
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800153{
Carolyn Wyborny1128c752011-10-14 00:13:49 +0000154 struct igb_adapter *adapter = hw->back;
Alexander Duyck832e8212016-01-06 23:10:30 -0800155 u32 regidx, vfta_delta, vfta;
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800156
Alexander Duyck832e8212016-01-06 23:10:30 -0800157 if (vlan > 4095)
158 return E1000_ERR_PARAM;
159
160 /* Part 1
161 * The VFTA is a bitstring made up of 128 32-bit registers
162 * that enable the particular VLAN id, much like the MTA:
163 * bits[11-5]: which register
164 * bits[4-0]: which bit in the register
165 */
166 regidx = vlan / 32;
167 vfta_delta = 1 << (vlan % 32);
168 vfta = adapter->shadow_vfta[regidx];
169
170 /* vfta_delta represents the difference between the current value
171 * of vfta and the value we want in the register. Since the diff
172 * is an XOR mask we can just update vfta using an XOR.
173 */
174 vfta_delta &= vlan_on ? ~vfta : vfta;
175 vfta ^= vfta_delta;
Carolyn Wyborny1128c752011-10-14 00:13:49 +0000176
Alexander Duyckcad6d052009-03-13 20:41:37 +0000177 /* bit was set/cleared before we started */
Alexander Duyck832e8212016-01-06 23:10:30 -0800178 if (vfta_delta)
179 hw->mac.ops.write_vfta(hw, regidx, vfta);
Alexander Duyckcad6d052009-03-13 20:41:37 +0000180
Alexander Duyck832e8212016-01-06 23:10:30 -0800181 return 0;
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800182}
183
184/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700185 * igb_check_alt_mac_addr - Check for alternate MAC addr
Auke Kok9d5c8242008-01-24 02:22:38 -0800186 * @hw: pointer to the HW structure
187 *
188 * Checks the nvm for an alternate MAC address. An alternate MAC address
189 * can be setup by pre-boot software and must be treated like a permanent
190 * address and must override the actual permanent MAC address. If an
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000191 * alternate MAC address is found it is saved in the hw struct and
192 * programmed into RAR0 and the function returns success, otherwise the
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300193 * function returns an error.
Auke Kok9d5c8242008-01-24 02:22:38 -0800194 **/
195s32 igb_check_alt_mac_addr(struct e1000_hw *hw)
196{
197 u32 i;
198 s32 ret_val = 0;
199 u16 offset, nvm_alt_mac_addr_offset, nvm_data;
200 u8 alt_mac_addr[ETH_ALEN];
201
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000202 /* Alternate MAC address is handled by the option ROM for 82580
Carolyn Wyborny65189d22011-10-13 17:28:39 +0000203 * and newer. SW support not required.
204 */
205 if (hw->mac.type >= e1000_82580)
206 goto out;
207
Alexander Duyck312c75a2009-02-06 23:17:47 +0000208 ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800209 &nvm_alt_mac_addr_offset);
210 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700211 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800212 goto out;
213 }
214
Akeem G. Abodunrin6538ee62011-09-02 23:08:55 +0000215 if ((nvm_alt_mac_addr_offset == 0xFFFF) ||
216 (nvm_alt_mac_addr_offset == 0x0000))
Alexander Duyck22896632009-10-05 06:34:25 +0000217 /* There is no Alternate MAC Address */
Auke Kok9d5c8242008-01-24 02:22:38 -0800218 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800219
220 if (hw->bus.func == E1000_FUNC_1)
Alexander Duyck22896632009-10-05 06:34:25 +0000221 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
Akeem G. Abodunrin45b58462011-09-02 23:09:30 +0000222 if (hw->bus.func == E1000_FUNC_2)
223 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN2;
224
225 if (hw->bus.func == E1000_FUNC_3)
226 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN3;
Auke Kok9d5c8242008-01-24 02:22:38 -0800227 for (i = 0; i < ETH_ALEN; i += 2) {
228 offset = nvm_alt_mac_addr_offset + (i >> 1);
Alexander Duyck312c75a2009-02-06 23:17:47 +0000229 ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800230 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700231 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800232 goto out;
233 }
234
235 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
236 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
237 }
238
239 /* if multicast bit is set, the alternate address will not be used */
Tobias Klauser58d14d42011-07-03 23:50:15 +0000240 if (is_multicast_ether_addr(alt_mac_addr)) {
Alexander Duyck22896632009-10-05 06:34:25 +0000241 hw_dbg("Ignoring Alternate Mac Address with MC bit set\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800242 goto out;
243 }
244
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000245 /* We have a valid alternate MAC address, and we want to treat it the
Alexander Duyck22896632009-10-05 06:34:25 +0000246 * same as the normal permanent MAC address stored by the HW into the
247 * RAR. Do this by mapping this address into RAR0.
248 */
249 hw->mac.ops.rar_set(hw, alt_mac_addr, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800250
251out:
252 return ret_val;
253}
254
255/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700256 * igb_rar_set - Set receive address register
Auke Kok9d5c8242008-01-24 02:22:38 -0800257 * @hw: pointer to the HW structure
258 * @addr: pointer to the receive address
259 * @index: receive address array register
260 *
261 * Sets the receive address array register at index to the address passed
262 * in by addr.
263 **/
264void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
265{
266 u32 rar_low, rar_high;
267
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000268 /* HW expects these in little endian so we reverse the byte order
Auke Kok9d5c8242008-01-24 02:22:38 -0800269 * from network order (big endian) to little endian
270 */
271 rar_low = ((u32) addr[0] |
272 ((u32) addr[1] << 8) |
273 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
274
275 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
276
Alexander Duyck86757372009-02-06 23:21:51 +0000277 /* If MAC address zero, no need to set the AV bit */
278 if (rar_low || rar_high)
Auke Kok9d5c8242008-01-24 02:22:38 -0800279 rar_high |= E1000_RAH_AV;
280
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000281 /* Some bridges will combine consecutive 32-bit writes into
Alexander Duyck6deac6f2009-10-05 06:36:01 +0000282 * a single burst write, which will malfunction on some parts.
283 * The flushes avoid this.
284 */
Alexander Duyck5e8427e2008-12-10 01:09:53 -0800285 wr32(E1000_RAL(index), rar_low);
Alexander Duyck6deac6f2009-10-05 06:36:01 +0000286 wrfl();
Alexander Duyck5e8427e2008-12-10 01:09:53 -0800287 wr32(E1000_RAH(index), rar_high);
Alexander Duyck6deac6f2009-10-05 06:36:01 +0000288 wrfl();
Auke Kok9d5c8242008-01-24 02:22:38 -0800289}
290
291/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700292 * igb_mta_set - Set multicast filter table address
Auke Kok9d5c8242008-01-24 02:22:38 -0800293 * @hw: pointer to the HW structure
294 * @hash_value: determines the MTA register and bit to set
295 *
296 * The multicast table address is a register array of 32-bit registers.
297 * The hash_value is used to determine what register the bit is in, the
298 * current value is read, the new bit is OR'd in and the new value is
299 * written back into the register.
300 **/
Alexander Duyck549bdd82008-08-04 15:00:06 -0700301void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
Auke Kok9d5c8242008-01-24 02:22:38 -0800302{
303 u32 hash_bit, hash_reg, mta;
304
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000305 /* The MTA is a register array of 32-bit registers. It is
Auke Kok9d5c8242008-01-24 02:22:38 -0800306 * treated like an array of (32*mta_reg_count) bits. We want to
307 * set bit BitArray[hash_value]. So we figure out what register
308 * the bit is in, read it, OR in the new bit, then write
309 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
310 * mask to bits 31:5 of the hash value which gives us the
311 * register we're modifying. The hash bit within that register
312 * is determined by the lower 5 bits of the hash value.
313 */
314 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
315 hash_bit = hash_value & 0x1F;
316
317 mta = array_rd32(E1000_MTA, hash_reg);
318
319 mta |= (1 << hash_bit);
320
321 array_wr32(E1000_MTA, hash_reg, mta);
322 wrfl();
323}
324
325/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700326 * igb_hash_mc_addr - Generate a multicast hash value
Auke Kok9d5c8242008-01-24 02:22:38 -0800327 * @hw: pointer to the HW structure
328 * @mc_addr: pointer to a multicast address
329 *
330 * Generates a multicast address hash value which is used to determine
331 * the multicast filter table array address and new table value. See
332 * igb_mta_set()
333 **/
Alexander Duyck44c852e2009-09-17 14:52:29 +0000334static u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Auke Kok9d5c8242008-01-24 02:22:38 -0800335{
336 u32 hash_value, hash_mask;
337 u8 bit_shift = 0;
338
339 /* Register count multiplied by bits per register */
340 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
341
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000342 /* For a mc_filter_type of 0, bit_shift is the number of left-shifts
Auke Kok9d5c8242008-01-24 02:22:38 -0800343 * where 0xFF would still fall within the hash mask.
344 */
345 while (hash_mask >> bit_shift != 0xFF)
346 bit_shift++;
347
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000348 /* The portion of the address that is used for the hash table
Auke Kok9d5c8242008-01-24 02:22:38 -0800349 * is determined by the mc_filter_type setting.
350 * The algorithm is such that there is a total of 8 bits of shifting.
351 * The bit_shift for a mc_filter_type of 0 represents the number of
352 * left-shifts where the MSB of mc_addr[5] would still fall within
353 * the hash_mask. Case 0 does this exactly. Since there are a total
354 * of 8 bits of shifting, then mc_addr[4] will shift right the
355 * remaining number of bits. Thus 8 - bit_shift. The rest of the
356 * cases are a variation of this algorithm...essentially raising the
357 * number of bits to shift mc_addr[5] left, while still keeping the
358 * 8-bit shifting total.
359 *
360 * For example, given the following Destination MAC Address and an
361 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
362 * we can see that the bit_shift for case 0 is 4. These are the hash
363 * values resulting from each mc_filter_type...
364 * [0] [1] [2] [3] [4] [5]
365 * 01 AA 00 12 34 56
366 * LSB MSB
367 *
368 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
369 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
370 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
371 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
372 */
373 switch (hw->mac.mc_filter_type) {
374 default:
375 case 0:
376 break;
377 case 1:
378 bit_shift += 1;
379 break;
380 case 2:
381 bit_shift += 2;
382 break;
383 case 3:
384 bit_shift += 4;
385 break;
386 }
387
388 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
389 (((u16) mc_addr[5]) << bit_shift)));
390
391 return hash_value;
392}
393
394/**
Alexander Duyck44c852e2009-09-17 14:52:29 +0000395 * igb_update_mc_addr_list - Update Multicast addresses
396 * @hw: pointer to the HW structure
397 * @mc_addr_list: array of multicast addresses to program
398 * @mc_addr_count: number of multicast addresses to program
399 *
400 * Updates entire Multicast Table Array.
401 * The caller must have a packed mc_addr_list of multicast addresses.
402 **/
403void igb_update_mc_addr_list(struct e1000_hw *hw,
Carolyn Wyborny9005df32014-04-11 01:45:34 +0000404 u8 *mc_addr_list, u32 mc_addr_count)
Alexander Duyck44c852e2009-09-17 14:52:29 +0000405{
406 u32 hash_value, hash_bit, hash_reg;
407 int i;
408
409 /* clear mta_shadow */
410 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
411
412 /* update mta_shadow from mc_addr_list */
413 for (i = 0; (u32) i < mc_addr_count; i++) {
414 hash_value = igb_hash_mc_addr(hw, mc_addr_list);
415
416 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
417 hash_bit = hash_value & 0x1F;
418
419 hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
420 mc_addr_list += (ETH_ALEN);
421 }
422
423 /* replace the entire MTA table */
424 for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
425 array_wr32(E1000_MTA, i, hw->mac.mta_shadow[i]);
426 wrfl();
427}
428
429/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700430 * igb_clear_hw_cntrs_base - Clear base hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -0800431 * @hw: pointer to the HW structure
432 *
433 * Clears the base hardware counters by reading the counter registers.
434 **/
435void igb_clear_hw_cntrs_base(struct e1000_hw *hw)
436{
Alexander Duyckcc9073b2009-10-05 06:31:25 +0000437 rd32(E1000_CRCERRS);
438 rd32(E1000_SYMERRS);
439 rd32(E1000_MPC);
440 rd32(E1000_SCC);
441 rd32(E1000_ECOL);
442 rd32(E1000_MCC);
443 rd32(E1000_LATECOL);
444 rd32(E1000_COLC);
445 rd32(E1000_DC);
446 rd32(E1000_SEC);
447 rd32(E1000_RLEC);
448 rd32(E1000_XONRXC);
449 rd32(E1000_XONTXC);
450 rd32(E1000_XOFFRXC);
451 rd32(E1000_XOFFTXC);
452 rd32(E1000_FCRUC);
453 rd32(E1000_GPRC);
454 rd32(E1000_BPRC);
455 rd32(E1000_MPRC);
456 rd32(E1000_GPTC);
457 rd32(E1000_GORCL);
458 rd32(E1000_GORCH);
459 rd32(E1000_GOTCL);
460 rd32(E1000_GOTCH);
461 rd32(E1000_RNBC);
462 rd32(E1000_RUC);
463 rd32(E1000_RFC);
464 rd32(E1000_ROC);
465 rd32(E1000_RJC);
466 rd32(E1000_TORL);
467 rd32(E1000_TORH);
468 rd32(E1000_TOTL);
469 rd32(E1000_TOTH);
470 rd32(E1000_TPR);
471 rd32(E1000_TPT);
472 rd32(E1000_MPTC);
473 rd32(E1000_BPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -0800474}
475
476/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700477 * igb_check_for_copper_link - Check for link (Copper)
Auke Kok9d5c8242008-01-24 02:22:38 -0800478 * @hw: pointer to the HW structure
479 *
480 * Checks to see of the link status of the hardware has changed. If a
481 * change in link status has been detected, then we read the PHY registers
482 * to get the current speed/duplex if link exists.
483 **/
484s32 igb_check_for_copper_link(struct e1000_hw *hw)
485{
486 struct e1000_mac_info *mac = &hw->mac;
487 s32 ret_val;
488 bool link;
489
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000490 /* We only want to go out to the PHY registers to see if Auto-Neg
Auke Kok9d5c8242008-01-24 02:22:38 -0800491 * has completed and/or if our link status has changed. The
492 * get_link_status flag is set upon receiving a Link Status
493 * Change or Rx Sequence Error interrupt.
494 */
495 if (!mac->get_link_status) {
496 ret_val = 0;
497 goto out;
498 }
499
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000500 /* First we want to see if the MII Status Register reports
Auke Kok9d5c8242008-01-24 02:22:38 -0800501 * link. If so, then we want to get the current speed/duplex
502 * of the PHY.
503 */
504 ret_val = igb_phy_has_link(hw, 1, 0, &link);
505 if (ret_val)
506 goto out;
507
508 if (!link)
509 goto out; /* No link detected */
510
511 mac->get_link_status = false;
512
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000513 /* Check if there was DownShift, must be checked
Auke Kok9d5c8242008-01-24 02:22:38 -0800514 * immediately after link-up
515 */
516 igb_check_downshift(hw);
517
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000518 /* If we are forcing speed/duplex, then we simply return since
Auke Kok9d5c8242008-01-24 02:22:38 -0800519 * we have already determined whether we have link or not.
520 */
521 if (!mac->autoneg) {
522 ret_val = -E1000_ERR_CONFIG;
523 goto out;
524 }
525
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000526 /* Auto-Neg is enabled. Auto Speed Detection takes care
Auke Kok9d5c8242008-01-24 02:22:38 -0800527 * of MAC speed/duplex configuration. So we only need to
528 * configure Collision Distance in the MAC.
529 */
530 igb_config_collision_dist(hw);
531
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000532 /* Configure Flow Control now that Auto-Neg has completed.
Auke Kok9d5c8242008-01-24 02:22:38 -0800533 * First, we need to restore the desired flow control
534 * settings because we may have had to re-autoneg with a
535 * different link partner.
536 */
537 ret_val = igb_config_fc_after_link_up(hw);
538 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -0700539 hw_dbg("Error configuring flow control\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800540
541out:
542 return ret_val;
543}
544
545/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700546 * igb_setup_link - Setup flow control and link settings
Auke Kok9d5c8242008-01-24 02:22:38 -0800547 * @hw: pointer to the HW structure
548 *
549 * Determines which flow control settings to use, then configures flow
550 * control. Calls the appropriate media-specific link configuration
551 * function. Assuming the adapter has a valid link partner, a valid link
552 * should be established. Assumes the hardware has previously been reset
553 * and the transmitter and receiver are not enabled.
554 **/
555s32 igb_setup_link(struct e1000_hw *hw)
556{
557 s32 ret_val = 0;
558
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000559 /* In the case of the phy reset being blocked, we already have a link.
Auke Kok9d5c8242008-01-24 02:22:38 -0800560 * We do not need to set it up again.
561 */
562 if (igb_check_reset_block(hw))
563 goto out;
564
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000565 /* If requested flow control is set to default, set flow control
Alexander Duyck0cce1192009-07-23 18:10:24 +0000566 * based on the EEPROM flow control settings.
567 */
568 if (hw->fc.requested_mode == e1000_fc_default) {
569 ret_val = igb_set_default_fc(hw);
570 if (ret_val)
571 goto out;
572 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800573
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000574 /* We want to save off the original Flow Control configuration just
Auke Kok9d5c8242008-01-24 02:22:38 -0800575 * in case we get disconnected and then reconnected into a different
576 * hub or switch with different Flow Control capabilities.
577 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000578 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kok9d5c8242008-01-24 02:22:38 -0800579
Alexander Duyck0cce1192009-07-23 18:10:24 +0000580 hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
Auke Kok9d5c8242008-01-24 02:22:38 -0800581
582 /* Call the necessary media_type subroutine to configure the link. */
583 ret_val = hw->mac.ops.setup_physical_interface(hw);
584 if (ret_val)
585 goto out;
586
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000587 /* Initialize the flow control address, type, and PAUSE timer
Auke Kok9d5c8242008-01-24 02:22:38 -0800588 * registers to their default values. This is done even if flow
589 * control is disabled, because it does not hurt anything to
590 * initialize these registers.
591 */
Auke Kok652fff32008-06-27 11:00:18 -0700592 hw_dbg("Initializing the Flow Control address, type and timer regs\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800593 wr32(E1000_FCT, FLOW_CONTROL_TYPE);
594 wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
595 wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
596
597 wr32(E1000_FCTTV, hw->fc.pause_time);
598
599 ret_val = igb_set_fc_watermarks(hw);
600
601out:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000602
Auke Kok9d5c8242008-01-24 02:22:38 -0800603 return ret_val;
604}
605
606/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700607 * igb_config_collision_dist - Configure collision distance
Auke Kok9d5c8242008-01-24 02:22:38 -0800608 * @hw: pointer to the HW structure
609 *
610 * Configures the collision distance to the default value and is used
611 * during link setup. Currently no func pointer exists and all
612 * implementations are handled in the generic version of this function.
613 **/
614void igb_config_collision_dist(struct e1000_hw *hw)
615{
616 u32 tctl;
617
618 tctl = rd32(E1000_TCTL);
619
620 tctl &= ~E1000_TCTL_COLD;
621 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
622
623 wr32(E1000_TCTL, tctl);
624 wrfl();
625}
626
627/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700628 * igb_set_fc_watermarks - Set flow control high/low watermarks
Auke Kok9d5c8242008-01-24 02:22:38 -0800629 * @hw: pointer to the HW structure
630 *
631 * Sets the flow control high/low threshold (watermark) registers. If
632 * flow control XON frame transmission is enabled, then set XON frame
633 * tansmission as well.
634 **/
635static s32 igb_set_fc_watermarks(struct e1000_hw *hw)
636{
637 s32 ret_val = 0;
638 u32 fcrtl = 0, fcrth = 0;
639
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000640 /* Set the flow control receive threshold registers. Normally,
Auke Kok9d5c8242008-01-24 02:22:38 -0800641 * these registers will be set to a default threshold that may be
642 * adjusted later by the driver's runtime code. However, if the
643 * ability to transmit pause frames is not enabled, then these
644 * registers will be set to 0.
645 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000646 if (hw->fc.current_mode & e1000_fc_tx_pause) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000647 /* We need to set up the Receive Threshold high and low water
Auke Kok9d5c8242008-01-24 02:22:38 -0800648 * marks as well as (optionally) enabling the transmission of
649 * XON frames.
650 */
651 fcrtl = hw->fc.low_water;
652 if (hw->fc.send_xon)
653 fcrtl |= E1000_FCRTL_XONE;
654
655 fcrth = hw->fc.high_water;
656 }
657 wr32(E1000_FCRTL, fcrtl);
658 wr32(E1000_FCRTH, fcrth);
659
660 return ret_val;
661}
662
663/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700664 * igb_set_default_fc - Set flow control default values
Auke Kok9d5c8242008-01-24 02:22:38 -0800665 * @hw: pointer to the HW structure
666 *
667 * Read the EEPROM for the default values for flow control and store the
668 * values.
669 **/
670static s32 igb_set_default_fc(struct e1000_hw *hw)
671{
672 s32 ret_val = 0;
Fujinaka, Toddc7cb0202013-09-10 11:57:17 -0700673 u16 lan_offset;
Auke Kok9d5c8242008-01-24 02:22:38 -0800674 u16 nvm_data;
675
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000676 /* Read and store word 0x0F of the EEPROM. This word contains bits
Auke Kok9d5c8242008-01-24 02:22:38 -0800677 * that determine the hardware's default PAUSE (flow control) mode,
678 * a bit that determines whether the HW defaults to enabling or
679 * disabling auto-negotiation, and the direction of the
680 * SW defined pins. If there is no SW over-ride of the flow
681 * control setting, then the variable hw->fc will
682 * be initialized based on a value in the EEPROM.
683 */
Fujinaka, Toddc7cb0202013-09-10 11:57:17 -0700684 if (hw->mac.type == e1000_i350) {
685 lan_offset = NVM_82580_LAN_FUNC_OFFSET(hw->bus.func);
686 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG
687 + lan_offset, 1, &nvm_data);
688 } else {
689 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG,
690 1, &nvm_data);
691 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800692
693 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700694 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800695 goto out;
696 }
697
698 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
Alexander Duyck0cce1192009-07-23 18:10:24 +0000699 hw->fc.requested_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -0800700 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
701 NVM_WORD0F_ASM_DIR)
Alexander Duyck0cce1192009-07-23 18:10:24 +0000702 hw->fc.requested_mode = e1000_fc_tx_pause;
Auke Kok9d5c8242008-01-24 02:22:38 -0800703 else
Alexander Duyck0cce1192009-07-23 18:10:24 +0000704 hw->fc.requested_mode = e1000_fc_full;
Auke Kok9d5c8242008-01-24 02:22:38 -0800705
706out:
707 return ret_val;
708}
709
710/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700711 * igb_force_mac_fc - Force the MAC's flow control settings
Auke Kok9d5c8242008-01-24 02:22:38 -0800712 * @hw: pointer to the HW structure
713 *
714 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
715 * device control register to reflect the adapter settings. TFCE and RFCE
716 * need to be explicitly set by software when a copper PHY is used because
717 * autonegotiation is managed by the PHY rather than the MAC. Software must
718 * also configure these bits when link is forced on a fiber connection.
719 **/
720s32 igb_force_mac_fc(struct e1000_hw *hw)
721{
722 u32 ctrl;
723 s32 ret_val = 0;
724
725 ctrl = rd32(E1000_CTRL);
726
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000727 /* Because we didn't get link via the internal auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -0800728 * mechanism (we either forced link or we got link via PHY
729 * auto-neg), we have to manually enable/disable transmit an
730 * receive flow control.
731 *
732 * The "Case" statement below enables/disable flow control
Alexander Duyck0cce1192009-07-23 18:10:24 +0000733 * according to the "hw->fc.current_mode" parameter.
Auke Kok9d5c8242008-01-24 02:22:38 -0800734 *
735 * The possible values of the "fc" parameter are:
736 * 0: Flow control is completely disabled
737 * 1: Rx flow control is enabled (we can receive pause
738 * frames but not send pause frames).
739 * 2: Tx flow control is enabled (we can send pause frames
740 * frames but we do not receive pause frames).
741 * 3: Both Rx and TX flow control (symmetric) is enabled.
742 * other: No other values should be possible at this point.
743 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000744 hw_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
Auke Kok9d5c8242008-01-24 02:22:38 -0800745
Alexander Duyck0cce1192009-07-23 18:10:24 +0000746 switch (hw->fc.current_mode) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800747 case e1000_fc_none:
748 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
749 break;
750 case e1000_fc_rx_pause:
751 ctrl &= (~E1000_CTRL_TFCE);
752 ctrl |= E1000_CTRL_RFCE;
753 break;
754 case e1000_fc_tx_pause:
755 ctrl &= (~E1000_CTRL_RFCE);
756 ctrl |= E1000_CTRL_TFCE;
757 break;
758 case e1000_fc_full:
759 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
760 break;
761 default:
Auke Kok652fff32008-06-27 11:00:18 -0700762 hw_dbg("Flow control param set incorrectly\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800763 ret_val = -E1000_ERR_CONFIG;
764 goto out;
765 }
766
767 wr32(E1000_CTRL, ctrl);
768
769out:
770 return ret_val;
771}
772
773/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700774 * igb_config_fc_after_link_up - Configures flow control after link
Auke Kok9d5c8242008-01-24 02:22:38 -0800775 * @hw: pointer to the HW structure
776 *
777 * Checks the status of auto-negotiation after link up to ensure that the
778 * speed and duplex were not forced. If the link needed to be forced, then
779 * flow control needs to be forced also. If auto-negotiation is enabled
780 * and did not fail, then we configure flow control based on our link
781 * partner.
782 **/
783s32 igb_config_fc_after_link_up(struct e1000_hw *hw)
784{
785 struct e1000_mac_info *mac = &hw->mac;
786 s32 ret_val = 0;
Carolyn Wybornydaf56e42012-10-23 12:54:33 +0000787 u32 pcs_status_reg, pcs_adv_reg, pcs_lp_ability_reg, pcs_ctrl_reg;
Auke Kok9d5c8242008-01-24 02:22:38 -0800788 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
789 u16 speed, duplex;
790
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000791 /* Check for the case where we have fiber media and auto-neg failed
Auke Kok9d5c8242008-01-24 02:22:38 -0800792 * so we had to force link. In this case, we need to force the
793 * configuration of the MAC to match the "fc" parameter.
794 */
795 if (mac->autoneg_failed) {
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000796 if (hw->phy.media_type == e1000_media_type_internal_serdes)
Auke Kok9d5c8242008-01-24 02:22:38 -0800797 ret_val = igb_force_mac_fc(hw);
798 } else {
799 if (hw->phy.media_type == e1000_media_type_copper)
800 ret_val = igb_force_mac_fc(hw);
801 }
802
803 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700804 hw_dbg("Error forcing flow control settings\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800805 goto out;
806 }
807
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000808 /* Check for the case where we have copper media and auto-neg is
Auke Kok9d5c8242008-01-24 02:22:38 -0800809 * enabled. In this case, we need to check and see if Auto-Neg
810 * has completed, and if so, how the PHY and link partner has
811 * flow control configured.
812 */
813 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000814 /* Read the MII Status Register and check to see if AutoNeg
Auke Kok9d5c8242008-01-24 02:22:38 -0800815 * has completed. We read this twice because this reg has
816 * some "sticky" (latched) bits.
817 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000818 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
Auke Kok9d5c8242008-01-24 02:22:38 -0800819 &mii_status_reg);
820 if (ret_val)
821 goto out;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000822 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
Auke Kok9d5c8242008-01-24 02:22:38 -0800823 &mii_status_reg);
824 if (ret_val)
825 goto out;
826
827 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
Carolyn Wybornyc75c4ed2014-04-11 01:45:17 +0000828 hw_dbg("Copper PHY and Auto Neg has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800829 goto out;
830 }
831
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000832 /* The AutoNeg process has completed, so we now need to
Auke Kok9d5c8242008-01-24 02:22:38 -0800833 * read both the Auto Negotiation Advertisement
834 * Register (Address 4) and the Auto_Negotiation Base
835 * Page Ability Register (Address 5) to determine how
836 * flow control was negotiated.
837 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000838 ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
Auke Kok9d5c8242008-01-24 02:22:38 -0800839 &mii_nway_adv_reg);
840 if (ret_val)
841 goto out;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000842 ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
Auke Kok9d5c8242008-01-24 02:22:38 -0800843 &mii_nway_lp_ability_reg);
844 if (ret_val)
845 goto out;
846
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000847 /* Two bits in the Auto Negotiation Advertisement Register
Auke Kok9d5c8242008-01-24 02:22:38 -0800848 * (Address 4) and two bits in the Auto Negotiation Base
849 * Page Ability Register (Address 5) determine flow control
850 * for both the PHY and the link partner. The following
851 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
852 * 1999, describes these PAUSE resolution bits and how flow
853 * control is determined based upon these settings.
854 * NOTE: DC = Don't Care
855 *
856 * LOCAL DEVICE | LINK PARTNER
857 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
858 *-------|---------|-------|---------|--------------------
859 * 0 | 0 | DC | DC | e1000_fc_none
860 * 0 | 1 | 0 | DC | e1000_fc_none
861 * 0 | 1 | 1 | 0 | e1000_fc_none
862 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
863 * 1 | 0 | 0 | DC | e1000_fc_none
864 * 1 | DC | 1 | DC | e1000_fc_full
865 * 1 | 1 | 0 | 0 | e1000_fc_none
866 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
867 *
868 * Are both PAUSE bits set to 1? If so, this implies
869 * Symmetric Flow Control is enabled at both ends. The
870 * ASM_DIR bits are irrelevant per the spec.
871 *
872 * For Symmetric Flow Control:
873 *
874 * LOCAL DEVICE | LINK PARTNER
875 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
876 *-------|---------|-------|---------|--------------------
877 * 1 | DC | 1 | DC | E1000_fc_full
878 *
879 */
880 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
881 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000882 /* Now we need to check if the user selected RX ONLY
Auke Kok9d5c8242008-01-24 02:22:38 -0800883 * of pause frames. In this case, we had to advertise
884 * FULL flow control because we could not advertise RX
885 * ONLY. Hence, we must now check to see if we need to
886 * turn OFF the TRANSMISSION of PAUSE frames.
887 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000888 if (hw->fc.requested_mode == e1000_fc_full) {
889 hw->fc.current_mode = e1000_fc_full;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000890 hw_dbg("Flow Control = FULL.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800891 } else {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000892 hw->fc.current_mode = e1000_fc_rx_pause;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000893 hw_dbg("Flow Control = RX PAUSE frames only.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800894 }
895 }
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000896 /* For receiving PAUSE frames ONLY.
Auke Kok9d5c8242008-01-24 02:22:38 -0800897 *
898 * LOCAL DEVICE | LINK PARTNER
899 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
900 *-------|---------|-------|---------|--------------------
901 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
902 */
903 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
904 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
905 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
906 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000907 hw->fc.current_mode = e1000_fc_tx_pause;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000908 hw_dbg("Flow Control = TX PAUSE frames only.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800909 }
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000910 /* For transmitting PAUSE frames ONLY.
Auke Kok9d5c8242008-01-24 02:22:38 -0800911 *
912 * LOCAL DEVICE | LINK PARTNER
913 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
914 *-------|---------|-------|---------|--------------------
915 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
916 */
917 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
918 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
919 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
920 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000921 hw->fc.current_mode = e1000_fc_rx_pause;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000922 hw_dbg("Flow Control = RX PAUSE frames only.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800923 }
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000924 /* Per the IEEE spec, at this point flow control should be
Auke Kok9d5c8242008-01-24 02:22:38 -0800925 * disabled. However, we want to consider that we could
926 * be connected to a legacy switch that doesn't advertise
927 * desired flow control, but can be forced on the link
928 * partner. So if we advertised no flow control, that is
929 * what we will resolve to. If we advertised some kind of
930 * receive capability (Rx Pause Only or Full Flow Control)
931 * and the link partner advertised none, we will configure
932 * ourselves to enable Rx Flow Control only. We can do
933 * this safely for two reasons: If the link partner really
934 * didn't want flow control enabled, and we enable Rx, no
935 * harm done since we won't be receiving any PAUSE frames
936 * anyway. If the intent on the link partner was to have
937 * flow control enabled, then by us enabling RX only, we
938 * can at least receive pause frames and process them.
939 * This is a good idea because in most cases, since we are
940 * predominantly a server NIC, more times than not we will
941 * be asked to delay transmission of packets than asking
942 * our link partner to pause transmission of frames.
943 */
Akeem G. Abodunrin5c17a202013-01-29 10:15:31 +0000944 else if ((hw->fc.requested_mode == e1000_fc_none) ||
945 (hw->fc.requested_mode == e1000_fc_tx_pause) ||
946 (hw->fc.strict_ieee)) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000947 hw->fc.current_mode = e1000_fc_none;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000948 hw_dbg("Flow Control = NONE.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800949 } else {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000950 hw->fc.current_mode = e1000_fc_rx_pause;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000951 hw_dbg("Flow Control = RX PAUSE frames only.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800952 }
953
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000954 /* Now we need to do one last check... If we auto-
Auke Kok9d5c8242008-01-24 02:22:38 -0800955 * negotiated to HALF DUPLEX, flow control should not be
956 * enabled per IEEE 802.3 spec.
957 */
958 ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
959 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700960 hw_dbg("Error getting link speed and duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800961 goto out;
962 }
963
964 if (duplex == HALF_DUPLEX)
Alexander Duyck0cce1192009-07-23 18:10:24 +0000965 hw->fc.current_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -0800966
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000967 /* Now we call a subroutine to actually force the MAC
Auke Kok9d5c8242008-01-24 02:22:38 -0800968 * controller to use the correct flow control settings.
969 */
970 ret_val = igb_force_mac_fc(hw);
971 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700972 hw_dbg("Error forcing flow control settings\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800973 goto out;
974 }
975 }
Carolyn Wybornydaf56e42012-10-23 12:54:33 +0000976 /* Check for the case where we have SerDes media and auto-neg is
977 * enabled. In this case, we need to check and see if Auto-Neg
978 * has completed, and if so, how the PHY and link partner has
979 * flow control configured.
980 */
981 if ((hw->phy.media_type == e1000_media_type_internal_serdes)
982 && mac->autoneg) {
983 /* Read the PCS_LSTS and check to see if AutoNeg
984 * has completed.
985 */
986 pcs_status_reg = rd32(E1000_PCS_LSTAT);
987
988 if (!(pcs_status_reg & E1000_PCS_LSTS_AN_COMPLETE)) {
989 hw_dbg("PCS Auto Neg has not completed.\n");
990 return ret_val;
991 }
992
993 /* The AutoNeg process has completed, so we now need to
994 * read both the Auto Negotiation Advertisement
995 * Register (PCS_ANADV) and the Auto_Negotiation Base
996 * Page Ability Register (PCS_LPAB) to determine how
997 * flow control was negotiated.
998 */
999 pcs_adv_reg = rd32(E1000_PCS_ANADV);
1000 pcs_lp_ability_reg = rd32(E1000_PCS_LPAB);
1001
1002 /* Two bits in the Auto Negotiation Advertisement Register
1003 * (PCS_ANADV) and two bits in the Auto Negotiation Base
1004 * Page Ability Register (PCS_LPAB) determine flow control
1005 * for both the PHY and the link partner. The following
1006 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1007 * 1999, describes these PAUSE resolution bits and how flow
1008 * control is determined based upon these settings.
1009 * NOTE: DC = Don't Care
1010 *
1011 * LOCAL DEVICE | LINK PARTNER
1012 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1013 *-------|---------|-------|---------|--------------------
1014 * 0 | 0 | DC | DC | e1000_fc_none
1015 * 0 | 1 | 0 | DC | e1000_fc_none
1016 * 0 | 1 | 1 | 0 | e1000_fc_none
1017 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1018 * 1 | 0 | 0 | DC | e1000_fc_none
1019 * 1 | DC | 1 | DC | e1000_fc_full
1020 * 1 | 1 | 0 | 0 | e1000_fc_none
1021 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1022 *
1023 * Are both PAUSE bits set to 1? If so, this implies
1024 * Symmetric Flow Control is enabled at both ends. The
1025 * ASM_DIR bits are irrelevant per the spec.
1026 *
1027 * For Symmetric Flow Control:
1028 *
1029 * LOCAL DEVICE | LINK PARTNER
1030 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1031 *-------|---------|-------|---------|--------------------
1032 * 1 | DC | 1 | DC | e1000_fc_full
1033 *
1034 */
1035 if ((pcs_adv_reg & E1000_TXCW_PAUSE) &&
1036 (pcs_lp_ability_reg & E1000_TXCW_PAUSE)) {
1037 /* Now we need to check if the user selected Rx ONLY
1038 * of pause frames. In this case, we had to advertise
1039 * FULL flow control because we could not advertise Rx
1040 * ONLY. Hence, we must now check to see if we need to
1041 * turn OFF the TRANSMISSION of PAUSE frames.
1042 */
1043 if (hw->fc.requested_mode == e1000_fc_full) {
1044 hw->fc.current_mode = e1000_fc_full;
1045 hw_dbg("Flow Control = FULL.\n");
1046 } else {
1047 hw->fc.current_mode = e1000_fc_rx_pause;
1048 hw_dbg("Flow Control = Rx PAUSE frames only.\n");
1049 }
1050 }
1051 /* For receiving PAUSE frames ONLY.
1052 *
1053 * LOCAL DEVICE | LINK PARTNER
1054 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1055 *-------|---------|-------|---------|--------------------
1056 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1057 */
1058 else if (!(pcs_adv_reg & E1000_TXCW_PAUSE) &&
1059 (pcs_adv_reg & E1000_TXCW_ASM_DIR) &&
1060 (pcs_lp_ability_reg & E1000_TXCW_PAUSE) &&
1061 (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) {
1062 hw->fc.current_mode = e1000_fc_tx_pause;
1063 hw_dbg("Flow Control = Tx PAUSE frames only.\n");
1064 }
1065 /* For transmitting PAUSE frames ONLY.
1066 *
1067 * LOCAL DEVICE | LINK PARTNER
1068 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1069 *-------|---------|-------|---------|--------------------
1070 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1071 */
1072 else if ((pcs_adv_reg & E1000_TXCW_PAUSE) &&
1073 (pcs_adv_reg & E1000_TXCW_ASM_DIR) &&
1074 !(pcs_lp_ability_reg & E1000_TXCW_PAUSE) &&
1075 (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) {
1076 hw->fc.current_mode = e1000_fc_rx_pause;
1077 hw_dbg("Flow Control = Rx PAUSE frames only.\n");
1078 } else {
1079 /* Per the IEEE spec, at this point flow control
1080 * should be disabled.
1081 */
1082 hw->fc.current_mode = e1000_fc_none;
1083 hw_dbg("Flow Control = NONE.\n");
1084 }
1085
1086 /* Now we call a subroutine to actually force the MAC
1087 * controller to use the correct flow control settings.
1088 */
1089 pcs_ctrl_reg = rd32(E1000_PCS_LCTL);
1090 pcs_ctrl_reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1091 wr32(E1000_PCS_LCTL, pcs_ctrl_reg);
1092
1093 ret_val = igb_force_mac_fc(hw);
1094 if (ret_val) {
1095 hw_dbg("Error forcing flow control settings\n");
1096 return ret_val;
1097 }
1098 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001099
1100out:
1101 return ret_val;
1102}
1103
1104/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001105 * igb_get_speed_and_duplex_copper - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001106 * @hw: pointer to the HW structure
1107 * @speed: stores the current speed
1108 * @duplex: stores the current duplex
1109 *
1110 * Read the status register for the current speed/duplex and store the current
1111 * speed and duplex for copper connections.
1112 **/
1113s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
1114 u16 *duplex)
1115{
1116 u32 status;
1117
1118 status = rd32(E1000_STATUS);
1119 if (status & E1000_STATUS_SPEED_1000) {
1120 *speed = SPEED_1000;
Auke Kok652fff32008-06-27 11:00:18 -07001121 hw_dbg("1000 Mbs, ");
Auke Kok9d5c8242008-01-24 02:22:38 -08001122 } else if (status & E1000_STATUS_SPEED_100) {
1123 *speed = SPEED_100;
Auke Kok652fff32008-06-27 11:00:18 -07001124 hw_dbg("100 Mbs, ");
Auke Kok9d5c8242008-01-24 02:22:38 -08001125 } else {
1126 *speed = SPEED_10;
Auke Kok652fff32008-06-27 11:00:18 -07001127 hw_dbg("10 Mbs, ");
Auke Kok9d5c8242008-01-24 02:22:38 -08001128 }
1129
1130 if (status & E1000_STATUS_FD) {
1131 *duplex = FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001132 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001133 } else {
1134 *duplex = HALF_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001135 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001136 }
1137
1138 return 0;
1139}
1140
1141/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001142 * igb_get_hw_semaphore - Acquire hardware semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001143 * @hw: pointer to the HW structure
1144 *
1145 * Acquire the HW semaphore to access the PHY or NVM
1146 **/
1147s32 igb_get_hw_semaphore(struct e1000_hw *hw)
1148{
1149 u32 swsm;
1150 s32 ret_val = 0;
1151 s32 timeout = hw->nvm.word_size + 1;
1152 s32 i = 0;
1153
1154 /* Get the SW semaphore */
1155 while (i < timeout) {
1156 swsm = rd32(E1000_SWSM);
1157 if (!(swsm & E1000_SWSM_SMBI))
1158 break;
1159
1160 udelay(50);
1161 i++;
1162 }
1163
1164 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001165 hw_dbg("Driver can't access device - SMBI bit is set.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001166 ret_val = -E1000_ERR_NVM;
1167 goto out;
1168 }
1169
1170 /* Get the FW semaphore. */
1171 for (i = 0; i < timeout; i++) {
1172 swsm = rd32(E1000_SWSM);
1173 wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
1174
1175 /* Semaphore acquired if bit latched */
1176 if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
1177 break;
1178
1179 udelay(50);
1180 }
1181
1182 if (i == timeout) {
1183 /* Release semaphores */
1184 igb_put_hw_semaphore(hw);
Auke Kok652fff32008-06-27 11:00:18 -07001185 hw_dbg("Driver can't access the NVM\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001186 ret_val = -E1000_ERR_NVM;
1187 goto out;
1188 }
1189
1190out:
1191 return ret_val;
1192}
1193
1194/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001195 * igb_put_hw_semaphore - Release hardware semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001196 * @hw: pointer to the HW structure
1197 *
1198 * Release hardware semaphore used to access the PHY or NVM
1199 **/
1200void igb_put_hw_semaphore(struct e1000_hw *hw)
1201{
1202 u32 swsm;
1203
1204 swsm = rd32(E1000_SWSM);
1205
1206 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1207
1208 wr32(E1000_SWSM, swsm);
1209}
1210
1211/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001212 * igb_get_auto_rd_done - Check for auto read completion
Auke Kok9d5c8242008-01-24 02:22:38 -08001213 * @hw: pointer to the HW structure
1214 *
1215 * Check EEPROM for Auto Read done bit.
1216 **/
1217s32 igb_get_auto_rd_done(struct e1000_hw *hw)
1218{
1219 s32 i = 0;
1220 s32 ret_val = 0;
1221
1222
1223 while (i < AUTO_READ_DONE_TIMEOUT) {
1224 if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD)
1225 break;
Carolyn Wyborny0d451e72014-04-11 01:46:40 +00001226 usleep_range(1000, 2000);
Auke Kok9d5c8242008-01-24 02:22:38 -08001227 i++;
1228 }
1229
1230 if (i == AUTO_READ_DONE_TIMEOUT) {
Auke Kok652fff32008-06-27 11:00:18 -07001231 hw_dbg("Auto read by HW from NVM has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001232 ret_val = -E1000_ERR_RESET;
1233 goto out;
1234 }
1235
1236out:
1237 return ret_val;
1238}
1239
1240/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001241 * igb_valid_led_default - Verify a valid default LED config
Auke Kok9d5c8242008-01-24 02:22:38 -08001242 * @hw: pointer to the HW structure
1243 * @data: pointer to the NVM (EEPROM)
1244 *
1245 * Read the EEPROM for the current default LED configuration. If the
1246 * LED configuration is not valid, set to a valid LED configuration.
1247 **/
1248static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data)
1249{
1250 s32 ret_val;
1251
Alexander Duyck312c75a2009-02-06 23:17:47 +00001252 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001253 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001254 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001255 goto out;
1256 }
1257
Alexander Duyck099e1cb2009-07-23 18:07:40 +00001258 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
Carolyn Wyborny9005df32014-04-11 01:45:34 +00001259 switch (hw->phy.media_type) {
Alexander Duyck099e1cb2009-07-23 18:07:40 +00001260 case e1000_media_type_internal_serdes:
1261 *data = ID_LED_DEFAULT_82575_SERDES;
1262 break;
1263 case e1000_media_type_copper:
1264 default:
1265 *data = ID_LED_DEFAULT;
1266 break;
1267 }
1268 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001269out:
1270 return ret_val;
1271}
1272
1273/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001274 * igb_id_led_init -
Auke Kok9d5c8242008-01-24 02:22:38 -08001275 * @hw: pointer to the HW structure
1276 *
1277 **/
1278s32 igb_id_led_init(struct e1000_hw *hw)
1279{
1280 struct e1000_mac_info *mac = &hw->mac;
1281 s32 ret_val;
1282 const u32 ledctl_mask = 0x000000FF;
1283 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
1284 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
1285 u16 data, i, temp;
1286 const u16 led_mask = 0x0F;
1287
Akeem G. Abodunrin6f8b9162013-05-01 05:44:45 +00001288 /* i210 and i211 devices have different LED mechanism */
1289 if ((hw->mac.type == e1000_i210) ||
1290 (hw->mac.type == e1000_i211))
1291 ret_val = igb_valid_led_default_i210(hw, &data);
1292 else
1293 ret_val = igb_valid_led_default(hw, &data);
1294
Auke Kok9d5c8242008-01-24 02:22:38 -08001295 if (ret_val)
1296 goto out;
1297
1298 mac->ledctl_default = rd32(E1000_LEDCTL);
1299 mac->ledctl_mode1 = mac->ledctl_default;
1300 mac->ledctl_mode2 = mac->ledctl_default;
1301
1302 for (i = 0; i < 4; i++) {
1303 temp = (data >> (i << 2)) & led_mask;
1304 switch (temp) {
1305 case ID_LED_ON1_DEF2:
1306 case ID_LED_ON1_ON2:
1307 case ID_LED_ON1_OFF2:
1308 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1309 mac->ledctl_mode1 |= ledctl_on << (i << 3);
1310 break;
1311 case ID_LED_OFF1_DEF2:
1312 case ID_LED_OFF1_ON2:
1313 case ID_LED_OFF1_OFF2:
1314 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1315 mac->ledctl_mode1 |= ledctl_off << (i << 3);
1316 break;
1317 default:
1318 /* Do nothing */
1319 break;
1320 }
1321 switch (temp) {
1322 case ID_LED_DEF1_ON2:
1323 case ID_LED_ON1_ON2:
1324 case ID_LED_OFF1_ON2:
1325 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1326 mac->ledctl_mode2 |= ledctl_on << (i << 3);
1327 break;
1328 case ID_LED_DEF1_OFF2:
1329 case ID_LED_ON1_OFF2:
1330 case ID_LED_OFF1_OFF2:
1331 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1332 mac->ledctl_mode2 |= ledctl_off << (i << 3);
1333 break;
1334 default:
1335 /* Do nothing */
1336 break;
1337 }
1338 }
1339
1340out:
1341 return ret_val;
1342}
1343
1344/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001345 * igb_cleanup_led - Set LED config to default operation
Auke Kok9d5c8242008-01-24 02:22:38 -08001346 * @hw: pointer to the HW structure
1347 *
1348 * Remove the current LED configuration and set the LED configuration
1349 * to the default value, saved from the EEPROM.
1350 **/
1351s32 igb_cleanup_led(struct e1000_hw *hw)
1352{
1353 wr32(E1000_LEDCTL, hw->mac.ledctl_default);
1354 return 0;
1355}
1356
1357/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001358 * igb_blink_led - Blink LED
Auke Kok9d5c8242008-01-24 02:22:38 -08001359 * @hw: pointer to the HW structure
1360 *
1361 * Blink the led's which are set to be on.
1362 **/
1363s32 igb_blink_led(struct e1000_hw *hw)
1364{
1365 u32 ledctl_blink = 0;
1366 u32 i;
1367
Akeem G. Abodunrincf7ed222013-03-29 08:22:25 +00001368 if (hw->phy.media_type == e1000_media_type_fiber) {
1369 /* always blink LED0 for PCI-E fiber */
1370 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
1371 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
1372 } else {
1373 /* Set the blink bit for each LED that's "on" (0x0E)
1374 * (or "off" if inverted) in ledctl_mode2. The blink
1375 * logic in hardware only works when mode is set to "on"
1376 * so it must be changed accordingly when the mode is
1377 * "off" and inverted.
1378 */
1379 ledctl_blink = hw->mac.ledctl_mode2;
1380 for (i = 0; i < 32; i += 8) {
1381 u32 mode = (hw->mac.ledctl_mode2 >> i) &
1382 E1000_LEDCTL_LED0_MODE_MASK;
1383 u32 led_default = hw->mac.ledctl_default >> i;
1384
1385 if ((!(led_default & E1000_LEDCTL_LED0_IVRT) &&
1386 (mode == E1000_LEDCTL_MODE_LED_ON)) ||
1387 ((led_default & E1000_LEDCTL_LED0_IVRT) &&
1388 (mode == E1000_LEDCTL_MODE_LED_OFF))) {
1389 ledctl_blink &=
1390 ~(E1000_LEDCTL_LED0_MODE_MASK << i);
1391 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK |
1392 E1000_LEDCTL_MODE_LED_ON) << i;
1393 }
1394 }
1395 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001396
1397 wr32(E1000_LEDCTL, ledctl_blink);
1398
1399 return 0;
1400}
1401
1402/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001403 * igb_led_off - Turn LED off
Auke Kok9d5c8242008-01-24 02:22:38 -08001404 * @hw: pointer to the HW structure
1405 *
1406 * Turn LED off.
1407 **/
1408s32 igb_led_off(struct e1000_hw *hw)
1409{
Auke Kok9d5c8242008-01-24 02:22:38 -08001410 switch (hw->phy.media_type) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001411 case e1000_media_type_copper:
1412 wr32(E1000_LEDCTL, hw->mac.ledctl_mode1);
1413 break;
1414 default:
1415 break;
1416 }
1417
1418 return 0;
1419}
1420
1421/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001422 * igb_disable_pcie_master - Disables PCI-express master access
Auke Kok9d5c8242008-01-24 02:22:38 -08001423 * @hw: pointer to the HW structure
1424 *
1425 * Returns 0 (0) if successful, else returns -10
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001426 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
Auke Kok9d5c8242008-01-24 02:22:38 -08001427 * the master requests to be disabled.
1428 *
1429 * Disables PCI-Express master access and verifies there are no pending
1430 * requests.
1431 **/
1432s32 igb_disable_pcie_master(struct e1000_hw *hw)
1433{
1434 u32 ctrl;
1435 s32 timeout = MASTER_DISABLE_TIMEOUT;
1436 s32 ret_val = 0;
1437
1438 if (hw->bus.type != e1000_bus_type_pci_express)
1439 goto out;
1440
1441 ctrl = rd32(E1000_CTRL);
1442 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
1443 wr32(E1000_CTRL, ctrl);
1444
1445 while (timeout) {
1446 if (!(rd32(E1000_STATUS) &
1447 E1000_STATUS_GIO_MASTER_ENABLE))
1448 break;
1449 udelay(100);
1450 timeout--;
1451 }
1452
1453 if (!timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001454 hw_dbg("Master requests are pending.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001455 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
1456 goto out;
1457 }
1458
1459out:
1460 return ret_val;
1461}
1462
1463/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001464 * igb_validate_mdi_setting - Verify MDI/MDIx settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001465 * @hw: pointer to the HW structure
1466 *
1467 * Verify that when not using auto-negotitation that MDI/MDIx is correctly
1468 * set, which is forced to MDI mode only.
1469 **/
1470s32 igb_validate_mdi_setting(struct e1000_hw *hw)
1471{
1472 s32 ret_val = 0;
1473
Matthew Vick9f0b8512012-10-16 07:44:45 +00001474 /* All MDI settings are supported on 82580 and newer. */
1475 if (hw->mac.type >= e1000_82580)
1476 goto out;
1477
Auke Kok9d5c8242008-01-24 02:22:38 -08001478 if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
Auke Kok652fff32008-06-27 11:00:18 -07001479 hw_dbg("Invalid MDI setting detected\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001480 hw->phy.mdix = 1;
1481 ret_val = -E1000_ERR_CONFIG;
1482 goto out;
1483 }
1484
1485out:
1486 return ret_val;
1487}
1488
1489/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001490 * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register
Auke Kok9d5c8242008-01-24 02:22:38 -08001491 * @hw: pointer to the HW structure
1492 * @reg: 32bit register offset such as E1000_SCTL
1493 * @offset: register offset to write to
1494 * @data: data to write at register offset
1495 *
1496 * Writes an address/data control type register. There are several of these
1497 * and they all have the format address << 8 | data and bit 31 is polled for
1498 * completion.
1499 **/
1500s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg,
1501 u32 offset, u8 data)
1502{
1503 u32 i, regvalue = 0;
1504 s32 ret_val = 0;
1505
1506 /* Set up the address and data */
1507 regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
1508 wr32(reg, regvalue);
1509
1510 /* Poll the ready bit to see if the MDI read completed */
1511 for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
1512 udelay(5);
1513 regvalue = rd32(reg);
1514 if (regvalue & E1000_GEN_CTL_READY)
1515 break;
1516 }
1517 if (!(regvalue & E1000_GEN_CTL_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -07001518 hw_dbg("Reg %08x did not indicate ready\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001519 ret_val = -E1000_ERR_PHY;
1520 goto out;
1521 }
1522
1523out:
1524 return ret_val;
1525}
1526
1527/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001528 * igb_enable_mng_pass_thru - Enable processing of ARP's
Auke Kok9d5c8242008-01-24 02:22:38 -08001529 * @hw: pointer to the HW structure
1530 *
Alexander Duycke017b602010-03-25 17:15:06 +00001531 * Verifies the hardware needs to leave interface enabled so that frames can
1532 * be directed to and from the management interface.
Auke Kok9d5c8242008-01-24 02:22:38 -08001533 **/
1534bool igb_enable_mng_pass_thru(struct e1000_hw *hw)
1535{
1536 u32 manc;
1537 u32 fwsm, factps;
1538 bool ret_val = false;
1539
1540 if (!hw->mac.asf_firmware_present)
1541 goto out;
1542
1543 manc = rd32(E1000_MANC);
1544
Alexander Duycke017b602010-03-25 17:15:06 +00001545 if (!(manc & E1000_MANC_RCV_TCO_EN))
Auke Kok9d5c8242008-01-24 02:22:38 -08001546 goto out;
1547
1548 if (hw->mac.arc_subsystem_valid) {
1549 fwsm = rd32(E1000_FWSM);
1550 factps = rd32(E1000_FACTPS);
1551
1552 if (!(factps & E1000_FACTPS_MNGCG) &&
1553 ((fwsm & E1000_FWSM_MODE_MASK) ==
1554 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
1555 ret_val = true;
1556 goto out;
1557 }
1558 } else {
1559 if ((manc & E1000_MANC_SMBUS_EN) &&
1560 !(manc & E1000_MANC_ASF_EN)) {
1561 ret_val = true;
1562 goto out;
1563 }
1564 }
1565
1566out:
1567 return ret_val;
1568}