1c6fd2807SJeff Garzik /* 2c6fd2807SJeff Garzik * sata_mv.c - Marvell SATA support 3c6fd2807SJeff Garzik * 4c6fd2807SJeff Garzik * Copyright 2005: EMC Corporation, all rights reserved. 5c6fd2807SJeff Garzik * Copyright 2005 Red Hat, Inc. All rights reserved. 6c6fd2807SJeff Garzik * 7c6fd2807SJeff Garzik * Please ALWAYS copy linux-ide@vger.kernel.org on emails. 8c6fd2807SJeff Garzik * 9c6fd2807SJeff Garzik * This program is free software; you can redistribute it and/or modify 10c6fd2807SJeff Garzik * it under the terms of the GNU General Public License as published by 11c6fd2807SJeff Garzik * the Free Software Foundation; version 2 of the License. 12c6fd2807SJeff Garzik * 13c6fd2807SJeff Garzik * This program is distributed in the hope that it will be useful, 14c6fd2807SJeff Garzik * but WITHOUT ANY WARRANTY; without even the implied warranty of 15c6fd2807SJeff Garzik * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16c6fd2807SJeff Garzik * GNU General Public License for more details. 17c6fd2807SJeff Garzik * 18c6fd2807SJeff Garzik * You should have received a copy of the GNU General Public License 19c6fd2807SJeff Garzik * along with this program; if not, write to the Free Software 20c6fd2807SJeff Garzik * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21c6fd2807SJeff Garzik * 22c6fd2807SJeff Garzik */ 23c6fd2807SJeff Garzik 244a05e209SJeff Garzik /* 254a05e209SJeff Garzik sata_mv TODO list: 264a05e209SJeff Garzik 274a05e209SJeff Garzik 1) Needs a full errata audit for all chipsets. I implemented most 284a05e209SJeff Garzik of the errata workarounds found in the Marvell vendor driver, but 294a05e209SJeff Garzik I distinctly remember a couple workarounds (one related to PCI-X) 304a05e209SJeff Garzik are still needed. 314a05e209SJeff Garzik 321fd2e1c2SMark Lord 2) Improve/fix IRQ and error handling sequences. 331fd2e1c2SMark Lord 341fd2e1c2SMark Lord 3) ATAPI support (Marvell claims the 60xx/70xx chips can do it). 351fd2e1c2SMark Lord 361fd2e1c2SMark Lord 4) Think about TCQ support here, and for libata in general 371fd2e1c2SMark Lord with controllers that suppport it via host-queuing hardware 381fd2e1c2SMark Lord (a software-only implementation could be a nightmare). 394a05e209SJeff Garzik 404a05e209SJeff Garzik 5) Investigate problems with PCI Message Signalled Interrupts (MSI). 414a05e209SJeff Garzik 424a05e209SJeff Garzik 6) Add port multiplier support (intermediate) 434a05e209SJeff Garzik 444a05e209SJeff Garzik 8) Develop a low-power-consumption strategy, and implement it. 454a05e209SJeff Garzik 464a05e209SJeff Garzik 9) [Experiment, low priority] See if ATAPI can be supported using 474a05e209SJeff Garzik "unknown FIS" or "vendor-specific FIS" support, or something creative 484a05e209SJeff Garzik like that. 494a05e209SJeff Garzik 504a05e209SJeff Garzik 10) [Experiment, low priority] Investigate interrupt coalescing. 514a05e209SJeff Garzik Quite often, especially with PCI Message Signalled Interrupts (MSI), 524a05e209SJeff Garzik the overhead reduced by interrupt mitigation is quite often not 534a05e209SJeff Garzik worth the latency cost. 544a05e209SJeff Garzik 554a05e209SJeff Garzik 11) [Experiment, Marvell value added] Is it possible to use target 564a05e209SJeff Garzik mode to cross-connect two Linux boxes with Marvell cards? If so, 574a05e209SJeff Garzik creating LibATA target mode support would be very interesting. 584a05e209SJeff Garzik 594a05e209SJeff Garzik Target mode, for those without docs, is the ability to directly 604a05e209SJeff Garzik connect two SATA controllers. 614a05e209SJeff Garzik 624a05e209SJeff Garzik */ 634a05e209SJeff Garzik 644a05e209SJeff Garzik 65c6fd2807SJeff Garzik #include <linux/kernel.h> 66c6fd2807SJeff Garzik #include <linux/module.h> 67c6fd2807SJeff Garzik #include <linux/pci.h> 68c6fd2807SJeff Garzik #include <linux/init.h> 69c6fd2807SJeff Garzik #include <linux/blkdev.h> 70c6fd2807SJeff Garzik #include <linux/delay.h> 71c6fd2807SJeff Garzik #include <linux/interrupt.h> 72c6fd2807SJeff Garzik #include <linux/dma-mapping.h> 73c6fd2807SJeff Garzik #include <linux/device.h> 74c6fd2807SJeff Garzik #include <scsi/scsi_host.h> 75c6fd2807SJeff Garzik #include <scsi/scsi_cmnd.h> 766c08772eSJeff Garzik #include <scsi/scsi_device.h> 77c6fd2807SJeff Garzik #include <linux/libata.h> 78c6fd2807SJeff Garzik 79c6fd2807SJeff Garzik #define DRV_NAME "sata_mv" 801fd2e1c2SMark Lord #define DRV_VERSION "1.20" 81c6fd2807SJeff Garzik 82c6fd2807SJeff Garzik enum { 83c6fd2807SJeff Garzik /* BAR's are enumerated in terms of pci_resource_start() terms */ 84c6fd2807SJeff Garzik MV_PRIMARY_BAR = 0, /* offset 0x10: memory space */ 85c6fd2807SJeff Garzik MV_IO_BAR = 2, /* offset 0x18: IO space */ 86c6fd2807SJeff Garzik MV_MISC_BAR = 3, /* offset 0x1c: FLASH, NVRAM, SRAM */ 87c6fd2807SJeff Garzik 88c6fd2807SJeff Garzik MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */ 89c6fd2807SJeff Garzik MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */ 90c6fd2807SJeff Garzik 91c6fd2807SJeff Garzik MV_PCI_REG_BASE = 0, 92c6fd2807SJeff Garzik MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */ 93c6fd2807SJeff Garzik MV_IRQ_COAL_CAUSE = (MV_IRQ_COAL_REG_BASE + 0x08), 94c6fd2807SJeff Garzik MV_IRQ_COAL_CAUSE_LO = (MV_IRQ_COAL_REG_BASE + 0x88), 95c6fd2807SJeff Garzik MV_IRQ_COAL_CAUSE_HI = (MV_IRQ_COAL_REG_BASE + 0x8c), 96c6fd2807SJeff Garzik MV_IRQ_COAL_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xcc), 97c6fd2807SJeff Garzik MV_IRQ_COAL_TIME_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xd0), 98c6fd2807SJeff Garzik 99c6fd2807SJeff Garzik MV_SATAHC0_REG_BASE = 0x20000, 100c6fd2807SJeff Garzik MV_FLASH_CTL = 0x1046c, 101c6fd2807SJeff Garzik MV_GPIO_PORT_CTL = 0x104f0, 102c6fd2807SJeff Garzik MV_RESET_CFG = 0x180d8, 103c6fd2807SJeff Garzik 104c6fd2807SJeff Garzik MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ, 105c6fd2807SJeff Garzik MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ, 106c6fd2807SJeff Garzik MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */ 107c6fd2807SJeff Garzik MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ, 108c6fd2807SJeff Garzik 109c6fd2807SJeff Garzik MV_MAX_Q_DEPTH = 32, 110c6fd2807SJeff Garzik MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1, 111c6fd2807SJeff Garzik 112c6fd2807SJeff Garzik /* CRQB needs alignment on a 1KB boundary. Size == 1KB 113c6fd2807SJeff Garzik * CRPB needs alignment on a 256B boundary. Size == 256B 114c6fd2807SJeff Garzik * ePRD (SG) entries need alignment on a 16B boundary. Size == 16B 115c6fd2807SJeff Garzik */ 116c6fd2807SJeff Garzik MV_CRQB_Q_SZ = (32 * MV_MAX_Q_DEPTH), 117c6fd2807SJeff Garzik MV_CRPB_Q_SZ = (8 * MV_MAX_Q_DEPTH), 118da2fa9baSMark Lord MV_MAX_SG_CT = 256, 119c6fd2807SJeff Garzik MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT), 120c6fd2807SJeff Garzik 121c6fd2807SJeff Garzik MV_PORTS_PER_HC = 4, 122c6fd2807SJeff Garzik /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */ 123c6fd2807SJeff Garzik MV_PORT_HC_SHIFT = 2, 124c6fd2807SJeff Garzik /* == (port % MV_PORTS_PER_HC) to determine hard port from 0-7 port */ 125c6fd2807SJeff Garzik MV_PORT_MASK = 3, 126c6fd2807SJeff Garzik 127c6fd2807SJeff Garzik /* Host Flags */ 128c6fd2807SJeff Garzik MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ 129c6fd2807SJeff Garzik MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */ 130*7bb3c529SSaeed Bishara /* SoC integrated controllers, no PCI interface */ 131*7bb3c529SSaeed Bishara MV_FLAG_SOC = (1 << 28), 132*7bb3c529SSaeed Bishara 133c5d3e45aSJeff Garzik MV_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 134bdd4dddeSJeff Garzik ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI | 135bdd4dddeSJeff Garzik ATA_FLAG_PIO_POLLING, 136c6fd2807SJeff Garzik MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE, 137c6fd2807SJeff Garzik 138c6fd2807SJeff Garzik CRQB_FLAG_READ = (1 << 0), 139c6fd2807SJeff Garzik CRQB_TAG_SHIFT = 1, 140c5d3e45aSJeff Garzik CRQB_IOID_SHIFT = 6, /* CRQB Gen-II/IIE IO Id shift */ 141c5d3e45aSJeff Garzik CRQB_HOSTQ_SHIFT = 17, /* CRQB Gen-II/IIE HostQueTag shift */ 142c6fd2807SJeff Garzik CRQB_CMD_ADDR_SHIFT = 8, 143c6fd2807SJeff Garzik CRQB_CMD_CS = (0x2 << 11), 144c6fd2807SJeff Garzik CRQB_CMD_LAST = (1 << 15), 145c6fd2807SJeff Garzik 146c6fd2807SJeff Garzik CRPB_FLAG_STATUS_SHIFT = 8, 147c5d3e45aSJeff Garzik CRPB_IOID_SHIFT_6 = 5, /* CRPB Gen-II IO Id shift */ 148c5d3e45aSJeff Garzik CRPB_IOID_SHIFT_7 = 7, /* CRPB Gen-IIE IO Id shift */ 149c6fd2807SJeff Garzik 150c6fd2807SJeff Garzik EPRD_FLAG_END_OF_TBL = (1 << 31), 151c6fd2807SJeff Garzik 152c6fd2807SJeff Garzik /* PCI interface registers */ 153c6fd2807SJeff Garzik 154c6fd2807SJeff Garzik PCI_COMMAND_OFS = 0xc00, 155c6fd2807SJeff Garzik 156c6fd2807SJeff Garzik PCI_MAIN_CMD_STS_OFS = 0xd30, 157c6fd2807SJeff Garzik STOP_PCI_MASTER = (1 << 2), 158c6fd2807SJeff Garzik PCI_MASTER_EMPTY = (1 << 3), 159c6fd2807SJeff Garzik GLOB_SFT_RST = (1 << 4), 160c6fd2807SJeff Garzik 161c6fd2807SJeff Garzik MV_PCI_MODE = 0xd00, 162c6fd2807SJeff Garzik MV_PCI_EXP_ROM_BAR_CTL = 0xd2c, 163c6fd2807SJeff Garzik MV_PCI_DISC_TIMER = 0xd04, 164c6fd2807SJeff Garzik MV_PCI_MSI_TRIGGER = 0xc38, 165c6fd2807SJeff Garzik MV_PCI_SERR_MASK = 0xc28, 166c6fd2807SJeff Garzik MV_PCI_XBAR_TMOUT = 0x1d04, 167c6fd2807SJeff Garzik MV_PCI_ERR_LOW_ADDRESS = 0x1d40, 168c6fd2807SJeff Garzik MV_PCI_ERR_HIGH_ADDRESS = 0x1d44, 169c6fd2807SJeff Garzik MV_PCI_ERR_ATTRIBUTE = 0x1d48, 170c6fd2807SJeff Garzik MV_PCI_ERR_COMMAND = 0x1d50, 171c6fd2807SJeff Garzik 172c6fd2807SJeff Garzik PCI_IRQ_CAUSE_OFS = 0x1d58, 173c6fd2807SJeff Garzik PCI_IRQ_MASK_OFS = 0x1d5c, 174c6fd2807SJeff Garzik PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */ 175c6fd2807SJeff Garzik 17602a121daSMark Lord PCIE_IRQ_CAUSE_OFS = 0x1900, 17702a121daSMark Lord PCIE_IRQ_MASK_OFS = 0x1910, 178646a4da5SMark Lord PCIE_UNMASK_ALL_IRQS = 0x40a, /* assorted bits */ 17902a121daSMark Lord 180c6fd2807SJeff Garzik HC_MAIN_IRQ_CAUSE_OFS = 0x1d60, 181c6fd2807SJeff Garzik HC_MAIN_IRQ_MASK_OFS = 0x1d64, 182c6fd2807SJeff Garzik PORT0_ERR = (1 << 0), /* shift by port # */ 183c6fd2807SJeff Garzik PORT0_DONE = (1 << 1), /* shift by port # */ 184c6fd2807SJeff Garzik HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */ 185c6fd2807SJeff Garzik HC_SHIFT = 9, /* bits 9-17 = HC1's ports */ 186c6fd2807SJeff Garzik PCI_ERR = (1 << 18), 187c6fd2807SJeff Garzik TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */ 188c6fd2807SJeff Garzik TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */ 189fb621e2fSJeff Garzik PORTS_0_3_COAL_DONE = (1 << 8), 190fb621e2fSJeff Garzik PORTS_4_7_COAL_DONE = (1 << 17), 191c6fd2807SJeff Garzik PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */ 192c6fd2807SJeff Garzik GPIO_INT = (1 << 22), 193c6fd2807SJeff Garzik SELF_INT = (1 << 23), 194c6fd2807SJeff Garzik TWSI_INT = (1 << 24), 195c6fd2807SJeff Garzik HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */ 196fb621e2fSJeff Garzik HC_MAIN_RSVD_5 = (0x1fff << 19), /* bits 31-19 */ 197c6fd2807SJeff Garzik HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE | 198c6fd2807SJeff Garzik PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT | 199c6fd2807SJeff Garzik HC_MAIN_RSVD), 200fb621e2fSJeff Garzik HC_MAIN_MASKED_IRQS_5 = (PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE | 201fb621e2fSJeff Garzik HC_MAIN_RSVD_5), 202c6fd2807SJeff Garzik 203c6fd2807SJeff Garzik /* SATAHC registers */ 204c6fd2807SJeff Garzik HC_CFG_OFS = 0, 205c6fd2807SJeff Garzik 206c6fd2807SJeff Garzik HC_IRQ_CAUSE_OFS = 0x14, 207c6fd2807SJeff Garzik CRPB_DMA_DONE = (1 << 0), /* shift by port # */ 208c6fd2807SJeff Garzik HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */ 209c6fd2807SJeff Garzik DEV_IRQ = (1 << 8), /* shift by port # */ 210c6fd2807SJeff Garzik 211c6fd2807SJeff Garzik /* Shadow block registers */ 212c6fd2807SJeff Garzik SHD_BLK_OFS = 0x100, 213c6fd2807SJeff Garzik SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */ 214c6fd2807SJeff Garzik 215c6fd2807SJeff Garzik /* SATA registers */ 216c6fd2807SJeff Garzik SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */ 217c6fd2807SJeff Garzik SATA_ACTIVE_OFS = 0x350, 2180c58912eSMark Lord SATA_FIS_IRQ_CAUSE_OFS = 0x364, 219c6fd2807SJeff Garzik PHY_MODE3 = 0x310, 220c6fd2807SJeff Garzik PHY_MODE4 = 0x314, 221c6fd2807SJeff Garzik PHY_MODE2 = 0x330, 222c6fd2807SJeff Garzik MV5_PHY_MODE = 0x74, 223c6fd2807SJeff Garzik MV5_LT_MODE = 0x30, 224c6fd2807SJeff Garzik MV5_PHY_CTL = 0x0C, 225c6fd2807SJeff Garzik SATA_INTERFACE_CTL = 0x050, 226c6fd2807SJeff Garzik 227c6fd2807SJeff Garzik MV_M2_PREAMP_MASK = 0x7e0, 228c6fd2807SJeff Garzik 229c6fd2807SJeff Garzik /* Port registers */ 230c6fd2807SJeff Garzik EDMA_CFG_OFS = 0, 2310c58912eSMark Lord EDMA_CFG_Q_DEPTH = 0x1f, /* max device queue depth */ 2320c58912eSMark Lord EDMA_CFG_NCQ = (1 << 5), /* for R/W FPDMA queued */ 233c6fd2807SJeff Garzik EDMA_CFG_NCQ_GO_ON_ERR = (1 << 14), /* continue on error */ 234c6fd2807SJeff Garzik EDMA_CFG_RD_BRST_EXT = (1 << 11), /* read burst 512B */ 235c6fd2807SJeff Garzik EDMA_CFG_WR_BUFF_LEN = (1 << 13), /* write buffer 512B */ 236c6fd2807SJeff Garzik 237c6fd2807SJeff Garzik EDMA_ERR_IRQ_CAUSE_OFS = 0x8, 238c6fd2807SJeff Garzik EDMA_ERR_IRQ_MASK_OFS = 0xc, 2396c1153e0SJeff Garzik EDMA_ERR_D_PAR = (1 << 0), /* UDMA data parity err */ 2406c1153e0SJeff Garzik EDMA_ERR_PRD_PAR = (1 << 1), /* UDMA PRD parity err */ 2416c1153e0SJeff Garzik EDMA_ERR_DEV = (1 << 2), /* device error */ 2426c1153e0SJeff Garzik EDMA_ERR_DEV_DCON = (1 << 3), /* device disconnect */ 2436c1153e0SJeff Garzik EDMA_ERR_DEV_CON = (1 << 4), /* device connected */ 2446c1153e0SJeff Garzik EDMA_ERR_SERR = (1 << 5), /* SError bits [WBDST] raised */ 245c5d3e45aSJeff Garzik EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */ 246c5d3e45aSJeff Garzik EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */ 2476c1153e0SJeff Garzik EDMA_ERR_BIST_ASYNC = (1 << 8), /* BIST FIS or Async Notify */ 248c5d3e45aSJeff Garzik EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */ 2496c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR = (1 << 9), /* CRQB parity error */ 2506c1153e0SJeff Garzik EDMA_ERR_CRPB_PAR = (1 << 10), /* CRPB parity error */ 2516c1153e0SJeff Garzik EDMA_ERR_INTRL_PAR = (1 << 11), /* internal parity error */ 2526c1153e0SJeff Garzik EDMA_ERR_IORDY = (1 << 12), /* IORdy timeout */ 253646a4da5SMark Lord 2546c1153e0SJeff Garzik EDMA_ERR_LNK_CTRL_RX = (0xf << 13), /* link ctrl rx error */ 255646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_0 = (1 << 13), /* transient: CRC err */ 256646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_1 = (1 << 14), /* transient: FIFO err */ 257646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15), /* fatal: caught SYNC */ 258646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_3 = (1 << 16), /* transient: FIS rx err */ 259646a4da5SMark Lord 2606c1153e0SJeff Garzik EDMA_ERR_LNK_DATA_RX = (0xf << 17), /* link data rx error */ 261646a4da5SMark Lord 2626c1153e0SJeff Garzik EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), /* link ctrl tx error */ 263646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_0 = (1 << 21), /* transient: CRC err */ 264646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_1 = (1 << 22), /* transient: FIFO err */ 265646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_2 = (1 << 23), /* transient: caught SYNC */ 266646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_3 = (1 << 24), /* transient: caught DMAT */ 267646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX_4 = (1 << 25), /* transient: FIS collision */ 268646a4da5SMark Lord 2696c1153e0SJeff Garzik EDMA_ERR_LNK_DATA_TX = (0x1f << 26), /* link data tx error */ 270646a4da5SMark Lord 2716c1153e0SJeff Garzik EDMA_ERR_TRANS_PROTO = (1 << 31), /* transport protocol error */ 272c5d3e45aSJeff Garzik EDMA_ERR_OVERRUN_5 = (1 << 5), 273c5d3e45aSJeff Garzik EDMA_ERR_UNDERRUN_5 = (1 << 6), 274646a4da5SMark Lord 275646a4da5SMark Lord EDMA_ERR_IRQ_TRANSIENT = EDMA_ERR_LNK_CTRL_RX_0 | 276646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_1 | 277646a4da5SMark Lord EDMA_ERR_LNK_CTRL_RX_3 | 278646a4da5SMark Lord EDMA_ERR_LNK_CTRL_TX, 279646a4da5SMark Lord 280bdd4dddeSJeff Garzik EDMA_EH_FREEZE = EDMA_ERR_D_PAR | 281bdd4dddeSJeff Garzik EDMA_ERR_PRD_PAR | 282bdd4dddeSJeff Garzik EDMA_ERR_DEV_DCON | 283bdd4dddeSJeff Garzik EDMA_ERR_DEV_CON | 284bdd4dddeSJeff Garzik EDMA_ERR_SERR | 285bdd4dddeSJeff Garzik EDMA_ERR_SELF_DIS | 2866c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR | 287bdd4dddeSJeff Garzik EDMA_ERR_CRPB_PAR | 288bdd4dddeSJeff Garzik EDMA_ERR_INTRL_PAR | 289bdd4dddeSJeff Garzik EDMA_ERR_IORDY | 290bdd4dddeSJeff Garzik EDMA_ERR_LNK_CTRL_RX_2 | 291c6fd2807SJeff Garzik EDMA_ERR_LNK_DATA_RX | 292c6fd2807SJeff Garzik EDMA_ERR_LNK_DATA_TX | 293bdd4dddeSJeff Garzik EDMA_ERR_TRANS_PROTO, 294bdd4dddeSJeff Garzik EDMA_EH_FREEZE_5 = EDMA_ERR_D_PAR | 295bdd4dddeSJeff Garzik EDMA_ERR_PRD_PAR | 296bdd4dddeSJeff Garzik EDMA_ERR_DEV_DCON | 297bdd4dddeSJeff Garzik EDMA_ERR_DEV_CON | 298bdd4dddeSJeff Garzik EDMA_ERR_OVERRUN_5 | 299bdd4dddeSJeff Garzik EDMA_ERR_UNDERRUN_5 | 300bdd4dddeSJeff Garzik EDMA_ERR_SELF_DIS_5 | 3016c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR | 302bdd4dddeSJeff Garzik EDMA_ERR_CRPB_PAR | 303bdd4dddeSJeff Garzik EDMA_ERR_INTRL_PAR | 304bdd4dddeSJeff Garzik EDMA_ERR_IORDY, 305c6fd2807SJeff Garzik 306c6fd2807SJeff Garzik EDMA_REQ_Q_BASE_HI_OFS = 0x10, 307c6fd2807SJeff Garzik EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */ 308c6fd2807SJeff Garzik 309c6fd2807SJeff Garzik EDMA_REQ_Q_OUT_PTR_OFS = 0x18, 310c6fd2807SJeff Garzik EDMA_REQ_Q_PTR_SHIFT = 5, 311c6fd2807SJeff Garzik 312c6fd2807SJeff Garzik EDMA_RSP_Q_BASE_HI_OFS = 0x1c, 313c6fd2807SJeff Garzik EDMA_RSP_Q_IN_PTR_OFS = 0x20, 314c6fd2807SJeff Garzik EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */ 315c6fd2807SJeff Garzik EDMA_RSP_Q_PTR_SHIFT = 3, 316c6fd2807SJeff Garzik 3170ea9e179SJeff Garzik EDMA_CMD_OFS = 0x28, /* EDMA command register */ 3180ea9e179SJeff Garzik EDMA_EN = (1 << 0), /* enable EDMA */ 3190ea9e179SJeff Garzik EDMA_DS = (1 << 1), /* disable EDMA; self-negated */ 3200ea9e179SJeff Garzik ATA_RST = (1 << 2), /* reset trans/link/phy */ 321c6fd2807SJeff Garzik 322c6fd2807SJeff Garzik EDMA_IORDY_TMOUT = 0x34, 323c6fd2807SJeff Garzik EDMA_ARB_CFG = 0x38, 324c6fd2807SJeff Garzik 325c6fd2807SJeff Garzik /* Host private flags (hp_flags) */ 326c6fd2807SJeff Garzik MV_HP_FLAG_MSI = (1 << 0), 327c6fd2807SJeff Garzik MV_HP_ERRATA_50XXB0 = (1 << 1), 328c6fd2807SJeff Garzik MV_HP_ERRATA_50XXB2 = (1 << 2), 329c6fd2807SJeff Garzik MV_HP_ERRATA_60X1B2 = (1 << 3), 330c6fd2807SJeff Garzik MV_HP_ERRATA_60X1C0 = (1 << 4), 331c6fd2807SJeff Garzik MV_HP_ERRATA_XX42A0 = (1 << 5), 3320ea9e179SJeff Garzik MV_HP_GEN_I = (1 << 6), /* Generation I: 50xx */ 3330ea9e179SJeff Garzik MV_HP_GEN_II = (1 << 7), /* Generation II: 60xx */ 3340ea9e179SJeff Garzik MV_HP_GEN_IIE = (1 << 8), /* Generation IIE: 6042/7042 */ 33502a121daSMark Lord MV_HP_PCIE = (1 << 9), /* PCIe bus/regs: 7042 */ 336c6fd2807SJeff Garzik 337c6fd2807SJeff Garzik /* Port private flags (pp_flags) */ 3380ea9e179SJeff Garzik MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */ 33972109168SMark Lord MV_PP_FLAG_NCQ_EN = (1 << 1), /* is EDMA set up for NCQ? */ 3400ea9e179SJeff Garzik MV_PP_FLAG_HAD_A_RESET = (1 << 2), /* 1st hard reset complete? */ 341c6fd2807SJeff Garzik }; 342c6fd2807SJeff Garzik 343ee9ccdf7SJeff Garzik #define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I) 344ee9ccdf7SJeff Garzik #define IS_GEN_II(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_II) 345c6fd2807SJeff Garzik #define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE) 346*7bb3c529SSaeed Bishara #define HAS_PCI(host) (!((host)->ports[0]->flags & MV_FLAG_SOC)) 347c6fd2807SJeff Garzik 348c6fd2807SJeff Garzik enum { 349baf14aa1SJeff Garzik /* DMA boundary 0xffff is required by the s/g splitting 350baf14aa1SJeff Garzik * we need on /length/ in mv_fill-sg(). 351baf14aa1SJeff Garzik */ 352baf14aa1SJeff Garzik MV_DMA_BOUNDARY = 0xffffU, 353c6fd2807SJeff Garzik 3540ea9e179SJeff Garzik /* mask of register bits containing lower 32 bits 3550ea9e179SJeff Garzik * of EDMA request queue DMA address 3560ea9e179SJeff Garzik */ 357c6fd2807SJeff Garzik EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U, 358c6fd2807SJeff Garzik 3590ea9e179SJeff Garzik /* ditto, for response queue */ 360c6fd2807SJeff Garzik EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U, 361c6fd2807SJeff Garzik }; 362c6fd2807SJeff Garzik 363c6fd2807SJeff Garzik enum chip_type { 364c6fd2807SJeff Garzik chip_504x, 365c6fd2807SJeff Garzik chip_508x, 366c6fd2807SJeff Garzik chip_5080, 367c6fd2807SJeff Garzik chip_604x, 368c6fd2807SJeff Garzik chip_608x, 369c6fd2807SJeff Garzik chip_6042, 370c6fd2807SJeff Garzik chip_7042, 371c6fd2807SJeff Garzik }; 372c6fd2807SJeff Garzik 373c6fd2807SJeff Garzik /* Command ReQuest Block: 32B */ 374c6fd2807SJeff Garzik struct mv_crqb { 375c6fd2807SJeff Garzik __le32 sg_addr; 376c6fd2807SJeff Garzik __le32 sg_addr_hi; 377c6fd2807SJeff Garzik __le16 ctrl_flags; 378c6fd2807SJeff Garzik __le16 ata_cmd[11]; 379c6fd2807SJeff Garzik }; 380c6fd2807SJeff Garzik 381c6fd2807SJeff Garzik struct mv_crqb_iie { 382c6fd2807SJeff Garzik __le32 addr; 383c6fd2807SJeff Garzik __le32 addr_hi; 384c6fd2807SJeff Garzik __le32 flags; 385c6fd2807SJeff Garzik __le32 len; 386c6fd2807SJeff Garzik __le32 ata_cmd[4]; 387c6fd2807SJeff Garzik }; 388c6fd2807SJeff Garzik 389c6fd2807SJeff Garzik /* Command ResPonse Block: 8B */ 390c6fd2807SJeff Garzik struct mv_crpb { 391c6fd2807SJeff Garzik __le16 id; 392c6fd2807SJeff Garzik __le16 flags; 393c6fd2807SJeff Garzik __le32 tmstmp; 394c6fd2807SJeff Garzik }; 395c6fd2807SJeff Garzik 396c6fd2807SJeff Garzik /* EDMA Physical Region Descriptor (ePRD); A.K.A. SG */ 397c6fd2807SJeff Garzik struct mv_sg { 398c6fd2807SJeff Garzik __le32 addr; 399c6fd2807SJeff Garzik __le32 flags_size; 400c6fd2807SJeff Garzik __le32 addr_hi; 401c6fd2807SJeff Garzik __le32 reserved; 402c6fd2807SJeff Garzik }; 403c6fd2807SJeff Garzik 404c6fd2807SJeff Garzik struct mv_port_priv { 405c6fd2807SJeff Garzik struct mv_crqb *crqb; 406c6fd2807SJeff Garzik dma_addr_t crqb_dma; 407c6fd2807SJeff Garzik struct mv_crpb *crpb; 408c6fd2807SJeff Garzik dma_addr_t crpb_dma; 409eb73d558SMark Lord struct mv_sg *sg_tbl[MV_MAX_Q_DEPTH]; 410eb73d558SMark Lord dma_addr_t sg_tbl_dma[MV_MAX_Q_DEPTH]; 411bdd4dddeSJeff Garzik 412bdd4dddeSJeff Garzik unsigned int req_idx; 413bdd4dddeSJeff Garzik unsigned int resp_idx; 414bdd4dddeSJeff Garzik 415c6fd2807SJeff Garzik u32 pp_flags; 416c6fd2807SJeff Garzik }; 417c6fd2807SJeff Garzik 418c6fd2807SJeff Garzik struct mv_port_signal { 419c6fd2807SJeff Garzik u32 amps; 420c6fd2807SJeff Garzik u32 pre; 421c6fd2807SJeff Garzik }; 422c6fd2807SJeff Garzik 42302a121daSMark Lord struct mv_host_priv { 42402a121daSMark Lord u32 hp_flags; 42502a121daSMark Lord struct mv_port_signal signal[8]; 42602a121daSMark Lord const struct mv_hw_ops *ops; 42702a121daSMark Lord u32 irq_cause_ofs; 42802a121daSMark Lord u32 irq_mask_ofs; 42902a121daSMark Lord u32 unmask_all_irqs; 430da2fa9baSMark Lord /* 431da2fa9baSMark Lord * These consistent DMA memory pools give us guaranteed 432da2fa9baSMark Lord * alignment for hardware-accessed data structures, 433da2fa9baSMark Lord * and less memory waste in accomplishing the alignment. 434da2fa9baSMark Lord */ 435da2fa9baSMark Lord struct dma_pool *crqb_pool; 436da2fa9baSMark Lord struct dma_pool *crpb_pool; 437da2fa9baSMark Lord struct dma_pool *sg_tbl_pool; 43802a121daSMark Lord }; 43902a121daSMark Lord 440c6fd2807SJeff Garzik struct mv_hw_ops { 441c6fd2807SJeff Garzik void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio, 442c6fd2807SJeff Garzik unsigned int port); 443c6fd2807SJeff Garzik void (*enable_leds)(struct mv_host_priv *hpriv, void __iomem *mmio); 444c6fd2807SJeff Garzik void (*read_preamp)(struct mv_host_priv *hpriv, int idx, 445c6fd2807SJeff Garzik void __iomem *mmio); 446c6fd2807SJeff Garzik int (*reset_hc)(struct mv_host_priv *hpriv, void __iomem *mmio, 447c6fd2807SJeff Garzik unsigned int n_hc); 448c6fd2807SJeff Garzik void (*reset_flash)(struct mv_host_priv *hpriv, void __iomem *mmio); 449*7bb3c529SSaeed Bishara void (*reset_bus)(struct ata_host *host, void __iomem *mmio); 450c6fd2807SJeff Garzik }; 451c6fd2807SJeff Garzik 452c6fd2807SJeff Garzik static void mv_irq_clear(struct ata_port *ap); 453da3dbb17STejun Heo static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); 454da3dbb17STejun Heo static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 455da3dbb17STejun Heo static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val); 456da3dbb17STejun Heo static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 457c6fd2807SJeff Garzik static int mv_port_start(struct ata_port *ap); 458c6fd2807SJeff Garzik static void mv_port_stop(struct ata_port *ap); 459c6fd2807SJeff Garzik static void mv_qc_prep(struct ata_queued_cmd *qc); 460c6fd2807SJeff Garzik static void mv_qc_prep_iie(struct ata_queued_cmd *qc); 461c6fd2807SJeff Garzik static unsigned int mv_qc_issue(struct ata_queued_cmd *qc); 462bdd4dddeSJeff Garzik static void mv_error_handler(struct ata_port *ap); 463bdd4dddeSJeff Garzik static void mv_eh_freeze(struct ata_port *ap); 464bdd4dddeSJeff Garzik static void mv_eh_thaw(struct ata_port *ap); 465f273827eSMark Lord static void mv6_dev_config(struct ata_device *dev); 466c6fd2807SJeff Garzik 467c6fd2807SJeff Garzik static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 468c6fd2807SJeff Garzik unsigned int port); 469c6fd2807SJeff Garzik static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); 470c6fd2807SJeff Garzik static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, 471c6fd2807SJeff Garzik void __iomem *mmio); 472c6fd2807SJeff Garzik static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 473c6fd2807SJeff Garzik unsigned int n_hc); 474c6fd2807SJeff Garzik static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); 475*7bb3c529SSaeed Bishara static void mv5_reset_bus(struct ata_host *host, void __iomem *mmio); 476c6fd2807SJeff Garzik 477c6fd2807SJeff Garzik static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 478c6fd2807SJeff Garzik unsigned int port); 479c6fd2807SJeff Garzik static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); 480c6fd2807SJeff Garzik static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, 481c6fd2807SJeff Garzik void __iomem *mmio); 482c6fd2807SJeff Garzik static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 483c6fd2807SJeff Garzik unsigned int n_hc); 484c6fd2807SJeff Garzik static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); 485*7bb3c529SSaeed Bishara static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio); 486c6fd2807SJeff Garzik static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, 487c6fd2807SJeff Garzik unsigned int port_no); 48872109168SMark Lord static void mv_edma_cfg(struct mv_port_priv *pp, struct mv_host_priv *hpriv, 48972109168SMark Lord void __iomem *port_mmio, int want_ncq); 49072109168SMark Lord static int __mv_stop_dma(struct ata_port *ap); 491c6fd2807SJeff Garzik 492eb73d558SMark Lord /* .sg_tablesize is (MV_MAX_SG_CT / 2) in the structures below 493eb73d558SMark Lord * because we have to allow room for worst case splitting of 494eb73d558SMark Lord * PRDs for 64K boundaries in mv_fill_sg(). 495eb73d558SMark Lord */ 496c5d3e45aSJeff Garzik static struct scsi_host_template mv5_sht = { 497c6fd2807SJeff Garzik .module = THIS_MODULE, 498c6fd2807SJeff Garzik .name = DRV_NAME, 499c6fd2807SJeff Garzik .ioctl = ata_scsi_ioctl, 500c6fd2807SJeff Garzik .queuecommand = ata_scsi_queuecmd, 501c5d3e45aSJeff Garzik .can_queue = ATA_DEF_QUEUE, 502c5d3e45aSJeff Garzik .this_id = ATA_SHT_THIS_ID, 503baf14aa1SJeff Garzik .sg_tablesize = MV_MAX_SG_CT / 2, 504c5d3e45aSJeff Garzik .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 505c5d3e45aSJeff Garzik .emulated = ATA_SHT_EMULATED, 506c5d3e45aSJeff Garzik .use_clustering = 1, 507c5d3e45aSJeff Garzik .proc_name = DRV_NAME, 508c5d3e45aSJeff Garzik .dma_boundary = MV_DMA_BOUNDARY, 5093be6cbd7SJeff Garzik .slave_configure = ata_scsi_slave_config, 510c5d3e45aSJeff Garzik .slave_destroy = ata_scsi_slave_destroy, 511c5d3e45aSJeff Garzik .bios_param = ata_std_bios_param, 512c5d3e45aSJeff Garzik }; 513c5d3e45aSJeff Garzik 514c5d3e45aSJeff Garzik static struct scsi_host_template mv6_sht = { 515c5d3e45aSJeff Garzik .module = THIS_MODULE, 516c5d3e45aSJeff Garzik .name = DRV_NAME, 517c5d3e45aSJeff Garzik .ioctl = ata_scsi_ioctl, 518c5d3e45aSJeff Garzik .queuecommand = ata_scsi_queuecmd, 519138bfdd0SMark Lord .change_queue_depth = ata_scsi_change_queue_depth, 520138bfdd0SMark Lord .can_queue = MV_MAX_Q_DEPTH - 1, 521c6fd2807SJeff Garzik .this_id = ATA_SHT_THIS_ID, 522baf14aa1SJeff Garzik .sg_tablesize = MV_MAX_SG_CT / 2, 523c6fd2807SJeff Garzik .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 524c6fd2807SJeff Garzik .emulated = ATA_SHT_EMULATED, 525d88184fbSJeff Garzik .use_clustering = 1, 526c6fd2807SJeff Garzik .proc_name = DRV_NAME, 527c6fd2807SJeff Garzik .dma_boundary = MV_DMA_BOUNDARY, 5283be6cbd7SJeff Garzik .slave_configure = ata_scsi_slave_config, 529c6fd2807SJeff Garzik .slave_destroy = ata_scsi_slave_destroy, 530c6fd2807SJeff Garzik .bios_param = ata_std_bios_param, 531c6fd2807SJeff Garzik }; 532c6fd2807SJeff Garzik 533c6fd2807SJeff Garzik static const struct ata_port_operations mv5_ops = { 534c6fd2807SJeff Garzik .tf_load = ata_tf_load, 535c6fd2807SJeff Garzik .tf_read = ata_tf_read, 536c6fd2807SJeff Garzik .check_status = ata_check_status, 537c6fd2807SJeff Garzik .exec_command = ata_exec_command, 538c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 539c6fd2807SJeff Garzik 540cffacd85SJeff Garzik .cable_detect = ata_cable_sata, 541c6fd2807SJeff Garzik 542c6fd2807SJeff Garzik .qc_prep = mv_qc_prep, 543c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 5440d5ff566STejun Heo .data_xfer = ata_data_xfer, 545c6fd2807SJeff Garzik 546c6fd2807SJeff Garzik .irq_clear = mv_irq_clear, 547246ce3b6SAkira Iguchi .irq_on = ata_irq_on, 548c6fd2807SJeff Garzik 549bdd4dddeSJeff Garzik .error_handler = mv_error_handler, 550bdd4dddeSJeff Garzik .freeze = mv_eh_freeze, 551bdd4dddeSJeff Garzik .thaw = mv_eh_thaw, 552bdd4dddeSJeff Garzik 553c6fd2807SJeff Garzik .scr_read = mv5_scr_read, 554c6fd2807SJeff Garzik .scr_write = mv5_scr_write, 555c6fd2807SJeff Garzik 556c6fd2807SJeff Garzik .port_start = mv_port_start, 557c6fd2807SJeff Garzik .port_stop = mv_port_stop, 558c6fd2807SJeff Garzik }; 559c6fd2807SJeff Garzik 560c6fd2807SJeff Garzik static const struct ata_port_operations mv6_ops = { 561f273827eSMark Lord .dev_config = mv6_dev_config, 562c6fd2807SJeff Garzik .tf_load = ata_tf_load, 563c6fd2807SJeff Garzik .tf_read = ata_tf_read, 564c6fd2807SJeff Garzik .check_status = ata_check_status, 565c6fd2807SJeff Garzik .exec_command = ata_exec_command, 566c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 567c6fd2807SJeff Garzik 568cffacd85SJeff Garzik .cable_detect = ata_cable_sata, 569c6fd2807SJeff Garzik 570c6fd2807SJeff Garzik .qc_prep = mv_qc_prep, 571c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 5720d5ff566STejun Heo .data_xfer = ata_data_xfer, 573c6fd2807SJeff Garzik 574c6fd2807SJeff Garzik .irq_clear = mv_irq_clear, 575246ce3b6SAkira Iguchi .irq_on = ata_irq_on, 576c6fd2807SJeff Garzik 577bdd4dddeSJeff Garzik .error_handler = mv_error_handler, 578bdd4dddeSJeff Garzik .freeze = mv_eh_freeze, 579bdd4dddeSJeff Garzik .thaw = mv_eh_thaw, 580138bfdd0SMark Lord .qc_defer = ata_std_qc_defer, 581bdd4dddeSJeff Garzik 582c6fd2807SJeff Garzik .scr_read = mv_scr_read, 583c6fd2807SJeff Garzik .scr_write = mv_scr_write, 584c6fd2807SJeff Garzik 585c6fd2807SJeff Garzik .port_start = mv_port_start, 586c6fd2807SJeff Garzik .port_stop = mv_port_stop, 587c6fd2807SJeff Garzik }; 588c6fd2807SJeff Garzik 589c6fd2807SJeff Garzik static const struct ata_port_operations mv_iie_ops = { 590c6fd2807SJeff Garzik .tf_load = ata_tf_load, 591c6fd2807SJeff Garzik .tf_read = ata_tf_read, 592c6fd2807SJeff Garzik .check_status = ata_check_status, 593c6fd2807SJeff Garzik .exec_command = ata_exec_command, 594c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 595c6fd2807SJeff Garzik 596cffacd85SJeff Garzik .cable_detect = ata_cable_sata, 597c6fd2807SJeff Garzik 598c6fd2807SJeff Garzik .qc_prep = mv_qc_prep_iie, 599c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 6000d5ff566STejun Heo .data_xfer = ata_data_xfer, 601c6fd2807SJeff Garzik 602c6fd2807SJeff Garzik .irq_clear = mv_irq_clear, 603246ce3b6SAkira Iguchi .irq_on = ata_irq_on, 604c6fd2807SJeff Garzik 605bdd4dddeSJeff Garzik .error_handler = mv_error_handler, 606bdd4dddeSJeff Garzik .freeze = mv_eh_freeze, 607bdd4dddeSJeff Garzik .thaw = mv_eh_thaw, 608138bfdd0SMark Lord .qc_defer = ata_std_qc_defer, 609bdd4dddeSJeff Garzik 610c6fd2807SJeff Garzik .scr_read = mv_scr_read, 611c6fd2807SJeff Garzik .scr_write = mv_scr_write, 612c6fd2807SJeff Garzik 613c6fd2807SJeff Garzik .port_start = mv_port_start, 614c6fd2807SJeff Garzik .port_stop = mv_port_stop, 615c6fd2807SJeff Garzik }; 616c6fd2807SJeff Garzik 617c6fd2807SJeff Garzik static const struct ata_port_info mv_port_info[] = { 618c6fd2807SJeff Garzik { /* chip_504x */ 619cca3974eSJeff Garzik .flags = MV_COMMON_FLAGS, 620c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 621bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 622c6fd2807SJeff Garzik .port_ops = &mv5_ops, 623c6fd2807SJeff Garzik }, 624c6fd2807SJeff Garzik { /* chip_508x */ 625c5d3e45aSJeff Garzik .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC, 626c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 627bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 628c6fd2807SJeff Garzik .port_ops = &mv5_ops, 629c6fd2807SJeff Garzik }, 630c6fd2807SJeff Garzik { /* chip_5080 */ 631c5d3e45aSJeff Garzik .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC, 632c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 633bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 634c6fd2807SJeff Garzik .port_ops = &mv5_ops, 635c6fd2807SJeff Garzik }, 636c6fd2807SJeff Garzik { /* chip_604x */ 637138bfdd0SMark Lord .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 638138bfdd0SMark Lord ATA_FLAG_NCQ, 639c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 640bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 641c6fd2807SJeff Garzik .port_ops = &mv6_ops, 642c6fd2807SJeff Garzik }, 643c6fd2807SJeff Garzik { /* chip_608x */ 644c5d3e45aSJeff Garzik .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 645138bfdd0SMark Lord ATA_FLAG_NCQ | MV_FLAG_DUAL_HC, 646c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 647bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 648c6fd2807SJeff Garzik .port_ops = &mv6_ops, 649c6fd2807SJeff Garzik }, 650c6fd2807SJeff Garzik { /* chip_6042 */ 651138bfdd0SMark Lord .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 652138bfdd0SMark Lord ATA_FLAG_NCQ, 653c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 654bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 655c6fd2807SJeff Garzik .port_ops = &mv_iie_ops, 656c6fd2807SJeff Garzik }, 657c6fd2807SJeff Garzik { /* chip_7042 */ 658138bfdd0SMark Lord .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 659138bfdd0SMark Lord ATA_FLAG_NCQ, 660c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 661bf6263a8SJeff Garzik .udma_mask = ATA_UDMA6, 662c6fd2807SJeff Garzik .port_ops = &mv_iie_ops, 663c6fd2807SJeff Garzik }, 664c6fd2807SJeff Garzik }; 665c6fd2807SJeff Garzik 666c6fd2807SJeff Garzik static const struct pci_device_id mv_pci_tbl[] = { 6672d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5040), chip_504x }, 6682d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5041), chip_504x }, 6692d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5080), chip_5080 }, 6702d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5081), chip_508x }, 671cfbf723eSAlan Cox /* RocketRAID 1740/174x have different identifiers */ 672cfbf723eSAlan Cox { PCI_VDEVICE(TTI, 0x1740), chip_508x }, 673cfbf723eSAlan Cox { PCI_VDEVICE(TTI, 0x1742), chip_508x }, 674c6fd2807SJeff Garzik 6752d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6040), chip_604x }, 6762d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6041), chip_604x }, 6772d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6042), chip_6042 }, 6782d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6080), chip_608x }, 6792d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6081), chip_608x }, 680c6fd2807SJeff Garzik 6812d2744fcSJeff Garzik { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x }, 6822d2744fcSJeff Garzik 683d9f9c6bcSFlorian Attenberger /* Adaptec 1430SA */ 684d9f9c6bcSFlorian Attenberger { PCI_VDEVICE(ADAPTEC2, 0x0243), chip_7042 }, 685d9f9c6bcSFlorian Attenberger 68602a121daSMark Lord /* Marvell 7042 support */ 6876a3d586dSMorrison, Tom { PCI_VDEVICE(MARVELL, 0x7042), chip_7042 }, 6886a3d586dSMorrison, Tom 68902a121daSMark Lord /* Highpoint RocketRAID PCIe series */ 69002a121daSMark Lord { PCI_VDEVICE(TTI, 0x2300), chip_7042 }, 69102a121daSMark Lord { PCI_VDEVICE(TTI, 0x2310), chip_7042 }, 69202a121daSMark Lord 693c6fd2807SJeff Garzik { } /* terminate list */ 694c6fd2807SJeff Garzik }; 695c6fd2807SJeff Garzik 696c6fd2807SJeff Garzik static const struct mv_hw_ops mv5xxx_ops = { 697c6fd2807SJeff Garzik .phy_errata = mv5_phy_errata, 698c6fd2807SJeff Garzik .enable_leds = mv5_enable_leds, 699c6fd2807SJeff Garzik .read_preamp = mv5_read_preamp, 700c6fd2807SJeff Garzik .reset_hc = mv5_reset_hc, 701c6fd2807SJeff Garzik .reset_flash = mv5_reset_flash, 702c6fd2807SJeff Garzik .reset_bus = mv5_reset_bus, 703c6fd2807SJeff Garzik }; 704c6fd2807SJeff Garzik 705c6fd2807SJeff Garzik static const struct mv_hw_ops mv6xxx_ops = { 706c6fd2807SJeff Garzik .phy_errata = mv6_phy_errata, 707c6fd2807SJeff Garzik .enable_leds = mv6_enable_leds, 708c6fd2807SJeff Garzik .read_preamp = mv6_read_preamp, 709c6fd2807SJeff Garzik .reset_hc = mv6_reset_hc, 710c6fd2807SJeff Garzik .reset_flash = mv6_reset_flash, 711c6fd2807SJeff Garzik .reset_bus = mv_reset_pci_bus, 712c6fd2807SJeff Garzik }; 713c6fd2807SJeff Garzik 714c6fd2807SJeff Garzik /* 715c6fd2807SJeff Garzik * Functions 716c6fd2807SJeff Garzik */ 717c6fd2807SJeff Garzik 718c6fd2807SJeff Garzik static inline void writelfl(unsigned long data, void __iomem *addr) 719c6fd2807SJeff Garzik { 720c6fd2807SJeff Garzik writel(data, addr); 721c6fd2807SJeff Garzik (void) readl(addr); /* flush to avoid PCI posted write */ 722c6fd2807SJeff Garzik } 723c6fd2807SJeff Garzik 724c6fd2807SJeff Garzik static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc) 725c6fd2807SJeff Garzik { 726c6fd2807SJeff Garzik return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ)); 727c6fd2807SJeff Garzik } 728c6fd2807SJeff Garzik 729c6fd2807SJeff Garzik static inline unsigned int mv_hc_from_port(unsigned int port) 730c6fd2807SJeff Garzik { 731c6fd2807SJeff Garzik return port >> MV_PORT_HC_SHIFT; 732c6fd2807SJeff Garzik } 733c6fd2807SJeff Garzik 734c6fd2807SJeff Garzik static inline unsigned int mv_hardport_from_port(unsigned int port) 735c6fd2807SJeff Garzik { 736c6fd2807SJeff Garzik return port & MV_PORT_MASK; 737c6fd2807SJeff Garzik } 738c6fd2807SJeff Garzik 739c6fd2807SJeff Garzik static inline void __iomem *mv_hc_base_from_port(void __iomem *base, 740c6fd2807SJeff Garzik unsigned int port) 741c6fd2807SJeff Garzik { 742c6fd2807SJeff Garzik return mv_hc_base(base, mv_hc_from_port(port)); 743c6fd2807SJeff Garzik } 744c6fd2807SJeff Garzik 745c6fd2807SJeff Garzik static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port) 746c6fd2807SJeff Garzik { 747c6fd2807SJeff Garzik return mv_hc_base_from_port(base, port) + 748c6fd2807SJeff Garzik MV_SATAHC_ARBTR_REG_SZ + 749c6fd2807SJeff Garzik (mv_hardport_from_port(port) * MV_PORT_REG_SZ); 750c6fd2807SJeff Garzik } 751c6fd2807SJeff Garzik 752c6fd2807SJeff Garzik static inline void __iomem *mv_ap_base(struct ata_port *ap) 753c6fd2807SJeff Garzik { 7540d5ff566STejun Heo return mv_port_base(ap->host->iomap[MV_PRIMARY_BAR], ap->port_no); 755c6fd2807SJeff Garzik } 756c6fd2807SJeff Garzik 757cca3974eSJeff Garzik static inline int mv_get_hc_count(unsigned long port_flags) 758c6fd2807SJeff Garzik { 759cca3974eSJeff Garzik return ((port_flags & MV_FLAG_DUAL_HC) ? 2 : 1); 760c6fd2807SJeff Garzik } 761c6fd2807SJeff Garzik 762c6fd2807SJeff Garzik static void mv_irq_clear(struct ata_port *ap) 763c6fd2807SJeff Garzik { 764c6fd2807SJeff Garzik } 765c6fd2807SJeff Garzik 766c5d3e45aSJeff Garzik static void mv_set_edma_ptrs(void __iomem *port_mmio, 767c5d3e45aSJeff Garzik struct mv_host_priv *hpriv, 768c5d3e45aSJeff Garzik struct mv_port_priv *pp) 769c5d3e45aSJeff Garzik { 770bdd4dddeSJeff Garzik u32 index; 771bdd4dddeSJeff Garzik 772c5d3e45aSJeff Garzik /* 773c5d3e45aSJeff Garzik * initialize request queue 774c5d3e45aSJeff Garzik */ 775bdd4dddeSJeff Garzik index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT; 776bdd4dddeSJeff Garzik 777c5d3e45aSJeff Garzik WARN_ON(pp->crqb_dma & 0x3ff); 778c5d3e45aSJeff Garzik writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); 779bdd4dddeSJeff Garzik writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | index, 780c5d3e45aSJeff Garzik port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 781c5d3e45aSJeff Garzik 782c5d3e45aSJeff Garzik if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) 783bdd4dddeSJeff Garzik writelfl((pp->crqb_dma & 0xffffffff) | index, 784c5d3e45aSJeff Garzik port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); 785c5d3e45aSJeff Garzik else 786bdd4dddeSJeff Garzik writelfl(index, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); 787c5d3e45aSJeff Garzik 788c5d3e45aSJeff Garzik /* 789c5d3e45aSJeff Garzik * initialize response queue 790c5d3e45aSJeff Garzik */ 791bdd4dddeSJeff Garzik index = (pp->resp_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_RSP_Q_PTR_SHIFT; 792bdd4dddeSJeff Garzik 793c5d3e45aSJeff Garzik WARN_ON(pp->crpb_dma & 0xff); 794c5d3e45aSJeff Garzik writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS); 795c5d3e45aSJeff Garzik 796c5d3e45aSJeff Garzik if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) 797bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & 0xffffffff) | index, 798c5d3e45aSJeff Garzik port_mmio + EDMA_RSP_Q_IN_PTR_OFS); 799c5d3e45aSJeff Garzik else 800bdd4dddeSJeff Garzik writelfl(index, port_mmio + EDMA_RSP_Q_IN_PTR_OFS); 801c5d3e45aSJeff Garzik 802bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | index, 803c5d3e45aSJeff Garzik port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 804c5d3e45aSJeff Garzik } 805c5d3e45aSJeff Garzik 806c6fd2807SJeff Garzik /** 807c6fd2807SJeff Garzik * mv_start_dma - Enable eDMA engine 808c6fd2807SJeff Garzik * @base: port base address 809c6fd2807SJeff Garzik * @pp: port private data 810c6fd2807SJeff Garzik * 811c6fd2807SJeff Garzik * Verify the local cache of the eDMA state is accurate with a 812c6fd2807SJeff Garzik * WARN_ON. 813c6fd2807SJeff Garzik * 814c6fd2807SJeff Garzik * LOCKING: 815c6fd2807SJeff Garzik * Inherited from caller. 816c6fd2807SJeff Garzik */ 8170c58912eSMark Lord static void mv_start_dma(struct ata_port *ap, void __iomem *port_mmio, 81872109168SMark Lord struct mv_port_priv *pp, u8 protocol) 819c6fd2807SJeff Garzik { 82072109168SMark Lord int want_ncq = (protocol == ATA_PROT_NCQ); 82172109168SMark Lord 82272109168SMark Lord if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 82372109168SMark Lord int using_ncq = ((pp->pp_flags & MV_PP_FLAG_NCQ_EN) != 0); 82472109168SMark Lord if (want_ncq != using_ncq) 82572109168SMark Lord __mv_stop_dma(ap); 82672109168SMark Lord } 827c5d3e45aSJeff Garzik if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) { 8280c58912eSMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 8290c58912eSMark Lord int hard_port = mv_hardport_from_port(ap->port_no); 8300c58912eSMark Lord void __iomem *hc_mmio = mv_hc_base_from_port( 8310c58912eSMark Lord ap->host->iomap[MV_PRIMARY_BAR], hard_port); 8320c58912eSMark Lord u32 hc_irq_cause, ipending; 8330c58912eSMark Lord 834bdd4dddeSJeff Garzik /* clear EDMA event indicators, if any */ 835f630d562SMark Lord writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 836bdd4dddeSJeff Garzik 8370c58912eSMark Lord /* clear EDMA interrupt indicator, if any */ 8380c58912eSMark Lord hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 8390c58912eSMark Lord ipending = (DEV_IRQ << hard_port) | 8400c58912eSMark Lord (CRPB_DMA_DONE << hard_port); 8410c58912eSMark Lord if (hc_irq_cause & ipending) { 8420c58912eSMark Lord writelfl(hc_irq_cause & ~ipending, 8430c58912eSMark Lord hc_mmio + HC_IRQ_CAUSE_OFS); 8440c58912eSMark Lord } 8450c58912eSMark Lord 84672109168SMark Lord mv_edma_cfg(pp, hpriv, port_mmio, want_ncq); 8470c58912eSMark Lord 8480c58912eSMark Lord /* clear FIS IRQ Cause */ 8490c58912eSMark Lord writelfl(0, port_mmio + SATA_FIS_IRQ_CAUSE_OFS); 8500c58912eSMark Lord 851f630d562SMark Lord mv_set_edma_ptrs(port_mmio, hpriv, pp); 852bdd4dddeSJeff Garzik 853f630d562SMark Lord writelfl(EDMA_EN, port_mmio + EDMA_CMD_OFS); 854c6fd2807SJeff Garzik pp->pp_flags |= MV_PP_FLAG_EDMA_EN; 855c6fd2807SJeff Garzik } 856f630d562SMark Lord WARN_ON(!(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS))); 857c6fd2807SJeff Garzik } 858c6fd2807SJeff Garzik 859c6fd2807SJeff Garzik /** 8600ea9e179SJeff Garzik * __mv_stop_dma - Disable eDMA engine 861c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 862c6fd2807SJeff Garzik * 863c6fd2807SJeff Garzik * Verify the local cache of the eDMA state is accurate with a 864c6fd2807SJeff Garzik * WARN_ON. 865c6fd2807SJeff Garzik * 866c6fd2807SJeff Garzik * LOCKING: 867c6fd2807SJeff Garzik * Inherited from caller. 868c6fd2807SJeff Garzik */ 8690ea9e179SJeff Garzik static int __mv_stop_dma(struct ata_port *ap) 870c6fd2807SJeff Garzik { 871c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 872c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 873c6fd2807SJeff Garzik u32 reg; 874c5d3e45aSJeff Garzik int i, err = 0; 875c6fd2807SJeff Garzik 8764537deb5SJeff Garzik if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 877c6fd2807SJeff Garzik /* Disable EDMA if active. The disable bit auto clears. 878c6fd2807SJeff Garzik */ 879c6fd2807SJeff Garzik writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 880c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 881c6fd2807SJeff Garzik } else { 882c6fd2807SJeff Garzik WARN_ON(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS)); 883c6fd2807SJeff Garzik } 884c6fd2807SJeff Garzik 885c6fd2807SJeff Garzik /* now properly wait for the eDMA to stop */ 886c6fd2807SJeff Garzik for (i = 1000; i > 0; i--) { 887c6fd2807SJeff Garzik reg = readl(port_mmio + EDMA_CMD_OFS); 8884537deb5SJeff Garzik if (!(reg & EDMA_EN)) 889c6fd2807SJeff Garzik break; 8904537deb5SJeff Garzik 891c6fd2807SJeff Garzik udelay(100); 892c6fd2807SJeff Garzik } 893c6fd2807SJeff Garzik 894c5d3e45aSJeff Garzik if (reg & EDMA_EN) { 895c6fd2807SJeff Garzik ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n"); 896c5d3e45aSJeff Garzik err = -EIO; 897c6fd2807SJeff Garzik } 898c5d3e45aSJeff Garzik 899c5d3e45aSJeff Garzik return err; 900c6fd2807SJeff Garzik } 901c6fd2807SJeff Garzik 9020ea9e179SJeff Garzik static int mv_stop_dma(struct ata_port *ap) 9030ea9e179SJeff Garzik { 9040ea9e179SJeff Garzik unsigned long flags; 9050ea9e179SJeff Garzik int rc; 9060ea9e179SJeff Garzik 9070ea9e179SJeff Garzik spin_lock_irqsave(&ap->host->lock, flags); 9080ea9e179SJeff Garzik rc = __mv_stop_dma(ap); 9090ea9e179SJeff Garzik spin_unlock_irqrestore(&ap->host->lock, flags); 9100ea9e179SJeff Garzik 9110ea9e179SJeff Garzik return rc; 9120ea9e179SJeff Garzik } 9130ea9e179SJeff Garzik 914c6fd2807SJeff Garzik #ifdef ATA_DEBUG 915c6fd2807SJeff Garzik static void mv_dump_mem(void __iomem *start, unsigned bytes) 916c6fd2807SJeff Garzik { 917c6fd2807SJeff Garzik int b, w; 918c6fd2807SJeff Garzik for (b = 0; b < bytes; ) { 919c6fd2807SJeff Garzik DPRINTK("%p: ", start + b); 920c6fd2807SJeff Garzik for (w = 0; b < bytes && w < 4; w++) { 921c6fd2807SJeff Garzik printk("%08x ", readl(start + b)); 922c6fd2807SJeff Garzik b += sizeof(u32); 923c6fd2807SJeff Garzik } 924c6fd2807SJeff Garzik printk("\n"); 925c6fd2807SJeff Garzik } 926c6fd2807SJeff Garzik } 927c6fd2807SJeff Garzik #endif 928c6fd2807SJeff Garzik 929c6fd2807SJeff Garzik static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes) 930c6fd2807SJeff Garzik { 931c6fd2807SJeff Garzik #ifdef ATA_DEBUG 932c6fd2807SJeff Garzik int b, w; 933c6fd2807SJeff Garzik u32 dw; 934c6fd2807SJeff Garzik for (b = 0; b < bytes; ) { 935c6fd2807SJeff Garzik DPRINTK("%02x: ", b); 936c6fd2807SJeff Garzik for (w = 0; b < bytes && w < 4; w++) { 937c6fd2807SJeff Garzik (void) pci_read_config_dword(pdev, b, &dw); 938c6fd2807SJeff Garzik printk("%08x ", dw); 939c6fd2807SJeff Garzik b += sizeof(u32); 940c6fd2807SJeff Garzik } 941c6fd2807SJeff Garzik printk("\n"); 942c6fd2807SJeff Garzik } 943c6fd2807SJeff Garzik #endif 944c6fd2807SJeff Garzik } 945c6fd2807SJeff Garzik static void mv_dump_all_regs(void __iomem *mmio_base, int port, 946c6fd2807SJeff Garzik struct pci_dev *pdev) 947c6fd2807SJeff Garzik { 948c6fd2807SJeff Garzik #ifdef ATA_DEBUG 949c6fd2807SJeff Garzik void __iomem *hc_base = mv_hc_base(mmio_base, 950c6fd2807SJeff Garzik port >> MV_PORT_HC_SHIFT); 951c6fd2807SJeff Garzik void __iomem *port_base; 952c6fd2807SJeff Garzik int start_port, num_ports, p, start_hc, num_hcs, hc; 953c6fd2807SJeff Garzik 954c6fd2807SJeff Garzik if (0 > port) { 955c6fd2807SJeff Garzik start_hc = start_port = 0; 956c6fd2807SJeff Garzik num_ports = 8; /* shld be benign for 4 port devs */ 957c6fd2807SJeff Garzik num_hcs = 2; 958c6fd2807SJeff Garzik } else { 959c6fd2807SJeff Garzik start_hc = port >> MV_PORT_HC_SHIFT; 960c6fd2807SJeff Garzik start_port = port; 961c6fd2807SJeff Garzik num_ports = num_hcs = 1; 962c6fd2807SJeff Garzik } 963c6fd2807SJeff Garzik DPRINTK("All registers for port(s) %u-%u:\n", start_port, 964c6fd2807SJeff Garzik num_ports > 1 ? num_ports - 1 : start_port); 965c6fd2807SJeff Garzik 966c6fd2807SJeff Garzik if (NULL != pdev) { 967c6fd2807SJeff Garzik DPRINTK("PCI config space regs:\n"); 968c6fd2807SJeff Garzik mv_dump_pci_cfg(pdev, 0x68); 969c6fd2807SJeff Garzik } 970c6fd2807SJeff Garzik DPRINTK("PCI regs:\n"); 971c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xc00, 0x3c); 972c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xd00, 0x34); 973c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xf00, 0x4); 974c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0x1d00, 0x6c); 975c6fd2807SJeff Garzik for (hc = start_hc; hc < start_hc + num_hcs; hc++) { 976c6fd2807SJeff Garzik hc_base = mv_hc_base(mmio_base, hc); 977c6fd2807SJeff Garzik DPRINTK("HC regs (HC %i):\n", hc); 978c6fd2807SJeff Garzik mv_dump_mem(hc_base, 0x1c); 979c6fd2807SJeff Garzik } 980c6fd2807SJeff Garzik for (p = start_port; p < start_port + num_ports; p++) { 981c6fd2807SJeff Garzik port_base = mv_port_base(mmio_base, p); 982c6fd2807SJeff Garzik DPRINTK("EDMA regs (port %i):\n", p); 983c6fd2807SJeff Garzik mv_dump_mem(port_base, 0x54); 984c6fd2807SJeff Garzik DPRINTK("SATA regs (port %i):\n", p); 985c6fd2807SJeff Garzik mv_dump_mem(port_base+0x300, 0x60); 986c6fd2807SJeff Garzik } 987c6fd2807SJeff Garzik #endif 988c6fd2807SJeff Garzik } 989c6fd2807SJeff Garzik 990c6fd2807SJeff Garzik static unsigned int mv_scr_offset(unsigned int sc_reg_in) 991c6fd2807SJeff Garzik { 992c6fd2807SJeff Garzik unsigned int ofs; 993c6fd2807SJeff Garzik 994c6fd2807SJeff Garzik switch (sc_reg_in) { 995c6fd2807SJeff Garzik case SCR_STATUS: 996c6fd2807SJeff Garzik case SCR_CONTROL: 997c6fd2807SJeff Garzik case SCR_ERROR: 998c6fd2807SJeff Garzik ofs = SATA_STATUS_OFS + (sc_reg_in * sizeof(u32)); 999c6fd2807SJeff Garzik break; 1000c6fd2807SJeff Garzik case SCR_ACTIVE: 1001c6fd2807SJeff Garzik ofs = SATA_ACTIVE_OFS; /* active is not with the others */ 1002c6fd2807SJeff Garzik break; 1003c6fd2807SJeff Garzik default: 1004c6fd2807SJeff Garzik ofs = 0xffffffffU; 1005c6fd2807SJeff Garzik break; 1006c6fd2807SJeff Garzik } 1007c6fd2807SJeff Garzik return ofs; 1008c6fd2807SJeff Garzik } 1009c6fd2807SJeff Garzik 1010da3dbb17STejun Heo static int mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val) 1011c6fd2807SJeff Garzik { 1012c6fd2807SJeff Garzik unsigned int ofs = mv_scr_offset(sc_reg_in); 1013c6fd2807SJeff Garzik 1014da3dbb17STejun Heo if (ofs != 0xffffffffU) { 1015da3dbb17STejun Heo *val = readl(mv_ap_base(ap) + ofs); 1016da3dbb17STejun Heo return 0; 1017da3dbb17STejun Heo } else 1018da3dbb17STejun Heo return -EINVAL; 1019c6fd2807SJeff Garzik } 1020c6fd2807SJeff Garzik 1021da3dbb17STejun Heo static int mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 1022c6fd2807SJeff Garzik { 1023c6fd2807SJeff Garzik unsigned int ofs = mv_scr_offset(sc_reg_in); 1024c6fd2807SJeff Garzik 1025da3dbb17STejun Heo if (ofs != 0xffffffffU) { 1026c6fd2807SJeff Garzik writelfl(val, mv_ap_base(ap) + ofs); 1027da3dbb17STejun Heo return 0; 1028da3dbb17STejun Heo } else 1029da3dbb17STejun Heo return -EINVAL; 1030c6fd2807SJeff Garzik } 1031c6fd2807SJeff Garzik 1032f273827eSMark Lord static void mv6_dev_config(struct ata_device *adev) 1033f273827eSMark Lord { 1034f273827eSMark Lord /* 1035f273827eSMark Lord * We don't have hob_nsect when doing NCQ commands on Gen-II. 1036f273827eSMark Lord * See mv_qc_prep() for more info. 1037f273827eSMark Lord */ 1038f273827eSMark Lord if (adev->flags & ATA_DFLAG_NCQ) 1039f273827eSMark Lord if (adev->max_sectors > ATA_MAX_SECTORS) 1040f273827eSMark Lord adev->max_sectors = ATA_MAX_SECTORS; 1041f273827eSMark Lord } 1042f273827eSMark Lord 104372109168SMark Lord static void mv_edma_cfg(struct mv_port_priv *pp, struct mv_host_priv *hpriv, 104472109168SMark Lord void __iomem *port_mmio, int want_ncq) 1045c6fd2807SJeff Garzik { 10460c58912eSMark Lord u32 cfg; 1047c6fd2807SJeff Garzik 1048c6fd2807SJeff Garzik /* set up non-NCQ EDMA configuration */ 10490c58912eSMark Lord cfg = EDMA_CFG_Q_DEPTH; /* always 0x1f for *all* chips */ 1050c6fd2807SJeff Garzik 10510c58912eSMark Lord if (IS_GEN_I(hpriv)) 1052c6fd2807SJeff Garzik cfg |= (1 << 8); /* enab config burst size mask */ 1053c6fd2807SJeff Garzik 10540c58912eSMark Lord else if (IS_GEN_II(hpriv)) 1055c6fd2807SJeff Garzik cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN; 1056c6fd2807SJeff Garzik 1057c6fd2807SJeff Garzik else if (IS_GEN_IIE(hpriv)) { 1058e728eabeSJeff Garzik cfg |= (1 << 23); /* do not mask PM field in rx'd FIS */ 1059e728eabeSJeff Garzik cfg |= (1 << 22); /* enab 4-entry host queue cache */ 1060c6fd2807SJeff Garzik cfg |= (1 << 18); /* enab early completion */ 1061e728eabeSJeff Garzik cfg |= (1 << 17); /* enab cut-through (dis stor&forwrd) */ 1062c6fd2807SJeff Garzik } 1063c6fd2807SJeff Garzik 106472109168SMark Lord if (want_ncq) { 106572109168SMark Lord cfg |= EDMA_CFG_NCQ; 106672109168SMark Lord pp->pp_flags |= MV_PP_FLAG_NCQ_EN; 106772109168SMark Lord } else 106872109168SMark Lord pp->pp_flags &= ~MV_PP_FLAG_NCQ_EN; 106972109168SMark Lord 1070c6fd2807SJeff Garzik writelfl(cfg, port_mmio + EDMA_CFG_OFS); 1071c6fd2807SJeff Garzik } 1072c6fd2807SJeff Garzik 1073da2fa9baSMark Lord static void mv_port_free_dma_mem(struct ata_port *ap) 1074da2fa9baSMark Lord { 1075da2fa9baSMark Lord struct mv_host_priv *hpriv = ap->host->private_data; 1076da2fa9baSMark Lord struct mv_port_priv *pp = ap->private_data; 1077eb73d558SMark Lord int tag; 1078da2fa9baSMark Lord 1079da2fa9baSMark Lord if (pp->crqb) { 1080da2fa9baSMark Lord dma_pool_free(hpriv->crqb_pool, pp->crqb, pp->crqb_dma); 1081da2fa9baSMark Lord pp->crqb = NULL; 1082da2fa9baSMark Lord } 1083da2fa9baSMark Lord if (pp->crpb) { 1084da2fa9baSMark Lord dma_pool_free(hpriv->crpb_pool, pp->crpb, pp->crpb_dma); 1085da2fa9baSMark Lord pp->crpb = NULL; 1086da2fa9baSMark Lord } 1087eb73d558SMark Lord /* 1088eb73d558SMark Lord * For GEN_I, there's no NCQ, so we have only a single sg_tbl. 1089eb73d558SMark Lord * For later hardware, we have one unique sg_tbl per NCQ tag. 1090eb73d558SMark Lord */ 1091eb73d558SMark Lord for (tag = 0; tag < MV_MAX_Q_DEPTH; ++tag) { 1092eb73d558SMark Lord if (pp->sg_tbl[tag]) { 1093eb73d558SMark Lord if (tag == 0 || !IS_GEN_I(hpriv)) 1094eb73d558SMark Lord dma_pool_free(hpriv->sg_tbl_pool, 1095eb73d558SMark Lord pp->sg_tbl[tag], 1096eb73d558SMark Lord pp->sg_tbl_dma[tag]); 1097eb73d558SMark Lord pp->sg_tbl[tag] = NULL; 1098eb73d558SMark Lord } 1099da2fa9baSMark Lord } 1100da2fa9baSMark Lord } 1101da2fa9baSMark Lord 1102c6fd2807SJeff Garzik /** 1103c6fd2807SJeff Garzik * mv_port_start - Port specific init/start routine. 1104c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1105c6fd2807SJeff Garzik * 1106c6fd2807SJeff Garzik * Allocate and point to DMA memory, init port private memory, 1107c6fd2807SJeff Garzik * zero indices. 1108c6fd2807SJeff Garzik * 1109c6fd2807SJeff Garzik * LOCKING: 1110c6fd2807SJeff Garzik * Inherited from caller. 1111c6fd2807SJeff Garzik */ 1112c6fd2807SJeff Garzik static int mv_port_start(struct ata_port *ap) 1113c6fd2807SJeff Garzik { 1114cca3974eSJeff Garzik struct device *dev = ap->host->dev; 1115cca3974eSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1116c6fd2807SJeff Garzik struct mv_port_priv *pp; 1117c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 11180ea9e179SJeff Garzik unsigned long flags; 1119eb73d558SMark Lord int tag, rc; 1120c6fd2807SJeff Garzik 112124dc5f33STejun Heo pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); 1122c6fd2807SJeff Garzik if (!pp) 112324dc5f33STejun Heo return -ENOMEM; 1124da2fa9baSMark Lord ap->private_data = pp; 1125c6fd2807SJeff Garzik 1126c6fd2807SJeff Garzik rc = ata_pad_alloc(ap, dev); 1127c6fd2807SJeff Garzik if (rc) 112824dc5f33STejun Heo return rc; 1129c6fd2807SJeff Garzik 1130da2fa9baSMark Lord pp->crqb = dma_pool_alloc(hpriv->crqb_pool, GFP_KERNEL, &pp->crqb_dma); 1131da2fa9baSMark Lord if (!pp->crqb) 1132da2fa9baSMark Lord return -ENOMEM; 1133da2fa9baSMark Lord memset(pp->crqb, 0, MV_CRQB_Q_SZ); 1134c6fd2807SJeff Garzik 1135da2fa9baSMark Lord pp->crpb = dma_pool_alloc(hpriv->crpb_pool, GFP_KERNEL, &pp->crpb_dma); 1136da2fa9baSMark Lord if (!pp->crpb) 1137da2fa9baSMark Lord goto out_port_free_dma_mem; 1138da2fa9baSMark Lord memset(pp->crpb, 0, MV_CRPB_Q_SZ); 1139c6fd2807SJeff Garzik 1140eb73d558SMark Lord /* 1141eb73d558SMark Lord * For GEN_I, there's no NCQ, so we only allocate a single sg_tbl. 1142eb73d558SMark Lord * For later hardware, we need one unique sg_tbl per NCQ tag. 1143eb73d558SMark Lord */ 1144eb73d558SMark Lord for (tag = 0; tag < MV_MAX_Q_DEPTH; ++tag) { 1145eb73d558SMark Lord if (tag == 0 || !IS_GEN_I(hpriv)) { 1146eb73d558SMark Lord pp->sg_tbl[tag] = dma_pool_alloc(hpriv->sg_tbl_pool, 1147eb73d558SMark Lord GFP_KERNEL, &pp->sg_tbl_dma[tag]); 1148eb73d558SMark Lord if (!pp->sg_tbl[tag]) 1149da2fa9baSMark Lord goto out_port_free_dma_mem; 1150eb73d558SMark Lord } else { 1151eb73d558SMark Lord pp->sg_tbl[tag] = pp->sg_tbl[0]; 1152eb73d558SMark Lord pp->sg_tbl_dma[tag] = pp->sg_tbl_dma[0]; 1153eb73d558SMark Lord } 1154eb73d558SMark Lord } 1155c6fd2807SJeff Garzik 11560ea9e179SJeff Garzik spin_lock_irqsave(&ap->host->lock, flags); 11570ea9e179SJeff Garzik 115872109168SMark Lord mv_edma_cfg(pp, hpriv, port_mmio, 0); 1159c5d3e45aSJeff Garzik mv_set_edma_ptrs(port_mmio, hpriv, pp); 1160c6fd2807SJeff Garzik 11610ea9e179SJeff Garzik spin_unlock_irqrestore(&ap->host->lock, flags); 11620ea9e179SJeff Garzik 1163c6fd2807SJeff Garzik /* Don't turn on EDMA here...do it before DMA commands only. Else 1164c6fd2807SJeff Garzik * we'll be unable to send non-data, PIO, etc due to restricted access 1165c6fd2807SJeff Garzik * to shadow regs. 1166c6fd2807SJeff Garzik */ 1167c6fd2807SJeff Garzik return 0; 1168da2fa9baSMark Lord 1169da2fa9baSMark Lord out_port_free_dma_mem: 1170da2fa9baSMark Lord mv_port_free_dma_mem(ap); 1171da2fa9baSMark Lord return -ENOMEM; 1172c6fd2807SJeff Garzik } 1173c6fd2807SJeff Garzik 1174c6fd2807SJeff Garzik /** 1175c6fd2807SJeff Garzik * mv_port_stop - Port specific cleanup/stop routine. 1176c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1177c6fd2807SJeff Garzik * 1178c6fd2807SJeff Garzik * Stop DMA, cleanup port memory. 1179c6fd2807SJeff Garzik * 1180c6fd2807SJeff Garzik * LOCKING: 1181cca3974eSJeff Garzik * This routine uses the host lock to protect the DMA stop. 1182c6fd2807SJeff Garzik */ 1183c6fd2807SJeff Garzik static void mv_port_stop(struct ata_port *ap) 1184c6fd2807SJeff Garzik { 1185c6fd2807SJeff Garzik mv_stop_dma(ap); 1186da2fa9baSMark Lord mv_port_free_dma_mem(ap); 1187c6fd2807SJeff Garzik } 1188c6fd2807SJeff Garzik 1189c6fd2807SJeff Garzik /** 1190c6fd2807SJeff Garzik * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries 1191c6fd2807SJeff Garzik * @qc: queued command whose SG list to source from 1192c6fd2807SJeff Garzik * 1193c6fd2807SJeff Garzik * Populate the SG list and mark the last entry. 1194c6fd2807SJeff Garzik * 1195c6fd2807SJeff Garzik * LOCKING: 1196c6fd2807SJeff Garzik * Inherited from caller. 1197c6fd2807SJeff Garzik */ 11986c08772eSJeff Garzik static void mv_fill_sg(struct ata_queued_cmd *qc) 1199c6fd2807SJeff Garzik { 1200c6fd2807SJeff Garzik struct mv_port_priv *pp = qc->ap->private_data; 1201c6fd2807SJeff Garzik struct scatterlist *sg; 12023be6cbd7SJeff Garzik struct mv_sg *mv_sg, *last_sg = NULL; 1203ff2aeb1eSTejun Heo unsigned int si; 1204c6fd2807SJeff Garzik 1205eb73d558SMark Lord mv_sg = pp->sg_tbl[qc->tag]; 1206ff2aeb1eSTejun Heo for_each_sg(qc->sg, sg, qc->n_elem, si) { 1207d88184fbSJeff Garzik dma_addr_t addr = sg_dma_address(sg); 1208d88184fbSJeff Garzik u32 sg_len = sg_dma_len(sg); 1209c6fd2807SJeff Garzik 12104007b493SOlof Johansson while (sg_len) { 12114007b493SOlof Johansson u32 offset = addr & 0xffff; 12124007b493SOlof Johansson u32 len = sg_len; 12134007b493SOlof Johansson 12144007b493SOlof Johansson if ((offset + sg_len > 0x10000)) 12154007b493SOlof Johansson len = 0x10000 - offset; 12164007b493SOlof Johansson 1217d88184fbSJeff Garzik mv_sg->addr = cpu_to_le32(addr & 0xffffffff); 1218d88184fbSJeff Garzik mv_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16); 12196c08772eSJeff Garzik mv_sg->flags_size = cpu_to_le32(len & 0xffff); 1220c6fd2807SJeff Garzik 12214007b493SOlof Johansson sg_len -= len; 12224007b493SOlof Johansson addr += len; 12234007b493SOlof Johansson 12243be6cbd7SJeff Garzik last_sg = mv_sg; 1225d88184fbSJeff Garzik mv_sg++; 1226c6fd2807SJeff Garzik } 12274007b493SOlof Johansson } 12283be6cbd7SJeff Garzik 12293be6cbd7SJeff Garzik if (likely(last_sg)) 12303be6cbd7SJeff Garzik last_sg->flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL); 1231c6fd2807SJeff Garzik } 1232c6fd2807SJeff Garzik 12335796d1c4SJeff Garzik static void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last) 1234c6fd2807SJeff Garzik { 1235c6fd2807SJeff Garzik u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS | 1236c6fd2807SJeff Garzik (last ? CRQB_CMD_LAST : 0); 1237c6fd2807SJeff Garzik *cmdw = cpu_to_le16(tmp); 1238c6fd2807SJeff Garzik } 1239c6fd2807SJeff Garzik 1240c6fd2807SJeff Garzik /** 1241c6fd2807SJeff Garzik * mv_qc_prep - Host specific command preparation. 1242c6fd2807SJeff Garzik * @qc: queued command to prepare 1243c6fd2807SJeff Garzik * 1244c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1245c6fd2807SJeff Garzik * if command is not DMA. Else, it handles prep of the CRQB 1246c6fd2807SJeff Garzik * (command request block), does some sanity checking, and calls 1247c6fd2807SJeff Garzik * the SG load routine. 1248c6fd2807SJeff Garzik * 1249c6fd2807SJeff Garzik * LOCKING: 1250c6fd2807SJeff Garzik * Inherited from caller. 1251c6fd2807SJeff Garzik */ 1252c6fd2807SJeff Garzik static void mv_qc_prep(struct ata_queued_cmd *qc) 1253c6fd2807SJeff Garzik { 1254c6fd2807SJeff Garzik struct ata_port *ap = qc->ap; 1255c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1256c6fd2807SJeff Garzik __le16 *cw; 1257c6fd2807SJeff Garzik struct ata_taskfile *tf; 1258c6fd2807SJeff Garzik u16 flags = 0; 1259c6fd2807SJeff Garzik unsigned in_index; 1260c6fd2807SJeff Garzik 1261138bfdd0SMark Lord if ((qc->tf.protocol != ATA_PROT_DMA) && 1262138bfdd0SMark Lord (qc->tf.protocol != ATA_PROT_NCQ)) 1263c6fd2807SJeff Garzik return; 1264c6fd2807SJeff Garzik 1265c6fd2807SJeff Garzik /* Fill in command request block 1266c6fd2807SJeff Garzik */ 1267c6fd2807SJeff Garzik if (!(qc->tf.flags & ATA_TFLAG_WRITE)) 1268c6fd2807SJeff Garzik flags |= CRQB_FLAG_READ; 1269c6fd2807SJeff Garzik WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 1270c6fd2807SJeff Garzik flags |= qc->tag << CRQB_TAG_SHIFT; 1271c6fd2807SJeff Garzik 1272bdd4dddeSJeff Garzik /* get current queue index from software */ 1273bdd4dddeSJeff Garzik in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; 1274c6fd2807SJeff Garzik 1275c6fd2807SJeff Garzik pp->crqb[in_index].sg_addr = 1276eb73d558SMark Lord cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff); 1277c6fd2807SJeff Garzik pp->crqb[in_index].sg_addr_hi = 1278eb73d558SMark Lord cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16); 1279c6fd2807SJeff Garzik pp->crqb[in_index].ctrl_flags = cpu_to_le16(flags); 1280c6fd2807SJeff Garzik 1281c6fd2807SJeff Garzik cw = &pp->crqb[in_index].ata_cmd[0]; 1282c6fd2807SJeff Garzik tf = &qc->tf; 1283c6fd2807SJeff Garzik 1284c6fd2807SJeff Garzik /* Sadly, the CRQB cannot accomodate all registers--there are 1285c6fd2807SJeff Garzik * only 11 bytes...so we must pick and choose required 1286c6fd2807SJeff Garzik * registers based on the command. So, we drop feature and 1287c6fd2807SJeff Garzik * hob_feature for [RW] DMA commands, but they are needed for 1288c6fd2807SJeff Garzik * NCQ. NCQ will drop hob_nsect. 1289c6fd2807SJeff Garzik */ 1290c6fd2807SJeff Garzik switch (tf->command) { 1291c6fd2807SJeff Garzik case ATA_CMD_READ: 1292c6fd2807SJeff Garzik case ATA_CMD_READ_EXT: 1293c6fd2807SJeff Garzik case ATA_CMD_WRITE: 1294c6fd2807SJeff Garzik case ATA_CMD_WRITE_EXT: 1295c6fd2807SJeff Garzik case ATA_CMD_WRITE_FUA_EXT: 1296c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0); 1297c6fd2807SJeff Garzik break; 1298c6fd2807SJeff Garzik case ATA_CMD_FPDMA_READ: 1299c6fd2807SJeff Garzik case ATA_CMD_FPDMA_WRITE: 1300c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0); 1301c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0); 1302c6fd2807SJeff Garzik break; 1303c6fd2807SJeff Garzik default: 1304c6fd2807SJeff Garzik /* The only other commands EDMA supports in non-queued and 1305c6fd2807SJeff Garzik * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none 1306c6fd2807SJeff Garzik * of which are defined/used by Linux. If we get here, this 1307c6fd2807SJeff Garzik * driver needs work. 1308c6fd2807SJeff Garzik * 1309c6fd2807SJeff Garzik * FIXME: modify libata to give qc_prep a return value and 1310c6fd2807SJeff Garzik * return error here. 1311c6fd2807SJeff Garzik */ 1312c6fd2807SJeff Garzik BUG_ON(tf->command); 1313c6fd2807SJeff Garzik break; 1314c6fd2807SJeff Garzik } 1315c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0); 1316c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0); 1317c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0); 1318c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0); 1319c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0); 1320c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0); 1321c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0); 1322c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0); 1323c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */ 1324c6fd2807SJeff Garzik 1325c6fd2807SJeff Garzik if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 1326c6fd2807SJeff Garzik return; 1327c6fd2807SJeff Garzik mv_fill_sg(qc); 1328c6fd2807SJeff Garzik } 1329c6fd2807SJeff Garzik 1330c6fd2807SJeff Garzik /** 1331c6fd2807SJeff Garzik * mv_qc_prep_iie - Host specific command preparation. 1332c6fd2807SJeff Garzik * @qc: queued command to prepare 1333c6fd2807SJeff Garzik * 1334c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1335c6fd2807SJeff Garzik * if command is not DMA. Else, it handles prep of the CRQB 1336c6fd2807SJeff Garzik * (command request block), does some sanity checking, and calls 1337c6fd2807SJeff Garzik * the SG load routine. 1338c6fd2807SJeff Garzik * 1339c6fd2807SJeff Garzik * LOCKING: 1340c6fd2807SJeff Garzik * Inherited from caller. 1341c6fd2807SJeff Garzik */ 1342c6fd2807SJeff Garzik static void mv_qc_prep_iie(struct ata_queued_cmd *qc) 1343c6fd2807SJeff Garzik { 1344c6fd2807SJeff Garzik struct ata_port *ap = qc->ap; 1345c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1346c6fd2807SJeff Garzik struct mv_crqb_iie *crqb; 1347c6fd2807SJeff Garzik struct ata_taskfile *tf; 1348c6fd2807SJeff Garzik unsigned in_index; 1349c6fd2807SJeff Garzik u32 flags = 0; 1350c6fd2807SJeff Garzik 1351138bfdd0SMark Lord if ((qc->tf.protocol != ATA_PROT_DMA) && 1352138bfdd0SMark Lord (qc->tf.protocol != ATA_PROT_NCQ)) 1353c6fd2807SJeff Garzik return; 1354c6fd2807SJeff Garzik 1355c6fd2807SJeff Garzik /* Fill in Gen IIE command request block 1356c6fd2807SJeff Garzik */ 1357c6fd2807SJeff Garzik if (!(qc->tf.flags & ATA_TFLAG_WRITE)) 1358c6fd2807SJeff Garzik flags |= CRQB_FLAG_READ; 1359c6fd2807SJeff Garzik 1360c6fd2807SJeff Garzik WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 1361c6fd2807SJeff Garzik flags |= qc->tag << CRQB_TAG_SHIFT; 13628c0aeb4aSMark Lord flags |= qc->tag << CRQB_HOSTQ_SHIFT; 1363c6fd2807SJeff Garzik 1364bdd4dddeSJeff Garzik /* get current queue index from software */ 1365bdd4dddeSJeff Garzik in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; 1366c6fd2807SJeff Garzik 1367c6fd2807SJeff Garzik crqb = (struct mv_crqb_iie *) &pp->crqb[in_index]; 1368eb73d558SMark Lord crqb->addr = cpu_to_le32(pp->sg_tbl_dma[qc->tag] & 0xffffffff); 1369eb73d558SMark Lord crqb->addr_hi = cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16); 1370c6fd2807SJeff Garzik crqb->flags = cpu_to_le32(flags); 1371c6fd2807SJeff Garzik 1372c6fd2807SJeff Garzik tf = &qc->tf; 1373c6fd2807SJeff Garzik crqb->ata_cmd[0] = cpu_to_le32( 1374c6fd2807SJeff Garzik (tf->command << 16) | 1375c6fd2807SJeff Garzik (tf->feature << 24) 1376c6fd2807SJeff Garzik ); 1377c6fd2807SJeff Garzik crqb->ata_cmd[1] = cpu_to_le32( 1378c6fd2807SJeff Garzik (tf->lbal << 0) | 1379c6fd2807SJeff Garzik (tf->lbam << 8) | 1380c6fd2807SJeff Garzik (tf->lbah << 16) | 1381c6fd2807SJeff Garzik (tf->device << 24) 1382c6fd2807SJeff Garzik ); 1383c6fd2807SJeff Garzik crqb->ata_cmd[2] = cpu_to_le32( 1384c6fd2807SJeff Garzik (tf->hob_lbal << 0) | 1385c6fd2807SJeff Garzik (tf->hob_lbam << 8) | 1386c6fd2807SJeff Garzik (tf->hob_lbah << 16) | 1387c6fd2807SJeff Garzik (tf->hob_feature << 24) 1388c6fd2807SJeff Garzik ); 1389c6fd2807SJeff Garzik crqb->ata_cmd[3] = cpu_to_le32( 1390c6fd2807SJeff Garzik (tf->nsect << 0) | 1391c6fd2807SJeff Garzik (tf->hob_nsect << 8) 1392c6fd2807SJeff Garzik ); 1393c6fd2807SJeff Garzik 1394c6fd2807SJeff Garzik if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 1395c6fd2807SJeff Garzik return; 1396c6fd2807SJeff Garzik mv_fill_sg(qc); 1397c6fd2807SJeff Garzik } 1398c6fd2807SJeff Garzik 1399c6fd2807SJeff Garzik /** 1400c6fd2807SJeff Garzik * mv_qc_issue - Initiate a command to the host 1401c6fd2807SJeff Garzik * @qc: queued command to start 1402c6fd2807SJeff Garzik * 1403c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1404c6fd2807SJeff Garzik * if command is not DMA. Else, it sanity checks our local 1405c6fd2807SJeff Garzik * caches of the request producer/consumer indices then enables 1406c6fd2807SJeff Garzik * DMA and bumps the request producer index. 1407c6fd2807SJeff Garzik * 1408c6fd2807SJeff Garzik * LOCKING: 1409c6fd2807SJeff Garzik * Inherited from caller. 1410c6fd2807SJeff Garzik */ 1411c6fd2807SJeff Garzik static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) 1412c6fd2807SJeff Garzik { 1413c5d3e45aSJeff Garzik struct ata_port *ap = qc->ap; 1414c5d3e45aSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1415c5d3e45aSJeff Garzik struct mv_port_priv *pp = ap->private_data; 1416bdd4dddeSJeff Garzik u32 in_index; 1417c6fd2807SJeff Garzik 1418138bfdd0SMark Lord if ((qc->tf.protocol != ATA_PROT_DMA) && 1419138bfdd0SMark Lord (qc->tf.protocol != ATA_PROT_NCQ)) { 1420c6fd2807SJeff Garzik /* We're about to send a non-EDMA capable command to the 1421c6fd2807SJeff Garzik * port. Turn off EDMA so there won't be problems accessing 1422c6fd2807SJeff Garzik * shadow block, etc registers. 1423c6fd2807SJeff Garzik */ 14240ea9e179SJeff Garzik __mv_stop_dma(ap); 1425c6fd2807SJeff Garzik return ata_qc_issue_prot(qc); 1426c6fd2807SJeff Garzik } 1427c6fd2807SJeff Garzik 142872109168SMark Lord mv_start_dma(ap, port_mmio, pp, qc->tf.protocol); 1429bdd4dddeSJeff Garzik 1430bdd4dddeSJeff Garzik pp->req_idx++; 1431c6fd2807SJeff Garzik 1432bdd4dddeSJeff Garzik in_index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT; 1433c6fd2807SJeff Garzik 1434c6fd2807SJeff Garzik /* and write the request in pointer to kick the EDMA to life */ 1435bdd4dddeSJeff Garzik writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index, 1436bdd4dddeSJeff Garzik port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 1437c6fd2807SJeff Garzik 1438c6fd2807SJeff Garzik return 0; 1439c6fd2807SJeff Garzik } 1440c6fd2807SJeff Garzik 1441c6fd2807SJeff Garzik /** 1442c6fd2807SJeff Garzik * mv_err_intr - Handle error interrupts on the port 1443c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1444c6fd2807SJeff Garzik * @reset_allowed: bool: 0 == don't trigger from reset here 1445c6fd2807SJeff Garzik * 1446c6fd2807SJeff Garzik * In most cases, just clear the interrupt and move on. However, 1447c6fd2807SJeff Garzik * some cases require an eDMA reset, which is done right before 1448c6fd2807SJeff Garzik * the COMRESET in mv_phy_reset(). The SERR case requires a 1449c6fd2807SJeff Garzik * clear of pending errors in the SATA SERROR register. Finally, 1450c6fd2807SJeff Garzik * if the port disabled DMA, update our cached copy to match. 1451c6fd2807SJeff Garzik * 1452c6fd2807SJeff Garzik * LOCKING: 1453c6fd2807SJeff Garzik * Inherited from caller. 1454c6fd2807SJeff Garzik */ 1455bdd4dddeSJeff Garzik static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc) 1456c6fd2807SJeff Garzik { 1457c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1458bdd4dddeSJeff Garzik u32 edma_err_cause, eh_freeze_mask, serr = 0; 1459bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 1460bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1461bdd4dddeSJeff Garzik unsigned int edma_enabled = (pp->pp_flags & MV_PP_FLAG_EDMA_EN); 1462bdd4dddeSJeff Garzik unsigned int action = 0, err_mask = 0; 14639af5c9c9STejun Heo struct ata_eh_info *ehi = &ap->link.eh_info; 1464c6fd2807SJeff Garzik 1465bdd4dddeSJeff Garzik ata_ehi_clear_desc(ehi); 1466c6fd2807SJeff Garzik 1467bdd4dddeSJeff Garzik if (!edma_enabled) { 1468bdd4dddeSJeff Garzik /* just a guess: do we need to do this? should we 1469bdd4dddeSJeff Garzik * expand this, and do it in all cases? 1470bdd4dddeSJeff Garzik */ 1471936fd732STejun Heo sata_scr_read(&ap->link, SCR_ERROR, &serr); 1472936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_ERROR, serr); 1473c6fd2807SJeff Garzik } 1474bdd4dddeSJeff Garzik 1475bdd4dddeSJeff Garzik edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1476bdd4dddeSJeff Garzik 1477bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, "edma_err 0x%08x", edma_err_cause); 1478bdd4dddeSJeff Garzik 1479bdd4dddeSJeff Garzik /* 1480bdd4dddeSJeff Garzik * all generations share these EDMA error cause bits 1481bdd4dddeSJeff Garzik */ 1482bdd4dddeSJeff Garzik 1483bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_DEV) 1484bdd4dddeSJeff Garzik err_mask |= AC_ERR_DEV; 1485bdd4dddeSJeff Garzik if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | 14866c1153e0SJeff Garzik EDMA_ERR_CRQB_PAR | EDMA_ERR_CRPB_PAR | 1487bdd4dddeSJeff Garzik EDMA_ERR_INTRL_PAR)) { 1488bdd4dddeSJeff Garzik err_mask |= AC_ERR_ATA_BUS; 1489bdd4dddeSJeff Garzik action |= ATA_EH_HARDRESET; 1490b64bbc39STejun Heo ata_ehi_push_desc(ehi, "parity error"); 1491bdd4dddeSJeff Garzik } 1492bdd4dddeSJeff Garzik if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) { 1493bdd4dddeSJeff Garzik ata_ehi_hotplugged(ehi); 1494bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ? 1495b64bbc39STejun Heo "dev disconnect" : "dev connect"); 14963606a380SMark Lord action |= ATA_EH_HARDRESET; 1497bdd4dddeSJeff Garzik } 1498bdd4dddeSJeff Garzik 1499ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) { 1500bdd4dddeSJeff Garzik eh_freeze_mask = EDMA_EH_FREEZE_5; 1501bdd4dddeSJeff Garzik 1502bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SELF_DIS_5) { 1503c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1504c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1505b64bbc39STejun Heo ata_ehi_push_desc(ehi, "EDMA self-disable"); 1506c6fd2807SJeff Garzik } 1507bdd4dddeSJeff Garzik } else { 1508bdd4dddeSJeff Garzik eh_freeze_mask = EDMA_EH_FREEZE; 1509bdd4dddeSJeff Garzik 1510bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SELF_DIS) { 1511bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 1512bdd4dddeSJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1513b64bbc39STejun Heo ata_ehi_push_desc(ehi, "EDMA self-disable"); 1514bdd4dddeSJeff Garzik } 1515bdd4dddeSJeff Garzik 1516bdd4dddeSJeff Garzik if (edma_err_cause & EDMA_ERR_SERR) { 1517936fd732STejun Heo sata_scr_read(&ap->link, SCR_ERROR, &serr); 1518936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_ERROR, serr); 1519bdd4dddeSJeff Garzik err_mask = AC_ERR_ATA_BUS; 1520bdd4dddeSJeff Garzik action |= ATA_EH_HARDRESET; 1521bdd4dddeSJeff Garzik } 1522bdd4dddeSJeff Garzik } 1523c6fd2807SJeff Garzik 1524c6fd2807SJeff Garzik /* Clear EDMA now that SERR cleanup done */ 15253606a380SMark Lord writelfl(~edma_err_cause, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1526c6fd2807SJeff Garzik 1527bdd4dddeSJeff Garzik if (!err_mask) { 1528bdd4dddeSJeff Garzik err_mask = AC_ERR_OTHER; 1529bdd4dddeSJeff Garzik action |= ATA_EH_HARDRESET; 1530bdd4dddeSJeff Garzik } 1531bdd4dddeSJeff Garzik 1532bdd4dddeSJeff Garzik ehi->serror |= serr; 1533bdd4dddeSJeff Garzik ehi->action |= action; 1534bdd4dddeSJeff Garzik 1535bdd4dddeSJeff Garzik if (qc) 1536bdd4dddeSJeff Garzik qc->err_mask |= err_mask; 1537bdd4dddeSJeff Garzik else 1538bdd4dddeSJeff Garzik ehi->err_mask |= err_mask; 1539bdd4dddeSJeff Garzik 1540bdd4dddeSJeff Garzik if (edma_err_cause & eh_freeze_mask) 1541bdd4dddeSJeff Garzik ata_port_freeze(ap); 1542bdd4dddeSJeff Garzik else 1543bdd4dddeSJeff Garzik ata_port_abort(ap); 1544bdd4dddeSJeff Garzik } 1545bdd4dddeSJeff Garzik 1546bdd4dddeSJeff Garzik static void mv_intr_pio(struct ata_port *ap) 1547bdd4dddeSJeff Garzik { 1548bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1549bdd4dddeSJeff Garzik u8 ata_status; 1550bdd4dddeSJeff Garzik 1551bdd4dddeSJeff Garzik /* ignore spurious intr if drive still BUSY */ 1552bdd4dddeSJeff Garzik ata_status = readb(ap->ioaddr.status_addr); 1553bdd4dddeSJeff Garzik if (unlikely(ata_status & ATA_BUSY)) 1554bdd4dddeSJeff Garzik return; 1555bdd4dddeSJeff Garzik 1556bdd4dddeSJeff Garzik /* get active ATA command */ 15579af5c9c9STejun Heo qc = ata_qc_from_tag(ap, ap->link.active_tag); 1558bdd4dddeSJeff Garzik if (unlikely(!qc)) /* no active tag */ 1559bdd4dddeSJeff Garzik return; 1560bdd4dddeSJeff Garzik if (qc->tf.flags & ATA_TFLAG_POLLING) /* polling; we don't own qc */ 1561bdd4dddeSJeff Garzik return; 1562bdd4dddeSJeff Garzik 1563bdd4dddeSJeff Garzik /* and finally, complete the ATA command */ 1564bdd4dddeSJeff Garzik qc->err_mask |= ac_err_mask(ata_status); 1565bdd4dddeSJeff Garzik ata_qc_complete(qc); 1566bdd4dddeSJeff Garzik } 1567bdd4dddeSJeff Garzik 1568bdd4dddeSJeff Garzik static void mv_intr_edma(struct ata_port *ap) 1569bdd4dddeSJeff Garzik { 1570bdd4dddeSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1571bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1572bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 1573bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1574bdd4dddeSJeff Garzik u32 out_index, in_index; 1575bdd4dddeSJeff Garzik bool work_done = false; 1576bdd4dddeSJeff Garzik 1577bdd4dddeSJeff Garzik /* get h/w response queue pointer */ 1578bdd4dddeSJeff Garzik in_index = (readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) 1579bdd4dddeSJeff Garzik >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 1580bdd4dddeSJeff Garzik 1581bdd4dddeSJeff Garzik while (1) { 1582bdd4dddeSJeff Garzik u16 status; 15836c1153e0SJeff Garzik unsigned int tag; 1584bdd4dddeSJeff Garzik 1585bdd4dddeSJeff Garzik /* get s/w response queue last-read pointer, and compare */ 1586bdd4dddeSJeff Garzik out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK; 1587bdd4dddeSJeff Garzik if (in_index == out_index) 1588bdd4dddeSJeff Garzik break; 1589bdd4dddeSJeff Garzik 1590bdd4dddeSJeff Garzik /* 50xx: get active ATA command */ 1591bdd4dddeSJeff Garzik if (IS_GEN_I(hpriv)) 15929af5c9c9STejun Heo tag = ap->link.active_tag; 1593bdd4dddeSJeff Garzik 15946c1153e0SJeff Garzik /* Gen II/IIE: get active ATA command via tag, to enable 15956c1153e0SJeff Garzik * support for queueing. this works transparently for 15966c1153e0SJeff Garzik * queued and non-queued modes. 1597bdd4dddeSJeff Garzik */ 15988c0aeb4aSMark Lord else 15998c0aeb4aSMark Lord tag = le16_to_cpu(pp->crpb[out_index].id) & 0x1f; 1600bdd4dddeSJeff Garzik 1601bdd4dddeSJeff Garzik qc = ata_qc_from_tag(ap, tag); 1602bdd4dddeSJeff Garzik 1603cb924419SMark Lord /* For non-NCQ mode, the lower 8 bits of status 1604cb924419SMark Lord * are from EDMA_ERR_IRQ_CAUSE_OFS, 1605cb924419SMark Lord * which should be zero if all went well. 1606bdd4dddeSJeff Garzik */ 1607bdd4dddeSJeff Garzik status = le16_to_cpu(pp->crpb[out_index].flags); 1608cb924419SMark Lord if ((status & 0xff) && !(pp->pp_flags & MV_PP_FLAG_NCQ_EN)) { 1609bdd4dddeSJeff Garzik mv_err_intr(ap, qc); 1610bdd4dddeSJeff Garzik return; 1611bdd4dddeSJeff Garzik } 1612bdd4dddeSJeff Garzik 1613bdd4dddeSJeff Garzik /* and finally, complete the ATA command */ 1614bdd4dddeSJeff Garzik if (qc) { 1615bdd4dddeSJeff Garzik qc->err_mask |= 1616bdd4dddeSJeff Garzik ac_err_mask(status >> CRPB_FLAG_STATUS_SHIFT); 1617bdd4dddeSJeff Garzik ata_qc_complete(qc); 1618bdd4dddeSJeff Garzik } 1619bdd4dddeSJeff Garzik 1620bdd4dddeSJeff Garzik /* advance software response queue pointer, to 1621bdd4dddeSJeff Garzik * indicate (after the loop completes) to hardware 1622bdd4dddeSJeff Garzik * that we have consumed a response queue entry. 1623bdd4dddeSJeff Garzik */ 1624bdd4dddeSJeff Garzik work_done = true; 1625bdd4dddeSJeff Garzik pp->resp_idx++; 1626bdd4dddeSJeff Garzik } 1627bdd4dddeSJeff Garzik 1628bdd4dddeSJeff Garzik if (work_done) 1629bdd4dddeSJeff Garzik writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | 1630bdd4dddeSJeff Garzik (out_index << EDMA_RSP_Q_PTR_SHIFT), 1631bdd4dddeSJeff Garzik port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 1632c6fd2807SJeff Garzik } 1633c6fd2807SJeff Garzik 1634c6fd2807SJeff Garzik /** 1635c6fd2807SJeff Garzik * mv_host_intr - Handle all interrupts on the given host controller 1636cca3974eSJeff Garzik * @host: host specific structure 1637c6fd2807SJeff Garzik * @relevant: port error bits relevant to this host controller 1638c6fd2807SJeff Garzik * @hc: which host controller we're to look at 1639c6fd2807SJeff Garzik * 1640c6fd2807SJeff Garzik * Read then write clear the HC interrupt status then walk each 1641c6fd2807SJeff Garzik * port connected to the HC and see if it needs servicing. Port 1642c6fd2807SJeff Garzik * success ints are reported in the HC interrupt status reg, the 1643c6fd2807SJeff Garzik * port error ints are reported in the higher level main 1644c6fd2807SJeff Garzik * interrupt status register and thus are passed in via the 1645c6fd2807SJeff Garzik * 'relevant' argument. 1646c6fd2807SJeff Garzik * 1647c6fd2807SJeff Garzik * LOCKING: 1648c6fd2807SJeff Garzik * Inherited from caller. 1649c6fd2807SJeff Garzik */ 1650cca3974eSJeff Garzik static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc) 1651c6fd2807SJeff Garzik { 16520d5ff566STejun Heo void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; 1653c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1654c6fd2807SJeff Garzik u32 hc_irq_cause; 1655c5d3e45aSJeff Garzik int port, port0; 1656c6fd2807SJeff Garzik 165735177265SJeff Garzik if (hc == 0) 1658c6fd2807SJeff Garzik port0 = 0; 165935177265SJeff Garzik else 1660c6fd2807SJeff Garzik port0 = MV_PORTS_PER_HC; 1661c6fd2807SJeff Garzik 1662c6fd2807SJeff Garzik /* we'll need the HC success int register in most cases */ 1663c6fd2807SJeff Garzik hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 1664bdd4dddeSJeff Garzik if (!hc_irq_cause) 1665bdd4dddeSJeff Garzik return; 1666bdd4dddeSJeff Garzik 1667c6fd2807SJeff Garzik writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); 1668c6fd2807SJeff Garzik 1669c6fd2807SJeff Garzik VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n", 1670c6fd2807SJeff Garzik hc, relevant, hc_irq_cause); 1671c6fd2807SJeff Garzik 1672c6fd2807SJeff Garzik for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) { 1673cca3974eSJeff Garzik struct ata_port *ap = host->ports[port]; 1674c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1675bdd4dddeSJeff Garzik int have_err_bits, hard_port, shift; 1676c6fd2807SJeff Garzik 1677bdd4dddeSJeff Garzik if ((!ap) || (ap->flags & ATA_FLAG_DISABLED)) 1678c6fd2807SJeff Garzik continue; 1679c6fd2807SJeff Garzik 1680c6fd2807SJeff Garzik shift = port << 1; /* (port * 2) */ 1681c6fd2807SJeff Garzik if (port >= MV_PORTS_PER_HC) { 1682c6fd2807SJeff Garzik shift++; /* skip bit 8 in the HC Main IRQ reg */ 1683c6fd2807SJeff Garzik } 1684bdd4dddeSJeff Garzik have_err_bits = ((PORT0_ERR << shift) & relevant); 1685bdd4dddeSJeff Garzik 1686bdd4dddeSJeff Garzik if (unlikely(have_err_bits)) { 1687bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1688bdd4dddeSJeff Garzik 16899af5c9c9STejun Heo qc = ata_qc_from_tag(ap, ap->link.active_tag); 1690bdd4dddeSJeff Garzik if (qc && (qc->tf.flags & ATA_TFLAG_POLLING)) 1691bdd4dddeSJeff Garzik continue; 1692bdd4dddeSJeff Garzik 1693bdd4dddeSJeff Garzik mv_err_intr(ap, qc); 1694bdd4dddeSJeff Garzik continue; 1695c6fd2807SJeff Garzik } 1696c6fd2807SJeff Garzik 1697bdd4dddeSJeff Garzik hard_port = mv_hardport_from_port(port); /* range 0..3 */ 1698bdd4dddeSJeff Garzik 1699bdd4dddeSJeff Garzik if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 1700bdd4dddeSJeff Garzik if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) 1701bdd4dddeSJeff Garzik mv_intr_edma(ap); 1702bdd4dddeSJeff Garzik } else { 1703bdd4dddeSJeff Garzik if ((DEV_IRQ << hard_port) & hc_irq_cause) 1704bdd4dddeSJeff Garzik mv_intr_pio(ap); 1705c6fd2807SJeff Garzik } 1706c6fd2807SJeff Garzik } 1707c6fd2807SJeff Garzik VPRINTK("EXIT\n"); 1708c6fd2807SJeff Garzik } 1709c6fd2807SJeff Garzik 1710bdd4dddeSJeff Garzik static void mv_pci_error(struct ata_host *host, void __iomem *mmio) 1711bdd4dddeSJeff Garzik { 171202a121daSMark Lord struct mv_host_priv *hpriv = host->private_data; 1713bdd4dddeSJeff Garzik struct ata_port *ap; 1714bdd4dddeSJeff Garzik struct ata_queued_cmd *qc; 1715bdd4dddeSJeff Garzik struct ata_eh_info *ehi; 1716bdd4dddeSJeff Garzik unsigned int i, err_mask, printed = 0; 1717bdd4dddeSJeff Garzik u32 err_cause; 1718bdd4dddeSJeff Garzik 171902a121daSMark Lord err_cause = readl(mmio + hpriv->irq_cause_ofs); 1720bdd4dddeSJeff Garzik 1721bdd4dddeSJeff Garzik dev_printk(KERN_ERR, host->dev, "PCI ERROR; PCI IRQ cause=0x%08x\n", 1722bdd4dddeSJeff Garzik err_cause); 1723bdd4dddeSJeff Garzik 1724bdd4dddeSJeff Garzik DPRINTK("All regs @ PCI error\n"); 1725bdd4dddeSJeff Garzik mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev)); 1726bdd4dddeSJeff Garzik 172702a121daSMark Lord writelfl(0, mmio + hpriv->irq_cause_ofs); 1728bdd4dddeSJeff Garzik 1729bdd4dddeSJeff Garzik for (i = 0; i < host->n_ports; i++) { 1730bdd4dddeSJeff Garzik ap = host->ports[i]; 1731936fd732STejun Heo if (!ata_link_offline(&ap->link)) { 17329af5c9c9STejun Heo ehi = &ap->link.eh_info; 1733bdd4dddeSJeff Garzik ata_ehi_clear_desc(ehi); 1734bdd4dddeSJeff Garzik if (!printed++) 1735bdd4dddeSJeff Garzik ata_ehi_push_desc(ehi, 1736bdd4dddeSJeff Garzik "PCI err cause 0x%08x", err_cause); 1737bdd4dddeSJeff Garzik err_mask = AC_ERR_HOST_BUS; 1738bdd4dddeSJeff Garzik ehi->action = ATA_EH_HARDRESET; 17399af5c9c9STejun Heo qc = ata_qc_from_tag(ap, ap->link.active_tag); 1740bdd4dddeSJeff Garzik if (qc) 1741bdd4dddeSJeff Garzik qc->err_mask |= err_mask; 1742bdd4dddeSJeff Garzik else 1743bdd4dddeSJeff Garzik ehi->err_mask |= err_mask; 1744bdd4dddeSJeff Garzik 1745bdd4dddeSJeff Garzik ata_port_freeze(ap); 1746bdd4dddeSJeff Garzik } 1747bdd4dddeSJeff Garzik } 1748bdd4dddeSJeff Garzik } 1749bdd4dddeSJeff Garzik 1750c6fd2807SJeff Garzik /** 1751c5d3e45aSJeff Garzik * mv_interrupt - Main interrupt event handler 1752c6fd2807SJeff Garzik * @irq: unused 1753c6fd2807SJeff Garzik * @dev_instance: private data; in this case the host structure 1754c6fd2807SJeff Garzik * 1755c6fd2807SJeff Garzik * Read the read only register to determine if any host 1756c6fd2807SJeff Garzik * controllers have pending interrupts. If so, call lower level 1757c6fd2807SJeff Garzik * routine to handle. Also check for PCI errors which are only 1758c6fd2807SJeff Garzik * reported here. 1759c6fd2807SJeff Garzik * 1760c6fd2807SJeff Garzik * LOCKING: 1761cca3974eSJeff Garzik * This routine holds the host lock while processing pending 1762c6fd2807SJeff Garzik * interrupts. 1763c6fd2807SJeff Garzik */ 17647d12e780SDavid Howells static irqreturn_t mv_interrupt(int irq, void *dev_instance) 1765c6fd2807SJeff Garzik { 1766cca3974eSJeff Garzik struct ata_host *host = dev_instance; 1767c6fd2807SJeff Garzik unsigned int hc, handled = 0, n_hcs; 17680d5ff566STejun Heo void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; 1769646a4da5SMark Lord u32 irq_stat, irq_mask; 1770c6fd2807SJeff Garzik 1771646a4da5SMark Lord spin_lock(&host->lock); 1772c6fd2807SJeff Garzik irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS); 1773646a4da5SMark Lord irq_mask = readl(mmio + HC_MAIN_IRQ_MASK_OFS); 1774c6fd2807SJeff Garzik 1775c6fd2807SJeff Garzik /* check the cases where we either have nothing pending or have read 1776c6fd2807SJeff Garzik * a bogus register value which can indicate HW removal or PCI fault 1777c6fd2807SJeff Garzik */ 1778646a4da5SMark Lord if (!(irq_stat & irq_mask) || (0xffffffffU == irq_stat)) 1779646a4da5SMark Lord goto out_unlock; 1780c6fd2807SJeff Garzik 1781cca3974eSJeff Garzik n_hcs = mv_get_hc_count(host->ports[0]->flags); 1782c6fd2807SJeff Garzik 1783*7bb3c529SSaeed Bishara if (unlikely((irq_stat & PCI_ERR) && HAS_PCI(host))) { 1784bdd4dddeSJeff Garzik mv_pci_error(host, mmio); 1785bdd4dddeSJeff Garzik handled = 1; 1786bdd4dddeSJeff Garzik goto out_unlock; /* skip all other HC irq handling */ 1787bdd4dddeSJeff Garzik } 1788bdd4dddeSJeff Garzik 1789c6fd2807SJeff Garzik for (hc = 0; hc < n_hcs; hc++) { 1790c6fd2807SJeff Garzik u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT)); 1791c6fd2807SJeff Garzik if (relevant) { 1792cca3974eSJeff Garzik mv_host_intr(host, relevant, hc); 1793bdd4dddeSJeff Garzik handled = 1; 1794c6fd2807SJeff Garzik } 1795c6fd2807SJeff Garzik } 1796c6fd2807SJeff Garzik 1797bdd4dddeSJeff Garzik out_unlock: 1798cca3974eSJeff Garzik spin_unlock(&host->lock); 1799c6fd2807SJeff Garzik 1800c6fd2807SJeff Garzik return IRQ_RETVAL(handled); 1801c6fd2807SJeff Garzik } 1802c6fd2807SJeff Garzik 1803c6fd2807SJeff Garzik static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port) 1804c6fd2807SJeff Garzik { 1805c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port); 1806c6fd2807SJeff Garzik unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL; 1807c6fd2807SJeff Garzik 1808c6fd2807SJeff Garzik return hc_mmio + ofs; 1809c6fd2807SJeff Garzik } 1810c6fd2807SJeff Garzik 1811c6fd2807SJeff Garzik static unsigned int mv5_scr_offset(unsigned int sc_reg_in) 1812c6fd2807SJeff Garzik { 1813c6fd2807SJeff Garzik unsigned int ofs; 1814c6fd2807SJeff Garzik 1815c6fd2807SJeff Garzik switch (sc_reg_in) { 1816c6fd2807SJeff Garzik case SCR_STATUS: 1817c6fd2807SJeff Garzik case SCR_ERROR: 1818c6fd2807SJeff Garzik case SCR_CONTROL: 1819c6fd2807SJeff Garzik ofs = sc_reg_in * sizeof(u32); 1820c6fd2807SJeff Garzik break; 1821c6fd2807SJeff Garzik default: 1822c6fd2807SJeff Garzik ofs = 0xffffffffU; 1823c6fd2807SJeff Garzik break; 1824c6fd2807SJeff Garzik } 1825c6fd2807SJeff Garzik return ofs; 1826c6fd2807SJeff Garzik } 1827c6fd2807SJeff Garzik 1828da3dbb17STejun Heo static int mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in, u32 *val) 1829c6fd2807SJeff Garzik { 18300d5ff566STejun Heo void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 18310d5ff566STejun Heo void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 1832c6fd2807SJeff Garzik unsigned int ofs = mv5_scr_offset(sc_reg_in); 1833c6fd2807SJeff Garzik 1834da3dbb17STejun Heo if (ofs != 0xffffffffU) { 1835da3dbb17STejun Heo *val = readl(addr + ofs); 1836da3dbb17STejun Heo return 0; 1837da3dbb17STejun Heo } else 1838da3dbb17STejun Heo return -EINVAL; 1839c6fd2807SJeff Garzik } 1840c6fd2807SJeff Garzik 1841da3dbb17STejun Heo static int mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 1842c6fd2807SJeff Garzik { 18430d5ff566STejun Heo void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 18440d5ff566STejun Heo void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 1845c6fd2807SJeff Garzik unsigned int ofs = mv5_scr_offset(sc_reg_in); 1846c6fd2807SJeff Garzik 1847da3dbb17STejun Heo if (ofs != 0xffffffffU) { 18480d5ff566STejun Heo writelfl(val, addr + ofs); 1849da3dbb17STejun Heo return 0; 1850da3dbb17STejun Heo } else 1851da3dbb17STejun Heo return -EINVAL; 1852c6fd2807SJeff Garzik } 1853c6fd2807SJeff Garzik 1854*7bb3c529SSaeed Bishara static void mv5_reset_bus(struct ata_host *host, void __iomem *mmio) 1855c6fd2807SJeff Garzik { 1856*7bb3c529SSaeed Bishara struct pci_dev *pdev = to_pci_dev(host->dev); 1857c6fd2807SJeff Garzik int early_5080; 1858c6fd2807SJeff Garzik 185944c10138SAuke Kok early_5080 = (pdev->device == 0x5080) && (pdev->revision == 0); 1860c6fd2807SJeff Garzik 1861c6fd2807SJeff Garzik if (!early_5080) { 1862c6fd2807SJeff Garzik u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); 1863c6fd2807SJeff Garzik tmp |= (1 << 0); 1864c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); 1865c6fd2807SJeff Garzik } 1866c6fd2807SJeff Garzik 1867*7bb3c529SSaeed Bishara mv_reset_pci_bus(host, mmio); 1868c6fd2807SJeff Garzik } 1869c6fd2807SJeff Garzik 1870c6fd2807SJeff Garzik static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) 1871c6fd2807SJeff Garzik { 1872c6fd2807SJeff Garzik writel(0x0fcfffff, mmio + MV_FLASH_CTL); 1873c6fd2807SJeff Garzik } 1874c6fd2807SJeff Garzik 1875c6fd2807SJeff Garzik static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, 1876c6fd2807SJeff Garzik void __iomem *mmio) 1877c6fd2807SJeff Garzik { 1878c6fd2807SJeff Garzik void __iomem *phy_mmio = mv5_phy_base(mmio, idx); 1879c6fd2807SJeff Garzik u32 tmp; 1880c6fd2807SJeff Garzik 1881c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_MODE); 1882c6fd2807SJeff Garzik 1883c6fd2807SJeff Garzik hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */ 1884c6fd2807SJeff Garzik hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */ 1885c6fd2807SJeff Garzik } 1886c6fd2807SJeff Garzik 1887c6fd2807SJeff Garzik static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) 1888c6fd2807SJeff Garzik { 1889c6fd2807SJeff Garzik u32 tmp; 1890c6fd2807SJeff Garzik 1891c6fd2807SJeff Garzik writel(0, mmio + MV_GPIO_PORT_CTL); 1892c6fd2807SJeff Garzik 1893c6fd2807SJeff Garzik /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */ 1894c6fd2807SJeff Garzik 1895c6fd2807SJeff Garzik tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); 1896c6fd2807SJeff Garzik tmp |= ~(1 << 0); 1897c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); 1898c6fd2807SJeff Garzik } 1899c6fd2807SJeff Garzik 1900c6fd2807SJeff Garzik static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 1901c6fd2807SJeff Garzik unsigned int port) 1902c6fd2807SJeff Garzik { 1903c6fd2807SJeff Garzik void __iomem *phy_mmio = mv5_phy_base(mmio, port); 1904c6fd2807SJeff Garzik const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5); 1905c6fd2807SJeff Garzik u32 tmp; 1906c6fd2807SJeff Garzik int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0); 1907c6fd2807SJeff Garzik 1908c6fd2807SJeff Garzik if (fix_apm_sq) { 1909c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_LT_MODE); 1910c6fd2807SJeff Garzik tmp |= (1 << 19); 1911c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_LT_MODE); 1912c6fd2807SJeff Garzik 1913c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_CTL); 1914c6fd2807SJeff Garzik tmp &= ~0x3; 1915c6fd2807SJeff Garzik tmp |= 0x1; 1916c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_PHY_CTL); 1917c6fd2807SJeff Garzik } 1918c6fd2807SJeff Garzik 1919c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_MODE); 1920c6fd2807SJeff Garzik tmp &= ~mask; 1921c6fd2807SJeff Garzik tmp |= hpriv->signal[port].pre; 1922c6fd2807SJeff Garzik tmp |= hpriv->signal[port].amps; 1923c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_PHY_MODE); 1924c6fd2807SJeff Garzik } 1925c6fd2807SJeff Garzik 1926c6fd2807SJeff Garzik 1927c6fd2807SJeff Garzik #undef ZERO 1928c6fd2807SJeff Garzik #define ZERO(reg) writel(0, port_mmio + (reg)) 1929c6fd2807SJeff Garzik static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio, 1930c6fd2807SJeff Garzik unsigned int port) 1931c6fd2807SJeff Garzik { 1932c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 1933c6fd2807SJeff Garzik 1934c6fd2807SJeff Garzik writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 1935c6fd2807SJeff Garzik 1936c6fd2807SJeff Garzik mv_channel_reset(hpriv, mmio, port); 1937c6fd2807SJeff Garzik 1938c6fd2807SJeff Garzik ZERO(0x028); /* command */ 1939c6fd2807SJeff Garzik writel(0x11f, port_mmio + EDMA_CFG_OFS); 1940c6fd2807SJeff Garzik ZERO(0x004); /* timer */ 1941c6fd2807SJeff Garzik ZERO(0x008); /* irq err cause */ 1942c6fd2807SJeff Garzik ZERO(0x00c); /* irq err mask */ 1943c6fd2807SJeff Garzik ZERO(0x010); /* rq bah */ 1944c6fd2807SJeff Garzik ZERO(0x014); /* rq inp */ 1945c6fd2807SJeff Garzik ZERO(0x018); /* rq outp */ 1946c6fd2807SJeff Garzik ZERO(0x01c); /* respq bah */ 1947c6fd2807SJeff Garzik ZERO(0x024); /* respq outp */ 1948c6fd2807SJeff Garzik ZERO(0x020); /* respq inp */ 1949c6fd2807SJeff Garzik ZERO(0x02c); /* test control */ 1950c6fd2807SJeff Garzik writel(0xbc, port_mmio + EDMA_IORDY_TMOUT); 1951c6fd2807SJeff Garzik } 1952c6fd2807SJeff Garzik #undef ZERO 1953c6fd2807SJeff Garzik 1954c6fd2807SJeff Garzik #define ZERO(reg) writel(0, hc_mmio + (reg)) 1955c6fd2807SJeff Garzik static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 1956c6fd2807SJeff Garzik unsigned int hc) 1957c6fd2807SJeff Garzik { 1958c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1959c6fd2807SJeff Garzik u32 tmp; 1960c6fd2807SJeff Garzik 1961c6fd2807SJeff Garzik ZERO(0x00c); 1962c6fd2807SJeff Garzik ZERO(0x010); 1963c6fd2807SJeff Garzik ZERO(0x014); 1964c6fd2807SJeff Garzik ZERO(0x018); 1965c6fd2807SJeff Garzik 1966c6fd2807SJeff Garzik tmp = readl(hc_mmio + 0x20); 1967c6fd2807SJeff Garzik tmp &= 0x1c1c1c1c; 1968c6fd2807SJeff Garzik tmp |= 0x03030303; 1969c6fd2807SJeff Garzik writel(tmp, hc_mmio + 0x20); 1970c6fd2807SJeff Garzik } 1971c6fd2807SJeff Garzik #undef ZERO 1972c6fd2807SJeff Garzik 1973c6fd2807SJeff Garzik static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 1974c6fd2807SJeff Garzik unsigned int n_hc) 1975c6fd2807SJeff Garzik { 1976c6fd2807SJeff Garzik unsigned int hc, port; 1977c6fd2807SJeff Garzik 1978c6fd2807SJeff Garzik for (hc = 0; hc < n_hc; hc++) { 1979c6fd2807SJeff Garzik for (port = 0; port < MV_PORTS_PER_HC; port++) 1980c6fd2807SJeff Garzik mv5_reset_hc_port(hpriv, mmio, 1981c6fd2807SJeff Garzik (hc * MV_PORTS_PER_HC) + port); 1982c6fd2807SJeff Garzik 1983c6fd2807SJeff Garzik mv5_reset_one_hc(hpriv, mmio, hc); 1984c6fd2807SJeff Garzik } 1985c6fd2807SJeff Garzik 1986c6fd2807SJeff Garzik return 0; 1987c6fd2807SJeff Garzik } 1988c6fd2807SJeff Garzik 1989c6fd2807SJeff Garzik #undef ZERO 1990c6fd2807SJeff Garzik #define ZERO(reg) writel(0, mmio + (reg)) 1991*7bb3c529SSaeed Bishara static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio) 1992c6fd2807SJeff Garzik { 199302a121daSMark Lord struct mv_host_priv *hpriv = host->private_data; 1994c6fd2807SJeff Garzik u32 tmp; 1995c6fd2807SJeff Garzik 1996c6fd2807SJeff Garzik tmp = readl(mmio + MV_PCI_MODE); 1997c6fd2807SJeff Garzik tmp &= 0xff00ffff; 1998c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_MODE); 1999c6fd2807SJeff Garzik 2000c6fd2807SJeff Garzik ZERO(MV_PCI_DISC_TIMER); 2001c6fd2807SJeff Garzik ZERO(MV_PCI_MSI_TRIGGER); 2002c6fd2807SJeff Garzik writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT); 2003c6fd2807SJeff Garzik ZERO(HC_MAIN_IRQ_MASK_OFS); 2004c6fd2807SJeff Garzik ZERO(MV_PCI_SERR_MASK); 200502a121daSMark Lord ZERO(hpriv->irq_cause_ofs); 200602a121daSMark Lord ZERO(hpriv->irq_mask_ofs); 2007c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_LOW_ADDRESS); 2008c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_HIGH_ADDRESS); 2009c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_ATTRIBUTE); 2010c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_COMMAND); 2011c6fd2807SJeff Garzik } 2012c6fd2807SJeff Garzik #undef ZERO 2013c6fd2807SJeff Garzik 2014c6fd2807SJeff Garzik static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) 2015c6fd2807SJeff Garzik { 2016c6fd2807SJeff Garzik u32 tmp; 2017c6fd2807SJeff Garzik 2018c6fd2807SJeff Garzik mv5_reset_flash(hpriv, mmio); 2019c6fd2807SJeff Garzik 2020c6fd2807SJeff Garzik tmp = readl(mmio + MV_GPIO_PORT_CTL); 2021c6fd2807SJeff Garzik tmp &= 0x3; 2022c6fd2807SJeff Garzik tmp |= (1 << 5) | (1 << 6); 2023c6fd2807SJeff Garzik writel(tmp, mmio + MV_GPIO_PORT_CTL); 2024c6fd2807SJeff Garzik } 2025c6fd2807SJeff Garzik 2026c6fd2807SJeff Garzik /** 2027c6fd2807SJeff Garzik * mv6_reset_hc - Perform the 6xxx global soft reset 2028c6fd2807SJeff Garzik * @mmio: base address of the HBA 2029c6fd2807SJeff Garzik * 2030c6fd2807SJeff Garzik * This routine only applies to 6xxx parts. 2031c6fd2807SJeff Garzik * 2032c6fd2807SJeff Garzik * LOCKING: 2033c6fd2807SJeff Garzik * Inherited from caller. 2034c6fd2807SJeff Garzik */ 2035c6fd2807SJeff Garzik static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 2036c6fd2807SJeff Garzik unsigned int n_hc) 2037c6fd2807SJeff Garzik { 2038c6fd2807SJeff Garzik void __iomem *reg = mmio + PCI_MAIN_CMD_STS_OFS; 2039c6fd2807SJeff Garzik int i, rc = 0; 2040c6fd2807SJeff Garzik u32 t; 2041c6fd2807SJeff Garzik 2042c6fd2807SJeff Garzik /* Following procedure defined in PCI "main command and status 2043c6fd2807SJeff Garzik * register" table. 2044c6fd2807SJeff Garzik */ 2045c6fd2807SJeff Garzik t = readl(reg); 2046c6fd2807SJeff Garzik writel(t | STOP_PCI_MASTER, reg); 2047c6fd2807SJeff Garzik 2048c6fd2807SJeff Garzik for (i = 0; i < 1000; i++) { 2049c6fd2807SJeff Garzik udelay(1); 2050c6fd2807SJeff Garzik t = readl(reg); 20512dcb407eSJeff Garzik if (PCI_MASTER_EMPTY & t) 2052c6fd2807SJeff Garzik break; 2053c6fd2807SJeff Garzik } 2054c6fd2807SJeff Garzik if (!(PCI_MASTER_EMPTY & t)) { 2055c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": PCI master won't flush\n"); 2056c6fd2807SJeff Garzik rc = 1; 2057c6fd2807SJeff Garzik goto done; 2058c6fd2807SJeff Garzik } 2059c6fd2807SJeff Garzik 2060c6fd2807SJeff Garzik /* set reset */ 2061c6fd2807SJeff Garzik i = 5; 2062c6fd2807SJeff Garzik do { 2063c6fd2807SJeff Garzik writel(t | GLOB_SFT_RST, reg); 2064c6fd2807SJeff Garzik t = readl(reg); 2065c6fd2807SJeff Garzik udelay(1); 2066c6fd2807SJeff Garzik } while (!(GLOB_SFT_RST & t) && (i-- > 0)); 2067c6fd2807SJeff Garzik 2068c6fd2807SJeff Garzik if (!(GLOB_SFT_RST & t)) { 2069c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": can't set global reset\n"); 2070c6fd2807SJeff Garzik rc = 1; 2071c6fd2807SJeff Garzik goto done; 2072c6fd2807SJeff Garzik } 2073c6fd2807SJeff Garzik 2074c6fd2807SJeff Garzik /* clear reset and *reenable the PCI master* (not mentioned in spec) */ 2075c6fd2807SJeff Garzik i = 5; 2076c6fd2807SJeff Garzik do { 2077c6fd2807SJeff Garzik writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg); 2078c6fd2807SJeff Garzik t = readl(reg); 2079c6fd2807SJeff Garzik udelay(1); 2080c6fd2807SJeff Garzik } while ((GLOB_SFT_RST & t) && (i-- > 0)); 2081c6fd2807SJeff Garzik 2082c6fd2807SJeff Garzik if (GLOB_SFT_RST & t) { 2083c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": can't clear global reset\n"); 2084c6fd2807SJeff Garzik rc = 1; 2085c6fd2807SJeff Garzik } 2086c6fd2807SJeff Garzik done: 2087c6fd2807SJeff Garzik return rc; 2088c6fd2807SJeff Garzik } 2089c6fd2807SJeff Garzik 2090c6fd2807SJeff Garzik static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, 2091c6fd2807SJeff Garzik void __iomem *mmio) 2092c6fd2807SJeff Garzik { 2093c6fd2807SJeff Garzik void __iomem *port_mmio; 2094c6fd2807SJeff Garzik u32 tmp; 2095c6fd2807SJeff Garzik 2096c6fd2807SJeff Garzik tmp = readl(mmio + MV_RESET_CFG); 2097c6fd2807SJeff Garzik if ((tmp & (1 << 0)) == 0) { 2098c6fd2807SJeff Garzik hpriv->signal[idx].amps = 0x7 << 8; 2099c6fd2807SJeff Garzik hpriv->signal[idx].pre = 0x1 << 5; 2100c6fd2807SJeff Garzik return; 2101c6fd2807SJeff Garzik } 2102c6fd2807SJeff Garzik 2103c6fd2807SJeff Garzik port_mmio = mv_port_base(mmio, idx); 2104c6fd2807SJeff Garzik tmp = readl(port_mmio + PHY_MODE2); 2105c6fd2807SJeff Garzik 2106c6fd2807SJeff Garzik hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */ 2107c6fd2807SJeff Garzik hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */ 2108c6fd2807SJeff Garzik } 2109c6fd2807SJeff Garzik 2110c6fd2807SJeff Garzik static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) 2111c6fd2807SJeff Garzik { 2112c6fd2807SJeff Garzik writel(0x00000060, mmio + MV_GPIO_PORT_CTL); 2113c6fd2807SJeff Garzik } 2114c6fd2807SJeff Garzik 2115c6fd2807SJeff Garzik static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 2116c6fd2807SJeff Garzik unsigned int port) 2117c6fd2807SJeff Garzik { 2118c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2119c6fd2807SJeff Garzik 2120c6fd2807SJeff Garzik u32 hp_flags = hpriv->hp_flags; 2121c6fd2807SJeff Garzik int fix_phy_mode2 = 2122c6fd2807SJeff Garzik hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); 2123c6fd2807SJeff Garzik int fix_phy_mode4 = 2124c6fd2807SJeff Garzik hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); 2125c6fd2807SJeff Garzik u32 m2, tmp; 2126c6fd2807SJeff Garzik 2127c6fd2807SJeff Garzik if (fix_phy_mode2) { 2128c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 2129c6fd2807SJeff Garzik m2 &= ~(1 << 16); 2130c6fd2807SJeff Garzik m2 |= (1 << 31); 2131c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 2132c6fd2807SJeff Garzik 2133c6fd2807SJeff Garzik udelay(200); 2134c6fd2807SJeff Garzik 2135c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 2136c6fd2807SJeff Garzik m2 &= ~((1 << 16) | (1 << 31)); 2137c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 2138c6fd2807SJeff Garzik 2139c6fd2807SJeff Garzik udelay(200); 2140c6fd2807SJeff Garzik } 2141c6fd2807SJeff Garzik 2142c6fd2807SJeff Garzik /* who knows what this magic does */ 2143c6fd2807SJeff Garzik tmp = readl(port_mmio + PHY_MODE3); 2144c6fd2807SJeff Garzik tmp &= ~0x7F800000; 2145c6fd2807SJeff Garzik tmp |= 0x2A800000; 2146c6fd2807SJeff Garzik writel(tmp, port_mmio + PHY_MODE3); 2147c6fd2807SJeff Garzik 2148c6fd2807SJeff Garzik if (fix_phy_mode4) { 2149c6fd2807SJeff Garzik u32 m4; 2150c6fd2807SJeff Garzik 2151c6fd2807SJeff Garzik m4 = readl(port_mmio + PHY_MODE4); 2152c6fd2807SJeff Garzik 2153c6fd2807SJeff Garzik if (hp_flags & MV_HP_ERRATA_60X1B2) 2154c6fd2807SJeff Garzik tmp = readl(port_mmio + 0x310); 2155c6fd2807SJeff Garzik 2156c6fd2807SJeff Garzik m4 = (m4 & ~(1 << 1)) | (1 << 0); 2157c6fd2807SJeff Garzik 2158c6fd2807SJeff Garzik writel(m4, port_mmio + PHY_MODE4); 2159c6fd2807SJeff Garzik 2160c6fd2807SJeff Garzik if (hp_flags & MV_HP_ERRATA_60X1B2) 2161c6fd2807SJeff Garzik writel(tmp, port_mmio + 0x310); 2162c6fd2807SJeff Garzik } 2163c6fd2807SJeff Garzik 2164c6fd2807SJeff Garzik /* Revert values of pre-emphasis and signal amps to the saved ones */ 2165c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 2166c6fd2807SJeff Garzik 2167c6fd2807SJeff Garzik m2 &= ~MV_M2_PREAMP_MASK; 2168c6fd2807SJeff Garzik m2 |= hpriv->signal[port].amps; 2169c6fd2807SJeff Garzik m2 |= hpriv->signal[port].pre; 2170c6fd2807SJeff Garzik m2 &= ~(1 << 16); 2171c6fd2807SJeff Garzik 2172c6fd2807SJeff Garzik /* according to mvSata 3.6.1, some IIE values are fixed */ 2173c6fd2807SJeff Garzik if (IS_GEN_IIE(hpriv)) { 2174c6fd2807SJeff Garzik m2 &= ~0xC30FF01F; 2175c6fd2807SJeff Garzik m2 |= 0x0000900F; 2176c6fd2807SJeff Garzik } 2177c6fd2807SJeff Garzik 2178c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 2179c6fd2807SJeff Garzik } 2180c6fd2807SJeff Garzik 2181c6fd2807SJeff Garzik static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, 2182c6fd2807SJeff Garzik unsigned int port_no) 2183c6fd2807SJeff Garzik { 2184c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port_no); 2185c6fd2807SJeff Garzik 2186c6fd2807SJeff Garzik writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS); 2187c6fd2807SJeff Garzik 2188ee9ccdf7SJeff Garzik if (IS_GEN_II(hpriv)) { 2189c6fd2807SJeff Garzik u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); 2190c6fd2807SJeff Garzik ifctl |= (1 << 7); /* enable gen2i speed */ 2191c6fd2807SJeff Garzik ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ 2192c6fd2807SJeff Garzik writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL); 2193c6fd2807SJeff Garzik } 2194c6fd2807SJeff Garzik 2195c6fd2807SJeff Garzik udelay(25); /* allow reset propagation */ 2196c6fd2807SJeff Garzik 2197c6fd2807SJeff Garzik /* Spec never mentions clearing the bit. Marvell's driver does 2198c6fd2807SJeff Garzik * clear the bit, however. 2199c6fd2807SJeff Garzik */ 2200c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_CMD_OFS); 2201c6fd2807SJeff Garzik 2202c6fd2807SJeff Garzik hpriv->ops->phy_errata(hpriv, mmio, port_no); 2203c6fd2807SJeff Garzik 2204ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) 2205c6fd2807SJeff Garzik mdelay(1); 2206c6fd2807SJeff Garzik } 2207c6fd2807SJeff Garzik 2208c6fd2807SJeff Garzik /** 2209bdd4dddeSJeff Garzik * mv_phy_reset - Perform eDMA reset followed by COMRESET 2210c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 2211c6fd2807SJeff Garzik * 2212c6fd2807SJeff Garzik * Part of this is taken from __sata_phy_reset and modified to 2213c6fd2807SJeff Garzik * not sleep since this routine gets called from interrupt level. 2214c6fd2807SJeff Garzik * 2215c6fd2807SJeff Garzik * LOCKING: 2216c6fd2807SJeff Garzik * Inherited from caller. This is coded to safe to call at 2217c6fd2807SJeff Garzik * interrupt level, i.e. it does not sleep. 2218c6fd2807SJeff Garzik */ 2219bdd4dddeSJeff Garzik static void mv_phy_reset(struct ata_port *ap, unsigned int *class, 2220bdd4dddeSJeff Garzik unsigned long deadline) 2221c6fd2807SJeff Garzik { 2222c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 2223cca3974eSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 2224c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 2225c6fd2807SJeff Garzik int retry = 5; 2226c6fd2807SJeff Garzik u32 sstatus; 2227c6fd2807SJeff Garzik 2228c6fd2807SJeff Garzik VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio); 2229c6fd2807SJeff Garzik 2230da3dbb17STejun Heo #ifdef DEBUG 2231da3dbb17STejun Heo { 2232da3dbb17STejun Heo u32 sstatus, serror, scontrol; 2233da3dbb17STejun Heo 2234da3dbb17STejun Heo mv_scr_read(ap, SCR_STATUS, &sstatus); 2235da3dbb17STejun Heo mv_scr_read(ap, SCR_ERROR, &serror); 2236da3dbb17STejun Heo mv_scr_read(ap, SCR_CONTROL, &scontrol); 2237c6fd2807SJeff Garzik DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x " 22382d79ab8fSSaeed Bishara "SCtrl 0x%08x\n", sstatus, serror, scontrol); 2239da3dbb17STejun Heo } 2240da3dbb17STejun Heo #endif 2241c6fd2807SJeff Garzik 2242c6fd2807SJeff Garzik /* Issue COMRESET via SControl */ 2243c6fd2807SJeff Garzik comreset_retry: 2244936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_CONTROL, 0x301); 2245bdd4dddeSJeff Garzik msleep(1); 2246c6fd2807SJeff Garzik 2247936fd732STejun Heo sata_scr_write_flush(&ap->link, SCR_CONTROL, 0x300); 2248bdd4dddeSJeff Garzik msleep(20); 2249c6fd2807SJeff Garzik 2250c6fd2807SJeff Garzik do { 2251936fd732STejun Heo sata_scr_read(&ap->link, SCR_STATUS, &sstatus); 2252dd1dc802SJeff Garzik if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0)) 2253c6fd2807SJeff Garzik break; 2254c6fd2807SJeff Garzik 2255bdd4dddeSJeff Garzik msleep(1); 2256c5d3e45aSJeff Garzik } while (time_before(jiffies, deadline)); 2257c6fd2807SJeff Garzik 2258c6fd2807SJeff Garzik /* work around errata */ 2259ee9ccdf7SJeff Garzik if (IS_GEN_II(hpriv) && 2260c6fd2807SJeff Garzik (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) && 2261c6fd2807SJeff Garzik (retry-- > 0)) 2262c6fd2807SJeff Garzik goto comreset_retry; 2263c6fd2807SJeff Garzik 2264da3dbb17STejun Heo #ifdef DEBUG 2265da3dbb17STejun Heo { 2266da3dbb17STejun Heo u32 sstatus, serror, scontrol; 2267da3dbb17STejun Heo 2268da3dbb17STejun Heo mv_scr_read(ap, SCR_STATUS, &sstatus); 2269da3dbb17STejun Heo mv_scr_read(ap, SCR_ERROR, &serror); 2270da3dbb17STejun Heo mv_scr_read(ap, SCR_CONTROL, &scontrol); 2271c6fd2807SJeff Garzik DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x " 2272da3dbb17STejun Heo "SCtrl 0x%08x\n", sstatus, serror, scontrol); 2273da3dbb17STejun Heo } 2274da3dbb17STejun Heo #endif 2275c6fd2807SJeff Garzik 2276936fd732STejun Heo if (ata_link_offline(&ap->link)) { 2277bdd4dddeSJeff Garzik *class = ATA_DEV_NONE; 2278c6fd2807SJeff Garzik return; 2279c6fd2807SJeff Garzik } 2280c6fd2807SJeff Garzik 2281c6fd2807SJeff Garzik /* even after SStatus reflects that device is ready, 2282c6fd2807SJeff Garzik * it seems to take a while for link to be fully 2283c6fd2807SJeff Garzik * established (and thus Status no longer 0x80/0x7F), 2284c6fd2807SJeff Garzik * so we poll a bit for that, here. 2285c6fd2807SJeff Garzik */ 2286c6fd2807SJeff Garzik retry = 20; 2287c6fd2807SJeff Garzik while (1) { 2288c6fd2807SJeff Garzik u8 drv_stat = ata_check_status(ap); 2289c6fd2807SJeff Garzik if ((drv_stat != 0x80) && (drv_stat != 0x7f)) 2290c6fd2807SJeff Garzik break; 2291bdd4dddeSJeff Garzik msleep(500); 2292c6fd2807SJeff Garzik if (retry-- <= 0) 2293c6fd2807SJeff Garzik break; 2294bdd4dddeSJeff Garzik if (time_after(jiffies, deadline)) 2295bdd4dddeSJeff Garzik break; 2296c6fd2807SJeff Garzik } 2297c6fd2807SJeff Garzik 2298bdd4dddeSJeff Garzik /* FIXME: if we passed the deadline, the following 2299bdd4dddeSJeff Garzik * code probably produces an invalid result 2300bdd4dddeSJeff Garzik */ 2301c6fd2807SJeff Garzik 2302bdd4dddeSJeff Garzik /* finally, read device signature from TF registers */ 23033f19859eSTejun Heo *class = ata_dev_try_classify(ap->link.device, 1, NULL); 2304c6fd2807SJeff Garzik 2305c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2306c6fd2807SJeff Garzik 2307bdd4dddeSJeff Garzik WARN_ON(pp->pp_flags & MV_PP_FLAG_EDMA_EN); 2308c6fd2807SJeff Garzik 2309c6fd2807SJeff Garzik VPRINTK("EXIT\n"); 2310c6fd2807SJeff Garzik } 2311c6fd2807SJeff Garzik 2312cc0680a5STejun Heo static int mv_prereset(struct ata_link *link, unsigned long deadline) 2313c6fd2807SJeff Garzik { 2314cc0680a5STejun Heo struct ata_port *ap = link->ap; 2315bdd4dddeSJeff Garzik struct mv_port_priv *pp = ap->private_data; 2316cc0680a5STejun Heo struct ata_eh_context *ehc = &link->eh_context; 2317bdd4dddeSJeff Garzik int rc; 2318bdd4dddeSJeff Garzik 2319bdd4dddeSJeff Garzik rc = mv_stop_dma(ap); 2320bdd4dddeSJeff Garzik if (rc) 2321bdd4dddeSJeff Garzik ehc->i.action |= ATA_EH_HARDRESET; 2322bdd4dddeSJeff Garzik 2323bdd4dddeSJeff Garzik if (!(pp->pp_flags & MV_PP_FLAG_HAD_A_RESET)) { 2324bdd4dddeSJeff Garzik pp->pp_flags |= MV_PP_FLAG_HAD_A_RESET; 2325bdd4dddeSJeff Garzik ehc->i.action |= ATA_EH_HARDRESET; 2326c6fd2807SJeff Garzik } 2327c6fd2807SJeff Garzik 2328bdd4dddeSJeff Garzik /* if we're about to do hardreset, nothing more to do */ 2329bdd4dddeSJeff Garzik if (ehc->i.action & ATA_EH_HARDRESET) 2330bdd4dddeSJeff Garzik return 0; 2331bdd4dddeSJeff Garzik 2332cc0680a5STejun Heo if (ata_link_online(link)) 2333bdd4dddeSJeff Garzik rc = ata_wait_ready(ap, deadline); 2334bdd4dddeSJeff Garzik else 2335bdd4dddeSJeff Garzik rc = -ENODEV; 2336bdd4dddeSJeff Garzik 2337bdd4dddeSJeff Garzik return rc; 2338bdd4dddeSJeff Garzik } 2339bdd4dddeSJeff Garzik 2340cc0680a5STejun Heo static int mv_hardreset(struct ata_link *link, unsigned int *class, 2341bdd4dddeSJeff Garzik unsigned long deadline) 2342bdd4dddeSJeff Garzik { 2343cc0680a5STejun Heo struct ata_port *ap = link->ap; 2344bdd4dddeSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 2345bdd4dddeSJeff Garzik void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 2346bdd4dddeSJeff Garzik 2347bdd4dddeSJeff Garzik mv_stop_dma(ap); 2348bdd4dddeSJeff Garzik 2349bdd4dddeSJeff Garzik mv_channel_reset(hpriv, mmio, ap->port_no); 2350bdd4dddeSJeff Garzik 2351bdd4dddeSJeff Garzik mv_phy_reset(ap, class, deadline); 2352bdd4dddeSJeff Garzik 2353bdd4dddeSJeff Garzik return 0; 2354bdd4dddeSJeff Garzik } 2355bdd4dddeSJeff Garzik 2356cc0680a5STejun Heo static void mv_postreset(struct ata_link *link, unsigned int *classes) 2357bdd4dddeSJeff Garzik { 2358cc0680a5STejun Heo struct ata_port *ap = link->ap; 2359bdd4dddeSJeff Garzik u32 serr; 2360bdd4dddeSJeff Garzik 2361bdd4dddeSJeff Garzik /* print link status */ 2362cc0680a5STejun Heo sata_print_link_status(link); 2363bdd4dddeSJeff Garzik 2364bdd4dddeSJeff Garzik /* clear SError */ 2365cc0680a5STejun Heo sata_scr_read(link, SCR_ERROR, &serr); 2366cc0680a5STejun Heo sata_scr_write_flush(link, SCR_ERROR, serr); 2367bdd4dddeSJeff Garzik 2368bdd4dddeSJeff Garzik /* bail out if no device is present */ 2369bdd4dddeSJeff Garzik if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) { 2370bdd4dddeSJeff Garzik DPRINTK("EXIT, no device\n"); 2371bdd4dddeSJeff Garzik return; 2372bdd4dddeSJeff Garzik } 2373bdd4dddeSJeff Garzik 2374bdd4dddeSJeff Garzik /* set up device control */ 2375bdd4dddeSJeff Garzik iowrite8(ap->ctl, ap->ioaddr.ctl_addr); 2376bdd4dddeSJeff Garzik } 2377bdd4dddeSJeff Garzik 2378bdd4dddeSJeff Garzik static void mv_error_handler(struct ata_port *ap) 2379bdd4dddeSJeff Garzik { 2380bdd4dddeSJeff Garzik ata_do_eh(ap, mv_prereset, ata_std_softreset, 2381bdd4dddeSJeff Garzik mv_hardreset, mv_postreset); 2382bdd4dddeSJeff Garzik } 2383bdd4dddeSJeff Garzik 2384bdd4dddeSJeff Garzik static void mv_eh_freeze(struct ata_port *ap) 2385c6fd2807SJeff Garzik { 23860d5ff566STejun Heo void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 2387bdd4dddeSJeff Garzik unsigned int hc = (ap->port_no > 3) ? 1 : 0; 2388bdd4dddeSJeff Garzik u32 tmp, mask; 2389bdd4dddeSJeff Garzik unsigned int shift; 2390c6fd2807SJeff Garzik 2391bdd4dddeSJeff Garzik /* FIXME: handle coalescing completion events properly */ 2392c6fd2807SJeff Garzik 2393bdd4dddeSJeff Garzik shift = ap->port_no * 2; 2394bdd4dddeSJeff Garzik if (hc > 0) 2395bdd4dddeSJeff Garzik shift++; 2396c6fd2807SJeff Garzik 2397bdd4dddeSJeff Garzik mask = 0x3 << shift; 2398c6fd2807SJeff Garzik 2399bdd4dddeSJeff Garzik /* disable assertion of portN err, done events */ 2400bdd4dddeSJeff Garzik tmp = readl(mmio + HC_MAIN_IRQ_MASK_OFS); 2401bdd4dddeSJeff Garzik writelfl(tmp & ~mask, mmio + HC_MAIN_IRQ_MASK_OFS); 2402c6fd2807SJeff Garzik } 2403bdd4dddeSJeff Garzik 2404bdd4dddeSJeff Garzik static void mv_eh_thaw(struct ata_port *ap) 2405bdd4dddeSJeff Garzik { 2406bdd4dddeSJeff Garzik void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 2407bdd4dddeSJeff Garzik unsigned int hc = (ap->port_no > 3) ? 1 : 0; 2408bdd4dddeSJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 2409bdd4dddeSJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 2410bdd4dddeSJeff Garzik u32 tmp, mask, hc_irq_cause; 2411bdd4dddeSJeff Garzik unsigned int shift, hc_port_no = ap->port_no; 2412bdd4dddeSJeff Garzik 2413bdd4dddeSJeff Garzik /* FIXME: handle coalescing completion events properly */ 2414bdd4dddeSJeff Garzik 2415bdd4dddeSJeff Garzik shift = ap->port_no * 2; 2416bdd4dddeSJeff Garzik if (hc > 0) { 2417bdd4dddeSJeff Garzik shift++; 2418bdd4dddeSJeff Garzik hc_port_no -= 4; 2419bdd4dddeSJeff Garzik } 2420bdd4dddeSJeff Garzik 2421bdd4dddeSJeff Garzik mask = 0x3 << shift; 2422bdd4dddeSJeff Garzik 2423bdd4dddeSJeff Garzik /* clear EDMA errors on this port */ 2424bdd4dddeSJeff Garzik writel(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2425bdd4dddeSJeff Garzik 2426bdd4dddeSJeff Garzik /* clear pending irq events */ 2427bdd4dddeSJeff Garzik hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 2428bdd4dddeSJeff Garzik hc_irq_cause &= ~(1 << hc_port_no); /* clear CRPB-done */ 2429bdd4dddeSJeff Garzik hc_irq_cause &= ~(1 << (hc_port_no + 8)); /* clear Device int */ 2430bdd4dddeSJeff Garzik writel(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); 2431bdd4dddeSJeff Garzik 2432bdd4dddeSJeff Garzik /* enable assertion of portN err, done events */ 2433bdd4dddeSJeff Garzik tmp = readl(mmio + HC_MAIN_IRQ_MASK_OFS); 2434bdd4dddeSJeff Garzik writelfl(tmp | mask, mmio + HC_MAIN_IRQ_MASK_OFS); 2435c6fd2807SJeff Garzik } 2436c6fd2807SJeff Garzik 2437c6fd2807SJeff Garzik /** 2438c6fd2807SJeff Garzik * mv_port_init - Perform some early initialization on a single port. 2439c6fd2807SJeff Garzik * @port: libata data structure storing shadow register addresses 2440c6fd2807SJeff Garzik * @port_mmio: base address of the port 2441c6fd2807SJeff Garzik * 2442c6fd2807SJeff Garzik * Initialize shadow register mmio addresses, clear outstanding 2443c6fd2807SJeff Garzik * interrupts on the port, and unmask interrupts for the future 2444c6fd2807SJeff Garzik * start of the port. 2445c6fd2807SJeff Garzik * 2446c6fd2807SJeff Garzik * LOCKING: 2447c6fd2807SJeff Garzik * Inherited from caller. 2448c6fd2807SJeff Garzik */ 2449c6fd2807SJeff Garzik static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio) 2450c6fd2807SJeff Garzik { 24510d5ff566STejun Heo void __iomem *shd_base = port_mmio + SHD_BLK_OFS; 2452c6fd2807SJeff Garzik unsigned serr_ofs; 2453c6fd2807SJeff Garzik 2454c6fd2807SJeff Garzik /* PIO related setup 2455c6fd2807SJeff Garzik */ 2456c6fd2807SJeff Garzik port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA); 2457c6fd2807SJeff Garzik port->error_addr = 2458c6fd2807SJeff Garzik port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR); 2459c6fd2807SJeff Garzik port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT); 2460c6fd2807SJeff Garzik port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL); 2461c6fd2807SJeff Garzik port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM); 2462c6fd2807SJeff Garzik port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH); 2463c6fd2807SJeff Garzik port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE); 2464c6fd2807SJeff Garzik port->status_addr = 2465c6fd2807SJeff Garzik port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS); 2466c6fd2807SJeff Garzik /* special case: control/altstatus doesn't have ATA_REG_ address */ 2467c6fd2807SJeff Garzik port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS; 2468c6fd2807SJeff Garzik 2469c6fd2807SJeff Garzik /* unused: */ 24708d9db2d2SRandy Dunlap port->cmd_addr = port->bmdma_addr = port->scr_addr = NULL; 2471c6fd2807SJeff Garzik 2472c6fd2807SJeff Garzik /* Clear any currently outstanding port interrupt conditions */ 2473c6fd2807SJeff Garzik serr_ofs = mv_scr_offset(SCR_ERROR); 2474c6fd2807SJeff Garzik writelfl(readl(port_mmio + serr_ofs), port_mmio + serr_ofs); 2475c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2476c6fd2807SJeff Garzik 2477646a4da5SMark Lord /* unmask all non-transient EDMA error interrupts */ 2478646a4da5SMark Lord writelfl(~EDMA_ERR_IRQ_TRANSIENT, port_mmio + EDMA_ERR_IRQ_MASK_OFS); 2479c6fd2807SJeff Garzik 2480c6fd2807SJeff Garzik VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n", 2481c6fd2807SJeff Garzik readl(port_mmio + EDMA_CFG_OFS), 2482c6fd2807SJeff Garzik readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS), 2483c6fd2807SJeff Garzik readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS)); 2484c6fd2807SJeff Garzik } 2485c6fd2807SJeff Garzik 24864447d351STejun Heo static int mv_chip_id(struct ata_host *host, unsigned int board_idx) 2487c6fd2807SJeff Garzik { 24884447d351STejun Heo struct pci_dev *pdev = to_pci_dev(host->dev); 24894447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 2490c6fd2807SJeff Garzik u32 hp_flags = hpriv->hp_flags; 2491c6fd2807SJeff Garzik 2492c6fd2807SJeff Garzik switch (board_idx) { 2493c6fd2807SJeff Garzik case chip_5080: 2494c6fd2807SJeff Garzik hpriv->ops = &mv5xxx_ops; 2495ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_I; 2496c6fd2807SJeff Garzik 249744c10138SAuke Kok switch (pdev->revision) { 2498c6fd2807SJeff Garzik case 0x1: 2499c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB0; 2500c6fd2807SJeff Garzik break; 2501c6fd2807SJeff Garzik case 0x3: 2502c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2503c6fd2807SJeff Garzik break; 2504c6fd2807SJeff Garzik default: 2505c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2506c6fd2807SJeff Garzik "Applying 50XXB2 workarounds to unknown rev\n"); 2507c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2508c6fd2807SJeff Garzik break; 2509c6fd2807SJeff Garzik } 2510c6fd2807SJeff Garzik break; 2511c6fd2807SJeff Garzik 2512c6fd2807SJeff Garzik case chip_504x: 2513c6fd2807SJeff Garzik case chip_508x: 2514c6fd2807SJeff Garzik hpriv->ops = &mv5xxx_ops; 2515ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_I; 2516c6fd2807SJeff Garzik 251744c10138SAuke Kok switch (pdev->revision) { 2518c6fd2807SJeff Garzik case 0x0: 2519c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB0; 2520c6fd2807SJeff Garzik break; 2521c6fd2807SJeff Garzik case 0x3: 2522c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2523c6fd2807SJeff Garzik break; 2524c6fd2807SJeff Garzik default: 2525c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2526c6fd2807SJeff Garzik "Applying B2 workarounds to unknown rev\n"); 2527c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2528c6fd2807SJeff Garzik break; 2529c6fd2807SJeff Garzik } 2530c6fd2807SJeff Garzik break; 2531c6fd2807SJeff Garzik 2532c6fd2807SJeff Garzik case chip_604x: 2533c6fd2807SJeff Garzik case chip_608x: 2534c6fd2807SJeff Garzik hpriv->ops = &mv6xxx_ops; 2535ee9ccdf7SJeff Garzik hp_flags |= MV_HP_GEN_II; 2536c6fd2807SJeff Garzik 253744c10138SAuke Kok switch (pdev->revision) { 2538c6fd2807SJeff Garzik case 0x7: 2539c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1B2; 2540c6fd2807SJeff Garzik break; 2541c6fd2807SJeff Garzik case 0x9: 2542c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2543c6fd2807SJeff Garzik break; 2544c6fd2807SJeff Garzik default: 2545c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2546c6fd2807SJeff Garzik "Applying B2 workarounds to unknown rev\n"); 2547c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1B2; 2548c6fd2807SJeff Garzik break; 2549c6fd2807SJeff Garzik } 2550c6fd2807SJeff Garzik break; 2551c6fd2807SJeff Garzik 2552c6fd2807SJeff Garzik case chip_7042: 255302a121daSMark Lord hp_flags |= MV_HP_PCIE; 2554306b30f7SMark Lord if (pdev->vendor == PCI_VENDOR_ID_TTI && 2555306b30f7SMark Lord (pdev->device == 0x2300 || pdev->device == 0x2310)) 2556306b30f7SMark Lord { 25574e520033SMark Lord /* 25584e520033SMark Lord * Highpoint RocketRAID PCIe 23xx series cards: 25594e520033SMark Lord * 25604e520033SMark Lord * Unconfigured drives are treated as "Legacy" 25614e520033SMark Lord * by the BIOS, and it overwrites sector 8 with 25624e520033SMark Lord * a "Lgcy" metadata block prior to Linux boot. 25634e520033SMark Lord * 25644e520033SMark Lord * Configured drives (RAID or JBOD) leave sector 8 25654e520033SMark Lord * alone, but instead overwrite a high numbered 25664e520033SMark Lord * sector for the RAID metadata. This sector can 25674e520033SMark Lord * be determined exactly, by truncating the physical 25684e520033SMark Lord * drive capacity to a nice even GB value. 25694e520033SMark Lord * 25704e520033SMark Lord * RAID metadata is at: (dev->n_sectors & ~0xfffff) 25714e520033SMark Lord * 25724e520033SMark Lord * Warn the user, lest they think we're just buggy. 25734e520033SMark Lord */ 25744e520033SMark Lord printk(KERN_WARNING DRV_NAME ": Highpoint RocketRAID" 25754e520033SMark Lord " BIOS CORRUPTS DATA on all attached drives," 25764e520033SMark Lord " regardless of if/how they are configured." 25774e520033SMark Lord " BEWARE!\n"); 25784e520033SMark Lord printk(KERN_WARNING DRV_NAME ": For data safety, do not" 25794e520033SMark Lord " use sectors 8-9 on \"Legacy\" drives," 25804e520033SMark Lord " and avoid the final two gigabytes on" 25814e520033SMark Lord " all RocketRAID BIOS initialized drives.\n"); 2582306b30f7SMark Lord } 2583c6fd2807SJeff Garzik case chip_6042: 2584c6fd2807SJeff Garzik hpriv->ops = &mv6xxx_ops; 2585c6fd2807SJeff Garzik hp_flags |= MV_HP_GEN_IIE; 2586c6fd2807SJeff Garzik 258744c10138SAuke Kok switch (pdev->revision) { 2588c6fd2807SJeff Garzik case 0x0: 2589c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_XX42A0; 2590c6fd2807SJeff Garzik break; 2591c6fd2807SJeff Garzik case 0x1: 2592c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2593c6fd2807SJeff Garzik break; 2594c6fd2807SJeff Garzik default: 2595c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2596c6fd2807SJeff Garzik "Applying 60X1C0 workarounds to unknown rev\n"); 2597c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2598c6fd2807SJeff Garzik break; 2599c6fd2807SJeff Garzik } 2600c6fd2807SJeff Garzik break; 2601c6fd2807SJeff Garzik 2602c6fd2807SJeff Garzik default: 26035796d1c4SJeff Garzik dev_printk(KERN_ERR, &pdev->dev, 26045796d1c4SJeff Garzik "BUG: invalid board index %u\n", board_idx); 2605c6fd2807SJeff Garzik return 1; 2606c6fd2807SJeff Garzik } 2607c6fd2807SJeff Garzik 2608c6fd2807SJeff Garzik hpriv->hp_flags = hp_flags; 260902a121daSMark Lord if (hp_flags & MV_HP_PCIE) { 261002a121daSMark Lord hpriv->irq_cause_ofs = PCIE_IRQ_CAUSE_OFS; 261102a121daSMark Lord hpriv->irq_mask_ofs = PCIE_IRQ_MASK_OFS; 261202a121daSMark Lord hpriv->unmask_all_irqs = PCIE_UNMASK_ALL_IRQS; 261302a121daSMark Lord } else { 261402a121daSMark Lord hpriv->irq_cause_ofs = PCI_IRQ_CAUSE_OFS; 261502a121daSMark Lord hpriv->irq_mask_ofs = PCI_IRQ_MASK_OFS; 261602a121daSMark Lord hpriv->unmask_all_irqs = PCI_UNMASK_ALL_IRQS; 261702a121daSMark Lord } 2618c6fd2807SJeff Garzik 2619c6fd2807SJeff Garzik return 0; 2620c6fd2807SJeff Garzik } 2621c6fd2807SJeff Garzik 2622c6fd2807SJeff Garzik /** 2623c6fd2807SJeff Garzik * mv_init_host - Perform some early initialization of the host. 26244447d351STejun Heo * @host: ATA host to initialize 26254447d351STejun Heo * @board_idx: controller index 2626c6fd2807SJeff Garzik * 2627c6fd2807SJeff Garzik * If possible, do an early global reset of the host. Then do 2628c6fd2807SJeff Garzik * our port init and clear/unmask all/relevant host interrupts. 2629c6fd2807SJeff Garzik * 2630c6fd2807SJeff Garzik * LOCKING: 2631c6fd2807SJeff Garzik * Inherited from caller. 2632c6fd2807SJeff Garzik */ 26334447d351STejun Heo static int mv_init_host(struct ata_host *host, unsigned int board_idx) 2634c6fd2807SJeff Garzik { 2635c6fd2807SJeff Garzik int rc = 0, n_hc, port, hc; 26364447d351STejun Heo void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; 26374447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 2638c6fd2807SJeff Garzik 2639c6fd2807SJeff Garzik /* global interrupt mask */ 2640c6fd2807SJeff Garzik writel(0, mmio + HC_MAIN_IRQ_MASK_OFS); 2641c6fd2807SJeff Garzik 26424447d351STejun Heo rc = mv_chip_id(host, board_idx); 2643c6fd2807SJeff Garzik if (rc) 2644c6fd2807SJeff Garzik goto done; 2645c6fd2807SJeff Garzik 26464447d351STejun Heo n_hc = mv_get_hc_count(host->ports[0]->flags); 2647c6fd2807SJeff Garzik 26484447d351STejun Heo for (port = 0; port < host->n_ports; port++) 2649c6fd2807SJeff Garzik hpriv->ops->read_preamp(hpriv, port, mmio); 2650c6fd2807SJeff Garzik 2651c6fd2807SJeff Garzik rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc); 2652c6fd2807SJeff Garzik if (rc) 2653c6fd2807SJeff Garzik goto done; 2654c6fd2807SJeff Garzik 2655c6fd2807SJeff Garzik hpriv->ops->reset_flash(hpriv, mmio); 2656*7bb3c529SSaeed Bishara hpriv->ops->reset_bus(host, mmio); 2657c6fd2807SJeff Garzik hpriv->ops->enable_leds(hpriv, mmio); 2658c6fd2807SJeff Garzik 26594447d351STejun Heo for (port = 0; port < host->n_ports; port++) { 2660ee9ccdf7SJeff Garzik if (IS_GEN_II(hpriv)) { 2661c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2662c6fd2807SJeff Garzik 2663c6fd2807SJeff Garzik u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); 2664c6fd2807SJeff Garzik ifctl |= (1 << 7); /* enable gen2i speed */ 2665c6fd2807SJeff Garzik ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ 2666c6fd2807SJeff Garzik writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL); 2667c6fd2807SJeff Garzik } 2668c6fd2807SJeff Garzik 2669c6fd2807SJeff Garzik hpriv->ops->phy_errata(hpriv, mmio, port); 2670c6fd2807SJeff Garzik } 2671c6fd2807SJeff Garzik 26724447d351STejun Heo for (port = 0; port < host->n_ports; port++) { 2673cbcdd875STejun Heo struct ata_port *ap = host->ports[port]; 2674c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2675cbcdd875STejun Heo unsigned int offset = port_mmio - mmio; 2676cbcdd875STejun Heo 2677cbcdd875STejun Heo mv_port_init(&ap->ioaddr, port_mmio); 2678cbcdd875STejun Heo 2679*7bb3c529SSaeed Bishara #ifdef CONFIG_PCI 2680cbcdd875STejun Heo ata_port_pbar_desc(ap, MV_PRIMARY_BAR, -1, "mmio"); 2681cbcdd875STejun Heo ata_port_pbar_desc(ap, MV_PRIMARY_BAR, offset, "port"); 2682*7bb3c529SSaeed Bishara #endif 2683c6fd2807SJeff Garzik } 2684c6fd2807SJeff Garzik 2685c6fd2807SJeff Garzik for (hc = 0; hc < n_hc; hc++) { 2686c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 2687c6fd2807SJeff Garzik 2688c6fd2807SJeff Garzik VPRINTK("HC%i: HC config=0x%08x HC IRQ cause " 2689c6fd2807SJeff Garzik "(before clear)=0x%08x\n", hc, 2690c6fd2807SJeff Garzik readl(hc_mmio + HC_CFG_OFS), 2691c6fd2807SJeff Garzik readl(hc_mmio + HC_IRQ_CAUSE_OFS)); 2692c6fd2807SJeff Garzik 2693c6fd2807SJeff Garzik /* Clear any currently outstanding hc interrupt conditions */ 2694c6fd2807SJeff Garzik writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS); 2695c6fd2807SJeff Garzik } 2696c6fd2807SJeff Garzik 2697c6fd2807SJeff Garzik /* Clear any currently outstanding host interrupt conditions */ 269802a121daSMark Lord writelfl(0, mmio + hpriv->irq_cause_ofs); 2699c6fd2807SJeff Garzik 2700c6fd2807SJeff Garzik /* and unmask interrupt generation for host regs */ 270102a121daSMark Lord writelfl(hpriv->unmask_all_irqs, mmio + hpriv->irq_mask_ofs); 2702fb621e2fSJeff Garzik 2703ee9ccdf7SJeff Garzik if (IS_GEN_I(hpriv)) 2704fb621e2fSJeff Garzik writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS); 2705fb621e2fSJeff Garzik else 2706c6fd2807SJeff Garzik writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS); 2707c6fd2807SJeff Garzik 2708c6fd2807SJeff Garzik VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x " 2709c6fd2807SJeff Garzik "PCI int cause/mask=0x%08x/0x%08x\n", 2710c6fd2807SJeff Garzik readl(mmio + HC_MAIN_IRQ_CAUSE_OFS), 2711c6fd2807SJeff Garzik readl(mmio + HC_MAIN_IRQ_MASK_OFS), 271202a121daSMark Lord readl(mmio + hpriv->irq_cause_ofs), 271302a121daSMark Lord readl(mmio + hpriv->irq_mask_ofs)); 2714c6fd2807SJeff Garzik 2715c6fd2807SJeff Garzik done: 2716c6fd2807SJeff Garzik return rc; 2717c6fd2807SJeff Garzik } 2718c6fd2807SJeff Garzik 2719*7bb3c529SSaeed Bishara #ifdef CONFIG_PCI 2720*7bb3c529SSaeed Bishara static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 2721*7bb3c529SSaeed Bishara 2722*7bb3c529SSaeed Bishara static struct pci_driver mv_pci_driver = { 2723*7bb3c529SSaeed Bishara .name = DRV_NAME, 2724*7bb3c529SSaeed Bishara .id_table = mv_pci_tbl, 2725*7bb3c529SSaeed Bishara .probe = mv_init_one, 2726*7bb3c529SSaeed Bishara .remove = ata_pci_remove_one, 2727*7bb3c529SSaeed Bishara }; 2728*7bb3c529SSaeed Bishara 2729*7bb3c529SSaeed Bishara /* 2730*7bb3c529SSaeed Bishara * module options 2731*7bb3c529SSaeed Bishara */ 2732*7bb3c529SSaeed Bishara static int msi; /* Use PCI msi; either zero (off, default) or non-zero */ 2733*7bb3c529SSaeed Bishara 2734*7bb3c529SSaeed Bishara 2735*7bb3c529SSaeed Bishara /* move to PCI layer or libata core? */ 2736*7bb3c529SSaeed Bishara static int pci_go_64(struct pci_dev *pdev) 2737*7bb3c529SSaeed Bishara { 2738*7bb3c529SSaeed Bishara int rc; 2739*7bb3c529SSaeed Bishara 2740*7bb3c529SSaeed Bishara if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) { 2741*7bb3c529SSaeed Bishara rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); 2742*7bb3c529SSaeed Bishara if (rc) { 2743*7bb3c529SSaeed Bishara rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 2744*7bb3c529SSaeed Bishara if (rc) { 2745*7bb3c529SSaeed Bishara dev_printk(KERN_ERR, &pdev->dev, 2746*7bb3c529SSaeed Bishara "64-bit DMA enable failed\n"); 2747*7bb3c529SSaeed Bishara return rc; 2748*7bb3c529SSaeed Bishara } 2749*7bb3c529SSaeed Bishara } 2750*7bb3c529SSaeed Bishara } else { 2751*7bb3c529SSaeed Bishara rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 2752*7bb3c529SSaeed Bishara if (rc) { 2753*7bb3c529SSaeed Bishara dev_printk(KERN_ERR, &pdev->dev, 2754*7bb3c529SSaeed Bishara "32-bit DMA enable failed\n"); 2755*7bb3c529SSaeed Bishara return rc; 2756*7bb3c529SSaeed Bishara } 2757*7bb3c529SSaeed Bishara rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 2758*7bb3c529SSaeed Bishara if (rc) { 2759*7bb3c529SSaeed Bishara dev_printk(KERN_ERR, &pdev->dev, 2760*7bb3c529SSaeed Bishara "32-bit consistent DMA enable failed\n"); 2761*7bb3c529SSaeed Bishara return rc; 2762*7bb3c529SSaeed Bishara } 2763*7bb3c529SSaeed Bishara } 2764*7bb3c529SSaeed Bishara 2765*7bb3c529SSaeed Bishara return rc; 2766*7bb3c529SSaeed Bishara } 2767*7bb3c529SSaeed Bishara 2768c6fd2807SJeff Garzik /** 2769c6fd2807SJeff Garzik * mv_print_info - Dump key info to kernel log for perusal. 27704447d351STejun Heo * @host: ATA host to print info about 2771c6fd2807SJeff Garzik * 2772c6fd2807SJeff Garzik * FIXME: complete this. 2773c6fd2807SJeff Garzik * 2774c6fd2807SJeff Garzik * LOCKING: 2775c6fd2807SJeff Garzik * Inherited from caller. 2776c6fd2807SJeff Garzik */ 27774447d351STejun Heo static void mv_print_info(struct ata_host *host) 2778c6fd2807SJeff Garzik { 27794447d351STejun Heo struct pci_dev *pdev = to_pci_dev(host->dev); 27804447d351STejun Heo struct mv_host_priv *hpriv = host->private_data; 278144c10138SAuke Kok u8 scc; 2782c1e4fe71SJeff Garzik const char *scc_s, *gen; 2783c6fd2807SJeff Garzik 2784c6fd2807SJeff Garzik /* Use this to determine the HW stepping of the chip so we know 2785c6fd2807SJeff Garzik * what errata to workaround 2786c6fd2807SJeff Garzik */ 2787c6fd2807SJeff Garzik pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc); 2788c6fd2807SJeff Garzik if (scc == 0) 2789c6fd2807SJeff Garzik scc_s = "SCSI"; 2790c6fd2807SJeff Garzik else if (scc == 0x01) 2791c6fd2807SJeff Garzik scc_s = "RAID"; 2792c6fd2807SJeff Garzik else 2793c1e4fe71SJeff Garzik scc_s = "?"; 2794c1e4fe71SJeff Garzik 2795c1e4fe71SJeff Garzik if (IS_GEN_I(hpriv)) 2796c1e4fe71SJeff Garzik gen = "I"; 2797c1e4fe71SJeff Garzik else if (IS_GEN_II(hpriv)) 2798c1e4fe71SJeff Garzik gen = "II"; 2799c1e4fe71SJeff Garzik else if (IS_GEN_IIE(hpriv)) 2800c1e4fe71SJeff Garzik gen = "IIE"; 2801c1e4fe71SJeff Garzik else 2802c1e4fe71SJeff Garzik gen = "?"; 2803c6fd2807SJeff Garzik 2804c6fd2807SJeff Garzik dev_printk(KERN_INFO, &pdev->dev, 2805c1e4fe71SJeff Garzik "Gen-%s %u slots %u ports %s mode IRQ via %s\n", 2806c1e4fe71SJeff Garzik gen, (unsigned)MV_MAX_Q_DEPTH, host->n_ports, 2807c6fd2807SJeff Garzik scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx"); 2808c6fd2807SJeff Garzik } 2809c6fd2807SJeff Garzik 2810da2fa9baSMark Lord static int mv_create_dma_pools(struct mv_host_priv *hpriv, struct device *dev) 2811da2fa9baSMark Lord { 2812da2fa9baSMark Lord hpriv->crqb_pool = dmam_pool_create("crqb_q", dev, MV_CRQB_Q_SZ, 2813da2fa9baSMark Lord MV_CRQB_Q_SZ, 0); 2814da2fa9baSMark Lord if (!hpriv->crqb_pool) 2815da2fa9baSMark Lord return -ENOMEM; 2816da2fa9baSMark Lord 2817da2fa9baSMark Lord hpriv->crpb_pool = dmam_pool_create("crpb_q", dev, MV_CRPB_Q_SZ, 2818da2fa9baSMark Lord MV_CRPB_Q_SZ, 0); 2819da2fa9baSMark Lord if (!hpriv->crpb_pool) 2820da2fa9baSMark Lord return -ENOMEM; 2821da2fa9baSMark Lord 2822da2fa9baSMark Lord hpriv->sg_tbl_pool = dmam_pool_create("sg_tbl", dev, MV_SG_TBL_SZ, 2823da2fa9baSMark Lord MV_SG_TBL_SZ, 0); 2824da2fa9baSMark Lord if (!hpriv->sg_tbl_pool) 2825da2fa9baSMark Lord return -ENOMEM; 2826da2fa9baSMark Lord 2827da2fa9baSMark Lord return 0; 2828da2fa9baSMark Lord } 2829da2fa9baSMark Lord 2830c6fd2807SJeff Garzik /** 2831c6fd2807SJeff Garzik * mv_init_one - handle a positive probe of a Marvell host 2832c6fd2807SJeff Garzik * @pdev: PCI device found 2833c6fd2807SJeff Garzik * @ent: PCI device ID entry for the matched host 2834c6fd2807SJeff Garzik * 2835c6fd2807SJeff Garzik * LOCKING: 2836c6fd2807SJeff Garzik * Inherited from caller. 2837c6fd2807SJeff Garzik */ 2838c6fd2807SJeff Garzik static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 2839c6fd2807SJeff Garzik { 28402dcb407eSJeff Garzik static int printed_version; 2841c6fd2807SJeff Garzik unsigned int board_idx = (unsigned int)ent->driver_data; 28424447d351STejun Heo const struct ata_port_info *ppi[] = { &mv_port_info[board_idx], NULL }; 28434447d351STejun Heo struct ata_host *host; 28444447d351STejun Heo struct mv_host_priv *hpriv; 28454447d351STejun Heo int n_ports, rc; 2846c6fd2807SJeff Garzik 2847c6fd2807SJeff Garzik if (!printed_version++) 2848c6fd2807SJeff Garzik dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 2849c6fd2807SJeff Garzik 28504447d351STejun Heo /* allocate host */ 28514447d351STejun Heo n_ports = mv_get_hc_count(ppi[0]->flags) * MV_PORTS_PER_HC; 28524447d351STejun Heo 28534447d351STejun Heo host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports); 28544447d351STejun Heo hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); 28554447d351STejun Heo if (!host || !hpriv) 28564447d351STejun Heo return -ENOMEM; 28574447d351STejun Heo host->private_data = hpriv; 28584447d351STejun Heo 28594447d351STejun Heo /* acquire resources */ 286024dc5f33STejun Heo rc = pcim_enable_device(pdev); 286124dc5f33STejun Heo if (rc) 2862c6fd2807SJeff Garzik return rc; 2863c6fd2807SJeff Garzik 28640d5ff566STejun Heo rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME); 28650d5ff566STejun Heo if (rc == -EBUSY) 286624dc5f33STejun Heo pcim_pin_device(pdev); 28670d5ff566STejun Heo if (rc) 286824dc5f33STejun Heo return rc; 28694447d351STejun Heo host->iomap = pcim_iomap_table(pdev); 2870c6fd2807SJeff Garzik 2871d88184fbSJeff Garzik rc = pci_go_64(pdev); 2872d88184fbSJeff Garzik if (rc) 2873d88184fbSJeff Garzik return rc; 2874d88184fbSJeff Garzik 2875da2fa9baSMark Lord rc = mv_create_dma_pools(hpriv, &pdev->dev); 2876da2fa9baSMark Lord if (rc) 2877da2fa9baSMark Lord return rc; 2878da2fa9baSMark Lord 2879c6fd2807SJeff Garzik /* initialize adapter */ 28804447d351STejun Heo rc = mv_init_host(host, board_idx); 288124dc5f33STejun Heo if (rc) 288224dc5f33STejun Heo return rc; 2883c6fd2807SJeff Garzik 2884c6fd2807SJeff Garzik /* Enable interrupts */ 28856a59dcf8STejun Heo if (msi && pci_enable_msi(pdev)) 2886c6fd2807SJeff Garzik pci_intx(pdev, 1); 2887c6fd2807SJeff Garzik 2888c6fd2807SJeff Garzik mv_dump_pci_cfg(pdev, 0x68); 28894447d351STejun Heo mv_print_info(host); 2890c6fd2807SJeff Garzik 28914447d351STejun Heo pci_set_master(pdev); 2892ea8b4db9SJeff Garzik pci_try_set_mwi(pdev); 28934447d351STejun Heo return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED, 2894c5d3e45aSJeff Garzik IS_GEN_I(hpriv) ? &mv5_sht : &mv6_sht); 2895c6fd2807SJeff Garzik } 2896*7bb3c529SSaeed Bishara #endif 2897c6fd2807SJeff Garzik 2898c6fd2807SJeff Garzik static int __init mv_init(void) 2899c6fd2807SJeff Garzik { 2900*7bb3c529SSaeed Bishara int rc = -ENODEV; 2901*7bb3c529SSaeed Bishara #ifdef CONFIG_PCI 2902*7bb3c529SSaeed Bishara rc = pci_register_driver(&mv_pci_driver); 2903*7bb3c529SSaeed Bishara #endif 2904*7bb3c529SSaeed Bishara return rc; 2905c6fd2807SJeff Garzik } 2906c6fd2807SJeff Garzik 2907c6fd2807SJeff Garzik static void __exit mv_exit(void) 2908c6fd2807SJeff Garzik { 2909*7bb3c529SSaeed Bishara #ifdef CONFIG_PCI 2910c6fd2807SJeff Garzik pci_unregister_driver(&mv_pci_driver); 2911*7bb3c529SSaeed Bishara #endif 2912c6fd2807SJeff Garzik } 2913c6fd2807SJeff Garzik 2914c6fd2807SJeff Garzik MODULE_AUTHOR("Brett Russ"); 2915c6fd2807SJeff Garzik MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers"); 2916c6fd2807SJeff Garzik MODULE_LICENSE("GPL"); 2917c6fd2807SJeff Garzik MODULE_DEVICE_TABLE(pci, mv_pci_tbl); 2918c6fd2807SJeff Garzik MODULE_VERSION(DRV_VERSION); 2919c6fd2807SJeff Garzik 2920*7bb3c529SSaeed Bishara #ifdef CONFIG_PCI 2921c6fd2807SJeff Garzik module_param(msi, int, 0444); 2922c6fd2807SJeff Garzik MODULE_PARM_DESC(msi, "Enable use of PCI MSI (0=off, 1=on)"); 2923*7bb3c529SSaeed Bishara #endif 2924c6fd2807SJeff Garzik 2925c6fd2807SJeff Garzik module_init(mv_init); 2926c6fd2807SJeff Garzik module_exit(mv_exit); 2927