2017-04-13 19:49:46

by Steven J. Hill

[permalink] [raw]
Subject: MMC block addressing mode.

Uffe,

The Cavium hardware requires knowledge of the card addressing mode.
We need to either restore mmc_card_blockaddr(), or create another
way to generate the same information. You previously suggested use
of the 'blksz' value, however, it has the same value regardless of
the card capacity. What would you suggest? Cheers.

Steve


2017-04-20 14:18:36

by Ulf Hansson

[permalink] [raw]
Subject: Re: MMC block addressing mode.

On 13 April 2017 at 21:49, Steven J. Hill <[email protected]> wrote:
> Uffe,
>
> The Cavium hardware requires knowledge of the card addressing mode.
> We need to either restore mmc_card_blockaddr(), or create another
> way to generate the same information. You previously suggested use
> of the 'blksz' value, however, it has the same value regardless of
> the card capacity. What would you suggest? Cheers.

Right. Can you explain what the Cavium hardware need it for?

Kind regards
Uffe

2017-04-20 16:18:04

by Steven J. Hill

[permalink] [raw]
Subject: Re: MMC block addressing mode.

On 04/20/2017 09:18 AM, Ulf Hansson wrote:
>>
>> The Cavium hardware requires knowledge of the card addressing mode.
>> We need to either restore mmc_card_blockaddr(), or create another
>> way to generate the same information. You previously suggested use
>> of the 'blksz' value, however, it has the same value regardless of
>> the card capacity. What would you suggest? Cheers.
>
> Right. Can you explain what the Cavium hardware need it for?
>
Uffe,

In Cavium's MMC controller, the DMA engine requires software to
specify the addressing mode of the card. For DMA write operations,
the CARD_ADDR field in the MIO_EMM_DMA register is programmed with
a byte address if the media card <= 2GB. If the card is > 2GB, the
address is interpreted as a 512 byte sector address. The SECTOR bit
tells the controller how to interpret the address in CARD_ADDR. If
set to 1, use 512 byte sector addressing, otherwise it is set to 0
and byte addressing is used.

Steve

2017-04-20 17:12:51

by David Daney

[permalink] [raw]
Subject: Re: MMC block addressing mode.

On 04/20/2017 09:17 AM, Steven J. Hill wrote:
> On 04/20/2017 09:18 AM, Ulf Hansson wrote:
>>>
>>> The Cavium hardware requires knowledge of the card addressing mode.
>>> We need to either restore mmc_card_blockaddr(), or create another
>>> way to generate the same information. You previously suggested use
>>> of the 'blksz' value, however, it has the same value regardless of
>>> the card capacity. What would you suggest? Cheers.
>>
>> Right. Can you explain what the Cavium hardware need it for?
>>
> Uffe,
>
> In Cavium's MMC controller, the DMA engine requires software to
> specify the addressing mode of the card. For DMA write operations,
> the CARD_ADDR field in the MIO_EMM_DMA register is programmed with
> a byte address if the media card <= 2GB. If the card is > 2GB, the
> address is interpreted as a 512 byte sector address. The SECTOR bit
> tells the controller how to interpret the address in CARD_ADDR. If
> set to 1, use 512 byte sector addressing, otherwise it is set to 0
> and byte addressing is used.
>

... In other words:

The Cavium MMC controller doesn't directly send the commands supplied by
the MMC core to the target device. The driver analyzes the intent of
the commands, and then programs the MMC bus interface unit to synthesize
an equivalent, but perhaps different, set of commands to the target
device. As part of this synthesis, hardware needs to be told if sector
or byte addressing is used by the target device.

Steven and Jan: Can we get around this requirement by:

- Always set MIO_EMM_DMA[MULTI] = 1; This way by SECTOR mode may be
unimportant.

- Always set MIO_EMM_DMA[SECTOR] = SUITABLE_CONSTANT.

2017-04-20 21:24:42

by Steven J. Hill

[permalink] [raw]
Subject: Re: MMC block addressing mode.

On 04/20/2017 12:12 PM, David Daney wrote:
>
> Steven and Jan: Can we get around this requirement by:
>
> - Always set MIO_EMM_DMA[MULTI] = 1; This way by SECTOR mode may be unimportant.
>
> - Always set MIO_EMM_DMA[SECTOR] = SUITABLE_CONSTANT.
>
No, this does not work. The 1.88GB card plugged into my 78xx
board gives the output below. We cannot just blindly set the
MULTI bit for all cards. These results are identical for all
four combinations of SECTOR and MULTI values hardcoded.


mmc0: host does not support reading read-only switch, assuming write-enable
mmc0: new high speed SD card at address d15e
mmcblk0: mmc0:d15e SD02G 1.88 GiB
mmcblk0: timed out sending r/w cmd command, card status 0x400900
mmcblk0: command error, retrying timeout
mmcblk0: timed out sending r/w cmd command, card status 0x400900
mmcblk0: command error, retrying timeout
mmcblk0: timed out sending r/w cmd command, card status 0x400900
mmcblk0: command error, retrying timeout
mmcblk0: timed out sending r/w cmd command, card status 0x400900
mmcblk0: command error, retrying timeout
mmcblk0: timed out sending r/w cmd command, card status 0x400900
mmcblk0: command error, retrying timeout
mmcblk0: timed out sending r/w cmd command, card status 0x400900
mmcblk0: command error, retrying timeout
mmcblk0: timed out sending r/w cmd command, card status 0x400900
mmcblk0: command error, retrying timeout
blk_update_request: I/O error, dev mmcblk0, sector 0
Buffer I/O error on dev mmcblk0, logical block 0, async page read
mmcblk0: timed out sending r/w cmd command, card status 0x400900
mmcblk0: command error, retrying timeout
mmcblk0: timed out sending r/w cmd command, card status 0x400900
mmcblk0: command error, retrying timeout
mmcblk0: timed out sending r/w cmd command, card status 0x40090

2017-04-20 21:28:18

by Steven J. Hill

[permalink] [raw]
Subject: Re: MMC block addressing mode.

On 04/20/2017 04:24 PM, Steven J. Hill wrote:
> On 04/20/2017 12:12 PM, David Daney wrote:
>>
>> Steven and Jan: Can we get around this requirement by:
>>
>> - Always set MIO_EMM_DMA[MULTI] = 1; This way by SECTOR mode may be unimportant.
>>
>> - Always set MIO_EMM_DMA[SECTOR] = SUITABLE_CONSTANT.
>>
> No, this does not work. The 1.88GB card plugged into my 78xx
> board gives the output below. We cannot just blindly set the
> MULTI bit for all cards. These results are identical for all
> four combinations of SECTOR and MULTI values hardcoded.
>
...for 3 of the 4 combinations. Obviously the correct one works.

2017-04-21 08:24:35

by Ulf Hansson

[permalink] [raw]
Subject: Re: MMC block addressing mode.

On 20 April 2017 at 23:28, Steven J. Hill <[email protected]> wrote:
> On 04/20/2017 04:24 PM, Steven J. Hill wrote:
>> On 04/20/2017 12:12 PM, David Daney wrote:
>>>
>>> Steven and Jan: Can we get around this requirement by:
>>>
>>> - Always set MIO_EMM_DMA[MULTI] = 1; This way by SECTOR mode may be unimportant.
>>>
>>> - Always set MIO_EMM_DMA[SECTOR] = SUITABLE_CONSTANT.
>>>
>> No, this does not work. The 1.88GB card plugged into my 78xx
>> board gives the output below. We cannot just blindly set the
>> MULTI bit for all cards. These results are identical for all
>> four combinations of SECTOR and MULTI values hardcoded.
>>
> ...for 3 of the 4 combinations. Obviously the correct one works.

I get it, thanks for the clarifications!

I have cooked a patch below, providing you with the API I think you
need. If it works, please fold in the patch in the series when you
post you updated Cavium driver(s).

Kind regards
Uffe

From: Ulf Hansson <[email protected]>
Date: Fri, 21 Apr 2017 08:31:15 +0200
Subject: [PATCH] mmc: core: Export API to allow hosts to get the card address
mode

Some hosts controllers, like Cavium, needs to know whether the card
operates in byte- or block-address mode. Therefore export a new API,
mmc_card_is_blockaddr(), which provides this information.

Signed-off-by: Ulf Hansson <[email protected]>
---
drivers/mmc/core/core.c | 6 ++++++
include/linux/mmc/card.h | 2 ++
2 files changed, 8 insertions(+)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 0bb3979..f053ef5 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2558,6 +2558,12 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
}
EXPORT_SYMBOL(mmc_calc_max_discard);

+bool mmc_card_is_blockaddr(struct mmc_card *card)
+{
+ return card ? mmc_card_blockaddr(card) : false;
+}
+EXPORT_SYMBOL(mmc_card_is_blockaddr);
+
int mmc_set_blocklen(struct mmc_card *card, unsigned int blocklen)
{
struct mmc_command cmd = {};
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 85b5f2b..aad015e 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -315,6 +315,8 @@ static inline bool mmc_large_sector(struct mmc_card *card)
return card->ext_csd.data_sector_size == 4096;
}

+bool mmc_card_is_blockaddr(struct mmc_card *card);
+
#define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
#define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD)
#define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO)
--
2.7.4