linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch 1/5] [RFC] Add MMC password protection (lock/unlock) support
@ 2005-12-14 13:30 Anderson Briglia
  2005-12-14 14:29 ` Russell King
  2005-12-15 13:28 ` Russell King
  0 siblings, 2 replies; 3+ messages in thread
From: Anderson Briglia @ 2005-12-14 13:30 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2 bytes --]



[-- Attachment #2: mmc_ignore_locked.diff --]
[-- Type: text/x-patch, Size: 4301 bytes --]

When a card is locked, only commands from the "basic" and "lock card" classes
are accepted. To be able to use the other commands, the card must be unlocked
first.

This patch prevents the block driver from trying to run privileged class
commands on locked MMC cards, which will fail anyway.

Signed-off-by: Anderson Briglia <anderson.briglia@indt.org.br>
Signed-off-by: Anderson Lizardo <anderson.lizardo@indt.org.br>
Signed-off-by: Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br>
Signed-off-by: David Brownell <david-b@pacbell.net>

Index: linux-2.6.14-omap2/drivers/mmc/mmc.c
===================================================================
--- linux-2.6.14-omap2.orig/drivers/mmc/mmc.c	2005-12-12 08:45:47.000000000 -0400
+++ linux-2.6.14-omap2/drivers/mmc/mmc.c	2005-12-12 08:47:04.000000000 -0400
@@ -986,10 +986,15 @@ static void mmc_check_cards(struct mmc_h
 		cmd.flags = MMC_RSP_R1;
 
 		err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
-		if (err == MMC_ERR_NONE)
+		if (err != MMC_ERR_NONE) {
+			mmc_card_set_dead(card);
 			continue;
+		}
 
-		mmc_card_set_dead(card);
+		if (cmd.resp[0] & R1_CARD_IS_LOCKED)
+			mmc_card_set_locked(card);
+		else
+			card->state &= ~MMC_STATE_LOCKED;
 	}
 }
 
Index: linux-2.6.14-omap2/drivers/mmc/mmc_sysfs.c
===================================================================
--- linux-2.6.14-omap2.orig/drivers/mmc/mmc_sysfs.c	2005-12-12 08:45:47.000000000 -0400
+++ linux-2.6.14-omap2/drivers/mmc/mmc_sysfs.c	2005-12-12 08:50:20.000000000 -0400
@@ -16,6 +16,7 @@
 
 #include <linux/mmc/card.h>
 #include <linux/mmc/host.h>
+#include <linux/mmc/protocol.h>
 
 #include "mmc.h"
 
@@ -69,13 +70,22 @@ static void mmc_release_card(struct devi
 }
 
 /*
- * This currently matches any MMC driver to any MMC card - drivers
- * themselves make the decision whether to drive this card in their
- * probe method.  However, we force "bad" cards to fail.
+ * This currently matches any MMC driver to any MMC card - drivers themselves
+ * make the decision whether to drive this card in their probe method. However,
+ * we force "bad" cards to fail.
+ *
+ * We also fail for all locked cards; drivers expect to be able to do block I/O
+ * still on probe(), which is not possible while the card is locked. Device
+ * probing must be triggered sometime later to make the card available to the
+ * block driver.
  */
 static int mmc_bus_match(struct device *dev, struct device_driver *drv)
 {
 	struct mmc_card *card = dev_to_mmc_card(dev);
+	if (mmc_card_lockable(card) && mmc_card_locked(card)) {
+		dev_dbg(&card->dev, "card is locked; binding is deferred\n");
+		return 0;
+	}
 	return !mmc_card_bad(card);
 }
 
Index: linux-2.6.14-omap2/include/linux/mmc/card.h
===================================================================
--- linux-2.6.14-omap2.orig/include/linux/mmc/card.h	2005-12-12 08:45:47.000000000 -0400
+++ linux-2.6.14-omap2/include/linux/mmc/card.h	2005-12-12 08:47:04.000000000 -0400
@@ -56,6 +56,7 @@ struct mmc_card {
 #define MMC_STATE_BAD		(1<<2)		/* unrecognised device */
 #define MMC_STATE_SDCARD	(1<<3)		/* is an SD card */
 #define MMC_STATE_READONLY	(1<<4)		/* card is read-only */
+#define MMC_STATE_LOCKED	(1<<5)		/* card is currently locked */
 	u32			raw_cid[4];	/* raw card CID */
 	u32			raw_csd[4];	/* raw card CSD */
 	u32			raw_scr[2];	/* raw card SCR */
@@ -69,12 +70,16 @@ struct mmc_card {
 #define mmc_card_bad(c)		((c)->state & MMC_STATE_BAD)
 #define mmc_card_sd(c)		((c)->state & MMC_STATE_SDCARD)
 #define mmc_card_readonly(c)	((c)->state & MMC_STATE_READONLY)
+#define mmc_card_locked(c)	((c)->state & MMC_STATE_LOCKED)
+
+#define mmc_card_lockable(c)	((c)->csd.cmdclass & CCC_LOCK_CARD)
 
 #define mmc_card_set_present(c)	((c)->state |= MMC_STATE_PRESENT)
 #define mmc_card_set_dead(c)	((c)->state |= MMC_STATE_DEAD)
 #define mmc_card_set_bad(c)	((c)->state |= MMC_STATE_BAD)
 #define mmc_card_set_sd(c)	((c)->state |= MMC_STATE_SDCARD)
 #define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
+#define mmc_card_set_locked(c)	((c)->state |= MMC_STATE_LOCKED)
 
 #define mmc_card_name(c)	((c)->cid.prod_name)
 #define mmc_card_id(c)		((c)->dev.bus_id)

--
Anderson Briglia,
Anderson Lizardo,
Carlos Eduardo Aguiar

Embedded Linux Lab - 10LE
Nokia Institute of Technology - INdT
Manaus - Brazil



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch 1/5] [RFC] Add MMC password protection (lock/unlock) support
  2005-12-14 13:30 [patch 1/5] [RFC] Add MMC password protection (lock/unlock) support Anderson Briglia
@ 2005-12-14 14:29 ` Russell King
  2005-12-15 13:28 ` Russell King
  1 sibling, 0 replies; 3+ messages in thread
From: Russell King @ 2005-12-14 14:29 UTC (permalink / raw)
  To: Anderson Briglia; +Cc: linux-kernel

On Wed, Dec 14, 2005 at 09:30:49AM -0400, Anderson Briglia wrote:
>  /*
> - * This currently matches any MMC driver to any MMC card - drivers
> - * themselves make the decision whether to drive this card in their
> - * probe method.  However, we force "bad" cards to fail.
> + * This currently matches any MMC driver to any MMC card - drivers themselves
> + * make the decision whether to drive this card in their probe method. However,
> + * we force "bad" cards to fail.
> + *
> + * We also fail for all locked cards; drivers expect to be able to do block I/O
> + * still on probe(), which is not possible while the card is locked. Device
> + * probing must be triggered sometime later to make the card available to the
> + * block driver.
>   */

Please arrange comments to wrap _before_ the last column, as per the
original.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch 1/5] [RFC] Add MMC password protection (lock/unlock) support
  2005-12-14 13:30 [patch 1/5] [RFC] Add MMC password protection (lock/unlock) support Anderson Briglia
  2005-12-14 14:29 ` Russell King
@ 2005-12-15 13:28 ` Russell King
  1 sibling, 0 replies; 3+ messages in thread
From: Russell King @ 2005-12-15 13:28 UTC (permalink / raw)
  To: Anderson Briglia; +Cc: linux-kernel

On Wed, Dec 14, 2005 at 09:30:49AM -0400, Anderson Briglia wrote:
> @@ -69,12 +70,16 @@ struct mmc_card {
>  #define mmc_card_bad(c)		((c)->state & MMC_STATE_BAD)
>  #define mmc_card_sd(c)		((c)->state & MMC_STATE_SDCARD)
>  #define mmc_card_readonly(c)	((c)->state & MMC_STATE_READONLY)
> +#define mmc_card_locked(c)	((c)->state & MMC_STATE_LOCKED)
> +
> +#define mmc_card_lockable(c)	((c)->csd.cmdclass & CCC_LOCK_CARD)

Looking at some of the MMC specs, this is not sufficient to tell whether
the card supports the lock/unlock commands - eg, the Sandisk cards have
a CCC value of 0x1ff but do not appear to support CMD42.

It would appear that there are different definitions for command
classes 6 to 8:

command group:		A				B
6			write write-protection		write protection
7			read write-protection		lock card
8			erase write-protection		app. specific

What the interpretation of whether A or B applies is unclear.
Type A cards have CSD structure 1 and MMC protocol version code 1.
Type B cards have CSD structure 2 and MMC protocol version code 3.

It would appear that the "CSD structure" field describes the version
of the CSD structure itself, and in part determines the validity
of the MMC protocol version field (maybe defining the mapping of
version codes to MMC spec versions).  Sandisk implies that CSD
structure 1 has version codes 0=v1.0-v1.2, 1=v1.4.

CSD structure 2 we have less idea about the interpretation of the
MMC protocol version codes, except that 3 may mean MMC spec v3.1.

-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-12-15 13:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-14 13:30 [patch 1/5] [RFC] Add MMC password protection (lock/unlock) support Anderson Briglia
2005-12-14 14:29 ` Russell King
2005-12-15 13:28 ` Russell King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).