From patchwork Tue Jul 5 06:45:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9213703 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 55D9F6048B for ; Tue, 5 Jul 2016 06:46:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4443D288F3 for ; Tue, 5 Jul 2016 06:46:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34E98288F2; Tue, 5 Jul 2016 06:46:13 +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 CD633288F2 for ; Tue, 5 Jul 2016 06:46:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932680AbcGEGqM (ORCPT ); Tue, 5 Jul 2016 02:46:12 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:33857 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932421AbcGEGqJ (ORCPT ); Tue, 5 Jul 2016 02:46:09 -0400 Received: by mail-pa0-f67.google.com with SMTP id us13so17591194pab.1; Mon, 04 Jul 2016 23:46:09 -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=h3MbCJ52qPm2wpw84Ddf40ob2b/y29n1CqlQFG2AmZM=; b=A2QELO+Ipv/pRVvoy59skuJwR57i6nTdv2YaTLv6TSnppjDfaDDtd/OaXpfG+1cztr aYY4ul60OeiGNv0dfPIFdz7qDIdmU8Fg2Fkb4hsABa3YckieyH8uRoVvUdiKJ1UwbeTw hNXiZBzlQw/dErEkR140wFuoO2Hb4Hb9GaARQuJ4OHm/iFD9t3NMZKtk+sMdFXttyb/o tnzxJZ54AQRhDwQ2gLFHJG2f6q/ro7n+CjkEZLkxoTVQfv/uru+EQ18qB4VqEkOh0TXZ HZWZSkhVNreez6deMlm6dt1f1s6lqj7wp5TZBlby2j5cJOdH9icOpYNfQnUvESkGz315 n2oQ== 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=h3MbCJ52qPm2wpw84Ddf40ob2b/y29n1CqlQFG2AmZM=; b=ihfBedF6+ejAd8Y45W/oelie1ujgC9JFFYdnSeTNK4+dMfxmQRD80F3gw9zE0Q+Pa8 puPBfuXRfciHYlvJrySoN0CORPM902QrsyUsS/fHbMil6+wMaoFpvfaHFdZ1284ieogF QdhMZxgDIO7M6DljwX+LPPO+MMfLZ2M7JoYwOOhEWHq2pA//nogfLwTqKVbDKD+zLxMj +x9Kwx/G4EQbX/Ddvht7nV78cYQvzAa5fkuP78bZwfY/MaXiwO2czBtZieHOtt9dkkbq h0KgpL5Lck4pEQ5Zaip9bueBe+M8vQEavZNA456rAdRtid9UHw15hawO5DSLhV5qvoKb YHxQ== X-Gm-Message-State: ALyK8tJArzWFi+O1/kQxaBJB7cc+0KJqVUFXsxaxBSVFaWTcGT3MPqQvhlPPbYXvaOMw4A== X-Received: by 10.66.139.133 with SMTP id qy5mr29183816pab.4.1467701168600; Mon, 04 Jul 2016 23:46:08 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id z88sm2191171pfa.59.2016.07.04.23.46.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jul 2016 23:46:08 -0700 (PDT) Message-ID: <577b57b0.5b4c620a.37648.6c8d@mx.google.com> X-Google-Original-Message-ID: <20160705064556.909-1-me> From: tom.ty89@gmail.com X-Google-Original-From: me To: tj@kernel.org, martin.petersen@oracle.com, sergei.shtylyov@cogentembedded.com Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, Tom Yan Subject: [PATCH v2 1/2] libata-scsi: improve TRIM translation Date: Tue, 5 Jul 2016 14:45:55 +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 to 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..029e738 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);