net/dpaa: fix max push mode queue
[dpdk.git] / drivers / net / dpaa / dpaa_ethdev.c
index 444c122..636ed55 100644 (file)
@@ -28,7 +28,7 @@
 #include <rte_eal.h>
 #include <rte_alarm.h>
 #include <rte_ether.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
 #include <rte_malloc.h>
 #include <rte_ring.h>
 
 #include <fsl_bman.h>
 #include <fsl_fman.h>
 
+/* Supported Rx offloads */
+static uint64_t dev_rx_offloads_sup =
+               DEV_RX_OFFLOAD_JUMBO_FRAME;
+
+/* Rx offloads which cannot be disabled */
+static uint64_t dev_rx_offloads_nodis =
+               DEV_RX_OFFLOAD_IPV4_CKSUM |
+               DEV_RX_OFFLOAD_UDP_CKSUM |
+               DEV_RX_OFFLOAD_TCP_CKSUM |
+               DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
+               DEV_RX_OFFLOAD_CRC_STRIP |
+               DEV_RX_OFFLOAD_SCATTER;
+
+/* Supported Tx offloads */
+static uint64_t dev_tx_offloads_sup;
+
+/* Tx offloads which cannot be disabled */
+static uint64_t dev_tx_offloads_nodis =
+               DEV_TX_OFFLOAD_IPV4_CKSUM |
+               DEV_TX_OFFLOAD_UDP_CKSUM |
+               DEV_TX_OFFLOAD_TCP_CKSUM |
+               DEV_TX_OFFLOAD_SCTP_CKSUM |
+               DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
+               DEV_TX_OFFLOAD_MULTI_SEGS |
+               DEV_TX_OFFLOAD_MT_LOCKFREE |
+               DEV_TX_OFFLOAD_MBUF_FAST_FREE;
+
 /* Keep track of whether QMAN and BMAN have been globally initialized */
 static int is_global_init;
-/* At present we only allow up to 4 push mode queues - as each of this queue
- * need dedicated portal and we are short of portals.
+/* At present we only allow up to 4 push mode queues as default - as each of
+ * this queue need dedicated portal and we are short of portals.
  */
-#define DPAA_MAX_PUSH_MODE_QUEUE       4
+#define DPAA_MAX_PUSH_MODE_QUEUE       8
+#define DPAA_DEFAULT_PUSH_MODE_QUEUE   4
 
-static int dpaa_push_mode_max_queue = DPAA_MAX_PUSH_MODE_QUEUE;
+static int dpaa_push_mode_max_queue = DPAA_DEFAULT_PUSH_MODE_QUEUE;
 static int dpaa_push_queue_idx; /* Queue index which are in push mode*/
 
 
@@ -95,6 +123,24 @@ static const struct rte_dpaa_xstats_name_off dpaa_xstats_strings[] = {
 
 static struct rte_dpaa_driver rte_dpaa_pmd;
 
+static void
+dpaa_eth_dev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info);
+
+static inline void
+dpaa_poll_queue_default_config(struct qm_mcc_initfq *opts)
+{
+       memset(opts, 0, sizeof(struct qm_mcc_initfq));
+       opts->we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_CONTEXTA;
+       opts->fqd.fq_ctrl = QM_FQCTRL_AVOIDBLOCK | QM_FQCTRL_CTXASTASHING |
+                          QM_FQCTRL_PREFERINCACHE;
+       opts->fqd.context_a.stashing.exclusive = 0;
+       if (dpaa_svr_family != SVR_LS1046A_FAMILY)
+               opts->fqd.context_a.stashing.annotation_cl =
+                                               DPAA_IF_RX_ANNOTATION_STASH;
+       opts->fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
+       opts->fqd.context_a.stashing.context_cl = DPAA_IF_RX_CONTEXT_STASH;
+}
+
 static int
 dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 {
@@ -107,9 +153,11 @@ dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        if (mtu < ETHER_MIN_MTU || frame_size > DPAA_MAX_RX_PKT_LEN)
                return -EINVAL;
        if (frame_size > ETHER_MAX_LEN)
-               dev->data->dev_conf.rxmode.jumbo_frame = 1;
+               dev->data->dev_conf.rxmode.offloads &=
+                                               DEV_RX_OFFLOAD_JUMBO_FRAME;
        else
-               dev->data->dev_conf.rxmode.jumbo_frame = 0;
+               dev->data->dev_conf.rxmode.offloads &=
+                                               ~DEV_RX_OFFLOAD_JUMBO_FRAME;
 
        dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
 
@@ -119,13 +167,48 @@ dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 }
 
 static int
-dpaa_eth_dev_configure(struct rte_eth_dev *dev __rte_unused)
+dpaa_eth_dev_configure(struct rte_eth_dev *dev)
 {
        struct dpaa_if *dpaa_intf = dev->data->dev_private;
+       struct rte_eth_conf *eth_conf = &dev->data->dev_conf;
+       uint64_t rx_offloads = eth_conf->rxmode.offloads;
+       uint64_t tx_offloads = eth_conf->txmode.offloads;
 
        PMD_INIT_FUNC_TRACE();
 
-       if (dev->data->dev_conf.rxmode.jumbo_frame == 1) {
+       /* Rx offloads validation */
+       if (~(dev_rx_offloads_sup | dev_rx_offloads_nodis) & rx_offloads) {
+               DPAA_PMD_ERR(
+               "Rx offloads non supported - requested 0x%" PRIx64
+               " supported 0x%" PRIx64,
+                       rx_offloads,
+                       dev_rx_offloads_sup | dev_rx_offloads_nodis);
+               return -ENOTSUP;
+       }
+       if (dev_rx_offloads_nodis & ~rx_offloads) {
+               DPAA_PMD_WARN(
+               "Rx offloads non configurable - requested 0x%" PRIx64
+               " ignored 0x%" PRIx64,
+                       rx_offloads, dev_rx_offloads_nodis);
+       }
+
+       /* Tx offloads validation */
+       if (~(dev_tx_offloads_sup | dev_tx_offloads_nodis) & tx_offloads) {
+               DPAA_PMD_ERR(
+               "Tx offloads non supported - requested 0x%" PRIx64
+               " supported 0x%" PRIx64,
+                       tx_offloads,
+                       dev_tx_offloads_sup | dev_tx_offloads_nodis);
+               return -ENOTSUP;
+       }
+       if (dev_tx_offloads_nodis & ~tx_offloads) {
+               DPAA_PMD_WARN(
+               "Tx offloads non configurable - requested 0x%" PRIx64
+               " ignored 0x%" PRIx64,
+                       tx_offloads, dev_tx_offloads_nodis);
+       }
+
+       if (rx_offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
                if (dev->data->dev_conf.rxmode.max_rx_pkt_len <=
                    DPAA_MAX_RX_PKT_LEN) {
                        fman_if_set_maxfrm(dpaa_intf->fif,
@@ -241,14 +324,10 @@ static void dpaa_eth_dev_info(struct rte_eth_dev *dev,
        dev_info->flow_type_rss_offloads = DPAA_RSS_OFFLOAD_ALL;
        dev_info->speed_capa = (ETH_LINK_SPEED_1G |
                                ETH_LINK_SPEED_10G);
-       dev_info->rx_offload_capa =
-               (DEV_RX_OFFLOAD_IPV4_CKSUM |
-               DEV_RX_OFFLOAD_UDP_CKSUM   |
-               DEV_RX_OFFLOAD_TCP_CKSUM);
-       dev_info->tx_offload_capa =
-               (DEV_TX_OFFLOAD_IPV4_CKSUM  |
-               DEV_TX_OFFLOAD_UDP_CKSUM   |
-               DEV_TX_OFFLOAD_TCP_CKSUM);
+       dev_info->rx_offload_capa = dev_rx_offloads_sup |
+                                       dev_rx_offloads_nodis;
+       dev_info->tx_offload_capa = dev_tx_offloads_sup |
+                                       dev_tx_offloads_nodis;
 }
 
 static int dpaa_eth_link_update(struct rte_eth_dev *dev,
@@ -260,9 +339,9 @@ static int dpaa_eth_link_update(struct rte_eth_dev *dev,
        PMD_INIT_FUNC_TRACE();
 
        if (dpaa_intf->fif->mac_type == fman_mac_1g)
-               link->link_speed = 1000;
+               link->link_speed = ETH_SPEED_NUM_1G;
        else if (dpaa_intf->fif->mac_type == fman_mac_10g)
-               link->link_speed = 10000;
+               link->link_speed = ETH_SPEED_NUM_10G;
        else
                DPAA_PMD_ERR("invalid link_speed: %s, %d",
                             dpaa_intf->name, dpaa_intf->fif->mac_type);
@@ -301,12 +380,12 @@ dpaa_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
        unsigned int i = 0, num = RTE_DIM(dpaa_xstats_strings);
        uint64_t values[sizeof(struct dpaa_if_stats) / 8];
 
-       if (xstats == NULL)
-               return 0;
-
        if (n < num)
                return num;
 
+       if (xstats == NULL)
+               return 0;
+
        fman_if_stats_get_all(dpaa_intf->fif, values,
                              sizeof(struct dpaa_if_stats) / 8);
 
@@ -320,10 +399,13 @@ dpaa_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
 static int
 dpaa_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
                      struct rte_eth_xstat_name *xstats_names,
-                     __rte_unused unsigned int limit)
+                     unsigned int limit)
 {
        unsigned int i, stat_cnt = RTE_DIM(dpaa_xstats_strings);
 
+       if (limit < stat_cnt)
+               return stat_cnt;
+
        if (xstats_names != NULL)
                for (i = 0; i < stat_cnt; i++)
                        snprintf(xstats_names[i].name,
@@ -351,7 +433,7 @@ dpaa_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
                        return 0;
 
                fman_if_stats_get_all(dpaa_intf->fif, values_copy,
-                                     sizeof(struct dpaa_if_stats));
+                                     sizeof(struct dpaa_if_stats) / 8);
 
                for (i = 0; i < stat_cnt; i++)
                        values[i] =
@@ -488,7 +570,11 @@ int dpaa_eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
                                   QM_FQCTRL_CTXASTASHING |
                                   QM_FQCTRL_PREFERINCACHE;
                opts.fqd.context_a.stashing.exclusive = 0;
-               opts.fqd.context_a.stashing.annotation_cl =
+               /* In muticore scenario stashing becomes a bottleneck on LS1046.
+                * So do not enable stashing in this case
+                */
+               if (dpaa_svr_family != SVR_LS1046A_FAMILY)
+                       opts.fqd.context_a.stashing.annotation_cl =
                                                DPAA_IF_RX_ANNOTATION_STASH;
                opts.fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
                opts.fqd.context_a.stashing.context_cl =
@@ -511,7 +597,8 @@ int dpaa_eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
                if (ret)
                        DPAA_PMD_ERR("Channel/Queue association failed. fqid %d"
                                     " ret: %d", rxq->fqid, ret);
-               rxq->cb.dqrr_dpdk_cb = dpaa_rx_cb;
+               rxq->cb.dqrr_dpdk_pull_cb = dpaa_rx_cb;
+               rxq->cb.dqrr_prepare = dpaa_rx_cb_prepare;
                rxq->is_static = true;
        }
        dev->data->rx_queues[queue_idx] = rxq;
@@ -533,6 +620,99 @@ int dpaa_eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
        return 0;
 }
 
+int __rte_experimental
+dpaa_eth_eventq_attach(const struct rte_eth_dev *dev,
+               int eth_rx_queue_id,
+               u16 ch_id,
+               const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
+{
+       int ret;
+       u32 flags = 0;
+       struct dpaa_if *dpaa_intf = dev->data->dev_private;
+       struct qman_fq *rxq = &dpaa_intf->rx_queues[eth_rx_queue_id];
+       struct qm_mcc_initfq opts = {0};
+
+       if (dpaa_push_mode_max_queue)
+               DPAA_PMD_WARN("PUSH mode already enabled for first %d queues.\n"
+                             "To disable set DPAA_PUSH_QUEUES_NUMBER to 0\n",
+                             dpaa_push_mode_max_queue);
+
+       dpaa_poll_queue_default_config(&opts);
+
+       switch (queue_conf->ev.sched_type) {
+       case RTE_SCHED_TYPE_ATOMIC:
+               opts.fqd.fq_ctrl |= QM_FQCTRL_HOLDACTIVE;
+               /* Reset FQCTRL_AVOIDBLOCK bit as it is unnecessary
+                * configuration with HOLD_ACTIVE setting
+                */
+               opts.fqd.fq_ctrl &= (~QM_FQCTRL_AVOIDBLOCK);
+               rxq->cb.dqrr_dpdk_cb = dpaa_rx_cb_atomic;
+               break;
+       case RTE_SCHED_TYPE_ORDERED:
+               DPAA_PMD_ERR("Ordered queue schedule type is not supported\n");
+               return -1;
+       default:
+               opts.fqd.fq_ctrl |= QM_FQCTRL_AVOIDBLOCK;
+               rxq->cb.dqrr_dpdk_cb = dpaa_rx_cb_parallel;
+               break;
+       }
+
+       opts.we_mask = opts.we_mask | QM_INITFQ_WE_DESTWQ;
+       opts.fqd.dest.channel = ch_id;
+       opts.fqd.dest.wq = queue_conf->ev.priority;
+
+       if (dpaa_intf->cgr_rx) {
+               opts.we_mask |= QM_INITFQ_WE_CGID;
+               opts.fqd.cgid = dpaa_intf->cgr_rx[eth_rx_queue_id].cgrid;
+               opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
+       }
+
+       flags = QMAN_INITFQ_FLAG_SCHED;
+
+       ret = qman_init_fq(rxq, flags, &opts);
+       if (ret) {
+               DPAA_PMD_ERR("Channel/Queue association failed. fqid %d ret:%d",
+                            rxq->fqid, ret);
+               return ret;
+       }
+
+       /* copy configuration which needs to be filled during dequeue */
+       memcpy(&rxq->ev, &queue_conf->ev, sizeof(struct rte_event));
+       dev->data->rx_queues[eth_rx_queue_id] = rxq;
+
+       return ret;
+}
+
+int __rte_experimental
+dpaa_eth_eventq_detach(const struct rte_eth_dev *dev,
+               int eth_rx_queue_id)
+{
+       struct qm_mcc_initfq opts;
+       int ret;
+       u32 flags = 0;
+       struct dpaa_if *dpaa_intf = dev->data->dev_private;
+       struct qman_fq *rxq = &dpaa_intf->rx_queues[eth_rx_queue_id];
+
+       dpaa_poll_queue_default_config(&opts);
+
+       if (dpaa_intf->cgr_rx) {
+               opts.we_mask |= QM_INITFQ_WE_CGID;
+               opts.fqd.cgid = dpaa_intf->cgr_rx[eth_rx_queue_id].cgrid;
+               opts.fqd.fq_ctrl |= QM_FQCTRL_CGE;
+       }
+
+       ret = qman_init_fq(rxq, flags, &opts);
+       if (ret) {
+               DPAA_PMD_ERR("init rx fqid %d failed with ret: %d",
+                            rxq->fqid, ret);
+       }
+
+       rxq->cb.dqrr_dpdk_cb = NULL;
+       dev->data->rx_queues[eth_rx_queue_id] = NULL;
+
+       return 0;
+}
+
 static
 void dpaa_eth_rx_queue_release(void *rxq __rte_unused)
 {
@@ -700,7 +880,7 @@ dpaa_dev_remove_mac_addr(struct rte_eth_dev *dev,
        fman_if_clear_mac_addr(dpaa_intf->fif, index);
 }
 
-static void
+static int
 dpaa_dev_set_mac_addr(struct rte_eth_dev *dev,
                       struct ether_addr *addr)
 {
@@ -712,6 +892,8 @@ dpaa_dev_set_mac_addr(struct rte_eth_dev *dev,
        ret = fman_if_add_mac_addr(dpaa_intf->fif, addr->addr_bytes, 0);
        if (ret)
                RTE_LOG(ERR, PMD, "error: Setting the MAC ADDR failed %d", ret);
+
+       return ret;
 }
 
 static struct eth_dev_ops dpaa_devops = {
@@ -769,7 +951,7 @@ is_dpaa_supported(struct rte_eth_dev *dev)
        return is_device_supported(dev, &rte_dpaa_pmd);
 }
 
-int
+int __rte_experimental
 rte_pmd_dpaa_set_tx_loopback(uint8_t port, uint8_t on)
 {
        struct rte_eth_dev *dev;
@@ -853,13 +1035,8 @@ static int dpaa_rx_queue_init(struct qman_fq *fq, struct qman_cgr *cgr_rx,
                return ret;
        }
        fq->is_static = false;
-       opts.we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_CONTEXTA;
-       opts.fqd.fq_ctrl = QM_FQCTRL_AVOIDBLOCK | QM_FQCTRL_CTXASTASHING |
-                          QM_FQCTRL_PREFERINCACHE;
-       opts.fqd.context_a.stashing.exclusive = 0;
-       opts.fqd.context_a.stashing.annotation_cl = DPAA_IF_RX_ANNOTATION_STASH;
-       opts.fqd.context_a.stashing.data_cl = DPAA_IF_RX_DATA_STASH;
-       opts.fqd.context_a.stashing.context_cl = DPAA_IF_RX_CONTEXT_STASH;
+
+       dpaa_poll_queue_default_config(&opts);
 
        if (cgr_rx) {
                /* Enable tail drop with cgr on this queue */
@@ -997,26 +1174,36 @@ dpaa_dev_init(struct rte_eth_dev *eth_dev)
                        dpaa_push_mode_max_queue = DPAA_MAX_PUSH_MODE_QUEUE;
        }
 
-       /* Each device can not have more than DPAA_PCD_FQID_MULTIPLIER RX
+       /* Each device can not have more than DPAA_MAX_NUM_PCD_QUEUES RX
         * queues.
         */
-       if (num_rx_fqs <= 0 || num_rx_fqs > DPAA_PCD_FQID_MULTIPLIER) {
+       if (num_rx_fqs <= 0 || num_rx_fqs > DPAA_MAX_NUM_PCD_QUEUES) {
                DPAA_PMD_ERR("Invalid number of RX queues\n");
                return -EINVAL;
        }
 
        dpaa_intf->rx_queues = rte_zmalloc(NULL,
                sizeof(struct qman_fq) * num_rx_fqs, MAX_CACHELINE);
+       if (!dpaa_intf->rx_queues) {
+               DPAA_PMD_ERR("Failed to alloc mem for RX queues\n");
+               return -ENOMEM;
+       }
 
        /* If congestion control is enabled globally*/
        if (td_threshold) {
                dpaa_intf->cgr_rx = rte_zmalloc(NULL,
                        sizeof(struct qman_cgr) * num_rx_fqs, MAX_CACHELINE);
+               if (!dpaa_intf->cgr_rx) {
+                       DPAA_PMD_ERR("Failed to alloc mem for cgr_rx\n");
+                       ret = -ENOMEM;
+                       goto free_rx;
+               }
 
                ret = qman_alloc_cgrid_range(&cgrid[0], num_rx_fqs, 1, 0);
                if (ret != num_rx_fqs) {
                        DPAA_PMD_WARN("insufficient CGRIDs available");
-                       return -EINVAL;
+                       ret = -EINVAL;
+                       goto free_rx;
                }
        } else {
                dpaa_intf->cgr_rx = NULL;
@@ -1033,23 +1220,26 @@ dpaa_dev_init(struct rte_eth_dev *eth_dev)
                        dpaa_intf->cgr_rx ? &dpaa_intf->cgr_rx[loop] : NULL,
                        fqid);
                if (ret)
-                       return ret;
+                       goto free_rx;
                dpaa_intf->rx_queues[loop].dpaa_intf = dpaa_intf;
        }
        dpaa_intf->nb_rx_queues = num_rx_fqs;
 
-       /* Initialise Tx FQs. Have as many Tx FQ's as number of cores */
+       /* Initialise Tx FQs.free_rx Have as many Tx FQ's as number of cores */
        num_cores = rte_lcore_count();
        dpaa_intf->tx_queues = rte_zmalloc(NULL, sizeof(struct qman_fq) *
                num_cores, MAX_CACHELINE);
-       if (!dpaa_intf->tx_queues)
-               return -ENOMEM;
+       if (!dpaa_intf->tx_queues) {
+               DPAA_PMD_ERR("Failed to alloc mem for TX queues\n");
+               ret = -ENOMEM;
+               goto free_rx;
+       }
 
        for (loop = 0; loop < num_cores; loop++) {
                ret = dpaa_tx_queue_init(&dpaa_intf->tx_queues[loop],
                                         fman_intf);
                if (ret)
-                       return ret;
+                       goto free_tx;
                dpaa_intf->tx_queues[loop].dpaa_intf = dpaa_intf;
        }
        dpaa_intf->nb_tx_queues = num_cores;
@@ -1086,14 +1276,8 @@ dpaa_dev_init(struct rte_eth_dev *eth_dev)
                DPAA_PMD_ERR("Failed to allocate %d bytes needed to "
                                                "store MAC addresses",
                                ETHER_ADDR_LEN * DPAA_MAX_MAC_FILTER);
-               rte_free(dpaa_intf->cgr_rx);
-               rte_free(dpaa_intf->rx_queues);
-               rte_free(dpaa_intf->tx_queues);
-               dpaa_intf->rx_queues = NULL;
-               dpaa_intf->tx_queues = NULL;
-               dpaa_intf->nb_rx_queues = 0;
-               dpaa_intf->nb_tx_queues = 0;
-               return -ENOMEM;
+               ret = -ENOMEM;
+               goto free_tx;
        }
 
        /* copy the primary mac address */
@@ -1119,6 +1303,18 @@ dpaa_dev_init(struct rte_eth_dev *eth_dev)
        fman_if_stats_reset(fman_intf);
 
        return 0;
+
+free_tx:
+       rte_free(dpaa_intf->tx_queues);
+       dpaa_intf->tx_queues = NULL;
+       dpaa_intf->nb_tx_queues = 0;
+
+free_rx:
+       rte_free(dpaa_intf->cgr_rx);
+       rte_free(dpaa_intf->rx_queues);
+       dpaa_intf->rx_queues = NULL;
+       dpaa_intf->nb_rx_queues = 0;
+       return ret;
 }
 
 static int
@@ -1211,10 +1407,12 @@ rte_dpaa_probe(struct rte_dpaa_driver *dpaa_drv,
                is_global_init = 1;
        }
 
-       ret = rte_dpaa_portal_init((void *)1);
-       if (ret) {
-               DPAA_PMD_ERR("Unable to initialize portal");
-               return ret;
+       if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
+               ret = rte_dpaa_portal_init((void *)1);
+               if (ret) {
+                       DPAA_PMD_ERR("Unable to initialize portal");
+                       return ret;
+               }
        }
 
        eth_dev = rte_eth_dev_allocate(dpaa_dev->name);