blob: 0893ab107adf320a5b07293fb64596e6e2794315 [file] [log] [blame]
Auke Kokbc7f75f2007-09-17 12:30:59 -07001/*******************************************************************************
2
3 Intel PRO/1000 Linux driver
Bruce Allan0d6057e2011-01-04 01:16:44 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kokbc7f75f2007-09-17 12:30:59 -07005
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 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
Auke Kokbc7f75f2007-09-17 12:30:59 -070029#include "e1000.h"
30
31enum e1000_mng_mode {
32 e1000_mng_mode_none = 0,
33 e1000_mng_mode_asf,
34 e1000_mng_mode_pt,
35 e1000_mng_mode_ipmi,
36 e1000_mng_mode_host_if_only
37};
38
39#define E1000_FACTPS_MNGCG 0x20000000
40
Bruce Allanad680762008-03-28 09:15:03 -070041/* Intel(R) Active Management Technology signature */
42#define E1000_IAMT_SIGNATURE 0x544D4149
Auke Kokbc7f75f2007-09-17 12:30:59 -070043
44/**
45 * e1000e_get_bus_info_pcie - Get PCIe bus information
46 * @hw: pointer to the HW structure
47 *
48 * Determines and stores the system bus information for a particular
49 * network interface. The following bus information is determined and stored:
50 * bus speed, bus width, type (PCIe), and PCIe function.
51 **/
52s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw)
53{
Bruce Allanf4d2dd42010-01-13 02:05:18 +000054 struct e1000_mac_info *mac = &hw->mac;
Auke Kokbc7f75f2007-09-17 12:30:59 -070055 struct e1000_bus_info *bus = &hw->bus;
56 struct e1000_adapter *adapter = hw->adapter;
Bruce Allanf4d2dd42010-01-13 02:05:18 +000057 u16 pcie_link_status, cap_offset;
Auke Kokbc7f75f2007-09-17 12:30:59 -070058
Jon Mason353064d2011-06-27 07:43:47 +000059 cap_offset = adapter->pdev->pcie_cap;
Auke Kokbc7f75f2007-09-17 12:30:59 -070060 if (!cap_offset) {
61 bus->width = e1000_bus_width_unknown;
62 } else {
63 pci_read_config_word(adapter->pdev,
64 cap_offset + PCIE_LINK_STATUS,
65 &pcie_link_status);
66 bus->width = (enum e1000_bus_width)((pcie_link_status &
67 PCIE_LINK_WIDTH_MASK) >>
68 PCIE_LINK_WIDTH_SHIFT);
69 }
70
Bruce Allanf4d2dd42010-01-13 02:05:18 +000071 mac->ops.set_lan_id(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -070072
73 return 0;
74}
75
76/**
Bruce Allanf4d2dd42010-01-13 02:05:18 +000077 * e1000_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
78 *
79 * @hw: pointer to the HW structure
80 *
81 * Determines the LAN function id by reading memory-mapped registers
82 * and swaps the port value if requested.
83 **/
84void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw)
85{
86 struct e1000_bus_info *bus = &hw->bus;
87 u32 reg;
88
89 /*
90 * The status register reports the correct function number
91 * for the device regardless of function swap state.
92 */
93 reg = er32(STATUS);
94 bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
95}
96
97/**
98 * e1000_set_lan_id_single_port - Set LAN id for a single port device
99 * @hw: pointer to the HW structure
100 *
101 * Sets the LAN function id to zero for a single port device.
102 **/
103void e1000_set_lan_id_single_port(struct e1000_hw *hw)
104{
105 struct e1000_bus_info *bus = &hw->bus;
106
107 bus->func = 0;
108}
109
110/**
Bruce Allancaaddaf2009-12-01 15:46:43 +0000111 * e1000_clear_vfta_generic - Clear VLAN filter table
112 * @hw: pointer to the HW structure
113 *
114 * Clears the register array which contains the VLAN filter table by
115 * setting all the values to 0.
116 **/
117void e1000_clear_vfta_generic(struct e1000_hw *hw)
118{
119 u32 offset;
120
121 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
122 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0);
123 e1e_flush();
124 }
125}
126
127/**
128 * e1000_write_vfta_generic - Write value to VLAN filter table
Auke Kokbc7f75f2007-09-17 12:30:59 -0700129 * @hw: pointer to the HW structure
130 * @offset: register offset in VLAN filter table
131 * @value: register value written to VLAN filter table
132 *
133 * Writes value at the given offset in the register array which stores
134 * the VLAN filter table.
135 **/
Bruce Allancaaddaf2009-12-01 15:46:43 +0000136void e1000_write_vfta_generic(struct e1000_hw *hw, u32 offset, u32 value)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700137{
138 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
139 e1e_flush();
140}
141
142/**
143 * e1000e_init_rx_addrs - Initialize receive address's
144 * @hw: pointer to the HW structure
145 * @rar_count: receive address registers
146 *
Bruce Alland64a6f42011-05-13 07:19:58 +0000147 * Setup the receive address registers by setting the base receive address
Auke Kokbc7f75f2007-09-17 12:30:59 -0700148 * register to the devices MAC address and clearing all the other receive
149 * address registers to 0.
150 **/
151void e1000e_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
152{
153 u32 i;
Bruce Allanb7a92162010-01-07 16:32:13 +0000154 u8 mac_addr[ETH_ALEN] = {0};
Auke Kokbc7f75f2007-09-17 12:30:59 -0700155
156 /* Setup the receive address */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000157 e_dbg("Programming MAC Address into RAR[0]\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700158
159 e1000e_rar_set(hw, hw->mac.addr, 0);
160
161 /* Zero out the other (rar_entry_count - 1) receive addresses */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000162 e_dbg("Clearing RAR[1-%u]\n", rar_count-1);
Bruce Allanb7a92162010-01-07 16:32:13 +0000163 for (i = 1; i < rar_count; i++)
164 e1000e_rar_set(hw, mac_addr, i);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700165}
166
167/**
Bruce Allan608f8a02010-01-13 02:04:58 +0000168 * e1000_check_alt_mac_addr_generic - Check for alternate MAC addr
169 * @hw: pointer to the HW structure
170 *
171 * Checks the nvm for an alternate MAC address. An alternate MAC address
172 * can be setup by pre-boot software and must be treated like a permanent
173 * address and must override the actual permanent MAC address. If an
174 * alternate MAC address is found it is programmed into RAR0, replacing
175 * the permanent address that was installed into RAR0 by the Si on reset.
176 * This function will return SUCCESS unless it encounters an error while
177 * reading the EEPROM.
178 **/
179s32 e1000_check_alt_mac_addr_generic(struct e1000_hw *hw)
180{
181 u32 i;
182 s32 ret_val = 0;
183 u16 offset, nvm_alt_mac_addr_offset, nvm_data;
184 u8 alt_mac_addr[ETH_ALEN];
185
Bruce Allan1aef70e2010-08-19 15:48:52 -0700186 ret_val = e1000_read_nvm(hw, NVM_COMPAT, 1, &nvm_data);
187 if (ret_val)
188 goto out;
189
190 /* Check for LOM (vs. NIC) or one of two valid mezzanine cards */
191 if (!((nvm_data & NVM_COMPAT_LOM) ||
192 (hw->adapter->pdev->device == E1000_DEV_ID_82571EB_SERDES_DUAL) ||
Bruce Allanc407bee2011-07-22 06:21:51 +0000193 (hw->adapter->pdev->device == E1000_DEV_ID_82571EB_SERDES_QUAD) ||
194 (hw->adapter->pdev->device == E1000_DEV_ID_82571EB_SERDES)))
Bruce Allan1aef70e2010-08-19 15:48:52 -0700195 goto out;
196
Bruce Allan608f8a02010-01-13 02:04:58 +0000197 ret_val = e1000_read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1,
198 &nvm_alt_mac_addr_offset);
199 if (ret_val) {
200 e_dbg("NVM Read Error\n");
201 goto out;
202 }
203
Bruce Allan244735f2011-07-29 05:53:07 +0000204 if ((nvm_alt_mac_addr_offset == 0xFFFF) ||
205 (nvm_alt_mac_addr_offset == 0x0000))
Bruce Allan608f8a02010-01-13 02:04:58 +0000206 /* There is no Alternate MAC Address */
207 goto out;
Bruce Allan608f8a02010-01-13 02:04:58 +0000208
209 if (hw->bus.func == E1000_FUNC_1)
210 nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
211 for (i = 0; i < ETH_ALEN; i += 2) {
212 offset = nvm_alt_mac_addr_offset + (i >> 1);
213 ret_val = e1000_read_nvm(hw, offset, 1, &nvm_data);
214 if (ret_val) {
215 e_dbg("NVM Read Error\n");
216 goto out;
217 }
218
219 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
220 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
221 }
222
223 /* if multicast bit is set, the alternate address will not be used */
Tobias Klauser3e714ad2011-07-03 23:47:04 +0000224 if (is_multicast_ether_addr(alt_mac_addr)) {
Bruce Allan608f8a02010-01-13 02:04:58 +0000225 e_dbg("Ignoring Alternate Mac Address with MC bit set\n");
226 goto out;
227 }
228
229 /*
230 * We have a valid alternate MAC address, and we want to treat it the
231 * same as the normal permanent MAC address stored by the HW into the
232 * RAR. Do this by mapping this address into RAR0.
233 */
234 e1000e_rar_set(hw, alt_mac_addr, 0);
235
236out:
237 return ret_val;
238}
239
240/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700241 * e1000e_rar_set - Set receive address register
242 * @hw: pointer to the HW structure
243 * @addr: pointer to the receive address
244 * @index: receive address array register
245 *
246 * Sets the receive address array register at index to the address passed
247 * in by addr.
248 **/
249void e1000e_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
250{
251 u32 rar_low, rar_high;
252
Bruce Allanad680762008-03-28 09:15:03 -0700253 /*
254 * HW expects these in little endian so we reverse the byte order
Auke Kokbc7f75f2007-09-17 12:30:59 -0700255 * from network order (big endian) to little endian
256 */
257 rar_low = ((u32) addr[0] |
258 ((u32) addr[1] << 8) |
259 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
260
261 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
262
Bruce Allanb7a92162010-01-07 16:32:13 +0000263 /* If MAC address zero, no need to set the AV bit */
264 if (rar_low || rar_high)
265 rar_high |= E1000_RAH_AV;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700266
Bruce Allanb7a92162010-01-07 16:32:13 +0000267 /*
268 * Some bridges will combine consecutive 32-bit writes into
269 * a single burst write, which will malfunction on some parts.
270 * The flushes avoid this.
271 */
272 ew32(RAL(index), rar_low);
273 e1e_flush();
274 ew32(RAH(index), rar_high);
275 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -0700276}
277
278/**
Auke Kokbc7f75f2007-09-17 12:30:59 -0700279 * e1000_hash_mc_addr - Generate a multicast hash value
280 * @hw: pointer to the HW structure
281 * @mc_addr: pointer to a multicast address
282 *
283 * Generates a multicast address hash value which is used to determine
284 * the multicast filter table array address and new table value. See
285 * e1000_mta_set_generic()
286 **/
287static u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
288{
289 u32 hash_value, hash_mask;
290 u8 bit_shift = 0;
291
292 /* Register count multiplied by bits per register */
293 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
294
Bruce Allanad680762008-03-28 09:15:03 -0700295 /*
296 * For a mc_filter_type of 0, bit_shift is the number of left-shifts
297 * where 0xFF would still fall within the hash mask.
298 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700299 while (hash_mask >> bit_shift != 0xFF)
300 bit_shift++;
301
Bruce Allanad680762008-03-28 09:15:03 -0700302 /*
303 * The portion of the address that is used for the hash table
Auke Kokbc7f75f2007-09-17 12:30:59 -0700304 * is determined by the mc_filter_type setting.
305 * The algorithm is such that there is a total of 8 bits of shifting.
306 * The bit_shift for a mc_filter_type of 0 represents the number of
307 * left-shifts where the MSB of mc_addr[5] would still fall within
308 * the hash_mask. Case 0 does this exactly. Since there are a total
309 * of 8 bits of shifting, then mc_addr[4] will shift right the
310 * remaining number of bits. Thus 8 - bit_shift. The rest of the
311 * cases are a variation of this algorithm...essentially raising the
312 * number of bits to shift mc_addr[5] left, while still keeping the
313 * 8-bit shifting total.
Bruce Allanad680762008-03-28 09:15:03 -0700314 *
315 * For example, given the following Destination MAC Address and an
Auke Kokbc7f75f2007-09-17 12:30:59 -0700316 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
317 * we can see that the bit_shift for case 0 is 4. These are the hash
318 * values resulting from each mc_filter_type...
319 * [0] [1] [2] [3] [4] [5]
320 * 01 AA 00 12 34 56
321 * LSB MSB
322 *
323 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
324 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
325 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
326 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
327 */
328 switch (hw->mac.mc_filter_type) {
329 default:
330 case 0:
331 break;
332 case 1:
333 bit_shift += 1;
334 break;
335 case 2:
336 bit_shift += 2;
337 break;
338 case 3:
339 bit_shift += 4;
340 break;
341 }
342
343 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
344 (((u16) mc_addr[5]) << bit_shift)));
345
346 return hash_value;
347}
348
349/**
Jeff Kirshere2de3eb2008-03-28 09:15:11 -0700350 * e1000e_update_mc_addr_list_generic - Update Multicast addresses
Auke Kokbc7f75f2007-09-17 12:30:59 -0700351 * @hw: pointer to the HW structure
352 * @mc_addr_list: array of multicast addresses to program
353 * @mc_addr_count: number of multicast addresses to program
Auke Kokbc7f75f2007-09-17 12:30:59 -0700354 *
Bruce Allanab8932f2010-01-13 02:05:38 +0000355 * Updates entire Multicast Table Array.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700356 * The caller must have a packed mc_addr_list of multicast addresses.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700357 **/
Jeff Kirshere2de3eb2008-03-28 09:15:11 -0700358void e1000e_update_mc_addr_list_generic(struct e1000_hw *hw,
Bruce Allanab8932f2010-01-13 02:05:38 +0000359 u8 *mc_addr_list, u32 mc_addr_count)
Auke Kokbc7f75f2007-09-17 12:30:59 -0700360{
Bruce Allanab8932f2010-01-13 02:05:38 +0000361 u32 hash_value, hash_bit, hash_reg;
362 int i;
Jesse Brandeburga72d2b22009-03-25 22:05:21 +0000363
Bruce Allanab8932f2010-01-13 02:05:38 +0000364 /* clear mta_shadow */
365 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
Auke Kokbc7f75f2007-09-17 12:30:59 -0700366
Bruce Allanab8932f2010-01-13 02:05:38 +0000367 /* update mta_shadow from mc_addr_list */
368 for (i = 0; (u32) i < mc_addr_count; i++) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700369 hash_value = e1000_hash_mc_addr(hw, mc_addr_list);
Bruce Allanab8932f2010-01-13 02:05:38 +0000370
Jesse Brandeburga72d2b22009-03-25 22:05:21 +0000371 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
372 hash_bit = hash_value & 0x1F;
Bruce Allanab8932f2010-01-13 02:05:38 +0000373
374 hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
375 mc_addr_list += (ETH_ALEN);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700376 }
Jesse Brandeburga72d2b22009-03-25 22:05:21 +0000377
Bruce Allanab8932f2010-01-13 02:05:38 +0000378 /* replace the entire MTA table */
379 for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
380 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, hw->mac.mta_shadow[i]);
Jesse Brandeburga72d2b22009-03-25 22:05:21 +0000381 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -0700382}
383
384/**
385 * e1000e_clear_hw_cntrs_base - Clear base hardware counters
386 * @hw: pointer to the HW structure
387 *
388 * Clears the base hardware counters by reading the counter registers.
389 **/
390void e1000e_clear_hw_cntrs_base(struct e1000_hw *hw)
391{
Bruce Allan99673d92009-11-20 23:27:21 +0000392 er32(CRCERRS);
393 er32(SYMERRS);
394 er32(MPC);
395 er32(SCC);
396 er32(ECOL);
397 er32(MCC);
398 er32(LATECOL);
399 er32(COLC);
400 er32(DC);
401 er32(SEC);
402 er32(RLEC);
403 er32(XONRXC);
404 er32(XONTXC);
405 er32(XOFFRXC);
406 er32(XOFFTXC);
407 er32(FCRUC);
408 er32(GPRC);
409 er32(BPRC);
410 er32(MPRC);
411 er32(GPTC);
412 er32(GORCL);
413 er32(GORCH);
414 er32(GOTCL);
415 er32(GOTCH);
416 er32(RNBC);
417 er32(RUC);
418 er32(RFC);
419 er32(ROC);
420 er32(RJC);
421 er32(TORL);
422 er32(TORH);
423 er32(TOTL);
424 er32(TOTH);
425 er32(TPR);
426 er32(TPT);
427 er32(MPTC);
428 er32(BPTC);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700429}
430
431/**
432 * e1000e_check_for_copper_link - Check for link (Copper)
433 * @hw: pointer to the HW structure
434 *
435 * Checks to see of the link status of the hardware has changed. If a
436 * change in link status has been detected, then we read the PHY registers
437 * to get the current speed/duplex if link exists.
438 **/
439s32 e1000e_check_for_copper_link(struct e1000_hw *hw)
440{
441 struct e1000_mac_info *mac = &hw->mac;
442 s32 ret_val;
443 bool link;
444
Bruce Allanad680762008-03-28 09:15:03 -0700445 /*
446 * We only want to go out to the PHY registers to see if Auto-Neg
Auke Kokbc7f75f2007-09-17 12:30:59 -0700447 * has completed and/or if our link status has changed. The
448 * get_link_status flag is set upon receiving a Link Status
449 * Change or Rx Sequence Error interrupt.
450 */
451 if (!mac->get_link_status)
452 return 0;
453
Bruce Allanad680762008-03-28 09:15:03 -0700454 /*
455 * First we want to see if the MII Status Register reports
Auke Kokbc7f75f2007-09-17 12:30:59 -0700456 * link. If so, then we want to get the current speed/duplex
457 * of the PHY.
458 */
459 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
460 if (ret_val)
461 return ret_val;
462
463 if (!link)
464 return ret_val; /* No link detected */
465
Bruce Allan564ea9b2009-11-20 23:26:44 +0000466 mac->get_link_status = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700467
Bruce Allanad680762008-03-28 09:15:03 -0700468 /*
469 * Check if there was DownShift, must be checked
470 * immediately after link-up
471 */
Auke Kokbc7f75f2007-09-17 12:30:59 -0700472 e1000e_check_downshift(hw);
473
Bruce Allanad680762008-03-28 09:15:03 -0700474 /*
475 * If we are forcing speed/duplex, then we simply return since
Auke Kokbc7f75f2007-09-17 12:30:59 -0700476 * we have already determined whether we have link or not.
477 */
478 if (!mac->autoneg) {
479 ret_val = -E1000_ERR_CONFIG;
480 return ret_val;
481 }
482
Bruce Allanad680762008-03-28 09:15:03 -0700483 /*
484 * Auto-Neg is enabled. Auto Speed Detection takes care
Auke Kokbc7f75f2007-09-17 12:30:59 -0700485 * of MAC speed/duplex configuration. So we only need to
486 * configure Collision Distance in the MAC.
487 */
488 e1000e_config_collision_dist(hw);
489
Bruce Allanad680762008-03-28 09:15:03 -0700490 /*
491 * Configure Flow Control now that Auto-Neg has completed.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700492 * First, we need to restore the desired flow control
493 * settings because we may have had to re-autoneg with a
494 * different link partner.
495 */
496 ret_val = e1000e_config_fc_after_link_up(hw);
Bruce Allanb1cdfea2010-12-11 05:53:47 +0000497 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000498 e_dbg("Error configuring flow control\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700499
500 return ret_val;
501}
502
503/**
504 * e1000e_check_for_fiber_link - Check for link (Fiber)
505 * @hw: pointer to the HW structure
506 *
507 * Checks for link up on the hardware. If link is not up and we have
508 * a signal, then we need to force link up.
509 **/
510s32 e1000e_check_for_fiber_link(struct e1000_hw *hw)
511{
512 struct e1000_mac_info *mac = &hw->mac;
513 u32 rxcw;
514 u32 ctrl;
515 u32 status;
516 s32 ret_val;
517
518 ctrl = er32(CTRL);
519 status = er32(STATUS);
520 rxcw = er32(RXCW);
521
Bruce Allanad680762008-03-28 09:15:03 -0700522 /*
523 * If we don't have link (auto-negotiation failed or link partner
Auke Kokbc7f75f2007-09-17 12:30:59 -0700524 * cannot auto-negotiate), the cable is plugged in (we have signal),
525 * and our link partner is not trying to auto-negotiate with us (we
526 * are receiving idles or data), we need to force link up. We also
527 * need to give auto-negotiation time to complete, in case the cable
528 * was just plugged in. The autoneg_failed flag does this.
529 */
530 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
531 if ((ctrl & E1000_CTRL_SWDPIN1) && (!(status & E1000_STATUS_LU)) &&
532 (!(rxcw & E1000_RXCW_C))) {
533 if (mac->autoneg_failed == 0) {
534 mac->autoneg_failed = 1;
535 return 0;
536 }
Bruce Allanaf667a22010-12-31 06:10:01 +0000537 e_dbg("NOT Rx'ing /C/, disable AutoNeg and force link.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700538
539 /* Disable auto-negotiation in the TXCW register */
540 ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
541
542 /* Force link-up and also force full-duplex. */
543 ctrl = er32(CTRL);
544 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
545 ew32(CTRL, ctrl);
546
547 /* Configure Flow Control after forcing link up. */
548 ret_val = e1000e_config_fc_after_link_up(hw);
549 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000550 e_dbg("Error configuring flow control\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700551 return ret_val;
552 }
553 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Bruce Allanad680762008-03-28 09:15:03 -0700554 /*
555 * If we are forcing link and we are receiving /C/ ordered
Auke Kokbc7f75f2007-09-17 12:30:59 -0700556 * sets, re-enable auto-negotiation in the TXCW register
557 * and disable forced link in the Device Control register
558 * in an attempt to auto-negotiate with our link partner.
559 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000560 e_dbg("Rx'ing /C/, enable AutoNeg and stop forcing link.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700561 ew32(TXCW, mac->txcw);
562 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
563
Alex Chiang612e2442009-02-05 23:55:45 -0800564 mac->serdes_has_link = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700565 }
566
567 return 0;
568}
569
570/**
571 * e1000e_check_for_serdes_link - Check for link (Serdes)
572 * @hw: pointer to the HW structure
573 *
574 * Checks for link up on the hardware. If link is not up and we have
575 * a signal, then we need to force link up.
576 **/
577s32 e1000e_check_for_serdes_link(struct e1000_hw *hw)
578{
579 struct e1000_mac_info *mac = &hw->mac;
580 u32 rxcw;
581 u32 ctrl;
582 u32 status;
583 s32 ret_val;
584
585 ctrl = er32(CTRL);
586 status = er32(STATUS);
587 rxcw = er32(RXCW);
588
Bruce Allanad680762008-03-28 09:15:03 -0700589 /*
590 * If we don't have link (auto-negotiation failed or link partner
Auke Kokbc7f75f2007-09-17 12:30:59 -0700591 * cannot auto-negotiate), and our link partner is not trying to
592 * auto-negotiate with us (we are receiving idles or data),
593 * we need to force link up. We also need to give auto-negotiation
594 * time to complete.
595 */
596 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
597 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
598 if (mac->autoneg_failed == 0) {
599 mac->autoneg_failed = 1;
600 return 0;
601 }
Bruce Allanaf667a22010-12-31 06:10:01 +0000602 e_dbg("NOT Rx'ing /C/, disable AutoNeg and force link.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700603
604 /* Disable auto-negotiation in the TXCW register */
605 ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
606
607 /* Force link-up and also force full-duplex. */
608 ctrl = er32(CTRL);
609 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
610 ew32(CTRL, ctrl);
611
612 /* Configure Flow Control after forcing link up. */
613 ret_val = e1000e_config_fc_after_link_up(hw);
614 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000615 e_dbg("Error configuring flow control\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700616 return ret_val;
617 }
618 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
Bruce Allanad680762008-03-28 09:15:03 -0700619 /*
620 * If we are forcing link and we are receiving /C/ ordered
Auke Kokbc7f75f2007-09-17 12:30:59 -0700621 * sets, re-enable auto-negotiation in the TXCW register
622 * and disable forced link in the Device Control register
623 * in an attempt to auto-negotiate with our link partner.
624 */
Bruce Allanaf667a22010-12-31 06:10:01 +0000625 e_dbg("Rx'ing /C/, enable AutoNeg and stop forcing link.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700626 ew32(TXCW, mac->txcw);
627 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
628
Alex Chiang612e2442009-02-05 23:55:45 -0800629 mac->serdes_has_link = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700630 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
Bruce Allanad680762008-03-28 09:15:03 -0700631 /*
632 * If we force link for non-auto-negotiation switch, check
Auke Kokbc7f75f2007-09-17 12:30:59 -0700633 * link status based on MAC synchronization for internal
634 * serdes media type.
635 */
636 /* SYNCH bit and IV bit are sticky. */
637 udelay(10);
Bruce Allan63dcf3d2008-11-21 16:50:34 -0800638 rxcw = er32(RXCW);
639 if (rxcw & E1000_RXCW_SYNCH) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700640 if (!(rxcw & E1000_RXCW_IV)) {
Bruce Allan63dcf3d2008-11-21 16:50:34 -0800641 mac->serdes_has_link = true;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000642 e_dbg("SERDES: Link up - forced.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700643 }
644 } else {
Bruce Allan63dcf3d2008-11-21 16:50:34 -0800645 mac->serdes_has_link = false;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000646 e_dbg("SERDES: Link down - force failed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700647 }
648 }
649
650 if (E1000_TXCW_ANE & er32(TXCW)) {
651 status = er32(STATUS);
Bruce Allan63dcf3d2008-11-21 16:50:34 -0800652 if (status & E1000_STATUS_LU) {
653 /* SYNCH bit and IV bit are sticky, so reread rxcw. */
654 udelay(10);
655 rxcw = er32(RXCW);
656 if (rxcw & E1000_RXCW_SYNCH) {
657 if (!(rxcw & E1000_RXCW_IV)) {
658 mac->serdes_has_link = true;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000659 e_dbg("SERDES: Link up - autoneg "
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800660 "completed successfully.\n");
Bruce Allan63dcf3d2008-11-21 16:50:34 -0800661 } else {
662 mac->serdes_has_link = false;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000663 e_dbg("SERDES: Link down - invalid"
Bruce Allan63dcf3d2008-11-21 16:50:34 -0800664 "codewords detected in autoneg.\n");
665 }
666 } else {
667 mac->serdes_has_link = false;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000668 e_dbg("SERDES: Link down - no sync.\n");
Bruce Allan63dcf3d2008-11-21 16:50:34 -0800669 }
670 } else {
671 mac->serdes_has_link = false;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000672 e_dbg("SERDES: Link down - autoneg failed\n");
Bruce Allan63dcf3d2008-11-21 16:50:34 -0800673 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700674 }
675
676 return 0;
677}
678
679/**
680 * e1000_set_default_fc_generic - Set flow control default values
681 * @hw: pointer to the HW structure
682 *
683 * Read the EEPROM for the default values for flow control and store the
684 * values.
685 **/
686static s32 e1000_set_default_fc_generic(struct e1000_hw *hw)
687{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700688 s32 ret_val;
689 u16 nvm_data;
690
Bruce Allanad680762008-03-28 09:15:03 -0700691 /*
692 * Read and store word 0x0F of the EEPROM. This word contains bits
Auke Kokbc7f75f2007-09-17 12:30:59 -0700693 * that determine the hardware's default PAUSE (flow control) mode,
694 * a bit that determines whether the HW defaults to enabling or
695 * disabling auto-negotiation, and the direction of the
696 * SW defined pins. If there is no SW over-ride of the flow
697 * control setting, then the variable hw->fc will
698 * be initialized based on a value in the EEPROM.
699 */
700 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
701
702 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000703 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700704 return ret_val;
705 }
706
707 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800708 hw->fc.requested_mode = e1000_fc_none;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700709 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
710 NVM_WORD0F_ASM_DIR)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800711 hw->fc.requested_mode = e1000_fc_tx_pause;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700712 else
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800713 hw->fc.requested_mode = e1000_fc_full;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700714
715 return 0;
716}
717
718/**
719 * e1000e_setup_link - Setup flow control and link settings
720 * @hw: pointer to the HW structure
721 *
722 * Determines which flow control settings to use, then configures flow
723 * control. Calls the appropriate media-specific link configuration
724 * function. Assuming the adapter has a valid link partner, a valid link
725 * should be established. Assumes the hardware has previously been reset
726 * and the transmitter and receiver are not enabled.
727 **/
728s32 e1000e_setup_link(struct e1000_hw *hw)
729{
730 struct e1000_mac_info *mac = &hw->mac;
731 s32 ret_val;
732
Bruce Allanad680762008-03-28 09:15:03 -0700733 /*
734 * In the case of the phy reset being blocked, we already have a link.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700735 * We do not need to set it up again.
736 */
737 if (e1000_check_reset_block(hw))
738 return 0;
739
Auke Kok309af402007-10-05 15:22:02 -0700740 /*
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800741 * If requested flow control is set to default, set flow control
742 * based on the EEPROM flow control settings.
Auke Kok309af402007-10-05 15:22:02 -0700743 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800744 if (hw->fc.requested_mode == e1000_fc_default) {
Auke Kok309af402007-10-05 15:22:02 -0700745 ret_val = e1000_set_default_fc_generic(hw);
746 if (ret_val)
747 return ret_val;
748 }
Auke Kokbc7f75f2007-09-17 12:30:59 -0700749
Bruce Allanad680762008-03-28 09:15:03 -0700750 /*
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800751 * Save off the requested flow control mode for use later. Depending
752 * on the link partner's capabilities, we may or may not use this mode.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700753 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800754 hw->fc.current_mode = hw->fc.requested_mode;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700755
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000756 e_dbg("After fix-ups FlowControl is now = %x\n",
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800757 hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700758
759 /* Call the necessary media_type subroutine to configure the link. */
760 ret_val = mac->ops.setup_physical_interface(hw);
761 if (ret_val)
762 return ret_val;
763
Bruce Allanad680762008-03-28 09:15:03 -0700764 /*
765 * Initialize the flow control address, type, and PAUSE timer
Auke Kokbc7f75f2007-09-17 12:30:59 -0700766 * registers to their default values. This is done even if flow
767 * control is disabled, because it does not hurt anything to
768 * initialize these registers.
769 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000770 e_dbg("Initializing the Flow Control address, type and timer regs\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700771 ew32(FCT, FLOW_CONTROL_TYPE);
772 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
773 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
774
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700775 ew32(FCTTV, hw->fc.pause_time);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700776
777 return e1000e_set_fc_watermarks(hw);
778}
779
780/**
781 * e1000_commit_fc_settings_generic - Configure flow control
782 * @hw: pointer to the HW structure
783 *
784 * Write the flow control settings to the Transmit Config Word Register (TXCW)
785 * base on the flow control settings in e1000_mac_info.
786 **/
787static s32 e1000_commit_fc_settings_generic(struct e1000_hw *hw)
788{
789 struct e1000_mac_info *mac = &hw->mac;
790 u32 txcw;
791
Bruce Allanad680762008-03-28 09:15:03 -0700792 /*
793 * Check for a software override of the flow control settings, and
Auke Kokbc7f75f2007-09-17 12:30:59 -0700794 * setup the device accordingly. If auto-negotiation is enabled, then
795 * software will have to set the "PAUSE" bits to the correct value in
796 * the Transmit Config Word Register (TXCW) and re-start auto-
797 * negotiation. However, if auto-negotiation is disabled, then
798 * software will have to manually configure the two flow control enable
799 * bits in the CTRL register.
800 *
801 * The possible values of the "fc" parameter are:
802 * 0: Flow control is completely disabled
803 * 1: Rx flow control is enabled (we can receive pause frames,
Bruce Allanaf667a22010-12-31 06:10:01 +0000804 * but not send pause frames).
Auke Kokbc7f75f2007-09-17 12:30:59 -0700805 * 2: Tx flow control is enabled (we can send pause frames but we
Bruce Allanaf667a22010-12-31 06:10:01 +0000806 * do not support receiving pause frames).
Bruce Allanad680762008-03-28 09:15:03 -0700807 * 3: Both Rx and Tx flow control (symmetric) are enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700808 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800809 switch (hw->fc.current_mode) {
Auke Kokbc7f75f2007-09-17 12:30:59 -0700810 case e1000_fc_none:
811 /* Flow control completely disabled by a software over-ride. */
812 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
813 break;
814 case e1000_fc_rx_pause:
Bruce Allanad680762008-03-28 09:15:03 -0700815 /*
816 * Rx Flow control is enabled and Tx Flow control is disabled
Auke Kokbc7f75f2007-09-17 12:30:59 -0700817 * by a software over-ride. Since there really isn't a way to
Bruce Allanad680762008-03-28 09:15:03 -0700818 * advertise that we are capable of Rx Pause ONLY, we will
819 * advertise that we support both symmetric and asymmetric Rx
Auke Kokbc7f75f2007-09-17 12:30:59 -0700820 * PAUSE. Later, we will disable the adapter's ability to send
821 * PAUSE frames.
822 */
823 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
824 break;
825 case e1000_fc_tx_pause:
Bruce Allanad680762008-03-28 09:15:03 -0700826 /*
827 * Tx Flow control is enabled, and Rx Flow control is disabled,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700828 * by a software over-ride.
829 */
830 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
831 break;
832 case e1000_fc_full:
Bruce Allanad680762008-03-28 09:15:03 -0700833 /*
834 * Flow control (both Rx and Tx) is enabled by a software
Auke Kokbc7f75f2007-09-17 12:30:59 -0700835 * over-ride.
836 */
837 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
838 break;
839 default:
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000840 e_dbg("Flow control param set incorrectly\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700841 return -E1000_ERR_CONFIG;
842 break;
843 }
844
845 ew32(TXCW, txcw);
846 mac->txcw = txcw;
847
848 return 0;
849}
850
851/**
852 * e1000_poll_fiber_serdes_link_generic - Poll for link up
853 * @hw: pointer to the HW structure
854 *
855 * Polls for link up by reading the status register, if link fails to come
856 * up with auto-negotiation, then the link is forced if a signal is detected.
857 **/
858static s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw)
859{
860 struct e1000_mac_info *mac = &hw->mac;
861 u32 i, status;
862 s32 ret_val;
863
Bruce Allanad680762008-03-28 09:15:03 -0700864 /*
865 * If we have a signal (the cable is plugged in, or assumed true for
Auke Kokbc7f75f2007-09-17 12:30:59 -0700866 * serdes media) then poll for a "Link-Up" indication in the Device
867 * Status Register. Time-out if a link isn't seen in 500 milliseconds
868 * seconds (Auto-negotiation should complete in less than 500
869 * milliseconds even if the other end is doing it in SW).
870 */
871 for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
Bruce Allan1bba4382011-03-19 00:27:20 +0000872 usleep_range(10000, 20000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700873 status = er32(STATUS);
874 if (status & E1000_STATUS_LU)
875 break;
876 }
877 if (i == FIBER_LINK_UP_LIMIT) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000878 e_dbg("Never got a valid link from auto-neg!!!\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700879 mac->autoneg_failed = 1;
Bruce Allanad680762008-03-28 09:15:03 -0700880 /*
881 * AutoNeg failed to achieve a link, so we'll call
Auke Kokbc7f75f2007-09-17 12:30:59 -0700882 * mac->check_for_link. This routine will force the
883 * link up if we detect a signal. This will allow us to
884 * communicate with non-autonegotiating link partners.
885 */
886 ret_val = mac->ops.check_for_link(hw);
887 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000888 e_dbg("Error while checking for link\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700889 return ret_val;
890 }
891 mac->autoneg_failed = 0;
892 } else {
893 mac->autoneg_failed = 0;
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000894 e_dbg("Valid Link Found\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700895 }
896
897 return 0;
898}
899
900/**
901 * e1000e_setup_fiber_serdes_link - Setup link for fiber/serdes
902 * @hw: pointer to the HW structure
903 *
904 * Configures collision distance and flow control for fiber and serdes
905 * links. Upon successful setup, poll for link.
906 **/
907s32 e1000e_setup_fiber_serdes_link(struct e1000_hw *hw)
908{
909 u32 ctrl;
910 s32 ret_val;
911
912 ctrl = er32(CTRL);
913
914 /* Take the link out of reset */
915 ctrl &= ~E1000_CTRL_LRST;
916
917 e1000e_config_collision_dist(hw);
918
919 ret_val = e1000_commit_fc_settings_generic(hw);
920 if (ret_val)
921 return ret_val;
922
Bruce Allanad680762008-03-28 09:15:03 -0700923 /*
924 * Since auto-negotiation is enabled, take the link out of reset (the
Auke Kokbc7f75f2007-09-17 12:30:59 -0700925 * link will be in reset, because we previously reset the chip). This
926 * will restart auto-negotiation. If auto-negotiation is successful
927 * then the link-up status bit will be set and the flow control enable
928 * bits (RFCE and TFCE) will be set according to their negotiated value.
929 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000930 e_dbg("Auto-negotiation enabled\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700931
932 ew32(CTRL, ctrl);
933 e1e_flush();
Bruce Allan1bba4382011-03-19 00:27:20 +0000934 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -0700935
Bruce Allanad680762008-03-28 09:15:03 -0700936 /*
937 * For these adapters, the SW definable pin 1 is set when the optics
Auke Kokbc7f75f2007-09-17 12:30:59 -0700938 * detect a signal. If we have a signal, then poll for a "Link-Up"
939 * indication.
940 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700941 if (hw->phy.media_type == e1000_media_type_internal_serdes ||
Auke Kokbc7f75f2007-09-17 12:30:59 -0700942 (er32(CTRL) & E1000_CTRL_SWDPIN1)) {
943 ret_val = e1000_poll_fiber_serdes_link_generic(hw);
944 } else {
Bruce Allan3bb99fe2009-11-20 23:25:07 +0000945 e_dbg("No signal detected\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -0700946 }
947
948 return 0;
949}
950
951/**
952 * e1000e_config_collision_dist - Configure collision distance
953 * @hw: pointer to the HW structure
954 *
955 * Configures the collision distance to the default value and is used
956 * during link setup. Currently no func pointer exists and all
957 * implementations are handled in the generic version of this function.
958 **/
959void e1000e_config_collision_dist(struct e1000_hw *hw)
960{
961 u32 tctl;
962
963 tctl = er32(TCTL);
964
965 tctl &= ~E1000_TCTL_COLD;
966 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
967
968 ew32(TCTL, tctl);
969 e1e_flush();
970}
971
972/**
973 * e1000e_set_fc_watermarks - Set flow control high/low watermarks
974 * @hw: pointer to the HW structure
975 *
976 * Sets the flow control high/low threshold (watermark) registers. If
977 * flow control XON frame transmission is enabled, then set XON frame
Bruce Allanad680762008-03-28 09:15:03 -0700978 * transmission as well.
Auke Kokbc7f75f2007-09-17 12:30:59 -0700979 **/
980s32 e1000e_set_fc_watermarks(struct e1000_hw *hw)
981{
Auke Kokbc7f75f2007-09-17 12:30:59 -0700982 u32 fcrtl = 0, fcrth = 0;
983
Bruce Allanad680762008-03-28 09:15:03 -0700984 /*
985 * Set the flow control receive threshold registers. Normally,
Auke Kokbc7f75f2007-09-17 12:30:59 -0700986 * these registers will be set to a default threshold that may be
987 * adjusted later by the driver's runtime code. However, if the
988 * ability to transmit pause frames is not enabled, then these
989 * registers will be set to 0.
990 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -0800991 if (hw->fc.current_mode & e1000_fc_tx_pause) {
Bruce Allanad680762008-03-28 09:15:03 -0700992 /*
993 * We need to set up the Receive Threshold high and low water
Auke Kokbc7f75f2007-09-17 12:30:59 -0700994 * marks as well as (optionally) enabling the transmission of
995 * XON frames.
996 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700997 fcrtl = hw->fc.low_water;
Auke Kokbc7f75f2007-09-17 12:30:59 -0700998 fcrtl |= E1000_FCRTL_XONE;
Jeff Kirsher318a94d2008-03-28 09:15:16 -0700999 fcrth = hw->fc.high_water;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001000 }
1001 ew32(FCRTL, fcrtl);
1002 ew32(FCRTH, fcrth);
1003
1004 return 0;
1005}
1006
1007/**
1008 * e1000e_force_mac_fc - Force the MAC's flow control settings
1009 * @hw: pointer to the HW structure
1010 *
1011 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
1012 * device control register to reflect the adapter settings. TFCE and RFCE
1013 * need to be explicitly set by software when a copper PHY is used because
1014 * autonegotiation is managed by the PHY rather than the MAC. Software must
1015 * also configure these bits when link is forced on a fiber connection.
1016 **/
1017s32 e1000e_force_mac_fc(struct e1000_hw *hw)
1018{
Auke Kokbc7f75f2007-09-17 12:30:59 -07001019 u32 ctrl;
1020
1021 ctrl = er32(CTRL);
1022
Bruce Allanad680762008-03-28 09:15:03 -07001023 /*
1024 * Because we didn't get link via the internal auto-negotiation
Auke Kokbc7f75f2007-09-17 12:30:59 -07001025 * mechanism (we either forced link or we got link via PHY
1026 * auto-neg), we have to manually enable/disable transmit an
1027 * receive flow control.
1028 *
1029 * The "Case" statement below enables/disable flow control
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001030 * according to the "hw->fc.current_mode" parameter.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001031 *
1032 * The possible values of the "fc" parameter are:
1033 * 0: Flow control is completely disabled
1034 * 1: Rx flow control is enabled (we can receive pause
Bruce Allanaf667a22010-12-31 06:10:01 +00001035 * frames but not send pause frames).
Auke Kokbc7f75f2007-09-17 12:30:59 -07001036 * 2: Tx flow control is enabled (we can send pause frames
Bruce Allanaf667a22010-12-31 06:10:01 +00001037 * frames but we do not receive pause frames).
Bruce Allanad680762008-03-28 09:15:03 -07001038 * 3: Both Rx and Tx flow control (symmetric) is enabled.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001039 * other: No other values should be possible at this point.
1040 */
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001041 e_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001042
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001043 switch (hw->fc.current_mode) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001044 case e1000_fc_none:
1045 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
1046 break;
1047 case e1000_fc_rx_pause:
1048 ctrl &= (~E1000_CTRL_TFCE);
1049 ctrl |= E1000_CTRL_RFCE;
1050 break;
1051 case e1000_fc_tx_pause:
1052 ctrl &= (~E1000_CTRL_RFCE);
1053 ctrl |= E1000_CTRL_TFCE;
1054 break;
1055 case e1000_fc_full:
1056 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
1057 break;
1058 default:
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001059 e_dbg("Flow control param set incorrectly\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001060 return -E1000_ERR_CONFIG;
1061 }
1062
1063 ew32(CTRL, ctrl);
1064
1065 return 0;
1066}
1067
1068/**
1069 * e1000e_config_fc_after_link_up - Configures flow control after link
1070 * @hw: pointer to the HW structure
1071 *
1072 * Checks the status of auto-negotiation after link up to ensure that the
1073 * speed and duplex were not forced. If the link needed to be forced, then
1074 * flow control needs to be forced also. If auto-negotiation is enabled
1075 * and did not fail, then we configure flow control based on our link
1076 * partner.
1077 **/
1078s32 e1000e_config_fc_after_link_up(struct e1000_hw *hw)
1079{
1080 struct e1000_mac_info *mac = &hw->mac;
1081 s32 ret_val = 0;
1082 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
1083 u16 speed, duplex;
1084
Bruce Allanad680762008-03-28 09:15:03 -07001085 /*
1086 * Check for the case where we have fiber media and auto-neg failed
Auke Kokbc7f75f2007-09-17 12:30:59 -07001087 * so we had to force link. In this case, we need to force the
1088 * configuration of the MAC to match the "fc" parameter.
1089 */
1090 if (mac->autoneg_failed) {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001091 if (hw->phy.media_type == e1000_media_type_fiber ||
1092 hw->phy.media_type == e1000_media_type_internal_serdes)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001093 ret_val = e1000e_force_mac_fc(hw);
1094 } else {
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001095 if (hw->phy.media_type == e1000_media_type_copper)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001096 ret_val = e1000e_force_mac_fc(hw);
1097 }
1098
1099 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001100 e_dbg("Error forcing flow control settings\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001101 return ret_val;
1102 }
1103
Bruce Allanad680762008-03-28 09:15:03 -07001104 /*
1105 * Check for the case where we have copper media and auto-neg is
Auke Kokbc7f75f2007-09-17 12:30:59 -07001106 * enabled. In this case, we need to check and see if Auto-Neg
1107 * has completed, and if so, how the PHY and link partner has
1108 * flow control configured.
1109 */
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001110 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
Bruce Allanad680762008-03-28 09:15:03 -07001111 /*
1112 * Read the MII Status Register and check to see if AutoNeg
Auke Kokbc7f75f2007-09-17 12:30:59 -07001113 * has completed. We read this twice because this reg has
1114 * some "sticky" (latched) bits.
1115 */
1116 ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg);
1117 if (ret_val)
1118 return ret_val;
1119 ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg);
1120 if (ret_val)
1121 return ret_val;
1122
1123 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001124 e_dbg("Copper PHY and Auto Neg "
Auke Kokbc7f75f2007-09-17 12:30:59 -07001125 "has not completed.\n");
1126 return ret_val;
1127 }
1128
Bruce Allanad680762008-03-28 09:15:03 -07001129 /*
1130 * The AutoNeg process has completed, so we now need to
Auke Kokbc7f75f2007-09-17 12:30:59 -07001131 * read both the Auto Negotiation Advertisement
1132 * Register (Address 4) and the Auto_Negotiation Base
1133 * Page Ability Register (Address 5) to determine how
1134 * flow control was negotiated.
1135 */
1136 ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg);
1137 if (ret_val)
1138 return ret_val;
Bruce Allan482fed82011-01-06 14:29:49 +00001139 ret_val =
1140 e1e_rphy(hw, PHY_LP_ABILITY, &mii_nway_lp_ability_reg);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001141 if (ret_val)
1142 return ret_val;
1143
Bruce Allanad680762008-03-28 09:15:03 -07001144 /*
1145 * Two bits in the Auto Negotiation Advertisement Register
Auke Kokbc7f75f2007-09-17 12:30:59 -07001146 * (Address 4) and two bits in the Auto Negotiation Base
1147 * Page Ability Register (Address 5) determine flow control
1148 * for both the PHY and the link partner. The following
1149 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1150 * 1999, describes these PAUSE resolution bits and how flow
1151 * control is determined based upon these settings.
1152 * NOTE: DC = Don't Care
1153 *
1154 * LOCAL DEVICE | LINK PARTNER
1155 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1156 *-------|---------|-------|---------|--------------------
1157 * 0 | 0 | DC | DC | e1000_fc_none
1158 * 0 | 1 | 0 | DC | e1000_fc_none
1159 * 0 | 1 | 1 | 0 | e1000_fc_none
1160 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1161 * 1 | 0 | 0 | DC | e1000_fc_none
1162 * 1 | DC | 1 | DC | e1000_fc_full
1163 * 1 | 1 | 0 | 0 | e1000_fc_none
1164 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1165 *
Bruce Allanad680762008-03-28 09:15:03 -07001166 * Are both PAUSE bits set to 1? If so, this implies
Auke Kokbc7f75f2007-09-17 12:30:59 -07001167 * Symmetric Flow Control is enabled at both ends. The
1168 * ASM_DIR bits are irrelevant per the spec.
1169 *
1170 * For Symmetric Flow Control:
1171 *
1172 * LOCAL DEVICE | LINK PARTNER
1173 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1174 *-------|---------|-------|---------|--------------------
1175 * 1 | DC | 1 | DC | E1000_fc_full
1176 *
1177 */
1178 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1179 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
Bruce Allanad680762008-03-28 09:15:03 -07001180 /*
1181 * Now we need to check if the user selected Rx ONLY
Auke Kokbc7f75f2007-09-17 12:30:59 -07001182 * of pause frames. In this case, we had to advertise
Bruce Allanad680762008-03-28 09:15:03 -07001183 * FULL flow control because we could not advertise Rx
Auke Kokbc7f75f2007-09-17 12:30:59 -07001184 * ONLY. Hence, we must now check to see if we need to
Bruce Alland64a6f42011-05-13 07:19:58 +00001185 * turn OFF the TRANSMISSION of PAUSE frames.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001186 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001187 if (hw->fc.requested_mode == e1000_fc_full) {
1188 hw->fc.current_mode = e1000_fc_full;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001189 e_dbg("Flow Control = FULL.\r\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001190 } else {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001191 hw->fc.current_mode = e1000_fc_rx_pause;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001192 e_dbg("Flow Control = "
Bruce Allanaf667a22010-12-31 06:10:01 +00001193 "Rx PAUSE frames only.\r\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001194 }
1195 }
Bruce Allanad680762008-03-28 09:15:03 -07001196 /*
1197 * For receiving PAUSE frames ONLY.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001198 *
1199 * LOCAL DEVICE | LINK PARTNER
1200 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1201 *-------|---------|-------|---------|--------------------
1202 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
Auke Kokbc7f75f2007-09-17 12:30:59 -07001203 */
1204 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1205 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1206 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1207 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001208 hw->fc.current_mode = e1000_fc_tx_pause;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001209 e_dbg("Flow Control = Tx PAUSE frames only.\r\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001210 }
Bruce Allanad680762008-03-28 09:15:03 -07001211 /*
1212 * For transmitting PAUSE frames ONLY.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001213 *
1214 * LOCAL DEVICE | LINK PARTNER
1215 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1216 *-------|---------|-------|---------|--------------------
1217 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
Auke Kokbc7f75f2007-09-17 12:30:59 -07001218 */
1219 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1220 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1221 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1222 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001223 hw->fc.current_mode = e1000_fc_rx_pause;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001224 e_dbg("Flow Control = Rx PAUSE frames only.\r\n");
Jesse Brandeburgde92d842008-02-21 15:11:02 -08001225 } else {
1226 /*
1227 * Per the IEEE spec, at this point flow control
1228 * should be disabled.
1229 */
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001230 hw->fc.current_mode = e1000_fc_none;
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001231 e_dbg("Flow Control = NONE.\r\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001232 }
1233
Bruce Allanad680762008-03-28 09:15:03 -07001234 /*
1235 * Now we need to do one last check... If we auto-
Auke Kokbc7f75f2007-09-17 12:30:59 -07001236 * negotiated to HALF DUPLEX, flow control should not be
1237 * enabled per IEEE 802.3 spec.
1238 */
1239 ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
1240 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001241 e_dbg("Error getting link speed and duplex\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001242 return ret_val;
1243 }
1244
1245 if (duplex == HALF_DUPLEX)
Bruce Allan5c48ef3e22008-11-21 16:57:36 -08001246 hw->fc.current_mode = e1000_fc_none;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001247
Bruce Allanad680762008-03-28 09:15:03 -07001248 /*
1249 * Now we call a subroutine to actually force the MAC
Auke Kokbc7f75f2007-09-17 12:30:59 -07001250 * controller to use the correct flow control settings.
1251 */
1252 ret_val = e1000e_force_mac_fc(hw);
1253 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001254 e_dbg("Error forcing flow control settings\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001255 return ret_val;
1256 }
1257 }
1258
1259 return 0;
1260}
1261
1262/**
Auke Kok489815c2008-02-21 15:11:07 -08001263 * e1000e_get_speed_and_duplex_copper - Retrieve current speed/duplex
Auke Kokbc7f75f2007-09-17 12:30:59 -07001264 * @hw: pointer to the HW structure
1265 * @speed: stores the current speed
1266 * @duplex: stores the current duplex
1267 *
1268 * Read the status register for the current speed/duplex and store the current
1269 * speed and duplex for copper connections.
1270 **/
1271s32 e1000e_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed, u16 *duplex)
1272{
1273 u32 status;
1274
1275 status = er32(STATUS);
Joe Perches2c73e1f2010-03-26 20:16:59 +00001276 if (status & E1000_STATUS_SPEED_1000)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001277 *speed = SPEED_1000;
Joe Perches2c73e1f2010-03-26 20:16:59 +00001278 else if (status & E1000_STATUS_SPEED_100)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001279 *speed = SPEED_100;
Joe Perches2c73e1f2010-03-26 20:16:59 +00001280 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07001281 *speed = SPEED_10;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001282
Joe Perches2c73e1f2010-03-26 20:16:59 +00001283 if (status & E1000_STATUS_FD)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001284 *duplex = FULL_DUPLEX;
Joe Perches2c73e1f2010-03-26 20:16:59 +00001285 else
Auke Kokbc7f75f2007-09-17 12:30:59 -07001286 *duplex = HALF_DUPLEX;
Joe Perches2c73e1f2010-03-26 20:16:59 +00001287
1288 e_dbg("%u Mbps, %s Duplex\n",
1289 *speed == SPEED_1000 ? 1000 : *speed == SPEED_100 ? 100 : 10,
1290 *duplex == FULL_DUPLEX ? "Full" : "Half");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001291
1292 return 0;
1293}
1294
1295/**
Auke Kok489815c2008-02-21 15:11:07 -08001296 * e1000e_get_speed_and_duplex_fiber_serdes - Retrieve current speed/duplex
Auke Kokbc7f75f2007-09-17 12:30:59 -07001297 * @hw: pointer to the HW structure
1298 * @speed: stores the current speed
1299 * @duplex: stores the current duplex
1300 *
1301 * Sets the speed and duplex to gigabit full duplex (the only possible option)
1302 * for fiber/serdes links.
1303 **/
1304s32 e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw *hw, u16 *speed, u16 *duplex)
1305{
1306 *speed = SPEED_1000;
1307 *duplex = FULL_DUPLEX;
1308
1309 return 0;
1310}
1311
1312/**
1313 * e1000e_get_hw_semaphore - Acquire hardware semaphore
1314 * @hw: pointer to the HW structure
1315 *
1316 * Acquire the HW semaphore to access the PHY or NVM
1317 **/
1318s32 e1000e_get_hw_semaphore(struct e1000_hw *hw)
1319{
1320 u32 swsm;
1321 s32 timeout = hw->nvm.word_size + 1;
1322 s32 i = 0;
1323
1324 /* Get the SW semaphore */
1325 while (i < timeout) {
1326 swsm = er32(SWSM);
1327 if (!(swsm & E1000_SWSM_SMBI))
1328 break;
1329
1330 udelay(50);
1331 i++;
1332 }
1333
1334 if (i == timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001335 e_dbg("Driver can't access device - SMBI bit is set.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001336 return -E1000_ERR_NVM;
1337 }
1338
1339 /* Get the FW semaphore. */
1340 for (i = 0; i < timeout; i++) {
1341 swsm = er32(SWSM);
1342 ew32(SWSM, swsm | E1000_SWSM_SWESMBI);
1343
1344 /* Semaphore acquired if bit latched */
1345 if (er32(SWSM) & E1000_SWSM_SWESMBI)
1346 break;
1347
1348 udelay(50);
1349 }
1350
1351 if (i == timeout) {
1352 /* Release semaphores */
1353 e1000e_put_hw_semaphore(hw);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001354 e_dbg("Driver can't access the NVM\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001355 return -E1000_ERR_NVM;
1356 }
1357
1358 return 0;
1359}
1360
1361/**
1362 * e1000e_put_hw_semaphore - Release hardware semaphore
1363 * @hw: pointer to the HW structure
1364 *
1365 * Release hardware semaphore used to access the PHY or NVM
1366 **/
1367void e1000e_put_hw_semaphore(struct e1000_hw *hw)
1368{
1369 u32 swsm;
1370
1371 swsm = er32(SWSM);
1372 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1373 ew32(SWSM, swsm);
1374}
1375
1376/**
1377 * e1000e_get_auto_rd_done - Check for auto read completion
1378 * @hw: pointer to the HW structure
1379 *
1380 * Check EEPROM for Auto Read done bit.
1381 **/
1382s32 e1000e_get_auto_rd_done(struct e1000_hw *hw)
1383{
1384 s32 i = 0;
1385
1386 while (i < AUTO_READ_DONE_TIMEOUT) {
1387 if (er32(EECD) & E1000_EECD_AUTO_RD)
1388 break;
Bruce Allan1bba4382011-03-19 00:27:20 +00001389 usleep_range(1000, 2000);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001390 i++;
1391 }
1392
1393 if (i == AUTO_READ_DONE_TIMEOUT) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001394 e_dbg("Auto read by HW from NVM has not completed.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001395 return -E1000_ERR_RESET;
1396 }
1397
1398 return 0;
1399}
1400
1401/**
1402 * e1000e_valid_led_default - Verify a valid default LED config
1403 * @hw: pointer to the HW structure
1404 * @data: pointer to the NVM (EEPROM)
1405 *
1406 * Read the EEPROM for the current default LED configuration. If the
1407 * LED configuration is not valid, set to a valid LED configuration.
1408 **/
1409s32 e1000e_valid_led_default(struct e1000_hw *hw, u16 *data)
1410{
1411 s32 ret_val;
1412
1413 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
1414 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001415 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001416 return ret_val;
1417 }
1418
1419 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
1420 *data = ID_LED_DEFAULT;
1421
1422 return 0;
1423}
1424
1425/**
1426 * e1000e_id_led_init -
1427 * @hw: pointer to the HW structure
1428 *
1429 **/
1430s32 e1000e_id_led_init(struct e1000_hw *hw)
1431{
1432 struct e1000_mac_info *mac = &hw->mac;
1433 s32 ret_val;
1434 const u32 ledctl_mask = 0x000000FF;
1435 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
1436 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
1437 u16 data, i, temp;
1438 const u16 led_mask = 0x0F;
1439
1440 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
1441 if (ret_val)
1442 return ret_val;
1443
1444 mac->ledctl_default = er32(LEDCTL);
1445 mac->ledctl_mode1 = mac->ledctl_default;
1446 mac->ledctl_mode2 = mac->ledctl_default;
1447
1448 for (i = 0; i < 4; i++) {
1449 temp = (data >> (i << 2)) & led_mask;
1450 switch (temp) {
1451 case ID_LED_ON1_DEF2:
1452 case ID_LED_ON1_ON2:
1453 case ID_LED_ON1_OFF2:
1454 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1455 mac->ledctl_mode1 |= ledctl_on << (i << 3);
1456 break;
1457 case ID_LED_OFF1_DEF2:
1458 case ID_LED_OFF1_ON2:
1459 case ID_LED_OFF1_OFF2:
1460 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1461 mac->ledctl_mode1 |= ledctl_off << (i << 3);
1462 break;
1463 default:
1464 /* Do nothing */
1465 break;
1466 }
1467 switch (temp) {
1468 case ID_LED_DEF1_ON2:
1469 case ID_LED_ON1_ON2:
1470 case ID_LED_OFF1_ON2:
1471 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1472 mac->ledctl_mode2 |= ledctl_on << (i << 3);
1473 break;
1474 case ID_LED_DEF1_OFF2:
1475 case ID_LED_ON1_OFF2:
1476 case ID_LED_OFF1_OFF2:
1477 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1478 mac->ledctl_mode2 |= ledctl_off << (i << 3);
1479 break;
1480 default:
1481 /* Do nothing */
1482 break;
1483 }
1484 }
1485
1486 return 0;
1487}
1488
1489/**
Bruce Allana4f58f52009-06-02 11:29:18 +00001490 * e1000e_setup_led_generic - Configures SW controllable LED
1491 * @hw: pointer to the HW structure
1492 *
1493 * This prepares the SW controllable LED for use and saves the current state
1494 * of the LED so it can be later restored.
1495 **/
1496s32 e1000e_setup_led_generic(struct e1000_hw *hw)
1497{
1498 u32 ledctl;
1499
Bruce Allanb1cdfea2010-12-11 05:53:47 +00001500 if (hw->mac.ops.setup_led != e1000e_setup_led_generic)
Bruce Allana4f58f52009-06-02 11:29:18 +00001501 return -E1000_ERR_CONFIG;
Bruce Allana4f58f52009-06-02 11:29:18 +00001502
1503 if (hw->phy.media_type == e1000_media_type_fiber) {
1504 ledctl = er32(LEDCTL);
1505 hw->mac.ledctl_default = ledctl;
1506 /* Turn off LED0 */
1507 ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
1508 E1000_LEDCTL_LED0_BLINK |
1509 E1000_LEDCTL_LED0_MODE_MASK);
1510 ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
1511 E1000_LEDCTL_LED0_MODE_SHIFT);
1512 ew32(LEDCTL, ledctl);
1513 } else if (hw->phy.media_type == e1000_media_type_copper) {
1514 ew32(LEDCTL, hw->mac.ledctl_mode1);
1515 }
1516
1517 return 0;
1518}
1519
1520/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07001521 * e1000e_cleanup_led_generic - Set LED config to default operation
1522 * @hw: pointer to the HW structure
1523 *
1524 * Remove the current LED configuration and set the LED configuration
1525 * to the default value, saved from the EEPROM.
1526 **/
1527s32 e1000e_cleanup_led_generic(struct e1000_hw *hw)
1528{
1529 ew32(LEDCTL, hw->mac.ledctl_default);
1530 return 0;
1531}
1532
1533/**
Bruce Allandbf80dc2011-04-16 00:34:40 +00001534 * e1000e_blink_led_generic - Blink LED
Auke Kokbc7f75f2007-09-17 12:30:59 -07001535 * @hw: pointer to the HW structure
1536 *
Auke Kok489815c2008-02-21 15:11:07 -08001537 * Blink the LEDs which are set to be on.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001538 **/
Bruce Allandbf80dc2011-04-16 00:34:40 +00001539s32 e1000e_blink_led_generic(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07001540{
1541 u32 ledctl_blink = 0;
1542 u32 i;
1543
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001544 if (hw->phy.media_type == e1000_media_type_fiber) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001545 /* always blink LED0 for PCI-E fiber */
1546 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
1547 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
1548 } else {
Bruce Allanad680762008-03-28 09:15:03 -07001549 /*
1550 * set the blink bit for each LED that's "on" (0x0E)
1551 * in ledctl_mode2
1552 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001553 ledctl_blink = hw->mac.ledctl_mode2;
1554 for (i = 0; i < 4; i++)
1555 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
1556 E1000_LEDCTL_MODE_LED_ON)
1557 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
1558 (i * 8));
1559 }
1560
1561 ew32(LEDCTL, ledctl_blink);
1562
1563 return 0;
1564}
1565
1566/**
1567 * e1000e_led_on_generic - Turn LED on
1568 * @hw: pointer to the HW structure
1569 *
1570 * Turn LED on.
1571 **/
1572s32 e1000e_led_on_generic(struct e1000_hw *hw)
1573{
1574 u32 ctrl;
1575
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001576 switch (hw->phy.media_type) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001577 case e1000_media_type_fiber:
1578 ctrl = er32(CTRL);
1579 ctrl &= ~E1000_CTRL_SWDPIN0;
1580 ctrl |= E1000_CTRL_SWDPIO0;
1581 ew32(CTRL, ctrl);
1582 break;
1583 case e1000_media_type_copper:
1584 ew32(LEDCTL, hw->mac.ledctl_mode2);
1585 break;
1586 default:
1587 break;
1588 }
1589
1590 return 0;
1591}
1592
1593/**
1594 * e1000e_led_off_generic - Turn LED off
1595 * @hw: pointer to the HW structure
1596 *
1597 * Turn LED off.
1598 **/
1599s32 e1000e_led_off_generic(struct e1000_hw *hw)
1600{
1601 u32 ctrl;
1602
Jeff Kirsher318a94d2008-03-28 09:15:16 -07001603 switch (hw->phy.media_type) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07001604 case e1000_media_type_fiber:
1605 ctrl = er32(CTRL);
1606 ctrl |= E1000_CTRL_SWDPIN0;
1607 ctrl |= E1000_CTRL_SWDPIO0;
1608 ew32(CTRL, ctrl);
1609 break;
1610 case e1000_media_type_copper:
1611 ew32(LEDCTL, hw->mac.ledctl_mode1);
1612 break;
1613 default:
1614 break;
1615 }
1616
1617 return 0;
1618}
1619
1620/**
1621 * e1000e_set_pcie_no_snoop - Set PCI-express capabilities
1622 * @hw: pointer to the HW structure
1623 * @no_snoop: bitmap of snoop events
1624 *
1625 * Set the PCI-express register to snoop for events enabled in 'no_snoop'.
1626 **/
1627void e1000e_set_pcie_no_snoop(struct e1000_hw *hw, u32 no_snoop)
1628{
1629 u32 gcr;
1630
1631 if (no_snoop) {
1632 gcr = er32(GCR);
1633 gcr &= ~(PCIE_NO_SNOOP_ALL);
1634 gcr |= no_snoop;
1635 ew32(GCR, gcr);
1636 }
1637}
1638
1639/**
1640 * e1000e_disable_pcie_master - Disables PCI-express master access
1641 * @hw: pointer to the HW structure
1642 *
1643 * Returns 0 if successful, else returns -10
Auke Kok489815c2008-02-21 15:11:07 -08001644 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
Auke Kokbc7f75f2007-09-17 12:30:59 -07001645 * the master requests to be disabled.
1646 *
1647 * Disables PCI-Express master access and verifies there are no pending
1648 * requests.
1649 **/
1650s32 e1000e_disable_pcie_master(struct e1000_hw *hw)
1651{
1652 u32 ctrl;
1653 s32 timeout = MASTER_DISABLE_TIMEOUT;
1654
1655 ctrl = er32(CTRL);
1656 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
1657 ew32(CTRL, ctrl);
1658
1659 while (timeout) {
1660 if (!(er32(STATUS) &
1661 E1000_STATUS_GIO_MASTER_ENABLE))
1662 break;
1663 udelay(100);
1664 timeout--;
1665 }
1666
1667 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001668 e_dbg("Master requests are pending.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001669 return -E1000_ERR_MASTER_REQUESTS_PENDING;
1670 }
1671
1672 return 0;
1673}
1674
1675/**
1676 * e1000e_reset_adaptive - Reset Adaptive Interframe Spacing
1677 * @hw: pointer to the HW structure
1678 *
1679 * Reset the Adaptive Interframe Spacing throttle to default values.
1680 **/
1681void e1000e_reset_adaptive(struct e1000_hw *hw)
1682{
1683 struct e1000_mac_info *mac = &hw->mac;
1684
Bruce Allanf464ba82010-01-07 16:31:35 +00001685 if (!mac->adaptive_ifs) {
1686 e_dbg("Not in Adaptive IFS mode!\n");
1687 goto out;
1688 }
1689
Auke Kokbc7f75f2007-09-17 12:30:59 -07001690 mac->current_ifs_val = 0;
1691 mac->ifs_min_val = IFS_MIN;
1692 mac->ifs_max_val = IFS_MAX;
1693 mac->ifs_step_size = IFS_STEP;
1694 mac->ifs_ratio = IFS_RATIO;
1695
Bruce Allan564ea9b2009-11-20 23:26:44 +00001696 mac->in_ifs_mode = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001697 ew32(AIT, 0);
Bruce Allanf464ba82010-01-07 16:31:35 +00001698out:
1699 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001700}
1701
1702/**
1703 * e1000e_update_adaptive - Update Adaptive Interframe Spacing
1704 * @hw: pointer to the HW structure
1705 *
1706 * Update the Adaptive Interframe Spacing Throttle value based on the
1707 * time between transmitted packets and time between collisions.
1708 **/
1709void e1000e_update_adaptive(struct e1000_hw *hw)
1710{
1711 struct e1000_mac_info *mac = &hw->mac;
1712
Bruce Allanf464ba82010-01-07 16:31:35 +00001713 if (!mac->adaptive_ifs) {
1714 e_dbg("Not in Adaptive IFS mode!\n");
1715 goto out;
1716 }
1717
Auke Kokbc7f75f2007-09-17 12:30:59 -07001718 if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
1719 if (mac->tx_packet_delta > MIN_NUM_XMITS) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00001720 mac->in_ifs_mode = true;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001721 if (mac->current_ifs_val < mac->ifs_max_val) {
1722 if (!mac->current_ifs_val)
1723 mac->current_ifs_val = mac->ifs_min_val;
1724 else
1725 mac->current_ifs_val +=
1726 mac->ifs_step_size;
Bruce Allanad680762008-03-28 09:15:03 -07001727 ew32(AIT, mac->current_ifs_val);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001728 }
1729 }
1730 } else {
1731 if (mac->in_ifs_mode &&
1732 (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
1733 mac->current_ifs_val = 0;
Bruce Allan564ea9b2009-11-20 23:26:44 +00001734 mac->in_ifs_mode = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001735 ew32(AIT, 0);
1736 }
1737 }
Bruce Allanf464ba82010-01-07 16:31:35 +00001738out:
1739 return;
Auke Kokbc7f75f2007-09-17 12:30:59 -07001740}
1741
1742/**
1743 * e1000_raise_eec_clk - Raise EEPROM clock
1744 * @hw: pointer to the HW structure
1745 * @eecd: pointer to the EEPROM
1746 *
1747 * Enable/Raise the EEPROM clock bit.
1748 **/
1749static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
1750{
1751 *eecd = *eecd | E1000_EECD_SK;
1752 ew32(EECD, *eecd);
1753 e1e_flush();
1754 udelay(hw->nvm.delay_usec);
1755}
1756
1757/**
1758 * e1000_lower_eec_clk - Lower EEPROM clock
1759 * @hw: pointer to the HW structure
1760 * @eecd: pointer to the EEPROM
1761 *
1762 * Clear/Lower the EEPROM clock bit.
1763 **/
1764static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
1765{
1766 *eecd = *eecd & ~E1000_EECD_SK;
1767 ew32(EECD, *eecd);
1768 e1e_flush();
1769 udelay(hw->nvm.delay_usec);
1770}
1771
1772/**
1773 * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
1774 * @hw: pointer to the HW structure
1775 * @data: data to send to the EEPROM
1776 * @count: number of bits to shift out
1777 *
1778 * We need to shift 'count' bits out to the EEPROM. So, the value in the
1779 * "data" parameter will be shifted out to the EEPROM one bit at a time.
1780 * In order to do this, "data" must be broken down into bits.
1781 **/
1782static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
1783{
1784 struct e1000_nvm_info *nvm = &hw->nvm;
1785 u32 eecd = er32(EECD);
1786 u32 mask;
1787
1788 mask = 0x01 << (count - 1);
1789 if (nvm->type == e1000_nvm_eeprom_spi)
1790 eecd |= E1000_EECD_DO;
1791
1792 do {
1793 eecd &= ~E1000_EECD_DI;
1794
1795 if (data & mask)
1796 eecd |= E1000_EECD_DI;
1797
1798 ew32(EECD, eecd);
1799 e1e_flush();
1800
1801 udelay(nvm->delay_usec);
1802
1803 e1000_raise_eec_clk(hw, &eecd);
1804 e1000_lower_eec_clk(hw, &eecd);
1805
1806 mask >>= 1;
1807 } while (mask);
1808
1809 eecd &= ~E1000_EECD_DI;
1810 ew32(EECD, eecd);
1811}
1812
1813/**
1814 * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
1815 * @hw: pointer to the HW structure
1816 * @count: number of bits to shift in
1817 *
1818 * In order to read a register from the EEPROM, we need to shift 'count' bits
1819 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
1820 * the EEPROM (setting the SK bit), and then reading the value of the data out
1821 * "DO" bit. During this "shifting in" process the data in "DI" bit should
1822 * always be clear.
1823 **/
1824static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
1825{
1826 u32 eecd;
1827 u32 i;
1828 u16 data;
1829
1830 eecd = er32(EECD);
1831
1832 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
1833 data = 0;
1834
1835 for (i = 0; i < count; i++) {
1836 data <<= 1;
1837 e1000_raise_eec_clk(hw, &eecd);
1838
1839 eecd = er32(EECD);
1840
1841 eecd &= ~E1000_EECD_DI;
1842 if (eecd & E1000_EECD_DO)
1843 data |= 1;
1844
1845 e1000_lower_eec_clk(hw, &eecd);
1846 }
1847
1848 return data;
1849}
1850
1851/**
1852 * e1000e_poll_eerd_eewr_done - Poll for EEPROM read/write completion
1853 * @hw: pointer to the HW structure
1854 * @ee_reg: EEPROM flag for polling
1855 *
1856 * Polls the EEPROM status bit for either read or write completion based
1857 * upon the value of 'ee_reg'.
1858 **/
1859s32 e1000e_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
1860{
1861 u32 attempts = 100000;
1862 u32 i, reg = 0;
1863
1864 for (i = 0; i < attempts; i++) {
1865 if (ee_reg == E1000_NVM_POLL_READ)
1866 reg = er32(EERD);
1867 else
1868 reg = er32(EEWR);
1869
1870 if (reg & E1000_NVM_RW_REG_DONE)
1871 return 0;
1872
1873 udelay(5);
1874 }
1875
1876 return -E1000_ERR_NVM;
1877}
1878
1879/**
1880 * e1000e_acquire_nvm - Generic request for access to EEPROM
1881 * @hw: pointer to the HW structure
1882 *
1883 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
1884 * Return successful if access grant bit set, else clear the request for
1885 * EEPROM access and return -E1000_ERR_NVM (-1).
1886 **/
1887s32 e1000e_acquire_nvm(struct e1000_hw *hw)
1888{
1889 u32 eecd = er32(EECD);
1890 s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
1891
1892 ew32(EECD, eecd | E1000_EECD_REQ);
1893 eecd = er32(EECD);
1894
1895 while (timeout) {
1896 if (eecd & E1000_EECD_GNT)
1897 break;
1898 udelay(5);
1899 eecd = er32(EECD);
1900 timeout--;
1901 }
1902
1903 if (!timeout) {
1904 eecd &= ~E1000_EECD_REQ;
1905 ew32(EECD, eecd);
Bruce Allan3bb99fe2009-11-20 23:25:07 +00001906 e_dbg("Could not acquire NVM grant\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07001907 return -E1000_ERR_NVM;
1908 }
1909
1910 return 0;
1911}
1912
1913/**
1914 * e1000_standby_nvm - Return EEPROM to standby state
1915 * @hw: pointer to the HW structure
1916 *
1917 * Return the EEPROM to a standby state.
1918 **/
1919static void e1000_standby_nvm(struct e1000_hw *hw)
1920{
1921 struct e1000_nvm_info *nvm = &hw->nvm;
1922 u32 eecd = er32(EECD);
1923
1924 if (nvm->type == e1000_nvm_eeprom_spi) {
1925 /* Toggle CS to flush commands */
1926 eecd |= E1000_EECD_CS;
1927 ew32(EECD, eecd);
1928 e1e_flush();
1929 udelay(nvm->delay_usec);
1930 eecd &= ~E1000_EECD_CS;
1931 ew32(EECD, eecd);
1932 e1e_flush();
1933 udelay(nvm->delay_usec);
1934 }
1935}
1936
1937/**
1938 * e1000_stop_nvm - Terminate EEPROM command
1939 * @hw: pointer to the HW structure
1940 *
1941 * Terminates the current command by inverting the EEPROM's chip select pin.
1942 **/
1943static void e1000_stop_nvm(struct e1000_hw *hw)
1944{
1945 u32 eecd;
1946
1947 eecd = er32(EECD);
1948 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
1949 /* Pull CS high */
1950 eecd |= E1000_EECD_CS;
1951 e1000_lower_eec_clk(hw, &eecd);
1952 }
1953}
1954
1955/**
1956 * e1000e_release_nvm - Release exclusive access to EEPROM
1957 * @hw: pointer to the HW structure
1958 *
1959 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
1960 **/
1961void e1000e_release_nvm(struct e1000_hw *hw)
1962{
1963 u32 eecd;
1964
1965 e1000_stop_nvm(hw);
1966
1967 eecd = er32(EECD);
1968 eecd &= ~E1000_EECD_REQ;
1969 ew32(EECD, eecd);
1970}
1971
1972/**
1973 * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
1974 * @hw: pointer to the HW structure
1975 *
1976 * Setups the EEPROM for reading and writing.
1977 **/
1978static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
1979{
1980 struct e1000_nvm_info *nvm = &hw->nvm;
1981 u32 eecd = er32(EECD);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001982 u8 spi_stat_reg;
1983
1984 if (nvm->type == e1000_nvm_eeprom_spi) {
Bruce Allan90da0662011-01-06 07:02:53 +00001985 u16 timeout = NVM_MAX_RETRY_SPI;
1986
Auke Kokbc7f75f2007-09-17 12:30:59 -07001987 /* Clear SK and CS */
1988 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
1989 ew32(EECD, eecd);
Jesse Brandeburg945a5152011-07-20 00:56:21 +00001990 e1e_flush();
Auke Kokbc7f75f2007-09-17 12:30:59 -07001991 udelay(1);
Auke Kokbc7f75f2007-09-17 12:30:59 -07001992
Bruce Allanad680762008-03-28 09:15:03 -07001993 /*
1994 * Read "Status Register" repeatedly until the LSB is cleared.
Auke Kokbc7f75f2007-09-17 12:30:59 -07001995 * The EEPROM will signal that the command has been completed
1996 * by clearing bit 0 of the internal status register. If it's
Bruce Allanad680762008-03-28 09:15:03 -07001997 * not cleared within 'timeout', then error out.
1998 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07001999 while (timeout) {
2000 e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
2001 hw->nvm.opcode_bits);
2002 spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
2003 if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
2004 break;
2005
2006 udelay(5);
2007 e1000_standby_nvm(hw);
2008 timeout--;
2009 }
2010
2011 if (!timeout) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002012 e_dbg("SPI NVM Status error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002013 return -E1000_ERR_NVM;
2014 }
2015 }
2016
2017 return 0;
2018}
2019
2020/**
Auke Kokbc7f75f2007-09-17 12:30:59 -07002021 * e1000e_read_nvm_eerd - Reads EEPROM using EERD register
2022 * @hw: pointer to the HW structure
2023 * @offset: offset of word in the EEPROM to read
2024 * @words: number of words to read
2025 * @data: word read from the EEPROM
2026 *
2027 * Reads a 16 bit word from the EEPROM using the EERD register.
2028 **/
2029s32 e1000e_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
2030{
2031 struct e1000_nvm_info *nvm = &hw->nvm;
2032 u32 i, eerd = 0;
2033 s32 ret_val = 0;
2034
Bruce Allanad680762008-03-28 09:15:03 -07002035 /*
2036 * A check for invalid values: offset too large, too many words,
2037 * too many words for the offset, and not enough words.
2038 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002039 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
2040 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002041 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002042 return -E1000_ERR_NVM;
2043 }
2044
2045 for (i = 0; i < words; i++) {
2046 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
2047 E1000_NVM_RW_REG_START;
2048
2049 ew32(EERD, eerd);
2050 ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
2051 if (ret_val)
2052 break;
2053
Bruce Allanad680762008-03-28 09:15:03 -07002054 data[i] = (er32(EERD) >> E1000_NVM_RW_REG_DATA);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002055 }
2056
2057 return ret_val;
2058}
2059
2060/**
2061 * e1000e_write_nvm_spi - Write to EEPROM using SPI
2062 * @hw: pointer to the HW structure
2063 * @offset: offset within the EEPROM to be written to
2064 * @words: number of words to write
2065 * @data: 16 bit word(s) to be written to the EEPROM
2066 *
2067 * Writes data to EEPROM at offset using SPI interface.
2068 *
2069 * If e1000e_update_nvm_checksum is not called after this function , the
Auke Kok489815c2008-02-21 15:11:07 -08002070 * EEPROM will most likely contain an invalid checksum.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002071 **/
2072s32 e1000e_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
2073{
2074 struct e1000_nvm_info *nvm = &hw->nvm;
2075 s32 ret_val;
2076 u16 widx = 0;
2077
Bruce Allanad680762008-03-28 09:15:03 -07002078 /*
2079 * A check for invalid values: offset too large, too many words,
2080 * and not enough words.
2081 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002082 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
2083 (words == 0)) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002084 e_dbg("nvm parameter(s) out of bounds\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002085 return -E1000_ERR_NVM;
2086 }
2087
Bruce Allan94d81862009-11-20 23:25:26 +00002088 ret_val = nvm->ops.acquire(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002089 if (ret_val)
2090 return ret_val;
2091
Auke Kokbc7f75f2007-09-17 12:30:59 -07002092 while (widx < words) {
2093 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
2094
2095 ret_val = e1000_ready_nvm_eeprom(hw);
2096 if (ret_val) {
Bruce Allan94d81862009-11-20 23:25:26 +00002097 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002098 return ret_val;
2099 }
2100
2101 e1000_standby_nvm(hw);
2102
2103 /* Send the WRITE ENABLE command (8 bit opcode) */
2104 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
2105 nvm->opcode_bits);
2106
2107 e1000_standby_nvm(hw);
2108
Bruce Allanad680762008-03-28 09:15:03 -07002109 /*
2110 * Some SPI eeproms use the 8th address bit embedded in the
2111 * opcode
2112 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002113 if ((nvm->address_bits == 8) && (offset >= 128))
2114 write_opcode |= NVM_A8_OPCODE_SPI;
2115
2116 /* Send the Write command (8-bit opcode + addr) */
2117 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
2118 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
2119 nvm->address_bits);
2120
2121 /* Loop to allow for up to whole page write of eeprom */
2122 while (widx < words) {
2123 u16 word_out = data[widx];
2124 word_out = (word_out >> 8) | (word_out << 8);
2125 e1000_shift_out_eec_bits(hw, word_out, 16);
2126 widx++;
2127
2128 if ((((offset + widx) * 2) % nvm->page_size) == 0) {
2129 e1000_standby_nvm(hw);
2130 break;
2131 }
2132 }
2133 }
2134
Bruce Allan1bba4382011-03-19 00:27:20 +00002135 usleep_range(10000, 20000);
Bruce Allan94d81862009-11-20 23:25:26 +00002136 nvm->ops.release(hw);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002137 return 0;
2138}
2139
2140/**
Bruce Allan073287c2010-11-24 06:01:51 +00002141 * e1000_read_pba_string_generic - Read device part number
2142 * @hw: pointer to the HW structure
2143 * @pba_num: pointer to device part number
2144 * @pba_num_size: size of part number buffer
2145 *
2146 * Reads the product board assembly (PBA) number from the EEPROM and stores
2147 * the value in pba_num.
2148 **/
2149s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num,
2150 u32 pba_num_size)
2151{
2152 s32 ret_val;
2153 u16 nvm_data;
2154 u16 pba_ptr;
2155 u16 offset;
2156 u16 length;
2157
2158 if (pba_num == NULL) {
2159 e_dbg("PBA string buffer was null\n");
2160 ret_val = E1000_ERR_INVALID_ARGUMENT;
2161 goto out;
2162 }
2163
2164 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
2165 if (ret_val) {
2166 e_dbg("NVM Read Error\n");
2167 goto out;
2168 }
2169
2170 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
2171 if (ret_val) {
2172 e_dbg("NVM Read Error\n");
2173 goto out;
2174 }
2175
2176 /*
2177 * if nvm_data is not ptr guard the PBA must be in legacy format which
2178 * means pba_ptr is actually our second data word for the PBA number
2179 * and we can decode it into an ascii string
2180 */
2181 if (nvm_data != NVM_PBA_PTR_GUARD) {
2182 e_dbg("NVM PBA number is not stored as string\n");
2183
2184 /* we will need 11 characters to store the PBA */
2185 if (pba_num_size < 11) {
2186 e_dbg("PBA string buffer too small\n");
2187 return E1000_ERR_NO_SPACE;
2188 }
2189
2190 /* extract hex string from data and pba_ptr */
2191 pba_num[0] = (nvm_data >> 12) & 0xF;
2192 pba_num[1] = (nvm_data >> 8) & 0xF;
2193 pba_num[2] = (nvm_data >> 4) & 0xF;
2194 pba_num[3] = nvm_data & 0xF;
2195 pba_num[4] = (pba_ptr >> 12) & 0xF;
2196 pba_num[5] = (pba_ptr >> 8) & 0xF;
2197 pba_num[6] = '-';
2198 pba_num[7] = 0;
2199 pba_num[8] = (pba_ptr >> 4) & 0xF;
2200 pba_num[9] = pba_ptr & 0xF;
2201
2202 /* put a null character on the end of our string */
2203 pba_num[10] = '\0';
2204
2205 /* switch all the data but the '-' to hex char */
2206 for (offset = 0; offset < 10; offset++) {
2207 if (pba_num[offset] < 0xA)
2208 pba_num[offset] += '0';
2209 else if (pba_num[offset] < 0x10)
2210 pba_num[offset] += 'A' - 0xA;
2211 }
2212
2213 goto out;
2214 }
2215
2216 ret_val = e1000_read_nvm(hw, pba_ptr, 1, &length);
2217 if (ret_val) {
2218 e_dbg("NVM Read Error\n");
2219 goto out;
2220 }
2221
2222 if (length == 0xFFFF || length == 0) {
2223 e_dbg("NVM PBA number section invalid length\n");
2224 ret_val = E1000_ERR_NVM_PBA_SECTION;
2225 goto out;
2226 }
2227 /* check if pba_num buffer is big enough */
2228 if (pba_num_size < (((u32)length * 2) - 1)) {
2229 e_dbg("PBA string buffer too small\n");
2230 ret_val = E1000_ERR_NO_SPACE;
2231 goto out;
2232 }
2233
2234 /* trim pba length from start of string */
2235 pba_ptr++;
2236 length--;
2237
2238 for (offset = 0; offset < length; offset++) {
2239 ret_val = e1000_read_nvm(hw, pba_ptr + offset, 1, &nvm_data);
2240 if (ret_val) {
2241 e_dbg("NVM Read Error\n");
2242 goto out;
2243 }
2244 pba_num[offset * 2] = (u8)(nvm_data >> 8);
2245 pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF);
2246 }
2247 pba_num[offset * 2] = '\0';
2248
2249out:
2250 return ret_val;
2251}
2252
2253/**
Bruce Allan608f8a02010-01-13 02:04:58 +00002254 * e1000_read_mac_addr_generic - Read device MAC address
Auke Kokbc7f75f2007-09-17 12:30:59 -07002255 * @hw: pointer to the HW structure
2256 *
2257 * Reads the device MAC address from the EEPROM and stores the value.
2258 * Since devices with two ports use the same EEPROM, we increment the
2259 * last bit in the MAC address for the second port.
2260 **/
Bruce Allan608f8a02010-01-13 02:04:58 +00002261s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002262{
Bruce Allan608f8a02010-01-13 02:04:58 +00002263 u32 rar_high;
2264 u32 rar_low;
2265 u16 i;
Bill Hayes93ca1612007-10-31 15:21:52 -07002266
Bruce Allan608f8a02010-01-13 02:04:58 +00002267 rar_high = er32(RAH(0));
2268 rar_low = er32(RAL(0));
Bill Hayes93ca1612007-10-31 15:21:52 -07002269
Bruce Allan608f8a02010-01-13 02:04:58 +00002270 for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
2271 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
Bill Hayes93ca1612007-10-31 15:21:52 -07002272
Bruce Allan608f8a02010-01-13 02:04:58 +00002273 for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
2274 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
Auke Kokbc7f75f2007-09-17 12:30:59 -07002275
2276 for (i = 0; i < ETH_ALEN; i++)
2277 hw->mac.addr[i] = hw->mac.perm_addr[i];
2278
2279 return 0;
2280}
2281
2282/**
2283 * e1000e_validate_nvm_checksum_generic - Validate EEPROM checksum
2284 * @hw: pointer to the HW structure
2285 *
2286 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2287 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2288 **/
2289s32 e1000e_validate_nvm_checksum_generic(struct e1000_hw *hw)
2290{
2291 s32 ret_val;
2292 u16 checksum = 0;
2293 u16 i, nvm_data;
2294
2295 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
2296 ret_val = e1000_read_nvm(hw, i, 1, &nvm_data);
2297 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002298 e_dbg("NVM Read Error\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002299 return ret_val;
2300 }
2301 checksum += nvm_data;
2302 }
2303
2304 if (checksum != (u16) NVM_SUM) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002305 e_dbg("NVM Checksum Invalid\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002306 return -E1000_ERR_NVM;
2307 }
2308
2309 return 0;
2310}
2311
2312/**
2313 * e1000e_update_nvm_checksum_generic - Update EEPROM checksum
2314 * @hw: pointer to the HW structure
2315 *
2316 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2317 * up to the checksum. Then calculates the EEPROM checksum and writes the
2318 * value to the EEPROM.
2319 **/
2320s32 e1000e_update_nvm_checksum_generic(struct e1000_hw *hw)
2321{
2322 s32 ret_val;
2323 u16 checksum = 0;
2324 u16 i, nvm_data;
2325
2326 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
2327 ret_val = e1000_read_nvm(hw, i, 1, &nvm_data);
2328 if (ret_val) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002329 e_dbg("NVM Read Error while updating checksum.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002330 return ret_val;
2331 }
2332 checksum += nvm_data;
2333 }
2334 checksum = (u16) NVM_SUM - checksum;
2335 ret_val = e1000_write_nvm(hw, NVM_CHECKSUM_REG, 1, &checksum);
2336 if (ret_val)
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002337 e_dbg("NVM Write Error while updating checksum.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002338
2339 return ret_val;
2340}
2341
2342/**
2343 * e1000e_reload_nvm - Reloads EEPROM
2344 * @hw: pointer to the HW structure
2345 *
2346 * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
2347 * extended control register.
2348 **/
2349void e1000e_reload_nvm(struct e1000_hw *hw)
2350{
2351 u32 ctrl_ext;
2352
2353 udelay(10);
2354 ctrl_ext = er32(CTRL_EXT);
2355 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
2356 ew32(CTRL_EXT, ctrl_ext);
2357 e1e_flush();
2358}
2359
2360/**
2361 * e1000_calculate_checksum - Calculate checksum for buffer
2362 * @buffer: pointer to EEPROM
2363 * @length: size of EEPROM to calculate a checksum for
2364 *
2365 * Calculates the checksum for some buffer on a specified length. The
2366 * checksum calculated is returned.
2367 **/
2368static u8 e1000_calculate_checksum(u8 *buffer, u32 length)
2369{
2370 u32 i;
2371 u8 sum = 0;
2372
2373 if (!buffer)
2374 return 0;
2375
2376 for (i = 0; i < length; i++)
2377 sum += buffer[i];
2378
2379 return (u8) (0 - sum);
2380}
2381
2382/**
2383 * e1000_mng_enable_host_if - Checks host interface is enabled
2384 * @hw: pointer to the HW structure
2385 *
2386 * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND
2387 *
Auke Kok489815c2008-02-21 15:11:07 -08002388 * This function checks whether the HOST IF is enabled for command operation
Auke Kokbc7f75f2007-09-17 12:30:59 -07002389 * and also checks whether the previous command is completed. It busy waits
2390 * in case of previous command is not completed.
2391 **/
2392static s32 e1000_mng_enable_host_if(struct e1000_hw *hw)
2393{
2394 u32 hicr;
2395 u8 i;
2396
Bruce Allana65a4a02010-05-10 15:01:51 +00002397 if (!(hw->mac.arc_subsystem_valid)) {
2398 e_dbg("ARC subsystem not valid.\n");
2399 return -E1000_ERR_HOST_INTERFACE_COMMAND;
2400 }
2401
Auke Kokbc7f75f2007-09-17 12:30:59 -07002402 /* Check that the host interface is enabled. */
2403 hicr = er32(HICR);
2404 if ((hicr & E1000_HICR_EN) == 0) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002405 e_dbg("E1000_HOST_EN bit disabled.\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002406 return -E1000_ERR_HOST_INTERFACE_COMMAND;
2407 }
2408 /* check the previous command is completed */
2409 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
2410 hicr = er32(HICR);
2411 if (!(hicr & E1000_HICR_C))
2412 break;
2413 mdelay(1);
2414 }
2415
2416 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
Bruce Allan3bb99fe2009-11-20 23:25:07 +00002417 e_dbg("Previous command timeout failed .\n");
Auke Kokbc7f75f2007-09-17 12:30:59 -07002418 return -E1000_ERR_HOST_INTERFACE_COMMAND;
2419 }
2420
2421 return 0;
2422}
2423
2424/**
Bruce Allan4662e822008-08-26 18:37:06 -07002425 * e1000e_check_mng_mode_generic - check management mode
Auke Kokbc7f75f2007-09-17 12:30:59 -07002426 * @hw: pointer to the HW structure
2427 *
2428 * Reads the firmware semaphore register and returns true (>0) if
2429 * manageability is enabled, else false (0).
2430 **/
Bruce Allan4662e822008-08-26 18:37:06 -07002431bool e1000e_check_mng_mode_generic(struct e1000_hw *hw)
Auke Kokbc7f75f2007-09-17 12:30:59 -07002432{
2433 u32 fwsm = er32(FWSM);
2434
Bruce Allan4662e822008-08-26 18:37:06 -07002435 return (fwsm & E1000_FWSM_MODE_MASK) ==
2436 (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT);
Auke Kokbc7f75f2007-09-17 12:30:59 -07002437}
2438
2439/**
Bruce Allanad680762008-03-28 09:15:03 -07002440 * e1000e_enable_tx_pkt_filtering - Enable packet filtering on Tx
Auke Kokbc7f75f2007-09-17 12:30:59 -07002441 * @hw: pointer to the HW structure
2442 *
2443 * Enables packet filtering on transmit packets if manageability is enabled
2444 * and host interface is enabled.
2445 **/
2446bool e1000e_enable_tx_pkt_filtering(struct e1000_hw *hw)
2447{
2448 struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie;
2449 u32 *buffer = (u32 *)&hw->mng_cookie;
2450 u32 offset;
2451 s32 ret_val, hdr_csum, csum;
2452 u8 i, len;
2453
Bruce Allanca777f92010-01-07 16:31:54 +00002454 hw->mac.tx_pkt_filtering = true;
2455
Auke Kokbc7f75f2007-09-17 12:30:59 -07002456 /* No manageability, no filtering */
2457 if (!e1000e_check_mng_mode(hw)) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002458 hw->mac.tx_pkt_filtering = false;
Bruce Allanca777f92010-01-07 16:31:54 +00002459 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002460 }
2461
Bruce Allanad680762008-03-28 09:15:03 -07002462 /*
2463 * If we can't read from the host interface for whatever
Auke Kokbc7f75f2007-09-17 12:30:59 -07002464 * reason, disable filtering.
2465 */
2466 ret_val = e1000_mng_enable_host_if(hw);
Bruce Allanca777f92010-01-07 16:31:54 +00002467 if (ret_val) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002468 hw->mac.tx_pkt_filtering = false;
Bruce Allanca777f92010-01-07 16:31:54 +00002469 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002470 }
2471
2472 /* Read in the header. Length and offset are in dwords. */
2473 len = E1000_MNG_DHCP_COOKIE_LENGTH >> 2;
2474 offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2;
2475 for (i = 0; i < len; i++)
2476 *(buffer + i) = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset + i);
2477 hdr_csum = hdr->checksum;
2478 hdr->checksum = 0;
2479 csum = e1000_calculate_checksum((u8 *)hdr,
2480 E1000_MNG_DHCP_COOKIE_LENGTH);
Bruce Allanad680762008-03-28 09:15:03 -07002481 /*
2482 * If either the checksums or signature don't match, then
Auke Kokbc7f75f2007-09-17 12:30:59 -07002483 * the cookie area isn't considered valid, in which case we
2484 * take the safe route of assuming Tx filtering is enabled.
2485 */
2486 if ((hdr_csum != csum) || (hdr->signature != E1000_IAMT_SIGNATURE)) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002487 hw->mac.tx_pkt_filtering = true;
Bruce Allanca777f92010-01-07 16:31:54 +00002488 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002489 }
2490
2491 /* Cookie area is valid, make the final check for filtering. */
2492 if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING)) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002493 hw->mac.tx_pkt_filtering = false;
Bruce Allanca777f92010-01-07 16:31:54 +00002494 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002495 }
2496
Bruce Allanca777f92010-01-07 16:31:54 +00002497out:
2498 return hw->mac.tx_pkt_filtering;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002499}
2500
2501/**
2502 * e1000_mng_write_cmd_header - Writes manageability command header
2503 * @hw: pointer to the HW structure
2504 * @hdr: pointer to the host interface command header
2505 *
2506 * Writes the command header after does the checksum calculation.
2507 **/
2508static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw,
2509 struct e1000_host_mng_command_header *hdr)
2510{
2511 u16 i, length = sizeof(struct e1000_host_mng_command_header);
2512
2513 /* Write the whole command header structure with new checksum. */
2514
2515 hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length);
2516
2517 length >>= 2;
2518 /* Write the relevant command block into the ram area. */
2519 for (i = 0; i < length; i++) {
2520 E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, i,
2521 *((u32 *) hdr + i));
2522 e1e_flush();
2523 }
2524
2525 return 0;
2526}
2527
2528/**
Bruce Allan5ff5b662009-12-01 15:51:11 +00002529 * e1000_mng_host_if_write - Write to the manageability host interface
Auke Kokbc7f75f2007-09-17 12:30:59 -07002530 * @hw: pointer to the HW structure
2531 * @buffer: pointer to the host interface buffer
2532 * @length: size of the buffer
2533 * @offset: location in the buffer to write to
2534 * @sum: sum of the data (not checksum)
2535 *
2536 * This function writes the buffer content at the offset given on the host if.
2537 * It also does alignment considerations to do the writes in most efficient
2538 * way. Also fills up the sum of the buffer in *buffer parameter.
2539 **/
2540static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer,
2541 u16 length, u16 offset, u8 *sum)
2542{
2543 u8 *tmp;
2544 u8 *bufptr = buffer;
2545 u32 data = 0;
2546 u16 remaining, i, j, prev_bytes;
2547
2548 /* sum = only sum of the data and it is not checksum */
2549
2550 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH)
2551 return -E1000_ERR_PARAM;
2552
2553 tmp = (u8 *)&data;
2554 prev_bytes = offset & 0x3;
2555 offset >>= 2;
2556
2557 if (prev_bytes) {
2558 data = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset);
2559 for (j = prev_bytes; j < sizeof(u32); j++) {
2560 *(tmp + j) = *bufptr++;
2561 *sum += *(tmp + j);
2562 }
2563 E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset, data);
2564 length -= j - prev_bytes;
2565 offset++;
2566 }
2567
2568 remaining = length & 0x3;
2569 length -= remaining;
2570
2571 /* Calculate length in DWORDs */
2572 length >>= 2;
2573
Bruce Allanad680762008-03-28 09:15:03 -07002574 /*
2575 * The device driver writes the relevant command block into the
2576 * ram area.
2577 */
Auke Kokbc7f75f2007-09-17 12:30:59 -07002578 for (i = 0; i < length; i++) {
2579 for (j = 0; j < sizeof(u32); j++) {
2580 *(tmp + j) = *bufptr++;
2581 *sum += *(tmp + j);
2582 }
2583
2584 E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data);
2585 }
2586 if (remaining) {
2587 for (j = 0; j < sizeof(u32); j++) {
2588 if (j < remaining)
2589 *(tmp + j) = *bufptr++;
2590 else
2591 *(tmp + j) = 0;
2592
2593 *sum += *(tmp + j);
2594 }
2595 E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data);
2596 }
2597
2598 return 0;
2599}
2600
2601/**
2602 * e1000e_mng_write_dhcp_info - Writes DHCP info to host interface
2603 * @hw: pointer to the HW structure
2604 * @buffer: pointer to the host interface
2605 * @length: size of the buffer
2606 *
2607 * Writes the DHCP information to the host interface.
2608 **/
2609s32 e1000e_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length)
2610{
2611 struct e1000_host_mng_command_header hdr;
2612 s32 ret_val;
2613 u32 hicr;
2614
2615 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
2616 hdr.command_length = length;
2617 hdr.reserved1 = 0;
2618 hdr.reserved2 = 0;
2619 hdr.checksum = 0;
2620
2621 /* Enable the host interface */
2622 ret_val = e1000_mng_enable_host_if(hw);
2623 if (ret_val)
2624 return ret_val;
2625
2626 /* Populate the host interface with the contents of "buffer". */
2627 ret_val = e1000_mng_host_if_write(hw, buffer, length,
2628 sizeof(hdr), &(hdr.checksum));
2629 if (ret_val)
2630 return ret_val;
2631
2632 /* Write the manageability command header */
2633 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
2634 if (ret_val)
2635 return ret_val;
2636
2637 /* Tell the ARC a new command is pending. */
2638 hicr = er32(HICR);
2639 ew32(HICR, hicr | E1000_HICR_C);
2640
2641 return 0;
2642}
2643
2644/**
Bruce Allan757c5302010-05-10 15:00:50 +00002645 * e1000e_enable_mng_pass_thru - Check if management passthrough is needed
Auke Kokbc7f75f2007-09-17 12:30:59 -07002646 * @hw: pointer to the HW structure
2647 *
Bruce Allan757c5302010-05-10 15:00:50 +00002648 * Verifies the hardware needs to leave interface enabled so that frames can
2649 * be directed to and from the management interface.
Auke Kokbc7f75f2007-09-17 12:30:59 -07002650 **/
2651bool e1000e_enable_mng_pass_thru(struct e1000_hw *hw)
2652{
2653 u32 manc;
2654 u32 fwsm, factps;
Bruce Allan564ea9b2009-11-20 23:26:44 +00002655 bool ret_val = false;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002656
2657 manc = er32(MANC);
2658
Bruce Allan757c5302010-05-10 15:00:50 +00002659 if (!(manc & E1000_MANC_RCV_TCO_EN))
Bruce Allana65a4a02010-05-10 15:01:51 +00002660 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002661
Bruce Allana65a4a02010-05-10 15:01:51 +00002662 if (hw->mac.has_fwsm) {
Auke Kokbc7f75f2007-09-17 12:30:59 -07002663 fwsm = er32(FWSM);
2664 factps = er32(FACTPS);
2665
2666 if (!(factps & E1000_FACTPS_MNGCG) &&
2667 ((fwsm & E1000_FWSM_MODE_MASK) ==
2668 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002669 ret_val = true;
Bruce Allana65a4a02010-05-10 15:01:51 +00002670 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002671 }
Bruce Allana65a4a02010-05-10 15:01:51 +00002672 } else if ((hw->mac.type == e1000_82574) ||
2673 (hw->mac.type == e1000_82583)) {
2674 u16 data;
2675
2676 factps = er32(FACTPS);
2677 e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data);
2678
2679 if (!(factps & E1000_FACTPS_MNGCG) &&
2680 ((data & E1000_NVM_INIT_CTRL2_MNGM) ==
2681 (e1000_mng_mode_pt << 13))) {
2682 ret_val = true;
2683 goto out;
2684 }
2685 } else if ((manc & E1000_MANC_SMBUS_EN) &&
Auke Kokbc7f75f2007-09-17 12:30:59 -07002686 !(manc & E1000_MANC_ASF_EN)) {
Bruce Allan564ea9b2009-11-20 23:26:44 +00002687 ret_val = true;
Bruce Allana65a4a02010-05-10 15:01:51 +00002688 goto out;
Auke Kokbc7f75f2007-09-17 12:30:59 -07002689 }
2690
Bruce Allana65a4a02010-05-10 15:01:51 +00002691out:
Auke Kokbc7f75f2007-09-17 12:30:59 -07002692 return ret_val;
2693}