From patchwork Fri Jun 23 18:41:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minwoo Im X-Patchwork-Id: 9807231 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 B746E6086C for ; Fri, 23 Jun 2017 18:41:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA4E8205D6 for ; Fri, 23 Jun 2017 18:41:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EC20285CA; Fri, 23 Jun 2017 18:41:28 +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.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 E818528505 for ; Fri, 23 Jun 2017 18:41:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754654AbdFWSlZ (ORCPT ); Fri, 23 Jun 2017 14:41:25 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36814 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754327AbdFWSlY (ORCPT ); Fri, 23 Jun 2017 14:41:24 -0400 Received: by mail-pf0-f194.google.com with SMTP id y7so8559460pfd.3; Fri, 23 Jun 2017 11:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=XrlaLrOoU4SiS+5vCH0nxVmej4SETx6og1pt4iz+8vA=; b=vUYppO717xYIMfBUHD6IfiZ5smd6kNZQgU3NvvzrFEs5v82sq+PMXgDdLjuxbSh9CT 1USDakiL563mPkuz4nFxWcGShd4Hp9u2p7q5HtCkklfEP4IhSGlsr09GqrsUFBlK0Sw9 9klFgFw2Wx9+ffPf6AAuQZnaS5pXPmIAS0ClAhRXFSjQkevrrRKgtw10FTiLgwwzfc8x YpRvqdontpdMCFOTs/sAowI6MI9TX5FXyRm6gaMOUXsGOfGVNlcht3p6EjHnWz6+3tj0 gGXRWqWGtPB7/riSVPRcUL79PHmqjoyvbiZcVEEf+03KIc1BSPhuvGAtRMIp+TaBDxV/ 5h6A== 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; bh=XrlaLrOoU4SiS+5vCH0nxVmej4SETx6og1pt4iz+8vA=; b=QzYwGffNesNZtZhei1/1O0JRDh+1eWzXM3cD5EIEldNcvC1wH1+jg/4dQhyCQEHefo P/SWda+Jbg3rEOyMKyh4bibBTTWrhDzPwH26nhZwczBa+Mo0EXmKLzIn1ztT+f7W6y5W rr1JWSAh9baXZNI7t7vWi5T7uxTQ32ly2KLovrqpYZwhu6bjTOgz0JX2zRtIPkKMMhiF Tt4hds/Zs01MxmlWO8ddFog/yXrZ+uqaq8LUbefXxaD6hTipqGAyqlGPumsGCsqHJKKB s62WzPWYMaUsoEoDvi1wLZx2LTDtwwt79yl6QRs6a6t4TmuYHS4owuXkOcUiINRYK60B 7+Ig== X-Gm-Message-State: AKS2vOw5lMWz+i2LlZn0aa70jSuW9QC7y1XCpL2tEAaB9D4lqV5E8BET 0me0a9fDyfuX8A== X-Received: by 10.101.75.133 with SMTP id t5mr9349344pgq.191.1498243278303; Fri, 23 Jun 2017 11:41:18 -0700 (PDT) Received: from Lim-localhost.skbroadband ([211.49.14.228]) by smtp.gmail.com with ESMTPSA id u9sm12161900pfk.131.2017.06.23.11.41.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Jun 2017 11:41:17 -0700 (PDT) From: Minwoo Im To: Tejun Heo , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org, Minwoo Im Subject: [PATCH] libata: Support for an ATA PASS-THROUGH(32) command. Date: Sat, 24 Jun 2017 03:41:10 +0900 Message-Id: <1498243270-21730-1-git-send-email-dn3108@gmail.com> X-Mailer: git-send-email 1.7.9.5 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 SAT-4(SCSI/ATA Translation) supports for an ata pass-thru(32). This patch will allow to translate an ata pass-thru(32) SCSI cmd to an ATA cmd. Signed-off-by: Minwoo Im Reviewed-by: Bart Van Assche --- drivers/ata/libata-core.c | 2 +- drivers/ata/libata-scsi.c | 72 +++++++++++++++++++++++++++++++++++++++++---- include/scsi/scsi_proto.h | 1 + 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 2d83b8c..4777e76 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -2587,7 +2587,7 @@ int ata_dev_configure(struct ata_device *dev) } ata_dev_config_sense_reporting(dev); ata_dev_config_zac(dev); - dev->cdb_len = 16; + dev->cdb_len = 32; } /* ATAPI-specific feature tests */ diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 49ba983..dc59860 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -3127,7 +3127,7 @@ static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap, * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile * @qc: command structure to be initialized * - * Handles either 12 or 16-byte versions of the CDB. + * Handles either 12, 16, or 32-byte versions of the CDB. * * RETURNS: * Zero on success, non-zero on failure. @@ -3139,13 +3139,19 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) struct ata_device *dev = qc->dev; const u8 *cdb = scmd->cmnd; u16 fp; + u16 cdb_offset = 0; - if ((tf->protocol = ata_scsi_map_proto(cdb[1])) == ATA_PROT_UNKNOWN) { + /* 7Fh variable length cmd means a ata pass-thru(32) */ + if (cdb[0] == VARIABLE_LENGTH_CMD) + cdb_offset = 9; + + tf->protocol = ata_scsi_map_proto(cdb[1 + cdb_offset]); + if (tf->protocol == ATA_PROT_UNKNOWN) { fp = 1; goto invalid_fld; } - if (ata_is_ncq(tf->protocol) && (cdb[2] & 0x3) == 0) + if (ata_is_ncq(tf->protocol) && (cdb[2 + cdb_offset] & 0x3) == 0) tf->protocol = ATA_PROT_NCQ_NODATA; /* enable LBA */ @@ -3181,7 +3187,7 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) tf->lbah = cdb[12]; tf->device = cdb[13]; tf->command = cdb[14]; - } else { + } else if (cdb[0] == ATA_12) { /* * 12-byte CDB - incapable of extended commands. */ @@ -3194,6 +3200,30 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) tf->lbah = cdb[7]; tf->device = cdb[8]; tf->command = cdb[9]; + } else { + /* + * 32-byte CDB - may contain extended command fields. + * + * If that is the case, copy the upper byte register values. + */ + if (cdb[10] & 0x01) { + tf->hob_feature = cdb[20]; + tf->hob_nsect = cdb[22]; + tf->hob_lbal = cdb[16]; + tf->hob_lbam = cdb[15]; + tf->hob_lbah = cdb[14]; + tf->flags |= ATA_TFLAG_LBA48; + } else + tf->flags &= ~ATA_TFLAG_LBA48; + + tf->feature = cdb[21]; + tf->nsect = cdb[23]; + tf->lbal = cdb[19]; + tf->lbam = cdb[18]; + tf->lbah = cdb[17]; + tf->device = cdb[24]; + tf->command = cdb[25]; + tf->auxiliary = get_unaligned_be32(&cdb[28]); } /* For NCQ commands copy the tag value */ @@ -4068,6 +4098,35 @@ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) } /** + * ata_scsi_var_len_cdb_xlat - SATL variable length CDB to Handler + * @qc: Command to be translated + * + * Translate a SCSI variable length CDB to specified commands. + * It checks a service action value in CDB to call corresponding handler. + * + * RETURNS: + * Zero on success, non-zero on failure + * + */ +static unsigned int ata_scsi_var_len_cdb_xlat(struct ata_queued_cmd *qc) +{ + struct scsi_cmnd *scmd = qc->scsicmd; + const u8 *cdb = scmd->cmnd; + const u16 sa = get_unaligned_be16(&cdb[8]); + + /* + * if service action represents a ata pass-thru(32) command, + * then pass it to ata_scsi_pass_thru handler. + */ + if (sa == ATA_32) + return ata_scsi_pass_thru(qc); + +unspprt_sa: + /* unsupported service action */ + return 1; +} + +/** * ata_get_xlat_func - check if SCSI to ATA translation is possible * @dev: ATA device * @cmd: SCSI command opcode to consider @@ -4107,6 +4166,9 @@ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) case ATA_16: return ata_scsi_pass_thru; + case VARIABLE_LENGTH_CMD: + return ata_scsi_var_len_cdb_xlat; + case MODE_SELECT: case MODE_SELECT_10: return ata_scsi_mode_select_xlat; @@ -4385,7 +4447,7 @@ int ata_scsi_add_hosts(struct ata_host *host, struct scsi_host_template *sht) shost->max_id = 16; shost->max_lun = 1; shost->max_channel = 1; - shost->max_cmd_len = 16; + shost->max_cmd_len = 32; /* Schedule policy is determined by ->qc_defer() * callback and it needs to see every deferred qc. diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index ce78ec8..06076b8 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -162,6 +162,7 @@ #define VERIFY_32 0x0a #define WRITE_32 0x0b #define WRITE_SAME_32 0x0d +#define ATA_32 0x1ff0 /* Values for T10/04-262r7 */ #define ATA_16 0x85 /* 16-byte pass-thru */