27 #define foreach_dpdk_tx_func_error \ 28 _(BAD_RETVAL, "DPDK tx function returned an error") \ 29 _(RING_FULL, "Tx packet drops (ring full)") \ 30 _(PKT_DROP, "Tx packet drops (dpdk tx failure)") \ 31 _(REPL_FAIL, "Tx packet drops (replication failure)") 35 #define _(f,s) DPDK_TX_FUNC_ERROR_##f, 54 error = rte_eth_dev_default_mac_addr_set (xd->
device_index,
55 (
struct ether_addr *) address);
69 struct ether_addr mc_addr_vec[],
int naddr)
75 error = rte_eth_dev_set_mc_addr_list (xd->
device_index, mc_addr_vec, naddr);
92 struct rte_mbuf *first_mb = 0, *new_mb, *pkt_mb, **prev_mb_next = 0;
93 u8 nb_segs, nb_segs_left;
99 nb_segs = pkt_mb->nb_segs;
100 for (nb_segs_left = nb_segs; nb_segs_left; nb_segs_left--)
105 "(nb_segs = %d, nb_segs_left = %d)!",
106 nb_segs - nb_segs_left, nb_segs, nb_segs_left);
108 rte_pktmbuf_free (first_mb);
115 rte_pktmbuf_free (first_mb);
125 rte_pktmbuf_pkt_len (first_mb) = pkt_mb->pkt_len;
126 first_mb->nb_segs = pkt_mb->nb_segs;
127 first_mb->port = pkt_mb->port;
128 #ifdef DAW_FIXME // TX Offload support TBD 129 first_mb->vlan_macip = pkt_mb->vlan_macip;
130 first_mb->hash = pkt_mb->hash;
131 first_mb->ol_flags = pkt_mb->ol_flags
136 ASSERT (prev_mb_next != 0);
137 *prev_mb_next = new_mb;
143 rte_pktmbuf_data_len (new_mb) = pkt_mb->data_len;
144 copy_bytes = pkt_mb->data_len + RTE_PKTMBUF_HEADROOM;
145 ASSERT (copy_bytes <= pkt_mb->buf_len);
146 clib_memcpy (new_mb->buf_addr, pkt_mb->buf_addr, copy_bytes);
148 prev_mb_next = &new_mb->next;
149 pkt_mb = pkt_mb->next;
153 __rte_mbuf_sanity_check (first_mb, 1);
163 struct rte_mbuf *first_mb = 0, *new_mb, *pkt_mb, **prev_mb_next = 0;
164 u8 nb_segs, nb_segs_left;
169 nb_segs = pkt_mb->nb_segs;
170 for (nb_segs_left = nb_segs; nb_segs_left; nb_segs_left--)
175 "(nb_segs = %d, nb_segs_left = %d)!",
176 nb_segs - nb_segs_left, nb_segs, nb_segs_left);
178 rte_pktmbuf_free (first_mb);
181 new_mb = rte_pktmbuf_clone (pkt_mb, bm->
pktmbuf_pools[socket_id]);
185 rte_pktmbuf_free (first_mb);
195 rte_pktmbuf_pkt_len (first_mb) = pkt_mb->pkt_len;
196 first_mb->nb_segs = pkt_mb->nb_segs;
197 first_mb->port = pkt_mb->port;
198 #ifdef DAW_FIXME // TX Offload support TBD 199 first_mb->vlan_macip = pkt_mb->vlan_macip;
200 first_mb->hash = pkt_mb->hash;
201 first_mb->ol_flags = pkt_mb->ol_flags
206 ASSERT (prev_mb_next != 0);
207 *prev_mb_next = new_mb;
213 rte_pktmbuf_data_len (new_mb) = pkt_mb->data_len;
215 prev_mb_next = &new_mb->next;
216 pkt_mb = pkt_mb->next;
220 __rte_mbuf_sanity_check (first_mb, 1);
245 sizeof (buffer[0]) -
sizeof (buffer->
pre_data));
269 struct rte_mbuf **tx_vector)
280 ring =
vec_header (tx_vector,
sizeof (*ring));
330 while (__sync_lock_test_and_set (xd->
lockp[queue_id], 1))
332 queue_id = (queue_id + 1) % xd->
tx_q_used;
375 while (__sync_lock_test_and_set (xd->
lockp[queue_id], 1));
386 offset = dq->
queue_id * VIRTIO_QNUM;
392 struct rte_mbuf **pkts = &tx_vector[tx_tail];
393 for (i = 0; i < (tx_head - tx_tail); i++)
395 struct rte_mbuf *buff = pkts[
i];
396 bytes += rte_pktmbuf_data_len (buff);
401 rte_vhost_enqueue_burst (&xd->vu_vhost_dev,
407 dpdk_vu_vring *vring =
408 &(xd->vu_intf->vrings[offset + VIRTIO_TXQ]);
409 vring->packets += rv;
410 vring->bytes += bytes;
412 if (dpdk_vhost_user_want_interrupt
413 (xd, offset + VIRTIO_RXQ))
415 vring = &(xd->vu_intf->vrings[offset + VIRTIO_RXQ]);
416 vring->n_since_last_int += rv;
419 if (vring->int_deadline < now ||
420 vring->n_since_last_int >
422 dpdk_vhost_user_send_interrupt (vm, xd,
423 offset + VIRTIO_RXQ);
428 rte_pktmbuf_free (tx_vector[tx_tail + c]);
440 struct rte_mbuf **pkts = &tx_vector[tx_tail];
443 struct rte_mbuf *buff = pkts[
i];
444 bytes += rte_pktmbuf_data_len (buff);
447 rte_vhost_enqueue_burst (&xd->vu_vhost_dev,
455 dpdk_vu_vring *vring =
456 &(xd->vu_intf->vrings[offset + VIRTIO_TXQ]);
457 vring->packets += rv;
458 vring->bytes += bytes;
460 if (dpdk_vhost_user_want_interrupt
461 (xd, offset + VIRTIO_RXQ))
463 vring = &(xd->vu_intf->vrings[offset + VIRTIO_RXQ]);
464 vring->n_since_last_int += rv;
467 if (vring->int_deadline < now ||
468 vring->n_since_last_int >
470 dpdk_vhost_user_send_interrupt (vm, xd,
471 offset + VIRTIO_RXQ);
476 rte_pktmbuf_free (tx_vector[tx_tail + c]);
483 *xd->
lockp[queue_id] = 0;
492 rv = rte_kni_tx_burst (xd->
kni,
505 rv = rte_kni_tx_burst (xd->
kni,
527 *xd->
lockp[queue_id] = 0;
547 while (rv && n_packets && (n_retry > 0));
567 struct rte_mbuf **tx_vector;
577 ring =
vec_header (tx_vector,
sizeof (*ring));
615 struct rte_mbuf **tx_vector;
627 tx_vector = xd->tx_vectors[queue_id];
628 ring =
vec_header (tx_vector,
sizeof (*ring));
646 u32 bi0 = from[n_packets];
649 rte_pktmbuf_free (mb0);
677 struct rte_mbuf *mb0, *mb1;
678 struct rte_mbuf *prefmb0, *prefmb1;
682 u16 new_data_len0, new_data_len1;
683 u16 new_pkt_len0, new_pkt_len1;
719 DPDK_TX_FUNC_ERROR_REPL_FAIL, 1);
732 DPDK_TX_FUNC_ERROR_REPL_FAIL, 1);
746 new_data_len0 = (
u16) ((
i16) mb0->data_len + delta0);
747 new_data_len1 = (
u16) ((
i16) mb1->data_len + delta1);
748 new_pkt_len0 = (
u16) ((
i16) mb0->pkt_len + delta0);
749 new_pkt_len1 = (
u16) ((
i16) mb1->pkt_len + delta1);
753 mb0->data_len = new_data_len0;
754 mb1->data_len = new_data_len1;
755 mb0->pkt_len = new_pkt_len0;
756 mb1->pkt_len = new_pkt_len1;
798 struct rte_mbuf *mb0;
816 DPDK_TX_FUNC_ERROR_REPL_FAIL, 1);
827 new_data_len0 = (
u16) ((
i16) mb0->data_len + delta0);
828 new_pkt_len0 = (
u16) ((
i16) mb0->pkt_len + delta0);
831 mb0->data_len = new_data_len0;
832 mb0->pkt_len = new_pkt_len0;
859 tx_pkts = n_on_ring - n_packets;
894 rte_pktmbuf_free (tx_vector[ring->
tx_tail + n_packets]);
907 _vec_len (dm->
recycle[my_cpu]) = 0;
925 (
"cannot renumber non-vhost-user interface (sw_if_index: %d)",
930 xd->vu_if_id = new_dev_instance;
975 for (i = 0; i < xd->
rx_q_used * VIRTIO_QNUM; i++)
977 xd->vu_intf->vrings[
i].packets = 0;
978 xd->vu_intf->vrings[
i].bytes = 0;
984 #ifdef RTE_LIBRTE_KNI 986 kni_config_network_if (
u8 port_id,
u8 if_up)
1006 ETH_LINK_FULL_DUPLEX : 0);
1011 kni_change_mtu (
u8 port_id,
unsigned new_mtu)
1046 #ifdef RTE_LIBRTE_KNI 1051 struct rte_kni_conf conf;
1052 struct rte_kni_ops ops;
1055 memset (&conf, 0,
sizeof (conf));
1056 snprintf (conf.name, RTE_KNI_NAMESIZE,
"vpp%u", xd->
kni_port_id);
1058 memset (&ops, 0,
sizeof (ops));
1060 ops.change_mtu = kni_change_mtu;
1061 ops.config_network_if = kni_config_network_if;
1080 kni_rv = rte_kni_release (xd->
kni);
1092 if (xd->vu_is_running)
1095 ETH_LINK_FULL_DUPLEX);
1140 if (xd->
pmd != VNET_DPDK_PMD_VMXNET3)
1154 if (xd->
pmd != VNET_DPDK_PMD_VMXNET3)
1158 if (xd->
pmd == VNET_DPDK_PMD_BOND)
1161 int nlink = rte_eth_bond_slaves_get (xd->
device_index, slink, 16);
1164 u8 dpdk_port = slink[--nlink];
1165 rte_eth_dev_stop (dpdk_port);
1171 clib_warning (
"rte_eth_dev_%s error: %d", is_up ?
"start" :
"stop", rv);
1189 if (node_index == ~0)
1209 int r, vlan_offload;
1221 if ((xd->
pmd != VNET_DPDK_PMD_IXGBEVF) && (xd->
pmd != VNET_DPDK_PMD_I40EVF))
1233 vlan_offload = rte_eth_dev_get_vlan_offload (xd->
device_index);
1234 vlan_offload |= ETH_VLAN_FILTER_OFFLOAD;
1236 if ((r = rte_eth_dev_set_vlan_offload (xd->
device_index, vlan_offload)))
1269 .no_flatten_output_chains = 1,
1283 #define UP_DOWN_FLAG_EVENT 1 1298 uword *event_data = 0;
1314 if (
vec_len (event_data) == 2)
1316 sw_if_index = event_data[0];
1317 flags = event_data[1];
1339 .name =
"admin-up-down-process",
1340 .process_log2_n_stack_bytes = 17,
1381 "Unable to get DPDK device from HW interface");
void(* dpdk_flowcontrol_callback_t)(vlib_main_t *vm, u32 hw_if_index, u32 n_packets)
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 cpu_index, u32 index, u32 increment)
Increment a simple counter.
i8 dpdk_get_cpu_socket(vnet_hw_interface_t *hi)
sll srl srl sll sra u16x4 i
#define rte_mbuf_from_vlib_buffer(x)
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
#define UP_DOWN_FLAG_EVENT
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
static vlib_main_t * vlib_get_main(void)
struct rte_eth_stats last_stats
vnet_interface_main_t interface_main
clib_error_t * dpdk_set_mac_address(vnet_hw_interface_t *hi, char *address)
vnet_device_class_t dpdk_device_class
static int dpdk_device_renumber(vnet_hw_interface_t *hi, u32 new_dev_instance)
u32 vhost_coalesce_frames
static void vlib_error_count(vlib_main_t *vm, uword node_index, uword counter, uword increment)
static f64 vlib_time_now(vlib_main_t *vm)
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
struct vnet_sub_interface_t::@120::@121::@123 flags
vlib_buffer_main_t * buffer_main
u32 per_interface_next_index
#define clib_error_report(e)
#define VNET_HW_INTERFACE_FLAG_LINK_UP
struct rte_eth_xstat * last_cleared_xstats
struct rte_mbuf * dpdk_zerocopy_replicate_packet_mb(vlib_buffer_t *b)
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
format_function_t format_dpdk_tx_dma_trace
uword admin_up_down_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
static clib_error_t * dpdk_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
struct rte_eth_stats stats
VNET_DEVICE_CLASS(af_packet_device_class)
vnet_main_t * vnet_get_main(void)
struct rte_mbuf *** tx_vectors
static_always_inline u32 tx_burst_vector_internal(vlib_main_t *vm, dpdk_device_t *xd, struct rte_mbuf **tx_vector)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define static_always_inline
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
vlib_node_registration_t dpdk_input_node
(constructor) VLIB_REGISTER_NODE (dpdk_input_node)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
#define clib_warning(format, args...)
A collection of simple counters.
struct rte_mbuf * dpdk_replicate_packet_mb(vlib_buffer_t *b)
vnet_hw_interface_t * hw_interfaces
static clib_error_t * dpdk_subif_add_del_function(vnet_main_t *vnm, u32 hw_if_index, struct vnet_sw_interface_t *st, int is_add)
u16 current_length
Nbytes between current data and the end of this buffer.
dpdk_device_and_queue_t ** devices_by_cpu
dpdk_flowcontrol_callback_t flowcontrol_callback
static char * dpdk_tx_func_error_strings[]
unsigned short int uint16_t
static void * vlib_process_signal_event_data(vlib_main_t *vm, uword node_index, uword type_opaque, uword n_data_elts, uword n_data_elt_bytes)
static void pcap_add_buffer(pcap_main_t *pm, vlib_main_t *vm, u32 buffer_index, u32 n_bytes_in_trace)
Add buffer (vlib_buffer_t) to the trace.
static void dpdk_set_interface_next_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
vlib_simple_counter_main_t * sw_if_counters
void dpdk_set_flowcontrol_callback(vlib_main_t *vm, dpdk_flowcontrol_callback_t callback)
static uword dpdk_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *f)
struct rte_mempool ** pktmbuf_pools
#define CLIB_PREFETCH(addr, size, type)
static void dpdk_update_counters(dpdk_device_t *xd, f64 now)
#define clib_memcpy(a, b, c)
#define VLIB_BUFFER_RECYCLE
format_function_t format_dpdk_device
struct vnet_sub_interface_t::@120 eth
struct rte_eth_xstat * xstats
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
#define DPDK_TX_RING_SIZE
format_function_t format_dpdk_device_name
#define VLIB_BUFFER_REPL_FAIL
void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
#define VLIB_NODE_FLAG_TRACE
void dpdk_update_link_state(dpdk_device_t *xd, f64 now)
#define VLIB_BUFFER_IS_TRACED
dpdk_pmd_t dpdk_get_pmd_type(vnet_hw_interface_t *hi)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static void dpdk_clear_hw_interface_counters(u32 instance)
static vlib_node_registration_t admin_up_down_process_node
(constructor) VLIB_REGISTER_NODE (admin_up_down_process_node)
template key/value backing page structure
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
dpdk_device_type_t dev_type
#define foreach_dpdk_tx_func_error
u8 admin_up_down_in_progress
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define VLIB_BUFFER_DATA_SIZE
static void dpdk_tx_trace_buffer(dpdk_main_t *dm, vlib_node_runtime_t *node, dpdk_device_t *xd, u16 queue_id, u32 buffer_index, vlib_buffer_t *buffer)
u32 dpdk_interface_tx_vector(vlib_main_t *vm, u32 dev_instance)
void post_sw_interface_set_flags(vlib_main_t *vm, u32 sw_if_index, u32 flags)
#define VLIB_REGISTER_NODE(x,...)
u32 dpdk_get_admin_up_down_in_progress(void)
static void * vec_header(void *v, uword header_bytes)
Find a user vector header.
#define vec_foreach(var, vec)
Vector iterator.
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
struct rte_eth_stats last_cleared_stats
#define clib_error_return(e, args...)
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
clib_error_t * dpdk_get_hw_interface_stats(u32 hw_if_index, struct rte_eth_stats *dest)
uword runtime_data[(128-1 *sizeof(vlib_node_function_t *)-1 *sizeof(vlib_error_t *)-11 *sizeof(u32)-5 *sizeof(u16))/sizeof(uword)]
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
#define VLIB_DEVICE_TX_FUNCTION_MULTIARCH(dev, fn)
clib_error_t * dpdk_set_mc_filter(vnet_hw_interface_t *hi, struct ether_addr mc_addr_vec[], int naddr)
uword * dpdk_device_by_kni_port_id
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
dpdk_config_main_t * conf