From: Viktor Barna <viktor.barna@xxxxxxxxxx> (Part of the split. Please, take a look at the cover letter for more details). Signed-off-by: Viktor Barna <viktor.barna@xxxxxxxxxx> --- drivers/net/wireless/celeno/cl8k/config.h | 405 ++++++++++++++++++++++ 1 file changed, 405 insertions(+) create mode 100644 drivers/net/wireless/celeno/cl8k/config.h diff --git a/drivers/net/wireless/celeno/cl8k/config.h b/drivers/net/wireless/celeno/cl8k/config.h new file mode 100644 index 000000000000..b918e4423efe --- /dev/null +++ b/drivers/net/wireless/celeno/cl8k/config.h @@ -0,0 +1,405 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* Copyright(c) 2019-2022, Celeno Communications Ltd. */ + +#ifndef CL_CONFIG_H +#define CL_CONFIG_H + +#include <linux/types.h> +#include <linux/kernel.h> +#include <linux/dcache.h> + +#define MAX_PARAM_NAME_LENGTH 64 + +#define PRINT_UNSIGNED_ARR(param, old_val, size, new_val) \ +do { \ + u8 i; \ + char buf[STR_LEN_256B]; \ + int len = 0; \ + len += snprintf(buf, sizeof(buf), "%s: old value ", #param); \ + for (i = 0; i < (size) - 1; i++) \ + len += snprintf(buf + len, sizeof(buf) - len, \ + "%u,", old_val[i]); \ + len += snprintf(buf + len, sizeof(buf) - len, \ + "%u --> new value %s\n", old_val[(size) - 1], new_val); \ + pr_debug("%s", buf); \ +} while (0) + +#define READ_BOOL(param) \ +{ \ + if (!strcmp(name, #param)) { \ + bool new_val = false; \ + ret = kstrtobool(value, &new_val); \ + if (ret) { \ + pr_err("%s: invalid value [%s]\n", #param, value); \ + break; \ + } \ + if (conf->param != new_val) { \ + pr_debug("%s: old value %u -> new value %u\n", \ + #param, conf->param, new_val); \ + conf->param = new_val; \ + } \ + break; \ + } \ +} + +#define READ_U8(param) \ +{ \ + if (!strcmp(name, #param)) { \ + u8 new_val = 0; \ + ret = kstrtou8(value, 0, &new_val); \ + if (ret) { \ + pr_err("%s: invalid value [%s]\n", #param, value); \ + break; \ + } \ + if (conf->param != new_val) { \ + pr_debug("%s: old value %u -> new value %u\n", \ + #param, conf->param, new_val); \ + conf->param = new_val; \ + } \ + break; \ + } \ +} + +#define READ_U16(param) \ +{ \ + if (!strcmp(name, #param)) { \ + u16 new_val = 0; \ + ret = kstrtou16(value, 0, &new_val); \ + if (ret) { \ + pr_err("%s: invalid value [%s]\n", #param, value); \ + break; \ + } \ + if (conf->param != new_val) { \ + pr_debug("%s: old value %u -> new value %u\n", \ + #param, conf->param, new_val); \ + conf->param = new_val; \ + } \ + break; \ + } \ +} + +#define READ_U32(param) \ +{ \ + if (!strcmp(name, #param)) { \ + u32 new_val = 0; \ + ret = kstrtou32(value, 0, &new_val); \ + if (ret) { \ + pr_err("%s: invalid value [%s]\n", #param, value); \ + break; \ + } \ + if (conf->param != new_val) { \ + pr_debug("%s: old value %u -> new value %u\n", \ + #param, conf->param, new_val); \ + conf->param = new_val; \ + } \ + break; \ + } \ +} + +#define READ_S8(param) \ +{ \ + if (!strcmp(name, #param)) { \ + s8 new_val = 0; \ + ret = kstrtos8(value, 0, &new_val); \ + if (ret) { \ + pr_err("%s: invalid value [%s]\n", #param, value); \ + break; \ + } \ + if (conf->param != new_val) { \ + pr_debug("%s: old value %d -> new value %d\n", \ + #param, conf->param, new_val); \ + conf->param = new_val; \ + } \ + break; \ + } \ +} + +#define READ_S16(param) \ +{ \ + if (!strcmp(name, #param)) { \ + s16 new_val = 0; \ + ret = kstrtos16(value, 0, &new_val); \ + if (ret) { \ + pr_err("%s: invalid value [%s]\n", #param, value); \ + break; \ + } \ + if (conf->param != new_val) { \ + pr_debug("%s: old value %d -> new value %d\n", \ + #param, conf->param, new_val); \ + conf->param = new_val; \ + } \ + break; \ + } \ +} + +#define READ_S32(param) \ +{ \ + if (!strcmp(name, #param)) { \ + s32 new_val = 0; \ + ret = kstrtos32(value, 0, &new_val); \ + if (ret) { \ + pr_err("%s: invalid value [%s]\n", #param, value); \ + break; \ + } \ + if (conf->param != new_val) { \ + pr_debug("%s: old value %d -> new value %d\n", \ + #param, conf->param, new_val); \ + conf->param = new_val; \ + } \ + break; \ + } \ +} + +#define READ_BOOL_ARR(param, size) \ +{ \ + if (!strcmp(name, #param)) { \ + u8 i = 0; \ + char *buf = NULL; \ + char vector[STR_LEN_256B] = {0}; \ + char *vector_p = &vector[i]; \ + bool old_val[size] = {false}; \ + memcpy(old_val, conf->param, sizeof(old_val)); \ + if (strlen(value) >= sizeof(vector)) { \ + pr_err("%s: value [%s] too big [%zu]\n", #param, value, strlen(value)); \ + ret = -E2BIG; \ + break; \ + } \ + strscpy(vector_p, value, sizeof(vector)); \ + buf = strsep(&vector_p, ","); \ + if (!buf) { \ + pr_err("%s: delimiter ',' not found\n", #param); \ + ret = -EIO; \ + break; \ + } \ + if (kstrtobool(buf, &conf->param[0]) != 0) { \ + pr_err("%s: invalid argument [%s]\n", #param, value); \ + ret = -EINVAL; \ + break; \ + } \ + for (i = 1; i < (size); i++) { \ + buf = strsep(&vector_p, ","); \ + if (!buf) \ + break; \ + if (kstrtobool(buf, &conf->param[i]) != 0) { \ + pr_err("%s: invalid argument [%s]\n", #param, value); \ + break; \ + } \ + } \ + if (i < size) { \ + pr_err("%s: value [%s] doesn't have %u elements\n", #param, value, size); \ + ret = -ENODATA; \ + break; \ + } \ + ret = 0; \ + if (memcmp(old_val, conf->param, sizeof(old_val))) \ + PRINT_UNSIGNED_ARR(param, old_val, size, value); \ + break; \ + } \ +} + +#define READ_U8_ARR(param, size, is_array_fix_size) \ +{ \ + if (!strcmp(name, #param)) { \ + u8 i = 0; \ + char *buf = NULL; \ + char vector[STR_LEN_256B] = {0}; \ + char *vector_p = &vector[0]; \ + u8 old_val[size] = {false}; \ + memcpy(old_val, conf->param, sizeof(old_val)); \ + if (strlen(value) >= sizeof(vector)) { \ + pr_err("%s: value [%s] too big [%zu]\n", #param, value, strlen(value)); \ + ret = -E2BIG; \ + break; \ + } \ + strscpy(vector_p, value, sizeof(vector)); \ + buf = strsep(&vector_p, ","); \ + if (!buf) { \ + pr_err("%s: delimiter ',' not found\n", #param); \ + ret = -EIO; \ + break; \ + } \ + if (kstrtou8(buf, 0, &conf->param[0]) != 0) { \ + pr_err("%s: invalid argument [%s]\n", #param, value); \ + ret = -EINVAL; \ + break; \ + } \ + for (i = 1; i < (size); i++) { \ + buf = strsep(&vector_p, ","); \ + if (!buf) \ + break; \ + if (kstrtou8(buf, 0, &conf->param[i]) != 0) { \ + pr_err("%s: invalid argument [%s]\n", #param, value); \ + break; \ + } \ + } \ + if ((is_array_fix_size) && i < (size)) { \ + pr_err("%s: value [%s] doesn't have %u elements\n", #param, value, size); \ + ret = -ENODATA; \ + break; \ + } \ + ret = 0; \ + if (memcmp(old_val, conf->param, sizeof(old_val))) \ + PRINT_UNSIGNED_ARR(param, old_val, size, value); \ + break; \ + } \ +} + +#define READ_U16_ARR(param, size, is_array_fix_size) \ +{ \ + if (!strcmp(name, #param)) { \ + u8 i = 0; \ + char *buf = NULL; \ + char vector[STR_LEN_256B] = {0}; \ + char *vector_p = &vector[0]; \ + u16 old_val[size] = {false}; \ + memcpy(old_val, conf->param, sizeof(old_val)); \ + if (strlen(value) >= sizeof(vector)) { \ + pr_err("%s: value [%s] too big [%zu]\n", #param, value, strlen(value)); \ + ret = -E2BIG; \ + break; \ + } \ + strscpy(vector_p, value, sizeof(vector)); \ + buf = strsep(&vector_p, ","); \ + if (!buf) { \ + pr_err("%s: delimiter ',' not found\n", #param); \ + ret = -EIO; \ + break; \ + } \ + if (kstrtou16(buf, 0, &conf->param[0]) != 0) { \ + pr_err("%s: invalid argument [%s]\n", #param, value); \ + ret = -EINVAL; \ + break; \ + } \ + for (i = 1; i < (size); i++) { \ + buf = strsep(&vector_p, ","); \ + if (!buf) \ + break; \ + if (kstrtou16(buf, 0, &conf->param[i]) != 0) { \ + pr_err("%s: invalid argument [%s]\n", #param, value); \ + break; \ + } \ + } \ + if ((is_array_fix_size) && i < (size)) { \ + pr_err("%s: value [%s] doesn't have %u elements\n", #param, value, size); \ + ret = -ENODATA; \ + break; \ + } \ + ret = 0; \ + if (memcmp(old_val, conf->param, sizeof(old_val))) \ + PRINT_UNSIGNED_ARR(param, old_val, size, value); \ + break; \ + } \ +} + +#define READ_S8_ARR(param, size) \ +{ \ + if (!strcmp(name, #param)) { \ + u8 i = 0; \ + char *buf = NULL; \ + char vector[STR_LEN_256B] = {0}; \ + char *vector_p = &vector[0]; \ + s8 old_val[size] = {false}; \ + memcpy(old_val, conf->param, sizeof(old_val)); \ + if (strlen(value) >= sizeof(vector)) { \ + pr_err("%s: value [%s] too big [%zu]\n", #param, value, strlen(value)); \ + ret = -E2BIG; \ + break; \ + } \ + strscpy(vector_p, value, sizeof(vector)); \ + buf = strsep(&vector_p, ","); \ + if (!buf) { \ + pr_err("%s: delimiter ',' not found\n", #param); \ + ret = -EIO; \ + break; \ + } \ + if (kstrtos8(buf, 0, &conf->param[0]) != 0) { \ + pr_err("%s: invalid argument [%s]\n", #param, value); \ + ret = -EINVAL; \ + break; \ + } \ + for (i = 1; i < (size); i++) { \ + buf = strsep(&vector_p, ","); \ + if (!buf) \ + break; \ + if (kstrtos8(buf, 0, &conf->param[i]) != 0) { \ + pr_err("%s: invalid argument [%s]\n", #param, value); \ + break; \ + } \ + } \ + if (i < (size)) { \ + pr_err("%s: value [%s] doesn't have %u elements\n", #param, value, size); \ + ret = -ENODATA; \ + break; \ + } \ + ret = 0; \ + if (memcmp(old_val, conf->param, sizeof(old_val))) \ + PRINT_UNSIGNED_ARR(param, old_val, size, value); \ + break; \ + } \ +} + +#define READ_STR(param) \ +{ \ + if (!strcmp(name, #param)) { \ + if (strcmp(value, conf->param)) { \ + pr_debug("%s: old value %s -> new value %s\n", \ + #param, conf->param, value); \ + strncpy(conf->param, value, sizeof(conf->param) - 1); \ + } \ + ret = 0; \ + break; \ + } \ +} + +#define READ_MAC(param) \ +{ \ + if (!strcmp(name, #param)) { \ + u8 i = 0; \ + char *buf = NULL; \ + char vector[STR_LEN_32B] = {0}; \ + char *vector_p = &vector[0]; \ + u8 old_val[ETH_ALEN] = {false}; \ + memcpy(old_val, conf->param, ETH_ALEN); \ + if (strlen(value) >= sizeof(vector)) { \ + pr_err("%s: value [%s] too big [%zu]\n", #param, value, strlen(value)); \ + ret = -E2BIG; \ + break; \ + } \ + strscpy(vector_p, value, sizeof(vector)); \ + buf = strsep(&vector_p, ":"); \ + if (!buf) { \ + pr_err("%s: delimiter ':' not found\n", #param); \ + ret = -EIO; \ + break; \ + } \ + if (kstrtou8(buf, 16, &conf->param[0]) != 0) { \ + pr_err("%s: invalid argument [%s]\n", #param, value); \ + ret = -EINVAL; \ + break; \ + } \ + for (i = 1; i < ETH_ALEN; i++) { \ + buf = strsep(&vector_p, ":"); \ + if (!buf) \ + break; \ + if (kstrtou8(buf, 16, &conf->param[i]) != 0) { \ + pr_err("%s: invalid argument [%s]\n", #param, value); \ + break; \ + } \ + } \ + if (i < ETH_ALEN) { \ + pr_err("%s: value [%s] doesn't have %u elements\n", #param, value, \ + ETH_ALEN); \ + ret = -ENODATA; \ + break; \ + } \ + ret = 0; \ + if (memcmp(old_val, conf->param, sizeof(old_val))) \ + pr_debug("%s: old value %pM -> new value %pM\n", \ + #param, old_val, conf->param); \ + break; \ + } \ +} + +bool cl_config_is_non_driver_param(char *name); + +#endif /* CL_CONFIG_H */ -- 2.36.1