xref: /dpdk/drivers/net/sfc/sfc_ev.h (revision a96eaf4e659ba2f3f901782a22fe30e7ecdf9c65)
1 /*-
2  *   BSD LICENSE
3  *
4  * Copyright (c) 2016-2017 Solarflare Communications Inc.
5  * All rights reserved.
6  *
7  * This software was jointly developed between OKTET Labs (under contract
8  * for Solarflare) and Solarflare Communications, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  *    this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  *    this list of conditions and the following disclaimer in the documentation
17  *    and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _SFC_EV_H_
33 #define _SFC_EV_H_
34 
35 #include <rte_ethdev.h>
36 
37 #include "efx.h"
38 
39 #include "sfc.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /* Number of entries in the management event queue */
46 #define SFC_MGMT_EVQ_ENTRIES	(EFX_EVQ_MINNEVS)
47 
48 struct sfc_adapter;
49 struct sfc_dp_rxq;
50 struct sfc_dp_txq;
51 
52 enum sfc_evq_state {
53 	SFC_EVQ_UNINITIALIZED = 0,
54 	SFC_EVQ_INITIALIZED,
55 	SFC_EVQ_STARTING,
56 	SFC_EVQ_STARTED,
57 
58 	SFC_EVQ_NSTATES
59 };
60 
61 enum sfc_evq_type {
62 	SFC_EVQ_TYPE_MGMT = 0,
63 	SFC_EVQ_TYPE_RX,
64 	SFC_EVQ_TYPE_TX,
65 
66 	SFC_EVQ_NTYPES
67 };
68 
69 struct sfc_evq {
70 	/* Used on datapath */
71 	efx_evq_t			*common;
72 	const efx_ev_callbacks_t	*callbacks;
73 	unsigned int			read_ptr;
74 	boolean_t			exception;
75 	efsys_mem_t			mem;
76 	struct sfc_dp_rxq		*dp_rxq;
77 	struct sfc_dp_txq		*dp_txq;
78 
79 	/* Not used on datapath */
80 	struct sfc_adapter		*sa;
81 	unsigned int			evq_index;
82 	enum sfc_evq_state		init_state;
83 	enum sfc_evq_type		type;
84 };
85 
86 struct sfc_evq_info {
87 	/* Number of EVQ entries */
88 	unsigned int		entries;
89 	/* Event queue creation flags */
90 	uint32_t		flags;
91 	/* NUMA-aware EVQ data structure used on datapath */
92 	struct sfc_evq		*evq;
93 };
94 
95 /*
96  * Functions below define event queue to transmit/receive queue and vice
97  * versa mapping.
98  */
99 
100 static inline unsigned int
101 sfc_ev_qcount(struct sfc_adapter *sa)
102 {
103 	const struct rte_eth_dev_data *dev_data = sa->eth_dev->data;
104 
105 	/*
106 	 * One management EVQ for global events.
107 	 * Own EVQ for each Tx and Rx queue.
108 	 */
109 	return 1 + dev_data->nb_rx_queues + dev_data->nb_tx_queues;
110 }
111 
112 static inline unsigned int
113 sfc_evq_index_by_rxq_sw_index(__rte_unused struct sfc_adapter *sa,
114 			      unsigned int rxq_sw_index)
115 {
116 	return 1 + rxq_sw_index;
117 }
118 
119 static inline unsigned int
120 sfc_evq_index_by_txq_sw_index(struct sfc_adapter *sa, unsigned int txq_sw_index)
121 {
122 	return 1 + sa->eth_dev->data->nb_rx_queues + txq_sw_index;
123 }
124 
125 int sfc_ev_init(struct sfc_adapter *sa);
126 void sfc_ev_fini(struct sfc_adapter *sa);
127 int sfc_ev_start(struct sfc_adapter *sa);
128 void sfc_ev_stop(struct sfc_adapter *sa);
129 
130 int sfc_ev_qinit(struct sfc_adapter *sa, unsigned int sw_index,
131 		 enum sfc_evq_type type, unsigned int type_index,
132 		 unsigned int entries, int socket_id);
133 void sfc_ev_qfini(struct sfc_adapter *sa, unsigned int sw_index);
134 int sfc_ev_qstart(struct sfc_adapter *sa, unsigned int sw_index);
135 void sfc_ev_qstop(struct sfc_adapter *sa, unsigned int sw_index);
136 
137 int sfc_ev_qprime(struct sfc_evq *evq);
138 void sfc_ev_qpoll(struct sfc_evq *evq);
139 
140 void sfc_ev_mgmt_qpoll(struct sfc_adapter *sa);
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 #endif /* _SFC_EV_H_ */
146