mlx5: support flow control
authorAdrien Mazarguil <adrien.mazarguil@6wind.com>
Fri, 30 Oct 2015 18:52:39 +0000 (19:52 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Fri, 30 Oct 2015 21:34:21 +0000 (22:34 +0100)
Like most other device control operations, those are handled by the related
kernel network device through syscalls.

Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_ethdev.c

index 5ed828d..c454e93 100644 (file)
@@ -145,6 +145,8 @@ static const struct eth_dev_ops mlx5_dev_ops = {
        .tx_queue_setup = mlx5_tx_queue_setup,
        .rx_queue_release = mlx5_rx_queue_release,
        .tx_queue_release = mlx5_tx_queue_release,
+       .flow_ctrl_get = mlx5_dev_get_flow_ctrl,
+       .flow_ctrl_set = mlx5_dev_set_flow_ctrl,
        .mac_addr_remove = mlx5_mac_addr_remove,
        .mac_addr_add = mlx5_mac_addr_add,
        .mtu_set = mlx5_dev_set_mtu,
index 1a18326..c6c3d3f 100644 (file)
@@ -166,6 +166,8 @@ int mlx5_dev_configure(struct rte_eth_dev *);
 void mlx5_dev_infos_get(struct rte_eth_dev *, struct rte_eth_dev_info *);
 int mlx5_link_update(struct rte_eth_dev *, int);
 int mlx5_dev_set_mtu(struct rte_eth_dev *, uint16_t);
+int mlx5_dev_get_flow_ctrl(struct rte_eth_dev *, struct rte_eth_fc_conf *);
+int mlx5_dev_set_flow_ctrl(struct rte_eth_dev *, struct rte_eth_fc_conf *);
 int mlx5_ibv_device_to_pci_addr(const struct ibv_device *,
                                struct rte_pci_addr *);
 
index d01dee5..5df5fa1 100644 (file)
@@ -694,6 +694,105 @@ out:
        return -ret;
 }
 
+/**
+ * DPDK callback to get flow control status.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param[out] fc_conf
+ *   Flow control output buffer.
+ *
+ * @return
+ *   0 on success, negative errno value on failure.
+ */
+int
+mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
+{
+       struct priv *priv = dev->data->dev_private;
+       struct ifreq ifr;
+       struct ethtool_pauseparam ethpause = {
+               .cmd = ETHTOOL_GPAUSEPARAM
+       };
+       int ret;
+
+       ifr.ifr_data = &ethpause;
+       priv_lock(priv);
+       if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
+               ret = errno;
+               WARN("ioctl(SIOCETHTOOL, ETHTOOL_GPAUSEPARAM)"
+                    " failed: %s",
+                    strerror(ret));
+               goto out;
+       }
+
+       fc_conf->autoneg = ethpause.autoneg;
+       if (ethpause.rx_pause && ethpause.tx_pause)
+               fc_conf->mode = RTE_FC_FULL;
+       else if (ethpause.rx_pause)
+               fc_conf->mode = RTE_FC_RX_PAUSE;
+       else if (ethpause.tx_pause)
+               fc_conf->mode = RTE_FC_TX_PAUSE;
+       else
+               fc_conf->mode = RTE_FC_NONE;
+       ret = 0;
+
+out:
+       priv_unlock(priv);
+       assert(ret >= 0);
+       return -ret;
+}
+
+/**
+ * DPDK callback to modify flow control parameters.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ * @param[in] fc_conf
+ *   Flow control parameters.
+ *
+ * @return
+ *   0 on success, negative errno value on failure.
+ */
+int
+mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
+{
+       struct priv *priv = dev->data->dev_private;
+       struct ifreq ifr;
+       struct ethtool_pauseparam ethpause = {
+               .cmd = ETHTOOL_SPAUSEPARAM
+       };
+       int ret;
+
+       ifr.ifr_data = &ethpause;
+       ethpause.autoneg = fc_conf->autoneg;
+       if (((fc_conf->mode & RTE_FC_FULL) == RTE_FC_FULL) ||
+           (fc_conf->mode & RTE_FC_RX_PAUSE))
+               ethpause.rx_pause = 1;
+       else
+               ethpause.rx_pause = 0;
+
+       if (((fc_conf->mode & RTE_FC_FULL) == RTE_FC_FULL) ||
+           (fc_conf->mode & RTE_FC_TX_PAUSE))
+               ethpause.tx_pause = 1;
+       else
+               ethpause.tx_pause = 0;
+
+       priv_lock(priv);
+       if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
+               ret = errno;
+               WARN("ioctl(SIOCETHTOOL, ETHTOOL_SPAUSEPARAM)"
+                    " failed: %s",
+                    strerror(ret));
+               goto out;
+       }
+       ret = 0;
+
+out:
+       priv_unlock(priv);
+       assert(ret >= 0);
+       return -ret;
+}
+
 /**
  * Get PCI information from struct ibv_device.
  *