Implement xsc ethdev configure and RSS hash functions.

Signed-off-by: WanRenyong <wa...@yunsilicon.com>
---
 doc/guides/nics/features/xsc.ini |   3 +
 drivers/net/xsc/xsc_defs.h       |  15 +++++
 drivers/net/xsc/xsc_dev.c        |  26 ++++++++
 drivers/net/xsc/xsc_dev.h        |   1 +
 drivers/net/xsc/xsc_ethdev.c     | 106 +++++++++++++++++++++++++++++++
 drivers/net/xsc/xsc_ethdev.h     |   7 ++
 6 files changed, 158 insertions(+)

diff --git a/doc/guides/nics/features/xsc.ini b/doc/guides/nics/features/xsc.ini
index b5c44ce535..bdeb7a984b 100644
--- a/doc/guides/nics/features/xsc.ini
+++ b/doc/guides/nics/features/xsc.ini
@@ -4,6 +4,9 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+RSS hash             = Y
+RSS key update       = Y
+RSS reta update      = Y
 Linux                = Y
 ARMv8                = Y
 x86-64               = Y
diff --git a/drivers/net/xsc/xsc_defs.h b/drivers/net/xsc/xsc_defs.h
index 111776f37e..c445eadca1 100644
--- a/drivers/net/xsc/xsc_defs.h
+++ b/drivers/net/xsc/xsc_defs.h
@@ -78,4 +78,19 @@ enum xsc_port_type {
        XSC_PORT_TYPE_UNKNOWN,
 };
 
+enum xsc_tbm_cap {
+       XSC_TBM_CAP_HASH_PPH = 0,
+       XSC_TBM_CAP_RSS,
+       XSC_TBM_CAP_PP_BYPASS,
+       XSC_TBM_CAP_PCT_DROP_CONFIG,
+};
+
+enum xsc_rss_hf {
+       XSC_RSS_HASH_KEY_UPDATE = 0,
+       XSC_RSS_HASH_TEMP_UPDATE,
+       XSC_RSS_HASH_FUNC_UPDATE,
+       XSC_RSS_RXQ_UPDATE,
+       XSC_RSS_RXQ_DROP,
+};
+
 #endif /* XSC_DEFS_H_ */
diff --git a/drivers/net/xsc/xsc_dev.c b/drivers/net/xsc/xsc_dev.c
index 71d7ab7ea4..84bab2bb93 100644
--- a/drivers/net/xsc/xsc_dev.c
+++ b/drivers/net/xsc/xsc_dev.c
@@ -19,6 +19,7 @@
 #include "xsc_log.h"
 #include "xsc_defs.h"
 #include "xsc_dev.h"
+#include "xsc_cmd.h"
 
 #define XSC_DEV_DEF_FLOW_MODE  7
 
@@ -74,6 +75,31 @@ xsc_dev_close(struct xsc_dev *xdev, int repr_id)
        return xdev->dev_ops->dev_close(xdev);
 }
 
+int
+xsc_dev_rss_key_modify(struct xsc_dev *xdev, uint8_t *rss_key, uint8_t 
rss_key_len)
+{
+       struct xsc_cmd_modify_nic_hca_mbox_in in = {};
+       struct xsc_cmd_modify_nic_hca_mbox_out out = {};
+       uint8_t rss_caps_mask = 0;
+       int ret, key_len = 0;
+
+       in.hdr.opcode = rte_cpu_to_be_16(XSC_CMD_OP_MODIFY_NIC_HCA);
+
+       key_len = RTE_MIN(rss_key_len, XSC_RSS_HASH_KEY_LEN);
+       rte_memcpy(in.rss.hash_key, rss_key, key_len);
+       rss_caps_mask |= RTE_BIT32(XSC_RSS_HASH_KEY_UPDATE);
+
+       in.rss.caps_mask = rss_caps_mask;
+       in.rss.rss_en = 1;
+       in.nic.caps_mask = rte_cpu_to_be_16(RTE_BIT32(XSC_TBM_CAP_RSS));
+       in.nic.caps = in.nic.caps_mask;
+
+       ret = xsc_dev_mailbox_exec(xdev, &in, sizeof(in), &out, sizeof(out));
+       if (ret != 0 || out.hdr.status != 0)
+               return -1;
+       return 0;
+}
+
 static int
 xsc_dev_alloc_vfos_info(struct xsc_dev *xdev)
 {
diff --git a/drivers/net/xsc/xsc_dev.h b/drivers/net/xsc/xsc_dev.h
index 9010225a20..3bebb18b98 100644
--- a/drivers/net/xsc/xsc_dev.h
+++ b/drivers/net/xsc/xsc_dev.h
@@ -162,6 +162,7 @@ int xsc_dev_init(struct rte_pci_device *pci_dev, struct 
xsc_dev **dev);
 void xsc_dev_uninit(struct xsc_dev *xdev);
 int xsc_dev_close(struct xsc_dev *xdev, int repr_id);
 int xsc_dev_repr_ports_probe(struct xsc_dev *xdev, int nb_repr_ports, int 
max_eth_ports);
+int xsc_dev_rss_key_modify(struct xsc_dev *xdev, uint8_t *rss_key, uint8_t 
rss_key_len);
 bool xsc_dev_is_vf(struct xsc_dev *xdev);
 int xsc_dev_qp_set_id_get(struct xsc_dev *xdev, int repr_id);
 int xsc_dev_get_mac(struct xsc_dev *xdev, uint8_t *mac);
diff --git a/drivers/net/xsc/xsc_ethdev.c b/drivers/net/xsc/xsc_ethdev.c
index 9fc5464754..81ac062862 100644
--- a/drivers/net/xsc/xsc_ethdev.c
+++ b/drivers/net/xsc/xsc_ethdev.c
@@ -9,6 +9,105 @@
 #include "xsc_defs.h"
 #include "xsc_ethdev.h"
 
+static int
+xsc_ethdev_rss_hash_conf_get(struct rte_eth_dev *dev,
+                            struct rte_eth_rss_conf *rss_conf)
+{
+       struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+
+       if (!rss_conf) {
+               rte_errno = EINVAL;
+               return -rte_errno;
+       }
+
+       if (rss_conf->rss_key != NULL && rss_conf->rss_key_len >= 
priv->rss_conf.rss_key_len)
+               memcpy(rss_conf->rss_key, priv->rss_conf.rss_key, 
priv->rss_conf.rss_key_len);
+
+       rss_conf->rss_key_len = priv->rss_conf.rss_key_len;
+       rss_conf->rss_hf = priv->rss_conf.rss_hf;
+       return 0;
+}
+
+static int
+xsc_ethdev_rss_hash_update(struct rte_eth_dev *dev,
+                          struct rte_eth_rss_conf *rss_conf)
+{
+       struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+       int ret = 0;
+
+       if (rss_conf->rss_key_len > XSC_RSS_HASH_KEY_LEN || rss_conf->rss_key 
== NULL) {
+               PMD_DRV_LOG(ERR, "Xsc pmd key len is %d bigger than %d",
+                           rss_conf->rss_key_len, XSC_RSS_HASH_KEY_LEN);
+               return -EINVAL;
+       }
+
+       ret = xsc_dev_rss_key_modify(priv->xdev, rss_conf->rss_key, 
rss_conf->rss_key_len);
+       if (ret == 0) {
+               rte_memcpy(priv->rss_conf.rss_key, rss_conf->rss_key,
+                          priv->rss_conf.rss_key_len);
+               priv->rss_conf.rss_key_len = rss_conf->rss_key_len;
+               priv->rss_conf.rss_hf = rss_conf->rss_hf;
+       }
+
+       return ret;
+}
+
+static int
+xsc_ethdev_configure(struct rte_eth_dev *dev)
+{
+       struct xsc_ethdev_priv *priv = TO_XSC_ETHDEV_PRIV(dev);
+       struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
+       int ret;
+       struct rte_eth_rss_conf *rss_conf;
+
+       priv->num_sq = dev->data->nb_tx_queues;
+       priv->num_rq = dev->data->nb_rx_queues;
+
+       if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
+               dev->data->dev_conf.rxmode.offloads |= 
RTE_ETH_RX_OFFLOAD_RSS_HASH;
+
+       if (priv->rss_conf.rss_key == NULL) {
+               priv->rss_conf.rss_key = rte_zmalloc(NULL, XSC_RSS_HASH_KEY_LEN,
+                                                    RTE_CACHE_LINE_SIZE);
+               if (priv->rss_conf.rss_key == NULL) {
+                       PMD_DRV_LOG(ERR, "Failed to alloc rss key");
+                       rte_errno = ENOMEM;
+                       ret = -rte_errno;
+                       goto error;
+               }
+               priv->rss_conf.rss_key_len = XSC_RSS_HASH_KEY_LEN;
+       }
+
+       if (dev->data->dev_conf.rx_adv_conf.rss_conf.rss_key != NULL) {
+               rss_conf = &dev->data->dev_conf.rx_adv_conf.rss_conf;
+               ret = xsc_ethdev_rss_hash_update(dev, rss_conf);
+               if (ret != 0) {
+                       PMD_DRV_LOG(ERR, "Xsc pmd set rss key error!");
+                       rte_errno = -ENOEXEC;
+                       goto error;
+               }
+       }
+
+       if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
+               PMD_DRV_LOG(ERR, "Xsc pmd do not support vlan filter now!");
+               rte_errno = EINVAL;
+               goto error;
+       }
+
+       if (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) {
+               PMD_DRV_LOG(ERR, "Xsc pmd do not support vlan strip now!");
+               rte_errno = EINVAL;
+               goto error;
+       }
+
+       priv->txqs = (void *)dev->data->tx_queues;
+       priv->rxqs = (void *)dev->data->rx_queues;
+       return 0;
+
+error:
+       return -rte_errno;
+}
+
 static int
 xsc_ethdev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, 
uint32_t index)
 {
@@ -35,6 +134,12 @@ xsc_ethdev_mac_addr_add(struct rte_eth_dev *dev, struct 
rte_ether_addr *mac, uin
        return 0;
 }
 
+const struct eth_dev_ops xsc_eth_dev_ops = {
+       .dev_configure = xsc_ethdev_configure,
+       .rss_hash_update = xsc_ethdev_rss_hash_update,
+       .rss_hash_conf_get = xsc_ethdev_rss_hash_conf_get,
+};
+
 static int
 xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, void *init_params)
 {
@@ -89,6 +194,7 @@ xsc_ethdev_init_one_representor(struct rte_eth_dev *eth_dev, 
void *init_params)
                eth_dev->data->backer_port_id = eth_dev->data->port_id;
        }
 
+       eth_dev->dev_ops = &xsc_eth_dev_ops;
        eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
        eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
 
diff --git a/drivers/net/xsc/xsc_ethdev.h b/drivers/net/xsc/xsc_ethdev.h
index 7d161bd22e..bc0fc54d50 100644
--- a/drivers/net/xsc/xsc_ethdev.h
+++ b/drivers/net/xsc/xsc_ethdev.h
@@ -30,6 +30,13 @@ struct xsc_ethdev_priv {
 
        uint16_t eth_type;
        uint16_t qp_set_id;
+
+       uint16_t num_sq;
+       uint16_t num_rq;
+
+       uint16_t flags;
+       struct xsc_txq_data *(*txqs)[];
+       struct xsc_rxq_data *(*rxqs)[];
 };
 
 #define TO_XSC_ETHDEV_PRIV(dev) ((struct xsc_ethdev_priv 
*)(dev)->data->dev_private)
-- 
2.25.1

Reply via email to