[dpdk-dev] [PATCH 18/29] ixgbe/base: update swfw semaphore function

2016-06-13 Thread Ferruh Yigit
On 5/6/2016 7:07 AM, Beilei Xing wrote:
> For X540 and forward it is possible if a system reset occur at the
> right time to leave the SWFW semaphore high. This new function will
> attempt to grab and release the semaphore. If the grab times out it
> will still release the semaphore placing it in a known good state.
> The idea is to call this when you know no one should be holding the
> semaphore (i.e. probe time)
> This patch alse fixes possible race issue between ports when issuing
> host interface command by acquiring/releasing the management host
> interface semaphore in ixgbe_host_interface_command.
> 
> Signed-off-by: Beilei Xing 
> ---
Does it make sense to separate this patch into two.

...

> +/**
> + *  ixgbe_init_swfw_semaphore - Clean up SWFW semaphore
> + *  @hw: pointer to hardware structure
> + *
> + *  Attempts to acquire the SWFW semaphore through SW_FW_SYNC register.
> + *  Regardless of whether is succeeds or not it then release the semaphore.
> + *  This is function is called to recover from catastrophic failures that
> + *  may have left the semaphore locked.
> + **/
> +void ixgbe_init_swfw_semaphore(struct ixgbe_hw *hw)
> +{
> + if (hw->mac.ops.init_swfw_sync)
> + hw->mac.ops.init_swfw_sync(hw);
> +}
One add ixgbe_init_swfw_semaphore related code (init_swfw_sync,
ixgbe_init_swfw_sync_X540)

...

> @@ -4390,6 +4392,12 @@ s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, 
> u32 *buffer,
>   DEBUGOUT1("Buffer length failure buffersize=%d.\n", length);
>   return IXGBE_ERR_HOST_INTERFACE_COMMAND;
>   }
> + /* Take management host interface semaphore */
> + status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
> +
> + if (status)
> + return status;
> +
Second is fix in ixgbe_host_interface_command, they are unrelated as far
as I can see.

>   /* Set bit 9 of FWSTS clearing FW reset indication */
>   fwsts = IXGBE_READ_REG(hw, IXGBE_FWSTS);
>   IXGBE_WRITE_REG(hw, IXGBE_FWSTS, fwsts | IXGBE_FWSTS_FWRI);
...


[dpdk-dev] [PATCH 18/29] ixgbe/base: update swfw semaphore function

2016-06-13 Thread Ferruh Yigit
On 5/6/2016 7:07 AM, Beilei Xing wrote:
> For X540 and forward it is possible if a system reset occur at the
> right time to leave the SWFW semaphore high. This new function will
> attempt to grab and release the semaphore. If the grab times out it
> will still release the semaphore placing it in a known good state.
> The idea is to call this when you know no one should be holding the
> semaphore (i.e. probe time)
> This patch alse fixes possible race issue between ports when issuing
typo: alse

> host interface command by acquiring/releasing the management host
> interface semaphore in ixgbe_host_interface_command.
> 
> Signed-off-by: Beilei Xing 
> ---

...


[dpdk-dev] [PATCH 18/29] ixgbe/base: update swfw semaphore function

2016-05-06 Thread Beilei Xing
For X540 and forward it is possible if a system reset occur at the
right time to leave the SWFW semaphore high. This new function will
attempt to grab and release the semaphore. If the grab times out it
will still release the semaphore placing it in a known good state.
The idea is to call this when you know no one should be holding the
semaphore (i.e. probe time)
This patch alse fixes possible race issue between ports when issuing
host interface command by acquiring/releasing the management host
interface semaphore in ixgbe_host_interface_command.

Signed-off-by: Beilei Xing 
---
 drivers/net/ixgbe/base/ixgbe_api.c| 14 
 drivers/net/ixgbe/base/ixgbe_api.h|  1 +
 drivers/net/ixgbe/base/ixgbe_common.c | 41 ---
 drivers/net/ixgbe/base/ixgbe_type.h   |  1 +
 drivers/net/ixgbe/base/ixgbe_x540.c   | 20 +
 drivers/net/ixgbe/base/ixgbe_x540.h   |  1 +
 6 files changed, 61 insertions(+), 17 deletions(-)

diff --git a/drivers/net/ixgbe/base/ixgbe_api.c 
b/drivers/net/ixgbe/base/ixgbe_api.c
index 19e52c9..e117b86 100644
--- a/drivers/net/ixgbe/base/ixgbe_api.c
+++ b/drivers/net/ixgbe/base/ixgbe_api.c
@@ -1639,6 +1639,20 @@ void ixgbe_release_swfw_semaphore(struct ixgbe_hw *hw, 
u32 mask)
hw->mac.ops.release_swfw_sync(hw, mask);
 }

+/**
+ *  ixgbe_init_swfw_semaphore - Clean up SWFW semaphore
+ *  @hw: pointer to hardware structure
+ *
+ *  Attempts to acquire the SWFW semaphore through SW_FW_SYNC register.
+ *  Regardless of whether is succeeds or not it then release the semaphore.
+ *  This is function is called to recover from catastrophic failures that
+ *  may have left the semaphore locked.
+ **/
+void ixgbe_init_swfw_semaphore(struct ixgbe_hw *hw)
+{
+   if (hw->mac.ops.init_swfw_sync)
+   hw->mac.ops.init_swfw_sync(hw);
+}

 void ixgbe_disable_rx(struct ixgbe_hw *hw)
 {
diff --git a/drivers/net/ixgbe/base/ixgbe_api.h 
b/drivers/net/ixgbe/base/ixgbe_api.h
index ae26a6a..f5970a8 100644
--- a/drivers/net/ixgbe/base/ixgbe_api.h
+++ b/drivers/net/ixgbe/base/ixgbe_api.h
@@ -191,6 +191,7 @@ s32 ixgbe_set_san_mac_addr(struct ixgbe_hw *hw, u8 
*san_mac_addr);
 s32 ixgbe_get_device_caps(struct ixgbe_hw *hw, u16 *device_caps);
 s32 ixgbe_acquire_swfw_semaphore(struct ixgbe_hw *hw, u32 mask);
 void ixgbe_release_swfw_semaphore(struct ixgbe_hw *hw, u32 mask);
+void ixgbe_init_swfw_semaphore(struct ixgbe_hw *hw);
 s32 ixgbe_get_wwn_prefix(struct ixgbe_hw *hw, u16 *wwnn_prefix,
 u16 *wwpn_prefix);
 s32 ixgbe_get_fcoe_boot_status(struct ixgbe_hw *hw, u16 *bs);
diff --git a/drivers/net/ixgbe/base/ixgbe_common.c 
b/drivers/net/ixgbe/base/ixgbe_common.c
index d211303..0a708cf 100644
--- a/drivers/net/ixgbe/base/ixgbe_common.c
+++ b/drivers/net/ixgbe/base/ixgbe_common.c
@@ -4373,8 +4373,9 @@ u8 ixgbe_calculate_checksum(u8 *buffer, u32 length)
  *   So we will leave this up to the caller to read back the data
  *   in these cases.
  *
- *  Communicates with the manageability block.  On success return IXGBE_SUCCESS
- *  else return IXGBE_ERR_HOST_INTERFACE_COMMAND.
+ *  Communicates with the manageability block. On success return IXGBE_SUCCESS
+ *  else returns semaphore error when encountering an error acquiring
+ *  semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
  **/
 s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer,
 u32 length, u32 timeout, bool return_data)
@@ -4383,6 +4384,7 @@ s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 
*buffer,
u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
u16 buf_len;
u16 dword_len;
+   s32 status;

DEBUGFUNC("ixgbe_host_interface_command");

@@ -4390,6 +4392,12 @@ s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, 
u32 *buffer,
DEBUGOUT1("Buffer length failure buffersize=%d.\n", length);
return IXGBE_ERR_HOST_INTERFACE_COMMAND;
}
+   /* Take management host interface semaphore */
+   status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
+
+   if (status)
+   return status;
+
/* Set bit 9 of FWSTS clearing FW reset indication */
fwsts = IXGBE_READ_REG(hw, IXGBE_FWSTS);
IXGBE_WRITE_REG(hw, IXGBE_FWSTS, fwsts | IXGBE_FWSTS_FWRI);
@@ -4398,13 +4406,15 @@ s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, 
u32 *buffer,
hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
if ((hicr & IXGBE_HICR_EN) == 0) {
DEBUGOUT("IXGBE_HOST_EN bit disabled.\n");
-   return IXGBE_ERR_HOST_INTERFACE_COMMAND;
+   status = IXGBE_ERR_HOST_INTERFACE_COMMAND;
+   goto rel_out;
}

/* Calculate length in DWORDs. We must be DWORD aligned */
if ((length % (sizeof(u32))) != 0) {
DEBUGOUT("Buffer length failure, not aligned to dword");
-   return IXGBE_ERR_INVALID_ARGUMENT;
+