vhost: support ifname for vhost-user
[dpdk.git] / lib / librte_pmd_ixgbe / ixgbe / ixgbe_x540.c
index 9cecd29..ab38450 100644 (file)
@@ -726,7 +726,7 @@ STATIC s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw)
                        status = IXGBE_SUCCESS;
                        break;
                }
-               usec_delay(5);
+               msec_delay(5);
        }
 
        if (i == IXGBE_FLUDONE_ATTEMPTS)
@@ -736,6 +736,26 @@ STATIC s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw)
        return status;
 }
 
+/**
+ * ixgbe_set_mux - Set mux for port 1 access with CS4227
+ * @hw: pointer to hardware structure
+ * @state: set mux if 1, clear if 0
+ */
+STATIC void ixgbe_set_mux(struct ixgbe_hw *hw, u8 state)
+{
+       u32 esdp;
+
+       if (!hw->phy.lan_id)
+               return;
+       esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
+       if (state)
+               esdp |= IXGBE_ESDP_SDP1;
+       else
+               esdp &= ~IXGBE_ESDP_SDP1;
+       IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
+       IXGBE_WRITE_FLUSH(hw);
+}
+
 /**
  *  ixgbe_acquire_swfw_sync_X540 - Acquire SWFW semaphore
  *  @hw: pointer to hardware structure
@@ -744,34 +764,33 @@ STATIC s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw)
  *  Acquires the SWFW semaphore thought the SW_FW_SYNC register for
  *  the specified function (CSR, PHY0, PHY1, NVM, Flash)
  **/
-s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
+s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u32 mask)
 {
-       u32 swfw_sync;
-       u32 swmask = mask;
-       u32 fwmask = mask << 5;
-       u32 hwmask = 0;
+       u32 swmask = mask & IXGBE_GSSR_NVM_PHY_MASK;
+       u32 fwmask = swmask << 5;
+       u32 swi2c_mask = mask & IXGBE_GSSR_I2C_MASK;
        u32 timeout = 200;
+       u32 hwmask = 0;
+       u32 swfw_sync;
        u32 i;
-       s32 ret_val = IXGBE_SUCCESS;
 
        DEBUGFUNC("ixgbe_acquire_swfw_sync_X540");
 
-       if (swmask == IXGBE_GSSR_EEP_SM)
-               hwmask = IXGBE_GSSR_FLASH_SM;
+       if (swmask & IXGBE_GSSR_EEP_SM)
+               hwmask |= IXGBE_GSSR_FLASH_SM;
 
        /* SW only mask doesn't have FW bit pair */
-       if (swmask == IXGBE_GSSR_SW_MNG_SM)
-               fwmask = 0;
+       if (mask & IXGBE_GSSR_SW_MNG_SM)
+               swmask |= IXGBE_GSSR_SW_MNG_SM;
 
+       swmask |= swi2c_mask;
+       fwmask |= swi2c_mask << 2;
        for (i = 0; i < timeout; i++) {
-               /*
-                * SW NVM semaphore bit is used for access to all
+               /* SW NVM semaphore bit is used for access to all
                 * SW_FW_SYNC bits (not just NVM)
                 */
-               if (ixgbe_get_swfw_sync_semaphore(hw)) {
-                       ret_val = IXGBE_ERR_SWFW_SYNC;
-                       goto out;
-               }
+               if (ixgbe_get_swfw_sync_semaphore(hw))
+                       return IXGBE_ERR_SWFW_SYNC;
 
                swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
                if (!(swfw_sync & (fwmask | swmask | hwmask))) {
@@ -779,24 +798,23 @@ s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
                        IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
                        ixgbe_release_swfw_sync_semaphore(hw);
                        msec_delay(5);
-                       goto out;
-               } else {
-                       /*
-                        * Firmware currently using resource (fwmask), hardware
-                        * currently using resource (hwmask), or other software
-                        * thread currently using resource (swmask)
-                        */
-                       ixgbe_release_swfw_sync_semaphore(hw);
-                       msec_delay(5);
+                       if (swi2c_mask)
+                               ixgbe_set_mux(hw, 1);
+                       return IXGBE_SUCCESS;
                }
+               /* Firmware currently using resource (fwmask), hardware
+                * currently using resource (hwmask), or other software
+                * thread currently using resource (swmask)
+                */
+               ixgbe_release_swfw_sync_semaphore(hw);
+               msec_delay(5);
        }
 
        /* Failed to get SW only semaphore */
        if (swmask == IXGBE_GSSR_SW_MNG_SM) {
-               ret_val = IXGBE_ERR_SWFW_SYNC;
                ERROR_REPORT1(IXGBE_ERROR_POLLING,
                             "Failed to get SW only semaphore");
-               goto out;
+               return IXGBE_ERR_SWFW_SYNC;
        }
 
        /* If the resource is not released by the FW/HW the SW can assume that
@@ -804,32 +822,36 @@ s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
         * of the requested resource(s) while ignoring the corresponding FW/HW
         * bits in the SW_FW_SYNC register.
         */
+       if (ixgbe_get_swfw_sync_semaphore(hw))
+               return IXGBE_ERR_SWFW_SYNC;
        swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);
        if (swfw_sync & (fwmask | hwmask)) {
-               if (ixgbe_get_swfw_sync_semaphore(hw)) {
-                       ret_val = IXGBE_ERR_SWFW_SYNC;
-                       goto out;
-               }
-
                swfw_sync |= swmask;
                IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC, swfw_sync);
                ixgbe_release_swfw_sync_semaphore(hw);
                msec_delay(5);
+               if (swi2c_mask)
+                       ixgbe_set_mux(hw, 1);
+               return IXGBE_SUCCESS;
        }
        /* If the resource is not released by other SW the SW can assume that
         * the other SW malfunctions. In that case the SW should clear all SW
         * flags that it does not own and then repeat the whole process once
         * again.
         */
-       else if (swfw_sync & swmask) {
-               ixgbe_release_swfw_sync_X540(hw, IXGBE_GSSR_EEP_SM |
-                       IXGBE_GSSR_PHY0_SM | IXGBE_GSSR_PHY1_SM |
-                       IXGBE_GSSR_MAC_CSR_SM);
-               ret_val = IXGBE_ERR_SWFW_SYNC;
+       if (swfw_sync & swmask) {
+               u32 rmask = IXGBE_GSSR_EEP_SM | IXGBE_GSSR_PHY0_SM |
+                           IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_MAC_CSR_SM;
+
+               if (swi2c_mask)
+                       rmask |= IXGBE_GSSR_I2C_MASK;
+               ixgbe_release_swfw_sync_X540(hw, rmask);
+               ixgbe_release_swfw_sync_semaphore(hw);
+               return IXGBE_ERR_SWFW_SYNC;
        }
+       ixgbe_release_swfw_sync_semaphore(hw);
 
-out:
-       return ret_val;
+       return IXGBE_ERR_SWFW_SYNC;
 }
 
 /**
@@ -840,13 +862,17 @@ out:
  *  Releases the SWFW semaphore through the SW_FW_SYNC register
  *  for the specified function (CSR, PHY0, PHY1, EVM, Flash)
  **/
-void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u16 mask)
+void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u32 mask)
 {
+       u32 swmask = mask & (IXGBE_GSSR_NVM_PHY_MASK | IXGBE_GSSR_SW_MNG_SM);
        u32 swfw_sync;
-       u32 swmask = mask;
 
        DEBUGFUNC("ixgbe_release_swfw_sync_X540");
 
+       if (mask & IXGBE_GSSR_I2C_MASK) {
+               swmask |= mask & IXGBE_GSSR_I2C_MASK;
+               ixgbe_set_mux(hw, 0);
+       }
        ixgbe_get_swfw_sync_semaphore(hw);
 
        swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC);