| 482 | } |
| 483 | |
| 484 | static int |
| 485 | nfp_stats_id_alloc(struct nfp_flow_priv *priv, uint32_t *ctx) |
| 486 | { |
| 487 | struct circ_buf *ring; |
| 488 | uint32_t temp_stats_id; |
| 489 | uint32_t freed_stats_id; |
| 490 | |
| 491 | /* Check for unallocated entries first. */ |
| 492 | if (priv->stats_ids.init_unallocated > 0) { |
| 493 | *ctx = ((priv->stats_ids.init_unallocated - 1) & NFP_FL_STAT_ID_STAT) | |
| 494 | (priv->active_mem_unit & NFP_FL_STAT_ID_MU_NUM); |
| 495 | if (++priv->active_mem_unit == priv->total_mem_units) { |
| 496 | priv->stats_ids.init_unallocated--; |
| 497 | priv->active_mem_unit = 0; |
| 498 | } |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | /* Check if buffer is empty */ |
| 504 | ring = &priv->stats_ids.free_list; |
| 505 | freed_stats_id = priv->stats_ring_size; |
| 506 | if (ring->head == ring->tail) { |
| 507 | *ctx = freed_stats_id; |
| 508 | return -ENOENT; |
| 509 | } |
| 510 | |
| 511 | memcpy(&temp_stats_id, &ring->buf[ring->tail], NFP_FL_STATS_ELEM_RS); |
| 512 | *ctx = temp_stats_id; |
| 513 | memcpy(&ring->buf[ring->tail], &freed_stats_id, NFP_FL_STATS_ELEM_RS); |
| 514 | ring->tail = (ring->tail + NFP_FL_STATS_ELEM_RS) % |
| 515 | (priv->stats_ring_size * NFP_FL_STATS_ELEM_RS); |
| 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | static int |
| 521 | nfp_stats_id_free(struct nfp_flow_priv *priv, uint32_t ctx) |
no test coverage detected