diff mbox

[dpdk-dev,v3,1/2] net/i40e: use PHY type to check PHY capability

Message ID 1474566582-41089-2-git-send-email-qi.z.zhang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Bruce Richardson
Headers show

Commit Message

Zhang, Qi Z Sept. 22, 2016, 5:49 p.m. UTC
In previous code, we use device ID to check PHY
capability which is not extensible since there is
always new device be added.
Now we use PHY type to detect PHY capability.
PHY type encoded all link speed the device support,
it is read out through aq command "get_phy_capability"
at init stage.

Signed-off-by: Zhang Qi <qi.z.zhang@intel.com>
---
 drivers/net/i40e/i40e_ethdev.c | 33 ++++++++++++++++++++++++++++-----
 drivers/net/i40e/i40e_ethdev.h |  8 ++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)

Comments

Wu, Jingjing Sept. 25, 2016, 9:58 a.m. UTC | #1
> -----Original Message-----
> From: Zhang, Qi Z
> Sent: Friday, September 23, 2016 1:50 AM
> To: Wu, Jingjing <jingjing.wu@intel.com>; Zhang, Helin <helin.zhang@intel.com>
> Cc: dev@dpdk.org; Zhang, Qi Z <qi.z.zhang@intel.com>
> Subject: [PATCH v3 1/2] net/i40e: use PHY type to check PHY capability
> 
> In previous code, we use device ID to check PHY
> capability which is not extensible since there is
> always new device be added.
> Now we use PHY type to detect PHY capability.
> PHY type encoded all link speed the device support,
> it is read out through aq command "get_phy_capability"
> at init stage.
> 
> Signed-off-by: Zhang Qi <qi.z.zhang@intel.com>
> ---
>  drivers/net/i40e/i40e_ethdev.c | 33 ++++++++++++++++++++++++++++-----
>  drivers/net/i40e/i40e_ethdev.h |  8 ++++++++
>  2 files changed, 36 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
> index acc25a2..9658503 100644
> --- a/drivers/net/i40e/i40e_ethdev.c
> +++ b/drivers/net/i40e/i40e_ethdev.c
> @@ -411,6 +411,7 @@ static int i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
>  				void *arg);
>  static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
>  				  struct rte_eth_dcb_info *dcb_info);
> +static int i40e_dev_sync_phy_type(struct i40e_hw *hw);
>  static void i40e_configure_registers(struct i40e_hw *hw);
>  static void i40e_hw_init(struct rte_eth_dev *dev);
>  static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
> @@ -1028,7 +1029,11 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
>  	config_floating_veb(dev);
>  	/* Clear PXE mode */
>  	i40e_clear_pxe_mode(hw);
> -
> +	ret = i40e_dev_sync_phy_type(hw);
> +	if (ret != I40E_SUCCESS) {
> +		PMD_INIT_LOG(ERR, "Failed to init phy type: %d", ret);
> +		goto err_sync_phy_type;
> +	}
Should we return from device initialization if failure?
And return value of i40e_dev_sync_phy_type is standard error, but you check
It by comparing with I40E defined error code.

Thanks
Jingjing
Zhang, Qi Z Sept. 26, 2016, 12:52 a.m. UTC | #2
Hi 

> -----Original Message-----
> From: Wu, Jingjing
> Sent: Sunday, September 25, 2016 5:59 PM
> To: Zhang, Qi Z <qi.z.zhang@intel.com>; Zhang, Helin <helin.zhang@intel.com>
> Cc: dev@dpdk.org
> Subject: RE: [PATCH v3 1/2] net/i40e: use PHY type to check PHY capability
> 
> 
> 
> > -----Original Message-----
> > From: Zhang, Qi Z
> > Sent: Friday, September 23, 2016 1:50 AM
> > To: Wu, Jingjing <jingjing.wu@intel.com>; Zhang, Helin
> > <helin.zhang@intel.com>
> > Cc: dev@dpdk.org; Zhang, Qi Z <qi.z.zhang@intel.com>
> > Subject: [PATCH v3 1/2] net/i40e: use PHY type to check PHY capability
> >
> > In previous code, we use device ID to check PHY capability which is
> > not extensible since there is always new device be added.
> > Now we use PHY type to detect PHY capability.
> > PHY type encoded all link speed the device support, it is read out
> > through aq command "get_phy_capability"
> > at init stage.
> >
> > Signed-off-by: Zhang Qi <qi.z.zhang@intel.com>
> > ---
> >  drivers/net/i40e/i40e_ethdev.c | 33 ++++++++++++++++++++++++++++-----
> > drivers/net/i40e/i40e_ethdev.h |  8 ++++++++
> >  2 files changed, 36 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/net/i40e/i40e_ethdev.c
> > b/drivers/net/i40e/i40e_ethdev.c index acc25a2..9658503 100644
> > --- a/drivers/net/i40e/i40e_ethdev.c
> > +++ b/drivers/net/i40e/i40e_ethdev.c
> > @@ -411,6 +411,7 @@ static int i40e_dev_filter_ctrl(struct rte_eth_dev
> *dev,
> >  				void *arg);
> >  static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
> >  				  struct rte_eth_dcb_info *dcb_info);
> > +static int i40e_dev_sync_phy_type(struct i40e_hw *hw);
> >  static void i40e_configure_registers(struct i40e_hw *hw);  static
> > void i40e_hw_init(struct rte_eth_dev *dev);  static int
> > i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi); @@ -1028,7
> > +1029,11 @@ eth_i40e_dev_init(struct rte_eth_dev *dev)
> >  	config_floating_veb(dev);
> >  	/* Clear PXE mode */
> >  	i40e_clear_pxe_mode(hw);
> > -
> > +	ret = i40e_dev_sync_phy_type(hw);
> > +	if (ret != I40E_SUCCESS) {
> > +		PMD_INIT_LOG(ERR, "Failed to init phy type: %d", ret);
> > +		goto err_sync_phy_type;
> > +	}
> Should we return from device initialization if failure?
Admin queue is already initialized before this, get_phy_capability should
not fail, so initialization should stop if an unexpected failure happen.
> And return value of i40e_dev_sync_phy_type is standard error, but you check It
> by comparing with I40E defined error code.
I will correct it, thanks for capture this.
> 
> Thanks
> Jingjing
Thanks
Qi
diff mbox

Patch

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index acc25a2..9658503 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -411,6 +411,7 @@  static int i40e_dev_filter_ctrl(struct rte_eth_dev *dev,
 				void *arg);
 static int i40e_dev_get_dcb_info(struct rte_eth_dev *dev,
 				  struct rte_eth_dcb_info *dcb_info);
+static int i40e_dev_sync_phy_type(struct i40e_hw *hw);
 static void i40e_configure_registers(struct i40e_hw *hw);
 static void i40e_hw_init(struct rte_eth_dev *dev);
 static int i40e_config_qinq(struct i40e_hw *hw, struct i40e_vsi *vsi);
@@ -1028,7 +1029,11 @@  eth_i40e_dev_init(struct rte_eth_dev *dev)
 	config_floating_veb(dev);
 	/* Clear PXE mode */
 	i40e_clear_pxe_mode(hw);
-
+	ret = i40e_dev_sync_phy_type(hw);
+	if (ret != I40E_SUCCESS) {
+		PMD_INIT_LOG(ERR, "Failed to init phy type: %d", ret);
+		goto err_sync_phy_type;
+	}
 	/*
 	 * On X710, performance number is far from the expectation on recent
 	 * firmware versions. The fix for this issue may not be integrated in
@@ -1184,6 +1189,7 @@  err_msix_pool_init:
 err_qp_pool_init:
 err_parameter_init:
 err_get_capabilities:
+err_sync_phy_type:
 	(void)i40e_shutdown_adminq(hw);
 
 	return ret;
@@ -1650,7 +1656,7 @@  i40e_apply_link_speed(struct rte_eth_dev *dev)
 	abilities |= I40E_AQ_PHY_LINK_ENABLED;
 
 	/* Skip changing speed on 40G interfaces, FW does not support */
-	if (i40e_is_40G_device(hw->device_id)) {
+	if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
 		speed =  I40E_LINK_SPEED_UNKNOWN;
 		abilities |= I40E_AQ_PHY_AN_ENABLED;
 	}
@@ -2625,7 +2631,7 @@  i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 		dev_info->max_tx_queues += dev_info->vmdq_queue_num;
 	}
 
-	if (i40e_is_40G_device(hw->device_id))
+	if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types))
 		/* For XL710 */
 		dev_info->speed_capa = ETH_LINK_SPEED_40G;
 	else
@@ -2873,7 +2879,7 @@  i40e_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
 	if (err < 0)
 		return -ENOSYS;
 
-	if (i40e_is_40G_device(hw->device_id)) {
+	if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) {
 		/* Configure flow control refresh threshold,
 		 * the value for stat_tx_pause_refresh_timer[8]
 		 * is used for global pause operation.
@@ -8055,6 +8061,23 @@  i40e_pctype_to_flowtype(enum i40e_filter_pctype pctype)
 #define I40E_GL_SWR_PM_UP_THR_SF_VALUE   0x06060606
 #define I40E_GL_SWR_PM_UP_THR            0x269FBC
 
+static int
+i40e_dev_sync_phy_type(struct i40e_hw *hw)
+{
+	enum i40e_status_code status;
+	struct i40e_aq_get_phy_abilities_resp phy_ab;
+	int ret = -ENOTSUP;
+
+	status = i40e_aq_get_phy_capabilities(hw, false, true, &phy_ab,
+					      NULL);
+
+	if (status)
+		return ret;
+
+	return 0;
+}
+
+
 static void
 i40e_configure_registers(struct i40e_hw *hw)
 {
@@ -8072,7 +8095,7 @@  i40e_configure_registers(struct i40e_hw *hw)
 
 	for (i = 0; i < RTE_DIM(reg_table); i++) {
 		if (reg_table[i].addr == I40E_GL_SWR_PM_UP_THR) {
-			if (i40e_is_40G_device(hw->device_id)) /* For XL710 */
+			if (I40E_PHY_TYPE_SUPPORT_40G(hw->phy.phy_types)) /* For XL710 */
 				reg_table[i].val =
 					I40E_GL_SWR_PM_UP_THR_SF_VALUE;
 			else /* For X710 */
diff --git a/drivers/net/i40e/i40e_ethdev.h b/drivers/net/i40e/i40e_ethdev.h
index 92c8fad..9b6b03c 100644
--- a/drivers/net/i40e/i40e_ethdev.h
+++ b/drivers/net/i40e/i40e_ethdev.h
@@ -712,4 +712,12 @@  i40e_calc_itr_interval(int16_t interval)
 	(pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER || \
 	(pctype) == I40E_FILTER_PCTYPE_L2_PAYLOAD)
 
+#define I40E_PHY_TYPE_SUPPORT_40G(phy_type) \
+	(((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_KR4) || \
+	((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU) || \
+	((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_AOC) || \
+	((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_CR4) || \
+	((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_SR4) || \
+	((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_LR4))
+
 #endif /* _I40E_ETHDEV_H_ */