From patchwork Fri Apr 12 19:34:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Carino X-Patchwork-Id: 236183 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2E7732C00AC for ; Sat, 13 Apr 2013 05:34:27 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752943Ab3DLTeZ (ORCPT ); Fri, 12 Apr 2013 15:34:25 -0400 Received: from mail-vc0-f177.google.com ([209.85.220.177]:54683 "EHLO mail-vc0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752680Ab3DLTeZ (ORCPT ); Fri, 12 Apr 2013 15:34:25 -0400 Received: by mail-vc0-f177.google.com with SMTP id hr11so2474856vcb.22 for ; Fri, 12 Apr 2013 12:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to:cc :content-type; bh=Qx119/XUZ9CzbfgQR2AxyAOycYBoCVzigwvQWFGjhzM=; b=NGh5umgb1XZ3LRp1oQuCHOMrbykfXutj8EPA7d+kAs8cS5vQwJfbumCEylpLNO32DY IxSlMzSTqXFVFUEDm0EH+G+ItjqHurCbRXdleJaxj8GM+OtU4zPCgwBVFTPUDpGLi7lX W26BQPiBtZrKNtdiFY8Z8LD+kYZET2KsqeLli1PPAwLd3dRlaWLuYlfFL6rzUkepMaer /HIr1ReGSOYqLiGpHNctA0zp3y+H+cH+GQobt7RPg77RZR+wrhFbCJUK1ONVbyDlwAer JEtkOR1oGyWElcsGpJBeRM3V57qFmPTNUJE9ii/gFlSju9Y+JFa/pOGmJmSbCczf52nN 9h8w== MIME-Version: 1.0 X-Received: by 10.52.70.5 with SMTP id i5mr8148429vdu.104.1365795264586; Fri, 12 Apr 2013 12:34:24 -0700 (PDT) Received: by 10.58.107.73 with HTTP; Fri, 12 Apr 2013 12:34:24 -0700 (PDT) Date: Fri, 12 Apr 2013 12:34:24 -0700 Message-ID: Subject: [RFC PATCH] AHCI: Workaround for ATAPI on buggy AHCI controller From: Marc C To: jeff@garzik.org Cc: linux-ide@vger.kernel.org Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org Hello Jeff, I'm working with a proprietary but AHCI-compatible SATA controller that uses the libata driver. Early versions of this controller have issues with processing non-data ATAPI commands. A workaround was identified which requires some register pokes in the command completion path of the driver. I don't expect to push this patch upstream (yet). However, I would like to get some feedback regarding the workaround, and check if the placement of the code is "acceptable" or if there would be a better place to put it. The workaround itself is rather simple: toggle the START bit immediately after a non-data ATAPI command completes. The ST bit toggle would be performed within atomic context in the AHCI port interrupt ISR. Signed-off-by: Marc C --- linux/drivers/ata/libahci.c | 26 ++++++++++++++++++++++++++ linux/drivers/ata/libata-core.c | 6 ++++++ 2 files changed, 32 insertions(+) -- Regards, Marc marc.ceeeee@gmail.com -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/linux/drivers/ata/libahci.c b/linux/drivers/ata/libahci.c index f9eaa82..20b3a9a 100644 --- a/linux/drivers/ata/libahci.c +++ b/linux/drivers/ata/libahci.c @@ -2215,6 +2215,32 @@ void ahci_set_em_messages(struct ahci_host_priv *hpriv, } EXPORT_SYMBOL_GPL(ahci_set_em_messages); +void ahci_apply_atapi_workaround(struct ata_queued_cmd *qc) +{ + if (!(qc->flags & ATA_QCFLAG_DMAMAP)) { + /* + * Non-data ATAPI commands need to kick the DMA engine + */ + struct ata_port *ap = qc->ap; + void __iomem *port_mmio = ahci_port_base(ap); + u32 tmp = readl(port_mmio + PORT_CMD); + + /* check if the HBA is idle */ + if ((tmp & (PORT_CMD_START | PORT_CMD_LIST_ON)) != 0) { + /* setting HBA to idle */ + tmp &= ~PORT_CMD_START; + writel(tmp, port_mmio + PORT_CMD); + + /* wait for engine to stop */ + do { + tmp = readl(port_mmio + PORT_CMD); + } while (tmp & PORT_CMD_LIST_ON); + } + ahci_start_engine(ap); + } +} +EXPORT_SYMBOL_GPL(ahci_apply_atapi_workaround); + MODULE_AUTHOR("Jeff Garzik"); MODULE_DESCRIPTION("Common AHCI SATA low-level routines"); MODULE_LICENSE("GPL"); diff --git a/linux/drivers/ata/libata-core.c b/linux/drivers/ata/libata-core.c index 4e73e1b..383de21 100644 --- a/linux/drivers/ata/libata-core.c +++ b/linux/drivers/ata/libata-core.c @@ -4827,6 +4827,12 @@ void ata_qc_complete(struct ata_queued_cmd *qc) { struct ata_port *ap = qc->ap; + if (ata_is_atapi(qc->tf.protocol)) { + void ahci_apply_atapi_workaround(struct ata_queued_cmd *qc); + ahci_apply_atapi_workaround(qc); + } + /* XXX: New EH and old EH use different mechanisms to * synchronize EH with regular execution path. * -- 1.7.9.5