All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 0/2] Set mmc(blk)X with DT alias
@ 2013-07-24  9:09 Steffen Trumtrar
  2013-07-24  9:09 ` [RFC 1/2] mmc: block: allow setting name_idx via devicetree Steffen Trumtrar
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Steffen Trumtrar @ 2013-07-24  9:09 UTC (permalink / raw)
  To: linux-mmc; +Cc: Chris Ball, devicetree, kernel, Steffen Trumtrar

Hi!

Embedded devices often use multiple SD/MMC devices as boot/rootfs disks.
Some of them are removable, some not. If the removable cards are not
present, but are probed before the non-removable ones, the indexing
scheme changes. This makes it harder to hard-code the rootfs in the
cmdline.

First solution I came up with was the alias-node in DT.
I guess my implementation is pretty hacky and ugly, but you can get lost
pretty fast in the whole mmc stack.
For example, the second patch should use "card->host->index" instead of parsing
the alias again, I guess. I'm not sure why it currently doesn't though.

So, if there is a better place or solution to specify a reliable ordering
of mmc devices, please let me hear it.

Thanks,
Steffen


Steffen Trumtrar (2):
  mmc: block: allow setting name_idx via devicetree
  mmc: host: allow setting index via devicetree

 drivers/mmc/card/block.c | 7 ++++++-
 drivers/mmc/core/host.c  | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

-- 
1.8.3.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [RFC 1/2] mmc: block: allow setting name_idx via devicetree
  2013-07-24  9:09 [RFC 0/2] Set mmc(blk)X with DT alias Steffen Trumtrar
@ 2013-07-24  9:09 ` Steffen Trumtrar
  2013-07-24  9:09 ` [RFC 2/2] mmc: host: allow setting index " Steffen Trumtrar
  2013-07-25 17:28 ` [RFC 0/2] Set mmc(blk)X with DT alias Stephen Warren
  2 siblings, 0 replies; 5+ messages in thread
From: Steffen Trumtrar @ 2013-07-24  9:09 UTC (permalink / raw)
  To: linux-mmc; +Cc: Chris Ball, devicetree, kernel, Steffen Trumtrar

As with gpio, uart and others, allow specifying the name_idx via the
aliases-node in the devicetree.

On embedded devices, there is often a combination of removable (e.g.
SD card) and non-removable mmc devices (e.g. eMMC).
Therefore the name_idx might change depending on
	- host of removable device
	- removable card present or not

This makes it difficult to hard code the root device, if it is on the
non-removable device. E.g. if SD card is present eMMC will be mmcblk1,
if SD card is not present at boot, eMMC will be mmcblk0.

If the aliases-node is not found, the driver will act as before.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>

---
 drivers/mmc/card/block.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index cd0b7f4..5853c59 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -35,6 +35,7 @@
 #include <linux/capability.h>
 #include <linux/compat.h>
 #include <linux/pm_runtime.h>
+#include <linux/of.h>
 
 #include <linux/mmc/ioctl.h>
 #include <linux/mmc/card.h>
@@ -2005,7 +2006,11 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
 	 * index anymore so we keep track of a name index.
 	 */
 	if (!subname) {
-		md->name_idx = find_first_zero_bit(name_use, max_devices);
+		ret = of_alias_get_id(card->host->parent->of_node, "mmc");
+		if (ret < 0)
+			md->name_idx = find_first_zero_bit(name_use, max_devices);
+		else
+			md->name_idx = ret;
 		__set_bit(md->name_idx, name_use);
 	} else
 		md->name_idx = ((struct mmc_blk_data *)
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC 2/2] mmc: host: allow setting index via devicetree
  2013-07-24  9:09 [RFC 0/2] Set mmc(blk)X with DT alias Steffen Trumtrar
  2013-07-24  9:09 ` [RFC 1/2] mmc: block: allow setting name_idx via devicetree Steffen Trumtrar
@ 2013-07-24  9:09 ` Steffen Trumtrar
  2013-07-25 17:28 ` [RFC 0/2] Set mmc(blk)X with DT alias Stephen Warren
  2 siblings, 0 replies; 5+ messages in thread
From: Steffen Trumtrar @ 2013-07-24  9:09 UTC (permalink / raw)
  To: linux-mmc; +Cc: Chris Ball, devicetree, kernel, Steffen Trumtrar

As with gpio, uart and others, allow specifying the host index via the
aliases-node in the devicetree.

On embedded devices, there is often a combination of removable (e.g.
SD card) and non-removable mmc devices (e.g. eMMC).
Therefore the mmcblk name_idx might change depending on
	- host of removable device
	- removable card present or not

This makes it difficult to hard code the root device, if it is on the
non-removable device. E.g. if SD card is present eMMC will be mmcblk1,
if SD card is not present at boot, eMMC will be mmcblk0.

To match the host index with the mmcblk, allow setting the index via
an alias node.

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
 drivers/mmc/core/host.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 6fb6f77..640228f 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -450,16 +450,21 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
 {
 	int err;
 	struct mmc_host *host;
+	int alias_id;
 
 	host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
 	if (!host)
 		return NULL;
 
+	alias_id = of_alias_get_id(dev->of_node, "mmc");
+	if (alias_id < 0)
+		alias_id = 0;
+
 	/* scanning will be enabled when we're ready */
 	host->rescan_disable = 1;
 	idr_preload(GFP_KERNEL);
 	spin_lock(&mmc_host_lock);
-	err = idr_alloc(&mmc_host_idr, host, 0, 0, GFP_NOWAIT);
+	err = idr_alloc(&mmc_host_idr, host, alias_id, 0, GFP_NOWAIT);
 	if (err >= 0)
 		host->index = err;
 	spin_unlock(&mmc_host_lock);
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC 0/2] Set mmc(blk)X with DT alias
  2013-07-24  9:09 [RFC 0/2] Set mmc(blk)X with DT alias Steffen Trumtrar
  2013-07-24  9:09 ` [RFC 1/2] mmc: block: allow setting name_idx via devicetree Steffen Trumtrar
  2013-07-24  9:09 ` [RFC 2/2] mmc: host: allow setting index " Steffen Trumtrar
@ 2013-07-25 17:28 ` Stephen Warren
  2013-07-26  8:09   ` Steffen Trumtrar
  2 siblings, 1 reply; 5+ messages in thread
From: Stephen Warren @ 2013-07-25 17:28 UTC (permalink / raw)
  To: Steffen Trumtrar; +Cc: linux-mmc, Chris Ball, devicetree, kernel

On 07/24/2013 02:09 AM, Steffen Trumtrar wrote:
> Hi!
> 
> Embedded devices often use multiple SD/MMC devices as boot/rootfs disks.
> Some of them are removable, some not. If the removable cards are not
> present, but are probed before the non-removable ones, the indexing
> scheme changes. This makes it harder to hard-code the rootfs in the
> cmdline.
>
> First solution I came up with was the alias-node in DT.
> I guess my implementation is pretty hacky and ugly, but you can get lost
> pretty fast in the whole mmc stack.
> For example, the second patch should use "card->host->index" instead of parsing
> the alias again, I guess. I'm not sure why it currently doesn't though.

This has been discussed a few times before and rejected IIRC. One issue
is that block device ID is actually decoupled from host controller ID
anyway, e.g. if a removable device is mounted, removed, and then
re-plugged the new device can get a different ID, so this approach
doesn't really work in all cases anyway.

> So, if there is a better place or solution to specify a reliable ordering
> of mmc devices, please let me hear it.

root=UUID=xxx or root=PARTUUID=xxx are the best solution. With recent
U-Boot, you can enable and use the "part" command to find the partition
UUID automatically, and hence not need to hard-code anything. Something
similar could presumably be implemented for other bootloaders.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC 0/2] Set mmc(blk)X with DT alias
  2013-07-25 17:28 ` [RFC 0/2] Set mmc(blk)X with DT alias Stephen Warren
@ 2013-07-26  8:09   ` Steffen Trumtrar
  0 siblings, 0 replies; 5+ messages in thread
From: Steffen Trumtrar @ 2013-07-26  8:09 UTC (permalink / raw)
  To: Stephen Warren; +Cc: linux-mmc, Chris Ball, devicetree, kernel

On Thu, Jul 25, 2013 at 10:28:38AM -0700, Stephen Warren wrote:
> On 07/24/2013 02:09 AM, Steffen Trumtrar wrote:
> > Hi!
> > 
> > Embedded devices often use multiple SD/MMC devices as boot/rootfs disks.
> > Some of them are removable, some not. If the removable cards are not
> > present, but are probed before the non-removable ones, the indexing
> > scheme changes. This makes it harder to hard-code the rootfs in the
> > cmdline.
> >
> > First solution I came up with was the alias-node in DT.
> > I guess my implementation is pretty hacky and ugly, but you can get lost
> > pretty fast in the whole mmc stack.
> > For example, the second patch should use "card->host->index" instead of parsing
> > the alias again, I guess. I'm not sure why it currently doesn't though.
> 
> This has been discussed a few times before and rejected IIRC. One issue
> is that block device ID is actually decoupled from host controller ID
> anyway, e.g. if a removable device is mounted, removed, and then
> re-plugged the new device can get a different ID, so this approach
> doesn't really work in all cases anyway.
> 

Hm, okay. I actually wasn't aware of the older discussions.

> > So, if there is a better place or solution to specify a reliable ordering
> > of mmc devices, please let me hear it.
> 
> root=UUID=xxx or root=PARTUUID=xxx are the best solution. With recent
> U-Boot, you can enable and use the "part" command to find the partition
> UUID automatically, and hence not need to hard-code anything. Something
> similar could presumably be implemented for other bootloaders.

I am actually okay with that. I know barebox can do that, but didn't knew that
U-Boot is also capabable of that.
So, I'm okay with dropping the patch.

Thanks,
Steffen

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-07-26  8:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-24  9:09 [RFC 0/2] Set mmc(blk)X with DT alias Steffen Trumtrar
2013-07-24  9:09 ` [RFC 1/2] mmc: block: allow setting name_idx via devicetree Steffen Trumtrar
2013-07-24  9:09 ` [RFC 2/2] mmc: host: allow setting index " Steffen Trumtrar
2013-07-25 17:28 ` [RFC 0/2] Set mmc(blk)X with DT alias Stephen Warren
2013-07-26  8:09   ` Steffen Trumtrar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.