From patchwork Thu Oct 11 19:20:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10637231 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 7EB7E69B1 for ; Thu, 11 Oct 2018 19:21:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AB232C007 for ; Thu, 11 Oct 2018 19:21:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6814B2BFF9; Thu, 11 Oct 2018 19:21:06 +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 BB43C2C007 for ; Thu, 11 Oct 2018 19:21:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729718AbeJLCtj (ORCPT ); Thu, 11 Oct 2018 22:49:39 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35023 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729706AbeJLCtj (ORCPT ); Thu, 11 Oct 2018 22:49:39 -0400 Received: by mail-pl1-f195.google.com with SMTP id f8-v6so4699442plb.2 for ; Thu, 11 Oct 2018 12:21:04 -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=AVQzxnwZ+JovvMlA2HaVlcZad/iCgk5sTtnxgboqqfo=; b=SRs0iSXQOQc/m1+EgEHV4CPuQSH17V0Wzm2TeN/06g/B73FLAdr4U6YA6naTDU6H+4 Nq3z/yY2a1wWOB0YRgG/iTpTZ9IWb73AJn15RRCshdpzjDDm8xJPpTPhk5e5uUc7/h9x 3f5RlUdu0sjDOpkdWw8sQERGmGlK+QT7ld1ABFsbef1pZqrmUOl4aky+nqvsWimA6/0P wRt1IavXIJQSiPb/mzvG8OyJzsmQm2wdeXsOVdqVJhjyVCNTNpqHy6OGkruJKoL7+glv vtsju4XeAyb7N+3gGCD65wS4iAymYMlcNK4Xqp+r+MjFX6TMnYn78mcXtullzvuzElUM zIfA== 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=AVQzxnwZ+JovvMlA2HaVlcZad/iCgk5sTtnxgboqqfo=; b=CyiRoae75QL5pwhToMHSlZ7CMWUbzN2vRtn+q4jyJPeYCKOSfpuJlj+9Vn3EiEGTqo jZiJOqo/HXKQ5Jeu5BZ3x3nK369wiNH5GBImyxe1yLpxlN8nZyKLEwl6d3cmdip/isYq eeJGzw9IjKZKA9J8ZdEBJ6V0de1WZvSlG99hLoVwBJcInovy+40E+m5x7GHhEBUcSIFQ nOCcC17cLuGFKldKKdRkb92N5kroTDvhmpUtqkvXQ0O87zh+ho4FLM8uVAcPCh4uAEqL pmpQeCzq8JVe/yOYZRE0Uh+2KItPfYnqOnGiu0LnV0Nfbr/aWxmiPT7V7MZfelanNlTM Q47g== X-Gm-Message-State: ABuFfohcvpgbBDNuW0fFFzfRPRNmgraQtG7f3u4JouGjmgLh/Zmgb2Tz e1QvFfTxnYx+0WB9cvrZ3AqenKyGhSw= X-Google-Smtp-Source: ACcGV60JSj2rLnauMFry7ISTAML2z0YAP7Yp3W6IqoVqwvJsOTA4xX83HkSX3m0b18DbL/aIxhK/9Q== X-Received: by 2002:a17:902:ba95:: with SMTP id k21-v6mr2796194pls.38.1539285663880; Thu, 11 Oct 2018 12:21:03 -0700 (PDT) Received: from vader.thefacebook.com ([2620:10d:c090:200::5:2383]) by smtp.gmail.com with ESMTPSA id y24-v6sm44378838pfi.24.2018.10.11.12.21.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 12:21:02 -0700 (PDT) From: Omar Sandoval To: linux-block@vger.kernel.org Cc: Jens Axboe , kernel-team@fb.com, Laurent Vivier Subject: [PATCH v2 07/11] amiflop: convert to blk-mq Date: Thu, 11 Oct 2018 12:20:47 -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 | 125 +++++++++++++++------------------------- 1 file changed, 46 insertions(+), 79 deletions(-) diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c index eef3b085e70a..1225b802f632 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) -{ - 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) +static blk_status_t amiflop_rw_cur_segment(struct amiga_floppy_struct *floppy, + struct request *rq) { - 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,40 @@ 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); + } 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 +1769,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 +1806,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: