From patchwork Thu Jul 7 16:32:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Yan X-Patchwork-Id: 9219165 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 2006A60467 for ; Thu, 7 Jul 2016 16:33:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F0FC28327 for ; Thu, 7 Jul 2016 16:33:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01B9B2833A; Thu, 7 Jul 2016 16:33:07 +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 91F0E28327 for ; Thu, 7 Jul 2016 16:33:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752971AbcGGQdG (ORCPT ); Thu, 7 Jul 2016 12:33:06 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36657 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752799AbcGGQdE (ORCPT ); Thu, 7 Jul 2016 12:33:04 -0400 Received: by mail-pf0-f194.google.com with SMTP id i123so2198318pfg.3; Thu, 07 Jul 2016 09:33:04 -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=2a4Kgt7ANd5xLbXumN/t2rmR0t/7GN+HIviXC1mJldE=; b=orV8r0xn9wQG/Thh3XvudP0E+nsrtwV68MMoX8sdQSMe/oVNrq5FdvCWrbvh//f+Cs 0o32H2WWy3AuSewu3Q0rZ0D8ca/sfDVZBnG8aVbxvWY/FP4NO8Z9SOLGwebDJmqPfGNZ SY3EGuJco08fL9NHF/fpEYh/9Beo45j2MMyttisgDP6u+oXTH9MojXtpvExt3e71d7jy KfFMtxApEme6ee4H6mOGFzvQdr/a4yxhbx/iHhNWz3nHisTCQpxrad9bse4TkIxoov7J /A0Cn7ByhyrQwDCJabw2rdFOpmc+OSc0qegC5ocG50nOSinBakGmWUrQ0k4q/9JSSJOz +K/w== 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=2a4Kgt7ANd5xLbXumN/t2rmR0t/7GN+HIviXC1mJldE=; b=eMLd3P3ned4FYfDaXJOZhR+/fWzq4gnkRC6hR1CSNqUfKSU+o1PDjQ/CPSAosEji5b 6xRRsHp9DCrX//RJyqK1ohF8Dfy4FlrKR3OGYiTQDHaRKS9OnEZv4y75TUIRm6jo7xJw wjo38IE3QeaoO/nyetsuLTHQ8NisKboqRNKAiM4OspYeh5BJ6Rrvv8UB2tvVcurrFd2b e3AYBPmITNIudq9sIaHvBpEMHSQMsxoKzeulKIx6hqHbJ7G6bAoduE8PiZw4HaGECi1Q 551GTsUe6TifTtFKshl1I0FNIW6wff3a8JOncr0FYfIMQ1K7XjVysDDDv7dHV22W+774 X/Ig== X-Gm-Message-State: ALyK8tJp8w1Q1n0JedRORsH22a9tPdMJmW+Qcf8LyVg7A9edydkU+YVgOCvrFGMql+O2hA== X-Received: by 10.98.158.206 with SMTP id f75mr1842954pfk.164.1467909183031; Thu, 07 Jul 2016 09:33:03 -0700 (PDT) Received: from localhost.localdomain ([2404:c805:e00:4700:ae22:bff:fe29:e60c]) by smtp.gmail.com with ESMTPSA id x10sm5465341pfd.8.2016.07.07.09.33.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jul 2016 09:33:02 -0700 (PDT) Message-ID: <577e843e.0a86620a.59167.ffffb899@mx.google.com> X-Google-Original-Message-ID: <20160707163254.990-1-me> From: tom.ty89@gmail.com X-Google-Original-From: me To: tj@kernel.org, martin.petersen@oracle.com, dgilbert@interlog.com Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, Tom Yan Subject: [RFC] libata-scsi: introducing SANITIZE translation Date: Fri, 8 Jul 2016 00:32:54 +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 With this patch, users can make use of the SANITIZE DEVICE feature set through utility like sg_sanitize. Support for BLOCK ERASE, CRYPTOGRAPHIC ERASE and EXIT FAILURE MODE has been implemented. Support for OVERWRITE that involves a parameter list has been left out for now. Further support for command with IMMED bit set to zero, REQUEST SENSE translation for user-space status polling, and support checking in IDENTIFY DEVICE data log (return proper sense data when designated method is not supported) should be implemented in the future as well. `sg_sanitize -e -B|-C|-F /dev/sdX` should work fine with this. Signed-off-by: Tom Yan diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index bfec66f..a64991b 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3346,6 +3346,63 @@ invalid_opcode: return 1; } +static unsigned int ata_scsi_sanitize_xlat(struct ata_queued_cmd *qc) { + struct ata_taskfile *tf = &qc->tf; + struct scsi_cmnd *scmd = qc->scsicmd; + struct ata_device *dev = qc->dev; + const u8 *cdb = scmd->cmnd; + u16 fp; + u8 bp = 0xff; + + /* for now we only support SANITIZE with IMMED bit set */ + if (unlikely(!(cdb[1] & 0x80))) { + fp = 1; + bp = 7; + goto invalid_fld; + } + + tf->protocol = ATA_PROT_NODATA; + tf->command = ATA_CMD_SANITIZE_DEVICE; + tf->hob_nsect |= (cdb[1] & 0x40) << 1; + tf->nsect |= (cdb[1] & 0x20) >> 1; + tf->flags |= ATA_TFLAG_LBA48 | ATA_TFLAG_ISADDR; + + switch (cdb[1] & 0x1f) { + /* TODO: add support for OVERWRITE */ + case 0x2: /* BLOCK ERASE */ + tf->hob_feature = 0x0; + tf->feature = 0x12; + tf->hob_lbal = 0x42; + tf->lbah = 0x6b; + tf->lbam = 0x45; + tf->lbal = 0x72; + break; + case 0x3: /* CRYPTOGRAPHIC ERASE */ + tf->hob_feature = 0x0; + tf->feature = 0x11; + tf->hob_lbal = 0x43; + tf->lbah = 0x72; + tf->lbam = 0x79; + tf->lbal = 0x70; + break; + case 0x1f: /* EXIT FAILURE MODE */ + tf->hob_feature = 0x0; + tf->feature = 0x0; + tf->nsect |= 0x1; + break; + default: + fp = 1; + bp = 4; + goto invalid_fld; + } + + return 0; + +invalid_fld: + ata_scsi_set_invalid_field(dev, scmd, fp, bp); + return 1; +} + /** * ata_scsi_report_zones_complete - convert ATA output * @qc: command structure returning the data @@ -3869,6 +3926,9 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) case WRITE_SAME_16: return ata_scsi_write_same_xlat; + case SANITIZE: + return ata_scsi_sanitize_xlat; + case SYNCHRONIZE_CACHE: if (ata_try_flush_cache(dev)) return ata_scsi_flush_xlat; diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index d1defd1..20d6085 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -72,6 +72,7 @@ #define UNMAP 0x42 #define READ_TOC 0x43 #define READ_HEADER 0x44 +#define SANITIZE 0x48 #define GET_EVENT_STATUS_NOTIFICATION 0x4a #define LOG_SELECT 0x4c #define LOG_SENSE 0x4d