blob: be8d010e40213a7b51616fad0e320464a43c751a [file] [log] [blame]
Auke Kok9d5c8242008-01-24 02:22:38 -08001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
Alexander Duyck86d5d382009-02-06 23:23:12 +00004 Copyright(c) 2007-2009 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
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/if_ether.h>
29#include <linux/delay.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32
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;
56 bus->speed = e1000_bus_speed_2500;
57
58 ret_val = igb_read_pcie_cap_reg(hw,
59 PCIE_LINK_STATUS,
60 &pcie_link_status);
61 if (ret_val)
62 bus->width = e1000_bus_width_unknown;
63 else
64 bus->width = (enum e1000_bus_width)((pcie_link_status &
65 PCIE_LINK_WIDTH_MASK) >>
66 PCIE_LINK_WIDTH_SHIFT);
67
Alexander Duyck5e8427e2008-12-10 01:09:53 -080068 reg = rd32(E1000_STATUS);
69 bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
Auke Kok9d5c8242008-01-24 02:22:38 -080070
71 return 0;
72}
73
74/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070075 * igb_clear_vfta - Clear VLAN filter table
Auke Kok9d5c8242008-01-24 02:22:38 -080076 * @hw: pointer to the HW structure
77 *
78 * Clears the register array which contains the VLAN filter table by
79 * setting all the values to 0.
80 **/
81void igb_clear_vfta(struct e1000_hw *hw)
82{
83 u32 offset;
84
85 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
86 array_wr32(E1000_VFTA, offset, 0);
87 wrfl();
88 }
89}
90
91/**
Jeff Kirsher733596b2008-06-27 10:59:59 -070092 * igb_write_vfta - Write value to VLAN filter table
Auke Kok9d5c8242008-01-24 02:22:38 -080093 * @hw: pointer to the HW structure
94 * @offset: register offset in VLAN filter table
95 * @value: register value written to VLAN filter table
96 *
97 * Writes value at the given offset in the register array which stores
98 * the VLAN filter table.
99 **/
Alexander Duyckff6f63d2009-04-09 22:49:02 +0000100static void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
Auke Kok9d5c8242008-01-24 02:22:38 -0800101{
102 array_wr32(E1000_VFTA, offset, value);
103 wrfl();
104}
105
106/**
Alexander Duyck5ac16652009-07-23 18:09:12 +0000107 * igb_init_rx_addrs - Initialize receive address's
108 * @hw: pointer to the HW structure
109 * @rar_count: receive address registers
110 *
111 * Setups the receive address registers by setting the base receive address
112 * register to the devices MAC address and clearing all the other receive
113 * address registers to 0.
114 **/
115void igb_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
116{
117 u32 i;
118 u8 mac_addr[ETH_ALEN] = {0};
119
120 /* Setup the receive address */
121 hw_dbg("Programming MAC Address into RAR[0]\n");
122
123 hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
124
125 /* Zero out the other (rar_entry_count - 1) receive addresses */
126 hw_dbg("Clearing RAR[1-%u]\n", rar_count-1);
127 for (i = 1; i < rar_count; i++)
128 hw->mac.ops.rar_set(hw, mac_addr, i);
129}
130
131/**
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800132 * igb_vfta_set - enable or disable vlan in VLAN filter table
133 * @hw: pointer to the HW structure
134 * @vid: VLAN id to add or remove
135 * @add: if true add filter, if false remove
136 *
137 * Sets or clears a bit in the VLAN filter table array based on VLAN id
138 * and if we are adding or removing the filter
139 **/
Alexander Duyckcad6d052009-03-13 20:41:37 +0000140s32 igb_vfta_set(struct e1000_hw *hw, u32 vid, bool add)
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800141{
142 u32 index = (vid >> E1000_VFTA_ENTRY_SHIFT) & E1000_VFTA_ENTRY_MASK;
Alexander Duyck75f4f382009-03-13 20:41:55 +0000143 u32 mask = 1 << (vid & E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
Alexander Duyckcad6d052009-03-13 20:41:37 +0000144 u32 vfta = array_rd32(E1000_VFTA, index);
145 s32 ret_val = 0;
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800146
Alexander Duyckcad6d052009-03-13 20:41:37 +0000147 /* bit was set/cleared before we started */
148 if ((!!(vfta & mask)) == add) {
149 ret_val = -E1000_ERR_CONFIG;
150 } else {
151 if (add)
152 vfta |= mask;
153 else
154 vfta &= ~mask;
155 }
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800156
157 igb_write_vfta(hw, index, vfta);
Alexander Duyckcad6d052009-03-13 20:41:37 +0000158
159 return ret_val;
Alexander Duyck4ae196d2009-02-19 20:40:07 -0800160}
161
162/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700163 * igb_check_alt_mac_addr - Check for alternate MAC addr
Auke Kok9d5c8242008-01-24 02:22:38 -0800164 * @hw: pointer to the HW structure
165 *
166 * Checks the nvm for an alternate MAC address. An alternate MAC address
167 * can be setup by pre-boot software and must be treated like a permanent
168 * address and must override the actual permanent MAC address. If an
169 * alternate MAC address is fopund it is saved in the hw struct and
170 * prgrammed into RAR0 and the cuntion returns success, otherwise the
171 * fucntion returns an error.
172 **/
173s32 igb_check_alt_mac_addr(struct e1000_hw *hw)
174{
175 u32 i;
176 s32 ret_val = 0;
177 u16 offset, nvm_alt_mac_addr_offset, nvm_data;
178 u8 alt_mac_addr[ETH_ALEN];
179
Alexander Duyck312c75a2009-02-06 23:17:47 +0000180 ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1,
Auke Kok9d5c8242008-01-24 02:22:38 -0800181 &nvm_alt_mac_addr_offset);
182 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700183 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800184 goto out;
185 }
186
187 if (nvm_alt_mac_addr_offset == 0xFFFF) {
Alexander Duyck22896632009-10-05 06:34:25 +0000188 /* There is no Alternate MAC Address */
Auke Kok9d5c8242008-01-24 02:22:38 -0800189 goto out;
190 }
191
192 if (hw->bus.func == E1000_FUNC_1)
Alexander Duyck22896632009-10-05 06:34:25 +0000193 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
Auke Kok9d5c8242008-01-24 02:22:38 -0800194 for (i = 0; i < ETH_ALEN; i += 2) {
195 offset = nvm_alt_mac_addr_offset + (i >> 1);
Alexander Duyck312c75a2009-02-06 23:17:47 +0000196 ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800197 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700198 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800199 goto out;
200 }
201
202 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
203 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
204 }
205
206 /* if multicast bit is set, the alternate address will not be used */
207 if (alt_mac_addr[0] & 0x01) {
Alexander Duyck22896632009-10-05 06:34:25 +0000208 hw_dbg("Ignoring Alternate Mac Address with MC bit set\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800209 goto out;
210 }
211
Alexander Duyck22896632009-10-05 06:34:25 +0000212 /*
213 * We have a valid alternate MAC address, and we want to treat it the
214 * same as the normal permanent MAC address stored by the HW into the
215 * RAR. Do this by mapping this address into RAR0.
216 */
217 hw->mac.ops.rar_set(hw, alt_mac_addr, 0);
Auke Kok9d5c8242008-01-24 02:22:38 -0800218
219out:
220 return ret_val;
221}
222
223/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700224 * igb_rar_set - Set receive address register
Auke Kok9d5c8242008-01-24 02:22:38 -0800225 * @hw: pointer to the HW structure
226 * @addr: pointer to the receive address
227 * @index: receive address array register
228 *
229 * Sets the receive address array register at index to the address passed
230 * in by addr.
231 **/
232void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
233{
234 u32 rar_low, rar_high;
235
236 /*
237 * HW expects these in little endian so we reverse the byte order
238 * from network order (big endian) to little endian
239 */
240 rar_low = ((u32) addr[0] |
241 ((u32) addr[1] << 8) |
242 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
243
244 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
245
Alexander Duyck86757372009-02-06 23:21:51 +0000246 /* If MAC address zero, no need to set the AV bit */
247 if (rar_low || rar_high)
Auke Kok9d5c8242008-01-24 02:22:38 -0800248 rar_high |= E1000_RAH_AV;
249
Alexander Duyck6deac6f2009-10-05 06:36:01 +0000250 /*
251 * Some bridges will combine consecutive 32-bit writes into
252 * a single burst write, which will malfunction on some parts.
253 * The flushes avoid this.
254 */
Alexander Duyck5e8427e2008-12-10 01:09:53 -0800255 wr32(E1000_RAL(index), rar_low);
Alexander Duyck6deac6f2009-10-05 06:36:01 +0000256 wrfl();
Alexander Duyck5e8427e2008-12-10 01:09:53 -0800257 wr32(E1000_RAH(index), rar_high);
Alexander Duyck6deac6f2009-10-05 06:36:01 +0000258 wrfl();
Auke Kok9d5c8242008-01-24 02:22:38 -0800259}
260
261/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700262 * igb_mta_set - Set multicast filter table address
Auke Kok9d5c8242008-01-24 02:22:38 -0800263 * @hw: pointer to the HW structure
264 * @hash_value: determines the MTA register and bit to set
265 *
266 * The multicast table address is a register array of 32-bit registers.
267 * The hash_value is used to determine what register the bit is in, the
268 * current value is read, the new bit is OR'd in and the new value is
269 * written back into the register.
270 **/
Alexander Duyck549bdd82008-08-04 15:00:06 -0700271void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
Auke Kok9d5c8242008-01-24 02:22:38 -0800272{
273 u32 hash_bit, hash_reg, mta;
274
275 /*
276 * The MTA is a register array of 32-bit registers. It is
277 * treated like an array of (32*mta_reg_count) bits. We want to
278 * set bit BitArray[hash_value]. So we figure out what register
279 * the bit is in, read it, OR in the new bit, then write
280 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
281 * mask to bits 31:5 of the hash value which gives us the
282 * register we're modifying. The hash bit within that register
283 * is determined by the lower 5 bits of the hash value.
284 */
285 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
286 hash_bit = hash_value & 0x1F;
287
288 mta = array_rd32(E1000_MTA, hash_reg);
289
290 mta |= (1 << hash_bit);
291
292 array_wr32(E1000_MTA, hash_reg, mta);
293 wrfl();
294}
295
296/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700297 * igb_hash_mc_addr - Generate a multicast hash value
Auke Kok9d5c8242008-01-24 02:22:38 -0800298 * @hw: pointer to the HW structure
299 * @mc_addr: pointer to a multicast address
300 *
301 * Generates a multicast address hash value which is used to determine
302 * the multicast filter table array address and new table value. See
303 * igb_mta_set()
304 **/
Alexander Duyck44c852e2009-09-17 14:52:29 +0000305static u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
Auke Kok9d5c8242008-01-24 02:22:38 -0800306{
307 u32 hash_value, hash_mask;
308 u8 bit_shift = 0;
309
310 /* Register count multiplied by bits per register */
311 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
312
313 /*
314 * For a mc_filter_type of 0, bit_shift is the number of left-shifts
315 * where 0xFF would still fall within the hash mask.
316 */
317 while (hash_mask >> bit_shift != 0xFF)
318 bit_shift++;
319
320 /*
321 * The portion of the address that is used for the hash table
322 * is determined by the mc_filter_type setting.
323 * The algorithm is such that there is a total of 8 bits of shifting.
324 * The bit_shift for a mc_filter_type of 0 represents the number of
325 * left-shifts where the MSB of mc_addr[5] would still fall within
326 * the hash_mask. Case 0 does this exactly. Since there are a total
327 * of 8 bits of shifting, then mc_addr[4] will shift right the
328 * remaining number of bits. Thus 8 - bit_shift. The rest of the
329 * cases are a variation of this algorithm...essentially raising the
330 * number of bits to shift mc_addr[5] left, while still keeping the
331 * 8-bit shifting total.
332 *
333 * For example, given the following Destination MAC Address and an
334 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
335 * we can see that the bit_shift for case 0 is 4. These are the hash
336 * values resulting from each mc_filter_type...
337 * [0] [1] [2] [3] [4] [5]
338 * 01 AA 00 12 34 56
339 * LSB MSB
340 *
341 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
342 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
343 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
344 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
345 */
346 switch (hw->mac.mc_filter_type) {
347 default:
348 case 0:
349 break;
350 case 1:
351 bit_shift += 1;
352 break;
353 case 2:
354 bit_shift += 2;
355 break;
356 case 3:
357 bit_shift += 4;
358 break;
359 }
360
361 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
362 (((u16) mc_addr[5]) << bit_shift)));
363
364 return hash_value;
365}
366
367/**
Alexander Duyck44c852e2009-09-17 14:52:29 +0000368 * igb_update_mc_addr_list - Update Multicast addresses
369 * @hw: pointer to the HW structure
370 * @mc_addr_list: array of multicast addresses to program
371 * @mc_addr_count: number of multicast addresses to program
372 *
373 * Updates entire Multicast Table Array.
374 * The caller must have a packed mc_addr_list of multicast addresses.
375 **/
376void igb_update_mc_addr_list(struct e1000_hw *hw,
377 u8 *mc_addr_list, u32 mc_addr_count)
378{
379 u32 hash_value, hash_bit, hash_reg;
380 int i;
381
382 /* clear mta_shadow */
383 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
384
385 /* update mta_shadow from mc_addr_list */
386 for (i = 0; (u32) i < mc_addr_count; i++) {
387 hash_value = igb_hash_mc_addr(hw, mc_addr_list);
388
389 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
390 hash_bit = hash_value & 0x1F;
391
392 hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
393 mc_addr_list += (ETH_ALEN);
394 }
395
396 /* replace the entire MTA table */
397 for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
398 array_wr32(E1000_MTA, i, hw->mac.mta_shadow[i]);
399 wrfl();
400}
401
402/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700403 * igb_clear_hw_cntrs_base - Clear base hardware counters
Auke Kok9d5c8242008-01-24 02:22:38 -0800404 * @hw: pointer to the HW structure
405 *
406 * Clears the base hardware counters by reading the counter registers.
407 **/
408void igb_clear_hw_cntrs_base(struct e1000_hw *hw)
409{
Alexander Duyckcc9073b2009-10-05 06:31:25 +0000410 rd32(E1000_CRCERRS);
411 rd32(E1000_SYMERRS);
412 rd32(E1000_MPC);
413 rd32(E1000_SCC);
414 rd32(E1000_ECOL);
415 rd32(E1000_MCC);
416 rd32(E1000_LATECOL);
417 rd32(E1000_COLC);
418 rd32(E1000_DC);
419 rd32(E1000_SEC);
420 rd32(E1000_RLEC);
421 rd32(E1000_XONRXC);
422 rd32(E1000_XONTXC);
423 rd32(E1000_XOFFRXC);
424 rd32(E1000_XOFFTXC);
425 rd32(E1000_FCRUC);
426 rd32(E1000_GPRC);
427 rd32(E1000_BPRC);
428 rd32(E1000_MPRC);
429 rd32(E1000_GPTC);
430 rd32(E1000_GORCL);
431 rd32(E1000_GORCH);
432 rd32(E1000_GOTCL);
433 rd32(E1000_GOTCH);
434 rd32(E1000_RNBC);
435 rd32(E1000_RUC);
436 rd32(E1000_RFC);
437 rd32(E1000_ROC);
438 rd32(E1000_RJC);
439 rd32(E1000_TORL);
440 rd32(E1000_TORH);
441 rd32(E1000_TOTL);
442 rd32(E1000_TOTH);
443 rd32(E1000_TPR);
444 rd32(E1000_TPT);
445 rd32(E1000_MPTC);
446 rd32(E1000_BPTC);
Auke Kok9d5c8242008-01-24 02:22:38 -0800447}
448
449/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700450 * igb_check_for_copper_link - Check for link (Copper)
Auke Kok9d5c8242008-01-24 02:22:38 -0800451 * @hw: pointer to the HW structure
452 *
453 * Checks to see of the link status of the hardware has changed. If a
454 * change in link status has been detected, then we read the PHY registers
455 * to get the current speed/duplex if link exists.
456 **/
457s32 igb_check_for_copper_link(struct e1000_hw *hw)
458{
459 struct e1000_mac_info *mac = &hw->mac;
460 s32 ret_val;
461 bool link;
462
463 /*
464 * We only want to go out to the PHY registers to see if Auto-Neg
465 * has completed and/or if our link status has changed. The
466 * get_link_status flag is set upon receiving a Link Status
467 * Change or Rx Sequence Error interrupt.
468 */
469 if (!mac->get_link_status) {
470 ret_val = 0;
471 goto out;
472 }
473
474 /*
475 * First we want to see if the MII Status Register reports
476 * link. If so, then we want to get the current speed/duplex
477 * of the PHY.
478 */
479 ret_val = igb_phy_has_link(hw, 1, 0, &link);
480 if (ret_val)
481 goto out;
482
483 if (!link)
484 goto out; /* No link detected */
485
486 mac->get_link_status = false;
487
488 /*
489 * Check if there was DownShift, must be checked
490 * immediately after link-up
491 */
492 igb_check_downshift(hw);
493
494 /*
495 * If we are forcing speed/duplex, then we simply return since
496 * we have already determined whether we have link or not.
497 */
498 if (!mac->autoneg) {
499 ret_val = -E1000_ERR_CONFIG;
500 goto out;
501 }
502
503 /*
504 * Auto-Neg is enabled. Auto Speed Detection takes care
505 * of MAC speed/duplex configuration. So we only need to
506 * configure Collision Distance in the MAC.
507 */
508 igb_config_collision_dist(hw);
509
510 /*
511 * Configure Flow Control now that Auto-Neg has completed.
512 * First, we need to restore the desired flow control
513 * settings because we may have had to re-autoneg with a
514 * different link partner.
515 */
516 ret_val = igb_config_fc_after_link_up(hw);
517 if (ret_val)
Auke Kok652fff32008-06-27 11:00:18 -0700518 hw_dbg("Error configuring flow control\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800519
520out:
521 return ret_val;
522}
523
524/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700525 * igb_setup_link - Setup flow control and link settings
Auke Kok9d5c8242008-01-24 02:22:38 -0800526 * @hw: pointer to the HW structure
527 *
528 * Determines which flow control settings to use, then configures flow
529 * control. Calls the appropriate media-specific link configuration
530 * function. Assuming the adapter has a valid link partner, a valid link
531 * should be established. Assumes the hardware has previously been reset
532 * and the transmitter and receiver are not enabled.
533 **/
534s32 igb_setup_link(struct e1000_hw *hw)
535{
536 s32 ret_val = 0;
537
538 /*
539 * In the case of the phy reset being blocked, we already have a link.
540 * We do not need to set it up again.
541 */
542 if (igb_check_reset_block(hw))
543 goto out;
544
Alexander Duyck0cce1192009-07-23 18:10:24 +0000545 /*
546 * If requested flow control is set to default, set flow control
547 * based on the EEPROM flow control settings.
548 */
549 if (hw->fc.requested_mode == e1000_fc_default) {
550 ret_val = igb_set_default_fc(hw);
551 if (ret_val)
552 goto out;
553 }
Auke Kok9d5c8242008-01-24 02:22:38 -0800554
555 /*
556 * We want to save off the original Flow Control configuration just
557 * in case we get disconnected and then reconnected into a different
558 * hub or switch with different Flow Control capabilities.
559 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000560 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kok9d5c8242008-01-24 02:22:38 -0800561
Alexander Duyck0cce1192009-07-23 18:10:24 +0000562 hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
Auke Kok9d5c8242008-01-24 02:22:38 -0800563
564 /* Call the necessary media_type subroutine to configure the link. */
565 ret_val = hw->mac.ops.setup_physical_interface(hw);
566 if (ret_val)
567 goto out;
568
569 /*
570 * Initialize the flow control address, type, and PAUSE timer
571 * registers to their default values. This is done even if flow
572 * control is disabled, because it does not hurt anything to
573 * initialize these registers.
574 */
Auke Kok652fff32008-06-27 11:00:18 -0700575 hw_dbg("Initializing the Flow Control address, type and timer regs\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800576 wr32(E1000_FCT, FLOW_CONTROL_TYPE);
577 wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
578 wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
579
580 wr32(E1000_FCTTV, hw->fc.pause_time);
581
582 ret_val = igb_set_fc_watermarks(hw);
583
584out:
585 return ret_val;
586}
587
588/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700589 * igb_config_collision_dist - Configure collision distance
Auke Kok9d5c8242008-01-24 02:22:38 -0800590 * @hw: pointer to the HW structure
591 *
592 * Configures the collision distance to the default value and is used
593 * during link setup. Currently no func pointer exists and all
594 * implementations are handled in the generic version of this function.
595 **/
596void igb_config_collision_dist(struct e1000_hw *hw)
597{
598 u32 tctl;
599
600 tctl = rd32(E1000_TCTL);
601
602 tctl &= ~E1000_TCTL_COLD;
603 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
604
605 wr32(E1000_TCTL, tctl);
606 wrfl();
607}
608
609/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700610 * igb_set_fc_watermarks - Set flow control high/low watermarks
Auke Kok9d5c8242008-01-24 02:22:38 -0800611 * @hw: pointer to the HW structure
612 *
613 * Sets the flow control high/low threshold (watermark) registers. If
614 * flow control XON frame transmission is enabled, then set XON frame
615 * tansmission as well.
616 **/
617static s32 igb_set_fc_watermarks(struct e1000_hw *hw)
618{
619 s32 ret_val = 0;
620 u32 fcrtl = 0, fcrth = 0;
621
622 /*
623 * Set the flow control receive threshold registers. Normally,
624 * these registers will be set to a default threshold that may be
625 * adjusted later by the driver's runtime code. However, if the
626 * ability to transmit pause frames is not enabled, then these
627 * registers will be set to 0.
628 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000629 if (hw->fc.current_mode & e1000_fc_tx_pause) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800630 /*
631 * We need to set up the Receive Threshold high and low water
632 * marks as well as (optionally) enabling the transmission of
633 * XON frames.
634 */
635 fcrtl = hw->fc.low_water;
636 if (hw->fc.send_xon)
637 fcrtl |= E1000_FCRTL_XONE;
638
639 fcrth = hw->fc.high_water;
640 }
641 wr32(E1000_FCRTL, fcrtl);
642 wr32(E1000_FCRTH, fcrth);
643
644 return ret_val;
645}
646
647/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700648 * igb_set_default_fc - Set flow control default values
Auke Kok9d5c8242008-01-24 02:22:38 -0800649 * @hw: pointer to the HW structure
650 *
651 * Read the EEPROM for the default values for flow control and store the
652 * values.
653 **/
654static s32 igb_set_default_fc(struct e1000_hw *hw)
655{
656 s32 ret_val = 0;
657 u16 nvm_data;
658
659 /*
660 * Read and store word 0x0F of the EEPROM. This word contains bits
661 * that determine the hardware's default PAUSE (flow control) mode,
662 * a bit that determines whether the HW defaults to enabling or
663 * disabling auto-negotiation, and the direction of the
664 * SW defined pins. If there is no SW over-ride of the flow
665 * control setting, then the variable hw->fc will
666 * be initialized based on a value in the EEPROM.
667 */
Alexander Duyck312c75a2009-02-06 23:17:47 +0000668 ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
Auke Kok9d5c8242008-01-24 02:22:38 -0800669
670 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700671 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800672 goto out;
673 }
674
675 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
Alexander Duyck0cce1192009-07-23 18:10:24 +0000676 hw->fc.requested_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -0800677 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
678 NVM_WORD0F_ASM_DIR)
Alexander Duyck0cce1192009-07-23 18:10:24 +0000679 hw->fc.requested_mode = e1000_fc_tx_pause;
Auke Kok9d5c8242008-01-24 02:22:38 -0800680 else
Alexander Duyck0cce1192009-07-23 18:10:24 +0000681 hw->fc.requested_mode = e1000_fc_full;
Auke Kok9d5c8242008-01-24 02:22:38 -0800682
683out:
684 return ret_val;
685}
686
687/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700688 * igb_force_mac_fc - Force the MAC's flow control settings
Auke Kok9d5c8242008-01-24 02:22:38 -0800689 * @hw: pointer to the HW structure
690 *
691 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
692 * device control register to reflect the adapter settings. TFCE and RFCE
693 * need to be explicitly set by software when a copper PHY is used because
694 * autonegotiation is managed by the PHY rather than the MAC. Software must
695 * also configure these bits when link is forced on a fiber connection.
696 **/
697s32 igb_force_mac_fc(struct e1000_hw *hw)
698{
699 u32 ctrl;
700 s32 ret_val = 0;
701
702 ctrl = rd32(E1000_CTRL);
703
704 /*
705 * Because we didn't get link via the internal auto-negotiation
706 * mechanism (we either forced link or we got link via PHY
707 * auto-neg), we have to manually enable/disable transmit an
708 * receive flow control.
709 *
710 * The "Case" statement below enables/disable flow control
Alexander Duyck0cce1192009-07-23 18:10:24 +0000711 * according to the "hw->fc.current_mode" parameter.
Auke Kok9d5c8242008-01-24 02:22:38 -0800712 *
713 * The possible values of the "fc" parameter are:
714 * 0: Flow control is completely disabled
715 * 1: Rx flow control is enabled (we can receive pause
716 * frames but not send pause frames).
717 * 2: Tx flow control is enabled (we can send pause frames
718 * frames but we do not receive pause frames).
719 * 3: Both Rx and TX flow control (symmetric) is enabled.
720 * other: No other values should be possible at this point.
721 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000722 hw_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
Auke Kok9d5c8242008-01-24 02:22:38 -0800723
Alexander Duyck0cce1192009-07-23 18:10:24 +0000724 switch (hw->fc.current_mode) {
Auke Kok9d5c8242008-01-24 02:22:38 -0800725 case e1000_fc_none:
726 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
727 break;
728 case e1000_fc_rx_pause:
729 ctrl &= (~E1000_CTRL_TFCE);
730 ctrl |= E1000_CTRL_RFCE;
731 break;
732 case e1000_fc_tx_pause:
733 ctrl &= (~E1000_CTRL_RFCE);
734 ctrl |= E1000_CTRL_TFCE;
735 break;
736 case e1000_fc_full:
737 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
738 break;
739 default:
Auke Kok652fff32008-06-27 11:00:18 -0700740 hw_dbg("Flow control param set incorrectly\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800741 ret_val = -E1000_ERR_CONFIG;
742 goto out;
743 }
744
745 wr32(E1000_CTRL, ctrl);
746
747out:
748 return ret_val;
749}
750
751/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700752 * igb_config_fc_after_link_up - Configures flow control after link
Auke Kok9d5c8242008-01-24 02:22:38 -0800753 * @hw: pointer to the HW structure
754 *
755 * Checks the status of auto-negotiation after link up to ensure that the
756 * speed and duplex were not forced. If the link needed to be forced, then
757 * flow control needs to be forced also. If auto-negotiation is enabled
758 * and did not fail, then we configure flow control based on our link
759 * partner.
760 **/
761s32 igb_config_fc_after_link_up(struct e1000_hw *hw)
762{
763 struct e1000_mac_info *mac = &hw->mac;
764 s32 ret_val = 0;
765 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
766 u16 speed, duplex;
767
768 /*
769 * Check for the case where we have fiber media and auto-neg failed
770 * so we had to force link. In this case, we need to force the
771 * configuration of the MAC to match the "fc" parameter.
772 */
773 if (mac->autoneg_failed) {
Alexander Duyckdcc3ae92009-07-23 18:07:20 +0000774 if (hw->phy.media_type == e1000_media_type_internal_serdes)
Auke Kok9d5c8242008-01-24 02:22:38 -0800775 ret_val = igb_force_mac_fc(hw);
776 } else {
777 if (hw->phy.media_type == e1000_media_type_copper)
778 ret_val = igb_force_mac_fc(hw);
779 }
780
781 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700782 hw_dbg("Error forcing flow control settings\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800783 goto out;
784 }
785
786 /*
787 * Check for the case where we have copper media and auto-neg is
788 * enabled. In this case, we need to check and see if Auto-Neg
789 * has completed, and if so, how the PHY and link partner has
790 * flow control configured.
791 */
792 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
793 /*
794 * Read the MII Status Register and check to see if AutoNeg
795 * has completed. We read this twice because this reg has
796 * some "sticky" (latched) bits.
797 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000798 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
Auke Kok9d5c8242008-01-24 02:22:38 -0800799 &mii_status_reg);
800 if (ret_val)
801 goto out;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000802 ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS,
Auke Kok9d5c8242008-01-24 02:22:38 -0800803 &mii_status_reg);
804 if (ret_val)
805 goto out;
806
807 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
Auke Kok652fff32008-06-27 11:00:18 -0700808 hw_dbg("Copper PHY and Auto Neg "
Auke Kok9d5c8242008-01-24 02:22:38 -0800809 "has not completed.\n");
810 goto out;
811 }
812
813 /*
814 * The AutoNeg process has completed, so we now need to
815 * read both the Auto Negotiation Advertisement
816 * Register (Address 4) and the Auto_Negotiation Base
817 * Page Ability Register (Address 5) to determine how
818 * flow control was negotiated.
819 */
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000820 ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
Auke Kok9d5c8242008-01-24 02:22:38 -0800821 &mii_nway_adv_reg);
822 if (ret_val)
823 goto out;
Alexander Duycka8d2a0c2009-02-06 23:17:26 +0000824 ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
Auke Kok9d5c8242008-01-24 02:22:38 -0800825 &mii_nway_lp_ability_reg);
826 if (ret_val)
827 goto out;
828
829 /*
830 * Two bits in the Auto Negotiation Advertisement Register
831 * (Address 4) and two bits in the Auto Negotiation Base
832 * Page Ability Register (Address 5) determine flow control
833 * for both the PHY and the link partner. The following
834 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
835 * 1999, describes these PAUSE resolution bits and how flow
836 * control is determined based upon these settings.
837 * NOTE: DC = Don't Care
838 *
839 * LOCAL DEVICE | LINK PARTNER
840 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
841 *-------|---------|-------|---------|--------------------
842 * 0 | 0 | DC | DC | e1000_fc_none
843 * 0 | 1 | 0 | DC | e1000_fc_none
844 * 0 | 1 | 1 | 0 | e1000_fc_none
845 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
846 * 1 | 0 | 0 | DC | e1000_fc_none
847 * 1 | DC | 1 | DC | e1000_fc_full
848 * 1 | 1 | 0 | 0 | e1000_fc_none
849 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
850 *
851 * Are both PAUSE bits set to 1? If so, this implies
852 * Symmetric Flow Control is enabled at both ends. The
853 * ASM_DIR bits are irrelevant per the spec.
854 *
855 * For Symmetric Flow Control:
856 *
857 * LOCAL DEVICE | LINK PARTNER
858 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
859 *-------|---------|-------|---------|--------------------
860 * 1 | DC | 1 | DC | E1000_fc_full
861 *
862 */
863 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
864 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
865 /*
866 * Now we need to check if the user selected RX ONLY
867 * of pause frames. In this case, we had to advertise
868 * FULL flow control because we could not advertise RX
869 * ONLY. Hence, we must now check to see if we need to
870 * turn OFF the TRANSMISSION of PAUSE frames.
871 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000872 if (hw->fc.requested_mode == e1000_fc_full) {
873 hw->fc.current_mode = e1000_fc_full;
Auke Kok652fff32008-06-27 11:00:18 -0700874 hw_dbg("Flow Control = FULL.\r\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800875 } else {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000876 hw->fc.current_mode = e1000_fc_rx_pause;
Auke Kok652fff32008-06-27 11:00:18 -0700877 hw_dbg("Flow Control = "
878 "RX PAUSE frames only.\r\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800879 }
880 }
881 /*
882 * For receiving PAUSE frames ONLY.
883 *
884 * LOCAL DEVICE | LINK PARTNER
885 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
886 *-------|---------|-------|---------|--------------------
887 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
888 */
889 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
890 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
891 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
892 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000893 hw->fc.current_mode = e1000_fc_tx_pause;
Auke Kok652fff32008-06-27 11:00:18 -0700894 hw_dbg("Flow Control = TX PAUSE frames only.\r\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800895 }
896 /*
897 * For transmitting PAUSE frames ONLY.
898 *
899 * LOCAL DEVICE | LINK PARTNER
900 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
901 *-------|---------|-------|---------|--------------------
902 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
903 */
904 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
905 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
906 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
907 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000908 hw->fc.current_mode = e1000_fc_rx_pause;
Auke Kok652fff32008-06-27 11:00:18 -0700909 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800910 }
911 /*
912 * Per the IEEE spec, at this point flow control should be
913 * disabled. However, we want to consider that we could
914 * be connected to a legacy switch that doesn't advertise
915 * desired flow control, but can be forced on the link
916 * partner. So if we advertised no flow control, that is
917 * what we will resolve to. If we advertised some kind of
918 * receive capability (Rx Pause Only or Full Flow Control)
919 * and the link partner advertised none, we will configure
920 * ourselves to enable Rx Flow Control only. We can do
921 * this safely for two reasons: If the link partner really
922 * didn't want flow control enabled, and we enable Rx, no
923 * harm done since we won't be receiving any PAUSE frames
924 * anyway. If the intent on the link partner was to have
925 * flow control enabled, then by us enabling RX only, we
926 * can at least receive pause frames and process them.
927 * This is a good idea because in most cases, since we are
928 * predominantly a server NIC, more times than not we will
929 * be asked to delay transmission of packets than asking
930 * our link partner to pause transmission of frames.
931 */
Alexander Duyck0cce1192009-07-23 18:10:24 +0000932 else if ((hw->fc.requested_mode == e1000_fc_none ||
933 hw->fc.requested_mode == e1000_fc_tx_pause) ||
Auke Kok9d5c8242008-01-24 02:22:38 -0800934 hw->fc.strict_ieee) {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000935 hw->fc.current_mode = e1000_fc_none;
Auke Kok652fff32008-06-27 11:00:18 -0700936 hw_dbg("Flow Control = NONE.\r\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800937 } else {
Alexander Duyck0cce1192009-07-23 18:10:24 +0000938 hw->fc.current_mode = e1000_fc_rx_pause;
Auke Kok652fff32008-06-27 11:00:18 -0700939 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800940 }
941
942 /*
943 * Now we need to do one last check... If we auto-
944 * negotiated to HALF DUPLEX, flow control should not be
945 * enabled per IEEE 802.3 spec.
946 */
947 ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
948 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700949 hw_dbg("Error getting link speed and duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800950 goto out;
951 }
952
953 if (duplex == HALF_DUPLEX)
Alexander Duyck0cce1192009-07-23 18:10:24 +0000954 hw->fc.current_mode = e1000_fc_none;
Auke Kok9d5c8242008-01-24 02:22:38 -0800955
956 /*
957 * Now we call a subroutine to actually force the MAC
958 * controller to use the correct flow control settings.
959 */
960 ret_val = igb_force_mac_fc(hw);
961 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -0700962 hw_dbg("Error forcing flow control settings\n");
Auke Kok9d5c8242008-01-24 02:22:38 -0800963 goto out;
964 }
965 }
966
967out:
968 return ret_val;
969}
970
971/**
Jeff Kirsher733596b2008-06-27 10:59:59 -0700972 * igb_get_speed_and_duplex_copper - Retreive current speed/duplex
Auke Kok9d5c8242008-01-24 02:22:38 -0800973 * @hw: pointer to the HW structure
974 * @speed: stores the current speed
975 * @duplex: stores the current duplex
976 *
977 * Read the status register for the current speed/duplex and store the current
978 * speed and duplex for copper connections.
979 **/
980s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
981 u16 *duplex)
982{
983 u32 status;
984
985 status = rd32(E1000_STATUS);
986 if (status & E1000_STATUS_SPEED_1000) {
987 *speed = SPEED_1000;
Auke Kok652fff32008-06-27 11:00:18 -0700988 hw_dbg("1000 Mbs, ");
Auke Kok9d5c8242008-01-24 02:22:38 -0800989 } else if (status & E1000_STATUS_SPEED_100) {
990 *speed = SPEED_100;
Auke Kok652fff32008-06-27 11:00:18 -0700991 hw_dbg("100 Mbs, ");
Auke Kok9d5c8242008-01-24 02:22:38 -0800992 } else {
993 *speed = SPEED_10;
Auke Kok652fff32008-06-27 11:00:18 -0700994 hw_dbg("10 Mbs, ");
Auke Kok9d5c8242008-01-24 02:22:38 -0800995 }
996
997 if (status & E1000_STATUS_FD) {
998 *duplex = FULL_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -0700999 hw_dbg("Full Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001000 } else {
1001 *duplex = HALF_DUPLEX;
Auke Kok652fff32008-06-27 11:00:18 -07001002 hw_dbg("Half Duplex\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001003 }
1004
1005 return 0;
1006}
1007
1008/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001009 * igb_get_hw_semaphore - Acquire hardware semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001010 * @hw: pointer to the HW structure
1011 *
1012 * Acquire the HW semaphore to access the PHY or NVM
1013 **/
1014s32 igb_get_hw_semaphore(struct e1000_hw *hw)
1015{
1016 u32 swsm;
1017 s32 ret_val = 0;
1018 s32 timeout = hw->nvm.word_size + 1;
1019 s32 i = 0;
1020
1021 /* Get the SW semaphore */
1022 while (i < timeout) {
1023 swsm = rd32(E1000_SWSM);
1024 if (!(swsm & E1000_SWSM_SMBI))
1025 break;
1026
1027 udelay(50);
1028 i++;
1029 }
1030
1031 if (i == timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001032 hw_dbg("Driver can't access device - SMBI bit is set.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001033 ret_val = -E1000_ERR_NVM;
1034 goto out;
1035 }
1036
1037 /* Get the FW semaphore. */
1038 for (i = 0; i < timeout; i++) {
1039 swsm = rd32(E1000_SWSM);
1040 wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
1041
1042 /* Semaphore acquired if bit latched */
1043 if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
1044 break;
1045
1046 udelay(50);
1047 }
1048
1049 if (i == timeout) {
1050 /* Release semaphores */
1051 igb_put_hw_semaphore(hw);
Auke Kok652fff32008-06-27 11:00:18 -07001052 hw_dbg("Driver can't access the NVM\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001053 ret_val = -E1000_ERR_NVM;
1054 goto out;
1055 }
1056
1057out:
1058 return ret_val;
1059}
1060
1061/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001062 * igb_put_hw_semaphore - Release hardware semaphore
Auke Kok9d5c8242008-01-24 02:22:38 -08001063 * @hw: pointer to the HW structure
1064 *
1065 * Release hardware semaphore used to access the PHY or NVM
1066 **/
1067void igb_put_hw_semaphore(struct e1000_hw *hw)
1068{
1069 u32 swsm;
1070
1071 swsm = rd32(E1000_SWSM);
1072
1073 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1074
1075 wr32(E1000_SWSM, swsm);
1076}
1077
1078/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001079 * igb_get_auto_rd_done - Check for auto read completion
Auke Kok9d5c8242008-01-24 02:22:38 -08001080 * @hw: pointer to the HW structure
1081 *
1082 * Check EEPROM for Auto Read done bit.
1083 **/
1084s32 igb_get_auto_rd_done(struct e1000_hw *hw)
1085{
1086 s32 i = 0;
1087 s32 ret_val = 0;
1088
1089
1090 while (i < AUTO_READ_DONE_TIMEOUT) {
1091 if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD)
1092 break;
1093 msleep(1);
1094 i++;
1095 }
1096
1097 if (i == AUTO_READ_DONE_TIMEOUT) {
Auke Kok652fff32008-06-27 11:00:18 -07001098 hw_dbg("Auto read by HW from NVM has not completed.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001099 ret_val = -E1000_ERR_RESET;
1100 goto out;
1101 }
1102
1103out:
1104 return ret_val;
1105}
1106
1107/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001108 * igb_valid_led_default - Verify a valid default LED config
Auke Kok9d5c8242008-01-24 02:22:38 -08001109 * @hw: pointer to the HW structure
1110 * @data: pointer to the NVM (EEPROM)
1111 *
1112 * Read the EEPROM for the current default LED configuration. If the
1113 * LED configuration is not valid, set to a valid LED configuration.
1114 **/
1115static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data)
1116{
1117 s32 ret_val;
1118
Alexander Duyck312c75a2009-02-06 23:17:47 +00001119 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
Auke Kok9d5c8242008-01-24 02:22:38 -08001120 if (ret_val) {
Auke Kok652fff32008-06-27 11:00:18 -07001121 hw_dbg("NVM Read Error\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001122 goto out;
1123 }
1124
Alexander Duyck099e1cb2009-07-23 18:07:40 +00001125 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
1126 switch(hw->phy.media_type) {
1127 case e1000_media_type_internal_serdes:
1128 *data = ID_LED_DEFAULT_82575_SERDES;
1129 break;
1130 case e1000_media_type_copper:
1131 default:
1132 *data = ID_LED_DEFAULT;
1133 break;
1134 }
1135 }
Auke Kok9d5c8242008-01-24 02:22:38 -08001136out:
1137 return ret_val;
1138}
1139
1140/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001141 * igb_id_led_init -
Auke Kok9d5c8242008-01-24 02:22:38 -08001142 * @hw: pointer to the HW structure
1143 *
1144 **/
1145s32 igb_id_led_init(struct e1000_hw *hw)
1146{
1147 struct e1000_mac_info *mac = &hw->mac;
1148 s32 ret_val;
1149 const u32 ledctl_mask = 0x000000FF;
1150 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
1151 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
1152 u16 data, i, temp;
1153 const u16 led_mask = 0x0F;
1154
1155 ret_val = igb_valid_led_default(hw, &data);
1156 if (ret_val)
1157 goto out;
1158
1159 mac->ledctl_default = rd32(E1000_LEDCTL);
1160 mac->ledctl_mode1 = mac->ledctl_default;
1161 mac->ledctl_mode2 = mac->ledctl_default;
1162
1163 for (i = 0; i < 4; i++) {
1164 temp = (data >> (i << 2)) & led_mask;
1165 switch (temp) {
1166 case ID_LED_ON1_DEF2:
1167 case ID_LED_ON1_ON2:
1168 case ID_LED_ON1_OFF2:
1169 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1170 mac->ledctl_mode1 |= ledctl_on << (i << 3);
1171 break;
1172 case ID_LED_OFF1_DEF2:
1173 case ID_LED_OFF1_ON2:
1174 case ID_LED_OFF1_OFF2:
1175 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1176 mac->ledctl_mode1 |= ledctl_off << (i << 3);
1177 break;
1178 default:
1179 /* Do nothing */
1180 break;
1181 }
1182 switch (temp) {
1183 case ID_LED_DEF1_ON2:
1184 case ID_LED_ON1_ON2:
1185 case ID_LED_OFF1_ON2:
1186 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1187 mac->ledctl_mode2 |= ledctl_on << (i << 3);
1188 break;
1189 case ID_LED_DEF1_OFF2:
1190 case ID_LED_ON1_OFF2:
1191 case ID_LED_OFF1_OFF2:
1192 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1193 mac->ledctl_mode2 |= ledctl_off << (i << 3);
1194 break;
1195 default:
1196 /* Do nothing */
1197 break;
1198 }
1199 }
1200
1201out:
1202 return ret_val;
1203}
1204
1205/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001206 * igb_cleanup_led - Set LED config to default operation
Auke Kok9d5c8242008-01-24 02:22:38 -08001207 * @hw: pointer to the HW structure
1208 *
1209 * Remove the current LED configuration and set the LED configuration
1210 * to the default value, saved from the EEPROM.
1211 **/
1212s32 igb_cleanup_led(struct e1000_hw *hw)
1213{
1214 wr32(E1000_LEDCTL, hw->mac.ledctl_default);
1215 return 0;
1216}
1217
1218/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001219 * igb_blink_led - Blink LED
Auke Kok9d5c8242008-01-24 02:22:38 -08001220 * @hw: pointer to the HW structure
1221 *
1222 * Blink the led's which are set to be on.
1223 **/
1224s32 igb_blink_led(struct e1000_hw *hw)
1225{
1226 u32 ledctl_blink = 0;
1227 u32 i;
1228
Alexander Duyckdcc3ae92009-07-23 18:07:20 +00001229 /*
1230 * set the blink bit for each LED that's "on" (0x0E)
1231 * in ledctl_mode2
1232 */
1233 ledctl_blink = hw->mac.ledctl_mode2;
1234 for (i = 0; i < 4; i++)
1235 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
1236 E1000_LEDCTL_MODE_LED_ON)
1237 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
1238 (i * 8));
Auke Kok9d5c8242008-01-24 02:22:38 -08001239
1240 wr32(E1000_LEDCTL, ledctl_blink);
1241
1242 return 0;
1243}
1244
1245/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001246 * igb_led_off - Turn LED off
Auke Kok9d5c8242008-01-24 02:22:38 -08001247 * @hw: pointer to the HW structure
1248 *
1249 * Turn LED off.
1250 **/
1251s32 igb_led_off(struct e1000_hw *hw)
1252{
Auke Kok9d5c8242008-01-24 02:22:38 -08001253 switch (hw->phy.media_type) {
Auke Kok9d5c8242008-01-24 02:22:38 -08001254 case e1000_media_type_copper:
1255 wr32(E1000_LEDCTL, hw->mac.ledctl_mode1);
1256 break;
1257 default:
1258 break;
1259 }
1260
1261 return 0;
1262}
1263
1264/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001265 * igb_disable_pcie_master - Disables PCI-express master access
Auke Kok9d5c8242008-01-24 02:22:38 -08001266 * @hw: pointer to the HW structure
1267 *
1268 * Returns 0 (0) if successful, else returns -10
1269 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not casued
1270 * the master requests to be disabled.
1271 *
1272 * Disables PCI-Express master access and verifies there are no pending
1273 * requests.
1274 **/
1275s32 igb_disable_pcie_master(struct e1000_hw *hw)
1276{
1277 u32 ctrl;
1278 s32 timeout = MASTER_DISABLE_TIMEOUT;
1279 s32 ret_val = 0;
1280
1281 if (hw->bus.type != e1000_bus_type_pci_express)
1282 goto out;
1283
1284 ctrl = rd32(E1000_CTRL);
1285 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
1286 wr32(E1000_CTRL, ctrl);
1287
1288 while (timeout) {
1289 if (!(rd32(E1000_STATUS) &
1290 E1000_STATUS_GIO_MASTER_ENABLE))
1291 break;
1292 udelay(100);
1293 timeout--;
1294 }
1295
1296 if (!timeout) {
Auke Kok652fff32008-06-27 11:00:18 -07001297 hw_dbg("Master requests are pending.\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001298 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
1299 goto out;
1300 }
1301
1302out:
1303 return ret_val;
1304}
1305
1306/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001307 * igb_validate_mdi_setting - Verify MDI/MDIx settings
Auke Kok9d5c8242008-01-24 02:22:38 -08001308 * @hw: pointer to the HW structure
1309 *
1310 * Verify that when not using auto-negotitation that MDI/MDIx is correctly
1311 * set, which is forced to MDI mode only.
1312 **/
1313s32 igb_validate_mdi_setting(struct e1000_hw *hw)
1314{
1315 s32 ret_val = 0;
1316
1317 if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
Auke Kok652fff32008-06-27 11:00:18 -07001318 hw_dbg("Invalid MDI setting detected\n");
Auke Kok9d5c8242008-01-24 02:22:38 -08001319 hw->phy.mdix = 1;
1320 ret_val = -E1000_ERR_CONFIG;
1321 goto out;
1322 }
1323
1324out:
1325 return ret_val;
1326}
1327
1328/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001329 * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register
Auke Kok9d5c8242008-01-24 02:22:38 -08001330 * @hw: pointer to the HW structure
1331 * @reg: 32bit register offset such as E1000_SCTL
1332 * @offset: register offset to write to
1333 * @data: data to write at register offset
1334 *
1335 * Writes an address/data control type register. There are several of these
1336 * and they all have the format address << 8 | data and bit 31 is polled for
1337 * completion.
1338 **/
1339s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg,
1340 u32 offset, u8 data)
1341{
1342 u32 i, regvalue = 0;
1343 s32 ret_val = 0;
1344
1345 /* Set up the address and data */
1346 regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
1347 wr32(reg, regvalue);
1348
1349 /* Poll the ready bit to see if the MDI read completed */
1350 for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
1351 udelay(5);
1352 regvalue = rd32(reg);
1353 if (regvalue & E1000_GEN_CTL_READY)
1354 break;
1355 }
1356 if (!(regvalue & E1000_GEN_CTL_READY)) {
Auke Kok652fff32008-06-27 11:00:18 -07001357 hw_dbg("Reg %08x did not indicate ready\n", reg);
Auke Kok9d5c8242008-01-24 02:22:38 -08001358 ret_val = -E1000_ERR_PHY;
1359 goto out;
1360 }
1361
1362out:
1363 return ret_val;
1364}
1365
1366/**
Jeff Kirsher733596b2008-06-27 10:59:59 -07001367 * igb_enable_mng_pass_thru - Enable processing of ARP's
Auke Kok9d5c8242008-01-24 02:22:38 -08001368 * @hw: pointer to the HW structure
1369 *
Alexander Duycke017b602010-03-25 17:15:06 +00001370 * Verifies the hardware needs to leave interface enabled so that frames can
1371 * be directed to and from the management interface.
Auke Kok9d5c8242008-01-24 02:22:38 -08001372 **/
1373bool igb_enable_mng_pass_thru(struct e1000_hw *hw)
1374{
1375 u32 manc;
1376 u32 fwsm, factps;
1377 bool ret_val = false;
1378
1379 if (!hw->mac.asf_firmware_present)
1380 goto out;
1381
1382 manc = rd32(E1000_MANC);
1383
Alexander Duycke017b602010-03-25 17:15:06 +00001384 if (!(manc & E1000_MANC_RCV_TCO_EN))
Auke Kok9d5c8242008-01-24 02:22:38 -08001385 goto out;
1386
1387 if (hw->mac.arc_subsystem_valid) {
1388 fwsm = rd32(E1000_FWSM);
1389 factps = rd32(E1000_FACTPS);
1390
1391 if (!(factps & E1000_FACTPS_MNGCG) &&
1392 ((fwsm & E1000_FWSM_MODE_MASK) ==
1393 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
1394 ret_val = true;
1395 goto out;
1396 }
1397 } else {
1398 if ((manc & E1000_MANC_SMBUS_EN) &&
1399 !(manc & E1000_MANC_ASF_EN)) {
1400 ret_val = true;
1401 goto out;
1402 }
1403 }
1404
1405out:
1406 return ret_val;
1407}