linux-fpga.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Simek <monstr@monstr.eu>
To: Brandon Maier <brandon.maier@rockwellcollins.com>,
	atull@kernel.org, mdf@kernel.org
Cc: linux-fpga@vger.kernel.org, clayton.shotwell@rockwellcollins.com
Subject: Re: [PATCH] fpga: mgr: Use devicetree /alias to assign FPGA IDs
Date: Tue, 16 Apr 2019 14:05:24 +0200	[thread overview]
Message-ID: <a3513e84-0328-b2ef-1ca2-1c563caf0e6d@monstr.eu> (raw)
In-Reply-To: <20190411221109.173242-1-brandon.maier@rockwellcollins.com>


[-- Attachment #1.1: Type: text/plain, Size: 2366 bytes --]

On 12. 04. 19 0:11, Brandon Maier wrote:
> The fpga-mgr assigns device IDs based on the order each driver calls
> fpga_mgr_register(). This is fine for systems with one FPGA, but if
> multiple FPGAs are in use, the device ID can change as probe order
> changes across reboots or configuration changes.
> 
> This makes it difficult to use the sysfs attributes, as the device path
> may change. Instead allow a static ID to be set by adding fpgaX props
> to the devicetree /aliases. Falling back to incrementing IDs if none are
> provided.
> 
> This is based on the function rtc_device_get_id() in drivers/rtc/class.c
> (9d2b7e532da8 rtc: honor device tree /alias entries when assigning IDs).
> 
> Signed-off-by: Brandon Maier <brandon.maier@rockwellcollins.com>
> ---
>  drivers/fpga/fpga-mgr.c | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/fpga/fpga-mgr.c b/drivers/fpga/fpga-mgr.c
> index c3866816456a..d8b7e7a61117 100644
> --- a/drivers/fpga/fpga-mgr.c
> +++ b/drivers/fpga/fpga-mgr.c
> @@ -551,6 +551,26 @@ void fpga_mgr_unlock(struct fpga_manager *mgr)
>  }
>  EXPORT_SYMBOL_GPL(fpga_mgr_unlock);
>  
> +static int fpga_mgr_get_id(struct device *dev)
> +{
> +	int of_id = -1, id = -1;
> +
> +	if (dev->of_node)
> +		of_id = of_alias_get_id(dev->of_node, "fpga");
> +
> +	if (of_id >= 0) {
> +		id = ida_simple_get(&fpga_mgr_ida, of_id, of_id + 1,
> +				    GFP_KERNEL);
> +		if (id < 0)
> +			dev_warn(dev, "/aliases ID %d not available\n", of_id);
> +	}
> +
> +	if (id < 0)
> +		id = ida_simple_get(&fpga_mgr_ida, 0, 0, GFP_KERNEL);
> +
> +	return id;
> +}

From the first look this is not proper implementation. It is not
handling cases where you have mix of devices with and without aliases.
If first mgr has no alias it gets 0, then second devices with fpga0
alias can't take it even it is assign to it.

For exactly this reason I have introduced of_alias_get_alias_list()
and take a look at cdns_get_id() in serial driver how I am using it.

Thanks,
Michal

-- 
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  parent reply	other threads:[~2019-04-16 12:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11 22:11 [PATCH] fpga: mgr: Use devicetree /alias to assign FPGA IDs Brandon Maier
2019-04-15 18:31 ` Alan Tull
2019-04-16 12:05 ` Michal Simek [this message]
2019-04-16 16:08   ` Brandon Maier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a3513e84-0328-b2ef-1ca2-1c563caf0e6d@monstr.eu \
    --to=monstr@monstr.eu \
    --cc=atull@kernel.org \
    --cc=brandon.maier@rockwellcollins.com \
    --cc=clayton.shotwell@rockwellcollins.com \
    --cc=linux-fpga@vger.kernel.org \
    --cc=mdf@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).