net/sfc: add simple port representor statistics
[dpdk.git] / drivers / net / sfc / sfc_dp.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2021 Xilinx, Inc.
4  * Copyright(c) 2017-2019 Solarflare Communications Inc.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9
10 #ifndef _SFC_DP_H
11 #define _SFC_DP_H
12
13 #include <stdbool.h>
14 #include <sys/queue.h>
15
16 #include <rte_pci.h>
17
18 #include "sfc_log.h"
19 #include "sfc_stats.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 #define SFC_DIV_ROUND_UP(a, b) \
26         __extension__ ({                \
27                 typeof(a) _a = (a);     \
28                 typeof(b) _b = (b);     \
29                                         \
30                 (_a + (_b - 1)) / _b;   \
31         })
32
33 /**
34  * Datapath exception handler to be provided by the control path.
35  */
36 typedef void (sfc_dp_exception_t)(void *ctrl);
37
38 enum sfc_dp_type {
39         SFC_DP_RX = 0,  /**< Receive datapath */
40         SFC_DP_TX,      /**< Transmit datapath */
41 };
42
43
44 /** Datapath queue run-time information */
45 struct sfc_dp_queue {
46         /*
47          * Typically the structure is located at the end of Rx/Tx queue
48          * data structure and not used on datapath. So, it is not a
49          * problem to have extra fields even if not used. However,
50          * put stats at top of the structure to be closer to fields
51          * used on datapath or reap to have more chances to be cache-hot.
52          */
53         union sfc_pkts_bytes            stats;
54         uint32_t                        rx_dbells;
55         uint32_t                        tx_dbells;
56
57         uint16_t                        port_id;
58         uint16_t                        queue_id;
59         struct rte_pci_addr             pci_addr;
60 };
61
62 void sfc_dp_queue_init(struct sfc_dp_queue *dpq,
63                        uint16_t port_id, uint16_t queue_id,
64                        const struct rte_pci_addr *pci_addr);
65
66 /* Maximum datapath log level to be included in build. */
67 #ifndef SFC_DP_LOG_LEVEL
68 #define SFC_DP_LOG_LEVEL        RTE_LOG_NOTICE
69 #endif
70
71 /*
72  * Helper macro to define datapath logging macros and have uniform
73  * logging.
74  */
75 #define SFC_DP_LOG(dp_name, level, dpq, ...) \
76         do {                                                            \
77                 const struct sfc_dp_queue *_dpq = (dpq);                \
78                 const struct rte_pci_addr *_addr = &(_dpq)->pci_addr;   \
79                                                                         \
80                 if (RTE_LOG_ ## level > SFC_DP_LOG_LEVEL)               \
81                         break;                                          \
82                 SFC_GENERIC_LOG(level,                                  \
83                         RTE_FMT("%s " PCI_PRI_FMT                       \
84                                 " #%" PRIu16 ".%" PRIu16 ": "           \
85                                 RTE_FMT_HEAD(__VA_ARGS__ ,),            \
86                                 dp_name,                                \
87                                 _addr->domain, _addr->bus,              \
88                                 _addr->devid, _addr->function,          \
89                                 _dpq->port_id, _dpq->queue_id,          \
90                                 RTE_FMT_TAIL(__VA_ARGS__,)));           \
91         } while (0)
92
93
94 /** Datapath definition */
95 struct sfc_dp {
96         TAILQ_ENTRY(sfc_dp)             links;
97         const char                      *name;
98         enum sfc_dp_type                type;
99         /* Mask of required hardware/firmware capabilities */
100         unsigned int                    hw_fw_caps;
101 #define SFC_DP_HW_FW_CAP_EF10                           0x1
102 #define SFC_DP_HW_FW_CAP_RX_ES_SUPER_BUFFER             0x2
103 #define SFC_DP_HW_FW_CAP_RX_EFX                         0x4
104 #define SFC_DP_HW_FW_CAP_TX_EFX                         0x8
105 #define SFC_DP_HW_FW_CAP_EF100                          0x10
106 };
107
108 /** List of datapath variants */
109 TAILQ_HEAD(sfc_dp_list, sfc_dp);
110
111 typedef unsigned int sfc_sw_index_t;
112 #define SFC_SW_INDEX_INVALID    ((sfc_sw_index_t)(UINT_MAX))
113
114 typedef int32_t sfc_ethdev_qid_t;
115 #define SFC_ETHDEV_QID_INVALID  ((sfc_ethdev_qid_t)(-1))
116
117 /* Check if available HW/FW capabilities are sufficient for the datapath */
118 static inline bool
119 sfc_dp_match_hw_fw_caps(const struct sfc_dp *dp, unsigned int avail_caps)
120 {
121         return (dp->hw_fw_caps & avail_caps) == dp->hw_fw_caps;
122 }
123
124 struct sfc_dp *sfc_dp_find_by_name(struct sfc_dp_list *head,
125                                    enum sfc_dp_type type, const char *name);
126 struct sfc_dp *sfc_dp_find_by_caps(struct sfc_dp_list *head,
127                                    enum sfc_dp_type type,
128                                    unsigned int avail_caps);
129 int sfc_dp_register(struct sfc_dp_list *head, struct sfc_dp *entry);
130
131 /**
132  * Dynamically registered mbuf flag "mport_override" (as a bitmask).
133  *
134  * If this flag is set in an mbuf then the dynamically registered
135  * mbuf field "mport" holds a valid value. This is used to direct
136  * port representor transmit traffic to the correct target port.
137  */
138 extern uint64_t sfc_dp_mport_override;
139
140 /**
141  * Dynamically registered mbuf field "mport" (mbuf byte offset).
142  *
143  * If the dynamically registered "mport_override" flag is set in
144  * an mbuf then the mbuf "mport" field holds a valid value. This
145  * is used to direct port representor transmit traffic to the
146  * correct target port.
147  */
148 extern int sfc_dp_mport_offset;
149
150 /**
151  * Register dynamic mbuf flag and field which can be used to require Tx override
152  * prefix descriptor with egress mport set.
153  */
154 int sfc_dp_mport_register(void);
155
156 #ifdef __cplusplus
157 }
158 #endif
159 #endif /* _SFC_DP_H */