net/cxgbe: support updating RSS hash configuration and key
[dpdk.git] / drivers / net / cxgbe / cxgbe_ethdev.c
index 7b7bfdf..b67dcb7 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2014-2016 Chelsio Communications.
+ *   Copyright(c) 2014-2017 Chelsio Communications.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
 #include <rte_log.h>
 #include <rte_debug.h>
 #include <rte_pci.h>
+#include <rte_bus_pci.h>
 #include <rte_atomic.h>
 #include <rte_branch_prediction.h>
 #include <rte_memory.h>
-#include <rte_memzone.h>
 #include <rte_tailq.h>
 #include <rte_eal.h>
 #include <rte_alarm.h>
 #include <rte_ether.h>
-#include <rte_ethdev.h>
-#include <rte_atomic.h>
+#include <rte_ethdev_driver.h>
+#include <rte_ethdev_pci.h>
 #include <rte_malloc.h>
 #include <rte_random.h>
 #include <rte_dev.h>
@@ -68,7 +68,7 @@
  * Macros needed to support the PCI Device ID Table ...
  */
 #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
-       static struct rte_pci_id cxgb4_pci_tbl[] = {
+       static const struct rte_pci_id cxgb4_pci_tbl[] = {
 #define CH_PCI_DEVICE_ID_FUNCTION 0x4
 
 #define PCI_VENDOR_ID_CHELSIO 0x1425
@@ -103,7 +103,8 @@ static uint16_t cxgbe_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
                pkts_remain = nb_pkts - total_sent;
 
                for (pkts_sent = 0; pkts_sent < pkts_remain; pkts_sent++) {
-                       ret = t4_eth_xmit(txq, tx_pkts[total_sent + pkts_sent]);
+                       ret = t4_eth_xmit(txq, tx_pkts[total_sent + pkts_sent],
+                                         nb_pkts);
                        if (ret < 0)
                                break;
                }
@@ -147,6 +148,8 @@ static void cxgbe_dev_info_get(struct rte_eth_dev *eth_dev,
                .nb_align = 1,
        };
 
+       device_info->pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+
        device_info->min_rx_bufsize = CXGBE_MIN_RX_BUFSIZE;
        device_info->max_rx_pktlen = CXGBE_MAX_RX_PKTLEN;
        device_info->max_rx_queues = max_queues;
@@ -168,10 +171,12 @@ static void cxgbe_dev_info_get(struct rte_eth_dev *eth_dev,
                                       DEV_TX_OFFLOAD_TCP_TSO;
 
        device_info->reta_size = pi->rss_size;
+       device_info->hash_key_size = CXGBE_DEFAULT_RSS_KEY_LEN;
+       device_info->flow_type_rss_offloads = CXGBE_RSS_HF_ALL;
 
        device_info->rx_desc_lim = cxgbe_desc_lim;
        device_info->tx_desc_lim = cxgbe_desc_lim;
-       device_info->speed_capa = ETH_LINK_SPEED_10G | ETH_LINK_SPEED_40G;
+       cxgbe_get_speed_caps(pi, &device_info->speed_capa);
 }
 
 static void cxgbe_dev_promiscuous_enable(struct rte_eth_dev *eth_dev)
@@ -335,6 +340,8 @@ static int cxgbe_dev_start(struct rte_eth_dev *eth_dev)
                        goto out;
        }
 
+       cxgbe_enable_rx_queues(pi);
+
        err = setup_rss(pi);
        if (err)
                goto out;
@@ -614,7 +621,7 @@ static int cxgbe_dev_rx_queue_setup(struct rte_eth_dev *eth_dev,
 
        err = t4_sge_alloc_rxq(adapter, &rxq->rspq, false, eth_dev, msi_idx,
                               &rxq->fl, t4_ethrx_handler,
-                              t4_get_mps_bg_map(adapter, pi->tx_chan), mp,
+                              t4_get_tp_ch_map(adapter, pi->tx_chan), mp,
                               queue_idx, socket_id);
 
        dev_debug(adapter, "%s: err = %d; port_id = %d; cntxt_id = %u\n",
@@ -642,7 +649,7 @@ static void cxgbe_dev_rx_queue_release(void *q)
 /*
  * Get port statistics.
  */
-static void cxgbe_dev_stats_get(struct rte_eth_dev *eth_dev,
+static int cxgbe_dev_stats_get(struct rte_eth_dev *eth_dev,
                                struct rte_eth_stats *eth_stats)
 {
        struct port_info *pi = (struct port_info *)(eth_dev->data->dev_private);
@@ -654,8 +661,6 @@ static void cxgbe_dev_stats_get(struct rte_eth_dev *eth_dev,
        cxgbe_stats_get(pi, &ps);
 
        /* RX Stats */
-       eth_stats->ipackets = ps.rx_frames;
-       eth_stats->ibytes   = ps.rx_octets;
        eth_stats->imissed  = ps.rx_ovflow0 + ps.rx_ovflow1 +
                              ps.rx_ovflow2 + ps.rx_ovflow3 +
                              ps.rx_trunc0 + ps.rx_trunc1 +
@@ -675,6 +680,8 @@ static void cxgbe_dev_stats_get(struct rte_eth_dev *eth_dev,
 
                eth_stats->q_ipackets[i] = rxq->stats.pkts;
                eth_stats->q_ibytes[i] = rxq->stats.rx_bytes;
+               eth_stats->ipackets += eth_stats->q_ipackets[i];
+               eth_stats->ibytes += eth_stats->q_ibytes[i];
        }
 
        for (i = 0; i < pi->n_tx_qsets; i++) {
@@ -685,6 +692,7 @@ static void cxgbe_dev_stats_get(struct rte_eth_dev *eth_dev,
                eth_stats->q_obytes[i] = txq->stats.tx_bytes;
                eth_stats->q_errors[i] = txq->stats.mapping_err;
        }
+       return 0;
 }
 
 /*
@@ -781,6 +789,36 @@ cxgbe_dev_supported_ptypes_get(struct rte_eth_dev *eth_dev)
        return NULL;
 }
 
+/* Update RSS hash configuration
+ */
+static int cxgbe_dev_rss_hash_update(struct rte_eth_dev *dev,
+                                    struct rte_eth_rss_conf *rss_conf)
+{
+       struct port_info *pi = (struct port_info *)(dev->data->dev_private);
+       struct adapter *adapter = pi->adapter;
+       int err;
+
+       err = cxgbe_write_rss_conf(pi, rss_conf->rss_hf);
+       if (err)
+               return err;
+
+       pi->rss_hf = rss_conf->rss_hf;
+
+       if (rss_conf->rss_key) {
+               u32 key[10], mod_key[10];
+               int i, j;
+
+               memcpy(key, rss_conf->rss_key, CXGBE_DEFAULT_RSS_KEY_LEN);
+
+               for (i = 9, j = 0; i >= 0; i--, j++)
+                       mod_key[j] = cpu_to_be32(key[i]);
+
+               t4_write_rss_key(adapter, mod_key, -1);
+       }
+
+       return 0;
+}
+
 static int cxgbe_get_eeprom_length(struct rte_eth_dev *dev)
 {
        RTE_SET_USED(dev);
@@ -979,6 +1017,7 @@ static const struct eth_dev_ops cxgbe_eth_dev_ops = {
        .get_eeprom             = cxgbe_get_eeprom,
        .set_eeprom             = cxgbe_set_eeprom,
        .get_reg                = cxgbe_get_regs,
+       .rss_hash_update        = cxgbe_dev_rss_hash_update,
 };
 
 /*
@@ -998,14 +1037,33 @@ static int eth_cxgbe_dev_init(struct rte_eth_dev *eth_dev)
        eth_dev->dev_ops = &cxgbe_eth_dev_ops;
        eth_dev->rx_pkt_burst = &cxgbe_recv_pkts;
        eth_dev->tx_pkt_burst = &cxgbe_xmit_pkts;
+       pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
-       /* for secondary processes, we don't initialise any further as primary
-        * has already done this work.
+       /* for secondary processes, we attach to ethdevs allocated by primary
+        * and do minimal initialization.
         */
-       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
+               int i;
+
+               for (i = 1; i < MAX_NPORTS; i++) {
+                       struct rte_eth_dev *rest_eth_dev;
+                       char namei[RTE_ETH_NAME_MAX_LEN];
+
+                       snprintf(namei, sizeof(namei), "%s_%d",
+                                pci_dev->device.name, i);
+                       rest_eth_dev = rte_eth_dev_attach_secondary(namei);
+                       if (rest_eth_dev) {
+                               rest_eth_dev->device = &pci_dev->device;
+                               rest_eth_dev->dev_ops =
+                                       eth_dev->dev_ops;
+                               rest_eth_dev->rx_pkt_burst =
+                                       eth_dev->rx_pkt_burst;
+                               rest_eth_dev->tx_pkt_burst =
+                                       eth_dev->tx_pkt_burst;
+                       }
+               }
                return 0;
-
-       pci_dev = eth_dev->pci_dev;
+       }
 
        snprintf(name, sizeof(name), "cxgbeadapter%d", eth_dev->data->port_id);
        adapter = rte_zmalloc(name, sizeof(*adapter), 0);
@@ -1037,35 +1095,25 @@ out_free_adapter:
        return err;
 }
 
-static struct eth_driver rte_cxgbe_pmd = {
-       .pci_drv = {
-               .name = "rte_cxgbe_pmd",
-               .id_table = cxgb4_pci_tbl,
-               .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
-       },
-       .eth_dev_init = eth_cxgbe_dev_init,
-       .dev_private_size = sizeof(struct port_info),
-};
-
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI CXGBE devices.
- */
-static int rte_cxgbe_pmd_init(const char *name __rte_unused,
-                             const char *params __rte_unused)
+static int eth_cxgbe_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+       struct rte_pci_device *pci_dev)
 {
-       CXGBE_FUNC_TRACE();
+       return rte_eth_dev_pci_generic_probe(pci_dev,
+               sizeof(struct port_info), eth_cxgbe_dev_init);
+}
 
-       rte_eth_driver_register(&rte_cxgbe_pmd);
-       return 0;
+static int eth_cxgbe_pci_remove(struct rte_pci_device *pci_dev)
+{
+       return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
 }
 
-static struct rte_driver rte_cxgbe_driver = {
-       .type = PMD_PDEV,
-       .init = rte_cxgbe_pmd_init,
+static struct rte_pci_driver rte_cxgbe_pmd = {
+       .id_table = cxgb4_pci_tbl,
+       .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
+       .probe = eth_cxgbe_pci_probe,
+       .remove = eth_cxgbe_pci_remove,
 };
 
-PMD_REGISTER_DRIVER(rte_cxgbe_driver, net_cxgbe);
-DRIVER_REGISTER_PCI_TABLE(net_cxgbe, cxgb4_pci_tbl);
-
+RTE_PMD_REGISTER_PCI(net_cxgbe, rte_cxgbe_pmd);
+RTE_PMD_REGISTER_PCI_TABLE(net_cxgbe, cxgb4_pci_tbl);
+RTE_PMD_REGISTER_KMOD_DEP(net_cxgbe, "* igb_uio | uio_pci_generic | vfio-pci");