From patchwork Mon Jul 4 20:53:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9213101 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2C0C060572 for ; Mon, 4 Jul 2016 20:53:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BA3623B3D for ; Mon, 4 Jul 2016 20:53:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F2232879D; Mon, 4 Jul 2016 20:53: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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 9782E23B3D for ; Mon, 4 Jul 2016 20:53:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753886AbcGDUxq (ORCPT ); Mon, 4 Jul 2016 16:53:46 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:34024 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753851AbcGDUxp (ORCPT ); Mon, 4 Jul 2016 16:53:45 -0400 Received: by mail-pf0-f195.google.com with SMTP id 66so17136051pfy.1; Mon, 04 Jul 2016 13:53:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:cc:subject:date; bh=74miNlK7ncEyqx9xSgzBehvWm6c1CMVivujMIDbM9h4=; b=mw8wINaslV4LLsdfrXh4BXzq+1GIcN0yxQDay0LFXBkn+3nRFhZL/QO9fyAck7SaR1 3vW5kVCqv8ZOD6loGLaKreR/C7YjVNPBAL4yjykXApmOFEDoqcDDhlXNnWyuiSE40Qr+ pt4U7CQoUQGC216X6lPXOX9iwq9Hg+7TQ6Ll6GBwvu90dQxEyVGD+dugVli+KXPF2eIv +zf+cfz0On1OLJjfTAp2xbtMCgSZTuOtNrXxrtNNjtKmkb3aUQtMuCq8X+8UvlWRmFPI TBQnBouyXWV0gMAj3FdxJaHN66YHQFjtgAMXtKQBFKfJ/95pouNlhGIbJHrxcuAbPgI7 7tnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:from:to:cc:subject:date; bh=74miNlK7ncEyqx9xSgzBehvWm6c1CMVivujMIDbM9h4=; b=PB2tUgL2F1B/bTjRacZcPEpyvNS0PLJeIHiZPyCfzxZJ79NqL+iRuqCdkY5CtoBoBd A1jR1CCFgLePsbwDYFdxWIKzq7T+hVYgcTJRdS6SDOJJ4z4mYHS2i6I6kKiW/4RLpZhF TQlWtNg/ceS63pDDQFDGNi4w6RpygHtKtrmFGB6mr/kbQdMfm+lzBvYFa+Ta++KRHtsb iHoMp7rXChKSAosDZshLA9DcSlgrFkrySXQYQmRTJEvF6rm7rveYYo2QeDqIIGsvfAp3 gHh3qfzQw8fXxC//s7nTeeOv3uLwfSunFFEkifMLKd6lpf3DSrDfh/IOSQ7nESM99xpK eBuA== X-Gm-Message-State: ALyK8tIM5pdXwS2eGH8GxLyDStIp1it72FNuEqVDXbLxlz4gZGaijkXjUucvrryZPd+bkQ== X-Received: by 10.98.56.86 with SMTP id f83mr25727683pfa.83.1467665624141; Mon, 04 Jul 2016 13:53:44 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id x67sm7023413pff.47.2016.07.04.13.53.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jul 2016 13:53:43 -0700 (PDT) Message-ID: <577accd7.46c0620a.65070.ffffec83@mx.google.com> X-Google-Original-Message-ID: <20160704205335.5484-1-me> From: tom.ty89@gmail.com X-Google-Original-From: me To: tj@kernel.org, martin.petersen@oracle.com Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, Tom Yan Subject: [PATCH 1/2] libata-scsi: improve TRIM translation Date: Tue, 5 Jul 2016 04:53:34 +0800 X-Mailer: git-send-email 2.9.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tom Yan Define TRIM_RANGE_SIZE and TRIM_RANGE_NUM so that the corresponding functions can be more generalized. Also, conform SBC by rejecting WRITE SAME (16) commands with number of blocks that exceeds the limit that is defined in the SATL. Signed-off-by: Tom Yan diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index bfec66f..80d732c 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -75,6 +75,9 @@ static struct ata_device *ata_scsi_find_dev(struct ata_port *ap, #define ALL_MPAGES 0x3f #define ALL_SUB_MPAGES 0xff +#define TRIM_RANGE_SIZE 0xffff +#define TRIM_RANGE_NUM 64 /* 512-byte payload / (6-byte LBA + 2-byte range per entry) */ + static const u8 def_rw_recovery_mpage[RW_RECOVERY_MPAGE_LEN] = { RW_RECOVERY_MPAGE, @@ -2314,7 +2317,7 @@ static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf) * with the unmap bit set. */ if (ata_id_has_trim(args->id)) { - put_unaligned_be64(65535 * 512 / 8, &rbuf[36]); + put_unaligned_be64(TRIM_RANGE_SIZE * TRIM_RANGE_NUM, &rbuf[36]); put_unaligned_be32(1, &rbuf[28]); } @@ -3305,7 +3308,10 @@ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) goto invalid_param_len; buf = page_address(sg_page(scsi_sglist(scmd))); - size = ata_set_lba_range_entries(buf, 512, block, n_block); + if (n_block <= TRIM_RANGE_SIZE * TRIM_RANGE_NUM) + size = ata_set_lba_range_entries(buf, TRIM_RANGE_NUM, block, n_block); + else + goto invalid_fld; if (ata_ncq_enabled(dev) && ata_fpdma_dsm_supported(dev)) { /* Newer devices support queued TRIM commands */ diff --git a/include/linux/ata.h b/include/linux/ata.h index 99346be..0971c3f 100644 --- a/include/linux/ata.h +++ b/include/linux/ata.h @@ -1071,7 +1071,7 @@ static inline unsigned ata_set_lba_range_entries(void *_buffer, __le64 *buffer = _buffer; unsigned i = 0, used_bytes; - while (i < buf_size / 8 ) { /* 6-byte LBA + 2-byte range per entry */ + while (i < buf_size) { u64 entry = sector | ((u64)(count > 0xffff ? 0xffff : count) << 48); buffer[i++] = __cpu_to_le64(entry);