All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrei Warkentin <andreiw@motorola.com>
To: linux-mmc@vger.kernel.org
Cc: Andrei Warkentin <andreiw@motorola.com>
Subject: [[RFC] 2/5] MMC: Add block quirks support.
Date: Fri,  4 Mar 2011 21:21:11 -0600	[thread overview]
Message-ID: <1299295274-32130-3-git-send-email-andreiw@motorola.com> (raw)
In-Reply-To: <1299295274-32130-2-git-send-email-andreiw@motorola.com>

Quirks are card-specific workarounds. Usually they involve
tuning mmcblk parameters at mmc_blk_probe time.

Signed-off-by: Andrei Warkentin <andreiw@motorola.com>
---
 drivers/mmc/card/Kconfig        |    7 ++++
 drivers/mmc/card/Makefile       |    1 +
 drivers/mmc/card/blk.h          |   70 +++++++++++++++++++++++++++++++++++++++
 drivers/mmc/card/block-quirks.c |   51 ++++++++++++++++++++++++++++
 drivers/mmc/card/block.c        |   22 ++++--------
 5 files changed, 137 insertions(+), 14 deletions(-)
 create mode 100644 drivers/mmc/card/blk.h
 create mode 100644 drivers/mmc/card/block-quirks.c

diff --git a/drivers/mmc/card/Kconfig b/drivers/mmc/card/Kconfig
index 86948f9..063fa16 100644
--- a/drivers/mmc/card/Kconfig
+++ b/drivers/mmc/card/Kconfig
@@ -14,6 +14,13 @@ config MMC_BLOCK
 	  mount the filesystem. Almost everyone wishing MMC support
 	  should say Y or M here.
 
+config MMC_BLOCK_QUIRKS
+       tristate "MMC block device quirks"
+       depends on MMC_BLOCK
+       default y
+       help
+         Say Y here to enable various workarounds for known cards.
+
 config MMC_BLOCK_BOUNCE
 	bool "Use bounce buffer for simple hosts"
 	depends on MMC_BLOCK
diff --git a/drivers/mmc/card/Makefile b/drivers/mmc/card/Makefile
index 0d40751..fcd3f45 100644
--- a/drivers/mmc/card/Makefile
+++ b/drivers/mmc/card/Makefile
@@ -7,6 +7,7 @@ ifeq ($(CONFIG_MMC_DEBUG),y)
 endif
 
 obj-$(CONFIG_MMC_BLOCK)		+= mmc_block.o
+obj-$(CONFIG_MMC_BLOCK_QUIRKS)  += block-quirks.o
 mmc_block-objs			:= block.o queue.o
 obj-$(CONFIG_MMC_TEST)		+= mmc_test.o
 
diff --git a/drivers/mmc/card/blk.h b/drivers/mmc/card/blk.h
new file mode 100644
index 0000000..3e7b8e6
--- /dev/null
+++ b/drivers/mmc/card/blk.h
@@ -0,0 +1,70 @@
+#ifndef MMC_BLK_H
+#define MMC_BLK_H
+
+struct gendisk;
+
+#ifdef CONFIG_MMC_BLOCK_QUIRKS
+struct mmc_blk_data;
+
+#define mmc_blk_qrev(hwrev, fwrev, year, month) \
+	(((u64) hwrev) << 40 |                  \
+	 ((u64) fwrev) << 32 |                  \
+	 ((u64) year) << 16 |                   \
+	 ((u64) month))
+
+#define mmc_blk_qrev_card(card)       \
+	mmc_blk_qrev(card->cid.hwrev, \
+		     card->cid.fwrev, \
+		     card->cid.year,  \
+		     card->cid.month)
+
+#define MMC_BLK_QUIRK_VERSION(_name, _manfid, _oemid, _rev_start, _rev_end, _probe) \
+	{							\
+		.name = (_name),				\
+		.manfid = (_manfid),				\
+		.oemid = (_oemid),				\
+		.rev_start = (_rev_start),			\
+		.rev_end = (_rev_end),				\
+		.probe = (_probe),				\
+	}
+
+#define MMC_BLK_QUIRK(_name, _manfid, _oemid, _probe) \
+	MMC_BLK_QUIRK_VERSION(_name, _manfid, _oemid, 0, -1ull, _probe)
+
+extern struct mmc_blk_quirk *mmc_blk_quirk_find(struct mmc_card *card);
+#else
+static inline struct mmc_blk_quirk *mmc_blk_quirk_find(struct mmc_card *card)
+{
+	return NULL;
+}
+#endif /* CONFIG_MMC_BLOCK_QUIRKS */
+
+struct mmc_blk_quirk {
+	const char *name;
+
+	/* First valid revision */
+	u64 rev_start;
+
+	/* Last valid revision */
+	u64 rev_end;
+
+	unsigned int manfid;
+	unsigned short oemid;
+	int (*probe)(struct mmc_blk_data *, struct mmc_card *);
+};
+
+/*
+ * There is one mmc_blk_data per slot.
+ */
+struct mmc_blk_data {
+	spinlock_t	lock;
+	struct gendisk	*disk;
+	struct mmc_queue queue;
+
+	unsigned int	usage;
+	unsigned int	read_only;
+	unsigned int	write_align_size;
+	unsigned int	write_align_limit;
+};
+
+#endif
diff --git a/drivers/mmc/card/block-quirks.c b/drivers/mmc/card/block-quirks.c
new file mode 100644
index 0000000..e122a74
--- /dev/null
+++ b/drivers/mmc/card/block-quirks.c
@@ -0,0 +1,51 @@
+/*
+ * linux/drivers/mmc/card/block-quirks.c
+ *
+ * Copyright (C) 2010 Andrei Warkentin <andreiw@motorola.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#include <linux/kernel.h>
+#include <linux/semaphore.h>
+#include <linux/mmc/card.h>
+
+#include "queue.h"
+#include "blk.h"
+
+/*
+   Caveat: Because this list is just looked up with a linear
+   search, take care that either overlapping revision ranges
+   don't exist, or that returning the first quirk that matches
+   a given revision has the desired effect.
+*/
+struct mmc_blk_quirk mmc_blk_quirks[] = {
+};
+
+static int mmc_blk_quirk_cmp(const struct mmc_blk_quirk *quirk,
+			      const struct mmc_card *card)
+{
+	u64 rev = mmc_blk_qrev_card(card);
+
+	if (quirk->manfid == card->cid.manfid &&
+	    quirk->oemid == card->cid.oemid &&
+	    !strcmp(quirk->name, card->cid.prod_name) &&
+	    rev >= quirk->rev_start &&
+	    rev <= quirk->rev_end)
+		return 0;
+
+	return -1;
+}
+
+struct mmc_blk_quirk *mmc_blk_quirk_find(struct mmc_card *card)
+{
+	unsigned index;
+
+	for (index = 0; index < ARRAY_SIZE(mmc_blk_quirks); index++)
+		if (!mmc_blk_quirk_cmp(&mmc_blk_quirks[index], card))
+			return &mmc_blk_quirks[index];
+
+	return NULL;
+}
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 9d44480..8640902 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -42,6 +42,7 @@
 #include <asm/uaccess.h>
 
 #include "queue.h"
+#include "blk.h"
 
 MODULE_ALIAS("mmc:block");
 
@@ -53,20 +54,6 @@ MODULE_ALIAS("mmc:block");
 
 static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS);
 
-/*
- * There is one mmc_blk_data per slot.
- */
-struct mmc_blk_data {
-	spinlock_t	lock;
-	struct gendisk	*disk;
-	struct mmc_queue queue;
-
-	unsigned int	usage;
-	unsigned int	read_only;
-	unsigned int	write_align_size;
-	unsigned int	write_align_limit;
-};
-
 static DEFINE_MUTEX(open_lock);
 
 static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
@@ -732,6 +719,7 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
 static int mmc_blk_probe(struct mmc_card *card)
 {
 	struct mmc_blk_data *md;
+	struct mmc_blk_quirk *quirk;
 	int err;
 
 	char cap_str[10];
@@ -750,6 +738,12 @@ static int mmc_blk_probe(struct mmc_card *card)
 	if (err)
 		goto out;
 
+	quirk = mmc_blk_quirk_find(card);
+	if (quirk && quirk->probe)
+		err = quirk->probe(md, card);
+	if (err)
+		goto out;
+
 	string_get_size((u64)get_capacity(md->disk) << 9, STRING_UNITS_2,
 			cap_str, sizeof(cap_str));
 	printk(KERN_INFO "%s: %s %s %s %s\n",
-- 
1.7.0.4


  reply	other threads:[~2011-03-05  2:37 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-01 22:09 MMC block quirk support + Toshiba performance quirk Andrei Warkentin
2011-03-01 22:09 ` [RFC 1/3] MMC: Adjust unaligned write accesses Andrei Warkentin
2011-03-01 22:09 ` [RFC 2/3] MMC: Add block quirks support Andrei Warkentin
2011-03-02 17:19   ` Arnd Bergmann
2011-03-02 20:48     ` Andrei Warkentin
2011-03-02 21:04       ` Arnd Bergmann
2011-03-02 21:19         ` Andrei Warkentin
2011-03-01 22:09 ` [RFC 3/3] MMC: Toshiba eMMC - Split 8K-unaligned accesses Andrei Warkentin
2011-03-05  3:21 ` MMC block quirk support + Toshiba quirks Andrei Warkentin
2011-03-05  3:21   ` [[RFC] 1/5] MMC: Adjust unaligned write accesses Andrei Warkentin
2011-03-05  3:21     ` Andrei Warkentin [this message]
2011-03-05  3:21       ` [[RFC] 3/5] MMC: Toshiba eMMC - Split 8K-unaligned accesses Andrei Warkentin
2011-03-05  3:21         ` [[RFC] 4/5] MMC: Block quirks request adjust support Andrei Warkentin
2011-03-05  3:21           ` [[RFC] 5/5] MMC: Toshiba eMMC - Part reliability improvement Andrei Warkentin
2011-03-06 12:28       ` [[RFC] 2/5] MMC: Add block quirks support Linus Walleij
2011-03-06 21:20         ` Linus Walleij
2011-03-07  8:16           ` Andrei Warkentin
2011-03-07 20:39             ` Andrei Warkentin
2011-03-07 20:51               ` Andrei Warkentin
2011-03-08 20:28                 ` Linus Walleij
2011-03-08 20:34                   ` Andrei Warkentin
2011-03-08 20:57                     ` Andrei Warkentin
2011-03-08 10:37               ` Tardy, Pierre
2011-03-08 16:21               ` Arnd Bergmann
     [not found]               ` <201103081542.46831.arnd@arndb.de>
2011-03-08 20:27                 ` Andrei Warkentin
2011-03-13 13:48 ` MMC " Andrei Warkentin
2011-03-13 13:48 ` [PATCH 1/2] MMC: Extends card quicks with MMC/SD quirks matching the CID Andrei Warkentin
2011-03-13 14:55   ` Arnd Bergmann
2011-04-11 20:55   ` Chris Ball
2011-04-11 21:25     ` Andrei Warkentin
2011-04-11 22:02     ` [PATCH] " Andrei Warkentin
2011-04-11 21:50       ` Chris Ball
2011-04-11 21:47         ` Andrei Warkentin
2011-03-13 13:48 ` [PATCH 2/2] MMC: Support for block quirks Andrei Warkentin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1299295274-32130-3-git-send-email-andreiw@motorola.com \
    --to=andreiw@motorola.com \
    --cc=linux-mmc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.