nvmem: core: introduce NVMEM layouts
Subsystems (7)
v5 cover nvmem: core: introduce NVMEM layouts
This is now the third attempt to fetch the MAC addresses from the VPD for the Kontron sl28 boards. Previous discussions can be found here:
https://lore.kernel.org/lkml/[email protected]/
NVMEM cells are typically added by board code or by the devicetree. But as the cells get more complex, there is (valid) push back from the devicetree maintainers to not put that handling in the devicetree.
Therefore, introduce NVMEM layouts. They operate on the NVMEM device and can add cells during runtime. That way it is possible to add more complex cells than it is possible right now with the offset/length/bits description in the device tree. For example, you can have post processing for individual cells (think of endian swapping, or ethernet offset handling).
The imx-ocotp driver is the only user of the global post processing hook, convert it to nvmem layouts and drop the global post pocessing hook.
For now, the layouts are selected by the device tree. But the idea is that also board files or other drivers could set a layout. Although no code for that exists yet.
Thanks to Miquel, the device tree bindings are already approved and merged.
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM core can't be compiled as a module. The layouts needs to be available at probe time. (That is also the reason why they get registered with subsys_initcall().) So if the NVMEM core would be a module, the layouts could be modules, too.
Michael Walle (19):
net: add helper eth_addr_add()
of: base: add of_parse_phandle_with_optional_args()
of: property: make #.*-cells optional for simple props
of: property: add #nvmem-cell-cells property
nvmem: core: fix device node refcounting
nvmem: core: add an index parameter to the cell
nvmem: core: move struct nvmem_cell_info to nvmem-provider.h
nvmem: core: drop the removal of the cells in nvmem_add_cells()
nvmem: core: fix cell removal on error
nvmem: core: add nvmem_add_one_cell()
nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of()
nvmem: core: introduce NVMEM layouts
nvmem: core: add per-cell post processing
nvmem: core: allow to modify a cell before adding it
nvmem: imx-ocotp: replace global post processing with layouts
nvmem: cell: drop global cell_post_process
nvmem: core: provide own priv pointer in post process callback
nvmem: layouts: add sl28vpd layout
MAINTAINERS: add myself as sl28vpd nvmem layout driver
Miquel Raynal (2):
nvmem: layouts: Add ONIE tlv layout driver
MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer
Documentation/driver-api/nvmem.rst | 15 ++ MAINTAINERS | 12 ++ drivers/nvmem/Kconfig | 4 + drivers/nvmem/Makefile | 1 + drivers/nvmem/core.c | 295 +++++++++++++++++++++-------- drivers/nvmem/imx-ocotp.c | 34 ++-- drivers/nvmem/layouts/Kconfig | 23 +++ drivers/nvmem/layouts/Makefile | 7 + drivers/nvmem/layouts/onie-tlv.c | 244 ++++++++++++++++++++++++ drivers/nvmem/layouts/sl28vpd.c | 153 +++++++++++++++ drivers/of/property.c | 6 +- include/linux/etherdevice.h | 14 ++ include/linux/nvmem-consumer.h | 17 +- include/linux/nvmem-provider.h | 95 +++++++++- include/linux/of.h | 25 +++ 15 files changed, 837 insertions(+), 108 deletions(-) create mode 100644 drivers/nvmem/layouts/Kconfig create mode 100644 drivers/nvmem/layouts/Makefile create mode 100644 drivers/nvmem/layouts/onie-tlv.c create mode 100644 drivers/nvmem/layouts/sl28vpd.c
Signature · 1 line
2.30.2
PATCH v5 1/21 net: add helper eth_addr_add()
Add a helper to add an offset to a ethernet address. This comes in handy if you have a base ethernet address for multiple interfaces.
---
changes since v4:
- none
changes since v3:
- fix typo s/and/an/
changes since v2:
- none
changes since v1:
- none
include/linux/etherdevice.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/linux/etherdevice.h +14 -0
@@ -507,6 +507,20 @@ static inline void eth_addr_inc(u8 *addr)u64_to_ether_addr (u, addr); } +/** +* eth_addr_add() - Add (or subtract) an offset to/from the given MAC address. +* +* @offset: Offset to add. +* @addr: Pointer to a six-byte array containing Ethernet address to increment. +*/ +static inline void eth_addr_add (u8 *addr,long offset) +{ +u64 u =ether_addr_to_u64 (addr); + + u += offset; +u64_to_ether_addr (u, addr); +} +/** * is_etherdev_addr - Tell if given Ethernet address belongs to the device. * @dev: Pointer to a device structure
Signature · 1 line
2.30.2
PATCH v5 2/21 of: base: add of_parse_phandle_with_optional_args()
In reply to Michael WalleAdd a new variant of the of_parse_phandle_with_args() which treats the cells name as optional. If it's missing, it is assumed that the phandle has no arguments.
Up until now, a nvmem node didn't have any arguments, so all the device trees haven't any '#*-cells' property. But there is a need for an additional argument for the phandle, for which we need a '#*-cells' property. Therefore, we need to support nvmem nodes with and without this property.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- none
changes since v1:
- none
include/linux/of.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
include/linux/of.h +25 -0
@@ -1008,6 +1008,31 @@ static inline int of_parse_phandle_with_fixed_args(const struct device_node *np, index, out_args); } +/** +* of_parse_phandle_with_optional_args() - Find a node pointed by phandle in a list +* @np: pointer to a device tree node containing a list +* @list_name: property name that contains a list +* @cells_name: property name that specifies phandles' arguments count +* @index: index of a phandle to parse out +* @out_args: optional pointer to output arguments structure (will be filled) +* +* Same as of_parse_phandle_with_args() except that if the cells_name property +* is not found, cell_count of 0 is assumed. +* +* This is used to useful, if you have a phandle which didn't have arguments +* before and thus doesn't have a '#*-cells' property but is now migrated to +* having arguments while retaining backwards compatibility. +*/ +static inline int of_parse_phandle_with_optional_args (const struct device_node *np, +const char *list_name, +const char *cells_name, +int index, +struct of_phandle_args *out_args) +{ +return __of_parse_phandle_with_args (np, list_name, cells_name, +0 , index, out_args); +} +/** * of_property_count_u8_elems - Count the number of u8 elements in a property *
Signature · 1 line
2.30.2
PATCH v5 3/21 of: property: make #.*-cells optional for simple props
In reply to Michael WalleSometimes, future bindings for phandles will get additional arguments. Thus the target node of the phandle will need a new #.*-cells property. To be backwards compatible, this needs to be optional.
Prepare the DEFINE_SIMPLE_PROPS() to handle the cells name as optional.
---
changes since v4:
- none
changes since v3:
- new patch
drivers/of/property.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/of/property.c +2 -2
@@ -1256,8 +1256,8 @@ static struct device_node *parse_suffix_prop_cells(struct device_node *np,if (strcmp_suffix (prop_name, suffix))return NULL ; -if (of_parse_phandle_with_args (np, prop_name, cells_name, index, - &sup_args)) +if (__of_parse_phandle_with_args (np, prop_name, cells_name,0 , index, + &sup_args))return NULL ;return sup_args.np;
Signature · 1 line
2.30.2
PATCH v5 4/21 of: property: add #nvmem-cell-cells property
In reply to Michael WalleBindings describe the new '#nvmem-cell-cells' property. Now that the arguments count property is optional, we just add this property to the nvmem-cells.
---
changes since v4:
- new patch
changes since v3:
- new patch
drivers/of/property.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/of/property.c +1 -1
@@ -1307,7 +1307,7 @@ DEFINE_SIMPLE_PROP(dmas, "dmas", "#dma-cells") DEFINE_SIMPLE_PROP(power_domains, "power-domains", "#power-domain-cells") DEFINE_SIMPLE_PROP(hwlocks, "hwlocks", "#hwlock-cells") DEFINE_SIMPLE_PROP(extcon, "extcon", NULL) -DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", NULL) +DEFINE_SIMPLE_PROP(nvmem_cells, "nvmem-cells", "#nvmem-cell-cells") DEFINE_SIMPLE_PROP(phys, "phys", "#phy-cells") DEFINE_SIMPLE_PROP(wakeup_parent, "wakeup-parent", NULL)DEFINE_SIMPLE_PROP (pinctrl0,"pinctrl-0" ,NULL )
Signature · 1 line
2.30.2
PATCH v5 5/21 nvmem: core: fix device node refcounting
In reply to Michael WalleIn of_nvmem_cell_get(), of_get_next_parent() is used on cell_np. This will decrement the refcount on cell_np, but cell_np is still used later in the code. Use of_get_parent() instead and of_node_put() in the appropriate places.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- new patch
drivers/nvmem/core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/nvmem/core.c +8 -3
@@ -1242,16 +1242,21 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)if (!cell_np)return ERR_PTR (-ENOENT ); - nvmem_np =of_get_next_parent (cell_np); -if (!nvmem_np) + nvmem_np =of_get_parent (cell_np); +if (!nvmem_np) { +of_node_put (cell_np);return ERR_PTR (-EINVAL ); + } nvmem =__nvmem_device_get (nvmem_np, device_match_of_node);of_node_put (nvmem_np); -if (IS_ERR (nvmem)) +if (IS_ERR (nvmem)) { +of_node_put (cell_np);return ERR_CAST (nvmem); + } cell_entry =nvmem_find_cell_entry_by_node (nvmem, cell_np); +of_node_put (cell_np);if (!cell_entry) {__nvmem_device_put (nvmem);return ERR_PTR (-ENOENT );
Signature · 1 line
2.30.2
PATCH v5 6/21 nvmem: core: add an index parameter to the cell
In reply to Michael WalleSometimes a cell can represend multiple values. For example, a base ethernet address stored in the NVMEM can be expanded into multiple discreet ones by adding an offset.
For this use case, introduce an index parameter which is then used to distiguish between values. This parameter will then be passed to the post process hook which can then use it to create different values during reading.
At the moment, there is only support for the device tree path. You can add the index to the phandle, e.g.
&net {
nvmem-cells = <&base_mac_address 2>;
nvmem-cell-names = "mac-address";
};
&nvmem_provider {
base_mac_address: base-mac-address@0 {
#nvmem-cell-cells = <1>;
reg = <0 6>;
};
};---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- none
changes since v1:
- none
drivers/nvmem/core.c | 37 ++++++++++++++++++++++++---------- drivers/nvmem/imx-ocotp.c | 4 ++-- include/linux/nvmem-provider.h | 4 ++-- 3 files changed, 30 insertions(+), 15 deletions(-)
drivers/nvmem/core.c +26 -11
@@ -60,6 +60,7 @@ struct nvmem_cell_entry {struct nvmem_cell {struct nvmem_cell_entry *entry;const char *id; +int index; };static DEFINE_MUTEX (nvmem_mutex);
@@ -1127,7 +1128,8 @@ struct nvmem_device *devm_nvmem_device_get(struct device *dev, const char *id) }EXPORT_SYMBOL_GPL (devm_nvmem_device_get); -static struct nvmem_cell *nvmem_create_cell (struct nvmem_cell_entry *entry,const char *id) +static struct nvmem_cell *nvmem_create_cell (struct nvmem_cell_entry *entry, +const char *id,int index) {struct nvmem_cell *cell;const char *name =NULL ;
@@ -1146,6 +1148,7 @@ static struct nvmem_cell *nvmem_create_cell(struct nvmem_cell_entry *entry, cons cell->id = name; cell->entry = entry; + cell->index = index;return cell; }
@@ -1184,7 +1187,7 @@ nvmem_cell_get_from_lookup(struct device *dev, const char *con_id)__nvmem_device_put (nvmem); cell =ERR_PTR (-ENOENT ); }else { - cell =nvmem_create_cell (cell_entry, con_id); + cell =nvmem_create_cell (cell_entry, con_id,0 );if (IS_ERR (cell))__nvmem_device_put (nvmem); }
@@ -1232,15 +1235,27 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)struct nvmem_device *nvmem;struct nvmem_cell_entry *cell_entry;struct nvmem_cell *cell; +struct of_phandle_args cell_spec;int index =0 ; +int cell_index =0 ; +int ret;/* if cell name exists, find index to the name */ if (id) index =of_property_match_string (np,"nvmem-cell-names" , id); - cell_np =of_parse_phandle (np,"nvmem-cells" , index); -if (!cell_np) -return ERR_PTR (-ENOENT ); + ret =of_parse_phandle_with_optional_args (np,"nvmem-cells" , +"#nvmem-cell-cells" , + index, &cell_spec); +if (ret) +return ERR_PTR (ret); + +if (cell_spec.args_count >1 ) +return ERR_PTR (-EINVAL ); + + cell_np = cell_spec.np; +if (cell_spec.args_count) + cell_index = cell_spec.args[0 ]; nvmem_np =of_get_parent (cell_np);if (!nvmem_np) {
@@ -1262,7 +1277,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)return ERR_PTR (-ENOENT ); } - cell =nvmem_create_cell (cell_entry, id); + cell =nvmem_create_cell (cell_entry, id, cell_index);if (IS_ERR (cell))__nvmem_device_put (nvmem);
@@ -1415,8 +1430,8 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void }static int __nvmem_cell_read (struct nvmem_device *nvmem, -struct nvmem_cell_entry *cell, -void *buf,size_t *len,const char *id) +struct nvmem_cell_entry *cell, +void *buf,size_t *len,const char *id,int index) {int rc;
@@ -1430,7 +1445,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,nvmem_shift_read_buffer_in_place (cell, buf);if (nvmem->cell_post_process) { - rc = nvmem->cell_post_process (nvmem->priv, id, + rc = nvmem->cell_post_process (nvmem->priv, id, index, cell->offset, buf, cell->bytes);if (rc)return rc;
@@ -1465,7 +1480,7 @@ void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len)if (!buf)return ERR_PTR (-ENOMEM ); - rc =__nvmem_cell_read (nvmem, cell->entry, buf, len, cell->id); + rc =__nvmem_cell_read (nvmem, cell->entry, buf, len, cell->id, cell->index);if (rc) {kfree (buf);return ERR_PTR (rc);
@@ -1778,7 +1793,7 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem,if (rc)return rc; - rc =__nvmem_cell_read (nvmem, &cell, buf, &len,NULL ); + rc =__nvmem_cell_read (nvmem, &cell, buf, &len,NULL ,0 );if (rc)return rc;
drivers/nvmem/imx-ocotp.c +2 -2
@@ -222,8 +222,8 @@ static int imx_ocotp_read(void *context, unsigned int offset,return ret; } -static int imx_ocotp_cell_pp (void *context,const char *id,unsigned int offset, -void *data,size_t bytes) +static int imx_ocotp_cell_pp (void *context,const char *id,int index, +unsigned int offset,void *data,size_t bytes) {struct ocotp_priv *priv = context;
include/linux/nvmem-provider.h +2 -2
@@ -20,8 +20,8 @@ typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset,typedef int (*nvmem_reg_write_t )(void *priv,unsigned int offset,void *val,size_t bytes);/* used for vendor specific post processing of cell data */ -typedef int (*nvmem_cell_post_process_t )(void *priv,const char *id,unsigned int offset, -void *buf,size_t bytes); +typedef int (*nvmem_cell_post_process_t )(void *priv,const char *id,int index, +unsigned int offset,void *buf,size_t bytes);enum nvmem_type {NVMEM_TYPE_UNKNOWN =0 ,
Signature · 1 line
2.30.2
PATCH v5 7/21 nvmem: core: move struct nvmem_cell_info to nvmem-provider.h
In reply to Michael Wallestruct nvmem_cell_info is used to describe a cell. Thus this should really be in the nvmem-provider's header. There are two (unused) nvmem access methods which use the nvmem_cell_info to describe the cell to be accesses. One can argue, that they will create a cell before accessing, thus they are both a provider and a consumer.
struct nvmem_cell_info will get used more and more by nvmem-providers, don't force them to also include the consumer header, although they are not.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- none
changes since v1:
- new patch
include/linux/nvmem-consumer.h | 10 +--------- include/linux/nvmem-provider.h | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 10 deletions(-)
include/linux/nvmem-consumer.h +1 -9
@@ -18,15 +18,7 @@ struct device_node;/* consumer cookie */ struct nvmem_cell ;struct nvmem_device ; - -struct nvmem_cell_info { -const char *name; -unsigned int offset; -unsigned int bytes; -unsigned int bit_offset; -unsigned int nbits; -struct device_node *np; -}; +struct nvmem_cell_info ;/** * struct nvmem_cell_lookup - cell lookup entry
include/linux/nvmem-provider.h +18 -1
@@ -14,7 +14,6 @@#include <linux/gpio/consumer.h> struct nvmem_device ; -struct nvmem_cell_info ;typedef int (*nvmem_reg_read_t )(void *priv,unsigned int offset,void *val,size_t bytes); typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset,
@@ -47,6 +46,24 @@ struct nvmem_keepout {unsigned char value; }; +/** +* struct nvmem_cell_info - NVMEM cell description +* @name: Name. +* @offset: Offset within the NVMEM device. +* @bytes: Length of the cell. +* @bit_offset: Bit offset if cell is smaller than a byte. +* @nbits: Number of bits. +* @np: Optional device_node pointer. +*/ +struct nvmem_cell_info { +const char *name; +unsigned int offset; +unsigned int bytes; +unsigned int bit_offset; +unsigned int nbits; +struct device_node *np; +}; +/** * struct nvmem_config - NVMEM device configuration *
Signature · 1 line
2.30.2
PATCH v5 8/21 nvmem: core: drop the removal of the cells in nvmem_add_cells()
In reply to Michael WalleIf nvmem_add_cells() fails, the whole nvmem_register() will fail and the cells will then be removed anyway. This is a preparation to introduce a nvmem_add_one_cell() which can then be used by nvmem_add_cells().
This is then the same to what nvmem_add_cells_from_table() and nvmem_add_cells_from_of() do.
---
changes since v4:
- none
changes since v3:
- fix typo, s/prepartion/preparation/
changes since v2:
- none
changes since v1:
- none
drivers/nvmem/core.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/nvmem/core.c +4 -10
@@ -515,7 +515,7 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, int ncells) {struct nvmem_cell_entry **cells; -int i, rval; +int i, rval =0 ; cells =kcalloc (ncells,sizeof (*cells),GFP_KERNEL );if (!cells)
@@ -525,28 +525,22 @@ static int nvmem_add_cells(struct nvmem_device *nvmem, cells[i] =kzalloc (sizeof (**cells),GFP_KERNEL );if (!cells[i]) { rval = -ENOMEM ; - goto err; + goto out; } rval =nvmem_cell_info_to_nvmem_cell_entry (nvmem, &info[i], cells[i]);if (rval) {kfree (cells[i]); - goto err; + goto out; }nvmem_cell_entry_add (cells[i]); } +out:/* remove tmp array */ kfree (cells); -return 0 ; -err: -while (i--) -nvmem_cell_entry_drop (cells[i]); - -kfree (cells); -return rval; }
Signature · 1 line
2.30.2
PATCH v5 9/21 nvmem: core: fix cell removal on error
In reply to Michael Wallenvmem_add_cells() could return an error after some cells are already added to the provider. In this case, the added cells are not removed. Remove any registered cells if nvmem_add_cells() fails.
---
changes since v4:
- new patch
drivers/nvmem/core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nvmem/core.c +1 -2
@@ -851,7 +851,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)if (config->cells) { rval =nvmem_add_cells (nvmem, config->cells, config->ncells);if (rval) - goto err_teardown_compat; + goto err_remove_cells; } rval =nvmem_add_cells_from_table (nvmem);
@@ -868,7 +868,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_remove_cells:nvmem_device_remove_all_cells (nvmem); -err_teardown_compat:if (config->compat)nvmem_sysfs_remove_compat (nvmem, config); err_device_del:
Signature · 1 line
2.30.2
PATCH v5 10/21 nvmem: core: add nvmem_add_one_cell()
In reply to Michael WalleAdd a new function to add exactly one cell. This will be used by the nvmem layout drivers to add custom cells. In contrast to the nvmem_add_cells(), this has the advantage that we don't have to assemble a list of cells on runtime.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- add EXPORT_SYMBOL_GPL()
changes since v1:
- none
drivers/nvmem/core.c | 59 ++++++++++++++++++++-------------- include/linux/nvmem-provider.h | 8 +++++ 2 files changed, 43 insertions(+), 24 deletions(-)
drivers/nvmem/core.c +35 -24
@@ -501,6 +501,36 @@ static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,return 0 ; } +/** +* nvmem_add_one_cell() - Add one cell information to an nvmem device +* +* @nvmem: nvmem device to add cells to. +* @info: nvmem cell info to add to the device +* +* Return: 0 or negative error code on failure. +*/ +int nvmem_add_one_cell (struct nvmem_device *nvmem, +const struct nvmem_cell_info *info) +{ +struct nvmem_cell_entry *cell; +int rval; + + cell =kzalloc (sizeof (*cell),GFP_KERNEL ); +if (!cell) +return -ENOMEM ; + + rval =nvmem_cell_info_to_nvmem_cell_entry (nvmem, info, cell); +if (rval) { +kfree (cell); +return rval; + } + +nvmem_cell_entry_add (cell); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nvmem_add_one_cell); +/** * nvmem_add_cells() - Add cell information to an nvmem device *
@@ -514,34 +544,15 @@ static int nvmem_add_cells(struct nvmem_device *nvmem,const struct nvmem_cell_info *info, int ncells) { -struct nvmem_cell_entry **cells; -int i, rval =0 ; - - cells =kcalloc (ncells,sizeof (*cells),GFP_KERNEL ); -if (!cells) -return -ENOMEM ; + int i, rval;for (i =0 ; i < ncells; i++) { - cells[i] =kzalloc (sizeof (**cells),GFP_KERNEL ); -if (!cells[i]) { - rval = -ENOMEM ; - goto out; - } - - rval =nvmem_cell_info_to_nvmem_cell_entry (nvmem, &info[i], cells[i]); -if (rval) { -kfree (cells[i]); - goto out; - } - -nvmem_cell_entry_add (cells[i]); + rval =nvmem_add_one_cell (nvmem, &info[i]); +if (rval) +return rval; } -out: -/* remove tmp array */ -kfree (cells); - -return rval; +return 0 ; }/**
include/linux/nvmem-provider.h +8 -0
@@ -155,6 +155,9 @@ struct nvmem_device *devm_nvmem_register(struct device *dev,void nvmem_add_cell_table (struct nvmem_cell_table *table);void nvmem_del_cell_table (struct nvmem_cell_table *table); +int nvmem_add_one_cell (struct nvmem_device *nvmem, +const struct nvmem_cell_info *info); +#else static inline struct nvmem_device *nvmem_register (const struct nvmem_config *c)
@@ -172,6 +175,11 @@ devm_nvmem_register(struct device *dev, const struct nvmem_config *c)static inline void nvmem_add_cell_table (struct nvmem_cell_table *table) {}static inline void nvmem_del_cell_table (struct nvmem_cell_table *table) {} +static inline int nvmem_add_one_cell (struct nvmem_device *nvmem, +const struct nvmem_cell_info *info) +{ +return -EOPNOTSUPP ; +}#endif /* CONFIG_NVMEM */ #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */
Signature · 1 line
2.30.2
PATCH v5 11/21 nvmem: core: use nvmem_add_one_cell() in nvmem_add_cells_from_of()
In reply to Michael WalleConvert nvmem_add_cells_from_of() to use the new nvmem_add_one_cell(). This will remove duplicate code and it will make it possible to add a hook to a nvmem layout in between, which can change fields before the cell is finally added.
---
changes since v4:
- drop now unused allocation of nvmem_cell_entrys, thanks Dan
changes since v3:
- none
changes since v2:
- none
changes since v1:
- new patch
drivers/nvmem/core.c | 45 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 31 deletions(-)
drivers/nvmem/core.c +14 -31
@@ -688,15 +688,14 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)static int nvmem_add_cells_from_of (struct nvmem_device *nvmem) { -struct device_node *parent, *child;struct device *dev = &nvmem->dev; -struct nvmem_cell_entry *cell; +struct device_node *child;const __be32 *addr; -int len; +int len, ret; - parent = dev->of_node; +for_each_child_of_node (dev->of_node, child) { +struct nvmem_cell_info info = {0 }; -for_each_child_of_node (parent, child) { addr =of_get_property (child,"reg" , &len);if (!addr)continue ;
@@ -706,40 +705,24 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)return -EINVAL ; } - cell =kzalloc (sizeof (*cell),GFP_KERNEL ); -if (!cell) { -of_node_put (child); -return -ENOMEM ; - } - - cell->nvmem = nvmem; - cell->offset =be32_to_cpup (addr++); - cell->bytes =be32_to_cpup (addr); - cell->name =kasprintf (GFP_KERNEL ,"%pOFn" , child); + info.offset =be32_to_cpup (addr++); + info.bytes =be32_to_cpup (addr); + info.name =kasprintf (GFP_KERNEL ,"%pOFn" , child); addr =of_get_property (child,"bits" , &len);if (addr && len == (2 *sizeof (u32))) { - cell->bit_offset =be32_to_cpup (addr++); - cell->nbits =be32_to_cpup (addr); + info.bit_offset =be32_to_cpup (addr++); + info.nbits =be32_to_cpup (addr); } -if (cell->nbits) - cell->bytes =DIV_ROUND_UP ( - cell->nbits + cell->bit_offset, -BITS_PER_BYTE ); + info.np =of_node_get (child); -if (!IS_ALIGNED (cell->offset, nvmem->stride)) { -dev_err (dev,"cell %s unaligned to nvmem stride %d\n" , - cell->name, nvmem->stride); -/* Cells already added will be freed later. */ -kfree_const (cell->name); -kfree (cell); + ret =nvmem_add_one_cell (nvmem, &info); +kfree (info.name); +if (ret) {of_node_put (child); -return -EINVAL ; +return ret; } - - cell->np =of_node_get (child); -nvmem_cell_entry_add (cell); }return 0 ;
Signature · 1 line
2.30.2
PATCH v5 12/21 nvmem: core: introduce NVMEM layouts
In reply to Michael WalleNVMEM layouts are used to generate NVMEM cells during runtime. Think of an EEPROM with a well-defined conent. For now, the content can be described by a device tree or a board file. But this only works if the offsets and lengths are static and don't change. One could also argue that putting the layout of the EEPROM in the device tree is the wrong place. Instead, the device tree should just have a specific compatible string.
Right now there are two use cases:
(1) The NVMEM cell needs special processing. E.g. if it only specifies a base MAC address offset and you need to add an offset, or it needs to parse a MAC from ASCII format or some proprietary format. (Post processing of cells is added in a later commit).
(2) u-boot environment parsing. The cells don't have a particular offset but it needs parsing the content to determine the offsets and length.
---
changes since v4:
- none
changes since v3:
- check return code of .add_cells()
changes since v2:
- look for "nvmem-layout" node and its compatible
- add of_nvmem_layout_get_container()
- special handling in of_nvmem_cell_get()
changes since v1:
- add documentation in nvmem.rst
- add nvmem_layout_unregister() + necessary module tracking
- make it possible to supply a layout via nvmem_register()
- check add_cells, before calling
Documentation/driver-api/nvmem.rst | 15 ++++ drivers/nvmem/Kconfig | 4 + drivers/nvmem/Makefile | 1 + drivers/nvmem/core.c | 118 +++++++++++++++++++++++++++++ drivers/nvmem/layouts/Kconfig | 5 ++ drivers/nvmem/layouts/Makefile | 4 + include/linux/nvmem-consumer.h | 7 ++ include/linux/nvmem-provider.h | 51 +++++++++++++ 8 files changed, 205 insertions(+) create mode 100644 drivers/nvmem/layouts/Kconfig create mode 100644 drivers/nvmem/layouts/Makefile
Documentation/driver-api/nvmem.rst +15 -0
@@ -185,3 +185,18 @@ ex:: ===================== See Documentation/devicetree/bindings/nvmem/nvmem.txt + +8. NVMEM layouts +================ + +NVMEM layouts are yet another mechanism to create cells. With the device +tree binding it is possible to specify simple cells by using an offset +and a length. Sometimes, the cells doesn't have a static offset, but +the content is still well defined, e.g. tag-length-values. In this case, +the NVMEM device content has to be first parsed and the cells need to +be added accordingly. Layouts let you read the content of the NVMEM device +and let you add cells dynamically. + +Another use case for layouts is the post processing of cells. With layouts, +it is possible to associate a custom post processing hook to a cell. It +even possible to add this hook to cells not created by the layout itself.
drivers/nvmem/Kconfig +4 -0
@@ -21,6 +21,10 @@ config NVMEM_SYSFS This interface is mostly used by userspace applications to read/write directly into nvmem. +# Layouts + +source "drivers/nvmem/layouts/Kconfig" + # Devices config NVMEM_APPLE_EFUSES
drivers/nvmem/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_NVMEM) += nvmem_core.o nvmem_core-y := core.o +obj-y += layouts/ # Devices obj-$(CONFIG_NVMEM_APPLE_EFUSES) += nvmem-apple-efuses.o
drivers/nvmem/core.c +118 -0
166 lines not on this page · raw message
drivers/nvmem/layouts/Kconfig new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +menu "Layout Types" + +endmenu
drivers/nvmem/layouts/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for nvmem layouts. +#
include/linux/nvmem-consumer.h +7 -0
@@ -239,6 +239,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id);struct nvmem_device *of_nvmem_device_get (struct device_node *np,const char *name); +struct device_node *of_nvmem_layout_get_container (struct nvmem_device *nvmem);#else static inline struct nvmem_cell *of_nvmem_cell_get (struct device_node *np,const char *id)
@@ -251,6 +252,12 @@ static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, {return ERR_PTR (-EOPNOTSUPP ); } + +static inline struct device_node * +of_nvmem_layout_get_container (struct nvmem_device *nvmem) +{ +return ERR_PTR (-EOPNOTSUPP ); +}#endif /* CONFIG_NVMEM && CONFIG_OF */ #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */
include/linux/nvmem-provider.h +51 -0
80 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v5 13/21 nvmem: core: add per-cell post processing
In reply to Michael WalleInstead of relying on the name the consumer is using for the cell, like it is done for the nvmem .cell_post_process configuration parameter, provide a per-cell post processing hook. This can then be populated by the NVMEM provider (or the NVMEM layout) when adding the cell.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- none
changes since v1:
- rename hook to read_post_process
drivers/nvmem/core.c | 17 +++++++++++++++++ include/linux/nvmem-provider.h | 3 +++ 2 files changed, 20 insertions(+)
drivers/nvmem/core.c +17 -0
@@ -53,6 +53,7 @@ struct nvmem_cell_entry {int bytes;int bit_offset;int nbits; +nvmem_cell_post_process_t read_post_process;struct device_node *np;struct nvmem_device *nvmem;struct list_head node;
@@ -469,6 +470,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, cell->offset = info->offset; cell->bytes = info->bytes; cell->name = info->name; + cell->read_post_process = info->read_post_process; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits;
@@ -1549,6 +1551,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,if (cell->bit_offset || cell->nbits)nvmem_shift_read_buffer_in_place (cell, buf); +if (cell->read_post_process) { + rc = cell->read_post_process (nvmem->priv, id, index, + cell->offset, buf, cell->bytes); +if (rc) +return rc; + } +if (nvmem->cell_post_process) { rc = nvmem->cell_post_process (nvmem->priv, id, index, cell->offset, buf, cell->bytes);
@@ -1657,6 +1666,14 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si (cell->bit_offset == 0 && len != cell->bytes))return -EINVAL ; +/* +* Any cells which have a read_post_process hook are read-only because +* we cannot reverse the operation and it might affect other cells, +* too. +*/ +if (cell->read_post_process) +return -EINVAL ; +if (cell->bit_offset || cell->nbits) { buf =nvmem_cell_prepare_write_buffer (cell, buf, len);if (IS_ERR (buf))
include/linux/nvmem-provider.h +3 -0
@@ -54,6 +54,8 @@ struct nvmem_keepout {* @bit_offset: Bit offset if cell is smaller than a byte. * @nbits: Number of bits. * @np: Optional device_node pointer. +* @read_post_process: Callback for optional post processing of cell data +* on reads. */ struct nvmem_cell_info {const char *name;
@@ -62,6 +64,7 @@ struct nvmem_cell_info {unsigned int bit_offset;unsigned int nbits;struct device_node *np; +nvmem_cell_post_process_t read_post_process; };/**
Signature · 1 line
2.30.2
PATCH v5 14/21 nvmem: core: allow to modify a cell before adding it
In reply to Michael WalleProvide a way to modify a cell before it will get added. This is useful to attach a custom post processing hook via a layout.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- none
changes since v1:
- new patch
drivers/nvmem/core.c | 4 ++++ include/linux/nvmem-provider.h | 5 +++++ 2 files changed, 9 insertions(+)
drivers/nvmem/core.c +4 -0
@@ -694,6 +694,7 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)static int nvmem_add_cells_from_of (struct nvmem_device *nvmem) { +struct nvmem_layout *layout = nvmem->layout;struct device *dev = &nvmem->dev;struct device_node *child;const __be32 *addr;
@@ -723,6 +724,9 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) info.np =of_node_get (child); +if (layout && layout->fixup_cell_info) + layout->fixup_cell_info (nvmem, layout, &info); + ret =nvmem_add_one_cell (nvmem, &info);kfree (info.name);if (ret) {
include/linux/nvmem-provider.h +5 -0
@@ -157,6 +157,8 @@ struct nvmem_cell_table {* @add_cells: Will be called if a nvmem device is found which * has this layout. The function will add layout * specific cells with nvmem_add_one_cell(). +* @fixup_cell_info: Will be called before a cell is added. Can be +* used to modify the nvmem_cell_info. * @owner: Pointer to struct module. * @node: List node. *
@@ -170,6 +172,9 @@ struct nvmem_layout {const struct of_device_id *of_match_table;int (*add_cells)(struct device *dev,struct nvmem_device *nvmem,struct nvmem_layout *layout); +void (*fixup_cell_info)(struct nvmem_device *nvmem, +struct nvmem_layout *layout, +struct nvmem_cell_info *cell);/* private */ struct module *owner;
Signature · 1 line
2.30.2
PATCH v5 15/21 nvmem: imx-ocotp: replace global post processing with layouts
In reply to Michael WalleIn preparation of retiring the global post processing hook change this driver to use layouts. The layout will be supplied during registration and will be used to add the post processing hook to all added cells.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- none
changes since v1:
- new patch
drivers/nvmem/imx-ocotp.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
drivers/nvmem/imx-ocotp.c +19 -11
@@ -225,18 +225,13 @@ static int imx_ocotp_read(void *context, unsigned int offset,static int imx_ocotp_cell_pp (void *context,const char *id,int index,unsigned int offset,void *data,size_t bytes) { -struct ocotp_priv *priv = context; +u8 *buf = data; +int i;/* Deal with some post processing of nvmem cell data */ -if (id && !strcmp (id,"mac-address" )) { -if (priv->params->reverse_mac_address) { -u8 *buf = data; -int i; - -for (i =0 ; i < bytes/2 ; i++) -swap (buf[i], buf[bytes - i -1 ]); - } - } +if (id && !strcmp (id,"mac-address" )) +for (i =0 ; i < bytes /2 ; i++) +swap (buf[i], buf[bytes - i -1 ]);return 0 ; }
@@ -488,7 +483,6 @@ static struct nvmem_config imx_ocotp_nvmem_config = { .stride = 1, .reg_read = imx_ocotp_read, .reg_write = imx_ocotp_write, - .cell_post_process = imx_ocotp_cell_pp, };static const struct ocotp_params imx6q_params = {
@@ -595,6 +589,17 @@ static const struct of_device_id imx_ocotp_dt_ids[] = { };MODULE_DEVICE_TABLE (of, imx_ocotp_dt_ids); +static void imx_ocotp_fixup_cell_info (struct nvmem_device *nvmem, +struct nvmem_layout *layout, +struct nvmem_cell_info *cell) +{ + cell->read_post_process = imx_ocotp_cell_pp; +} + +struct nvmem_layout imx_ocotp_layout = { + .fixup_cell_info = imx_ocotp_fixup_cell_info, +}; +static int imx_ocotp_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -619,6 +624,9 @@ static int imx_ocotp_probe(struct platform_device *pdev) imx_ocotp_nvmem_config.size =4 * priv->params->nregs; imx_ocotp_nvmem_config.dev = dev; imx_ocotp_nvmem_config.priv = priv; +if (priv->params->reverse_mac_address) + imx_ocotp_nvmem_config.layout = &imx_ocotp_layout; + priv->config = &imx_ocotp_nvmem_config;clk_prepare_enable (priv->clk);
Signature · 1 line
2.30.2
PATCH v5 16/21 nvmem: cell: drop global cell_post_process
In reply to Michael WalleThere are no users anymore for the global cell_post_process callback anymore. New users should use proper nvmem layouts.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- none
changes since v1:
- new patch
drivers/nvmem/core.c | 9 --------- include/linux/nvmem-provider.h | 2 -- 2 files changed, 11 deletions(-)
drivers/nvmem/core.c +0 -9
@@ -38,7 +38,6 @@ struct nvmem_device {unsigned int nkeepout;nvmem_reg_read_t reg_read;nvmem_reg_write_t reg_write; -nvmem_cell_post_process_t cell_post_process;struct gpio_desc *wp_gpio;struct nvmem_layout *layout;void *priv;
@@ -892,7 +891,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->type = config->type; nvmem->reg_read = config->reg_read; nvmem->reg_write = config->reg_write; - nvmem->cell_post_process = config->cell_post_process; nvmem->keepout = config->keepout; nvmem->nkeepout = config->nkeepout;if (config->of_node)
@@ -1562,13 +1560,6 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,return rc; } -if (nvmem->cell_post_process) { - rc = nvmem->cell_post_process (nvmem->priv, id, index, - cell->offset, buf, cell->bytes); -if (rc) -return rc; - } -if (len) *len = cell->bytes;
include/linux/nvmem-provider.h +0 -2
@@ -85,7 +85,6 @@ struct nvmem_cell_info {* @no_of_node: Device should not use the parent's of_node even if it's !NULL. * @reg_read: Callback to read data. * @reg_write: Callback to write data. -* @cell_post_process: Callback for vendor specific post processing of cell data * @size: Device size. * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride.
@@ -120,7 +119,6 @@ struct nvmem_config {bool no_of_node;nvmem_reg_read_t reg_read;nvmem_reg_write_t reg_write; -nvmem_cell_post_process_t cell_post_process;int size;int word_size;int stride;
Signature · 1 line
2.30.2
PATCH v5 17/21 nvmem: core: provide own priv pointer in post process callback
In reply to Michael WalleIt doesn't make any more sense to have a opaque pointer set up by the nvmem device. Usually, the layout isn't associated with a particular nvmem device. Instead, let the caller who set the post process callback provide the priv pointer.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- don't drop the pointer but let the user specify an opaque pointer
changes since v1:
- new patch
drivers/nvmem/core.c | 4 +++- include/linux/nvmem-provider.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/nvmem/core.c +3 -1
@@ -53,6 +53,7 @@ struct nvmem_cell_entry {int bit_offset;int nbits;nvmem_cell_post_process_t read_post_process; +void *priv;struct device_node *np;struct nvmem_device *nvmem;struct list_head node;
@@ -470,6 +471,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, cell->bytes = info->bytes; cell->name = info->name; cell->read_post_process = info->read_post_process; + cell->priv = info->priv; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits;
@@ -1554,7 +1556,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,nvmem_shift_read_buffer_in_place (cell, buf);if (cell->read_post_process) { - rc = cell->read_post_process (nvmem->priv, id, index, + rc = cell->read_post_process (cell->priv, id, index, cell->offset, buf, cell->bytes);if (rc)return rc;
include/linux/nvmem-provider.h +4 -1
@@ -20,7 +20,8 @@ typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, void *val, size_t bytes);/* used for vendor specific post processing of cell data */ typedef int (*nvmem_cell_post_process_t )(void *priv,const char *id,int index, -unsigned int offset,void *buf,size_t bytes); +unsigned int offset,void *buf, +size_t bytes);enum nvmem_type {NVMEM_TYPE_UNKNOWN =0 ,
@@ -56,6 +57,7 @@ struct nvmem_keepout {* @np: Optional device_node pointer. * @read_post_process: Callback for optional post processing of cell data * on reads. +* @priv: Opaque data passed to the read_post_process hook. */ struct nvmem_cell_info {const char *name;
@@ -65,6 +67,7 @@ struct nvmem_cell_info {unsigned int nbits;struct device_node *np;nvmem_cell_post_process_t read_post_process; +void *priv; };/**
Signature · 1 line
2.30.2
PATCH v5 18/21 nvmem: layouts: add sl28vpd layout
In reply to Michael WalleThis layout applies to the VPD of the Kontron sl28 boards. The VPD only contains a base MAC address. Therefore, we have to add an individual offset to it. This is done by taking the second argument of the nvmem phandle into account. Also this let us checking the VPD version and the checksum.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- use of_nvmem_layout_get_container()
changes since v1:
- none
drivers/nvmem/layouts/Kconfig | 9 ++ drivers/nvmem/layouts/Makefile | 2 + drivers/nvmem/layouts/sl28vpd.c | 153 ++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 drivers/nvmem/layouts/sl28vpd.c
drivers/nvmem/layouts/Kconfig +9 -0
@@ -2,4 +2,13 @@ menu "Layout Types" +config NVMEM_LAYOUT_SL28_VPD + bool "Kontron sl28 VPD layout support" + select CRC8 + help + Say Y here if you want to support the VPD layout of the Kontron + SMARC-sAL28 boards. + + If unsure, say N. + endmenu
drivers/nvmem/layouts/Makefile +2 -0
@@ -2,3 +2,5 @@ # # Makefile for nvmem layouts. # + +obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o
drivers/nvmem/layouts/sl28vpd.c new file +153 -0
153 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v5 19/21 MAINTAINERS: add myself as sl28vpd nvmem layout driver
In reply to Michael WalleAdd myself as a maintainer for the new sl28vpd nvmem layout driver.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- new patch
MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -19134,6 +19134,12 @@ F: drivers/irqchip/irq-sl28cpld.c F: drivers/pwm/pwm-sl28cpld.c F: drivers/watchdog/sl28cpld_wdt.c +SL28 VPD NVMEM LAYOUT DRIVER +M: Michael Walle <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml +F: drivers/nvmem/layouts/sl28vpd.c + SLAB ALLOCATOR M: Christoph Lameter <[email protected]> M: Pekka Enberg <[email protected]>
Signature · 1 line
2.30.2
PATCH v5 20/21 nvmem: layouts: Add ONIE tlv layout driver
In reply to Michael WalleFrom: Miquel Raynal <[email protected]>
This layout applies on top of any non volatile storage device containing an ONIE table factory flashed. This table follows the tlv (type-length-value) organization described in the link below. We cannot afford using regular parsers because the content of these tables is manufacturer specific and must be dynamically discovered.
---
changes since v4:
- none
changes since v3:
- don't use kfree()
- fix typo, s/no/on/
changes since v2:
- new patch
drivers/nvmem/layouts/Kconfig | 9 ++ drivers/nvmem/layouts/Makefile | 1 + drivers/nvmem/layouts/onie-tlv.c | 244 +++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 drivers/nvmem/layouts/onie-tlv.c
drivers/nvmem/layouts/Kconfig +9 -0
@@ -11,4 +11,13 @@ config NVMEM_LAYOUT_SL28_VPD If unsure, say N. +config NVMEM_LAYOUT_ONIE_TLV + bool "ONIE tlv support" + select CRC32 + help + Say Y here if you want to support the Open Compute Project ONIE + Type-Length-Value standard table. + + If unsure, say N. + endmenu
drivers/nvmem/layouts/Makefile +1 -0
@@ -4,3 +4,4 @@ # obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o +obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o
drivers/nvmem/layouts/onie-tlv.c new file +244 -0
244 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v5 21/21 MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer
In reply to Michael WalleFrom: Miquel Raynal <[email protected]>
Following the introduction of the bindings for this NVMEM parser and the layout driver, add myself as maintainer.
---
changes since v4:
- none
changes since v3:
- none
changes since v2:
- new patch
MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -15529,6 +15529,12 @@ L: [email protected] S: Maintained F: drivers/hwmon/oxp-sensors.c +ONIE TLV NVMEM LAYOUT DRIVER +M: Miquel Raynal <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml +F: drivers/nvmem/layouts/onie-tlv.c + ONION OMEGA2+ BOARD M: Harvey Hunt <[email protected]> L: [email protected]
Signature · 1 line
2.30.2
Miquel Raynal
maintainerHi Srinivas,
[email protected] wrote on Tue, 6 Dec 2022 21:07:19 +0100:
Quoted 23 lines
This is now the third attempt to fetch the MAC addresses from the VPD for the Kontron sl28 boards. Previous discussions can be found here:
https://lore.kernel.org/lkml/[email protected]/NVMEM cells are typically added by board code or by the devicetree. But as the cells get more complex, there is (valid) push back from the devicetree maintainers to not put that handling in the devicetree.
Therefore, introduce NVMEM layouts. They operate on the NVMEM device and can add cells during runtime. That way it is possible to add more complex cells than it is possible right now with the offset/length/bits description in the device tree. For example, you can have post processing for individual cells (think of endian swapping, or ethernet offset handling).
The imx-ocotp driver is the only user of the global post processing hook, convert it to nvmem layouts and drop the global post pocessing hook.
For now, the layouts are selected by the device tree. But the idea is that also board files or other drivers could set a layout. Although no code for that exists yet.
Quoted 8 lines
Thanks to Miquel, the device tree bindings are already approved and merged.
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM core can't be compiled as a module. The layouts needs to be available at probe time. (That is also the reason why they get registered withsubsys_initcall().) So if the NVMEM core would be a module, the layouts could be modules, too.
I believe this series still applies even though -rc1 (and -rc2) are out now, may we know if you consider merging it anytime soon or if there are still discrepancies in the implementation you would like to discuss? Otherwise I would really like to see this laying in -next a few weeks before being sent out to Linus, just in case.
Thanks,
Miquèl
Hi Miquel,
Quoted 36 lines · Miquel Raynal
Hi Srinivas,
[email protected] wrote on Tue, 6 Dec 2022 21:07:19 +0100:
Quoted 23 lines
This is now the third attempt to fetch the MAC addresses from the VPD for the Kontron sl28 boards. Previous discussions can be found here:
https://lore.kernel.org/lkml/[email protected]/NVMEM cells are typically added by board code or by the devicetree. But as the cells get more complex, there is (valid) push back from the devicetree maintainers to not put that handling in the devicetree.
Therefore, introduce NVMEM layouts. They operate on the NVMEM device and can add cells during runtime. That way it is possible to add more complex cells than it is possible right now with the offset/length/bits description in the device tree. For example, you can have post processing for individual cells (think of endian swapping, or ethernet offset handling).
The imx-ocotp driver is the only user of the global post processing hook, convert it to nvmem layouts and drop the global post pocessing hook.
For now, the layouts are selected by the device tree. But the idea is that also board files or other drivers could set a layout. Although no code for that exists yet.
Quoted 8 lines
Thanks to Miquel, the device tree bindings are already approved and merged.
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM core can't be compiled as a module. The layouts needs to be available at probe time. (That is also the reason why they get registered withsubsys_initcall().) So if the NVMEM core would be a module, the layouts could be modules, too.
Quoted 5 lines
I believe this series still applies even though -rc1 (and -rc2) are out now, may we know if you consider merging it anytime soon or if there are still discrepancies in the implementation you would like to discuss? Otherwise I would really like to see this laying in -next a few weeks before being sent out to Linus, just in case.
Thanks for the work!
Lets get some testing in -next.
Applied now,
--srini
Quoted 3 lines
Thanks,
Miquèl
Miquel Raynal
maintainerHi Srinivas,
[email protected] wrote on Tue, 3 Jan 2023 15:51:31 +0000:
Quoted 45 lines
Hi Miquel,
Quoted 36 lines · Miquel Raynal
Hi Srinivas,
[email protected] wrote on Tue, 6 Dec 2022 21:07:19 +0100:
Quoted 23 lines
This is now the third attempt to fetch the MAC addresses from the VPD for the Kontron sl28 boards. Previous discussions can be found here:
https://lore.kernel.org/lkml/[email protected]/NVMEM cells are typically added by board code or by the devicetree. But as the cells get more complex, there is (valid) push back from the devicetree maintainers to not put that handling in the devicetree.
Therefore, introduce NVMEM layouts. They operate on the NVMEM device and can add cells during runtime. That way it is possible to add more complex cells than it is possible right now with the offset/length/bits description in the device tree. For example, you can have post processing for individual cells (think of endian swapping, or ethernet offset handling).
The imx-ocotp driver is the only user of the global post processing hook, convert it to nvmem layouts and drop the global post pocessing hook.
For now, the layouts are selected by the device tree. But the idea is that also board files or other drivers could set a layout. Although no code for that exists yet.
Quoted 8 lines
Thanks to Miquel, the device tree bindings are already approved and merged.
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM core can't be compiled as a module. The layouts needs to be available at probe time. (That is also the reason why they get registered withsubsys_initcall().) So if the NVMEM core would be a module, the layouts could be modules, too.Quoted 5 lines
I believe this series still applies even though -rc1 (and -rc2) are out now, may we know if you consider merging it anytime soon or if there are still discrepancies in the implementation you would like to discuss? Otherwise I would really like to see this laying in -next a few weeks before being sent out to Linus, just in case.
Quoted 6 lines
Thanks for the work!
Lets get some testing in -next.
Applied now,
Excellent! Thanks a lot for the quick answer and thanks for applying, let's see how it behaves.
Thanks,
Miquèl
Am Dienstag, 3. Januar 2023, 16:51:31 CET schrieb Srinivas Kandagatla:
Quoted 45 lines
Hi Miquel,
Quoted 36 lines · Miquel Raynal
Hi Srinivas,
[email protected] wrote on Tue, 6 Dec 2022 21:07:19 +0100:
Quoted 26 lines
This is now the third attempt to fetch the MAC addresses from the VPD for the Kontron sl28 boards. Previous discussions can be found here:
https://lore.kernel.org/lkml/[email protected]/NVMEM cells are typically added by board code or by the devicetree. But as the cells get more complex, there is (valid) push back from the devicetree maintainers to not put that handling in the devicetree.
Therefore, introduce NVMEM layouts. They operate on the NVMEM device and can add cells during runtime. That way it is possible to add more complex cells than it is possible right now with the offset/length/bits description in the device tree. For example, you can have post processing for individual cells (think of endian swapping, or ethernet offset handling).
The imx-ocotp driver is the only user of the global post processing hook, convert it to nvmem layouts and drop the global post pocessing hook.
For now, the layouts are selected by the device tree. But the idea is that also board files or other drivers could set a layout. Although no code for that exists yet.
Thanks to Miquel, the device tree bindings are already approved and merged.
Quoted 6 lines
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM core can't be compiled as a module. The layouts needs to be available at probe time. (That is also the reason why they get registered withsubsys_initcall().) So if the NVMEM core would be a module, the layouts could be modules, too.Quoted 5 lines
I believe this series still applies even though -rc1 (and -rc2) are out now, may we know if you consider merging it anytime soon or if there are still discrepancies in the implementation you would like to discuss? Otherwise I would really like to see this laying in -next a few weeks before being sent out to Linus, just in case.
Quoted 3 lines
Thanks for the work!
Lets get some testing in -next.
This causes the following errors on existing boards (imx8mq-tqma8mq- mba8mx.dtb):
root@tqma8-common:~# uname -r 6.2.0-rc2-next-20230105
Quoted 1 line
OF: /soc@0: could not get #nvmem-cell-cells for /soc@0/bus@30000000/
efuse@30350000/soc-uid@4
Quoted 1 line
OF: /soc@0/bus@30800000/ethernet@30be0000: could not get #nvmem-cell-cells
for /soc@0/bus@30000000/efuse@30350000/mac-address@90
These are caused because '#nvmem-cell-cells = <0>;' is not explicitly set in DT.
Quoted 1 line
TI DP83867 30be0000.ethernet-1:0e: error
-EINVAL: failed to get nvmem cell
io_impedance_ctrl
Quoted 1 line
TI DP83867: probe of 30be0000.ethernet-1:0e failed with error -22
These are caused because of_nvmem_cell_get() now returns -EINVAL instead of - ENODEV if the requested nvmem cell is not available.
Best regards,
Alexander
Miquel Raynal
maintainerHello,
[email protected] wrote on Thu, 05 Jan 2023 12:04:52 +0100:
Quoted 63 lines
Am Dienstag, 3. Januar 2023, 16:51:31 CET schrieb Srinivas Kandagatla:
Quoted 45 lines
Hi Miquel,
Quoted 36 lines · Miquel Raynal
Hi Srinivas,
[email protected] wrote on Tue, 6 Dec 2022 21:07:19 +0100:
Quoted 26 lines
This is now the third attempt to fetch the MAC addresses from the VPD for the Kontron sl28 boards. Previous discussions can be found here:
https://lore.kernel.org/lkml/[email protected]/NVMEM cells are typically added by board code or by the devicetree. But as the cells get more complex, there is (valid) push back from the devicetree maintainers to not put that handling in the devicetree.
Therefore, introduce NVMEM layouts. They operate on the NVMEM device and can add cells during runtime. That way it is possible to add more complex cells than it is possible right now with the offset/length/bits description in the device tree. For example, you can have post processing for individual cells (think of endian swapping, or ethernet offset handling).
The imx-ocotp driver is the only user of the global post processing hook, convert it to nvmem layouts and drop the global post pocessing hook.
For now, the layouts are selected by the device tree. But the idea is that also board files or other drivers could set a layout. Although no code for that exists yet.
Thanks to Miquel, the device tree bindings are already approved and merged.
Quoted 6 lines
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM core can't be compiled as a module. The layouts needs to be available at probe time. (That is also the reason why they get registered withsubsys_initcall().) So if the NVMEM core would be a module, the layouts could be modules, too.Quoted 5 lines
I believe this series still applies even though -rc1 (and -rc2) are out now, may we know if you consider merging it anytime soon or if there are still discrepancies in the implementation you would like to discuss? Otherwise I would really like to see this laying in -next a few weeks before being sent out to Linus, just in case.
Quoted 3 lines
Thanks for the work!
Lets get some testing in -next.
This causes the following errors on existing boards (imx8mq-tqma8mq- mba8mx.dtb):
root@tqma8-common:~# uname -r 6.2.0-rc2-next-20230105Quoted 1 line
OF: /soc@0: could not get #nvmem-cell-cells for /soc@0/bus@30000000/
efuse@30350000/soc-uid@4
Quoted 1 line
OF: /soc@0/bus@30800000/ethernet@30be0000: could not get #nvmem-cell-cells
for /soc@0/bus@30000000/efuse@30350000/mac-address@90
These are caused because '#nvmem-cell-cells = <0>;' is not explicitly set in DT.
Quoted 6 lines
Quoted 1 line
TI DP83867 30be0000.ethernet-1:0e: error
-EINVAL: failed to get nvmem cell
io_impedance_ctrlQuoted 1 line
TI DP83867: probe of 30be0000.ethernet-1:0e failed with error -22
These are caused because
of_nvmem_cell_get()now returns-EINVALinstead of - ENODEV if the requested nvmem cell is not available.
Should we just assume #nvmem-cell-cells = <0> by default? I guess it's a safe assumption.
Thanks,
Miquèl
Hi Alexander,
thanks for debugging. I'm not yet sure what is going wrong, so I have some more questions below.
Quoted 13 lines
Quoted 13 lines
This causes the following errors on existing boards (imx8mq-tqma8mq- mba8mx.dtb):
root@tqma8-common:~# uname -r 6.2.0-rc2-next-20230105Quoted 1 line
OF: /soc@0: could not get #nvmem-cell-cells for /soc@0/bus@30000000/
efuse@30350000/soc-uid@4
Quoted 1 line
OF: /soc@0/bus@30800000/ethernet@30be0000: could not get #nvmem-cell-cells
for /soc@0/bus@30000000/efuse@30350000/mac-address@90
These are caused because '#nvmem-cell-cells = <0>;' is not explicitly set in DT.
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
TI DP83867 30be0000.ethernet-1:0e: error
-EINVAL: failed to get nvmem cell
io_impedance_ctrlQuoted 1 line
TI DP83867: probe of 30be0000.ethernet-1:0e failed with error -22
These are caused because
of_nvmem_cell_get()now returns-EINVALinstead of - ENODEV if the requested nvmem cell is not available.
What do you mean with not available? Not yet available because of probe order?
Quoted 2 lines
Should we just assume #nvmem-cell-cells = <0> by default? I guess it's a safe assumption.
Actually, that's what patch 2/21 is for.
Alexander, did you verify that the EINVAL is returned by of_parse_phandle_with_optional_args()?
-michael
Hi Michael,
Am Donnerstag, 5. Januar 2023, 13:11:37 CET schrieb Michael Walle:
Quoted 28 lines
Hi Alexander,
thanks for debugging. I'm not yet sure what is going wrong, so I have some more questions below.
Quoted 23 lines
Quoted 23 lines
This causes the following errors on existing boards (imx8mq-tqma8mq- mba8mx.dtb):
root@tqma8-common:~# uname -r 6.2.0-rc2-next-20230105Quoted 1 line
OF: /soc@0: could not get #nvmem-cell-cells for /soc@0/bus@30000000/
efuse@30350000/soc-uid@4
Quoted 2 lines
OF: /soc@0/bus@30800000/ethernet@30be0000: could not get #nvmem-cell-cells
for /soc@0/bus@30000000/efuse@30350000/mac-address@90
These are caused because '#nvmem-cell-cells = <0>;' is not explicitly set in
DT.Quoted 2 lines
TI DP83867 30be0000.ethernet-1:0e: error
-EINVAL: failed to get nvmem cell
io_impedance_ctrl
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
TI DP83867: probe of 30be0000.ethernet-1:0e failed with error -22
These are caused because
of_nvmem_cell_get()now returns-EINVALinstead of -
ENODEV if the requested nvmem cell is not available.What do you mean with not available? Not yet available because of probe order?
Ah, I was talking about there is no nvmem cell being used in my PHY node, e.g. no 'nvmem-cells' nor 'nvmem-cell-names' (set to 'io_impedance_ctrl'). That's why of_property_match_string returns -EINVAL.
Quoted 7 lines
Quoted 2 lines
Should we just assume #nvmem-cell-cells = <0> by default? I guess it's a safe assumption.
Actually, that's what patch 2/21 is for.
Alexander, did you verify that the EINVAL is returned by
of_parse_phandle_with_optional_args()?
Yep.
--8<--
drivers/nvmem/core.c +0 -0
@@ -1339,9 +1339,11 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node
*np, const char *id)
if (id)
index = of_property_match_string(np, "nvmem-cell-names", id);+ pr_info("%s: index: %d\n", __func__, index);
ret = of_parse_phandle_with_optional_args(np, "nvmem-cells",
"#nvmem-cell-cells",
index, &cell_spec);
+ pr_info("%s: of_parse_phandle_with_optional_args: %d\n", __func__,
ret);
if (ret)
return ERR_PTR(ret);--8<--
Results in:
Quoted 3 lines
[ 1.861896] of_nvmem_cell_get: index: -22 [ 1.865934] of_nvmem_cell_get: of_parse_phandle_with_optional_args: -22 [ 1.872595] TI DP83867 30be0000.ethernet-1:0e: error -EINVAL: failed to
get nvmem cell io_impedance_ctrl
Quoted 1 line
[ 2.402575] TI DP83867: probe of 30be0000.ethernet-1:0e failed with error
-22
So, the index is wrong in the first place, but this was no problem until now.
Best regards,
Alexander
Hi,
Am 2023-01-05 13:21, schrieb Alexander Stein:
Quoted 33 lines
Am Donnerstag, 5. Januar 2023, 13:11:37 CET schrieb Michael Walle:
Quoted 32 lines
thanks for debugging. I'm not yet sure what is going wrong, so I have some more questions below.
Quoted 28 lines
Quoted 28 lines
This causes the following errors on existing boards (imx8mq-tqma8mq- mba8mx.dtb):
root@tqma8-common:~# uname -r 6.2.0-rc2-next-20230105Quoted 1 line
OF: /soc@0: could not get #nvmem-cell-cells for /soc@0/bus@30000000/
efuse@30350000/soc-uid@4
Quoted 2 lines
OF: /soc@0/bus@30800000/ethernet@30be0000: could not get #nvmem-cell-cells
for /soc@0/bus@30000000/efuse@30350000/mac-address@90
These are caused because '#nvmem-cell-cells = <0>;' is not explicitly set in
DT.Quoted 2 lines
TI DP83867 30be0000.ethernet-1:0e: error
-EINVAL: failed to get nvmem cell
io_impedance_ctrlQuoted 1 line
TI DP83867: probe of 30be0000.ethernet-1:0e failed with error -22
These are caused because
of_nvmem_cell_get()now returns-EINVALinstead of -
ENODEV if the requested nvmem cell is not available.
Quoted 6 lines
Quoted 2 lines
What do you mean with not available? Not yet available because of probe order?
Ah, I was talking about there is no nvmem cell being used in my PHY node, e.g. no 'nvmem-cells' nor 'nvmem-cell-names' (set to '
io_impedance_ctrl'). That's whyof_property_match_stringreturns-EINVAL.
Ahh I see. You mean ENOENT instead of ENODEV, right?
Quoted 38 lines
Quoted 7 lines
Quoted 2 lines
Should we just assume #nvmem-cell-cells = <0> by default? I guess it's a safe assumption.
Actually, that's what patch 2/21 is for.
Alexander, did you verify that the EINVAL is returned by
of_parse_phandle_with_optional_args()?Yep.
--8<--
drivers/nvmem/core.c +0
-0@@ -1339,9 +1339,11 @@ struct nvmem_cell *of_nvmem_cell_get(struct
device_node
*np, const char *id)
if (id)
index = of_property_match_string(np,
"nvmem-cell-names", id);drivers/nvmem/core.c +2
-0+pr_info ("%s: index: %d\n" , __func__, index); ret =of_parse_phandle_with_optional_args (np,"nvmem-cells" ,"#nvmem-cell-cells" , index, &cell_spec); + pr_info("%s: of_parse_phandle_with_optional_args: %d\n",
__func__,ret); if (ret) return ERR_PTR(ret);--8<--
Results in:
Quoted 4 lines
[ 1.861896] of_nvmem_cell_get: index: -22 [ 1.865934] of_nvmem_cell_get: of_parse_phandle_with_optional_args: -22 [ 1.872595] TI DP83867 30be0000.ethernet-1:0e: error -EINVAL: failed to
Quoted 5 lines
get nvmem cell
io_impedance_ctrlQuoted 1 line
[ 2.402575] TI DP83867: probe of 30be0000.ethernet-1:0e failed with error-22
So, the index is wrong in the first place, but this was no problem until now.
Thanks, could you try the following patch:
drivers/nvmem/core.c +1 -1
@@ -1336,8 +1336,11 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)int ret;/* if cell name exists, find index to the name */ -if (id) +if (id) { index = of_property_match_string(np, "nvmem-cell-names",
id);
+ if (index < 0)
+ return ERR_PTR(-ENOENT);
+ }
ret = of_parse_phandle_with_optional_args(np, "nvmem-cells",
"#nvmem-cell-cells",
Before patch 6/21, the -EINVAL was passed as index to of_parse_phandle() which then returned NULL, which caused the nvmem core to return ENOENT. I have a vague memory, that I made sure, that of_parse_phandle_with_optional_args() will also propagate the wrong index to its return code. But now, it won't be converted to ENOENT.
-michael
Hi Michael,
Am Donnerstag, 5. Januar 2023, 13:51:53 CET schrieb Michael Walle:
Quoted 41 lines
Hi,
Am 2023-01-05 13:21, schrieb Alexander Stein:
Quoted 38 lines
Am Donnerstag, 5. Januar 2023, 13:11:37 CET schrieb Michael Walle:
Quoted 36 lines
thanks for debugging. I'm not yet sure what is going wrong, so I have some more questions below.
Quoted 22 lines
Quoted 22 lines
This causes the following errors on existing boards (imx8mq-tqma8mq- mba8mx.dtb):
root@tqma8-common:~# uname -r 6.2.0-rc2-next-20230105Quoted 1 line
OF: /soc@0: could not get #nvmem-cell-cells for /soc@0/bus@30000000/
efuse@30350000/soc-uid@4
Quoted 2 lines
OF: /soc@0/bus@30800000/ethernet@30be0000: could not get #nvmem-cell-cells
for /soc@0/bus@30000000/efuse@30350000/mac-address@90
These are caused because '#nvmem-cell-cells = <0>;' is not explicitly set in
DT.Quoted 3 lines
TI DP83867 30be0000.ethernet-1:0e: error
-EINVAL: failed to get nvmem
cellQuoted 7 lines
Quoted 7 lines
io_impedance_ctrlQuoted 1 line
TI DP83867: probe of 30be0000.ethernet-1:0e failed with error -22
These are caused because
of_nvmem_cell_get()now returns-EINVALinstead of -
ENODEV if the requested nvmem cell is not available.What do you mean with not available? Not yet available because of probe
order?
Quoted 7 lines
Quoted 5 lines
Ah, I was talking about there is no nvmem cell being used in my PHY node, e.g.
no 'nvmem-cells' nor 'nvmem-cell-names' (set to 'io_impedance_ctrl'). That's
whyof_property_match_stringreturns-EINVAL.Ahh I see. You mean ENOENT instead of ENODEV, right?
Yeah you are right here, ENOENT is the one missing.
Quoted 81 lines
Quoted 51 lines
Quoted 7 lines
Quoted 2 lines
Should we just assume #nvmem-cell-cells = <0> by default? I guess it's a safe assumption.
Actually, that's what patch 2/21 is for.
Alexander, did you verify that the EINVAL is returned by
of_parse_phandle_with_optional_args()?Yep.
--8<--
drivers/nvmem/core.c +0
-0@@ -1339,9 +1339,11 @@ struct nvmem_cell *of_nvmem_cell_get(struct
device_node
*np, const char *id)if (id)
index = of_property_match_string(np,
"nvmem-cell-names", id);
drivers/nvmem/core.c +2
-0+pr_info ("%s: index: %d\n" , __func__, index); ret =of_parse_phandle_with_optional_args (np,"nvmem-cells" ,"#nvmem-cell-cells" , index, &cell_spec); + pr_info("%s: of_parse_phandle_with_optional_args: %d\n",
__func__,
ret);if (ret) return ERR_PTR(ret);--8<--
Results in:
Quoted 5 lines
[ 1.861896] of_nvmem_cell_get: index: -22 [ 1.865934] of_nvmem_cell_get: of_parse_phandle_with_optional_args: -22 [ 1.872595] TI DP83867 30be0000.ethernet-1:0e: error -EINVAL:failed to
get nvmem cell
io_impedance_ctrlQuoted 7 lines
Quoted 2 lines
[ 2.402575] TI DP83867: probe of 30be0000.ethernet-1:0e failed witherror
-22
So, the index is wrong in the first place, but this was no problem until now.
Thanks, could you try the following patch:
drivers/nvmem/core.c +4
-1@@ -1336,8 +1336,11 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) int ret;/* if cell name exists, find index to the name */ -if (id) +if (id) { index =of_property_match_string (np,"nvmem-cell-names" , id); +if (index <0 ) +return ERR_PTR (-ENOENT ); + }ret = of_parse_phandle_with_optional_args(np, "nvmem-cells",
"#nvmem-cell-cells",
Quoted 6 lines
Before patch 6/21, the
-EINVALwas passed as index toof_parse_phandle()which then returned NULL, which caused the nvmem core to return ENOENT. I have a vague memory, that I made sure, thatof_parse_phandle_with_optional_args()will also propagate the wrong index to its return code. But now, it won't be converted to ENOENT.
Yes, this does the trick. Thanks
Best regards,
Alexander
Hi Michael/Miquel,
I had to revert Layout patches due to comments from Greg about Making the layouts as built-in rather than modules, he is not ready to merge them as it is.
His original comment,
"Why are we going back to "custom-built" kernel configurations? Why can this not be a loadable module? Distros are now forced to enable these layout and all kernels will have this dead code in the tree without any choice in the matter?
That's not ok, these need to be auto-loaded based on the hardware representation like any other kernel module. You can't force them to be always present, sorry.
"
I have applied most of the patches except
nvmem: core: introduce NVMEM layouts
nvmem: core: add per-cell post processing
nvmem: core: allow to modify a cell before adding it
nvmem: imx-ocotp: replace global post processing with layouts
nvmem: cell: drop global cell_post_process
nvmem: core: provide own priv pointer in post process callback
nvmem: layouts: add sl28vpd layoutMAINTAINERS: add myself as sl28vpd nvmem layout driver
nvmem: layouts: Add ONIE tlv layout driverMAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer
nvmem: core: return -ENOENT if nvmem cell is not found
nvmem: layouts: Fix spelling mistake "platforn" -> "platform"
dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform"
nvmem: core: fix nvmem_layout_get_match_data()
Please rebase your patches on top of nvmem-next once layouts are converted to loadable modules.
thanks,
srini
Quoted 44 lines · Miquel Raynal
Hi Srinivas,
[email protected] wrote on Tue, 6 Dec 2022 21:07:19 +0100:
Quoted 23 lines
This is now the third attempt to fetch the MAC addresses from the VPD for the Kontron sl28 boards. Previous discussions can be found here:
https://lore.kernel.org/lkml/[email protected]/NVMEM cells are typically added by board code or by the devicetree. But as the cells get more complex, there is (valid) push back from the devicetree maintainers to not put that handling in the devicetree.
Therefore, introduce NVMEM layouts. They operate on the NVMEM device and can add cells during runtime. That way it is possible to add more complex cells than it is possible right now with the offset/length/bits description in the device tree. For example, you can have post processing for individual cells (think of endian swapping, or ethernet offset handling).
The imx-ocotp driver is the only user of the global post processing hook, convert it to nvmem layouts and drop the global post pocessing hook.
For now, the layouts are selected by the device tree. But the idea is that also board files or other drivers could set a layout. Although no code for that exists yet.
Quoted 8 lines
Thanks to Miquel, the device tree bindings are already approved and merged.
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM core can't be compiled as a module. The layouts needs to be available at probe time. (That is also the reason why they get registered withsubsys_initcall().) So if the NVMEM core would be a module, the layouts could be modules, too.I believe this series still applies even though -rc1 (and -rc2) are out now, may we know if you consider merging it anytime soon or if there are still discrepancies in the implementation you would like to discuss? Otherwise I would really like to see this laying in -next a few weeks before being sent out to Linus, just in case.
Thanks,
Miquèl
Miquel Raynal
maintainerHi Srinivas,
+ Greg
[email protected] wrote on Mon, 6 Feb 2023 20:31:46 +0000:
Quoted 3 lines
Hi Michael/Miquel,
I had to revert Layout patches due to comments from Greg about Making the layouts as built-in rather than modules, he is not ready to merge them as it is.
Ok this is the second time I see something similar happening:
- maintainer or maintainers group doing the review/apply job and sending to "upper" maintainer
- upper maintainer refusing for a "questionable" reason at this stage.
I am not saying the review is incorrect or anything. I'm just wondering whether, for the second time, I am facing a fair situation, either myself as a contributor or the intermediate maintainer who's being kind of bypassed.
What I mean is: the review process has happened. Nothing was hidden, this series has started leaving on the mailing lists more than two years ago. The contribution process which has been in place for many years asks the contributors to send new versions when the review process leads to comments, which we did. Once the series has been "accepted" it is expected that this series will be pulled during the next merge window. If there is something else to fix, there are 6 to 8 long weeks where contributors' fixes are welcome. Why not letting us the opportunity to use them? Why, for the second time, I am facing an extremely urgent situation where I have to cancel all my commitments just because a random comment has been made on a series which has been standing still for months?
What I would expect instead, is a discussion on the cover letter of the series where Michael explained why he did no choose to use modules in the first place. If it appears that for some reason it is best to enable NVMEM layouts as modules, we will send a timely series on top of the current one to enable that particular case.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM core can't be compiled as a module. The layouts needs to be available at probe time. (That is also the reason why they get registered withsubsys_initcall().) So if the NVMEM core would be a module, the layouts could be modules, too.
I know Michael is busy after the FOSDEM and so am I, so, Greg, would you accept to take the PR as it is, participate to the discussion and wait for an update?
Thanks,
Miquèl
Quoted 81 lines
His original comment,
"Why are we going back to "custom-built" kernel configurations? Why can this not be a loadable module? Distros are now forced to enable these layout and all kernels will have this dead code in the tree without any choice in the matter?
That's not ok, these need to be auto-loaded based on the hardware representation like any other kernel module. You can't force them to be always present, sorry.
"I have applied most of the patches except
nvmem: core: introduce NVMEM layouts
nvmem: core: add per-cell post processing
nvmem: core: allow to modify a cell before adding it
nvmem: imx-ocotp: replace global post processing with layouts
nvmem: cell: drop globalcell_post_process
nvmem: core: provide own priv pointer in post process callback
nvmem: layouts: add sl28vpd layoutMAINTAINERS: add myself as sl28vpd nvmem layout driver
nvmem: layouts: Add ONIE tlv layout driverMAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer
nvmem: core: return-ENOENTif nvmem cell is not found
nvmem: layouts: Fix spelling mistake "platforn" -> "platform"
dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform"
nvmem: core: fixnvmem_layout_get_match_data()Please rebase your patches on top of nvmem-next once layouts are converted to loadable modules.
thanks,
sriniQuoted 44 lines · Miquel Raynal
Hi Srinivas,
[email protected] wrote on Tue, 6 Dec 2022 21:07:19 +0100:
Quoted 23 lines
This is now the third attempt to fetch the MAC addresses from the VPD for the Kontron sl28 boards. Previous discussions can be found here:
https://lore.kernel.org/lkml/[email protected]/NVMEM cells are typically added by board code or by the devicetree. But as the cells get more complex, there is (valid) push back from the devicetree maintainers to not put that handling in the devicetree.
Therefore, introduce NVMEM layouts. They operate on the NVMEM device and can add cells during runtime. That way it is possible to add more complex cells than it is possible right now with the offset/length/bits description in the device tree. For example, you can have post processing for individual cells (think of endian swapping, or ethernet offset handling).
The imx-ocotp driver is the only user of the global post processing hook, convert it to nvmem layouts and drop the global post pocessing hook.
For now, the layouts are selected by the device tree. But the idea is that also board files or other drivers could set a layout. Although no code for that exists yet.
Quoted 8 lines
Thanks to Miquel, the device tree bindings are already approved and merged.
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM core can't be compiled as a module. The layouts needs to be available at probe time. (That is also the reason why they get registered withsubsys_initcall().) So if the NVMEM core would be a module, the layouts could be modules, too.I believe this series still applies even though -rc1 (and -rc2) are out now, may we know if you consider merging it anytime soon or if there are still discrepancies in the implementation you would like to discuss? Otherwise I would really like to see this laying in -next a few weeks before being sent out to Linus, just in case.
Thanks,
Miquèl
Quoted 6 lines · Miquel Raynal
Hi Srinivas,
+ Greg
[email protected] wrote on Mon, 6 Feb 2023 20:31:46 +0000:
Quoted 8 lines
Quoted 3 lines
Hi Michael/Miquel,
I had to revert Layout patches due to comments from Greg about Making the layouts as built-in rather than modules, he is not ready to merge them as it is.
Ok this is the second time I see something similar happening:
- maintainer or maintainers group doing the review/apply job and sending to "upper" maintainer
- upper maintainer refusing for a "questionable" reason at this stage.
Only the second time? You've gotten lucky then :)
This happens all the time based on experience levels of reviewers and just the very nature of how this whole process works. It's nothing unusual and is good overall for the health of the project. In other words, this is a a feature, not a bug.
Quoted 5 lines
I am not saying the review is incorrect or anything. I'm just wondering whether, for the second time, I am facing a fair situation, either myself as a contributor or the intermediate maintainer who's being kind of bypassed.
Quoted 12 lines
What I mean is: the review process has happened. Nothing was hidden, this series has started leaving on the mailing lists more than two years ago. The contribution process which has been in place for many years asks the contributors to send new versions when the review process leads to comments, which we did. Once the series has been "accepted" it is expected that this series will be pulled during the next merge window. If there is something else to fix, there are 6 to 8 long weeks where contributors' fixes are welcome. Why not letting us the opportunity to use them? Why, for the second time, I am facing an extremely urgent situation where I have to cancel all my commitments just because a random comment has been made on a series which has been standing still for months?
There's no need to cancel anything, there are no deadlines in kernel development and I am not asking for any sort of rush whatsoever.
So relax, take a week or two off (or month), and come back with an updated patch series when you are ready. And feel free to cc: me on it if you want my reviews (as I objected to these patches as-is) so that we don't end up in the same situation (where one maintainer accepted something, but the maintainer they sent it to rejected it.)
Again, there's no rush, and this is totally normal.
Quoted 5 lines
What I would expect instead, is a discussion on the cover letter of the series where Michael explained why he did no choose to use modules in the first place. If it appears that for some reason it is best to enable NVMEM layouts as modules, we will send a timely series on top of the current one to enable that particular case.
Why not rework the existing series to handle this and not require "fixups" at the end of the series? We don't normally create bugs and then fix them up in the same patch set, as you know, so this shouldn't be treated any differently.
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
NVMEM layouts as modules?
While possible in principle, it doesn't make any sense because the NVMEM core can't be compiled as a module. The layouts needs to be available at probe time. (That is also the reason why they get registered withsubsys_initcall().) So if the NVMEM core would be a module, the layouts could be modules, too.I know Michael is busy after the FOSDEM and so am I, so, Greg, would you accept to take the PR as it is, participate to the discussion and wait for an update?
Kernel development doesn't work on "PR" :)
And no, I can't take these, as I don't agree with them, and I totally imagine others will object for the same reason I did (and then they would object to me, as the patches would be in my tree, as I am then responsible for them.)
So send an updated version whenever you have the chance. Again, there's no rush, deadline, or anything else here. Code is accepted when it is ready and correct, not anytime earlier.
thanks,
greg k-h