xref: /dpdk/drivers/net/sfc/sfc_dp.h (revision f55fe01f88a6802f27df96d78a489306370406a4)
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			dbells;
55 
56 	uint16_t			port_id;
57 	uint16_t			queue_id;
58 	struct rte_pci_addr		pci_addr;
59 };
60 
61 void sfc_dp_queue_init(struct sfc_dp_queue *dpq,
62 		       uint16_t port_id, uint16_t queue_id,
63 		       const struct rte_pci_addr *pci_addr);
64 
65 /* Maximum datapath log level to be included in build. */
66 #ifndef SFC_DP_LOG_LEVEL
67 #define SFC_DP_LOG_LEVEL	RTE_LOG_NOTICE
68 #endif
69 
70 /*
71  * Helper macro to define datapath logging macros and have uniform
72  * logging.
73  */
74 #define SFC_DP_LOG(dp_name, level, dpq, ...) \
75 	do {								\
76 		const struct sfc_dp_queue *_dpq = (dpq);		\
77 		const struct rte_pci_addr *_addr = &(_dpq)->pci_addr;	\
78 									\
79 		if (RTE_LOG_ ## level > SFC_DP_LOG_LEVEL)		\
80 			break;						\
81 		SFC_GENERIC_LOG(level,					\
82 			RTE_FMT("%s " PCI_PRI_FMT			\
83 				" #%" PRIu16 ".%" PRIu16 ": "		\
84 				RTE_FMT_HEAD(__VA_ARGS__ ,),		\
85 				dp_name,				\
86 				_addr->domain, _addr->bus,		\
87 				_addr->devid, _addr->function,		\
88 				_dpq->port_id, _dpq->queue_id,		\
89 				RTE_FMT_TAIL(__VA_ARGS__,)));		\
90 	} while (0)
91 
92 
93 /** Datapath definition */
94 struct sfc_dp {
95 	TAILQ_ENTRY(sfc_dp)		links;
96 	const char			*name;
97 	enum sfc_dp_type		type;
98 	/* Mask of required hardware/firmware capabilities */
99 	unsigned int			hw_fw_caps;
100 #define SFC_DP_HW_FW_CAP_EF10				0x1
101 #define SFC_DP_HW_FW_CAP_RX_ES_SUPER_BUFFER		0x2
102 #define SFC_DP_HW_FW_CAP_RX_EFX				0x4
103 #define SFC_DP_HW_FW_CAP_TX_EFX				0x8
104 #define SFC_DP_HW_FW_CAP_EF100				0x10
105 };
106 
107 /** List of datapath variants */
108 TAILQ_HEAD(sfc_dp_list, sfc_dp);
109 
110 typedef unsigned int sfc_sw_index_t;
111 #define SFC_SW_INDEX_INVALID	((sfc_sw_index_t)(UINT_MAX))
112 
113 typedef int32_t	sfc_ethdev_qid_t;
114 #define SFC_ETHDEV_QID_INVALID	((sfc_ethdev_qid_t)(-1))
115 
116 /* Check if available HW/FW capabilities are sufficient for the datapath */
117 static inline bool
sfc_dp_match_hw_fw_caps(const struct sfc_dp * dp,unsigned int avail_caps)118 sfc_dp_match_hw_fw_caps(const struct sfc_dp *dp, unsigned int avail_caps)
119 {
120 	return (dp->hw_fw_caps & avail_caps) == dp->hw_fw_caps;
121 }
122 
123 struct sfc_dp *sfc_dp_find_by_name(struct sfc_dp_list *head,
124 				   enum sfc_dp_type type, const char *name);
125 struct sfc_dp *sfc_dp_find_by_caps(struct sfc_dp_list *head,
126 				   enum sfc_dp_type type,
127 				   unsigned int avail_caps);
128 int sfc_dp_register(struct sfc_dp_list *head, struct sfc_dp *entry);
129 
130 /**
131  * Dynamically registered mbuf flag "mport_override" (as a bitmask).
132  *
133  * If this flag is set in an mbuf then the dynamically registered
134  * mbuf field "mport" holds a valid value. This is used to direct
135  * port representor transmit traffic to the correct target port.
136  */
137 extern uint64_t sfc_dp_mport_override;
138 
139 /**
140  * Dynamically registered mbuf field "mport" (mbuf byte offset).
141  *
142  * If the dynamically registered "mport_override" flag is set in
143  * an mbuf then the mbuf "mport" field holds a valid value. This
144  * is used to direct port representor transmit traffic to the
145  * correct target port.
146  */
147 extern int sfc_dp_mport_offset;
148 
149 /**
150  * Register dynamic mbuf flag and field which can be used to require Tx override
151  * prefix descriptor with egress mport set.
152  */
153 int sfc_dp_mport_register(void);
154 
155 /** Dynamically registered mbuf "ft_ctx_id" validity flag (as a bitmask). */
156 extern uint64_t sfc_dp_ft_ctx_id_valid;
157 
158 /** Dynamically registered mbuf field "ft_ctx_id" (mbuf byte offset). */
159 extern int sfc_dp_ft_ctx_id_offset;
160 
161 /** Register dynamic mbuf field "ft_ctx_id" and its validity flag. */
162 int sfc_dp_ft_ctx_id_register(void);
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 #endif /* _SFC_DP_H */
168