Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp240924rdd; Wed, 22 Nov 2023 14:46:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLHXZQGI8AUfdCTz1Ep28H4TEPQPlFR8ZJdsrwNuDCOpwSTAm+vHLkzZEL14aML3uNNSLr X-Received: by 2002:a05:6871:5386:b0:1f5:b56e:d637 with SMTP id hy6-20020a056871538600b001f5b56ed637mr5151587oac.32.1700693182300; Wed, 22 Nov 2023 14:46:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700693182; cv=none; d=google.com; s=arc-20160816; b=SoskVtVDgwltojdd+UUKvb21hEwCbGbmSjy4ST5BVjihrFNheiznhItkvgaCZd9IXs WHzcibzX0ZcKa3c3dR/jEMDna/ijh3Zj9c8ZBEFDwJ2W4VqivmpTDUPrBOvCj1acjQT8 MtRQw7+h5MBQYSpENDCbdARl/4+AnjRbNKafRZJiic6EjkqwkB9ZTHQ9olwiXG7Jzffi 6EDQWIRzZYWZl/NqzqWlgtHcaKVF2+dyCGyHjBPfUVf3RHAudZ9ZhXcBLikPn2zyhvjI 2KCtEsTxaWI4T3pkHl/NEm7ZZLVxKkU9lg1av7qGwytsg904r6ytEbToCgZU8wrnRz7x jsYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=rR90Kd8fSoWHXAg0+ZfAjbBZ96hgpkPA9T6R8qdT1tg=; fh=j+Uu8tOZSLtWMjoH+7Q8oIV7EcfjccZrZa1IRkA4Ypc=; b=kqMlG2fDqUmkeOmnlUGZau2q/y/vZpCjNpQtgU1izdo/uMm2ydPt0ltgBvVcep0+0X bAPXQnsOqlY3q2Vz1w10Dmfrv4SDzxX1qzSGrVHV04HKbtVNiWFA+9qOYM2AIpr4SJAp LXWzQu1EXcmneVZlF54Sl6RSh7kk/yeD9q9iz0uayG0RNf5cUDk9qJgpkovxWEQB4G5W uxcNBztxJAJdnIdlhqMxsOOlAlDH922Ypes+9aY6Pog8Fx1tjvjrRMZObOSrJTPCwE4g YD09uqpFLlMSJe/fJm2S3mHOetogWXRaBkF6atLsptcmqn36VGKfzkN+9neIJUyAptBJ rg8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q21-20020a056a00151500b006c6a9c10e15si17326pfu.46.2023.11.22.14.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 14:46:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id E29A6837FA3D; Wed, 22 Nov 2023 14:46:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232195AbjKVWqD (ORCPT + 99 others); Wed, 22 Nov 2023 17:46:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231478AbjKVWqC (ORCPT ); Wed, 22 Nov 2023 17:46:02 -0500 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90F8AD8 for ; Wed, 22 Nov 2023 14:45:58 -0800 (PST) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r5vyj-0007xT-Si; Wed, 22 Nov 2023 23:45:53 +0100 Received: from [2a0a:edc0:2:b01:1d::c0] (helo=ptx.whiteo.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r5vyj-00AuMF-4Q; Wed, 22 Nov 2023 23:45:53 +0100 Received: from mfe by ptx.whiteo.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1r5vyj-003Mus-1S; Wed, 22 Nov 2023 23:45:53 +0100 Date: Wed, 22 Nov 2023 23:45:53 +0100 From: Marco Felsch To: Miquel Raynal Cc: devicetree@vger.kernel.org, Luka Perkov , kernel@pengutronix.de, Greg Kroah-Hartman , Randy Dunlap , linux-kernel@vger.kernel.org, Daniel Golle , Michael Walle , Rob Herring , Srinivas Kandagatla , Thomas Petazzoni , Chen-Yu Tsai , =?utf-8?B?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Frank Rowand Subject: Re: [PATCH v13 4/6] nvmem: core: Rework layouts to become regular devices Message-ID: <20231122224553.cfklcv6rew6ktixj@pengutronix.de> References: <20231011111529.86440-1-miquel.raynal@bootlin.com> <20231011111529.86440-5-miquel.raynal@bootlin.com> <20231122220240.4jg245vblnh6d5zy@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231122220240.4jg245vblnh6d5zy@pengutronix.de> User-Agent: NeoMutt/20180716 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: mfe@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 22 Nov 2023 14:46:19 -0800 (PST) Hi Miquel, sorry for answering to my own mail, I forgot something I noticed later. On 23-11-22, Marco Felsch wrote: > Hi Miquel, > > thanks a lot for your effort on this. Please see my comments inline. > > On 23-10-11, Miquel Raynal wrote: > > Current layout support was initially written without modules support in > > mind. When the requirement for module support rose, the existing base > > was improved to adopt modularization support, but kind of a design flaw > > was introduced. With the existing implementation, when a storage device > > registers into NVMEM, the core tries to hook a layout (if any) and > > populates its cells immediately. This means, if the hardware description > > expects a layout to be hooked up, but no driver was provided for that, > > the storage medium will fail to probe and try later from > > scratch. Even if we consider that the hardware description shall be > > correct, we could still probe the storage device (especially if it > > contains the rootfs). > > > > One way to overcome this situation is to consider the layouts as > > devices, and leverage the existing notifier mechanism. When a new NVMEM > > device is registered, we can: > > - populate its nvmem-layout child, if any > > - try to modprobe the relevant driver, if relevant I'm not sure why we call of_request_module() the driver framework should handle that right? > > - try to hook the NVMEM device with a layout in the notifier The last part is no longer true since you don't use the notifier anymore. > > And when a new layout is registered: > > - try to hook all the existing NVMEM devices which are not yet hooked to > > a layout with the new layout > > This way, there is no strong order to enforce, any NVMEM device creation > > or NVMEM layout driver insertion will be observed as a new event which > > may lead to the creation of additional cells, without disturbing the > > probes with costly (and sometimes endless) deferrals. > > > > In order to achieve that goal we need: > > * To keep track of all nvmem devices > > * To create a new bus for the nvmem-layouts with minimal logic to match > > nvmem-layout devices with nvmem-layout drivers. > > All this infrastructure code is created in the layouts.c file. > > > > Signed-off-by: Miquel Raynal > > Tested-by: Rafał Miłecki ... > > @@ -944,19 +872,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) > > goto err_put_device; > > } > > > > - /* > > - * If the driver supplied a layout by config->layout, the module > > - * pointer will be NULL and nvmem_layout_put() will be a noop. > > - */ > > - nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); > > - if (IS_ERR(nvmem->layout)) { > > - rval = PTR_ERR(nvmem->layout); > > - nvmem->layout = NULL; > > - > > - if (rval == -EPROBE_DEFER) > > - goto err_teardown_compat; > > - } Since this logic will be gone and the layout became a device the fixup hook for the layout is more than confusing. E.g. the imx-ocotp driver uses the layout to register a fixup for a cell which is fine but the hook should be moved from the layout[-dev] to the config. Please see below. > > - > > if (config->cells) { > > rval = nvmem_add_cells(nvmem, config->cells, config->ncells); > > if (rval) > > @@ -975,7 +890,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) > > if (rval) > > goto err_remove_cells; > > > > - rval = nvmem_add_cells_from_layout(nvmem); > > + rval = nvmem_populate_layout(nvmem); > > if (rval) > > goto err_remove_cells; Also why do we populate the nvmem-layout device infront of the nvmem device? > > > > @@ -983,16 +898,17 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) > > > > rval = device_add(&nvmem->dev); > > if (rval) > > - goto err_remove_cells; > > + goto err_destroy_layout; > > + > > > > blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); > > > > return nvmem; > > > > +err_destroy_layout: > > + nvmem_destroy_layout(nvmem); > > err_remove_cells: > > nvmem_device_remove_all_cells(nvmem); > > - nvmem_layout_put(nvmem->layout); > > -err_teardown_compat: > > if (config->compat) > > nvmem_sysfs_remove_compat(nvmem, config); > > err_put_device: > > @@ -1014,7 +930,7 @@ static void nvmem_device_release(struct kref *kref) > > device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); > > > > nvmem_device_remove_all_cells(nvmem); > > - nvmem_layout_put(nvmem->layout); > > + nvmem_destroy_layout(nvmem); > > device_unregister(&nvmem->dev); > > } > > ... > > diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h > > index 2905f9e6fc2a..a0ea8326605a 100644 > > --- a/include/linux/nvmem-provider.h > > +++ b/include/linux/nvmem-provider.h > > @@ -9,6 +9,7 @@ > > #ifndef _LINUX_NVMEM_PROVIDER_H > > #define _LINUX_NVMEM_PROVIDER_H > > > > +#include > > #include > > #include > > #include > > @@ -154,15 +155,13 @@ struct nvmem_cell_table { > > /** > > * struct nvmem_layout - NVMEM layout definitions > > * > > - * @name: Layout name. > > - * @of_match_table: Open firmware match table. > > + * @dev: Device-model layout device. > > + * @nvmem: The underlying NVMEM device > > * @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. > > * > > * A nvmem device can hold a well defined structure which can just be > > * evaluated during runtime. For example a TLV list, or a list of "name=val" > > @@ -170,17 +169,19 @@ struct nvmem_cell_table { > > * cells. > > */ > > struct nvmem_layout { > > Since this became a device now should we refelct this within the struct > name, e.g. nvmem_layout_dev, nvmem_ldev, nvm_ldev? > > Regards, > Marco > > > - const char *name; > > - const struct of_device_id *of_match_table; > > + struct device dev; > > + struct nvmem_device *nvmem; > > 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); I speak about this hook. This should be moved into the config, maybe also renamed to fixup_dt_cell_info() or so to not confuse the users. If we move that hook and remove the add_cells hook there are only two members left for the cross-link. Regards, Marco