From patchwork Thu Oct 11 19:20:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637221 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 4084E112B for ; Thu, 11 Oct 2018 19:21:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C91B2C02B for ; Thu, 11 Oct 2018 19:21:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2ADB82C017; Thu, 11 Oct 2018 19:21:02 +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 8CF9D2C02B for ; Thu, 11 Oct 2018 19:21:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729693AbeJLCtf (ORCPT ); Thu, 11 Oct 2018 22:49:35 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38054 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729564AbeJLCtf (ORCPT ); Thu, 11 Oct 2018 22:49:35 -0400 Received: by mail-pg1-f195.google.com with SMTP id f8-v6so4627848pgq.5 for ; Thu, 11 Oct 2018 12:21:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+6VZot58qp49Ij07oU7N0yQ3eeu/2FmOrP+jtMbEq1s=; b=xU55UhZzf95LvWuIm2ehiHuwc4NVfZjZqpN02paOJMmEvy8S9Mezp14VKYu0DC+fpa gC7UP7VT5ZhrKc7SFJteZ+HFfBAkiFBsKrFk1eh5gH2blbSZNpqTBJpBva/1Ucpp+l0X 18EfZG5Im71ACag4evcg23nu02f5KA46xZrsNvdwreo9K6xmVVSi2VZEqQdQC9Zs7GHD GH5Z0RGF4yLhvSjod5NahQ6wRaLq7aR0S7+iy+NdoqsnFw4Lwumv45SOECeUo1CM6cA9 QX8scbr6ArEY4qxQj/bYrBxbzTjUjXaPHGZrHSQ52jjblvclz3u8c73u+bQVCQ+RYcoX rpBQ== 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:mime-version:content-transfer-encoding; bh=+6VZot58qp49Ij07oU7N0yQ3eeu/2FmOrP+jtMbEq1s=; b=D2e5M8GZFpOKcm06EWu1M1USNmLPsyOqAyDk6bd+qnTVsXBE8j+JZ6trMv48hqmgOg GLqydDd8TazOfmVGaLFhTzO4neDM2a7hQw17+cW7pxHnLSx/AC1xEYX59i25rGigb6mT OnvT9rCRtEya7rTHP9ZjvwbXASqD9YgCsLWvgK2g00F/NJ8ZlZud59m3J8MVmPpnIhDh u8RpbwcGeWbi3LKew+uqy8UGU5w+xFUsxfH//RFDqWNMY9aQy/IiEDCB1D/Wf3bYMyUH zMMQhXBV6oOiYHpRuVWRQWhtM+pn9ro0Ot4KhIfwnkqV/52mPSA0naL4zf1Dd9amGQVs 9JUQ== X-Gm-Message-State: ABuFfoi0O6uXzLXK6vvGdGfqTLBl8iQbCvuorF8JHH0Su3oUNjFMAjuV yIY/tagUQEJmmnqk3Ekh/RR2hZL/ne0= X-Google-Smtp-Source: ACcGV6354i+GEqJBJT9xfLCVT0K+3ayhGRp5y5LQGjQX1+mZBuDOjFqbJ4Wo+gYeyQib1xz8LCopXQ== X-Received: by 2002:a62:7788:: with SMTP id s130-v6mr2794465pfc.189.1539285659172; Thu, 11 Oct 2018 12:20:59 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id y24-v6sm44378838pfi.24.2018.10.11.12.20.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 12:20:58 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com, Finn Thain , Laurent Vivier Subject: [PATCH v2 02/11] swim: convert to blk-mq Date: Thu, 11 Oct 2018 12:20:42 -0700 Message-Id: <93deb9240babdba64c4a7e2fd8b8b0d3b2bdcbdc.1539284959.git.osandov@fb.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 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 From: Omar Sandoval The only interesting thing here is that there may be two floppies (i.e., request queues) sharing the same controller, so we use the global struct swim_priv->lock to check whether the controller is busy. Compile-tested only. Cc: Finn Thain Cc: Laurent Vivier Signed-off-by: Omar Sandoval Acked-by: Laurent Vivier --- drivers/block/swim.c | 101 +++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 52 deletions(-) diff --git a/drivers/block/swim.c b/drivers/block/swim.c index cbe909c51847..f07fa993c364 100644 --- a/drivers/block/swim.c +++ b/drivers/block/swim.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -190,6 +190,7 @@ struct floppy_state { int ref_count; struct gendisk *disk; + struct blk_mq_tag_set tag_set; /* parent controller */ @@ -211,7 +212,6 @@ enum head { struct swim_priv { struct swim __iomem *base; spinlock_t lock; - int fdc_queue; int floppy_count; struct floppy_state unit[FD_MAX_UNIT]; }; @@ -525,58 +525,36 @@ static blk_status_t floppy_read_sectors(struct floppy_state *fs, return 0; } -static struct request *swim_next_request(struct swim_priv *swd) +static blk_status_t swim_queue_rq(struct blk_mq_hw_ctx *hctx, + const struct blk_mq_queue_data *bd) { - struct request_queue *q; - struct request *rq; - int old_pos = swd->fdc_queue; + struct floppy_state *fs = hctx->queue->queuedata; + struct swim_priv *swd = fs->swd; + struct request *req = bd->rq; + blk_status_t err; - do { - q = swd->unit[swd->fdc_queue].disk->queue; - if (++swd->fdc_queue == swd->floppy_count) - swd->fdc_queue = 0; - if (q) { - rq = blk_fetch_request(q); - if (rq) - return rq; - } - } while (swd->fdc_queue != old_pos); + if (!spin_trylock_irq(&swd->lock)) + return BLK_STS_DEV_RESOURCE; - return NULL; -} + blk_mq_start_request(req); -static void do_fd_request(struct request_queue *q) -{ - struct swim_priv *swd = q->queuedata; - struct request *req; - struct floppy_state *fs; + if (!fs->disk_in || rq_data_dir(req) == WRITE) { + err = BLK_STS_IOERR; + goto out; + } - req = swim_next_request(swd); - while (req) { - blk_status_t err = BLK_STS_IOERR; + do { + err = floppy_read_sectors(fs, blk_rq_pos(req), + blk_rq_cur_sectors(req), + bio_data(req->bio)); + } while (blk_update_request(req, err, blk_rq_cur_bytes(req))); + __blk_mq_end_request(req, err); - fs = req->rq_disk->private_data; - if (blk_rq_pos(req) >= fs->total_secs) - goto done; - if (!fs->disk_in) - goto done; - if (rq_data_dir(req) == WRITE && fs->write_protected) - goto done; + err = BLK_STS_OK; +out: + spin_unlock_irq(&swd->lock); + return err; - switch (rq_data_dir(req)) { - case WRITE: - /* NOT IMPLEMENTED */ - break; - case READ: - err = floppy_read_sectors(fs, blk_rq_pos(req), - blk_rq_cur_sectors(req), - bio_data(req->bio)); - break; - } - done: - if (!__blk_end_request_cur(req, err)) - req = swim_next_request(swd); - } } static struct floppy_struct floppy_type[4] = { @@ -823,6 +801,10 @@ static int swim_add_floppy(struct swim_priv *swd, enum drive_location location) return 0; } +static const struct blk_mq_ops swim_mq_ops = { + .queue_rq = swim_queue_rq, +}; + static int swim_floppy_init(struct swim_priv *swd) { int err; @@ -852,20 +834,33 @@ static int swim_floppy_init(struct swim_priv *swd) spin_lock_init(&swd->lock); for (drive = 0; drive < swd->floppy_count; drive++) { + struct blk_mq_tag_set *set; + swd->unit[drive].disk = alloc_disk(1); if (swd->unit[drive].disk == NULL) { err = -ENOMEM; goto exit_put_disks; } - swd->unit[drive].disk->queue = blk_init_queue(do_fd_request, - &swd->lock); - if (!swd->unit[drive].disk->queue) { - err = -ENOMEM; + + set = &swd->unit[drive].tag_set; + set->ops = &swim_mq_ops; + set->nr_hw_queues = 1; + set->queue_depth = 2; + set->numa_node = NUMA_NO_NODE; + set->flags = BLK_MQ_F_SHOULD_MERGE; + err = blk_mq_alloc_tag_set(set); + if (err) + goto exit_put_disks; + + swd->unit[drive].disk->queue = blk_mq_init_queue(set); + if (IS_ERR(swd->unit[drive].disk->queue)) { + err = PTR_ERR(swd->unit[drive].disk->queue); + swd->unit[drive].disk->queue = NULL; goto exit_put_disks; } blk_queue_bounce_limit(swd->unit[drive].disk->queue, BLK_BOUNCE_HIGH); - swd->unit[drive].disk->queue->queuedata = swd; + swd->unit[drive].disk->queue->queuedata = &swd->unit[drive]; swd->unit[drive].swd = swd; } @@ -895,6 +890,7 @@ static int swim_floppy_init(struct swim_priv *swd) blk_cleanup_queue(disk->queue); disk->queue = NULL; } + blk_mq_free_tag_set(&swd->unit[drive].tag_set); put_disk(disk); } } while (drive--); @@ -970,6 +966,7 @@ static int swim_remove(struct platform_device *dev) for (drive = 0; drive < swd->floppy_count; drive++) { del_gendisk(swd->unit[drive].disk); blk_cleanup_queue(swd->unit[drive].disk->queue); + blk_mq_free_tag_set(&swd->unit[drive].tag_set); put_disk(swd->unit[drive].disk); }