[dpdk-dev] i40e: configure MTU
Commit Message
This patch enables configuring MTU for i40e.
Since changing MTU needs to reconfigure queue, stop port first
before configuring MTU.
Signed-off-by: Beilei Xing <beilei.xing@intel.com>
---
drivers/net/i40e/i40e_ethdev.c | 49 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
Comments
On 4/23/2016 7:26 PM, Xing, Beilei wrote:
> This patch enables configuring MTU for i40e.
> Since changing MTU needs to reconfigure queue, stop port first
> before configuring MTU.
>
> Signed-off-by: Beilei Xing <beilei.xing@intel.com>
> ---
> drivers/net/i40e/i40e_ethdev.c | 49 ++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 49 insertions(+)
>
> diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
> index bc28d3c..29259b9 100644
> --- a/drivers/net/i40e/i40e_ethdev.c
> +++ b/drivers/net/i40e/i40e_ethdev.c
> @@ -447,6 +447,8 @@ static int i40e_get_eeprom(struct rte_eth_dev *dev,
> static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
> struct ether_addr *mac_addr);
>
> +static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
> +
> static const struct rte_pci_id pci_id_i40e_map[] = {
> #define RTE_PCI_DEV_ID_DECL_I40E(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
> #include "rte_pci_dev_ids.h"
> @@ -520,6 +522,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = {
> .get_eeprom_length = i40e_get_eeprom_length,
> .get_eeprom = i40e_get_eeprom,
> .mac_addr_set = i40e_set_default_mac_addr,
> + .mtu_set = i40e_dev_mtu_set,
> };
>
> /* store statistics names and its offset in stats structure */
> @@ -9104,3 +9107,49 @@ static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
> /* Flags: 0x3 updates port address */
> i40e_aq_mac_address_write(hw, 0x3, mac_addr->addr_bytes, NULL);
> }
> +
> +static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
According to the coding style, at function definition, "The function
type should be on a line by itself preceding the function."
> +{
> + struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
> + struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
> + struct rte_eth_dev_data *dev_data = pf->dev_data;
> + struct rte_eth_dev_info dev_info;
> + struct i40e_rx_queue *rxq;
> + int i;
> + uint16_t len;
> + uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
> + int ret = 0;
> +
> + i40e_dev_info_get(dev, &dev_info);
> +
> + /* check if mtu is within the allowed range */
> + if ((mtu < ETHER_MIN_MTU) || (frame_size > dev_info.max_rx_pktlen))
> + return -EINVAL;
> +
The dev_info.max_rx_pktlen queried by i40e_dev_info_get is
"I40E_FRAME_SIZE_MAX".
No need to call the API to get dev info in driver.
Hello,
On 04/23/2016 01:26 PM, Beilei Xing wrote:
[...]
> + /* mtu setting is forbidden if port is start */
> + if (dev_data->dev_started) {
> + PMD_DRV_LOG(ERR,
> + "port %d must be stopped before configuration\n",
> + dev_data->port_id);
> + return -EBUSY;
> + }
According to rte_ethdev.h, only 4 return codes are supported for
rte_eth_dev_set_mtu:
* - (0) if successful.
* - (-ENOTSUP) if operation is not supported.
* - (-ENODEV) if *port_id* invalid.
* - (-EINVAL) if *mtu* invalid.
EBUSY should not be returned.
> + for (i = 0; i < dev_data->nb_rx_queues; i++) {
> + rxq = dev_data->rx_queues[i];
> + if (!rxq || !rxq->q_set)
> + continue;
> +
> + dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
> + len = hw->func_caps.rx_buf_chain_len * rxq->rx_buf_len;
> + rxq->max_pkt_len = RTE_MIN(len, frame_size);
> + }
> +
> + ret = i40e_dev_rx_init(pf);
> +
> + return ret;
> +}
>
Why do want to reconfigure rxq here ? All these operations are already
done when you call i40e_dev_rx_init.
i40e_dev_rx_init => i40e_rx_queue_init (for each queue) =>
i40e_rx_queue_config => redefine rxq->max_pkt_len
Moreover, you should move dev_data->dev_conf.rxmode.max_rx_pkt_len out
of the loop. frame_size is the same for all rx_queues.
> -----Original Message-----
> From: Julien Meunier [mailto:julien.meunier@6wind.com]
> Sent: Wednesday, April 27, 2016 7:44 PM
> To: Xing, Beilei <beilei.xing@intel.com>; Wu, Jingjing <jingjing.wu@intel.com>
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] i40e: configure MTU
>
> Hello,
>
> On 04/23/2016 01:26 PM, Beilei Xing wrote:
> [...]
> > + /* mtu setting is forbidden if port is start */
> > + if (dev_data->dev_started) {
> > + PMD_DRV_LOG(ERR,
> > + "port %d must be stopped before configuration\n",
> > + dev_data->port_id);
> > + return -EBUSY;
> > + }
>
> According to rte_ethdev.h, only 4 return codes are supported for
> rte_eth_dev_set_mtu:
>
> * - (0) if successful.
> * - (-ENOTSUP) if operation is not supported.
> * - (-ENODEV) if *port_id* invalid.
> * - (-EINVAL) if *mtu* invalid.
>
> EBUSY should not be returned.
Hi Meunier,
Thanks for your comments, it shouldn't be EBUSY here.
>
> > + for (i = 0; i < dev_data->nb_rx_queues; i++) {
> > + rxq = dev_data->rx_queues[i];
> > + if (!rxq || !rxq->q_set)
> > + continue;
> > +
> > + dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
> > + len = hw->func_caps.rx_buf_chain_len * rxq->rx_buf_len;
> > + rxq->max_pkt_len = RTE_MIN(len, frame_size);
> > + }
> > +
> > + ret = i40e_dev_rx_init(pf);
> > +
> > + return ret;
> > +}
> >
>
> Why do want to reconfigure rxq here ? All these operations are already done
> when you call i40e_dev_rx_init.
> i40e_dev_rx_init => i40e_rx_queue_init (for each queue) =>
> i40e_rx_queue_config => redefine rxq->max_pkt_len
>
> Moreover, you should move dev_data->dev_conf.rxmode.max_rx_pkt_len out
> of the loop. frame_size is the same for all rx_queues.
Yes, you're right, needn't reconfigure rxq->max_pkt_len here, I just need reconfigure dev_data->dev_conf.rxmode.max_rx_pkt_len cause i40e_dev_rx_init will cover all.
Thanks very much.
Beilei
>
> --
> Julien MEUNIER
> 6WIND
@@ -447,6 +447,8 @@ static int i40e_get_eeprom(struct rte_eth_dev *dev,
static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
struct ether_addr *mac_addr);
+static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
+
static const struct rte_pci_id pci_id_i40e_map[] = {
#define RTE_PCI_DEV_ID_DECL_I40E(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
#include "rte_pci_dev_ids.h"
@@ -520,6 +522,7 @@ static const struct eth_dev_ops i40e_eth_dev_ops = {
.get_eeprom_length = i40e_get_eeprom_length,
.get_eeprom = i40e_get_eeprom,
.mac_addr_set = i40e_set_default_mac_addr,
+ .mtu_set = i40e_dev_mtu_set,
};
/* store statistics names and its offset in stats structure */
@@ -9104,3 +9107,49 @@ static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
/* Flags: 0x3 updates port address */
i40e_aq_mac_address_write(hw, 0x3, mac_addr->addr_bytes, NULL);
}
+
+static int i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+{
+ struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+ struct i40e_hw *hw = I40E_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+ struct rte_eth_dev_data *dev_data = pf->dev_data;
+ struct rte_eth_dev_info dev_info;
+ struct i40e_rx_queue *rxq;
+ int i;
+ uint16_t len;
+ uint32_t frame_size = mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
+ int ret = 0;
+
+ i40e_dev_info_get(dev, &dev_info);
+
+ /* check if mtu is within the allowed range */
+ if ((mtu < ETHER_MIN_MTU) || (frame_size > dev_info.max_rx_pktlen))
+ return -EINVAL;
+
+ /* mtu setting is forbidden if port is start */
+ if (dev_data->dev_started) {
+ PMD_DRV_LOG(ERR,
+ "port %d must be stopped before configuration\n",
+ dev_data->port_id);
+ return -EBUSY;
+ }
+
+ if (frame_size > ETHER_MAX_LEN)
+ dev_data->dev_conf.rxmode.jumbo_frame = 1;
+ else
+ dev_data->dev_conf.rxmode.jumbo_frame = 0;
+
+ for (i = 0; i < dev_data->nb_rx_queues; i++) {
+ rxq = dev_data->rx_queues[i];
+ if (!rxq || !rxq->q_set)
+ continue;
+
+ dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
+ len = hw->func_caps.rx_buf_chain_len * rxq->rx_buf_len;
+ rxq->max_pkt_len = RTE_MIN(len, frame_size);
+ }
+
+ ret = i40e_dev_rx_init(pf);
+
+ return ret;
+}