net/softnic: restructure
[dpdk.git] / drivers / net / softnic / rte_eth_softnic_internals.h
index 08a633f..6ae5954 100644 (file)
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2017 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2017 Intel Corporation
  */
 
 #ifndef __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
 #define __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__
 
+#include <stddef.h>
 #include <stdint.h>
 
 #include <rte_mbuf.h>
 #include <rte_ethdev.h>
+#include <rte_sched.h>
+#include <rte_ethdev_driver.h>
+#include <rte_tm_driver.h>
 
 #include "rte_eth_softnic.h"
 
-#ifndef INTRUSIVE
-#define INTRUSIVE                                      0
-#endif
+/**
+ * PMD Parameters
+ */
 
 struct pmd_params {
-       /** Parameters for the soft device (to be created) */
-       struct {
-               const char *name; /**< Name */
-               uint32_t flags; /**< Flags */
-
-               /** 0 = Access hard device though API only (potentially slower,
-                *      but safer);
-                *  1 = Access hard device private data structures is allowed
-                *      (potentially faster).
-                */
-               int intrusive;
-       } soft;
+       const char *name;
+       const char *firmware;
+       uint32_t cpu_id;
 
-       /** Parameters for the hard device (existing) */
+       /** Traffic Management (TM) */
        struct {
-               char *name; /**< Name */
-               uint16_t tx_queue_id; /**< TX queue ID */
-       } hard;
+               uint32_t n_queues; /**< Number of queues */
+               uint16_t qsize[RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE];
+       } tm;
 };
 
 /**
- * Default Internals
+ * Traffic Management (TM) Internals
  */
 
-#ifndef DEFAULT_BURST_SIZE
-#define DEFAULT_BURST_SIZE                             32
+#ifndef TM_MAX_SUBPORTS
+#define TM_MAX_SUBPORTS                                        8
 #endif
 
-#ifndef FLUSH_COUNT_THRESHOLD
-#define FLUSH_COUNT_THRESHOLD                  (1 << 17)
+#ifndef TM_MAX_PIPES_PER_SUBPORT
+#define TM_MAX_PIPES_PER_SUBPORT                       4096
 #endif
 
-struct default_internals {
-       struct rte_mbuf **pkts;
-       uint32_t pkts_len;
-       uint32_t txq_pos;
-       uint32_t flush_count;
+struct tm_params {
+       struct rte_sched_port_params port_params;
+
+       struct rte_sched_subport_params subport_params[TM_MAX_SUBPORTS];
+
+       struct rte_sched_pipe_params
+               pipe_profiles[RTE_SCHED_PIPE_PROFILES_PER_PORT];
+       uint32_t n_pipe_profiles;
+       uint32_t pipe_to_profile[TM_MAX_SUBPORTS * TM_MAX_PIPES_PER_SUBPORT];
+};
+
+/* TM Levels */
+enum tm_node_level {
+       TM_NODE_LEVEL_PORT = 0,
+       TM_NODE_LEVEL_SUBPORT,
+       TM_NODE_LEVEL_PIPE,
+       TM_NODE_LEVEL_TC,
+       TM_NODE_LEVEL_QUEUE,
+       TM_NODE_LEVEL_MAX,
+};
+
+/* TM Shaper Profile */
+struct tm_shaper_profile {
+       TAILQ_ENTRY(tm_shaper_profile) node;
+       uint32_t shaper_profile_id;
+       uint32_t n_users;
+       struct rte_tm_shaper_params params;
+};
+
+TAILQ_HEAD(tm_shaper_profile_list, tm_shaper_profile);
+
+/* TM Shared Shaper */
+struct tm_shared_shaper {
+       TAILQ_ENTRY(tm_shared_shaper) node;
+       uint32_t shared_shaper_id;
+       uint32_t n_users;
+       uint32_t shaper_profile_id;
+};
+
+TAILQ_HEAD(tm_shared_shaper_list, tm_shared_shaper);
+
+/* TM WRED Profile */
+struct tm_wred_profile {
+       TAILQ_ENTRY(tm_wred_profile) node;
+       uint32_t wred_profile_id;
+       uint32_t n_users;
+       struct rte_tm_wred_params params;
+};
+
+TAILQ_HEAD(tm_wred_profile_list, tm_wred_profile);
+
+/* TM Node */
+struct tm_node {
+       TAILQ_ENTRY(tm_node) node;
+       uint32_t node_id;
+       uint32_t parent_node_id;
+       uint32_t priority;
+       uint32_t weight;
+       uint32_t level;
+       struct tm_node *parent_node;
+       struct tm_shaper_profile *shaper_profile;
+       struct tm_wred_profile *wred_profile;
+       struct rte_tm_node_params params;
+       struct rte_tm_node_stats stats;
+       uint32_t n_children;
+};
+
+TAILQ_HEAD(tm_node_list, tm_node);
+
+/* TM Hierarchy Specification */
+struct tm_hierarchy {
+       struct tm_shaper_profile_list shaper_profiles;
+       struct tm_shared_shaper_list shared_shapers;
+       struct tm_wred_profile_list wred_profiles;
+       struct tm_node_list nodes;
+
+       uint32_t n_shaper_profiles;
+       uint32_t n_shared_shapers;
+       uint32_t n_wred_profiles;
+       uint32_t n_nodes;
+
+       uint32_t n_tm_nodes[TM_NODE_LEVEL_MAX];
+};
+
+struct tm_internals {
+       /** Hierarchy specification
+        *
+        *     -Hierarchy is unfrozen at init and when port is stopped.
+        *     -Hierarchy is frozen on successful hierarchy commit.
+        *     -Run-time hierarchy changes are not allowed, therefore it makes
+        *      sense to keep the hierarchy frozen after the port is started.
+        */
+       struct tm_hierarchy h;
+       int hierarchy_frozen;
+
+       /** Blueprints */
+       struct tm_params params;
+       struct rte_sched_port *sched;
 };
 
 /**
@@ -94,21 +153,31 @@ struct pmd_internals {
 
        /** Soft device */
        struct {
-               struct default_internals def; /**< Default */
+               struct tm_internals tm; /**< Traffic Management */
        } soft;
-
-       /** Hard device */
-       struct {
-               uint16_t port_id;
-       } hard;
 };
 
-struct pmd_rx_queue {
-       /** Hard device */
-       struct {
-               uint16_t port_id;
-               uint16_t rx_queue_id;
-       } hard;
-};
+/**
+ * Traffic Management (TM) Operation
+ */
+extern const struct rte_tm_ops pmd_tm_ops;
+
+int
+tm_init(struct pmd_internals *p, struct pmd_params *params, int numa_node);
+
+void
+tm_free(struct pmd_internals *p);
+
+int
+tm_start(struct pmd_internals *p);
+
+void
+tm_stop(struct pmd_internals *p);
+
+static inline int
+tm_used(struct rte_eth_dev *dev __rte_unused)
+{
+       return 0;
+}
 
 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */