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