1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2012 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
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 "LICENSE.GPL".
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *******************************************************************************/
28 #include "ixgbe_type.h"
29 #include "ixgbe_82598.h"
30 #include "ixgbe_api.h"
31 #include "ixgbe_common.h"
32 #include "ixgbe_phy.h"
34 static s32 ixgbe_get_link_capabilities_82598(struct ixgbe_hw *hw,
35 ixgbe_link_speed *speed,
37 static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw);
38 static s32 ixgbe_start_mac_link_82598(struct ixgbe_hw *hw,
39 bool autoneg_wait_to_complete);
40 static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw,
41 ixgbe_link_speed *speed, bool *link_up,
42 bool link_up_wait_to_complete);
43 static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw,
44 ixgbe_link_speed speed,
46 bool autoneg_wait_to_complete);
47 static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw,
48 ixgbe_link_speed speed,
50 bool autoneg_wait_to_complete);
51 static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw);
52 static s32 ixgbe_clear_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq);
53 static s32 ixgbe_clear_vfta_82598(struct ixgbe_hw *hw);
54 static void ixgbe_set_rxpba_82598(struct ixgbe_hw *hw, int num_pb,
55 u32 headroom, int strategy);
58 * ixgbe_set_pcie_completion_timeout - set pci-e completion timeout
59 * @hw: pointer to the HW structure
61 * The defaults for 82598 should be in the range of 50us to 50ms,
62 * however the hardware default for these parts is 500us to 1ms which is less
63 * than the 10ms recommended by the pci-e spec. To address this we need to
64 * increase the value to either 10ms to 250ms for capability version 1 config,
65 * or 16ms to 55ms for version 2.
67 void ixgbe_set_pcie_completion_timeout(struct ixgbe_hw *hw)
69 u32 gcr = IXGBE_READ_REG(hw, IXGBE_GCR);
72 /* only take action if timeout value is defaulted to 0 */
73 if (gcr & IXGBE_GCR_CMPL_TMOUT_MASK)
77 * if capababilities version is type 1 we can write the
78 * timeout of 10ms to 250ms through the GCR register
80 if (!(gcr & IXGBE_GCR_CAP_VER2)) {
81 gcr |= IXGBE_GCR_CMPL_TMOUT_10ms;
86 * for version 2 capabilities we need to write the config space
87 * directly in order to set the completion timeout value for
90 pcie_devctl2 = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_CONTROL2);
91 pcie_devctl2 |= IXGBE_PCI_DEVICE_CONTROL2_16ms;
92 IXGBE_WRITE_PCIE_WORD(hw, IXGBE_PCI_DEVICE_CONTROL2, pcie_devctl2);
94 /* disable completion timeout resend */
95 gcr &= ~IXGBE_GCR_CMPL_TMOUT_RESEND;
96 IXGBE_WRITE_REG(hw, IXGBE_GCR, gcr);
100 * ixgbe_init_ops_82598 - Inits func ptrs and MAC type
101 * @hw: pointer to hardware structure
103 * Initialize the function pointers and assign the MAC type for 82598.
104 * Does not touch the hardware.
106 s32 ixgbe_init_ops_82598(struct ixgbe_hw *hw)
108 struct ixgbe_mac_info *mac = &hw->mac;
109 struct ixgbe_phy_info *phy = &hw->phy;
112 ret_val = ixgbe_init_phy_ops_generic(hw);
113 ret_val = ixgbe_init_ops_generic(hw);
116 phy->ops.init = &ixgbe_init_phy_ops_82598;
119 mac->ops.start_hw = &ixgbe_start_hw_82598;
120 mac->ops.reset_hw = &ixgbe_reset_hw_82598;
121 mac->ops.get_media_type = &ixgbe_get_media_type_82598;
122 mac->ops.get_supported_physical_layer =
123 &ixgbe_get_supported_physical_layer_82598;
124 mac->ops.read_analog_reg8 = &ixgbe_read_analog_reg8_82598;
125 mac->ops.write_analog_reg8 = &ixgbe_write_analog_reg8_82598;
126 mac->ops.set_lan_id = &ixgbe_set_lan_id_multi_port_pcie_82598;
128 /* RAR, Multicast, VLAN */
129 mac->ops.set_vmdq = &ixgbe_set_vmdq_82598;
130 mac->ops.clear_vmdq = &ixgbe_clear_vmdq_82598;
131 mac->ops.set_vfta = &ixgbe_set_vfta_82598;
132 mac->ops.set_vlvf = NULL;
133 mac->ops.clear_vfta = &ixgbe_clear_vfta_82598;
136 mac->ops.fc_enable = &ixgbe_fc_enable_82598;
138 mac->mcft_size = 128;
140 mac->num_rar_entries = 16;
141 mac->rx_pb_size = 512;
142 mac->max_tx_queues = 32;
143 mac->max_rx_queues = 64;
144 mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
147 phy->ops.read_i2c_eeprom = &ixgbe_read_i2c_eeprom_82598;
150 mac->ops.check_link = &ixgbe_check_mac_link_82598;
151 mac->ops.setup_link = &ixgbe_setup_mac_link_82598;
152 mac->ops.flap_tx_laser = NULL;
153 mac->ops.get_link_capabilities = &ixgbe_get_link_capabilities_82598;
154 mac->ops.setup_rxpba = &ixgbe_set_rxpba_82598;
156 /* Manageability interface */
157 mac->ops.set_fw_drv_ver = NULL;
163 * ixgbe_init_phy_ops_82598 - PHY/SFP specific init
164 * @hw: pointer to hardware structure
166 * Initialize any function pointers that were not able to be
167 * set during init_shared_code because the PHY/SFP type was
168 * not known. Perform the SFP init if necessary.
171 s32 ixgbe_init_phy_ops_82598(struct ixgbe_hw *hw)
173 struct ixgbe_mac_info *mac = &hw->mac;
174 struct ixgbe_phy_info *phy = &hw->phy;
176 u16 list_offset, data_offset;
178 /* Identify the PHY */
179 phy->ops.identify(hw);
181 /* Overwrite the link function pointers if copper PHY */
182 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper) {
183 mac->ops.setup_link = &ixgbe_setup_copper_link_82598;
184 mac->ops.get_link_capabilities =
185 &ixgbe_get_copper_link_capabilities_generic;
188 switch (hw->phy.type) {
190 phy->ops.setup_link = &ixgbe_setup_phy_link_tnx;
191 phy->ops.check_link = &ixgbe_check_phy_link_tnx;
192 phy->ops.get_firmware_version =
193 &ixgbe_get_phy_firmware_version_tnx;
196 phy->ops.reset = &ixgbe_reset_phy_nl;
198 /* Call SFP+ identify routine to get the SFP+ module type */
199 ret_val = phy->ops.identify_sfp(hw);
202 else if (hw->phy.sfp_type == ixgbe_sfp_type_unknown) {
203 ret_val = IXGBE_ERR_SFP_NOT_SUPPORTED;
207 /* Check to see if SFP+ module is supported */
208 ret_val = ixgbe_get_sfp_init_sequence_offsets(hw,
212 ret_val = IXGBE_ERR_SFP_NOT_SUPPORTED;
225 * ixgbe_start_hw_82598 - Prepare hardware for Tx/Rx
226 * @hw: pointer to hardware structure
228 * Starts the hardware using the generic start_hw function.
229 * Disables relaxed ordering Then set pcie completion timeout
232 s32 ixgbe_start_hw_82598(struct ixgbe_hw *hw)
238 ret_val = ixgbe_start_hw_generic(hw);
240 /* Disable relaxed ordering */
241 for (i = 0; ((i < hw->mac.max_tx_queues) &&
242 (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
243 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(i));
244 regval &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
245 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(i), regval);
248 for (i = 0; ((i < hw->mac.max_rx_queues) &&
249 (i < IXGBE_DCA_MAX_QUEUES_82598)); i++) {
250 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
251 regval &= ~(IXGBE_DCA_RXCTRL_DATA_WRO_EN |
252 IXGBE_DCA_RXCTRL_HEAD_WRO_EN);
253 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
256 /* set the completion timeout for interface */
258 ixgbe_set_pcie_completion_timeout(hw);
264 * ixgbe_get_link_capabilities_82598 - Determines link capabilities
265 * @hw: pointer to hardware structure
266 * @speed: pointer to link speed
267 * @autoneg: boolean auto-negotiation value
269 * Determines the link capabilities by reading the AUTOC register.
271 static s32 ixgbe_get_link_capabilities_82598(struct ixgbe_hw *hw,
272 ixgbe_link_speed *speed,
279 * Determine link capabilities based on the stored value of AUTOC,
280 * which represents EEPROM defaults. If AUTOC value has not been
281 * stored, use the current register value.
283 if (hw->mac.orig_link_settings_stored)
284 autoc = hw->mac.orig_autoc;
286 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
288 switch (autoc & IXGBE_AUTOC_LMS_MASK) {
289 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
290 *speed = IXGBE_LINK_SPEED_1GB_FULL;
294 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
295 *speed = IXGBE_LINK_SPEED_10GB_FULL;
299 case IXGBE_AUTOC_LMS_1G_AN:
300 *speed = IXGBE_LINK_SPEED_1GB_FULL;
304 case IXGBE_AUTOC_LMS_KX4_AN:
305 case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
306 *speed = IXGBE_LINK_SPEED_UNKNOWN;
307 if (autoc & IXGBE_AUTOC_KX4_SUPP)
308 *speed |= IXGBE_LINK_SPEED_10GB_FULL;
309 if (autoc & IXGBE_AUTOC_KX_SUPP)
310 *speed |= IXGBE_LINK_SPEED_1GB_FULL;
315 status = IXGBE_ERR_LINK_SETUP;
323 * ixgbe_get_media_type_82598 - Determines media type
324 * @hw: pointer to hardware structure
326 * Returns the media type (fiber, copper, backplane)
328 static enum ixgbe_media_type ixgbe_get_media_type_82598(struct ixgbe_hw *hw)
330 enum ixgbe_media_type media_type;
332 /* Detect if there is a copper PHY attached. */
333 switch (hw->phy.type) {
334 case ixgbe_phy_cu_unknown:
336 media_type = ixgbe_media_type_copper;
342 /* Media type for I82598 is based on device ID */
343 switch (hw->device_id) {
344 case IXGBE_DEV_ID_82598:
345 case IXGBE_DEV_ID_82598_BX:
346 /* Default device ID is mezzanine card KX/KX4 */
347 media_type = ixgbe_media_type_backplane;
349 case IXGBE_DEV_ID_82598AF_DUAL_PORT:
350 case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
351 case IXGBE_DEV_ID_82598_DA_DUAL_PORT:
352 case IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM:
353 case IXGBE_DEV_ID_82598EB_XF_LR:
354 case IXGBE_DEV_ID_82598EB_SFP_LOM:
355 media_type = ixgbe_media_type_fiber;
357 case IXGBE_DEV_ID_82598EB_CX4:
358 case IXGBE_DEV_ID_82598_CX4_DUAL_PORT:
359 media_type = ixgbe_media_type_cx4;
361 case IXGBE_DEV_ID_82598AT:
362 case IXGBE_DEV_ID_82598AT2:
363 media_type = ixgbe_media_type_copper;
366 media_type = ixgbe_media_type_unknown;
374 * ixgbe_fc_enable_82598 - Enable flow control
375 * @hw: pointer to hardware structure
377 * Enable flow control according to the current settings.
379 s32 ixgbe_fc_enable_82598(struct ixgbe_hw *hw)
390 /* Validate the water mark configuration */
391 if (!hw->fc.pause_time) {
392 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
396 /* Low water mark of zero causes XOFF floods */
397 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
398 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
399 hw->fc.high_water[i]) {
400 if (!hw->fc.low_water[i] ||
401 hw->fc.low_water[i] >= hw->fc.high_water[i]) {
402 hw_dbg(hw, "Invalid water mark configuration\n");
403 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
410 * On 82598 having Rx FC on causes resets while doing 1G
411 * so if it's on turn it off once we know link_speed. For
412 * more details see 82598 Specification update.
414 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
415 if (link_up && link_speed == IXGBE_LINK_SPEED_1GB_FULL) {
416 switch (hw->fc.requested_mode) {
418 hw->fc.requested_mode = ixgbe_fc_tx_pause;
420 case ixgbe_fc_rx_pause:
421 hw->fc.requested_mode = ixgbe_fc_none;
429 /* Negotiate the fc mode to use */
430 ixgbe_fc_autoneg(hw);
432 /* Disable any previous flow control settings */
433 fctrl_reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
434 fctrl_reg &= ~(IXGBE_FCTRL_RFCE | IXGBE_FCTRL_RPFCE);
436 rmcs_reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
437 rmcs_reg &= ~(IXGBE_RMCS_TFCE_PRIORITY | IXGBE_RMCS_TFCE_802_3X);
440 * The possible values of fc.current_mode are:
441 * 0: Flow control is completely disabled
442 * 1: Rx flow control is enabled (we can receive pause frames,
443 * but not send pause frames).
444 * 2: Tx flow control is enabled (we can send pause frames but
445 * we do not support receiving pause frames).
446 * 3: Both Rx and Tx flow control (symmetric) are enabled.
449 switch (hw->fc.current_mode) {
452 * Flow control is disabled by software override or autoneg.
453 * The code below will actually disable it in the HW.
456 case ixgbe_fc_rx_pause:
458 * Rx Flow control is enabled and Tx Flow control is
459 * disabled by software override. Since there really
460 * isn't a way to advertise that we are capable of RX
461 * Pause ONLY, we will advertise that we support both
462 * symmetric and asymmetric Rx PAUSE. Later, we will
463 * disable the adapter's ability to send PAUSE frames.
465 fctrl_reg |= IXGBE_FCTRL_RFCE;
467 case ixgbe_fc_tx_pause:
469 * Tx Flow control is enabled, and Rx Flow control is
470 * disabled by software override.
472 rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
475 /* Flow control (both Rx and Tx) is enabled by SW override. */
476 fctrl_reg |= IXGBE_FCTRL_RFCE;
477 rmcs_reg |= IXGBE_RMCS_TFCE_802_3X;
480 hw_dbg(hw, "Flow control param set incorrectly\n");
481 ret_val = IXGBE_ERR_CONFIG;
486 /* Set 802.3x based flow control settings. */
487 fctrl_reg |= IXGBE_FCTRL_DPF;
488 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl_reg);
489 IXGBE_WRITE_REG(hw, IXGBE_RMCS, rmcs_reg);
491 /* Set up and enable Rx high/low water mark thresholds, enable XON. */
492 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
493 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
494 hw->fc.high_water[i]) {
495 fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
496 fcrth = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
497 IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), fcrtl);
498 IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), fcrth);
500 IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), 0);
501 IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), 0);
506 /* Configure pause time (2 TCs per register) */
507 reg = hw->fc.pause_time * 0x00010001;
508 for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
509 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
511 /* Configure flow control refresh threshold value */
512 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
519 * ixgbe_start_mac_link_82598 - Configures MAC link settings
520 * @hw: pointer to hardware structure
522 * Configures link settings based on values in the ixgbe_hw struct.
523 * Restarts the link. Performs autonegotiation if needed.
525 static s32 ixgbe_start_mac_link_82598(struct ixgbe_hw *hw,
526 bool autoneg_wait_to_complete)
534 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
535 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
536 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
538 /* Only poll for autoneg to complete if specified to do so */
539 if (autoneg_wait_to_complete) {
540 if ((autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
541 IXGBE_AUTOC_LMS_KX4_AN ||
542 (autoc_reg & IXGBE_AUTOC_LMS_MASK) ==
543 IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
544 links_reg = 0; /* Just in case Autoneg time = 0 */
545 for (i = 0; i < IXGBE_AUTO_NEG_TIME; i++) {
546 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
547 if (links_reg & IXGBE_LINKS_KX_AN_COMP)
551 if (!(links_reg & IXGBE_LINKS_KX_AN_COMP)) {
552 status = IXGBE_ERR_AUTONEG_NOT_COMPLETE;
553 hw_dbg(hw, "Autonegotiation did not complete.\n");
558 /* Add delay to filter out noises during initial link setup */
565 * ixgbe_validate_link_ready - Function looks for phy link
566 * @hw: pointer to hardware structure
568 * Function indicates success when phy link is available. If phy is not ready
569 * within 5 seconds of MAC indicating link, the function returns error.
571 static s32 ixgbe_validate_link_ready(struct ixgbe_hw *hw)
576 if (hw->device_id != IXGBE_DEV_ID_82598AT2)
580 timeout < IXGBE_VALIDATE_LINK_READY_TIMEOUT; timeout++) {
581 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
582 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &an_reg);
584 if ((an_reg & IXGBE_MII_AUTONEG_COMPLETE) &&
585 (an_reg & IXGBE_MII_AUTONEG_LINK_UP))
591 if (timeout == IXGBE_VALIDATE_LINK_READY_TIMEOUT) {
592 hw_dbg(hw, "Link was indicated but link is down\n");
593 return IXGBE_ERR_LINK_SETUP;
600 * ixgbe_check_mac_link_82598 - Get link/speed status
601 * @hw: pointer to hardware structure
602 * @speed: pointer to link speed
603 * @link_up: true is link is up, false otherwise
604 * @link_up_wait_to_complete: bool used to wait for link up or not
606 * Reads the links register to determine if link is up and the current speed
608 static s32 ixgbe_check_mac_link_82598(struct ixgbe_hw *hw,
609 ixgbe_link_speed *speed, bool *link_up,
610 bool link_up_wait_to_complete)
614 u16 link_reg, adapt_comp_reg;
617 * SERDES PHY requires us to read link status from undocumented
618 * register 0xC79F. Bit 0 set indicates link is up/ready; clear
619 * indicates link down. OxC00C is read to check that the XAUI lanes
620 * are active. Bit 0 clear indicates active; set indicates inactive.
622 if (hw->phy.type == ixgbe_phy_nl) {
623 hw->phy.ops.read_reg(hw, 0xC79F, IXGBE_TWINAX_DEV, &link_reg);
624 hw->phy.ops.read_reg(hw, 0xC79F, IXGBE_TWINAX_DEV, &link_reg);
625 hw->phy.ops.read_reg(hw, 0xC00C, IXGBE_TWINAX_DEV,
627 if (link_up_wait_to_complete) {
628 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
629 if ((link_reg & 1) &&
630 ((adapt_comp_reg & 1) == 0)) {
637 hw->phy.ops.read_reg(hw, 0xC79F,
640 hw->phy.ops.read_reg(hw, 0xC00C,
645 if ((link_reg & 1) && ((adapt_comp_reg & 1) == 0))
651 if (*link_up == false)
655 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
656 if (link_up_wait_to_complete) {
657 for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
658 if (links_reg & IXGBE_LINKS_UP) {
665 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
668 if (links_reg & IXGBE_LINKS_UP)
674 if (links_reg & IXGBE_LINKS_SPEED)
675 *speed = IXGBE_LINK_SPEED_10GB_FULL;
677 *speed = IXGBE_LINK_SPEED_1GB_FULL;
679 if ((hw->device_id == IXGBE_DEV_ID_82598AT2) && (*link_up == true) &&
680 (ixgbe_validate_link_ready(hw) != 0))
688 * ixgbe_setup_mac_link_82598 - Set MAC link speed
689 * @hw: pointer to hardware structure
690 * @speed: new link speed
691 * @autoneg: true if autonegotiation enabled
692 * @autoneg_wait_to_complete: true when waiting for completion is needed
694 * Set the link speed in the AUTOC register and restarts link.
696 static s32 ixgbe_setup_mac_link_82598(struct ixgbe_hw *hw,
697 ixgbe_link_speed speed, bool autoneg,
698 bool autoneg_wait_to_complete)
701 ixgbe_link_speed link_capabilities = IXGBE_LINK_SPEED_UNKNOWN;
702 u32 curr_autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
703 u32 autoc = curr_autoc;
704 u32 link_mode = autoc & IXGBE_AUTOC_LMS_MASK;
706 /* Check to see if speed passed in is supported. */
707 ixgbe_get_link_capabilities(hw, &link_capabilities, &autoneg);
708 speed &= link_capabilities;
710 if (speed == IXGBE_LINK_SPEED_UNKNOWN)
711 status = IXGBE_ERR_LINK_SETUP;
713 /* Set KX4/KX support according to speed requested */
714 else if (link_mode == IXGBE_AUTOC_LMS_KX4_AN ||
715 link_mode == IXGBE_AUTOC_LMS_KX4_AN_1G_AN) {
716 autoc &= ~IXGBE_AUTOC_KX4_KX_SUPP_MASK;
717 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
718 autoc |= IXGBE_AUTOC_KX4_SUPP;
719 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
720 autoc |= IXGBE_AUTOC_KX_SUPP;
721 if (autoc != curr_autoc)
722 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc);
727 * Setup and restart the link based on the new values in
728 * ixgbe_hw This will write the AUTOC register based on the new
731 status = ixgbe_start_mac_link_82598(hw,
732 autoneg_wait_to_complete);
740 * ixgbe_setup_copper_link_82598 - Set the PHY autoneg advertised field
741 * @hw: pointer to hardware structure
742 * @speed: new link speed
743 * @autoneg: true if autonegotiation enabled
744 * @autoneg_wait_to_complete: true if waiting is needed to complete
746 * Sets the link speed in the AUTOC register in the MAC and restarts link.
748 static s32 ixgbe_setup_copper_link_82598(struct ixgbe_hw *hw,
749 ixgbe_link_speed speed,
751 bool autoneg_wait_to_complete)
755 /* Setup the PHY according to input speed */
756 status = hw->phy.ops.setup_link_speed(hw, speed, autoneg,
757 autoneg_wait_to_complete);
759 ixgbe_start_mac_link_82598(hw, autoneg_wait_to_complete);
765 * ixgbe_reset_hw_82598 - Performs hardware reset
766 * @hw: pointer to hardware structure
768 * Resets the hardware by resetting the transmit and receive units, masks and
769 * clears all interrupts, performing a PHY reset, and performing a link (MAC)
772 static s32 ixgbe_reset_hw_82598(struct ixgbe_hw *hw)
782 /* Call adapter stop to disable tx/rx and clear interrupts */
783 status = hw->mac.ops.stop_adapter(hw);
788 * Power up the Atlas Tx lanes if they are currently powered down.
789 * Atlas Tx lanes are powered down for MAC loopback tests, but
790 * they are not automatically restored on reset.
792 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK, &analog_val);
793 if (analog_val & IXGBE_ATLAS_PDN_TX_REG_EN) {
794 /* Enable Tx Atlas so packets can be transmitted again */
795 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
797 analog_val &= ~IXGBE_ATLAS_PDN_TX_REG_EN;
798 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_LPBK,
801 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
803 analog_val &= ~IXGBE_ATLAS_PDN_TX_10G_QL_ALL;
804 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_10G,
807 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
809 analog_val &= ~IXGBE_ATLAS_PDN_TX_1G_QL_ALL;
810 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_1G,
813 hw->mac.ops.read_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
815 analog_val &= ~IXGBE_ATLAS_PDN_TX_AN_QL_ALL;
816 hw->mac.ops.write_analog_reg8(hw, IXGBE_ATLAS_PDN_AN,
821 if (hw->phy.reset_disable == false) {
822 /* PHY ops must be identified and initialized prior to reset */
824 /* Init PHY and function pointers, perform SFP setup */
825 phy_status = hw->phy.ops.init(hw);
826 if (phy_status == IXGBE_ERR_SFP_NOT_SUPPORTED)
828 if (phy_status == IXGBE_ERR_SFP_NOT_PRESENT)
831 hw->phy.ops.reset(hw);
836 * Issue global reset to the MAC. This needs to be a SW reset.
837 * If link reset is used, it might reset the MAC when mng is using it
839 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL) | IXGBE_CTRL_RST;
840 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
841 IXGBE_WRITE_FLUSH(hw);
843 /* Poll for reset bit to self-clear indicating reset is complete */
844 for (i = 0; i < 10; i++) {
846 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
847 if (!(ctrl & IXGBE_CTRL_RST))
850 if (ctrl & IXGBE_CTRL_RST) {
851 status = IXGBE_ERR_RESET_FAILED;
852 hw_dbg(hw, "Reset polling failed to complete.\n");
858 * Double resets are required for recovery from certain error
859 * conditions. Between resets, it is necessary to stall to allow time
860 * for any pending HW events to complete.
862 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
863 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
867 gheccr = IXGBE_READ_REG(hw, IXGBE_GHECCR);
868 gheccr &= ~((1 << 21) | (1 << 18) | (1 << 9) | (1 << 6));
869 IXGBE_WRITE_REG(hw, IXGBE_GHECCR, gheccr);
872 * Store the original AUTOC value if it has not been
873 * stored off yet. Otherwise restore the stored original
874 * AUTOC value since the reset operation sets back to deaults.
876 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
877 if (hw->mac.orig_link_settings_stored == false) {
878 hw->mac.orig_autoc = autoc;
879 hw->mac.orig_link_settings_stored = true;
880 } else if (autoc != hw->mac.orig_autoc) {
881 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, hw->mac.orig_autoc);
884 /* Store the permanent mac address */
885 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
888 * Store MAC address from RAR0, clear receive address registers, and
889 * clear the multicast table
891 hw->mac.ops.init_rx_addrs(hw);
901 * ixgbe_set_vmdq_82598 - Associate a VMDq set index with a rx address
902 * @hw: pointer to hardware struct
903 * @rar: receive address register index to associate with a VMDq index
904 * @vmdq: VMDq set index
906 s32 ixgbe_set_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
909 u32 rar_entries = hw->mac.num_rar_entries;
911 /* Make sure we are using a valid rar index range */
912 if (rar >= rar_entries) {
913 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
914 return IXGBE_ERR_INVALID_ARGUMENT;
917 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
918 rar_high &= ~IXGBE_RAH_VIND_MASK;
919 rar_high |= ((vmdq << IXGBE_RAH_VIND_SHIFT) & IXGBE_RAH_VIND_MASK);
920 IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
925 * ixgbe_clear_vmdq_82598 - Disassociate a VMDq set index from an rx address
926 * @hw: pointer to hardware struct
927 * @rar: receive address register index to associate with a VMDq index
928 * @vmdq: VMDq clear index (not used in 82598, but elsewhere)
930 static s32 ixgbe_clear_vmdq_82598(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
933 u32 rar_entries = hw->mac.num_rar_entries;
936 /* Make sure we are using a valid rar index range */
937 if (rar >= rar_entries) {
938 hw_dbg(hw, "RAR index %d is out of range.\n", rar);
939 return IXGBE_ERR_INVALID_ARGUMENT;
942 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
943 if (rar_high & IXGBE_RAH_VIND_MASK) {
944 rar_high &= ~IXGBE_RAH_VIND_MASK;
945 IXGBE_WRITE_REG(hw, IXGBE_RAH(rar), rar_high);
952 * ixgbe_set_vfta_82598 - Set VLAN filter table
953 * @hw: pointer to hardware structure
954 * @vlan: VLAN id to write to VLAN filter
955 * @vind: VMDq output index that maps queue to VLAN id in VFTA
956 * @vlan_on: boolean flag to turn on/off VLAN in VFTA
958 * Turn on/off specified VLAN in the VLAN filter table.
960 s32 ixgbe_set_vfta_82598(struct ixgbe_hw *hw, u32 vlan, u32 vind,
969 return IXGBE_ERR_PARAM;
971 /* Determine 32-bit word position in array */
972 regindex = (vlan >> 5) & 0x7F; /* upper seven bits */
974 /* Determine the location of the (VMD) queue index */
975 vftabyte = ((vlan >> 3) & 0x03); /* bits (4:3) indicating byte array */
976 bitindex = (vlan & 0x7) << 2; /* lower 3 bits indicate nibble */
978 /* Set the nibble for VMD queue index */
979 bits = IXGBE_READ_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex));
980 bits &= (~(0x0F << bitindex));
981 bits |= (vind << bitindex);
982 IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vftabyte, regindex), bits);
984 /* Determine the location of the bit for this VLAN id */
985 bitindex = vlan & 0x1F; /* lower five bits */
987 bits = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
989 /* Turn on this VLAN id */
990 bits |= (1 << bitindex);
992 /* Turn off this VLAN id */
993 bits &= ~(1 << bitindex);
994 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), bits);
1000 * ixgbe_clear_vfta_82598 - Clear VLAN filter table
1001 * @hw: pointer to hardware structure
1003 * Clears the VLAN filer table, and the VMDq index associated with the filter
1005 static s32 ixgbe_clear_vfta_82598(struct ixgbe_hw *hw)
1010 for (offset = 0; offset < hw->mac.vft_size; offset++)
1011 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
1013 for (vlanbyte = 0; vlanbyte < 4; vlanbyte++)
1014 for (offset = 0; offset < hw->mac.vft_size; offset++)
1015 IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vlanbyte, offset),
1022 * ixgbe_read_analog_reg8_82598 - Reads 8 bit Atlas analog register
1023 * @hw: pointer to hardware structure
1024 * @reg: analog register to read
1027 * Performs read operation to Atlas analog register specified.
1029 s32 ixgbe_read_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 *val)
1033 IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL,
1034 IXGBE_ATLASCTL_WRITE_CMD | (reg << 8));
1035 IXGBE_WRITE_FLUSH(hw);
1037 atlas_ctl = IXGBE_READ_REG(hw, IXGBE_ATLASCTL);
1038 *val = (u8)atlas_ctl;
1044 * ixgbe_write_analog_reg8_82598 - Writes 8 bit Atlas analog register
1045 * @hw: pointer to hardware structure
1046 * @reg: atlas register to write
1047 * @val: value to write
1049 * Performs write operation to Atlas analog register specified.
1051 s32 ixgbe_write_analog_reg8_82598(struct ixgbe_hw *hw, u32 reg, u8 val)
1055 atlas_ctl = (reg << 8) | val;
1056 IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, atlas_ctl);
1057 IXGBE_WRITE_FLUSH(hw);
1064 * ixgbe_read_i2c_eeprom_82598 - Reads 8 bit word over I2C interface.
1065 * @hw: pointer to hardware structure
1066 * @byte_offset: EEPROM byte offset to read
1067 * @eeprom_data: value read
1069 * Performs 8 byte read operation to SFP module's EEPROM over I2C interface.
1071 s32 ixgbe_read_i2c_eeprom_82598(struct ixgbe_hw *hw, u8 byte_offset,
1080 if (hw->phy.type == ixgbe_phy_nl) {
1082 * NetLogic phy SDA/SCL registers are at addresses 0xC30A to
1083 * 0xC30D. These registers are used to talk to the SFP+
1084 * module's EEPROM through the SDA/SCL (I2C) interface.
1086 sfp_addr = (IXGBE_I2C_EEPROM_DEV_ADDR << 8) + byte_offset;
1087 sfp_addr = (sfp_addr | IXGBE_I2C_EEPROM_READ_MASK);
1088 hw->phy.ops.write_reg(hw,
1089 IXGBE_MDIO_PMA_PMD_SDA_SCL_ADDR,
1090 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
1094 for (i = 0; i < 100; i++) {
1095 hw->phy.ops.read_reg(hw,
1096 IXGBE_MDIO_PMA_PMD_SDA_SCL_STAT,
1097 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
1099 sfp_stat = sfp_stat & IXGBE_I2C_EEPROM_STATUS_MASK;
1100 if (sfp_stat != IXGBE_I2C_EEPROM_STATUS_IN_PROGRESS)
1105 if (sfp_stat != IXGBE_I2C_EEPROM_STATUS_PASS) {
1106 hw_dbg(hw, "EEPROM read did not pass.\n");
1107 status = IXGBE_ERR_SFP_NOT_PRESENT;
1112 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_PMD_SDA_SCL_DATA,
1113 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &sfp_data);
1115 *eeprom_data = (u8)(sfp_data >> 8);
1117 status = IXGBE_ERR_PHY;
1126 * ixgbe_get_supported_physical_layer_82598 - Returns physical layer type
1127 * @hw: pointer to hardware structure
1129 * Determines physical layer capabilities of the current configuration.
1131 u32 ixgbe_get_supported_physical_layer_82598(struct ixgbe_hw *hw)
1133 u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
1134 u32 autoc = IXGBE_READ_REG(hw, IXGBE_AUTOC);
1135 u32 pma_pmd_10g = autoc & IXGBE_AUTOC_10G_PMA_PMD_MASK;
1136 u32 pma_pmd_1g = autoc & IXGBE_AUTOC_1G_PMA_PMD_MASK;
1137 u16 ext_ability = 0;
1139 hw->phy.ops.identify(hw);
1141 /* Copper PHY must be checked before AUTOC LMS to determine correct
1142 * physical layer because 10GBase-T PHYs use LMS = KX4/KX */
1143 switch (hw->phy.type) {
1145 case ixgbe_phy_cu_unknown:
1146 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
1147 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &ext_ability);
1148 if (ext_ability & IXGBE_MDIO_PHY_10GBASET_ABILITY)
1149 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
1150 if (ext_ability & IXGBE_MDIO_PHY_1000BASET_ABILITY)
1151 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
1152 if (ext_ability & IXGBE_MDIO_PHY_100BASETX_ABILITY)
1153 physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
1159 switch (autoc & IXGBE_AUTOC_LMS_MASK) {
1160 case IXGBE_AUTOC_LMS_1G_AN:
1161 case IXGBE_AUTOC_LMS_1G_LINK_NO_AN:
1162 if (pma_pmd_1g == IXGBE_AUTOC_1G_KX)
1163 physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_KX;
1165 physical_layer = IXGBE_PHYSICAL_LAYER_1000BASE_BX;
1167 case IXGBE_AUTOC_LMS_10G_LINK_NO_AN:
1168 if (pma_pmd_10g == IXGBE_AUTOC_10G_CX4)
1169 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_CX4;
1170 else if (pma_pmd_10g == IXGBE_AUTOC_10G_KX4)
1171 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
1173 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
1175 case IXGBE_AUTOC_LMS_KX4_AN:
1176 case IXGBE_AUTOC_LMS_KX4_AN_1G_AN:
1177 if (autoc & IXGBE_AUTOC_KX_SUPP)
1178 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_KX;
1179 if (autoc & IXGBE_AUTOC_KX4_SUPP)
1180 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_KX4;
1186 if (hw->phy.type == ixgbe_phy_nl) {
1187 hw->phy.ops.identify_sfp(hw);
1189 switch (hw->phy.sfp_type) {
1190 case ixgbe_sfp_type_da_cu:
1191 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
1193 case ixgbe_sfp_type_sr:
1194 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
1196 case ixgbe_sfp_type_lr:
1197 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
1200 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
1205 switch (hw->device_id) {
1206 case IXGBE_DEV_ID_82598_DA_DUAL_PORT:
1207 physical_layer = IXGBE_PHYSICAL_LAYER_SFP_PLUS_CU;
1209 case IXGBE_DEV_ID_82598AF_DUAL_PORT:
1210 case IXGBE_DEV_ID_82598AF_SINGLE_PORT:
1211 case IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM:
1212 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_SR;
1214 case IXGBE_DEV_ID_82598EB_XF_LR:
1215 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_LR;
1222 return physical_layer;
1226 * ixgbe_set_lan_id_multi_port_pcie_82598 - Set LAN id for PCIe multiple
1228 * @hw: pointer to the HW structure
1230 * Calls common function and corrects issue with some single port devices
1231 * that enable LAN1 but not LAN0.
1233 void ixgbe_set_lan_id_multi_port_pcie_82598(struct ixgbe_hw *hw)
1235 struct ixgbe_bus_info *bus = &hw->bus;
1239 ixgbe_set_lan_id_multi_port_pcie(hw);
1241 /* check if LAN0 is disabled */
1242 hw->eeprom.ops.read(hw, IXGBE_PCIE_GENERAL_PTR, &pci_gen);
1243 if ((pci_gen != 0) && (pci_gen != 0xFFFF)) {
1245 hw->eeprom.ops.read(hw, pci_gen + IXGBE_PCIE_CTRL2, &pci_ctrl2);
1247 /* if LAN0 is completely disabled force function to 0 */
1248 if ((pci_ctrl2 & IXGBE_PCIE_CTRL2_LAN_DISABLE) &&
1249 !(pci_ctrl2 & IXGBE_PCIE_CTRL2_DISABLE_SELECT) &&
1250 !(pci_ctrl2 & IXGBE_PCIE_CTRL2_DUMMY_ENABLE)) {
1258 * ixgbe_set_rxpba_82598 - Initialize RX packet buffer
1259 * @hw: pointer to hardware structure
1260 * @num_pb: number of packet buffers to allocate
1261 * @headroom: reserve n KB of headroom
1262 * @strategy: packet buffer allocation strategy
1264 static void ixgbe_set_rxpba_82598(struct ixgbe_hw *hw, int num_pb,
1265 u32 headroom, int strategy)
1267 u32 rxpktsize = IXGBE_RXPBSIZE_64KB;
1273 /* Setup Rx packet buffer sizes */
1275 case PBA_STRATEGY_WEIGHTED:
1276 /* Setup the first four at 80KB */
1277 rxpktsize = IXGBE_RXPBSIZE_80KB;
1279 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
1280 /* Setup the last four at 48KB...don't re-init i */
1281 rxpktsize = IXGBE_RXPBSIZE_48KB;
1283 case PBA_STRATEGY_EQUAL:
1285 /* Divide the remaining Rx packet buffer evenly among the TCs */
1286 for (; i < IXGBE_MAX_PACKET_BUFFERS; i++)
1287 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
1291 /* Setup Tx packet buffer sizes */
1292 for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++)
1293 IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), IXGBE_TXPBSIZE_40KB);