blob: 1e0c404db81a263861c2b0e683ec5b702b305df8 [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Carolyn Wyborny74cfb2e2014-02-25 17:58:57 -08004 Copyright(c) 2007-2014 Intel Corporation.
Auke Kok9d5c8242008-01-24 02:22:38 -08005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
Carolyn Wyborny74cfb2e2014-02-25 17:58:57 -080016 this program; if not, see <http://www.gnu.org/licenses/>.
Auke Kok9d5c8242008-01-24 02:22:38 -080017
18 The full GNU General Public License is included in this distribution in
19 the file called "COPYING".
20
21 Contact Information:
22 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24
25*******************************************************************************/
26
27#include <linux/if_ether.h>
28#include <linux/delay.h>
29#include <linux/pci.h>
30#include <linux/netdevice.h>
Tobias Klauser58d14d42011-07-03 23:50:15 +000031#include <linux/etherdevice.h>
Auke Kok9d5c8242008-01-24 02:22:38 -080032
33#include "e1000_mac.h"
34
35#include "igb.h"
36
37static s32 igb_set_default_fc(struct e1000_hw *hw);
38static s32 igb_set_fc_watermarks(struct e1000_hw *hw);
Auke Kok9d5c8242008-01-24 02:22:38 -080039
Auke Kok9d5c8242008-01-24 02:22:38 -080040/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070041 * igb_get_bus_info_pcie - Get PCIe bus information
Auke Kok9d5c8242008-01-24 02:22:38 -080042 * @hw: pointer to the HW structure
43 *
44 * Determines and stores the system bus information for a particular
45 * network interface. The following bus information is determined and stored:
46 * bus speed, bus width, type (PCIe), and PCIe function.
47 **/
48s32 igb_get_bus_info_pcie(struct e1000_hw *hw)
49{
50 struct e1000_bus_info *bus = &hw->bus;
51 s32 ret_val;
Alexander Duyck5e8427e2008-12-10 01:09:53 -080052 u32 reg;
53 u16 pcie_link_status;
Auke Kok9d5c8242008-01-24 02:22:38 -080054
55 bus->type = e1000_bus_type_pci_express;
Auke Kok9d5c8242008-01-24 02:22:38 -080056
57 ret_val = igb_read_pcie_cap_reg(hw,
Alexander Duyckff846f52010-04-27 01:02:40 +000058 PCI_EXP_LNKSTA,
59 &pcie_link_status);
60 if (ret_val) {
Auke Kok9d5c8242008-01-24 02:22:38 -080061 bus->width = e1000_bus_width_unknown;
Alexander Duyckff846f52010-04-27 01:02:40 +000062 bus->speed = e1000_bus_speed_unknown;
63 } else {
64 switch (pcie_link_status & PCI_EXP_LNKSTA_CLS) {
65 case PCI_EXP_LNKSTA_CLS_2_5GB:
66 bus->speed = e1000_bus_speed_2500;
67 break;
68 case PCI_EXP_LNKSTA_CLS_5_0GB:
69 bus->speed = e1000_bus_speed_5000;
70 break;
71 default:
72 bus->speed = e1000_bus_speed_unknown;
73 break;
74 }
75
Auke Kok9d5c8242008-01-24 02:22:38 -080076 bus->width = (enum e1000_bus_width)((pcie_link_status &
Alexander Duyckff846f52010-04-27 01:02:40 +000077 PCI_EXP_LNKSTA_NLW) >>
78 PCI_EXP_LNKSTA_NLW_SHIFT);
79 }
Auke Kok9d5c8242008-01-24 02:22:38 -080080
Alexander Duyck5e8427e2008-12-10 01:09:53 -080081 reg = rd32(E1000_STATUS);
82 bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
Auke Kok9d5c8242008-01-24 02:22:38 -080083
84 return 0;
85}
86
87/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070088 * igb_clear_vfta - Clear VLAN filter table
Auke Kok9d5c8242008-01-24 02:22:38 -080089 * @hw: pointer to the HW structure
90 *
91 * Clears the register array which contains the VLAN filter table by
92 * setting all the values to 0.
93 **/
94void igb_clear_vfta(struct e1000_hw *hw)
95{
96 u32 offset;
97
98 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
99 array_wr32(E1000_VFTA, offset, 0);
100 wrfl();
101 }
102}
103
104/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700105 * igb_write_vfta - Write value to VLAN filter table
Auke Kok9d5c8242008-01-24 02:22:38 -0800106 * @hw: pointer to the HW structure
107 * @offset: register offset in VLAN filter table
108 * @value: register value written to VLAN filter table
109 *
110 * Writes value at the given offset in the register array which stores
111 * the VLAN filter table.
112 **/
Alexander Duyckff6f63d2009-04-09 22:49:02 +0000113static void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Auke Kok9d5c8242008-01-24 02:22:38 -0800114{
115 array_wr32(E1000_VFTA, offset, value);
116 wrfl();
117}
118
Carolyn Wyborny1128c752011-10-14 00:13:49 +0000119/* Due to a hw errata, if the host tries to configure the VFTA register
120 * while performing queries from the BMC or DMA, then the VFTA in some
121 * cases won't be written.
122 */
123
124/**
125 * igb_clear_vfta_i350 - Clear VLAN filter table
126 * @hw: pointer to the HW structure
127 *
128 * Clears the register array which contains the VLAN filter table by
129 * setting all the values to 0.
130 **/
131void igb_clear_vfta_i350(struct e1000_hw *hw)
132{
133 u32 offset;
134 int i;
135
136 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
137 for (i = 0; i < 10; i++)
138 array_wr32(E1000_VFTA, offset, 0);
139
140 wrfl();
141 }
142}
143
144/**
145 * igb_write_vfta_i350 - Write value to VLAN filter table
146 * @hw: pointer to the HW structure
147 * @offset: register offset in VLAN filter table
148 * @value: register value written to VLAN filter table
149 *
150 * Writes value at the given offset in the register array which stores
151 * the VLAN filter table.
152 **/
Stephen Hemmingerc50b52a2012-01-18 22:13:26 +0000153static void igb_write_vfta_i350(struct e1000_hw *hw, u32 offset, u32 value)
Carolyn Wyborny1128c752011-10-14 00:13:49 +0000154{
155 int i;
156
157 for (i = 0; i < 10; i++)
158 array_wr32(E1000_VFTA, offset, value);
159
160 wrfl();
161}
162
Auke Kok9d5c8242008-01-24 02:22:38 -0800163/**
Alexander Duyck5ac16652009-07-23 18:09:12 +0000164 * igb_init_rx_addrs - Initialize receive address's
165 * @hw: pointer to the HW structure
166 * @rar_count: receive address registers
167 *
168 * Setups the receive address registers by setting the base receive address
169 * register to the devices MAC address and clearing all the other receive
170 * address registers to 0.
171 **/
172void igb_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
173{
174 u32 i;
175 u8 mac_addr[ETH_ALEN] = {0};
176
177 /* Setup the receive address */
178 hw_dbg("Programming MAC Address into RAR[0]\n");
179
180 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
181
182 /* Zero out the other (rar_entry_count - 1) receive addresses */
183 hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
184 for (i = 1; i < rar_count; i++)
185 hw->mac.ops.rar_set(hw, mac_addr, i);
186}
187
188/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800189 * igb_vfta_set - enable or disable vlan in VLAN filter table
190 * @hw: pointer to the HW structure
191 * @vid: VLAN id to add or remove
192 * @add: if true add filter, if false remove
193 *
194 * Sets or clears a bit in the VLAN filter table array based on VLAN id
195 * and if we are adding or removing the filter
196 **/
Alexander Duyckcad6d052009-03-13 20:41:37 +0000197s32 igb_vfta_set(struct e1000_hw *hw, u32 vid, bool add)
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800198{
199 u32 index = (vid >> E1000_VFTA_ENTRY_SHIFT) & E1000_VFTA_ENTRY_MASK;
Alexander Duyck75f4f382009-03-13 20:41:55 +0000200 u32 mask = 1 << (vid & E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
Carolyn Wyborny1128c752011-10-14 00:13:49 +0000201 u32 vfta;
202 struct igb_adapter *adapter = hw->back;
Alexander Duyckcad6d052009-03-13 20:41:37 +0000203 s32 ret_val = 0;
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800204
Carolyn Wyborny1128c752011-10-14 00:13:49 +0000205 vfta = adapter->shadow_vfta[index];
206
Alexander Duyckcad6d052009-03-13 20:41:37 +0000207 /* bit was set/cleared before we started */
208 if ((!!(vfta & mask)) == add) {
209 ret_val = -E1000_ERR_CONFIG;
210 } else {
211 if (add)
212 vfta |= mask;
213 else
214 vfta &= ~mask;
215 }
Carolyn Wybornyceb5f132013-04-18 22:21:30 +0000216 if ((hw->mac.type == e1000_i350) || (hw->mac.type == e1000_i354))
Carolyn Wyborny1128c752011-10-14 00:13:49 +0000217 igb_write_vfta_i350(hw, index, vfta);
218 else
219 igb_write_vfta(hw, index, vfta);
220 adapter->shadow_vfta[index] = vfta;
Alexander Duyckcad6d052009-03-13 20:41:37 +0000221
222 return ret_val;
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800223}
224
225/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700226 * igb_check_alt_mac_addr - Check for alternate MAC addr
Auke Kok9d5c8242008-01-24 02:22:38 -0800227 * @hw: pointer to the HW structure
228 *
229 * Checks the nvm for an alternate MAC address. An alternate MAC address
230 * can be setup by pre-boot software and must be treated like a permanent
231 * address and must override the actual permanent MAC address. If an
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000232 * alternate MAC address is found it is saved in the hw struct and
233 * programmed into RAR0 and the function returns success, otherwise the
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300234 * function returns an error.
Auke Kok9d5c8242008-01-24 02:22:38 -0800235 **/
236s32 igb_check_alt_mac_addr(struct e1000_hw *hw)
237{
238 u32 i;
239 s32 ret_val = 0;
240 u16 offset, nvm_alt_mac_addr_offset, nvm_data;
241 u8 alt_mac_addr[ETH_ALEN];
242
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000243 /* Alternate MAC address is handled by the option ROM for 82580
Carolyn Wyborny65189d22011-10-13 17:28:39 +0000244 * and newer. SW support not required.
245 */
246 if (hw->mac.type >= e1000_82580)
247 goto out;
248
Alexander Duyck312c75a2009-02-06 23:17:47 +0000249 ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800250 &nvm_alt_mac_addr_offset);
251 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700252 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800253 goto out;
254 }
255
Akeem G. Abodunrin6538ee62011-09-02 23:08:55 +0000256 if ((nvm_alt_mac_addr_offset == 0xFFFF) ||
257 (nvm_alt_mac_addr_offset == 0x0000))
Alexander Duyck22896632009-10-05 06:34:25 +0000258 /* There is no Alternate MAC Address */
Auke Kok9d5c8242008-01-24 02:22:38 -0800259 goto out;
Auke Kok9d5c8242008-01-24 02:22:38 -0800260
261 if (hw->bus.func == E1000_FUNC_1)
Alexander Duyck22896632009-10-05 06:34:25 +0000262 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
Akeem G. Abodunrin45b58462011-09-02 23:09:30 +0000263 if (hw->bus.func == E1000_FUNC_2)
264 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN2;
265
266 if (hw->bus.func == E1000_FUNC_3)
267 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN3;
Auke Kok9d5c8242008-01-24 02:22:38 -0800268 for (i = 0; i < ETH_ALEN; i += 2) {
269 offset = nvm_alt_mac_addr_offset + (i >> 1);
Alexander Duyck312c75a2009-02-06 23:17:47 +0000270 ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800271 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700272 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800273 goto out;
274 }
275
276 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
277 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
278 }
279
280 /* if multicast bit is set, the alternate address will not be used */
Tobias Klauser58d14d42011-07-03 23:50:15 +0000281 if (is_multicast_ether_addr(alt_mac_addr)) {
Alexander Duyck22896632009-10-05 06:34:25 +0000282 hw_dbg("Ignoring Alternate Mac Address with MC bit set\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800283 goto out;
284 }
285
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000286 /* We have a valid alternate MAC address, and we want to treat it the
Alexander Duyck22896632009-10-05 06:34:25 +0000287 * same as the normal permanent MAC address stored by the HW into the
288 * RAR. Do this by mapping this address into RAR0.
289 */
290 hw->mac.ops.rar_set(hw, alt_mac_addr, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800291
292out:
293 return ret_val;
294}
295
296/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700297 * igb_rar_set - Set receive address register
Auke Kok9d5c8242008-01-24 02:22:38 -0800298 * @hw: pointer to the HW structure
299 * @addr: pointer to the receive address
300 * @index: receive address array register
301 *
302 * Sets the receive address array register at index to the address passed
303 * in by addr.
304 **/
305void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
306{
307 u32 rar_low, rar_high;
308
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000309 /* HW expects these in little endian so we reverse the byte order
Auke Kok9d5c8242008-01-24 02:22:38 -0800310 * from network order (big endian) to little endian
311 */
312 rar_low = ((u32) addr[0] |
313 ((u32) addr[1] << 8) |
314 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
315
316 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
317
Alexander Duyck86757372009-02-06 23:21:51 +0000318 /* If MAC address zero, no need to set the AV bit */
319 if (rar_low || rar_high)
Auke Kok9d5c8242008-01-24 02:22:38 -0800320 rar_high |= E1000_RAH_AV;
321
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000322 /* Some bridges will combine consecutive 32-bit writes into
Alexander Duyck6deac6f2009-10-05 06:36:01 +0000323 * a single burst write, which will malfunction on some parts.
324 * The flushes avoid this.
325 */
Alexander Duyck5e8427e2008-12-10 01:09:53 -0800326 wr32(E1000_RAL(index), rar_low);
Alexander Duyck6deac6f2009-10-05 06:36:01 +0000327 wrfl();
Alexander Duyck5e8427e2008-12-10 01:09:53 -0800328 wr32(E1000_RAH(index), rar_high);
Alexander Duyck6deac6f2009-10-05 06:36:01 +0000329 wrfl();
Auke Kok9d5c8242008-01-24 02:22:38 -0800330}
331
332/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700333 * igb_mta_set - Set multicast filter table address
Auke Kok9d5c8242008-01-24 02:22:38 -0800334 * @hw: pointer to the HW structure
335 * @hash_value: determines the MTA register and bit to set
336 *
337 * The multicast table address is a register array of 32-bit registers.
338 * The hash_value is used to determine what register the bit is in, the
339 * current value is read, the new bit is OR'd in and the new value is
340 * written back into the register.
341 **/
Alexander Duyck549bdd82008-08-04 15:00:06 -0700342void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
Auke Kok9d5c8242008-01-24 02:22:38 -0800343{
344 u32 hash_bit, hash_reg, mta;
345
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000346 /* The MTA is a register array of 32-bit registers. It is
Auke Kok9d5c8242008-01-24 02:22:38 -0800347 * treated like an array of (32*mta_reg_count) bits. We want to
348 * set bit BitArray[hash_value]. So we figure out what register
349 * the bit is in, read it, OR in the new bit, then write
350 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
351 * mask to bits 31:5 of the hash value which gives us the
352 * register we're modifying. The hash bit within that register
353 * is determined by the lower 5 bits of the hash value.
354 */
355 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
356 hash_bit = hash_value & 0x1F;
357
358 mta = array_rd32(E1000_MTA, hash_reg);
359
360 mta |= (1 << hash_bit);
361
362 array_wr32(E1000_MTA, hash_reg, mta);
363 wrfl();
364}
365
366/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700367 * igb_hash_mc_addr - Generate a multicast hash value
Auke Kok9d5c8242008-01-24 02:22:38 -0800368 * @hw: pointer to the HW structure
369 * @mc_addr: pointer to a multicast address
370 *
371 * Generates a multicast address hash value which is used to determine
372 * the multicast filter table array address and new table value. See
373 * igb_mta_set()
374 **/
Alexander Duyck44c852e2009-09-17 14:52:29 +0000375static u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Auke Kok9d5c8242008-01-24 02:22:38 -0800376{
377 u32 hash_value, hash_mask;
378 u8 bit_shift = 0;
379
380 /* Register count multiplied by bits per register */
381 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
382
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000383 /* For a mc_filter_type of 0, bit_shift is the number of left-shifts
Auke Kok9d5c8242008-01-24 02:22:38 -0800384 * where 0xFF would still fall within the hash mask.
385 */
386 while (hash_mask >> bit_shift != 0xFF)
387 bit_shift++;
388
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000389 /* The portion of the address that is used for the hash table
Auke Kok9d5c8242008-01-24 02:22:38 -0800390 * is determined by the mc_filter_type setting.
391 * The algorithm is such that there is a total of 8 bits of shifting.
392 * The bit_shift for a mc_filter_type of 0 represents the number of
393 * left-shifts where the MSB of mc_addr[5] would still fall within
394 * the hash_mask. Case 0 does this exactly. Since there are a total
395 * of 8 bits of shifting, then mc_addr[4] will shift right the
396 * remaining number of bits. Thus 8 - bit_shift. The rest of the
397 * cases are a variation of this algorithm...essentially raising the
398 * number of bits to shift mc_addr[5] left, while still keeping the
399 * 8-bit shifting total.
400 *
401 * For example, given the following Destination MAC Address and an
402 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
403 * we can see that the bit_shift for case 0 is 4. These are the hash
404 * values resulting from each mc_filter_type...
405 * [0] [1] [2] [3] [4] [5]
406 * 01 AA 00 12 34 56
407 * LSB MSB
408 *
409 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
410 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
411 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
412 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
413 */
414 switch (hw->mac.mc_filter_type) {
415 default:
416 case 0:
417 break;
418 case 1:
419 bit_shift += 1;
420 break;
421 case 2:
422 bit_shift += 2;
423 break;
424 case 3:
425 bit_shift += 4;
426 break;
427 }
428
429 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
430 (((u16) mc_addr[5]) << bit_shift)));
431
432 return hash_value;
433}
434
435/**
Alexander Duyck44c852e2009-09-17 14:52:29 +0000436 * igb_update_mc_addr_list - Update Multicast addresses
437 * @hw: pointer to the HW structure
438 * @mc_addr_list: array of multicast addresses to program
439 * @mc_addr_count: number of multicast addresses to program
440 *
441 * Updates entire Multicast Table Array.
442 * The caller must have a packed mc_addr_list of multicast addresses.
443 **/
444void igb_update_mc_addr_list(struct e1000_hw *hw,
445 u8 *mc_addr_list, u32 mc_addr_count)
446{
447 u32 hash_value, hash_bit, hash_reg;
448 int i;
449
450 /* clear mta_shadow */
451 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
452
453 /* update mta_shadow from mc_addr_list */
454 for (i = 0; (u32) i < mc_addr_count; i++) {
455 hash_value = igb_hash_mc_addr(hw, mc_addr_list);
456
457 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
458 hash_bit = hash_value & 0x1F;
459
460 hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
461 mc_addr_list += (ETH_ALEN);
462 }
463
464 /* replace the entire MTA table */
465 for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
466 array_wr32(E1000_MTA, i, hw->mac.mta_shadow[i]);
467 wrfl();
468}
469
470/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700471 * igb_clear_hw_cntrs_base - Clear base hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -0800472 * @hw: pointer to the HW structure
473 *
474 * Clears the base hardware counters by reading the counter registers.
475 **/
476void igb_clear_hw_cntrs_base(struct e1000_hw *hw)
477{
Alexander Duyckcc9073b2009-10-05 06:31:25 +0000478 rd32(E1000_CRCERRS);
479 rd32(E1000_SYMERRS);
480 rd32(E1000_MPC);
481 rd32(E1000_SCC);
482 rd32(E1000_ECOL);
483 rd32(E1000_MCC);
484 rd32(E1000_LATECOL);
485 rd32(E1000_COLC);
486 rd32(E1000_DC);
487 rd32(E1000_SEC);
488 rd32(E1000_RLEC);
489 rd32(E1000_XONRXC);
490 rd32(E1000_XONTXC);
491 rd32(E1000_XOFFRXC);
492 rd32(E1000_XOFFTXC);
493 rd32(E1000_FCRUC);
494 rd32(E1000_GPRC);
495 rd32(E1000_BPRC);
496 rd32(E1000_MPRC);
497 rd32(E1000_GPTC);
498 rd32(E1000_GORCL);
499 rd32(E1000_GORCH);
500 rd32(E1000_GOTCL);
501 rd32(E1000_GOTCH);
502 rd32(E1000_RNBC);
503 rd32(E1000_RUC);
504 rd32(E1000_RFC);
505 rd32(E1000_ROC);
506 rd32(E1000_RJC);
507 rd32(E1000_TORL);
508 rd32(E1000_TORH);
509 rd32(E1000_TOTL);
510 rd32(E1000_TOTH);
511 rd32(E1000_TPR);
512 rd32(E1000_TPT);
513 rd32(E1000_MPTC);
514 rd32(E1000_BPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -0800515}
516
517/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700518 * igb_check_for_copper_link - Check for link (Copper)
Auke Kok9d5c8242008-01-24 02:22:38 -0800519 * @hw: pointer to the HW structure
520 *
521 * Checks to see of the link status of the hardware has changed. If a
522 * change in link status has been detected, then we read the PHY registers
523 * to get the current speed/duplex if link exists.
524 **/
525s32 igb_check_for_copper_link(struct e1000_hw *hw)
526{
527 struct e1000_mac_info *mac = &hw->mac;
528 s32 ret_val;
529 bool link;
530
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000531 /* We only want to go out to the PHY registers to see if Auto-Neg
Auke Kok9d5c8242008-01-24 02:22:38 -0800532 * has completed and/or if our link status has changed. The
533 * get_link_status flag is set upon receiving a Link Status
534 * Change or Rx Sequence Error interrupt.
535 */
536 if (!mac->get_link_status) {
537 ret_val = 0;
538 goto out;
539 }
540
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000541 /* First we want to see if the MII Status Register reports
Auke Kok9d5c8242008-01-24 02:22:38 -0800542 * link. If so, then we want to get the current speed/duplex
543 * of the PHY.
544 */
545 ret_val = igb_phy_has_link(hw, 1, 0, &link);
546 if (ret_val)
547 goto out;
548
549 if (!link)
550 goto out; /* No link detected */
551
552 mac->get_link_status = false;
553
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000554 /* Check if there was DownShift, must be checked
Auke Kok9d5c8242008-01-24 02:22:38 -0800555 * immediately after link-up
556 */
557 igb_check_downshift(hw);
558
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000559 /* If we are forcing speed/duplex, then we simply return since
Auke Kok9d5c8242008-01-24 02:22:38 -0800560 * we have already determined whether we have link or not.
561 */
562 if (!mac->autoneg) {
563 ret_val = -E1000_ERR_CONFIG;
564 goto out;
565 }
566
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000567 /* Auto-Neg is enabled. Auto Speed Detection takes care
Auke Kok9d5c8242008-01-24 02:22:38 -0800568 * of MAC speed/duplex configuration. So we only need to
569 * configure Collision Distance in the MAC.
570 */
571 igb_config_collision_dist(hw);
572
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000573 /* Configure Flow Control now that Auto-Neg has completed.
Auke Kok9d5c8242008-01-24 02:22:38 -0800574 * First, we need to restore the desired flow control
575 * settings because we may have had to re-autoneg with a
576 * different link partner.
577 */
578 ret_val = igb_config_fc_after_link_up(hw);
579 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -0700580 hw_dbg("Error configuring flow control\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800581
582out:
583 return ret_val;
584}
585
586/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700587 * igb_setup_link - Setup flow control and link settings
Auke Kok9d5c8242008-01-24 02:22:38 -0800588 * @hw: pointer to the HW structure
589 *
590 * Determines which flow control settings to use, then configures flow
591 * control. Calls the appropriate media-specific link configuration
592 * function. Assuming the adapter has a valid link partner, a valid link
593 * should be established. Assumes the hardware has previously been reset
594 * and the transmitter and receiver are not enabled.
595 **/
596s32 igb_setup_link(struct e1000_hw *hw)
597{
598 s32 ret_val = 0;
599
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000600 /* In the case of the phy reset being blocked, we already have a link.
Auke Kok9d5c8242008-01-24 02:22:38 -0800601 * We do not need to set it up again.
602 */
603 if (igb_check_reset_block(hw))
604 goto out;
605
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000606 /* If requested flow control is set to default, set flow control
Alexander Duyck0cce1192009-07-23 18:10:24 +0000607 * based on the EEPROM flow control settings.
608 */
609 if (hw->fc.requested_mode == e1000_fc_default) {
610 ret_val = igb_set_default_fc(hw);
611 if (ret_val)
612 goto out;
613 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800614
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000615 /* We want to save off the original Flow Control configuration just
Auke Kok9d5c8242008-01-24 02:22:38 -0800616 * in case we get disconnected and then reconnected into a different
617 * hub or switch with different Flow Control capabilities.
618 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000619 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kok9d5c8242008-01-24 02:22:38 -0800620
Alexander Duyck0cce1192009-07-23 18:10:24 +0000621 hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
Auke Kok9d5c8242008-01-24 02:22:38 -0800622
623 /* Call the necessary media_type subroutine to configure the link. */
624 ret_val = hw->mac.ops.setup_physical_interface(hw);
625 if (ret_val)
626 goto out;
627
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000628 /* Initialize the flow control address, type, and PAUSE timer
Auke Kok9d5c8242008-01-24 02:22:38 -0800629 * registers to their default values. This is done even if flow
630 * control is disabled, because it does not hurt anything to
631 * initialize these registers.
632 */
Auke Kok652fff32008-06-27 11:00:18 -0700633 hw_dbg("Initializing the Flow Control address, type and timer regs\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800634 wr32(E1000_FCT, FLOW_CONTROL_TYPE);
635 wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
636 wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
637
638 wr32(E1000_FCTTV, hw->fc.pause_time);
639
640 ret_val = igb_set_fc_watermarks(hw);
641
642out:
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000643
Auke Kok9d5c8242008-01-24 02:22:38 -0800644 return ret_val;
645}
646
647/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700648 * igb_config_collision_dist - Configure collision distance
Auke Kok9d5c8242008-01-24 02:22:38 -0800649 * @hw: pointer to the HW structure
650 *
651 * Configures the collision distance to the default value and is used
652 * during link setup. Currently no func pointer exists and all
653 * implementations are handled in the generic version of this function.
654 **/
655void igb_config_collision_dist(struct e1000_hw *hw)
656{
657 u32 tctl;
658
659 tctl = rd32(E1000_TCTL);
660
661 tctl &= ~E1000_TCTL_COLD;
662 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
663
664 wr32(E1000_TCTL, tctl);
665 wrfl();
666}
667
668/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700669 * igb_set_fc_watermarks - Set flow control high/low watermarks
Auke Kok9d5c8242008-01-24 02:22:38 -0800670 * @hw: pointer to the HW structure
671 *
672 * Sets the flow control high/low threshold (watermark) registers. If
673 * flow control XON frame transmission is enabled, then set XON frame
674 * tansmission as well.
675 **/
676static s32 igb_set_fc_watermarks(struct e1000_hw *hw)
677{
678 s32 ret_val = 0;
679 u32 fcrtl = 0, fcrth = 0;
680
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000681 /* Set the flow control receive threshold registers. Normally,
Auke Kok9d5c8242008-01-24 02:22:38 -0800682 * these registers will be set to a default threshold that may be
683 * adjusted later by the driver's runtime code. However, if the
684 * ability to transmit pause frames is not enabled, then these
685 * registers will be set to 0.
686 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000687 if (hw->fc.current_mode & e1000_fc_tx_pause) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000688 /* We need to set up the Receive Threshold high and low water
Auke Kok9d5c8242008-01-24 02:22:38 -0800689 * marks as well as (optionally) enabling the transmission of
690 * XON frames.
691 */
692 fcrtl = hw->fc.low_water;
693 if (hw->fc.send_xon)
694 fcrtl |= E1000_FCRTL_XONE;
695
696 fcrth = hw->fc.high_water;
697 }
698 wr32(E1000_FCRTL, fcrtl);
699 wr32(E1000_FCRTH, fcrth);
700
701 return ret_val;
702}
703
704/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700705 * igb_set_default_fc - Set flow control default values
Auke Kok9d5c8242008-01-24 02:22:38 -0800706 * @hw: pointer to the HW structure
707 *
708 * Read the EEPROM for the default values for flow control and store the
709 * values.
710 **/
711static s32 igb_set_default_fc(struct e1000_hw *hw)
712{
713 s32 ret_val = 0;
Fujinaka, Toddc7cb0202013-09-10 11:57:17 -0700714 u16 lan_offset;
Auke Kok9d5c8242008-01-24 02:22:38 -0800715 u16 nvm_data;
716
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000717 /* Read and store word 0x0F of the EEPROM. This word contains bits
Auke Kok9d5c8242008-01-24 02:22:38 -0800718 * that determine the hardware's default PAUSE (flow control) mode,
719 * a bit that determines whether the HW defaults to enabling or
720 * disabling auto-negotiation, and the direction of the
721 * SW defined pins. If there is no SW over-ride of the flow
722 * control setting, then the variable hw->fc will
723 * be initialized based on a value in the EEPROM.
724 */
Fujinaka, Toddc7cb0202013-09-10 11:57:17 -0700725 if (hw->mac.type == e1000_i350) {
726 lan_offset = NVM_82580_LAN_FUNC_OFFSET(hw->bus.func);
727 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG
728 + lan_offset, 1, &nvm_data);
729 } else {
730 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG,
731 1, &nvm_data);
732 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800733
734 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700735 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800736 goto out;
737 }
738
739 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
Alexander Duyck0cce1192009-07-23 18:10:24 +0000740 hw->fc.requested_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -0800741 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
742 NVM_WORD0F_ASM_DIR)
Alexander Duyck0cce1192009-07-23 18:10:24 +0000743 hw->fc.requested_mode = e1000_fc_tx_pause;
Auke Kok9d5c8242008-01-24 02:22:38 -0800744 else
Alexander Duyck0cce1192009-07-23 18:10:24 +0000745 hw->fc.requested_mode = e1000_fc_full;
Auke Kok9d5c8242008-01-24 02:22:38 -0800746
747out:
748 return ret_val;
749}
750
751/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700752 * igb_force_mac_fc - Force the MAC's flow control settings
Auke Kok9d5c8242008-01-24 02:22:38 -0800753 * @hw: pointer to the HW structure
754 *
755 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
756 * device control register to reflect the adapter settings. TFCE and RFCE
757 * need to be explicitly set by software when a copper PHY is used because
758 * autonegotiation is managed by the PHY rather than the MAC. Software must
759 * also configure these bits when link is forced on a fiber connection.
760 **/
761s32 igb_force_mac_fc(struct e1000_hw *hw)
762{
763 u32 ctrl;
764 s32 ret_val = 0;
765
766 ctrl = rd32(E1000_CTRL);
767
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000768 /* Because we didn't get link via the internal auto-negotiation
Auke Kok9d5c8242008-01-24 02:22:38 -0800769 * mechanism (we either forced link or we got link via PHY
770 * auto-neg), we have to manually enable/disable transmit an
771 * receive flow control.
772 *
773 * The "Case" statement below enables/disable flow control
Alexander Duyck0cce1192009-07-23 18:10:24 +0000774 * according to the "hw->fc.current_mode" parameter.
Auke Kok9d5c8242008-01-24 02:22:38 -0800775 *
776 * The possible values of the "fc" parameter are:
777 * 0: Flow control is completely disabled
778 * 1: Rx flow control is enabled (we can receive pause
779 * frames but not send pause frames).
780 * 2: Tx flow control is enabled (we can send pause frames
781 * frames but we do not receive pause frames).
782 * 3: Both Rx and TX flow control (symmetric) is enabled.
783 * other: No other values should be possible at this point.
784 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000785 hw_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
Auke Kok9d5c8242008-01-24 02:22:38 -0800786
Alexander Duyck0cce1192009-07-23 18:10:24 +0000787 switch (hw->fc.current_mode) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800788 case e1000_fc_none:
789 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
790 break;
791 case e1000_fc_rx_pause:
792 ctrl &= (~E1000_CTRL_TFCE);
793 ctrl |= E1000_CTRL_RFCE;
794 break;
795 case e1000_fc_tx_pause:
796 ctrl &= (~E1000_CTRL_RFCE);
797 ctrl |= E1000_CTRL_TFCE;
798 break;
799 case e1000_fc_full:
800 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
801 break;
802 default:
Auke Kok652fff32008-06-27 11:00:18 -0700803 hw_dbg("Flow control param set incorrectly\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800804 ret_val = -E1000_ERR_CONFIG;
805 goto out;
806 }
807
808 wr32(E1000_CTRL, ctrl);
809
810out:
811 return ret_val;
812}
813
814/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700815 * igb_config_fc_after_link_up - Configures flow control after link
Auke Kok9d5c8242008-01-24 02:22:38 -0800816 * @hw: pointer to the HW structure
817 *
818 * Checks the status of auto-negotiation after link up to ensure that the
819 * speed and duplex were not forced. If the link needed to be forced, then
820 * flow control needs to be forced also. If auto-negotiation is enabled
821 * and did not fail, then we configure flow control based on our link
822 * partner.
823 **/
824s32 igb_config_fc_after_link_up(struct e1000_hw *hw)
825{
826 struct e1000_mac_info *mac = &hw->mac;
827 s32 ret_val = 0;
Carolyn Wybornydaf56e42012-10-23 12:54:33 +0000828 u32 pcs_status_reg, pcs_adv_reg, pcs_lp_ability_reg, pcs_ctrl_reg;
Auke Kok9d5c8242008-01-24 02:22:38 -0800829 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
830 u16 speed, duplex;
831
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000832 /* Check for the case where we have fiber media and auto-neg failed
Auke Kok9d5c8242008-01-24 02:22:38 -0800833 * so we had to force link. In this case, we need to force the
834 * configuration of the MAC to match the "fc" parameter.
835 */
836 if (mac->autoneg_failed) {
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000837 if (hw->phy.media_type == e1000_media_type_internal_serdes)
Auke Kok9d5c8242008-01-24 02:22:38 -0800838 ret_val = igb_force_mac_fc(hw);
839 } else {
840 if (hw->phy.media_type == e1000_media_type_copper)
841 ret_val = igb_force_mac_fc(hw);
842 }
843
844 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700845 hw_dbg("Error forcing flow control settings\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800846 goto out;
847 }
848
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000849 /* Check for the case where we have copper media and auto-neg is
Auke Kok9d5c8242008-01-24 02:22:38 -0800850 * enabled. In this case, we need to check and see if Auto-Neg
851 * has completed, and if so, how the PHY and link partner has
852 * flow control configured.
853 */
854 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000855 /* Read the MII Status Register and check to see if AutoNeg
Auke Kok9d5c8242008-01-24 02:22:38 -0800856 * has completed. We read this twice because this reg has
857 * some "sticky" (latched) bits.
858 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000859 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
Auke Kok9d5c8242008-01-24 02:22:38 -0800860 &mii_status_reg);
861 if (ret_val)
862 goto out;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000863 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
Auke Kok9d5c8242008-01-24 02:22:38 -0800864 &mii_status_reg);
865 if (ret_val)
866 goto out;
867
868 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
Auke Kok652fff32008-06-27 11:00:18 -0700869 hw_dbg("Copper PHY and Auto Neg "
Auke Kok9d5c8242008-01-24 02:22:38 -0800870 "has not completed.\n");
871 goto out;
872 }
873
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000874 /* The AutoNeg process has completed, so we now need to
Auke Kok9d5c8242008-01-24 02:22:38 -0800875 * read both the Auto Negotiation Advertisement
876 * Register (Address 4) and the Auto_Negotiation Base
877 * Page Ability Register (Address 5) to determine how
878 * flow control was negotiated.
879 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000880 ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
Auke Kok9d5c8242008-01-24 02:22:38 -0800881 &mii_nway_adv_reg);
882 if (ret_val)
883 goto out;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000884 ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
Auke Kok9d5c8242008-01-24 02:22:38 -0800885 &mii_nway_lp_ability_reg);
886 if (ret_val)
887 goto out;
888
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000889 /* Two bits in the Auto Negotiation Advertisement Register
Auke Kok9d5c8242008-01-24 02:22:38 -0800890 * (Address 4) and two bits in the Auto Negotiation Base
891 * Page Ability Register (Address 5) determine flow control
892 * for both the PHY and the link partner. The following
893 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
894 * 1999, describes these PAUSE resolution bits and how flow
895 * control is determined based upon these settings.
896 * NOTE: DC = Don't Care
897 *
898 * LOCAL DEVICE | LINK PARTNER
899 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
900 *-------|---------|-------|---------|--------------------
901 * 0 | 0 | DC | DC | e1000_fc_none
902 * 0 | 1 | 0 | DC | e1000_fc_none
903 * 0 | 1 | 1 | 0 | e1000_fc_none
904 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
905 * 1 | 0 | 0 | DC | e1000_fc_none
906 * 1 | DC | 1 | DC | e1000_fc_full
907 * 1 | 1 | 0 | 0 | e1000_fc_none
908 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
909 *
910 * Are both PAUSE bits set to 1? If so, this implies
911 * Symmetric Flow Control is enabled at both ends. The
912 * ASM_DIR bits are irrelevant per the spec.
913 *
914 * For Symmetric Flow Control:
915 *
916 * LOCAL DEVICE | LINK PARTNER
917 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
918 *-------|---------|-------|---------|--------------------
919 * 1 | DC | 1 | DC | E1000_fc_full
920 *
921 */
922 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
923 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000924 /* Now we need to check if the user selected RX ONLY
Auke Kok9d5c8242008-01-24 02:22:38 -0800925 * of pause frames. In this case, we had to advertise
926 * FULL flow control because we could not advertise RX
927 * ONLY. Hence, we must now check to see if we need to
928 * turn OFF the TRANSMISSION of PAUSE frames.
929 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000930 if (hw->fc.requested_mode == e1000_fc_full) {
931 hw->fc.current_mode = e1000_fc_full;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000932 hw_dbg("Flow Control = FULL.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800933 } else {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000934 hw->fc.current_mode = e1000_fc_rx_pause;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000935 hw_dbg("Flow Control = RX PAUSE frames only.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800936 }
937 }
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000938 /* For receiving PAUSE frames ONLY.
Auke Kok9d5c8242008-01-24 02:22:38 -0800939 *
940 * LOCAL DEVICE | LINK PARTNER
941 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
942 *-------|---------|-------|---------|--------------------
943 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
944 */
945 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
946 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
947 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
948 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000949 hw->fc.current_mode = e1000_fc_tx_pause;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000950 hw_dbg("Flow Control = TX PAUSE frames only.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800951 }
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000952 /* For transmitting PAUSE frames ONLY.
Auke Kok9d5c8242008-01-24 02:22:38 -0800953 *
954 * LOCAL DEVICE | LINK PARTNER
955 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
956 *-------|---------|-------|---------|--------------------
957 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
958 */
959 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
960 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
961 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
962 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000963 hw->fc.current_mode = e1000_fc_rx_pause;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000964 hw_dbg("Flow Control = RX PAUSE frames only.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800965 }
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000966 /* Per the IEEE spec, at this point flow control should be
Auke Kok9d5c8242008-01-24 02:22:38 -0800967 * disabled. However, we want to consider that we could
968 * be connected to a legacy switch that doesn't advertise
969 * desired flow control, but can be forced on the link
970 * partner. So if we advertised no flow control, that is
971 * what we will resolve to. If we advertised some kind of
972 * receive capability (Rx Pause Only or Full Flow Control)
973 * and the link partner advertised none, we will configure
974 * ourselves to enable Rx Flow Control only. We can do
975 * this safely for two reasons: If the link partner really
976 * didn't want flow control enabled, and we enable Rx, no
977 * harm done since we won't be receiving any PAUSE frames
978 * anyway. If the intent on the link partner was to have
979 * flow control enabled, then by us enabling RX only, we
980 * can at least receive pause frames and process them.
981 * This is a good idea because in most cases, since we are
982 * predominantly a server NIC, more times than not we will
983 * be asked to delay transmission of packets than asking
984 * our link partner to pause transmission of frames.
985 */
Akeem G. Abodunrin5c17a202013-01-29 10:15:31 +0000986 else if ((hw->fc.requested_mode == e1000_fc_none) ||
987 (hw->fc.requested_mode == e1000_fc_tx_pause) ||
988 (hw->fc.strict_ieee)) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000989 hw->fc.current_mode = e1000_fc_none;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000990 hw_dbg("Flow Control = NONE.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800991 } else {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000992 hw->fc.current_mode = e1000_fc_rx_pause;
Jakub Kicinskic5ffe7e2014-04-02 10:33:22 +0000993 hw_dbg("Flow Control = RX PAUSE frames only.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800994 }
995
Jeff Kirsherb980ac12013-02-23 07:29:56 +0000996 /* Now we need to do one last check... If we auto-
Auke Kok9d5c8242008-01-24 02:22:38 -0800997 * negotiated to HALF DUPLEX, flow control should not be
998 * enabled per IEEE 802.3 spec.
999 */
1000 ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
1001 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001002 hw_dbg("Error getting link speed and duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001003 goto out;
1004 }
1005
1006 if (duplex == HALF_DUPLEX)
Alexander Duyck0cce1192009-07-23 18:10:24 +00001007 hw->fc.current_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -08001008
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001009 /* Now we call a subroutine to actually force the MAC
Auke Kok9d5c8242008-01-24 02:22:38 -08001010 * controller to use the correct flow control settings.
1011 */
1012 ret_val = igb_force_mac_fc(hw);
1013 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001014 hw_dbg("Error forcing flow control settings\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001015 goto out;
1016 }
1017 }
Carolyn Wybornydaf56e42012-10-23 12:54:33 +00001018 /* Check for the case where we have SerDes media and auto-neg is
1019 * enabled. In this case, we need to check and see if Auto-Neg
1020 * has completed, and if so, how the PHY and link partner has
1021 * flow control configured.
1022 */
1023 if ((hw->phy.media_type == e1000_media_type_internal_serdes)
1024 && mac->autoneg) {
1025 /* Read the PCS_LSTS and check to see if AutoNeg
1026 * has completed.
1027 */
1028 pcs_status_reg = rd32(E1000_PCS_LSTAT);
1029
1030 if (!(pcs_status_reg & E1000_PCS_LSTS_AN_COMPLETE)) {
1031 hw_dbg("PCS Auto Neg has not completed.\n");
1032 return ret_val;
1033 }
1034
1035 /* The AutoNeg process has completed, so we now need to
1036 * read both the Auto Negotiation Advertisement
1037 * Register (PCS_ANADV) and the Auto_Negotiation Base
1038 * Page Ability Register (PCS_LPAB) to determine how
1039 * flow control was negotiated.
1040 */
1041 pcs_adv_reg = rd32(E1000_PCS_ANADV);
1042 pcs_lp_ability_reg = rd32(E1000_PCS_LPAB);
1043
1044 /* Two bits in the Auto Negotiation Advertisement Register
1045 * (PCS_ANADV) and two bits in the Auto Negotiation Base
1046 * Page Ability Register (PCS_LPAB) determine flow control
1047 * for both the PHY and the link partner. The following
1048 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1049 * 1999, describes these PAUSE resolution bits and how flow
1050 * control is determined based upon these settings.
1051 * NOTE: DC = Don't Care
1052 *
1053 * LOCAL DEVICE | LINK PARTNER
1054 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1055 *-------|---------|-------|---------|--------------------
1056 * 0 | 0 | DC | DC | e1000_fc_none
1057 * 0 | 1 | 0 | DC | e1000_fc_none
1058 * 0 | 1 | 1 | 0 | e1000_fc_none
1059 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1060 * 1 | 0 | 0 | DC | e1000_fc_none
1061 * 1 | DC | 1 | DC | e1000_fc_full
1062 * 1 | 1 | 0 | 0 | e1000_fc_none
1063 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1064 *
1065 * Are both PAUSE bits set to 1? If so, this implies
1066 * Symmetric Flow Control is enabled at both ends. The
1067 * ASM_DIR bits are irrelevant per the spec.
1068 *
1069 * For Symmetric Flow Control:
1070 *
1071 * LOCAL DEVICE | LINK PARTNER
1072 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1073 *-------|---------|-------|---------|--------------------
1074 * 1 | DC | 1 | DC | e1000_fc_full
1075 *
1076 */
1077 if ((pcs_adv_reg & E1000_TXCW_PAUSE) &&
1078 (pcs_lp_ability_reg & E1000_TXCW_PAUSE)) {
1079 /* Now we need to check if the user selected Rx ONLY
1080 * of pause frames. In this case, we had to advertise
1081 * FULL flow control because we could not advertise Rx
1082 * ONLY. Hence, we must now check to see if we need to
1083 * turn OFF the TRANSMISSION of PAUSE frames.
1084 */
1085 if (hw->fc.requested_mode == e1000_fc_full) {
1086 hw->fc.current_mode = e1000_fc_full;
1087 hw_dbg("Flow Control = FULL.\n");
1088 } else {
1089 hw->fc.current_mode = e1000_fc_rx_pause;
1090 hw_dbg("Flow Control = Rx PAUSE frames only.\n");
1091 }
1092 }
1093 /* For receiving PAUSE frames ONLY.
1094 *
1095 * LOCAL DEVICE | LINK PARTNER
1096 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1097 *-------|---------|-------|---------|--------------------
1098 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1099 */
1100 else if (!(pcs_adv_reg & E1000_TXCW_PAUSE) &&
1101 (pcs_adv_reg & E1000_TXCW_ASM_DIR) &&
1102 (pcs_lp_ability_reg & E1000_TXCW_PAUSE) &&
1103 (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) {
1104 hw->fc.current_mode = e1000_fc_tx_pause;
1105 hw_dbg("Flow Control = Tx PAUSE frames only.\n");
1106 }
1107 /* For transmitting PAUSE frames ONLY.
1108 *
1109 * LOCAL DEVICE | LINK PARTNER
1110 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1111 *-------|---------|-------|---------|--------------------
1112 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1113 */
1114 else if ((pcs_adv_reg & E1000_TXCW_PAUSE) &&
1115 (pcs_adv_reg & E1000_TXCW_ASM_DIR) &&
1116 !(pcs_lp_ability_reg & E1000_TXCW_PAUSE) &&
1117 (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) {
1118 hw->fc.current_mode = e1000_fc_rx_pause;
1119 hw_dbg("Flow Control = Rx PAUSE frames only.\n");
1120 } else {
1121 /* Per the IEEE spec, at this point flow control
1122 * should be disabled.
1123 */
1124 hw->fc.current_mode = e1000_fc_none;
1125 hw_dbg("Flow Control = NONE.\n");
1126 }
1127
1128 /* Now we call a subroutine to actually force the MAC
1129 * controller to use the correct flow control settings.
1130 */
1131 pcs_ctrl_reg = rd32(E1000_PCS_LCTL);
1132 pcs_ctrl_reg |= E1000_PCS_LCTL_FORCE_FCTRL;
1133 wr32(E1000_PCS_LCTL, pcs_ctrl_reg);
1134
1135 ret_val = igb_force_mac_fc(hw);
1136 if (ret_val) {
1137 hw_dbg("Error forcing flow control settings\n");
1138 return ret_val;
1139 }
1140 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001141
1142out:
1143 return ret_val;
1144}
1145
1146/**
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001147 * igb_get_speed_and_duplex_copper - Retrieve current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -08001148 * @hw: pointer to the HW structure
1149 * @speed: stores the current speed
1150 * @duplex: stores the current duplex
1151 *
1152 * Read the status register for the current speed/duplex and store the current
1153 * speed and duplex for copper connections.
1154 **/
1155s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
1156 u16 *duplex)
1157{
1158 u32 status;
1159
1160 status = rd32(E1000_STATUS);
1161 if (status & E1000_STATUS_SPEED_1000) {
1162 *speed = SPEED_1000;
Auke Kok652fff32008-06-27 11:00:18 -07001163 hw_dbg("1000 Mbs, ");
Auke Kok9d5c8242008-01-24 02:22:38 -08001164 } else if (status & E1000_STATUS_SPEED_100) {
1165 *speed = SPEED_100;
Auke Kok652fff32008-06-27 11:00:18 -07001166 hw_dbg("100 Mbs, ");
Auke Kok9d5c8242008-01-24 02:22:38 -08001167 } else {
1168 *speed = SPEED_10;
Auke Kok652fff32008-06-27 11:00:18 -07001169 hw_dbg("10 Mbs, ");
Auke Kok9d5c8242008-01-24 02:22:38 -08001170 }
1171
1172 if (status & E1000_STATUS_FD) {
1173 *duplex = FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001174 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001175 } else {
1176 *duplex = HALF_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001177 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001178 }
1179
1180 return 0;
1181}
1182
1183/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001184 * igb_get_hw_semaphore - Acquire hardware semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001185 * @hw: pointer to the HW structure
1186 *
1187 * Acquire the HW semaphore to access the PHY or NVM
1188 **/
1189s32 igb_get_hw_semaphore(struct e1000_hw *hw)
1190{
1191 u32 swsm;
1192 s32 ret_val = 0;
1193 s32 timeout = hw->nvm.word_size + 1;
1194 s32 i = 0;
1195
1196 /* Get the SW semaphore */
1197 while (i < timeout) {
1198 swsm = rd32(E1000_SWSM);
1199 if (!(swsm & E1000_SWSM_SMBI))
1200 break;
1201
1202 udelay(50);
1203 i++;
1204 }
1205
1206 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001207 hw_dbg("Driver can't access device - SMBI bit is set.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001208 ret_val = -E1000_ERR_NVM;
1209 goto out;
1210 }
1211
1212 /* Get the FW semaphore. */
1213 for (i = 0; i < timeout; i++) {
1214 swsm = rd32(E1000_SWSM);
1215 wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
1216
1217 /* Semaphore acquired if bit latched */
1218 if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
1219 break;
1220
1221 udelay(50);
1222 }
1223
1224 if (i == timeout) {
1225 /* Release semaphores */
1226 igb_put_hw_semaphore(hw);
Auke Kok652fff32008-06-27 11:00:18 -07001227 hw_dbg("Driver can't access the NVM\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001228 ret_val = -E1000_ERR_NVM;
1229 goto out;
1230 }
1231
1232out:
1233 return ret_val;
1234}
1235
1236/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001237 * igb_put_hw_semaphore - Release hardware semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001238 * @hw: pointer to the HW structure
1239 *
1240 * Release hardware semaphore used to access the PHY or NVM
1241 **/
1242void igb_put_hw_semaphore(struct e1000_hw *hw)
1243{
1244 u32 swsm;
1245
1246 swsm = rd32(E1000_SWSM);
1247
1248 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1249
1250 wr32(E1000_SWSM, swsm);
1251}
1252
1253/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001254 * igb_get_auto_rd_done - Check for auto read completion
Auke Kok9d5c8242008-01-24 02:22:38 -08001255 * @hw: pointer to the HW structure
1256 *
1257 * Check EEPROM for Auto Read done bit.
1258 **/
1259s32 igb_get_auto_rd_done(struct e1000_hw *hw)
1260{
1261 s32 i = 0;
1262 s32 ret_val = 0;
1263
1264
1265 while (i < AUTO_READ_DONE_TIMEOUT) {
1266 if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD)
1267 break;
1268 msleep(1);
1269 i++;
1270 }
1271
1272 if (i == AUTO_READ_DONE_TIMEOUT) {
Auke Kok652fff32008-06-27 11:00:18 -07001273 hw_dbg("Auto read by HW from NVM has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001274 ret_val = -E1000_ERR_RESET;
1275 goto out;
1276 }
1277
1278out:
1279 return ret_val;
1280}
1281
1282/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001283 * igb_valid_led_default - Verify a valid default LED config
Auke Kok9d5c8242008-01-24 02:22:38 -08001284 * @hw: pointer to the HW structure
1285 * @data: pointer to the NVM (EEPROM)
1286 *
1287 * Read the EEPROM for the current default LED configuration. If the
1288 * LED configuration is not valid, set to a valid LED configuration.
1289 **/
1290static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data)
1291{
1292 s32 ret_val;
1293
Alexander Duyck312c75a2009-02-06 23:17:47 +00001294 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001295 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001296 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001297 goto out;
1298 }
1299
Alexander Duyck099e1cb2009-07-23 18:07:40 +00001300 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
1301 switch(hw->phy.media_type) {
1302 case e1000_media_type_internal_serdes:
1303 *data = ID_LED_DEFAULT_82575_SERDES;
1304 break;
1305 case e1000_media_type_copper:
1306 default:
1307 *data = ID_LED_DEFAULT;
1308 break;
1309 }
1310 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001311out:
1312 return ret_val;
1313}
1314
1315/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001316 * igb_id_led_init -
Auke Kok9d5c8242008-01-24 02:22:38 -08001317 * @hw: pointer to the HW structure
1318 *
1319 **/
1320s32 igb_id_led_init(struct e1000_hw *hw)
1321{
1322 struct e1000_mac_info *mac = &hw->mac;
1323 s32 ret_val;
1324 const u32 ledctl_mask = 0x000000FF;
1325 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
1326 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
1327 u16 data, i, temp;
1328 const u16 led_mask = 0x0F;
1329
Akeem G. Abodunrin6f8b9162013-05-01 05:44:45 +00001330 /* i210 and i211 devices have different LED mechanism */
1331 if ((hw->mac.type == e1000_i210) ||
1332 (hw->mac.type == e1000_i211))
1333 ret_val = igb_valid_led_default_i210(hw, &data);
1334 else
1335 ret_val = igb_valid_led_default(hw, &data);
1336
Auke Kok9d5c8242008-01-24 02:22:38 -08001337 if (ret_val)
1338 goto out;
1339
1340 mac->ledctl_default = rd32(E1000_LEDCTL);
1341 mac->ledctl_mode1 = mac->ledctl_default;
1342 mac->ledctl_mode2 = mac->ledctl_default;
1343
1344 for (i = 0; i < 4; i++) {
1345 temp = (data >> (i << 2)) & led_mask;
1346 switch (temp) {
1347 case ID_LED_ON1_DEF2:
1348 case ID_LED_ON1_ON2:
1349 case ID_LED_ON1_OFF2:
1350 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1351 mac->ledctl_mode1 |= ledctl_on << (i << 3);
1352 break;
1353 case ID_LED_OFF1_DEF2:
1354 case ID_LED_OFF1_ON2:
1355 case ID_LED_OFF1_OFF2:
1356 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1357 mac->ledctl_mode1 |= ledctl_off << (i << 3);
1358 break;
1359 default:
1360 /* Do nothing */
1361 break;
1362 }
1363 switch (temp) {
1364 case ID_LED_DEF1_ON2:
1365 case ID_LED_ON1_ON2:
1366 case ID_LED_OFF1_ON2:
1367 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1368 mac->ledctl_mode2 |= ledctl_on << (i << 3);
1369 break;
1370 case ID_LED_DEF1_OFF2:
1371 case ID_LED_ON1_OFF2:
1372 case ID_LED_OFF1_OFF2:
1373 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1374 mac->ledctl_mode2 |= ledctl_off << (i << 3);
1375 break;
1376 default:
1377 /* Do nothing */
1378 break;
1379 }
1380 }
1381
1382out:
1383 return ret_val;
1384}
1385
1386/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001387 * igb_cleanup_led - Set LED config to default operation
Auke Kok9d5c8242008-01-24 02:22:38 -08001388 * @hw: pointer to the HW structure
1389 *
1390 * Remove the current LED configuration and set the LED configuration
1391 * to the default value, saved from the EEPROM.
1392 **/
1393s32 igb_cleanup_led(struct e1000_hw *hw)
1394{
1395 wr32(E1000_LEDCTL, hw->mac.ledctl_default);
1396 return 0;
1397}
1398
1399/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001400 * igb_blink_led - Blink LED
Auke Kok9d5c8242008-01-24 02:22:38 -08001401 * @hw: pointer to the HW structure
1402 *
1403 * Blink the led's which are set to be on.
1404 **/
1405s32 igb_blink_led(struct e1000_hw *hw)
1406{
1407 u32 ledctl_blink = 0;
1408 u32 i;
1409
Akeem G. Abodunrincf7ed222013-03-29 08:22:25 +00001410 if (hw->phy.media_type == e1000_media_type_fiber) {
1411 /* always blink LED0 for PCI-E fiber */
1412 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
1413 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
1414 } else {
1415 /* Set the blink bit for each LED that's "on" (0x0E)
1416 * (or "off" if inverted) in ledctl_mode2. The blink
1417 * logic in hardware only works when mode is set to "on"
1418 * so it must be changed accordingly when the mode is
1419 * "off" and inverted.
1420 */
1421 ledctl_blink = hw->mac.ledctl_mode2;
1422 for (i = 0; i < 32; i += 8) {
1423 u32 mode = (hw->mac.ledctl_mode2 >> i) &
1424 E1000_LEDCTL_LED0_MODE_MASK;
1425 u32 led_default = hw->mac.ledctl_default >> i;
1426
1427 if ((!(led_default & E1000_LEDCTL_LED0_IVRT) &&
1428 (mode == E1000_LEDCTL_MODE_LED_ON)) ||
1429 ((led_default & E1000_LEDCTL_LED0_IVRT) &&
1430 (mode == E1000_LEDCTL_MODE_LED_OFF))) {
1431 ledctl_blink &=
1432 ~(E1000_LEDCTL_LED0_MODE_MASK << i);
1433 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK |
1434 E1000_LEDCTL_MODE_LED_ON) << i;
1435 }
1436 }
1437 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001438
1439 wr32(E1000_LEDCTL, ledctl_blink);
1440
1441 return 0;
1442}
1443
1444/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001445 * igb_led_off - Turn LED off
Auke Kok9d5c8242008-01-24 02:22:38 -08001446 * @hw: pointer to the HW structure
1447 *
1448 * Turn LED off.
1449 **/
1450s32 igb_led_off(struct e1000_hw *hw)
1451{
Auke Kok9d5c8242008-01-24 02:22:38 -08001452 switch (hw->phy.media_type) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001453 case e1000_media_type_copper:
1454 wr32(E1000_LEDCTL, hw->mac.ledctl_mode1);
1455 break;
1456 default:
1457 break;
1458 }
1459
1460 return 0;
1461}
1462
1463/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001464 * igb_disable_pcie_master - Disables PCI-express master access
Auke Kok9d5c8242008-01-24 02:22:38 -08001465 * @hw: pointer to the HW structure
1466 *
1467 * Returns 0 (0) if successful, else returns -10
Jeff Kirsherb980ac12013-02-23 07:29:56 +00001468 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
Auke Kok9d5c8242008-01-24 02:22:38 -08001469 * the master requests to be disabled.
1470 *
1471 * Disables PCI-Express master access and verifies there are no pending
1472 * requests.
1473 **/
1474s32 igb_disable_pcie_master(struct e1000_hw *hw)
1475{
1476 u32 ctrl;
1477 s32 timeout = MASTER_DISABLE_TIMEOUT;
1478 s32 ret_val = 0;
1479
1480 if (hw->bus.type != e1000_bus_type_pci_express)
1481 goto out;
1482
1483 ctrl = rd32(E1000_CTRL);
1484 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
1485 wr32(E1000_CTRL, ctrl);
1486
1487 while (timeout) {
1488 if (!(rd32(E1000_STATUS) &
1489 E1000_STATUS_GIO_MASTER_ENABLE))
1490 break;
1491 udelay(100);
1492 timeout--;
1493 }
1494
1495 if (!timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001496 hw_dbg("Master requests are pending.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001497 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
1498 goto out;
1499 }
1500
1501out:
1502 return ret_val;
1503}
1504
1505/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001506 * igb_validate_mdi_setting - Verify MDI/MDIx settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001507 * @hw: pointer to the HW structure
1508 *
1509 * Verify that when not using auto-negotitation that MDI/MDIx is correctly
1510 * set, which is forced to MDI mode only.
1511 **/
1512s32 igb_validate_mdi_setting(struct e1000_hw *hw)
1513{
1514 s32 ret_val = 0;
1515
Matthew Vick9f0b8512012-10-16 07:44:45 +00001516 /* All MDI settings are supported on 82580 and newer. */
1517 if (hw->mac.type >= e1000_82580)
1518 goto out;
1519
Auke Kok9d5c8242008-01-24 02:22:38 -08001520 if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
Auke Kok652fff32008-06-27 11:00:18 -07001521 hw_dbg("Invalid MDI setting detected\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001522 hw->phy.mdix = 1;
1523 ret_val = -E1000_ERR_CONFIG;
1524 goto out;
1525 }
1526
1527out:
1528 return ret_val;
1529}
1530
1531/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001532 * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register
Auke Kok9d5c8242008-01-24 02:22:38 -08001533 * @hw: pointer to the HW structure
1534 * @reg: 32bit register offset such as E1000_SCTL
1535 * @offset: register offset to write to
1536 * @data: data to write at register offset
1537 *
1538 * Writes an address/data control type register. There are several of these
1539 * and they all have the format address << 8 | data and bit 31 is polled for
1540 * completion.
1541 **/
1542s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg,
1543 u32 offset, u8 data)
1544{
1545 u32 i, regvalue = 0;
1546 s32 ret_val = 0;
1547
1548 /* Set up the address and data */
1549 regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
1550 wr32(reg, regvalue);
1551
1552 /* Poll the ready bit to see if the MDI read completed */
1553 for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
1554 udelay(5);
1555 regvalue = rd32(reg);
1556 if (regvalue & E1000_GEN_CTL_READY)
1557 break;
1558 }
1559 if (!(regvalue & E1000_GEN_CTL_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -07001560 hw_dbg("Reg %08x did not indicate ready\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001561 ret_val = -E1000_ERR_PHY;
1562 goto out;
1563 }
1564
1565out:
1566 return ret_val;
1567}
1568
1569/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001570 * igb_enable_mng_pass_thru - Enable processing of ARP's
Auke Kok9d5c8242008-01-24 02:22:38 -08001571 * @hw: pointer to the HW structure
1572 *
Alexander Duycke017b602010-03-25 17:15:06 +00001573 * Verifies the hardware needs to leave interface enabled so that frames can
1574 * be directed to and from the management interface.
Auke Kok9d5c8242008-01-24 02:22:38 -08001575 **/
1576bool igb_enable_mng_pass_thru(struct e1000_hw *hw)
1577{
1578 u32 manc;
1579 u32 fwsm, factps;
1580 bool ret_val = false;
1581
1582 if (!hw->mac.asf_firmware_present)
1583 goto out;
1584
1585 manc = rd32(E1000_MANC);
1586
Alexander Duycke017b602010-03-25 17:15:06 +00001587 if (!(manc & E1000_MANC_RCV_TCO_EN))
Auke Kok9d5c8242008-01-24 02:22:38 -08001588 goto out;
1589
1590 if (hw->mac.arc_subsystem_valid) {
1591 fwsm = rd32(E1000_FWSM);
1592 factps = rd32(E1000_FACTPS);
1593
1594 if (!(factps & E1000_FACTPS_MNGCG) &&
1595 ((fwsm & E1000_FWSM_MODE_MASK) ==
1596 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
1597 ret_val = true;
1598 goto out;
1599 }
1600 } else {
1601 if ((manc & E1000_MANC_SMBUS_EN) &&
1602 !(manc & E1000_MANC_ASF_EN)) {
1603 ret_val = true;
1604 goto out;
1605 }
1606 }
1607
1608out:
1609 return ret_val;
1610}