144c0947bSAndrew Rybchenko /* SPDX-License-Identifier: BSD-3-Clause
2244cfa79SAndrew Rybchenko *
398d26ef7SAndrew Rybchenko * Copyright(c) 2019-2021 Xilinx, Inc.
4a0147be5SAndrew Rybchenko * Copyright(c) 2016-2019 Solarflare Communications Inc.
558294ee6SAndrew Rybchenko *
658294ee6SAndrew Rybchenko * This software was jointly developed between OKTET Labs (under contract
758294ee6SAndrew Rybchenko * for Solarflare) and Solarflare Communications, Inc.
858294ee6SAndrew Rybchenko */
958294ee6SAndrew Rybchenko
1058294ee6SAndrew Rybchenko #ifndef _SFC_EV_H_
1158294ee6SAndrew Rybchenko #define _SFC_EV_H_
1258294ee6SAndrew Rybchenko
13df96fd0dSBruce Richardson #include <ethdev_driver.h>
14dbdc8241SAndrew Rybchenko
1558294ee6SAndrew Rybchenko #include "efx.h"
1658294ee6SAndrew Rybchenko
17dbdc8241SAndrew Rybchenko #include "sfc.h"
18dbdc8241SAndrew Rybchenko
1958294ee6SAndrew Rybchenko #ifdef __cplusplus
2058294ee6SAndrew Rybchenko extern "C" {
2158294ee6SAndrew Rybchenko #endif
2258294ee6SAndrew Rybchenko
2358294ee6SAndrew Rybchenko struct sfc_adapter;
24df1bfde4SAndrew Rybchenko struct sfc_dp_rxq;
25dbdc8241SAndrew Rybchenko struct sfc_dp_txq;
2658294ee6SAndrew Rybchenko
2758294ee6SAndrew Rybchenko enum sfc_evq_state {
2858294ee6SAndrew Rybchenko SFC_EVQ_UNINITIALIZED = 0,
2958294ee6SAndrew Rybchenko SFC_EVQ_INITIALIZED,
3058294ee6SAndrew Rybchenko SFC_EVQ_STARTING,
3158294ee6SAndrew Rybchenko SFC_EVQ_STARTED,
3258294ee6SAndrew Rybchenko
3358294ee6SAndrew Rybchenko SFC_EVQ_NSTATES
3458294ee6SAndrew Rybchenko };
3558294ee6SAndrew Rybchenko
36298951a4SAndrew Rybchenko enum sfc_evq_type {
37298951a4SAndrew Rybchenko SFC_EVQ_TYPE_MGMT = 0,
38298951a4SAndrew Rybchenko SFC_EVQ_TYPE_RX,
39298951a4SAndrew Rybchenko SFC_EVQ_TYPE_TX,
40298951a4SAndrew Rybchenko
41298951a4SAndrew Rybchenko SFC_EVQ_NTYPES
42298951a4SAndrew Rybchenko };
43298951a4SAndrew Rybchenko
4458294ee6SAndrew Rybchenko struct sfc_evq {
4558294ee6SAndrew Rybchenko /* Used on datapath */
4658294ee6SAndrew Rybchenko efx_evq_t *common;
477965557eSAndrew Rybchenko const efx_ev_callbacks_t *callbacks;
4858294ee6SAndrew Rybchenko unsigned int read_ptr;
494279b54eSGeorgiy Levashov unsigned int read_ptr_primed;
5058294ee6SAndrew Rybchenko boolean_t exception;
5158294ee6SAndrew Rybchenko efsys_mem_t mem;
52df1bfde4SAndrew Rybchenko struct sfc_dp_rxq *dp_rxq;
53dbdc8241SAndrew Rybchenko struct sfc_dp_txq *dp_txq;
5458294ee6SAndrew Rybchenko
5558294ee6SAndrew Rybchenko /* Not used on datapath */
5658294ee6SAndrew Rybchenko struct sfc_adapter *sa;
5758294ee6SAndrew Rybchenko unsigned int evq_index;
5858294ee6SAndrew Rybchenko enum sfc_evq_state init_state;
59298951a4SAndrew Rybchenko enum sfc_evq_type type;
60ec9217f9SAndrew Rybchenko unsigned int entries;
6158294ee6SAndrew Rybchenko };
6258294ee6SAndrew Rybchenko
6329b133bbSIgor Romanov static inline sfc_sw_index_t
sfc_mgmt_evq_sw_index(__rte_unused const struct sfc_adapter_shared * sas)6429b133bbSIgor Romanov sfc_mgmt_evq_sw_index(__rte_unused const struct sfc_adapter_shared *sas)
6529b133bbSIgor Romanov {
6629b133bbSIgor Romanov return 0;
6729b133bbSIgor Romanov }
6829b133bbSIgor Romanov
69983ce116SIgor Romanov /* Return the number of Rx queues reserved for driver's internal use */
70983ce116SIgor Romanov static inline unsigned int
sfc_nb_reserved_rxq(const struct sfc_adapter_shared * sas)71983ce116SIgor Romanov sfc_nb_reserved_rxq(const struct sfc_adapter_shared *sas)
72983ce116SIgor Romanov {
73689a5674SIgor Romanov return sfc_nb_counter_rxq(sas) + sfc_repr_nb_rxq(sas);
74689a5674SIgor Romanov }
75689a5674SIgor Romanov
76689a5674SIgor Romanov /* Return the number of Tx queues reserved for driver's internal use */
77689a5674SIgor Romanov static inline unsigned int
sfc_nb_txq_reserved(const struct sfc_adapter_shared * sas)78689a5674SIgor Romanov sfc_nb_txq_reserved(const struct sfc_adapter_shared *sas)
79689a5674SIgor Romanov {
80689a5674SIgor Romanov return sfc_repr_nb_txq(sas);
81983ce116SIgor Romanov }
82983ce116SIgor Romanov
83983ce116SIgor Romanov static inline unsigned int
sfc_nb_reserved_evq(const struct sfc_adapter_shared * sas)84983ce116SIgor Romanov sfc_nb_reserved_evq(const struct sfc_adapter_shared *sas)
85983ce116SIgor Romanov {
86689a5674SIgor Romanov /* An EvQ is required for each reserved Rx/Tx queue */
87689a5674SIgor Romanov return 1 + sfc_nb_reserved_rxq(sas) + sfc_nb_txq_reserved(sas);
88983ce116SIgor Romanov }
89983ce116SIgor Romanov
90983ce116SIgor Romanov /*
91983ce116SIgor Romanov * The mapping functions that return SW index of a specific reserved
92983ce116SIgor Romanov * queue rely on the relative order of reserved queues. Some reserved
93983ce116SIgor Romanov * queues are optional, and if they are disabled or not supported, then
94983ce116SIgor Romanov * the function for that specific reserved queue will return previous
95983ce116SIgor Romanov * valid index of a reserved queue in the dependency chain or
96983ce116SIgor Romanov * SFC_SW_INDEX_INVALID if it is the first reserved queue in the chain.
97983ce116SIgor Romanov * If at least one of the reserved queues in the chain is enabled, then
98983ce116SIgor Romanov * the corresponding function will give valid SW index, even if previous
99983ce116SIgor Romanov * functions in the chain returned SFC_SW_INDEX_INVALID, since this value
100983ce116SIgor Romanov * is one less than the first valid SW index.
101983ce116SIgor Romanov *
102983ce116SIgor Romanov * The dependency mechanism is utilized to avoid regid defines for SW indices
103983ce116SIgor Romanov * for reserved queues and to allow these indices to shrink and make space
104983ce116SIgor Romanov * for ethdev queue indices when some of the reserved queues are disabled.
105983ce116SIgor Romanov */
106983ce116SIgor Romanov
107983ce116SIgor Romanov static inline sfc_sw_index_t
sfc_counters_rxq_sw_index(const struct sfc_adapter_shared * sas)108983ce116SIgor Romanov sfc_counters_rxq_sw_index(const struct sfc_adapter_shared *sas)
109983ce116SIgor Romanov {
110983ce116SIgor Romanov return sas->counters_rxq_allocated ? 0 : SFC_SW_INDEX_INVALID;
111983ce116SIgor Romanov }
112983ce116SIgor Romanov
113671735bbSIgor Romanov static inline sfc_sw_index_t
sfc_repr_rxq_sw_index(const struct sfc_adapter_shared * sas,unsigned int repr_queue_id)114671735bbSIgor Romanov sfc_repr_rxq_sw_index(const struct sfc_adapter_shared *sas,
115671735bbSIgor Romanov unsigned int repr_queue_id)
116671735bbSIgor Romanov {
117671735bbSIgor Romanov return sfc_counters_rxq_sw_index(sas) + sfc_repr_nb_rxq(sas) +
118671735bbSIgor Romanov repr_queue_id;
119671735bbSIgor Romanov }
120671735bbSIgor Romanov
121*58d6f89aSIgor Romanov static inline sfc_sw_index_t
sfc_repr_txq_sw_index(const struct sfc_adapter_shared * sas,unsigned int repr_queue_id)122*58d6f89aSIgor Romanov sfc_repr_txq_sw_index(const struct sfc_adapter_shared *sas,
123*58d6f89aSIgor Romanov unsigned int repr_queue_id)
124*58d6f89aSIgor Romanov {
125*58d6f89aSIgor Romanov /* Reserved TxQ for representors is the first reserved TxQ */
126*58d6f89aSIgor Romanov return sfc_repr_available(sas) ? repr_queue_id : SFC_SW_INDEX_INVALID;
127*58d6f89aSIgor Romanov }
128*58d6f89aSIgor Romanov
12958294ee6SAndrew Rybchenko /*
13058294ee6SAndrew Rybchenko * Functions below define event queue to transmit/receive queue and vice
13158294ee6SAndrew Rybchenko * versa mapping.
132983ce116SIgor Romanov * SFC_ETHDEV_QID_INVALID is returned when sw_index is converted to
133983ce116SIgor Romanov * ethdev_qid, but sw_index represents a reserved queue for driver's
134983ce116SIgor Romanov * internal use.
1356caeec47SAndrew Rybchenko * Own event queue is allocated for management, each Rx and each Tx queue.
1366caeec47SAndrew Rybchenko * Zero event queue is used for management events.
137983ce116SIgor Romanov * When counters are supported, one Rx event queue is reserved.
138689a5674SIgor Romanov * When representors are supported, Rx and Tx event queues are reserved.
139983ce116SIgor Romanov * Rx event queues follow reserved event queues.
1406caeec47SAndrew Rybchenko * Tx event queues follow Rx event queues.
14158294ee6SAndrew Rybchenko */
14258294ee6SAndrew Rybchenko
14309cafbddSIgor Romanov static inline sfc_ethdev_qid_t
sfc_ethdev_rx_qid_by_rxq_sw_index(struct sfc_adapter_shared * sas,sfc_sw_index_t rxq_sw_index)144983ce116SIgor Romanov sfc_ethdev_rx_qid_by_rxq_sw_index(struct sfc_adapter_shared *sas,
14509cafbddSIgor Romanov sfc_sw_index_t rxq_sw_index)
14609cafbddSIgor Romanov {
147983ce116SIgor Romanov if (rxq_sw_index < sfc_nb_reserved_rxq(sas))
148983ce116SIgor Romanov return SFC_ETHDEV_QID_INVALID;
149983ce116SIgor Romanov
150983ce116SIgor Romanov return rxq_sw_index - sfc_nb_reserved_rxq(sas);
15109cafbddSIgor Romanov }
15209cafbddSIgor Romanov
15309cafbddSIgor Romanov static inline sfc_sw_index_t
sfc_rxq_sw_index_by_ethdev_rx_qid(struct sfc_adapter_shared * sas,sfc_ethdev_qid_t ethdev_qid)154983ce116SIgor Romanov sfc_rxq_sw_index_by_ethdev_rx_qid(struct sfc_adapter_shared *sas,
15509cafbddSIgor Romanov sfc_ethdev_qid_t ethdev_qid)
15609cafbddSIgor Romanov {
157983ce116SIgor Romanov return sfc_nb_reserved_rxq(sas) + ethdev_qid;
15809cafbddSIgor Romanov }
15909cafbddSIgor Romanov
16009cafbddSIgor Romanov static inline sfc_sw_index_t
sfc_evq_sw_index_by_rxq_sw_index(struct sfc_adapter * sa,sfc_sw_index_t rxq_sw_index)161983ce116SIgor Romanov sfc_evq_sw_index_by_rxq_sw_index(struct sfc_adapter *sa,
16209cafbddSIgor Romanov sfc_sw_index_t rxq_sw_index)
16358294ee6SAndrew Rybchenko {
164983ce116SIgor Romanov struct sfc_adapter_shared *sas = sfc_sa2shared(sa);
165983ce116SIgor Romanov sfc_ethdev_qid_t ethdev_qid;
166983ce116SIgor Romanov
167983ce116SIgor Romanov ethdev_qid = sfc_ethdev_rx_qid_by_rxq_sw_index(sas, rxq_sw_index);
168983ce116SIgor Romanov if (ethdev_qid == SFC_ETHDEV_QID_INVALID) {
169983ce116SIgor Romanov /* One EvQ is reserved for management */
17058294ee6SAndrew Rybchenko return 1 + rxq_sw_index;
17158294ee6SAndrew Rybchenko }
17258294ee6SAndrew Rybchenko
173983ce116SIgor Romanov return sfc_nb_reserved_evq(sas) + ethdev_qid;
174983ce116SIgor Romanov }
175983ce116SIgor Romanov
176db980d26SIgor Romanov static inline sfc_ethdev_qid_t
sfc_ethdev_tx_qid_by_txq_sw_index(struct sfc_adapter_shared * sas,sfc_sw_index_t txq_sw_index)177689a5674SIgor Romanov sfc_ethdev_tx_qid_by_txq_sw_index(struct sfc_adapter_shared *sas,
178db980d26SIgor Romanov sfc_sw_index_t txq_sw_index)
179db980d26SIgor Romanov {
180689a5674SIgor Romanov if (txq_sw_index < sfc_nb_txq_reserved(sas))
181689a5674SIgor Romanov return SFC_ETHDEV_QID_INVALID;
182689a5674SIgor Romanov
183689a5674SIgor Romanov return txq_sw_index - sfc_nb_txq_reserved(sas);
184db980d26SIgor Romanov }
185db980d26SIgor Romanov
186db980d26SIgor Romanov static inline sfc_sw_index_t
sfc_txq_sw_index_by_ethdev_tx_qid(struct sfc_adapter_shared * sas,sfc_ethdev_qid_t ethdev_qid)187689a5674SIgor Romanov sfc_txq_sw_index_by_ethdev_tx_qid(struct sfc_adapter_shared *sas,
188db980d26SIgor Romanov sfc_ethdev_qid_t ethdev_qid)
189db980d26SIgor Romanov {
190689a5674SIgor Romanov return sfc_nb_txq_reserved(sas) + ethdev_qid;
191db980d26SIgor Romanov }
192db980d26SIgor Romanov
193db980d26SIgor Romanov static inline sfc_sw_index_t
sfc_evq_sw_index_by_txq_sw_index(struct sfc_adapter * sa,sfc_sw_index_t txq_sw_index)194db980d26SIgor Romanov sfc_evq_sw_index_by_txq_sw_index(struct sfc_adapter *sa,
195db980d26SIgor Romanov sfc_sw_index_t txq_sw_index)
19658294ee6SAndrew Rybchenko {
197689a5674SIgor Romanov struct sfc_adapter_shared *sas = sfc_sa2shared(sa);
198689a5674SIgor Romanov sfc_ethdev_qid_t ethdev_qid;
199689a5674SIgor Romanov
200689a5674SIgor Romanov ethdev_qid = sfc_ethdev_tx_qid_by_txq_sw_index(sas, txq_sw_index);
201689a5674SIgor Romanov if (ethdev_qid == SFC_ETHDEV_QID_INVALID) {
202689a5674SIgor Romanov return sfc_nb_reserved_evq(sas) - sfc_nb_txq_reserved(sas) +
203689a5674SIgor Romanov txq_sw_index;
204689a5674SIgor Romanov }
205689a5674SIgor Romanov
206689a5674SIgor Romanov return sfc_nb_reserved_evq(sas) + sa->eth_dev->data->nb_rx_queues +
207689a5674SIgor Romanov ethdev_qid;
20858294ee6SAndrew Rybchenko }
20958294ee6SAndrew Rybchenko
21047995190SAndrew Rybchenko int sfc_ev_attach(struct sfc_adapter *sa);
21147995190SAndrew Rybchenko void sfc_ev_detach(struct sfc_adapter *sa);
21258294ee6SAndrew Rybchenko int sfc_ev_start(struct sfc_adapter *sa);
21358294ee6SAndrew Rybchenko void sfc_ev_stop(struct sfc_adapter *sa);
21458294ee6SAndrew Rybchenko
2156caeec47SAndrew Rybchenko int sfc_ev_qinit(struct sfc_adapter *sa,
216298951a4SAndrew Rybchenko enum sfc_evq_type type, unsigned int type_index,
2176caeec47SAndrew Rybchenko unsigned int entries, int socket_id, struct sfc_evq **evqp);
2186caeec47SAndrew Rybchenko void sfc_ev_qfini(struct sfc_evq *evq);
2196caeec47SAndrew Rybchenko int sfc_ev_qstart(struct sfc_evq *evq, unsigned int hw_index);
2206caeec47SAndrew Rybchenko void sfc_ev_qstop(struct sfc_evq *evq);
22158294ee6SAndrew Rybchenko
22258294ee6SAndrew Rybchenko int sfc_ev_qprime(struct sfc_evq *evq);
22358294ee6SAndrew Rybchenko void sfc_ev_qpoll(struct sfc_evq *evq);
22458294ee6SAndrew Rybchenko
2259a75f75cSAndrew Rybchenko void sfc_ev_mgmt_qpoll(struct sfc_adapter *sa);
2269a75f75cSAndrew Rybchenko
22758294ee6SAndrew Rybchenko #ifdef __cplusplus
22858294ee6SAndrew Rybchenko }
22958294ee6SAndrew Rybchenko #endif
23058294ee6SAndrew Rybchenko #endif /* _SFC_EV_H_ */
231