From patchwork Thu Oct 11 16:59:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10637055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 258B43CF1 for ; Thu, 11 Oct 2018 16:59:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1217F2BC71 for ; Thu, 11 Oct 2018 16:59:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06A2F2BC73; Thu, 11 Oct 2018 16:59:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 18AA22BC85 for ; Thu, 11 Oct 2018 16:59:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730779AbeJLA1u (ORCPT ); Thu, 11 Oct 2018 20:27:50 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:44084 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730621AbeJLA1u (ORCPT ); Thu, 11 Oct 2018 20:27:50 -0400 Received: by mail-io1-f65.google.com with SMTP id x26-v6so7136696iog.11 for ; Thu, 11 Oct 2018 09:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6BuvQEA8vZ5dlycA4ZWFDerayozi0hak+U1N/UT2yUc=; b=sT1dUeyroUq/AAQZ3psC7eY1S380XsuDipUTyogzu/OIQ4VPAkVU8u+ZJVr+/ZTArr AoB1z3Awsowz65UwWhwieOJVMrY72eOcqyRvDyO2G3U1r0ZX/Jz9HQN4g8zKubBwuH6M wXehF/tmj3rBHm8izMRaVtV9DWPqxeSKnpr4rkPVHrcl1mabavlyR7zacPECGmCxrhQQ g/oL1WmJxQyP0cDAtBccL99mKi3FUAORHaM9rCSkz9cQusM9IDVqDKXCa4hlPLX8I0s1 LrkpSgOdrJoer/RpC3h7bRoZC35esDz8gMS5CTRcAl4G7cfBPrkjyH3Oj8PM0U+u8mH1 PUaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6BuvQEA8vZ5dlycA4ZWFDerayozi0hak+U1N/UT2yUc=; b=AQqXxT9KwspkIU0s7LcZ64yfSwMkEmYPxCnehH3zkBPsm6N0OyAdBliqgTuperHoxV 2be4bYC77NGKw3WUU6qXrkOuEY0957x6U09RacDg0fmRLJwS4c+f+aWyNFJlxFg7wboo /C1X60E2XsII4cbd9RmwZ/22bSKQ3z9nbiH6LC2VKE3bEgFiBEmlwIe1kTyTngZEYdSb BJlGyAx10I+0M08tdB/qC6/eSRMo94Lsc+NRy91zb66sXERSEEgVuJ9Q9S+LWh7H7SqQ qTVrV+U41ilpJP8v73ZP3OW5kc6fKW+IeX6up+nmwvaFQbxJLyZxfMMbHpsOG4gSsJ2z UrAg== X-Gm-Message-State: ABuFfogc6exnunbr2VVMjc8/edFe4AOU3fKocQVzGT/GvuacGh0EmPkY KwEQkvnYwtaNdAB/NFHnZYw9H4Qw7Zw= X-Google-Smtp-Source: ACcGV628RnMg0XfuQt46AzLnk1XLcHNgDJqphbhhWKJWRiurxp68n7SAR8TeOc5pF2TbDYW9n9m4bw== X-Received: by 2002:a6b:4f0e:: with SMTP id d14-v6mr1820203iob.68.1539277183528; Thu, 11 Oct 2018 09:59:43 -0700 (PDT) Received: from localhost.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id z128-v6sm8366088itc.21.2018.10.11.09.59.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 09:59:42 -0700 (PDT) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe , Michal Simek Subject: [PATCH 15/17] xsysace: convert to blk-mq Date: Thu, 11 Oct 2018 10:59:07 -0600 Message-Id: <20181011165909.32615-16-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181011165909.32615-1-axboe@kernel.dk> References: <20181011165909.32615-1-axboe@kernel.dk> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Straight forward conversion, using an internal list to enable the driver to pull requests at will. Cc: Michal Simek Signed-off-by: Jens Axboe Acked-by: Michal Simek --- drivers/block/xsysace.c | 91 ++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 25 deletions(-) diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c index c24589414c75..ddaa362ffe82 100644 --- a/drivers/block/xsysace.c +++ b/drivers/block/xsysace.c @@ -88,7 +88,7 @@ #include #include #include -#include +#include #include #include #include @@ -209,6 +209,8 @@ struct ace_device { struct device *dev; struct request_queue *queue; struct gendisk *gd; + struct blk_mq_tag_set tag_set; + struct list_head rq_list; /* Inserted CF card parameters */ u16 cf_id[ATA_ID_WORDS]; @@ -462,18 +464,26 @@ static inline void ace_fsm_yieldirq(struct ace_device *ace) ace->fsm_continue_flag = 0; } +static bool ace_has_next_request(struct request_queue *q) +{ + struct ace_device *ace = q->queuedata; + + return !list_empty(&ace->rq_list); +} + /* Get the next read/write request; ending requests that we don't handle */ static struct request *ace_get_next_request(struct request_queue *q) { - struct request *req; + struct ace_device *ace = q->queuedata; + struct request *rq; - while ((req = blk_peek_request(q)) != NULL) { - if (!blk_rq_is_passthrough(req)) - break; - blk_start_request(req); - __blk_end_request_all(req, BLK_STS_IOERR); + rq = list_first_entry_or_null(&ace->rq_list, struct request, queuelist); + if (rq) { + list_del_init(&rq->queuelist); + blk_mq_start_request(rq); } - return req; + + return NULL; } static void ace_fsm_dostate(struct ace_device *ace) @@ -499,11 +509,11 @@ static void ace_fsm_dostate(struct ace_device *ace) /* Drop all in-flight and pending requests */ if (ace->req) { - __blk_end_request_all(ace->req, BLK_STS_IOERR); + blk_mq_end_request(ace->req, BLK_STS_IOERR); ace->req = NULL; } - while ((req = blk_fetch_request(ace->queue)) != NULL) - __blk_end_request_all(req, BLK_STS_IOERR); + while ((req = ace_get_next_request(ace->queue)) != NULL) + blk_mq_end_request(req, BLK_STS_IOERR); /* Drop back to IDLE state and notify waiters */ ace->fsm_state = ACE_FSM_STATE_IDLE; @@ -517,7 +527,7 @@ static void ace_fsm_dostate(struct ace_device *ace) switch (ace->fsm_state) { case ACE_FSM_STATE_IDLE: /* See if there is anything to do */ - if (ace->id_req_count || ace_get_next_request(ace->queue)) { + if (ace->id_req_count || ace_has_next_request(ace->queue)) { ace->fsm_iter_num++; ace->fsm_state = ACE_FSM_STATE_REQ_LOCK; mod_timer(&ace->stall_timer, jiffies + HZ); @@ -651,7 +661,6 @@ static void ace_fsm_dostate(struct ace_device *ace) ace->fsm_state = ACE_FSM_STATE_IDLE; break; } - blk_start_request(req); /* Okay, it's a data request, set it up for transfer */ dev_dbg(ace->dev, @@ -728,7 +737,8 @@ static void ace_fsm_dostate(struct ace_device *ace) } /* bio finished; is there another one? */ - if (__blk_end_request_cur(ace->req, BLK_STS_OK)) { + if (blk_update_request(ace->req, BLK_STS_OK, + blk_rq_cur_bytes(ace->req))) { /* dev_dbg(ace->dev, "next block; h=%u c=%u\n", * blk_rq_sectors(ace->req), * blk_rq_cur_sectors(ace->req)); @@ -854,17 +864,23 @@ static irqreturn_t ace_interrupt(int irq, void *dev_id) /* --------------------------------------------------------------------- * Block ops */ -static void ace_request(struct request_queue * q) +static blk_status_t ace_queue_rq(struct blk_mq_hw_ctx *hctx, + const struct blk_mq_queue_data *bd) { - struct request *req; - struct ace_device *ace; + struct ace_device *ace = hctx->queue->queuedata; + struct request *req = bd->rq; - req = ace_get_next_request(q); - - if (req) { - ace = req->rq_disk->private_data; - tasklet_schedule(&ace->fsm_tasklet); + if (blk_rq_is_passthrough(req)) { + blk_mq_start_request(req); + return BLK_STS_IOERR; } + + spin_lock_irq(&ace->lock); + list_add_tail(&req->queuelist, &ace->rq_list); + spin_unlock_irq(&ace->lock); + + tasklet_schedule(&ace->fsm_tasklet); + return BLK_STS_OK; } static unsigned int ace_check_events(struct gendisk *gd, unsigned int clearing) @@ -957,11 +973,16 @@ static const struct block_device_operations ace_fops = { .getgeo = ace_getgeo, }; +static const struct blk_mq_ops ace_mq_ops = { + .queue_rq = ace_queue_rq, +}; + /* -------------------------------------------------------------------- * SystemACE device setup/teardown code */ static int ace_setup(struct ace_device *ace) { + struct blk_mq_tag_set *set; u16 version; u16 val; int rc; @@ -972,6 +993,7 @@ static int ace_setup(struct ace_device *ace) spin_lock_init(&ace->lock); init_completion(&ace->id_completion); + INIT_LIST_HEAD(&ace->rq_list); /* * Map the device @@ -989,9 +1011,25 @@ static int ace_setup(struct ace_device *ace) /* * Initialize the request queue */ - ace->queue = blk_init_queue(ace_request, &ace->lock); - if (ace->queue == NULL) + set = &ace->tag_set; + set->ops = &ace_mq_ops; + set->nr_hw_queues = 1; + set->queue_depth = 2; + set->numa_node = NUMA_NO_NODE; + set->flags = BLK_MQ_F_SHOULD_MERGE; + rc = blk_mq_alloc_tag_set(set); + if (rc) goto err_blk_initq; + + ace->queue = blk_mq_init_queue(set); + if (IS_ERR(ace->queue)) { + rc = PTR_ERR(ace->queue); + ace->queue = NULL; + blk_mq_free_tag_set(&ace->tag_set); + goto err_blk_initq; + } + ace->queue->queuedata = ace; + blk_queue_logical_block_size(ace->queue, 512); blk_queue_bounce_limit(ace->queue, BLK_BOUNCE_HIGH); @@ -1065,6 +1103,7 @@ static int ace_setup(struct ace_device *ace) err_read: put_disk(ace->gd); err_alloc_disk: + blk_mq_free_tag_set(&ace->tag_set); blk_cleanup_queue(ace->queue); err_blk_initq: iounmap(ace->baseaddr); @@ -1081,8 +1120,10 @@ static void ace_teardown(struct ace_device *ace) put_disk(ace->gd); } - if (ace->queue) + if (ace->queue) { + blk_mq_free_tag_set(&ace->tag_set); blk_cleanup_queue(ace->queue); + } tasklet_kill(&ace->fsm_tasklet);