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 24c6fd2807SJeff Garzik #include <linux/kernel.h> 25c6fd2807SJeff Garzik #include <linux/module.h> 26c6fd2807SJeff Garzik #include <linux/pci.h> 27c6fd2807SJeff Garzik #include <linux/init.h> 28c6fd2807SJeff Garzik #include <linux/blkdev.h> 29c6fd2807SJeff Garzik #include <linux/delay.h> 30c6fd2807SJeff Garzik #include <linux/interrupt.h> 31c6fd2807SJeff Garzik #include <linux/sched.h> 32c6fd2807SJeff Garzik #include <linux/dma-mapping.h> 33c6fd2807SJeff Garzik #include <linux/device.h> 34c6fd2807SJeff Garzik #include <scsi/scsi_host.h> 35c6fd2807SJeff Garzik #include <scsi/scsi_cmnd.h> 36c6fd2807SJeff Garzik #include <linux/libata.h> 37c6fd2807SJeff Garzik 38c6fd2807SJeff Garzik #define DRV_NAME "sata_mv" 39c6fd2807SJeff Garzik #define DRV_VERSION "0.7" 40c6fd2807SJeff Garzik 41c6fd2807SJeff Garzik enum { 42c6fd2807SJeff Garzik /* BAR's are enumerated in terms of pci_resource_start() terms */ 43c6fd2807SJeff Garzik MV_PRIMARY_BAR = 0, /* offset 0x10: memory space */ 44c6fd2807SJeff Garzik MV_IO_BAR = 2, /* offset 0x18: IO space */ 45c6fd2807SJeff Garzik MV_MISC_BAR = 3, /* offset 0x1c: FLASH, NVRAM, SRAM */ 46c6fd2807SJeff Garzik 47c6fd2807SJeff Garzik MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */ 48c6fd2807SJeff Garzik MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */ 49c6fd2807SJeff Garzik 50c6fd2807SJeff Garzik MV_PCI_REG_BASE = 0, 51c6fd2807SJeff Garzik MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */ 52c6fd2807SJeff Garzik MV_IRQ_COAL_CAUSE = (MV_IRQ_COAL_REG_BASE + 0x08), 53c6fd2807SJeff Garzik MV_IRQ_COAL_CAUSE_LO = (MV_IRQ_COAL_REG_BASE + 0x88), 54c6fd2807SJeff Garzik MV_IRQ_COAL_CAUSE_HI = (MV_IRQ_COAL_REG_BASE + 0x8c), 55c6fd2807SJeff Garzik MV_IRQ_COAL_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xcc), 56c6fd2807SJeff Garzik MV_IRQ_COAL_TIME_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xd0), 57c6fd2807SJeff Garzik 58c6fd2807SJeff Garzik MV_SATAHC0_REG_BASE = 0x20000, 59c6fd2807SJeff Garzik MV_FLASH_CTL = 0x1046c, 60c6fd2807SJeff Garzik MV_GPIO_PORT_CTL = 0x104f0, 61c6fd2807SJeff Garzik MV_RESET_CFG = 0x180d8, 62c6fd2807SJeff Garzik 63c6fd2807SJeff Garzik MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ, 64c6fd2807SJeff Garzik MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ, 65c6fd2807SJeff Garzik MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */ 66c6fd2807SJeff Garzik MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ, 67c6fd2807SJeff Garzik 68c6fd2807SJeff Garzik MV_USE_Q_DEPTH = ATA_DEF_QUEUE, 69c6fd2807SJeff Garzik 70c6fd2807SJeff Garzik MV_MAX_Q_DEPTH = 32, 71c6fd2807SJeff Garzik MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1, 72c6fd2807SJeff Garzik 73c6fd2807SJeff Garzik /* CRQB needs alignment on a 1KB boundary. Size == 1KB 74c6fd2807SJeff Garzik * CRPB needs alignment on a 256B boundary. Size == 256B 75c6fd2807SJeff Garzik * SG count of 176 leads to MV_PORT_PRIV_DMA_SZ == 4KB 76c6fd2807SJeff Garzik * ePRD (SG) entries need alignment on a 16B boundary. Size == 16B 77c6fd2807SJeff Garzik */ 78c6fd2807SJeff Garzik MV_CRQB_Q_SZ = (32 * MV_MAX_Q_DEPTH), 79c6fd2807SJeff Garzik MV_CRPB_Q_SZ = (8 * MV_MAX_Q_DEPTH), 80c6fd2807SJeff Garzik MV_MAX_SG_CT = 176, 81c6fd2807SJeff Garzik MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT), 82c6fd2807SJeff Garzik MV_PORT_PRIV_DMA_SZ = (MV_CRQB_Q_SZ + MV_CRPB_Q_SZ + MV_SG_TBL_SZ), 83c6fd2807SJeff Garzik 84c6fd2807SJeff Garzik MV_PORTS_PER_HC = 4, 85c6fd2807SJeff Garzik /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */ 86c6fd2807SJeff Garzik MV_PORT_HC_SHIFT = 2, 87c6fd2807SJeff Garzik /* == (port % MV_PORTS_PER_HC) to determine hard port from 0-7 port */ 88c6fd2807SJeff Garzik MV_PORT_MASK = 3, 89c6fd2807SJeff Garzik 90c6fd2807SJeff Garzik /* Host Flags */ 91c6fd2807SJeff Garzik MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ 92c6fd2807SJeff Garzik MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */ 93c6fd2807SJeff Garzik MV_COMMON_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 94c6fd2807SJeff Garzik ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO | 95c6fd2807SJeff Garzik ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING), 96c6fd2807SJeff Garzik MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE, 97c6fd2807SJeff Garzik 98c6fd2807SJeff Garzik CRQB_FLAG_READ = (1 << 0), 99c6fd2807SJeff Garzik CRQB_TAG_SHIFT = 1, 100c6fd2807SJeff Garzik CRQB_CMD_ADDR_SHIFT = 8, 101c6fd2807SJeff Garzik CRQB_CMD_CS = (0x2 << 11), 102c6fd2807SJeff Garzik CRQB_CMD_LAST = (1 << 15), 103c6fd2807SJeff Garzik 104c6fd2807SJeff Garzik CRPB_FLAG_STATUS_SHIFT = 8, 105c6fd2807SJeff Garzik 106c6fd2807SJeff Garzik EPRD_FLAG_END_OF_TBL = (1 << 31), 107c6fd2807SJeff Garzik 108c6fd2807SJeff Garzik /* PCI interface registers */ 109c6fd2807SJeff Garzik 110c6fd2807SJeff Garzik PCI_COMMAND_OFS = 0xc00, 111c6fd2807SJeff Garzik 112c6fd2807SJeff Garzik PCI_MAIN_CMD_STS_OFS = 0xd30, 113c6fd2807SJeff Garzik STOP_PCI_MASTER = (1 << 2), 114c6fd2807SJeff Garzik PCI_MASTER_EMPTY = (1 << 3), 115c6fd2807SJeff Garzik GLOB_SFT_RST = (1 << 4), 116c6fd2807SJeff Garzik 117c6fd2807SJeff Garzik MV_PCI_MODE = 0xd00, 118c6fd2807SJeff Garzik MV_PCI_EXP_ROM_BAR_CTL = 0xd2c, 119c6fd2807SJeff Garzik MV_PCI_DISC_TIMER = 0xd04, 120c6fd2807SJeff Garzik MV_PCI_MSI_TRIGGER = 0xc38, 121c6fd2807SJeff Garzik MV_PCI_SERR_MASK = 0xc28, 122c6fd2807SJeff Garzik MV_PCI_XBAR_TMOUT = 0x1d04, 123c6fd2807SJeff Garzik MV_PCI_ERR_LOW_ADDRESS = 0x1d40, 124c6fd2807SJeff Garzik MV_PCI_ERR_HIGH_ADDRESS = 0x1d44, 125c6fd2807SJeff Garzik MV_PCI_ERR_ATTRIBUTE = 0x1d48, 126c6fd2807SJeff Garzik MV_PCI_ERR_COMMAND = 0x1d50, 127c6fd2807SJeff Garzik 128c6fd2807SJeff Garzik PCI_IRQ_CAUSE_OFS = 0x1d58, 129c6fd2807SJeff Garzik PCI_IRQ_MASK_OFS = 0x1d5c, 130c6fd2807SJeff Garzik PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */ 131c6fd2807SJeff Garzik 132c6fd2807SJeff Garzik HC_MAIN_IRQ_CAUSE_OFS = 0x1d60, 133c6fd2807SJeff Garzik HC_MAIN_IRQ_MASK_OFS = 0x1d64, 134c6fd2807SJeff Garzik PORT0_ERR = (1 << 0), /* shift by port # */ 135c6fd2807SJeff Garzik PORT0_DONE = (1 << 1), /* shift by port # */ 136c6fd2807SJeff Garzik HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */ 137c6fd2807SJeff Garzik HC_SHIFT = 9, /* bits 9-17 = HC1's ports */ 138c6fd2807SJeff Garzik PCI_ERR = (1 << 18), 139c6fd2807SJeff Garzik TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */ 140c6fd2807SJeff Garzik TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */ 141c6fd2807SJeff Garzik PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */ 142c6fd2807SJeff Garzik GPIO_INT = (1 << 22), 143c6fd2807SJeff Garzik SELF_INT = (1 << 23), 144c6fd2807SJeff Garzik TWSI_INT = (1 << 24), 145c6fd2807SJeff Garzik HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */ 146c6fd2807SJeff Garzik HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE | 147c6fd2807SJeff Garzik PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT | 148c6fd2807SJeff Garzik HC_MAIN_RSVD), 149c6fd2807SJeff Garzik 150c6fd2807SJeff Garzik /* SATAHC registers */ 151c6fd2807SJeff Garzik HC_CFG_OFS = 0, 152c6fd2807SJeff Garzik 153c6fd2807SJeff Garzik HC_IRQ_CAUSE_OFS = 0x14, 154c6fd2807SJeff Garzik CRPB_DMA_DONE = (1 << 0), /* shift by port # */ 155c6fd2807SJeff Garzik HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */ 156c6fd2807SJeff Garzik DEV_IRQ = (1 << 8), /* shift by port # */ 157c6fd2807SJeff Garzik 158c6fd2807SJeff Garzik /* Shadow block registers */ 159c6fd2807SJeff Garzik SHD_BLK_OFS = 0x100, 160c6fd2807SJeff Garzik SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */ 161c6fd2807SJeff Garzik 162c6fd2807SJeff Garzik /* SATA registers */ 163c6fd2807SJeff Garzik SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */ 164c6fd2807SJeff Garzik SATA_ACTIVE_OFS = 0x350, 165c6fd2807SJeff Garzik PHY_MODE3 = 0x310, 166c6fd2807SJeff Garzik PHY_MODE4 = 0x314, 167c6fd2807SJeff Garzik PHY_MODE2 = 0x330, 168c6fd2807SJeff Garzik MV5_PHY_MODE = 0x74, 169c6fd2807SJeff Garzik MV5_LT_MODE = 0x30, 170c6fd2807SJeff Garzik MV5_PHY_CTL = 0x0C, 171c6fd2807SJeff Garzik SATA_INTERFACE_CTL = 0x050, 172c6fd2807SJeff Garzik 173c6fd2807SJeff Garzik MV_M2_PREAMP_MASK = 0x7e0, 174c6fd2807SJeff Garzik 175c6fd2807SJeff Garzik /* Port registers */ 176c6fd2807SJeff Garzik EDMA_CFG_OFS = 0, 177c6fd2807SJeff Garzik EDMA_CFG_Q_DEPTH = 0, /* queueing disabled */ 178c6fd2807SJeff Garzik EDMA_CFG_NCQ = (1 << 5), 179c6fd2807SJeff Garzik EDMA_CFG_NCQ_GO_ON_ERR = (1 << 14), /* continue on error */ 180c6fd2807SJeff Garzik EDMA_CFG_RD_BRST_EXT = (1 << 11), /* read burst 512B */ 181c6fd2807SJeff Garzik EDMA_CFG_WR_BUFF_LEN = (1 << 13), /* write buffer 512B */ 182c6fd2807SJeff Garzik 183c6fd2807SJeff Garzik EDMA_ERR_IRQ_CAUSE_OFS = 0x8, 184c6fd2807SJeff Garzik EDMA_ERR_IRQ_MASK_OFS = 0xc, 185c6fd2807SJeff Garzik EDMA_ERR_D_PAR = (1 << 0), 186c6fd2807SJeff Garzik EDMA_ERR_PRD_PAR = (1 << 1), 187c6fd2807SJeff Garzik EDMA_ERR_DEV = (1 << 2), 188c6fd2807SJeff Garzik EDMA_ERR_DEV_DCON = (1 << 3), 189c6fd2807SJeff Garzik EDMA_ERR_DEV_CON = (1 << 4), 190c6fd2807SJeff Garzik EDMA_ERR_SERR = (1 << 5), 191c6fd2807SJeff Garzik EDMA_ERR_SELF_DIS = (1 << 7), 192c6fd2807SJeff Garzik EDMA_ERR_BIST_ASYNC = (1 << 8), 193c6fd2807SJeff Garzik EDMA_ERR_CRBQ_PAR = (1 << 9), 194c6fd2807SJeff Garzik EDMA_ERR_CRPB_PAR = (1 << 10), 195c6fd2807SJeff Garzik EDMA_ERR_INTRL_PAR = (1 << 11), 196c6fd2807SJeff Garzik EDMA_ERR_IORDY = (1 << 12), 197c6fd2807SJeff Garzik EDMA_ERR_LNK_CTRL_RX = (0xf << 13), 198c6fd2807SJeff Garzik EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15), 199c6fd2807SJeff Garzik EDMA_ERR_LNK_DATA_RX = (0xf << 17), 200c6fd2807SJeff Garzik EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), 201c6fd2807SJeff Garzik EDMA_ERR_LNK_DATA_TX = (0x1f << 26), 202c6fd2807SJeff Garzik EDMA_ERR_TRANS_PROTO = (1 << 31), 203c6fd2807SJeff Garzik EDMA_ERR_FATAL = (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | 204c6fd2807SJeff Garzik EDMA_ERR_DEV_DCON | EDMA_ERR_CRBQ_PAR | 205c6fd2807SJeff Garzik EDMA_ERR_CRPB_PAR | EDMA_ERR_INTRL_PAR | 206c6fd2807SJeff Garzik EDMA_ERR_IORDY | EDMA_ERR_LNK_CTRL_RX_2 | 207c6fd2807SJeff Garzik EDMA_ERR_LNK_DATA_RX | 208c6fd2807SJeff Garzik EDMA_ERR_LNK_DATA_TX | 209c6fd2807SJeff Garzik EDMA_ERR_TRANS_PROTO), 210c6fd2807SJeff Garzik 211c6fd2807SJeff Garzik EDMA_REQ_Q_BASE_HI_OFS = 0x10, 212c6fd2807SJeff Garzik EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */ 213c6fd2807SJeff Garzik 214c6fd2807SJeff Garzik EDMA_REQ_Q_OUT_PTR_OFS = 0x18, 215c6fd2807SJeff Garzik EDMA_REQ_Q_PTR_SHIFT = 5, 216c6fd2807SJeff Garzik 217c6fd2807SJeff Garzik EDMA_RSP_Q_BASE_HI_OFS = 0x1c, 218c6fd2807SJeff Garzik EDMA_RSP_Q_IN_PTR_OFS = 0x20, 219c6fd2807SJeff Garzik EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */ 220c6fd2807SJeff Garzik EDMA_RSP_Q_PTR_SHIFT = 3, 221c6fd2807SJeff Garzik 222c6fd2807SJeff Garzik EDMA_CMD_OFS = 0x28, 223c6fd2807SJeff Garzik EDMA_EN = (1 << 0), 224c6fd2807SJeff Garzik EDMA_DS = (1 << 1), 225c6fd2807SJeff Garzik ATA_RST = (1 << 2), 226c6fd2807SJeff Garzik 227c6fd2807SJeff Garzik EDMA_IORDY_TMOUT = 0x34, 228c6fd2807SJeff Garzik EDMA_ARB_CFG = 0x38, 229c6fd2807SJeff Garzik 230c6fd2807SJeff Garzik /* Host private flags (hp_flags) */ 231c6fd2807SJeff Garzik MV_HP_FLAG_MSI = (1 << 0), 232c6fd2807SJeff Garzik MV_HP_ERRATA_50XXB0 = (1 << 1), 233c6fd2807SJeff Garzik MV_HP_ERRATA_50XXB2 = (1 << 2), 234c6fd2807SJeff Garzik MV_HP_ERRATA_60X1B2 = (1 << 3), 235c6fd2807SJeff Garzik MV_HP_ERRATA_60X1C0 = (1 << 4), 236c6fd2807SJeff Garzik MV_HP_ERRATA_XX42A0 = (1 << 5), 237c6fd2807SJeff Garzik MV_HP_50XX = (1 << 6), 238c6fd2807SJeff Garzik MV_HP_GEN_IIE = (1 << 7), 239c6fd2807SJeff Garzik 240c6fd2807SJeff Garzik /* Port private flags (pp_flags) */ 241c6fd2807SJeff Garzik MV_PP_FLAG_EDMA_EN = (1 << 0), 242c6fd2807SJeff Garzik MV_PP_FLAG_EDMA_DS_ACT = (1 << 1), 243c6fd2807SJeff Garzik }; 244c6fd2807SJeff Garzik 245c6fd2807SJeff Garzik #define IS_50XX(hpriv) ((hpriv)->hp_flags & MV_HP_50XX) 246c6fd2807SJeff Garzik #define IS_60XX(hpriv) (((hpriv)->hp_flags & MV_HP_50XX) == 0) 247c6fd2807SJeff Garzik #define IS_GEN_I(hpriv) IS_50XX(hpriv) 248c6fd2807SJeff Garzik #define IS_GEN_II(hpriv) IS_60XX(hpriv) 249c6fd2807SJeff Garzik #define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE) 250c6fd2807SJeff Garzik 251c6fd2807SJeff Garzik enum { 252c6fd2807SJeff Garzik /* Our DMA boundary is determined by an ePRD being unable to handle 253c6fd2807SJeff Garzik * anything larger than 64KB 254c6fd2807SJeff Garzik */ 255c6fd2807SJeff Garzik MV_DMA_BOUNDARY = 0xffffU, 256c6fd2807SJeff Garzik 257c6fd2807SJeff Garzik EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U, 258c6fd2807SJeff Garzik 259c6fd2807SJeff Garzik EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U, 260c6fd2807SJeff Garzik }; 261c6fd2807SJeff Garzik 262c6fd2807SJeff Garzik enum chip_type { 263c6fd2807SJeff Garzik chip_504x, 264c6fd2807SJeff Garzik chip_508x, 265c6fd2807SJeff Garzik chip_5080, 266c6fd2807SJeff Garzik chip_604x, 267c6fd2807SJeff Garzik chip_608x, 268c6fd2807SJeff Garzik chip_6042, 269c6fd2807SJeff Garzik chip_7042, 270c6fd2807SJeff Garzik }; 271c6fd2807SJeff Garzik 272c6fd2807SJeff Garzik /* Command ReQuest Block: 32B */ 273c6fd2807SJeff Garzik struct mv_crqb { 274c6fd2807SJeff Garzik __le32 sg_addr; 275c6fd2807SJeff Garzik __le32 sg_addr_hi; 276c6fd2807SJeff Garzik __le16 ctrl_flags; 277c6fd2807SJeff Garzik __le16 ata_cmd[11]; 278c6fd2807SJeff Garzik }; 279c6fd2807SJeff Garzik 280c6fd2807SJeff Garzik struct mv_crqb_iie { 281c6fd2807SJeff Garzik __le32 addr; 282c6fd2807SJeff Garzik __le32 addr_hi; 283c6fd2807SJeff Garzik __le32 flags; 284c6fd2807SJeff Garzik __le32 len; 285c6fd2807SJeff Garzik __le32 ata_cmd[4]; 286c6fd2807SJeff Garzik }; 287c6fd2807SJeff Garzik 288c6fd2807SJeff Garzik /* Command ResPonse Block: 8B */ 289c6fd2807SJeff Garzik struct mv_crpb { 290c6fd2807SJeff Garzik __le16 id; 291c6fd2807SJeff Garzik __le16 flags; 292c6fd2807SJeff Garzik __le32 tmstmp; 293c6fd2807SJeff Garzik }; 294c6fd2807SJeff Garzik 295c6fd2807SJeff Garzik /* EDMA Physical Region Descriptor (ePRD); A.K.A. SG */ 296c6fd2807SJeff Garzik struct mv_sg { 297c6fd2807SJeff Garzik __le32 addr; 298c6fd2807SJeff Garzik __le32 flags_size; 299c6fd2807SJeff Garzik __le32 addr_hi; 300c6fd2807SJeff Garzik __le32 reserved; 301c6fd2807SJeff Garzik }; 302c6fd2807SJeff Garzik 303c6fd2807SJeff Garzik struct mv_port_priv { 304c6fd2807SJeff Garzik struct mv_crqb *crqb; 305c6fd2807SJeff Garzik dma_addr_t crqb_dma; 306c6fd2807SJeff Garzik struct mv_crpb *crpb; 307c6fd2807SJeff Garzik dma_addr_t crpb_dma; 308c6fd2807SJeff Garzik struct mv_sg *sg_tbl; 309c6fd2807SJeff Garzik dma_addr_t sg_tbl_dma; 310c6fd2807SJeff Garzik u32 pp_flags; 311c6fd2807SJeff Garzik }; 312c6fd2807SJeff Garzik 313c6fd2807SJeff Garzik struct mv_port_signal { 314c6fd2807SJeff Garzik u32 amps; 315c6fd2807SJeff Garzik u32 pre; 316c6fd2807SJeff Garzik }; 317c6fd2807SJeff Garzik 318c6fd2807SJeff Garzik struct mv_host_priv; 319c6fd2807SJeff Garzik struct mv_hw_ops { 320c6fd2807SJeff Garzik void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio, 321c6fd2807SJeff Garzik unsigned int port); 322c6fd2807SJeff Garzik void (*enable_leds)(struct mv_host_priv *hpriv, void __iomem *mmio); 323c6fd2807SJeff Garzik void (*read_preamp)(struct mv_host_priv *hpriv, int idx, 324c6fd2807SJeff Garzik void __iomem *mmio); 325c6fd2807SJeff Garzik int (*reset_hc)(struct mv_host_priv *hpriv, void __iomem *mmio, 326c6fd2807SJeff Garzik unsigned int n_hc); 327c6fd2807SJeff Garzik void (*reset_flash)(struct mv_host_priv *hpriv, void __iomem *mmio); 328c6fd2807SJeff Garzik void (*reset_bus)(struct pci_dev *pdev, void __iomem *mmio); 329c6fd2807SJeff Garzik }; 330c6fd2807SJeff Garzik 331c6fd2807SJeff Garzik struct mv_host_priv { 332c6fd2807SJeff Garzik u32 hp_flags; 333c6fd2807SJeff Garzik struct mv_port_signal signal[8]; 334c6fd2807SJeff Garzik const struct mv_hw_ops *ops; 335c6fd2807SJeff Garzik }; 336c6fd2807SJeff Garzik 337c6fd2807SJeff Garzik static void mv_irq_clear(struct ata_port *ap); 338c6fd2807SJeff Garzik static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in); 339c6fd2807SJeff Garzik static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 340c6fd2807SJeff Garzik static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in); 341c6fd2807SJeff Garzik static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 342c6fd2807SJeff Garzik static void mv_phy_reset(struct ata_port *ap); 343c6fd2807SJeff Garzik static void __mv_phy_reset(struct ata_port *ap, int can_sleep); 344c6fd2807SJeff Garzik static int mv_port_start(struct ata_port *ap); 345c6fd2807SJeff Garzik static void mv_port_stop(struct ata_port *ap); 346c6fd2807SJeff Garzik static void mv_qc_prep(struct ata_queued_cmd *qc); 347c6fd2807SJeff Garzik static void mv_qc_prep_iie(struct ata_queued_cmd *qc); 348c6fd2807SJeff Garzik static unsigned int mv_qc_issue(struct ata_queued_cmd *qc); 3497d12e780SDavid Howells static irqreturn_t mv_interrupt(int irq, void *dev_instance); 350c6fd2807SJeff Garzik static void mv_eng_timeout(struct ata_port *ap); 351c6fd2807SJeff Garzik static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 352c6fd2807SJeff Garzik 353c6fd2807SJeff Garzik static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 354c6fd2807SJeff Garzik unsigned int port); 355c6fd2807SJeff Garzik static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); 356c6fd2807SJeff Garzik static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, 357c6fd2807SJeff Garzik void __iomem *mmio); 358c6fd2807SJeff Garzik static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 359c6fd2807SJeff Garzik unsigned int n_hc); 360c6fd2807SJeff Garzik static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); 361c6fd2807SJeff Garzik static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio); 362c6fd2807SJeff Garzik 363c6fd2807SJeff Garzik static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 364c6fd2807SJeff Garzik unsigned int port); 365c6fd2807SJeff Garzik static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); 366c6fd2807SJeff Garzik static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, 367c6fd2807SJeff Garzik void __iomem *mmio); 368c6fd2807SJeff Garzik static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 369c6fd2807SJeff Garzik unsigned int n_hc); 370c6fd2807SJeff Garzik static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); 371c6fd2807SJeff Garzik static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio); 372c6fd2807SJeff Garzik static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, 373c6fd2807SJeff Garzik unsigned int port_no); 374c6fd2807SJeff Garzik static void mv_stop_and_reset(struct ata_port *ap); 375c6fd2807SJeff Garzik 376c6fd2807SJeff Garzik static struct scsi_host_template mv_sht = { 377c6fd2807SJeff Garzik .module = THIS_MODULE, 378c6fd2807SJeff Garzik .name = DRV_NAME, 379c6fd2807SJeff Garzik .ioctl = ata_scsi_ioctl, 380c6fd2807SJeff Garzik .queuecommand = ata_scsi_queuecmd, 381c6fd2807SJeff Garzik .can_queue = MV_USE_Q_DEPTH, 382c6fd2807SJeff Garzik .this_id = ATA_SHT_THIS_ID, 383c6fd2807SJeff Garzik .sg_tablesize = MV_MAX_SG_CT / 2, 384c6fd2807SJeff Garzik .cmd_per_lun = ATA_SHT_CMD_PER_LUN, 385c6fd2807SJeff Garzik .emulated = ATA_SHT_EMULATED, 386c6fd2807SJeff Garzik .use_clustering = ATA_SHT_USE_CLUSTERING, 387c6fd2807SJeff Garzik .proc_name = DRV_NAME, 388c6fd2807SJeff Garzik .dma_boundary = MV_DMA_BOUNDARY, 389c6fd2807SJeff Garzik .slave_configure = ata_scsi_slave_config, 390c6fd2807SJeff Garzik .slave_destroy = ata_scsi_slave_destroy, 391c6fd2807SJeff Garzik .bios_param = ata_std_bios_param, 392c6fd2807SJeff Garzik }; 393c6fd2807SJeff Garzik 394c6fd2807SJeff Garzik static const struct ata_port_operations mv5_ops = { 395c6fd2807SJeff Garzik .port_disable = ata_port_disable, 396c6fd2807SJeff Garzik 397c6fd2807SJeff Garzik .tf_load = ata_tf_load, 398c6fd2807SJeff Garzik .tf_read = ata_tf_read, 399c6fd2807SJeff Garzik .check_status = ata_check_status, 400c6fd2807SJeff Garzik .exec_command = ata_exec_command, 401c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 402c6fd2807SJeff Garzik 403c6fd2807SJeff Garzik .phy_reset = mv_phy_reset, 404c6fd2807SJeff Garzik 405c6fd2807SJeff Garzik .qc_prep = mv_qc_prep, 406c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 407*0d5ff566STejun Heo .data_xfer = ata_data_xfer, 408c6fd2807SJeff Garzik 409c6fd2807SJeff Garzik .eng_timeout = mv_eng_timeout, 410c6fd2807SJeff Garzik 411c6fd2807SJeff Garzik .irq_handler = mv_interrupt, 412c6fd2807SJeff Garzik .irq_clear = mv_irq_clear, 413c6fd2807SJeff Garzik 414c6fd2807SJeff Garzik .scr_read = mv5_scr_read, 415c6fd2807SJeff Garzik .scr_write = mv5_scr_write, 416c6fd2807SJeff Garzik 417c6fd2807SJeff Garzik .port_start = mv_port_start, 418c6fd2807SJeff Garzik .port_stop = mv_port_stop, 419c6fd2807SJeff Garzik }; 420c6fd2807SJeff Garzik 421c6fd2807SJeff Garzik static const struct ata_port_operations mv6_ops = { 422c6fd2807SJeff Garzik .port_disable = ata_port_disable, 423c6fd2807SJeff Garzik 424c6fd2807SJeff Garzik .tf_load = ata_tf_load, 425c6fd2807SJeff Garzik .tf_read = ata_tf_read, 426c6fd2807SJeff Garzik .check_status = ata_check_status, 427c6fd2807SJeff Garzik .exec_command = ata_exec_command, 428c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 429c6fd2807SJeff Garzik 430c6fd2807SJeff Garzik .phy_reset = mv_phy_reset, 431c6fd2807SJeff Garzik 432c6fd2807SJeff Garzik .qc_prep = mv_qc_prep, 433c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 434*0d5ff566STejun Heo .data_xfer = ata_data_xfer, 435c6fd2807SJeff Garzik 436c6fd2807SJeff Garzik .eng_timeout = mv_eng_timeout, 437c6fd2807SJeff Garzik 438c6fd2807SJeff Garzik .irq_handler = mv_interrupt, 439c6fd2807SJeff Garzik .irq_clear = mv_irq_clear, 440c6fd2807SJeff Garzik 441c6fd2807SJeff Garzik .scr_read = mv_scr_read, 442c6fd2807SJeff Garzik .scr_write = mv_scr_write, 443c6fd2807SJeff Garzik 444c6fd2807SJeff Garzik .port_start = mv_port_start, 445c6fd2807SJeff Garzik .port_stop = mv_port_stop, 446c6fd2807SJeff Garzik }; 447c6fd2807SJeff Garzik 448c6fd2807SJeff Garzik static const struct ata_port_operations mv_iie_ops = { 449c6fd2807SJeff Garzik .port_disable = ata_port_disable, 450c6fd2807SJeff Garzik 451c6fd2807SJeff Garzik .tf_load = ata_tf_load, 452c6fd2807SJeff Garzik .tf_read = ata_tf_read, 453c6fd2807SJeff Garzik .check_status = ata_check_status, 454c6fd2807SJeff Garzik .exec_command = ata_exec_command, 455c6fd2807SJeff Garzik .dev_select = ata_std_dev_select, 456c6fd2807SJeff Garzik 457c6fd2807SJeff Garzik .phy_reset = mv_phy_reset, 458c6fd2807SJeff Garzik 459c6fd2807SJeff Garzik .qc_prep = mv_qc_prep_iie, 460c6fd2807SJeff Garzik .qc_issue = mv_qc_issue, 461*0d5ff566STejun Heo .data_xfer = ata_data_xfer, 462c6fd2807SJeff Garzik 463c6fd2807SJeff Garzik .eng_timeout = mv_eng_timeout, 464c6fd2807SJeff Garzik 465c6fd2807SJeff Garzik .irq_handler = mv_interrupt, 466c6fd2807SJeff Garzik .irq_clear = mv_irq_clear, 467c6fd2807SJeff Garzik 468c6fd2807SJeff Garzik .scr_read = mv_scr_read, 469c6fd2807SJeff Garzik .scr_write = mv_scr_write, 470c6fd2807SJeff Garzik 471c6fd2807SJeff Garzik .port_start = mv_port_start, 472c6fd2807SJeff Garzik .port_stop = mv_port_stop, 473c6fd2807SJeff Garzik }; 474c6fd2807SJeff Garzik 475c6fd2807SJeff Garzik static const struct ata_port_info mv_port_info[] = { 476c6fd2807SJeff Garzik { /* chip_504x */ 477c6fd2807SJeff Garzik .sht = &mv_sht, 478cca3974eSJeff Garzik .flags = MV_COMMON_FLAGS, 479c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 480c6fd2807SJeff Garzik .udma_mask = 0x7f, /* udma0-6 */ 481c6fd2807SJeff Garzik .port_ops = &mv5_ops, 482c6fd2807SJeff Garzik }, 483c6fd2807SJeff Garzik { /* chip_508x */ 484c6fd2807SJeff Garzik .sht = &mv_sht, 485cca3974eSJeff Garzik .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), 486c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 487c6fd2807SJeff Garzik .udma_mask = 0x7f, /* udma0-6 */ 488c6fd2807SJeff Garzik .port_ops = &mv5_ops, 489c6fd2807SJeff Garzik }, 490c6fd2807SJeff Garzik { /* chip_5080 */ 491c6fd2807SJeff Garzik .sht = &mv_sht, 492cca3974eSJeff Garzik .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), 493c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 494c6fd2807SJeff Garzik .udma_mask = 0x7f, /* udma0-6 */ 495c6fd2807SJeff Garzik .port_ops = &mv5_ops, 496c6fd2807SJeff Garzik }, 497c6fd2807SJeff Garzik { /* chip_604x */ 498c6fd2807SJeff Garzik .sht = &mv_sht, 499cca3974eSJeff Garzik .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), 500c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 501c6fd2807SJeff Garzik .udma_mask = 0x7f, /* udma0-6 */ 502c6fd2807SJeff Garzik .port_ops = &mv6_ops, 503c6fd2807SJeff Garzik }, 504c6fd2807SJeff Garzik { /* chip_608x */ 505c6fd2807SJeff Garzik .sht = &mv_sht, 506cca3974eSJeff Garzik .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS | 507c6fd2807SJeff Garzik MV_FLAG_DUAL_HC), 508c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 509c6fd2807SJeff Garzik .udma_mask = 0x7f, /* udma0-6 */ 510c6fd2807SJeff Garzik .port_ops = &mv6_ops, 511c6fd2807SJeff Garzik }, 512c6fd2807SJeff Garzik { /* chip_6042 */ 513c6fd2807SJeff Garzik .sht = &mv_sht, 514cca3974eSJeff Garzik .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), 515c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 516c6fd2807SJeff Garzik .udma_mask = 0x7f, /* udma0-6 */ 517c6fd2807SJeff Garzik .port_ops = &mv_iie_ops, 518c6fd2807SJeff Garzik }, 519c6fd2807SJeff Garzik { /* chip_7042 */ 520c6fd2807SJeff Garzik .sht = &mv_sht, 521e93f09dcSOlof Johansson .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), 522c6fd2807SJeff Garzik .pio_mask = 0x1f, /* pio0-4 */ 523c6fd2807SJeff Garzik .udma_mask = 0x7f, /* udma0-6 */ 524c6fd2807SJeff Garzik .port_ops = &mv_iie_ops, 525c6fd2807SJeff Garzik }, 526c6fd2807SJeff Garzik }; 527c6fd2807SJeff Garzik 528c6fd2807SJeff Garzik static const struct pci_device_id mv_pci_tbl[] = { 5292d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5040), chip_504x }, 5302d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5041), chip_504x }, 5312d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5080), chip_5080 }, 5322d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x5081), chip_508x }, 533c6fd2807SJeff Garzik 5342d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6040), chip_604x }, 5352d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6041), chip_604x }, 5362d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6042), chip_6042 }, 5372d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6080), chip_608x }, 5382d2744fcSJeff Garzik { PCI_VDEVICE(MARVELL, 0x6081), chip_608x }, 539c6fd2807SJeff Garzik 5402d2744fcSJeff Garzik { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x }, 5412d2744fcSJeff Garzik 542e93f09dcSOlof Johansson { PCI_VDEVICE(TTI, 0x2310), chip_7042 }, 543e93f09dcSOlof Johansson 544c6fd2807SJeff Garzik { } /* terminate list */ 545c6fd2807SJeff Garzik }; 546c6fd2807SJeff Garzik 547c6fd2807SJeff Garzik static struct pci_driver mv_pci_driver = { 548c6fd2807SJeff Garzik .name = DRV_NAME, 549c6fd2807SJeff Garzik .id_table = mv_pci_tbl, 550c6fd2807SJeff Garzik .probe = mv_init_one, 551c6fd2807SJeff Garzik .remove = ata_pci_remove_one, 552c6fd2807SJeff Garzik }; 553c6fd2807SJeff Garzik 554c6fd2807SJeff Garzik static const struct mv_hw_ops mv5xxx_ops = { 555c6fd2807SJeff Garzik .phy_errata = mv5_phy_errata, 556c6fd2807SJeff Garzik .enable_leds = mv5_enable_leds, 557c6fd2807SJeff Garzik .read_preamp = mv5_read_preamp, 558c6fd2807SJeff Garzik .reset_hc = mv5_reset_hc, 559c6fd2807SJeff Garzik .reset_flash = mv5_reset_flash, 560c6fd2807SJeff Garzik .reset_bus = mv5_reset_bus, 561c6fd2807SJeff Garzik }; 562c6fd2807SJeff Garzik 563c6fd2807SJeff Garzik static const struct mv_hw_ops mv6xxx_ops = { 564c6fd2807SJeff Garzik .phy_errata = mv6_phy_errata, 565c6fd2807SJeff Garzik .enable_leds = mv6_enable_leds, 566c6fd2807SJeff Garzik .read_preamp = mv6_read_preamp, 567c6fd2807SJeff Garzik .reset_hc = mv6_reset_hc, 568c6fd2807SJeff Garzik .reset_flash = mv6_reset_flash, 569c6fd2807SJeff Garzik .reset_bus = mv_reset_pci_bus, 570c6fd2807SJeff Garzik }; 571c6fd2807SJeff Garzik 572c6fd2807SJeff Garzik /* 573c6fd2807SJeff Garzik * module options 574c6fd2807SJeff Garzik */ 575c6fd2807SJeff Garzik static int msi; /* Use PCI msi; either zero (off, default) or non-zero */ 576c6fd2807SJeff Garzik 577c6fd2807SJeff Garzik 578c6fd2807SJeff Garzik /* 579c6fd2807SJeff Garzik * Functions 580c6fd2807SJeff Garzik */ 581c6fd2807SJeff Garzik 582c6fd2807SJeff Garzik static inline void writelfl(unsigned long data, void __iomem *addr) 583c6fd2807SJeff Garzik { 584c6fd2807SJeff Garzik writel(data, addr); 585c6fd2807SJeff Garzik (void) readl(addr); /* flush to avoid PCI posted write */ 586c6fd2807SJeff Garzik } 587c6fd2807SJeff Garzik 588c6fd2807SJeff Garzik static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc) 589c6fd2807SJeff Garzik { 590c6fd2807SJeff Garzik return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ)); 591c6fd2807SJeff Garzik } 592c6fd2807SJeff Garzik 593c6fd2807SJeff Garzik static inline unsigned int mv_hc_from_port(unsigned int port) 594c6fd2807SJeff Garzik { 595c6fd2807SJeff Garzik return port >> MV_PORT_HC_SHIFT; 596c6fd2807SJeff Garzik } 597c6fd2807SJeff Garzik 598c6fd2807SJeff Garzik static inline unsigned int mv_hardport_from_port(unsigned int port) 599c6fd2807SJeff Garzik { 600c6fd2807SJeff Garzik return port & MV_PORT_MASK; 601c6fd2807SJeff Garzik } 602c6fd2807SJeff Garzik 603c6fd2807SJeff Garzik static inline void __iomem *mv_hc_base_from_port(void __iomem *base, 604c6fd2807SJeff Garzik unsigned int port) 605c6fd2807SJeff Garzik { 606c6fd2807SJeff Garzik return mv_hc_base(base, mv_hc_from_port(port)); 607c6fd2807SJeff Garzik } 608c6fd2807SJeff Garzik 609c6fd2807SJeff Garzik static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port) 610c6fd2807SJeff Garzik { 611c6fd2807SJeff Garzik return mv_hc_base_from_port(base, port) + 612c6fd2807SJeff Garzik MV_SATAHC_ARBTR_REG_SZ + 613c6fd2807SJeff Garzik (mv_hardport_from_port(port) * MV_PORT_REG_SZ); 614c6fd2807SJeff Garzik } 615c6fd2807SJeff Garzik 616c6fd2807SJeff Garzik static inline void __iomem *mv_ap_base(struct ata_port *ap) 617c6fd2807SJeff Garzik { 618*0d5ff566STejun Heo return mv_port_base(ap->host->iomap[MV_PRIMARY_BAR], ap->port_no); 619c6fd2807SJeff Garzik } 620c6fd2807SJeff Garzik 621cca3974eSJeff Garzik static inline int mv_get_hc_count(unsigned long port_flags) 622c6fd2807SJeff Garzik { 623cca3974eSJeff Garzik return ((port_flags & MV_FLAG_DUAL_HC) ? 2 : 1); 624c6fd2807SJeff Garzik } 625c6fd2807SJeff Garzik 626c6fd2807SJeff Garzik static void mv_irq_clear(struct ata_port *ap) 627c6fd2807SJeff Garzik { 628c6fd2807SJeff Garzik } 629c6fd2807SJeff Garzik 630c6fd2807SJeff Garzik /** 631c6fd2807SJeff Garzik * mv_start_dma - Enable eDMA engine 632c6fd2807SJeff Garzik * @base: port base address 633c6fd2807SJeff Garzik * @pp: port private data 634c6fd2807SJeff Garzik * 635c6fd2807SJeff Garzik * Verify the local cache of the eDMA state is accurate with a 636c6fd2807SJeff Garzik * WARN_ON. 637c6fd2807SJeff Garzik * 638c6fd2807SJeff Garzik * LOCKING: 639c6fd2807SJeff Garzik * Inherited from caller. 640c6fd2807SJeff Garzik */ 641c6fd2807SJeff Garzik static void mv_start_dma(void __iomem *base, struct mv_port_priv *pp) 642c6fd2807SJeff Garzik { 643c6fd2807SJeff Garzik if (!(MV_PP_FLAG_EDMA_EN & pp->pp_flags)) { 644c6fd2807SJeff Garzik writelfl(EDMA_EN, base + EDMA_CMD_OFS); 645c6fd2807SJeff Garzik pp->pp_flags |= MV_PP_FLAG_EDMA_EN; 646c6fd2807SJeff Garzik } 647c6fd2807SJeff Garzik WARN_ON(!(EDMA_EN & readl(base + EDMA_CMD_OFS))); 648c6fd2807SJeff Garzik } 649c6fd2807SJeff Garzik 650c6fd2807SJeff Garzik /** 651c6fd2807SJeff Garzik * mv_stop_dma - Disable eDMA engine 652c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 653c6fd2807SJeff Garzik * 654c6fd2807SJeff Garzik * Verify the local cache of the eDMA state is accurate with a 655c6fd2807SJeff Garzik * WARN_ON. 656c6fd2807SJeff Garzik * 657c6fd2807SJeff Garzik * LOCKING: 658c6fd2807SJeff Garzik * Inherited from caller. 659c6fd2807SJeff Garzik */ 660c6fd2807SJeff Garzik static void mv_stop_dma(struct ata_port *ap) 661c6fd2807SJeff Garzik { 662c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 663c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 664c6fd2807SJeff Garzik u32 reg; 665c6fd2807SJeff Garzik int i; 666c6fd2807SJeff Garzik 667c6fd2807SJeff Garzik if (MV_PP_FLAG_EDMA_EN & pp->pp_flags) { 668c6fd2807SJeff Garzik /* Disable EDMA if active. The disable bit auto clears. 669c6fd2807SJeff Garzik */ 670c6fd2807SJeff Garzik writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 671c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 672c6fd2807SJeff Garzik } else { 673c6fd2807SJeff Garzik WARN_ON(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS)); 674c6fd2807SJeff Garzik } 675c6fd2807SJeff Garzik 676c6fd2807SJeff Garzik /* now properly wait for the eDMA to stop */ 677c6fd2807SJeff Garzik for (i = 1000; i > 0; i--) { 678c6fd2807SJeff Garzik reg = readl(port_mmio + EDMA_CMD_OFS); 679c6fd2807SJeff Garzik if (!(EDMA_EN & reg)) { 680c6fd2807SJeff Garzik break; 681c6fd2807SJeff Garzik } 682c6fd2807SJeff Garzik udelay(100); 683c6fd2807SJeff Garzik } 684c6fd2807SJeff Garzik 685c6fd2807SJeff Garzik if (EDMA_EN & reg) { 686c6fd2807SJeff Garzik ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n"); 687c6fd2807SJeff Garzik /* FIXME: Consider doing a reset here to recover */ 688c6fd2807SJeff Garzik } 689c6fd2807SJeff Garzik } 690c6fd2807SJeff Garzik 691c6fd2807SJeff Garzik #ifdef ATA_DEBUG 692c6fd2807SJeff Garzik static void mv_dump_mem(void __iomem *start, unsigned bytes) 693c6fd2807SJeff Garzik { 694c6fd2807SJeff Garzik int b, w; 695c6fd2807SJeff Garzik for (b = 0; b < bytes; ) { 696c6fd2807SJeff Garzik DPRINTK("%p: ", start + b); 697c6fd2807SJeff Garzik for (w = 0; b < bytes && w < 4; w++) { 698c6fd2807SJeff Garzik printk("%08x ",readl(start + b)); 699c6fd2807SJeff Garzik b += sizeof(u32); 700c6fd2807SJeff Garzik } 701c6fd2807SJeff Garzik printk("\n"); 702c6fd2807SJeff Garzik } 703c6fd2807SJeff Garzik } 704c6fd2807SJeff Garzik #endif 705c6fd2807SJeff Garzik 706c6fd2807SJeff Garzik static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes) 707c6fd2807SJeff Garzik { 708c6fd2807SJeff Garzik #ifdef ATA_DEBUG 709c6fd2807SJeff Garzik int b, w; 710c6fd2807SJeff Garzik u32 dw; 711c6fd2807SJeff Garzik for (b = 0; b < bytes; ) { 712c6fd2807SJeff Garzik DPRINTK("%02x: ", b); 713c6fd2807SJeff Garzik for (w = 0; b < bytes && w < 4; w++) { 714c6fd2807SJeff Garzik (void) pci_read_config_dword(pdev,b,&dw); 715c6fd2807SJeff Garzik printk("%08x ",dw); 716c6fd2807SJeff Garzik b += sizeof(u32); 717c6fd2807SJeff Garzik } 718c6fd2807SJeff Garzik printk("\n"); 719c6fd2807SJeff Garzik } 720c6fd2807SJeff Garzik #endif 721c6fd2807SJeff Garzik } 722c6fd2807SJeff Garzik static void mv_dump_all_regs(void __iomem *mmio_base, int port, 723c6fd2807SJeff Garzik struct pci_dev *pdev) 724c6fd2807SJeff Garzik { 725c6fd2807SJeff Garzik #ifdef ATA_DEBUG 726c6fd2807SJeff Garzik void __iomem *hc_base = mv_hc_base(mmio_base, 727c6fd2807SJeff Garzik port >> MV_PORT_HC_SHIFT); 728c6fd2807SJeff Garzik void __iomem *port_base; 729c6fd2807SJeff Garzik int start_port, num_ports, p, start_hc, num_hcs, hc; 730c6fd2807SJeff Garzik 731c6fd2807SJeff Garzik if (0 > port) { 732c6fd2807SJeff Garzik start_hc = start_port = 0; 733c6fd2807SJeff Garzik num_ports = 8; /* shld be benign for 4 port devs */ 734c6fd2807SJeff Garzik num_hcs = 2; 735c6fd2807SJeff Garzik } else { 736c6fd2807SJeff Garzik start_hc = port >> MV_PORT_HC_SHIFT; 737c6fd2807SJeff Garzik start_port = port; 738c6fd2807SJeff Garzik num_ports = num_hcs = 1; 739c6fd2807SJeff Garzik } 740c6fd2807SJeff Garzik DPRINTK("All registers for port(s) %u-%u:\n", start_port, 741c6fd2807SJeff Garzik num_ports > 1 ? num_ports - 1 : start_port); 742c6fd2807SJeff Garzik 743c6fd2807SJeff Garzik if (NULL != pdev) { 744c6fd2807SJeff Garzik DPRINTK("PCI config space regs:\n"); 745c6fd2807SJeff Garzik mv_dump_pci_cfg(pdev, 0x68); 746c6fd2807SJeff Garzik } 747c6fd2807SJeff Garzik DPRINTK("PCI regs:\n"); 748c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xc00, 0x3c); 749c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xd00, 0x34); 750c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0xf00, 0x4); 751c6fd2807SJeff Garzik mv_dump_mem(mmio_base+0x1d00, 0x6c); 752c6fd2807SJeff Garzik for (hc = start_hc; hc < start_hc + num_hcs; hc++) { 753c6fd2807SJeff Garzik hc_base = mv_hc_base(mmio_base, hc); 754c6fd2807SJeff Garzik DPRINTK("HC regs (HC %i):\n", hc); 755c6fd2807SJeff Garzik mv_dump_mem(hc_base, 0x1c); 756c6fd2807SJeff Garzik } 757c6fd2807SJeff Garzik for (p = start_port; p < start_port + num_ports; p++) { 758c6fd2807SJeff Garzik port_base = mv_port_base(mmio_base, p); 759c6fd2807SJeff Garzik DPRINTK("EDMA regs (port %i):\n",p); 760c6fd2807SJeff Garzik mv_dump_mem(port_base, 0x54); 761c6fd2807SJeff Garzik DPRINTK("SATA regs (port %i):\n",p); 762c6fd2807SJeff Garzik mv_dump_mem(port_base+0x300, 0x60); 763c6fd2807SJeff Garzik } 764c6fd2807SJeff Garzik #endif 765c6fd2807SJeff Garzik } 766c6fd2807SJeff Garzik 767c6fd2807SJeff Garzik static unsigned int mv_scr_offset(unsigned int sc_reg_in) 768c6fd2807SJeff Garzik { 769c6fd2807SJeff Garzik unsigned int ofs; 770c6fd2807SJeff Garzik 771c6fd2807SJeff Garzik switch (sc_reg_in) { 772c6fd2807SJeff Garzik case SCR_STATUS: 773c6fd2807SJeff Garzik case SCR_CONTROL: 774c6fd2807SJeff Garzik case SCR_ERROR: 775c6fd2807SJeff Garzik ofs = SATA_STATUS_OFS + (sc_reg_in * sizeof(u32)); 776c6fd2807SJeff Garzik break; 777c6fd2807SJeff Garzik case SCR_ACTIVE: 778c6fd2807SJeff Garzik ofs = SATA_ACTIVE_OFS; /* active is not with the others */ 779c6fd2807SJeff Garzik break; 780c6fd2807SJeff Garzik default: 781c6fd2807SJeff Garzik ofs = 0xffffffffU; 782c6fd2807SJeff Garzik break; 783c6fd2807SJeff Garzik } 784c6fd2807SJeff Garzik return ofs; 785c6fd2807SJeff Garzik } 786c6fd2807SJeff Garzik 787c6fd2807SJeff Garzik static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in) 788c6fd2807SJeff Garzik { 789c6fd2807SJeff Garzik unsigned int ofs = mv_scr_offset(sc_reg_in); 790c6fd2807SJeff Garzik 791c6fd2807SJeff Garzik if (0xffffffffU != ofs) { 792c6fd2807SJeff Garzik return readl(mv_ap_base(ap) + ofs); 793c6fd2807SJeff Garzik } else { 794c6fd2807SJeff Garzik return (u32) ofs; 795c6fd2807SJeff Garzik } 796c6fd2807SJeff Garzik } 797c6fd2807SJeff Garzik 798c6fd2807SJeff Garzik static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 799c6fd2807SJeff Garzik { 800c6fd2807SJeff Garzik unsigned int ofs = mv_scr_offset(sc_reg_in); 801c6fd2807SJeff Garzik 802c6fd2807SJeff Garzik if (0xffffffffU != ofs) { 803c6fd2807SJeff Garzik writelfl(val, mv_ap_base(ap) + ofs); 804c6fd2807SJeff Garzik } 805c6fd2807SJeff Garzik } 806c6fd2807SJeff Garzik 807c6fd2807SJeff Garzik static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio) 808c6fd2807SJeff Garzik { 809c6fd2807SJeff Garzik u32 cfg = readl(port_mmio + EDMA_CFG_OFS); 810c6fd2807SJeff Garzik 811c6fd2807SJeff Garzik /* set up non-NCQ EDMA configuration */ 812c6fd2807SJeff Garzik cfg &= ~0x1f; /* clear queue depth */ 813c6fd2807SJeff Garzik cfg &= ~EDMA_CFG_NCQ; /* clear NCQ mode */ 814c6fd2807SJeff Garzik cfg &= ~(1 << 9); /* disable equeue */ 815c6fd2807SJeff Garzik 816c6fd2807SJeff Garzik if (IS_GEN_I(hpriv)) 817c6fd2807SJeff Garzik cfg |= (1 << 8); /* enab config burst size mask */ 818c6fd2807SJeff Garzik 819c6fd2807SJeff Garzik else if (IS_GEN_II(hpriv)) 820c6fd2807SJeff Garzik cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN; 821c6fd2807SJeff Garzik 822c6fd2807SJeff Garzik else if (IS_GEN_IIE(hpriv)) { 823c6fd2807SJeff Garzik cfg |= (1 << 23); /* dis RX PM port mask */ 824c6fd2807SJeff Garzik cfg &= ~(1 << 16); /* dis FIS-based switching (for now) */ 825c6fd2807SJeff Garzik cfg &= ~(1 << 19); /* dis 128-entry queue (for now?) */ 826c6fd2807SJeff Garzik cfg |= (1 << 18); /* enab early completion */ 827c6fd2807SJeff Garzik cfg |= (1 << 17); /* enab host q cache */ 828c6fd2807SJeff Garzik cfg |= (1 << 22); /* enab cutthrough */ 829c6fd2807SJeff Garzik } 830c6fd2807SJeff Garzik 831c6fd2807SJeff Garzik writelfl(cfg, port_mmio + EDMA_CFG_OFS); 832c6fd2807SJeff Garzik } 833c6fd2807SJeff Garzik 834c6fd2807SJeff Garzik /** 835c6fd2807SJeff Garzik * mv_port_start - Port specific init/start routine. 836c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 837c6fd2807SJeff Garzik * 838c6fd2807SJeff Garzik * Allocate and point to DMA memory, init port private memory, 839c6fd2807SJeff Garzik * zero indices. 840c6fd2807SJeff Garzik * 841c6fd2807SJeff Garzik * LOCKING: 842c6fd2807SJeff Garzik * Inherited from caller. 843c6fd2807SJeff Garzik */ 844c6fd2807SJeff Garzik static int mv_port_start(struct ata_port *ap) 845c6fd2807SJeff Garzik { 846cca3974eSJeff Garzik struct device *dev = ap->host->dev; 847cca3974eSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 848c6fd2807SJeff Garzik struct mv_port_priv *pp; 849c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 850c6fd2807SJeff Garzik void *mem; 851c6fd2807SJeff Garzik dma_addr_t mem_dma; 85224dc5f33STejun Heo int rc; 853c6fd2807SJeff Garzik 85424dc5f33STejun Heo pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL); 855c6fd2807SJeff Garzik if (!pp) 85624dc5f33STejun Heo return -ENOMEM; 857c6fd2807SJeff Garzik 85824dc5f33STejun Heo mem = dmam_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma, 859c6fd2807SJeff Garzik GFP_KERNEL); 860c6fd2807SJeff Garzik if (!mem) 86124dc5f33STejun Heo return -ENOMEM; 862c6fd2807SJeff Garzik memset(mem, 0, MV_PORT_PRIV_DMA_SZ); 863c6fd2807SJeff Garzik 864c6fd2807SJeff Garzik rc = ata_pad_alloc(ap, dev); 865c6fd2807SJeff Garzik if (rc) 86624dc5f33STejun Heo return rc; 867c6fd2807SJeff Garzik 868c6fd2807SJeff Garzik /* First item in chunk of DMA memory: 869c6fd2807SJeff Garzik * 32-slot command request table (CRQB), 32 bytes each in size 870c6fd2807SJeff Garzik */ 871c6fd2807SJeff Garzik pp->crqb = mem; 872c6fd2807SJeff Garzik pp->crqb_dma = mem_dma; 873c6fd2807SJeff Garzik mem += MV_CRQB_Q_SZ; 874c6fd2807SJeff Garzik mem_dma += MV_CRQB_Q_SZ; 875c6fd2807SJeff Garzik 876c6fd2807SJeff Garzik /* Second item: 877c6fd2807SJeff Garzik * 32-slot command response table (CRPB), 8 bytes each in size 878c6fd2807SJeff Garzik */ 879c6fd2807SJeff Garzik pp->crpb = mem; 880c6fd2807SJeff Garzik pp->crpb_dma = mem_dma; 881c6fd2807SJeff Garzik mem += MV_CRPB_Q_SZ; 882c6fd2807SJeff Garzik mem_dma += MV_CRPB_Q_SZ; 883c6fd2807SJeff Garzik 884c6fd2807SJeff Garzik /* Third item: 885c6fd2807SJeff Garzik * Table of scatter-gather descriptors (ePRD), 16 bytes each 886c6fd2807SJeff Garzik */ 887c6fd2807SJeff Garzik pp->sg_tbl = mem; 888c6fd2807SJeff Garzik pp->sg_tbl_dma = mem_dma; 889c6fd2807SJeff Garzik 890c6fd2807SJeff Garzik mv_edma_cfg(hpriv, port_mmio); 891c6fd2807SJeff Garzik 892c6fd2807SJeff Garzik writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); 893c6fd2807SJeff Garzik writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK, 894c6fd2807SJeff Garzik port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 895c6fd2807SJeff Garzik 896c6fd2807SJeff Garzik if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) 897c6fd2807SJeff Garzik writelfl(pp->crqb_dma & 0xffffffff, 898c6fd2807SJeff Garzik port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); 899c6fd2807SJeff Garzik else 900c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); 901c6fd2807SJeff Garzik 902c6fd2807SJeff Garzik writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS); 903c6fd2807SJeff Garzik 904c6fd2807SJeff Garzik if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) 905c6fd2807SJeff Garzik writelfl(pp->crpb_dma & 0xffffffff, 906c6fd2807SJeff Garzik port_mmio + EDMA_RSP_Q_IN_PTR_OFS); 907c6fd2807SJeff Garzik else 908c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS); 909c6fd2807SJeff Garzik 910c6fd2807SJeff Garzik writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK, 911c6fd2807SJeff Garzik port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 912c6fd2807SJeff Garzik 913c6fd2807SJeff Garzik /* Don't turn on EDMA here...do it before DMA commands only. Else 914c6fd2807SJeff Garzik * we'll be unable to send non-data, PIO, etc due to restricted access 915c6fd2807SJeff Garzik * to shadow regs. 916c6fd2807SJeff Garzik */ 917c6fd2807SJeff Garzik ap->private_data = pp; 918c6fd2807SJeff Garzik return 0; 919c6fd2807SJeff Garzik } 920c6fd2807SJeff Garzik 921c6fd2807SJeff Garzik /** 922c6fd2807SJeff Garzik * mv_port_stop - Port specific cleanup/stop routine. 923c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 924c6fd2807SJeff Garzik * 925c6fd2807SJeff Garzik * Stop DMA, cleanup port memory. 926c6fd2807SJeff Garzik * 927c6fd2807SJeff Garzik * LOCKING: 928cca3974eSJeff Garzik * This routine uses the host lock to protect the DMA stop. 929c6fd2807SJeff Garzik */ 930c6fd2807SJeff Garzik static void mv_port_stop(struct ata_port *ap) 931c6fd2807SJeff Garzik { 932c6fd2807SJeff Garzik unsigned long flags; 933c6fd2807SJeff Garzik 934cca3974eSJeff Garzik spin_lock_irqsave(&ap->host->lock, flags); 935c6fd2807SJeff Garzik mv_stop_dma(ap); 936cca3974eSJeff Garzik spin_unlock_irqrestore(&ap->host->lock, flags); 937c6fd2807SJeff Garzik } 938c6fd2807SJeff Garzik 939c6fd2807SJeff Garzik /** 940c6fd2807SJeff Garzik * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries 941c6fd2807SJeff Garzik * @qc: queued command whose SG list to source from 942c6fd2807SJeff Garzik * 943c6fd2807SJeff Garzik * Populate the SG list and mark the last entry. 944c6fd2807SJeff Garzik * 945c6fd2807SJeff Garzik * LOCKING: 946c6fd2807SJeff Garzik * Inherited from caller. 947c6fd2807SJeff Garzik */ 948c6fd2807SJeff Garzik static void mv_fill_sg(struct ata_queued_cmd *qc) 949c6fd2807SJeff Garzik { 950c6fd2807SJeff Garzik struct mv_port_priv *pp = qc->ap->private_data; 951c6fd2807SJeff Garzik unsigned int i = 0; 952c6fd2807SJeff Garzik struct scatterlist *sg; 953c6fd2807SJeff Garzik 954c6fd2807SJeff Garzik ata_for_each_sg(sg, qc) { 955c6fd2807SJeff Garzik dma_addr_t addr; 956c6fd2807SJeff Garzik u32 sg_len, len, offset; 957c6fd2807SJeff Garzik 958c6fd2807SJeff Garzik addr = sg_dma_address(sg); 959c6fd2807SJeff Garzik sg_len = sg_dma_len(sg); 960c6fd2807SJeff Garzik 961c6fd2807SJeff Garzik while (sg_len) { 962c6fd2807SJeff Garzik offset = addr & MV_DMA_BOUNDARY; 963c6fd2807SJeff Garzik len = sg_len; 964c6fd2807SJeff Garzik if ((offset + sg_len) > 0x10000) 965c6fd2807SJeff Garzik len = 0x10000 - offset; 966c6fd2807SJeff Garzik 967c6fd2807SJeff Garzik pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff); 968c6fd2807SJeff Garzik pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16); 969c6fd2807SJeff Garzik pp->sg_tbl[i].flags_size = cpu_to_le32(len & 0xffff); 970c6fd2807SJeff Garzik 971c6fd2807SJeff Garzik sg_len -= len; 972c6fd2807SJeff Garzik addr += len; 973c6fd2807SJeff Garzik 974c6fd2807SJeff Garzik if (!sg_len && ata_sg_is_last(sg, qc)) 975c6fd2807SJeff Garzik pp->sg_tbl[i].flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL); 976c6fd2807SJeff Garzik 977c6fd2807SJeff Garzik i++; 978c6fd2807SJeff Garzik } 979c6fd2807SJeff Garzik } 980c6fd2807SJeff Garzik } 981c6fd2807SJeff Garzik 982c6fd2807SJeff Garzik static inline unsigned mv_inc_q_index(unsigned index) 983c6fd2807SJeff Garzik { 984c6fd2807SJeff Garzik return (index + 1) & MV_MAX_Q_DEPTH_MASK; 985c6fd2807SJeff Garzik } 986c6fd2807SJeff Garzik 987c6fd2807SJeff Garzik static inline void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last) 988c6fd2807SJeff Garzik { 989c6fd2807SJeff Garzik u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS | 990c6fd2807SJeff Garzik (last ? CRQB_CMD_LAST : 0); 991c6fd2807SJeff Garzik *cmdw = cpu_to_le16(tmp); 992c6fd2807SJeff Garzik } 993c6fd2807SJeff Garzik 994c6fd2807SJeff Garzik /** 995c6fd2807SJeff Garzik * mv_qc_prep - Host specific command preparation. 996c6fd2807SJeff Garzik * @qc: queued command to prepare 997c6fd2807SJeff Garzik * 998c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 999c6fd2807SJeff Garzik * if command is not DMA. Else, it handles prep of the CRQB 1000c6fd2807SJeff Garzik * (command request block), does some sanity checking, and calls 1001c6fd2807SJeff Garzik * the SG load routine. 1002c6fd2807SJeff Garzik * 1003c6fd2807SJeff Garzik * LOCKING: 1004c6fd2807SJeff Garzik * Inherited from caller. 1005c6fd2807SJeff Garzik */ 1006c6fd2807SJeff Garzik static void mv_qc_prep(struct ata_queued_cmd *qc) 1007c6fd2807SJeff Garzik { 1008c6fd2807SJeff Garzik struct ata_port *ap = qc->ap; 1009c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1010c6fd2807SJeff Garzik __le16 *cw; 1011c6fd2807SJeff Garzik struct ata_taskfile *tf; 1012c6fd2807SJeff Garzik u16 flags = 0; 1013c6fd2807SJeff Garzik unsigned in_index; 1014c6fd2807SJeff Garzik 1015c6fd2807SJeff Garzik if (ATA_PROT_DMA != qc->tf.protocol) 1016c6fd2807SJeff Garzik return; 1017c6fd2807SJeff Garzik 1018c6fd2807SJeff Garzik /* Fill in command request block 1019c6fd2807SJeff Garzik */ 1020c6fd2807SJeff Garzik if (!(qc->tf.flags & ATA_TFLAG_WRITE)) 1021c6fd2807SJeff Garzik flags |= CRQB_FLAG_READ; 1022c6fd2807SJeff Garzik WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 1023c6fd2807SJeff Garzik flags |= qc->tag << CRQB_TAG_SHIFT; 1024c6fd2807SJeff Garzik 1025c6fd2807SJeff Garzik /* get current queue index from hardware */ 1026c6fd2807SJeff Garzik in_index = (readl(mv_ap_base(ap) + EDMA_REQ_Q_IN_PTR_OFS) 1027c6fd2807SJeff Garzik >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 1028c6fd2807SJeff Garzik 1029c6fd2807SJeff Garzik pp->crqb[in_index].sg_addr = 1030c6fd2807SJeff Garzik cpu_to_le32(pp->sg_tbl_dma & 0xffffffff); 1031c6fd2807SJeff Garzik pp->crqb[in_index].sg_addr_hi = 1032c6fd2807SJeff Garzik cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16); 1033c6fd2807SJeff Garzik pp->crqb[in_index].ctrl_flags = cpu_to_le16(flags); 1034c6fd2807SJeff Garzik 1035c6fd2807SJeff Garzik cw = &pp->crqb[in_index].ata_cmd[0]; 1036c6fd2807SJeff Garzik tf = &qc->tf; 1037c6fd2807SJeff Garzik 1038c6fd2807SJeff Garzik /* Sadly, the CRQB cannot accomodate all registers--there are 1039c6fd2807SJeff Garzik * only 11 bytes...so we must pick and choose required 1040c6fd2807SJeff Garzik * registers based on the command. So, we drop feature and 1041c6fd2807SJeff Garzik * hob_feature for [RW] DMA commands, but they are needed for 1042c6fd2807SJeff Garzik * NCQ. NCQ will drop hob_nsect. 1043c6fd2807SJeff Garzik */ 1044c6fd2807SJeff Garzik switch (tf->command) { 1045c6fd2807SJeff Garzik case ATA_CMD_READ: 1046c6fd2807SJeff Garzik case ATA_CMD_READ_EXT: 1047c6fd2807SJeff Garzik case ATA_CMD_WRITE: 1048c6fd2807SJeff Garzik case ATA_CMD_WRITE_EXT: 1049c6fd2807SJeff Garzik case ATA_CMD_WRITE_FUA_EXT: 1050c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0); 1051c6fd2807SJeff Garzik break; 1052c6fd2807SJeff Garzik #ifdef LIBATA_NCQ /* FIXME: remove this line when NCQ added */ 1053c6fd2807SJeff Garzik case ATA_CMD_FPDMA_READ: 1054c6fd2807SJeff Garzik case ATA_CMD_FPDMA_WRITE: 1055c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0); 1056c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0); 1057c6fd2807SJeff Garzik break; 1058c6fd2807SJeff Garzik #endif /* FIXME: remove this line when NCQ added */ 1059c6fd2807SJeff Garzik default: 1060c6fd2807SJeff Garzik /* The only other commands EDMA supports in non-queued and 1061c6fd2807SJeff Garzik * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none 1062c6fd2807SJeff Garzik * of which are defined/used by Linux. If we get here, this 1063c6fd2807SJeff Garzik * driver needs work. 1064c6fd2807SJeff Garzik * 1065c6fd2807SJeff Garzik * FIXME: modify libata to give qc_prep a return value and 1066c6fd2807SJeff Garzik * return error here. 1067c6fd2807SJeff Garzik */ 1068c6fd2807SJeff Garzik BUG_ON(tf->command); 1069c6fd2807SJeff Garzik break; 1070c6fd2807SJeff Garzik } 1071c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0); 1072c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0); 1073c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0); 1074c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0); 1075c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0); 1076c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0); 1077c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0); 1078c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0); 1079c6fd2807SJeff Garzik mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */ 1080c6fd2807SJeff Garzik 1081c6fd2807SJeff Garzik if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 1082c6fd2807SJeff Garzik return; 1083c6fd2807SJeff Garzik mv_fill_sg(qc); 1084c6fd2807SJeff Garzik } 1085c6fd2807SJeff Garzik 1086c6fd2807SJeff Garzik /** 1087c6fd2807SJeff Garzik * mv_qc_prep_iie - Host specific command preparation. 1088c6fd2807SJeff Garzik * @qc: queued command to prepare 1089c6fd2807SJeff Garzik * 1090c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1091c6fd2807SJeff Garzik * if command is not DMA. Else, it handles prep of the CRQB 1092c6fd2807SJeff Garzik * (command request block), does some sanity checking, and calls 1093c6fd2807SJeff Garzik * the SG load routine. 1094c6fd2807SJeff Garzik * 1095c6fd2807SJeff Garzik * LOCKING: 1096c6fd2807SJeff Garzik * Inherited from caller. 1097c6fd2807SJeff Garzik */ 1098c6fd2807SJeff Garzik static void mv_qc_prep_iie(struct ata_queued_cmd *qc) 1099c6fd2807SJeff Garzik { 1100c6fd2807SJeff Garzik struct ata_port *ap = qc->ap; 1101c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1102c6fd2807SJeff Garzik struct mv_crqb_iie *crqb; 1103c6fd2807SJeff Garzik struct ata_taskfile *tf; 1104c6fd2807SJeff Garzik unsigned in_index; 1105c6fd2807SJeff Garzik u32 flags = 0; 1106c6fd2807SJeff Garzik 1107c6fd2807SJeff Garzik if (ATA_PROT_DMA != qc->tf.protocol) 1108c6fd2807SJeff Garzik return; 1109c6fd2807SJeff Garzik 1110c6fd2807SJeff Garzik /* Fill in Gen IIE command request block 1111c6fd2807SJeff Garzik */ 1112c6fd2807SJeff Garzik if (!(qc->tf.flags & ATA_TFLAG_WRITE)) 1113c6fd2807SJeff Garzik flags |= CRQB_FLAG_READ; 1114c6fd2807SJeff Garzik 1115c6fd2807SJeff Garzik WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); 1116c6fd2807SJeff Garzik flags |= qc->tag << CRQB_TAG_SHIFT; 1117c6fd2807SJeff Garzik 1118c6fd2807SJeff Garzik /* get current queue index from hardware */ 1119c6fd2807SJeff Garzik in_index = (readl(mv_ap_base(ap) + EDMA_REQ_Q_IN_PTR_OFS) 1120c6fd2807SJeff Garzik >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 1121c6fd2807SJeff Garzik 1122c6fd2807SJeff Garzik crqb = (struct mv_crqb_iie *) &pp->crqb[in_index]; 1123c6fd2807SJeff Garzik crqb->addr = cpu_to_le32(pp->sg_tbl_dma & 0xffffffff); 1124c6fd2807SJeff Garzik crqb->addr_hi = cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16); 1125c6fd2807SJeff Garzik crqb->flags = cpu_to_le32(flags); 1126c6fd2807SJeff Garzik 1127c6fd2807SJeff Garzik tf = &qc->tf; 1128c6fd2807SJeff Garzik crqb->ata_cmd[0] = cpu_to_le32( 1129c6fd2807SJeff Garzik (tf->command << 16) | 1130c6fd2807SJeff Garzik (tf->feature << 24) 1131c6fd2807SJeff Garzik ); 1132c6fd2807SJeff Garzik crqb->ata_cmd[1] = cpu_to_le32( 1133c6fd2807SJeff Garzik (tf->lbal << 0) | 1134c6fd2807SJeff Garzik (tf->lbam << 8) | 1135c6fd2807SJeff Garzik (tf->lbah << 16) | 1136c6fd2807SJeff Garzik (tf->device << 24) 1137c6fd2807SJeff Garzik ); 1138c6fd2807SJeff Garzik crqb->ata_cmd[2] = cpu_to_le32( 1139c6fd2807SJeff Garzik (tf->hob_lbal << 0) | 1140c6fd2807SJeff Garzik (tf->hob_lbam << 8) | 1141c6fd2807SJeff Garzik (tf->hob_lbah << 16) | 1142c6fd2807SJeff Garzik (tf->hob_feature << 24) 1143c6fd2807SJeff Garzik ); 1144c6fd2807SJeff Garzik crqb->ata_cmd[3] = cpu_to_le32( 1145c6fd2807SJeff Garzik (tf->nsect << 0) | 1146c6fd2807SJeff Garzik (tf->hob_nsect << 8) 1147c6fd2807SJeff Garzik ); 1148c6fd2807SJeff Garzik 1149c6fd2807SJeff Garzik if (!(qc->flags & ATA_QCFLAG_DMAMAP)) 1150c6fd2807SJeff Garzik return; 1151c6fd2807SJeff Garzik mv_fill_sg(qc); 1152c6fd2807SJeff Garzik } 1153c6fd2807SJeff Garzik 1154c6fd2807SJeff Garzik /** 1155c6fd2807SJeff Garzik * mv_qc_issue - Initiate a command to the host 1156c6fd2807SJeff Garzik * @qc: queued command to start 1157c6fd2807SJeff Garzik * 1158c6fd2807SJeff Garzik * This routine simply redirects to the general purpose routine 1159c6fd2807SJeff Garzik * if command is not DMA. Else, it sanity checks our local 1160c6fd2807SJeff Garzik * caches of the request producer/consumer indices then enables 1161c6fd2807SJeff Garzik * DMA and bumps the request producer index. 1162c6fd2807SJeff Garzik * 1163c6fd2807SJeff Garzik * LOCKING: 1164c6fd2807SJeff Garzik * Inherited from caller. 1165c6fd2807SJeff Garzik */ 1166c6fd2807SJeff Garzik static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) 1167c6fd2807SJeff Garzik { 1168c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(qc->ap); 1169c6fd2807SJeff Garzik struct mv_port_priv *pp = qc->ap->private_data; 1170c6fd2807SJeff Garzik unsigned in_index; 1171c6fd2807SJeff Garzik u32 in_ptr; 1172c6fd2807SJeff Garzik 1173c6fd2807SJeff Garzik if (ATA_PROT_DMA != qc->tf.protocol) { 1174c6fd2807SJeff Garzik /* We're about to send a non-EDMA capable command to the 1175c6fd2807SJeff Garzik * port. Turn off EDMA so there won't be problems accessing 1176c6fd2807SJeff Garzik * shadow block, etc registers. 1177c6fd2807SJeff Garzik */ 1178c6fd2807SJeff Garzik mv_stop_dma(qc->ap); 1179c6fd2807SJeff Garzik return ata_qc_issue_prot(qc); 1180c6fd2807SJeff Garzik } 1181c6fd2807SJeff Garzik 1182c6fd2807SJeff Garzik in_ptr = readl(port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 1183c6fd2807SJeff Garzik in_index = (in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 1184c6fd2807SJeff Garzik 1185c6fd2807SJeff Garzik /* until we do queuing, the queue should be empty at this point */ 1186c6fd2807SJeff Garzik WARN_ON(in_index != ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) 1187c6fd2807SJeff Garzik >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK)); 1188c6fd2807SJeff Garzik 1189c6fd2807SJeff Garzik in_index = mv_inc_q_index(in_index); /* now incr producer index */ 1190c6fd2807SJeff Garzik 1191c6fd2807SJeff Garzik mv_start_dma(port_mmio, pp); 1192c6fd2807SJeff Garzik 1193c6fd2807SJeff Garzik /* and write the request in pointer to kick the EDMA to life */ 1194c6fd2807SJeff Garzik in_ptr &= EDMA_REQ_Q_BASE_LO_MASK; 1195c6fd2807SJeff Garzik in_ptr |= in_index << EDMA_REQ_Q_PTR_SHIFT; 1196c6fd2807SJeff Garzik writelfl(in_ptr, port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 1197c6fd2807SJeff Garzik 1198c6fd2807SJeff Garzik return 0; 1199c6fd2807SJeff Garzik } 1200c6fd2807SJeff Garzik 1201c6fd2807SJeff Garzik /** 1202c6fd2807SJeff Garzik * mv_get_crpb_status - get status from most recently completed cmd 1203c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1204c6fd2807SJeff Garzik * 1205c6fd2807SJeff Garzik * This routine is for use when the port is in DMA mode, when it 1206c6fd2807SJeff Garzik * will be using the CRPB (command response block) method of 1207c6fd2807SJeff Garzik * returning command completion information. We check indices 1208c6fd2807SJeff Garzik * are good, grab status, and bump the response consumer index to 1209c6fd2807SJeff Garzik * prove that we're up to date. 1210c6fd2807SJeff Garzik * 1211c6fd2807SJeff Garzik * LOCKING: 1212c6fd2807SJeff Garzik * Inherited from caller. 1213c6fd2807SJeff Garzik */ 1214c6fd2807SJeff Garzik static u8 mv_get_crpb_status(struct ata_port *ap) 1215c6fd2807SJeff Garzik { 1216c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1217c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1218c6fd2807SJeff Garzik unsigned out_index; 1219c6fd2807SJeff Garzik u32 out_ptr; 1220c6fd2807SJeff Garzik u8 ata_status; 1221c6fd2807SJeff Garzik 1222c6fd2807SJeff Garzik out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 1223c6fd2807SJeff Garzik out_index = (out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; 1224c6fd2807SJeff Garzik 1225c6fd2807SJeff Garzik ata_status = le16_to_cpu(pp->crpb[out_index].flags) 1226c6fd2807SJeff Garzik >> CRPB_FLAG_STATUS_SHIFT; 1227c6fd2807SJeff Garzik 1228c6fd2807SJeff Garzik /* increment our consumer index... */ 1229c6fd2807SJeff Garzik out_index = mv_inc_q_index(out_index); 1230c6fd2807SJeff Garzik 1231c6fd2807SJeff Garzik /* and, until we do NCQ, there should only be 1 CRPB waiting */ 1232c6fd2807SJeff Garzik WARN_ON(out_index != ((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) 1233c6fd2807SJeff Garzik >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK)); 1234c6fd2807SJeff Garzik 1235c6fd2807SJeff Garzik /* write out our inc'd consumer index so EDMA knows we're caught up */ 1236c6fd2807SJeff Garzik out_ptr &= EDMA_RSP_Q_BASE_LO_MASK; 1237c6fd2807SJeff Garzik out_ptr |= out_index << EDMA_RSP_Q_PTR_SHIFT; 1238c6fd2807SJeff Garzik writelfl(out_ptr, port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 1239c6fd2807SJeff Garzik 1240c6fd2807SJeff Garzik /* Return ATA status register for completed CRPB */ 1241c6fd2807SJeff Garzik return ata_status; 1242c6fd2807SJeff Garzik } 1243c6fd2807SJeff Garzik 1244c6fd2807SJeff Garzik /** 1245c6fd2807SJeff Garzik * mv_err_intr - Handle error interrupts on the port 1246c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1247c6fd2807SJeff Garzik * @reset_allowed: bool: 0 == don't trigger from reset here 1248c6fd2807SJeff Garzik * 1249c6fd2807SJeff Garzik * In most cases, just clear the interrupt and move on. However, 1250c6fd2807SJeff Garzik * some cases require an eDMA reset, which is done right before 1251c6fd2807SJeff Garzik * the COMRESET in mv_phy_reset(). The SERR case requires a 1252c6fd2807SJeff Garzik * clear of pending errors in the SATA SERROR register. Finally, 1253c6fd2807SJeff Garzik * if the port disabled DMA, update our cached copy to match. 1254c6fd2807SJeff Garzik * 1255c6fd2807SJeff Garzik * LOCKING: 1256c6fd2807SJeff Garzik * Inherited from caller. 1257c6fd2807SJeff Garzik */ 1258c6fd2807SJeff Garzik static void mv_err_intr(struct ata_port *ap, int reset_allowed) 1259c6fd2807SJeff Garzik { 1260c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1261c6fd2807SJeff Garzik u32 edma_err_cause, serr = 0; 1262c6fd2807SJeff Garzik 1263c6fd2807SJeff Garzik edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1264c6fd2807SJeff Garzik 1265c6fd2807SJeff Garzik if (EDMA_ERR_SERR & edma_err_cause) { 1266c6fd2807SJeff Garzik sata_scr_read(ap, SCR_ERROR, &serr); 1267c6fd2807SJeff Garzik sata_scr_write_flush(ap, SCR_ERROR, serr); 1268c6fd2807SJeff Garzik } 1269c6fd2807SJeff Garzik if (EDMA_ERR_SELF_DIS & edma_err_cause) { 1270c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1271c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1272c6fd2807SJeff Garzik } 1273c6fd2807SJeff Garzik DPRINTK(KERN_ERR "ata%u: port error; EDMA err cause: 0x%08x " 1274c6fd2807SJeff Garzik "SERR: 0x%08x\n", ap->id, edma_err_cause, serr); 1275c6fd2807SJeff Garzik 1276c6fd2807SJeff Garzik /* Clear EDMA now that SERR cleanup done */ 1277c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1278c6fd2807SJeff Garzik 1279c6fd2807SJeff Garzik /* check for fatal here and recover if needed */ 1280c6fd2807SJeff Garzik if (reset_allowed && (EDMA_ERR_FATAL & edma_err_cause)) 1281c6fd2807SJeff Garzik mv_stop_and_reset(ap); 1282c6fd2807SJeff Garzik } 1283c6fd2807SJeff Garzik 1284c6fd2807SJeff Garzik /** 1285c6fd2807SJeff Garzik * mv_host_intr - Handle all interrupts on the given host controller 1286cca3974eSJeff Garzik * @host: host specific structure 1287c6fd2807SJeff Garzik * @relevant: port error bits relevant to this host controller 1288c6fd2807SJeff Garzik * @hc: which host controller we're to look at 1289c6fd2807SJeff Garzik * 1290c6fd2807SJeff Garzik * Read then write clear the HC interrupt status then walk each 1291c6fd2807SJeff Garzik * port connected to the HC and see if it needs servicing. Port 1292c6fd2807SJeff Garzik * success ints are reported in the HC interrupt status reg, the 1293c6fd2807SJeff Garzik * port error ints are reported in the higher level main 1294c6fd2807SJeff Garzik * interrupt status register and thus are passed in via the 1295c6fd2807SJeff Garzik * 'relevant' argument. 1296c6fd2807SJeff Garzik * 1297c6fd2807SJeff Garzik * LOCKING: 1298c6fd2807SJeff Garzik * Inherited from caller. 1299c6fd2807SJeff Garzik */ 1300cca3974eSJeff Garzik static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc) 1301c6fd2807SJeff Garzik { 1302*0d5ff566STejun Heo void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; 1303c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1304c6fd2807SJeff Garzik struct ata_queued_cmd *qc; 1305c6fd2807SJeff Garzik u32 hc_irq_cause; 1306c6fd2807SJeff Garzik int shift, port, port0, hard_port, handled; 1307c6fd2807SJeff Garzik unsigned int err_mask; 1308c6fd2807SJeff Garzik 1309c6fd2807SJeff Garzik if (hc == 0) { 1310c6fd2807SJeff Garzik port0 = 0; 1311c6fd2807SJeff Garzik } else { 1312c6fd2807SJeff Garzik port0 = MV_PORTS_PER_HC; 1313c6fd2807SJeff Garzik } 1314c6fd2807SJeff Garzik 1315c6fd2807SJeff Garzik /* we'll need the HC success int register in most cases */ 1316c6fd2807SJeff Garzik hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); 1317c6fd2807SJeff Garzik if (hc_irq_cause) { 1318c6fd2807SJeff Garzik writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); 1319c6fd2807SJeff Garzik } 1320c6fd2807SJeff Garzik 1321c6fd2807SJeff Garzik VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n", 1322c6fd2807SJeff Garzik hc,relevant,hc_irq_cause); 1323c6fd2807SJeff Garzik 1324c6fd2807SJeff Garzik for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) { 1325c6fd2807SJeff Garzik u8 ata_status = 0; 1326cca3974eSJeff Garzik struct ata_port *ap = host->ports[port]; 1327c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1328c6fd2807SJeff Garzik 1329c6fd2807SJeff Garzik hard_port = mv_hardport_from_port(port); /* range 0..3 */ 1330c6fd2807SJeff Garzik handled = 0; /* ensure ata_status is set if handled++ */ 1331c6fd2807SJeff Garzik 1332c6fd2807SJeff Garzik /* Note that DEV_IRQ might happen spuriously during EDMA, 1333c6fd2807SJeff Garzik * and should be ignored in such cases. 1334c6fd2807SJeff Garzik * The cause of this is still under investigation. 1335c6fd2807SJeff Garzik */ 1336c6fd2807SJeff Garzik if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { 1337c6fd2807SJeff Garzik /* EDMA: check for response queue interrupt */ 1338c6fd2807SJeff Garzik if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) { 1339c6fd2807SJeff Garzik ata_status = mv_get_crpb_status(ap); 1340c6fd2807SJeff Garzik handled = 1; 1341c6fd2807SJeff Garzik } 1342c6fd2807SJeff Garzik } else { 1343c6fd2807SJeff Garzik /* PIO: check for device (drive) interrupt */ 1344c6fd2807SJeff Garzik if ((DEV_IRQ << hard_port) & hc_irq_cause) { 1345*0d5ff566STejun Heo ata_status = readb(ap->ioaddr.status_addr); 1346c6fd2807SJeff Garzik handled = 1; 1347c6fd2807SJeff Garzik /* ignore spurious intr if drive still BUSY */ 1348c6fd2807SJeff Garzik if (ata_status & ATA_BUSY) { 1349c6fd2807SJeff Garzik ata_status = 0; 1350c6fd2807SJeff Garzik handled = 0; 1351c6fd2807SJeff Garzik } 1352c6fd2807SJeff Garzik } 1353c6fd2807SJeff Garzik } 1354c6fd2807SJeff Garzik 1355c6fd2807SJeff Garzik if (ap && (ap->flags & ATA_FLAG_DISABLED)) 1356c6fd2807SJeff Garzik continue; 1357c6fd2807SJeff Garzik 1358c6fd2807SJeff Garzik err_mask = ac_err_mask(ata_status); 1359c6fd2807SJeff Garzik 1360c6fd2807SJeff Garzik shift = port << 1; /* (port * 2) */ 1361c6fd2807SJeff Garzik if (port >= MV_PORTS_PER_HC) { 1362c6fd2807SJeff Garzik shift++; /* skip bit 8 in the HC Main IRQ reg */ 1363c6fd2807SJeff Garzik } 1364c6fd2807SJeff Garzik if ((PORT0_ERR << shift) & relevant) { 1365c6fd2807SJeff Garzik mv_err_intr(ap, 1); 1366c6fd2807SJeff Garzik err_mask |= AC_ERR_OTHER; 1367c6fd2807SJeff Garzik handled = 1; 1368c6fd2807SJeff Garzik } 1369c6fd2807SJeff Garzik 1370c6fd2807SJeff Garzik if (handled) { 1371c6fd2807SJeff Garzik qc = ata_qc_from_tag(ap, ap->active_tag); 1372c6fd2807SJeff Garzik if (qc && (qc->flags & ATA_QCFLAG_ACTIVE)) { 1373c6fd2807SJeff Garzik VPRINTK("port %u IRQ found for qc, " 1374c6fd2807SJeff Garzik "ata_status 0x%x\n", port,ata_status); 1375c6fd2807SJeff Garzik /* mark qc status appropriately */ 1376c6fd2807SJeff Garzik if (!(qc->tf.flags & ATA_TFLAG_POLLING)) { 1377c6fd2807SJeff Garzik qc->err_mask |= err_mask; 1378c6fd2807SJeff Garzik ata_qc_complete(qc); 1379c6fd2807SJeff Garzik } 1380c6fd2807SJeff Garzik } 1381c6fd2807SJeff Garzik } 1382c6fd2807SJeff Garzik } 1383c6fd2807SJeff Garzik VPRINTK("EXIT\n"); 1384c6fd2807SJeff Garzik } 1385c6fd2807SJeff Garzik 1386c6fd2807SJeff Garzik /** 1387c6fd2807SJeff Garzik * mv_interrupt - 1388c6fd2807SJeff Garzik * @irq: unused 1389c6fd2807SJeff Garzik * @dev_instance: private data; in this case the host structure 1390c6fd2807SJeff Garzik * @regs: unused 1391c6fd2807SJeff Garzik * 1392c6fd2807SJeff Garzik * Read the read only register to determine if any host 1393c6fd2807SJeff Garzik * controllers have pending interrupts. If so, call lower level 1394c6fd2807SJeff Garzik * routine to handle. Also check for PCI errors which are only 1395c6fd2807SJeff Garzik * reported here. 1396c6fd2807SJeff Garzik * 1397c6fd2807SJeff Garzik * LOCKING: 1398cca3974eSJeff Garzik * This routine holds the host lock while processing pending 1399c6fd2807SJeff Garzik * interrupts. 1400c6fd2807SJeff Garzik */ 14017d12e780SDavid Howells static irqreturn_t mv_interrupt(int irq, void *dev_instance) 1402c6fd2807SJeff Garzik { 1403cca3974eSJeff Garzik struct ata_host *host = dev_instance; 1404c6fd2807SJeff Garzik unsigned int hc, handled = 0, n_hcs; 1405*0d5ff566STejun Heo void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; 1406c6fd2807SJeff Garzik struct mv_host_priv *hpriv; 1407c6fd2807SJeff Garzik u32 irq_stat; 1408c6fd2807SJeff Garzik 1409c6fd2807SJeff Garzik irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS); 1410c6fd2807SJeff Garzik 1411c6fd2807SJeff Garzik /* check the cases where we either have nothing pending or have read 1412c6fd2807SJeff Garzik * a bogus register value which can indicate HW removal or PCI fault 1413c6fd2807SJeff Garzik */ 1414c6fd2807SJeff Garzik if (!irq_stat || (0xffffffffU == irq_stat)) { 1415c6fd2807SJeff Garzik return IRQ_NONE; 1416c6fd2807SJeff Garzik } 1417c6fd2807SJeff Garzik 1418cca3974eSJeff Garzik n_hcs = mv_get_hc_count(host->ports[0]->flags); 1419cca3974eSJeff Garzik spin_lock(&host->lock); 1420c6fd2807SJeff Garzik 1421c6fd2807SJeff Garzik for (hc = 0; hc < n_hcs; hc++) { 1422c6fd2807SJeff Garzik u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT)); 1423c6fd2807SJeff Garzik if (relevant) { 1424cca3974eSJeff Garzik mv_host_intr(host, relevant, hc); 1425c6fd2807SJeff Garzik handled++; 1426c6fd2807SJeff Garzik } 1427c6fd2807SJeff Garzik } 1428c6fd2807SJeff Garzik 1429cca3974eSJeff Garzik hpriv = host->private_data; 1430c6fd2807SJeff Garzik if (IS_60XX(hpriv)) { 1431c6fd2807SJeff Garzik /* deal with the interrupt coalescing bits */ 1432c6fd2807SJeff Garzik if (irq_stat & (TRAN_LO_DONE | TRAN_HI_DONE | PORTS_0_7_COAL_DONE)) { 1433c6fd2807SJeff Garzik writelfl(0, mmio + MV_IRQ_COAL_CAUSE_LO); 1434c6fd2807SJeff Garzik writelfl(0, mmio + MV_IRQ_COAL_CAUSE_HI); 1435c6fd2807SJeff Garzik writelfl(0, mmio + MV_IRQ_COAL_CAUSE); 1436c6fd2807SJeff Garzik } 1437c6fd2807SJeff Garzik } 1438c6fd2807SJeff Garzik 1439c6fd2807SJeff Garzik if (PCI_ERR & irq_stat) { 1440c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": PCI ERROR; PCI IRQ cause=0x%08x\n", 1441c6fd2807SJeff Garzik readl(mmio + PCI_IRQ_CAUSE_OFS)); 1442c6fd2807SJeff Garzik 1443c6fd2807SJeff Garzik DPRINTK("All regs @ PCI error\n"); 1444cca3974eSJeff Garzik mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev)); 1445c6fd2807SJeff Garzik 1446c6fd2807SJeff Garzik writelfl(0, mmio + PCI_IRQ_CAUSE_OFS); 1447c6fd2807SJeff Garzik handled++; 1448c6fd2807SJeff Garzik } 1449cca3974eSJeff Garzik spin_unlock(&host->lock); 1450c6fd2807SJeff Garzik 1451c6fd2807SJeff Garzik return IRQ_RETVAL(handled); 1452c6fd2807SJeff Garzik } 1453c6fd2807SJeff Garzik 1454c6fd2807SJeff Garzik static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port) 1455c6fd2807SJeff Garzik { 1456c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port); 1457c6fd2807SJeff Garzik unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL; 1458c6fd2807SJeff Garzik 1459c6fd2807SJeff Garzik return hc_mmio + ofs; 1460c6fd2807SJeff Garzik } 1461c6fd2807SJeff Garzik 1462c6fd2807SJeff Garzik static unsigned int mv5_scr_offset(unsigned int sc_reg_in) 1463c6fd2807SJeff Garzik { 1464c6fd2807SJeff Garzik unsigned int ofs; 1465c6fd2807SJeff Garzik 1466c6fd2807SJeff Garzik switch (sc_reg_in) { 1467c6fd2807SJeff Garzik case SCR_STATUS: 1468c6fd2807SJeff Garzik case SCR_ERROR: 1469c6fd2807SJeff Garzik case SCR_CONTROL: 1470c6fd2807SJeff Garzik ofs = sc_reg_in * sizeof(u32); 1471c6fd2807SJeff Garzik break; 1472c6fd2807SJeff Garzik default: 1473c6fd2807SJeff Garzik ofs = 0xffffffffU; 1474c6fd2807SJeff Garzik break; 1475c6fd2807SJeff Garzik } 1476c6fd2807SJeff Garzik return ofs; 1477c6fd2807SJeff Garzik } 1478c6fd2807SJeff Garzik 1479c6fd2807SJeff Garzik static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in) 1480c6fd2807SJeff Garzik { 1481*0d5ff566STejun Heo void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 1482*0d5ff566STejun Heo void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 1483c6fd2807SJeff Garzik unsigned int ofs = mv5_scr_offset(sc_reg_in); 1484c6fd2807SJeff Garzik 1485c6fd2807SJeff Garzik if (ofs != 0xffffffffU) 1486*0d5ff566STejun Heo return readl(addr + ofs); 1487c6fd2807SJeff Garzik else 1488c6fd2807SJeff Garzik return (u32) ofs; 1489c6fd2807SJeff Garzik } 1490c6fd2807SJeff Garzik 1491c6fd2807SJeff Garzik static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 1492c6fd2807SJeff Garzik { 1493*0d5ff566STejun Heo void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 1494*0d5ff566STejun Heo void __iomem *addr = mv5_phy_base(mmio, ap->port_no); 1495c6fd2807SJeff Garzik unsigned int ofs = mv5_scr_offset(sc_reg_in); 1496c6fd2807SJeff Garzik 1497c6fd2807SJeff Garzik if (ofs != 0xffffffffU) 1498*0d5ff566STejun Heo writelfl(val, addr + ofs); 1499c6fd2807SJeff Garzik } 1500c6fd2807SJeff Garzik 1501c6fd2807SJeff Garzik static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio) 1502c6fd2807SJeff Garzik { 1503c6fd2807SJeff Garzik u8 rev_id; 1504c6fd2807SJeff Garzik int early_5080; 1505c6fd2807SJeff Garzik 1506c6fd2807SJeff Garzik pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id); 1507c6fd2807SJeff Garzik 1508c6fd2807SJeff Garzik early_5080 = (pdev->device == 0x5080) && (rev_id == 0); 1509c6fd2807SJeff Garzik 1510c6fd2807SJeff Garzik if (!early_5080) { 1511c6fd2807SJeff Garzik u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); 1512c6fd2807SJeff Garzik tmp |= (1 << 0); 1513c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); 1514c6fd2807SJeff Garzik } 1515c6fd2807SJeff Garzik 1516c6fd2807SJeff Garzik mv_reset_pci_bus(pdev, mmio); 1517c6fd2807SJeff Garzik } 1518c6fd2807SJeff Garzik 1519c6fd2807SJeff Garzik static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) 1520c6fd2807SJeff Garzik { 1521c6fd2807SJeff Garzik writel(0x0fcfffff, mmio + MV_FLASH_CTL); 1522c6fd2807SJeff Garzik } 1523c6fd2807SJeff Garzik 1524c6fd2807SJeff Garzik static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, 1525c6fd2807SJeff Garzik void __iomem *mmio) 1526c6fd2807SJeff Garzik { 1527c6fd2807SJeff Garzik void __iomem *phy_mmio = mv5_phy_base(mmio, idx); 1528c6fd2807SJeff Garzik u32 tmp; 1529c6fd2807SJeff Garzik 1530c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_MODE); 1531c6fd2807SJeff Garzik 1532c6fd2807SJeff Garzik hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */ 1533c6fd2807SJeff Garzik hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */ 1534c6fd2807SJeff Garzik } 1535c6fd2807SJeff Garzik 1536c6fd2807SJeff Garzik static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) 1537c6fd2807SJeff Garzik { 1538c6fd2807SJeff Garzik u32 tmp; 1539c6fd2807SJeff Garzik 1540c6fd2807SJeff Garzik writel(0, mmio + MV_GPIO_PORT_CTL); 1541c6fd2807SJeff Garzik 1542c6fd2807SJeff Garzik /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */ 1543c6fd2807SJeff Garzik 1544c6fd2807SJeff Garzik tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); 1545c6fd2807SJeff Garzik tmp |= ~(1 << 0); 1546c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); 1547c6fd2807SJeff Garzik } 1548c6fd2807SJeff Garzik 1549c6fd2807SJeff Garzik static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 1550c6fd2807SJeff Garzik unsigned int port) 1551c6fd2807SJeff Garzik { 1552c6fd2807SJeff Garzik void __iomem *phy_mmio = mv5_phy_base(mmio, port); 1553c6fd2807SJeff Garzik const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5); 1554c6fd2807SJeff Garzik u32 tmp; 1555c6fd2807SJeff Garzik int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0); 1556c6fd2807SJeff Garzik 1557c6fd2807SJeff Garzik if (fix_apm_sq) { 1558c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_LT_MODE); 1559c6fd2807SJeff Garzik tmp |= (1 << 19); 1560c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_LT_MODE); 1561c6fd2807SJeff Garzik 1562c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_CTL); 1563c6fd2807SJeff Garzik tmp &= ~0x3; 1564c6fd2807SJeff Garzik tmp |= 0x1; 1565c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_PHY_CTL); 1566c6fd2807SJeff Garzik } 1567c6fd2807SJeff Garzik 1568c6fd2807SJeff Garzik tmp = readl(phy_mmio + MV5_PHY_MODE); 1569c6fd2807SJeff Garzik tmp &= ~mask; 1570c6fd2807SJeff Garzik tmp |= hpriv->signal[port].pre; 1571c6fd2807SJeff Garzik tmp |= hpriv->signal[port].amps; 1572c6fd2807SJeff Garzik writel(tmp, phy_mmio + MV5_PHY_MODE); 1573c6fd2807SJeff Garzik } 1574c6fd2807SJeff Garzik 1575c6fd2807SJeff Garzik 1576c6fd2807SJeff Garzik #undef ZERO 1577c6fd2807SJeff Garzik #define ZERO(reg) writel(0, port_mmio + (reg)) 1578c6fd2807SJeff Garzik static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio, 1579c6fd2807SJeff Garzik unsigned int port) 1580c6fd2807SJeff Garzik { 1581c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 1582c6fd2807SJeff Garzik 1583c6fd2807SJeff Garzik writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); 1584c6fd2807SJeff Garzik 1585c6fd2807SJeff Garzik mv_channel_reset(hpriv, mmio, port); 1586c6fd2807SJeff Garzik 1587c6fd2807SJeff Garzik ZERO(0x028); /* command */ 1588c6fd2807SJeff Garzik writel(0x11f, port_mmio + EDMA_CFG_OFS); 1589c6fd2807SJeff Garzik ZERO(0x004); /* timer */ 1590c6fd2807SJeff Garzik ZERO(0x008); /* irq err cause */ 1591c6fd2807SJeff Garzik ZERO(0x00c); /* irq err mask */ 1592c6fd2807SJeff Garzik ZERO(0x010); /* rq bah */ 1593c6fd2807SJeff Garzik ZERO(0x014); /* rq inp */ 1594c6fd2807SJeff Garzik ZERO(0x018); /* rq outp */ 1595c6fd2807SJeff Garzik ZERO(0x01c); /* respq bah */ 1596c6fd2807SJeff Garzik ZERO(0x024); /* respq outp */ 1597c6fd2807SJeff Garzik ZERO(0x020); /* respq inp */ 1598c6fd2807SJeff Garzik ZERO(0x02c); /* test control */ 1599c6fd2807SJeff Garzik writel(0xbc, port_mmio + EDMA_IORDY_TMOUT); 1600c6fd2807SJeff Garzik } 1601c6fd2807SJeff Garzik #undef ZERO 1602c6fd2807SJeff Garzik 1603c6fd2807SJeff Garzik #define ZERO(reg) writel(0, hc_mmio + (reg)) 1604c6fd2807SJeff Garzik static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 1605c6fd2807SJeff Garzik unsigned int hc) 1606c6fd2807SJeff Garzik { 1607c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1608c6fd2807SJeff Garzik u32 tmp; 1609c6fd2807SJeff Garzik 1610c6fd2807SJeff Garzik ZERO(0x00c); 1611c6fd2807SJeff Garzik ZERO(0x010); 1612c6fd2807SJeff Garzik ZERO(0x014); 1613c6fd2807SJeff Garzik ZERO(0x018); 1614c6fd2807SJeff Garzik 1615c6fd2807SJeff Garzik tmp = readl(hc_mmio + 0x20); 1616c6fd2807SJeff Garzik tmp &= 0x1c1c1c1c; 1617c6fd2807SJeff Garzik tmp |= 0x03030303; 1618c6fd2807SJeff Garzik writel(tmp, hc_mmio + 0x20); 1619c6fd2807SJeff Garzik } 1620c6fd2807SJeff Garzik #undef ZERO 1621c6fd2807SJeff Garzik 1622c6fd2807SJeff Garzik static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 1623c6fd2807SJeff Garzik unsigned int n_hc) 1624c6fd2807SJeff Garzik { 1625c6fd2807SJeff Garzik unsigned int hc, port; 1626c6fd2807SJeff Garzik 1627c6fd2807SJeff Garzik for (hc = 0; hc < n_hc; hc++) { 1628c6fd2807SJeff Garzik for (port = 0; port < MV_PORTS_PER_HC; port++) 1629c6fd2807SJeff Garzik mv5_reset_hc_port(hpriv, mmio, 1630c6fd2807SJeff Garzik (hc * MV_PORTS_PER_HC) + port); 1631c6fd2807SJeff Garzik 1632c6fd2807SJeff Garzik mv5_reset_one_hc(hpriv, mmio, hc); 1633c6fd2807SJeff Garzik } 1634c6fd2807SJeff Garzik 1635c6fd2807SJeff Garzik return 0; 1636c6fd2807SJeff Garzik } 1637c6fd2807SJeff Garzik 1638c6fd2807SJeff Garzik #undef ZERO 1639c6fd2807SJeff Garzik #define ZERO(reg) writel(0, mmio + (reg)) 1640c6fd2807SJeff Garzik static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio) 1641c6fd2807SJeff Garzik { 1642c6fd2807SJeff Garzik u32 tmp; 1643c6fd2807SJeff Garzik 1644c6fd2807SJeff Garzik tmp = readl(mmio + MV_PCI_MODE); 1645c6fd2807SJeff Garzik tmp &= 0xff00ffff; 1646c6fd2807SJeff Garzik writel(tmp, mmio + MV_PCI_MODE); 1647c6fd2807SJeff Garzik 1648c6fd2807SJeff Garzik ZERO(MV_PCI_DISC_TIMER); 1649c6fd2807SJeff Garzik ZERO(MV_PCI_MSI_TRIGGER); 1650c6fd2807SJeff Garzik writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT); 1651c6fd2807SJeff Garzik ZERO(HC_MAIN_IRQ_MASK_OFS); 1652c6fd2807SJeff Garzik ZERO(MV_PCI_SERR_MASK); 1653c6fd2807SJeff Garzik ZERO(PCI_IRQ_CAUSE_OFS); 1654c6fd2807SJeff Garzik ZERO(PCI_IRQ_MASK_OFS); 1655c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_LOW_ADDRESS); 1656c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_HIGH_ADDRESS); 1657c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_ATTRIBUTE); 1658c6fd2807SJeff Garzik ZERO(MV_PCI_ERR_COMMAND); 1659c6fd2807SJeff Garzik } 1660c6fd2807SJeff Garzik #undef ZERO 1661c6fd2807SJeff Garzik 1662c6fd2807SJeff Garzik static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) 1663c6fd2807SJeff Garzik { 1664c6fd2807SJeff Garzik u32 tmp; 1665c6fd2807SJeff Garzik 1666c6fd2807SJeff Garzik mv5_reset_flash(hpriv, mmio); 1667c6fd2807SJeff Garzik 1668c6fd2807SJeff Garzik tmp = readl(mmio + MV_GPIO_PORT_CTL); 1669c6fd2807SJeff Garzik tmp &= 0x3; 1670c6fd2807SJeff Garzik tmp |= (1 << 5) | (1 << 6); 1671c6fd2807SJeff Garzik writel(tmp, mmio + MV_GPIO_PORT_CTL); 1672c6fd2807SJeff Garzik } 1673c6fd2807SJeff Garzik 1674c6fd2807SJeff Garzik /** 1675c6fd2807SJeff Garzik * mv6_reset_hc - Perform the 6xxx global soft reset 1676c6fd2807SJeff Garzik * @mmio: base address of the HBA 1677c6fd2807SJeff Garzik * 1678c6fd2807SJeff Garzik * This routine only applies to 6xxx parts. 1679c6fd2807SJeff Garzik * 1680c6fd2807SJeff Garzik * LOCKING: 1681c6fd2807SJeff Garzik * Inherited from caller. 1682c6fd2807SJeff Garzik */ 1683c6fd2807SJeff Garzik static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, 1684c6fd2807SJeff Garzik unsigned int n_hc) 1685c6fd2807SJeff Garzik { 1686c6fd2807SJeff Garzik void __iomem *reg = mmio + PCI_MAIN_CMD_STS_OFS; 1687c6fd2807SJeff Garzik int i, rc = 0; 1688c6fd2807SJeff Garzik u32 t; 1689c6fd2807SJeff Garzik 1690c6fd2807SJeff Garzik /* Following procedure defined in PCI "main command and status 1691c6fd2807SJeff Garzik * register" table. 1692c6fd2807SJeff Garzik */ 1693c6fd2807SJeff Garzik t = readl(reg); 1694c6fd2807SJeff Garzik writel(t | STOP_PCI_MASTER, reg); 1695c6fd2807SJeff Garzik 1696c6fd2807SJeff Garzik for (i = 0; i < 1000; i++) { 1697c6fd2807SJeff Garzik udelay(1); 1698c6fd2807SJeff Garzik t = readl(reg); 1699c6fd2807SJeff Garzik if (PCI_MASTER_EMPTY & t) { 1700c6fd2807SJeff Garzik break; 1701c6fd2807SJeff Garzik } 1702c6fd2807SJeff Garzik } 1703c6fd2807SJeff Garzik if (!(PCI_MASTER_EMPTY & t)) { 1704c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": PCI master won't flush\n"); 1705c6fd2807SJeff Garzik rc = 1; 1706c6fd2807SJeff Garzik goto done; 1707c6fd2807SJeff Garzik } 1708c6fd2807SJeff Garzik 1709c6fd2807SJeff Garzik /* set reset */ 1710c6fd2807SJeff Garzik i = 5; 1711c6fd2807SJeff Garzik do { 1712c6fd2807SJeff Garzik writel(t | GLOB_SFT_RST, reg); 1713c6fd2807SJeff Garzik t = readl(reg); 1714c6fd2807SJeff Garzik udelay(1); 1715c6fd2807SJeff Garzik } while (!(GLOB_SFT_RST & t) && (i-- > 0)); 1716c6fd2807SJeff Garzik 1717c6fd2807SJeff Garzik if (!(GLOB_SFT_RST & t)) { 1718c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": can't set global reset\n"); 1719c6fd2807SJeff Garzik rc = 1; 1720c6fd2807SJeff Garzik goto done; 1721c6fd2807SJeff Garzik } 1722c6fd2807SJeff Garzik 1723c6fd2807SJeff Garzik /* clear reset and *reenable the PCI master* (not mentioned in spec) */ 1724c6fd2807SJeff Garzik i = 5; 1725c6fd2807SJeff Garzik do { 1726c6fd2807SJeff Garzik writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg); 1727c6fd2807SJeff Garzik t = readl(reg); 1728c6fd2807SJeff Garzik udelay(1); 1729c6fd2807SJeff Garzik } while ((GLOB_SFT_RST & t) && (i-- > 0)); 1730c6fd2807SJeff Garzik 1731c6fd2807SJeff Garzik if (GLOB_SFT_RST & t) { 1732c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": can't clear global reset\n"); 1733c6fd2807SJeff Garzik rc = 1; 1734c6fd2807SJeff Garzik } 1735c6fd2807SJeff Garzik done: 1736c6fd2807SJeff Garzik return rc; 1737c6fd2807SJeff Garzik } 1738c6fd2807SJeff Garzik 1739c6fd2807SJeff Garzik static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, 1740c6fd2807SJeff Garzik void __iomem *mmio) 1741c6fd2807SJeff Garzik { 1742c6fd2807SJeff Garzik void __iomem *port_mmio; 1743c6fd2807SJeff Garzik u32 tmp; 1744c6fd2807SJeff Garzik 1745c6fd2807SJeff Garzik tmp = readl(mmio + MV_RESET_CFG); 1746c6fd2807SJeff Garzik if ((tmp & (1 << 0)) == 0) { 1747c6fd2807SJeff Garzik hpriv->signal[idx].amps = 0x7 << 8; 1748c6fd2807SJeff Garzik hpriv->signal[idx].pre = 0x1 << 5; 1749c6fd2807SJeff Garzik return; 1750c6fd2807SJeff Garzik } 1751c6fd2807SJeff Garzik 1752c6fd2807SJeff Garzik port_mmio = mv_port_base(mmio, idx); 1753c6fd2807SJeff Garzik tmp = readl(port_mmio + PHY_MODE2); 1754c6fd2807SJeff Garzik 1755c6fd2807SJeff Garzik hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */ 1756c6fd2807SJeff Garzik hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */ 1757c6fd2807SJeff Garzik } 1758c6fd2807SJeff Garzik 1759c6fd2807SJeff Garzik static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) 1760c6fd2807SJeff Garzik { 1761c6fd2807SJeff Garzik writel(0x00000060, mmio + MV_GPIO_PORT_CTL); 1762c6fd2807SJeff Garzik } 1763c6fd2807SJeff Garzik 1764c6fd2807SJeff Garzik static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, 1765c6fd2807SJeff Garzik unsigned int port) 1766c6fd2807SJeff Garzik { 1767c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 1768c6fd2807SJeff Garzik 1769c6fd2807SJeff Garzik u32 hp_flags = hpriv->hp_flags; 1770c6fd2807SJeff Garzik int fix_phy_mode2 = 1771c6fd2807SJeff Garzik hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); 1772c6fd2807SJeff Garzik int fix_phy_mode4 = 1773c6fd2807SJeff Garzik hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); 1774c6fd2807SJeff Garzik u32 m2, tmp; 1775c6fd2807SJeff Garzik 1776c6fd2807SJeff Garzik if (fix_phy_mode2) { 1777c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 1778c6fd2807SJeff Garzik m2 &= ~(1 << 16); 1779c6fd2807SJeff Garzik m2 |= (1 << 31); 1780c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 1781c6fd2807SJeff Garzik 1782c6fd2807SJeff Garzik udelay(200); 1783c6fd2807SJeff Garzik 1784c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 1785c6fd2807SJeff Garzik m2 &= ~((1 << 16) | (1 << 31)); 1786c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 1787c6fd2807SJeff Garzik 1788c6fd2807SJeff Garzik udelay(200); 1789c6fd2807SJeff Garzik } 1790c6fd2807SJeff Garzik 1791c6fd2807SJeff Garzik /* who knows what this magic does */ 1792c6fd2807SJeff Garzik tmp = readl(port_mmio + PHY_MODE3); 1793c6fd2807SJeff Garzik tmp &= ~0x7F800000; 1794c6fd2807SJeff Garzik tmp |= 0x2A800000; 1795c6fd2807SJeff Garzik writel(tmp, port_mmio + PHY_MODE3); 1796c6fd2807SJeff Garzik 1797c6fd2807SJeff Garzik if (fix_phy_mode4) { 1798c6fd2807SJeff Garzik u32 m4; 1799c6fd2807SJeff Garzik 1800c6fd2807SJeff Garzik m4 = readl(port_mmio + PHY_MODE4); 1801c6fd2807SJeff Garzik 1802c6fd2807SJeff Garzik if (hp_flags & MV_HP_ERRATA_60X1B2) 1803c6fd2807SJeff Garzik tmp = readl(port_mmio + 0x310); 1804c6fd2807SJeff Garzik 1805c6fd2807SJeff Garzik m4 = (m4 & ~(1 << 1)) | (1 << 0); 1806c6fd2807SJeff Garzik 1807c6fd2807SJeff Garzik writel(m4, port_mmio + PHY_MODE4); 1808c6fd2807SJeff Garzik 1809c6fd2807SJeff Garzik if (hp_flags & MV_HP_ERRATA_60X1B2) 1810c6fd2807SJeff Garzik writel(tmp, port_mmio + 0x310); 1811c6fd2807SJeff Garzik } 1812c6fd2807SJeff Garzik 1813c6fd2807SJeff Garzik /* Revert values of pre-emphasis and signal amps to the saved ones */ 1814c6fd2807SJeff Garzik m2 = readl(port_mmio + PHY_MODE2); 1815c6fd2807SJeff Garzik 1816c6fd2807SJeff Garzik m2 &= ~MV_M2_PREAMP_MASK; 1817c6fd2807SJeff Garzik m2 |= hpriv->signal[port].amps; 1818c6fd2807SJeff Garzik m2 |= hpriv->signal[port].pre; 1819c6fd2807SJeff Garzik m2 &= ~(1 << 16); 1820c6fd2807SJeff Garzik 1821c6fd2807SJeff Garzik /* according to mvSata 3.6.1, some IIE values are fixed */ 1822c6fd2807SJeff Garzik if (IS_GEN_IIE(hpriv)) { 1823c6fd2807SJeff Garzik m2 &= ~0xC30FF01F; 1824c6fd2807SJeff Garzik m2 |= 0x0000900F; 1825c6fd2807SJeff Garzik } 1826c6fd2807SJeff Garzik 1827c6fd2807SJeff Garzik writel(m2, port_mmio + PHY_MODE2); 1828c6fd2807SJeff Garzik } 1829c6fd2807SJeff Garzik 1830c6fd2807SJeff Garzik static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, 1831c6fd2807SJeff Garzik unsigned int port_no) 1832c6fd2807SJeff Garzik { 1833c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port_no); 1834c6fd2807SJeff Garzik 1835c6fd2807SJeff Garzik writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS); 1836c6fd2807SJeff Garzik 1837c6fd2807SJeff Garzik if (IS_60XX(hpriv)) { 1838c6fd2807SJeff Garzik u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); 1839c6fd2807SJeff Garzik ifctl |= (1 << 7); /* enable gen2i speed */ 1840c6fd2807SJeff Garzik ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ 1841c6fd2807SJeff Garzik writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL); 1842c6fd2807SJeff Garzik } 1843c6fd2807SJeff Garzik 1844c6fd2807SJeff Garzik udelay(25); /* allow reset propagation */ 1845c6fd2807SJeff Garzik 1846c6fd2807SJeff Garzik /* Spec never mentions clearing the bit. Marvell's driver does 1847c6fd2807SJeff Garzik * clear the bit, however. 1848c6fd2807SJeff Garzik */ 1849c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_CMD_OFS); 1850c6fd2807SJeff Garzik 1851c6fd2807SJeff Garzik hpriv->ops->phy_errata(hpriv, mmio, port_no); 1852c6fd2807SJeff Garzik 1853c6fd2807SJeff Garzik if (IS_50XX(hpriv)) 1854c6fd2807SJeff Garzik mdelay(1); 1855c6fd2807SJeff Garzik } 1856c6fd2807SJeff Garzik 1857c6fd2807SJeff Garzik static void mv_stop_and_reset(struct ata_port *ap) 1858c6fd2807SJeff Garzik { 1859cca3974eSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1860*0d5ff566STejun Heo void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 1861c6fd2807SJeff Garzik 1862c6fd2807SJeff Garzik mv_stop_dma(ap); 1863c6fd2807SJeff Garzik 1864c6fd2807SJeff Garzik mv_channel_reset(hpriv, mmio, ap->port_no); 1865c6fd2807SJeff Garzik 1866c6fd2807SJeff Garzik __mv_phy_reset(ap, 0); 1867c6fd2807SJeff Garzik } 1868c6fd2807SJeff Garzik 1869c6fd2807SJeff Garzik static inline void __msleep(unsigned int msec, int can_sleep) 1870c6fd2807SJeff Garzik { 1871c6fd2807SJeff Garzik if (can_sleep) 1872c6fd2807SJeff Garzik msleep(msec); 1873c6fd2807SJeff Garzik else 1874c6fd2807SJeff Garzik mdelay(msec); 1875c6fd2807SJeff Garzik } 1876c6fd2807SJeff Garzik 1877c6fd2807SJeff Garzik /** 1878c6fd2807SJeff Garzik * __mv_phy_reset - Perform eDMA reset followed by COMRESET 1879c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1880c6fd2807SJeff Garzik * 1881c6fd2807SJeff Garzik * Part of this is taken from __sata_phy_reset and modified to 1882c6fd2807SJeff Garzik * not sleep since this routine gets called from interrupt level. 1883c6fd2807SJeff Garzik * 1884c6fd2807SJeff Garzik * LOCKING: 1885c6fd2807SJeff Garzik * Inherited from caller. This is coded to safe to call at 1886c6fd2807SJeff Garzik * interrupt level, i.e. it does not sleep. 1887c6fd2807SJeff Garzik */ 1888c6fd2807SJeff Garzik static void __mv_phy_reset(struct ata_port *ap, int can_sleep) 1889c6fd2807SJeff Garzik { 1890c6fd2807SJeff Garzik struct mv_port_priv *pp = ap->private_data; 1891cca3974eSJeff Garzik struct mv_host_priv *hpriv = ap->host->private_data; 1892c6fd2807SJeff Garzik void __iomem *port_mmio = mv_ap_base(ap); 1893c6fd2807SJeff Garzik struct ata_taskfile tf; 1894c6fd2807SJeff Garzik struct ata_device *dev = &ap->device[0]; 1895c6fd2807SJeff Garzik unsigned long timeout; 1896c6fd2807SJeff Garzik int retry = 5; 1897c6fd2807SJeff Garzik u32 sstatus; 1898c6fd2807SJeff Garzik 1899c6fd2807SJeff Garzik VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio); 1900c6fd2807SJeff Garzik 1901c6fd2807SJeff Garzik DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x " 1902c6fd2807SJeff Garzik "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), 1903c6fd2807SJeff Garzik mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); 1904c6fd2807SJeff Garzik 1905c6fd2807SJeff Garzik /* Issue COMRESET via SControl */ 1906c6fd2807SJeff Garzik comreset_retry: 1907c6fd2807SJeff Garzik sata_scr_write_flush(ap, SCR_CONTROL, 0x301); 1908c6fd2807SJeff Garzik __msleep(1, can_sleep); 1909c6fd2807SJeff Garzik 1910c6fd2807SJeff Garzik sata_scr_write_flush(ap, SCR_CONTROL, 0x300); 1911c6fd2807SJeff Garzik __msleep(20, can_sleep); 1912c6fd2807SJeff Garzik 1913c6fd2807SJeff Garzik timeout = jiffies + msecs_to_jiffies(200); 1914c6fd2807SJeff Garzik do { 1915c6fd2807SJeff Garzik sata_scr_read(ap, SCR_STATUS, &sstatus); 1916dd1dc802SJeff Garzik if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0)) 1917c6fd2807SJeff Garzik break; 1918c6fd2807SJeff Garzik 1919c6fd2807SJeff Garzik __msleep(1, can_sleep); 1920c6fd2807SJeff Garzik } while (time_before(jiffies, timeout)); 1921c6fd2807SJeff Garzik 1922c6fd2807SJeff Garzik /* work around errata */ 1923c6fd2807SJeff Garzik if (IS_60XX(hpriv) && 1924c6fd2807SJeff Garzik (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) && 1925c6fd2807SJeff Garzik (retry-- > 0)) 1926c6fd2807SJeff Garzik goto comreset_retry; 1927c6fd2807SJeff Garzik 1928c6fd2807SJeff Garzik DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x " 1929c6fd2807SJeff Garzik "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), 1930c6fd2807SJeff Garzik mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); 1931c6fd2807SJeff Garzik 1932c6fd2807SJeff Garzik if (ata_port_online(ap)) { 1933c6fd2807SJeff Garzik ata_port_probe(ap); 1934c6fd2807SJeff Garzik } else { 1935c6fd2807SJeff Garzik sata_scr_read(ap, SCR_STATUS, &sstatus); 1936c6fd2807SJeff Garzik ata_port_printk(ap, KERN_INFO, 1937c6fd2807SJeff Garzik "no device found (phy stat %08x)\n", sstatus); 1938c6fd2807SJeff Garzik ata_port_disable(ap); 1939c6fd2807SJeff Garzik return; 1940c6fd2807SJeff Garzik } 1941c6fd2807SJeff Garzik ap->cbl = ATA_CBL_SATA; 1942c6fd2807SJeff Garzik 1943c6fd2807SJeff Garzik /* even after SStatus reflects that device is ready, 1944c6fd2807SJeff Garzik * it seems to take a while for link to be fully 1945c6fd2807SJeff Garzik * established (and thus Status no longer 0x80/0x7F), 1946c6fd2807SJeff Garzik * so we poll a bit for that, here. 1947c6fd2807SJeff Garzik */ 1948c6fd2807SJeff Garzik retry = 20; 1949c6fd2807SJeff Garzik while (1) { 1950c6fd2807SJeff Garzik u8 drv_stat = ata_check_status(ap); 1951c6fd2807SJeff Garzik if ((drv_stat != 0x80) && (drv_stat != 0x7f)) 1952c6fd2807SJeff Garzik break; 1953c6fd2807SJeff Garzik __msleep(500, can_sleep); 1954c6fd2807SJeff Garzik if (retry-- <= 0) 1955c6fd2807SJeff Garzik break; 1956c6fd2807SJeff Garzik } 1957c6fd2807SJeff Garzik 1958*0d5ff566STejun Heo tf.lbah = readb(ap->ioaddr.lbah_addr); 1959*0d5ff566STejun Heo tf.lbam = readb(ap->ioaddr.lbam_addr); 1960*0d5ff566STejun Heo tf.lbal = readb(ap->ioaddr.lbal_addr); 1961*0d5ff566STejun Heo tf.nsect = readb(ap->ioaddr.nsect_addr); 1962c6fd2807SJeff Garzik 1963c6fd2807SJeff Garzik dev->class = ata_dev_classify(&tf); 1964c6fd2807SJeff Garzik if (!ata_dev_enabled(dev)) { 1965c6fd2807SJeff Garzik VPRINTK("Port disabled post-sig: No device present.\n"); 1966c6fd2807SJeff Garzik ata_port_disable(ap); 1967c6fd2807SJeff Garzik } 1968c6fd2807SJeff Garzik 1969c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 1970c6fd2807SJeff Garzik 1971c6fd2807SJeff Garzik pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 1972c6fd2807SJeff Garzik 1973c6fd2807SJeff Garzik VPRINTK("EXIT\n"); 1974c6fd2807SJeff Garzik } 1975c6fd2807SJeff Garzik 1976c6fd2807SJeff Garzik static void mv_phy_reset(struct ata_port *ap) 1977c6fd2807SJeff Garzik { 1978c6fd2807SJeff Garzik __mv_phy_reset(ap, 1); 1979c6fd2807SJeff Garzik } 1980c6fd2807SJeff Garzik 1981c6fd2807SJeff Garzik /** 1982c6fd2807SJeff Garzik * mv_eng_timeout - Routine called by libata when SCSI times out I/O 1983c6fd2807SJeff Garzik * @ap: ATA channel to manipulate 1984c6fd2807SJeff Garzik * 1985c6fd2807SJeff Garzik * Intent is to clear all pending error conditions, reset the 1986c6fd2807SJeff Garzik * chip/bus, fail the command, and move on. 1987c6fd2807SJeff Garzik * 1988c6fd2807SJeff Garzik * LOCKING: 1989cca3974eSJeff Garzik * This routine holds the host lock while failing the command. 1990c6fd2807SJeff Garzik */ 1991c6fd2807SJeff Garzik static void mv_eng_timeout(struct ata_port *ap) 1992c6fd2807SJeff Garzik { 1993*0d5ff566STejun Heo void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; 1994c6fd2807SJeff Garzik struct ata_queued_cmd *qc; 1995c6fd2807SJeff Garzik unsigned long flags; 1996c6fd2807SJeff Garzik 1997c6fd2807SJeff Garzik ata_port_printk(ap, KERN_ERR, "Entering mv_eng_timeout\n"); 1998c6fd2807SJeff Garzik DPRINTK("All regs @ start of eng_timeout\n"); 1999*0d5ff566STejun Heo mv_dump_all_regs(mmio, ap->port_no, to_pci_dev(ap->host->dev)); 2000c6fd2807SJeff Garzik 2001c6fd2807SJeff Garzik qc = ata_qc_from_tag(ap, ap->active_tag); 2002c6fd2807SJeff Garzik printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n", 2003*0d5ff566STejun Heo mmio, ap, qc, qc->scsicmd, &qc->scsicmd->cmnd); 2004c6fd2807SJeff Garzik 2005cca3974eSJeff Garzik spin_lock_irqsave(&ap->host->lock, flags); 2006c6fd2807SJeff Garzik mv_err_intr(ap, 0); 2007c6fd2807SJeff Garzik mv_stop_and_reset(ap); 2008cca3974eSJeff Garzik spin_unlock_irqrestore(&ap->host->lock, flags); 2009c6fd2807SJeff Garzik 2010c6fd2807SJeff Garzik WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE)); 2011c6fd2807SJeff Garzik if (qc->flags & ATA_QCFLAG_ACTIVE) { 2012c6fd2807SJeff Garzik qc->err_mask |= AC_ERR_TIMEOUT; 2013c6fd2807SJeff Garzik ata_eh_qc_complete(qc); 2014c6fd2807SJeff Garzik } 2015c6fd2807SJeff Garzik } 2016c6fd2807SJeff Garzik 2017c6fd2807SJeff Garzik /** 2018c6fd2807SJeff Garzik * mv_port_init - Perform some early initialization on a single port. 2019c6fd2807SJeff Garzik * @port: libata data structure storing shadow register addresses 2020c6fd2807SJeff Garzik * @port_mmio: base address of the port 2021c6fd2807SJeff Garzik * 2022c6fd2807SJeff Garzik * Initialize shadow register mmio addresses, clear outstanding 2023c6fd2807SJeff Garzik * interrupts on the port, and unmask interrupts for the future 2024c6fd2807SJeff Garzik * start of the port. 2025c6fd2807SJeff Garzik * 2026c6fd2807SJeff Garzik * LOCKING: 2027c6fd2807SJeff Garzik * Inherited from caller. 2028c6fd2807SJeff Garzik */ 2029c6fd2807SJeff Garzik static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio) 2030c6fd2807SJeff Garzik { 2031*0d5ff566STejun Heo void __iomem *shd_base = port_mmio + SHD_BLK_OFS; 2032c6fd2807SJeff Garzik unsigned serr_ofs; 2033c6fd2807SJeff Garzik 2034c6fd2807SJeff Garzik /* PIO related setup 2035c6fd2807SJeff Garzik */ 2036c6fd2807SJeff Garzik port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA); 2037c6fd2807SJeff Garzik port->error_addr = 2038c6fd2807SJeff Garzik port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR); 2039c6fd2807SJeff Garzik port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT); 2040c6fd2807SJeff Garzik port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL); 2041c6fd2807SJeff Garzik port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM); 2042c6fd2807SJeff Garzik port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH); 2043c6fd2807SJeff Garzik port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE); 2044c6fd2807SJeff Garzik port->status_addr = 2045c6fd2807SJeff Garzik port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS); 2046c6fd2807SJeff Garzik /* special case: control/altstatus doesn't have ATA_REG_ address */ 2047c6fd2807SJeff Garzik port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS; 2048c6fd2807SJeff Garzik 2049c6fd2807SJeff Garzik /* unused: */ 2050c6fd2807SJeff Garzik port->cmd_addr = port->bmdma_addr = port->scr_addr = 0; 2051c6fd2807SJeff Garzik 2052c6fd2807SJeff Garzik /* Clear any currently outstanding port interrupt conditions */ 2053c6fd2807SJeff Garzik serr_ofs = mv_scr_offset(SCR_ERROR); 2054c6fd2807SJeff Garzik writelfl(readl(port_mmio + serr_ofs), port_mmio + serr_ofs); 2055c6fd2807SJeff Garzik writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); 2056c6fd2807SJeff Garzik 2057c6fd2807SJeff Garzik /* unmask all EDMA error interrupts */ 2058c6fd2807SJeff Garzik writelfl(~0, port_mmio + EDMA_ERR_IRQ_MASK_OFS); 2059c6fd2807SJeff Garzik 2060c6fd2807SJeff Garzik VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n", 2061c6fd2807SJeff Garzik readl(port_mmio + EDMA_CFG_OFS), 2062c6fd2807SJeff Garzik readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS), 2063c6fd2807SJeff Garzik readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS)); 2064c6fd2807SJeff Garzik } 2065c6fd2807SJeff Garzik 2066c6fd2807SJeff Garzik static int mv_chip_id(struct pci_dev *pdev, struct mv_host_priv *hpriv, 2067c6fd2807SJeff Garzik unsigned int board_idx) 2068c6fd2807SJeff Garzik { 2069c6fd2807SJeff Garzik u8 rev_id; 2070c6fd2807SJeff Garzik u32 hp_flags = hpriv->hp_flags; 2071c6fd2807SJeff Garzik 2072c6fd2807SJeff Garzik pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id); 2073c6fd2807SJeff Garzik 2074c6fd2807SJeff Garzik switch(board_idx) { 2075c6fd2807SJeff Garzik case chip_5080: 2076c6fd2807SJeff Garzik hpriv->ops = &mv5xxx_ops; 2077c6fd2807SJeff Garzik hp_flags |= MV_HP_50XX; 2078c6fd2807SJeff Garzik 2079c6fd2807SJeff Garzik switch (rev_id) { 2080c6fd2807SJeff Garzik case 0x1: 2081c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB0; 2082c6fd2807SJeff Garzik break; 2083c6fd2807SJeff Garzik case 0x3: 2084c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2085c6fd2807SJeff Garzik break; 2086c6fd2807SJeff Garzik default: 2087c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2088c6fd2807SJeff Garzik "Applying 50XXB2 workarounds to unknown rev\n"); 2089c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2090c6fd2807SJeff Garzik break; 2091c6fd2807SJeff Garzik } 2092c6fd2807SJeff Garzik break; 2093c6fd2807SJeff Garzik 2094c6fd2807SJeff Garzik case chip_504x: 2095c6fd2807SJeff Garzik case chip_508x: 2096c6fd2807SJeff Garzik hpriv->ops = &mv5xxx_ops; 2097c6fd2807SJeff Garzik hp_flags |= MV_HP_50XX; 2098c6fd2807SJeff Garzik 2099c6fd2807SJeff Garzik switch (rev_id) { 2100c6fd2807SJeff Garzik case 0x0: 2101c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB0; 2102c6fd2807SJeff Garzik break; 2103c6fd2807SJeff Garzik case 0x3: 2104c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2105c6fd2807SJeff Garzik break; 2106c6fd2807SJeff Garzik default: 2107c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2108c6fd2807SJeff Garzik "Applying B2 workarounds to unknown rev\n"); 2109c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_50XXB2; 2110c6fd2807SJeff Garzik break; 2111c6fd2807SJeff Garzik } 2112c6fd2807SJeff Garzik break; 2113c6fd2807SJeff Garzik 2114c6fd2807SJeff Garzik case chip_604x: 2115c6fd2807SJeff Garzik case chip_608x: 2116c6fd2807SJeff Garzik hpriv->ops = &mv6xxx_ops; 2117c6fd2807SJeff Garzik 2118c6fd2807SJeff Garzik switch (rev_id) { 2119c6fd2807SJeff Garzik case 0x7: 2120c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1B2; 2121c6fd2807SJeff Garzik break; 2122c6fd2807SJeff Garzik case 0x9: 2123c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2124c6fd2807SJeff Garzik break; 2125c6fd2807SJeff Garzik default: 2126c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2127c6fd2807SJeff Garzik "Applying B2 workarounds to unknown rev\n"); 2128c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1B2; 2129c6fd2807SJeff Garzik break; 2130c6fd2807SJeff Garzik } 2131c6fd2807SJeff Garzik break; 2132c6fd2807SJeff Garzik 2133c6fd2807SJeff Garzik case chip_7042: 2134c6fd2807SJeff Garzik case chip_6042: 2135c6fd2807SJeff Garzik hpriv->ops = &mv6xxx_ops; 2136c6fd2807SJeff Garzik 2137c6fd2807SJeff Garzik hp_flags |= MV_HP_GEN_IIE; 2138c6fd2807SJeff Garzik 2139c6fd2807SJeff Garzik switch (rev_id) { 2140c6fd2807SJeff Garzik case 0x0: 2141c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_XX42A0; 2142c6fd2807SJeff Garzik break; 2143c6fd2807SJeff Garzik case 0x1: 2144c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2145c6fd2807SJeff Garzik break; 2146c6fd2807SJeff Garzik default: 2147c6fd2807SJeff Garzik dev_printk(KERN_WARNING, &pdev->dev, 2148c6fd2807SJeff Garzik "Applying 60X1C0 workarounds to unknown rev\n"); 2149c6fd2807SJeff Garzik hp_flags |= MV_HP_ERRATA_60X1C0; 2150c6fd2807SJeff Garzik break; 2151c6fd2807SJeff Garzik } 2152c6fd2807SJeff Garzik break; 2153c6fd2807SJeff Garzik 2154c6fd2807SJeff Garzik default: 2155c6fd2807SJeff Garzik printk(KERN_ERR DRV_NAME ": BUG: invalid board index %u\n", board_idx); 2156c6fd2807SJeff Garzik return 1; 2157c6fd2807SJeff Garzik } 2158c6fd2807SJeff Garzik 2159c6fd2807SJeff Garzik hpriv->hp_flags = hp_flags; 2160c6fd2807SJeff Garzik 2161c6fd2807SJeff Garzik return 0; 2162c6fd2807SJeff Garzik } 2163c6fd2807SJeff Garzik 2164c6fd2807SJeff Garzik /** 2165c6fd2807SJeff Garzik * mv_init_host - Perform some early initialization of the host. 2166c6fd2807SJeff Garzik * @pdev: host PCI device 2167c6fd2807SJeff Garzik * @probe_ent: early data struct representing the host 2168c6fd2807SJeff Garzik * 2169c6fd2807SJeff Garzik * If possible, do an early global reset of the host. Then do 2170c6fd2807SJeff Garzik * our port init and clear/unmask all/relevant host interrupts. 2171c6fd2807SJeff Garzik * 2172c6fd2807SJeff Garzik * LOCKING: 2173c6fd2807SJeff Garzik * Inherited from caller. 2174c6fd2807SJeff Garzik */ 2175c6fd2807SJeff Garzik static int mv_init_host(struct pci_dev *pdev, struct ata_probe_ent *probe_ent, 2176c6fd2807SJeff Garzik unsigned int board_idx) 2177c6fd2807SJeff Garzik { 2178c6fd2807SJeff Garzik int rc = 0, n_hc, port, hc; 2179*0d5ff566STejun Heo void __iomem *mmio = probe_ent->iomap[MV_PRIMARY_BAR]; 2180c6fd2807SJeff Garzik struct mv_host_priv *hpriv = probe_ent->private_data; 2181c6fd2807SJeff Garzik 2182c6fd2807SJeff Garzik /* global interrupt mask */ 2183c6fd2807SJeff Garzik writel(0, mmio + HC_MAIN_IRQ_MASK_OFS); 2184c6fd2807SJeff Garzik 2185c6fd2807SJeff Garzik rc = mv_chip_id(pdev, hpriv, board_idx); 2186c6fd2807SJeff Garzik if (rc) 2187c6fd2807SJeff Garzik goto done; 2188c6fd2807SJeff Garzik 2189cca3974eSJeff Garzik n_hc = mv_get_hc_count(probe_ent->port_flags); 2190c6fd2807SJeff Garzik probe_ent->n_ports = MV_PORTS_PER_HC * n_hc; 2191c6fd2807SJeff Garzik 2192c6fd2807SJeff Garzik for (port = 0; port < probe_ent->n_ports; port++) 2193c6fd2807SJeff Garzik hpriv->ops->read_preamp(hpriv, port, mmio); 2194c6fd2807SJeff Garzik 2195c6fd2807SJeff Garzik rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc); 2196c6fd2807SJeff Garzik if (rc) 2197c6fd2807SJeff Garzik goto done; 2198c6fd2807SJeff Garzik 2199c6fd2807SJeff Garzik hpriv->ops->reset_flash(hpriv, mmio); 2200c6fd2807SJeff Garzik hpriv->ops->reset_bus(pdev, mmio); 2201c6fd2807SJeff Garzik hpriv->ops->enable_leds(hpriv, mmio); 2202c6fd2807SJeff Garzik 2203c6fd2807SJeff Garzik for (port = 0; port < probe_ent->n_ports; port++) { 2204c6fd2807SJeff Garzik if (IS_60XX(hpriv)) { 2205c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2206c6fd2807SJeff Garzik 2207c6fd2807SJeff Garzik u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); 2208c6fd2807SJeff Garzik ifctl |= (1 << 7); /* enable gen2i speed */ 2209c6fd2807SJeff Garzik ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ 2210c6fd2807SJeff Garzik writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL); 2211c6fd2807SJeff Garzik } 2212c6fd2807SJeff Garzik 2213c6fd2807SJeff Garzik hpriv->ops->phy_errata(hpriv, mmio, port); 2214c6fd2807SJeff Garzik } 2215c6fd2807SJeff Garzik 2216c6fd2807SJeff Garzik for (port = 0; port < probe_ent->n_ports; port++) { 2217c6fd2807SJeff Garzik void __iomem *port_mmio = mv_port_base(mmio, port); 2218c6fd2807SJeff Garzik mv_port_init(&probe_ent->port[port], port_mmio); 2219c6fd2807SJeff Garzik } 2220c6fd2807SJeff Garzik 2221c6fd2807SJeff Garzik for (hc = 0; hc < n_hc; hc++) { 2222c6fd2807SJeff Garzik void __iomem *hc_mmio = mv_hc_base(mmio, hc); 2223c6fd2807SJeff Garzik 2224c6fd2807SJeff Garzik VPRINTK("HC%i: HC config=0x%08x HC IRQ cause " 2225c6fd2807SJeff Garzik "(before clear)=0x%08x\n", hc, 2226c6fd2807SJeff Garzik readl(hc_mmio + HC_CFG_OFS), 2227c6fd2807SJeff Garzik readl(hc_mmio + HC_IRQ_CAUSE_OFS)); 2228c6fd2807SJeff Garzik 2229c6fd2807SJeff Garzik /* Clear any currently outstanding hc interrupt conditions */ 2230c6fd2807SJeff Garzik writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS); 2231c6fd2807SJeff Garzik } 2232c6fd2807SJeff Garzik 2233c6fd2807SJeff Garzik /* Clear any currently outstanding host interrupt conditions */ 2234c6fd2807SJeff Garzik writelfl(0, mmio + PCI_IRQ_CAUSE_OFS); 2235c6fd2807SJeff Garzik 2236c6fd2807SJeff Garzik /* and unmask interrupt generation for host regs */ 2237c6fd2807SJeff Garzik writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS); 2238c6fd2807SJeff Garzik writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS); 2239c6fd2807SJeff Garzik 2240c6fd2807SJeff Garzik VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x " 2241c6fd2807SJeff Garzik "PCI int cause/mask=0x%08x/0x%08x\n", 2242c6fd2807SJeff Garzik readl(mmio + HC_MAIN_IRQ_CAUSE_OFS), 2243c6fd2807SJeff Garzik readl(mmio + HC_MAIN_IRQ_MASK_OFS), 2244c6fd2807SJeff Garzik readl(mmio + PCI_IRQ_CAUSE_OFS), 2245c6fd2807SJeff Garzik readl(mmio + PCI_IRQ_MASK_OFS)); 2246c6fd2807SJeff Garzik 2247c6fd2807SJeff Garzik done: 2248c6fd2807SJeff Garzik return rc; 2249c6fd2807SJeff Garzik } 2250c6fd2807SJeff Garzik 2251c6fd2807SJeff Garzik /** 2252c6fd2807SJeff Garzik * mv_print_info - Dump key info to kernel log for perusal. 2253c6fd2807SJeff Garzik * @probe_ent: early data struct representing the host 2254c6fd2807SJeff Garzik * 2255c6fd2807SJeff Garzik * FIXME: complete this. 2256c6fd2807SJeff Garzik * 2257c6fd2807SJeff Garzik * LOCKING: 2258c6fd2807SJeff Garzik * Inherited from caller. 2259c6fd2807SJeff Garzik */ 2260c6fd2807SJeff Garzik static void mv_print_info(struct ata_probe_ent *probe_ent) 2261c6fd2807SJeff Garzik { 2262c6fd2807SJeff Garzik struct pci_dev *pdev = to_pci_dev(probe_ent->dev); 2263c6fd2807SJeff Garzik struct mv_host_priv *hpriv = probe_ent->private_data; 2264c6fd2807SJeff Garzik u8 rev_id, scc; 2265c6fd2807SJeff Garzik const char *scc_s; 2266c6fd2807SJeff Garzik 2267c6fd2807SJeff Garzik /* Use this to determine the HW stepping of the chip so we know 2268c6fd2807SJeff Garzik * what errata to workaround 2269c6fd2807SJeff Garzik */ 2270c6fd2807SJeff Garzik pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id); 2271c6fd2807SJeff Garzik 2272c6fd2807SJeff Garzik pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc); 2273c6fd2807SJeff Garzik if (scc == 0) 2274c6fd2807SJeff Garzik scc_s = "SCSI"; 2275c6fd2807SJeff Garzik else if (scc == 0x01) 2276c6fd2807SJeff Garzik scc_s = "RAID"; 2277c6fd2807SJeff Garzik else 2278c6fd2807SJeff Garzik scc_s = "unknown"; 2279c6fd2807SJeff Garzik 2280c6fd2807SJeff Garzik dev_printk(KERN_INFO, &pdev->dev, 2281c6fd2807SJeff Garzik "%u slots %u ports %s mode IRQ via %s\n", 2282c6fd2807SJeff Garzik (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports, 2283c6fd2807SJeff Garzik scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx"); 2284c6fd2807SJeff Garzik } 2285c6fd2807SJeff Garzik 2286c6fd2807SJeff Garzik /** 2287c6fd2807SJeff Garzik * mv_init_one - handle a positive probe of a Marvell host 2288c6fd2807SJeff Garzik * @pdev: PCI device found 2289c6fd2807SJeff Garzik * @ent: PCI device ID entry for the matched host 2290c6fd2807SJeff Garzik * 2291c6fd2807SJeff Garzik * LOCKING: 2292c6fd2807SJeff Garzik * Inherited from caller. 2293c6fd2807SJeff Garzik */ 2294c6fd2807SJeff Garzik static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 2295c6fd2807SJeff Garzik { 2296c6fd2807SJeff Garzik static int printed_version = 0; 229724dc5f33STejun Heo struct device *dev = &pdev->dev; 229824dc5f33STejun Heo struct ata_probe_ent *probe_ent; 2299c6fd2807SJeff Garzik struct mv_host_priv *hpriv; 2300c6fd2807SJeff Garzik unsigned int board_idx = (unsigned int)ent->driver_data; 230124dc5f33STejun Heo int rc; 2302c6fd2807SJeff Garzik 2303c6fd2807SJeff Garzik if (!printed_version++) 2304c6fd2807SJeff Garzik dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 2305c6fd2807SJeff Garzik 230624dc5f33STejun Heo rc = pcim_enable_device(pdev); 230724dc5f33STejun Heo if (rc) 2308c6fd2807SJeff Garzik return rc; 2309c6fd2807SJeff Garzik pci_set_master(pdev); 2310c6fd2807SJeff Garzik 2311*0d5ff566STejun Heo rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME); 2312*0d5ff566STejun Heo if (rc == -EBUSY) 231324dc5f33STejun Heo pcim_pin_device(pdev); 2314*0d5ff566STejun Heo if (rc) 231524dc5f33STejun Heo return rc; 2316c6fd2807SJeff Garzik 231724dc5f33STejun Heo probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL); 231824dc5f33STejun Heo if (probe_ent == NULL) 231924dc5f33STejun Heo return -ENOMEM; 2320c6fd2807SJeff Garzik 2321c6fd2807SJeff Garzik probe_ent->dev = pci_dev_to_dev(pdev); 2322c6fd2807SJeff Garzik INIT_LIST_HEAD(&probe_ent->node); 2323c6fd2807SJeff Garzik 232424dc5f33STejun Heo hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); 232524dc5f33STejun Heo if (!hpriv) 232624dc5f33STejun Heo return -ENOMEM; 2327c6fd2807SJeff Garzik 2328c6fd2807SJeff Garzik probe_ent->sht = mv_port_info[board_idx].sht; 2329cca3974eSJeff Garzik probe_ent->port_flags = mv_port_info[board_idx].flags; 2330c6fd2807SJeff Garzik probe_ent->pio_mask = mv_port_info[board_idx].pio_mask; 2331c6fd2807SJeff Garzik probe_ent->udma_mask = mv_port_info[board_idx].udma_mask; 2332c6fd2807SJeff Garzik probe_ent->port_ops = mv_port_info[board_idx].port_ops; 2333c6fd2807SJeff Garzik 2334c6fd2807SJeff Garzik probe_ent->irq = pdev->irq; 2335c6fd2807SJeff Garzik probe_ent->irq_flags = IRQF_SHARED; 2336*0d5ff566STejun Heo probe_ent->iomap = pcim_iomap_table(pdev); 2337c6fd2807SJeff Garzik probe_ent->private_data = hpriv; 2338c6fd2807SJeff Garzik 2339c6fd2807SJeff Garzik /* initialize adapter */ 2340c6fd2807SJeff Garzik rc = mv_init_host(pdev, probe_ent, board_idx); 234124dc5f33STejun Heo if (rc) 234224dc5f33STejun Heo return rc; 2343c6fd2807SJeff Garzik 2344c6fd2807SJeff Garzik /* Enable interrupts */ 234524dc5f33STejun Heo if (msi && !pci_enable_msi(pdev)) 2346c6fd2807SJeff Garzik pci_intx(pdev, 1); 2347c6fd2807SJeff Garzik 2348c6fd2807SJeff Garzik mv_dump_pci_cfg(pdev, 0x68); 2349c6fd2807SJeff Garzik mv_print_info(probe_ent); 2350c6fd2807SJeff Garzik 235124dc5f33STejun Heo if (ata_device_add(probe_ent) == 0) 235224dc5f33STejun Heo return -ENODEV; 2353c6fd2807SJeff Garzik 235424dc5f33STejun Heo devm_kfree(dev, probe_ent); 2355c6fd2807SJeff Garzik return 0; 2356c6fd2807SJeff Garzik } 2357c6fd2807SJeff Garzik 2358c6fd2807SJeff Garzik static int __init mv_init(void) 2359c6fd2807SJeff Garzik { 2360c6fd2807SJeff Garzik return pci_register_driver(&mv_pci_driver); 2361c6fd2807SJeff Garzik } 2362c6fd2807SJeff Garzik 2363c6fd2807SJeff Garzik static void __exit mv_exit(void) 2364c6fd2807SJeff Garzik { 2365c6fd2807SJeff Garzik pci_unregister_driver(&mv_pci_driver); 2366c6fd2807SJeff Garzik } 2367c6fd2807SJeff Garzik 2368c6fd2807SJeff Garzik MODULE_AUTHOR("Brett Russ"); 2369c6fd2807SJeff Garzik MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers"); 2370c6fd2807SJeff Garzik MODULE_LICENSE("GPL"); 2371c6fd2807SJeff Garzik MODULE_DEVICE_TABLE(pci, mv_pci_tbl); 2372c6fd2807SJeff Garzik MODULE_VERSION(DRV_VERSION); 2373c6fd2807SJeff Garzik 2374c6fd2807SJeff Garzik module_param(msi, int, 0444); 2375c6fd2807SJeff Garzik MODULE_PARM_DESC(msi, "Enable use of PCI MSI (0=off, 1=on)"); 2376c6fd2807SJeff Garzik 2377c6fd2807SJeff Garzik module_init(mv_init); 2378c6fd2807SJeff Garzik module_exit(mv_exit); 2379