net/ngbe: fix external PHY power down
[dpdk.git] / drivers / net / ngbe / base / ngbe_hw.c
index 541d916..fa2d749 100644 (file)
@@ -18,7 +18,7 @@
  **/
 s32 ngbe_start_hw(struct ngbe_hw *hw)
 {
-       DEBUGFUNC("ngbe_start_hw");
+       s32 err;
 
        /* Clear the VLAN filter table */
        hw->mac.clear_vfta(hw);
@@ -26,6 +26,13 @@ s32 ngbe_start_hw(struct ngbe_hw *hw)
        /* Clear statistics registers */
        hw->mac.clear_hw_cntrs(hw);
 
+       /* Setup flow control */
+       err = hw->mac.setup_fc(hw);
+       if (err != 0 && err != NGBE_NOT_IMPLEMENTED) {
+               DEBUGOUT("Flow control setup failed, returning %d", err);
+               return err;
+       }
+
        /* Clear adapter stopped flag */
        hw->adapter_stopped = false;
 
@@ -46,8 +53,6 @@ s32 ngbe_init_hw(struct ngbe_hw *hw)
 {
        s32 status;
 
-       DEBUGFUNC("ngbe_init_hw");
-
        ngbe_save_eeprom_version(hw);
 
        /* Reset the hardware */
@@ -58,7 +63,7 @@ s32 ngbe_init_hw(struct ngbe_hw *hw)
        }
 
        if (status != 0)
-               DEBUGOUT("Failed to initialize HW, STATUS = %d\n", status);
+               DEBUGOUT("Failed to initialize HW, STATUS = %d", status);
 
        return status;
 }
@@ -115,8 +120,7 @@ ngbe_reset_misc_em(struct ngbe_hw *hw)
 
        wr32m(hw, NGBE_GPIE, NGBE_GPIE_MSIX, NGBE_GPIE_MSIX);
 
-       if ((hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_M88E1512_SFP ||
-               (hw->sub_system_id & NGBE_OEM_MASK) == NGBE_LY_YT8521S_SFP) {
+       if (hw->gpio_ctl) {
                /* gpio0 is used to power on/off control*/
                wr32(hw, NGBE_GPIODIR, NGBE_GPIODIR_DDR(1));
                wr32(hw, NGBE_GPIODATA, NGBE_GPIOBIT_0);
@@ -147,8 +151,6 @@ s32 ngbe_reset_hw_em(struct ngbe_hw *hw)
 {
        s32 status;
 
-       DEBUGFUNC("ngbe_reset_hw_em");
-
        /* Call adapter stop to disable tx/rx and clear interrupts */
        status = hw->mac.stop_hw(hw);
        if (status != 0)
@@ -196,8 +198,6 @@ s32 ngbe_clear_hw_cntrs(struct ngbe_hw *hw)
 {
        u16 i = 0;
 
-       DEBUGFUNC("ngbe_clear_hw_cntrs");
-
        /* QP Stats */
        /* don't write clear queue stats */
        for (i = 0; i < NGBE_MAX_QP; i++) {
@@ -296,8 +296,6 @@ s32 ngbe_get_mac_addr(struct ngbe_hw *hw, u8 *mac_addr)
        u32 rar_low;
        u16 i;
 
-       DEBUGFUNC("ngbe_get_mac_addr");
-
        wr32(hw, NGBE_ETHADDRIDX, 0);
        rar_high = rd32(hw, NGBE_ETHADDRH);
        rar_low = rd32(hw, NGBE_ETHADDRL);
@@ -323,8 +321,6 @@ void ngbe_set_lan_id_multi_port(struct ngbe_hw *hw)
        struct ngbe_bus_info *bus = &hw->bus;
        u32 reg = 0;
 
-       DEBUGFUNC("ngbe_set_lan_id_multi_port");
-
        reg = rd32(hw, NGBE_PORTSTAT);
        bus->lan_id = NGBE_PORTSTAT_ID(reg);
        bus->func = bus->lan_id;
@@ -341,10 +337,8 @@ void ngbe_set_lan_id_multi_port(struct ngbe_hw *hw)
  **/
 s32 ngbe_stop_hw(struct ngbe_hw *hw)
 {
-       u32 reg_val;
        u16 i;
-
-       DEBUGFUNC("ngbe_stop_hw");
+       s32 status = 0;
 
        /*
         * Set the adapter_stopped flag so other driver functions stop touching
@@ -363,21 +357,72 @@ s32 ngbe_stop_hw(struct ngbe_hw *hw)
        wr32(hw, NGBE_ICRMISC, NGBE_ICRMISC_MASK);
        wr32(hw, NGBE_ICR(0), NGBE_ICR_MASK);
 
-       /* Disable the transmit unit.  Each queue must be disabled. */
-       for (i = 0; i < hw->mac.max_tx_queues; i++)
-               wr32(hw, NGBE_TXCFG(i), NGBE_TXCFG_FLUSH);
+       wr32(hw, NGBE_BMECTL, 0x3);
 
        /* Disable the receive unit by stopping each queue */
-       for (i = 0; i < hw->mac.max_rx_queues; i++) {
-               reg_val = rd32(hw, NGBE_RXCFG(i));
-               reg_val &= ~NGBE_RXCFG_ENA;
-               wr32(hw, NGBE_RXCFG(i), reg_val);
-       }
+       for (i = 0; i < hw->mac.max_rx_queues; i++)
+               wr32(hw, NGBE_RXCFG(i), 0);
 
        /* flush all queues disables */
        ngbe_flush(hw);
        msec_delay(2);
 
+       /*
+        * Prevent the PCI-E bus from hanging by disabling PCI-E master
+        * access and verify no pending requests
+        */
+       status = ngbe_set_pcie_master(hw, false);
+       if (status)
+               return status;
+
+       /* Disable the transmit unit.  Each queue must be disabled. */
+       for (i = 0; i < hw->mac.max_tx_queues; i++)
+               wr32(hw, NGBE_TXCFG(i), 0);
+
+       /* flush all queues disables */
+       ngbe_flush(hw);
+       msec_delay(2);
+
+       return 0;
+}
+
+/**
+ *  ngbe_led_on - Turns on the software controllable LEDs.
+ *  @hw: pointer to hardware structure
+ *  @index: led number to turn on
+ **/
+s32 ngbe_led_on(struct ngbe_hw *hw, u32 index)
+{
+       u32 led_reg = rd32(hw, NGBE_LEDCTL);
+
+       if (index > 3)
+               return NGBE_ERR_PARAM;
+
+       /* To turn on the LED, set mode to ON. */
+       led_reg |= NGBE_LEDCTL_100M;
+       wr32(hw, NGBE_LEDCTL, led_reg);
+       ngbe_flush(hw);
+
+       return 0;
+}
+
+/**
+ *  ngbe_led_off - Turns off the software controllable LEDs.
+ *  @hw: pointer to hardware structure
+ *  @index: led number to turn off
+ **/
+s32 ngbe_led_off(struct ngbe_hw *hw, u32 index)
+{
+       u32 led_reg = rd32(hw, NGBE_LEDCTL);
+
+       if (index > 3)
+               return NGBE_ERR_PARAM;
+
+       /* To turn off the LED, set mode to OFF. */
+       led_reg &= ~NGBE_LEDCTL_100M;
+       wr32(hw, NGBE_LEDCTL, led_reg);
+       ngbe_flush(hw);
+
        return 0;
 }
 
@@ -391,8 +436,6 @@ s32 ngbe_validate_mac_addr(u8 *mac_addr)
 {
        s32 status = 0;
 
-       DEBUGFUNC("ngbe_validate_mac_addr");
-
        /* Make sure it is not a multicast address */
        if (NGBE_IS_MULTICAST((struct rte_ether_addr *)mac_addr)) {
                status = NGBE_ERR_INVALID_MAC_ADDR;
@@ -423,11 +466,9 @@ s32 ngbe_set_rar(struct ngbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
        u32 rar_low, rar_high;
        u32 rar_entries = hw->mac.num_rar_entries;
 
-       DEBUGFUNC("ngbe_set_rar");
-
        /* Make sure we are using a valid rar index range */
        if (index >= rar_entries) {
-               DEBUGOUT("RAR index %d is out of range.\n", index);
+               DEBUGOUT("RAR index %d is out of range.", index);
                return NGBE_ERR_INVALID_ARGUMENT;
        }
 
@@ -475,11 +516,9 @@ s32 ngbe_clear_rar(struct ngbe_hw *hw, u32 index)
        u32 rar_high;
        u32 rar_entries = hw->mac.num_rar_entries;
 
-       DEBUGFUNC("ngbe_clear_rar");
-
        /* Make sure we are using a valid rar index range */
        if (index >= rar_entries) {
-               DEBUGOUT("RAR index %d is out of range.\n", index);
+               DEBUGOUT("RAR index %d is out of range.", index);
                return NGBE_ERR_INVALID_ARGUMENT;
        }
 
@@ -515,8 +554,6 @@ s32 ngbe_init_rx_addrs(struct ngbe_hw *hw)
        u32 psrctl;
        u32 rar_entries = hw->mac.num_rar_entries;
 
-       DEBUGFUNC("ngbe_init_rx_addrs");
-
        /*
         * If the current mac address is valid, assume it is a software override
         * to the permanent address.
@@ -527,18 +564,18 @@ s32 ngbe_init_rx_addrs(struct ngbe_hw *hw)
                /* Get the MAC address from the RAR0 for later reference */
                hw->mac.get_mac_addr(hw, hw->mac.addr);
 
-               DEBUGOUT(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
+               DEBUGOUT(" Keeping Current RAR0 Addr = "
+                         RTE_ETHER_ADDR_PRT_FMT,
                          hw->mac.addr[0], hw->mac.addr[1],
-                         hw->mac.addr[2]);
-               DEBUGOUT("%.2X %.2X %.2X\n", hw->mac.addr[3],
+                         hw->mac.addr[2], hw->mac.addr[3],
                          hw->mac.addr[4], hw->mac.addr[5]);
        } else {
                /* Setup the receive address. */
-               DEBUGOUT("Overriding MAC Address in RAR[0]\n");
-               DEBUGOUT(" New MAC Addr =%.2X %.2X %.2X ",
+               DEBUGOUT("Overriding MAC Address in RAR[0]");
+               DEBUGOUT(" New MAC Addr = "
+                         RTE_ETHER_ADDR_PRT_FMT,
                          hw->mac.addr[0], hw->mac.addr[1],
-                         hw->mac.addr[2]);
-               DEBUGOUT("%.2X %.2X %.2X\n", hw->mac.addr[3],
+                         hw->mac.addr[2], hw->mac.addr[3],
                          hw->mac.addr[4], hw->mac.addr[5]);
 
                hw->mac.set_rar(hw, 0, hw->mac.addr, 0, true);
@@ -548,7 +585,7 @@ s32 ngbe_init_rx_addrs(struct ngbe_hw *hw)
        hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
 
        /* Zero out the other receive addresses. */
-       DEBUGOUT("Clearing RAR[1-%d]\n", rar_entries - 1);
+       DEBUGOUT("Clearing RAR[1-%d]", rar_entries - 1);
        for (i = 1; i < rar_entries; i++) {
                wr32(hw, NGBE_ETHADDRIDX, i);
                wr32(hw, NGBE_ETHADDRL, 0);
@@ -562,7 +599,7 @@ s32 ngbe_init_rx_addrs(struct ngbe_hw *hw)
        psrctl |= NGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
        wr32(hw, NGBE_PSRCTL, psrctl);
 
-       DEBUGOUT(" Clearing MTA\n");
+       DEBUGOUT(" Clearing MTA");
        for (i = 0; i < hw->mac.mcft_size; i++)
                wr32(hw, NGBE_MCADDRTBL(i), 0);
 
@@ -587,8 +624,6 @@ static s32 ngbe_mta_vector(struct ngbe_hw *hw, u8 *mc_addr)
 {
        u32 vector = 0;
 
-       DEBUGFUNC("ngbe_mta_vector");
-
        switch (hw->mac.mc_filter_type) {
        case 0:   /* use bits [47:36] of the address */
                vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
@@ -603,7 +638,7 @@ static s32 ngbe_mta_vector(struct ngbe_hw *hw, u8 *mc_addr)
                vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
                break;
        default:  /* Invalid mc_filter_type */
-               DEBUGOUT("MC filter type param set incorrectly\n");
+               DEBUGOUT("MC filter type param set incorrectly");
                ASSERT(0);
                break;
        }
@@ -626,12 +661,10 @@ void ngbe_set_mta(struct ngbe_hw *hw, u8 *mc_addr)
        u32 vector_bit;
        u32 vector_reg;
 
-       DEBUGFUNC("ngbe_set_mta");
-
        hw->addr_ctrl.mta_in_use++;
 
        vector = ngbe_mta_vector(hw, mc_addr);
-       DEBUGOUT(" bit-vector = 0x%03X\n", vector);
+       DEBUGOUT(" bit-vector = 0x%03X", vector);
 
        /*
         * The MTA is a register array of 128 32-bit registers. It is treated
@@ -665,8 +698,6 @@ s32 ngbe_update_mc_addr_list(struct ngbe_hw *hw, u8 *mc_addr_list,
        u32 i;
        u32 vmdq;
 
-       DEBUGFUNC("ngbe_update_mc_addr_list");
-
        /*
         * Set the new number of MC addresses that we are being requested to
         * use.
@@ -676,13 +707,13 @@ s32 ngbe_update_mc_addr_list(struct ngbe_hw *hw, u8 *mc_addr_list,
 
        /* Clear mta_shadow */
        if (clear) {
-               DEBUGOUT(" Clearing MTA\n");
+               DEBUGOUT(" Clearing MTA");
                memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
        }
 
        /* Update mta_shadow */
        for (i = 0; i < mc_addr_count; i++) {
-               DEBUGOUT(" Adding the multicast addresses:\n");
+               DEBUGOUT(" Adding the multicast addresses:");
                ngbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
        }
 
@@ -699,10 +730,368 @@ s32 ngbe_update_mc_addr_list(struct ngbe_hw *hw, u8 *mc_addr_list,
                wr32(hw, NGBE_PSRCTL, psrctl);
        }
 
-       DEBUGOUT("ngbe update mc addr list complete\n");
+       DEBUGOUT("ngbe update mc addr list complete");
+       return 0;
+}
+
+/**
+ *  ngbe_setup_fc_em - Set up flow control
+ *  @hw: pointer to hardware structure
+ *
+ *  Called at init time to set up flow control.
+ **/
+s32 ngbe_setup_fc_em(struct ngbe_hw *hw)
+{
+       s32 err = 0;
+       u16 reg_cu = 0;
+
+       /* Validate the requested mode */
+       if (hw->fc.strict_ieee && hw->fc.requested_mode == ngbe_fc_rx_pause) {
+               DEBUGOUT("ngbe_fc_rx_pause not valid in strict IEEE mode");
+               err = NGBE_ERR_INVALID_LINK_SETTINGS;
+               goto out;
+       }
+
+       /*
+        * 1gig parts do not have a word in the EEPROM to determine the
+        * default flow control setting, so we explicitly set it to full.
+        */
+       if (hw->fc.requested_mode == ngbe_fc_default)
+               hw->fc.requested_mode = ngbe_fc_full;
+
+       /*
+        * The possible values of fc.requested_mode are:
+        * 0: Flow control is completely disabled
+        * 1: Rx flow control is enabled (we can receive pause frames,
+        *    but not send pause frames).
+        * 2: Tx flow control is enabled (we can send pause frames but
+        *    we do not support receiving pause frames).
+        * 3: Both Rx and Tx flow control (symmetric) are enabled.
+        * other: Invalid.
+        */
+       switch (hw->fc.requested_mode) {
+       case ngbe_fc_none:
+               /* Flow control completely disabled by software override. */
+               break;
+       case ngbe_fc_tx_pause:
+               /*
+                * Tx Flow control is enabled, and Rx Flow control is
+                * disabled by software override.
+                */
+               if (hw->phy.type == ngbe_phy_mvl_sfi ||
+                       hw->phy.type == ngbe_phy_yt8521s_sfi)
+                       reg_cu |= MVL_FANA_ASM_PAUSE;
+               else
+                       reg_cu |= 0x800; /*need to merge rtl and mvl on page 0*/
+               break;
+       case ngbe_fc_rx_pause:
+               /*
+                * Rx Flow control is enabled and Tx Flow control is
+                * disabled by software override. Since there really
+                * isn't a way to advertise that we are capable of RX
+                * Pause ONLY, we will advertise that we support both
+                * symmetric and asymmetric Rx PAUSE, as such we fall
+                * through to the fc_full statement.  Later, we will
+                * disable the adapter's ability to send PAUSE frames.
+                */
+       case ngbe_fc_full:
+               /* Flow control (both Rx and Tx) is enabled by SW override. */
+               if (hw->phy.type == ngbe_phy_mvl_sfi ||
+                       hw->phy.type == ngbe_phy_yt8521s_sfi)
+                       reg_cu |= MVL_FANA_SYM_PAUSE;
+               else
+                       reg_cu |= 0xC00; /*need to merge rtl and mvl on page 0*/
+               break;
+       default:
+               DEBUGOUT("Flow control param set incorrectly");
+               err = NGBE_ERR_CONFIG;
+               goto out;
+       }
+
+       err = hw->phy.set_pause_adv(hw, reg_cu);
+
+out:
+       return err;
+}
+
+/**
+ *  ngbe_fc_enable - Enable flow control
+ *  @hw: pointer to hardware structure
+ *
+ *  Enable flow control according to the current settings.
+ **/
+s32 ngbe_fc_enable(struct ngbe_hw *hw)
+{
+       s32 err = 0;
+       u32 mflcn_reg, fccfg_reg;
+       u32 pause_time;
+       u32 fcrtl, fcrth;
+
+       /* Validate the water mark configuration */
+       if (!hw->fc.pause_time) {
+               err = NGBE_ERR_INVALID_LINK_SETTINGS;
+               goto out;
+       }
+
+       /* Low water mark of zero causes XOFF floods */
+       if ((hw->fc.current_mode & ngbe_fc_tx_pause) && hw->fc.high_water) {
+               if (!hw->fc.low_water ||
+                       hw->fc.low_water >= hw->fc.high_water) {
+                       DEBUGOUT("Invalid water mark configuration");
+                       err = NGBE_ERR_INVALID_LINK_SETTINGS;
+                       goto out;
+               }
+       }
+
+       /* Negotiate the fc mode to use */
+       hw->mac.fc_autoneg(hw);
+
+       /* Disable any previous flow control settings */
+       mflcn_reg = rd32(hw, NGBE_RXFCCFG);
+       mflcn_reg &= ~NGBE_RXFCCFG_FC;
+
+       fccfg_reg = rd32(hw, NGBE_TXFCCFG);
+       fccfg_reg &= ~NGBE_TXFCCFG_FC;
+       /*
+        * The possible values of fc.current_mode are:
+        * 0: Flow control is completely disabled
+        * 1: Rx flow control is enabled (we can receive pause frames,
+        *    but not send pause frames).
+        * 2: Tx flow control is enabled (we can send pause frames but
+        *    we do not support receiving pause frames).
+        * 3: Both Rx and Tx flow control (symmetric) are enabled.
+        * other: Invalid.
+        */
+       switch (hw->fc.current_mode) {
+       case ngbe_fc_none:
+               /*
+                * Flow control is disabled by software override or autoneg.
+                * The code below will actually disable it in the HW.
+                */
+               break;
+       case ngbe_fc_rx_pause:
+               /*
+                * Rx Flow control is enabled and Tx Flow control is
+                * disabled by software override. Since there really
+                * isn't a way to advertise that we are capable of RX
+                * Pause ONLY, we will advertise that we support both
+                * symmetric and asymmetric Rx PAUSE.  Later, we will
+                * disable the adapter's ability to send PAUSE frames.
+                */
+               mflcn_reg |= NGBE_RXFCCFG_FC;
+               break;
+       case ngbe_fc_tx_pause:
+               /*
+                * Tx Flow control is enabled, and Rx Flow control is
+                * disabled by software override.
+                */
+               fccfg_reg |= NGBE_TXFCCFG_FC;
+               break;
+       case ngbe_fc_full:
+               /* Flow control (both Rx and Tx) is enabled by SW override. */
+               mflcn_reg |= NGBE_RXFCCFG_FC;
+               fccfg_reg |= NGBE_TXFCCFG_FC;
+               break;
+       default:
+               DEBUGOUT("Flow control param set incorrectly");
+               err = NGBE_ERR_CONFIG;
+               goto out;
+       }
+
+       /* Set 802.3x based flow control settings. */
+       wr32(hw, NGBE_RXFCCFG, mflcn_reg);
+       wr32(hw, NGBE_TXFCCFG, fccfg_reg);
+
+       /* Set up and enable Rx high/low water mark thresholds, enable XON. */
+       if ((hw->fc.current_mode & ngbe_fc_tx_pause) &&
+               hw->fc.high_water) {
+               fcrtl = NGBE_FCWTRLO_TH(hw->fc.low_water) |
+                       NGBE_FCWTRLO_XON;
+               fcrth = NGBE_FCWTRHI_TH(hw->fc.high_water) |
+                       NGBE_FCWTRHI_XOFF;
+       } else {
+               /*
+                * In order to prevent Tx hangs when the internal Tx
+                * switch is enabled we must set the high water mark
+                * to the Rx packet buffer size - 24KB.  This allows
+                * the Tx switch to function even under heavy Rx
+                * workloads.
+                */
+               fcrtl = 0;
+               fcrth = rd32(hw, NGBE_PBRXSIZE) - 24576;
+       }
+       wr32(hw, NGBE_FCWTRLO, fcrtl);
+       wr32(hw, NGBE_FCWTRHI, fcrth);
+
+       /* Configure pause time */
+       pause_time = NGBE_RXFCFSH_TIME(hw->fc.pause_time);
+       wr32(hw, NGBE_FCXOFFTM, pause_time * 0x00010000);
+
+       /* Configure flow control refresh threshold value */
+       wr32(hw, NGBE_RXFCRFSH, hw->fc.pause_time / 2);
+
+out:
+       return err;
+}
+
+/**
+ *  ngbe_negotiate_fc - Negotiate flow control
+ *  @hw: pointer to hardware structure
+ *  @adv_reg: flow control advertised settings
+ *  @lp_reg: link partner's flow control settings
+ *  @adv_sym: symmetric pause bit in advertisement
+ *  @adv_asm: asymmetric pause bit in advertisement
+ *  @lp_sym: symmetric pause bit in link partner advertisement
+ *  @lp_asm: asymmetric pause bit in link partner advertisement
+ *
+ *  Find the intersection between advertised settings and link partner's
+ *  advertised settings
+ **/
+s32 ngbe_negotiate_fc(struct ngbe_hw *hw, u32 adv_reg, u32 lp_reg,
+                      u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
+{
+       if ((!(adv_reg)) ||  (!(lp_reg))) {
+               DEBUGOUT("Local or link partner's advertised flow control settings are NULL. Local: %x, link partner: %x",
+                             adv_reg, lp_reg);
+               return NGBE_ERR_FC_NOT_NEGOTIATED;
+       }
+
+       if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
+               /*
+                * Now we need to check if the user selected Rx ONLY
+                * of pause frames.  In this case, we had to advertise
+                * FULL flow control because we could not advertise RX
+                * ONLY. Hence, we must now check to see if we need to
+                * turn OFF the TRANSMISSION of PAUSE frames.
+                */
+               if (hw->fc.requested_mode == ngbe_fc_full) {
+                       hw->fc.current_mode = ngbe_fc_full;
+                       DEBUGOUT("Flow Control = FULL.");
+               } else {
+                       hw->fc.current_mode = ngbe_fc_rx_pause;
+                       DEBUGOUT("Flow Control=RX PAUSE frames only");
+               }
+       } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
+                  (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
+               hw->fc.current_mode = ngbe_fc_tx_pause;
+               DEBUGOUT("Flow Control = TX PAUSE frames only.");
+       } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
+                  !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
+               hw->fc.current_mode = ngbe_fc_rx_pause;
+               DEBUGOUT("Flow Control = RX PAUSE frames only.");
+       } else {
+               hw->fc.current_mode = ngbe_fc_none;
+               DEBUGOUT("Flow Control = NONE.");
+       }
        return 0;
 }
 
+/**
+ *  ngbe_fc_autoneg_em - Enable flow control IEEE clause 37
+ *  @hw: pointer to hardware structure
+ *
+ *  Enable flow control according to IEEE clause 37.
+ **/
+STATIC s32 ngbe_fc_autoneg_em(struct ngbe_hw *hw)
+{
+       u8 technology_ability_reg = 0;
+       u8 lp_technology_ability_reg = 0;
+
+       hw->phy.get_adv_pause(hw, &technology_ability_reg);
+       hw->phy.get_lp_adv_pause(hw, &lp_technology_ability_reg);
+
+       return ngbe_negotiate_fc(hw, (u32)technology_ability_reg,
+                                 (u32)lp_technology_ability_reg,
+                                 NGBE_TAF_SYM_PAUSE, NGBE_TAF_ASM_PAUSE,
+                                 NGBE_TAF_SYM_PAUSE, NGBE_TAF_ASM_PAUSE);
+}
+
+/**
+ *  ngbe_fc_autoneg - Configure flow control
+ *  @hw: pointer to hardware structure
+ *
+ *  Compares our advertised flow control capabilities to those advertised by
+ *  our link partner, and determines the proper flow control mode to use.
+ **/
+void ngbe_fc_autoneg(struct ngbe_hw *hw)
+{
+       s32 err = NGBE_ERR_FC_NOT_NEGOTIATED;
+       u32 speed;
+       bool link_up;
+
+       /*
+        * AN should have completed when the cable was plugged in.
+        * Look for reasons to bail out.  Bail out if:
+        * - FC autoneg is disabled, or if
+        * - link is not up.
+        */
+       if (hw->fc.disable_fc_autoneg) {
+               DEBUGOUT("Flow control autoneg is disabled");
+               goto out;
+       }
+
+       hw->mac.check_link(hw, &speed, &link_up, false);
+       if (!link_up) {
+               DEBUGOUT("The link is down");
+               goto out;
+       }
+
+       err = ngbe_fc_autoneg_em(hw);
+
+out:
+       if (err == 0) {
+               hw->fc.fc_was_autonegged = true;
+       } else {
+               hw->fc.fc_was_autonegged = false;
+               hw->fc.current_mode = hw->fc.requested_mode;
+       }
+}
+
+/**
+ *  ngbe_set_pcie_master - Disable or Enable PCI-express master access
+ *  @hw: pointer to hardware structure
+ *
+ *  Disables PCI-Express master access and verifies there are no pending
+ *  requests. NGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
+ *  bit hasn't caused the master requests to be disabled, else 0
+ *  is returned signifying master requests disabled.
+ **/
+s32 ngbe_set_pcie_master(struct ngbe_hw *hw, bool enable)
+{
+       s32 status = 0;
+       u16 addr = 0x04;
+       u32 data, i;
+
+       ngbe_hic_pcie_read(hw, addr, &data, 4);
+       if (enable)
+               data |= 0x04;
+       else
+               data &= ~0x04;
+
+       ngbe_hic_pcie_write(hw, addr, &data, 4);
+
+       if (enable)
+               goto out;
+
+       /* Exit if master requests are blocked */
+       if (!(rd32(hw, NGBE_BMEPEND)) ||
+           NGBE_REMOVED(hw->hw_addr))
+               goto out;
+
+       /* Poll for master request bit to clear */
+       for (i = 0; i < NGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
+               usec_delay(100);
+               if (!(rd32(hw, NGBE_BMEPEND)))
+                       goto out;
+       }
+
+       DEBUGOUT("PCIe transaction pending bit also did not clear.");
+       status = NGBE_ERR_MASTER_REQUESTS_PENDING;
+
+out:
+       return status;
+}
+
 /**
  *  ngbe_acquire_swfw_sync - Acquire SWFW semaphore
  *  @hw: pointer to hardware structure
@@ -714,13 +1103,12 @@ s32 ngbe_update_mc_addr_list(struct ngbe_hw *hw, u8 *mc_addr_list,
 s32 ngbe_acquire_swfw_sync(struct ngbe_hw *hw, u32 mask)
 {
        u32 mngsem = 0;
+       u32 fwsm = 0;
        u32 swmask = NGBE_MNGSEM_SW(mask);
        u32 fwmask = NGBE_MNGSEM_FW(mask);
        u32 timeout = 200;
        u32 i;
 
-       DEBUGFUNC("ngbe_acquire_swfw_sync");
-
        for (i = 0; i < timeout; i++) {
                /*
                 * SW NVM semaphore bit is used for access to all
@@ -742,9 +1130,9 @@ s32 ngbe_acquire_swfw_sync(struct ngbe_hw *hw, u32 mask)
                }
        }
 
-       /* If time expired clear the bits holding the lock and retry */
-       if (mngsem & (fwmask | swmask))
-               ngbe_release_swfw_sync(hw, mngsem & (fwmask | swmask));
+       fwsm = rd32(hw, NGBE_MNGFWSYNC);
+       DEBUGOUT("SWFW semaphore not granted: MNG_SWFW_SYNC = 0x%x, MNG_FW_SM = 0x%x",
+                       mngsem, fwsm);
 
        msec_delay(5);
        return NGBE_ERR_SWFW_SYNC;
@@ -763,8 +1151,6 @@ void ngbe_release_swfw_sync(struct ngbe_hw *hw, u32 mask)
        u32 mngsem;
        u32 swmask = mask;
 
-       DEBUGFUNC("ngbe_release_swfw_sync");
-
        ngbe_get_eeprom_semaphore(hw);
 
        mngsem = rd32(hw, NGBE_MNGSEM);
@@ -788,9 +1174,6 @@ s32 ngbe_disable_sec_rx_path(struct ngbe_hw *hw)
        int i;
        u32 secrxreg;
 
-       DEBUGFUNC("ngbe_disable_sec_rx_path");
-
-
        secrxreg = rd32(hw, NGBE_SECRXCTL);
        secrxreg |= NGBE_SECRXCTL_XDSA;
        wr32(hw, NGBE_SECRXCTL, secrxreg);
@@ -805,8 +1188,7 @@ s32 ngbe_disable_sec_rx_path(struct ngbe_hw *hw)
 
        /* For informational purposes only */
        if (i >= NGBE_MAX_SECRX_POLL)
-               DEBUGOUT("Rx unit being enabled before security "
-                        "path fully disabled.  Continuing with init.\n");
+               DEBUGOUT("Rx unit being enabled before security path fully disabled.  Continuing with init.");
 
        return 0;
 }
@@ -821,8 +1203,6 @@ s32 ngbe_enable_sec_rx_path(struct ngbe_hw *hw)
 {
        u32 secrxreg;
 
-       DEBUGFUNC("ngbe_enable_sec_rx_path");
-
        secrxreg = rd32(hw, NGBE_SECRXCTL);
        secrxreg &= ~NGBE_SECRXCTL_XDSA;
        wr32(hw, NGBE_SECRXCTL, secrxreg);
@@ -842,11 +1222,9 @@ s32 ngbe_clear_vmdq(struct ngbe_hw *hw, u32 rar, u32 vmdq)
        u32 mpsar;
        u32 rar_entries = hw->mac.num_rar_entries;
 
-       DEBUGFUNC("ngbe_clear_vmdq");
-
        /* Make sure we are using a valid rar index range */
        if (rar >= rar_entries) {
-               DEBUGOUT("RAR index %d is out of range.\n", rar);
+               DEBUGOUT("RAR index %d is out of range.", rar);
                return NGBE_ERR_INVALID_ARGUMENT;
        }
 
@@ -880,11 +1258,9 @@ s32 ngbe_set_vmdq(struct ngbe_hw *hw, u32 rar, u32 vmdq)
        u32 mpsar;
        u32 rar_entries = hw->mac.num_rar_entries;
 
-       DEBUGFUNC("ngbe_set_vmdq");
-
        /* Make sure we are using a valid rar index range */
        if (rar >= rar_entries) {
-               DEBUGOUT("RAR index %d is out of range.\n", rar);
+               DEBUGOUT("RAR index %d is out of range.", rar);
                return NGBE_ERR_INVALID_ARGUMENT;
        }
 
@@ -905,8 +1281,7 @@ s32 ngbe_init_uta_tables(struct ngbe_hw *hw)
 {
        int i;
 
-       DEBUGFUNC("ngbe_init_uta_tables");
-       DEBUGOUT(" Clearing UTA\n");
+       DEBUGOUT(" Clearing UTA");
 
        for (i = 0; i < 128; i++)
                wr32(hw, NGBE_UCADDRTBL(i), 0);
@@ -961,7 +1336,7 @@ s32 ngbe_find_vlvf_slot(struct ngbe_hw *hw, u32 vlan, bool vlvf_bypass)
         * slot we found during our search, else error.
         */
        if (!first_empty_slot)
-               DEBUGOUT("No space in VLVF.\n");
+               DEBUGOUT("No space in VLVF.");
 
        return first_empty_slot ? first_empty_slot : NGBE_ERR_NO_SPACE;
 }
@@ -982,8 +1357,6 @@ s32 ngbe_set_vfta(struct ngbe_hw *hw, u32 vlan, u32 vind,
        u32 regidx, vfta_delta, vfta;
        s32 err;
 
-       DEBUGFUNC("ngbe_set_vfta");
-
        if (vlan > 4095 || vind > 63)
                return NGBE_ERR_PARAM;
 
@@ -1051,8 +1424,6 @@ s32 ngbe_set_vlvf(struct ngbe_hw *hw, u32 vlan, u32 vind,
        u32 portctl;
        s32 vlvf_index;
 
-       DEBUGFUNC("ngbe_set_vlvf");
-
        if (vlan > 4095 || vind > 63)
                return NGBE_ERR_PARAM;
 
@@ -1132,8 +1503,6 @@ s32 ngbe_clear_vfta(struct ngbe_hw *hw)
 {
        u32 offset;
 
-       DEBUGFUNC("ngbe_clear_vfta");
-
        for (offset = 0; offset < hw->mac.vft_size; offset++)
                wr32(hw, NGBE_VLANTBL(offset), 0);
 
@@ -1161,8 +1530,6 @@ s32 ngbe_check_mac_link_em(struct ngbe_hw *hw, u32 *speed,
        u32 i, reg;
        s32 status = 0;
 
-       DEBUGFUNC("ngbe_check_mac_link_em");
-
        reg = rd32(hw, NGBE_GPIOINTSTAT);
        wr32(hw, NGBE_GPIOEOI, reg);
 
@@ -1185,19 +1552,20 @@ s32 ngbe_get_link_capabilities_em(struct ngbe_hw *hw,
                                      bool *autoneg)
 {
        s32 status = 0;
-
-       DEBUGFUNC("\n");
+       u16 value = 0;
 
        hw->mac.autoneg = *autoneg;
 
-       switch (hw->sub_device_id) {
-       case NGBE_SUB_DEV_ID_EM_RTL_SGMII:
+       if (hw->phy.type == ngbe_phy_rtl) {
                *speed = NGBE_LINK_SPEED_1GB_FULL |
                        NGBE_LINK_SPEED_100M_FULL |
                        NGBE_LINK_SPEED_10M_FULL;
-               break;
-       default:
-               break;
+       }
+
+       if (hw->phy.type == ngbe_phy_yt8521s_sfi) {
+               ngbe_read_phy_reg_ext_yt(hw, YT_CHIP, 0, &value);
+               if ((value & YT_CHIP_MODE_MASK) == YT_CHIP_MODE_SEL(1))
+                       *speed = NGBE_LINK_SPEED_1GB_FULL;
        }
 
        return status;
@@ -1209,8 +1577,6 @@ s32 ngbe_setup_mac_link_em(struct ngbe_hw *hw,
 {
        s32 status;
 
-       DEBUGFUNC("\n");
-
        /* Setup the PHY according to input speed */
        status = hw->phy.setup_link(hw, speed, autoneg_wait_to_complete);
 
@@ -1236,6 +1602,30 @@ void ngbe_set_mac_anti_spoofing(struct ngbe_hw *hw, bool enable, int vf)
        wr32(hw, NGBE_POOLTXASMAC, pfvfspoof);
 }
 
+/**
+ * ngbe_set_pba - Initialize Rx packet buffer
+ * @hw: pointer to hardware structure
+ * @headroom: reserve n KB of headroom
+ **/
+void ngbe_set_pba(struct ngbe_hw *hw)
+{
+       u32 rxpktsize = hw->mac.rx_pb_size;
+       u32 txpktsize, txpbthresh;
+
+       /* Reserve 256 KB of headroom */
+       rxpktsize -= 256;
+
+       rxpktsize <<= 10;
+       wr32(hw, NGBE_PBRXSIZE, rxpktsize);
+
+       /* Only support an equally distributed Tx packet buffer strategy. */
+       txpktsize = NGBE_PBTXSIZE_MAX;
+       txpbthresh = (txpktsize / 1024) - NGBE_TXPKT_SIZE_MAX;
+
+       wr32(hw, NGBE_PBTXSIZE, txpktsize);
+       wr32(hw, NGBE_PBTXDMATH, txpbthresh);
+}
+
 /**
  *  ngbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
  *  @hw: pointer to hardware structure
@@ -1266,8 +1656,6 @@ s32 ngbe_init_thermal_sensor_thresh(struct ngbe_hw *hw)
 {
        struct ngbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
 
-       DEBUGFUNC("ngbe_init_thermal_sensor_thresh");
-
        memset(data, 0, sizeof(struct ngbe_thermal_sensor_data));
 
        if (hw->bus.lan_id != 0)
@@ -1291,8 +1679,6 @@ s32 ngbe_mac_check_overtemp(struct ngbe_hw *hw)
        s32 status = 0;
        u32 ts_state;
 
-       DEBUGFUNC("ngbe_mac_check_overtemp");
-
        /* Check that the LASI temp alarm status was triggered */
        ts_state = rd32(hw, NGBE_TSALM);
 
@@ -1347,8 +1733,6 @@ s32 ngbe_set_mac_type(struct ngbe_hw *hw)
 {
        s32 err = 0;
 
-       DEBUGFUNC("ngbe_set_mac_type");
-
        if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
                DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
                return NGBE_ERR_DEVICE_NOT_SUPPORTED;
@@ -1359,11 +1743,23 @@ s32 ngbe_set_mac_type(struct ngbe_hw *hw)
        case NGBE_SUB_DEV_ID_EM_MVL_RGMII:
                hw->phy.media_type = ngbe_media_type_copper;
                hw->mac.type = ngbe_mac_em;
+               hw->mac.link_type = ngbe_link_copper;
+               break;
+       case NGBE_SUB_DEV_ID_EM_RTL_YT8521S_SFP:
+               hw->phy.media_type = ngbe_media_type_copper;
+               hw->mac.type = ngbe_mac_em;
+               hw->mac.link_type = ngbe_link_fiber;
                break;
        case NGBE_SUB_DEV_ID_EM_MVL_SFP:
        case NGBE_SUB_DEV_ID_EM_YT8521S_SFP:
                hw->phy.media_type = ngbe_media_type_fiber;
                hw->mac.type = ngbe_mac_em;
+               hw->mac.link_type = ngbe_link_fiber;
+               break;
+       case NGBE_SUB_DEV_ID_EM_MVL_MIX:
+               hw->phy.media_type = ngbe_media_type_unknown;
+               hw->mac.type = ngbe_mac_em;
+               hw->mac.link_type = ngbe_link_type_unknown;
                break;
        case NGBE_SUB_DEV_ID_EM_VF:
                hw->phy.media_type = ngbe_media_type_virtual;
@@ -1377,7 +1773,7 @@ s32 ngbe_set_mac_type(struct ngbe_hw *hw)
                break;
        }
 
-       DEBUGOUT("found mac: %d media: %d, returns: %d\n",
+       DEBUGOUT("found mac: %d media: %d, returns: %d",
                  hw->mac.type, hw->phy.media_type, err);
        return err;
 }
@@ -1391,15 +1787,12 @@ s32 ngbe_set_mac_type(struct ngbe_hw *hw)
  **/
 s32 ngbe_enable_rx_dma(struct ngbe_hw *hw, u32 regval)
 {
-       DEBUGFUNC("ngbe_enable_rx_dma");
-
        /*
         * Workaround silicon errata when enabling the Rx datapath.
         * If traffic is incoming before we enable the Rx unit, it could hang
         * the Rx DMA unit.  Therefore, make sure the security engine is
         * completely disabled prior to enabling the Rx unit.
         */
-
        hw->mac.disable_sec_rx_path(hw);
 
        if (regval & NGBE_PBRXCTL_ENA)
@@ -1415,7 +1808,7 @@ s32 ngbe_enable_rx_dma(struct ngbe_hw *hw, u32 regval)
 void ngbe_map_device_id(struct ngbe_hw *hw)
 {
        u16 oem = hw->sub_system_id & NGBE_OEM_MASK;
-       u16 internal = hw->sub_system_id & NGBE_INTERNAL_MASK;
+
        hw->is_pf = true;
 
        /* move subsystem_device_id to device_id */
@@ -1449,20 +1842,31 @@ void ngbe_map_device_id(struct ngbe_hw *hw)
        case NGBE_DEV_ID_EM_WX1860A1:
        case NGBE_DEV_ID_EM_WX1860A1L:
                hw->device_id = NGBE_DEV_ID_EM;
-               if (oem == NGBE_LY_M88E1512_SFP ||
-                               internal == NGBE_INTERNAL_SFP)
+               if (oem == NGBE_M88E1512_SFP || oem == NGBE_LY_M88E1512_SFP)
                        hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_SFP;
-               else if (hw->sub_system_id == NGBE_SUB_DEV_ID_EM_M88E1512_RJ45)
+               else if (oem == NGBE_M88E1512_RJ45 ||
+                       (hw->sub_system_id == NGBE_SUB_DEV_ID_EM_M88E1512_RJ45))
                        hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_RGMII;
+               else if (oem == NGBE_M88E1512_MIX)
+                       hw->sub_device_id = NGBE_SUB_DEV_ID_EM_MVL_MIX;
                else if (oem == NGBE_YT8521S_SFP ||
-                               oem == NGBE_LY_YT8521S_SFP)
+                        oem == NGBE_YT8521S_SFP_GPIO ||
+                        oem == NGBE_LY_YT8521S_SFP)
                        hw->sub_device_id = NGBE_SUB_DEV_ID_EM_YT8521S_SFP;
+               else if (oem == NGBE_INTERNAL_YT8521S_SFP ||
+                        oem == NGBE_INTERNAL_YT8521S_SFP_GPIO)
+                       hw->sub_device_id = NGBE_SUB_DEV_ID_EM_RTL_YT8521S_SFP;
                else
                        hw->sub_device_id = NGBE_SUB_DEV_ID_EM_RTL_SGMII;
                break;
        default:
                break;
        }
+
+       if (oem == NGBE_LY_M88E1512_SFP || oem == NGBE_YT8521S_SFP_GPIO ||
+                       oem == NGBE_INTERNAL_YT8521S_SFP_GPIO ||
+                       oem == NGBE_LY_YT8521S_SFP)
+               hw->gpio_ctl = true;
 }
 
 /**
@@ -1480,8 +1884,6 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
        struct ngbe_rom_info *rom = &hw->rom;
        struct ngbe_mbx_info *mbx = &hw->mbx;
 
-       DEBUGFUNC("ngbe_init_ops_pf");
-
        /* BUS */
        bus->set_lan_id = ngbe_set_lan_id_multi_port;
 
@@ -1492,6 +1894,7 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
        phy->read_reg_unlocked = ngbe_read_phy_reg_mdi;
        phy->write_reg_unlocked = ngbe_write_phy_reg_mdi;
        phy->reset_hw = ngbe_reset_phy;
+       phy->led_oem_chk = ngbe_phy_led_oem_chk;
 
        /* MAC */
        mac->init_hw = ngbe_init_hw;
@@ -1507,6 +1910,10 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
        mac->disable_sec_rx_path = ngbe_disable_sec_rx_path;
        mac->enable_sec_rx_path = ngbe_enable_sec_rx_path;
 
+       /* LEDs */
+       mac->led_on = ngbe_led_on;
+       mac->led_off = ngbe_led_off;
+
        /* RAR, VLAN, Multicast */
        mac->set_rar = ngbe_set_rar;
        mac->clear_rar = ngbe_clear_rar;
@@ -1520,11 +1927,18 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
        mac->set_mac_anti_spoofing = ngbe_set_mac_anti_spoofing;
        mac->set_vlan_anti_spoofing = ngbe_set_vlan_anti_spoofing;
 
+       /* Flow Control */
+       mac->fc_enable = ngbe_fc_enable;
+       mac->fc_autoneg = ngbe_fc_autoneg;
+       mac->setup_fc = ngbe_setup_fc_em;
+
        /* Link */
        mac->get_link_capabilities = ngbe_get_link_capabilities_em;
        mac->check_link = ngbe_check_mac_link_em;
        mac->setup_link = ngbe_setup_mac_link_em;
 
+       mac->setup_pba = ngbe_set_pba;
+
        /* Manageability interface */
        mac->init_thermal_sensor_thresh = ngbe_init_thermal_sensor_thresh;
        mac->check_overtemp = ngbe_mac_check_overtemp;
@@ -1538,12 +1952,15 @@ s32 ngbe_init_ops_pf(struct ngbe_hw *hw)
 
        /* EEPROM */
        rom->init_params = ngbe_init_eeprom_params;
+       rom->readw_buffer = ngbe_ee_readw_buffer;
        rom->read32 = ngbe_ee_read32;
+       rom->writew_buffer = ngbe_ee_writew_buffer;
        rom->validate_checksum = ngbe_validate_eeprom_checksum_em;
 
        mac->mcft_size          = NGBE_EM_MC_TBL_SIZE;
        mac->vft_size           = NGBE_EM_VFT_TBL_SIZE;
        mac->num_rar_entries    = NGBE_EM_RAR_ENTRIES;
+       mac->rx_pb_size         = NGBE_EM_RX_PB_SIZE;
        mac->max_rx_queues      = NGBE_EM_MAX_RX_QUEUES;
        mac->max_tx_queues      = NGBE_EM_MAX_TX_QUEUES;
 
@@ -1569,8 +1986,6 @@ s32 ngbe_init_shared_code(struct ngbe_hw *hw)
 {
        s32 status = 0;
 
-       DEBUGFUNC("ngbe_init_shared_code");
-
        /*
         * Set the mac type
         */