1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation 3 */ 4 5 #ifndef __INCLUDE_RTE_PORT_H__ 6 #define __INCLUDE_RTE_PORT_H__ 7 8 /** 9 * @file 10 * RTE Port 11 * 12 * This tool is part of the DPDK Packet Framework tool suite and provides 13 * a standard interface to implement different types of packet ports. 14 */ 15 16 #include <stdint.h> 17 #include <rte_mbuf.h> 18 19 /**@{ 20 * Macros to allow accessing metadata stored in the mbuf headroom 21 * just beyond the end of the mbuf data structure returned by a port 22 */ 23 #define RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset) \ 24 (&((uint8_t *)(mbuf))[offset]) 25 #define RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset) \ 26 ((uint16_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)) 27 #define RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset) \ 28 ((uint32_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)) 29 #define RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset) \ 30 ((uint64_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)) 31 32 #define RTE_MBUF_METADATA_UINT8(mbuf, offset) \ 33 (*RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)) 34 #define RTE_MBUF_METADATA_UINT16(mbuf, offset) \ 35 (*RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset)) 36 #define RTE_MBUF_METADATA_UINT32(mbuf, offset) \ 37 (*RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset)) 38 #define RTE_MBUF_METADATA_UINT64(mbuf, offset) \ 39 (*RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset)) 40 /**@}*/ 41 42 /* 43 * Port IN 44 */ 45 /** Maximum number of packets read from any input port in a single burst. 46 Cannot be changed. */ 47 #define RTE_PORT_IN_BURST_SIZE_MAX 64 48 49 /** Input port statistics */ 50 struct rte_port_in_stats { 51 uint64_t n_pkts_in; 52 uint64_t n_pkts_drop; 53 }; 54 55 /** 56 * Input port create 57 * 58 * @param params 59 * Parameters for input port creation 60 * @param socket_id 61 * CPU socket ID (e.g. for memory allocation purpose) 62 * @return 63 * Handle to input port instance 64 */ 65 typedef void* (*rte_port_in_op_create)(void *params, int socket_id); 66 67 /** 68 * Input port free 69 * 70 * @param port 71 * Handle to input port instance 72 * @return 73 * 0 on success, error code otherwise 74 */ 75 typedef int (*rte_port_in_op_free)(void *port); 76 77 /** 78 * Input port packet burst RX 79 * 80 * @param port 81 * Handle to input port instance 82 * @param pkts 83 * Burst of input packets 84 * @param n_pkts 85 * Number of packets in the input burst 86 * @return 87 * 0 on success, error code otherwise 88 */ 89 typedef int (*rte_port_in_op_rx)( 90 void *port, 91 struct rte_mbuf **pkts, 92 uint32_t n_pkts); 93 94 /** 95 * Input port stats get 96 * 97 * @param port 98 * Handle to output port instance 99 * @param stats 100 * Handle to port_in stats struct to copy data 101 * @param clear 102 * Flag indicating that stats should be cleared after read 103 * 104 * @return 105 * Error code or 0 on success. 106 */ 107 typedef int (*rte_port_in_op_stats_read)( 108 void *port, 109 struct rte_port_in_stats *stats, 110 int clear); 111 112 /** Input port interface defining the input port operation */ 113 struct rte_port_in_ops { 114 rte_port_in_op_create f_create; /**< Create */ 115 rte_port_in_op_free f_free; /**< Free */ 116 rte_port_in_op_rx f_rx; /**< Packet RX (packet burst) */ 117 rte_port_in_op_stats_read f_stats; /**< Stats */ 118 }; 119 120 /* 121 * Port OUT 122 */ 123 /** Output port statistics */ 124 struct rte_port_out_stats { 125 uint64_t n_pkts_in; 126 uint64_t n_pkts_drop; 127 }; 128 129 /** 130 * Output port create 131 * 132 * @param params 133 * Parameters for output port creation 134 * @param socket_id 135 * CPU socket ID (e.g. for memory allocation purpose) 136 * @return 137 * Handle to output port instance 138 */ 139 typedef void* (*rte_port_out_op_create)(void *params, int socket_id); 140 141 /** 142 * Output port free 143 * 144 * @param port 145 * Handle to output port instance 146 * @return 147 * 0 on success, error code otherwise 148 */ 149 typedef int (*rte_port_out_op_free)(void *port); 150 151 /** 152 * Output port single packet TX 153 * 154 * @param port 155 * Handle to output port instance 156 * @param pkt 157 * Input packet 158 * @return 159 * 0 on success, error code otherwise 160 */ 161 typedef int (*rte_port_out_op_tx)( 162 void *port, 163 struct rte_mbuf *pkt); 164 165 /** 166 * Output port packet burst TX 167 * 168 * @param port 169 * Handle to output port instance 170 * @param pkts 171 * Burst of input packets specified as array of up to 64 pointers to struct 172 * rte_mbuf 173 * @param pkts_mask 174 * 64-bit bitmask specifying which packets in the input burst are valid. When 175 * pkts_mask bit n is set, then element n of pkts array is pointing to a 176 * valid packet. Otherwise, element n of pkts array will not be accessed. 177 * @return 178 * 0 on success, error code otherwise 179 */ 180 typedef int (*rte_port_out_op_tx_bulk)( 181 void *port, 182 struct rte_mbuf **pkts, 183 uint64_t pkts_mask); 184 185 /** 186 * Output port flush 187 * 188 * @param port 189 * Handle to output port instance 190 * @return 191 * 0 on success, error code otherwise 192 */ 193 typedef int (*rte_port_out_op_flush)(void *port); 194 195 /** 196 * Output port stats read 197 * 198 * @param port 199 * Handle to output port instance 200 * @param stats 201 * Handle to port_out stats struct to copy data 202 * @param clear 203 * Flag indicating that stats should be cleared after read 204 * 205 * @return 206 * Error code or 0 on success. 207 */ 208 typedef int (*rte_port_out_op_stats_read)( 209 void *port, 210 struct rte_port_out_stats *stats, 211 int clear); 212 213 /** Output port interface defining the output port operation */ 214 struct rte_port_out_ops { 215 rte_port_out_op_create f_create; /**< Create */ 216 rte_port_out_op_free f_free; /**< Free */ 217 rte_port_out_op_tx f_tx; /**< Packet TX (single packet) */ 218 rte_port_out_op_tx_bulk f_tx_bulk; /**< Packet TX (packet burst) */ 219 rte_port_out_op_flush f_flush; /**< Flush */ 220 rte_port_out_op_stats_read f_stats; /**< Stats */ 221 }; 222 223 #endif 224