Merge branch 'linus' into x86/core
[deliverable/linux.git] / drivers / net / igb / e1000_mac.c
1 /*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007 Intel Corporation.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26 *******************************************************************************/
27
28 #include <linux/if_ether.h>
29 #include <linux/delay.h>
30 #include <linux/pci.h>
31 #include <linux/netdevice.h>
32
33 #include "e1000_mac.h"
34
35 #include "igb.h"
36
37 static s32 igb_set_default_fc(struct e1000_hw *hw);
38 static s32 igb_set_fc_watermarks(struct e1000_hw *hw);
39
40 /**
41 * igb_remove_device - Free device specific structure
42 * @hw: pointer to the HW structure
43 *
44 * If a device specific structure was allocated, this function will
45 * free it.
46 **/
47 void igb_remove_device(struct e1000_hw *hw)
48 {
49 /* Freeing the dev_spec member of e1000_hw structure */
50 kfree(hw->dev_spec);
51 }
52
53 static void igb_read_pci_cfg(struct e1000_hw *hw, u32 reg, u16 *value)
54 {
55 struct igb_adapter *adapter = hw->back;
56
57 pci_read_config_word(adapter->pdev, reg, value);
58 }
59
60 static s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
61 {
62 struct igb_adapter *adapter = hw->back;
63 u16 cap_offset;
64
65 cap_offset = pci_find_capability(adapter->pdev, PCI_CAP_ID_EXP);
66 if (!cap_offset)
67 return -E1000_ERR_CONFIG;
68
69 pci_read_config_word(adapter->pdev, cap_offset + reg, value);
70
71 return 0;
72 }
73
74 /**
75 * igb_get_bus_info_pcie - Get PCIe bus information
76 * @hw: pointer to the HW structure
77 *
78 * Determines and stores the system bus information for a particular
79 * network interface. The following bus information is determined and stored:
80 * bus speed, bus width, type (PCIe), and PCIe function.
81 **/
82 s32 igb_get_bus_info_pcie(struct e1000_hw *hw)
83 {
84 struct e1000_bus_info *bus = &hw->bus;
85 s32 ret_val;
86 u32 status;
87 u16 pcie_link_status, pci_header_type;
88
89 bus->type = e1000_bus_type_pci_express;
90 bus->speed = e1000_bus_speed_2500;
91
92 ret_val = igb_read_pcie_cap_reg(hw,
93 PCIE_LINK_STATUS,
94 &pcie_link_status);
95 if (ret_val)
96 bus->width = e1000_bus_width_unknown;
97 else
98 bus->width = (enum e1000_bus_width)((pcie_link_status &
99 PCIE_LINK_WIDTH_MASK) >>
100 PCIE_LINK_WIDTH_SHIFT);
101
102 igb_read_pci_cfg(hw, PCI_HEADER_TYPE_REGISTER, &pci_header_type);
103 if (pci_header_type & PCI_HEADER_TYPE_MULTIFUNC) {
104 status = rd32(E1000_STATUS);
105 bus->func = (status & E1000_STATUS_FUNC_MASK)
106 >> E1000_STATUS_FUNC_SHIFT;
107 } else {
108 bus->func = 0;
109 }
110
111 return 0;
112 }
113
114 /**
115 * igb_clear_vfta - Clear VLAN filter table
116 * @hw: pointer to the HW structure
117 *
118 * Clears the register array which contains the VLAN filter table by
119 * setting all the values to 0.
120 **/
121 void igb_clear_vfta(struct e1000_hw *hw)
122 {
123 u32 offset;
124
125 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
126 array_wr32(E1000_VFTA, offset, 0);
127 wrfl();
128 }
129 }
130
131 /**
132 * igb_write_vfta - Write value to VLAN filter table
133 * @hw: pointer to the HW structure
134 * @offset: register offset in VLAN filter table
135 * @value: register value written to VLAN filter table
136 *
137 * Writes value at the given offset in the register array which stores
138 * the VLAN filter table.
139 **/
140 void igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value)
141 {
142 array_wr32(E1000_VFTA, offset, value);
143 wrfl();
144 }
145
146 /**
147 * igb_check_alt_mac_addr - Check for alternate MAC addr
148 * @hw: pointer to the HW structure
149 *
150 * Checks the nvm for an alternate MAC address. An alternate MAC address
151 * can be setup by pre-boot software and must be treated like a permanent
152 * address and must override the actual permanent MAC address. If an
153 * alternate MAC address is fopund it is saved in the hw struct and
154 * prgrammed into RAR0 and the cuntion returns success, otherwise the
155 * fucntion returns an error.
156 **/
157 s32 igb_check_alt_mac_addr(struct e1000_hw *hw)
158 {
159 u32 i;
160 s32 ret_val = 0;
161 u16 offset, nvm_alt_mac_addr_offset, nvm_data;
162 u8 alt_mac_addr[ETH_ALEN];
163
164 ret_val = hw->nvm.ops.read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1,
165 &nvm_alt_mac_addr_offset);
166 if (ret_val) {
167 hw_dbg("NVM Read Error\n");
168 goto out;
169 }
170
171 if (nvm_alt_mac_addr_offset == 0xFFFF) {
172 ret_val = -(E1000_NOT_IMPLEMENTED);
173 goto out;
174 }
175
176 if (hw->bus.func == E1000_FUNC_1)
177 nvm_alt_mac_addr_offset += ETH_ALEN/sizeof(u16);
178
179 for (i = 0; i < ETH_ALEN; i += 2) {
180 offset = nvm_alt_mac_addr_offset + (i >> 1);
181 ret_val = hw->nvm.ops.read_nvm(hw, offset, 1, &nvm_data);
182 if (ret_val) {
183 hw_dbg("NVM Read Error\n");
184 goto out;
185 }
186
187 alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
188 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
189 }
190
191 /* if multicast bit is set, the alternate address will not be used */
192 if (alt_mac_addr[0] & 0x01) {
193 ret_val = -(E1000_NOT_IMPLEMENTED);
194 goto out;
195 }
196
197 for (i = 0; i < ETH_ALEN; i++)
198 hw->mac.addr[i] = hw->mac.perm_addr[i] = alt_mac_addr[i];
199
200 hw->mac.ops.rar_set(hw, hw->mac.perm_addr, 0);
201
202 out:
203 return ret_val;
204 }
205
206 /**
207 * igb_rar_set - Set receive address register
208 * @hw: pointer to the HW structure
209 * @addr: pointer to the receive address
210 * @index: receive address array register
211 *
212 * Sets the receive address array register at index to the address passed
213 * in by addr.
214 **/
215 void igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index)
216 {
217 u32 rar_low, rar_high;
218
219 /*
220 * HW expects these in little endian so we reverse the byte order
221 * from network order (big endian) to little endian
222 */
223 rar_low = ((u32) addr[0] |
224 ((u32) addr[1] << 8) |
225 ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
226
227 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
228
229 if (!hw->mac.disable_av)
230 rar_high |= E1000_RAH_AV;
231
232 array_wr32(E1000_RA, (index << 1), rar_low);
233 array_wr32(E1000_RA, ((index << 1) + 1), rar_high);
234 }
235
236 /**
237 * igb_mta_set - Set multicast filter table address
238 * @hw: pointer to the HW structure
239 * @hash_value: determines the MTA register and bit to set
240 *
241 * The multicast table address is a register array of 32-bit registers.
242 * The hash_value is used to determine what register the bit is in, the
243 * current value is read, the new bit is OR'd in and the new value is
244 * written back into the register.
245 **/
246 void igb_mta_set(struct e1000_hw *hw, u32 hash_value)
247 {
248 u32 hash_bit, hash_reg, mta;
249
250 /*
251 * The MTA is a register array of 32-bit registers. It is
252 * treated like an array of (32*mta_reg_count) bits. We want to
253 * set bit BitArray[hash_value]. So we figure out what register
254 * the bit is in, read it, OR in the new bit, then write
255 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a
256 * mask to bits 31:5 of the hash value which gives us the
257 * register we're modifying. The hash bit within that register
258 * is determined by the lower 5 bits of the hash value.
259 */
260 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
261 hash_bit = hash_value & 0x1F;
262
263 mta = array_rd32(E1000_MTA, hash_reg);
264
265 mta |= (1 << hash_bit);
266
267 array_wr32(E1000_MTA, hash_reg, mta);
268 wrfl();
269 }
270
271 /**
272 * igb_hash_mc_addr - Generate a multicast hash value
273 * @hw: pointer to the HW structure
274 * @mc_addr: pointer to a multicast address
275 *
276 * Generates a multicast address hash value which is used to determine
277 * the multicast filter table array address and new table value. See
278 * igb_mta_set()
279 **/
280 u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr)
281 {
282 u32 hash_value, hash_mask;
283 u8 bit_shift = 0;
284
285 /* Register count multiplied by bits per register */
286 hash_mask = (hw->mac.mta_reg_count * 32) - 1;
287
288 /*
289 * For a mc_filter_type of 0, bit_shift is the number of left-shifts
290 * where 0xFF would still fall within the hash mask.
291 */
292 while (hash_mask >> bit_shift != 0xFF)
293 bit_shift++;
294
295 /*
296 * The portion of the address that is used for the hash table
297 * is determined by the mc_filter_type setting.
298 * The algorithm is such that there is a total of 8 bits of shifting.
299 * The bit_shift for a mc_filter_type of 0 represents the number of
300 * left-shifts where the MSB of mc_addr[5] would still fall within
301 * the hash_mask. Case 0 does this exactly. Since there are a total
302 * of 8 bits of shifting, then mc_addr[4] will shift right the
303 * remaining number of bits. Thus 8 - bit_shift. The rest of the
304 * cases are a variation of this algorithm...essentially raising the
305 * number of bits to shift mc_addr[5] left, while still keeping the
306 * 8-bit shifting total.
307 *
308 * For example, given the following Destination MAC Address and an
309 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
310 * we can see that the bit_shift for case 0 is 4. These are the hash
311 * values resulting from each mc_filter_type...
312 * [0] [1] [2] [3] [4] [5]
313 * 01 AA 00 12 34 56
314 * LSB MSB
315 *
316 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
317 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
318 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
319 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
320 */
321 switch (hw->mac.mc_filter_type) {
322 default:
323 case 0:
324 break;
325 case 1:
326 bit_shift += 1;
327 break;
328 case 2:
329 bit_shift += 2;
330 break;
331 case 3:
332 bit_shift += 4;
333 break;
334 }
335
336 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
337 (((u16) mc_addr[5]) << bit_shift)));
338
339 return hash_value;
340 }
341
342 /**
343 * igb_clear_hw_cntrs_base - Clear base hardware counters
344 * @hw: pointer to the HW structure
345 *
346 * Clears the base hardware counters by reading the counter registers.
347 **/
348 void igb_clear_hw_cntrs_base(struct e1000_hw *hw)
349 {
350 u32 temp;
351
352 temp = rd32(E1000_CRCERRS);
353 temp = rd32(E1000_SYMERRS);
354 temp = rd32(E1000_MPC);
355 temp = rd32(E1000_SCC);
356 temp = rd32(E1000_ECOL);
357 temp = rd32(E1000_MCC);
358 temp = rd32(E1000_LATECOL);
359 temp = rd32(E1000_COLC);
360 temp = rd32(E1000_DC);
361 temp = rd32(E1000_SEC);
362 temp = rd32(E1000_RLEC);
363 temp = rd32(E1000_XONRXC);
364 temp = rd32(E1000_XONTXC);
365 temp = rd32(E1000_XOFFRXC);
366 temp = rd32(E1000_XOFFTXC);
367 temp = rd32(E1000_FCRUC);
368 temp = rd32(E1000_GPRC);
369 temp = rd32(E1000_BPRC);
370 temp = rd32(E1000_MPRC);
371 temp = rd32(E1000_GPTC);
372 temp = rd32(E1000_GORCL);
373 temp = rd32(E1000_GORCH);
374 temp = rd32(E1000_GOTCL);
375 temp = rd32(E1000_GOTCH);
376 temp = rd32(E1000_RNBC);
377 temp = rd32(E1000_RUC);
378 temp = rd32(E1000_RFC);
379 temp = rd32(E1000_ROC);
380 temp = rd32(E1000_RJC);
381 temp = rd32(E1000_TORL);
382 temp = rd32(E1000_TORH);
383 temp = rd32(E1000_TOTL);
384 temp = rd32(E1000_TOTH);
385 temp = rd32(E1000_TPR);
386 temp = rd32(E1000_TPT);
387 temp = rd32(E1000_MPTC);
388 temp = rd32(E1000_BPTC);
389 }
390
391 /**
392 * igb_check_for_copper_link - Check for link (Copper)
393 * @hw: pointer to the HW structure
394 *
395 * Checks to see of the link status of the hardware has changed. If a
396 * change in link status has been detected, then we read the PHY registers
397 * to get the current speed/duplex if link exists.
398 **/
399 s32 igb_check_for_copper_link(struct e1000_hw *hw)
400 {
401 struct e1000_mac_info *mac = &hw->mac;
402 s32 ret_val;
403 bool link;
404
405 /*
406 * We only want to go out to the PHY registers to see if Auto-Neg
407 * has completed and/or if our link status has changed. The
408 * get_link_status flag is set upon receiving a Link Status
409 * Change or Rx Sequence Error interrupt.
410 */
411 if (!mac->get_link_status) {
412 ret_val = 0;
413 goto out;
414 }
415
416 /*
417 * First we want to see if the MII Status Register reports
418 * link. If so, then we want to get the current speed/duplex
419 * of the PHY.
420 */
421 ret_val = igb_phy_has_link(hw, 1, 0, &link);
422 if (ret_val)
423 goto out;
424
425 if (!link)
426 goto out; /* No link detected */
427
428 mac->get_link_status = false;
429
430 /*
431 * Check if there was DownShift, must be checked
432 * immediately after link-up
433 */
434 igb_check_downshift(hw);
435
436 /*
437 * If we are forcing speed/duplex, then we simply return since
438 * we have already determined whether we have link or not.
439 */
440 if (!mac->autoneg) {
441 ret_val = -E1000_ERR_CONFIG;
442 goto out;
443 }
444
445 /*
446 * Auto-Neg is enabled. Auto Speed Detection takes care
447 * of MAC speed/duplex configuration. So we only need to
448 * configure Collision Distance in the MAC.
449 */
450 igb_config_collision_dist(hw);
451
452 /*
453 * Configure Flow Control now that Auto-Neg has completed.
454 * First, we need to restore the desired flow control
455 * settings because we may have had to re-autoneg with a
456 * different link partner.
457 */
458 ret_val = igb_config_fc_after_link_up(hw);
459 if (ret_val)
460 hw_dbg("Error configuring flow control\n");
461
462 out:
463 return ret_val;
464 }
465
466 /**
467 * igb_setup_link - Setup flow control and link settings
468 * @hw: pointer to the HW structure
469 *
470 * Determines which flow control settings to use, then configures flow
471 * control. Calls the appropriate media-specific link configuration
472 * function. Assuming the adapter has a valid link partner, a valid link
473 * should be established. Assumes the hardware has previously been reset
474 * and the transmitter and receiver are not enabled.
475 **/
476 s32 igb_setup_link(struct e1000_hw *hw)
477 {
478 s32 ret_val = 0;
479
480 /*
481 * In the case of the phy reset being blocked, we already have a link.
482 * We do not need to set it up again.
483 */
484 if (igb_check_reset_block(hw))
485 goto out;
486
487 ret_val = igb_set_default_fc(hw);
488 if (ret_val)
489 goto out;
490
491 /*
492 * We want to save off the original Flow Control configuration just
493 * in case we get disconnected and then reconnected into a different
494 * hub or switch with different Flow Control capabilities.
495 */
496 hw->fc.original_type = hw->fc.type;
497
498 hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.type);
499
500 /* Call the necessary media_type subroutine to configure the link. */
501 ret_val = hw->mac.ops.setup_physical_interface(hw);
502 if (ret_val)
503 goto out;
504
505 /*
506 * Initialize the flow control address, type, and PAUSE timer
507 * registers to their default values. This is done even if flow
508 * control is disabled, because it does not hurt anything to
509 * initialize these registers.
510 */
511 hw_dbg("Initializing the Flow Control address, type and timer regs\n");
512 wr32(E1000_FCT, FLOW_CONTROL_TYPE);
513 wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
514 wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
515
516 wr32(E1000_FCTTV, hw->fc.pause_time);
517
518 ret_val = igb_set_fc_watermarks(hw);
519
520 out:
521 return ret_val;
522 }
523
524 /**
525 * igb_config_collision_dist - Configure collision distance
526 * @hw: pointer to the HW structure
527 *
528 * Configures the collision distance to the default value and is used
529 * during link setup. Currently no func pointer exists and all
530 * implementations are handled in the generic version of this function.
531 **/
532 void igb_config_collision_dist(struct e1000_hw *hw)
533 {
534 u32 tctl;
535
536 tctl = rd32(E1000_TCTL);
537
538 tctl &= ~E1000_TCTL_COLD;
539 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
540
541 wr32(E1000_TCTL, tctl);
542 wrfl();
543 }
544
545 /**
546 * igb_set_fc_watermarks - Set flow control high/low watermarks
547 * @hw: pointer to the HW structure
548 *
549 * Sets the flow control high/low threshold (watermark) registers. If
550 * flow control XON frame transmission is enabled, then set XON frame
551 * tansmission as well.
552 **/
553 static s32 igb_set_fc_watermarks(struct e1000_hw *hw)
554 {
555 s32 ret_val = 0;
556 u32 fcrtl = 0, fcrth = 0;
557
558 /*
559 * Set the flow control receive threshold registers. Normally,
560 * these registers will be set to a default threshold that may be
561 * adjusted later by the driver's runtime code. However, if the
562 * ability to transmit pause frames is not enabled, then these
563 * registers will be set to 0.
564 */
565 if (hw->fc.type & e1000_fc_tx_pause) {
566 /*
567 * We need to set up the Receive Threshold high and low water
568 * marks as well as (optionally) enabling the transmission of
569 * XON frames.
570 */
571 fcrtl = hw->fc.low_water;
572 if (hw->fc.send_xon)
573 fcrtl |= E1000_FCRTL_XONE;
574
575 fcrth = hw->fc.high_water;
576 }
577 wr32(E1000_FCRTL, fcrtl);
578 wr32(E1000_FCRTH, fcrth);
579
580 return ret_val;
581 }
582
583 /**
584 * igb_set_default_fc - Set flow control default values
585 * @hw: pointer to the HW structure
586 *
587 * Read the EEPROM for the default values for flow control and store the
588 * values.
589 **/
590 static s32 igb_set_default_fc(struct e1000_hw *hw)
591 {
592 s32 ret_val = 0;
593 u16 nvm_data;
594
595 /*
596 * Read and store word 0x0F of the EEPROM. This word contains bits
597 * that determine the hardware's default PAUSE (flow control) mode,
598 * a bit that determines whether the HW defaults to enabling or
599 * disabling auto-negotiation, and the direction of the
600 * SW defined pins. If there is no SW over-ride of the flow
601 * control setting, then the variable hw->fc will
602 * be initialized based on a value in the EEPROM.
603 */
604 ret_val = hw->nvm.ops.read_nvm(hw, NVM_INIT_CONTROL2_REG, 1,
605 &nvm_data);
606
607 if (ret_val) {
608 hw_dbg("NVM Read Error\n");
609 goto out;
610 }
611
612 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
613 hw->fc.type = e1000_fc_none;
614 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
615 NVM_WORD0F_ASM_DIR)
616 hw->fc.type = e1000_fc_tx_pause;
617 else
618 hw->fc.type = e1000_fc_full;
619
620 out:
621 return ret_val;
622 }
623
624 /**
625 * igb_force_mac_fc - Force the MAC's flow control settings
626 * @hw: pointer to the HW structure
627 *
628 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the
629 * device control register to reflect the adapter settings. TFCE and RFCE
630 * need to be explicitly set by software when a copper PHY is used because
631 * autonegotiation is managed by the PHY rather than the MAC. Software must
632 * also configure these bits when link is forced on a fiber connection.
633 **/
634 s32 igb_force_mac_fc(struct e1000_hw *hw)
635 {
636 u32 ctrl;
637 s32 ret_val = 0;
638
639 ctrl = rd32(E1000_CTRL);
640
641 /*
642 * Because we didn't get link via the internal auto-negotiation
643 * mechanism (we either forced link or we got link via PHY
644 * auto-neg), we have to manually enable/disable transmit an
645 * receive flow control.
646 *
647 * The "Case" statement below enables/disable flow control
648 * according to the "hw->fc.type" parameter.
649 *
650 * The possible values of the "fc" parameter are:
651 * 0: Flow control is completely disabled
652 * 1: Rx flow control is enabled (we can receive pause
653 * frames but not send pause frames).
654 * 2: Tx flow control is enabled (we can send pause frames
655 * frames but we do not receive pause frames).
656 * 3: Both Rx and TX flow control (symmetric) is enabled.
657 * other: No other values should be possible at this point.
658 */
659 hw_dbg("hw->fc.type = %u\n", hw->fc.type);
660
661 switch (hw->fc.type) {
662 case e1000_fc_none:
663 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
664 break;
665 case e1000_fc_rx_pause:
666 ctrl &= (~E1000_CTRL_TFCE);
667 ctrl |= E1000_CTRL_RFCE;
668 break;
669 case e1000_fc_tx_pause:
670 ctrl &= (~E1000_CTRL_RFCE);
671 ctrl |= E1000_CTRL_TFCE;
672 break;
673 case e1000_fc_full:
674 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
675 break;
676 default:
677 hw_dbg("Flow control param set incorrectly\n");
678 ret_val = -E1000_ERR_CONFIG;
679 goto out;
680 }
681
682 wr32(E1000_CTRL, ctrl);
683
684 out:
685 return ret_val;
686 }
687
688 /**
689 * igb_config_fc_after_link_up - Configures flow control after link
690 * @hw: pointer to the HW structure
691 *
692 * Checks the status of auto-negotiation after link up to ensure that the
693 * speed and duplex were not forced. If the link needed to be forced, then
694 * flow control needs to be forced also. If auto-negotiation is enabled
695 * and did not fail, then we configure flow control based on our link
696 * partner.
697 **/
698 s32 igb_config_fc_after_link_up(struct e1000_hw *hw)
699 {
700 struct e1000_mac_info *mac = &hw->mac;
701 s32 ret_val = 0;
702 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
703 u16 speed, duplex;
704
705 /*
706 * Check for the case where we have fiber media and auto-neg failed
707 * so we had to force link. In this case, we need to force the
708 * configuration of the MAC to match the "fc" parameter.
709 */
710 if (mac->autoneg_failed) {
711 if (hw->phy.media_type == e1000_media_type_fiber ||
712 hw->phy.media_type == e1000_media_type_internal_serdes)
713 ret_val = igb_force_mac_fc(hw);
714 } else {
715 if (hw->phy.media_type == e1000_media_type_copper)
716 ret_val = igb_force_mac_fc(hw);
717 }
718
719 if (ret_val) {
720 hw_dbg("Error forcing flow control settings\n");
721 goto out;
722 }
723
724 /*
725 * Check for the case where we have copper media and auto-neg is
726 * enabled. In this case, we need to check and see if Auto-Neg
727 * has completed, and if so, how the PHY and link partner has
728 * flow control configured.
729 */
730 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
731 /*
732 * Read the MII Status Register and check to see if AutoNeg
733 * has completed. We read this twice because this reg has
734 * some "sticky" (latched) bits.
735 */
736 ret_val = hw->phy.ops.read_phy_reg(hw, PHY_STATUS,
737 &mii_status_reg);
738 if (ret_val)
739 goto out;
740 ret_val = hw->phy.ops.read_phy_reg(hw, PHY_STATUS,
741 &mii_status_reg);
742 if (ret_val)
743 goto out;
744
745 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
746 hw_dbg("Copper PHY and Auto Neg "
747 "has not completed.\n");
748 goto out;
749 }
750
751 /*
752 * The AutoNeg process has completed, so we now need to
753 * read both the Auto Negotiation Advertisement
754 * Register (Address 4) and the Auto_Negotiation Base
755 * Page Ability Register (Address 5) to determine how
756 * flow control was negotiated.
757 */
758 ret_val = hw->phy.ops.read_phy_reg(hw, PHY_AUTONEG_ADV,
759 &mii_nway_adv_reg);
760 if (ret_val)
761 goto out;
762 ret_val = hw->phy.ops.read_phy_reg(hw, PHY_LP_ABILITY,
763 &mii_nway_lp_ability_reg);
764 if (ret_val)
765 goto out;
766
767 /*
768 * Two bits in the Auto Negotiation Advertisement Register
769 * (Address 4) and two bits in the Auto Negotiation Base
770 * Page Ability Register (Address 5) determine flow control
771 * for both the PHY and the link partner. The following
772 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
773 * 1999, describes these PAUSE resolution bits and how flow
774 * control is determined based upon these settings.
775 * NOTE: DC = Don't Care
776 *
777 * LOCAL DEVICE | LINK PARTNER
778 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
779 *-------|---------|-------|---------|--------------------
780 * 0 | 0 | DC | DC | e1000_fc_none
781 * 0 | 1 | 0 | DC | e1000_fc_none
782 * 0 | 1 | 1 | 0 | e1000_fc_none
783 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
784 * 1 | 0 | 0 | DC | e1000_fc_none
785 * 1 | DC | 1 | DC | e1000_fc_full
786 * 1 | 1 | 0 | 0 | e1000_fc_none
787 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
788 *
789 * Are both PAUSE bits set to 1? If so, this implies
790 * Symmetric Flow Control is enabled at both ends. The
791 * ASM_DIR bits are irrelevant per the spec.
792 *
793 * For Symmetric Flow Control:
794 *
795 * LOCAL DEVICE | LINK PARTNER
796 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
797 *-------|---------|-------|---------|--------------------
798 * 1 | DC | 1 | DC | E1000_fc_full
799 *
800 */
801 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
802 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
803 /*
804 * Now we need to check if the user selected RX ONLY
805 * of pause frames. In this case, we had to advertise
806 * FULL flow control because we could not advertise RX
807 * ONLY. Hence, we must now check to see if we need to
808 * turn OFF the TRANSMISSION of PAUSE frames.
809 */
810 if (hw->fc.original_type == e1000_fc_full) {
811 hw->fc.type = e1000_fc_full;
812 hw_dbg("Flow Control = FULL.\r\n");
813 } else {
814 hw->fc.type = e1000_fc_rx_pause;
815 hw_dbg("Flow Control = "
816 "RX PAUSE frames only.\r\n");
817 }
818 }
819 /*
820 * For receiving PAUSE frames ONLY.
821 *
822 * LOCAL DEVICE | LINK PARTNER
823 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
824 *-------|---------|-------|---------|--------------------
825 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
826 */
827 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
828 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
829 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
830 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
831 hw->fc.type = e1000_fc_tx_pause;
832 hw_dbg("Flow Control = TX PAUSE frames only.\r\n");
833 }
834 /*
835 * For transmitting PAUSE frames ONLY.
836 *
837 * LOCAL DEVICE | LINK PARTNER
838 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
839 *-------|---------|-------|---------|--------------------
840 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
841 */
842 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
843 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
844 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
845 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
846 hw->fc.type = e1000_fc_rx_pause;
847 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
848 }
849 /*
850 * Per the IEEE spec, at this point flow control should be
851 * disabled. However, we want to consider that we could
852 * be connected to a legacy switch that doesn't advertise
853 * desired flow control, but can be forced on the link
854 * partner. So if we advertised no flow control, that is
855 * what we will resolve to. If we advertised some kind of
856 * receive capability (Rx Pause Only or Full Flow Control)
857 * and the link partner advertised none, we will configure
858 * ourselves to enable Rx Flow Control only. We can do
859 * this safely for two reasons: If the link partner really
860 * didn't want flow control enabled, and we enable Rx, no
861 * harm done since we won't be receiving any PAUSE frames
862 * anyway. If the intent on the link partner was to have
863 * flow control enabled, then by us enabling RX only, we
864 * can at least receive pause frames and process them.
865 * This is a good idea because in most cases, since we are
866 * predominantly a server NIC, more times than not we will
867 * be asked to delay transmission of packets than asking
868 * our link partner to pause transmission of frames.
869 */
870 else if ((hw->fc.original_type == e1000_fc_none ||
871 hw->fc.original_type == e1000_fc_tx_pause) ||
872 hw->fc.strict_ieee) {
873 hw->fc.type = e1000_fc_none;
874 hw_dbg("Flow Control = NONE.\r\n");
875 } else {
876 hw->fc.type = e1000_fc_rx_pause;
877 hw_dbg("Flow Control = RX PAUSE frames only.\r\n");
878 }
879
880 /*
881 * Now we need to do one last check... If we auto-
882 * negotiated to HALF DUPLEX, flow control should not be
883 * enabled per IEEE 802.3 spec.
884 */
885 ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex);
886 if (ret_val) {
887 hw_dbg("Error getting link speed and duplex\n");
888 goto out;
889 }
890
891 if (duplex == HALF_DUPLEX)
892 hw->fc.type = e1000_fc_none;
893
894 /*
895 * Now we call a subroutine to actually force the MAC
896 * controller to use the correct flow control settings.
897 */
898 ret_val = igb_force_mac_fc(hw);
899 if (ret_val) {
900 hw_dbg("Error forcing flow control settings\n");
901 goto out;
902 }
903 }
904
905 out:
906 return ret_val;
907 }
908
909 /**
910 * igb_get_speed_and_duplex_copper - Retreive current speed/duplex
911 * @hw: pointer to the HW structure
912 * @speed: stores the current speed
913 * @duplex: stores the current duplex
914 *
915 * Read the status register for the current speed/duplex and store the current
916 * speed and duplex for copper connections.
917 **/
918 s32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed,
919 u16 *duplex)
920 {
921 u32 status;
922
923 status = rd32(E1000_STATUS);
924 if (status & E1000_STATUS_SPEED_1000) {
925 *speed = SPEED_1000;
926 hw_dbg("1000 Mbs, ");
927 } else if (status & E1000_STATUS_SPEED_100) {
928 *speed = SPEED_100;
929 hw_dbg("100 Mbs, ");
930 } else {
931 *speed = SPEED_10;
932 hw_dbg("10 Mbs, ");
933 }
934
935 if (status & E1000_STATUS_FD) {
936 *duplex = FULL_DUPLEX;
937 hw_dbg("Full Duplex\n");
938 } else {
939 *duplex = HALF_DUPLEX;
940 hw_dbg("Half Duplex\n");
941 }
942
943 return 0;
944 }
945
946 /**
947 * igb_get_hw_semaphore - Acquire hardware semaphore
948 * @hw: pointer to the HW structure
949 *
950 * Acquire the HW semaphore to access the PHY or NVM
951 **/
952 s32 igb_get_hw_semaphore(struct e1000_hw *hw)
953 {
954 u32 swsm;
955 s32 ret_val = 0;
956 s32 timeout = hw->nvm.word_size + 1;
957 s32 i = 0;
958
959 /* Get the SW semaphore */
960 while (i < timeout) {
961 swsm = rd32(E1000_SWSM);
962 if (!(swsm & E1000_SWSM_SMBI))
963 break;
964
965 udelay(50);
966 i++;
967 }
968
969 if (i == timeout) {
970 hw_dbg("Driver can't access device - SMBI bit is set.\n");
971 ret_val = -E1000_ERR_NVM;
972 goto out;
973 }
974
975 /* Get the FW semaphore. */
976 for (i = 0; i < timeout; i++) {
977 swsm = rd32(E1000_SWSM);
978 wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
979
980 /* Semaphore acquired if bit latched */
981 if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
982 break;
983
984 udelay(50);
985 }
986
987 if (i == timeout) {
988 /* Release semaphores */
989 igb_put_hw_semaphore(hw);
990 hw_dbg("Driver can't access the NVM\n");
991 ret_val = -E1000_ERR_NVM;
992 goto out;
993 }
994
995 out:
996 return ret_val;
997 }
998
999 /**
1000 * igb_put_hw_semaphore - Release hardware semaphore
1001 * @hw: pointer to the HW structure
1002 *
1003 * Release hardware semaphore used to access the PHY or NVM
1004 **/
1005 void igb_put_hw_semaphore(struct e1000_hw *hw)
1006 {
1007 u32 swsm;
1008
1009 swsm = rd32(E1000_SWSM);
1010
1011 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
1012
1013 wr32(E1000_SWSM, swsm);
1014 }
1015
1016 /**
1017 * igb_get_auto_rd_done - Check for auto read completion
1018 * @hw: pointer to the HW structure
1019 *
1020 * Check EEPROM for Auto Read done bit.
1021 **/
1022 s32 igb_get_auto_rd_done(struct e1000_hw *hw)
1023 {
1024 s32 i = 0;
1025 s32 ret_val = 0;
1026
1027
1028 while (i < AUTO_READ_DONE_TIMEOUT) {
1029 if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD)
1030 break;
1031 msleep(1);
1032 i++;
1033 }
1034
1035 if (i == AUTO_READ_DONE_TIMEOUT) {
1036 hw_dbg("Auto read by HW from NVM has not completed.\n");
1037 ret_val = -E1000_ERR_RESET;
1038 goto out;
1039 }
1040
1041 out:
1042 return ret_val;
1043 }
1044
1045 /**
1046 * igb_valid_led_default - Verify a valid default LED config
1047 * @hw: pointer to the HW structure
1048 * @data: pointer to the NVM (EEPROM)
1049 *
1050 * Read the EEPROM for the current default LED configuration. If the
1051 * LED configuration is not valid, set to a valid LED configuration.
1052 **/
1053 static s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data)
1054 {
1055 s32 ret_val;
1056
1057 ret_val = hw->nvm.ops.read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
1058 if (ret_val) {
1059 hw_dbg("NVM Read Error\n");
1060 goto out;
1061 }
1062
1063 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
1064 *data = ID_LED_DEFAULT;
1065
1066 out:
1067 return ret_val;
1068 }
1069
1070 /**
1071 * igb_id_led_init -
1072 * @hw: pointer to the HW structure
1073 *
1074 **/
1075 s32 igb_id_led_init(struct e1000_hw *hw)
1076 {
1077 struct e1000_mac_info *mac = &hw->mac;
1078 s32 ret_val;
1079 const u32 ledctl_mask = 0x000000FF;
1080 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
1081 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
1082 u16 data, i, temp;
1083 const u16 led_mask = 0x0F;
1084
1085 ret_val = igb_valid_led_default(hw, &data);
1086 if (ret_val)
1087 goto out;
1088
1089 mac->ledctl_default = rd32(E1000_LEDCTL);
1090 mac->ledctl_mode1 = mac->ledctl_default;
1091 mac->ledctl_mode2 = mac->ledctl_default;
1092
1093 for (i = 0; i < 4; i++) {
1094 temp = (data >> (i << 2)) & led_mask;
1095 switch (temp) {
1096 case ID_LED_ON1_DEF2:
1097 case ID_LED_ON1_ON2:
1098 case ID_LED_ON1_OFF2:
1099 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1100 mac->ledctl_mode1 |= ledctl_on << (i << 3);
1101 break;
1102 case ID_LED_OFF1_DEF2:
1103 case ID_LED_OFF1_ON2:
1104 case ID_LED_OFF1_OFF2:
1105 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
1106 mac->ledctl_mode1 |= ledctl_off << (i << 3);
1107 break;
1108 default:
1109 /* Do nothing */
1110 break;
1111 }
1112 switch (temp) {
1113 case ID_LED_DEF1_ON2:
1114 case ID_LED_ON1_ON2:
1115 case ID_LED_OFF1_ON2:
1116 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1117 mac->ledctl_mode2 |= ledctl_on << (i << 3);
1118 break;
1119 case ID_LED_DEF1_OFF2:
1120 case ID_LED_ON1_OFF2:
1121 case ID_LED_OFF1_OFF2:
1122 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
1123 mac->ledctl_mode2 |= ledctl_off << (i << 3);
1124 break;
1125 default:
1126 /* Do nothing */
1127 break;
1128 }
1129 }
1130
1131 out:
1132 return ret_val;
1133 }
1134
1135 /**
1136 * igb_cleanup_led - Set LED config to default operation
1137 * @hw: pointer to the HW structure
1138 *
1139 * Remove the current LED configuration and set the LED configuration
1140 * to the default value, saved from the EEPROM.
1141 **/
1142 s32 igb_cleanup_led(struct e1000_hw *hw)
1143 {
1144 wr32(E1000_LEDCTL, hw->mac.ledctl_default);
1145 return 0;
1146 }
1147
1148 /**
1149 * igb_blink_led - Blink LED
1150 * @hw: pointer to the HW structure
1151 *
1152 * Blink the led's which are set to be on.
1153 **/
1154 s32 igb_blink_led(struct e1000_hw *hw)
1155 {
1156 u32 ledctl_blink = 0;
1157 u32 i;
1158
1159 if (hw->phy.media_type == e1000_media_type_fiber) {
1160 /* always blink LED0 for PCI-E fiber */
1161 ledctl_blink = E1000_LEDCTL_LED0_BLINK |
1162 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
1163 } else {
1164 /*
1165 * set the blink bit for each LED that's "on" (0x0E)
1166 * in ledctl_mode2
1167 */
1168 ledctl_blink = hw->mac.ledctl_mode2;
1169 for (i = 0; i < 4; i++)
1170 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
1171 E1000_LEDCTL_MODE_LED_ON)
1172 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
1173 (i * 8));
1174 }
1175
1176 wr32(E1000_LEDCTL, ledctl_blink);
1177
1178 return 0;
1179 }
1180
1181 /**
1182 * igb_led_off - Turn LED off
1183 * @hw: pointer to the HW structure
1184 *
1185 * Turn LED off.
1186 **/
1187 s32 igb_led_off(struct e1000_hw *hw)
1188 {
1189 u32 ctrl;
1190
1191 switch (hw->phy.media_type) {
1192 case e1000_media_type_fiber:
1193 ctrl = rd32(E1000_CTRL);
1194 ctrl |= E1000_CTRL_SWDPIN0;
1195 ctrl |= E1000_CTRL_SWDPIO0;
1196 wr32(E1000_CTRL, ctrl);
1197 break;
1198 case e1000_media_type_copper:
1199 wr32(E1000_LEDCTL, hw->mac.ledctl_mode1);
1200 break;
1201 default:
1202 break;
1203 }
1204
1205 return 0;
1206 }
1207
1208 /**
1209 * igb_disable_pcie_master - Disables PCI-express master access
1210 * @hw: pointer to the HW structure
1211 *
1212 * Returns 0 (0) if successful, else returns -10
1213 * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not casued
1214 * the master requests to be disabled.
1215 *
1216 * Disables PCI-Express master access and verifies there are no pending
1217 * requests.
1218 **/
1219 s32 igb_disable_pcie_master(struct e1000_hw *hw)
1220 {
1221 u32 ctrl;
1222 s32 timeout = MASTER_DISABLE_TIMEOUT;
1223 s32 ret_val = 0;
1224
1225 if (hw->bus.type != e1000_bus_type_pci_express)
1226 goto out;
1227
1228 ctrl = rd32(E1000_CTRL);
1229 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
1230 wr32(E1000_CTRL, ctrl);
1231
1232 while (timeout) {
1233 if (!(rd32(E1000_STATUS) &
1234 E1000_STATUS_GIO_MASTER_ENABLE))
1235 break;
1236 udelay(100);
1237 timeout--;
1238 }
1239
1240 if (!timeout) {
1241 hw_dbg("Master requests are pending.\n");
1242 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
1243 goto out;
1244 }
1245
1246 out:
1247 return ret_val;
1248 }
1249
1250 /**
1251 * igb_reset_adaptive - Reset Adaptive Interframe Spacing
1252 * @hw: pointer to the HW structure
1253 *
1254 * Reset the Adaptive Interframe Spacing throttle to default values.
1255 **/
1256 void igb_reset_adaptive(struct e1000_hw *hw)
1257 {
1258 struct e1000_mac_info *mac = &hw->mac;
1259
1260 if (!mac->adaptive_ifs) {
1261 hw_dbg("Not in Adaptive IFS mode!\n");
1262 goto out;
1263 }
1264
1265 if (!mac->ifs_params_forced) {
1266 mac->current_ifs_val = 0;
1267 mac->ifs_min_val = IFS_MIN;
1268 mac->ifs_max_val = IFS_MAX;
1269 mac->ifs_step_size = IFS_STEP;
1270 mac->ifs_ratio = IFS_RATIO;
1271 }
1272
1273 mac->in_ifs_mode = false;
1274 wr32(E1000_AIT, 0);
1275 out:
1276 return;
1277 }
1278
1279 /**
1280 * igb_update_adaptive - Update Adaptive Interframe Spacing
1281 * @hw: pointer to the HW structure
1282 *
1283 * Update the Adaptive Interframe Spacing Throttle value based on the
1284 * time between transmitted packets and time between collisions.
1285 **/
1286 void igb_update_adaptive(struct e1000_hw *hw)
1287 {
1288 struct e1000_mac_info *mac = &hw->mac;
1289
1290 if (!mac->adaptive_ifs) {
1291 hw_dbg("Not in Adaptive IFS mode!\n");
1292 goto out;
1293 }
1294
1295 if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
1296 if (mac->tx_packet_delta > MIN_NUM_XMITS) {
1297 mac->in_ifs_mode = true;
1298 if (mac->current_ifs_val < mac->ifs_max_val) {
1299 if (!mac->current_ifs_val)
1300 mac->current_ifs_val = mac->ifs_min_val;
1301 else
1302 mac->current_ifs_val +=
1303 mac->ifs_step_size;
1304 wr32(E1000_AIT,
1305 mac->current_ifs_val);
1306 }
1307 }
1308 } else {
1309 if (mac->in_ifs_mode &&
1310 (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
1311 mac->current_ifs_val = 0;
1312 mac->in_ifs_mode = false;
1313 wr32(E1000_AIT, 0);
1314 }
1315 }
1316 out:
1317 return;
1318 }
1319
1320 /**
1321 * igb_validate_mdi_setting - Verify MDI/MDIx settings
1322 * @hw: pointer to the HW structure
1323 *
1324 * Verify that when not using auto-negotitation that MDI/MDIx is correctly
1325 * set, which is forced to MDI mode only.
1326 **/
1327 s32 igb_validate_mdi_setting(struct e1000_hw *hw)
1328 {
1329 s32 ret_val = 0;
1330
1331 if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
1332 hw_dbg("Invalid MDI setting detected\n");
1333 hw->phy.mdix = 1;
1334 ret_val = -E1000_ERR_CONFIG;
1335 goto out;
1336 }
1337
1338 out:
1339 return ret_val;
1340 }
1341
1342 /**
1343 * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register
1344 * @hw: pointer to the HW structure
1345 * @reg: 32bit register offset such as E1000_SCTL
1346 * @offset: register offset to write to
1347 * @data: data to write at register offset
1348 *
1349 * Writes an address/data control type register. There are several of these
1350 * and they all have the format address << 8 | data and bit 31 is polled for
1351 * completion.
1352 **/
1353 s32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg,
1354 u32 offset, u8 data)
1355 {
1356 u32 i, regvalue = 0;
1357 s32 ret_val = 0;
1358
1359 /* Set up the address and data */
1360 regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
1361 wr32(reg, regvalue);
1362
1363 /* Poll the ready bit to see if the MDI read completed */
1364 for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
1365 udelay(5);
1366 regvalue = rd32(reg);
1367 if (regvalue & E1000_GEN_CTL_READY)
1368 break;
1369 }
1370 if (!(regvalue & E1000_GEN_CTL_READY)) {
1371 hw_dbg("Reg %08x did not indicate ready\n", reg);
1372 ret_val = -E1000_ERR_PHY;
1373 goto out;
1374 }
1375
1376 out:
1377 return ret_val;
1378 }
1379
1380 /**
1381 * igb_enable_mng_pass_thru - Enable processing of ARP's
1382 * @hw: pointer to the HW structure
1383 *
1384 * Verifies the hardware needs to allow ARPs to be processed by the host.
1385 **/
1386 bool igb_enable_mng_pass_thru(struct e1000_hw *hw)
1387 {
1388 u32 manc;
1389 u32 fwsm, factps;
1390 bool ret_val = false;
1391
1392 if (!hw->mac.asf_firmware_present)
1393 goto out;
1394
1395 manc = rd32(E1000_MANC);
1396
1397 if (!(manc & E1000_MANC_RCV_TCO_EN) ||
1398 !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
1399 goto out;
1400
1401 if (hw->mac.arc_subsystem_valid) {
1402 fwsm = rd32(E1000_FWSM);
1403 factps = rd32(E1000_FACTPS);
1404
1405 if (!(factps & E1000_FACTPS_MNGCG) &&
1406 ((fwsm & E1000_FWSM_MODE_MASK) ==
1407 (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) {
1408 ret_val = true;
1409 goto out;
1410 }
1411 } else {
1412 if ((manc & E1000_MANC_SMBUS_EN) &&
1413 !(manc & E1000_MANC_ASF_EN)) {
1414 ret_val = true;
1415 goto out;
1416 }
1417 }
1418
1419 out:
1420 return ret_val;
1421 }
This page took 0.057924 seconds and 6 git commands to generate.