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 "efx.h" 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 /* Number of entries in the management event queue */ 42 #define SFC_MGMT_EVQ_ENTRIES (EFX_EVQ_MINNEVS) 43 44 struct sfc_adapter; 45 struct sfc_dp_rxq; 46 struct sfc_txq; 47 48 enum sfc_evq_state { 49 SFC_EVQ_UNINITIALIZED = 0, 50 SFC_EVQ_INITIALIZED, 51 SFC_EVQ_STARTING, 52 SFC_EVQ_STARTED, 53 54 SFC_EVQ_NSTATES 55 }; 56 57 struct sfc_evq { 58 /* Used on datapath */ 59 efx_evq_t *common; 60 const efx_ev_callbacks_t *callbacks; 61 unsigned int read_ptr; 62 boolean_t exception; 63 efsys_mem_t mem; 64 struct sfc_dp_rxq *dp_rxq; 65 struct sfc_txq *txq; 66 67 /* Not used on datapath */ 68 struct sfc_adapter *sa; 69 unsigned int evq_index; 70 enum sfc_evq_state init_state; 71 }; 72 73 struct sfc_evq_info { 74 /* Maximum number of EVQ entries taken into account when buffer 75 * table space is allocated. 76 */ 77 unsigned int max_entries; 78 /* Real number of EVQ entries, less or equal to max_entries */ 79 unsigned int entries; 80 /* Event queue creation flags */ 81 uint32_t flags; 82 /* NUMA-aware EVQ data structure used on datapath */ 83 struct sfc_evq *evq; 84 }; 85 86 /* 87 * Functions below define event queue to transmit/receive queue and vice 88 * versa mapping. 89 */ 90 91 static inline unsigned int 92 sfc_ev_qcount(struct sfc_adapter *sa) 93 { 94 const struct rte_eth_dev_data *dev_data = sa->eth_dev->data; 95 96 /* 97 * One management EVQ for global events. 98 * Own EVQ for each Tx and Rx queue. 99 */ 100 return 1 + dev_data->nb_rx_queues + dev_data->nb_tx_queues; 101 } 102 103 static inline unsigned int 104 sfc_evq_max_entries(struct sfc_adapter *sa, unsigned int sw_index) 105 { 106 unsigned int max_entries; 107 108 if (sw_index == sa->mgmt_evq_index) 109 max_entries = SFC_MGMT_EVQ_ENTRIES; 110 else if (sw_index <= sa->eth_dev->data->nb_rx_queues) 111 max_entries = EFX_RXQ_MAXNDESCS; 112 else 113 max_entries = efx_nic_cfg_get(sa->nic)->enc_txq_max_ndescs; 114 115 return max_entries; 116 } 117 118 static inline unsigned int 119 sfc_evq_index_by_rxq_sw_index(__rte_unused struct sfc_adapter *sa, 120 unsigned int rxq_sw_index) 121 { 122 return 1 + rxq_sw_index; 123 } 124 125 static inline unsigned int 126 sfc_evq_index_by_txq_sw_index(struct sfc_adapter *sa, unsigned int txq_sw_index) 127 { 128 return 1 + sa->eth_dev->data->nb_rx_queues + txq_sw_index; 129 } 130 131 int sfc_ev_init(struct sfc_adapter *sa); 132 void sfc_ev_fini(struct sfc_adapter *sa); 133 int sfc_ev_start(struct sfc_adapter *sa); 134 void sfc_ev_stop(struct sfc_adapter *sa); 135 136 int sfc_ev_qinit(struct sfc_adapter *sa, unsigned int sw_index, 137 unsigned int entries, int socket_id); 138 void sfc_ev_qfini(struct sfc_adapter *sa, unsigned int sw_index); 139 int sfc_ev_qstart(struct sfc_adapter *sa, unsigned int sw_index); 140 void sfc_ev_qstop(struct sfc_adapter *sa, unsigned int sw_index); 141 142 int sfc_ev_qprime(struct sfc_evq *evq); 143 void sfc_ev_qpoll(struct sfc_evq *evq); 144 145 void sfc_ev_mgmt_qpoll(struct sfc_adapter *sa); 146 147 #ifdef __cplusplus 148 } 149 #endif 150 #endif /* _SFC_EV_H_ */ 151