-
-static int
-tcp_alloc_tx_buffers (tcp_worker_ctx_t * wrk, u16 * n_bufs, u32 wanted)
-{
- vlib_main_t *vm = vlib_get_main ();
- u32 n_alloc;
-
- ASSERT (wanted > *n_bufs);
- vec_validate_aligned (wrk->tx_buffers, wanted - 1, CLIB_CACHE_LINE_BYTES);
- n_alloc = vlib_buffer_alloc (vm, &wrk->tx_buffers[*n_bufs],
- wanted - *n_bufs);
- *n_bufs += n_alloc;
- _vec_len (wrk->tx_buffers) = *n_bufs;
- return n_alloc;
-}
-
-always_inline int
-tcp_get_free_buffer_index (tcp_worker_ctx_t * wrk, u32 * bidx)
-{
- u16 n_bufs = vec_len (wrk->tx_buffers);
-
- TCP_DBG_BUFFER_ALLOC_MAYBE_FAIL (wrk->vm->thread_index);
-
- if (PREDICT_FALSE (!n_bufs))
- {
- if (!tcp_alloc_tx_buffers (wrk, &n_bufs, VLIB_FRAME_SIZE))
- {
- *bidx = ~0;
- return -1;
- }
- }
- *bidx = wrk->tx_buffers[--n_bufs];
- _vec_len (wrk->tx_buffers) = n_bufs;
- return 0;
-}