Enhanced loopback AQ command to allow variety of loopback modes.

Signed-off-by: Qi Zhang <qi.z.zh...@intel.com>
---
 drivers/net/i40e/base/i40e_adminq_cmd.h | 21 +++++++++++++++++++--
 drivers/net/i40e/base/i40e_common.c     | 12 ++++++++----
 drivers/net/i40e/base/i40e_diag.c       | 17 +++++++++++++++--
 drivers/net/i40e/base/i40e_prototype.h  |  5 +++--
 drivers/net/i40e/i40e_ethdev.c          |  4 +++-
 5 files changed, 48 insertions(+), 11 deletions(-)

diff --git a/drivers/net/i40e/base/i40e_adminq_cmd.h 
b/drivers/net/i40e/base/i40e_adminq_cmd.h
index 8d9012189..62c335453 100644
--- a/drivers/net/i40e/base/i40e_adminq_cmd.h
+++ b/drivers/net/i40e/base/i40e_adminq_cmd.h
@@ -2129,11 +2129,28 @@ I40E_CHECK_CMD_LENGTH(i40e_aqc_an_advt_reg);
 
 /* Set Loopback mode (0x0618) */
 struct i40e_aqc_set_lb_mode {
-       __le16  lb_mode;
+       u8      lb_level;
+#define I40E_AQ_LB_NONE        0
+#define I40E_AQ_LB_MAC 1
+#define I40E_AQ_LB_SERDES      2
+#define I40E_AQ_LB_PHY_INT     3
+#define I40E_AQ_LB_PHY_EXT     4
+#define I40E_AQ_LB_CPVL_PCS    5
+#define I40E_AQ_LB_CPVL_EXT    6
 #define I40E_AQ_LB_PHY_LOCAL   0x01
 #define I40E_AQ_LB_PHY_REMOTE  0x02
 #define I40E_AQ_LB_MAC_LOCAL   0x04
-       u8      reserved[14];
+       u8      lb_type;
+#define I40E_AQ_LB_LOCAL       0
+#define I40E_AQ_LB_FAR 0x01
+       u8      speed;
+#define I40E_AQ_LB_SPEED_NONE  0
+#define I40E_AQ_LB_SPEED_1G    1
+#define I40E_AQ_LB_SPEED_10G   2
+#define I40E_AQ_LB_SPEED_40G   3
+#define I40E_AQ_LB_SPEED_20G   4
+       u8      force_speed;
+       u8      reserved[12];
 };
 
 I40E_CHECK_CMD_LENGTH(i40e_aqc_set_lb_mode);
diff --git a/drivers/net/i40e/base/i40e_common.c 
b/drivers/net/i40e/base/i40e_common.c
index 94f64d61d..13f513968 100644
--- a/drivers/net/i40e/base/i40e_common.c
+++ b/drivers/net/i40e/base/i40e_common.c
@@ -2166,9 +2166,9 @@ enum i40e_status_code i40e_aq_get_partner_advt(struct 
i40e_hw *hw,
  *
  * Sets loopback modes.
  **/
-enum i40e_status_code i40e_aq_set_lb_modes(struct i40e_hw *hw,
-                               u16 lb_modes,
-                               struct i40e_asq_cmd_details *cmd_details)
+enum i40e_status_code
+i40e_aq_set_lb_modes(struct i40e_hw *hw, u8 lb_level, u8 lb_type, u8 speed,
+                    struct i40e_asq_cmd_details *cmd_details)
 {
        struct i40e_aq_desc desc;
        struct i40e_aqc_set_lb_mode *cmd =
@@ -2178,7 +2178,11 @@ enum i40e_status_code i40e_aq_set_lb_modes(struct 
i40e_hw *hw,
        i40e_fill_default_direct_cmd_desc(&desc,
                                          i40e_aqc_opc_set_lb_modes);
 
-       cmd->lb_mode = CPU_TO_LE16(lb_modes);
+       cmd->lb_level = lb_level;
+       cmd->lb_type = lb_type;
+       cmd->speed = speed;
+       if (speed)
+               cmd->force_speed = 1;
 
        status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
 
diff --git a/drivers/net/i40e/base/i40e_diag.c 
b/drivers/net/i40e/base/i40e_diag.c
index c3c76a0c8..0efa59de3 100644
--- a/drivers/net/i40e/base/i40e_diag.c
+++ b/drivers/net/i40e/base/i40e_diag.c
@@ -45,8 +45,21 @@ enum i40e_status_code i40e_diag_set_loopback(struct i40e_hw 
*hw,
                                             enum i40e_lb_mode mode)
 {
        enum i40e_status_code ret_code = I40E_SUCCESS;
-
-       if (i40e_aq_set_lb_modes(hw, mode, NULL))
+       u8 speed = I40E_AQ_LB_SPEED_10G;
+       u8 level = 0;
+       u8 type = 0;
+
+       if (mode == I40E_LB_MODE_PHY_LOCAL) {
+               level = I40E_AQ_LB_PHY_INT;
+               type = I40E_AQ_LB_LOCAL;
+       } else if (mode == I40E_LB_MODE_PHY_REMOTE) {
+               level = I40E_AQ_LB_PHY_INT;
+               type = I40E_AQ_LB_FAR;
+       } else if (mode == I40E_LB_MODE_MAC_LOCAL) {
+               level = I40E_AQ_LB_MAC;
+               type = I40E_AQ_LB_LOCAL;
+       }
+       if (i40e_aq_set_lb_modes(hw, level, type, speed, NULL))
                ret_code = I40E_ERR_DIAG_TEST_FAILED;
 
        return ret_code;
diff --git a/drivers/net/i40e/base/i40e_prototype.h 
b/drivers/net/i40e/base/i40e_prototype.h
index c6ec2d769..1edfb2d18 100644
--- a/drivers/net/i40e/base/i40e_prototype.h
+++ b/drivers/net/i40e/base/i40e_prototype.h
@@ -142,8 +142,9 @@ enum i40e_status_code i40e_aq_get_local_advt_reg(struct 
i40e_hw *hw,
 enum i40e_status_code i40e_aq_get_partner_advt(struct i40e_hw *hw,
                                u64 *advt_reg,
                                struct i40e_asq_cmd_details *cmd_details);
-enum i40e_status_code i40e_aq_set_lb_modes(struct i40e_hw *hw, u16 lb_modes,
-                               struct i40e_asq_cmd_details *cmd_details);
+enum i40e_status_code
+i40e_aq_set_lb_modes(struct i40e_hw *hw, u8 lb_level, u8 lb_type, u8 speed,
+                    struct i40e_asq_cmd_details *cmd_details);
 enum i40e_status_code i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
                        struct i40e_asq_cmd_details *cmd_details);
 enum i40e_status_code i40e_aq_set_link_restart_an(struct i40e_hw *hw,
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 9ec02012a..a8e321381 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -33,6 +33,7 @@
 #include "base/i40e_type.h"
 #include "base/i40e_register.h"
 #include "base/i40e_dcb.h"
+#include "base/i40e_diag.h"
 #include "i40e_ethdev.h"
 #include "i40e_rxtx.h"
 #include "i40e_pf.h"
@@ -1993,6 +1994,7 @@ i40e_dev_start(struct rte_eth_dev *dev)
 
        /* Enable all queues which have been configured */
        ret = i40e_dev_switch_queues(pf, TRUE);
+
        if (ret != I40E_SUCCESS) {
                PMD_DRV_LOG(ERR, "Failed to enable VSI");
                goto err_up;
@@ -2022,7 +2024,7 @@ i40e_dev_start(struct rte_eth_dev *dev)
        /* Enable mac loopback mode */
        if (dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_MODE_NONE ||
            dev->data->dev_conf.lpbk_mode == I40E_AQ_LB_PHY_LOCAL) {
-               ret = i40e_aq_set_lb_modes(hw, dev->data->dev_conf.lpbk_mode, 
NULL);
+               ret = i40e_diag_set_loopback(hw, dev->data->dev_conf.lpbk_mode);
                if (ret != I40E_SUCCESS) {
                        PMD_DRV_LOG(ERR, "fail to set loopback link");
                        goto err_up;
-- 
2.14.1

Reply via email to