From patchwork Thu Oct 11 18:30:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637083 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 E508F17E3 for ; Thu, 11 Oct 2018 18:30:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D89D02BED9 for ; Thu, 11 Oct 2018 18:30:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6FDB2BEDE; Thu, 11 Oct 2018 18:30:39 +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 8A57D2BEDB for ; Thu, 11 Oct 2018 18:30:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728762AbeJLB7C (ORCPT ); Thu, 11 Oct 2018 21:59:02 -0400 Received: from mail-pg1-f181.google.com ([209.85.215.181]:41178 "EHLO mail-pg1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729119AbeJLB7C (ORCPT ); Thu, 11 Oct 2018 21:59:02 -0400 Received: by mail-pg1-f181.google.com with SMTP id 23-v6so4566037pgc.8 for ; Thu, 11 Oct 2018 11:30:38 -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=i5CA2DVmUK9FVTPCh8E1wZSA/j10L4r/DeujVBBb8lM=; b=eTsh1ub1GwGxS1dTPMFYcgxo+vWF6RbsJx9PtaffJSwuc6n4TFof6Nhrr/0ZKSDXsV ifo+iutVH+TvTdjPZJLVL9aCdyxELbLa7JMH6eSgsAxrEYuS/G+5HNOY30k0zJNFRD8n c30LaopHMTl+5Ztfo59KswHuwRkygowBfEM5qn0CAwpRXMQUoH7gI4Q1FH77Z2pLMqzo qLpZkmu9IAIEaNw0/qXwZIt7zQjfbrBijG2Vs5JLfzCNtGn1MPyEDrOBF98medd29ySb W8/W1v3dbjjtR7XwG4Lqv9O1o1w9zixhtrrunKyJMDF4maxPBFC7UNelJPbCO1HytzGO HehQ== 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=i5CA2DVmUK9FVTPCh8E1wZSA/j10L4r/DeujVBBb8lM=; b=QDMxTOXoy3hlS+dsmJlt/MoBoXRxQWsZDCEi5UQtNp3dTBRC6X1PyaFGl4CUDJIxwF ZD03/E+ctSGLRp+nOPSfHRpvkENsKj/bvzhk/nrcNrKvK5Gn3lTsBX42y+E2b1KCCPwr Utj9dranhvH8YdoNjHsip9ecYNlp5scD6s3Xjb7nrbRQJOQNTdmjc1Brxh2ex3h4XDga BcLynl65FLsEz4jYsiouIH7VOesuCId41LhdB0EcGZ+eFkiasD3hM6rQti3d1ZReeuxe qtm9eFpZSEprUSBcFMPAgERi8QcchI/tyiebT01YP+aP0xJxEM2wPwt0K3Ub6PzpFfHI Bk9A== X-Gm-Message-State: ABuFfoggqVMlIf9L4VMp4SiZR/bcZWNLnFQEK/WjsxgKY/laKJInG+G6 LXxokuwwjZgDrDiEycY41jYzOFkAwuo= X-Google-Smtp-Source: ACcGV602kv4WD79jG5uVVk6dGjih86B+KIxwVCU6P76FptYtSymhEKTYjx1ZAwOwofMLUz3Cbn3ooQ== X-Received: by 2002:a63:a047:: with SMTP id u7-v6mr2405680pgn.145.1539282637397; Thu, 11 Oct 2018 11:30:37 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:37 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 01/13] swim: fix cleanup on setup error Date: Thu, 11 Oct 2018 11:30:11 -0700 Message-Id: <6fc80069461e094f5d018c948873f11b8d4331de.1539282366.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 If we fail to allocate the request queue for a disk, we still need to free that disk, not just the previous ones. Additionally, we need to cleanup the previous request queues. Signed-off-by: Omar Sandoval --- drivers/block/swim.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/block/swim.c b/drivers/block/swim.c index 0e31884a9519..cbe909c51847 100644 --- a/drivers/block/swim.c +++ b/drivers/block/swim.c @@ -887,8 +887,17 @@ static int swim_floppy_init(struct swim_priv *swd) exit_put_disks: unregister_blkdev(FLOPPY_MAJOR, "fd"); - while (drive--) - put_disk(swd->unit[drive].disk); + do { + struct gendisk *disk = swd->unit[drive].disk; + + if (disk) { + if (disk->queue) { + blk_cleanup_queue(disk->queue); + disk->queue = NULL; + } + put_disk(disk); + } + } while (drive--); return err; } From patchwork Thu Oct 11 18:30:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637087 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 5797F17E3 for ; Thu, 11 Oct 2018 18:30:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47BD02BEA4 for ; Thu, 11 Oct 2018 18:30:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B6412BEA0; Thu, 11 Oct 2018 18:30:41 +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 A79912BEE1 for ; Thu, 11 Oct 2018 18:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729127AbeJLB7D (ORCPT ); Thu, 11 Oct 2018 21:59:03 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:36955 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729119AbeJLB7D (ORCPT ); Thu, 11 Oct 2018 21:59:03 -0400 Received: by mail-pf1-f193.google.com with SMTP id j23-v6so4833343pfi.4 for ; Thu, 11 Oct 2018 11:30:39 -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=r7aPGyyuqnpg3lGCfAEnhsh94HYd5jM3eDt3jItpn8U=; b=jPXmnQzVQlBeDox0fSw2pR/8jsQIbnmMfwSsqtsuZyCbD1e0hZHgbRGsFnG060oCUa MzJAhXpx8OsHvjUqfL4KtNIMX8CBVcFzZK+KYDrJTNv75oJ5xkWtxqvxWZrLqBAYf4lr 3Xv4Xh0hj7gif2q/PGaP3Gw4MoCIr8XLMvQI6qXdUVbsLNruhHrZjbZKIxhewimKnmKR BG4SDRAYZEoCPvt1Btibi7j2sx8hgp8YA7JODxsnz582dZl0ti+V9+rKJN0qjxPqAgIS NYqZvCXK+VwNi4j4NsYTHGts8uS5UIW3cwxG14XCO23+leyUuswVU2zZ94a0gl8lKbBc F8ug== 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=r7aPGyyuqnpg3lGCfAEnhsh94HYd5jM3eDt3jItpn8U=; b=FF0a/p7YKWqwknbqKLqlW+smZ5VEoR4jskvaU149OjXeF1mS8Bvc5P16xoE2C+pU+/ tJhcuFj2HRbu+DPrXcx/FtOd1jUG7B+GIrJQ95H9zZD5WzY4nyPLtLmkVD2lh1rYvh6x NVUykxoOumjRm6zRRtb+mSH5G0852+nf56JY7n2hm5nQ9u9lbeUhn3+f/yUL/NS49tnn DOeZ44LaknGioqouGnptJA6lTxZme06VVCDcZ4EK4ICEkoiawLCflk5BRcsfs+UkI7uX pS9Ji2ANvX8DqKwngF1PmrFhDNlsy5fJfKTTEiSWJTvgzyEJHxtBooSdCAJJqF180fwl HzlQ== X-Gm-Message-State: ABuFfohUWU33kbZjD0kNs3m+UuSzIyC3hyY5Qyq0RTSn1b44r3TLGi3k LDatSghojbrZMbWAmyiqgJ0EmLUcoco= X-Google-Smtp-Source: ACcGV61KtXIq74JUqqMix72SaEKGl84+EJ6xKJ2TXfJCVKL8utnCt/OTO9HgcGObgrHkxbFE5ZQhsg== X-Received: by 2002:a63:7d2:: with SMTP id 201-v6mr2457578pgh.129.1539282638242; Thu, 11 Oct 2018 11:30:38 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:37 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com, Finn Thain , Laurent Vivier Subject: [PATCH 02/13] swim: convert to blk-mq Date: Thu, 11 Oct 2018 11:30:12 -0700 Message-Id: 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 --- drivers/block/swim.c | 103 +++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/drivers/block/swim.c b/drivers/block/swim.c index cbe909c51847..bb3ac4da5b8d 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,38 @@ 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)); + if (err) + break; + } 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 +803,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 +836,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 +892,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 +968,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); } From patchwork Thu Oct 11 18:30:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637089 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 78E5369B1 for ; Thu, 11 Oct 2018 18:30:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AB8A2BEA4 for ; Thu, 11 Oct 2018 18:30:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 687B02BEC1; Thu, 11 Oct 2018 18:30:41 +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 D19502BEB6 for ; Thu, 11 Oct 2018 18:30:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729119AbeJLB7E (ORCPT ); Thu, 11 Oct 2018 21:59:04 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44134 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729126AbeJLB7D (ORCPT ); Thu, 11 Oct 2018 21:59:03 -0400 Received: by mail-pg1-f193.google.com with SMTP id g2-v6so4559750pgu.11 for ; Thu, 11 Oct 2018 11:30:39 -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=1XN1LWsZsF9oaS5oMVL5qGAnAmhGwbO2jFh4zUORlt8=; b=0yyXl8ncDZjonmTftnrc9EqthIIZgxHHLZYB7vbXbP/qhb3aZjxmbTH0t1Z8ePOq1B 42IgixrUeDVY+lGVq0wGsJ7L8RtU+hGxJLnAdsrf4oLMDNioIahc5Iob86XsFUQwdmRu dhv3U8Z1Y7BqcWVhUlUBKbm2g3JZB459YsHY4sQIMV6H3OOukZXDbmihDvpCiYlAY/ho r9pphZpXPC/lOXPxSXiHDlDHqbsu7qcFxzn+xHwSqUh8rvMP/bQH+hgg6vnvyIEHNl1G TEwKYlMIQQxbWFHzK7hdCXBAXKR1DThzomAAgqgnjqLqHPCCk7zVzOoti0PkayMXWHSC 89mg== 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=1XN1LWsZsF9oaS5oMVL5qGAnAmhGwbO2jFh4zUORlt8=; b=gUo2h8csfKoAEhNsXzv6dpF2B962Sg9nWO+XaWoCp9cGXwYGz/E5oe7oRjO+md30Tt T8xfwVOuKpxVQRCNc3qP7BeLmgw9jtiY7AFgAml82p8F/HY5Ey+mCbqlC5lQC5ckZh4M x0Abx5yucziO4+dNMPqMGl699fpF10bu451XdBgtWVmomheD1Gfji39mRtK3nGrkVtfW EZDWosORLd2Dqxw73chEMhC3mHTzKzmFg1yQd9fpg5wsxjmIswMmdeTMfVawa2WpEHi8 SQcOKPQH32VrQqziTL/Vxa27NtP2nUdx96dkM0gfjH085Dh0TukTxE9aQJsmYcmr+Kmi 191Q== X-Gm-Message-State: ABuFfohKMCG8i2VhFgTww+1LPW43GiXRs8xypEXfcS5t/MVFfNVxsXdO ThuIArNylB8Pc+26YhB2E8Ba08brrVA= X-Google-Smtp-Source: ACcGV627ttQ/7ietCi0NfdRdvdFzqKjvbvJWRzwfaFG6hVvxdLMj2QbJT5m3YtBTGiX8bmOiyx67oA== X-Received: by 2002:a62:184a:: with SMTP id 71-v6mr2635206pfy.246.1539282639038; Thu, 11 Oct 2018 11:30:39 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:38 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 03/13] swim3: add real error handling in setup Date: Thu, 11 Oct 2018 11:30:13 -0700 Message-Id: <55fe5524750d283207728b18449a9e2d72e7f68a.1539282366.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 driver doesn't have support for removing a device that has already been configured, but with more careful ordering we can avoid the need for that and make sure that we don't leak generic resources. Signed-off-by: Omar Sandoval --- drivers/block/swim3.c | 60 ++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c index 469541c1e51e..df7ebe016e2c 100644 --- a/drivers/block/swim3.c +++ b/drivers/block/swim3.c @@ -1202,47 +1202,59 @@ static int swim3_add_device(struct macio_dev *mdev, int index) static int swim3_attach(struct macio_dev *mdev, const struct of_device_id *match) { + struct floppy_state *fs; struct gendisk *disk; - int index, rc; + int rc; - index = floppy_count++; - if (index >= MAX_FLOPPIES) + if (floppy_count >= MAX_FLOPPIES) return -ENXIO; - /* Add the drive */ - rc = swim3_add_device(mdev, index); - if (rc) - return rc; - /* Now register that disk. Same comment about failure handling */ - disk = disks[index] = alloc_disk(1); - if (disk == NULL) - return -ENOMEM; + if (floppy_count == 0) { + rc = register_blkdev(FLOPPY_MAJOR, "fd"); + if (rc) + return rc; + } + + fs = &floppy_states[floppy_count]; + + disk = alloc_disk(1); + if (disk == NULL) { + rc = -ENOMEM; + goto out_unregister; + } disk->queue = blk_init_queue(do_fd_request, &swim3_lock); if (disk->queue == NULL) { - put_disk(disk); - return -ENOMEM; + rc = -ENOMEM; + goto out_put_disk; } blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH); - disk->queue->queuedata = &floppy_states[index]; + disk->queue->queuedata = fs; - if (index == 0) { - /* If we failed, there isn't much we can do as the driver is still - * too dumb to remove the device, just bail out - */ - if (register_blkdev(FLOPPY_MAJOR, "fd")) - return 0; - } + rc = swim3_add_device(mdev, floppy_count); + if (rc) + goto out_cleanup_queue; disk->major = FLOPPY_MAJOR; - disk->first_minor = index; + disk->first_minor = floppy_count; disk->fops = &floppy_fops; - disk->private_data = &floppy_states[index]; + disk->private_data = fs; disk->flags |= GENHD_FL_REMOVABLE; - sprintf(disk->disk_name, "fd%d", index); + sprintf(disk->disk_name, "fd%d", floppy_count); set_capacity(disk, 2880); add_disk(disk); + disks[floppy_count++] = disk; return 0; + +out_cleanup_queue: + blk_cleanup_queue(disk->queue); + disk->queue = NULL; +out_put_disk: + put_disk(disk); +out_unregister: + if (floppy_count == 0) + unregister_blkdev(FLOPPY_MAJOR, "fd"); + return rc; } static const struct of_device_id swim3_match[] = From patchwork Thu Oct 11 18:30:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637091 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 3D4F613AD for ; Thu, 11 Oct 2018 18:30:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F4722BEA4 for ; Thu, 11 Oct 2018 18:30:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23AC02BEE1; Thu, 11 Oct 2018 18:30:42 +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 CF0BD2BEA4 for ; Thu, 11 Oct 2018 18:30:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729129AbeJLB7F (ORCPT ); Thu, 11 Oct 2018 21:59:05 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35741 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729126AbeJLB7E (ORCPT ); Thu, 11 Oct 2018 21:59:04 -0400 Received: by mail-pg1-f193.google.com with SMTP id v133-v6so4577350pgb.2 for ; Thu, 11 Oct 2018 11:30:40 -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=Wn2h4qwdMgzKdi2hsU+Es8MwOL4pnKG38TLGb0b0DEg=; b=dODzookQ/2FgfZ8ZAIPJ4swwzEWshpwFLE6kCwSo68cSpKrOjUt5IAY/ydw+A9tSP9 IXZ5lAuT0qHP7OvhsnId7FCT85nDfXoG64zL9OwasGQ6ftw+Ua0cFCM5yRgYffLrNNKu OpERVu/5iX+j/GvhrGDPQs6qlTa8/R2BKkdsYkKspfI1OVrmkwzPz3R+HFBp5hWYjLlm CfVSYd3wOBtOZZe2bFyJIRFjcQi426l4KhXZdIas+bWQUdyoIV6EMN9/OD8BrGgvgDxc lO85nop5dLdcLofz7+xPAdTg0IYkO09lcFXylCJZ/L+b6ePDj45MC12b3V608GVtKGmG tRmA== 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=Wn2h4qwdMgzKdi2hsU+Es8MwOL4pnKG38TLGb0b0DEg=; b=dDEw2UH8sZYywMIzIXvhrSQ0Ypj4Gw7BAfpH1Il8pX1tpl5nR32jCTt+ijeGlbjPvy i3U2FpucCyYu+QMdjyXBh3Op5k3DpaaPCKFdK9mSI49K9SXpbOPrZLC0piblFC+5fTx4 4LINzvK6EIPe+R6by0odNzyZGYfJfTzzatepKBN4k3EethJIlv9/ldtkndrqMntdfyOx vwVgKl1BjHa+WlLTsxM2mzIL4IOlqtrdZuMWHheNjxhNXH68hwfWGOdtuI5slgShAQpA wBf80iCJ4DvXrJFIzWndwNbD1T6UloWTW44SnIPMpUkF248L784YxhM46FRcLFIhp37M 8A0w== X-Gm-Message-State: ABuFfojjwlU2rAJa6djtL5v9Ht+Drn5csWOhBFbxv2UXm9rReF4p1LLf zoCOng9/6NMw7hli4/s61U5jhSl1dRs= X-Google-Smtp-Source: ACcGV63oJlfreZThw2hQ4+GhpKf0tq/hXUZYpxw+rEMr+d0jPVHOHveFSUPrDVj0gvnVSgJjqk08CA== X-Received: by 2002:a65:44c6:: with SMTP id g6-v6mr2337710pgs.350.1539282640052; Thu, 11 Oct 2018 11:30:40 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:39 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 04/13] swim3: end whole request on error Date: Thu, 11 Oct 2018 11:30:14 -0700 Message-Id: <3e2de6e6c66ab09f7fcf91ac7ad12228cdbcabb4.1539282366.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 When swim3_end_request() gets passed an error, it seems that the intent is to end the whole request, but we're only ending the current segment. Signed-off-by: Omar Sandoval --- drivers/block/swim3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c index df7ebe016e2c..24e121ee274b 100644 --- a/drivers/block/swim3.c +++ b/drivers/block/swim3.c @@ -266,7 +266,7 @@ static bool swim3_end_request(struct floppy_state *fs, blk_status_t err, unsigne err, nr_bytes, req); if (err) - nr_bytes = blk_rq_cur_bytes(req); + nr_bytes = blk_rq_bytes(req); rc = __blk_end_request(req, err, nr_bytes); if (rc) return true; From patchwork Thu Oct 11 18:30:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637093 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 36A3113AD for ; Thu, 11 Oct 2018 18:30:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 261B82BEE2 for ; Thu, 11 Oct 2018 18:30:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 245462BEE3; Thu, 11 Oct 2018 18:30:44 +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 5656B2BED0 for ; Thu, 11 Oct 2018 18:30:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729132AbeJLB7G (ORCPT ); Thu, 11 Oct 2018 21:59:06 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:34433 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729126AbeJLB7G (ORCPT ); Thu, 11 Oct 2018 21:59:06 -0400 Received: by mail-pl1-f194.google.com with SMTP id f18-v6so4646720plr.1 for ; Thu, 11 Oct 2018 11:30:42 -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=rzbaLhdOPHdJfLHKQZrEIilZylltLW8EVGMU+9LUqrI=; b=DBjEBqstVRTNI1LJFjP9YxRgprqTOKoGi+k0EbfQvt+P8evuICab2SrhHAhXlkqdqX rbT/TUQMN4Ji1GYnVYG+/wSu/86Adp117SUWeC3MPOv8xgumTjeIcbqFy+j6Q8V63l74 WIQTf1IpWalpnntVN+VGyyjgXAjb7fwStclYFC/Zwy0J+8eqy627R01Klk8obgbge7Qp X7J16f9fkqd2IdxVOjXgjRN9qIkAp2cwEin4xQtzdhyFkdRaauh+Nc7DMXxna0Ly7mdg ODa3iFxWa3u1bwAGLMdskRbyYUhOHxEEj3W9l+WVXTEjUMy8pOUwjrtC1kcYN8Cw3BNs FMgQ== 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=rzbaLhdOPHdJfLHKQZrEIilZylltLW8EVGMU+9LUqrI=; b=jO0AoXyjv74+YRmwLYyG993/FEpVZOcQx4+/5w2YIuNVeLz70EsHja6UbDkhZeeoe1 9Bx0doTNmjtI8VW/Cvv45YTdN/0rQPfbKmeareb5SSMUL2jUw2EQwZp0DlXpKUgJM/dk NuUnAp6gUCzPTFhzhsyVLjTxxRAMqBqqSNstJwORfj7EPk57ANzOkfInMjmKASraqdSe 09ZSqQyR/mFuCAKIM+T+50mlG/TmIW7t4EewD3D7f3DrCIebafk5jCy5++1MbGEU/8pq 3I+WMfGwmf+2q4lnxGn25vJBxLRvCcqmc4NxA//kZm3CUSrwpV4uG4psin7lTyUYGQqE oJfQ== X-Gm-Message-State: ABuFfojoyOexxS1g+gRMelR0BRfpGQrQCDKBwjoEmacVE0xkXQYi17dK 1Ik2a7zR7nG6QDd6lYMibDNUD7k7sNI= X-Google-Smtp-Source: ACcGV63qOB6EygPb6Kxva/wTqS/07qZgh5F8RwCI6vj1UUIp9Kf4plhQjk0ZV0DzuuBDduo/ov/urQ== X-Received: by 2002:a17:902:848f:: with SMTP id c15-v6mr2502201plo.119.1539282641400; Thu, 11 Oct 2018 11:30:41 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:40 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com, Benjamin Herrenschmidt Subject: [PATCH 05/13] swim3: convert to blk-mq Date: Thu, 11 Oct 2018 11:30:15 -0700 Message-Id: <9a5654dc2713ea559d8dea54a0a07dea83c22592.1539282366.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 Pretty simple conversion. To avoid extra churn, we keep the swim3_end_request() wrapper. grab_drive() could probably be replaced by some freeze/quiesce incantation, but I left it alone, and just used freeze/quiesce for eject. Compile-tested only. Cc: Benjamin Herrenschmidt Signed-off-by: Omar Sandoval --- drivers/block/swim3.c | 163 +++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 88 deletions(-) diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c index 24e121ee274b..e2061a4d43f7 100644 --- a/drivers/block/swim3.c +++ b/drivers/block/swim3.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include @@ -206,6 +206,7 @@ struct floppy_state { char dbdma_cmd_space[5 * sizeof(struct dbdma_cmd)]; int index; struct request *cur_req; + struct blk_mq_tag_set tag_set; }; #define swim3_err(fmt, arg...) dev_err(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg) @@ -260,16 +261,15 @@ static int floppy_revalidate(struct gendisk *disk); static bool swim3_end_request(struct floppy_state *fs, blk_status_t err, unsigned int nr_bytes) { struct request *req = fs->cur_req; - int rc; swim3_dbg(" end request, err=%d nr_bytes=%d, cur_req=%p\n", err, nr_bytes, req); if (err) nr_bytes = blk_rq_bytes(req); - rc = __blk_end_request(req, err, nr_bytes); - if (rc) + if (blk_update_request(req, err, nr_bytes)) return true; + __blk_mq_end_request(req, err); fs->cur_req = NULL; return false; } @@ -309,86 +309,58 @@ static int swim3_readbit(struct floppy_state *fs, int bit) return (stat & DATA) == 0; } -static void start_request(struct floppy_state *fs) +static blk_status_t swim3_queue_rq(struct blk_mq_hw_ctx *hctx, + const struct blk_mq_queue_data *bd) { - struct request *req; + struct floppy_state *fs = hctx->queue->queuedata; + struct request *req = bd->rq; unsigned long x; - swim3_dbg("start request, initial state=%d\n", fs->state); - - if (fs->state == idle && fs->wanted) { - fs->state = available; - wake_up(&fs->wait); - return; + spin_lock_irq(&swim3_lock); + if (fs->cur_req || fs->state != idle) { + spin_unlock_irq(&swim3_lock); + return BLK_STS_DEV_RESOURCE; } - while (fs->state == idle) { - swim3_dbg("start request, idle loop, cur_req=%p\n", fs->cur_req); - if (!fs->cur_req) { - fs->cur_req = blk_fetch_request(disks[fs->index]->queue); - swim3_dbg(" fetched request %p\n", fs->cur_req); - if (!fs->cur_req) - break; - } - req = fs->cur_req; - - if (fs->mdev->media_bay && - check_media_bay(fs->mdev->media_bay) != MB_FD) { - swim3_dbg("%s", " media bay absent, dropping req\n"); - swim3_end_request(fs, BLK_STS_IOERR, 0); - continue; - } - -#if 0 /* This is really too verbose */ - swim3_dbg("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%u buf=%p\n", - req->rq_disk->disk_name, req->cmd, - (long)blk_rq_pos(req), blk_rq_sectors(req), - bio_data(req->bio)); - swim3_dbg(" current_nr_sectors=%u\n", - blk_rq_cur_sectors(req)); -#endif - - if (blk_rq_pos(req) >= fs->total_secs) { - swim3_dbg(" pos out of bounds (%ld, max is %ld)\n", - (long)blk_rq_pos(req), (long)fs->total_secs); - swim3_end_request(fs, BLK_STS_IOERR, 0); - continue; - } - if (fs->ejected) { - swim3_dbg("%s", " disk ejected\n"); + blk_mq_start_request(req); + fs->cur_req = req; + if (fs->mdev->media_bay && + check_media_bay(fs->mdev->media_bay) != MB_FD) { + swim3_dbg("%s", " media bay absent, dropping req\n"); + swim3_end_request(fs, BLK_STS_IOERR, 0); + goto out; + } + if (fs->ejected) { + swim3_dbg("%s", " disk ejected\n"); + swim3_end_request(fs, BLK_STS_IOERR, 0); + goto out; + } + if (rq_data_dir(req) == WRITE) { + if (fs->write_prot < 0) + fs->write_prot = swim3_readbit(fs, WRITE_PROT); + if (fs->write_prot) { + swim3_dbg("%s", " try to write, disk write protected\n"); swim3_end_request(fs, BLK_STS_IOERR, 0); - continue; - } - - if (rq_data_dir(req) == WRITE) { - if (fs->write_prot < 0) - fs->write_prot = swim3_readbit(fs, WRITE_PROT); - if (fs->write_prot) { - swim3_dbg("%s", " try to write, disk write protected\n"); - swim3_end_request(fs, BLK_STS_IOERR, 0); - continue; - } + goto out; } - - /* Do not remove the cast. blk_rq_pos(req) is now a - * sector_t and can be 64 bits, but it will never go - * past 32 bits for this driver anyway, so we can - * safely cast it down and not have to do a 64/32 - * division - */ - fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl; - x = ((long)blk_rq_pos(req)) % fs->secpercyl; - fs->head = x / fs->secpertrack; - fs->req_sector = x % fs->secpertrack + 1; - fs->state = do_transfer; - fs->retries = 0; - - act(fs); } -} -static void do_fd_request(struct request_queue * q) -{ - start_request(q->queuedata); + /* + * Do not remove the cast. blk_rq_pos(req) is now a sector_t and can be + * 64 bits, but it will never go past 32 bits for this driver anyway, so + * we can safely cast it down and not have to do a 64/32 division + */ + fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl; + x = ((long)blk_rq_pos(req)) % fs->secpercyl; + fs->head = x / fs->secpertrack; + fs->req_sector = x % fs->secpertrack + 1; + fs->state = do_transfer; + fs->retries = 0; + + act(fs); + +out: + spin_unlock_irq(&swim3_lock); + return BLK_STS_OK; } static void set_timeout(struct floppy_state *fs, int nticks, @@ -585,7 +557,6 @@ static void scan_timeout(struct timer_list *t) if (fs->retries > 5) { swim3_end_request(fs, BLK_STS_IOERR, 0); fs->state = idle; - start_request(fs); } else { fs->state = jogging; act(fs); @@ -609,7 +580,6 @@ static void seek_timeout(struct timer_list *t) swim3_err("%s", "Seek timeout\n"); swim3_end_request(fs, BLK_STS_IOERR, 0); fs->state = idle; - start_request(fs); spin_unlock_irqrestore(&swim3_lock, flags); } @@ -638,7 +608,6 @@ static void settle_timeout(struct timer_list *t) swim3_err("%s", "Seek settle timeout\n"); swim3_end_request(fs, BLK_STS_IOERR, 0); fs->state = idle; - start_request(fs); unlock: spin_unlock_irqrestore(&swim3_lock, flags); } @@ -667,7 +636,6 @@ static void xfer_timeout(struct timer_list *t) (long)blk_rq_pos(fs->cur_req)); swim3_end_request(fs, BLK_STS_IOERR, 0); fs->state = idle; - start_request(fs); spin_unlock_irqrestore(&swim3_lock, flags); } @@ -704,7 +672,6 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id) if (fs->retries > 5) { swim3_end_request(fs, BLK_STS_IOERR, 0); fs->state = idle; - start_request(fs); } else { fs->state = jogging; act(fs); @@ -796,7 +763,6 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id) fs->state, rq_data_dir(req), intr, err); swim3_end_request(fs, BLK_STS_IOERR, 0); fs->state = idle; - start_request(fs); break; } fs->retries = 0; @@ -813,8 +779,6 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id) } else fs->state = idle; } - if (fs->state == idle) - start_request(fs); break; default: swim3_err("Don't know what to do in state %d\n", fs->state); @@ -862,14 +826,19 @@ static int grab_drive(struct floppy_state *fs, enum swim_state state, static void release_drive(struct floppy_state *fs) { + struct request_queue *q = disks[fs->index]->queue; unsigned long flags; swim3_dbg("%s", "-> release drive\n"); spin_lock_irqsave(&swim3_lock, flags); fs->state = idle; - start_request(fs); spin_unlock_irqrestore(&swim3_lock, flags); + + blk_mq_freeze_queue(q); + blk_mq_quiesce_queue(q); + blk_mq_unquiesce_queue(q); + blk_mq_unfreeze_queue(q); } static int fd_eject(struct floppy_state *fs) @@ -1089,6 +1058,10 @@ static const struct block_device_operations floppy_fops = { .revalidate_disk= floppy_revalidate, }; +static const struct blk_mq_ops swim3_mq_ops = { + .queue_rq = swim3_queue_rq, +}; + static void swim3_mb_event(struct macio_dev* mdev, int mb_state) { struct floppy_state *fs = macio_get_drvdata(mdev); @@ -1222,10 +1195,22 @@ static int swim3_attach(struct macio_dev *mdev, rc = -ENOMEM; goto out_unregister; } - disk->queue = blk_init_queue(do_fd_request, &swim3_lock); - if (disk->queue == NULL) { - rc = -ENOMEM; + + fs->tag_set.ops = &swim3_mq_ops; + fs->tag_set.nr_hw_queues = 1; + fs->tag_set.queue_depth = 2; + fs->tag_set.numa_node = NUMA_NO_NODE; + fs->tag_set.flags = BLK_MQ_F_SHOULD_MERGE; + + rc = blk_mq_alloc_tag_set(&fs->tag_set); + if (rc) goto out_put_disk; + + disk->queue = blk_mq_init_queue(&fs->tag_set); + if (IS_ERR(disk->queue)) { + rc = PTR_ERR(disk->queue); + disk->queue = NULL; + goto out_free_tag_set; } blk_queue_bounce_limit(disk->queue, BLK_BOUNCE_HIGH); disk->queue->queuedata = fs; @@ -1249,6 +1234,8 @@ static int swim3_attach(struct macio_dev *mdev, out_cleanup_queue: blk_cleanup_queue(disk->queue); disk->queue = NULL; +out_free_tag_set: + blk_mq_free_tag_set(&fs->tag_set); out_put_disk: put_disk(disk); out_unregister: From patchwork Thu Oct 11 18:30:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637095 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 28D1017E3 for ; Thu, 11 Oct 2018 18:30:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 195612BEE5 for ; Thu, 11 Oct 2018 18:30:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E0932BEDD; Thu, 11 Oct 2018 18:30:45 +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 260E52BEE1 for ; Thu, 11 Oct 2018 18:30:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729145AbeJLB7H (ORCPT ); Thu, 11 Oct 2018 21:59:07 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35269 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729126AbeJLB7H (ORCPT ); Thu, 11 Oct 2018 21:59:07 -0400 Received: by mail-pl1-f195.google.com with SMTP id f8-v6so4642096plb.2 for ; Thu, 11 Oct 2018 11:30:43 -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=jDyM4RjmP61L1FWHCgVNY8FnqnEcpFwMNojjgFxhyz0=; b=x0rM2f1hP3GNG9oxBb+XubAo5GFAbzUXj3UZMMcNu0zffJnqx4GcYVXJFeohg6jgCa CktRuZ5GByVMYwemAuYDqyfKoUeMSY/gTnuDcdWOG6bswQXcYwn4TZcQ8hWqIUvaSxdu xbyzEXwp6Sn1uJtn5ReF+IhhUar+qcHr4lVjTPQ+nJYQzJxBhZlJ9OZg8KceRaoklZi1 pPwKV3SRcy2pRSPdAb4rwpp/DFU1yW/UuTPoGrwrH946N8QWQBCNKiv2QNQ8B8jQ9lCB MLGNYAFnIyXEVG+Btw2Fdlj1C09zWLxDh/ZfmePzhEbvtQCgNVXtwIF1XzqDfsnEF3ND 87iQ== 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=jDyM4RjmP61L1FWHCgVNY8FnqnEcpFwMNojjgFxhyz0=; b=WWbzD17ZZ+EfdasZAk2EUUGc60U2kbCsVp64IC2wGgLmGZsICzBVsHV6Ws9WlJdw/E 5XPN0iaiG3MSZYdm78SqnC+Ooi8EXo6gcPqAKyilnnYC+4ZPkir/NwsAImyXXo0BwZIV maDQXJK/QGa80H1Vwgp6S1LmqV2psuOpG9eF7BJB5ciXEFI/dadrYpF/quSKxLyN35td HZ9sOy5OzAlGqrG1MuFeElWJgBEGyUZEuNPbq/hqyCBG3eVpBvLyHpXMp6s0tf4aWI4G hHV7Gv9k7EvaEf+b5ZoaqblGKsiqJ67rSoQC09XmZ/84lvVSGqfpf4WkBrhcgt+pAVb2 62xQ== X-Gm-Message-State: ABuFfogyxPqYoKXByq+TdOQaIc4qpE613F+H8Hsi1T/owdT8vUtfWpuY xtr6ol/m7nPYSLZGZfkwNI7hEDdNn7s= X-Google-Smtp-Source: ACcGV61nALEhxNGv/vHPaKvACFAUeYlcM90wK9LLOzzK5fkxUwJ+Ef+z8YplN5h1JdD0UO0yjh7aVg== X-Received: by 2002:a17:902:28a2:: with SMTP id f31-v6mr2614680plb.312.1539282642314; Thu, 11 Oct 2018 11:30:42 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:41 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 06/13] amiflop: fold headers into C file Date: Thu, 11 Oct 2018 11:30:16 -0700 Message-Id: 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 amifd.h and amifdreg.h are only used from amiflop.c, and they're pretty small, so move the contents to amiflop.c and get rid of the .h files. This is preparation for adding a struct blk_mq_tag_set to struct amiga_floppy_struct. Signed-off-by: Omar Sandoval --- drivers/block/amiflop.c | 123 ++++++++++++++++++++++++++++++++++++++- include/linux/amifd.h | 63 -------------------- include/linux/amifdreg.h | 82 -------------------------- 3 files changed, 120 insertions(+), 148 deletions(-) delete mode 100644 include/linux/amifd.h delete mode 100644 include/linux/amifdreg.h diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c index 3aaf6af3ec23..a7d6e6a9b12f 100644 --- a/drivers/block/amiflop.c +++ b/drivers/block/amiflop.c @@ -61,10 +61,8 @@ #include #include #include -#include -#include #include -#include +#include #include #include #include @@ -86,6 +84,125 @@ * Defines */ +/* + * CIAAPRA bits (read only) + */ + +#define DSKRDY (0x1<<5) /* disk ready when low */ +#define DSKTRACK0 (0x1<<4) /* head at track zero when low */ +#define DSKPROT (0x1<<3) /* disk protected when low */ +#define DSKCHANGE (0x1<<2) /* low when disk removed */ + +/* + * CIAAPRB bits (read/write) + */ + +#define DSKMOTOR (0x1<<7) /* motor on when low */ +#define DSKSEL3 (0x1<<6) /* select drive 3 when low */ +#define DSKSEL2 (0x1<<5) /* select drive 2 when low */ +#define DSKSEL1 (0x1<<4) /* select drive 1 when low */ +#define DSKSEL0 (0x1<<3) /* select drive 0 when low */ +#define DSKSIDE (0x1<<2) /* side selection: 0 = upper, 1 = lower */ +#define DSKDIREC (0x1<<1) /* step direction: 0=in, 1=out (to trk 0) */ +#define DSKSTEP (0x1) /* pulse low to step head 1 track */ + +/* + * DSKBYTR bits (read only) + */ + +#define DSKBYT (1<<15) /* register contains valid byte when set */ +#define DMAON (1<<14) /* disk DMA enabled */ +#define DISKWRITE (1<<13) /* disk write bit in DSKLEN enabled */ +#define WORDEQUAL (1<<12) /* DSKSYNC register match when true */ +/* bits 7-0 are data */ + +/* + * ADKCON/ADKCONR bits + */ + +#ifndef SETCLR +#define ADK_SETCLR (1<<15) /* control bit */ +#endif +#define ADK_PRECOMP1 (1<<14) /* precompensation selection */ +#define ADK_PRECOMP0 (1<<13) /* 00=none, 01=140ns, 10=280ns, 11=500ns */ +#define ADK_MFMPREC (1<<12) /* 0=GCR precomp., 1=MFM precomp. */ +#define ADK_WORDSYNC (1<<10) /* enable DSKSYNC auto DMA */ +#define ADK_MSBSYNC (1<<9) /* when 1, enable sync on MSbit (for GCR) */ +#define ADK_FAST (1<<8) /* bit cell: 0=2us (GCR), 1=1us (MFM) */ + +/* + * DSKLEN bits + */ + +#define DSKLEN_DMAEN (1<<15) +#define DSKLEN_WRITE (1<<14) + +/* + * INTENA/INTREQ bits + */ + +#define DSKINDEX (0x1<<4) /* DSKINDEX bit */ + +/* + * Misc + */ + +#define MFM_SYNC 0x4489 /* standard MFM sync value */ + +/* Values for FD_COMMAND */ +#define FD_RECALIBRATE 0x07 /* move to track 0 */ +#define FD_SEEK 0x0F /* seek track */ +#define FD_READ 0xE6 /* read with MT, MFM, SKip deleted */ +#define FD_WRITE 0xC5 /* write with MT, MFM */ +#define FD_SENSEI 0x08 /* Sense Interrupt Status */ +#define FD_SPECIFY 0x03 /* specify HUT etc */ +#define FD_FORMAT 0x4D /* format one track */ +#define FD_VERSION 0x10 /* get version code */ +#define FD_CONFIGURE 0x13 /* configure FIFO operation */ +#define FD_PERPENDICULAR 0x12 /* perpendicular r/w mode */ + +#define FD_MAX_UNITS 4 /* Max. Number of drives */ +#define FLOPPY_MAX_SECTORS 22 /* Max. Number of sectors per track */ + +struct fd_data_type { + char *name; /* description of data type */ + int sects; /* sectors per track */ + int (*read_fkt)(int); /* read whole track */ + void (*write_fkt)(int); /* write whole track */ +}; + +struct fd_drive_type { + unsigned long code; /* code returned from drive */ + char *name; /* description of drive */ + unsigned int tracks; /* number of tracks */ + unsigned int heads; /* number of heads */ + unsigned int read_size; /* raw read size for one track */ + unsigned int write_size; /* raw write size for one track */ + unsigned int sect_mult; /* sectors and gap multiplier (HD = 2) */ + unsigned int precomp1; /* start track for precomp 1 */ + unsigned int precomp2; /* start track for precomp 2 */ + unsigned int step_delay; /* time (in ms) for delay after step */ + unsigned int settle_time; /* time to settle after dir change */ + unsigned int side_time; /* time needed to change sides */ +}; + +struct amiga_floppy_struct { + struct fd_drive_type *type; /* type of floppy for this unit */ + struct fd_data_type *dtype; /* type of floppy for this unit */ + int track; /* current track (-1 == unknown) */ + unsigned char *trackbuf; /* current track (kmaloc()'d */ + + int blocks; /* total # blocks on disk */ + + int changed; /* true when not known */ + int disk; /* disk in drive (-1 == unknown) */ + int motor; /* true when motor is at speed */ + int busy; /* true when drive is active */ + int dirty; /* true when trackbuf is not on disk */ + int status; /* current error code for unit */ + struct gendisk *gendisk; +}; + /* * Error codes */ diff --git a/include/linux/amifd.h b/include/linux/amifd.h deleted file mode 100644 index 202a77dbe46d..000000000000 --- a/include/linux/amifd.h +++ /dev/null @@ -1,63 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _AMIFD_H -#define _AMIFD_H - -/* Definitions for the Amiga floppy driver */ - -#include - -#define FD_MAX_UNITS 4 /* Max. Number of drives */ -#define FLOPPY_MAX_SECTORS 22 /* Max. Number of sectors per track */ - -#ifndef ASSEMBLER - -struct fd_data_type { - char *name; /* description of data type */ - int sects; /* sectors per track */ -#ifdef __STDC__ - int (*read_fkt)(int); - void (*write_fkt)(int); -#else - int (*read_fkt)(); /* read whole track */ - void (*write_fkt)(); /* write whole track */ -#endif -}; - -/* -** Floppy type descriptions -*/ - -struct fd_drive_type { - unsigned long code; /* code returned from drive */ - char *name; /* description of drive */ - unsigned int tracks; /* number of tracks */ - unsigned int heads; /* number of heads */ - unsigned int read_size; /* raw read size for one track */ - unsigned int write_size; /* raw write size for one track */ - unsigned int sect_mult; /* sectors and gap multiplier (HD = 2) */ - unsigned int precomp1; /* start track for precomp 1 */ - unsigned int precomp2; /* start track for precomp 2 */ - unsigned int step_delay; /* time (in ms) for delay after step */ - unsigned int settle_time; /* time to settle after dir change */ - unsigned int side_time; /* time needed to change sides */ -}; - -struct amiga_floppy_struct { - struct fd_drive_type *type; /* type of floppy for this unit */ - struct fd_data_type *dtype; /* type of floppy for this unit */ - int track; /* current track (-1 == unknown) */ - unsigned char *trackbuf; /* current track (kmaloc()'d */ - - int blocks; /* total # blocks on disk */ - - int changed; /* true when not known */ - int disk; /* disk in drive (-1 == unknown) */ - int motor; /* true when motor is at speed */ - int busy; /* true when drive is active */ - int dirty; /* true when trackbuf is not on disk */ - int status; /* current error code for unit */ - struct gendisk *gendisk; -}; -#endif - -#endif diff --git a/include/linux/amifdreg.h b/include/linux/amifdreg.h deleted file mode 100644 index 9b514d05ec70..000000000000 --- a/include/linux/amifdreg.h +++ /dev/null @@ -1,82 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _LINUX_AMIFDREG_H -#define _LINUX_AMIFDREG_H - -/* -** CIAAPRA bits (read only) -*/ - -#define DSKRDY (0x1<<5) /* disk ready when low */ -#define DSKTRACK0 (0x1<<4) /* head at track zero when low */ -#define DSKPROT (0x1<<3) /* disk protected when low */ -#define DSKCHANGE (0x1<<2) /* low when disk removed */ - -/* -** CIAAPRB bits (read/write) -*/ - -#define DSKMOTOR (0x1<<7) /* motor on when low */ -#define DSKSEL3 (0x1<<6) /* select drive 3 when low */ -#define DSKSEL2 (0x1<<5) /* select drive 2 when low */ -#define DSKSEL1 (0x1<<4) /* select drive 1 when low */ -#define DSKSEL0 (0x1<<3) /* select drive 0 when low */ -#define DSKSIDE (0x1<<2) /* side selection: 0 = upper, 1 = lower */ -#define DSKDIREC (0x1<<1) /* step direction: 0=in, 1=out (to trk 0) */ -#define DSKSTEP (0x1) /* pulse low to step head 1 track */ - -/* -** DSKBYTR bits (read only) -*/ - -#define DSKBYT (1<<15) /* register contains valid byte when set */ -#define DMAON (1<<14) /* disk DMA enabled */ -#define DISKWRITE (1<<13) /* disk write bit in DSKLEN enabled */ -#define WORDEQUAL (1<<12) /* DSKSYNC register match when true */ -/* bits 7-0 are data */ - -/* -** ADKCON/ADKCONR bits -*/ - -#ifndef SETCLR -#define ADK_SETCLR (1<<15) /* control bit */ -#endif -#define ADK_PRECOMP1 (1<<14) /* precompensation selection */ -#define ADK_PRECOMP0 (1<<13) /* 00=none, 01=140ns, 10=280ns, 11=500ns */ -#define ADK_MFMPREC (1<<12) /* 0=GCR precomp., 1=MFM precomp. */ -#define ADK_WORDSYNC (1<<10) /* enable DSKSYNC auto DMA */ -#define ADK_MSBSYNC (1<<9) /* when 1, enable sync on MSbit (for GCR) */ -#define ADK_FAST (1<<8) /* bit cell: 0=2us (GCR), 1=1us (MFM) */ - -/* -** DSKLEN bits -*/ - -#define DSKLEN_DMAEN (1<<15) -#define DSKLEN_WRITE (1<<14) - -/* -** INTENA/INTREQ bits -*/ - -#define DSKINDEX (0x1<<4) /* DSKINDEX bit */ - -/* -** Misc -*/ - -#define MFM_SYNC 0x4489 /* standard MFM sync value */ - -/* Values for FD_COMMAND */ -#define FD_RECALIBRATE 0x07 /* move to track 0 */ -#define FD_SEEK 0x0F /* seek track */ -#define FD_READ 0xE6 /* read with MT, MFM, SKip deleted */ -#define FD_WRITE 0xC5 /* write with MT, MFM */ -#define FD_SENSEI 0x08 /* Sense Interrupt Status */ -#define FD_SPECIFY 0x03 /* specify HUT etc */ -#define FD_FORMAT 0x4D /* format one track */ -#define FD_VERSION 0x10 /* get version code */ -#define FD_CONFIGURE 0x13 /* configure FIFO operation */ -#define FD_PERPENDICULAR 0x12 /* perpendicular r/w mode */ - -#endif /* _LINUX_AMIFDREG_H */ From patchwork Thu Oct 11 18:30:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637097 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 E096417E3 for ; Thu, 11 Oct 2018 18:30:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3B342BEEA for ; Thu, 11 Oct 2018 18:30:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1F882BEC3; Thu, 11 Oct 2018 18:30:45 +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 605D22BEDF for ; Thu, 11 Oct 2018 18:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729160AbeJLB7I (ORCPT ); Thu, 11 Oct 2018 21:59:08 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42852 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729126AbeJLB7I (ORCPT ); Thu, 11 Oct 2018 21:59:08 -0400 Received: by mail-pg1-f194.google.com with SMTP id i4-v6so4565640pgq.9 for ; Thu, 11 Oct 2018 11:30:44 -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=2Ie2tq/bgvbAoAevW4WXu14HcjbWRpIkuaJskCC0HTc=; b=H/8andZz8o0AFtj3T4PALSPbtZ28YdvVqsDFfRm2fBDHjJlnZCqv5odUEaV8Sk3x73 1b7vdBcdZvWhYIsR1HIas/OldqGhmi7EmBEXn76IUN3OWI8CkARhJ7B3cwZ3owoXZYQG USLhiMwMWR5mq0p4TUkQ0+30liZAiweL93z5aDMgfLxHBNAMnDIbv1F6CQizxo28VaD+ LDdGVpcThH1noCHqRasoBETOSOvyY2G3iO9sCRvUkJXwUBoLYXeN4nQeSqJ1lZrZY2zo jqTXOm6YKOgUOWJezSHCDfAuh/NvOtRl3VjPQYTclzzyVgXaAIFLMLFWh2iP78k84FrP Jpxw== 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=2Ie2tq/bgvbAoAevW4WXu14HcjbWRpIkuaJskCC0HTc=; b=ldjaIE2VGXFBkpgrbweLRauEzs6PI50UZs7Put3gKD3/IUw09uaocQibIIUS0kw85F 84hZ7Bq15SHgMoQ8INxanaTltqegAI35ezjTKNrdXrZ6EtY5qlsTvilWkqBY9Fp4XQwh xNdGCU05x8mtCTcoa+yf/Bn2ggI6r7e9WQZNtQKIQlSbVhKooat7WSNCJ4xT29IZHlzy GeShcMXrBsSm9Cj9Er+KJn80KHK1iQDRob6O6sq3Hvcssf1p98LvXIFJJcT7oEmyWcfT h7u8rsoT9C2REEGcXB8cQ0lJBvNSxcjv4xoZnteVEW4NNJLoPzdhfZYgFjzAWuwkQsyb Qj8w== X-Gm-Message-State: ABuFfogMZbS8b0tV+khxjoB78u2PrzPIh2d6TUEaUQrXHu//h9oBwWhO VTjBgzVnjSwpEh9kAdJbtNxB33V/CSY= X-Google-Smtp-Source: ACcGV62ESj26QZf8JmNGj1R/e0UhdFdgiUkrRvGWkVR1xEifGRhdfEIYsX0L8dQBPaVJ9jQAxqXq+w== X-Received: by 2002:a63:5509:: with SMTP id j9-v6mr2365790pgb.208.1539282643015; Thu, 11 Oct 2018 11:30:43 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:42 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 07/13] amiflop: clean up on errors during setup Date: Thu, 11 Oct 2018 11:30:17 -0700 Message-Id: <92d692ff3dc902e4b1845fd784be750dda2cab0b.1539282366.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 error handling in fd_probe_drives() doesn't clean up at all. Fix it up in preparation for converting to blk-mq. While we're here, get rid of the commented out amiga_floppy_remove(). Signed-off-by: Omar Sandoval --- drivers/block/amiflop.c | 84 ++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c index a7d6e6a9b12f..eef3b085e70a 100644 --- a/drivers/block/amiflop.c +++ b/drivers/block/amiflop.c @@ -1818,11 +1818,41 @@ static const struct block_device_operations floppy_fops = { .check_events = amiga_check_events, }; +static struct gendisk *fd_alloc_disk(int drive) +{ + struct gendisk *disk; + + disk = alloc_disk(1); + if (!disk) + goto out; + + disk->queue = blk_init_queue(do_fd_request, &amiflop_lock); + if (IS_ERR(disk->queue)) { + disk->queue = NULL; + goto out_put_disk; + } + + unit[drive].trackbuf = kmalloc(FLOPPY_MAX_SECTORS * 512, GFP_KERNEL); + if (!unit[drive].trackbuf) + goto out_cleanup_queue; + + return disk; + +out_cleanup_queue: + blk_cleanup_queue(disk->queue); + disk->queue = NULL; +out_put_disk: + put_disk(disk); +out: + unit[drive].type->code = FD_NODRIVE; + return NULL; +} + static int __init fd_probe_drives(void) { int drive,drives,nomem; - printk(KERN_INFO "FD: probing units\nfound "); + pr_info("FD: probing units\nfound"); drives=0; nomem=0; for(drive=0;drivecode == FD_NODRIVE) continue; - disk = alloc_disk(1); + + disk = fd_alloc_disk(drive); if (!disk) { - unit[drive].type->code = FD_NODRIVE; + pr_cont(" no mem for fd%d", drive); + nomem = 1; continue; } unit[drive].gendisk = disk; - - disk->queue = blk_init_queue(do_fd_request, &amiflop_lock); - if (!disk->queue) { - unit[drive].type->code = FD_NODRIVE; - continue; - } - drives++; - if ((unit[drive].trackbuf = kmalloc(FLOPPY_MAX_SECTORS * 512, GFP_KERNEL)) == NULL) { - printk("no mem for "); - unit[drive].type = &drive_types[num_dr_types - 1]; /* FD_NODRIVE */ - drives--; - nomem = 1; - } - printk("fd%d ",drive); + + pr_cont(" fd%d",drive); disk->major = FLOPPY_MAJOR; disk->first_minor = drive; disk->fops = &floppy_fops; @@ -1861,11 +1881,11 @@ static int __init fd_probe_drives(void) } if ((drives > 0) || (nomem == 0)) { if (drives == 0) - printk("no drives"); - printk("\n"); + pr_cont(" no drives"); + pr_cont("\n"); return drives; } - printk("\n"); + pr_cont("\n"); return -ENOMEM; } @@ -1948,30 +1968,6 @@ static int __init amiga_floppy_probe(struct platform_device *pdev) return ret; } -#if 0 /* not safe to unload */ -static int __exit amiga_floppy_remove(struct platform_device *pdev) -{ - int i; - - for( i = 0; i < FD_MAX_UNITS; i++) { - if (unit[i].type->code != FD_NODRIVE) { - struct request_queue *q = unit[i].gendisk->queue; - del_gendisk(unit[i].gendisk); - put_disk(unit[i].gendisk); - kfree(unit[i].trackbuf); - if (q) - blk_cleanup_queue(q); - } - } - blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); - free_irq(IRQ_AMIGA_CIAA_TB, NULL); - free_irq(IRQ_AMIGA_DSKBLK, NULL); - custom.dmacon = DMAF_DISK; /* disable DMA */ - amiga_chip_free(raw_buf); - unregister_blkdev(FLOPPY_MAJOR, "fd"); -} -#endif - static struct platform_driver amiga_floppy_driver = { .driver = { .name = "amiga-floppy", From patchwork Thu Oct 11 18:30:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637099 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 9233A13AD for ; Thu, 11 Oct 2018 18:30:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 857372BEC0 for ; Thu, 11 Oct 2018 18:30:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 798C12BEEE; Thu, 11 Oct 2018 18:30:46 +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 DE9B12BEE1 for ; Thu, 11 Oct 2018 18:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729126AbeJLB7J (ORCPT ); Thu, 11 Oct 2018 21:59:09 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41611 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729154AbeJLB7I (ORCPT ); Thu, 11 Oct 2018 21:59:08 -0400 Received: by mail-pl1-f194.google.com with SMTP id q17-v6so4633490plr.8 for ; Thu, 11 Oct 2018 11:30:44 -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=ERRnvUZIS8N8n63xlS85f/X0ts6OeeVqCOjS1np0D6g=; b=XbAFdY2LGtFEj6Oynf07bBgAZCVgHzbnSbZj5VitT/q9fDCfLccfNaaGDF4hju+1Cx G/HglCZ69hF5tybD3kllZEpfS5ISV6FmIjNCZtiSJ/rz91wWVZO7sB10f7WmCJcGXE99 Bhz/oRE3dD7Gkive3Ld+wVwv5yoteQs5ya4r+27P7By+K8FanBSMiGD9wMfekIx+wgGI OziNBNYJN3laY4qbQ74m6vZXNx8LDWjtkLMhopJUyURDPbVL9ZqL4BVf91M6qNx6Noyg vDq9SEmmLrX/uGJ0zEaxW4Y7wmJK6crC29SdWF3n7sz0YA96WAdfPlWvBlTvlY6V5v0L xMpA== 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=ERRnvUZIS8N8n63xlS85f/X0ts6OeeVqCOjS1np0D6g=; b=D/2sfUQLeHXCsXL7yYvXuXkIwyEiM8xrP0XbR4ESp+/QThddkUCRC6W/ObPCLsjwj7 12KDsqfJGni4MMlmNniOA4wY/4yWeqBWl1p2gQwNLCFUrPLBRBvrvE3h3DM2Y4NuXtu7 QSyMd19daJjHBU2orz3xsykj3xEZghlWMxpn9QnSVE3GLZYr4okkKr2I8IbClRBjn+wc OXIbxpCNpunwB0EJ/JdUyVI2CvvT2xKkmpLqKmx0H5tas8Oz4g4KzfH30fPxNWTJVNok HFplaGHSyvGcNmMgObWNLpw/30jdB5g5oYZQUC3V03X0pSprz+L1Zf3aaoUh3chV/VWW xvEg== X-Gm-Message-State: ABuFfohHjkFKvHk6CZO6pdu1OZhOfUJ0x3R99U73tbe2JvH0sqKOYggj qgyefbQdQO9Fy5eyXXvMkZyuLM53e0o= X-Google-Smtp-Source: ACcGV62UhvQss/cHCeyH9mNvXK3Q13Gf57CSFaosmMXjoGg5sptCcDT6C6+hVvP25GvAjKesY9J0KQ== X-Received: by 2002:a17:902:9047:: with SMTP id w7-v6mr2614669plz.4.1539282643885; Thu, 11 Oct 2018 11:30:43 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:43 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com, Laurent Vivier Subject: [PATCH 08/13] amiflop: convert to blk-mq Date: Thu, 11 Oct 2018 11:30:18 -0700 Message-Id: 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 Straightforward conversion, just use the existing amiflop_lock to serialize access to the controller. Compile-tested only. Cc: Laurent Vivier Signed-off-by: Omar Sandoval --- drivers/block/amiflop.c | 127 +++++++++++++++------------------------- 1 file changed, 48 insertions(+), 79 deletions(-) diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c index eef3b085e70a..e9c701f9b32b 100644 --- a/drivers/block/amiflop.c +++ b/drivers/block/amiflop.c @@ -201,6 +201,7 @@ struct amiga_floppy_struct { int dirty; /* true when trackbuf is not on disk */ int status; /* current error code for unit */ struct gendisk *gendisk; + struct blk_mq_tag_set tag_set; }; /* @@ -281,7 +282,6 @@ static volatile int selected = -1; /* currently selected drive */ static int writepending; static int writefromint; static char *raw_buf; -static int fdc_queue; static DEFINE_SPINLOCK(amiflop_lock); @@ -1454,76 +1454,20 @@ static int get_track(int drive, int track) return -1; } -/* - * Round-robin between our available drives, doing one request from each - */ -static struct request *set_next_request(void) +static blk_status_t amiflop_rw_cur_segment(struct amiga_floppy_struct *floppy, + struct request *rq) { - struct request_queue *q; - int cnt = FD_MAX_UNITS; - struct request *rq = NULL; - - /* Find next queue we can dispatch from */ - fdc_queue = fdc_queue + 1; - if (fdc_queue == FD_MAX_UNITS) - fdc_queue = 0; - - for(cnt = FD_MAX_UNITS; cnt > 0; cnt--) { - - if (unit[fdc_queue].type->code == FD_NODRIVE) { - if (++fdc_queue == FD_MAX_UNITS) - fdc_queue = 0; - continue; - } - - q = unit[fdc_queue].gendisk->queue; - if (q) { - rq = blk_fetch_request(q); - if (rq) - break; - } - - if (++fdc_queue == FD_MAX_UNITS) - fdc_queue = 0; - } - - return rq; -} - -static void redo_fd_request(void) -{ - struct request *rq; + int drive = floppy - unit; unsigned int cnt, block, track, sector; - int drive; - struct amiga_floppy_struct *floppy; char *data; - unsigned long flags; - blk_status_t err; - -next_req: - rq = set_next_request(); - if (!rq) { - /* Nothing left to do */ - return; - } - floppy = rq->rq_disk->private_data; - drive = floppy - unit; - -next_segment: - /* Here someone could investigate to be more efficient */ - for (cnt = 0, err = BLK_STS_OK; cnt < blk_rq_cur_sectors(rq); cnt++) { + for (cnt = 0; cnt < blk_rq_cur_sectors(rq); cnt++) { #ifdef DEBUG printk("fd: sector %ld + %d requested for %s\n", blk_rq_pos(rq), cnt, (rq_data_dir(rq) == READ) ? "read" : "write"); #endif block = blk_rq_pos(rq) + cnt; - if ((int)block > floppy->blocks) { - err = BLK_STS_IOERR; - break; - } - track = block / (floppy->dtype->sects * floppy->type->sect_mult); sector = block % (floppy->dtype->sects * floppy->type->sect_mult); data = bio_data(rq->bio) + 512 * cnt; @@ -1532,10 +1476,8 @@ static void redo_fd_request(void) "0x%08lx\n", track, sector, data); #endif - if (get_track(drive, track) == -1) { - err = BLK_STS_IOERR; - break; - } + if (get_track(drive, track) == -1) + return BLK_STS_IOERR; if (rq_data_dir(rq) == READ) { memcpy(data, floppy->trackbuf + sector * 512, 512); @@ -1543,31 +1485,42 @@ static void redo_fd_request(void) memcpy(floppy->trackbuf + sector * 512, data, 512); /* keep the drive spinning while writes are scheduled */ - if (!fd_motor_on(drive)) { - err = BLK_STS_IOERR; - break; - } + if (!fd_motor_on(drive)) + return BLK_STS_IOERR; /* * setup a callback to write the track buffer * after a short (1 tick) delay. */ - local_irq_save(flags); - floppy->dirty = 1; /* reset the timer */ mod_timer (flush_track_timer + drive, jiffies + 1); - local_irq_restore(flags); } } - if (__blk_end_request_cur(rq, err)) - goto next_segment; - goto next_req; + return BLK_STS_OK; } -static void do_fd_request(struct request_queue * q) +static blk_status_t amiflop_queue_rq(struct blk_mq_hw_ctx *hctx, + const struct blk_mq_queue_data *bd) { - redo_fd_request(); + struct request *rq = bd->rq; + struct amiga_floppy_struct *floppy = rq->rq_disk->private_data; + blk_status_t err; + + if (!spin_trylock_irq(&amiflop_lock)) + return BLK_STS_DEV_RESOURCE; + + blk_mq_start_request(rq); + + do { + err = amiflop_rw_cur_segment(floppy, rq); + if (err) + break; + } while (blk_update_request(rq, err, blk_rq_cur_bytes(rq))); + blk_mq_end_request(rq, err); + + spin_unlock_irq(&amiflop_lock); + return BLK_STS_OK; } static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo) @@ -1818,18 +1771,32 @@ static const struct block_device_operations floppy_fops = { .check_events = amiga_check_events, }; +static const struct blk_mq_ops amiflop_mq_ops = { + .queue_rq = amiflop_queue_rq, +}; + static struct gendisk *fd_alloc_disk(int drive) { struct gendisk *disk; + struct blk_mq_tag_set *set; disk = alloc_disk(1); if (!disk) goto out; - disk->queue = blk_init_queue(do_fd_request, &amiflop_lock); + set = &unit[drive].tag_set; + set->ops = &amiflop_mq_ops; + set->nr_hw_queues = 1; + set->queue_depth = 2; + set->numa_node = NUMA_NO_NODE; + set->flags = BLK_MQ_F_SHOULD_MERGE; + if (blk_mq_alloc_tag_set(set)) + goto out_put_disk; + + disk->queue = blk_mq_init_queue(set); if (IS_ERR(disk->queue)) { disk->queue = NULL; - goto out_put_disk; + goto out_free_tag_set; } unit[drive].trackbuf = kmalloc(FLOPPY_MAX_SECTORS * 512, GFP_KERNEL); @@ -1841,6 +1808,8 @@ static struct gendisk *fd_alloc_disk(int drive) out_cleanup_queue: blk_cleanup_queue(disk->queue); disk->queue = NULL; +out_free_tag_set: + blk_mq_free_tag_set(set); out_put_disk: put_disk(disk); out: From patchwork Thu Oct 11 18:30:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637101 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 3FFB117E3 for ; Thu, 11 Oct 2018 18:30:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 328D52BEC1 for ; Thu, 11 Oct 2018 18:30:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26ADB2BEE5; Thu, 11 Oct 2018 18:30:48 +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 7589F2BEC1 for ; Thu, 11 Oct 2018 18:30:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729189AbeJLB7K (ORCPT ); Thu, 11 Oct 2018 21:59:10 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36073 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729163AbeJLB7K (ORCPT ); Thu, 11 Oct 2018 21:59:10 -0400 Received: by mail-pl1-f196.google.com with SMTP id y11-v6so4630052plt.3 for ; Thu, 11 Oct 2018 11:30:46 -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=F4LAjIP9acIjVKJWwpueWAOtJilldCnnjf3dNmDJpSg=; b=yXE/z0O/k74JzJnJe6eH+e4T9tSxPxxrvrgj+kVtMnBcuvavBKPmiR6aLpc1/+7L3G owTEgh6/CxCeFDWYN2eYkKxmZ8ORHCTOC1yWtojlUSVWMr3HWNY3vi9H0/cKYPcHNVuR X9dsaPCbCJ6oX4k2ISCIvTt4qhiogGdU49EiRzABM+5J3Ip4d3ZfSCYTgU5X0kusRHKo PDiMUF9/LWwhTDzrvEemlT6Dzucoe4onQuqbUuoZDjQ5GF+UFgjcZXbIpQERLjrkrZjN rlu06hmZBDpe1XJlCscaN97bNZMhoGROVQbK5QTwodwyKwrkxcKWCLi28M0f89oa9TL/ J5xg== 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=F4LAjIP9acIjVKJWwpueWAOtJilldCnnjf3dNmDJpSg=; b=U168PfQGExEnm+8F3ThmxUJ41Qpi0kwRDlJ91mOtnYHIeda9O+QBpwwEBOQWAN2xjm BoXxpWZeDZ/1tng3xCaL1CofmymYv5+XcyOJZn8WUfpW22c01ioKJnYsF/+dUS7JLZ3y pyPmjbTa+/g+iLE0rBuajZot1HMCj9dfSKgwHKMxWf3GLwEttoNS+88D6E+6IgrQ5Z6W so7BD9tMXrVQzSMSYhBdwwb/mrTpasENYsJL1vgqXGJ+eNvLlY58O2px5wNIRdIV4Po+ ABWzpImfAj9gO1zbg3xoHZN5W0ArGEm+Q8vx6C9+9PCxG9wtTizXoY7qZVtcrOoe5M1/ 7gmw== X-Gm-Message-State: ABuFfojxk38f3fsw2UPKqJ4zxAeE7LhkIUanm2M3qrz752VLuaF9y4NZ yhs3w8Wc2NHmvENrZvzOSo+DSmV8uRg= X-Google-Smtp-Source: ACcGV62kLVovbvvVqTcAijEZkIDMRtbxRj0aiyqNKS+KqAm2AOs5T4qEacsQ4Aasy427vU4n7GF5Dw== X-Received: by 2002:a17:902:9b84:: with SMTP id y4-v6mr2647841plp.332.1539282645162; Thu, 11 Oct 2018 11:30:45 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:44 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 09/13] ataflop: fold headers into C file Date: Thu, 11 Oct 2018 11:30:19 -0700 Message-Id: <197d7737abcfd32fe9351c3cda5bf5c27413af83.1539282366.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 atafd.h and atafdreg.h are only used from ataflop.c, so merge them in there. Signed-off-by: Omar Sandoval --- arch/m68k/include/asm/atafd.h | 13 ----- arch/m68k/include/asm/atafdreg.h | 80 ------------------------------ drivers/block/ataflop.c | 83 +++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 95 deletions(-) delete mode 100644 arch/m68k/include/asm/atafd.h delete mode 100644 arch/m68k/include/asm/atafdreg.h diff --git a/arch/m68k/include/asm/atafd.h b/arch/m68k/include/asm/atafd.h deleted file mode 100644 index ad7014cad633..000000000000 --- a/arch/m68k/include/asm/atafd.h +++ /dev/null @@ -1,13 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _ASM_M68K_FD_H -#define _ASM_M68K_FD_H - -/* Definitions for the Atari Floppy driver */ - -struct atari_format_descr { - int track; /* to be formatted */ - int head; /* "" "" */ - int sect_offset; /* offset of first sector */ -}; - -#endif diff --git a/arch/m68k/include/asm/atafdreg.h b/arch/m68k/include/asm/atafdreg.h deleted file mode 100644 index c31b4919ed2d..000000000000 --- a/arch/m68k/include/asm/atafdreg.h +++ /dev/null @@ -1,80 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef _LINUX_FDREG_H -#define _LINUX_FDREG_H - -/* -** WD1772 stuff - */ - -/* register codes */ - -#define FDCSELREG_STP (0x80) /* command/status register */ -#define FDCSELREG_TRA (0x82) /* track register */ -#define FDCSELREG_SEC (0x84) /* sector register */ -#define FDCSELREG_DTA (0x86) /* data register */ - -/* register names for FDC_READ/WRITE macros */ - -#define FDCREG_CMD 0 -#define FDCREG_STATUS 0 -#define FDCREG_TRACK 2 -#define FDCREG_SECTOR 4 -#define FDCREG_DATA 6 - -/* command opcodes */ - -#define FDCCMD_RESTORE (0x00) /* - */ -#define FDCCMD_SEEK (0x10) /* | */ -#define FDCCMD_STEP (0x20) /* | TYP 1 Commands */ -#define FDCCMD_STIN (0x40) /* | */ -#define FDCCMD_STOT (0x60) /* - */ -#define FDCCMD_RDSEC (0x80) /* - TYP 2 Commands */ -#define FDCCMD_WRSEC (0xa0) /* - " */ -#define FDCCMD_RDADR (0xc0) /* - */ -#define FDCCMD_RDTRA (0xe0) /* | TYP 3 Commands */ -#define FDCCMD_WRTRA (0xf0) /* - */ -#define FDCCMD_FORCI (0xd0) /* - TYP 4 Command */ - -/* command modifier bits */ - -#define FDCCMDADD_SR6 (0x00) /* step rate settings */ -#define FDCCMDADD_SR12 (0x01) -#define FDCCMDADD_SR2 (0x02) -#define FDCCMDADD_SR3 (0x03) -#define FDCCMDADD_V (0x04) /* verify */ -#define FDCCMDADD_H (0x08) /* wait for spin-up */ -#define FDCCMDADD_U (0x10) /* update track register */ -#define FDCCMDADD_M (0x10) /* multiple sector access */ -#define FDCCMDADD_E (0x04) /* head settling flag */ -#define FDCCMDADD_P (0x02) /* precompensation off */ -#define FDCCMDADD_A0 (0x01) /* DAM flag */ - -/* status register bits */ - -#define FDCSTAT_MOTORON (0x80) /* motor on */ -#define FDCSTAT_WPROT (0x40) /* write protected (FDCCMD_WR*) */ -#define FDCSTAT_SPINUP (0x20) /* motor speed stable (Type I) */ -#define FDCSTAT_DELDAM (0x20) /* sector has deleted DAM (Type II+III) */ -#define FDCSTAT_RECNF (0x10) /* record not found */ -#define FDCSTAT_CRC (0x08) /* CRC error */ -#define FDCSTAT_TR00 (0x04) /* Track 00 flag (Type I) */ -#define FDCSTAT_LOST (0x04) /* Lost Data (Type II+III) */ -#define FDCSTAT_IDX (0x02) /* Index status (Type I) */ -#define FDCSTAT_DRQ (0x02) /* DRQ status (Type II+III) */ -#define FDCSTAT_BUSY (0x01) /* FDC is busy */ - - -/* PSG Port A Bit Nr 0 .. Side Sel .. 0 -> Side 1 1 -> Side 2 */ -#define DSKSIDE (0x01) - -#define DSKDRVNONE (0x06) -#define DSKDRV0 (0x02) -#define DSKDRV1 (0x04) - -/* step rates */ -#define FDCSTEP_6 0x00 -#define FDCSTEP_12 0x01 -#define FDCSTEP_2 0x02 -#define FDCSTEP_3 0x03 - -#endif diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index dfb2c2622e5a..17df631c5d85 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c @@ -71,8 +71,6 @@ #include #include -#include -#include #include #include #include @@ -85,6 +83,87 @@ static DEFINE_MUTEX(ataflop_mutex); static struct request *fd_request; static int fdc_queue; +/* + * WD1772 stuff + */ + +/* register codes */ + +#define FDCSELREG_STP (0x80) /* command/status register */ +#define FDCSELREG_TRA (0x82) /* track register */ +#define FDCSELREG_SEC (0x84) /* sector register */ +#define FDCSELREG_DTA (0x86) /* data register */ + +/* register names for FDC_READ/WRITE macros */ + +#define FDCREG_CMD 0 +#define FDCREG_STATUS 0 +#define FDCREG_TRACK 2 +#define FDCREG_SECTOR 4 +#define FDCREG_DATA 6 + +/* command opcodes */ + +#define FDCCMD_RESTORE (0x00) /* - */ +#define FDCCMD_SEEK (0x10) /* | */ +#define FDCCMD_STEP (0x20) /* | TYP 1 Commands */ +#define FDCCMD_STIN (0x40) /* | */ +#define FDCCMD_STOT (0x60) /* - */ +#define FDCCMD_RDSEC (0x80) /* - TYP 2 Commands */ +#define FDCCMD_WRSEC (0xa0) /* - " */ +#define FDCCMD_RDADR (0xc0) /* - */ +#define FDCCMD_RDTRA (0xe0) /* | TYP 3 Commands */ +#define FDCCMD_WRTRA (0xf0) /* - */ +#define FDCCMD_FORCI (0xd0) /* - TYP 4 Command */ + +/* command modifier bits */ + +#define FDCCMDADD_SR6 (0x00) /* step rate settings */ +#define FDCCMDADD_SR12 (0x01) +#define FDCCMDADD_SR2 (0x02) +#define FDCCMDADD_SR3 (0x03) +#define FDCCMDADD_V (0x04) /* verify */ +#define FDCCMDADD_H (0x08) /* wait for spin-up */ +#define FDCCMDADD_U (0x10) /* update track register */ +#define FDCCMDADD_M (0x10) /* multiple sector access */ +#define FDCCMDADD_E (0x04) /* head settling flag */ +#define FDCCMDADD_P (0x02) /* precompensation off */ +#define FDCCMDADD_A0 (0x01) /* DAM flag */ + +/* status register bits */ + +#define FDCSTAT_MOTORON (0x80) /* motor on */ +#define FDCSTAT_WPROT (0x40) /* write protected (FDCCMD_WR*) */ +#define FDCSTAT_SPINUP (0x20) /* motor speed stable (Type I) */ +#define FDCSTAT_DELDAM (0x20) /* sector has deleted DAM (Type II+III) */ +#define FDCSTAT_RECNF (0x10) /* record not found */ +#define FDCSTAT_CRC (0x08) /* CRC error */ +#define FDCSTAT_TR00 (0x04) /* Track 00 flag (Type I) */ +#define FDCSTAT_LOST (0x04) /* Lost Data (Type II+III) */ +#define FDCSTAT_IDX (0x02) /* Index status (Type I) */ +#define FDCSTAT_DRQ (0x02) /* DRQ status (Type II+III) */ +#define FDCSTAT_BUSY (0x01) /* FDC is busy */ + + +/* PSG Port A Bit Nr 0 .. Side Sel .. 0 -> Side 1 1 -> Side 2 */ +#define DSKSIDE (0x01) + +#define DSKDRVNONE (0x06) +#define DSKDRV0 (0x02) +#define DSKDRV1 (0x04) + +/* step rates */ +#define FDCSTEP_6 0x00 +#define FDCSTEP_12 0x01 +#define FDCSTEP_2 0x02 +#define FDCSTEP_3 0x03 + +struct atari_format_descr { + int track; /* to be formatted */ + int head; /* "" "" */ + int sect_offset; /* offset of first sector */ +}; + /* Disk types: DD, HD, ED */ static struct atari_disk_type { const char *name; From patchwork Thu Oct 11 18:30:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637103 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 EDEBD17E3 for ; Thu, 11 Oct 2018 18:30:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E05EB2BEC1 for ; Thu, 11 Oct 2018 18:30:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D51C42BEEA; Thu, 11 Oct 2018 18:30:48 +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 7A7C72BEE9 for ; Thu, 11 Oct 2018 18:30:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729152AbeJLB7L (ORCPT ); Thu, 11 Oct 2018 21:59:11 -0400 Received: from mail-pg1-f179.google.com ([209.85.215.179]:43932 "EHLO mail-pg1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729175AbeJLB7L (ORCPT ); Thu, 11 Oct 2018 21:59:11 -0400 Received: by mail-pg1-f179.google.com with SMTP id 80-v6so4561915pgh.10 for ; Thu, 11 Oct 2018 11:30:46 -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=/+ISgGhJwtAGzKowvLRcks0rVA+K+dVjkOrn5EYUabs=; b=I2MajMEK2gEDIEMTOWVhKHcP4NpuD27vhNHJX/JLU4FjmHrsEw3M9/SBJGQSFbB96n bcXtpxYcuDObxf+B/eqnUdvmQb7An5zY5Sy2BTQf1HjimeUy0YCPoAfjqAkWonDTg4FN JMPyVUzhZDsbo9gyKglZkTNcxCXEKRIiuatzOu8tBmAA9imsSYmZniq3RHxf0BYmcJvS lOzMnGV/IIi9KETJzzft6l2T9Sdt49tDESAnUEg5f8ZrBXrPPOxr948a32n7OzbgddhP U/xssnJ/hn07HDihjBg/YQ3ws/jSPQngL7F3O2v8yKjS3TL+wawTTu3W+NW1ewj4p6EC cQeA== 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=/+ISgGhJwtAGzKowvLRcks0rVA+K+dVjkOrn5EYUabs=; b=HG+3OoJQDomdAbEiCkyJeVvi8biW41aELSkW1cIhUMVxqnP3S/RBIhs1Qh9s3+S3Uf ji2DIz3HrdypkB9yzy2rQ8xCiiIkmEF6V+D9MDIGlgUItKtPfp8jm18z8iVjbBjH/iV9 OgB6Z8RReJrPuiU/mQnjvMjctjQ4QiuurqU5J9xwhv628LikXm77FU73et0FQdea4bHr HLrL10gScNZwZL6heWic7O4vvAb+1l3Jlno1PZt96mdgnRmgCAKUjqb6a5b1exe90K1g TuEroFzzyjTMhdAP7YCMWmElv2hrnFcj9hEZDCdvUgXdu7suadrrOeMYcJ/waJotk5hn QYZQ== X-Gm-Message-State: ABuFfoh9A/SMP7BFXFhcjkwyYA2GGJBQ4FundIt/FZAgINSJmw9FhTWR uiAon+Z4pVg6SDQd1o/dJJu29pVdedw= X-Google-Smtp-Source: ACcGV60l4MLvKpOIfnU/spyPjlVN74PlGo5HCy6ZqwVeVAYG7zz7HczbjV6c2bCFfNuefH17HpNcyA== X-Received: by 2002:a63:184a:: with SMTP id 10-v6mr2362728pgy.81.1539282645949; Thu, 11 Oct 2018 11:30:45 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:45 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 10/13] ataflop: fix error handling during setup Date: Thu, 11 Oct 2018 11:30:20 -0700 Message-Id: <22892297ed4f1b951dfb06c0c20752cc6956cb1a.1539282366.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 Move queue allocation next to disk allocation to fix a couple of issues: - If add_disk() hasn't been called, we should clear disk->queue before calling put_disk(). - If we fail to allocate a request queue, we still need to put all of the disks, not just the ones that we allocated queues for. Signed-off-by: Omar Sandoval --- drivers/block/ataflop.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index 17df631c5d85..0144d598ac47 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c @@ -2014,6 +2014,11 @@ static int __init atari_floppy_init (void) unit[i].disk = alloc_disk(1); if (!unit[i].disk) goto Enomem; + + unit[i].disk->queue = blk_init_queue(do_fd_request, + &ataflop_lock); + if (!unit[i].disk->queue) + goto Enomem; } if (UseTrackbuffer < 0) @@ -2045,10 +2050,6 @@ static int __init atari_floppy_init (void) sprintf(unit[i].disk->disk_name, "fd%d", i); unit[i].disk->fops = &floppy_fops; unit[i].disk->private_data = &unit[i]; - unit[i].disk->queue = blk_init_queue(do_fd_request, - &ataflop_lock); - if (!unit[i].disk->queue) - goto Enomem; set_capacity(unit[i].disk, MAX_DISK_SIZE * 2); add_disk(unit[i].disk); } @@ -2063,13 +2064,17 @@ static int __init atari_floppy_init (void) return 0; Enomem: - while (i--) { - struct request_queue *q = unit[i].disk->queue; + do { + struct gendisk *disk = unit[i].disk; - put_disk(unit[i].disk); - if (q) - blk_cleanup_queue(q); - } + if (disk) { + if (disk->queue) { + blk_cleanup_queue(disk->queue); + disk->queue = NULL; + } + put_disk(unit[i].disk); + } + } while (i--); unregister_blkdev(FLOPPY_MAJOR, "fd"); return -ENOMEM; From patchwork Thu Oct 11 18:30:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637105 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 28E9213AD for ; Thu, 11 Oct 2018 18:30:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BFD22BEE1 for ; Thu, 11 Oct 2018 18:30:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 09FD52BEF0; Thu, 11 Oct 2018 18:30:50 +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 20C6C2BEE1 for ; Thu, 11 Oct 2018 18:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729191AbeJLB7M (ORCPT ); Thu, 11 Oct 2018 21:59:12 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:39986 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729154AbeJLB7M (ORCPT ); Thu, 11 Oct 2018 21:59:12 -0400 Received: by mail-pg1-f196.google.com with SMTP id n31-v6so4570688pgm.7 for ; Thu, 11 Oct 2018 11:30:47 -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=P1Ndg/QskIhY1oMKEwqGrvC50eCUcRCGFxE6AFaqJxg=; b=LqpFEeL0Fdn2qcGMtvNIPpj/ZwMa6VNIQY3pFRl3aXPP4G5a0KppIjWWQ5mzaGJG5D diEGjWTHjneumGY0nW6u/7e+tP0FFAz8kjfwsISLRx21y1NJLTCSHDeS2vJOxPyPMxCm PT6n++qDMPf3YRDm5TpSmSTE7p1p/jTASH/TLgVfbQtf0CqM2NuOjbeuHwIXg1KUQQM7 EAEv9Tt50o/JQiwyrWstln0bo/wM7h6LVJsRPfsCjfTseSKfa4YU565oDPemUUrDD8Le x1W8J2SXPtpC/Dqm5d+4GFfhmVGOTLC517YDedxuSkGgX71ZiUDp9fDF/kWy3hF2XWJH dYwA== 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=P1Ndg/QskIhY1oMKEwqGrvC50eCUcRCGFxE6AFaqJxg=; b=XSh6rYxhn/OPA+IzSEazeSZhUNBwrQupGQoacTh9KASsSePLQr4i7w77kcRvZBW0Wq Pl4gr6OpTCvl7pNlB+jyZ20+GmXwlP1ghmtvNMo3Hido6jhEmTvWKc1wVa2XNGpLJnOD ORFQcraC10k0ImDLFyjFIYj2Af0xYYirVuBSNbyOnA4uCEqu+smX+wAz9lH2OWvJD9xK msZyY8/LjUQBiXJAe5OROl6IR4gjTShxcREQANV7egxjOKY2Gil8Ur6AuF9uysr101kX IBLDQVBp13FzNgqFrhtFhBA0WzQYMxjdKvbpbpfPr8Gl1MqTj6F7aJAhYujKJ+5wT8/2 zT1w== X-Gm-Message-State: ABuFfohI6W3Jpt59qNSiPM7nu9OpzfD94PpraEUSb2yYeUJGeenm1u0R J2Xx5PDMfEIGGmwjAcW5oVmVgAEhOcM= X-Google-Smtp-Source: ACcGV62A0CtK/xy4aGIwepujCsFqbtHQtrlCqSHxFECqkz7g7ZZn2nQQkei1+6ORhr8vjLg8iC3Ruw== X-Received: by 2002:a62:cac4:: with SMTP id y65-v6mr2630772pfk.27.1539282646948; Thu, 11 Oct 2018 11:30:46 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:46 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com, Laurent Vivier Subject: [PATCH 11/13] ataflop: convert to blk-mq Date: Thu, 11 Oct 2018 11:30:21 -0700 Message-Id: <3461961db53c6f209afb7bf09ea35880acbe39cd.1539282366.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 This driver is already pretty broken, in that it has two wait_events() (one in stdma_lock()) in request_fn. Get rid of the first one by freezing/quiescing the queue on format, and the second one by replacing it with stdma_try_lock(). The rest is straightforward. Compile-tested only and probably incorrect. Cc: Laurent Vivier Signed-off-by: Omar Sandoval --- drivers/block/ataflop.c | 188 ++++++++++++++++++---------------------- 1 file changed, 86 insertions(+), 102 deletions(-) diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index 0144d598ac47..5934e30d4805 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c @@ -66,7 +66,7 @@ #include #include #include -#include +#include #include #include #include @@ -81,7 +81,6 @@ static DEFINE_MUTEX(ataflop_mutex); static struct request *fd_request; -static int fdc_queue; /* * WD1772 stuff @@ -300,6 +299,7 @@ static struct atari_floppy_struct { struct gendisk *disk; int ref; int type; + struct blk_mq_tag_set tag_set; } unit[FD_MAX_UNITS]; #define UD unit[drive] @@ -379,9 +379,6 @@ static int IsFormatting = 0, FormatError; static int UserSteprate[FD_MAX_UNITS] = { -1, -1 }; module_param_array(UserSteprate, int, NULL, 0); -/* Synchronization of FDC access. */ -static volatile int fdc_busy = 0; -static DECLARE_WAIT_QUEUE_HEAD(fdc_wait); static DECLARE_COMPLETION(format_wait); static unsigned long changed_floppies = 0xff, fake_change = 0; @@ -441,7 +438,6 @@ static void fd_times_out(struct timer_list *unused); static void finish_fdc( void ); static void finish_fdc_done( int dummy ); static void setup_req_params( int drive ); -static void redo_fd_request( void); static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long param); static void fd_probe( int drive ); @@ -459,8 +455,16 @@ static DEFINE_TIMER(fd_timer, check_change); static void fd_end_request_cur(blk_status_t err) { - if (!__blk_end_request_cur(fd_request, err)) + if (err) { + blk_mq_end_request(fd_request, err); + return; + } + + if (!blk_update_request(fd_request, err, + blk_rq_cur_bytes(fd_request))) { + __blk_mq_end_request(fd_request, err); fd_request = NULL; + } } static inline void start_motor_off_timer(void) @@ -706,7 +710,6 @@ static void fd_error( void ) if (SelectedDrive != -1) SUD.track = -1; } - redo_fd_request(); } @@ -724,14 +727,15 @@ static void fd_error( void ) static int do_format(int drive, int type, struct atari_format_descr *desc) { + struct request_queue *q = unit[drive].disk->queue; unsigned char *p; int sect, nsect; unsigned long flags; + int ret; - DPRINT(("do_format( dr=%d tr=%d he=%d offs=%d )\n", - drive, desc->track, desc->head, desc->sect_offset )); + blk_mq_freeze_queue(q); + blk_mq_quiesce_queue(q); - wait_event(fdc_wait, cmpxchg(&fdc_busy, 0, 1) == 0); local_irq_save(flags); stdma_lock(floppy_irq, NULL); atari_turnon_irq( IRQ_MFP_FDC ); /* should be already, just to be sure */ @@ -740,16 +744,16 @@ static int do_format(int drive, int type, struct atari_format_descr *desc) if (type) { if (--type >= NUM_DISK_MINORS || minor2disktype[type].drive_types > DriveType) { - redo_fd_request(); - return -EINVAL; + ret = -EINVAL; + goto out; } type = minor2disktype[type].index; UDT = &atari_disk_type[type]; } if (!UDT || desc->track >= UDT->blocks/UDT->spt/2 || desc->head >= 2) { - redo_fd_request(); - return -EINVAL; + ret = -EINVAL; + goto out; } nsect = UDT->spt; @@ -788,8 +792,11 @@ static int do_format(int drive, int type, struct atari_format_descr *desc) wait_for_completion(&format_wait); - redo_fd_request(); - return( FormatError ? -EIO : 0 ); + ret = FormatError ? -EIO : 0; +out: + blk_mq_unquiesce_queue(q); + blk_mq_unfreeze_queue(q); + return ret; } @@ -819,7 +826,6 @@ static void do_fd_action( int drive ) else { /* all sectors finished */ fd_end_request_cur(BLK_STS_OK); - redo_fd_request(); return; } } @@ -1224,7 +1230,6 @@ static void fd_rwsec_done1(int status) else { /* all sectors finished */ fd_end_request_cur(BLK_STS_OK); - redo_fd_request(); } return; @@ -1382,8 +1387,6 @@ static void finish_fdc_done( int dummy ) local_irq_save(flags); stdma_release(); - fdc_busy = 0; - wake_up( &fdc_wait ); local_irq_restore(flags); DPRINT(("finish_fdc() finished\n")); @@ -1473,59 +1476,34 @@ static void setup_req_params( int drive ) ReqTrack, ReqSector, (unsigned long)ReqData )); } -/* - * Round-robin between our available drives, doing one request from each - */ -static struct request *set_next_request(void) +static blk_status_t ataflop_queue_rq(struct blk_mq_hw_ctx *hctx, + const struct blk_mq_queue_data *bd) { - struct request_queue *q; - int old_pos = fdc_queue; - struct request *rq = NULL; - - do { - q = unit[fdc_queue].disk->queue; - if (++fdc_queue == FD_MAX_UNITS) - fdc_queue = 0; - if (q) { - rq = blk_fetch_request(q); - if (rq) { - rq->error_count = 0; - break; - } - } - } while (fdc_queue != old_pos); - - return rq; -} - + struct atari_floppy_struct *floppy = bd->rq->rq_disk->private_data; + int drive = floppy - unit; + int type = floppy->type; -static void redo_fd_request(void) -{ - int drive, type; - struct atari_floppy_struct *floppy; + spin_lock_irq(&ataflop_lock); + if (fd_request) { + spin_unlock_irq(&ataflop_lock); + return BLK_STS_DEV_RESOURCE; + } + if (!stdma_try_lock(floppy_irq, NULL)) { + spin_unlock_irq(&ataflop_lock); + return BLK_STS_RESOURCE; + } + fd_request = bd->rq; + blk_mq_start_request(fd_request); - DPRINT(("redo_fd_request: fd_request=%p dev=%s fd_request->sector=%ld\n", - fd_request, fd_request ? fd_request->rq_disk->disk_name : "", - fd_request ? blk_rq_pos(fd_request) : 0 )); + atari_disable_irq( IRQ_MFP_FDC ); IsFormatting = 0; -repeat: - if (!fd_request) { - fd_request = set_next_request(); - if (!fd_request) - goto the_end; - } - - floppy = fd_request->rq_disk->private_data; - drive = floppy - unit; - type = floppy->type; - if (!UD.connected) { /* drive not connected */ printk(KERN_ERR "Unknown Device: fd%d\n", drive ); fd_end_request_cur(BLK_STS_IOERR); - goto repeat; + goto out; } if (type == 0) { @@ -1541,23 +1519,18 @@ static void redo_fd_request(void) if (--type >= NUM_DISK_MINORS) { printk(KERN_WARNING "fd%d: invalid disk format", drive ); fd_end_request_cur(BLK_STS_IOERR); - goto repeat; + goto out; } if (minor2disktype[type].drive_types > DriveType) { printk(KERN_WARNING "fd%d: unsupported disk format", drive ); fd_end_request_cur(BLK_STS_IOERR); - goto repeat; + goto out; } type = minor2disktype[type].index; UDT = &atari_disk_type[type]; set_capacity(floppy->disk, UDT->blocks); UD.autoprobe = 0; } - - if (blk_rq_pos(fd_request) + 1 > UDT->blocks) { - fd_end_request_cur(BLK_STS_IOERR); - goto repeat; - } /* stop deselect timer */ del_timer( &motor_off_timer ); @@ -1569,22 +1542,13 @@ static void redo_fd_request(void) setup_req_params( drive ); do_fd_action( drive ); - return; - - the_end: - finish_fdc(); -} - - -void do_fd_request(struct request_queue * q) -{ - DPRINT(("do_fd_request for pid %d\n",current->pid)); - wait_event(fdc_wait, cmpxchg(&fdc_busy, 0, 1) == 0); - stdma_lock(floppy_irq, NULL); - - atari_disable_irq( IRQ_MFP_FDC ); - redo_fd_request(); + if (bd->last) + finish_fdc(); atari_enable_irq( IRQ_MFP_FDC ); + +out: + spin_unlock_irq(&ataflop_lock); + return BLK_STS_OK; } static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, @@ -1662,7 +1626,6 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, /* what if type > 0 here? Overwrite specified entry ? */ if (type) { /* refuse to re-set a predefined type for now */ - redo_fd_request(); return -EINVAL; } @@ -1730,10 +1693,8 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, /* sanity check */ if (setprm.track != dtp->blocks/dtp->spt/2 || - setprm.head != 2) { - redo_fd_request(); + setprm.head != 2) return -EINVAL; - } UDT = dtp; set_capacity(floppy->disk, UDT->blocks); @@ -1989,6 +1950,10 @@ static const struct block_device_operations floppy_fops = { .revalidate_disk= floppy_revalidate, }; +static const struct blk_mq_ops ataflop_mq_ops = { + .queue_rq = ataflop_queue_rq, +}; + static struct kobject *floppy_find(dev_t dev, int *part, void *data) { int drive = *part & 3; @@ -2002,6 +1967,7 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data) static int __init atari_floppy_init (void) { int i; + int ret; if (!MACH_IS_ATARI) /* Amiga, Mac, ... don't have Atari-compatible floppy :-) */ @@ -2011,14 +1977,30 @@ static int __init atari_floppy_init (void) return -EBUSY; for (i = 0; i < FD_MAX_UNITS; i++) { + struct blk_mq_tag_set *set; + unit[i].disk = alloc_disk(1); - if (!unit[i].disk) - goto Enomem; + if (!unit[i].disk) { + ret = -ENOMEM; + goto err; + } - unit[i].disk->queue = blk_init_queue(do_fd_request, - &ataflop_lock); - if (!unit[i].disk->queue) - goto Enomem; + set = &unit[i].tag_set; + set->ops = &ataflop_mq_ops; + set->nr_hw_queues = 1; + set->queue_depth = 2; + set->numa_node = NUMA_NO_NODE; + set->flags = BLK_MQ_F_SHOULD_MERGE; + ret = blk_mq_alloc_tag_set(set); + if (ret) + goto err; + + unit[i].disk->queue = blk_mq_init_queue(set); + if (IS_ERR(unit[i].disk->queue)) { + ret = PTR_ERR(unit[i].disk->queue); + unit[i].disk->queue = NULL; + goto err; + } } if (UseTrackbuffer < 0) @@ -2035,7 +2017,8 @@ static int __init atari_floppy_init (void) DMABuffer = atari_stram_alloc(BUFFER_SIZE+512, "ataflop"); if (!DMABuffer) { printk(KERN_ERR "atari_floppy_init: cannot get dma buffer\n"); - goto Enomem; + ret = -ENOMEM; + goto err; } TrackBuffer = DMABuffer + 512; PhysDMABuffer = atari_stram_to_phys(DMABuffer); @@ -2063,7 +2046,8 @@ static int __init atari_floppy_init (void) config_types(); return 0; -Enomem: + +err: do { struct gendisk *disk = unit[i].disk; @@ -2072,12 +2056,13 @@ static int __init atari_floppy_init (void) blk_cleanup_queue(disk->queue); disk->queue = NULL; } + blk_mq_free_tag_set(&unit[i].tag_set); put_disk(unit[i].disk); } } while (i--); unregister_blkdev(FLOPPY_MAJOR, "fd"); - return -ENOMEM; + return ret; } #ifndef MODULE @@ -2124,11 +2109,10 @@ static void __exit atari_floppy_exit(void) int i; blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); for (i = 0; i < FD_MAX_UNITS; i++) { - struct request_queue *q = unit[i].disk->queue; - del_gendisk(unit[i].disk); + blk_cleanup_queue(unit[i].disk->queue); + blk_mq_free_tag_set(&unit[i].tag_set); put_disk(unit[i].disk); - blk_cleanup_queue(q); } unregister_blkdev(FLOPPY_MAJOR, "fd"); From patchwork Thu Oct 11 18:30:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637107 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 4606D69B1 for ; Thu, 11 Oct 2018 18:30:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3751B2BEE1 for ; Thu, 11 Oct 2018 18:30:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3570B2BEE0; Thu, 11 Oct 2018 18:30:50 +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 DB7AE2BEEE for ; Thu, 11 Oct 2018 18:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729154AbeJLB7M (ORCPT ); Thu, 11 Oct 2018 21:59:12 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39985 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729175AbeJLB7M (ORCPT ); Thu, 11 Oct 2018 21:59:12 -0400 Received: by mail-pg1-f194.google.com with SMTP id n31-v6so4570696pgm.7 for ; Thu, 11 Oct 2018 11:30:48 -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=OW+N/ciED27CxbZv1LEba5SEww3LPafMQJoQCiFCVXc=; b=xXVNcIPdIC+pyj2OMX2S9S/6N3aSkqKXafPvpMk5ujzR5a9lx0HIJsydlVhgBSMBzc VSpf0aLyhBSSMjdg6ZnQjDkCTxvJTstc9V8B1AxcF6bEdy8vOpASJI1ETw978iJu31QJ Gow6GKzCWFkoRRgJhjPoaSFUc5/M8p39rg4uh9e2PIxh7zJjZ1Eeud4LyT73JKSNXBEF UTlC/irHYey7VVqj4l0P92vc8ERwuCzayVNwGB6sFwED1qlLIEDnxtkLD0K31LcqdukK X9H0m2uNchMj97rZPUwj8w1zXQm1Qbu7YfY7DzEpd1GO3X89SRZ6S5ihDrSoxKpCUr4T GVmQ== 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=OW+N/ciED27CxbZv1LEba5SEww3LPafMQJoQCiFCVXc=; b=kRvny/ps3897lhathHUAf2v50X1QtFXBc+nD8PNRYTzNZ5ihrQ/oIim6HARqVA7FYe yvk+UMzx6Cil+1dQIIO1y7hkJ1410PUAPeFkuFr+Jrs8t1O7Ojnj6rUrE6YggeU0YP05 bwEQhTB84Yk0G7f/zS/yCUtlXvXOiYoFzmQLHbD1rI+BRhne/BnAOzOoGUe7kWu1t1OL ChMNniSjiuKvzLrNisFAw1YpQluKZbvQhEAczGWjFRS3m4hNLRlpvm8KmjUSjMGE4BNX WJ1irPw5Z7/Kt8b7PmZmRSXXxbCm2n22nnmc2iHCiTtGHX2m+axEvFl2JrtwEY+qqjHt GInw== X-Gm-Message-State: ABuFfohdjS1f93Yjt3ikjCPeuTTuRjedj9WcU7x4o9Ujsclcwzp/Xijo eX4Xc3LgTVPo6q88lU7d7xFkCmtE8HY= X-Google-Smtp-Source: ACcGV626Yw2xw7K6bi0YHjkm/G+CaL36L5c8UHMhHIICtQhvxnJh9LfTrlcg7yOIm/acOtf1Tjy5RA== X-Received: by 2002:a62:c05a:: with SMTP id x87-v6mr2614581pff.149.1539282647678; Thu, 11 Oct 2018 11:30:47 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:47 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 12/13] floppy: end whole request on error Date: Thu, 11 Oct 2018 11:30:22 -0700 Message-Id: <4b575ac74fab6d233b891f8c12dadaea3873931c.1539282366.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 If floppy_end_request() gets passed an error, it should end the whole request, not just the current segment. Signed-off-by: Omar Sandoval --- drivers/block/floppy.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index f2b6f4da1034..acbafd831ea3 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -2210,13 +2210,15 @@ static int do_format(int drive, struct format_descr *tmp_format_req) static void floppy_end_request(struct request *req, blk_status_t error) { - unsigned int nr_sectors = current_count_sectors; + unsigned int nr_bytes; unsigned int drive = (unsigned long)req->rq_disk->private_data; /* current_count_sectors can be zero if transfer failed */ if (error) - nr_sectors = blk_rq_cur_sectors(req); - if (__blk_end_request(req, error, nr_sectors << 9)) + nr_bytes = blk_rq_bytes(req); + else + nr_bytes = current_count_sectors << 9; + if (__blk_end_request(req, error, nr_bytes)) return; /* We're done with the request */ From patchwork Thu Oct 11 18:30:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637109 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 21DCB17E3 for ; Thu, 11 Oct 2018 18:30:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C73B2BEF5 for ; Thu, 11 Oct 2018 18:30:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00D9B2BEDC; Thu, 11 Oct 2018 18:30:50 +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 7D8F52BEEA for ; Thu, 11 Oct 2018 18:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729192AbeJLB7N (ORCPT ); Thu, 11 Oct 2018 21:59:13 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36324 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729175AbeJLB7N (ORCPT ); Thu, 11 Oct 2018 21:59:13 -0400 Received: by mail-pg1-f195.google.com with SMTP id f18-v6so4583586pgv.3 for ; Thu, 11 Oct 2018 11:30:49 -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=LHNgOBPRAw2HSrLay2mD8bP3FPFWkFAOZGj6ry1/IJ0=; b=kEbK9OnH4Hsz0ODaU+YagzTj/zQj1n2S77YUvcx8Y/VrkY8W7qI0dzXxOi3gLaffUb CWz4KNwP3X2vdYoXQvO1c/ClyLn6ergCv1mLCCI7CqHd4a8XP3/fLMKAFZZkOOCO/LL1 dNqxNNelGbU91Ul2FWFnunSSzmR6QhzYfBgoNJh9sA3bwcFwamw8urkjg1L5RV7MpHKB I1sOQGT7jryAHBgotnooG1foaj/2hu6FIbvmUuuiBY3UWPv0ryNrmSuOUssRVAhjAWxR g/09tHQQ935mO8H+dDdMcvCy+U5ABLqeCBZo9jRW1QSJxUjqdvU8wYM6aCJgusLyuIK2 uLBQ== 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=LHNgOBPRAw2HSrLay2mD8bP3FPFWkFAOZGj6ry1/IJ0=; b=lxWIHs5nQlbXKSL/0IGV3fg8Wiag9phvtKVuFNaGHbx1EQCfYlmMpvTPOkQoB0RDVs cFYOBoG9y8lawt76o6KTmx3E35GRfVCar9OJA8Lwzn/3fxJZc93HfwrlfGWRdWlJ/UCp puz09HPkLEpFqyYyoHF2UQ3Z8I6P+jt7dCoZAFZlEtb2WN7hsLCp+XxdcYrJZm8Ptqwh 4eR6wI7wZ4fMtRKrDgq67ryF2HyQKCCGP4L6bIrC76JNBORdjZ6N7mZb0p/aOhbmRkD8 fkmyFFBfKVY2qrl2/fqJM+o1CXH8WP6ypaTY5OImM8CqCnzJKGKI9AXnS/g0pgmOFfrH 3aNA== X-Gm-Message-State: ABuFfoiz/WXsqjl/4MZ+WTKhbkdk/eeVkr+7MJO9QmhV3LvFk4rBWtDR XaktNr5APCBDdwuIrIGwnB3LHUwIGhE= X-Google-Smtp-Source: ACcGV60uq6Kng2z1Hn0DUUqpei8cash81kroJ/61S62Sy2Yb/8oU1QBlY+YOuw6n0s5hHeAIQUKOZg== X-Received: by 2002:a63:1148:: with SMTP id 8-v6mr2450585pgr.172.1539282648641; Thu, 11 Oct 2018 11:30:48 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id o2-v6sm57514640pfj.57.2018.10.11.11.30.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 11:30:48 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com Subject: [PATCH 13/13] floppy: convert to blk-mq Date: Thu, 11 Oct 2018 11:30:23 -0700 Message-Id: <5aa64bbc9651c69eb75cf8a6e4f9182f2e68ade3.1539282366.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 This driver likes to fetch requests from all over the place, so make queue_rq put requests on a list so that the logic stays the same. Tested with QEMU. Signed-off-by: Omar Sandoval --- drivers/block/floppy.c | 74 +++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index acbafd831ea3..eb19125beb90 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -252,13 +252,13 @@ static int allowed_drive_mask = 0x33; static int irqdma_allocated; -#include +#include #include #include /* for the compatibility eject ioctl */ #include +static LIST_HEAD(floppy_reqs); static struct request *current_req; -static void do_fd_request(struct request_queue *q); static int set_next_request(void); #ifndef fd_get_dma_residue @@ -414,10 +414,10 @@ static struct floppy_drive_struct drive_state[N_DRIVE]; static struct floppy_write_errors write_errors[N_DRIVE]; static struct timer_list motor_off_timer[N_DRIVE]; static struct gendisk *disks[N_DRIVE]; +static struct blk_mq_tag_set tag_sets[N_DRIVE]; static struct block_device *opened_bdev[N_DRIVE]; static DEFINE_MUTEX(open_lock); static struct floppy_raw_cmd *raw_cmd, default_raw_cmd; -static int fdc_queue; /* * This struct defines the different floppy types. @@ -2218,8 +2218,9 @@ static void floppy_end_request(struct request *req, blk_status_t error) nr_bytes = blk_rq_bytes(req); else nr_bytes = current_count_sectors << 9; - if (__blk_end_request(req, error, nr_bytes)) + if (blk_update_request(req, error, nr_bytes)) return; + __blk_mq_end_request(req, error); /* We're done with the request */ floppy_off(drive); @@ -2799,27 +2800,14 @@ static int make_raw_rw_request(void) return 2; } -/* - * Round-robin between our available drives, doing one request from each - */ static int set_next_request(void) { - struct request_queue *q; - int old_pos = fdc_queue; - - do { - q = disks[fdc_queue]->queue; - if (++fdc_queue == N_DRIVE) - fdc_queue = 0; - if (q) { - current_req = blk_fetch_request(q); - if (current_req) { - current_req->error_count = 0; - break; - } - } - } while (fdc_queue != old_pos); - + current_req = list_first_entry_or_null(&floppy_reqs, struct request, + queuelist); + if (current_req) { + current_req->error_count = 0; + list_del_init(¤t_req->queuelist); + } return current_req != NULL; } @@ -2903,29 +2891,38 @@ static void process_fd_request(void) schedule_bh(redo_fd_request); } -static void do_fd_request(struct request_queue *q) +static blk_status_t floppy_queue_rq(struct blk_mq_hw_ctx *hctx, + const struct blk_mq_queue_data *bd) { + blk_mq_start_request(bd->rq); + if (WARN(max_buffer_sectors == 0, "VFS: %s called on non-open device\n", __func__)) - return; + return BLK_STS_IOERR; if (WARN(atomic_read(&usage_count) == 0, "warning: usage count=0, current_req=%p sect=%ld flags=%llx\n", current_req, (long)blk_rq_pos(current_req), (unsigned long long) current_req->cmd_flags)) - return; + return BLK_STS_IOERR; + + spin_lock_irq(&floppy_lock); + list_add_tail(&bd->rq->queuelist, &floppy_reqs); + spin_unlock_irq(&floppy_lock); if (test_and_set_bit(0, &fdc_busy)) { /* fdc busy, this new request will be treated when the current one is done */ is_alive(__func__, "old request running"); - return; + return BLK_STS_OK; } + command_status = FD_COMMAND_NONE; __reschedule_timeout(MAXTIMEOUT, "fd_request"); set_fdc(0); process_fd_request(); is_alive(__func__, ""); + return BLK_STS_OK; } static const struct cont_t poll_cont = { @@ -4488,6 +4485,10 @@ static struct platform_driver floppy_driver = { }, }; +static const struct blk_mq_ops floppy_mq_ops = { + .queue_rq = floppy_queue_rq, +}; + static struct platform_device floppy_device[N_DRIVE]; static bool floppy_available(int drive) @@ -4529,15 +4530,28 @@ static int __init do_floppy_init(void) return -ENOMEM; for (drive = 0; drive < N_DRIVE; drive++) { + struct blk_mq_tag_set *set; + disks[drive] = alloc_disk(1); if (!disks[drive]) { err = -ENOMEM; goto out_put_disk; } - disks[drive]->queue = blk_init_queue(do_fd_request, &floppy_lock); - if (!disks[drive]->queue) { - err = -ENOMEM; + set = &tag_sets[drive]; + set->ops = &floppy_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 out_put_disk; + + disks[drive]->queue = blk_mq_init_queue(set); + if (IS_ERR(disks[drive]->queue)) { + err = PTR_ERR(disks[drive]->queue); + disks[drive]->queue = NULL; goto out_put_disk; }