Merge tag 'mmc-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 31 Aug 2021 21:31:10 +0000 (14:31 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 31 Aug 2021 21:31:10 +0000 (14:31 -0700)
Pull MMC and MEMSTICK updates from Ulf Hansson:
 "MMC core:
   - Return a proper response in case of an ioctl error
   - Issue HPI to interrupt BKOPS for eMMC if it timed out
   - Avoid hogging the CPU while polling for busy
   - Extend sd8787 pwrseq to support the wilc1000 SDIO
   - Remove a couple of confusing warning messages
   - Clarify comment for ->card_busy() host ops

  MMC host:
   - dw_mmc: Add data CRC error injection
   - mmci: De-assert reset during ->probe()
   - rtsx_pci: Fix long reads when clock is pre-scaled
   - sdhci: Correct the tuning command handle for PIO mode
   - sdhci-esdhc-imx: Improve support for auto tuning
   - sdhci-msm: Add support for the sc7280
   - sdhci-of-arasan: Don't auto tune for DDR50 mode for ZynqMP
   - sdhci-of-arasan: Enable support for auto cmd12
   - sdhci-of-arasan: Use 19MHz for SD default speed for ZynqMP for level shifter
   - usdhi6rol0: Implement the ->card_busy() host ops

  MEMSTICK:
   - A couple of minor cleanups"

* tag 'mmc-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc: (52 commits)
  mmc: queue: Remove unused parameters(request_queue)
  mmc: pwrseq: sd8787: fix compilation warning
  mmc: core: Return correct emmc response in case of ioctl error
  mmc: sdhci-esdhc-imx: Select the correct mode for auto tuning
  mmc: sdhci-esdhc-imx: Remove redundant code for manual tuning
  mmc: core: Issue HPI in case the BKOPS timed out
  mmc: queue: Match the data type of max_segments
  mmc: switch from 'pci_' to 'dma_' API
  memstick: switch from 'pci_' to 'dma_' API
  memstick: r592: Change the name of the 'pci_driver' structure to be consistent
  mmc: pwrseq: add wilc1000_sdio dependency for pwrseq_sd8787
  mmc: pwrseq: sd8787: add support for wilc1000
  dt-bindings: mmc: Extend pwrseq-sd8787 binding for wilc1000
  dt-bindings: mmc: fsl-imx-esdhc: change the pinctrl-names rule
  dt-bindings: mmc: fsl-imx-esdhc: add a new compatible string
  dt-bindings: mmc: renesas,sdhi: Document RZ/G2L bindings
  dt-bindings: mmc: renesas,sdhi: Fix dtbs-check warning
  mmc: core: Update ->card_busy() callback comment
  mmc: usdhi6rol0: Implement card_busy function
  mmc: sdhci: Correct the tuning command handle for PIO mode
  ...

1  2 
drivers/mmc/core/block.c
drivers/mmc/core/core.c
include/linux/mmc/host.h

diff --combined drivers/mmc/core/block.c
@@@ -98,6 -98,11 +98,11 @@@ static int max_devices
  static DEFINE_IDA(mmc_blk_ida);
  static DEFINE_IDA(mmc_rpmb_ida);
  
+ struct mmc_blk_busy_data {
+       struct mmc_card *card;
+       u32 status;
+ };
  /*
   * There is one mmc_blk_data per slot.
   */
@@@ -128,6 -133,8 +133,6 @@@ struct mmc_blk_data 
         * track of the current selected device partition.
         */
        unsigned int    part_curr;
 -      struct device_attribute force_ro;
 -      struct device_attribute power_ro_lock;
        int     area_type;
  
        /* debugfs files (only in main mmc_blk_data) */
@@@ -279,9 -286,6 +284,9 @@@ out_put
        return count;
  }
  
 +static DEVICE_ATTR(ro_lock_until_next_power_on, 0,
 +              power_ro_lock_show, power_ro_lock_store);
 +
  static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr,
                             char *buf)
  {
@@@ -314,44 -318,6 +319,44 @@@ out
        return ret;
  }
  
 +static DEVICE_ATTR(force_ro, 0644, force_ro_show, force_ro_store);
 +
 +static struct attribute *mmc_disk_attrs[] = {
 +      &dev_attr_force_ro.attr,
 +      &dev_attr_ro_lock_until_next_power_on.attr,
 +      NULL,
 +};
 +
 +static umode_t mmc_disk_attrs_is_visible(struct kobject *kobj,
 +              struct attribute *a, int n)
 +{
 +      struct device *dev = container_of(kobj, struct device, kobj);
 +      struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
 +      umode_t mode = a->mode;
 +
 +      if (a == &dev_attr_ro_lock_until_next_power_on.attr &&
 +          (md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
 +          md->queue.card->ext_csd.boot_ro_lockable) {
 +              mode = S_IRUGO;
 +              if (!(md->queue.card->ext_csd.boot_ro_lock &
 +                              EXT_CSD_BOOT_WP_B_PWR_WP_DIS))
 +                      mode |= S_IWUSR;
 +      }
 +
 +      mmc_blk_put(md);
 +      return mode;
 +}
 +
 +static const struct attribute_group mmc_disk_attr_group = {
 +      .is_visible     = mmc_disk_attrs_is_visible,
 +      .attrs          = mmc_disk_attrs,
 +};
 +
 +static const struct attribute_group *mmc_disk_attr_groups[] = {
 +      &mmc_disk_attr_group,
 +      NULL,
 +};
 +
  static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
  {
        struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
@@@ -456,42 -422,6 +461,6 @@@ static int mmc_blk_ioctl_copy_to_user(s
        return 0;
  }
  
- static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
-                           u32 *resp_errs)
- {
-       unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
-       int err = 0;
-       u32 status;
-       do {
-               bool done = time_after(jiffies, timeout);
-               err = __mmc_send_status(card, &status, 5);
-               if (err) {
-                       dev_err(mmc_dev(card->host),
-                               "error %d requesting status\n", err);
-                       return err;
-               }
-               /* Accumulate any response error bits seen */
-               if (resp_errs)
-                       *resp_errs |= status;
-               /*
-                * Timeout if the device never becomes ready for data and never
-                * leaves the program state.
-                */
-               if (done) {
-                       dev_err(mmc_dev(card->host),
-                               "Card stuck in wrong state! %s status: %#x\n",
-                                __func__, status);
-                       return -ETIMEDOUT;
-               }
-       } while (!mmc_ready_for_data(status));
-       return err;
- }
  static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
                               struct mmc_blk_ioc_data *idata)
  {
                return mmc_sanitize(card, idata->ic.cmd_timeout_ms);
  
        mmc_wait_for_req(card->host, &mrq);
+       memcpy(&idata->ic.response, cmd.resp, sizeof(cmd.resp));
  
        if (cmd.error) {
                dev_err(mmc_dev(card->host), "%s: cmd error %d\n",
        if (idata->ic.postsleep_min_us)
                usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
  
-       memcpy(&(idata->ic.response), cmd.resp, sizeof(cmd.resp));
        if (idata->rpmb || (cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B) {
                /*
                 * Ensure RPMB/R1B command has completed by polling CMD13
                 * "Send Status".
                 */
-               err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, NULL);
+               err = mmc_poll_for_busy(card, MMC_BLK_TIMEOUT_MS, false,
+                                       MMC_BUSY_IO);
        }
  
        return err;
@@@ -831,26 -761,6 +800,26 @@@ static int mmc_blk_compat_ioctl(struct 
  }
  #endif
  
 +static int mmc_blk_alternative_gpt_sector(struct gendisk *disk,
 +                                        sector_t *sector)
 +{
 +      struct mmc_blk_data *md;
 +      int ret;
 +
 +      md = mmc_blk_get(disk);
 +      if (!md)
 +              return -EINVAL;
 +
 +      if (md->queue.card)
 +              ret = mmc_card_alternative_gpt_sector(md->queue.card, sector);
 +      else
 +              ret = -ENODEV;
 +
 +      mmc_blk_put(md);
 +
 +      return ret;
 +}
 +
  static const struct block_device_operations mmc_bdops = {
        .open                   = mmc_blk_open,
        .release                = mmc_blk_release,
  #ifdef CONFIG_COMPAT
        .compat_ioctl           = mmc_blk_compat_ioctl,
  #endif
 +      .alternative_gpt_sector = mmc_blk_alternative_gpt_sector,
  };
  
  static int mmc_blk_part_switch_pre(struct mmc_card *card,
@@@ -1696,7 -1605,7 +1665,7 @@@ static int mmc_blk_fix_state(struct mmc
  
        mmc_blk_send_stop(card, timeout);
  
-       err = card_busy_detect(card, timeout, NULL);
+       err = mmc_poll_for_busy(card, timeout, false, MMC_BUSY_IO);
  
        mmc_retune_release(card->host);
  
@@@ -1911,28 -1820,48 +1880,48 @@@ static inline bool mmc_blk_rq_error(str
               brq->data.error || brq->cmd.resp[0] & CMD_ERRORS;
  }
  
+ static int mmc_blk_busy_cb(void *cb_data, bool *busy)
+ {
+       struct mmc_blk_busy_data *data = cb_data;
+       u32 status = 0;
+       int err;
+       err = mmc_send_status(data->card, &status);
+       if (err)
+               return err;
+       /* Accumulate response error bits. */
+       data->status |= status;
+       *busy = !mmc_ready_for_data(status);
+       return 0;
+ }
  static int mmc_blk_card_busy(struct mmc_card *card, struct request *req)
  {
        struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
-       u32 status = 0;
+       struct mmc_blk_busy_data cb_data;
        int err;
  
        if (mmc_host_is_spi(card->host) || rq_data_dir(req) == READ)
                return 0;
  
-       err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, &status);
+       cb_data.card = card;
+       cb_data.status = 0;
+       err = __mmc_poll_for_busy(card, MMC_BLK_TIMEOUT_MS, &mmc_blk_busy_cb,
+                                 &cb_data);
  
        /*
         * Do not assume data transferred correctly if there are any error bits
         * set.
         */
-       if (status & mmc_blk_stop_err_bits(&mqrq->brq)) {
+       if (cb_data.status & mmc_blk_stop_err_bits(&mqrq->brq)) {
                mqrq->brq.data.bytes_xfered = 0;
                err = err ? err : -EIO;
        }
  
        /* Copy the exception bit so it will be seen later on */
-       if (mmc_card_mmc(card) && status & R1_EXCEPTION_EVENT)
+       if (mmc_card_mmc(card) && cb_data.status & R1_EXCEPTION_EVENT)
                mqrq->brq.cmd.resp[0] |= R1_EXCEPTION_EVENT;
  
        return err;
@@@ -2349,8 -2278,7 +2338,8 @@@ static struct mmc_blk_data *mmc_blk_all
                                              sector_t size,
                                              bool default_ro,
                                              const char *subname,
 -                                            int area_type)
 +                                            int area_type,
 +                                            unsigned int part_type)
  {
        struct mmc_blk_data *md;
        int devidx, ret;
        kref_init(&md->kref);
  
        md->queue.blkdata = md;
 +      md->part_type = part_type;
  
        md->disk->major = MMC_BLOCK_MAJOR;
        md->disk->minors = perdev_minors;
                md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
                cap_str, md->read_only ? "(ro)" : "");
  
 +      /* used in ->open, must be set before add_disk: */
 +      if (area_type == MMC_BLK_DATA_AREA_MAIN)
 +              dev_set_drvdata(&card->dev, md);
 +      device_add_disk(md->parent, md->disk, mmc_disk_attr_groups);
        return md;
  
   err_kfree:
@@@ -2483,7 -2406,7 +2472,7 @@@ static struct mmc_blk_data *mmc_blk_all
        }
  
        return mmc_blk_alloc_req(card, &card->dev, size, false, NULL,
 -                                      MMC_BLK_DATA_AREA_MAIN);
 +                                      MMC_BLK_DATA_AREA_MAIN, 0);
  }
  
  static int mmc_blk_alloc_part(struct mmc_card *card,
        struct mmc_blk_data *part_md;
  
        part_md = mmc_blk_alloc_req(card, disk_to_dev(md->disk), size, default_ro,
 -                                  subname, area_type);
 +                                  subname, area_type, part_type);
        if (IS_ERR(part_md))
                return PTR_ERR(part_md);
 -      part_md->part_type = part_type;
        list_add(&part_md->part, &md->part);
  
        return 0;
@@@ -2700,13 -2624,27 +2689,13 @@@ static int mmc_blk_alloc_parts(struct m
  
  static void mmc_blk_remove_req(struct mmc_blk_data *md)
  {
 -      struct mmc_card *card;
 -
 -      if (md) {
 -              /*
 -               * Flush remaining requests and free queues. It
 -               * is freeing the queue that stops new requests
 -               * from being accepted.
 -               */
 -              card = md->queue.card;
 -              if (md->disk->flags & GENHD_FL_UP) {
 -                      device_remove_file(disk_to_dev(md->disk), &md->force_ro);
 -                      if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
 -                                      card->ext_csd.boot_ro_lockable)
 -                              device_remove_file(disk_to_dev(md->disk),
 -                                      &md->power_ro_lock);
 -
 -                      del_gendisk(md->disk);
 -              }
 -              mmc_cleanup_queue(&md->queue);
 -              mmc_blk_put(md);
 -      }
 +      /*
 +       * Flush remaining requests and free queues. It is freeing the queue
 +       * that stops new requests from being accepted.
 +       */
 +      del_gendisk(md->disk);
 +      mmc_cleanup_queue(&md->queue);
 +      mmc_blk_put(md);
  }
  
  static void mmc_blk_remove_parts(struct mmc_card *card,
        }
  }
  
 -static int mmc_add_disk(struct mmc_blk_data *md)
 -{
 -      int ret;
 -      struct mmc_card *card = md->queue.card;
 -
 -      device_add_disk(md->parent, md->disk, NULL);
 -      md->force_ro.show = force_ro_show;
 -      md->force_ro.store = force_ro_store;
 -      sysfs_attr_init(&md->force_ro.attr);
 -      md->force_ro.attr.name = "force_ro";
 -      md->force_ro.attr.mode = S_IRUGO | S_IWUSR;
 -      ret = device_create_file(disk_to_dev(md->disk), &md->force_ro);
 -      if (ret)
 -              goto force_ro_fail;
 -
 -      if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
 -           card->ext_csd.boot_ro_lockable) {
 -              umode_t mode;
 -
 -              if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_DIS)
 -                      mode = S_IRUGO;
 -              else
 -                      mode = S_IRUGO | S_IWUSR;
 -
 -              md->power_ro_lock.show = power_ro_lock_show;
 -              md->power_ro_lock.store = power_ro_lock_store;
 -              sysfs_attr_init(&md->power_ro_lock.attr);
 -              md->power_ro_lock.attr.mode = mode;
 -              md->power_ro_lock.attr.name =
 -                                      "ro_lock_until_next_power_on";
 -              ret = device_create_file(disk_to_dev(md->disk),
 -                              &md->power_ro_lock);
 -              if (ret)
 -                      goto power_ro_lock_fail;
 -      }
 -      return ret;
 -
 -power_ro_lock_fail:
 -      device_remove_file(disk_to_dev(md->disk), &md->force_ro);
 -force_ro_fail:
 -      del_gendisk(md->disk);
 -
 -      return ret;
 -}
 -
  #ifdef CONFIG_DEBUG_FS
  
  static int mmc_dbg_card_status_get(void *data, u64 *val)
@@@ -2895,7 -2878,7 +2884,7 @@@ static void mmc_blk_remove_debugfs(stru
  
  static int mmc_blk_probe(struct mmc_card *card)
  {
 -      struct mmc_blk_data *md, *part_md;
 +      struct mmc_blk_data *md;
        int ret = 0;
  
        /*
        if (ret)
                goto out;
  
 -      dev_set_drvdata(&card->dev, md);
 -
 -      ret = mmc_add_disk(md);
 -      if (ret)
 -              goto out;
 -
 -      list_for_each_entry(part_md, &md->part, part) {
 -              ret = mmc_add_disk(part_md);
 -              if (ret)
 -                      goto out;
 -      }
 -
        /* Add two debugfs entries */
        mmc_blk_add_debugfs(card, md);
  
diff --combined drivers/mmc/core/core.c
@@@ -936,15 -936,16 +936,16 @@@ int mmc_execute_tuning(struct mmc_card 
                opcode = MMC_SEND_TUNING_BLOCK;
  
        err = host->ops->execute_tuning(host, opcode);
+       if (!err) {
+               mmc_retune_clear(host);
+               mmc_retune_enable(host);
+               return 0;
+       }
  
-       if (err) {
+       /* Only print error when we don't check for card removal */
+       if (!host->detect_change)
                pr_err("%s: tuning execution failed: %d\n",
                        mmc_hostname(host), err);
-       } else {
-               host->retune_now = 0;
-               host->need_retune = 0;
-               mmc_retune_enable(host);
-       }
  
        return err;
  }
@@@ -2149,41 -2150,6 +2150,41 @@@ int mmc_detect_card_removed(struct mmc_
  }
  EXPORT_SYMBOL(mmc_detect_card_removed);
  
 +int mmc_card_alternative_gpt_sector(struct mmc_card *card, sector_t *gpt_sector)
 +{
 +      unsigned int boot_sectors_num;
 +
 +      if ((!(card->host->caps2 & MMC_CAP2_ALT_GPT_TEGRA)))
 +              return -EOPNOTSUPP;
 +
 +      /* filter out unrelated cards */
 +      if (card->ext_csd.rev < 3 ||
 +          !mmc_card_mmc(card) ||
 +          !mmc_card_is_blockaddr(card) ||
 +           mmc_card_is_removable(card->host))
 +              return -ENOENT;
 +
 +      /*
 +       * eMMC storage has two special boot partitions in addition to the
 +       * main one.  NVIDIA's bootloader linearizes eMMC boot0->boot1->main
 +       * accesses, this means that the partition table addresses are shifted
 +       * by the size of boot partitions.  In accordance with the eMMC
 +       * specification, the boot partition size is calculated as follows:
 +       *
 +       *      boot partition size = 128K byte x BOOT_SIZE_MULT
 +       *
 +       * Calculate number of sectors occupied by the both boot partitions.
 +       */
 +      boot_sectors_num = card->ext_csd.raw_boot_mult * SZ_128K /
 +                         SZ_512 * MMC_NUM_BOOT_PARTITION;
 +
 +      /* Defined by NVIDIA and used by Android devices. */
 +      *gpt_sector = card->ext_csd.sectors - boot_sectors_num - 1;
 +
 +      return 0;
 +}
 +EXPORT_SYMBOL(mmc_card_alternative_gpt_sector);
 +
  void mmc_rescan(struct work_struct *work)
  {
        struct mmc_host *host =
diff --combined include/linux/mmc/host.h
@@@ -153,7 -153,7 +153,7 @@@ struct mmc_host_ops 
  
        int     (*start_signal_voltage_switch)(struct mmc_host *host, struct mmc_ios *ios);
  
-       /* Check if the card is pulling dat[0:3] low */
+       /* Check if the card is pulling dat[0] low */
        int     (*card_busy)(struct mmc_host *host);
  
        /* The tuning command opcode value is different for SD and eMMC cards */
@@@ -398,7 -398,6 +398,7 @@@ struct mmc_host 
  #else
  #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 */
  
        int                     fixed_drv_type; /* fixed driver type for non-removable media */