1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef _VMXNET3_RING_H_ 35 #define _VMXNET3_RING_H_ 36 37 #define VMXNET3_RX_CMDRING_SIZE 2 38 39 #define VMXNET3_DRIVER_VERSION_NUM 0x01012000 40 41 /* Default ring size */ 42 #define VMXNET3_DEF_TX_RING_SIZE 512 43 #define VMXNET3_DEF_RX_RING_SIZE 128 44 45 /* Default rx data ring desc size */ 46 #define VMXNET3_DEF_RXDATA_DESC_SIZE 128 47 48 #define VMXNET3_SUCCESS 0 49 #define VMXNET3_FAIL -1 50 51 #define TRUE 1 52 #define FALSE 0 53 54 55 typedef struct vmxnet3_buf_info { 56 uint16_t len; 57 struct rte_mbuf *m; 58 uint64_t bufPA; 59 } vmxnet3_buf_info_t; 60 61 typedef struct vmxnet3_cmd_ring { 62 vmxnet3_buf_info_t *buf_info; 63 uint32_t size; 64 uint32_t next2fill; 65 uint32_t next2comp; 66 uint8_t gen; 67 uint8_t rid; 68 Vmxnet3_GenericDesc *base; 69 uint64_t basePA; 70 } vmxnet3_cmd_ring_t; 71 72 static inline void 73 vmxnet3_cmd_ring_adv_next2fill(struct vmxnet3_cmd_ring *ring) 74 { 75 ring->next2fill++; 76 if (unlikely(ring->next2fill == ring->size)) { 77 ring->next2fill = 0; 78 ring->gen = (uint8_t)(ring->gen ^ 1); 79 } 80 } 81 82 static inline void 83 vmxnet3_cmd_ring_adv_next2comp(struct vmxnet3_cmd_ring *ring) 84 { 85 VMXNET3_INC_RING_IDX_ONLY(ring->next2comp, ring->size); 86 } 87 88 static inline uint32_t 89 vmxnet3_cmd_ring_desc_avail(struct vmxnet3_cmd_ring *ring) 90 { 91 return (ring->next2comp > ring->next2fill ? 0 : ring->size) + 92 ring->next2comp - ring->next2fill - 1; 93 } 94 95 static inline bool 96 vmxnet3_cmd_ring_desc_empty(struct vmxnet3_cmd_ring *ring) 97 { 98 return ring->next2comp == ring->next2fill; 99 } 100 101 typedef struct vmxnet3_comp_ring { 102 uint32_t size; 103 uint32_t next2proc; 104 uint8_t gen; 105 uint8_t intr_idx; 106 Vmxnet3_GenericDesc *base; 107 uint64_t basePA; 108 } vmxnet3_comp_ring_t; 109 110 struct vmxnet3_data_ring { 111 struct Vmxnet3_TxDataDesc *base; 112 uint32_t size; 113 uint64_t basePA; 114 }; 115 116 static inline void 117 vmxnet3_comp_ring_adv_next2proc(struct vmxnet3_comp_ring *ring) 118 { 119 ring->next2proc++; 120 if (unlikely(ring->next2proc == ring->size)) { 121 ring->next2proc = 0; 122 ring->gen = (uint8_t)(ring->gen ^ 1); 123 } 124 } 125 126 struct vmxnet3_txq_stats { 127 uint64_t drop_total; /* # of pkts dropped by the driver, 128 * the counters below track droppings due to 129 * different reasons 130 */ 131 uint64_t drop_too_many_segs; 132 uint64_t drop_tso; 133 uint64_t tx_ring_full; 134 }; 135 136 typedef struct vmxnet3_tx_queue { 137 struct vmxnet3_hw *hw; 138 struct vmxnet3_cmd_ring cmd_ring; 139 struct vmxnet3_comp_ring comp_ring; 140 struct vmxnet3_data_ring data_ring; 141 uint32_t qid; 142 struct Vmxnet3_TxQueueDesc *shared; 143 struct vmxnet3_txq_stats stats; 144 const struct rte_memzone *mz; 145 bool stopped; 146 uint16_t queue_id; /**< Device TX queue index. */ 147 uint16_t port_id; /**< Device port identifier. */ 148 uint16_t txdata_desc_size; 149 } vmxnet3_tx_queue_t; 150 151 struct vmxnet3_rxq_stats { 152 uint64_t drop_total; 153 uint64_t drop_err; 154 uint64_t drop_fcs; 155 uint64_t rx_buf_alloc_failure; 156 }; 157 158 struct vmxnet3_rx_data_ring { 159 uint8_t *base; 160 uint64_t basePA; 161 uint32_t size; 162 }; 163 164 typedef struct vmxnet3_rx_queue { 165 struct rte_mempool *mp; 166 struct vmxnet3_hw *hw; 167 struct vmxnet3_cmd_ring cmd_ring[VMXNET3_RX_CMDRING_SIZE]; 168 struct vmxnet3_comp_ring comp_ring; 169 struct vmxnet3_rx_data_ring data_ring; 170 uint16_t data_desc_size; 171 uint32_t qid1; 172 uint32_t qid2; 173 /* rqID in RCD for buffer from data ring */ 174 uint32_t data_ring_qid; 175 Vmxnet3_RxQueueDesc *shared; 176 struct rte_mbuf *start_seg; 177 struct rte_mbuf *last_seg; 178 struct vmxnet3_rxq_stats stats; 179 const struct rte_memzone *mz; 180 bool stopped; 181 uint16_t queue_id; /**< Device RX queue index. */ 182 uint16_t port_id; /**< Device port identifier. */ 183 } vmxnet3_rx_queue_t; 184 185 #endif /* _VMXNET3_RING_H_ */ 186