Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CQE improvements for 6.6 #6591

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions arch/arm/boot/dts/overlays/README
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,14 @@ Params:
non-lite SKU of CM4).
(default "on")

sd_cqe Set to "off" to disable Command Queueing if you
have an incompatible Class A2 SD card
(Pi 5 only, default "on")
sd_cqe Modify Command Queuing behaviour on the main SD
interface. Legal values are:
0: disable CQ
1: allow CQ for known-good SD A2 cards, and all
eMMC cards
2: allow CQ for all SD A2 cards that aren't
known-bad, and all eMMC cards.
(2712 only, default "1")

sd_overclock Clock (in MHz) to use when the MMC framework
requests 50MHz
Expand Down
4 changes: 2 additions & 2 deletions arch/arm64/boot/dts/broadcom/bcm2712-rpi-5-b.dts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ dpi_16bit_gpio2: &rp1_dpi_16bit_gpio2 { };
sd-uhs-sdr50;
sd-uhs-ddr50;
sd-uhs-sdr104;
supports-cqe;
supports-cqe = <1>;
cd-gpios = <&gio_aon 5 GPIO_ACTIVE_LOW>;
//no-1-8-v;
status = "okay";
Expand Down Expand Up @@ -745,6 +745,6 @@ spi10_cs_pins: &spi10_cs_gpio1 {};

/ {
__overrides__ {
sd_cqe = <&sdio1>, "supports-cqe?";
sd_cqe = <&sdio1>, "supports-cqe:0";
};
};
3 changes: 2 additions & 1 deletion arch/arm64/boot/dts/broadcom/bcm2712-rpi-cm5.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ dpi_16bit_gpio2: &rp1_dpi_16bit_gpio2 { };
mmc-hs400-1_8v;
mmc-hs400-enhanced-strobe;
broken-cd;
supports-cqe;
supports-cqe = <1>;
status = "okay";
};

Expand Down Expand Up @@ -752,5 +752,6 @@ spi10_cs_pins: &spi10_cs_gpio1 {};
<&ant2>, "output-low?=on";
noanthogs = <&ant1>,"status=disabled",
<&ant2>, "status=disabled";
sd_cqe = <&sdio1>, "supports-cqe:0";
};
};
2 changes: 1 addition & 1 deletion arch/arm64/boot/dts/broadcom/bcm2712.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@
clocks = <&clk_emmc2>;
sdhci-caps-mask = <0x0000C000 0x0>;
sdhci-caps = <0x0 0x0>;
supports-cqe;
supports-cqe = <1>;
mmc-ddr-3_3v;
status = "disabled";
};
Expand Down
6 changes: 6 additions & 0 deletions drivers/mmc/core/card.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct mmc_fixup {
#define CID_MANFID_KINGSTON 0x70
#define CID_MANFID_HYNIX 0x90
#define CID_MANFID_KINGSTON_SD 0x9F
#define CID_MANFID_LONGSYS_SD 0xAD
#define CID_MANFID_NUMONYX 0xFE

#define END_FIXUP { NULL }
Expand Down Expand Up @@ -292,4 +293,9 @@ static inline int mmc_card_broken_sd_poweroff_notify(const struct mmc_card *c)
return c->quirks & MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY;
}

static inline int mmc_card_working_sd_cq(const struct mmc_card *c)
{
return c->quirks & MMC_QUIRK_WORKING_SD_CQ;
}

#endif
11 changes: 10 additions & 1 deletion drivers/mmc/core/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ EXPORT_SYMBOL(mmc_of_parse_clk_phase);
int mmc_of_parse(struct mmc_host *host)
{
struct device *dev = host->parent;
u32 bus_width, drv_type, cd_debounce_delay_ms;
u32 bus_width, drv_type, cd_debounce_delay_ms, cq_allow;
int ret;

if (!dev || !dev_fwnode(dev))
Expand Down Expand Up @@ -410,6 +410,15 @@ int mmc_of_parse(struct mmc_host *host)
host->caps2 &= ~(MMC_CAP2_HS400_1_8V | MMC_CAP2_HS400_1_2V |
MMC_CAP2_HS400_ES);

cq_allow = 0;
/*
* Downstream property - if a u32 and 2 instead of a bool,
* trust most A2 SD cards claiming CQ support.
*/
device_property_read_u32(dev, "supports-cqe", &cq_allow);
if (cq_allow == 2)
host->caps2 |= MMC_CAP2_SD_CQE_PERMISSIVE;

/* Must be after "non-removable" check */
if (device_property_read_u32(dev, "fixed-emmc-driver-type", &drv_type) == 0) {
if (host->caps & MMC_CAP_NONREMOVABLE)
Expand Down
6 changes: 6 additions & 0 deletions drivers/mmc/core/quirks.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ static const struct mmc_fixup __maybe_unused mmc_sd_fixups[] = {
MMC_QUIRK_BROKEN_SD_CACHE | MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY,
EXT_CSD_REV_ANY),

/* SD A2 allow-list - only trust CQ on these cards */
/* Raspberry Pi A2 cards */
_FIXUP_EXT(CID_NAME_ANY, CID_MANFID_LONGSYS_SD, 0x4c53, CID_YEAR_ANY, CID_MONTH_ANY,
cid_rev(1, 0, 0, 0), -1ull, SDIO_ANY_ID, SDIO_ANY_ID, add_quirk_sd,
MMC_QUIRK_WORKING_SD_CQ, EXT_CSD_REV_ANY),

END_FIXUP
};

Expand Down
4 changes: 4 additions & 0 deletions drivers/mmc/core/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,10 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
goto free_card;
}

/* Disallow command queueing on unvetted cards unless overridden */
if (!(host->caps2 & MMC_CAP2_SD_CQE_PERMISSIVE) && !mmc_card_working_sd_cq(card))
card->ext_csd.cmdq_support = false;

/* Enable command queueing if supported */
if (card->ext_csd.cmdq_support && host->caps2 & MMC_CAP2_CQE) {
/*
Expand Down
6 changes: 4 additions & 2 deletions drivers/mmc/host/sdhci-brcmstb.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev)
struct sdhci_pltfm_host *pltfm_host;
const struct of_device_id *match;
struct sdhci_brcmstb_priv *priv;
u32 actual_clock_mhz;
u32 actual_clock_mhz, cqe;
struct sdhci_host *host;
struct resource *iomem;
bool no_pinctrl = false;
Expand Down Expand Up @@ -540,7 +540,9 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev)
pltfm_host->clk = clk;

priv = sdhci_pltfm_priv(pltfm_host);
if (device_property_read_bool(&pdev->dev, "supports-cqe")) {
cqe = 0;
device_property_read_u32(&pdev->dev, "supports-cqe", &cqe);
if (cqe > 0) {
priv->flags |= BRCMSTB_PRIV_FLAGS_HAS_CQE;
match_priv->ops->irq = sdhci_brcmstb_cqhci_irq;
}
Expand Down
1 change: 1 addition & 0 deletions include/linux/mmc/card.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ struct mmc_card {
#define MMC_QUIRK_BROKEN_SD_CACHE (1<<15) /* Disable broken SD cache support */
#define MMC_QUIRK_BROKEN_CACHE_FLUSH (1<<16) /* Don't flush cache until the write has occurred */
#define MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY (1<<17) /* Disable broken SD poweroff notify support */
#define MMC_QUIRK_WORKING_SD_CQ (1<<30) /* SD card has known-good CQ implementation */
#define MMC_QUIRK_ERASE_BROKEN (1<<31) /* Skip erase */

bool written_flag; /* Indicates eMMC has been written since power on */
Expand Down
1 change: 1 addition & 0 deletions include/linux/mmc/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
#define MMC_CAP2_CRYPTO 0
#endif
#define MMC_CAP2_ALT_GPT_TEGRA (1 << 28) /* Host with eMMC that has GPT entry at a non-standard location */
#define MMC_CAP2_SD_CQE_PERMISSIVE (1 << 31) /* Ignore allow-list for CQ capable SD card detection */

Check failure on line 430 in include/linux/mmc/host.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 112 exceeds 100 columns

Check failure on line 430 in include/linux/mmc/host.h

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: line length of 112 exceeds 100 columns

int fixed_drv_type; /* fixed driver type for non-removable media */

Expand Down
Loading