From patchwork Mon Oct 29 15:24:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 195045 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 903942C008A for ; Tue, 30 Oct 2012 02:30:44 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DE6794A02C; Mon, 29 Oct 2012 16:28:00 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zg+CGZfV43Ly; Mon, 29 Oct 2012 16:28:00 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C229E4A0AA; Mon, 29 Oct 2012 16:25:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C41DB4A041 for ; Mon, 29 Oct 2012 16:25:02 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C+dnBCQxzBMc for ; Mon, 29 Oct 2012 16:24:59 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-gg0-f202.google.com (mail-gg0-f202.google.com [209.85.161.202]) by theia.denx.de (Postfix) with ESMTPS id B49714A04E for ; Mon, 29 Oct 2012 16:24:23 +0100 (CET) Received: by mail-gg0-f202.google.com with SMTP id i4so646494ggm.3 for ; Mon, 29 Oct 2012 08:24:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=T0FEcfba7z52um3fl4ZlRc83m2BPUzbqS0XGwI8Ao/c=; b=WHKBdaFrungkaMoYX/iT1wKim6dKEe0p01hunP39wYXCXXyDd51hMbKca/reVh3vsr fL9qIdrEoZ8vzwJH2Zkx6iiVZ8Lu0TvkS+uXpV5xZ/u+nZMv97/pdXJHHs8nU7O0TMnB LiomBk6fpnBlAhvktsZXWN9HY/8bSOXWXsFBUPRah/6WTogdXnDXVDy/prfcA2oZsPKg egYTP5zXL+IBZyEa/gfSluY0/ZFoi3YnUzSxHL7dVOlzsdipz35yV6WTKEHeQVPor5XS M1XGI/FJLHrifn5l9YgKMGmu4av5ZkErgb7G+0N+5VOYT6MMlzJOgKv/mnHV/J4Aolbx ul0g== Received: by 10.236.193.73 with SMTP id j49mr22083796yhn.7.1351524261415; Mon, 29 Oct 2012 08:24:21 -0700 (PDT) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id m9si713183yhc.5.2012.10.29.08.24.21 (version=TLSv1/SSLv3 cipher=AES128-SHA); Mon, 29 Oct 2012 08:24:21 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id 2E89F1E0048; Mon, 29 Oct 2012 08:24:21 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 0E487160C5F; Mon, 29 Oct 2012 08:24:21 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 29 Oct 2012 08:24:02 -0700 Message-Id: <1351524245-19584-20-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1351524245-19584-1-git-send-email-sjg@chromium.org> References: <1351524245-19584-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQlRhSosiDJLOyoyK7ablSEForjJ6R4OflDbX6pf5jB2edNZxNvFJFVha6M+NQRi1h9PCaPVWbg6hdtE3ihrAlZ4qSOlB35QZf6jD9mM/9P4TK9Gws9QV6+8hNAGpiY/K46y/2/iwOGSQhtKYtM4YfDuh9uco3h0lZLqu0hByRoUv4TuCSndy6YlsJgWm0vhmaU/dSIi Cc: Tom Rini , Rob Herring , Marc Jones Subject: [U-Boot] [PATCH v3 19/22] ahci: Perform SATA flush after disk write. X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Marc Jones Writes in u-boot are so rare, and the logic to know when is the last write and do a flush only there is sufficiently difficult. Just do a flush after every write. This incurs, usually, one extra flush when the rare writes do happen. Signed-off-by: Marc Jones Signed-off-by: Simon Glass --- drivers/block/ahci.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++- include/ata.h | 3 ++ 2 files changed, 54 insertions(+), 1 deletions(-) diff --git a/drivers/block/ahci.c b/drivers/block/ahci.c index 19c5f13..963efec 100644 --- a/drivers/block/ahci.c +++ b/drivers/block/ahci.c @@ -37,6 +37,8 @@ #include #include +static int ata_io_flush(u8 port); + struct ahci_probe_ent *probe_ent = NULL; hd_driveid_t *ataid[AHCI_MAX_PORTS]; @@ -55,6 +57,7 @@ hd_driveid_t *ataid[AHCI_MAX_PORTS]; /* Maximum timeouts for each event */ #define WAIT_MS_SPINUP 10000 #define WAIT_MS_DATAIO 5000 +#define WAIT_MS_FLUSH 5000 #define WAIT_MS_LINKUP 4 static inline u32 ahci_port_base(u32 base, u32 port) @@ -267,7 +270,7 @@ static int ahci_host_init(struct ahci_probe_ent *probe_ent) /* register linkup ports */ tmp = readl(port_mmio + PORT_SCR_STAT); - debug("Port %d status: 0x%x\n", i, tmp); + debug("SATA port %d status: 0x%x\n", i, tmp); if ((tmp & 0xf) == 0x03) probe_ent->link_port_map |= (0x01 << i); } @@ -736,6 +739,17 @@ static int ata_scsiop_read_write(ccb *pccb, u8 is_write) is_write ? "WRITE" : "READ"); return -EIO; } + + /* If this transaction is a write, do a following flush. + * Writes in u-boot are so rare, and the logic to know when is + * the last write and do a flush only there is sufficiently + * difficult. Just do a flush after every write. This incurs, + * usually, one extra flush when the rare writes do happen. + */ + if (is_write) { + if (-EIO == ata_io_flush(pccb->target)) + return -EIO; + } user_buffer += transfer_size; user_buffer_size -= transfer_size; blocks -= now_blocks; @@ -929,6 +943,42 @@ err_out: } #endif +/* + * In the general case of generic rotating media it makes sense to have a + * flush capability. It probably even makes sense in the case of SSDs because + * one cannot always know for sure what kind of internal cache/flush mechanism + * is embodied therein. At first it was planned to invoke this after the last + * write to disk and before rebooting. In practice, knowing, a priori, which + * is the last write is difficult. Because writing to the disk in u-boot is + * very rare, this flush command will be invoked after every block write. + */ +static int ata_io_flush(u8 port) +{ + u8 fis[20]; + struct ahci_ioports *pp = &(probe_ent->port[port]); + volatile u8 *port_mmio = (volatile u8 *)pp->port_mmio; + u32 cmd_fis_len = 5; /* five dwords */ + + /* Preset the FIS */ + memset(fis, 0, 20); + fis[0] = 0x27; /* Host to device FIS. */ + fis[1] = 1 << 7; /* Command FIS. */ + fis[2] = ATA_CMD_FLUSH; + + memcpy((unsigned char *)pp->cmd_tbl, fis, 20); + ahci_fill_cmd_slot(pp, cmd_fis_len); + writel_with_flush(1, port_mmio + PORT_CMD_ISSUE); + + if (waiting_for_cmd_completed(port_mmio + PORT_CMD_ISSUE, + WAIT_MS_FLUSH, 0x1)) { + debug("scsi_ahci: flush command timeout on port %d.\n", port); + return -EIO; + } + + return 0; +} + + void scsi_bus_reset(void) { /*Not implement*/ diff --git a/include/ata.h b/include/ata.h index 3b2d737..a614724 100644 --- a/include/ata.h +++ b/include/ata.h @@ -114,6 +114,9 @@ #define ATA_CMD_WRITE_EXT 0x34 /* Write Sectores (with retries) with 48bit addressing */ #define ATA_CMD_VRFY_EXT 0x42 /* Read Verify (with retries) with 48bit addressing */ +#define ATA_CMD_FLUSH 0xE7 /* Flush drive cache */ +#define ATA_CMD_FLUSH_EXT 0xEA /* Flush drive cache, with 48bit addressing */ + /* * ATAPI Commands */