void apipe_init(struct atomic_pipe *ap, void *buf, size_t buf_sz, size_t elem_sz) { ap->ap_buf = buf; /* power of two number of elements in the ring. */ ap->ap_ring_sz = ROUNDDOWNPWR2(buf_sz / elem_sz); ap->ap_elem_sz = elem_sz; ap->ap_rd_off = 0; ap->ap_wr_off = 0; ap->ap_nr_readers = 1; ap->ap_nr_writers = 1; /* Three CVs, all using the same lock. */ spinlock_init(&ap->ap_lock); cv_init_with_lock(&ap->ap_priority_reader, &ap->ap_lock); cv_init_with_lock(&ap->ap_general_readers, &ap->ap_lock); cv_init_with_lock(&ap->ap_writers, &ap->ap_lock); ap->ap_has_priority_reader = FALSE; }
static int mlx4_en_fill_rx_buffers(struct mlx4_en_priv *priv) { struct mlx4_en_rx_ring *ring; int ring_ind; int buf_ind; int new_size; for (buf_ind = 0; buf_ind < priv->prof->rx_ring_size; buf_ind++) { for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) { ring = priv->rx_ring[ring_ind]; if (mlx4_en_prepare_rx_desc(priv, ring, ring->actual_size, MEM_WAIT | __GFP_COLD)) { if (ring->actual_size < MLX4_EN_MIN_RX_SIZE) { en_err(priv, "Failed to allocate enough rx buffers\n"); return -ENOMEM; } else { new_size = ROUNDDOWNPWR2(ring->actual_size); en_warn(priv, "Only %d buffers allocated reducing ring size to %d\n", ring->actual_size, new_size); goto reduce_rings; } } ring->actual_size++; ring->prod++; } } return 0; reduce_rings: for (ring_ind = 0; ring_ind < priv->rx_ring_num; ring_ind++) { ring = priv->rx_ring[ring_ind]; while (ring->actual_size > new_size) { ring->actual_size--; ring->prod--; mlx4_en_free_rx_desc(priv, ring, ring->actual_size); } } return 0; }
void mlx4_en_set_num_rx_rings(struct mlx4_en_dev *mdev) { int i; int num_of_eqs; int num_rx_rings; struct mlx4_dev *dev = mdev->dev; mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_ETH) { if (!dev->caps.comp_pool) num_of_eqs = MAX_T(int, MIN_RX_RINGS, MIN_T(int, dev->caps.num_comp_vectors, DEF_RX_RINGS)); else num_of_eqs = MIN_T(int, MAX_MSIX_P_PORT, dev->caps.comp_pool / dev->caps.num_ports) - 1; num_rx_rings = mlx4_low_memory_profile() ? MIN_RX_RINGS : MIN_T(int, num_of_eqs, netif_get_num_default_rss_queues()); mdev->profile.prof[i].rx_ring_num = ROUNDDOWNPWR2(num_rx_rings); }