// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
/* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */

#include <linux/kernel.h>
#include <linux/bitops.h>
#include <linux/spinlock.h>

#include "spectrum_cnt.h"

struct mlxsw_sp_counter_sub_pool {
	u64 size;
	unsigned int base_index;
	enum mlxsw_res_id entry_size_res_id;
	const char *resource_name; /* devlink resource name */
	u64 resource_id; /* devlink resource id */
	unsigned int entry_size;
	unsigned int bank_count;
	atomic_t active_entries_count;
};

struct mlxsw_sp_counter_pool {
	u64 pool_size;
	unsigned long *usage; /* Usage bitmap */
	spinlock_t counter_pool_lock; /* Protects counter pool allocations */
	atomic_t active_entries_count;
	unsigned int sub_pools_count;
	struct mlxsw_sp_counter_sub_pool sub_pools[] __counted_by(sub_pools_count);
};

static const struct mlxsw_sp_counter_sub_pool mlxsw_sp_counter_sub_pools[] = {
	[MLXSW_SP_COUNTER_SUB_POOL_FLOW] = {
		.entry_size_res_id = MLXSW_RES_ID_COUNTER_SIZE_PACKETS_BYTES,
		.resource_name = MLXSW_SP_RESOURCE_NAME_COUNTERS_FLOW,
		.resource_id = MLXSW_SP_RESOURCE_COUNTERS_FLOW,
		.bank_count = 6,
	},
	[MLXSW_SP_COUNTER_SUB_POOL_RIF] = {
		.entry_size_res_id = MLXSW_RES_ID_COUNTER_SIZE_ROUTER_BASIC,
		.resource_name = MLXSW_SP_RESOURCE_NAME_COUNTERS_RIF,
		.resource_id = MLXSW_SP_RESOURCE_COUNTERS_RIF,
		.bank_count = 2,
	}
};

static u64 mlxsw_sp_counter_sub_pool_occ_get(void *priv)
{
	const struct mlxsw_sp_counter_sub_pool *sub_pool = priv;

	return atomic_read(&sub_pool->active_entries_count);
}

static int mlxsw_sp_counter_sub_pools_init(struct mlxsw_sp *mlxsw_sp)
{
	struct mlxsw_sp_counter_pool *pool = mlxsw_sp->counter_pool;
	struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
	struct mlxsw_sp_counter_sub_pool *sub_pool;
	unsigned int base_index = 0;
	enum mlxsw_res_id res_id;
	int err;
	int i;

	for (i = 0; i < pool->sub_pools_count; i++) {
		sub_pool = &pool->sub_pools[i];
		res_id = sub_pool->entry_size_res_id;

		if (!mlxsw_core_res_valid(mlxsw_sp->core, res_id))
			return -EIO;
		sub_pool->entry_size = mlxsw_core_res_get(mlxsw_sp->core,
							  res_id);
		err = devl_resource_size_get(devlink,
					     sub_pool->resource_id,
					     &sub_pool->size);
		if (err)
			goto err_resource_size_get;

		devl_resource_occ_get_register(devlink,
					       sub_pool->resource_id,
					       mlxsw_sp_counter_sub_pool_occ_get,
					       sub_pool);

		sub_pool->base_index = base_index;
		base_index += sub_pool->size;
		atomic_set(&sub_pool->active_entries_count, 0);
	}
	return 0;

err_resource_size_get:
	for (i--; i >= 0; i--) {
		sub_pool = &pool->sub_pools[i];

		devl_resource_occ_get_unregister(devlink,
						 sub_pool->resource_id);
	}
	return err;
}

static void mlxsw_sp_counter_sub_pools_fini(struct mlxsw_sp *mlxsw_sp)
{
	struct mlxsw_sp_counter_pool *pool = mlxsw_sp->counter_pool;
	struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
	struct mlxsw_sp_counter_sub_pool *sub_pool;
	int i;

	for (i = 0; i < pool->sub_pools_count; i++) {
		sub_pool = &pool->sub_pools[i];

		WARN_ON(atomic_read(&sub_pool->active_entries_count));
		devl_resource_occ_get_unregister(devlink,
						 sub_pool->resource_id);
	}
}

static u64 mlxsw_sp_counter_pool_occ_get(void *priv)
{
	const struct mlxsw_sp_counter_pool *pool = priv;

	return atomic_read(&pool->active_entries_count);
}

int mlxsw_sp_counter_pool_init(struct mlxsw_sp *mlxsw_sp)
{
	unsigned int sub_pools_count = ARRAY_SIZE(mlxsw_sp_counter_sub_pools);
	struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
	struct mlxsw_sp_counter_pool *pool;
	int err;

	pool = kzalloc(struct_size(pool, sub_pools, sub_pools_count),
		       GFP_KERNEL);
	if (!pool)
		return -ENOMEM;
	mlxsw_sp->counter_pool = pool;
	pool->sub_pools_count = sub_pools_count;
	memcpy(pool->sub_pools, mlxsw_sp_counter_sub_pools,
	       flex_array_size(pool, sub_pools, pool->sub_pools_count));
	spin_lock_init(&pool->counter_pool_lock);
	atomic_set(&pool->active_entries_count, 0);

	err = devl_resource_size_get(devlink, MLXSW_SP_RESOURCE_COUNTERS,
				     &pool->pool_size);
	if (err)
		goto err_pool_resource_size_get;
	devl_resource_occ_get_register(devlink, MLXSW_SP_RESOURCE_COUNTERS,
				       mlxsw_sp_counter_pool_occ_get, pool);

	pool->usage = bitmap_zalloc(pool->pool_size, GFP_KERNEL);
	if (!pool->usage) {
		err = -ENOMEM;
		goto err_usage_alloc;
	}

	err = mlxsw_sp_counter_sub_pools_init(mlxsw_sp);
	if (err)
		goto err_sub_pools_init;

	return 0;

err_sub_pools_init:
	bitmap_free(pool->usage);
err_usage_alloc:
	devl_resource_occ_get_unregister(devlink,
					 MLXSW_SP_RESOURCE_COUNTERS);
err_pool_resource_size_get:
	kfree(pool);
	return err;
}

void mlxsw_sp_counter_pool_fini(struct mlxsw_sp *mlxsw_sp)
{
	struct mlxsw_sp_counter_pool *pool = mlxsw_sp->counter_pool;
	struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);

	mlxsw_sp_counter_sub_pools_fini(mlxsw_sp);
	WARN_ON(find_first_bit(pool->usage, pool->pool_size) !=
			       pool->pool_size);
	WARN_ON(atomic_read(&pool->active_entries_count));
	bitmap_free(pool->usage);
	devl_resource_occ_get_unregister(devlink,
					 MLXSW_SP_RESOURCE_COUNTERS);
	kfree(pool);
}

int mlxsw_sp_counter_alloc(struct mlxsw_sp *mlxsw_sp,
			   enum mlxsw_sp_counter_sub_pool_id sub_pool_id,
			   unsigned int *p_counter_index)
{
	struct mlxsw_sp_counter_pool *pool = mlxsw_sp->counter_pool;
	struct mlxsw_sp_counter_sub_pool *sub_pool;
	unsigned int entry_index;
	unsigned int stop_index;
	int i, err;

	sub_pool = &pool->sub_pools[sub_pool_id];
	stop_index = sub_pool->base_index + sub_pool->size;
	entry_index = sub_pool->base_index;

	spin_lock(&pool->counter_pool_lock);
	entry_index = find_next_zero_bit(pool->usage, stop_index, entry_index);
	if (entry_index == stop_index) {
		err = -ENOBUFS;
		goto err_alloc;
	}
	/* The sub-pools can contain non-integer number of entries
	 * so we must check for overflow
	 */
	if (entry_index + sub_pool->entry_size > stop_index) {
		err = -ENOBUFS;
		goto err_alloc;
	}
	for (i = 0; i < sub_pool->entry_size; i++)
		__set_bit(entry_index + i, pool->usage);
	spin_unlock(&pool->counter_pool_lock);

	*p_counter_index = entry_index;
	atomic_add(sub_pool->entry_size, &sub_pool->active_entries_count);
	atomic_add(sub_pool->entry_size, &pool->active_entries_count);
	return 0;

err_alloc:
	spin_unlock(&pool->counter_pool_lock);
	return err;
}

void mlxsw_sp_counter_free(struct mlxsw_sp *mlxsw_sp,
			   enum mlxsw_sp_counter_sub_pool_id sub_pool_id,
			   unsigned int counter_index)
{
	struct mlxsw_sp_counter_pool *pool = mlxsw_sp->counter_pool;
	struct mlxsw_sp_counter_sub_pool *sub_pool;
	int i;

	if (WARN_ON(counter_index >= pool->pool_size))
		return;
	sub_pool = &pool->sub_pools[sub_pool_id];
	spin_lock(&pool->counter_pool_lock);
	for (i = 0; i < sub_pool->entry_size; i++)
		__clear_bit(counter_index + i, pool->usage);
	spin_unlock(&pool->counter_pool_lock);
	atomic_sub(sub_pool->entry_size, &sub_pool->active_entries_count);
	atomic_sub(sub_pool->entry_size, &pool->active_entries_count);
}

int mlxsw_sp_counter_resources_register(struct mlxsw_core *mlxsw_core)
{
	static struct devlink_resource_size_params size_params;
	struct devlink *devlink = priv_to_devlink(mlxsw_core);
	const struct mlxsw_sp_counter_sub_pool *sub_pool;
	unsigned int total_bank_config;
	u64 sub_pool_size;
	u64 base_index;
	u64 pool_size;
	u64 bank_size;
	int err;
	int i;

	if (!MLXSW_CORE_RES_VALID(mlxsw_core, COUNTER_POOL_SIZE) ||
	    !MLXSW_CORE_RES_VALID(mlxsw_core, COUNTER_BANK_SIZE))
		return -EIO;

	pool_size = MLXSW_CORE_RES_GET(mlxsw_core, COUNTER_POOL_SIZE);
	bank_size = MLXSW_CORE_RES_GET(mlxsw_core, COUNTER_BANK_SIZE);

	devlink_resource_size_params_init(&size_params, pool_size,
					  pool_size, bank_size,
					  DEVLINK_RESOURCE_UNIT_ENTRY);
	err = devl_resource_register(devlink,
				     MLXSW_SP_RESOURCE_NAME_COUNTERS,
				     pool_size,
				     MLXSW_SP_RESOURCE_COUNTERS,
				     DEVLINK_RESOURCE_ID_PARENT_TOP,
				     &size_params);
	if (err)
		return err;

	/* Allocation is based on bank count which should be
	 * specified for each sub pool statically.
	 */
	total_bank_config = 0;
	base_index = 0;
	for (i = 0; i < ARRAY_SIZE(mlxsw_sp_counter_sub_pools); i++) {
		sub_pool = &mlxsw_sp_counter_sub_pools[i];
		sub_pool_size = sub_pool->bank_count * bank_size;
		/* The last bank can't be fully used */
		if (base_index + sub_pool_size > pool_size)
			sub_pool_size = pool_size - base_index;
		base_index += sub_pool_size;

		devlink_resource_size_params_init(&size_params, sub_pool_size,
						  sub_pool_size, bank_size,
						  DEVLINK_RESOURCE_UNIT_ENTRY);
		err = devl_resource_register(devlink,
					     sub_pool->resource_name,
					     sub_pool_size,
					     sub_pool->resource_id,
					     MLXSW_SP_RESOURCE_COUNTERS,
					     &size_params);
		if (err)
			return err;
		total_bank_config += sub_pool->bank_count;
	}

	/* Check config is valid, no bank over subscription */
	if (WARN_ON(total_bank_config > div64_u64(pool_size, bank_size) + 1))
		return -EINVAL;

	return 0;
}
