mmc: meson-gx: check for scatterlist size alignment in block mode
Subsystems (2)
PATCH 1/1 mmc: meson-gx: check for scatterlist size alignment in block mode
Enable SGDMA support for SD_IO_RW_EXTENDED and add proper check for scatterlist size alignment in block mode.
According to documentation, in SDIO block mode meson-gx DMA could only handle buffers with sizes that are multiples of SDIO block size.
Some SDIO drivers like brcmfmac use scatterlist API, but do not enforce proper scatterlist buffer size alignemnt, this looks like a root cause of non-working CMD53.
Some minor style fixes.
--- drivers/mmc/host/meson-gx-mmc.c | 37 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +22 -15
@@ -227,7 +227,6 @@ static void meson_mmc_get_transfer_mode(struct mmc_host *mmc,struct mmc_data *data = mrq->data;struct scatterlist *sg;int i; -bool use_desc_chain_mode = true;/* * When Controller DMA cannot directly access DDR memory, disable
@@ -237,25 +236,33 @@ static void meson_mmc_get_transfer_mode(struct mmc_host *mmc,if (host->dram_access_quirk)return ; -/* -* Broken SDIO with AP6255-based WiFi on Khadas VIM Pro has been -* reported. For some strange reason this occurs in descriptor -* chain mode only. So let's fall back to bounce buffer mode -* for command SD_IO_RW_EXTENDED. -*/ -if (mrq->cmd->opcode ==SD_IO_RW_EXTENDED ) -return ; +if (data->blocks >1 ) { +/* +* In block mode DMA descriptor format, "length" field indicates +* number of blocks and there is no way to pass DMA size that +* is not multiple of SDIO block size, making it impossible to +* tie more than one memory buffer with single SDIO block. +* Block mode sg buffer size should be aligned with SDIO block +* size, otherwise chain mode could not be used. +*/ +for_each_sg (data->sg, sg, data->sg_len, i) { +if (sg->length % data->blksz) { +WARN_ONCE (1 ,"unaligned sg len %u blksize %u\n" , + sg->length, data->blksz); +return ; + } + } + } -for_each_sg (data->sg, sg, data->sg_len, i) +for_each_sg (data->sg, sg, data->sg_len, i) {/* check for 8 byte alignment */ -if (sg->offset &7 ) { +if (sg->offset %8 ) {WARN_ONCE (1 ,"unaligned scatterlist buffer\n" ); - use_desc_chain_mode = false; -break ; +return ; } + } -if (use_desc_chain_mode) - data->host_cookie |=SD_EMMC_DESC_CHAIN_MODE ; + data->host_cookie |=SD_EMMC_DESC_CHAIN_MODE ; }static inline bool meson_mmc_desc_chain_mode (const struct mmc_data *data)
Signature · 7 lines
2.24.3 (Apple Git-128) _______________________________________________ linux-amlogic mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-amlogic
Am 18.12.2020 um 08:53 schrieb Dmitry Lebed:
Quoted 10 lines
Enable SGDMA support for
SD_IO_RW_EXTENDEDand add proper check for scatterlist size alignment in block mode.According to documentation, in SDIO block mode meson-gx DMA could only handle buffers with sizes that are multiples of SDIO block size.
Some SDIO drivers like brcmfmac use scatterlist API, but do not enforce proper scatterlist buffer size alignemnt, this looks like a root cause of non-working CMD53.
It's been too long ago that I worked on this to provide real feedback. Just one comment: Your commit description sounds like there's a problem in drivers like brcmfmac. Wouldn't it be better then to first fix these drivers?
Quoted 58 lines
Some minor style fixes.
Signed-off-by Dmitry Lebed <[email protected]>--- drivers/mmc/host/meson-gx-mmc.c | 37 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-)drivers/mmc/host/meson-gx-mmc.c +19
-13@@ -227,7 +227,6 @@ static void meson_mmc_get_transfer_mode(struct mmc_host *mmc,struct mmc_data *data = mrq->data;struct scatterlist *sg;int i; -bool use_desc_chain_mode = true;/* * When Controller DMA cannot directly access DDR memory, disable @@ -237,25 +236,33 @@ static void meson_mmc_get_transfer_mode(struct mmc_host *mmc,if (host->dram_access_quirk)return ; -/* -* Broken SDIO with AP6255-based WiFi on Khadas VIM Pro has been -* reported. For some strange reason this occurs in descriptor -* chain mode only. So let's fall back to bounce buffer mode -* for command SD_IO_RW_EXTENDED. -*/ -if (mrq->cmd->opcode ==SD_IO_RW_EXTENDED ) -return ; +if (data->blocks >1 ) { +/* +* In block mode DMA descriptor format, "length" field indicates +* number of blocks and there is no way to pass DMA size that +* is not multiple of SDIO block size, making it impossible to +* tie more than one memory buffer with single SDIO block. +* Block mode sg buffer size should be aligned with SDIO block +* size, otherwise chain mode could not be used. +*/ +for_each_sg (data->sg, sg, data->sg_len, i) { +if (sg->length % data->blksz) { +WARN_ONCE (1 ,"unaligned sg len %u blksize %u\n" , + sg->length, data->blksz); +return ; + } + } + } -for_each_sg (data->sg, sg, data->sg_len, i) +for_each_sg (data->sg, sg, data->sg_len, i) {/* check for 8 byte alignment */ -if (sg->offset &7 ) { +if (sg->offset %8 ) {WARN_ONCE (1 ,"unaligned scatterlist buffer\n" ); - use_desc_chain_mode = false; -break ;
drivers/mmc/host/meson-gx-mmc.c static void meson_mmc_get_transfer_mode(struct mmc_host *mmc, · line 268
Quoted 10 lines
drivers/mmc/host/meson-gx-mmc.c +3
-2+return ; } + } -if (use_desc_chain_mode) - data->host_cookie |=SD_EMMC_DESC_CHAIN_MODE ; + data->host_cookie |=SD_EMMC_DESC_CHAIN_MODE ; }static inline bool meson_mmc_desc_chain_mode (const struct mmc_data *data)
_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Quoted 7 lines · Heiner Kallweit
Am 18.12.2020 um 08:53 schrieb Dmitry Lebed:
Quoted 6 lines
Enable SGDMA support for
SD_IO_RW_EXTENDEDand add proper check for scatterlist size alignment in block mode.According to documentation, in SDIO block mode meson-gx DMA could only handle buffers with sizes that are multiples of SDIO block size.
Quoted 8 lines
Quoted 4 lines
Some SDIO drivers like brcmfmac use scatterlist API, but do not enforce proper scatterlist buffer size alignemnt, this looks like a root cause of non-working CMD53.
It's been too long ago that I worked on this to provide real feedback. Just one comment: Your commit description sounds like there's a problem in drivers like brcmfmac. Wouldn't it be better then to first fix these drivers?
While this may be true, I think the proposed change is better than the device/command specific work around we had so far.
Quoted 4 lines
Quoted 4 lines
Some minor style fixes.
Signed-off-by Dmitry Lebed <[email protected]>
Thx.
Quoted 63 lines
Quoted 63 lines
--- drivers/mmc/host/meson-gx-mmc.c | 37 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-)drivers/mmc/host/meson-gx-mmc.c +22
-15@@ -227,7 +227,6 @@ static void meson_mmc_get_transfer_mode(struct mmc_host *mmc,struct mmc_data *data = mrq->data;struct scatterlist *sg;int i; -bool use_desc_chain_mode = true;/* * When Controller DMA cannot directly access DDR memory, disable @@ -237,25 +236,33 @@ static void meson_mmc_get_transfer_mode(struct mmc_host *mmc,if (host->dram_access_quirk)return ; -/* -* Broken SDIO with AP6255-based WiFi on Khadas VIM Pro has been -* reported. For some strange reason this occurs in descriptor -* chain mode only. So let's fall back to bounce buffer mode -* for command SD_IO_RW_EXTENDED. -*/ -if (mrq->cmd->opcode ==SD_IO_RW_EXTENDED ) -return ; +if (data->blocks >1 ) { +/* +* In block mode DMA descriptor format, "length" field indicates +* number of blocks and there is no way to pass DMA size that +* is not multiple of SDIO block size, making it impossible to +* tie more than one memory buffer with single SDIO block. +* Block mode sg buffer size should be aligned with SDIO block +* size, otherwise chain mode could not be used. +*/ +for_each_sg (data->sg, sg, data->sg_len, i) { +if (sg->length % data->blksz) { +WARN_ONCE (1 ,"unaligned sg len %u blksize %u\n" , + sg->length, data->blksz); +return ; + } + } + } -for_each_sg (data->sg, sg, data->sg_len, i) +for_each_sg (data->sg, sg, data->sg_len, i) {/* check for 8 byte alignment */ -if (sg->offset &7 ) { +if (sg->offset %8 ) {WARN_ONCE (1 ,"unaligned scatterlist buffer\n" ); - use_desc_chain_mode = false; -break ; +return ; } + } -if (use_desc_chain_mode) - data->host_cookie |=SD_EMMC_DESC_CHAIN_MODE ; + data->host_cookie |=SD_EMMC_DESC_CHAIN_MODE ; }
Quoted 8 lines
drivers/mmc/host/meson-gx-mmc.c static void meson_mmc_get_transfer_mode(struct mmc_host *mmc, · line 268
Quoted 2 lines
drivers/mmc/host/meson-gx-mmc.c +0
-0static inline bool meson_mmc_desc_chain_mode (const struct mmc_data *data)_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Quoted 7 lines · Dmitry Lebed
Enable SGDMA support for
SD_IO_RW_EXTENDEDand add proper check for scatterlist size alignment in block mode.According to documentation, in SDIO block mode meson-gx DMA could only handle buffers with sizes that are multiples of SDIO block size.
Quoted 7 lines
Some SDIO drivers like brcmfmac use scatterlist API, but do not enforce proper scatterlist buffer size alignemnt, this looks like a root cause of non-working CMD53.
Some minor style fixes.
Signed-off-by Dmitry Lebed <[email protected]>
Applied for next, thanks!
Kind regards
Uffe
Quoted 65 lines
--- drivers/mmc/host/meson-gx-mmc.c | 37 ++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-)drivers/mmc/host/meson-gx-mmc.c +22
-16@@ -227,7 +227,6 @@ static void meson_mmc_get_transfer_mode(struct mmc_host *mmc,struct mmc_data *data = mrq->data;struct scatterlist *sg;int i; -bool use_desc_chain_mode = true;/* * When Controller DMA cannot directly access DDR memory, disable @@ -237,25 +236,33 @@ static void meson_mmc_get_transfer_mode(struct mmc_host *mmc,if (host->dram_access_quirk)return ; -/* -* Broken SDIO with AP6255-based WiFi on Khadas VIM Pro has been -* reported. For some strange reason this occurs in descriptor -* chain mode only. So let's fall back to bounce buffer mode -* for command SD_IO_RW_EXTENDED. -*/ -if (mrq->cmd->opcode ==SD_IO_RW_EXTENDED ) -return ; +if (data->blocks >1 ) { +/* +* In block mode DMA descriptor format, "length" field indicates +* number of blocks and there is no way to pass DMA size that +* is not multiple of SDIO block size, making it impossible to +* tie more than one memory buffer with single SDIO block. +* Block mode sg buffer size should be aligned with SDIO block +* size, otherwise chain mode could not be used. +*/ +for_each_sg (data->sg, sg, data->sg_len, i) { +if (sg->length % data->blksz) { +WARN_ONCE (1 ,"unaligned sg len %u blksize %u\n" , + sg->length, data->blksz); +return ; + } + } + } -for_each_sg (data->sg, sg, data->sg_len, i) +for_each_sg (data->sg, sg, data->sg_len, i) {/* check for 8 byte alignment */ -if (sg->offset &7 ) { +if (sg->offset %8 ) {WARN_ONCE (1 ,"unaligned scatterlist buffer\n" ); - use_desc_chain_mode = false; -break ; +return ; } + } -if (use_desc_chain_mode) - data->host_cookie |=SD_EMMC_DESC_CHAIN_MODE ; + data->host_cookie |=SD_EMMC_DESC_CHAIN_MODE ; }static inline bool meson_mmc_desc_chain_mode (const struct mmc_data *data) --
Quoted 2 lines
2.24.3 (Apple Git-128)
_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic