mmc: core: fix missing reserved indexes

This has been accidentially dropped with the merge of v5.4.118 tag from
stable korg.

Functionality ommitted present only in the NXP tree, therefore merge
conflict solve dropped the functionality in favor of stable update.

Bring back the functionality present in the NXP tree to assign reserved
indexes to block devices.

Signed-off-by: Grygorii Tertychnyi <grygorii.tertychnyi@leica-geosystems.com>
Signed-off-by: Andrey Zhizhikin <andrey.zhizhikin@leica-geosystems.com>
Fixes: ba4e63325c ("Merge tag 'v5.4.118' into 5.4-2.3.x-imx")
Link: https://github.com/Freescale/linux-fslc/pull/334
This commit is contained in:
Andrey Zhizhikin 2021-05-26 17:24:55 +00:00
parent d34d22f869
commit ff9d9347c3
2 changed files with 48 additions and 2 deletions

View File

@ -52,6 +52,8 @@
static const unsigned freqs[] = { 400000, 300000, 200000, 100000 };
static int __mmc_max_reserved_idx = -1;
/*
* Enabling software CRCs on the data blocks can be a significant (30%)
* performance cost, and for other reasons may not always be desired.
@ -2392,10 +2394,46 @@ void mmc_stop_host(struct mmc_host *host)
mmc_release_host(host);
}
/*
* mmc_first_nonreserved_index() - get the first index that
* is not reserved
*/
int mmc_first_nonreserved_index(void)
{
return __mmc_max_reserved_idx + 1;
}
EXPORT_SYMBOL(mmc_first_nonreserved_index);
/*
* mmc_get_reserved_index() - get the index reserved for this host
* Return: The index reserved for this host or negative error value
* if no index is reserved for this host
*/
int mmc_get_reserved_index(struct mmc_host *host)
{
return of_alias_get_id(host->parent->of_node, "mmc");
}
EXPORT_SYMBOL(mmc_get_reserved_index);
static void mmc_of_reserve_idx(void)
{
int max;
max = of_alias_max_index("mmc");
if (max < 0)
return;
__mmc_max_reserved_idx = max;
pr_debug("MMC: reserving %d slots for of aliases\n",
__mmc_max_reserved_idx + 1);
}
static int __init mmc_init(void)
{
int ret;
mmc_of_reserve_idx();
ret = mmc_register_bus();
if (ret)
return ret;

View File

@ -433,6 +433,7 @@ EXPORT_SYMBOL(mmc_of_parse_voltage);
struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
{
int err;
int alias_id;
struct mmc_host *host;
host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
@ -441,8 +442,16 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
/* scanning will be enabled when we're ready */
host->rescan_disable = 1;
host->parent = dev;
err = ida_simple_get(&mmc_host_ida, 0, 0, GFP_KERNEL);
alias_id = mmc_get_reserved_index(host);
if (alias_id >= 0)
err = ida_simple_get(&mmc_host_ida, alias_id,
alias_id + 1, GFP_KERNEL);
else
err = ida_simple_get(&mmc_host_ida,
mmc_first_nonreserved_index(),
0, GFP_KERNEL);
if (err < 0) {
kfree(host);
return NULL;
@ -452,7 +461,6 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
dev_set_name(&host->class_dev, "mmc%d", host->index);
host->parent = dev;
host->class_dev.parent = dev;
host->class_dev.class = &mmc_host_class;
device_initialize(&host->class_dev);