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