nvmem: add ONIE NVMEM cells provider
cover nvmem: add ONIE NVMEM cells provider
This series adds cells provider for the ONIE TLV attributes which are stored on NVMEM device. It adds possibility to read the mac address (and other info) by other drivers.
Driver needs to register NVMEM cells table for already registered NVMEM device, this requires additional change to the core logic because current logic only allows to add additional cells only before nvmem device registration.
Vadym Kochan (2):
nvmem: core: allow to register cells for existing device
nvmem: add ONIE NVMEM cells support
drivers/nvmem/Kconfig | 9 ++ drivers/nvmem/Makefile | 3 + drivers/nvmem/core.c | 61 ++++--- drivers/nvmem/onie-cells.c | 324 +++++++++++++++++++++++++++++++++++++ 4 files changed, 375 insertions(+), 22 deletions(-) create mode 100644 drivers/nvmem/onie-cells.c
Signature · 1 line
2.17.1
PATCH 1/2 nvmem: core: allow to register cells for existing device
Current implementation does not allow to register nvmem cells for existing device and requires that this will be done before device is registered.
But there might a driver which provides only cells info which needs to be added for already registered nvmem device.
--- drivers/nvmem/core.c | 59 +++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 22 deletions(-)
drivers/nvmem/core.c +37 -22
@@ -482,35 +482,43 @@ int nvmem_unregister_notifier(struct notifier_block *nb) }EXPORT_SYMBOL_GPL (nvmem_unregister_notifier); -static int nvmem_add_cells_from_table (struct nvmem_device *nvmem) +static int __nvmem_add_cells_from_table (struct nvmem_device *nvmem, +struct nvmem_cell_table *table) {const struct nvmem_cell_info *info; -struct nvmem_cell_table *table;struct nvmem_cell *cell; -int rval =0 , i; +int err, i; + +for (i =0 ; i < table->ncells; i++) { + info = &table->cells[i]; + + cell =kzalloc (sizeof (*cell),GFP_KERNEL ); +if (!cell) +return -ENOMEM ; + + err =nvmem_cell_info_to_nvmem_cell (nvmem, info, cell); +if (err) { +kfree (cell); +return err; + } + +nvmem_cell_add (cell); + } + +return 0 ; +} + +static int nvmem_add_cells_from_table (struct nvmem_device *nvmem) +{ +struct nvmem_cell_table *table; +int rval =0 ;mutex_lock (&nvmem_cell_mutex);list_for_each_entry (table, &nvmem_cell_tables, node) {if (strcmp (nvmem_dev_name (nvmem), table->nvmem_name) ==0 ) { -for (i =0 ; i < table->ncells; i++) { - info = &table->cells[i]; - - cell =kzalloc (sizeof (*cell),GFP_KERNEL ); -if (!cell) { - rval = -ENOMEM ; - goto out; - } - - rval =nvmem_cell_info_to_nvmem_cell (nvmem, - info, - cell); -if (rval) { -kfree (cell); - goto out; - } - -nvmem_cell_add (cell); - } + rval =__nvmem_add_cells_from_table (nvmem, table); +if (rval) + goto out; } }
@@ -1560,6 +1568,13 @@ EXPORT_SYMBOL_GPL(nvmem_device_write);*/ void nvmem_add_cell_table (struct nvmem_cell_table *table) { +const char *dev_name = table->nvmem_name; +struct nvmem_device *nvmem; + + nvmem =__nvmem_device_get ((void *)dev_name, device_match_name); +if (nvmem) +__nvmem_add_cells_from_table (nvmem, table); +mutex_lock (&nvmem_cell_mutex);list_add_tail (&table->node, &nvmem_cell_tables);mutex_unlock (&nvmem_cell_mutex);
Signature · 1 line
2.17.1
PATCH 2/2 nvmem: add ONIE NVMEM cells support
In reply to Vadym KochanONIE is a small operating system, pre-installed on bare metal network switches, that provides an environment for automated provisioning.
This system requires that NVMEM (EEPROM) device holds various system information (mac address, platform name, etc) in a special TLV layout.
The driver registers ONIE TLV attributes as NVMEM cells which can be accessed by other platform driver. Also it allows to use of_get_mac_address() to retrieve mac address for the netdev.
--- drivers/nvmem/Kconfig | 9 + drivers/nvmem/Makefile | 3 + drivers/nvmem/onie-cells.c | 332 +++++++++++++++++++++++++++++++++++++ 3 files changed, 344 insertions(+) create mode 100644 drivers/nvmem/onie-cells.c
drivers/nvmem/Kconfig +9 -0
@@ -273,4 +273,13 @@ config SPRD_EFUSE This driver can also be built as a module. If so, the module will be called nvmem-sprd-efuse. +config NVMEM_ONIE_CELLS + tristate "ONIE TLV cells support" + help + This is a driver to provide cells from ONIE TLV structure stored + on NVME device. + + This driver can also be built as a module. If so, the module + will be called nvmem-onie-cells. + endif
drivers/nvmem/Makefile +3 -0
@@ -55,3 +55,6 @@ obj-$(CONFIG_NVMEM_ZYNQMP) += nvmem_zynqmp_nvmem.o nvmem_zynqmp_nvmem-y := zynqmp_nvmem.o obj-$(CONFIG_SPRD_EFUSE) += nvmem_sprd_efuse.o nvmem_sprd_efuse-y := sprd-efuse.o + +obj-$(CONFIG_NVMEM_ONIE_CELLS) += nvmem-onie-cells.o +nvmem-onie-cells-y := onie-cells.o
drivers/nvmem/onie-cells.c new file +332 -0
332 lines not on this page · raw message
Signature · 1 line
2.17.1
kbuild test robot
build botRe: [PATCH 2/2] nvmem: add ONIE NVMEM cells support
Thank you for the patch! Perhaps something to improve:
Hi Vadym,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on linux/master v5.7-rc7 next-20200529] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Vadym-Kochan/nvmem-add-ONIE-NVMEM-cells-provider/20200528-041903 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git b0c3ba31be3e45a130e13b278cf3b90f69bda6f6 config: x86_64-randconfig-r024-20200529 (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 2d068e534f1671459e1b135852c1b3c10502e929)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> drivers/nvmem/onie-cells.c:56:57: warning: size argument in 'memcmp' call is a comparison [-Wmemsize-comparison]
if (memcmp(hdr->id, ONIE_NVMEM_HDR_ID, sizeof(hdr->id) != 0))
~~~~~~~~~~~~~~~~^~~~drivers/nvmem/onie-cells.c:56:6: note: did you mean to compare the result of 'memcmp' instead? if (memcmp(hdr->id, ONIE_NVMEM_HDR_ID, sizeof(hdr->id) != 0))
^ ~
)drivers/nvmem/onie-cells.c:56:41: note: explicitly cast the argument to size_t to silence this warning if (memcmp(hdr->id, ONIE_NVMEM_HDR_ID, sizeof(hdr->id) != 0))
^
(size_t)( )
1 warning generated.
vim +/memcmp +56 drivers/nvmem/onie-cells.c
53
54 static bool onie_nvmem_hdr_is_valid(struct onie_nvmem_hdr *hdr)
55 {
> 56 if (memcmp(hdr->id, ONIE_NVMEM_HDR_ID, sizeof(hdr->id) != 0))
57 return false;
58 if (hdr->version != 0x1)
59 return false;
60
61 return true;
62 }
63 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org