LCOV - code coverage report
Current view: top level - drivers/mmc/core - block.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 316 1142 27.7 %
Date: 2020-09-30 20:25:40 Functions: 32 84 38.1 %
Branches: 140 786 17.8 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Block driver for media (i.e., flash cards)
       3                 :            :  *
       4                 :            :  * Copyright 2002 Hewlett-Packard Company
       5                 :            :  * Copyright 2005-2008 Pierre Ossman
       6                 :            :  *
       7                 :            :  * Use consistent with the GNU GPL is permitted,
       8                 :            :  * provided that this copyright notice is
       9                 :            :  * preserved in its entirety in all copies and derived works.
      10                 :            :  *
      11                 :            :  * HEWLETT-PACKARD COMPANY MAKES NO WARRANTIES, EXPRESSED OR IMPLIED,
      12                 :            :  * AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS
      13                 :            :  * FITNESS FOR ANY PARTICULAR PURPOSE.
      14                 :            :  *
      15                 :            :  * Many thanks to Alessandro Rubini and Jonathan Corbet!
      16                 :            :  *
      17                 :            :  * Author:  Andrew Christian
      18                 :            :  *          28 May 2002
      19                 :            :  */
      20                 :            : #include <linux/moduleparam.h>
      21                 :            : #include <linux/module.h>
      22                 :            : #include <linux/init.h>
      23                 :            : 
      24                 :            : #include <linux/kernel.h>
      25                 :            : #include <linux/fs.h>
      26                 :            : #include <linux/slab.h>
      27                 :            : #include <linux/errno.h>
      28                 :            : #include <linux/hdreg.h>
      29                 :            : #include <linux/kdev_t.h>
      30                 :            : #include <linux/blkdev.h>
      31                 :            : #include <linux/cdev.h>
      32                 :            : #include <linux/mutex.h>
      33                 :            : #include <linux/scatterlist.h>
      34                 :            : #include <linux/string_helpers.h>
      35                 :            : #include <linux/delay.h>
      36                 :            : #include <linux/capability.h>
      37                 :            : #include <linux/compat.h>
      38                 :            : #include <linux/pm_runtime.h>
      39                 :            : #include <linux/idr.h>
      40                 :            : #include <linux/debugfs.h>
      41                 :            : 
      42                 :            : #include <linux/mmc/ioctl.h>
      43                 :            : #include <linux/mmc/card.h>
      44                 :            : #include <linux/mmc/host.h>
      45                 :            : #include <linux/mmc/mmc.h>
      46                 :            : #include <linux/mmc/sd.h>
      47                 :            : 
      48                 :            : #include <linux/uaccess.h>
      49                 :            : 
      50                 :            : #include "queue.h"
      51                 :            : #include "block.h"
      52                 :            : #include "core.h"
      53                 :            : #include "card.h"
      54                 :            : #include "host.h"
      55                 :            : #include "bus.h"
      56                 :            : #include "mmc_ops.h"
      57                 :            : #include "quirks.h"
      58                 :            : #include "sd_ops.h"
      59                 :            : 
      60                 :            : MODULE_ALIAS("mmc:block");
      61                 :            : #ifdef MODULE_PARAM_PREFIX
      62                 :            : #undef MODULE_PARAM_PREFIX
      63                 :            : #endif
      64                 :            : #define MODULE_PARAM_PREFIX "mmcblk."
      65                 :            : 
      66                 :            : /*
      67                 :            :  * Set a 10 second timeout for polling write request busy state. Note, mmc core
      68                 :            :  * is setting a 3 second timeout for SD cards, and SDHCI has long had a 10
      69                 :            :  * second software timer to timeout the whole request, so 10 seconds should be
      70                 :            :  * ample.
      71                 :            :  */
      72                 :            : #define MMC_BLK_TIMEOUT_MS  (10 * 1000)
      73                 :            : #define MMC_SANITIZE_REQ_TIMEOUT 240000
      74                 :            : #define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16)
      75                 :            : #define MMC_EXTRACT_VALUE_FROM_ARG(x) ((x & 0x0000FF00) >> 8)
      76                 :            : 
      77                 :            : #define mmc_req_rel_wr(req)     ((req->cmd_flags & REQ_FUA) && \
      78                 :            :                                   (rq_data_dir(req) == WRITE))
      79                 :            : static DEFINE_MUTEX(block_mutex);
      80                 :            : 
      81                 :            : /*
      82                 :            :  * The defaults come from config options but can be overriden by module
      83                 :            :  * or bootarg options.
      84                 :            :  */
      85                 :            : static int perdev_minors = CONFIG_MMC_BLOCK_MINORS;
      86                 :            : 
      87                 :            : /*
      88                 :            :  * We've only got one major, so number of mmcblk devices is
      89                 :            :  * limited to (1 << 20) / number of minors per device.  It is also
      90                 :            :  * limited by the MAX_DEVICES below.
      91                 :            :  */
      92                 :            : static int max_devices;
      93                 :            : 
      94                 :            : #define MAX_DEVICES 256
      95                 :            : 
      96                 :            : static DEFINE_IDA(mmc_blk_ida);
      97                 :            : static DEFINE_IDA(mmc_rpmb_ida);
      98                 :            : 
      99                 :            : /*
     100                 :            :  * There is one mmc_blk_data per slot.
     101                 :            :  */
     102                 :            : struct mmc_blk_data {
     103                 :            :         struct device   *parent;
     104                 :            :         struct gendisk  *disk;
     105                 :            :         struct mmc_queue queue;
     106                 :            :         struct list_head part;
     107                 :            :         struct list_head rpmbs;
     108                 :            : 
     109                 :            :         unsigned int    flags;
     110                 :            : #define MMC_BLK_CMD23   (1 << 0)  /* Can do SET_BLOCK_COUNT for multiblock */
     111                 :            : #define MMC_BLK_REL_WR  (1 << 1)  /* MMC Reliable write support */
     112                 :            : 
     113                 :            :         unsigned int    usage;
     114                 :            :         unsigned int    read_only;
     115                 :            :         unsigned int    part_type;
     116                 :            :         unsigned int    reset_done;
     117                 :            : #define MMC_BLK_READ            BIT(0)
     118                 :            : #define MMC_BLK_WRITE           BIT(1)
     119                 :            : #define MMC_BLK_DISCARD         BIT(2)
     120                 :            : #define MMC_BLK_SECDISCARD      BIT(3)
     121                 :            : #define MMC_BLK_CQE_RECOVERY    BIT(4)
     122                 :            : 
     123                 :            :         /*
     124                 :            :          * Only set in main mmc_blk_data associated
     125                 :            :          * with mmc_card with dev_set_drvdata, and keeps
     126                 :            :          * track of the current selected device partition.
     127                 :            :          */
     128                 :            :         unsigned int    part_curr;
     129                 :            :         struct device_attribute force_ro;
     130                 :            :         struct device_attribute power_ro_lock;
     131                 :            :         int     area_type;
     132                 :            : 
     133                 :            :         /* debugfs files (only in main mmc_blk_data) */
     134                 :            :         struct dentry *status_dentry;
     135                 :            :         struct dentry *ext_csd_dentry;
     136                 :            : };
     137                 :            : 
     138                 :            : /* Device type for RPMB character devices */
     139                 :            : static dev_t mmc_rpmb_devt;
     140                 :            : 
     141                 :            : /* Bus type for RPMB character devices */
     142                 :            : static struct bus_type mmc_rpmb_bus_type = {
     143                 :            :         .name = "mmc_rpmb",
     144                 :            : };
     145                 :            : 
     146                 :            : /**
     147                 :            :  * struct mmc_rpmb_data - special RPMB device type for these areas
     148                 :            :  * @dev: the device for the RPMB area
     149                 :            :  * @chrdev: character device for the RPMB area
     150                 :            :  * @id: unique device ID number
     151                 :            :  * @part_index: partition index (0 on first)
     152                 :            :  * @md: parent MMC block device
     153                 :            :  * @node: list item, so we can put this device on a list
     154                 :            :  */
     155                 :            : struct mmc_rpmb_data {
     156                 :            :         struct device dev;
     157                 :            :         struct cdev chrdev;
     158                 :            :         int id;
     159                 :            :         unsigned int part_index;
     160                 :            :         struct mmc_blk_data *md;
     161                 :            :         struct list_head node;
     162                 :            : };
     163                 :            : 
     164                 :            : static DEFINE_MUTEX(open_lock);
     165                 :            : 
     166                 :            : module_param(perdev_minors, int, 0444);
     167                 :            : MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
     168                 :            : 
     169                 :            : /*
     170                 :            :  * Allow quirks to be overridden for the current card
     171                 :            :  */
     172                 :            : static char *card_quirks;
     173                 :            : module_param(card_quirks, charp, 0644);
     174                 :            : MODULE_PARM_DESC(card_quirks, "Force the use of the indicated quirks (a bitfield)");
     175                 :            : 
     176                 :            : static inline int mmc_blk_part_switch(struct mmc_card *card,
     177                 :            :                                       unsigned int part_type);
     178                 :            : 
     179                 :       4191 : static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
     180                 :            : {
     181                 :            :         struct mmc_blk_data *md;
     182                 :            : 
     183                 :       4191 :         mutex_lock(&open_lock);
     184                 :       4191 :         md = disk->private_data;
     185   [ +  -  -  + ]:       4191 :         if (md && md->usage == 0)
     186                 :            :                 md = NULL;
     187         [ +  - ]:       4191 :         if (md)
     188                 :       4191 :                 md->usage++;
     189                 :       4191 :         mutex_unlock(&open_lock);
     190                 :            : 
     191                 :       4191 :         return md;
     192                 :            : }
     193                 :            : 
     194                 :            : static inline int mmc_get_devidx(struct gendisk *disk)
     195                 :            : {
     196                 :          0 :         int devidx = disk->first_minor / perdev_minors;
     197                 :            :         return devidx;
     198                 :            : }
     199                 :            : 
     200                 :       3777 : static void mmc_blk_put(struct mmc_blk_data *md)
     201                 :            : {
     202                 :       3777 :         mutex_lock(&open_lock);
     203                 :       3777 :         md->usage--;
     204         [ -  + ]:       3777 :         if (md->usage == 0) {
     205                 :          0 :                 int devidx = mmc_get_devidx(md->disk);
     206                 :          0 :                 blk_put_queue(md->queue.queue);
     207                 :          0 :                 ida_simple_remove(&mmc_blk_ida, devidx);
     208                 :          0 :                 put_disk(md->disk);
     209                 :          0 :                 kfree(md);
     210                 :            :         }
     211                 :       3777 :         mutex_unlock(&open_lock);
     212                 :       3777 : }
     213                 :            : 
     214                 :          0 : static ssize_t power_ro_lock_show(struct device *dev,
     215                 :            :                 struct device_attribute *attr, char *buf)
     216                 :            : {
     217                 :            :         int ret;
     218                 :          0 :         struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
     219                 :          0 :         struct mmc_card *card = md->queue.card;
     220                 :            :         int locked = 0;
     221                 :            : 
     222         [ #  # ]:          0 :         if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PERM_WP_EN)
     223                 :            :                 locked = 2;
     224         [ #  # ]:          0 :         else if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_EN)
     225                 :            :                 locked = 1;
     226                 :            : 
     227                 :          0 :         ret = snprintf(buf, PAGE_SIZE, "%d\n", locked);
     228                 :            : 
     229                 :          0 :         mmc_blk_put(md);
     230                 :            : 
     231                 :          0 :         return ret;
     232                 :            : }
     233                 :            : 
     234                 :          0 : static ssize_t power_ro_lock_store(struct device *dev,
     235                 :            :                 struct device_attribute *attr, const char *buf, size_t count)
     236                 :            : {
     237                 :            :         int ret;
     238                 :            :         struct mmc_blk_data *md, *part_md;
     239                 :            :         struct mmc_queue *mq;
     240                 :            :         struct request *req;
     241                 :            :         unsigned long set;
     242                 :            : 
     243         [ #  # ]:          0 :         if (kstrtoul(buf, 0, &set))
     244                 :            :                 return -EINVAL;
     245                 :            : 
     246         [ #  # ]:          0 :         if (set != 1)
     247                 :          0 :                 return count;
     248                 :            : 
     249                 :          0 :         md = mmc_blk_get(dev_to_disk(dev));
     250                 :            :         mq = &md->queue;
     251                 :            : 
     252                 :            :         /* Dispatch locking to the block layer */
     253                 :          0 :         req = blk_get_request(mq->queue, REQ_OP_DRV_OUT, 0);
     254         [ #  # ]:          0 :         if (IS_ERR(req)) {
     255                 :          0 :                 count = PTR_ERR(req);
     256                 :          0 :                 goto out_put;
     257                 :            :         }
     258                 :          0 :         req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_BOOT_WP;
     259                 :          0 :         blk_execute_rq(mq->queue, NULL, req, 0);
     260                 :          0 :         ret = req_to_mmc_queue_req(req)->drv_op_result;
     261                 :          0 :         blk_put_request(req);
     262                 :            : 
     263         [ #  # ]:          0 :         if (!ret) {
     264                 :          0 :                 pr_info("%s: Locking boot partition ro until next power on\n",
     265                 :            :                         md->disk->disk_name);
     266                 :          0 :                 set_disk_ro(md->disk, 1);
     267                 :            : 
     268         [ #  # ]:          0 :                 list_for_each_entry(part_md, &md->part, part)
     269         [ #  # ]:          0 :                         if (part_md->area_type == MMC_BLK_DATA_AREA_BOOT) {
     270                 :          0 :                                 pr_info("%s: Locking boot partition ro until next power on\n", part_md->disk->disk_name);
     271                 :          0 :                                 set_disk_ro(part_md->disk, 1);
     272                 :            :                         }
     273                 :            :         }
     274                 :            : out_put:
     275                 :          0 :         mmc_blk_put(md);
     276                 :          0 :         return count;
     277                 :            : }
     278                 :            : 
     279                 :          0 : static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr,
     280                 :            :                              char *buf)
     281                 :            : {
     282                 :            :         int ret;
     283                 :          0 :         struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
     284                 :            : 
     285                 :          0 :         ret = snprintf(buf, PAGE_SIZE, "%d\n",
     286                 :            :                        get_disk_ro(dev_to_disk(dev)) ^
     287                 :          0 :                        md->read_only);
     288                 :          0 :         mmc_blk_put(md);
     289                 :          0 :         return ret;
     290                 :            : }
     291                 :            : 
     292                 :          0 : static ssize_t force_ro_store(struct device *dev, struct device_attribute *attr,
     293                 :            :                               const char *buf, size_t count)
     294                 :            : {
     295                 :            :         int ret;
     296                 :            :         char *end;
     297                 :          0 :         struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
     298                 :          0 :         unsigned long set = simple_strtoul(buf, &end, 0);
     299         [ #  # ]:          0 :         if (end == buf) {
     300                 :            :                 ret = -EINVAL;
     301                 :            :                 goto out;
     302                 :            :         }
     303                 :            : 
     304   [ #  #  #  # ]:          0 :         set_disk_ro(dev_to_disk(dev), set || md->read_only);
     305                 :          0 :         ret = count;
     306                 :            : out:
     307                 :          0 :         mmc_blk_put(md);
     308                 :          0 :         return ret;
     309                 :            : }
     310                 :            : 
     311                 :       4191 : static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
     312                 :            : {
     313                 :       4191 :         struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
     314                 :            :         int ret = -ENXIO;
     315                 :            : 
     316                 :       4191 :         mutex_lock(&block_mutex);
     317         [ +  - ]:       4191 :         if (md) {
     318         [ +  + ]:       4191 :                 if (md->usage == 2)
     319                 :        414 :                         check_disk_change(bdev);
     320                 :            :                 ret = 0;
     321                 :            : 
     322   [ +  +  -  + ]:       4191 :                 if ((mode & FMODE_WRITE) && md->read_only) {
     323                 :          0 :                         mmc_blk_put(md);
     324                 :            :                         ret = -EROFS;
     325                 :            :                 }
     326                 :            :         }
     327                 :       4191 :         mutex_unlock(&block_mutex);
     328                 :            : 
     329                 :       4191 :         return ret;
     330                 :            : }
     331                 :            : 
     332                 :       3777 : static void mmc_blk_release(struct gendisk *disk, fmode_t mode)
     333                 :            : {
     334                 :       3777 :         struct mmc_blk_data *md = disk->private_data;
     335                 :            : 
     336                 :       3777 :         mutex_lock(&block_mutex);
     337                 :       3777 :         mmc_blk_put(md);
     338                 :       3777 :         mutex_unlock(&block_mutex);
     339                 :       3777 : }
     340                 :            : 
     341                 :            : static int
     342                 :          0 : mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
     343                 :            : {
     344                 :          0 :         geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16);
     345                 :          0 :         geo->heads = 4;
     346                 :          0 :         geo->sectors = 16;
     347                 :          0 :         return 0;
     348                 :            : }
     349                 :            : 
     350                 :            : struct mmc_blk_ioc_data {
     351                 :            :         struct mmc_ioc_cmd ic;
     352                 :            :         unsigned char *buf;
     353                 :            :         u64 buf_bytes;
     354                 :            :         struct mmc_rpmb_data *rpmb;
     355                 :            : };
     356                 :            : 
     357                 :          0 : static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
     358                 :            :         struct mmc_ioc_cmd __user *user)
     359                 :            : {
     360                 :            :         struct mmc_blk_ioc_data *idata;
     361                 :            :         int err;
     362                 :            : 
     363                 :            :         idata = kmalloc(sizeof(*idata), GFP_KERNEL);
     364         [ #  # ]:          0 :         if (!idata) {
     365                 :            :                 err = -ENOMEM;
     366                 :            :                 goto out;
     367                 :            :         }
     368                 :            : 
     369         [ #  # ]:          0 :         if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) {
     370                 :            :                 err = -EFAULT;
     371                 :            :                 goto idata_err;
     372                 :            :         }
     373                 :            : 
     374                 :          0 :         idata->buf_bytes = (u64) idata->ic.blksz * idata->ic.blocks;
     375         [ #  # ]:          0 :         if (idata->buf_bytes > MMC_IOC_MAX_BYTES) {
     376                 :            :                 err = -EOVERFLOW;
     377                 :            :                 goto idata_err;
     378                 :            :         }
     379                 :            : 
     380         [ #  # ]:          0 :         if (!idata->buf_bytes) {
     381                 :          0 :                 idata->buf = NULL;
     382                 :          0 :                 return idata;
     383                 :            :         }
     384                 :            : 
     385                 :          0 :         idata->buf = memdup_user((void __user *)(unsigned long)
     386                 :          0 :                                  idata->ic.data_ptr, idata->buf_bytes);
     387         [ #  # ]:          0 :         if (IS_ERR(idata->buf)) {
     388                 :            :                 err = PTR_ERR(idata->buf);
     389                 :          0 :                 goto idata_err;
     390                 :            :         }
     391                 :            : 
     392                 :            :         return idata;
     393                 :            : 
     394                 :            : idata_err:
     395                 :          0 :         kfree(idata);
     396                 :            : out:
     397                 :          0 :         return ERR_PTR(err);
     398                 :            : }
     399                 :            : 
     400                 :          0 : static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr,
     401                 :            :                                       struct mmc_blk_ioc_data *idata)
     402                 :            : {
     403                 :            :         struct mmc_ioc_cmd *ic = &idata->ic;
     404                 :            : 
     405         [ #  # ]:          0 :         if (copy_to_user(&(ic_ptr->response), ic->response,
     406                 :            :                          sizeof(ic->response)))
     407                 :            :                 return -EFAULT;
     408                 :            : 
     409         [ #  # ]:          0 :         if (!idata->ic.write_flag) {
     410         [ #  # ]:          0 :                 if (copy_to_user((void __user *)(unsigned long)ic->data_ptr,
     411                 :          0 :                                  idata->buf, idata->buf_bytes))
     412                 :            :                         return -EFAULT;
     413                 :            :         }
     414                 :            : 
     415                 :            :         return 0;
     416                 :            : }
     417                 :            : 
     418                 :          0 : static int ioctl_do_sanitize(struct mmc_card *card)
     419                 :            : {
     420                 :            :         int err;
     421                 :            : 
     422         [ #  # ]:          0 :         if (!mmc_can_sanitize(card)) {
     423                 :          0 :                         pr_warn("%s: %s - SANITIZE is not supported\n",
     424                 :            :                                 mmc_hostname(card->host), __func__);
     425                 :            :                         err = -EOPNOTSUPP;
     426                 :          0 :                         goto out;
     427                 :            :         }
     428                 :            : 
     429                 :            :         pr_debug("%s: %s - SANITIZE IN PROGRESS...\n",
     430                 :            :                 mmc_hostname(card->host), __func__);
     431                 :            : 
     432                 :          0 :         err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
     433                 :            :                                         EXT_CSD_SANITIZE_START, 1,
     434                 :            :                                         MMC_SANITIZE_REQ_TIMEOUT);
     435                 :            : 
     436         [ #  # ]:          0 :         if (err)
     437                 :          0 :                 pr_err("%s: %s - EXT_CSD_SANITIZE_START failed. err=%d\n",
     438                 :            :                        mmc_hostname(card->host), __func__, err);
     439                 :            : 
     440                 :            :         pr_debug("%s: %s - SANITIZE COMPLETED\n", mmc_hostname(card->host),
     441                 :            :                                              __func__);
     442                 :            : out:
     443                 :          0 :         return err;
     444                 :            : }
     445                 :            : 
     446                 :            : static inline bool mmc_blk_in_tran_state(u32 status)
     447                 :            : {
     448                 :            :         /*
     449                 :            :          * Some cards mishandle the status bits, so make sure to check both the
     450                 :            :          * busy indication and the card state.
     451                 :            :          */
     452   [ #  #  #  #  :     124034 :         return status & R1_READY_FOR_DATA &&
          #  #  #  #  #  
          #  #  #  +  -  
                   -  + ]
     453                 :      62017 :                (R1_CURRENT_STATE(status) == R1_STATE_TRAN);
     454                 :            : }
     455                 :            : 
     456                 :      62018 : static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
     457                 :            :                             u32 *resp_errs)
     458                 :            : {
     459                 :      62018 :         unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms);
     460                 :            :         int err = 0;
     461                 :            :         u32 status;
     462                 :            : 
     463                 :            :         do {
     464         [ +  - ]:      62018 :                 bool done = time_after(jiffies, timeout);
     465                 :            : 
     466                 :      62018 :                 err = __mmc_send_status(card, &status, 5);
     467         [ -  + ]:      62017 :                 if (err) {
     468                 :          0 :                         dev_err(mmc_dev(card->host),
     469                 :            :                                 "error %d requesting status\n", err);
     470                 :          0 :                         return err;
     471                 :            :                 }
     472                 :            : 
     473                 :            :                 /* Accumulate any response error bits seen */
     474         [ +  - ]:      62017 :                 if (resp_errs)
     475                 :      62017 :                         *resp_errs |= status;
     476                 :            : 
     477                 :            :                 /*
     478                 :            :                  * Timeout if the device never becomes ready for data and never
     479                 :            :                  * leaves the program state.
     480                 :            :                  */
     481         [ -  + ]:      62017 :                 if (done) {
     482                 :          0 :                         dev_err(mmc_dev(card->host),
     483                 :            :                                 "Card stuck in wrong state! %s status: %#x\n",
     484                 :            :                                  __func__, status);
     485                 :          0 :                         return -ETIMEDOUT;
     486                 :            :                 }
     487                 :            : 
     488                 :            :                 /*
     489                 :            :                  * Some cards mishandle the status bits,
     490                 :            :                  * so make sure to check both the busy
     491                 :            :                  * indication and the card state.
     492                 :            :                  */
     493         [ -  + ]:     124034 :         } while (!mmc_blk_in_tran_state(status));
     494                 :            : 
     495                 :      62017 :         return err;
     496                 :            : }
     497                 :            : 
     498                 :          0 : static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
     499                 :            :                                struct mmc_blk_ioc_data *idata)
     500                 :            : {
     501                 :          0 :         struct mmc_command cmd = {}, sbc = {};
     502                 :          0 :         struct mmc_data data = {};
     503                 :          0 :         struct mmc_request mrq = {};
     504                 :            :         struct scatterlist sg;
     505                 :            :         int err;
     506                 :            :         unsigned int target_part;
     507                 :            : 
     508   [ #  #  #  # ]:          0 :         if (!card || !md || !idata)
     509                 :            :                 return -EINVAL;
     510                 :            : 
     511                 :            :         /*
     512                 :            :          * The RPMB accesses comes in from the character device, so we
     513                 :            :          * need to target these explicitly. Else we just target the
     514                 :            :          * partition type for the block device the ioctl() was issued
     515                 :            :          * on.
     516                 :            :          */
     517         [ #  # ]:          0 :         if (idata->rpmb) {
     518                 :            :                 /* Support multiple RPMB partitions */
     519                 :          0 :                 target_part = idata->rpmb->part_index;
     520                 :          0 :                 target_part |= EXT_CSD_PART_CONFIG_ACC_RPMB;
     521                 :            :         } else {
     522                 :          0 :                 target_part = md->part_type;
     523                 :            :         }
     524                 :            : 
     525                 :          0 :         cmd.opcode = idata->ic.opcode;
     526                 :          0 :         cmd.arg = idata->ic.arg;
     527                 :          0 :         cmd.flags = idata->ic.flags;
     528                 :            : 
     529         [ #  # ]:          0 :         if (idata->buf_bytes) {
     530                 :          0 :                 data.sg = &sg;
     531                 :          0 :                 data.sg_len = 1;
     532                 :          0 :                 data.blksz = idata->ic.blksz;
     533                 :          0 :                 data.blocks = idata->ic.blocks;
     534                 :            : 
     535                 :          0 :                 sg_init_one(data.sg, idata->buf, idata->buf_bytes);
     536                 :            : 
     537         [ #  # ]:          0 :                 if (idata->ic.write_flag)
     538                 :          0 :                         data.flags = MMC_DATA_WRITE;
     539                 :            :                 else
     540                 :          0 :                         data.flags = MMC_DATA_READ;
     541                 :            : 
     542                 :            :                 /* data.flags must already be set before doing this. */
     543                 :          0 :                 mmc_set_data_timeout(&data, card);
     544                 :            : 
     545                 :            :                 /* Allow overriding the timeout_ns for empirical tuning. */
     546         [ #  # ]:          0 :                 if (idata->ic.data_timeout_ns)
     547                 :          0 :                         data.timeout_ns = idata->ic.data_timeout_ns;
     548                 :            : 
     549         [ #  # ]:          0 :                 if ((cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B) {
     550                 :            :                         /*
     551                 :            :                          * Pretend this is a data transfer and rely on the
     552                 :            :                          * host driver to compute timeout.  When all host
     553                 :            :                          * drivers support cmd.cmd_timeout for R1B, this
     554                 :            :                          * can be changed to:
     555                 :            :                          *
     556                 :            :                          *     mrq.data = NULL;
     557                 :            :                          *     cmd.cmd_timeout = idata->ic.cmd_timeout_ms;
     558                 :            :                          */
     559                 :          0 :                         data.timeout_ns = idata->ic.cmd_timeout_ms * 1000000;
     560                 :            :                 }
     561                 :            : 
     562                 :          0 :                 mrq.data = &data;
     563                 :            :         }
     564                 :            : 
     565                 :          0 :         mrq.cmd = &cmd;
     566                 :            : 
     567                 :          0 :         err = mmc_blk_part_switch(card, target_part);
     568         [ #  # ]:          0 :         if (err)
     569                 :            :                 return err;
     570                 :            : 
     571         [ #  # ]:          0 :         if (idata->ic.is_acmd) {
     572                 :          0 :                 err = mmc_app_cmd(card->host, card);
     573         [ #  # ]:          0 :                 if (err)
     574                 :            :                         return err;
     575                 :            :         }
     576                 :            : 
     577         [ #  # ]:          0 :         if (idata->rpmb) {
     578                 :          0 :                 sbc.opcode = MMC_SET_BLOCK_COUNT;
     579                 :            :                 /*
     580                 :            :                  * We don't do any blockcount validation because the max size
     581                 :            :                  * may be increased by a future standard. We just copy the
     582                 :            :                  * 'Reliable Write' bit here.
     583                 :            :                  */
     584                 :          0 :                 sbc.arg = data.blocks | (idata->ic.write_flag & BIT(31));
     585                 :          0 :                 sbc.flags = MMC_RSP_R1 | MMC_CMD_AC;
     586                 :          0 :                 mrq.sbc = &sbc;
     587                 :            :         }
     588                 :            : 
     589   [ #  #  #  # ]:          0 :         if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_SANITIZE_START) &&
     590                 :          0 :             (cmd.opcode == MMC_SWITCH)) {
     591                 :          0 :                 err = ioctl_do_sanitize(card);
     592                 :            : 
     593         [ #  # ]:          0 :                 if (err)
     594                 :          0 :                         pr_err("%s: ioctl_do_sanitize() failed. err = %d",
     595                 :            :                                __func__, err);
     596                 :            : 
     597                 :          0 :                 return err;
     598                 :            :         }
     599                 :            : 
     600                 :          0 :         mmc_wait_for_req(card->host, &mrq);
     601                 :            : 
     602         [ #  # ]:          0 :         if (cmd.error) {
     603                 :          0 :                 dev_err(mmc_dev(card->host), "%s: cmd error %d\n",
     604                 :            :                                                 __func__, cmd.error);
     605                 :          0 :                 return cmd.error;
     606                 :            :         }
     607         [ #  # ]:          0 :         if (data.error) {
     608                 :          0 :                 dev_err(mmc_dev(card->host), "%s: data error %d\n",
     609                 :            :                                                 __func__, data.error);
     610                 :          0 :                 return data.error;
     611                 :            :         }
     612                 :            : 
     613                 :            :         /*
     614                 :            :          * Make sure the cache of the PARTITION_CONFIG register and
     615                 :            :          * PARTITION_ACCESS bits is updated in case the ioctl ext_csd write
     616                 :            :          * changed it successfully.
     617                 :            :          */
     618   [ #  #  #  # ]:          0 :         if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_PART_CONFIG) &&
     619                 :          0 :             (cmd.opcode == MMC_SWITCH)) {
     620                 :            :                 struct mmc_blk_data *main_md = dev_get_drvdata(&card->dev);
     621                 :          0 :                 u8 value = MMC_EXTRACT_VALUE_FROM_ARG(cmd.arg);
     622                 :            : 
     623                 :            :                 /*
     624                 :            :                  * Update cache so the next mmc_blk_part_switch call operates
     625                 :            :                  * on up-to-date data.
     626                 :            :                  */
     627                 :          0 :                 card->ext_csd.part_config = value;
     628                 :          0 :                 main_md->part_curr = value & EXT_CSD_PART_CONFIG_ACC_MASK;
     629                 :            :         }
     630                 :            : 
     631                 :            :         /*
     632                 :            :          * According to the SD specs, some commands require a delay after
     633                 :            :          * issuing the command.
     634                 :            :          */
     635         [ #  # ]:          0 :         if (idata->ic.postsleep_min_us)
     636                 :          0 :                 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
     637                 :            : 
     638                 :          0 :         memcpy(&(idata->ic.response), cmd.resp, sizeof(cmd.resp));
     639                 :            : 
     640   [ #  #  #  # ]:          0 :         if (idata->rpmb || (cmd.flags & MMC_RSP_R1B)) {
     641                 :            :                 /*
     642                 :            :                  * Ensure RPMB/R1B command has completed by polling CMD13
     643                 :            :                  * "Send Status".
     644                 :            :                  */
     645                 :          0 :                 err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, NULL);
     646                 :            :         }
     647                 :            : 
     648                 :          0 :         return err;
     649                 :            : }
     650                 :            : 
     651                 :          0 : static int mmc_blk_ioctl_cmd(struct mmc_blk_data *md,
     652                 :            :                              struct mmc_ioc_cmd __user *ic_ptr,
     653                 :            :                              struct mmc_rpmb_data *rpmb)
     654                 :            : {
     655                 :            :         struct mmc_blk_ioc_data *idata;
     656                 :            :         struct mmc_blk_ioc_data *idatas[1];
     657                 :            :         struct mmc_queue *mq;
     658                 :            :         struct mmc_card *card;
     659                 :            :         int err = 0, ioc_err = 0;
     660                 :            :         struct request *req;
     661                 :            : 
     662                 :          0 :         idata = mmc_blk_ioctl_copy_from_user(ic_ptr);
     663         [ #  # ]:          0 :         if (IS_ERR(idata))
     664                 :          0 :                 return PTR_ERR(idata);
     665                 :            :         /* This will be NULL on non-RPMB ioctl():s */
     666                 :          0 :         idata->rpmb = rpmb;
     667                 :            : 
     668                 :          0 :         card = md->queue.card;
     669         [ #  # ]:          0 :         if (IS_ERR(card)) {
     670                 :            :                 err = PTR_ERR(card);
     671                 :          0 :                 goto cmd_done;
     672                 :            :         }
     673                 :            : 
     674                 :            :         /*
     675                 :            :          * Dispatch the ioctl() into the block request queue.
     676                 :            :          */
     677                 :            :         mq = &md->queue;
     678         [ #  # ]:          0 :         req = blk_get_request(mq->queue,
     679                 :          0 :                 idata->ic.write_flag ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
     680         [ #  # ]:          0 :         if (IS_ERR(req)) {
     681                 :            :                 err = PTR_ERR(req);
     682                 :          0 :                 goto cmd_done;
     683                 :            :         }
     684                 :          0 :         idatas[0] = idata;
     685                 :          0 :         req_to_mmc_queue_req(req)->drv_op =
     686                 :          0 :                 rpmb ? MMC_DRV_OP_IOCTL_RPMB : MMC_DRV_OP_IOCTL;
     687                 :          0 :         req_to_mmc_queue_req(req)->drv_op_data = idatas;
     688                 :          0 :         req_to_mmc_queue_req(req)->ioc_count = 1;
     689                 :          0 :         blk_execute_rq(mq->queue, NULL, req, 0);
     690                 :          0 :         ioc_err = req_to_mmc_queue_req(req)->drv_op_result;
     691                 :          0 :         err = mmc_blk_ioctl_copy_to_user(ic_ptr, idata);
     692                 :          0 :         blk_put_request(req);
     693                 :            : 
     694                 :            : cmd_done:
     695                 :          0 :         kfree(idata->buf);
     696                 :          0 :         kfree(idata);
     697         [ #  # ]:          0 :         return ioc_err ? ioc_err : err;
     698                 :            : }
     699                 :            : 
     700                 :          0 : static int mmc_blk_ioctl_multi_cmd(struct mmc_blk_data *md,
     701                 :            :                                    struct mmc_ioc_multi_cmd __user *user,
     702                 :            :                                    struct mmc_rpmb_data *rpmb)
     703                 :            : {
     704                 :            :         struct mmc_blk_ioc_data **idata = NULL;
     705                 :          0 :         struct mmc_ioc_cmd __user *cmds = user->cmds;
     706                 :            :         struct mmc_card *card;
     707                 :            :         struct mmc_queue *mq;
     708                 :            :         int i, err = 0, ioc_err = 0;
     709                 :            :         __u64 num_of_cmds;
     710                 :            :         struct request *req;
     711                 :            : 
     712         [ #  # ]:          0 :         if (copy_from_user(&num_of_cmds, &user->num_of_cmds,
     713                 :            :                            sizeof(num_of_cmds)))
     714                 :            :                 return -EFAULT;
     715                 :            : 
     716         [ #  # ]:          0 :         if (!num_of_cmds)
     717                 :            :                 return 0;
     718                 :            : 
     719         [ #  # ]:          0 :         if (num_of_cmds > MMC_IOC_MAX_CMDS)
     720                 :            :                 return -EINVAL;
     721                 :            : 
     722                 :          0 :         idata = kcalloc(num_of_cmds, sizeof(*idata), GFP_KERNEL);
     723         [ #  # ]:          0 :         if (!idata)
     724                 :            :                 return -ENOMEM;
     725                 :            : 
     726         [ #  # ]:          0 :         for (i = 0; i < num_of_cmds; i++) {
     727                 :          0 :                 idata[i] = mmc_blk_ioctl_copy_from_user(&cmds[i]);
     728         [ #  # ]:          0 :                 if (IS_ERR(idata[i])) {
     729                 :          0 :                         err = PTR_ERR(idata[i]);
     730                 :          0 :                         num_of_cmds = i;
     731                 :          0 :                         goto cmd_err;
     732                 :            :                 }
     733                 :            :                 /* This will be NULL on non-RPMB ioctl():s */
     734                 :          0 :                 idata[i]->rpmb = rpmb;
     735                 :            :         }
     736                 :            : 
     737                 :          0 :         card = md->queue.card;
     738         [ #  # ]:          0 :         if (IS_ERR(card)) {
     739                 :            :                 err = PTR_ERR(card);
     740                 :          0 :                 goto cmd_err;
     741                 :            :         }
     742                 :            : 
     743                 :            : 
     744                 :            :         /*
     745                 :            :          * Dispatch the ioctl()s into the block request queue.
     746                 :            :          */
     747                 :            :         mq = &md->queue;
     748         [ #  # ]:          0 :         req = blk_get_request(mq->queue,
     749                 :          0 :                 idata[0]->ic.write_flag ? REQ_OP_DRV_OUT : REQ_OP_DRV_IN, 0);
     750         [ #  # ]:          0 :         if (IS_ERR(req)) {
     751                 :            :                 err = PTR_ERR(req);
     752                 :          0 :                 goto cmd_err;
     753                 :            :         }
     754                 :          0 :         req_to_mmc_queue_req(req)->drv_op =
     755                 :          0 :                 rpmb ? MMC_DRV_OP_IOCTL_RPMB : MMC_DRV_OP_IOCTL;
     756                 :          0 :         req_to_mmc_queue_req(req)->drv_op_data = idata;
     757                 :          0 :         req_to_mmc_queue_req(req)->ioc_count = num_of_cmds;
     758                 :          0 :         blk_execute_rq(mq->queue, NULL, req, 0);
     759                 :          0 :         ioc_err = req_to_mmc_queue_req(req)->drv_op_result;
     760                 :            : 
     761                 :            :         /* copy to user if data and response */
     762   [ #  #  #  # ]:          0 :         for (i = 0; i < num_of_cmds && !err; i++)
     763                 :          0 :                 err = mmc_blk_ioctl_copy_to_user(&cmds[i], idata[i]);
     764                 :            : 
     765                 :          0 :         blk_put_request(req);
     766                 :            : 
     767                 :            : cmd_err:
     768         [ #  # ]:          0 :         for (i = 0; i < num_of_cmds; i++) {
     769                 :          0 :                 kfree(idata[i]->buf);
     770                 :          0 :                 kfree(idata[i]);
     771                 :            :         }
     772                 :          0 :         kfree(idata);
     773         [ #  # ]:          0 :         return ioc_err ? ioc_err : err;
     774                 :            : }
     775                 :            : 
     776                 :            : static int mmc_blk_check_blkdev(struct block_device *bdev)
     777                 :            : {
     778                 :            :         /*
     779                 :            :          * The caller must have CAP_SYS_RAWIO, and must be calling this on the
     780                 :            :          * whole block device, not on a partition.  This prevents overspray
     781                 :            :          * between sibling partitions.
     782                 :            :          */
     783   [ #  #  #  #  :          0 :         if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains))
             #  #  #  # ]
     784                 :            :                 return -EPERM;
     785                 :            :         return 0;
     786                 :            : }
     787                 :            : 
     788                 :       1863 : static int mmc_blk_ioctl(struct block_device *bdev, fmode_t mode,
     789                 :            :         unsigned int cmd, unsigned long arg)
     790                 :            : {
     791                 :            :         struct mmc_blk_data *md;
     792                 :            :         int ret;
     793                 :            : 
     794      [ -  -  + ]:       1863 :         switch (cmd) {
     795                 :            :         case MMC_IOC_CMD:
     796                 :            :                 ret = mmc_blk_check_blkdev(bdev);
     797         [ #  # ]:          0 :                 if (ret)
     798                 :            :                         return ret;
     799                 :          0 :                 md = mmc_blk_get(bdev->bd_disk);
     800         [ #  # ]:          0 :                 if (!md)
     801                 :            :                         return -EINVAL;
     802                 :          0 :                 ret = mmc_blk_ioctl_cmd(md,
     803                 :            :                                         (struct mmc_ioc_cmd __user *)arg,
     804                 :            :                                         NULL);
     805                 :          0 :                 mmc_blk_put(md);
     806                 :          0 :                 return ret;
     807                 :            :         case MMC_IOC_MULTI_CMD:
     808                 :            :                 ret = mmc_blk_check_blkdev(bdev);
     809         [ #  # ]:          0 :                 if (ret)
     810                 :            :                         return ret;
     811                 :          0 :                 md = mmc_blk_get(bdev->bd_disk);
     812         [ #  # ]:          0 :                 if (!md)
     813                 :            :                         return -EINVAL;
     814                 :          0 :                 ret = mmc_blk_ioctl_multi_cmd(md,
     815                 :            :                                         (struct mmc_ioc_multi_cmd __user *)arg,
     816                 :            :                                         NULL);
     817                 :          0 :                 mmc_blk_put(md);
     818                 :          0 :                 return ret;
     819                 :            :         default:
     820                 :            :                 return -EINVAL;
     821                 :            :         }
     822                 :            : }
     823                 :            : 
     824                 :            : #ifdef CONFIG_COMPAT
     825                 :            : static int mmc_blk_compat_ioctl(struct block_device *bdev, fmode_t mode,
     826                 :            :         unsigned int cmd, unsigned long arg)
     827                 :            : {
     828                 :            :         return mmc_blk_ioctl(bdev, mode, cmd, (unsigned long) compat_ptr(arg));
     829                 :            : }
     830                 :            : #endif
     831                 :            : 
     832                 :            : static const struct block_device_operations mmc_bdops = {
     833                 :            :         .open                   = mmc_blk_open,
     834                 :            :         .release                = mmc_blk_release,
     835                 :            :         .getgeo                 = mmc_blk_getgeo,
     836                 :            :         .owner                  = THIS_MODULE,
     837                 :            :         .ioctl                  = mmc_blk_ioctl,
     838                 :            : #ifdef CONFIG_COMPAT
     839                 :            :         .compat_ioctl           = mmc_blk_compat_ioctl,
     840                 :            : #endif
     841                 :            : };
     842                 :            : 
     843                 :          0 : static int mmc_blk_part_switch_pre(struct mmc_card *card,
     844                 :            :                                    unsigned int part_type)
     845                 :            : {
     846                 :            :         int ret = 0;
     847                 :            : 
     848         [ #  # ]:          0 :         if (part_type == EXT_CSD_PART_CONFIG_ACC_RPMB) {
     849         [ #  # ]:          0 :                 if (card->ext_csd.cmdq_en) {
     850                 :          0 :                         ret = mmc_cmdq_disable(card);
     851         [ #  # ]:          0 :                         if (ret)
     852                 :            :                                 return ret;
     853                 :            :                 }
     854                 :          0 :                 mmc_retune_pause(card->host);
     855                 :            :         }
     856                 :            : 
     857                 :          0 :         return ret;
     858                 :            : }
     859                 :            : 
     860                 :          0 : static int mmc_blk_part_switch_post(struct mmc_card *card,
     861                 :            :                                     unsigned int part_type)
     862                 :            : {
     863                 :            :         int ret = 0;
     864                 :            : 
     865         [ #  # ]:          0 :         if (part_type == EXT_CSD_PART_CONFIG_ACC_RPMB) {
     866                 :          0 :                 mmc_retune_unpause(card->host);
     867   [ #  #  #  # ]:          0 :                 if (card->reenable_cmdq && !card->ext_csd.cmdq_en)
     868                 :          0 :                         ret = mmc_cmdq_enable(card);
     869                 :            :         }
     870                 :            : 
     871                 :          0 :         return ret;
     872                 :            : }
     873                 :            : 
     874                 :    1150941 : static inline int mmc_blk_part_switch(struct mmc_card *card,
     875                 :            :                                       unsigned int part_type)
     876                 :            : {
     877                 :            :         int ret = 0;
     878                 :            :         struct mmc_blk_data *main_md = dev_get_drvdata(&card->dev);
     879                 :            : 
     880         [ -  + ]:    1150941 :         if (main_md->part_curr == part_type)
     881                 :            :                 return 0;
     882                 :            : 
     883         [ #  # ]:          0 :         if (mmc_card_mmc(card)) {
     884                 :          0 :                 u8 part_config = card->ext_csd.part_config;
     885                 :            : 
     886                 :          0 :                 ret = mmc_blk_part_switch_pre(card, part_type);
     887         [ #  # ]:          0 :                 if (ret)
     888                 :            :                         return ret;
     889                 :            : 
     890                 :          0 :                 part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK;
     891                 :          0 :                 part_config |= part_type;
     892                 :            : 
     893                 :          0 :                 ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
     894                 :            :                                  EXT_CSD_PART_CONFIG, part_config,
     895                 :            :                                  card->ext_csd.part_time);
     896         [ #  # ]:          0 :                 if (ret) {
     897                 :          0 :                         mmc_blk_part_switch_post(card, part_type);
     898                 :          0 :                         return ret;
     899                 :            :                 }
     900                 :            : 
     901                 :          0 :                 card->ext_csd.part_config = part_config;
     902                 :            : 
     903                 :          0 :                 ret = mmc_blk_part_switch_post(card, main_md->part_curr);
     904                 :            :         }
     905                 :            : 
     906                 :          0 :         main_md->part_curr = part_type;
     907                 :          0 :         return ret;
     908                 :            : }
     909                 :            : 
     910                 :          0 : static int mmc_sd_num_wr_blocks(struct mmc_card *card, u32 *written_blocks)
     911                 :            : {
     912                 :            :         int err;
     913                 :            :         u32 result;
     914                 :            :         __be32 *blocks;
     915                 :            : 
     916                 :          0 :         struct mmc_request mrq = {};
     917                 :          0 :         struct mmc_command cmd = {};
     918                 :          0 :         struct mmc_data data = {};
     919                 :            : 
     920                 :            :         struct scatterlist sg;
     921                 :            : 
     922                 :          0 :         cmd.opcode = MMC_APP_CMD;
     923                 :          0 :         cmd.arg = card->rca << 16;
     924                 :          0 :         cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
     925                 :            : 
     926                 :          0 :         err = mmc_wait_for_cmd(card->host, &cmd, 0);
     927         [ #  # ]:          0 :         if (err)
     928                 :            :                 return err;
     929   [ #  #  #  # ]:          0 :         if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
     930                 :            :                 return -EIO;
     931                 :            : 
     932                 :          0 :         memset(&cmd, 0, sizeof(struct mmc_command));
     933                 :            : 
     934                 :          0 :         cmd.opcode = SD_APP_SEND_NUM_WR_BLKS;
     935                 :            :         cmd.arg = 0;
     936                 :          0 :         cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
     937                 :            : 
     938                 :          0 :         data.blksz = 4;
     939                 :          0 :         data.blocks = 1;
     940                 :          0 :         data.flags = MMC_DATA_READ;
     941                 :          0 :         data.sg = &sg;
     942                 :          0 :         data.sg_len = 1;
     943                 :          0 :         mmc_set_data_timeout(&data, card);
     944                 :            : 
     945                 :          0 :         mrq.cmd = &cmd;
     946                 :          0 :         mrq.data = &data;
     947                 :            : 
     948                 :            :         blocks = kmalloc(4, GFP_KERNEL);
     949         [ #  # ]:          0 :         if (!blocks)
     950                 :            :                 return -ENOMEM;
     951                 :            : 
     952                 :          0 :         sg_init_one(&sg, blocks, 4);
     953                 :            : 
     954                 :          0 :         mmc_wait_for_req(card->host, &mrq);
     955                 :            : 
     956                 :          0 :         result = ntohl(*blocks);
     957                 :          0 :         kfree(blocks);
     958                 :            : 
     959   [ #  #  #  # ]:          0 :         if (cmd.error || data.error)
     960                 :            :                 return -EIO;
     961                 :            : 
     962                 :          0 :         *written_blocks = result;
     963                 :            : 
     964                 :          0 :         return 0;
     965                 :            : }
     966                 :            : 
     967                 :          0 : static unsigned int mmc_blk_clock_khz(struct mmc_host *host)
     968                 :            : {
     969         [ #  # ]:          0 :         if (host->actual_clock)
     970                 :          0 :                 return host->actual_clock / 1000;
     971                 :            : 
     972                 :            :         /* Clock may be subject to a divisor, fudge it by a factor of 2. */
     973         [ #  # ]:          0 :         if (host->ios.clock)
     974                 :          0 :                 return host->ios.clock / 2000;
     975                 :            : 
     976                 :            :         /* How can there be no clock */
     977         [ #  # ]:          0 :         WARN_ON_ONCE(1);
     978                 :            :         return 100; /* 100 kHz is minimum possible value */
     979                 :            : }
     980                 :            : 
     981                 :          0 : static unsigned int mmc_blk_data_timeout_ms(struct mmc_host *host,
     982                 :            :                                             struct mmc_data *data)
     983                 :            : {
     984                 :          0 :         unsigned int ms = DIV_ROUND_UP(data->timeout_ns, 1000000);
     985                 :            :         unsigned int khz;
     986                 :            : 
     987         [ #  # ]:          0 :         if (data->timeout_clks) {
     988                 :          0 :                 khz = mmc_blk_clock_khz(host);
     989                 :          0 :                 ms += DIV_ROUND_UP(data->timeout_clks, khz);
     990                 :            :         }
     991                 :            : 
     992                 :          0 :         return ms;
     993                 :            : }
     994                 :            : 
     995                 :          0 : static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host,
     996                 :            :                          int type)
     997                 :            : {
     998                 :            :         int err;
     999                 :            : 
    1000         [ #  # ]:          0 :         if (md->reset_done & type)
    1001                 :            :                 return -EEXIST;
    1002                 :            : 
    1003                 :          0 :         md->reset_done |= type;
    1004                 :          0 :         err = mmc_hw_reset(host);
    1005                 :            :         /* Ensure we switch back to the correct partition */
    1006         [ #  # ]:          0 :         if (err != -EOPNOTSUPP) {
    1007                 :            :                 struct mmc_blk_data *main_md =
    1008                 :          0 :                         dev_get_drvdata(&host->card->dev);
    1009                 :            :                 int part_err;
    1010                 :            : 
    1011                 :          0 :                 main_md->part_curr = main_md->part_type;
    1012                 :          0 :                 part_err = mmc_blk_part_switch(host->card, md->part_type);
    1013         [ #  # ]:          0 :                 if (part_err) {
    1014                 :            :                         /*
    1015                 :            :                          * We have failed to get back into the correct
    1016                 :            :                          * partition, so we need to abort the whole request.
    1017                 :            :                          */
    1018                 :            :                         return -ENODEV;
    1019                 :            :                 }
    1020                 :            :         }
    1021                 :          0 :         return err;
    1022                 :            : }
    1023                 :            : 
    1024                 :            : static inline void mmc_blk_reset_success(struct mmc_blk_data *md, int type)
    1025                 :            : {
    1026                 :    1150935 :         md->reset_done &= ~type;
    1027                 :            : }
    1028                 :            : 
    1029                 :            : /*
    1030                 :            :  * The non-block commands come back from the block layer after it queued it and
    1031                 :            :  * processed it with all other requests and then they get issued in this
    1032                 :            :  * function.
    1033                 :            :  */
    1034                 :          0 : static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req)
    1035                 :            : {
    1036                 :            :         struct mmc_queue_req *mq_rq;
    1037                 :          0 :         struct mmc_card *card = mq->card;
    1038                 :          0 :         struct mmc_blk_data *md = mq->blkdata;
    1039                 :            :         struct mmc_blk_ioc_data **idata;
    1040                 :            :         bool rpmb_ioctl;
    1041                 :            :         u8 **ext_csd;
    1042                 :            :         u32 status;
    1043                 :            :         int ret;
    1044                 :            :         int i;
    1045                 :            : 
    1046                 :            :         mq_rq = req_to_mmc_queue_req(req);
    1047                 :          0 :         rpmb_ioctl = (mq_rq->drv_op == MMC_DRV_OP_IOCTL_RPMB);
    1048                 :            : 
    1049   [ #  #  #  #  :          0 :         switch (mq_rq->drv_op) {
                      # ]
    1050                 :            :         case MMC_DRV_OP_IOCTL:
    1051                 :            :         case MMC_DRV_OP_IOCTL_RPMB:
    1052                 :          0 :                 idata = mq_rq->drv_op_data;
    1053         [ #  # ]:          0 :                 for (i = 0, ret = 0; i < mq_rq->ioc_count; i++) {
    1054                 :          0 :                         ret = __mmc_blk_ioctl_cmd(card, md, idata[i]);
    1055         [ #  # ]:          0 :                         if (ret)
    1056                 :            :                                 break;
    1057                 :            :                 }
    1058                 :            :                 /* Always switch back to main area after RPMB access */
    1059         [ #  # ]:          0 :                 if (rpmb_ioctl)
    1060                 :          0 :                         mmc_blk_part_switch(card, 0);
    1061                 :            :                 break;
    1062                 :            :         case MMC_DRV_OP_BOOT_WP:
    1063                 :          0 :                 ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP,
    1064                 :          0 :                                  card->ext_csd.boot_ro_lock |
    1065                 :            :                                  EXT_CSD_BOOT_WP_B_PWR_WP_EN,
    1066                 :            :                                  card->ext_csd.part_time);
    1067         [ #  # ]:          0 :                 if (ret)
    1068                 :          0 :                         pr_err("%s: Locking boot partition ro until next power on failed: %d\n",
    1069                 :            :                                md->disk->disk_name, ret);
    1070                 :            :                 else
    1071                 :          0 :                         card->ext_csd.boot_ro_lock |=
    1072                 :            :                                 EXT_CSD_BOOT_WP_B_PWR_WP_EN;
    1073                 :            :                 break;
    1074                 :            :         case MMC_DRV_OP_GET_CARD_STATUS:
    1075                 :          0 :                 ret = mmc_send_status(card, &status);
    1076         [ #  # ]:          0 :                 if (!ret)
    1077                 :          0 :                         ret = status;
    1078                 :            :                 break;
    1079                 :            :         case MMC_DRV_OP_GET_EXT_CSD:
    1080                 :          0 :                 ext_csd = mq_rq->drv_op_data;
    1081                 :          0 :                 ret = mmc_get_ext_csd(card, ext_csd);
    1082                 :          0 :                 break;
    1083                 :            :         default:
    1084                 :          0 :                 pr_err("%s: unknown driver specific operation\n",
    1085                 :            :                        md->disk->disk_name);
    1086                 :            :                 ret = -EINVAL;
    1087                 :          0 :                 break;
    1088                 :            :         }
    1089                 :          0 :         mq_rq->drv_op_result = ret;
    1090         [ #  # ]:          0 :         blk_mq_end_request(req, ret ? BLK_STS_IOERR : BLK_STS_OK);
    1091                 :          0 : }
    1092                 :            : 
    1093                 :          0 : static void mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
    1094                 :            : {
    1095                 :          0 :         struct mmc_blk_data *md = mq->blkdata;
    1096                 :          0 :         struct mmc_card *card = md->queue.card;
    1097                 :            :         unsigned int from, nr;
    1098                 :            :         int err = 0, type = MMC_BLK_DISCARD;
    1099                 :            :         blk_status_t status = BLK_STS_OK;
    1100                 :            : 
    1101         [ #  # ]:          0 :         if (!mmc_can_erase(card)) {
    1102                 :            :                 status = BLK_STS_NOTSUPP;
    1103                 :            :                 goto fail;
    1104                 :            :         }
    1105                 :            : 
    1106                 :          0 :         from = blk_rq_pos(req);
    1107                 :            :         nr = blk_rq_sectors(req);
    1108                 :            : 
    1109                 :            :         do {
    1110                 :            :                 err = 0;
    1111         [ #  # ]:          0 :                 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
    1112                 :          0 :                         err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
    1113                 :            :                                          INAND_CMD38_ARG_EXT_CSD,
    1114                 :          0 :                                          card->erase_arg == MMC_TRIM_ARG ?
    1115                 :            :                                          INAND_CMD38_ARG_TRIM :
    1116                 :            :                                          INAND_CMD38_ARG_ERASE,
    1117                 :            :                                          0);
    1118                 :            :                 }
    1119         [ #  # ]:          0 :                 if (!err)
    1120                 :          0 :                         err = mmc_erase(card, from, nr, card->erase_arg);
    1121   [ #  #  #  # ]:          0 :         } while (err == -EIO && !mmc_blk_reset(md, card->host, type));
    1122         [ #  # ]:          0 :         if (err)
    1123                 :            :                 status = BLK_STS_IOERR;
    1124                 :            :         else
    1125                 :            :                 mmc_blk_reset_success(md, type);
    1126                 :            : fail:
    1127                 :          0 :         blk_mq_end_request(req, status);
    1128                 :          0 : }
    1129                 :            : 
    1130                 :          0 : static void mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
    1131                 :            :                                        struct request *req)
    1132                 :            : {
    1133                 :          0 :         struct mmc_blk_data *md = mq->blkdata;
    1134                 :          0 :         struct mmc_card *card = md->queue.card;
    1135                 :            :         unsigned int from, nr, arg;
    1136                 :            :         int err = 0, type = MMC_BLK_SECDISCARD;
    1137                 :            :         blk_status_t status = BLK_STS_OK;
    1138                 :            : 
    1139         [ #  # ]:          0 :         if (!(mmc_can_secure_erase_trim(card))) {
    1140                 :            :                 status = BLK_STS_NOTSUPP;
    1141                 :            :                 goto out;
    1142                 :            :         }
    1143                 :            : 
    1144                 :          0 :         from = blk_rq_pos(req);
    1145                 :            :         nr = blk_rq_sectors(req);
    1146                 :            : 
    1147   [ #  #  #  # ]:          0 :         if (mmc_can_trim(card) && !mmc_erase_group_aligned(card, from, nr))
    1148                 :            :                 arg = MMC_SECURE_TRIM1_ARG;
    1149                 :            :         else
    1150                 :            :                 arg = MMC_SECURE_ERASE_ARG;
    1151                 :            : 
    1152                 :            : retry:
    1153         [ #  # ]:          0 :         if (card->quirks & MMC_QUIRK_INAND_CMD38) {
    1154         [ #  # ]:          0 :                 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
    1155                 :            :                                  INAND_CMD38_ARG_EXT_CSD,
    1156                 :            :                                  arg == MMC_SECURE_TRIM1_ARG ?
    1157                 :            :                                  INAND_CMD38_ARG_SECTRIM1 :
    1158                 :            :                                  INAND_CMD38_ARG_SECERASE,
    1159                 :            :                                  0);
    1160         [ #  # ]:          0 :                 if (err)
    1161                 :            :                         goto out_retry;
    1162                 :            :         }
    1163                 :            : 
    1164                 :          0 :         err = mmc_erase(card, from, nr, arg);
    1165         [ #  # ]:          0 :         if (err == -EIO)
    1166                 :            :                 goto out_retry;
    1167         [ #  # ]:          0 :         if (err) {
    1168                 :            :                 status = BLK_STS_IOERR;
    1169                 :            :                 goto out;
    1170                 :            :         }
    1171                 :            : 
    1172         [ #  # ]:          0 :         if (arg == MMC_SECURE_TRIM1_ARG) {
    1173         [ #  # ]:          0 :                 if (card->quirks & MMC_QUIRK_INAND_CMD38) {
    1174                 :          0 :                         err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
    1175                 :            :                                          INAND_CMD38_ARG_EXT_CSD,
    1176                 :            :                                          INAND_CMD38_ARG_SECTRIM2,
    1177                 :            :                                          0);
    1178         [ #  # ]:          0 :                         if (err)
    1179                 :            :                                 goto out_retry;
    1180                 :            :                 }
    1181                 :            : 
    1182                 :          0 :                 err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG);
    1183         [ #  # ]:          0 :                 if (err == -EIO)
    1184                 :            :                         goto out_retry;
    1185         [ #  # ]:          0 :                 if (err) {
    1186                 :            :                         status = BLK_STS_IOERR;
    1187                 :            :                         goto out;
    1188                 :            :                 }
    1189                 :            :         }
    1190                 :            : 
    1191                 :            : out_retry:
    1192   [ #  #  #  # ]:          0 :         if (err && !mmc_blk_reset(md, card->host, type))
    1193                 :            :                 goto retry;
    1194         [ #  # ]:          0 :         if (!err)
    1195                 :            :                 mmc_blk_reset_success(md, type);
    1196                 :            : out:
    1197                 :          0 :         blk_mq_end_request(req, status);
    1198                 :          0 : }
    1199                 :            : 
    1200                 :          0 : static void mmc_blk_issue_flush(struct mmc_queue *mq, struct request *req)
    1201                 :            : {
    1202                 :          0 :         struct mmc_blk_data *md = mq->blkdata;
    1203                 :          0 :         struct mmc_card *card = md->queue.card;
    1204                 :            :         int ret = 0;
    1205                 :            : 
    1206                 :          0 :         ret = mmc_flush_cache(card);
    1207         [ #  # ]:          0 :         blk_mq_end_request(req, ret ? BLK_STS_IOERR : BLK_STS_OK);
    1208                 :          0 : }
    1209                 :            : 
    1210                 :            : /*
    1211                 :            :  * Reformat current write as a reliable write, supporting
    1212                 :            :  * both legacy and the enhanced reliable write MMC cards.
    1213                 :            :  * In each transfer we'll handle only as much as a single
    1214                 :            :  * reliable write can handle, thus finish the request in
    1215                 :            :  * partial completions.
    1216                 :            :  */
    1217                 :          0 : static inline void mmc_apply_rel_rw(struct mmc_blk_request *brq,
    1218                 :            :                                     struct mmc_card *card,
    1219                 :            :                                     struct request *req)
    1220                 :            : {
    1221         [ #  # ]:          0 :         if (!(card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN)) {
    1222                 :            :                 /* Legacy mode imposes restrictions on transfers. */
    1223         [ #  # ]:          0 :                 if (!IS_ALIGNED(blk_rq_pos(req), card->ext_csd.rel_sectors))
    1224                 :          0 :                         brq->data.blocks = 1;
    1225                 :            : 
    1226         [ #  # ]:          0 :                 if (brq->data.blocks > card->ext_csd.rel_sectors)
    1227                 :          0 :                         brq->data.blocks = card->ext_csd.rel_sectors;
    1228         [ #  # ]:          0 :                 else if (brq->data.blocks < card->ext_csd.rel_sectors)
    1229                 :          0 :                         brq->data.blocks = 1;
    1230                 :            :         }
    1231                 :          0 : }
    1232                 :            : 
    1233                 :            : #define CMD_ERRORS_EXCL_OOR                                             \
    1234                 :            :         (R1_ADDRESS_ERROR |     /* Misaligned address */                \
    1235                 :            :          R1_BLOCK_LEN_ERROR |   /* Transferred block length incorrect */\
    1236                 :            :          R1_WP_VIOLATION |      /* Tried to write to protected block */ \
    1237                 :            :          R1_CARD_ECC_FAILED |   /* Card ECC failed */                   \
    1238                 :            :          R1_CC_ERROR |          /* Card controller error */             \
    1239                 :            :          R1_ERROR)              /* General/unknown error */
    1240                 :            : 
    1241                 :            : #define CMD_ERRORS                                                      \
    1242                 :            :         (CMD_ERRORS_EXCL_OOR |                                          \
    1243                 :            :          R1_OUT_OF_RANGE)       /* Command argument out of range */     \
    1244                 :            : 
    1245                 :            : static void mmc_blk_eval_resp_error(struct mmc_blk_request *brq)
    1246                 :            : {
    1247                 :            :         u32 val;
    1248                 :            : 
    1249                 :            :         /*
    1250                 :            :          * Per the SD specification(physical layer version 4.10)[1],
    1251                 :            :          * section 4.3.3, it explicitly states that "When the last
    1252                 :            :          * block of user area is read using CMD18, the host should
    1253                 :            :          * ignore OUT_OF_RANGE error that may occur even the sequence
    1254                 :            :          * is correct". And JESD84-B51 for eMMC also has a similar
    1255                 :            :          * statement on section 6.8.3.
    1256                 :            :          *
    1257                 :            :          * Multiple block read/write could be done by either predefined
    1258                 :            :          * method, namely CMD23, or open-ending mode. For open-ending mode,
    1259                 :            :          * we should ignore the OUT_OF_RANGE error as it's normal behaviour.
    1260                 :            :          *
    1261                 :            :          * However the spec[1] doesn't tell us whether we should also
    1262                 :            :          * ignore that for predefined method. But per the spec[1], section
    1263                 :            :          * 4.15 Set Block Count Command, it says"If illegal block count
    1264                 :            :          * is set, out of range error will be indicated during read/write
    1265                 :            :          * operation (For example, data transfer is stopped at user area
    1266                 :            :          * boundary)." In another word, we could expect a out of range error
    1267                 :            :          * in the response for the following CMD18/25. And if argument of
    1268                 :            :          * CMD23 + the argument of CMD18/25 exceed the max number of blocks,
    1269                 :            :          * we could also expect to get a -ETIMEDOUT or any error number from
    1270                 :            :          * the host drivers due to missing data response(for write)/data(for
    1271                 :            :          * read), as the cards will stop the data transfer by itself per the
    1272                 :            :          * spec. So we only need to check R1_OUT_OF_RANGE for open-ending mode.
    1273                 :            :          */
    1274                 :            : 
    1275         [ +  - ]:    1150935 :         if (!brq->stop.error) {
    1276                 :            :                 bool oor_with_open_end;
    1277                 :            :                 /* If there is no error yet, check R1 response */
    1278                 :            : 
    1279                 :    1150935 :                 val = brq->stop.resp[0] & CMD_ERRORS;
    1280   [ -  +  #  # ]:    1150935 :                 oor_with_open_end = val & R1_OUT_OF_RANGE && !brq->mrq.sbc;
    1281                 :            : 
    1282         [ -  + ]:    1150935 :                 if (val && !oor_with_open_end)
    1283                 :          0 :                         brq->stop.error = -EIO;
    1284                 :            :         }
    1285                 :            : }
    1286                 :            : 
    1287                 :    1150941 : static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
    1288                 :            :                               int disable_multi, bool *do_rel_wr_p,
    1289                 :            :                               bool *do_data_tag_p)
    1290                 :            : {
    1291                 :    1150941 :         struct mmc_blk_data *md = mq->blkdata;
    1292                 :    1150941 :         struct mmc_card *card = md->queue.card;
    1293                 :    1150941 :         struct mmc_blk_request *brq = &mqrq->brq;
    1294                 :            :         struct request *req = mmc_queue_req_to_req(mqrq);
    1295                 :            :         bool do_rel_wr, do_data_tag;
    1296                 :            : 
    1297                 :            :         /*
    1298                 :            :          * Reliable writes are used to implement Forced Unit Access and
    1299                 :            :          * are supported only on MMCs.
    1300                 :            :          */
    1301         [ #  # ]:    2301882 :         do_rel_wr = (req->cmd_flags & REQ_FUA) &&
    1302   [ -  +  #  # ]:    1150941 :                     rq_data_dir(req) == WRITE &&
    1303                 :          0 :                     (md->flags & MMC_BLK_REL_WR);
    1304                 :            : 
    1305                 :    1150941 :         memset(brq, 0, sizeof(struct mmc_blk_request));
    1306                 :            : 
    1307                 :    1150941 :         brq->mrq.data = &brq->data;
    1308                 :    1150941 :         brq->mrq.tag = req->tag;
    1309                 :            : 
    1310                 :    1150941 :         brq->stop.opcode = MMC_STOP_TRANSMISSION;
    1311                 :    1150941 :         brq->stop.arg = 0;
    1312                 :            : 
    1313         [ +  + ]:    1150941 :         if (rq_data_dir(req) == READ) {
    1314                 :    1088918 :                 brq->data.flags = MMC_DATA_READ;
    1315                 :    1088918 :                 brq->stop.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
    1316                 :            :         } else {
    1317                 :      62023 :                 brq->data.flags = MMC_DATA_WRITE;
    1318                 :      62023 :                 brq->stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
    1319                 :            :         }
    1320                 :            : 
    1321                 :    1150941 :         brq->data.blksz = 512;
    1322                 :    1150941 :         brq->data.blocks = blk_rq_sectors(req);
    1323                 :    1150941 :         brq->data.blk_addr = blk_rq_pos(req);
    1324                 :            : 
    1325                 :            :         /*
    1326                 :            :          * The command queue supports 2 priorities: "high" (1) and "simple" (0).
    1327                 :            :          * The eMMC will give "high" priority tasks priority over "simple"
    1328                 :            :          * priority tasks. Here we always set "simple" priority by not setting
    1329                 :            :          * MMC_DATA_PRIO.
    1330                 :            :          */
    1331                 :            : 
    1332                 :            :         /*
    1333                 :            :          * The block layer doesn't support all sector count
    1334                 :            :          * restrictions, so we need to be prepared for too big
    1335                 :            :          * requests.
    1336                 :            :          */
    1337         [ -  + ]:    1150941 :         if (brq->data.blocks > card->host->max_blk_count)
    1338                 :          0 :                 brq->data.blocks = card->host->max_blk_count;
    1339                 :            : 
    1340         [ +  + ]:    1150941 :         if (brq->data.blocks > 1) {
    1341                 :            :                 /*
    1342                 :            :                  * Some SD cards in SPI mode return a CRC error or even lock up
    1343                 :            :                  * completely when trying to read the last block using a
    1344                 :            :                  * multiblock read command.
    1345                 :            :                  */
    1346   [ -  +  #  #  :    1051918 :                 if (mmc_host_is_spi(card->host) && (rq_data_dir(req) == READ) &&
                   #  # ]
    1347                 :          0 :                     (blk_rq_pos(req) + blk_rq_sectors(req) ==
    1348                 :          0 :                      get_capacity(md->disk)))
    1349                 :          0 :                         brq->data.blocks--;
    1350                 :            : 
    1351                 :            :                 /*
    1352                 :            :                  * After a read error, we redo the request one sector
    1353                 :            :                  * at a time in order to accurately determine which
    1354                 :            :                  * sectors can be read successfully.
    1355                 :            :                  */
    1356         [ -  + ]:    1051918 :                 if (disable_multi)
    1357                 :          0 :                         brq->data.blocks = 1;
    1358                 :            : 
    1359                 :            :                 /*
    1360                 :            :                  * Some controllers have HW issues while operating
    1361                 :            :                  * in multiple I/O mode
    1362                 :            :                  */
    1363         [ -  + ]:    1051918 :                 if (card->host->ops->multi_io_quirk)
    1364         [ #  # ]:          0 :                         brq->data.blocks = card->host->ops->multi_io_quirk(card,
    1365                 :          0 :                                                 (rq_data_dir(req) == READ) ?
    1366                 :            :                                                 MMC_DATA_READ : MMC_DATA_WRITE,
    1367                 :          0 :                                                 brq->data.blocks);
    1368                 :            :         }
    1369                 :            : 
    1370         [ -  + ]:    1150941 :         if (do_rel_wr) {
    1371                 :          0 :                 mmc_apply_rel_rw(brq, card, req);
    1372                 :          0 :                 brq->data.flags |= MMC_DATA_REL_WR;
    1373                 :            :         }
    1374                 :            : 
    1375                 :            :         /*
    1376                 :            :          * Data tag is used only during writing meta data to speed
    1377                 :            :          * up write and any subsequent read of this meta data
    1378                 :            :          */
    1379         [ #  # ]:    2301882 :         do_data_tag = card->ext_csd.data_tag_unit_size &&
    1380         [ #  # ]:          0 :                       (req->cmd_flags & REQ_META) &&
    1381   [ -  +  #  # ]:    1150941 :                       (rq_data_dir(req) == WRITE) &&
    1382                 :          0 :                       ((brq->data.blocks * brq->data.blksz) >=
    1383                 :            :                        card->ext_csd.data_tag_unit_size);
    1384                 :            : 
    1385         [ -  + ]:    1150941 :         if (do_data_tag)
    1386                 :          0 :                 brq->data.flags |= MMC_DATA_DAT_TAG;
    1387                 :            : 
    1388                 :    1150941 :         mmc_set_data_timeout(&brq->data, card);
    1389                 :            : 
    1390                 :    1150941 :         brq->data.sg = mqrq->sg;
    1391                 :    1150941 :         brq->data.sg_len = mmc_queue_map_sg(mq, mqrq);
    1392                 :            : 
    1393                 :            :         /*
    1394                 :            :          * Adjust the sg list so it is the same size as the
    1395                 :            :          * request.
    1396                 :            :          */
    1397         [ -  + ]:    2301882 :         if (brq->data.blocks != blk_rq_sectors(req)) {
    1398                 :          0 :                 int i, data_size = brq->data.blocks << 9;
    1399                 :            :                 struct scatterlist *sg;
    1400                 :            : 
    1401         [ #  # ]:          0 :                 for_each_sg(brq->data.sg, sg, brq->data.sg_len, i) {
    1402                 :          0 :                         data_size -= sg->length;
    1403         [ #  # ]:          0 :                         if (data_size <= 0) {
    1404                 :          0 :                                 sg->length += data_size;
    1405                 :          0 :                                 i++;
    1406                 :          0 :                                 break;
    1407                 :            :                         }
    1408                 :            :                 }
    1409                 :          0 :                 brq->data.sg_len = i;
    1410                 :            :         }
    1411                 :            : 
    1412         [ +  - ]:    1150941 :         if (do_rel_wr_p)
    1413                 :    1150941 :                 *do_rel_wr_p = do_rel_wr;
    1414                 :            : 
    1415         [ +  - ]:    1150941 :         if (do_data_tag_p)
    1416                 :    1150941 :                 *do_data_tag_p = do_data_tag;
    1417                 :    1150941 : }
    1418                 :            : 
    1419                 :            : #define MMC_CQE_RETRIES 2
    1420                 :            : 
    1421                 :          0 : static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
    1422                 :            : {
    1423                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1424                 :          0 :         struct mmc_request *mrq = &mqrq->brq.mrq;
    1425                 :          0 :         struct request_queue *q = req->q;
    1426                 :          0 :         struct mmc_host *host = mq->card->host;
    1427                 :          0 :         enum mmc_issue_type issue_type = mmc_issue_type(mq, req);
    1428                 :            :         unsigned long flags;
    1429                 :            :         bool put_card;
    1430                 :            :         int err;
    1431                 :            : 
    1432                 :          0 :         mmc_cqe_post_req(host, mrq);
    1433                 :            : 
    1434   [ #  #  #  # ]:          0 :         if (mrq->cmd && mrq->cmd->error)
    1435                 :            :                 err = mrq->cmd->error;
    1436   [ #  #  #  # ]:          0 :         else if (mrq->data && mrq->data->error)
    1437                 :          0 :                 err = mrq->data->error;
    1438                 :            :         else
    1439                 :            :                 err = 0;
    1440                 :            : 
    1441         [ #  # ]:          0 :         if (err) {
    1442         [ #  # ]:          0 :                 if (mqrq->retries++ < MMC_CQE_RETRIES)
    1443                 :          0 :                         blk_mq_requeue_request(req, true);
    1444                 :            :                 else
    1445                 :          0 :                         blk_mq_end_request(req, BLK_STS_IOERR);
    1446         [ #  # ]:          0 :         } else if (mrq->data) {
    1447         [ #  # ]:          0 :                 if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
    1448                 :          0 :                         blk_mq_requeue_request(req, true);
    1449                 :            :                 else
    1450                 :          0 :                         __blk_mq_end_request(req, BLK_STS_OK);
    1451                 :            :         } else {
    1452                 :          0 :                 blk_mq_end_request(req, BLK_STS_OK);
    1453                 :            :         }
    1454                 :            : 
    1455                 :          0 :         spin_lock_irqsave(&mq->lock, flags);
    1456                 :            : 
    1457                 :          0 :         mq->in_flight[issue_type] -= 1;
    1458                 :            : 
    1459                 :            :         put_card = (mmc_tot_in_flight(mq) == 0);
    1460                 :            : 
    1461                 :          0 :         mmc_cqe_check_busy(mq);
    1462                 :            : 
    1463                 :            :         spin_unlock_irqrestore(&mq->lock, flags);
    1464                 :            : 
    1465         [ #  # ]:          0 :         if (!mq->cqe_busy)
    1466                 :          0 :                 blk_mq_run_hw_queues(q, true);
    1467                 :            : 
    1468         [ #  # ]:          0 :         if (put_card)
    1469                 :          0 :                 mmc_put_card(mq->card, &mq->ctx);
    1470                 :          0 : }
    1471                 :            : 
    1472                 :          0 : void mmc_blk_cqe_recovery(struct mmc_queue *mq)
    1473                 :            : {
    1474                 :          0 :         struct mmc_card *card = mq->card;
    1475                 :          0 :         struct mmc_host *host = card->host;
    1476                 :            :         int err;
    1477                 :            : 
    1478                 :            :         pr_debug("%s: CQE recovery start\n", mmc_hostname(host));
    1479                 :            : 
    1480                 :          0 :         err = mmc_cqe_recovery(host);
    1481         [ #  # ]:          0 :         if (err)
    1482                 :          0 :                 mmc_blk_reset(mq->blkdata, host, MMC_BLK_CQE_RECOVERY);
    1483                 :            :         else
    1484                 :          0 :                 mmc_blk_reset_success(mq->blkdata, MMC_BLK_CQE_RECOVERY);
    1485                 :            : 
    1486                 :            :         pr_debug("%s: CQE recovery done\n", mmc_hostname(host));
    1487                 :          0 : }
    1488                 :            : 
    1489                 :          0 : static void mmc_blk_cqe_req_done(struct mmc_request *mrq)
    1490                 :            : {
    1491                 :            :         struct mmc_queue_req *mqrq = container_of(mrq, struct mmc_queue_req,
    1492                 :            :                                                   brq.mrq);
    1493                 :            :         struct request *req = mmc_queue_req_to_req(mqrq);
    1494                 :          0 :         struct request_queue *q = req->q;
    1495                 :          0 :         struct mmc_queue *mq = q->queuedata;
    1496                 :            : 
    1497                 :            :         /*
    1498                 :            :          * Block layer timeouts race with completions which means the normal
    1499                 :            :          * completion path cannot be used during recovery.
    1500                 :            :          */
    1501         [ #  # ]:          0 :         if (mq->in_recovery)
    1502                 :          0 :                 mmc_blk_cqe_complete_rq(mq, req);
    1503                 :            :         else
    1504                 :          0 :                 blk_mq_complete_request(req);
    1505                 :          0 : }
    1506                 :            : 
    1507                 :            : static int mmc_blk_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq)
    1508                 :            : {
    1509                 :          0 :         mrq->done            = mmc_blk_cqe_req_done;
    1510                 :          0 :         mrq->recovery_notifier       = mmc_cqe_recovery_notifier;
    1511                 :            : 
    1512                 :          0 :         return mmc_cqe_start_req(host, mrq);
    1513                 :            : }
    1514                 :            : 
    1515                 :            : static struct mmc_request *mmc_blk_cqe_prep_dcmd(struct mmc_queue_req *mqrq,
    1516                 :            :                                                  struct request *req)
    1517                 :            : {
    1518                 :          0 :         struct mmc_blk_request *brq = &mqrq->brq;
    1519                 :            : 
    1520                 :          0 :         memset(brq, 0, sizeof(*brq));
    1521                 :            : 
    1522                 :          0 :         brq->mrq.cmd = &brq->cmd;
    1523                 :          0 :         brq->mrq.tag = req->tag;
    1524                 :            : 
    1525                 :          0 :         return &brq->mrq;
    1526                 :            : }
    1527                 :            : 
    1528                 :          0 : static int mmc_blk_cqe_issue_flush(struct mmc_queue *mq, struct request *req)
    1529                 :            : {
    1530                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1531                 :            :         struct mmc_request *mrq = mmc_blk_cqe_prep_dcmd(mqrq, req);
    1532                 :            : 
    1533                 :          0 :         mrq->cmd->opcode = MMC_SWITCH;
    1534                 :          0 :         mrq->cmd->arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) |
    1535                 :            :                         (EXT_CSD_FLUSH_CACHE << 16) |
    1536                 :            :                         (1 << 8) |
    1537                 :            :                         EXT_CSD_CMD_SET_NORMAL;
    1538                 :          0 :         mrq->cmd->flags = MMC_CMD_AC | MMC_RSP_R1B;
    1539                 :            : 
    1540                 :          0 :         return mmc_blk_cqe_start_req(mq->card->host, mrq);
    1541                 :            : }
    1542                 :            : 
    1543                 :          0 : static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue *mq, struct request *req)
    1544                 :            : {
    1545                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1546                 :            : 
    1547                 :          0 :         mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL);
    1548                 :            : 
    1549                 :          0 :         return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
    1550                 :            : }
    1551                 :            : 
    1552                 :    1150941 : static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
    1553                 :            :                                struct mmc_card *card,
    1554                 :            :                                int disable_multi,
    1555                 :            :                                struct mmc_queue *mq)
    1556                 :            : {
    1557                 :            :         u32 readcmd, writecmd;
    1558                 :            :         struct mmc_blk_request *brq = &mqrq->brq;
    1559                 :            :         struct request *req = mmc_queue_req_to_req(mqrq);
    1560                 :    1150941 :         struct mmc_blk_data *md = mq->blkdata;
    1561                 :            :         bool do_rel_wr, do_data_tag;
    1562                 :            : 
    1563                 :    1150941 :         mmc_blk_data_prep(mq, mqrq, disable_multi, &do_rel_wr, &do_data_tag);
    1564                 :            : 
    1565                 :    1150941 :         brq->mrq.cmd = &brq->cmd;
    1566                 :            : 
    1567                 :    1150941 :         brq->cmd.arg = blk_rq_pos(req);
    1568         [ -  + ]:    1150941 :         if (!mmc_card_blockaddr(card))
    1569                 :          0 :                 brq->cmd.arg <<= 9;
    1570                 :    1150941 :         brq->cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
    1571                 :            : 
    1572   [ +  +  -  + ]:    1150941 :         if (brq->data.blocks > 1 || do_rel_wr) {
    1573                 :            :                 /* SPI multiblock writes terminate using a special
    1574                 :            :                  * token, not a STOP_TRANSMISSION request.
    1575                 :            :                  */
    1576   [ -  +  #  # ]:    1051918 :                 if (!mmc_host_is_spi(card->host) ||
    1577                 :          0 :                     rq_data_dir(req) == READ)
    1578                 :    1051918 :                         brq->mrq.stop = &brq->stop;
    1579                 :            :                 readcmd = MMC_READ_MULTIPLE_BLOCK;
    1580                 :            :                 writecmd = MMC_WRITE_MULTIPLE_BLOCK;
    1581                 :            :         } else {
    1582                 :      99023 :                 brq->mrq.stop = NULL;
    1583                 :            :                 readcmd = MMC_READ_SINGLE_BLOCK;
    1584                 :            :                 writecmd = MMC_WRITE_BLOCK;
    1585                 :            :         }
    1586         [ +  + ]:    2301882 :         brq->cmd.opcode = rq_data_dir(req) == READ ? readcmd : writecmd;
    1587                 :            : 
    1588                 :            :         /*
    1589                 :            :          * Pre-defined multi-block transfers are preferable to
    1590                 :            :          * open ended-ones (and necessary for reliable writes).
    1591                 :            :          * However, it is not sufficient to just send CMD23,
    1592                 :            :          * and avoid the final CMD12, as on an error condition
    1593                 :            :          * CMD12 (stop) needs to be sent anyway. This, coupled
    1594                 :            :          * with Auto-CMD23 enhancements provided by some
    1595                 :            :          * hosts, means that the complexity of dealing
    1596                 :            :          * with this is best left to the host. If CMD23 is
    1597                 :            :          * supported by card and host, we'll fill sbc in and let
    1598                 :            :          * the host deal with handling it correctly. This means
    1599                 :            :          * that for hosts that don't expose MMC_CAP_CMD23, no
    1600                 :            :          * change of behavior will be observed.
    1601                 :            :          *
    1602                 :            :          * N.B: Some MMC cards experience perf degradation.
    1603                 :            :          * We'll avoid using CMD23-bounded multiblock writes for
    1604                 :            :          * these, while retaining features like reliable writes.
    1605                 :            :          */
    1606   [ +  -  +  +  :    3353800 :         if ((md->flags & MMC_BLK_CMD23) && mmc_op_multi(brq->cmd.opcode) &&
                   +  - ]
    1607   [ -  +  #  # ]:    2103836 :             (do_rel_wr || !(card->quirks & MMC_QUIRK_BLK_NO_CMD23) ||
    1608                 :            :              do_data_tag)) {
    1609                 :    1051918 :                 brq->sbc.opcode = MMC_SET_BLOCK_COUNT;
    1610         [ +  - ]:    2103836 :                 brq->sbc.arg = brq->data.blocks |
    1611         [ +  - ]:    1051918 :                         (do_rel_wr ? (1 << 31) : 0) |
    1612                 :    1051918 :                         (do_data_tag ? (1 << 29) : 0);
    1613                 :    1051918 :                 brq->sbc.flags = MMC_RSP_R1 | MMC_CMD_AC;
    1614                 :    1051918 :                 brq->mrq.sbc = &brq->sbc;
    1615                 :            :         }
    1616                 :    1150941 : }
    1617                 :            : 
    1618                 :            : #define MMC_MAX_RETRIES         5
    1619                 :            : #define MMC_DATA_RETRIES        2
    1620                 :            : #define MMC_NO_RETRIES          (MMC_MAX_RETRIES + 1)
    1621                 :            : 
    1622                 :          0 : static int mmc_blk_send_stop(struct mmc_card *card, unsigned int timeout)
    1623                 :            : {
    1624                 :          0 :         struct mmc_command cmd = {
    1625                 :            :                 .opcode = MMC_STOP_TRANSMISSION,
    1626                 :            :                 .flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC,
    1627                 :            :                 /* Some hosts wait for busy anyway, so provide a busy timeout */
    1628                 :            :                 .busy_timeout = timeout,
    1629                 :            :         };
    1630                 :            : 
    1631                 :          0 :         return mmc_wait_for_cmd(card->host, &cmd, 5);
    1632                 :            : }
    1633                 :            : 
    1634                 :          0 : static int mmc_blk_fix_state(struct mmc_card *card, struct request *req)
    1635                 :            : {
    1636                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1637                 :            :         struct mmc_blk_request *brq = &mqrq->brq;
    1638                 :          0 :         unsigned int timeout = mmc_blk_data_timeout_ms(card->host, &brq->data);
    1639                 :            :         int err;
    1640                 :            : 
    1641                 :          0 :         mmc_retune_hold_now(card->host);
    1642                 :            : 
    1643                 :          0 :         mmc_blk_send_stop(card, timeout);
    1644                 :            : 
    1645                 :          0 :         err = card_busy_detect(card, timeout, NULL);
    1646                 :            : 
    1647                 :          0 :         mmc_retune_release(card->host);
    1648                 :            : 
    1649                 :          0 :         return err;
    1650                 :            : }
    1651                 :            : 
    1652                 :            : #define MMC_READ_SINGLE_RETRIES 2
    1653                 :            : 
    1654                 :            : /* Single sector read during recovery */
    1655                 :          0 : static void mmc_blk_read_single(struct mmc_queue *mq, struct request *req)
    1656                 :            : {
    1657                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1658                 :          0 :         struct mmc_request *mrq = &mqrq->brq.mrq;
    1659                 :          0 :         struct mmc_card *card = mq->card;
    1660                 :          0 :         struct mmc_host *host = card->host;
    1661                 :            :         blk_status_t error = BLK_STS_OK;
    1662                 :            :         int retries = 0;
    1663                 :            : 
    1664                 :            :         do {
    1665                 :            :                 u32 status;
    1666                 :            :                 int err;
    1667                 :            : 
    1668                 :          0 :                 mmc_blk_rw_rq_prep(mqrq, card, 1, mq);
    1669                 :            : 
    1670                 :          0 :                 mmc_wait_for_req(host, mrq);
    1671                 :            : 
    1672                 :          0 :                 err = mmc_send_status(card, &status);
    1673         [ #  # ]:          0 :                 if (err)
    1674                 :            :                         goto error_exit;
    1675                 :            : 
    1676   [ #  #  #  # ]:          0 :                 if (!mmc_host_is_spi(host) &&
    1677                 :          0 :                     !mmc_blk_in_tran_state(status)) {
    1678                 :          0 :                         err = mmc_blk_fix_state(card, req);
    1679         [ #  # ]:          0 :                         if (err)
    1680                 :            :                                 goto error_exit;
    1681                 :            :                 }
    1682                 :            : 
    1683   [ #  #  #  # ]:          0 :                 if (mrq->cmd->error && retries++ < MMC_READ_SINGLE_RETRIES)
    1684                 :          0 :                         continue;
    1685                 :            : 
    1686                 :            :                 retries = 0;
    1687                 :            : 
    1688   [ #  #  #  # ]:          0 :                 if (mrq->cmd->error ||
    1689         [ #  # ]:          0 :                     mrq->data->error ||
    1690         [ #  # ]:          0 :                     (!mmc_host_is_spi(host) &&
    1691         [ #  # ]:          0 :                      (mrq->cmd->resp[0] & CMD_ERRORS || status & CMD_ERRORS)))
    1692                 :            :                         error = BLK_STS_IOERR;
    1693                 :            :                 else
    1694                 :            :                         error = BLK_STS_OK;
    1695                 :            : 
    1696         [ #  # ]:          0 :         } while (blk_update_request(req, error, 512));
    1697                 :            : 
    1698                 :          0 :         return;
    1699                 :            : 
    1700                 :            : error_exit:
    1701                 :          0 :         mrq->data->bytes_xfered = 0;
    1702                 :          0 :         blk_update_request(req, BLK_STS_IOERR, 512);
    1703                 :            :         /* Let it try the remaining request again */
    1704         [ #  # ]:          0 :         if (mqrq->retries > MMC_MAX_RETRIES - 1)
    1705                 :          0 :                 mqrq->retries = MMC_MAX_RETRIES - 1;
    1706                 :            : }
    1707                 :            : 
    1708                 :            : static inline bool mmc_blk_oor_valid(struct mmc_blk_request *brq)
    1709                 :            : {
    1710                 :      62017 :         return !!brq->mrq.sbc;
    1711                 :            : }
    1712                 :            : 
    1713                 :            : static inline u32 mmc_blk_stop_err_bits(struct mmc_blk_request *brq)
    1714                 :            : {
    1715   [ +  +  #  # ]:      62017 :         return mmc_blk_oor_valid(brq) ? CMD_ERRORS : CMD_ERRORS_EXCL_OOR;
    1716                 :            : }
    1717                 :            : 
    1718                 :            : /*
    1719                 :            :  * Check for errors the host controller driver might not have seen such as
    1720                 :            :  * response mode errors or invalid card state.
    1721                 :            :  */
    1722                 :          0 : static bool mmc_blk_status_error(struct request *req, u32 status)
    1723                 :            : {
    1724                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1725                 :            :         struct mmc_blk_request *brq = &mqrq->brq;
    1726                 :          0 :         struct mmc_queue *mq = req->q->queuedata;
    1727                 :            :         u32 stop_err_bits;
    1728                 :            : 
    1729         [ #  # ]:          0 :         if (mmc_host_is_spi(mq->card->host))
    1730                 :            :                 return false;
    1731                 :            : 
    1732                 :            :         stop_err_bits = mmc_blk_stop_err_bits(brq);
    1733                 :            : 
    1734         [ #  # ]:          0 :         return brq->cmd.resp[0]  & CMD_ERRORS    ||
    1735         [ #  # ]:          0 :                brq->stop.resp[0] & stop_err_bits ||
    1736   [ #  #  #  # ]:          0 :                status            & stop_err_bits ||
    1737         [ #  # ]:          0 :                (rq_data_dir(req) == WRITE && !mmc_blk_in_tran_state(status));
    1738                 :            : }
    1739                 :            : 
    1740                 :            : static inline bool mmc_blk_cmd_started(struct mmc_blk_request *brq)
    1741                 :            : {
    1742   [ #  #  #  #  :          0 :         return !brq->sbc.error && !brq->cmd.error &&
                   #  # ]
    1743                 :          0 :                !(brq->cmd.resp[0] & CMD_ERRORS);
    1744                 :            : }
    1745                 :            : 
    1746                 :            : /*
    1747                 :            :  * Requests are completed by mmc_blk_mq_complete_rq() which sets simple
    1748                 :            :  * policy:
    1749                 :            :  * 1. A request that has transferred at least some data is considered
    1750                 :            :  * successful and will be requeued if there is remaining data to
    1751                 :            :  * transfer.
    1752                 :            :  * 2. Otherwise the number of retries is incremented and the request
    1753                 :            :  * will be requeued if there are remaining retries.
    1754                 :            :  * 3. Otherwise the request will be errored out.
    1755                 :            :  * That means mmc_blk_mq_complete_rq() is controlled by bytes_xfered and
    1756                 :            :  * mqrq->retries. So there are only 4 possible actions here:
    1757                 :            :  *      1. do not accept the bytes_xfered value i.e. set it to zero
    1758                 :            :  *      2. change mqrq->retries to determine the number of retries
    1759                 :            :  *      3. try to reset the card
    1760                 :            :  *      4. read one sector at a time
    1761                 :            :  */
    1762                 :          0 : static void mmc_blk_mq_rw_recovery(struct mmc_queue *mq, struct request *req)
    1763                 :            : {
    1764         [ #  # ]:          0 :         int type = rq_data_dir(req) == READ ? MMC_BLK_READ : MMC_BLK_WRITE;
    1765                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1766                 :            :         struct mmc_blk_request *brq = &mqrq->brq;
    1767                 :          0 :         struct mmc_blk_data *md = mq->blkdata;
    1768                 :          0 :         struct mmc_card *card = mq->card;
    1769                 :            :         u32 status;
    1770                 :            :         u32 blocks;
    1771                 :            :         int err;
    1772                 :            : 
    1773                 :            :         /*
    1774                 :            :          * Some errors the host driver might not have seen. Set the number of
    1775                 :            :          * bytes transferred to zero in that case.
    1776                 :            :          */
    1777                 :          0 :         err = __mmc_send_status(card, &status, 0);
    1778   [ #  #  #  # ]:          0 :         if (err || mmc_blk_status_error(req, status))
    1779                 :          0 :                 brq->data.bytes_xfered = 0;
    1780                 :            : 
    1781                 :          0 :         mmc_retune_release(card->host);
    1782                 :            : 
    1783                 :            :         /*
    1784                 :            :          * Try again to get the status. This also provides an opportunity for
    1785                 :            :          * re-tuning.
    1786                 :            :          */
    1787         [ #  # ]:          0 :         if (err)
    1788                 :          0 :                 err = __mmc_send_status(card, &status, 0);
    1789                 :            : 
    1790                 :            :         /*
    1791                 :            :          * Nothing more to do after the number of bytes transferred has been
    1792                 :            :          * updated and there is no card.
    1793                 :            :          */
    1794   [ #  #  #  # ]:          0 :         if (err && mmc_detect_card_removed(card->host))
    1795                 :          0 :                 return;
    1796                 :            : 
    1797                 :            :         /* Try to get back to "tran" state */
    1798   [ #  #  #  # ]:          0 :         if (!mmc_host_is_spi(mq->card->host) &&
    1799         [ #  # ]:          0 :             (err || !mmc_blk_in_tran_state(status)))
    1800                 :          0 :                 err = mmc_blk_fix_state(mq->card, req);
    1801                 :            : 
    1802                 :            :         /*
    1803                 :            :          * Special case for SD cards where the card might record the number of
    1804                 :            :          * blocks written.
    1805                 :            :          */
    1806   [ #  #  #  #  :          0 :         if (!err && mmc_blk_cmd_started(brq) && mmc_card_sd(card) &&
             #  #  #  # ]
    1807                 :          0 :             rq_data_dir(req) == WRITE) {
    1808         [ #  # ]:          0 :                 if (mmc_sd_num_wr_blocks(card, &blocks))
    1809                 :          0 :                         brq->data.bytes_xfered = 0;
    1810                 :            :                 else
    1811                 :          0 :                         brq->data.bytes_xfered = blocks << 9;
    1812                 :            :         }
    1813                 :            : 
    1814                 :            :         /* Reset if the card is in a bad state */
    1815   [ #  #  #  # ]:          0 :         if (!mmc_host_is_spi(mq->card->host) &&
    1816         [ #  # ]:          0 :             err && mmc_blk_reset(md, card->host, type)) {
    1817                 :          0 :                 pr_err("%s: recovery failed!\n", req->rq_disk->disk_name);
    1818                 :          0 :                 mqrq->retries = MMC_NO_RETRIES;
    1819                 :          0 :                 return;
    1820                 :            :         }
    1821                 :            : 
    1822                 :            :         /*
    1823                 :            :          * If anything was done, just return and if there is anything remaining
    1824                 :            :          * on the request it will get requeued.
    1825                 :            :          */
    1826         [ #  # ]:          0 :         if (brq->data.bytes_xfered)
    1827                 :            :                 return;
    1828                 :            : 
    1829                 :            :         /* Reset before last retry */
    1830         [ #  # ]:          0 :         if (mqrq->retries + 1 == MMC_MAX_RETRIES)
    1831                 :          0 :                 mmc_blk_reset(md, card->host, type);
    1832                 :            : 
    1833                 :            :         /* Command errors fail fast, so use all MMC_MAX_RETRIES */
    1834   [ #  #  #  # ]:          0 :         if (brq->sbc.error || brq->cmd.error)
    1835                 :            :                 return;
    1836                 :            : 
    1837                 :            :         /* Reduce the remaining retries for data errors */
    1838         [ #  # ]:          0 :         if (mqrq->retries < MMC_MAX_RETRIES - MMC_DATA_RETRIES) {
    1839                 :          0 :                 mqrq->retries = MMC_MAX_RETRIES - MMC_DATA_RETRIES;
    1840                 :          0 :                 return;
    1841                 :            :         }
    1842                 :            : 
    1843                 :            :         /* FIXME: Missing single sector read for large sector size */
    1844   [ #  #  #  #  :          0 :         if (!mmc_large_sector(card) && rq_data_dir(req) == READ &&
                   #  # ]
    1845                 :          0 :             brq->data.blocks > 1) {
    1846                 :            :                 /* Read one sector at a time */
    1847                 :          0 :                 mmc_blk_read_single(mq, req);
    1848                 :          0 :                 return;
    1849                 :            :         }
    1850                 :            : }
    1851                 :            : 
    1852                 :    1150935 : static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq)
    1853                 :            : {
    1854                 :            :         mmc_blk_eval_resp_error(brq);
    1855                 :            : 
    1856   [ +  -  +  -  :    4603740 :         return brq->sbc.error || brq->cmd.error || brq->stop.error ||
                   +  - ]
    1857   [ +  -  +  - ]:    3452805 :                brq->data.error || brq->cmd.resp[0] & CMD_ERRORS;
    1858                 :            : }
    1859                 :            : 
    1860                 :    1150935 : static int mmc_blk_card_busy(struct mmc_card *card, struct request *req)
    1861                 :            : {
    1862                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1863                 :    1150935 :         u32 status = 0;
    1864                 :            :         int err;
    1865                 :            : 
    1866   [ +  -  +  + ]:    2301870 :         if (mmc_host_is_spi(card->host) || rq_data_dir(req) == READ)
    1867                 :            :                 return 0;
    1868                 :            : 
    1869                 :      62017 :         err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, &status);
    1870                 :            : 
    1871                 :            :         /*
    1872                 :            :          * Do not assume data transferred correctly if there are any error bits
    1873                 :            :          * set.
    1874                 :            :          */
    1875         [ -  + ]:      62017 :         if (status & mmc_blk_stop_err_bits(&mqrq->brq)) {
    1876                 :          0 :                 mqrq->brq.data.bytes_xfered = 0;
    1877         [ #  # ]:          0 :                 err = err ? err : -EIO;
    1878                 :            :         }
    1879                 :            : 
    1880                 :            :         /* Copy the exception bit so it will be seen later on */
    1881   [ -  +  #  # ]:      62017 :         if (mmc_card_mmc(card) && status & R1_EXCEPTION_EVENT)
    1882                 :          0 :                 mqrq->brq.cmd.resp[0] |= R1_EXCEPTION_EVENT;
    1883                 :            : 
    1884                 :      62017 :         return err;
    1885                 :            : }
    1886                 :            : 
    1887                 :            : static inline void mmc_blk_rw_reset_success(struct mmc_queue *mq,
    1888                 :            :                                             struct request *req)
    1889                 :            : {
    1890   [ #  #  +  + ]:    2301870 :         int type = rq_data_dir(req) == READ ? MMC_BLK_READ : MMC_BLK_WRITE;
    1891                 :            : 
    1892                 :    1150935 :         mmc_blk_reset_success(mq->blkdata, type);
    1893                 :            : }
    1894                 :            : 
    1895                 :    1150935 : static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
    1896                 :            : {
    1897                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1898                 :    1150935 :         unsigned int nr_bytes = mqrq->brq.data.bytes_xfered;
    1899                 :            : 
    1900         [ +  - ]:    1150935 :         if (nr_bytes) {
    1901         [ -  + ]:    1150935 :                 if (blk_update_request(req, BLK_STS_OK, nr_bytes))
    1902                 :          0 :                         blk_mq_requeue_request(req, true);
    1903                 :            :                 else
    1904                 :    1150928 :                         __blk_mq_end_request(req, BLK_STS_OK);
    1905         [ #  # ]:          0 :         } else if (!blk_rq_bytes(req)) {
    1906                 :          0 :                 __blk_mq_end_request(req, BLK_STS_IOERR);
    1907         [ #  # ]:          0 :         } else if (mqrq->retries++ < MMC_MAX_RETRIES) {
    1908                 :          0 :                 blk_mq_requeue_request(req, true);
    1909                 :            :         } else {
    1910   [ #  #  #  # ]:          0 :                 if (mmc_card_removed(mq->card))
    1911                 :          0 :                         req->rq_flags |= RQF_QUIET;
    1912                 :          0 :                 blk_mq_end_request(req, BLK_STS_IOERR);
    1913                 :            :         }
    1914                 :    1150933 : }
    1915                 :            : 
    1916                 :    1150935 : static bool mmc_blk_urgent_bkops_needed(struct mmc_queue *mq,
    1917                 :            :                                         struct mmc_queue_req *mqrq)
    1918                 :            : {
    1919   [ -  +  #  #  :    2301870 :         return mmc_card_mmc(mq->card) && !mmc_host_is_spi(mq->card->host) &&
                   #  # ]
    1920         [ #  # ]:          0 :                (mqrq->brq.cmd.resp[0] & R1_EXCEPTION_EVENT ||
    1921                 :          0 :                 mqrq->brq.stop.resp[0] & R1_EXCEPTION_EVENT);
    1922                 :            : }
    1923                 :            : 
    1924                 :    1150935 : static void mmc_blk_urgent_bkops(struct mmc_queue *mq,
    1925                 :            :                                  struct mmc_queue_req *mqrq)
    1926                 :            : {
    1927         [ -  + ]:    1150935 :         if (mmc_blk_urgent_bkops_needed(mq, mqrq))
    1928                 :          0 :                 mmc_run_bkops(mq->card);
    1929                 :    1150935 : }
    1930                 :            : 
    1931                 :    1150935 : void mmc_blk_mq_complete(struct request *req)
    1932                 :            : {
    1933                 :    1150935 :         struct mmc_queue *mq = req->q->queuedata;
    1934                 :            : 
    1935         [ -  + ]:    1150935 :         if (mq->use_cqe)
    1936                 :          0 :                 mmc_blk_cqe_complete_rq(mq, req);
    1937                 :            :         else
    1938                 :    1150935 :                 mmc_blk_mq_complete_rq(mq, req);
    1939                 :    1150928 : }
    1940                 :            : 
    1941                 :    1150935 : static void mmc_blk_mq_poll_completion(struct mmc_queue *mq,
    1942                 :            :                                        struct request *req)
    1943                 :            : {
    1944                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1945                 :    1150935 :         struct mmc_host *host = mq->card->host;
    1946                 :            : 
    1947   [ +  -  -  + ]:    2301870 :         if (mmc_blk_rq_error(&mqrq->brq) ||
    1948                 :    1150935 :             mmc_blk_card_busy(mq->card, req)) {
    1949                 :          0 :                 mmc_blk_mq_rw_recovery(mq, req);
    1950                 :            :         } else {
    1951                 :            :                 mmc_blk_rw_reset_success(mq, req);
    1952                 :    1150935 :                 mmc_retune_release(host);
    1953                 :            :         }
    1954                 :            : 
    1955                 :    1150935 :         mmc_blk_urgent_bkops(mq, mqrq);
    1956                 :    1150935 : }
    1957                 :            : 
    1958                 :    1150935 : static void mmc_blk_mq_dec_in_flight(struct mmc_queue *mq, struct request *req)
    1959                 :            : {
    1960                 :            :         unsigned long flags;
    1961                 :            :         bool put_card;
    1962                 :            : 
    1963                 :    1150935 :         spin_lock_irqsave(&mq->lock, flags);
    1964                 :            : 
    1965                 :    1150935 :         mq->in_flight[mmc_issue_type(mq, req)] -= 1;
    1966                 :            : 
    1967                 :            :         put_card = (mmc_tot_in_flight(mq) == 0);
    1968                 :            : 
    1969                 :            :         spin_unlock_irqrestore(&mq->lock, flags);
    1970                 :            : 
    1971         [ +  + ]:    1150935 :         if (put_card)
    1972                 :     756414 :                 mmc_put_card(mq->card, &mq->ctx);
    1973                 :    1150935 : }
    1974                 :            : 
    1975                 :    1150935 : static void mmc_blk_mq_post_req(struct mmc_queue *mq, struct request *req)
    1976                 :            : {
    1977                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    1978                 :    1150935 :         struct mmc_request *mrq = &mqrq->brq.mrq;
    1979                 :    1150935 :         struct mmc_host *host = mq->card->host;
    1980                 :            : 
    1981                 :            :         mmc_post_req(host, mrq, 0);
    1982                 :            : 
    1983                 :            :         /*
    1984                 :            :          * Block layer timeouts race with completions which means the normal
    1985                 :            :          * completion path cannot be used during recovery.
    1986                 :            :          */
    1987         [ -  + ]:    1150935 :         if (mq->in_recovery)
    1988                 :          0 :                 mmc_blk_mq_complete_rq(mq, req);
    1989                 :            :         else
    1990                 :    1150935 :                 blk_mq_complete_request(req);
    1991                 :            : 
    1992                 :    1150935 :         mmc_blk_mq_dec_in_flight(mq, req);
    1993                 :    1150935 : }
    1994                 :            : 
    1995                 :          0 : void mmc_blk_mq_recovery(struct mmc_queue *mq)
    1996                 :            : {
    1997                 :          0 :         struct request *req = mq->recovery_req;
    1998                 :          0 :         struct mmc_host *host = mq->card->host;
    1999                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    2000                 :            : 
    2001                 :          0 :         mq->recovery_req = NULL;
    2002                 :          0 :         mq->rw_wait = false;
    2003                 :            : 
    2004         [ #  # ]:          0 :         if (mmc_blk_rq_error(&mqrq->brq)) {
    2005                 :            :                 mmc_retune_hold_now(host);
    2006                 :          0 :                 mmc_blk_mq_rw_recovery(mq, req);
    2007                 :            :         }
    2008                 :            : 
    2009                 :          0 :         mmc_blk_urgent_bkops(mq, mqrq);
    2010                 :            : 
    2011                 :          0 :         mmc_blk_mq_post_req(mq, req);
    2012                 :          0 : }
    2013                 :            : 
    2014                 :    1946361 : static void mmc_blk_mq_complete_prev_req(struct mmc_queue *mq,
    2015                 :            :                                          struct request **prev_req)
    2016                 :            : {
    2017         [ +  + ]:    3892722 :         if (mmc_host_done_complete(mq->card->host))
    2018                 :    1946382 :                 return;
    2019                 :            : 
    2020                 :    1946353 :         mutex_lock(&mq->complete_lock);
    2021                 :            : 
    2022         [ +  + ]:    1946374 :         if (!mq->complete_req)
    2023                 :            :                 goto out_unlock;
    2024                 :            : 
    2025                 :    1150935 :         mmc_blk_mq_poll_completion(mq, mq->complete_req);
    2026                 :            : 
    2027         [ +  + ]:    1150935 :         if (prev_req)
    2028                 :     385188 :                 *prev_req = mq->complete_req;
    2029                 :            :         else
    2030                 :     765747 :                 mmc_blk_mq_post_req(mq, mq->complete_req);
    2031                 :            : 
    2032                 :    1150935 :         mq->complete_req = NULL;
    2033                 :            : 
    2034                 :            : out_unlock:
    2035                 :    1946374 :         mutex_unlock(&mq->complete_lock);
    2036                 :            : }
    2037                 :            : 
    2038                 :     795436 : void mmc_blk_mq_complete_work(struct work_struct *work)
    2039                 :            : {
    2040                 :     795436 :         struct mmc_queue *mq = container_of(work, struct mmc_queue,
    2041                 :            :                                             complete_work);
    2042                 :            : 
    2043                 :     795436 :         mmc_blk_mq_complete_prev_req(mq, NULL);
    2044                 :     795436 : }
    2045                 :            : 
    2046                 :    1150935 : static void mmc_blk_mq_req_done(struct mmc_request *mrq)
    2047                 :            : {
    2048                 :            :         struct mmc_queue_req *mqrq = container_of(mrq, struct mmc_queue_req,
    2049                 :            :                                                   brq.mrq);
    2050                 :            :         struct request *req = mmc_queue_req_to_req(mqrq);
    2051                 :    1150935 :         struct request_queue *q = req->q;
    2052                 :    1150935 :         struct mmc_queue *mq = q->queuedata;
    2053                 :    1150935 :         struct mmc_host *host = mq->card->host;
    2054                 :            :         unsigned long flags;
    2055                 :            : 
    2056         [ +  - ]:    1150935 :         if (!mmc_host_done_complete(host)) {
    2057                 :            :                 bool waiting;
    2058                 :            : 
    2059                 :            :                 /*
    2060                 :            :                  * We cannot complete the request in this context, so record
    2061                 :            :                  * that there is a request to complete, and that a following
    2062                 :            :                  * request does not need to wait (although it does need to
    2063                 :            :                  * complete complete_req first).
    2064                 :            :                  */
    2065                 :    1150935 :                 spin_lock_irqsave(&mq->lock, flags);
    2066                 :    1150935 :                 mq->complete_req = req;
    2067                 :    1150935 :                 mq->rw_wait = false;
    2068                 :    1150935 :                 waiting = mq->waiting;
    2069                 :            :                 spin_unlock_irqrestore(&mq->lock, flags);
    2070                 :            : 
    2071                 :            :                 /*
    2072                 :            :                  * If 'waiting' then the waiting task will complete this
    2073                 :            :                  * request, otherwise queue a work to do it. Note that
    2074                 :            :                  * complete_work may still race with the dispatch of a following
    2075                 :            :                  * request.
    2076                 :            :                  */
    2077         [ +  + ]:    1150935 :                 if (waiting)
    2078                 :     354928 :                         wake_up(&mq->wait);
    2079                 :            :                 else
    2080                 :     796007 :                         queue_work(mq->card->complete_wq, &mq->complete_work);
    2081                 :            : 
    2082                 :            :                 return;
    2083                 :            :         }
    2084                 :            : 
    2085                 :            :         /* Take the recovery path for errors or urgent background operations */
    2086   [ #  #  #  # ]:          0 :         if (mmc_blk_rq_error(&mqrq->brq) ||
    2087                 :          0 :             mmc_blk_urgent_bkops_needed(mq, mqrq)) {
    2088                 :          0 :                 spin_lock_irqsave(&mq->lock, flags);
    2089                 :          0 :                 mq->recovery_needed = true;
    2090                 :          0 :                 mq->recovery_req = req;
    2091                 :            :                 spin_unlock_irqrestore(&mq->lock, flags);
    2092                 :          0 :                 wake_up(&mq->wait);
    2093                 :          0 :                 schedule_work(&mq->recovery_work);
    2094                 :            :                 return;
    2095                 :            :         }
    2096                 :            : 
    2097                 :            :         mmc_blk_rw_reset_success(mq, req);
    2098                 :            : 
    2099                 :          0 :         mq->rw_wait = false;
    2100                 :          0 :         wake_up(&mq->wait);
    2101                 :            : 
    2102                 :          0 :         mmc_blk_mq_post_req(mq, req);
    2103                 :            : }
    2104                 :            : 
    2105                 :    1857196 : static bool mmc_blk_rw_wait_cond(struct mmc_queue *mq, int *err)
    2106                 :            : {
    2107                 :            :         unsigned long flags;
    2108                 :            :         bool done;
    2109                 :            : 
    2110                 :            :         /*
    2111                 :            :          * Wait while there is another request in progress, but not if recovery
    2112                 :            :          * is needed. Also indicate whether there is a request waiting to start.
    2113                 :            :          */
    2114                 :    1857196 :         spin_lock_irqsave(&mq->lock, flags);
    2115         [ -  + ]:    1857196 :         if (mq->recovery_needed) {
    2116                 :          0 :                 *err = -EBUSY;
    2117                 :            :                 done = true;
    2118                 :            :         } else {
    2119                 :    1857196 :                 done = !mq->rw_wait;
    2120                 :            :         }
    2121                 :    1857196 :         mq->waiting = !done;
    2122                 :            :         spin_unlock_irqrestore(&mq->lock, flags);
    2123                 :            : 
    2124                 :    1857196 :         return done;
    2125                 :            : }
    2126                 :            : 
    2127                 :    1150941 : static int mmc_blk_rw_wait(struct mmc_queue *mq, struct request **prev_req)
    2128                 :            : {
    2129                 :    1150941 :         int err = 0;
    2130                 :            : 
    2131   [ +  +  +  + ]:    1150941 :         wait_event(mq->wait, mmc_blk_rw_wait_cond(mq, &err));
    2132                 :            : 
    2133                 :            :         /* Always complete the previous request if there is one */
    2134                 :    1150938 :         mmc_blk_mq_complete_prev_req(mq, prev_req);
    2135                 :            : 
    2136                 :    1150938 :         return err;
    2137                 :            : }
    2138                 :            : 
    2139                 :    1150941 : static int mmc_blk_mq_issue_rw_rq(struct mmc_queue *mq,
    2140                 :            :                                   struct request *req)
    2141                 :            : {
    2142                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
    2143                 :    1150941 :         struct mmc_host *host = mq->card->host;
    2144                 :    1150941 :         struct request *prev_req = NULL;
    2145                 :            :         int err = 0;
    2146                 :            : 
    2147                 :    1150941 :         mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq);
    2148                 :            : 
    2149                 :    1150941 :         mqrq->brq.mrq.done = mmc_blk_mq_req_done;
    2150                 :            : 
    2151                 :    1150941 :         mmc_pre_req(host, &mqrq->brq.mrq);
    2152                 :            : 
    2153                 :    1150941 :         err = mmc_blk_rw_wait(mq, &prev_req);
    2154         [ +  - ]:    1150938 :         if (err)
    2155                 :            :                 goto out_post_req;
    2156                 :            : 
    2157                 :    1150938 :         mq->rw_wait = true;
    2158                 :            : 
    2159                 :    1150938 :         err = mmc_start_request(host, &mqrq->brq.mrq);
    2160                 :            : 
    2161         [ +  + ]:    1150938 :         if (prev_req)
    2162                 :     385188 :                 mmc_blk_mq_post_req(mq, prev_req);
    2163                 :            : 
    2164         [ -  + ]:    1150938 :         if (err)
    2165                 :          0 :                 mq->rw_wait = false;
    2166                 :            : 
    2167                 :            :         /* Release re-tuning here where there is no synchronization required */
    2168   [ +  -  -  + ]:    2301876 :         if (err || mmc_host_done_complete(host))
    2169                 :          0 :                 mmc_retune_release(host);
    2170                 :            : 
    2171                 :            : out_post_req:
    2172         [ -  + ]:    1150938 :         if (err)
    2173                 :            :                 mmc_post_req(host, &mqrq->brq.mrq, err);
    2174                 :            : 
    2175                 :    1150938 :         return err;
    2176                 :            : }
    2177                 :            : 
    2178                 :          0 : static int mmc_blk_wait_for_idle(struct mmc_queue *mq, struct mmc_host *host)
    2179                 :            : {
    2180         [ #  # ]:          0 :         if (mq->use_cqe)
    2181                 :          0 :                 return host->cqe_ops->cqe_wait_for_idle(host);
    2182                 :            : 
    2183                 :          0 :         return mmc_blk_rw_wait(mq, NULL);
    2184                 :            : }
    2185                 :            : 
    2186                 :    1150941 : enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req)
    2187                 :            : {
    2188                 :    1150941 :         struct mmc_blk_data *md = mq->blkdata;
    2189                 :    1150941 :         struct mmc_card *card = md->queue.card;
    2190                 :    1150941 :         struct mmc_host *host = card->host;
    2191                 :            :         int ret;
    2192                 :            : 
    2193                 :    1150941 :         ret = mmc_blk_part_switch(card, md->part_type);
    2194         [ +  - ]:    1150941 :         if (ret)
    2195                 :            :                 return MMC_REQ_FAILED_TO_START;
    2196                 :            : 
    2197      [ -  +  - ]:    1150941 :         switch (mmc_issue_type(mq, req)) {
    2198                 :            :         case MMC_ISSUE_SYNC:
    2199                 :          0 :                 ret = mmc_blk_wait_for_idle(mq, host);
    2200         [ #  # ]:          0 :                 if (ret)
    2201                 :            :                         return MMC_REQ_BUSY;
    2202   [ #  #  #  #  :          0 :                 switch (req_op(req)) {
                      # ]
    2203                 :            :                 case REQ_OP_DRV_IN:
    2204                 :            :                 case REQ_OP_DRV_OUT:
    2205                 :          0 :                         mmc_blk_issue_drv_op(mq, req);
    2206                 :          0 :                         break;
    2207                 :            :                 case REQ_OP_DISCARD:
    2208                 :          0 :                         mmc_blk_issue_discard_rq(mq, req);
    2209                 :          0 :                         break;
    2210                 :            :                 case REQ_OP_SECURE_ERASE:
    2211                 :          0 :                         mmc_blk_issue_secdiscard_rq(mq, req);
    2212                 :          0 :                         break;
    2213                 :            :                 case REQ_OP_FLUSH:
    2214                 :          0 :                         mmc_blk_issue_flush(mq, req);
    2215                 :          0 :                         break;
    2216                 :            :                 default:
    2217         [ #  # ]:          0 :                         WARN_ON_ONCE(1);
    2218                 :            :                         return MMC_REQ_FAILED_TO_START;
    2219                 :            :                 }
    2220                 :            :                 return MMC_REQ_FINISHED;
    2221                 :            :         case MMC_ISSUE_DCMD:
    2222                 :            :         case MMC_ISSUE_ASYNC:
    2223      [ -  +  - ]:    1150941 :                 switch (req_op(req)) {
    2224                 :            :                 case REQ_OP_FLUSH:
    2225                 :          0 :                         ret = mmc_blk_cqe_issue_flush(mq, req);
    2226                 :          0 :                         break;
    2227                 :            :                 case REQ_OP_READ:
    2228                 :            :                 case REQ_OP_WRITE:
    2229         [ -  + ]:    1150941 :                         if (mq->use_cqe)
    2230                 :          0 :                                 ret = mmc_blk_cqe_issue_rw_rq(mq, req);
    2231                 :            :                         else
    2232                 :    1150941 :                                 ret = mmc_blk_mq_issue_rw_rq(mq, req);
    2233                 :            :                         break;
    2234                 :            :                 default:
    2235         [ #  # ]:          0 :                         WARN_ON_ONCE(1);
    2236                 :            :                         ret = -EINVAL;
    2237                 :            :                 }
    2238         [ -  + ]:    1150938 :                 if (!ret)
    2239                 :            :                         return MMC_REQ_STARTED;
    2240         [ #  # ]:          0 :                 return ret == -EBUSY ? MMC_REQ_BUSY : MMC_REQ_FAILED_TO_START;
    2241                 :            :         default:
    2242         [ #  # ]:          0 :                 WARN_ON_ONCE(1);
    2243                 :            :                 return MMC_REQ_FAILED_TO_START;
    2244                 :            :         }
    2245                 :            : }
    2246                 :            : 
    2247                 :            : static inline int mmc_blk_readonly(struct mmc_card *card)
    2248                 :            : {
    2249   [ +  -  +  - ]:        414 :         return mmc_card_readonly(card) ||
    2250                 :        207 :                !(card->csd.cmdclass & CCC_BLOCK_WRITE);
    2251                 :            : }
    2252                 :            : 
    2253                 :        207 : static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
    2254                 :            :                                               struct device *parent,
    2255                 :            :                                               sector_t size,
    2256                 :            :                                               bool default_ro,
    2257                 :            :                                               const char *subname,
    2258                 :            :                                               int area_type)
    2259                 :            : {
    2260                 :            :         struct mmc_blk_data *md;
    2261                 :            :         int devidx, ret;
    2262                 :            : 
    2263                 :        207 :         devidx = ida_simple_get(&mmc_blk_ida, 0, max_devices, GFP_KERNEL);
    2264         [ -  + ]:        207 :         if (devidx < 0) {
    2265                 :            :                 /*
    2266                 :            :                  * We get -ENOSPC because there are no more any available
    2267                 :            :                  * devidx. The reason may be that, either userspace haven't yet
    2268                 :            :                  * unmounted the partitions, which postpones mmc_blk_release()
    2269                 :            :                  * from being called, or the device has more partitions than
    2270                 :            :                  * what we support.
    2271                 :            :                  */
    2272         [ #  # ]:          0 :                 if (devidx == -ENOSPC)
    2273                 :          0 :                         dev_err(mmc_dev(card->host),
    2274                 :            :                                 "no more device IDs available\n");
    2275                 :            : 
    2276                 :          0 :                 return ERR_PTR(devidx);
    2277                 :            :         }
    2278                 :            : 
    2279                 :        207 :         md = kzalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
    2280         [ +  - ]:        207 :         if (!md) {
    2281                 :            :                 ret = -ENOMEM;
    2282                 :            :                 goto out;
    2283                 :            :         }
    2284                 :            : 
    2285                 :        207 :         md->area_type = area_type;
    2286                 :            : 
    2287                 :            :         /*
    2288                 :            :          * Set the read-only status based on the supported commands
    2289                 :            :          * and the write protect switch.
    2290                 :            :          */
    2291                 :        207 :         md->read_only = mmc_blk_readonly(card);
    2292                 :            : 
    2293                 :        207 :         md->disk = alloc_disk(perdev_minors);
    2294         [ +  - ]:        207 :         if (md->disk == NULL) {
    2295                 :            :                 ret = -ENOMEM;
    2296                 :            :                 goto err_kfree;
    2297                 :            :         }
    2298                 :            : 
    2299                 :        207 :         INIT_LIST_HEAD(&md->part);
    2300                 :        207 :         INIT_LIST_HEAD(&md->rpmbs);
    2301                 :        207 :         md->usage = 1;
    2302                 :            : 
    2303                 :        207 :         ret = mmc_init_queue(&md->queue, card);
    2304         [ +  - ]:        207 :         if (ret)
    2305                 :            :                 goto err_putdisk;
    2306                 :            : 
    2307                 :        207 :         md->queue.blkdata = md;
    2308                 :            : 
    2309                 :            :         /*
    2310                 :            :          * Keep an extra reference to the queue so that we can shutdown the
    2311                 :            :          * queue (i.e. call blk_cleanup_queue()) while there are still
    2312                 :            :          * references to the 'md'. The corresponding blk_put_queue() is in
    2313                 :            :          * mmc_blk_put().
    2314                 :            :          */
    2315         [ -  + ]:        207 :         if (!blk_get_queue(md->queue.queue)) {
    2316                 :          0 :                 mmc_cleanup_queue(&md->queue);
    2317                 :            :                 ret = -ENODEV;
    2318                 :          0 :                 goto err_putdisk;
    2319                 :            :         }
    2320                 :            : 
    2321                 :        207 :         md->disk->major   = MMC_BLOCK_MAJOR;
    2322                 :        207 :         md->disk->first_minor = devidx * perdev_minors;
    2323                 :        207 :         md->disk->fops = &mmc_bdops;
    2324                 :        207 :         md->disk->private_data = md;
    2325                 :        207 :         md->disk->queue = md->queue.queue;
    2326                 :        207 :         md->parent = parent;
    2327   [ +  -  +  - ]:        207 :         set_disk_ro(md->disk, md->read_only || default_ro);
    2328                 :        207 :         md->disk->flags = GENHD_FL_EXT_DEVT;
    2329         [ -  + ]:        207 :         if (area_type & (MMC_BLK_DATA_AREA_RPMB | MMC_BLK_DATA_AREA_BOOT))
    2330                 :          0 :                 md->disk->flags |= GENHD_FL_NO_PART_SCAN
    2331                 :            :                                    | GENHD_FL_SUPPRESS_PARTITION_INFO;
    2332                 :            : 
    2333                 :            :         /*
    2334                 :            :          * As discussed on lkml, GENHD_FL_REMOVABLE should:
    2335                 :            :          *
    2336                 :            :          * - be set for removable media with permanent block devices
    2337                 :            :          * - be unset for removable block devices with permanent media
    2338                 :            :          *
    2339                 :            :          * Since MMC block devices clearly fall under the second
    2340                 :            :          * case, we do not set GENHD_FL_REMOVABLE.  Userspace
    2341                 :            :          * should use the block device creation/destruction hotplug
    2342                 :            :          * messages to tell when the card is present.
    2343                 :            :          */
    2344                 :            : 
    2345         [ -  + ]:        414 :         snprintf(md->disk->disk_name, sizeof(md->disk->disk_name),
    2346                 :        207 :                  "mmcblk%u%s", card->host->index, subname ? subname : "");
    2347                 :            : 
    2348                 :        207 :         set_capacity(md->disk, size);
    2349                 :            : 
    2350         [ +  - ]:        414 :         if (mmc_host_cmd23(card->host)) {
    2351   [ -  +  #  # ]:        207 :                 if ((mmc_card_mmc(card) &&
    2352         [ +  - ]:        207 :                      card->csd.mmca_vsn >= CSD_SPEC_VER_3) ||
    2353         [ +  - ]:        207 :                     (mmc_card_sd(card) &&
    2354                 :        207 :                      card->scr.cmds & SD_SCR_CMD23_SUPPORT))
    2355                 :        207 :                         md->flags |= MMC_BLK_CMD23;
    2356                 :            :         }
    2357                 :            : 
    2358   [ -  +  #  # ]:        207 :         if (mmc_card_mmc(card) &&
    2359         [ #  # ]:          0 :             md->flags & MMC_BLK_CMD23 &&
    2360         [ #  # ]:          0 :             ((card->ext_csd.rel_param & EXT_CSD_WR_REL_PARAM_EN) ||
    2361                 :          0 :              card->ext_csd.rel_sectors)) {
    2362                 :          0 :                 md->flags |= MMC_BLK_REL_WR;
    2363                 :          0 :                 blk_queue_write_cache(md->queue.queue, true, true);
    2364                 :            :         }
    2365                 :            : 
    2366                 :        207 :         return md;
    2367                 :            : 
    2368                 :            :  err_putdisk:
    2369                 :          0 :         put_disk(md->disk);
    2370                 :            :  err_kfree:
    2371                 :          0 :         kfree(md);
    2372                 :            :  out:
    2373                 :          0 :         ida_simple_remove(&mmc_blk_ida, devidx);
    2374                 :          0 :         return ERR_PTR(ret);
    2375                 :            : }
    2376                 :            : 
    2377                 :        207 : static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
    2378                 :            : {
    2379                 :            :         sector_t size;
    2380                 :            : 
    2381   [ -  +  #  # ]:        207 :         if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
    2382                 :            :                 /*
    2383                 :            :                  * The EXT_CSD sector count is in number or 512 byte
    2384                 :            :                  * sectors.
    2385                 :            :                  */
    2386                 :          0 :                 size = card->ext_csd.sectors;
    2387                 :            :         } else {
    2388                 :            :                 /*
    2389                 :            :                  * The CSD capacity field is in units of read_blkbits.
    2390                 :            :                  * set_capacity takes units of 512 bytes.
    2391                 :            :                  */
    2392                 :        414 :                 size = (typeof(sector_t))card->csd.capacity
    2393                 :        207 :                         << (card->csd.read_blkbits - 9);
    2394                 :            :         }
    2395                 :            : 
    2396                 :        207 :         return mmc_blk_alloc_req(card, &card->dev, size, false, NULL,
    2397                 :            :                                         MMC_BLK_DATA_AREA_MAIN);
    2398                 :            : }
    2399                 :            : 
    2400                 :          0 : static int mmc_blk_alloc_part(struct mmc_card *card,
    2401                 :            :                               struct mmc_blk_data *md,
    2402                 :            :                               unsigned int part_type,
    2403                 :            :                               sector_t size,
    2404                 :            :                               bool default_ro,
    2405                 :            :                               const char *subname,
    2406                 :            :                               int area_type)
    2407                 :            : {
    2408                 :            :         char cap_str[10];
    2409                 :            :         struct mmc_blk_data *part_md;
    2410                 :            : 
    2411                 :          0 :         part_md = mmc_blk_alloc_req(card, disk_to_dev(md->disk), size, default_ro,
    2412                 :            :                                     subname, area_type);
    2413         [ #  # ]:          0 :         if (IS_ERR(part_md))
    2414                 :          0 :                 return PTR_ERR(part_md);
    2415                 :          0 :         part_md->part_type = part_type;
    2416                 :          0 :         list_add(&part_md->part, &md->part);
    2417                 :            : 
    2418                 :          0 :         string_get_size((u64)get_capacity(part_md->disk), 512, STRING_UNITS_2,
    2419                 :            :                         cap_str, sizeof(cap_str));
    2420                 :          0 :         pr_info("%s: %s %s partition %u %s\n",
    2421                 :            :                part_md->disk->disk_name, mmc_card_id(card),
    2422                 :            :                mmc_card_name(card), part_md->part_type, cap_str);
    2423                 :          0 :         return 0;
    2424                 :            : }
    2425                 :            : 
    2426                 :            : /**
    2427                 :            :  * mmc_rpmb_ioctl() - ioctl handler for the RPMB chardev
    2428                 :            :  * @filp: the character device file
    2429                 :            :  * @cmd: the ioctl() command
    2430                 :            :  * @arg: the argument from userspace
    2431                 :            :  *
    2432                 :            :  * This will essentially just redirect the ioctl()s coming in over to
    2433                 :            :  * the main block device spawning the RPMB character device.
    2434                 :            :  */
    2435                 :          0 : static long mmc_rpmb_ioctl(struct file *filp, unsigned int cmd,
    2436                 :            :                            unsigned long arg)
    2437                 :            : {
    2438                 :          0 :         struct mmc_rpmb_data *rpmb = filp->private_data;
    2439                 :            :         int ret;
    2440                 :            : 
    2441      [ #  #  # ]:          0 :         switch (cmd) {
    2442                 :            :         case MMC_IOC_CMD:
    2443                 :          0 :                 ret = mmc_blk_ioctl_cmd(rpmb->md,
    2444                 :            :                                         (struct mmc_ioc_cmd __user *)arg,
    2445                 :            :                                         rpmb);
    2446                 :          0 :                 break;
    2447                 :            :         case MMC_IOC_MULTI_CMD:
    2448                 :          0 :                 ret = mmc_blk_ioctl_multi_cmd(rpmb->md,
    2449                 :            :                                         (struct mmc_ioc_multi_cmd __user *)arg,
    2450                 :            :                                         rpmb);
    2451                 :          0 :                 break;
    2452                 :            :         default:
    2453                 :            :                 ret = -EINVAL;
    2454                 :            :                 break;
    2455                 :            :         }
    2456                 :            : 
    2457                 :          0 :         return ret;
    2458                 :            : }
    2459                 :            : 
    2460                 :            : #ifdef CONFIG_COMPAT
    2461                 :            : static long mmc_rpmb_ioctl_compat(struct file *filp, unsigned int cmd,
    2462                 :            :                               unsigned long arg)
    2463                 :            : {
    2464                 :            :         return mmc_rpmb_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
    2465                 :            : }
    2466                 :            : #endif
    2467                 :            : 
    2468                 :          0 : static int mmc_rpmb_chrdev_open(struct inode *inode, struct file *filp)
    2469                 :            : {
    2470                 :          0 :         struct mmc_rpmb_data *rpmb = container_of(inode->i_cdev,
    2471                 :            :                                                   struct mmc_rpmb_data, chrdev);
    2472                 :            : 
    2473                 :          0 :         get_device(&rpmb->dev);
    2474                 :          0 :         filp->private_data = rpmb;
    2475                 :          0 :         mmc_blk_get(rpmb->md->disk);
    2476                 :            : 
    2477                 :          0 :         return nonseekable_open(inode, filp);
    2478                 :            : }
    2479                 :            : 
    2480                 :          0 : static int mmc_rpmb_chrdev_release(struct inode *inode, struct file *filp)
    2481                 :            : {
    2482                 :          0 :         struct mmc_rpmb_data *rpmb = container_of(inode->i_cdev,
    2483                 :            :                                                   struct mmc_rpmb_data, chrdev);
    2484                 :            : 
    2485                 :          0 :         mmc_blk_put(rpmb->md);
    2486                 :          0 :         put_device(&rpmb->dev);
    2487                 :            : 
    2488                 :          0 :         return 0;
    2489                 :            : }
    2490                 :            : 
    2491                 :            : static const struct file_operations mmc_rpmb_fileops = {
    2492                 :            :         .release = mmc_rpmb_chrdev_release,
    2493                 :            :         .open = mmc_rpmb_chrdev_open,
    2494                 :            :         .owner = THIS_MODULE,
    2495                 :            :         .llseek = no_llseek,
    2496                 :            :         .unlocked_ioctl = mmc_rpmb_ioctl,
    2497                 :            : #ifdef CONFIG_COMPAT
    2498                 :            :         .compat_ioctl = mmc_rpmb_ioctl_compat,
    2499                 :            : #endif
    2500                 :            : };
    2501                 :            : 
    2502                 :          0 : static void mmc_blk_rpmb_device_release(struct device *dev)
    2503                 :            : {
    2504                 :            :         struct mmc_rpmb_data *rpmb = dev_get_drvdata(dev);
    2505                 :            : 
    2506                 :          0 :         ida_simple_remove(&mmc_rpmb_ida, rpmb->id);
    2507                 :          0 :         kfree(rpmb);
    2508                 :          0 : }
    2509                 :            : 
    2510                 :          0 : static int mmc_blk_alloc_rpmb_part(struct mmc_card *card,
    2511                 :            :                                    struct mmc_blk_data *md,
    2512                 :            :                                    unsigned int part_index,
    2513                 :            :                                    sector_t size,
    2514                 :            :                                    const char *subname)
    2515                 :            : {
    2516                 :            :         int devidx, ret;
    2517                 :            :         char rpmb_name[DISK_NAME_LEN];
    2518                 :            :         char cap_str[10];
    2519                 :            :         struct mmc_rpmb_data *rpmb;
    2520                 :            : 
    2521                 :            :         /* This creates the minor number for the RPMB char device */
    2522                 :          0 :         devidx = ida_simple_get(&mmc_rpmb_ida, 0, max_devices, GFP_KERNEL);
    2523         [ #  # ]:          0 :         if (devidx < 0)
    2524                 :            :                 return devidx;
    2525                 :            : 
    2526                 :          0 :         rpmb = kzalloc(sizeof(*rpmb), GFP_KERNEL);
    2527         [ #  # ]:          0 :         if (!rpmb) {
    2528                 :          0 :                 ida_simple_remove(&mmc_rpmb_ida, devidx);
    2529                 :          0 :                 return -ENOMEM;
    2530                 :            :         }
    2531                 :            : 
    2532         [ #  # ]:          0 :         snprintf(rpmb_name, sizeof(rpmb_name),
    2533                 :          0 :                  "mmcblk%u%s", card->host->index, subname ? subname : "");
    2534                 :            : 
    2535                 :          0 :         rpmb->id = devidx;
    2536                 :          0 :         rpmb->part_index = part_index;
    2537                 :          0 :         rpmb->dev.init_name = rpmb_name;
    2538                 :          0 :         rpmb->dev.bus = &mmc_rpmb_bus_type;
    2539                 :          0 :         rpmb->dev.devt = MKDEV(MAJOR(mmc_rpmb_devt), rpmb->id);
    2540                 :          0 :         rpmb->dev.parent = &card->dev;
    2541                 :          0 :         rpmb->dev.release = mmc_blk_rpmb_device_release;
    2542                 :          0 :         device_initialize(&rpmb->dev);
    2543                 :            :         dev_set_drvdata(&rpmb->dev, rpmb);
    2544                 :          0 :         rpmb->md = md;
    2545                 :            : 
    2546                 :          0 :         cdev_init(&rpmb->chrdev, &mmc_rpmb_fileops);
    2547                 :          0 :         rpmb->chrdev.owner = THIS_MODULE;
    2548                 :          0 :         ret = cdev_device_add(&rpmb->chrdev, &rpmb->dev);
    2549         [ #  # ]:          0 :         if (ret) {
    2550                 :          0 :                 pr_err("%s: could not add character device\n", rpmb_name);
    2551                 :            :                 goto out_put_device;
    2552                 :            :         }
    2553                 :            : 
    2554                 :          0 :         list_add(&rpmb->node, &md->rpmbs);
    2555                 :            : 
    2556                 :          0 :         string_get_size((u64)size, 512, STRING_UNITS_2,
    2557                 :            :                         cap_str, sizeof(cap_str));
    2558                 :            : 
    2559                 :          0 :         pr_info("%s: %s %s partition %u %s, chardev (%d:%d)\n",
    2560                 :            :                 rpmb_name, mmc_card_id(card),
    2561                 :            :                 mmc_card_name(card), EXT_CSD_PART_CONFIG_ACC_RPMB, cap_str,
    2562                 :            :                 MAJOR(mmc_rpmb_devt), rpmb->id);
    2563                 :            : 
    2564                 :          0 :         return 0;
    2565                 :            : 
    2566                 :            : out_put_device:
    2567                 :          0 :         put_device(&rpmb->dev);
    2568                 :          0 :         return ret;
    2569                 :            : }
    2570                 :            : 
    2571                 :            : static void mmc_blk_remove_rpmb_part(struct mmc_rpmb_data *rpmb)
    2572                 :            : 
    2573                 :            : {
    2574                 :          0 :         cdev_device_del(&rpmb->chrdev, &rpmb->dev);
    2575                 :          0 :         put_device(&rpmb->dev);
    2576                 :            : }
    2577                 :            : 
    2578                 :            : /* MMC Physical partitions consist of two boot partitions and
    2579                 :            :  * up to four general purpose partitions.
    2580                 :            :  * For each partition enabled in EXT_CSD a block device will be allocatedi
    2581                 :            :  * to provide access to the partition.
    2582                 :            :  */
    2583                 :            : 
    2584                 :        207 : static int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data *md)
    2585                 :            : {
    2586                 :            :         int idx, ret;
    2587                 :            : 
    2588         [ -  + ]:        207 :         if (!mmc_card_mmc(card))
    2589                 :            :                 return 0;
    2590                 :            : 
    2591         [ #  # ]:          0 :         for (idx = 0; idx < card->nr_parts; idx++) {
    2592         [ #  # ]:          0 :                 if (card->part[idx].area_type & MMC_BLK_DATA_AREA_RPMB) {
    2593                 :            :                         /*
    2594                 :            :                          * RPMB partitions does not provide block access, they
    2595                 :            :                          * are only accessed using ioctl():s. Thus create
    2596                 :            :                          * special RPMB block devices that do not have a
    2597                 :            :                          * backing block queue for these.
    2598                 :            :                          */
    2599                 :          0 :                         ret = mmc_blk_alloc_rpmb_part(card, md,
    2600                 :            :                                 card->part[idx].part_cfg,
    2601                 :          0 :                                 card->part[idx].size >> 9,
    2602                 :          0 :                                 card->part[idx].name);
    2603         [ #  # ]:          0 :                         if (ret)
    2604                 :          0 :                                 return ret;
    2605         [ #  # ]:          0 :                 } else if (card->part[idx].size) {
    2606                 :          0 :                         ret = mmc_blk_alloc_part(card, md,
    2607                 :            :                                 card->part[idx].part_cfg,
    2608                 :          0 :                                 card->part[idx].size >> 9,
    2609                 :            :                                 card->part[idx].force_ro,
    2610                 :          0 :                                 card->part[idx].name,
    2611                 :            :                                 card->part[idx].area_type);
    2612         [ #  # ]:          0 :                         if (ret)
    2613                 :          0 :                                 return ret;
    2614                 :            :                 }
    2615                 :            :         }
    2616                 :            : 
    2617                 :            :         return 0;
    2618                 :            : }
    2619                 :            : 
    2620                 :          0 : static void mmc_blk_remove_req(struct mmc_blk_data *md)
    2621                 :            : {
    2622                 :            :         struct mmc_card *card;
    2623                 :            : 
    2624         [ #  # ]:          0 :         if (md) {
    2625                 :            :                 /*
    2626                 :            :                  * Flush remaining requests and free queues. It
    2627                 :            :                  * is freeing the queue that stops new requests
    2628                 :            :                  * from being accepted.
    2629                 :            :                  */
    2630                 :          0 :                 card = md->queue.card;
    2631         [ #  # ]:          0 :                 if (md->disk->flags & GENHD_FL_UP) {
    2632                 :          0 :                         device_remove_file(disk_to_dev(md->disk), &md->force_ro);
    2633   [ #  #  #  # ]:          0 :                         if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
    2634                 :          0 :                                         card->ext_csd.boot_ro_lockable)
    2635                 :          0 :                                 device_remove_file(disk_to_dev(md->disk),
    2636                 :          0 :                                         &md->power_ro_lock);
    2637                 :            : 
    2638                 :          0 :                         del_gendisk(md->disk);
    2639                 :            :                 }
    2640                 :          0 :                 mmc_cleanup_queue(&md->queue);
    2641                 :          0 :                 mmc_blk_put(md);
    2642                 :            :         }
    2643                 :          0 : }
    2644                 :            : 
    2645                 :          0 : static void mmc_blk_remove_parts(struct mmc_card *card,
    2646                 :            :                                  struct mmc_blk_data *md)
    2647                 :            : {
    2648                 :            :         struct list_head *pos, *q;
    2649                 :            :         struct mmc_blk_data *part_md;
    2650                 :            :         struct mmc_rpmb_data *rpmb;
    2651                 :            : 
    2652                 :            :         /* Remove RPMB partitions */
    2653         [ #  # ]:          0 :         list_for_each_safe(pos, q, &md->rpmbs) {
    2654                 :            :                 rpmb = list_entry(pos, struct mmc_rpmb_data, node);
    2655                 :            :                 list_del(pos);
    2656                 :            :                 mmc_blk_remove_rpmb_part(rpmb);
    2657                 :            :         }
    2658                 :            :         /* Remove block partitions */
    2659         [ #  # ]:          0 :         list_for_each_safe(pos, q, &md->part) {
    2660                 :          0 :                 part_md = list_entry(pos, struct mmc_blk_data, part);
    2661                 :            :                 list_del(pos);
    2662                 :          0 :                 mmc_blk_remove_req(part_md);
    2663                 :            :         }
    2664                 :          0 : }
    2665                 :            : 
    2666                 :        207 : static int mmc_add_disk(struct mmc_blk_data *md)
    2667                 :            : {
    2668                 :            :         int ret;
    2669                 :        207 :         struct mmc_card *card = md->queue.card;
    2670                 :            : 
    2671                 :        207 :         device_add_disk(md->parent, md->disk, NULL);
    2672                 :        207 :         md->force_ro.show = force_ro_show;
    2673                 :        207 :         md->force_ro.store = force_ro_store;
    2674                 :            :         sysfs_attr_init(&md->force_ro.attr);
    2675                 :        207 :         md->force_ro.attr.name = "force_ro";
    2676                 :        207 :         md->force_ro.attr.mode = S_IRUGO | S_IWUSR;
    2677                 :        207 :         ret = device_create_file(disk_to_dev(md->disk), &md->force_ro);
    2678         [ +  - ]:        207 :         if (ret)
    2679                 :            :                 goto force_ro_fail;
    2680                 :            : 
    2681   [ -  +  #  # ]:        207 :         if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
    2682                 :          0 :              card->ext_csd.boot_ro_lockable) {
    2683                 :            :                 umode_t mode;
    2684                 :            : 
    2685         [ #  # ]:          0 :                 if (card->ext_csd.boot_ro_lock & EXT_CSD_BOOT_WP_B_PWR_WP_DIS)
    2686                 :            :                         mode = S_IRUGO;
    2687                 :            :                 else
    2688                 :            :                         mode = S_IRUGO | S_IWUSR;
    2689                 :            : 
    2690                 :          0 :                 md->power_ro_lock.show = power_ro_lock_show;
    2691                 :          0 :                 md->power_ro_lock.store = power_ro_lock_store;
    2692                 :            :                 sysfs_attr_init(&md->power_ro_lock.attr);
    2693                 :          0 :                 md->power_ro_lock.attr.mode = mode;
    2694                 :          0 :                 md->power_ro_lock.attr.name =
    2695                 :            :                                         "ro_lock_until_next_power_on";
    2696                 :          0 :                 ret = device_create_file(disk_to_dev(md->disk),
    2697                 :          0 :                                 &md->power_ro_lock);
    2698         [ #  # ]:          0 :                 if (ret)
    2699                 :            :                         goto power_ro_lock_fail;
    2700                 :            :         }
    2701                 :        207 :         return ret;
    2702                 :            : 
    2703                 :            : power_ro_lock_fail:
    2704                 :          0 :         device_remove_file(disk_to_dev(md->disk), &md->force_ro);
    2705                 :            : force_ro_fail:
    2706                 :          0 :         del_gendisk(md->disk);
    2707                 :            : 
    2708                 :          0 :         return ret;
    2709                 :            : }
    2710                 :            : 
    2711                 :            : #ifdef CONFIG_DEBUG_FS
    2712                 :            : 
    2713                 :          0 : static int mmc_dbg_card_status_get(void *data, u64 *val)
    2714                 :            : {
    2715                 :            :         struct mmc_card *card = data;
    2716                 :            :         struct mmc_blk_data *md = dev_get_drvdata(&card->dev);
    2717                 :            :         struct mmc_queue *mq = &md->queue;
    2718                 :            :         struct request *req;
    2719                 :            :         int ret;
    2720                 :            : 
    2721                 :            :         /* Ask the block layer about the card status */
    2722                 :          0 :         req = blk_get_request(mq->queue, REQ_OP_DRV_IN, 0);
    2723         [ #  # ]:          0 :         if (IS_ERR(req))
    2724                 :          0 :                 return PTR_ERR(req);
    2725                 :          0 :         req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_GET_CARD_STATUS;
    2726                 :          0 :         blk_execute_rq(mq->queue, NULL, req, 0);
    2727                 :          0 :         ret = req_to_mmc_queue_req(req)->drv_op_result;
    2728         [ #  # ]:          0 :         if (ret >= 0) {
    2729                 :          0 :                 *val = ret;
    2730                 :            :                 ret = 0;
    2731                 :            :         }
    2732                 :          0 :         blk_put_request(req);
    2733                 :            : 
    2734                 :          0 :         return ret;
    2735                 :            : }
    2736                 :          0 : DEFINE_DEBUGFS_ATTRIBUTE(mmc_dbg_card_status_fops, mmc_dbg_card_status_get,
    2737                 :            :                          NULL, "%08llx\n");
    2738                 :            : 
    2739                 :            : /* That is two digits * 512 + 1 for newline */
    2740                 :            : #define EXT_CSD_STR_LEN 1025
    2741                 :            : 
    2742                 :          0 : static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
    2743                 :            : {
    2744                 :          0 :         struct mmc_card *card = inode->i_private;
    2745                 :            :         struct mmc_blk_data *md = dev_get_drvdata(&card->dev);
    2746                 :            :         struct mmc_queue *mq = &md->queue;
    2747                 :            :         struct request *req;
    2748                 :            :         char *buf;
    2749                 :            :         ssize_t n = 0;
    2750                 :            :         u8 *ext_csd;
    2751                 :            :         int err, i;
    2752                 :            : 
    2753                 :            :         buf = kmalloc(EXT_CSD_STR_LEN + 1, GFP_KERNEL);
    2754         [ #  # ]:          0 :         if (!buf)
    2755                 :            :                 return -ENOMEM;
    2756                 :            : 
    2757                 :            :         /* Ask the block layer for the EXT CSD */
    2758                 :          0 :         req = blk_get_request(mq->queue, REQ_OP_DRV_IN, 0);
    2759         [ #  # ]:          0 :         if (IS_ERR(req)) {
    2760                 :            :                 err = PTR_ERR(req);
    2761                 :          0 :                 goto out_free;
    2762                 :            :         }
    2763                 :          0 :         req_to_mmc_queue_req(req)->drv_op = MMC_DRV_OP_GET_EXT_CSD;
    2764                 :          0 :         req_to_mmc_queue_req(req)->drv_op_data = &ext_csd;
    2765                 :          0 :         blk_execute_rq(mq->queue, NULL, req, 0);
    2766                 :          0 :         err = req_to_mmc_queue_req(req)->drv_op_result;
    2767                 :          0 :         blk_put_request(req);
    2768         [ #  # ]:          0 :         if (err) {
    2769                 :          0 :                 pr_err("FAILED %d\n", err);
    2770                 :          0 :                 goto out_free;
    2771                 :            :         }
    2772                 :            : 
    2773         [ #  # ]:          0 :         for (i = 0; i < 512; i++)
    2774                 :          0 :                 n += sprintf(buf + n, "%02x", ext_csd[i]);
    2775                 :          0 :         n += sprintf(buf + n, "\n");
    2776                 :            : 
    2777         [ #  # ]:          0 :         if (n != EXT_CSD_STR_LEN) {
    2778                 :            :                 err = -EINVAL;
    2779                 :          0 :                 kfree(ext_csd);
    2780                 :          0 :                 goto out_free;
    2781                 :            :         }
    2782                 :            : 
    2783                 :          0 :         filp->private_data = buf;
    2784                 :          0 :         kfree(ext_csd);
    2785                 :          0 :         return 0;
    2786                 :            : 
    2787                 :            : out_free:
    2788                 :          0 :         kfree(buf);
    2789                 :          0 :         return err;
    2790                 :            : }
    2791                 :            : 
    2792                 :          0 : static ssize_t mmc_ext_csd_read(struct file *filp, char __user *ubuf,
    2793                 :            :                                 size_t cnt, loff_t *ppos)
    2794                 :            : {
    2795                 :          0 :         char *buf = filp->private_data;
    2796                 :            : 
    2797                 :          0 :         return simple_read_from_buffer(ubuf, cnt, ppos,
    2798                 :            :                                        buf, EXT_CSD_STR_LEN);
    2799                 :            : }
    2800                 :            : 
    2801                 :          0 : static int mmc_ext_csd_release(struct inode *inode, struct file *file)
    2802                 :            : {
    2803                 :          0 :         kfree(file->private_data);
    2804                 :          0 :         return 0;
    2805                 :            : }
    2806                 :            : 
    2807                 :            : static const struct file_operations mmc_dbg_ext_csd_fops = {
    2808                 :            :         .open           = mmc_ext_csd_open,
    2809                 :            :         .read           = mmc_ext_csd_read,
    2810                 :            :         .release        = mmc_ext_csd_release,
    2811                 :            :         .llseek         = default_llseek,
    2812                 :            : };
    2813                 :            : 
    2814                 :        207 : static int mmc_blk_add_debugfs(struct mmc_card *card, struct mmc_blk_data *md)
    2815                 :            : {
    2816                 :            :         struct dentry *root;
    2817                 :            : 
    2818         [ +  - ]:        207 :         if (!card->debugfs_root)
    2819                 :            :                 return 0;
    2820                 :            : 
    2821                 :            :         root = card->debugfs_root;
    2822                 :            : 
    2823         [ +  - ]:        207 :         if (mmc_card_mmc(card) || mmc_card_sd(card)) {
    2824                 :        207 :                 md->status_dentry =
    2825                 :        207 :                         debugfs_create_file_unsafe("status", 0400, root,
    2826                 :            :                                                    card,
    2827                 :            :                                                    &mmc_dbg_card_status_fops);
    2828         [ +  - ]:        207 :                 if (!md->status_dentry)
    2829                 :            :                         return -EIO;
    2830                 :            :         }
    2831                 :            : 
    2832         [ -  + ]:        207 :         if (mmc_card_mmc(card)) {
    2833                 :          0 :                 md->ext_csd_dentry =
    2834                 :          0 :                         debugfs_create_file("ext_csd", S_IRUSR, root, card,
    2835                 :            :                                             &mmc_dbg_ext_csd_fops);
    2836         [ #  # ]:          0 :                 if (!md->ext_csd_dentry)
    2837                 :            :                         return -EIO;
    2838                 :            :         }
    2839                 :            : 
    2840                 :            :         return 0;
    2841                 :            : }
    2842                 :            : 
    2843                 :          0 : static void mmc_blk_remove_debugfs(struct mmc_card *card,
    2844                 :            :                                    struct mmc_blk_data *md)
    2845                 :            : {
    2846         [ #  # ]:          0 :         if (!card->debugfs_root)
    2847                 :          0 :                 return;
    2848                 :            : 
    2849         [ #  # ]:          0 :         if (!IS_ERR_OR_NULL(md->status_dentry)) {
    2850                 :          0 :                 debugfs_remove(md->status_dentry);
    2851                 :          0 :                 md->status_dentry = NULL;
    2852                 :            :         }
    2853                 :            : 
    2854         [ #  # ]:          0 :         if (!IS_ERR_OR_NULL(md->ext_csd_dentry)) {
    2855                 :          0 :                 debugfs_remove(md->ext_csd_dentry);
    2856                 :          0 :                 md->ext_csd_dentry = NULL;
    2857                 :            :         }
    2858                 :            : }
    2859                 :            : 
    2860                 :            : #else
    2861                 :            : 
    2862                 :            : static int mmc_blk_add_debugfs(struct mmc_card *card, struct mmc_blk_data *md)
    2863                 :            : {
    2864                 :            :         return 0;
    2865                 :            : }
    2866                 :            : 
    2867                 :            : static void mmc_blk_remove_debugfs(struct mmc_card *card,
    2868                 :            :                                    struct mmc_blk_data *md)
    2869                 :            : {
    2870                 :            : }
    2871                 :            : 
    2872                 :            : #endif /* CONFIG_DEBUG_FS */
    2873                 :            : 
    2874                 :        207 : static int mmc_blk_probe(struct mmc_card *card)
    2875                 :            : {
    2876                 :            :         struct mmc_blk_data *md, *part_md;
    2877                 :            :         char cap_str[10];
    2878                 :            :         char quirk_str[24];
    2879                 :            : 
    2880                 :            :         /*
    2881                 :            :          * Check that the card supports the command class(es) we need.
    2882                 :            :          */
    2883         [ +  - ]:        207 :         if (!(card->csd.cmdclass & CCC_BLOCK_READ))
    2884                 :            :                 return -ENODEV;
    2885                 :            : 
    2886         [ -  + ]:        207 :         if (card_quirks) {
    2887                 :            :                 unsigned long quirks;
    2888         [ #  # ]:          0 :                 if (kstrtoul(card_quirks, 0, &quirks) == 0)
    2889                 :          0 :                         card->quirks = (unsigned int)quirks;
    2890                 :            :                 else
    2891                 :          0 :                         pr_err("mmc_block: Invalid card_quirks parameter '%s'\n",
    2892                 :            :                                card_quirks);
    2893                 :            :         }
    2894                 :            :         else
    2895                 :        207 :                 mmc_fixup_device(card, mmc_blk_fixups);
    2896                 :            : 
    2897                 :        207 :         card->complete_wq = alloc_workqueue("mmc_complete",
    2898                 :            :                                         WQ_MEM_RECLAIM | WQ_HIGHPRI, 0);
    2899         [ -  + ]:        207 :         if (unlikely(!card->complete_wq)) {
    2900                 :          0 :                 pr_err("Failed to create mmc completion workqueue");
    2901                 :          0 :                 return -ENOMEM;
    2902                 :            :         }
    2903                 :            : 
    2904                 :        207 :         md = mmc_blk_alloc(card);
    2905         [ -  + ]:        207 :         if (IS_ERR(md))
    2906                 :          0 :                 return PTR_ERR(md);
    2907                 :            : 
    2908                 :        414 :         string_get_size((u64)get_capacity(md->disk), 512, STRING_UNITS_2,
    2909                 :            :                         cap_str, sizeof(cap_str));
    2910         [ -  + ]:        207 :         if (card->quirks)
    2911                 :          0 :                 snprintf(quirk_str, sizeof(quirk_str),
    2912                 :            :                          " (quirks 0x%08x)", card->quirks);
    2913                 :            :         else
    2914                 :        207 :                 quirk_str[0] = '\0';
    2915         [ +  - ]:        414 :         pr_info("%s: %s %s %s%s%s\n",
    2916                 :            :                 md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
    2917                 :            :                 cap_str, md->read_only ? " (ro)" : "", quirk_str);
    2918                 :            : 
    2919         [ +  - ]:        207 :         if (mmc_blk_alloc_parts(card, md))
    2920                 :            :                 goto out;
    2921                 :            : 
    2922                 :            :         dev_set_drvdata(&card->dev, md);
    2923                 :            : 
    2924         [ +  - ]:        207 :         if (mmc_add_disk(md))
    2925                 :            :                 goto out;
    2926                 :            : 
    2927         [ -  + ]:        207 :         list_for_each_entry(part_md, &md->part, part) {
    2928         [ #  # ]:          0 :                 if (mmc_add_disk(part_md))
    2929                 :            :                         goto out;
    2930                 :            :         }
    2931                 :            : 
    2932                 :            :         /* Add two debugfs entries */
    2933                 :        207 :         mmc_blk_add_debugfs(card, md);
    2934                 :            : 
    2935                 :        207 :         pm_runtime_set_autosuspend_delay(&card->dev, 3000);
    2936                 :            :         pm_runtime_use_autosuspend(&card->dev);
    2937                 :            : 
    2938                 :            :         /*
    2939                 :            :          * Don't enable runtime PM for SD-combo cards here. Leave that
    2940                 :            :          * decision to be taken during the SDIO init sequence instead.
    2941                 :            :          */
    2942         [ +  - ]:        207 :         if (card->type != MMC_TYPE_SD_COMBO) {
    2943                 :            :                 pm_runtime_set_active(&card->dev);
    2944                 :        207 :                 pm_runtime_enable(&card->dev);
    2945                 :            :         }
    2946                 :            : 
    2947                 :            :         return 0;
    2948                 :            : 
    2949                 :            :  out:
    2950                 :          0 :         mmc_blk_remove_parts(card, md);
    2951                 :          0 :         mmc_blk_remove_req(md);
    2952                 :          0 :         return 0;
    2953                 :            : }
    2954                 :            : 
    2955                 :          0 : static void mmc_blk_remove(struct mmc_card *card)
    2956                 :            : {
    2957                 :            :         struct mmc_blk_data *md = dev_get_drvdata(&card->dev);
    2958                 :            : 
    2959                 :          0 :         mmc_blk_remove_debugfs(card, md);
    2960                 :          0 :         mmc_blk_remove_parts(card, md);
    2961                 :          0 :         pm_runtime_get_sync(&card->dev);
    2962         [ #  # ]:          0 :         if (md->part_curr != md->part_type) {
    2963                 :          0 :                 mmc_claim_host(card->host);
    2964                 :          0 :                 mmc_blk_part_switch(card, md->part_type);
    2965                 :          0 :                 mmc_release_host(card->host);
    2966                 :            :         }
    2967         [ #  # ]:          0 :         if (card->type != MMC_TYPE_SD_COMBO)
    2968                 :            :                 pm_runtime_disable(&card->dev);
    2969                 :            :         pm_runtime_put_noidle(&card->dev);
    2970                 :          0 :         mmc_blk_remove_req(md);
    2971                 :            :         dev_set_drvdata(&card->dev, NULL);
    2972                 :          0 :         destroy_workqueue(card->complete_wq);
    2973                 :          0 : }
    2974                 :            : 
    2975                 :          0 : static int _mmc_blk_suspend(struct mmc_card *card)
    2976                 :            : {
    2977                 :            :         struct mmc_blk_data *part_md;
    2978                 :            :         struct mmc_blk_data *md = dev_get_drvdata(&card->dev);
    2979                 :            : 
    2980         [ #  # ]:          0 :         if (md) {
    2981                 :          0 :                 mmc_queue_suspend(&md->queue);
    2982         [ #  # ]:          0 :                 list_for_each_entry(part_md, &md->part, part) {
    2983                 :          0 :                         mmc_queue_suspend(&part_md->queue);
    2984                 :            :                 }
    2985                 :            :         }
    2986                 :          0 :         return 0;
    2987                 :            : }
    2988                 :            : 
    2989                 :          0 : static void mmc_blk_shutdown(struct mmc_card *card)
    2990                 :            : {
    2991                 :          0 :         _mmc_blk_suspend(card);
    2992                 :          0 : }
    2993                 :            : 
    2994                 :            : #ifdef CONFIG_PM_SLEEP
    2995                 :            : static int mmc_blk_suspend(struct device *dev)
    2996                 :            : {
    2997                 :            :         struct mmc_card *card = mmc_dev_to_card(dev);
    2998                 :            : 
    2999                 :            :         return _mmc_blk_suspend(card);
    3000                 :            : }
    3001                 :            : 
    3002                 :            : static int mmc_blk_resume(struct device *dev)
    3003                 :            : {
    3004                 :            :         struct mmc_blk_data *part_md;
    3005                 :            :         struct mmc_blk_data *md = dev_get_drvdata(dev);
    3006                 :            : 
    3007                 :            :         if (md) {
    3008                 :            :                 /*
    3009                 :            :                  * Resume involves the card going into idle state,
    3010                 :            :                  * so current partition is always the main one.
    3011                 :            :                  */
    3012                 :            :                 md->part_curr = md->part_type;
    3013                 :            :                 mmc_queue_resume(&md->queue);
    3014                 :            :                 list_for_each_entry(part_md, &md->part, part) {
    3015                 :            :                         mmc_queue_resume(&part_md->queue);
    3016                 :            :                 }
    3017                 :            :         }
    3018                 :            :         return 0;
    3019                 :            : }
    3020                 :            : #endif
    3021                 :            : 
    3022                 :            : static SIMPLE_DEV_PM_OPS(mmc_blk_pm_ops, mmc_blk_suspend, mmc_blk_resume);
    3023                 :            : 
    3024                 :            : static struct mmc_driver mmc_driver = {
    3025                 :            :         .drv            = {
    3026                 :            :                 .name   = "mmcblk",
    3027                 :            :                 .pm     = &mmc_blk_pm_ops,
    3028                 :            :         },
    3029                 :            :         .probe          = mmc_blk_probe,
    3030                 :            :         .remove         = mmc_blk_remove,
    3031                 :            :         .shutdown       = mmc_blk_shutdown,
    3032                 :            : };
    3033                 :            : 
    3034                 :        207 : static int __init mmc_blk_init(void)
    3035                 :            : {
    3036                 :            :         int res;
    3037                 :            : 
    3038                 :        207 :         res  = bus_register(&mmc_rpmb_bus_type);
    3039         [ -  + ]:        207 :         if (res < 0) {
    3040                 :          0 :                 pr_err("mmcblk: could not register RPMB bus type\n");
    3041                 :          0 :                 return res;
    3042                 :            :         }
    3043                 :        207 :         res = alloc_chrdev_region(&mmc_rpmb_devt, 0, MAX_DEVICES, "rpmb");
    3044         [ -  + ]:        207 :         if (res < 0) {
    3045                 :          0 :                 pr_err("mmcblk: failed to allocate rpmb chrdev region\n");
    3046                 :          0 :                 goto out_bus_unreg;
    3047                 :            :         }
    3048                 :            : 
    3049         [ -  + ]:        207 :         if (perdev_minors != CONFIG_MMC_BLOCK_MINORS)
    3050                 :          0 :                 pr_info("mmcblk: using %d minors per device\n", perdev_minors);
    3051                 :            : 
    3052                 :        207 :         max_devices = min(MAX_DEVICES, (1 << MINORBITS) / perdev_minors);
    3053                 :            : 
    3054                 :        207 :         res = register_blkdev(MMC_BLOCK_MAJOR, "mmc");
    3055         [ +  - ]:        207 :         if (res)
    3056                 :            :                 goto out_chrdev_unreg;
    3057                 :            : 
    3058                 :        207 :         res = mmc_register_driver(&mmc_driver);
    3059         [ -  + ]:        207 :         if (res)
    3060                 :            :                 goto out_blkdev_unreg;
    3061                 :            : 
    3062                 :            :         return 0;
    3063                 :            : 
    3064                 :            : out_blkdev_unreg:
    3065                 :          0 :         unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
    3066                 :            : out_chrdev_unreg:
    3067                 :          0 :         unregister_chrdev_region(mmc_rpmb_devt, MAX_DEVICES);
    3068                 :            : out_bus_unreg:
    3069                 :          0 :         bus_unregister(&mmc_rpmb_bus_type);
    3070                 :          0 :         return res;
    3071                 :            : }
    3072                 :            : 
    3073                 :          0 : static void __exit mmc_blk_exit(void)
    3074                 :            : {
    3075                 :          0 :         mmc_unregister_driver(&mmc_driver);
    3076                 :          0 :         unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
    3077                 :          0 :         unregister_chrdev_region(mmc_rpmb_devt, MAX_DEVICES);
    3078                 :          0 :         bus_unregister(&mmc_rpmb_bus_type);
    3079                 :          0 : }
    3080                 :            : 
    3081                 :            : module_init(mmc_blk_init);
    3082                 :            : module_exit(mmc_blk_exit);
    3083                 :            : 
    3084                 :            : MODULE_LICENSE("GPL");
    3085                 :            : MODULE_DESCRIPTION("Multimedia Card (MMC) block device driver");
    3086                 :            : 

Generated by: LCOV version 1.14