Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / net / e1000e / lib.c
blob20a6d3e07895f1dd7b422c7179b204368e3d3fa7
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2007 Intel Corporation.
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.
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.
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.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
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
27 *******************************************************************************/
29 #include <linux/netdevice.h>
30 #include <linux/ethtool.h>
31 #include <linux/delay.h>
32 #include <linux/pci.h>
34 #include "e1000.h"
36 enum e1000_mng_mode {
37 e1000_mng_mode_none = 0,
38 e1000_mng_mode_asf,
39 e1000_mng_mode_pt,
40 e1000_mng_mode_ipmi,
41 e1000_mng_mode_host_if_only
44 #define E1000_FACTPS_MNGCG 0x20000000
46 #define E1000_IAMT_SIGNATURE 0x544D4149 /* Intel(R) Active Management
47 * Technology signature */
49 /**
50 * e1000e_get_bus_info_pcie - Get PCIe bus information
51 * @hw: pointer to the HW structure
53 * Determines and stores the system bus information for a particular
54 * network interface. The following bus information is determined and stored:
55 * bus speed, bus width, type (PCIe), and PCIe function.
56 **/
57 s32 e1000e_get_bus_info_pcie(struct e1000_hw *hw)
59 struct e1000_bus_info *bus = &hw->bus;
60 struct e1000_adapter *adapter = hw->adapter;
61 u32 status;
62 u16 pcie_link_status, pci_header_type, cap_offset;
64 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
65 if (!cap_offset) {
66 bus->width = e1000_bus_width_unknown;
67 } else {
68 pci_read_config_word(adapter->pdev,
69 cap_offset + PCIE_LINK_STATUS,
70 &pcie_link_status);
71 bus->width = (enum e1000_bus_width)((pcie_link_status &
72 PCIE_LINK_WIDTH_MASK) >>
73 PCIE_LINK_WIDTH_SHIFT);
76 pci_read_config_word(adapter->pdev, PCI_HEADER_TYPE_REGISTER,
77 &pci_header_type);
78 if (pci_header_type & PCI_HEADER_TYPE_MULTIFUNC) {
79 status = er32(STATUS);
80 bus->func = (status & E1000_STATUS_FUNC_MASK)
81 >> E1000_STATUS_FUNC_SHIFT;
82 } else {
83 bus->func = 0;
86 return 0;
89 /**
90 * e1000e_write_vfta - Write value to VLAN filter table
91 * @hw: pointer to the HW structure
92 * @offset: register offset in VLAN filter table
93 * @value: register value written to VLAN filter table
95 * Writes value at the given offset in the register array which stores
96 * the VLAN filter table.
97 **/
98 void e1000e_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
100 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
101 e1e_flush();
105 * e1000e_init_rx_addrs - Initialize receive address's
106 * @hw: pointer to the HW structure
107 * @rar_count: receive address registers
109 * Setups the receive address registers by setting the base receive address
110 * register to the devices MAC address and clearing all the other receive
111 * address registers to 0.
113 void e1000e_init_rx_addrs(struct e1000_hw *hw, u16 rar_count)
115 u32 i;
117 /* Setup the receive address */
118 hw_dbg(hw, "Programming MAC Address into RAR[0]\n");
120 e1000e_rar_set(hw, hw->mac.addr, 0);
122 /* Zero out the other (rar_entry_count - 1) receive addresses */
123 hw_dbg(hw, "Clearing RAR[1-%u]\n", rar_count-1);
124 for (i = 1; i < rar_count; i++) {
125 E1000_WRITE_REG_ARRAY(hw, E1000_RA, (i << 1), 0);
126 e1e_flush();
127 E1000_WRITE_REG_ARRAY(hw, E1000_RA, ((i << 1) + 1), 0);
128 e1e_flush();
133 * e1000e_rar_set - Set receive address register
134 * @hw: pointer to the HW structure
135 * @addr: pointer to the receive address
136 * @index: receive address array register
138 * Sets the receive address array register at index to the address passed
139 * in by addr.
141 void e1000e_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
143 u32 rar_low, rar_high;
145 /* HW expects these in little endian so we reverse the byte order
146 * from network order (big endian) to little endian
148 rar_low = ((u32) addr[0] |
149 ((u32) addr[1] << 8) |
150 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
152 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
154 rar_high |= E1000_RAH_AV;
156 E1000_WRITE_REG_ARRAY(hw, E1000_RA, (index << 1), rar_low);
157 E1000_WRITE_REG_ARRAY(hw, E1000_RA, ((index << 1) + 1), rar_high);
161 * e1000_mta_set - Set multicast filter table address
162 * @hw: pointer to the HW structure
163 * @hash_value: determines the MTA register and bit to set
165 * The multicast table address is a register array of 32-bit registers.
166 * The hash_value is used to determine what register the bit is in, the
167 * current value is read, the new bit is OR'd in and the new value is
168 * written back into the register.
170 static void e1000_mta_set(struct e1000_hw *hw, u32 hash_value)
172 u32 hash_bit, hash_reg, mta;
174 /* The MTA is a register array of 32-bit registers. It is
175 * treated like an array of (32*mta_reg_count) bits. We want to
176 * set bit BitArray[hash_value]. So we figure out what register
177 * the bit is in, read it, OR in the new bit, then write
178 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
179 * mask to bits 31:5 of the hash value which gives us the
180 * register we're modifying. The hash bit within that register
181 * is determined by the lower 5 bits of the hash value.
183 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
184 hash_bit = hash_value & 0x1F;
186 mta = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg);
188 mta |= (1 << hash_bit);
190 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg, mta);
191 e1e_flush();
195 * e1000_hash_mc_addr - Generate a multicast hash value
196 * @hw: pointer to the HW structure
197 * @mc_addr: pointer to a multicast address
199 * Generates a multicast address hash value which is used to determine
200 * the multicast filter table array address and new table value. See
201 * e1000_mta_set_generic()
203 static u32 e1000_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
205 u32 hash_value, hash_mask;
206 u8 bit_shift = 0;
208 /* Register count multiplied by bits per register */
209 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
211 /* For a mc_filter_type of 0, bit_shift is the number of left-shifts
212 * where 0xFF would still fall within the hash mask. */
213 while (hash_mask >> bit_shift != 0xFF)
214 bit_shift++;
216 /* The portion of the address that is used for the hash table
217 * is determined by the mc_filter_type setting.
218 * The algorithm is such that there is a total of 8 bits of shifting.
219 * The bit_shift for a mc_filter_type of 0 represents the number of
220 * left-shifts where the MSB of mc_addr[5] would still fall within
221 * the hash_mask. Case 0 does this exactly. Since there are a total
222 * of 8 bits of shifting, then mc_addr[4] will shift right the
223 * remaining number of bits. Thus 8 - bit_shift. The rest of the
224 * cases are a variation of this algorithm...essentially raising the
225 * number of bits to shift mc_addr[5] left, while still keeping the
226 * 8-bit shifting total.
228 /* For example, given the following Destination MAC Address and an
229 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
230 * we can see that the bit_shift for case 0 is 4. These are the hash
231 * values resulting from each mc_filter_type...
232 * [0] [1] [2] [3] [4] [5]
233 * 01 AA 00 12 34 56
234 * LSB MSB
236 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
237 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
238 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
239 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
241 switch (hw->mac.mc_filter_type) {
242 default:
243 case 0:
244 break;
245 case 1:
246 bit_shift += 1;
247 break;
248 case 2:
249 bit_shift += 2;
250 break;
251 case 3:
252 bit_shift += 4;
253 break;
256 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
257 (((u16) mc_addr[5]) << bit_shift)));
259 return hash_value;
263 * e1000e_mc_addr_list_update_generic - Update Multicast addresses
264 * @hw: pointer to the HW structure
265 * @mc_addr_list: array of multicast addresses to program
266 * @mc_addr_count: number of multicast addresses to program
267 * @rar_used_count: the first RAR register free to program
268 * @rar_count: total number of supported Receive Address Registers
270 * Updates the Receive Address Registers and Multicast Table Array.
271 * The caller must have a packed mc_addr_list of multicast addresses.
272 * The parameter rar_count will usually be hw->mac.rar_entry_count
273 * unless there are workarounds that change this.
275 void e1000e_mc_addr_list_update_generic(struct e1000_hw *hw,
276 u8 *mc_addr_list, u32 mc_addr_count,
277 u32 rar_used_count, u32 rar_count)
279 u32 hash_value;
280 u32 i;
282 /* Load the first set of multicast addresses into the exact
283 * filters (RAR). If there are not enough to fill the RAR
284 * array, clear the filters.
286 for (i = rar_used_count; i < rar_count; i++) {
287 if (mc_addr_count) {
288 e1000e_rar_set(hw, mc_addr_list, i);
289 mc_addr_count--;
290 mc_addr_list += ETH_ALEN;
291 } else {
292 E1000_WRITE_REG_ARRAY(hw, E1000_RA, i << 1, 0);
293 e1e_flush();
294 E1000_WRITE_REG_ARRAY(hw, E1000_RA, (i << 1) + 1, 0);
295 e1e_flush();
299 /* Clear the old settings from the MTA */
300 hw_dbg(hw, "Clearing MTA\n");
301 for (i = 0; i < hw->mac.mta_reg_count; i++) {
302 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
303 e1e_flush();
306 /* Load any remaining multicast addresses into the hash table. */
307 for (; mc_addr_count > 0; mc_addr_count--) {
308 hash_value = e1000_hash_mc_addr(hw, mc_addr_list);
309 hw_dbg(hw, "Hash value = 0x%03X\n", hash_value);
310 e1000_mta_set(hw, hash_value);
311 mc_addr_list += ETH_ALEN;
316 * e1000e_clear_hw_cntrs_base - Clear base hardware counters
317 * @hw: pointer to the HW structure
319 * Clears the base hardware counters by reading the counter registers.
321 void e1000e_clear_hw_cntrs_base(struct e1000_hw *hw)
323 u32 temp;
325 temp = er32(CRCERRS);
326 temp = er32(SYMERRS);
327 temp = er32(MPC);
328 temp = er32(SCC);
329 temp = er32(ECOL);
330 temp = er32(MCC);
331 temp = er32(LATECOL);
332 temp = er32(COLC);
333 temp = er32(DC);
334 temp = er32(SEC);
335 temp = er32(RLEC);
336 temp = er32(XONRXC);
337 temp = er32(XONTXC);
338 temp = er32(XOFFRXC);
339 temp = er32(XOFFTXC);
340 temp = er32(FCRUC);
341 temp = er32(GPRC);
342 temp = er32(BPRC);
343 temp = er32(MPRC);
344 temp = er32(GPTC);
345 temp = er32(GORCL);
346 temp = er32(GORCH);
347 temp = er32(GOTCL);
348 temp = er32(GOTCH);
349 temp = er32(RNBC);
350 temp = er32(RUC);
351 temp = er32(RFC);
352 temp = er32(ROC);
353 temp = er32(RJC);
354 temp = er32(TORL);
355 temp = er32(TORH);
356 temp = er32(TOTL);
357 temp = er32(TOTH);
358 temp = er32(TPR);
359 temp = er32(TPT);
360 temp = er32(MPTC);
361 temp = er32(BPTC);
365 * e1000e_check_for_copper_link - Check for link (Copper)
366 * @hw: pointer to the HW structure
368 * Checks to see of the link status of the hardware has changed. If a
369 * change in link status has been detected, then we read the PHY registers
370 * to get the current speed/duplex if link exists.
372 s32 e1000e_check_for_copper_link(struct e1000_hw *hw)
374 struct e1000_mac_info *mac = &hw->mac;
375 s32 ret_val;
376 bool link;
378 /* We only want to go out to the PHY registers to see if Auto-Neg
379 * has completed and/or if our link status has changed. The
380 * get_link_status flag is set upon receiving a Link Status
381 * Change or Rx Sequence Error interrupt.
383 if (!mac->get_link_status)
384 return 0;
386 /* First we want to see if the MII Status Register reports
387 * link. If so, then we want to get the current speed/duplex
388 * of the PHY.
390 ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
391 if (ret_val)
392 return ret_val;
394 if (!link)
395 return ret_val; /* No link detected */
397 mac->get_link_status = 0;
399 /* Check if there was DownShift, must be checked
400 * immediately after link-up */
401 e1000e_check_downshift(hw);
403 /* If we are forcing speed/duplex, then we simply return since
404 * we have already determined whether we have link or not.
406 if (!mac->autoneg) {
407 ret_val = -E1000_ERR_CONFIG;
408 return ret_val;
411 /* Auto-Neg is enabled. Auto Speed Detection takes care
412 * of MAC speed/duplex configuration. So we only need to
413 * configure Collision Distance in the MAC.
415 e1000e_config_collision_dist(hw);
417 /* Configure Flow Control now that Auto-Neg has completed.
418 * First, we need to restore the desired flow control
419 * settings because we may have had to re-autoneg with a
420 * different link partner.
422 ret_val = e1000e_config_fc_after_link_up(hw);
423 if (ret_val) {
424 hw_dbg(hw, "Error configuring flow control\n");
427 return ret_val;
431 * e1000e_check_for_fiber_link - Check for link (Fiber)
432 * @hw: pointer to the HW structure
434 * Checks for link up on the hardware. If link is not up and we have
435 * a signal, then we need to force link up.
437 s32 e1000e_check_for_fiber_link(struct e1000_hw *hw)
439 struct e1000_mac_info *mac = &hw->mac;
440 u32 rxcw;
441 u32 ctrl;
442 u32 status;
443 s32 ret_val;
445 ctrl = er32(CTRL);
446 status = er32(STATUS);
447 rxcw = er32(RXCW);
449 /* If we don't have link (auto-negotiation failed or link partner
450 * cannot auto-negotiate), the cable is plugged in (we have signal),
451 * and our link partner is not trying to auto-negotiate with us (we
452 * are receiving idles or data), we need to force link up. We also
453 * need to give auto-negotiation time to complete, in case the cable
454 * was just plugged in. The autoneg_failed flag does this.
456 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
457 if ((ctrl & E1000_CTRL_SWDPIN1) && (!(status & E1000_STATUS_LU)) &&
458 (!(rxcw & E1000_RXCW_C))) {
459 if (mac->autoneg_failed == 0) {
460 mac->autoneg_failed = 1;
461 return 0;
463 hw_dbg(hw, "NOT RXing /C/, disable AutoNeg and force link.\n");
465 /* Disable auto-negotiation in the TXCW register */
466 ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
468 /* Force link-up and also force full-duplex. */
469 ctrl = er32(CTRL);
470 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
471 ew32(CTRL, ctrl);
473 /* Configure Flow Control after forcing link up. */
474 ret_val = e1000e_config_fc_after_link_up(hw);
475 if (ret_val) {
476 hw_dbg(hw, "Error configuring flow control\n");
477 return ret_val;
479 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
480 /* If we are forcing link and we are receiving /C/ ordered
481 * sets, re-enable auto-negotiation in the TXCW register
482 * and disable forced link in the Device Control register
483 * in an attempt to auto-negotiate with our link partner.
485 hw_dbg(hw, "RXing /C/, enable AutoNeg and stop forcing link.\n");
486 ew32(TXCW, mac->txcw);
487 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
489 mac->serdes_has_link = 1;
492 return 0;
496 * e1000e_check_for_serdes_link - Check for link (Serdes)
497 * @hw: pointer to the HW structure
499 * Checks for link up on the hardware. If link is not up and we have
500 * a signal, then we need to force link up.
502 s32 e1000e_check_for_serdes_link(struct e1000_hw *hw)
504 struct e1000_mac_info *mac = &hw->mac;
505 u32 rxcw;
506 u32 ctrl;
507 u32 status;
508 s32 ret_val;
510 ctrl = er32(CTRL);
511 status = er32(STATUS);
512 rxcw = er32(RXCW);
514 /* If we don't have link (auto-negotiation failed or link partner
515 * cannot auto-negotiate), and our link partner is not trying to
516 * auto-negotiate with us (we are receiving idles or data),
517 * we need to force link up. We also need to give auto-negotiation
518 * time to complete.
520 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
521 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
522 if (mac->autoneg_failed == 0) {
523 mac->autoneg_failed = 1;
524 return 0;
526 hw_dbg(hw, "NOT RXing /C/, disable AutoNeg and force link.\n");
528 /* Disable auto-negotiation in the TXCW register */
529 ew32(TXCW, (mac->txcw & ~E1000_TXCW_ANE));
531 /* Force link-up and also force full-duplex. */
532 ctrl = er32(CTRL);
533 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
534 ew32(CTRL, ctrl);
536 /* Configure Flow Control after forcing link up. */
537 ret_val = e1000e_config_fc_after_link_up(hw);
538 if (ret_val) {
539 hw_dbg(hw, "Error configuring flow control\n");
540 return ret_val;
542 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
543 /* If we are forcing link and we are receiving /C/ ordered
544 * sets, re-enable auto-negotiation in the TXCW register
545 * and disable forced link in the Device Control register
546 * in an attempt to auto-negotiate with our link partner.
548 hw_dbg(hw, "RXing /C/, enable AutoNeg and stop forcing link.\n");
549 ew32(TXCW, mac->txcw);
550 ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
552 mac->serdes_has_link = 1;
553 } else if (!(E1000_TXCW_ANE & er32(TXCW))) {
554 /* If we force link for non-auto-negotiation switch, check
555 * link status based on MAC synchronization for internal
556 * serdes media type.
558 /* SYNCH bit and IV bit are sticky. */
559 udelay(10);
560 if (E1000_RXCW_SYNCH & er32(RXCW)) {
561 if (!(rxcw & E1000_RXCW_IV)) {
562 mac->serdes_has_link = 1;
563 hw_dbg(hw, "SERDES: Link is up.\n");
565 } else {
566 mac->serdes_has_link = 0;
567 hw_dbg(hw, "SERDES: Link is down.\n");
571 if (E1000_TXCW_ANE & er32(TXCW)) {
572 status = er32(STATUS);
573 mac->serdes_has_link = (status & E1000_STATUS_LU);
576 return 0;
580 * e1000_set_default_fc_generic - Set flow control default values
581 * @hw: pointer to the HW structure
583 * Read the EEPROM for the default values for flow control and store the
584 * values.
586 static s32 e1000_set_default_fc_generic(struct e1000_hw *hw)
588 struct e1000_mac_info *mac = &hw->mac;
589 s32 ret_val;
590 u16 nvm_data;
592 <<<<<<< HEAD:drivers/net/e1000e/lib.c
593 if (mac->fc != e1000_fc_default)
594 return 0;
596 =======
597 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
598 /* Read and store word 0x0F of the EEPROM. This word contains bits
599 * that determine the hardware's default PAUSE (flow control) mode,
600 * a bit that determines whether the HW defaults to enabling or
601 * disabling auto-negotiation, and the direction of the
602 * SW defined pins. If there is no SW over-ride of the flow
603 * control setting, then the variable hw->fc will
604 * be initialized based on a value in the EEPROM.
606 ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
608 if (ret_val) {
609 hw_dbg(hw, "NVM Read Error\n");
610 return ret_val;
613 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
614 mac->fc = e1000_fc_none;
615 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
616 NVM_WORD0F_ASM_DIR)
617 mac->fc = e1000_fc_tx_pause;
618 else
619 mac->fc = e1000_fc_full;
621 return 0;
625 * e1000e_setup_link - Setup flow control and link settings
626 * @hw: pointer to the HW structure
628 * Determines which flow control settings to use, then configures flow
629 * control. Calls the appropriate media-specific link configuration
630 * function. Assuming the adapter has a valid link partner, a valid link
631 * should be established. Assumes the hardware has previously been reset
632 * and the transmitter and receiver are not enabled.
634 s32 e1000e_setup_link(struct e1000_hw *hw)
636 struct e1000_mac_info *mac = &hw->mac;
637 s32 ret_val;
639 /* In the case of the phy reset being blocked, we already have a link.
640 * We do not need to set it up again.
642 if (e1000_check_reset_block(hw))
643 return 0;
646 * If flow control is set to default, set flow control based on
647 * the EEPROM flow control settings.
649 if (mac->fc == e1000_fc_default) {
650 ret_val = e1000_set_default_fc_generic(hw);
651 if (ret_val)
652 return ret_val;
655 /* We want to save off the original Flow Control configuration just
656 * in case we get disconnected and then reconnected into a different
657 * hub or switch with different Flow Control capabilities.
659 mac->original_fc = mac->fc;
661 hw_dbg(hw, "After fix-ups FlowControl is now = %x\n", mac->fc);
663 /* Call the necessary media_type subroutine to configure the link. */
664 ret_val = mac->ops.setup_physical_interface(hw);
665 if (ret_val)
666 return ret_val;
668 /* Initialize the flow control address, type, and PAUSE timer
669 * registers to their default values. This is done even if flow
670 * control is disabled, because it does not hurt anything to
671 * initialize these registers.
673 hw_dbg(hw, "Initializing the Flow Control address, type and timer regs\n");
674 ew32(FCT, FLOW_CONTROL_TYPE);
675 ew32(FCAH, FLOW_CONTROL_ADDRESS_HIGH);
676 ew32(FCAL, FLOW_CONTROL_ADDRESS_LOW);
678 ew32(FCTTV, mac->fc_pause_time);
680 return e1000e_set_fc_watermarks(hw);
684 * e1000_commit_fc_settings_generic - Configure flow control
685 * @hw: pointer to the HW structure
687 * Write the flow control settings to the Transmit Config Word Register (TXCW)
688 * base on the flow control settings in e1000_mac_info.
690 static s32 e1000_commit_fc_settings_generic(struct e1000_hw *hw)
692 struct e1000_mac_info *mac = &hw->mac;
693 u32 txcw;
695 /* Check for a software override of the flow control settings, and
696 * setup the device accordingly. If auto-negotiation is enabled, then
697 * software will have to set the "PAUSE" bits to the correct value in
698 * the Transmit Config Word Register (TXCW) and re-start auto-
699 * negotiation. However, if auto-negotiation is disabled, then
700 * software will have to manually configure the two flow control enable
701 * bits in the CTRL register.
703 * The possible values of the "fc" parameter are:
704 * 0: Flow control is completely disabled
705 * 1: Rx flow control is enabled (we can receive pause frames,
706 * but not send pause frames).
707 * 2: Tx flow control is enabled (we can send pause frames but we
708 * do not support receiving pause frames).
709 * 3: Both Rx and TX flow control (symmetric) are enabled.
711 switch (mac->fc) {
712 case e1000_fc_none:
713 /* Flow control completely disabled by a software over-ride. */
714 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
715 break;
716 case e1000_fc_rx_pause:
717 /* RX Flow control is enabled and TX Flow control is disabled
718 * by a software over-ride. Since there really isn't a way to
719 * advertise that we are capable of RX Pause ONLY, we will
720 * advertise that we support both symmetric and asymmetric RX
721 * PAUSE. Later, we will disable the adapter's ability to send
722 * PAUSE frames.
724 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
725 break;
726 case e1000_fc_tx_pause:
727 /* TX Flow control is enabled, and RX Flow control is disabled,
728 * by a software over-ride.
730 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
731 break;
732 case e1000_fc_full:
733 /* Flow control (both RX and TX) is enabled by a software
734 * over-ride.
736 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
737 break;
738 default:
739 hw_dbg(hw, "Flow control param set incorrectly\n");
740 return -E1000_ERR_CONFIG;
741 break;
744 ew32(TXCW, txcw);
745 mac->txcw = txcw;
747 return 0;
751 * e1000_poll_fiber_serdes_link_generic - Poll for link up
752 * @hw: pointer to the HW structure
754 * Polls for link up by reading the status register, if link fails to come
755 * up with auto-negotiation, then the link is forced if a signal is detected.
757 static s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw)
759 struct e1000_mac_info *mac = &hw->mac;
760 u32 i, status;
761 s32 ret_val;
763 /* If we have a signal (the cable is plugged in, or assumed true for
764 * serdes media) then poll for a "Link-Up" indication in the Device
765 * Status Register. Time-out if a link isn't seen in 500 milliseconds
766 * seconds (Auto-negotiation should complete in less than 500
767 * milliseconds even if the other end is doing it in SW).
769 for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
770 msleep(10);
771 status = er32(STATUS);
772 if (status & E1000_STATUS_LU)
773 break;
775 if (i == FIBER_LINK_UP_LIMIT) {
776 hw_dbg(hw, "Never got a valid link from auto-neg!!!\n");
777 mac->autoneg_failed = 1;
778 /* AutoNeg failed to achieve a link, so we'll call
779 * mac->check_for_link. This routine will force the
780 * link up if we detect a signal. This will allow us to
781 * communicate with non-autonegotiating link partners.
783 ret_val = mac->ops.check_for_link(hw);
784 if (ret_val) {
785 hw_dbg(hw, "Error while checking for link\n");
786 return ret_val;
788 mac->autoneg_failed = 0;
789 } else {
790 mac->autoneg_failed = 0;
791 hw_dbg(hw, "Valid Link Found\n");
794 return 0;
798 * e1000e_setup_fiber_serdes_link - Setup link for fiber/serdes
799 * @hw: pointer to the HW structure
801 * Configures collision distance and flow control for fiber and serdes
802 * links. Upon successful setup, poll for link.
804 s32 e1000e_setup_fiber_serdes_link(struct e1000_hw *hw)
806 u32 ctrl;
807 s32 ret_val;
809 ctrl = er32(CTRL);
811 /* Take the link out of reset */
812 ctrl &= ~E1000_CTRL_LRST;
814 e1000e_config_collision_dist(hw);
816 ret_val = e1000_commit_fc_settings_generic(hw);
817 if (ret_val)
818 return ret_val;
820 /* Since auto-negotiation is enabled, take the link out of reset (the
821 * link will be in reset, because we previously reset the chip). This
822 * will restart auto-negotiation. If auto-negotiation is successful
823 * then the link-up status bit will be set and the flow control enable
824 * bits (RFCE and TFCE) will be set according to their negotiated value.
826 hw_dbg(hw, "Auto-negotiation enabled\n");
828 ew32(CTRL, ctrl);
829 e1e_flush();
830 msleep(1);
832 /* For these adapters, the SW defineable pin 1 is set when the optics
833 * detect a signal. If we have a signal, then poll for a "Link-Up"
834 * indication.
836 if (hw->media_type == e1000_media_type_internal_serdes ||
837 (er32(CTRL) & E1000_CTRL_SWDPIN1)) {
838 ret_val = e1000_poll_fiber_serdes_link_generic(hw);
839 } else {
840 hw_dbg(hw, "No signal detected\n");
843 return 0;
847 * e1000e_config_collision_dist - Configure collision distance
848 * @hw: pointer to the HW structure
850 * Configures the collision distance to the default value and is used
851 * during link setup. Currently no func pointer exists and all
852 * implementations are handled in the generic version of this function.
854 void e1000e_config_collision_dist(struct e1000_hw *hw)
856 u32 tctl;
858 tctl = er32(TCTL);
860 tctl &= ~E1000_TCTL_COLD;
861 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
863 ew32(TCTL, tctl);
864 e1e_flush();
868 * e1000e_set_fc_watermarks - Set flow control high/low watermarks
869 * @hw: pointer to the HW structure
871 * Sets the flow control high/low threshold (watermark) registers. If
872 * flow control XON frame transmission is enabled, then set XON frame
873 * tansmission as well.
875 s32 e1000e_set_fc_watermarks(struct e1000_hw *hw)
877 struct e1000_mac_info *mac = &hw->mac;
878 u32 fcrtl = 0, fcrth = 0;
880 /* Set the flow control receive threshold registers. Normally,
881 * these registers will be set to a default threshold that may be
882 * adjusted later by the driver's runtime code. However, if the
883 * ability to transmit pause frames is not enabled, then these
884 * registers will be set to 0.
886 if (mac->fc & e1000_fc_tx_pause) {
887 /* We need to set up the Receive Threshold high and low water
888 * marks as well as (optionally) enabling the transmission of
889 * XON frames.
891 fcrtl = mac->fc_low_water;
892 fcrtl |= E1000_FCRTL_XONE;
893 fcrth = mac->fc_high_water;
895 ew32(FCRTL, fcrtl);
896 ew32(FCRTH, fcrth);
898 return 0;
902 * e1000e_force_mac_fc - Force the MAC's flow control settings
903 * @hw: pointer to the HW structure
905 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
906 * device control register to reflect the adapter settings. TFCE and RFCE
907 * need to be explicitly set by software when a copper PHY is used because
908 * autonegotiation is managed by the PHY rather than the MAC. Software must
909 * also configure these bits when link is forced on a fiber connection.
911 s32 e1000e_force_mac_fc(struct e1000_hw *hw)
913 struct e1000_mac_info *mac = &hw->mac;
914 u32 ctrl;
916 ctrl = er32(CTRL);
918 /* Because we didn't get link via the internal auto-negotiation
919 * mechanism (we either forced link or we got link via PHY
920 * auto-neg), we have to manually enable/disable transmit an
921 * receive flow control.
923 * The "Case" statement below enables/disable flow control
924 * according to the "mac->fc" parameter.
926 * The possible values of the "fc" parameter are:
927 * 0: Flow control is completely disabled
928 * 1: Rx flow control is enabled (we can receive pause
929 * frames but not send pause frames).
930 * 2: Tx flow control is enabled (we can send pause frames
931 * frames but we do not receive pause frames).
932 * 3: Both Rx and TX flow control (symmetric) is enabled.
933 * other: No other values should be possible at this point.
935 hw_dbg(hw, "mac->fc = %u\n", mac->fc);
937 switch (mac->fc) {
938 case e1000_fc_none:
939 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
940 break;
941 case e1000_fc_rx_pause:
942 ctrl &= (~E1000_CTRL_TFCE);
943 ctrl |= E1000_CTRL_RFCE;
944 break;
945 case e1000_fc_tx_pause:
946 ctrl &= (~E1000_CTRL_RFCE);
947 ctrl |= E1000_CTRL_TFCE;
948 break;
949 case e1000_fc_full:
950 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
951 break;
952 default:
953 hw_dbg(hw, "Flow control param set incorrectly\n");
954 return -E1000_ERR_CONFIG;
957 ew32(CTRL, ctrl);
959 return 0;
963 * e1000e_config_fc_after_link_up - Configures flow control after link
964 * @hw: pointer to the HW structure
966 * Checks the status of auto-negotiation after link up to ensure that the
967 * speed and duplex were not forced. If the link needed to be forced, then
968 * flow control needs to be forced also. If auto-negotiation is enabled
969 * and did not fail, then we configure flow control based on our link
970 * partner.
972 s32 e1000e_config_fc_after_link_up(struct e1000_hw *hw)
974 struct e1000_mac_info *mac = &hw->mac;
975 s32 ret_val = 0;
976 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
977 u16 speed, duplex;
979 /* Check for the case where we have fiber media and auto-neg failed
980 * so we had to force link. In this case, we need to force the
981 * configuration of the MAC to match the "fc" parameter.
983 if (mac->autoneg_failed) {
984 if (hw->media_type == e1000_media_type_fiber ||
985 hw->media_type == e1000_media_type_internal_serdes)
986 ret_val = e1000e_force_mac_fc(hw);
987 } else {
988 if (hw->media_type == e1000_media_type_copper)
989 ret_val = e1000e_force_mac_fc(hw);
992 if (ret_val) {
993 hw_dbg(hw, "Error forcing flow control settings\n");
994 return ret_val;
997 /* Check for the case where we have copper media and auto-neg is
998 * enabled. In this case, we need to check and see if Auto-Neg
999 * has completed, and if so, how the PHY and link partner has
1000 * flow control configured.
1002 if ((hw->media_type == e1000_media_type_copper) && mac->autoneg) {
1003 /* Read the MII Status Register and check to see if AutoNeg
1004 * has completed. We read this twice because this reg has
1005 * some "sticky" (latched) bits.
1007 ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg);
1008 if (ret_val)
1009 return ret_val;
1010 ret_val = e1e_rphy(hw, PHY_STATUS, &mii_status_reg);
1011 if (ret_val)
1012 return ret_val;
1014 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
1015 hw_dbg(hw, "Copper PHY and Auto Neg "
1016 "has not completed.\n");
1017 return ret_val;
1020 /* The AutoNeg process has completed, so we now need to
1021 * read both the Auto Negotiation Advertisement
1022 * Register (Address 4) and the Auto_Negotiation Base
1023 * Page Ability Register (Address 5) to determine how
1024 * flow control was negotiated.
1026 ret_val = e1e_rphy(hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg);
1027 if (ret_val)
1028 return ret_val;
1029 ret_val = e1e_rphy(hw, PHY_LP_ABILITY, &mii_nway_lp_ability_reg);
1030 if (ret_val)
1031 return ret_val;
1033 /* Two bits in the Auto Negotiation Advertisement Register
1034 * (Address 4) and two bits in the Auto Negotiation Base
1035 * Page Ability Register (Address 5) determine flow control
1036 * for both the PHY and the link partner. The following
1037 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
1038 * 1999, describes these PAUSE resolution bits and how flow
1039 * control is determined based upon these settings.
1040 * NOTE: DC = Don't Care
1042 * LOCAL DEVICE | LINK PARTNER
1043 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
1044 *-------|---------|-------|---------|--------------------
1045 * 0 | 0 | DC | DC | e1000_fc_none
1046 * 0 | 1 | 0 | DC | e1000_fc_none
1047 * 0 | 1 | 1 | 0 | e1000_fc_none
1048 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1049 * 1 | 0 | 0 | DC | e1000_fc_none
1050 * 1 | DC | 1 | DC | e1000_fc_full
1051 * 1 | 1 | 0 | 0 | e1000_fc_none
1052 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1055 /* Are both PAUSE bits set to 1? If so, this implies
1056 * Symmetric Flow Control is enabled at both ends. The
1057 * ASM_DIR bits are irrelevant per the spec.
1059 * For Symmetric Flow Control:
1061 * LOCAL DEVICE | LINK PARTNER
1062 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1063 *-------|---------|-------|---------|--------------------
1064 * 1 | DC | 1 | DC | E1000_fc_full
1067 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1068 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1069 /* Now we need to check if the user selected RX ONLY
1070 * of pause frames. In this case, we had to advertise
1071 * FULL flow control because we could not advertise RX
1072 * ONLY. Hence, we must now check to see if we need to
1073 * turn OFF the TRANSMISSION of PAUSE frames.
1075 if (mac->original_fc == e1000_fc_full) {
1076 mac->fc = e1000_fc_full;
1077 hw_dbg(hw, "Flow Control = FULL.\r\n");
1078 } else {
1079 mac->fc = e1000_fc_rx_pause;
1080 hw_dbg(hw, "Flow Control = "
1081 "RX PAUSE frames only.\r\n");
1084 /* For receiving PAUSE frames ONLY.
1086 * LOCAL DEVICE | LINK PARTNER
1087 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1088 *-------|---------|-------|---------|--------------------
1089 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
1092 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1093 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1094 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1095 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1096 mac->fc = e1000_fc_tx_pause;
1097 hw_dbg(hw, "Flow Control = TX PAUSE frames only.\r\n");
1099 /* For transmitting PAUSE frames ONLY.
1101 * LOCAL DEVICE | LINK PARTNER
1102 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
1103 *-------|---------|-------|---------|--------------------
1104 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
1107 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
1108 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
1109 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
1110 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1111 mac->fc = e1000_fc_rx_pause;
1112 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\r\n");
1113 <<<<<<< HEAD:drivers/net/e1000e/lib.c
1115 /* Per the IEEE spec, at this point flow control should be
1116 * disabled. However, we want to consider that we could
1117 * be connected to a legacy switch that doesn't advertise
1118 * desired flow control, but can be forced on the link
1119 * partner. So if we advertised no flow control, that is
1120 * what we will resolve to. If we advertised some kind of
1121 * receive capability (Rx Pause Only or Full Flow Control)
1122 * and the link partner advertised none, we will configure
1123 * ourselves to enable Rx Flow Control only. We can do
1124 * this safely for two reasons: If the link partner really
1125 * didn't want flow control enabled, and we enable Rx, no
1126 * harm done since we won't be receiving any PAUSE frames
1127 * anyway. If the intent on the link partner was to have
1128 * flow control enabled, then by us enabling RX only, we
1129 * can at least receive pause frames and process them.
1130 * This is a good idea because in most cases, since we are
1131 * predominantly a server NIC, more times than not we will
1132 * be asked to delay transmission of packets than asking
1133 * our link partner to pause transmission of frames.
1135 else if ((mac->original_fc == e1000_fc_none) ||
1136 (mac->original_fc == e1000_fc_tx_pause)) {
1137 =======
1138 } else {
1140 * Per the IEEE spec, at this point flow control
1141 * should be disabled.
1143 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
1144 mac->fc = e1000_fc_none;
1145 hw_dbg(hw, "Flow Control = NONE.\r\n");
1146 <<<<<<< HEAD:drivers/net/e1000e/lib.c
1147 } else {
1148 mac->fc = e1000_fc_rx_pause;
1149 hw_dbg(hw, "Flow Control = RX PAUSE frames only.\r\n");
1150 =======
1151 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
1154 /* Now we need to do one last check... If we auto-
1155 * negotiated to HALF DUPLEX, flow control should not be
1156 * enabled per IEEE 802.3 spec.
1158 ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
1159 if (ret_val) {
1160 hw_dbg(hw, "Error getting link speed and duplex\n");
1161 return ret_val;
1164 if (duplex == HALF_DUPLEX)
1165 mac->fc = e1000_fc_none;
1167 /* Now we call a subroutine to actually force the MAC
1168 * controller to use the correct flow control settings.
1170 ret_val = e1000e_force_mac_fc(hw);
1171 if (ret_val) {
1172 hw_dbg(hw, "Error forcing flow control settings\n");
1173 return ret_val;
1177 return 0;
1181 <<<<<<< HEAD:drivers/net/e1000e/lib.c
1182 * e1000e_get_speed_and_duplex_copper - Retreive current speed/duplex
1183 =======
1184 * e1000e_get_speed_and_duplex_copper - Retrieve current speed/duplex
1185 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
1186 * @hw: pointer to the HW structure
1187 * @speed: stores the current speed
1188 * @duplex: stores the current duplex
1190 * Read the status register for the current speed/duplex and store the current
1191 * speed and duplex for copper connections.
1193 s32 e1000e_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed, u16 *duplex)
1195 u32 status;
1197 status = er32(STATUS);
1198 if (status & E1000_STATUS_SPEED_1000) {
1199 *speed = SPEED_1000;
1200 hw_dbg(hw, "1000 Mbs, ");
1201 } else if (status & E1000_STATUS_SPEED_100) {
1202 *speed = SPEED_100;
1203 hw_dbg(hw, "100 Mbs, ");
1204 } else {
1205 *speed = SPEED_10;
1206 hw_dbg(hw, "10 Mbs, ");
1209 if (status & E1000_STATUS_FD) {
1210 *duplex = FULL_DUPLEX;
1211 hw_dbg(hw, "Full Duplex\n");
1212 } else {
1213 *duplex = HALF_DUPLEX;
1214 hw_dbg(hw, "Half Duplex\n");
1217 return 0;
1221 <<<<<<< HEAD:drivers/net/e1000e/lib.c
1222 * e1000e_get_speed_and_duplex_fiber_serdes - Retreive current speed/duplex
1223 =======
1224 * e1000e_get_speed_and_duplex_fiber_serdes - Retrieve current speed/duplex
1225 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
1226 * @hw: pointer to the HW structure
1227 * @speed: stores the current speed
1228 * @duplex: stores the current duplex
1230 * Sets the speed and duplex to gigabit full duplex (the only possible option)
1231 * for fiber/serdes links.
1233 s32 e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw *hw, u16 *speed, u16 *duplex)
1235 *speed = SPEED_1000;
1236 *duplex = FULL_DUPLEX;
1238 return 0;
1242 * e1000e_get_hw_semaphore - Acquire hardware semaphore
1243 * @hw: pointer to the HW structure
1245 * Acquire the HW semaphore to access the PHY or NVM
1247 s32 e1000e_get_hw_semaphore(struct e1000_hw *hw)
1249 u32 swsm;
1250 s32 timeout = hw->nvm.word_size + 1;
1251 s32 i = 0;
1253 /* Get the SW semaphore */
1254 while (i < timeout) {
1255 swsm = er32(SWSM);
1256 if (!(swsm & E1000_SWSM_SMBI))
1257 break;
1259 udelay(50);
1260 i++;
1263 if (i == timeout) {
1264 hw_dbg(hw, "Driver can't access device - SMBI bit is set.\n");
1265 return -E1000_ERR_NVM;
1268 /* Get the FW semaphore. */
1269 for (i = 0; i < timeout; i++) {
1270 swsm = er32(SWSM);
1271 ew32(SWSM, swsm | E1000_SWSM_SWESMBI);
1273 /* Semaphore acquired if bit latched */
1274 if (er32(SWSM) & E1000_SWSM_SWESMBI)
1275 break;
1277 udelay(50);
1280 if (i == timeout) {
1281 /* Release semaphores */
1282 e1000e_put_hw_semaphore(hw);
1283 hw_dbg(hw, "Driver can't access the NVM\n");
1284 return -E1000_ERR_NVM;
1287 return 0;
1291 * e1000e_put_hw_semaphore - Release hardware semaphore
1292 * @hw: pointer to the HW structure
1294 * Release hardware semaphore used to access the PHY or NVM
1296 void e1000e_put_hw_semaphore(struct e1000_hw *hw)
1298 u32 swsm;
1300 swsm = er32(SWSM);
1301 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1302 ew32(SWSM, swsm);
1306 * e1000e_get_auto_rd_done - Check for auto read completion
1307 * @hw: pointer to the HW structure
1309 * Check EEPROM for Auto Read done bit.
1311 s32 e1000e_get_auto_rd_done(struct e1000_hw *hw)
1313 s32 i = 0;
1315 while (i < AUTO_READ_DONE_TIMEOUT) {
1316 if (er32(EECD) & E1000_EECD_AUTO_RD)
1317 break;
1318 msleep(1);
1319 i++;
1322 if (i == AUTO_READ_DONE_TIMEOUT) {
1323 hw_dbg(hw, "Auto read by HW from NVM has not completed.\n");
1324 return -E1000_ERR_RESET;
1327 return 0;
1331 * e1000e_valid_led_default - Verify a valid default LED config
1332 * @hw: pointer to the HW structure
1333 * @data: pointer to the NVM (EEPROM)
1335 * Read the EEPROM for the current default LED configuration. If the
1336 * LED configuration is not valid, set to a valid LED configuration.
1338 s32 e1000e_valid_led_default(struct e1000_hw *hw, u16 *data)
1340 s32 ret_val;
1342 ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
1343 if (ret_val) {
1344 hw_dbg(hw, "NVM Read Error\n");
1345 return ret_val;
1348 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
1349 *data = ID_LED_DEFAULT;
1351 return 0;
1355 * e1000e_id_led_init -
1356 * @hw: pointer to the HW structure
1359 s32 e1000e_id_led_init(struct e1000_hw *hw)
1361 struct e1000_mac_info *mac = &hw->mac;
1362 s32 ret_val;
1363 const u32 ledctl_mask = 0x000000FF;
1364 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
1365 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
1366 u16 data, i, temp;
1367 const u16 led_mask = 0x0F;
1369 ret_val = hw->nvm.ops.valid_led_default(hw, &data);
1370 if (ret_val)
1371 return ret_val;
1373 mac->ledctl_default = er32(LEDCTL);
1374 mac->ledctl_mode1 = mac->ledctl_default;
1375 mac->ledctl_mode2 = mac->ledctl_default;
1377 for (i = 0; i < 4; i++) {
1378 temp = (data >> (i << 2)) & led_mask;
1379 switch (temp) {
1380 case ID_LED_ON1_DEF2:
1381 case ID_LED_ON1_ON2:
1382 case ID_LED_ON1_OFF2:
1383 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1384 mac->ledctl_mode1 |= ledctl_on << (i << 3);
1385 break;
1386 case ID_LED_OFF1_DEF2:
1387 case ID_LED_OFF1_ON2:
1388 case ID_LED_OFF1_OFF2:
1389 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1390 mac->ledctl_mode1 |= ledctl_off << (i << 3);
1391 break;
1392 default:
1393 /* Do nothing */
1394 break;
1396 switch (temp) {
1397 case ID_LED_DEF1_ON2:
1398 case ID_LED_ON1_ON2:
1399 case ID_LED_OFF1_ON2:
1400 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1401 mac->ledctl_mode2 |= ledctl_on << (i << 3);
1402 break;
1403 case ID_LED_DEF1_OFF2:
1404 case ID_LED_ON1_OFF2:
1405 case ID_LED_OFF1_OFF2:
1406 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1407 mac->ledctl_mode2 |= ledctl_off << (i << 3);
1408 break;
1409 default:
1410 /* Do nothing */
1411 break;
1415 return 0;
1419 * e1000e_cleanup_led_generic - Set LED config to default operation
1420 * @hw: pointer to the HW structure
1422 * Remove the current LED configuration and set the LED configuration
1423 * to the default value, saved from the EEPROM.
1425 s32 e1000e_cleanup_led_generic(struct e1000_hw *hw)
1427 ew32(LEDCTL, hw->mac.ledctl_default);
1428 return 0;
1432 * e1000e_blink_led - Blink LED
1433 * @hw: pointer to the HW structure
1435 <<<<<<< HEAD:drivers/net/e1000e/lib.c
1436 * Blink the led's which are set to be on.
1437 =======
1438 * Blink the LEDs which are set to be on.
1439 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
1441 s32 e1000e_blink_led(struct e1000_hw *hw)
1443 u32 ledctl_blink = 0;
1444 u32 i;
1446 if (hw->media_type == e1000_media_type_fiber) {
1447 /* always blink LED0 for PCI-E fiber */
1448 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
1449 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
1450 } else {
1451 /* set the blink bit for each LED that's "on" (0x0E)
1452 * in ledctl_mode2 */
1453 ledctl_blink = hw->mac.ledctl_mode2;
1454 for (i = 0; i < 4; i++)
1455 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
1456 E1000_LEDCTL_MODE_LED_ON)
1457 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
1458 (i * 8));
1461 ew32(LEDCTL, ledctl_blink);
1463 return 0;
1467 * e1000e_led_on_generic - Turn LED on
1468 * @hw: pointer to the HW structure
1470 * Turn LED on.
1472 s32 e1000e_led_on_generic(struct e1000_hw *hw)
1474 u32 ctrl;
1476 switch (hw->media_type) {
1477 case e1000_media_type_fiber:
1478 ctrl = er32(CTRL);
1479 ctrl &= ~E1000_CTRL_SWDPIN0;
1480 ctrl |= E1000_CTRL_SWDPIO0;
1481 ew32(CTRL, ctrl);
1482 break;
1483 case e1000_media_type_copper:
1484 ew32(LEDCTL, hw->mac.ledctl_mode2);
1485 break;
1486 default:
1487 break;
1490 return 0;
1494 * e1000e_led_off_generic - Turn LED off
1495 * @hw: pointer to the HW structure
1497 * Turn LED off.
1499 s32 e1000e_led_off_generic(struct e1000_hw *hw)
1501 u32 ctrl;
1503 switch (hw->media_type) {
1504 case e1000_media_type_fiber:
1505 ctrl = er32(CTRL);
1506 ctrl |= E1000_CTRL_SWDPIN0;
1507 ctrl |= E1000_CTRL_SWDPIO0;
1508 ew32(CTRL, ctrl);
1509 break;
1510 case e1000_media_type_copper:
1511 ew32(LEDCTL, hw->mac.ledctl_mode1);
1512 break;
1513 default:
1514 break;
1517 return 0;
1521 * e1000e_set_pcie_no_snoop - Set PCI-express capabilities
1522 * @hw: pointer to the HW structure
1523 * @no_snoop: bitmap of snoop events
1525 * Set the PCI-express register to snoop for events enabled in 'no_snoop'.
1527 void e1000e_set_pcie_no_snoop(struct e1000_hw *hw, u32 no_snoop)
1529 u32 gcr;
1531 if (no_snoop) {
1532 gcr = er32(GCR);
1533 gcr &= ~(PCIE_NO_SNOOP_ALL);
1534 gcr |= no_snoop;
1535 ew32(GCR, gcr);
1540 * e1000e_disable_pcie_master - Disables PCI-express master access
1541 * @hw: pointer to the HW structure
1543 * Returns 0 if successful, else returns -10
1544 <<<<<<< HEAD:drivers/net/e1000e/lib.c
1545 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not casued
1546 =======
1547 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
1548 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
1549 * the master requests to be disabled.
1551 * Disables PCI-Express master access and verifies there are no pending
1552 * requests.
1554 s32 e1000e_disable_pcie_master(struct e1000_hw *hw)
1556 u32 ctrl;
1557 s32 timeout = MASTER_DISABLE_TIMEOUT;
1559 ctrl = er32(CTRL);
1560 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
1561 ew32(CTRL, ctrl);
1563 while (timeout) {
1564 if (!(er32(STATUS) &
1565 E1000_STATUS_GIO_MASTER_ENABLE))
1566 break;
1567 udelay(100);
1568 timeout--;
1571 if (!timeout) {
1572 hw_dbg(hw, "Master requests are pending.\n");
1573 return -E1000_ERR_MASTER_REQUESTS_PENDING;
1576 return 0;
1580 * e1000e_reset_adaptive - Reset Adaptive Interframe Spacing
1581 * @hw: pointer to the HW structure
1583 * Reset the Adaptive Interframe Spacing throttle to default values.
1585 void e1000e_reset_adaptive(struct e1000_hw *hw)
1587 struct e1000_mac_info *mac = &hw->mac;
1589 mac->current_ifs_val = 0;
1590 mac->ifs_min_val = IFS_MIN;
1591 mac->ifs_max_val = IFS_MAX;
1592 mac->ifs_step_size = IFS_STEP;
1593 mac->ifs_ratio = IFS_RATIO;
1595 mac->in_ifs_mode = 0;
1596 ew32(AIT, 0);
1600 * e1000e_update_adaptive - Update Adaptive Interframe Spacing
1601 * @hw: pointer to the HW structure
1603 * Update the Adaptive Interframe Spacing Throttle value based on the
1604 * time between transmitted packets and time between collisions.
1606 void e1000e_update_adaptive(struct e1000_hw *hw)
1608 struct e1000_mac_info *mac = &hw->mac;
1610 if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
1611 if (mac->tx_packet_delta > MIN_NUM_XMITS) {
1612 mac->in_ifs_mode = 1;
1613 if (mac->current_ifs_val < mac->ifs_max_val) {
1614 if (!mac->current_ifs_val)
1615 mac->current_ifs_val = mac->ifs_min_val;
1616 else
1617 mac->current_ifs_val +=
1618 mac->ifs_step_size;
1619 ew32(AIT,
1620 mac->current_ifs_val);
1623 } else {
1624 if (mac->in_ifs_mode &&
1625 (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
1626 mac->current_ifs_val = 0;
1627 mac->in_ifs_mode = 0;
1628 ew32(AIT, 0);
1634 * e1000_raise_eec_clk - Raise EEPROM clock
1635 * @hw: pointer to the HW structure
1636 * @eecd: pointer to the EEPROM
1638 * Enable/Raise the EEPROM clock bit.
1640 static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
1642 *eecd = *eecd | E1000_EECD_SK;
1643 ew32(EECD, *eecd);
1644 e1e_flush();
1645 udelay(hw->nvm.delay_usec);
1649 * e1000_lower_eec_clk - Lower EEPROM clock
1650 * @hw: pointer to the HW structure
1651 * @eecd: pointer to the EEPROM
1653 * Clear/Lower the EEPROM clock bit.
1655 static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
1657 *eecd = *eecd & ~E1000_EECD_SK;
1658 ew32(EECD, *eecd);
1659 e1e_flush();
1660 udelay(hw->nvm.delay_usec);
1664 * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
1665 * @hw: pointer to the HW structure
1666 * @data: data to send to the EEPROM
1667 * @count: number of bits to shift out
1669 * We need to shift 'count' bits out to the EEPROM. So, the value in the
1670 * "data" parameter will be shifted out to the EEPROM one bit at a time.
1671 * In order to do this, "data" must be broken down into bits.
1673 static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
1675 struct e1000_nvm_info *nvm = &hw->nvm;
1676 u32 eecd = er32(EECD);
1677 u32 mask;
1679 mask = 0x01 << (count - 1);
1680 if (nvm->type == e1000_nvm_eeprom_spi)
1681 eecd |= E1000_EECD_DO;
1683 do {
1684 eecd &= ~E1000_EECD_DI;
1686 if (data & mask)
1687 eecd |= E1000_EECD_DI;
1689 ew32(EECD, eecd);
1690 e1e_flush();
1692 udelay(nvm->delay_usec);
1694 e1000_raise_eec_clk(hw, &eecd);
1695 e1000_lower_eec_clk(hw, &eecd);
1697 mask >>= 1;
1698 } while (mask);
1700 eecd &= ~E1000_EECD_DI;
1701 ew32(EECD, eecd);
1705 * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
1706 * @hw: pointer to the HW structure
1707 * @count: number of bits to shift in
1709 * In order to read a register from the EEPROM, we need to shift 'count' bits
1710 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
1711 * the EEPROM (setting the SK bit), and then reading the value of the data out
1712 * "DO" bit. During this "shifting in" process the data in "DI" bit should
1713 * always be clear.
1715 static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
1717 u32 eecd;
1718 u32 i;
1719 u16 data;
1721 eecd = er32(EECD);
1723 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
1724 data = 0;
1726 for (i = 0; i < count; i++) {
1727 data <<= 1;
1728 e1000_raise_eec_clk(hw, &eecd);
1730 eecd = er32(EECD);
1732 eecd &= ~E1000_EECD_DI;
1733 if (eecd & E1000_EECD_DO)
1734 data |= 1;
1736 e1000_lower_eec_clk(hw, &eecd);
1739 return data;
1743 * e1000e_poll_eerd_eewr_done - Poll for EEPROM read/write completion
1744 * @hw: pointer to the HW structure
1745 * @ee_reg: EEPROM flag for polling
1747 * Polls the EEPROM status bit for either read or write completion based
1748 * upon the value of 'ee_reg'.
1750 s32 e1000e_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
1752 u32 attempts = 100000;
1753 u32 i, reg = 0;
1755 for (i = 0; i < attempts; i++) {
1756 if (ee_reg == E1000_NVM_POLL_READ)
1757 reg = er32(EERD);
1758 else
1759 reg = er32(EEWR);
1761 if (reg & E1000_NVM_RW_REG_DONE)
1762 return 0;
1764 udelay(5);
1767 return -E1000_ERR_NVM;
1771 * e1000e_acquire_nvm - Generic request for access to EEPROM
1772 * @hw: pointer to the HW structure
1774 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
1775 * Return successful if access grant bit set, else clear the request for
1776 * EEPROM access and return -E1000_ERR_NVM (-1).
1778 s32 e1000e_acquire_nvm(struct e1000_hw *hw)
1780 u32 eecd = er32(EECD);
1781 s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
1783 ew32(EECD, eecd | E1000_EECD_REQ);
1784 eecd = er32(EECD);
1786 while (timeout) {
1787 if (eecd & E1000_EECD_GNT)
1788 break;
1789 udelay(5);
1790 eecd = er32(EECD);
1791 timeout--;
1794 if (!timeout) {
1795 eecd &= ~E1000_EECD_REQ;
1796 ew32(EECD, eecd);
1797 hw_dbg(hw, "Could not acquire NVM grant\n");
1798 return -E1000_ERR_NVM;
1801 return 0;
1805 * e1000_standby_nvm - Return EEPROM to standby state
1806 * @hw: pointer to the HW structure
1808 * Return the EEPROM to a standby state.
1810 static void e1000_standby_nvm(struct e1000_hw *hw)
1812 struct e1000_nvm_info *nvm = &hw->nvm;
1813 u32 eecd = er32(EECD);
1815 if (nvm->type == e1000_nvm_eeprom_spi) {
1816 /* Toggle CS to flush commands */
1817 eecd |= E1000_EECD_CS;
1818 ew32(EECD, eecd);
1819 e1e_flush();
1820 udelay(nvm->delay_usec);
1821 eecd &= ~E1000_EECD_CS;
1822 ew32(EECD, eecd);
1823 e1e_flush();
1824 udelay(nvm->delay_usec);
1829 * e1000_stop_nvm - Terminate EEPROM command
1830 * @hw: pointer to the HW structure
1832 * Terminates the current command by inverting the EEPROM's chip select pin.
1834 static void e1000_stop_nvm(struct e1000_hw *hw)
1836 u32 eecd;
1838 eecd = er32(EECD);
1839 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
1840 /* Pull CS high */
1841 eecd |= E1000_EECD_CS;
1842 e1000_lower_eec_clk(hw, &eecd);
1847 * e1000e_release_nvm - Release exclusive access to EEPROM
1848 * @hw: pointer to the HW structure
1850 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
1852 void e1000e_release_nvm(struct e1000_hw *hw)
1854 u32 eecd;
1856 e1000_stop_nvm(hw);
1858 eecd = er32(EECD);
1859 eecd &= ~E1000_EECD_REQ;
1860 ew32(EECD, eecd);
1864 * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
1865 * @hw: pointer to the HW structure
1867 * Setups the EEPROM for reading and writing.
1869 static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
1871 struct e1000_nvm_info *nvm = &hw->nvm;
1872 u32 eecd = er32(EECD);
1873 u16 timeout = 0;
1874 u8 spi_stat_reg;
1876 if (nvm->type == e1000_nvm_eeprom_spi) {
1877 /* Clear SK and CS */
1878 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
1879 ew32(EECD, eecd);
1880 udelay(1);
1881 timeout = NVM_MAX_RETRY_SPI;
1883 /* Read "Status Register" repeatedly until the LSB is cleared.
1884 * The EEPROM will signal that the command has been completed
1885 * by clearing bit 0 of the internal status register. If it's
1886 * not cleared within 'timeout', then error out. */
1887 while (timeout) {
1888 e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
1889 hw->nvm.opcode_bits);
1890 spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
1891 if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
1892 break;
1894 udelay(5);
1895 e1000_standby_nvm(hw);
1896 timeout--;
1899 if (!timeout) {
1900 hw_dbg(hw, "SPI NVM Status error\n");
1901 return -E1000_ERR_NVM;
1905 return 0;
1909 <<<<<<< HEAD:drivers/net/e1000e/lib.c
1910 * e1000e_read_nvm_spi - Read EEPROM's using SPI
1911 =======
1912 * e1000e_read_nvm_spi - Reads EEPROM using SPI
1913 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
1914 * @hw: pointer to the HW structure
1915 * @offset: offset of word in the EEPROM to read
1916 * @words: number of words to read
1917 * @data: word read from the EEPROM
1919 * Reads a 16 bit word from the EEPROM.
1921 s32 e1000e_read_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
1923 struct e1000_nvm_info *nvm = &hw->nvm;
1924 u32 i = 0;
1925 s32 ret_val;
1926 u16 word_in;
1927 u8 read_opcode = NVM_READ_OPCODE_SPI;
1929 /* A check for invalid values: offset too large, too many words,
1930 * and not enough words. */
1931 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
1932 (words == 0)) {
1933 hw_dbg(hw, "nvm parameter(s) out of bounds\n");
1934 return -E1000_ERR_NVM;
1937 ret_val = nvm->ops.acquire_nvm(hw);
1938 if (ret_val)
1939 return ret_val;
1941 ret_val = e1000_ready_nvm_eeprom(hw);
1942 if (ret_val) {
1943 nvm->ops.release_nvm(hw);
1944 return ret_val;
1947 e1000_standby_nvm(hw);
1949 if ((nvm->address_bits == 8) && (offset >= 128))
1950 read_opcode |= NVM_A8_OPCODE_SPI;
1952 /* Send the READ command (opcode + addr) */
1953 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
1954 e1000_shift_out_eec_bits(hw, (u16)(offset*2), nvm->address_bits);
1956 /* Read the data. SPI NVMs increment the address with each byte
1957 * read and will roll over if reading beyond the end. This allows
1958 * us to read the whole NVM from any offset */
1959 for (i = 0; i < words; i++) {
1960 word_in = e1000_shift_in_eec_bits(hw, 16);
1961 data[i] = (word_in >> 8) | (word_in << 8);
1964 nvm->ops.release_nvm(hw);
1965 return 0;
1969 * e1000e_read_nvm_eerd - Reads EEPROM using EERD register
1970 * @hw: pointer to the HW structure
1971 * @offset: offset of word in the EEPROM to read
1972 * @words: number of words to read
1973 * @data: word read from the EEPROM
1975 * Reads a 16 bit word from the EEPROM using the EERD register.
1977 s32 e1000e_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
1979 struct e1000_nvm_info *nvm = &hw->nvm;
1980 u32 i, eerd = 0;
1981 s32 ret_val = 0;
1983 /* A check for invalid values: offset too large, too many words,
1984 * and not enough words. */
1985 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
1986 (words == 0)) {
1987 hw_dbg(hw, "nvm parameter(s) out of bounds\n");
1988 return -E1000_ERR_NVM;
1991 for (i = 0; i < words; i++) {
1992 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
1993 E1000_NVM_RW_REG_START;
1995 ew32(EERD, eerd);
1996 ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
1997 if (ret_val)
1998 break;
2000 data[i] = (er32(EERD) >>
2001 E1000_NVM_RW_REG_DATA);
2004 return ret_val;
2008 * e1000e_write_nvm_spi - Write to EEPROM using SPI
2009 * @hw: pointer to the HW structure
2010 * @offset: offset within the EEPROM to be written to
2011 * @words: number of words to write
2012 * @data: 16 bit word(s) to be written to the EEPROM
2014 * Writes data to EEPROM at offset using SPI interface.
2016 * If e1000e_update_nvm_checksum is not called after this function , the
2017 <<<<<<< HEAD:drivers/net/e1000e/lib.c
2018 * EEPROM will most likley contain an invalid checksum.
2019 =======
2020 * EEPROM will most likely contain an invalid checksum.
2021 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
2023 s32 e1000e_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
2025 struct e1000_nvm_info *nvm = &hw->nvm;
2026 s32 ret_val;
2027 u16 widx = 0;
2029 /* A check for invalid values: offset too large, too many words,
2030 * and not enough words. */
2031 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
2032 (words == 0)) {
2033 hw_dbg(hw, "nvm parameter(s) out of bounds\n");
2034 return -E1000_ERR_NVM;
2037 ret_val = nvm->ops.acquire_nvm(hw);
2038 if (ret_val)
2039 return ret_val;
2041 msleep(10);
2043 while (widx < words) {
2044 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
2046 ret_val = e1000_ready_nvm_eeprom(hw);
2047 if (ret_val) {
2048 nvm->ops.release_nvm(hw);
2049 return ret_val;
2052 e1000_standby_nvm(hw);
2054 /* Send the WRITE ENABLE command (8 bit opcode) */
2055 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
2056 nvm->opcode_bits);
2058 e1000_standby_nvm(hw);
2060 /* Some SPI eeproms use the 8th address bit embedded in the
2061 * opcode */
2062 if ((nvm->address_bits == 8) && (offset >= 128))
2063 write_opcode |= NVM_A8_OPCODE_SPI;
2065 /* Send the Write command (8-bit opcode + addr) */
2066 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
2067 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
2068 nvm->address_bits);
2070 /* Loop to allow for up to whole page write of eeprom */
2071 while (widx < words) {
2072 u16 word_out = data[widx];
2073 word_out = (word_out >> 8) | (word_out << 8);
2074 e1000_shift_out_eec_bits(hw, word_out, 16);
2075 widx++;
2077 if ((((offset + widx) * 2) % nvm->page_size) == 0) {
2078 e1000_standby_nvm(hw);
2079 break;
2084 msleep(10);
2085 return 0;
2089 * e1000e_read_mac_addr - Read device MAC address
2090 * @hw: pointer to the HW structure
2092 * Reads the device MAC address from the EEPROM and stores the value.
2093 * Since devices with two ports use the same EEPROM, we increment the
2094 * last bit in the MAC address for the second port.
2096 s32 e1000e_read_mac_addr(struct e1000_hw *hw)
2098 s32 ret_val;
2099 u16 offset, nvm_data, i;
2100 u16 mac_addr_offset = 0;
2102 if (hw->mac.type == e1000_82571) {
2103 /* Check for an alternate MAC address. An alternate MAC
2104 * address can be setup by pre-boot software and must be
2105 * treated like a permanent address and must override the
2106 * actual permanent MAC address. */
2107 ret_val = e1000_read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1,
2108 &mac_addr_offset);
2109 if (ret_val) {
2110 hw_dbg(hw, "NVM Read Error\n");
2111 return ret_val;
2113 if (mac_addr_offset == 0xFFFF)
2114 mac_addr_offset = 0;
2116 if (mac_addr_offset) {
2117 if (hw->bus.func == E1000_FUNC_1)
2118 mac_addr_offset += ETH_ALEN/sizeof(u16);
2120 /* make sure we have a valid mac address here
2121 * before using it */
2122 ret_val = e1000_read_nvm(hw, mac_addr_offset, 1,
2123 &nvm_data);
2124 if (ret_val) {
2125 hw_dbg(hw, "NVM Read Error\n");
2126 return ret_val;
2128 if (nvm_data & 0x0001)
2129 mac_addr_offset = 0;
2132 if (mac_addr_offset)
2133 hw->dev_spec.e82571.alt_mac_addr_is_present = 1;
2136 for (i = 0; i < ETH_ALEN; i += 2) {
2137 offset = mac_addr_offset + (i >> 1);
2138 ret_val = e1000_read_nvm(hw, offset, 1, &nvm_data);
2139 if (ret_val) {
2140 hw_dbg(hw, "NVM Read Error\n");
2141 return ret_val;
2143 hw->mac.perm_addr[i] = (u8)(nvm_data & 0xFF);
2144 hw->mac.perm_addr[i+1] = (u8)(nvm_data >> 8);
2147 /* Flip last bit of mac address if we're on second port */
2148 if (!mac_addr_offset && hw->bus.func == E1000_FUNC_1)
2149 hw->mac.perm_addr[5] ^= 1;
2151 for (i = 0; i < ETH_ALEN; i++)
2152 hw->mac.addr[i] = hw->mac.perm_addr[i];
2154 return 0;
2158 * e1000e_validate_nvm_checksum_generic - Validate EEPROM checksum
2159 * @hw: pointer to the HW structure
2161 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
2162 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
2164 s32 e1000e_validate_nvm_checksum_generic(struct e1000_hw *hw)
2166 s32 ret_val;
2167 u16 checksum = 0;
2168 u16 i, nvm_data;
2170 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
2171 ret_val = e1000_read_nvm(hw, i, 1, &nvm_data);
2172 if (ret_val) {
2173 hw_dbg(hw, "NVM Read Error\n");
2174 return ret_val;
2176 checksum += nvm_data;
2179 if (checksum != (u16) NVM_SUM) {
2180 hw_dbg(hw, "NVM Checksum Invalid\n");
2181 return -E1000_ERR_NVM;
2184 return 0;
2188 * e1000e_update_nvm_checksum_generic - Update EEPROM checksum
2189 * @hw: pointer to the HW structure
2191 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
2192 * up to the checksum. Then calculates the EEPROM checksum and writes the
2193 * value to the EEPROM.
2195 s32 e1000e_update_nvm_checksum_generic(struct e1000_hw *hw)
2197 s32 ret_val;
2198 u16 checksum = 0;
2199 u16 i, nvm_data;
2201 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
2202 ret_val = e1000_read_nvm(hw, i, 1, &nvm_data);
2203 if (ret_val) {
2204 hw_dbg(hw, "NVM Read Error while updating checksum.\n");
2205 return ret_val;
2207 checksum += nvm_data;
2209 checksum = (u16) NVM_SUM - checksum;
2210 ret_val = e1000_write_nvm(hw, NVM_CHECKSUM_REG, 1, &checksum);
2211 if (ret_val)
2212 hw_dbg(hw, "NVM Write Error while updating checksum.\n");
2214 return ret_val;
2218 * e1000e_reload_nvm - Reloads EEPROM
2219 * @hw: pointer to the HW structure
2221 * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
2222 * extended control register.
2224 void e1000e_reload_nvm(struct e1000_hw *hw)
2226 u32 ctrl_ext;
2228 udelay(10);
2229 ctrl_ext = er32(CTRL_EXT);
2230 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
2231 ew32(CTRL_EXT, ctrl_ext);
2232 e1e_flush();
2236 * e1000_calculate_checksum - Calculate checksum for buffer
2237 * @buffer: pointer to EEPROM
2238 * @length: size of EEPROM to calculate a checksum for
2240 * Calculates the checksum for some buffer on a specified length. The
2241 * checksum calculated is returned.
2243 static u8 e1000_calculate_checksum(u8 *buffer, u32 length)
2245 u32 i;
2246 u8 sum = 0;
2248 if (!buffer)
2249 return 0;
2251 for (i = 0; i < length; i++)
2252 sum += buffer[i];
2254 return (u8) (0 - sum);
2258 * e1000_mng_enable_host_if - Checks host interface is enabled
2259 * @hw: pointer to the HW structure
2261 * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND
2263 <<<<<<< HEAD:drivers/net/e1000e/lib.c
2264 * This function checks whether the HOST IF is enabled for command operaton
2265 =======
2266 * This function checks whether the HOST IF is enabled for command operation
2267 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
2268 * and also checks whether the previous command is completed. It busy waits
2269 * in case of previous command is not completed.
2271 static s32 e1000_mng_enable_host_if(struct e1000_hw *hw)
2273 u32 hicr;
2274 u8 i;
2276 /* Check that the host interface is enabled. */
2277 hicr = er32(HICR);
2278 if ((hicr & E1000_HICR_EN) == 0) {
2279 hw_dbg(hw, "E1000_HOST_EN bit disabled.\n");
2280 return -E1000_ERR_HOST_INTERFACE_COMMAND;
2282 /* check the previous command is completed */
2283 for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
2284 hicr = er32(HICR);
2285 if (!(hicr & E1000_HICR_C))
2286 break;
2287 mdelay(1);
2290 if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
2291 hw_dbg(hw, "Previous command timeout failed .\n");
2292 return -E1000_ERR_HOST_INTERFACE_COMMAND;
2295 return 0;
2299 <<<<<<< HEAD:drivers/net/e1000e/lib.c
2300 * e1000e_check_mng_mode - check managament mode
2301 =======
2302 * e1000e_check_mng_mode - check management mode
2303 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/net/e1000e/lib.c
2304 * @hw: pointer to the HW structure
2306 * Reads the firmware semaphore register and returns true (>0) if
2307 * manageability is enabled, else false (0).
2309 bool e1000e_check_mng_mode(struct e1000_hw *hw)
2311 u32 fwsm = er32(FWSM);
2313 return (fwsm & E1000_FWSM_MODE_MASK) == hw->mac.ops.mng_mode_enab;
2317 * e1000e_enable_tx_pkt_filtering - Enable packet filtering on TX
2318 * @hw: pointer to the HW structure
2320 * Enables packet filtering on transmit packets if manageability is enabled
2321 * and host interface is enabled.
2323 bool e1000e_enable_tx_pkt_filtering(struct e1000_hw *hw)
2325 struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie;
2326 u32 *buffer = (u32 *)&hw->mng_cookie;
2327 u32 offset;
2328 s32 ret_val, hdr_csum, csum;
2329 u8 i, len;
2331 /* No manageability, no filtering */
2332 if (!e1000e_check_mng_mode(hw)) {
2333 hw->mac.tx_pkt_filtering = 0;
2334 return 0;
2337 /* If we can't read from the host interface for whatever
2338 * reason, disable filtering.
2340 ret_val = e1000_mng_enable_host_if(hw);
2341 if (ret_val != 0) {
2342 hw->mac.tx_pkt_filtering = 0;
2343 return ret_val;
2346 /* Read in the header. Length and offset are in dwords. */
2347 len = E1000_MNG_DHCP_COOKIE_LENGTH >> 2;
2348 offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2;
2349 for (i = 0; i < len; i++)
2350 *(buffer + i) = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset + i);
2351 hdr_csum = hdr->checksum;
2352 hdr->checksum = 0;
2353 csum = e1000_calculate_checksum((u8 *)hdr,
2354 E1000_MNG_DHCP_COOKIE_LENGTH);
2355 /* If either the checksums or signature don't match, then
2356 * the cookie area isn't considered valid, in which case we
2357 * take the safe route of assuming Tx filtering is enabled.
2359 if ((hdr_csum != csum) || (hdr->signature != E1000_IAMT_SIGNATURE)) {
2360 hw->mac.tx_pkt_filtering = 1;
2361 return 1;
2364 /* Cookie area is valid, make the final check for filtering. */
2365 if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING)) {
2366 hw->mac.tx_pkt_filtering = 0;
2367 return 0;
2370 hw->mac.tx_pkt_filtering = 1;
2371 return 1;
2375 * e1000_mng_write_cmd_header - Writes manageability command header
2376 * @hw: pointer to the HW structure
2377 * @hdr: pointer to the host interface command header
2379 * Writes the command header after does the checksum calculation.
2381 static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw,
2382 struct e1000_host_mng_command_header *hdr)
2384 u16 i, length = sizeof(struct e1000_host_mng_command_header);
2386 /* Write the whole command header structure with new checksum. */
2388 hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length);
2390 length >>= 2;
2391 /* Write the relevant command block into the ram area. */
2392 for (i = 0; i < length; i++) {
2393 E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, i,
2394 *((u32 *) hdr + i));
2395 e1e_flush();
2398 return 0;
2402 * e1000_mng_host_if_write - Writes to the manageability host interface
2403 * @hw: pointer to the HW structure
2404 * @buffer: pointer to the host interface buffer
2405 * @length: size of the buffer
2406 * @offset: location in the buffer to write to
2407 * @sum: sum of the data (not checksum)
2409 * This function writes the buffer content at the offset given on the host if.
2410 * It also does alignment considerations to do the writes in most efficient
2411 * way. Also fills up the sum of the buffer in *buffer parameter.
2413 static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer,
2414 u16 length, u16 offset, u8 *sum)
2416 u8 *tmp;
2417 u8 *bufptr = buffer;
2418 u32 data = 0;
2419 u16 remaining, i, j, prev_bytes;
2421 /* sum = only sum of the data and it is not checksum */
2423 if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH)
2424 return -E1000_ERR_PARAM;
2426 tmp = (u8 *)&data;
2427 prev_bytes = offset & 0x3;
2428 offset >>= 2;
2430 if (prev_bytes) {
2431 data = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset);
2432 for (j = prev_bytes; j < sizeof(u32); j++) {
2433 *(tmp + j) = *bufptr++;
2434 *sum += *(tmp + j);
2436 E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset, data);
2437 length -= j - prev_bytes;
2438 offset++;
2441 remaining = length & 0x3;
2442 length -= remaining;
2444 /* Calculate length in DWORDs */
2445 length >>= 2;
2447 /* The device driver writes the relevant command block into the
2448 * ram area. */
2449 for (i = 0; i < length; i++) {
2450 for (j = 0; j < sizeof(u32); j++) {
2451 *(tmp + j) = *bufptr++;
2452 *sum += *(tmp + j);
2455 E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data);
2457 if (remaining) {
2458 for (j = 0; j < sizeof(u32); j++) {
2459 if (j < remaining)
2460 *(tmp + j) = *bufptr++;
2461 else
2462 *(tmp + j) = 0;
2464 *sum += *(tmp + j);
2466 E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data);
2469 return 0;
2473 * e1000e_mng_write_dhcp_info - Writes DHCP info to host interface
2474 * @hw: pointer to the HW structure
2475 * @buffer: pointer to the host interface
2476 * @length: size of the buffer
2478 * Writes the DHCP information to the host interface.
2480 s32 e1000e_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length)
2482 struct e1000_host_mng_command_header hdr;
2483 s32 ret_val;
2484 u32 hicr;
2486 hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
2487 hdr.command_length = length;
2488 hdr.reserved1 = 0;
2489 hdr.reserved2 = 0;
2490 hdr.checksum = 0;
2492 /* Enable the host interface */
2493 ret_val = e1000_mng_enable_host_if(hw);
2494 if (ret_val)
2495 return ret_val;
2497 /* Populate the host interface with the contents of "buffer". */
2498 ret_val = e1000_mng_host_if_write(hw, buffer, length,
2499 sizeof(hdr), &(hdr.checksum));
2500 if (ret_val)
2501 return ret_val;
2503 /* Write the manageability command header */
2504 ret_val = e1000_mng_write_cmd_header(hw, &hdr);
2505 if (ret_val)
2506 return ret_val;
2508 /* Tell the ARC a new command is pending. */
2509 hicr = er32(HICR);
2510 ew32(HICR, hicr | E1000_HICR_C);
2512 return 0;
2516 * e1000e_enable_mng_pass_thru - Enable processing of ARP's
2517 * @hw: pointer to the HW structure
2519 * Verifies the hardware needs to allow ARPs to be processed by the host.
2521 bool e1000e_enable_mng_pass_thru(struct e1000_hw *hw)
2523 u32 manc;
2524 u32 fwsm, factps;
2525 bool ret_val = 0;
2527 manc = er32(MANC);
2529 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
2530 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
2531 return ret_val;
2533 if (hw->mac.arc_subsystem_valid) {
2534 fwsm = er32(FWSM);
2535 factps = er32(FACTPS);
2537 if (!(factps & E1000_FACTPS_MNGCG) &&
2538 ((fwsm & E1000_FWSM_MODE_MASK) ==
2539 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
2540 ret_val = 1;
2541 return ret_val;
2543 } else {
2544 if ((manc & E1000_MANC_SMBUS_EN) &&
2545 !(manc & E1000_MANC_ASF_EN)) {
2546 ret_val = 1;
2547 return ret_val;
2551 return ret_val;
2554 s32 e1000e_read_part_num(struct e1000_hw *hw, u32 *part_num)
2556 s32 ret_val;
2557 u16 nvm_data;
2559 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
2560 if (ret_val) {
2561 hw_dbg(hw, "NVM Read Error\n");
2562 return ret_val;
2564 *part_num = (u32)(nvm_data << 16);
2566 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
2567 if (ret_val) {
2568 hw_dbg(hw, "NVM Read Error\n");
2569 return ret_val;
2571 *part_num |= nvm_data;
2573 return 0;