LCOV - code coverage report
Current view: top level - drivers/mmc/core - queue.c (source / functions) Hit Total Coverage
Test: Real Lines: 102 203 50.2 %
Date: 2020-10-17 15:46:16 Functions: 0 19 0.0 %
Legend: Neither, QEMU, Real, Both Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0-only
       2                 :            : /*
       3                 :            :  *  Copyright (C) 2003 Russell King, All Rights Reserved.
       4                 :            :  *  Copyright 2006-2007 Pierre Ossman
       5                 :            :  */
       6                 :            : #include <linux/slab.h>
       7                 :            : #include <linux/module.h>
       8                 :            : #include <linux/blkdev.h>
       9                 :            : #include <linux/freezer.h>
      10                 :            : #include <linux/kthread.h>
      11                 :            : #include <linux/scatterlist.h>
      12                 :            : #include <linux/dma-mapping.h>
      13                 :            : #include <linux/backing-dev.h>
      14                 :            : 
      15                 :            : #include <linux/mmc/card.h>
      16                 :            : #include <linux/mmc/host.h>
      17                 :            : 
      18                 :            : #include "queue.h"
      19                 :            : #include "block.h"
      20                 :            : #include "core.h"
      21                 :            : #include "card.h"
      22                 :            : #include "host.h"
      23                 :            : 
      24                 :            : #define MMC_DMA_MAP_MERGE_SEGMENTS      512
      25                 :            : 
      26                 :            : static inline bool mmc_cqe_dcmd_busy(struct mmc_queue *mq)
      27                 :            : {
      28                 :            :         /* Allow only 1 DCMD at a time */
      29                 :          0 :         return mq->in_flight[MMC_ISSUE_DCMD];
      30                 :            : }
      31                 :            : 
      32                 :          0 : void mmc_cqe_check_busy(struct mmc_queue *mq)
      33                 :            : {
      34                 :          0 :         if ((mq->cqe_busy & MMC_CQE_DCMD_BUSY) && !mmc_cqe_dcmd_busy(mq))
      35                 :          0 :                 mq->cqe_busy &= ~MMC_CQE_DCMD_BUSY;
      36                 :            : 
      37                 :          0 :         mq->cqe_busy &= ~MMC_CQE_QUEUE_FULL;
      38                 :          0 : }
      39                 :            : 
      40                 :            : static inline bool mmc_cqe_can_dcmd(struct mmc_host *host)
      41                 :            : {
      42                 :          0 :         return host->caps2 & MMC_CAP2_CQE_DCMD;
      43                 :            : }
      44                 :            : 
      45                 :            : static enum mmc_issue_type mmc_cqe_issue_type(struct mmc_host *host,
      46                 :            :                                               struct request *req)
      47                 :            : {
      48                 :          0 :         switch (req_op(req)) {
      49                 :            :         case REQ_OP_DRV_IN:
      50                 :            :         case REQ_OP_DRV_OUT:
      51                 :            :         case REQ_OP_DISCARD:
      52                 :            :         case REQ_OP_SECURE_ERASE:
      53                 :            :                 return MMC_ISSUE_SYNC;
      54                 :            :         case REQ_OP_FLUSH:
      55                 :          0 :                 return mmc_cqe_can_dcmd(host) ? MMC_ISSUE_DCMD : MMC_ISSUE_SYNC;
      56                 :            :         default:
      57                 :            :                 return MMC_ISSUE_ASYNC;
      58                 :            :         }
      59                 :            : }
      60                 :            : 
      61                 :          3 : enum mmc_issue_type mmc_issue_type(struct mmc_queue *mq, struct request *req)
      62                 :            : {
      63                 :          3 :         struct mmc_host *host = mq->card->host;
      64                 :            : 
      65                 :          3 :         if (mq->use_cqe)
      66                 :          0 :                 return mmc_cqe_issue_type(host, req);
      67                 :            : 
      68                 :          3 :         if (req_op(req) == REQ_OP_READ || req_op(req) == REQ_OP_WRITE)
      69                 :            :                 return MMC_ISSUE_ASYNC;
      70                 :            : 
      71                 :          0 :         return MMC_ISSUE_SYNC;
      72                 :            : }
      73                 :            : 
      74                 :          0 : static void __mmc_cqe_recovery_notifier(struct mmc_queue *mq)
      75                 :            : {
      76                 :          0 :         if (!mq->recovery_needed) {
      77                 :          0 :                 mq->recovery_needed = true;
      78                 :          0 :                 schedule_work(&mq->recovery_work);
      79                 :            :         }
      80                 :          0 : }
      81                 :            : 
      82                 :          0 : void mmc_cqe_recovery_notifier(struct mmc_request *mrq)
      83                 :            : {
      84                 :            :         struct mmc_queue_req *mqrq = container_of(mrq, struct mmc_queue_req,
      85                 :            :                                                   brq.mrq);
      86                 :            :         struct request *req = mmc_queue_req_to_req(mqrq);
      87                 :          0 :         struct request_queue *q = req->q;
      88                 :          0 :         struct mmc_queue *mq = q->queuedata;
      89                 :            :         unsigned long flags;
      90                 :            : 
      91                 :          0 :         spin_lock_irqsave(&mq->lock, flags);
      92                 :          0 :         __mmc_cqe_recovery_notifier(mq);
      93                 :            :         spin_unlock_irqrestore(&mq->lock, flags);
      94                 :          0 : }
      95                 :            : 
      96                 :          0 : static enum blk_eh_timer_return mmc_cqe_timed_out(struct request *req)
      97                 :            : {
      98                 :            :         struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
      99                 :          0 :         struct mmc_request *mrq = &mqrq->brq.mrq;
     100                 :          0 :         struct mmc_queue *mq = req->q->queuedata;
     101                 :          0 :         struct mmc_host *host = mq->card->host;
     102                 :          0 :         enum mmc_issue_type issue_type = mmc_issue_type(mq, req);
     103                 :          0 :         bool recovery_needed = false;
     104                 :            : 
     105                 :          0 :         switch (issue_type) {
     106                 :            :         case MMC_ISSUE_ASYNC:
     107                 :            :         case MMC_ISSUE_DCMD:
     108                 :          0 :                 if (host->cqe_ops->cqe_timeout(host, mrq, &recovery_needed)) {
     109                 :          0 :                         if (recovery_needed)
     110                 :          0 :                                 mmc_cqe_recovery_notifier(mrq);
     111                 :            :                         return BLK_EH_RESET_TIMER;
     112                 :            :                 }
     113                 :            :                 /* The request has gone already */
     114                 :            :                 return BLK_EH_DONE;
     115                 :            :         default:
     116                 :            :                 /* Timeout is handled by mmc core */
     117                 :            :                 return BLK_EH_RESET_TIMER;
     118                 :            :         }
     119                 :            : }
     120                 :            : 
     121                 :          0 : static enum blk_eh_timer_return mmc_mq_timed_out(struct request *req,
     122                 :            :                                                  bool reserved)
     123                 :            : {
     124                 :          0 :         struct request_queue *q = req->q;
     125                 :          0 :         struct mmc_queue *mq = q->queuedata;
     126                 :            :         unsigned long flags;
     127                 :            :         bool ignore_tout;
     128                 :            : 
     129                 :          0 :         spin_lock_irqsave(&mq->lock, flags);
     130                 :          0 :         ignore_tout = mq->recovery_needed || !mq->use_cqe;
     131                 :            :         spin_unlock_irqrestore(&mq->lock, flags);
     132                 :            : 
     133                 :          0 :         return ignore_tout ? BLK_EH_RESET_TIMER : mmc_cqe_timed_out(req);
     134                 :            : }
     135                 :            : 
     136                 :          0 : static void mmc_mq_recovery_handler(struct work_struct *work)
     137                 :            : {
     138                 :          0 :         struct mmc_queue *mq = container_of(work, struct mmc_queue,
     139                 :            :                                             recovery_work);
     140                 :          0 :         struct request_queue *q = mq->queue;
     141                 :            : 
     142                 :          0 :         mmc_get_card(mq->card, &mq->ctx);
     143                 :            : 
     144                 :          0 :         mq->in_recovery = true;
     145                 :            : 
     146                 :          0 :         if (mq->use_cqe)
     147                 :          0 :                 mmc_blk_cqe_recovery(mq);
     148                 :            :         else
     149                 :          0 :                 mmc_blk_mq_recovery(mq);
     150                 :            : 
     151                 :          0 :         mq->in_recovery = false;
     152                 :            : 
     153                 :            :         spin_lock_irq(&mq->lock);
     154                 :          0 :         mq->recovery_needed = false;
     155                 :            :         spin_unlock_irq(&mq->lock);
     156                 :            : 
     157                 :          0 :         mmc_put_card(mq->card, &mq->ctx);
     158                 :            : 
     159                 :          0 :         blk_mq_run_hw_queues(q, true);
     160                 :          0 : }
     161                 :            : 
     162                 :          3 : static struct scatterlist *mmc_alloc_sg(int sg_len, gfp_t gfp)
     163                 :            : {
     164                 :            :         struct scatterlist *sg;
     165                 :            : 
     166                 :          3 :         sg = kmalloc_array(sg_len, sizeof(*sg), gfp);
     167                 :          3 :         if (sg)
     168                 :          3 :                 sg_init_table(sg, sg_len);
     169                 :            : 
     170                 :          3 :         return sg;
     171                 :            : }
     172                 :            : 
     173                 :          3 : static void mmc_queue_setup_discard(struct request_queue *q,
     174                 :            :                                     struct mmc_card *card)
     175                 :            : {
     176                 :            :         unsigned max_discard;
     177                 :            : 
     178                 :          3 :         max_discard = mmc_calc_max_discard(card);
     179                 :          3 :         if (!max_discard)
     180                 :          3 :                 return;
     181                 :            : 
     182                 :          3 :         blk_queue_flag_set(QUEUE_FLAG_DISCARD, q);
     183                 :          3 :         blk_queue_max_discard_sectors(q, max_discard);
     184                 :          3 :         q->limits.discard_granularity = card->pref_erase << 9;
     185                 :            :         /* granularity must not be greater than max. discard */
     186                 :          3 :         if (card->pref_erase > max_discard)
     187                 :          0 :                 q->limits.discard_granularity = 0;
     188                 :          3 :         if (mmc_can_secure_erase_trim(card))
     189                 :          0 :                 blk_queue_flag_set(QUEUE_FLAG_SECERASE, q);
     190                 :            : }
     191                 :            : 
     192                 :            : static unsigned int mmc_get_max_segments(struct mmc_host *host)
     193                 :            : {
     194                 :          3 :         return host->can_dma_map_merge ? MMC_DMA_MAP_MERGE_SEGMENTS :
     195                 :          3 :                                          host->max_segs;
     196                 :            : }
     197                 :            : 
     198                 :            : /**
     199                 :            :  * mmc_init_request() - initialize the MMC-specific per-request data
     200                 :            :  * @q: the request queue
     201                 :            :  * @req: the request
     202                 :            :  * @gfp: memory allocation policy
     203                 :            :  */
     204                 :          3 : static int __mmc_init_request(struct mmc_queue *mq, struct request *req,
     205                 :            :                               gfp_t gfp)
     206                 :            : {
     207                 :            :         struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req);
     208                 :          3 :         struct mmc_card *card = mq->card;
     209                 :          3 :         struct mmc_host *host = card->host;
     210                 :            : 
     211                 :          3 :         mq_rq->sg = mmc_alloc_sg(mmc_get_max_segments(host), gfp);
     212                 :          3 :         if (!mq_rq->sg)
     213                 :            :                 return -ENOMEM;
     214                 :            : 
     215                 :          3 :         return 0;
     216                 :            : }
     217                 :            : 
     218                 :            : static void mmc_exit_request(struct request_queue *q, struct request *req)
     219                 :            : {
     220                 :            :         struct mmc_queue_req *mq_rq = req_to_mmc_queue_req(req);
     221                 :            : 
     222                 :          0 :         kfree(mq_rq->sg);
     223                 :          0 :         mq_rq->sg = NULL;
     224                 :            : }
     225                 :            : 
     226                 :          3 : static int mmc_mq_init_request(struct blk_mq_tag_set *set, struct request *req,
     227                 :            :                                unsigned int hctx_idx, unsigned int numa_node)
     228                 :            : {
     229                 :          3 :         return __mmc_init_request(set->driver_data, req, GFP_KERNEL);
     230                 :            : }
     231                 :            : 
     232                 :          0 : static void mmc_mq_exit_request(struct blk_mq_tag_set *set, struct request *req,
     233                 :            :                                 unsigned int hctx_idx)
     234                 :            : {
     235                 :            :         struct mmc_queue *mq = set->driver_data;
     236                 :            : 
     237                 :            :         mmc_exit_request(mq->queue, req);
     238                 :          0 : }
     239                 :            : 
     240                 :          3 : static blk_status_t mmc_mq_queue_rq(struct blk_mq_hw_ctx *hctx,
     241                 :            :                                     const struct blk_mq_queue_data *bd)
     242                 :            : {
     243                 :          3 :         struct request *req = bd->rq;
     244                 :          3 :         struct request_queue *q = req->q;
     245                 :          3 :         struct mmc_queue *mq = q->queuedata;
     246                 :          3 :         struct mmc_card *card = mq->card;
     247                 :          3 :         struct mmc_host *host = card->host;
     248                 :            :         enum mmc_issue_type issue_type;
     249                 :            :         enum mmc_issued issued;
     250                 :            :         bool get_card, cqe_retune_ok;
     251                 :            :         int ret;
     252                 :            : 
     253                 :          3 :         if (mmc_card_removed(mq->card)) {
     254                 :          0 :                 req->rq_flags |= RQF_QUIET;
     255                 :          0 :                 return BLK_STS_IOERR;
     256                 :            :         }
     257                 :            : 
     258                 :          3 :         issue_type = mmc_issue_type(mq, req);
     259                 :            : 
     260                 :            :         spin_lock_irq(&mq->lock);
     261                 :            : 
     262                 :          3 :         if (mq->recovery_needed || mq->busy) {
     263                 :            :                 spin_unlock_irq(&mq->lock);
     264                 :          0 :                 return BLK_STS_RESOURCE;
     265                 :            :         }
     266                 :            : 
     267                 :          3 :         switch (issue_type) {
     268                 :            :         case MMC_ISSUE_DCMD:
     269                 :          0 :                 if (mmc_cqe_dcmd_busy(mq)) {
     270                 :          0 :                         mq->cqe_busy |= MMC_CQE_DCMD_BUSY;
     271                 :            :                         spin_unlock_irq(&mq->lock);
     272                 :          0 :                         return BLK_STS_RESOURCE;
     273                 :            :                 }
     274                 :            :                 break;
     275                 :            :         case MMC_ISSUE_ASYNC:
     276                 :            :                 break;
     277                 :            :         default:
     278                 :            :                 /*
     279                 :            :                  * Timeouts are handled by mmc core, and we don't have a host
     280                 :            :                  * API to abort requests, so we can't handle the timeout anyway.
     281                 :            :                  * However, when the timeout happens, blk_mq_complete_request()
     282                 :            :                  * no longer works (to stop the request disappearing under us).
     283                 :            :                  * To avoid racing with that, set a large timeout.
     284                 :            :                  */
     285                 :          0 :                 req->timeout = 600 * HZ;
     286                 :          0 :                 break;
     287                 :            :         }
     288                 :            : 
     289                 :            :         /* Parallel dispatch of requests is not supported at the moment */
     290                 :          3 :         mq->busy = true;
     291                 :            : 
     292                 :          3 :         mq->in_flight[issue_type] += 1;
     293                 :            :         get_card = (mmc_tot_in_flight(mq) == 1);
     294                 :            :         cqe_retune_ok = (mmc_cqe_qcnt(mq) == 1);
     295                 :            : 
     296                 :            :         spin_unlock_irq(&mq->lock);
     297                 :            : 
     298                 :          3 :         if (!(req->rq_flags & RQF_DONTPREP)) {
     299                 :          3 :                 req_to_mmc_queue_req(req)->retries = 0;
     300                 :          3 :                 req->rq_flags |= RQF_DONTPREP;
     301                 :            :         }
     302                 :            : 
     303                 :          3 :         if (get_card)
     304                 :          3 :                 mmc_get_card(card, &mq->ctx);
     305                 :            : 
     306                 :          3 :         if (mq->use_cqe) {
     307                 :          0 :                 host->retune_now = host->need_retune && cqe_retune_ok &&
     308                 :          0 :                                    !host->hold_retune;
     309                 :            :         }
     310                 :            : 
     311                 :          3 :         blk_mq_start_request(req);
     312                 :            : 
     313                 :          3 :         issued = mmc_blk_mq_issue_rq(mq, req);
     314                 :            : 
     315                 :          3 :         switch (issued) {
     316                 :            :         case MMC_REQ_BUSY:
     317                 :            :                 ret = BLK_STS_RESOURCE;
     318                 :            :                 break;
     319                 :            :         case MMC_REQ_FAILED_TO_START:
     320                 :            :                 ret = BLK_STS_IOERR;
     321                 :          0 :                 break;
     322                 :            :         default:
     323                 :            :                 ret = BLK_STS_OK;
     324                 :          3 :                 break;
     325                 :            :         }
     326                 :            : 
     327                 :          3 :         if (issued != MMC_REQ_STARTED) {
     328                 :            :                 bool put_card = false;
     329                 :            : 
     330                 :            :                 spin_lock_irq(&mq->lock);
     331                 :          0 :                 mq->in_flight[issue_type] -= 1;
     332                 :          0 :                 if (mmc_tot_in_flight(mq) == 0)
     333                 :            :                         put_card = true;
     334                 :          0 :                 mq->busy = false;
     335                 :            :                 spin_unlock_irq(&mq->lock);
     336                 :          0 :                 if (put_card)
     337                 :          0 :                         mmc_put_card(card, &mq->ctx);
     338                 :            :         } else {
     339                 :            :                 WRITE_ONCE(mq->busy, false);
     340                 :            :         }
     341                 :            : 
     342                 :          3 :         return ret;
     343                 :            : }
     344                 :            : 
     345                 :            : static const struct blk_mq_ops mmc_mq_ops = {
     346                 :            :         .queue_rq       = mmc_mq_queue_rq,
     347                 :            :         .init_request   = mmc_mq_init_request,
     348                 :            :         .exit_request   = mmc_mq_exit_request,
     349                 :            :         .complete       = mmc_blk_mq_complete,
     350                 :            :         .timeout        = mmc_mq_timed_out,
     351                 :            : };
     352                 :            : 
     353                 :          3 : static void mmc_setup_queue(struct mmc_queue *mq, struct mmc_card *card)
     354                 :            : {
     355                 :          3 :         struct mmc_host *host = card->host;
     356                 :            :         unsigned block_size = 512;
     357                 :            : 
     358                 :          3 :         blk_queue_flag_set(QUEUE_FLAG_NONROT, mq->queue);
     359                 :          3 :         blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, mq->queue);
     360                 :          3 :         if (mmc_can_erase(card))
     361                 :          3 :                 mmc_queue_setup_discard(mq->queue, card);
     362                 :            : 
     363                 :          3 :         if (!mmc_dev(host)->dma_mask || !*mmc_dev(host)->dma_mask)
     364                 :          0 :                 blk_queue_bounce_limit(mq->queue, BLK_BOUNCE_HIGH);
     365                 :          3 :         blk_queue_max_hw_sectors(mq->queue,
     366                 :          3 :                 min(host->max_blk_count, host->max_req_size / 512));
     367                 :          3 :         if (host->can_dma_map_merge)
     368                 :          0 :                 WARN(!blk_queue_can_use_dma_map_merging(mq->queue,
     369                 :            :                                                         mmc_dev(host)),
     370                 :            :                      "merging was advertised but not possible");
     371                 :          3 :         blk_queue_max_segments(mq->queue, mmc_get_max_segments(host));
     372                 :            : 
     373                 :          3 :         if (mmc_card_mmc(card))
     374                 :          0 :                 block_size = card->ext_csd.data_sector_size;
     375                 :            : 
     376                 :          3 :         blk_queue_logical_block_size(mq->queue, block_size);
     377                 :            :         /*
     378                 :            :          * After blk_queue_can_use_dma_map_merging() was called with succeed,
     379                 :            :          * since it calls blk_queue_virt_boundary(), the mmc should not call
     380                 :            :          * both blk_queue_max_segment_size().
     381                 :            :          */
     382                 :          3 :         if (!host->can_dma_map_merge)
     383                 :          3 :                 blk_queue_max_segment_size(mq->queue,
     384                 :          3 :                         round_down(host->max_seg_size, block_size));
     385                 :            : 
     386                 :          3 :         dma_set_max_seg_size(mmc_dev(host), queue_max_segment_size(mq->queue));
     387                 :            : 
     388                 :          3 :         INIT_WORK(&mq->recovery_work, mmc_mq_recovery_handler);
     389                 :          3 :         INIT_WORK(&mq->complete_work, mmc_blk_mq_complete_work);
     390                 :            : 
     391                 :          3 :         mutex_init(&mq->complete_lock);
     392                 :            : 
     393                 :          3 :         init_waitqueue_head(&mq->wait);
     394                 :          3 : }
     395                 :            : 
     396                 :            : static inline bool mmc_merge_capable(struct mmc_host *host)
     397                 :            : {
     398                 :          3 :         return host->caps2 & MMC_CAP2_MERGE_CAPABLE;
     399                 :            : }
     400                 :            : 
     401                 :            : /* Set queue depth to get a reasonable value for q->nr_requests */
     402                 :            : #define MMC_QUEUE_DEPTH 64
     403                 :            : 
     404                 :            : /**
     405                 :            :  * mmc_init_queue - initialise a queue structure.
     406                 :            :  * @mq: mmc queue
     407                 :            :  * @card: mmc card to attach this queue
     408                 :            :  *
     409                 :            :  * Initialise a MMC card request queue.
     410                 :            :  */
     411                 :          3 : int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card)
     412                 :            : {
     413                 :          3 :         struct mmc_host *host = card->host;
     414                 :            :         int ret;
     415                 :            : 
     416                 :          3 :         mq->card = card;
     417                 :          3 :         mq->use_cqe = host->cqe_enabled;
     418                 :            :         
     419                 :          3 :         spin_lock_init(&mq->lock);
     420                 :            : 
     421                 :          3 :         memset(&mq->tag_set, 0, sizeof(mq->tag_set));
     422                 :          3 :         mq->tag_set.ops = &mmc_mq_ops;
     423                 :            :         /*
     424                 :            :          * The queue depth for CQE must match the hardware because the request
     425                 :            :          * tag is used to index the hardware queue.
     426                 :            :          */
     427                 :          3 :         if (mq->use_cqe)
     428                 :          0 :                 mq->tag_set.queue_depth =
     429                 :          0 :                         min_t(int, card->ext_csd.cmdq_depth, host->cqe_qdepth);
     430                 :            :         else
     431                 :          3 :                 mq->tag_set.queue_depth = MMC_QUEUE_DEPTH;
     432                 :          3 :         mq->tag_set.numa_node = NUMA_NO_NODE;
     433                 :          3 :         mq->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING;
     434                 :          3 :         mq->tag_set.nr_hw_queues = 1;
     435                 :          3 :         mq->tag_set.cmd_size = sizeof(struct mmc_queue_req);
     436                 :          3 :         mq->tag_set.driver_data = mq;
     437                 :            : 
     438                 :            :         /*
     439                 :            :          * Since blk_mq_alloc_tag_set() calls .init_request() of mmc_mq_ops,
     440                 :            :          * the host->can_dma_map_merge should be set before to get max_segs
     441                 :            :          * from mmc_get_max_segments().
     442                 :            :          */
     443                 :          3 :         if (mmc_merge_capable(host) &&
     444                 :          0 :             host->max_segs < MMC_DMA_MAP_MERGE_SEGMENTS &&
     445                 :          0 :             dma_get_merge_boundary(mmc_dev(host)))
     446                 :          0 :                 host->can_dma_map_merge = 1;
     447                 :            :         else
     448                 :          3 :                 host->can_dma_map_merge = 0;
     449                 :            : 
     450                 :          3 :         ret = blk_mq_alloc_tag_set(&mq->tag_set);
     451                 :          3 :         if (ret)
     452                 :            :                 return ret;
     453                 :            : 
     454                 :          3 :         mq->queue = blk_mq_init_queue(&mq->tag_set);
     455                 :          3 :         if (IS_ERR(mq->queue)) {
     456                 :            :                 ret = PTR_ERR(mq->queue);
     457                 :            :                 goto free_tag_set;
     458                 :            :         }
     459                 :            : 
     460                 :          3 :         if (mmc_host_is_spi(host) && host->use_spi_crc)
     461                 :          0 :                 mq->queue->backing_dev_info->capabilities |=
     462                 :            :                         BDI_CAP_STABLE_WRITES;
     463                 :            : 
     464                 :          3 :         mq->queue->queuedata = mq;
     465                 :          3 :         blk_queue_rq_timeout(mq->queue, 60 * HZ);
     466                 :            : 
     467                 :          3 :         mmc_setup_queue(mq, card);
     468                 :          3 :         return 0;
     469                 :            : 
     470                 :            : free_tag_set:
     471                 :          0 :         blk_mq_free_tag_set(&mq->tag_set);
     472                 :          0 :         return ret;
     473                 :            : }
     474                 :            : 
     475                 :          0 : void mmc_queue_suspend(struct mmc_queue *mq)
     476                 :            : {
     477                 :          0 :         blk_mq_quiesce_queue(mq->queue);
     478                 :            : 
     479                 :            :         /*
     480                 :            :          * The host remains claimed while there are outstanding requests, so
     481                 :            :          * simply claiming and releasing here ensures there are none.
     482                 :            :          */
     483                 :          0 :         mmc_claim_host(mq->card->host);
     484                 :          0 :         mmc_release_host(mq->card->host);
     485                 :          0 : }
     486                 :            : 
     487                 :          0 : void mmc_queue_resume(struct mmc_queue *mq)
     488                 :            : {
     489                 :          0 :         blk_mq_unquiesce_queue(mq->queue);
     490                 :          0 : }
     491                 :            : 
     492                 :          0 : void mmc_cleanup_queue(struct mmc_queue *mq)
     493                 :            : {
     494                 :          0 :         struct request_queue *q = mq->queue;
     495                 :            : 
     496                 :            :         /*
     497                 :            :          * The legacy code handled the possibility of being suspended,
     498                 :            :          * so do that here too.
     499                 :            :          */
     500                 :          0 :         if (blk_queue_quiesced(q))
     501                 :          0 :                 blk_mq_unquiesce_queue(q);
     502                 :            : 
     503                 :          0 :         blk_cleanup_queue(q);
     504                 :          0 :         blk_mq_free_tag_set(&mq->tag_set);
     505                 :            : 
     506                 :            :         /*
     507                 :            :          * A request can be completed before the next request, potentially
     508                 :            :          * leaving a complete_work with nothing to do. Such a work item might
     509                 :            :          * still be queued at this point. Flush it.
     510                 :            :          */
     511                 :          0 :         flush_work(&mq->complete_work);
     512                 :            : 
     513                 :          0 :         mq->card = NULL;
     514                 :          0 : }
     515                 :            : 
     516                 :            : /*
     517                 :            :  * Prepare the sg list(s) to be handed of to the host driver
     518                 :            :  */
     519                 :          3 : unsigned int mmc_queue_map_sg(struct mmc_queue *mq, struct mmc_queue_req *mqrq)
     520                 :            : {
     521                 :            :         struct request *req = mmc_queue_req_to_req(mqrq);
     522                 :            : 
     523                 :          3 :         return blk_rq_map_sg(mq->queue, req, mqrq->sg);
     524                 :            : }
    

Generated by: LCOV version 1.14