From patchwork Wed Sep 11 05:26:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Behme X-Patchwork-Id: 2870291 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 25BC39F485 for ; Wed, 11 Sep 2013 05:27:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2A64C202F0 for ; Wed, 11 Sep 2013 05:27:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2D5E420378 for ; Wed, 11 Sep 2013 05:27:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756436Ab3IKF0x (ORCPT ); Wed, 11 Sep 2013 01:26:53 -0400 Received: from mail-ee0-f52.google.com ([74.125.83.52]:43212 "EHLO mail-ee0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755654Ab3IKF0v (ORCPT ); Wed, 11 Sep 2013 01:26:51 -0400 Received: by mail-ee0-f52.google.com with SMTP id c41so4271849eek.25 for ; Tue, 10 Sep 2013 22:26:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=uyirElLAJHGU/5B0wdcecArAqPyyLqaj3kC8Vn5HriY=; b=OcBGV+GYQnX6zDMlWWfzylSkQzNY+fhYNqi5e7wnWkmxXDRD2psmn/TsX9rRIYQs7V 1IsEalMXfdJq6nRTn6EqGbaZqtRwLyvUUFxBfKzaoWO0GdHTXFy6bY+ifBM9xwB7++FN qUezAgpxO+II/s/EQPZp5b/reSzUVPcGb2PfRhIkK9M56Oywcqb6iP6Lue72wKHjXKB4 TW+rBaGR5UQPNb7m7em+OVZ9mRQw16QKiG4waM76IQvmMCdMBIP/7csvZSk0Yg7j1LIZ /8sn8fdCqGY2RvtrcAqY9UkEXEe7vHTk7b7DQZy3hIQvj88N4g1mvY2QE4bQKzvz/owD BPug== X-Received: by 10.14.98.137 with SMTP id v9mr290084eef.62.1378877210661; Tue, 10 Sep 2013 22:26:50 -0700 (PDT) Received: from localhost.localdomain (p4FEE14C2.dip0.t-ipconnect.de. [79.238.20.194]) by mx.google.com with ESMTPSA id k7sm37014596eeg.13.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Sep 2013 22:26:50 -0700 (PDT) From: Dirk Behme To: linux-mmc@vger.kernel.org Cc: Chris Ball , Dirk Behme Subject: [RFC PATCH] mmc: core: Update ext_csd if touched by ioctl Date: Wed, 11 Sep 2013 07:26:46 +0200 Message-Id: <1378877206-3376-1-git-send-email-dirk.behme@gmail.com> X-Mailer: git-send-email 1.7.10.4 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In case an ioctl changes an EXT_CSD register, update the internal ext_csd data structure, too. Else the driver's internal ext_csd data structure and the EXT_CSD register content doesn't match any more. In this case additional ioctls changing the ext_csd would revert the initial one due to the old data in the driver's internal ext_csd data. E.g. using the mmc utils utility to enable the bootpart mmc bootpart enable 1 0 /dev/mmcblk1 correctly writes to the EXT_CSD structure of the device, but doesn't update card->ext_csd.part_config Issuing additional MMC_SWITCH commands afterwards use the then (wrong) card->ext_csd.part_config. Resulting in an undo of the initial mmc bootpart enable. Fix this by updating the ext_csd in case of an EXT_CSD update ioctl. Signed-off-by: Dirk Behme --- Notes: This fixes the issue discussed in http://marc.info/?l=linux-mmc&m=137820629730918 This patch is marked as RFC due to two reasons: * exporting mmc_update_ext_csd() in core/mmc.c and calling it directly from card/block.c * It seems it's not allowed to call mmc_part_add() in mmc_read_ext_csd() several times. So this is disabled by passing an 'update' variable to mmc_read_ext_csd() disabling the mmc_part_add() in case we just want to update the ext_csd variables. How can this be done better/cleaner? drivers/mmc/card/block.c | 14 ++++++++++++++ drivers/mmc/core/mmc.c | 26 ++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index 1a3163f..0a4bd62 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -132,6 +132,8 @@ enum { module_param(perdev_minors, int, 0444); MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device"); +int mmc_update_ext_csd(struct mmc_card *card); + static inline int mmc_blk_part_switch(struct mmc_card *card, struct mmc_blk_data *md); static int get_card_status(struct mmc_card *card, u32 *status, int retries); @@ -600,6 +602,18 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev, __func__, status, err); } + if ((cmd.opcode == MMC_SWITCH) && ((cmd.arg >> 24) & 0x3)) { + /* + * In case the IOCTL has modified the EXT_CSD, + * update it, i.e. re-read the EXT_CSD. + */ + err = mmc_update_ext_csd(card); + if (err) + dev_err(mmc_dev(card->host), + "%s: EXT_CSD update failed, error %d\n", + __func__, err); + } + cmd_rel_host: mmc_put_card(card); diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 6d02012..5db9d8c 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -269,7 +269,7 @@ static void mmc_select_card_type(struct mmc_card *card) /* * Decode extended CSD. */ -static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) +static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd, int update) { int err = 0, idx; unsigned int part_size; @@ -348,7 +348,8 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) * There are two boot regions of equal size, defined in * multiples of 128K. */ - if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { + if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host) && + !update) { for (idx = 0; idx < MMC_NUM_BOOT_PARTITION; idx++) { part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; mmc_part_add(card, part_size, @@ -519,7 +520,8 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) * RPMB regions are defined in multiples of 128K. */ card->ext_csd.raw_rpmb_size_mult = ext_csd[EXT_CSD_RPMB_MULT]; - if (ext_csd[EXT_CSD_RPMB_MULT] && mmc_host_cmd23(card->host)) { + if (ext_csd[EXT_CSD_RPMB_MULT] && mmc_host_cmd23(card->host) && + !update) { mmc_part_add(card, ext_csd[EXT_CSD_RPMB_MULT] << 17, EXT_CSD_PART_CONFIG_ACC_RPMB, "rpmb", 0, false, @@ -983,7 +985,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, err = mmc_get_ext_csd(card, &ext_csd); if (err) goto free_card; - err = mmc_read_ext_csd(card, ext_csd); + err = mmc_read_ext_csd(card, ext_csd, 0); if (err) goto free_card; @@ -1634,6 +1636,22 @@ static void mmc_attach_bus_ops(struct mmc_host *host) mmc_attach_bus(host, bus_ops); } +int mmc_update_ext_csd(struct mmc_card *card) +{ + u8 *new_ext_csd; + int err; + + err = mmc_get_ext_csd(card, &new_ext_csd); + if (err || new_ext_csd == NULL) + goto out; + + err = mmc_read_ext_csd(card, new_ext_csd, 1); + +out: + mmc_free_ext_csd(new_ext_csd); + return err; +} + /* * Starting point for MMC card init. */