blob: 2580beb70539b31609e5c547f38ae88182e53118 [file] [log] [blame]
Brett Russ20f733e2005-09-01 18:26:17 -04001/*
2 * sata_mv.c - Marvell SATA support
3 *
Jeff Garzik8b260242005-11-12 12:32:50 -05004 * Copyright 2005: EMC Corporation, all rights reserved.
Jeff Garzike2b1be52005-11-18 14:04:23 -05005 * Copyright 2005 Red Hat, Inc. All rights reserved.
Brett Russ20f733e2005-09-01 18:26:17 -04006 *
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
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/pci.h>
27#include <linux/init.h>
28#include <linux/blkdev.h>
29#include <linux/delay.h>
30#include <linux/interrupt.h>
Brett Russ20f733e2005-09-01 18:26:17 -040031#include <linux/dma-mapping.h>
Jeff Garzika9524a72005-10-30 14:39:11 -050032#include <linux/device.h>
Brett Russ20f733e2005-09-01 18:26:17 -040033#include <scsi/scsi_host.h>
Jeff Garzik193515d2005-11-07 00:59:37 -050034#include <scsi/scsi_cmnd.h>
Brett Russ20f733e2005-09-01 18:26:17 -040035#include <linux/libata.h>
Brett Russ20f733e2005-09-01 18:26:17 -040036
37#define DRV_NAME "sata_mv"
Jeff Garzikcb48cab2007-02-26 06:04:24 -050038#define DRV_VERSION "0.8"
Brett Russ20f733e2005-09-01 18:26:17 -040039
40enum {
41 /* BAR's are enumerated in terms of pci_resource_start() terms */
42 MV_PRIMARY_BAR = 0, /* offset 0x10: memory space */
43 MV_IO_BAR = 2, /* offset 0x18: IO space */
44 MV_MISC_BAR = 3, /* offset 0x1c: FLASH, NVRAM, SRAM */
45
46 MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */
47 MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */
48
49 MV_PCI_REG_BASE = 0,
50 MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */
Mark Lord615ab952006-05-19 16:24:56 -040051 MV_IRQ_COAL_CAUSE = (MV_IRQ_COAL_REG_BASE + 0x08),
52 MV_IRQ_COAL_CAUSE_LO = (MV_IRQ_COAL_REG_BASE + 0x88),
53 MV_IRQ_COAL_CAUSE_HI = (MV_IRQ_COAL_REG_BASE + 0x8c),
54 MV_IRQ_COAL_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xcc),
55 MV_IRQ_COAL_TIME_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xd0),
56
Brett Russ20f733e2005-09-01 18:26:17 -040057 MV_SATAHC0_REG_BASE = 0x20000,
Jeff Garzik522479f2005-11-12 22:14:02 -050058 MV_FLASH_CTL = 0x1046c,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -050059 MV_GPIO_PORT_CTL = 0x104f0,
60 MV_RESET_CFG = 0x180d8,
Brett Russ20f733e2005-09-01 18:26:17 -040061
62 MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ,
63 MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ,
64 MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */
65 MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ,
66
Brett Russ31961942005-09-30 01:36:00 -040067 MV_USE_Q_DEPTH = ATA_DEF_QUEUE,
Brett Russ20f733e2005-09-01 18:26:17 -040068
Brett Russ31961942005-09-30 01:36:00 -040069 MV_MAX_Q_DEPTH = 32,
70 MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1,
71
72 /* CRQB needs alignment on a 1KB boundary. Size == 1KB
73 * CRPB needs alignment on a 256B boundary. Size == 256B
74 * SG count of 176 leads to MV_PORT_PRIV_DMA_SZ == 4KB
75 * ePRD (SG) entries need alignment on a 16B boundary. Size == 16B
76 */
77 MV_CRQB_Q_SZ = (32 * MV_MAX_Q_DEPTH),
78 MV_CRPB_Q_SZ = (8 * MV_MAX_Q_DEPTH),
79 MV_MAX_SG_CT = 176,
80 MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT),
81 MV_PORT_PRIV_DMA_SZ = (MV_CRQB_Q_SZ + MV_CRPB_Q_SZ + MV_SG_TBL_SZ),
82
Brett Russ20f733e2005-09-01 18:26:17 -040083 MV_PORTS_PER_HC = 4,
84 /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */
85 MV_PORT_HC_SHIFT = 2,
Brett Russ31961942005-09-30 01:36:00 -040086 /* == (port % MV_PORTS_PER_HC) to determine hard port from 0-7 port */
Brett Russ20f733e2005-09-01 18:26:17 -040087 MV_PORT_MASK = 3,
88
89 /* Host Flags */
90 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */
91 MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */
Brett Russ31961942005-09-30 01:36:00 -040092 MV_COMMON_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
Jeff Garzik50630192005-12-13 02:29:45 -050093 ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO |
Albert Lee1f3461a2006-05-23 18:12:30 +080094 ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING),
Jeff Garzik47c2b672005-11-12 21:13:17 -050095 MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE,
Brett Russ20f733e2005-09-01 18:26:17 -040096
Brett Russ31961942005-09-30 01:36:00 -040097 CRQB_FLAG_READ = (1 << 0),
98 CRQB_TAG_SHIFT = 1,
99 CRQB_CMD_ADDR_SHIFT = 8,
100 CRQB_CMD_CS = (0x2 << 11),
101 CRQB_CMD_LAST = (1 << 15),
102
103 CRPB_FLAG_STATUS_SHIFT = 8,
104
105 EPRD_FLAG_END_OF_TBL = (1 << 31),
106
Brett Russ20f733e2005-09-01 18:26:17 -0400107 /* PCI interface registers */
108
Brett Russ31961942005-09-30 01:36:00 -0400109 PCI_COMMAND_OFS = 0xc00,
110
Brett Russ20f733e2005-09-01 18:26:17 -0400111 PCI_MAIN_CMD_STS_OFS = 0xd30,
112 STOP_PCI_MASTER = (1 << 2),
113 PCI_MASTER_EMPTY = (1 << 3),
114 GLOB_SFT_RST = (1 << 4),
115
Jeff Garzik522479f2005-11-12 22:14:02 -0500116 MV_PCI_MODE = 0xd00,
117 MV_PCI_EXP_ROM_BAR_CTL = 0xd2c,
118 MV_PCI_DISC_TIMER = 0xd04,
119 MV_PCI_MSI_TRIGGER = 0xc38,
120 MV_PCI_SERR_MASK = 0xc28,
121 MV_PCI_XBAR_TMOUT = 0x1d04,
122 MV_PCI_ERR_LOW_ADDRESS = 0x1d40,
123 MV_PCI_ERR_HIGH_ADDRESS = 0x1d44,
124 MV_PCI_ERR_ATTRIBUTE = 0x1d48,
125 MV_PCI_ERR_COMMAND = 0x1d50,
126
127 PCI_IRQ_CAUSE_OFS = 0x1d58,
128 PCI_IRQ_MASK_OFS = 0x1d5c,
Brett Russ20f733e2005-09-01 18:26:17 -0400129 PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */
130
131 HC_MAIN_IRQ_CAUSE_OFS = 0x1d60,
132 HC_MAIN_IRQ_MASK_OFS = 0x1d64,
133 PORT0_ERR = (1 << 0), /* shift by port # */
134 PORT0_DONE = (1 << 1), /* shift by port # */
135 HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */
136 HC_SHIFT = 9, /* bits 9-17 = HC1's ports */
137 PCI_ERR = (1 << 18),
138 TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */
139 TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */
Jeff Garzikfb621e22007-02-25 04:19:45 -0500140 PORTS_0_3_COAL_DONE = (1 << 8),
141 PORTS_4_7_COAL_DONE = (1 << 17),
Brett Russ20f733e2005-09-01 18:26:17 -0400142 PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */
143 GPIO_INT = (1 << 22),
144 SELF_INT = (1 << 23),
145 TWSI_INT = (1 << 24),
146 HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */
Jeff Garzikfb621e22007-02-25 04:19:45 -0500147 HC_MAIN_RSVD_5 = (0x1fff << 19), /* bits 31-19 */
Jeff Garzik8b260242005-11-12 12:32:50 -0500148 HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE |
Brett Russ20f733e2005-09-01 18:26:17 -0400149 PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT |
150 HC_MAIN_RSVD),
Jeff Garzikfb621e22007-02-25 04:19:45 -0500151 HC_MAIN_MASKED_IRQS_5 = (PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE |
152 HC_MAIN_RSVD_5),
Brett Russ20f733e2005-09-01 18:26:17 -0400153
154 /* SATAHC registers */
155 HC_CFG_OFS = 0,
156
157 HC_IRQ_CAUSE_OFS = 0x14,
Brett Russ31961942005-09-30 01:36:00 -0400158 CRPB_DMA_DONE = (1 << 0), /* shift by port # */
Brett Russ20f733e2005-09-01 18:26:17 -0400159 HC_IRQ_COAL = (1 << 4), /* IRQ coalescing */
160 DEV_IRQ = (1 << 8), /* shift by port # */
161
162 /* Shadow block registers */
Brett Russ31961942005-09-30 01:36:00 -0400163 SHD_BLK_OFS = 0x100,
164 SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */
Brett Russ20f733e2005-09-01 18:26:17 -0400165
166 /* SATA registers */
167 SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */
168 SATA_ACTIVE_OFS = 0x350,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500169 PHY_MODE3 = 0x310,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500170 PHY_MODE4 = 0x314,
171 PHY_MODE2 = 0x330,
Jeff Garzikc9d39132005-11-13 17:47:51 -0500172 MV5_PHY_MODE = 0x74,
173 MV5_LT_MODE = 0x30,
174 MV5_PHY_CTL = 0x0C,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500175 SATA_INTERFACE_CTL = 0x050,
176
177 MV_M2_PREAMP_MASK = 0x7e0,
Brett Russ20f733e2005-09-01 18:26:17 -0400178
179 /* Port registers */
180 EDMA_CFG_OFS = 0,
Brett Russ31961942005-09-30 01:36:00 -0400181 EDMA_CFG_Q_DEPTH = 0, /* queueing disabled */
182 EDMA_CFG_NCQ = (1 << 5),
183 EDMA_CFG_NCQ_GO_ON_ERR = (1 << 14), /* continue on error */
184 EDMA_CFG_RD_BRST_EXT = (1 << 11), /* read burst 512B */
185 EDMA_CFG_WR_BUFF_LEN = (1 << 13), /* write buffer 512B */
Brett Russ20f733e2005-09-01 18:26:17 -0400186
187 EDMA_ERR_IRQ_CAUSE_OFS = 0x8,
188 EDMA_ERR_IRQ_MASK_OFS = 0xc,
189 EDMA_ERR_D_PAR = (1 << 0),
190 EDMA_ERR_PRD_PAR = (1 << 1),
191 EDMA_ERR_DEV = (1 << 2),
192 EDMA_ERR_DEV_DCON = (1 << 3),
193 EDMA_ERR_DEV_CON = (1 << 4),
194 EDMA_ERR_SERR = (1 << 5),
195 EDMA_ERR_SELF_DIS = (1 << 7),
196 EDMA_ERR_BIST_ASYNC = (1 << 8),
197 EDMA_ERR_CRBQ_PAR = (1 << 9),
198 EDMA_ERR_CRPB_PAR = (1 << 10),
199 EDMA_ERR_INTRL_PAR = (1 << 11),
200 EDMA_ERR_IORDY = (1 << 12),
201 EDMA_ERR_LNK_CTRL_RX = (0xf << 13),
202 EDMA_ERR_LNK_CTRL_RX_2 = (1 << 15),
203 EDMA_ERR_LNK_DATA_RX = (0xf << 17),
204 EDMA_ERR_LNK_CTRL_TX = (0x1f << 21),
205 EDMA_ERR_LNK_DATA_TX = (0x1f << 26),
206 EDMA_ERR_TRANS_PROTO = (1 << 31),
Jeff Garzik8b260242005-11-12 12:32:50 -0500207 EDMA_ERR_FATAL = (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR |
Brett Russ20f733e2005-09-01 18:26:17 -0400208 EDMA_ERR_DEV_DCON | EDMA_ERR_CRBQ_PAR |
209 EDMA_ERR_CRPB_PAR | EDMA_ERR_INTRL_PAR |
Jeff Garzik8b260242005-11-12 12:32:50 -0500210 EDMA_ERR_IORDY | EDMA_ERR_LNK_CTRL_RX_2 |
Brett Russ20f733e2005-09-01 18:26:17 -0400211 EDMA_ERR_LNK_DATA_RX |
Jeff Garzik8b260242005-11-12 12:32:50 -0500212 EDMA_ERR_LNK_DATA_TX |
Brett Russ20f733e2005-09-01 18:26:17 -0400213 EDMA_ERR_TRANS_PROTO),
214
Brett Russ31961942005-09-30 01:36:00 -0400215 EDMA_REQ_Q_BASE_HI_OFS = 0x10,
216 EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */
Brett Russ31961942005-09-30 01:36:00 -0400217
218 EDMA_REQ_Q_OUT_PTR_OFS = 0x18,
219 EDMA_REQ_Q_PTR_SHIFT = 5,
220
221 EDMA_RSP_Q_BASE_HI_OFS = 0x1c,
222 EDMA_RSP_Q_IN_PTR_OFS = 0x20,
223 EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */
Brett Russ31961942005-09-30 01:36:00 -0400224 EDMA_RSP_Q_PTR_SHIFT = 3,
225
Brett Russ20f733e2005-09-01 18:26:17 -0400226 EDMA_CMD_OFS = 0x28,
227 EDMA_EN = (1 << 0),
228 EDMA_DS = (1 << 1),
229 ATA_RST = (1 << 2),
230
Jeff Garzikc9d39132005-11-13 17:47:51 -0500231 EDMA_IORDY_TMOUT = 0x34,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500232 EDMA_ARB_CFG = 0x38,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500233
Brett Russ31961942005-09-30 01:36:00 -0400234 /* Host private flags (hp_flags) */
235 MV_HP_FLAG_MSI = (1 << 0),
Jeff Garzik47c2b672005-11-12 21:13:17 -0500236 MV_HP_ERRATA_50XXB0 = (1 << 1),
237 MV_HP_ERRATA_50XXB2 = (1 << 2),
238 MV_HP_ERRATA_60X1B2 = (1 << 3),
239 MV_HP_ERRATA_60X1C0 = (1 << 4),
Jeff Garzike4e7b892006-01-31 12:18:41 -0500240 MV_HP_ERRATA_XX42A0 = (1 << 5),
241 MV_HP_50XX = (1 << 6),
242 MV_HP_GEN_IIE = (1 << 7),
Brett Russ20f733e2005-09-01 18:26:17 -0400243
Brett Russ31961942005-09-30 01:36:00 -0400244 /* Port private flags (pp_flags) */
245 MV_PP_FLAG_EDMA_EN = (1 << 0),
246 MV_PP_FLAG_EDMA_DS_ACT = (1 << 1),
247};
248
Jeff Garzikc9d39132005-11-13 17:47:51 -0500249#define IS_50XX(hpriv) ((hpriv)->hp_flags & MV_HP_50XX)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500250#define IS_60XX(hpriv) (((hpriv)->hp_flags & MV_HP_50XX) == 0)
Jeff Garzike4e7b892006-01-31 12:18:41 -0500251#define IS_GEN_I(hpriv) IS_50XX(hpriv)
252#define IS_GEN_II(hpriv) IS_60XX(hpriv)
253#define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500254
Jeff Garzik095fec82005-11-12 09:50:49 -0500255enum {
Jeff Garzikd88184f2007-02-26 01:26:06 -0500256 MV_DMA_BOUNDARY = 0xffffffffU,
Jeff Garzik095fec82005-11-12 09:50:49 -0500257
258 EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U,
259
260 EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U,
261};
262
Jeff Garzik522479f2005-11-12 22:14:02 -0500263enum chip_type {
264 chip_504x,
265 chip_508x,
266 chip_5080,
267 chip_604x,
268 chip_608x,
Jeff Garzike4e7b892006-01-31 12:18:41 -0500269 chip_6042,
270 chip_7042,
Jeff Garzik522479f2005-11-12 22:14:02 -0500271};
272
Brett Russ31961942005-09-30 01:36:00 -0400273/* Command ReQuest Block: 32B */
274struct mv_crqb {
Mark Lorde1469872006-05-22 19:02:03 -0400275 __le32 sg_addr;
276 __le32 sg_addr_hi;
277 __le16 ctrl_flags;
278 __le16 ata_cmd[11];
Brett Russ31961942005-09-30 01:36:00 -0400279};
280
Jeff Garzike4e7b892006-01-31 12:18:41 -0500281struct mv_crqb_iie {
Mark Lorde1469872006-05-22 19:02:03 -0400282 __le32 addr;
283 __le32 addr_hi;
284 __le32 flags;
285 __le32 len;
286 __le32 ata_cmd[4];
Jeff Garzike4e7b892006-01-31 12:18:41 -0500287};
288
Brett Russ31961942005-09-30 01:36:00 -0400289/* Command ResPonse Block: 8B */
290struct mv_crpb {
Mark Lorde1469872006-05-22 19:02:03 -0400291 __le16 id;
292 __le16 flags;
293 __le32 tmstmp;
Brett Russ31961942005-09-30 01:36:00 -0400294};
295
296/* EDMA Physical Region Descriptor (ePRD); A.K.A. SG */
297struct mv_sg {
Mark Lorde1469872006-05-22 19:02:03 -0400298 __le32 addr;
299 __le32 flags_size;
300 __le32 addr_hi;
301 __le32 reserved;
Brett Russ20f733e2005-09-01 18:26:17 -0400302};
303
304struct mv_port_priv {
Brett Russ31961942005-09-30 01:36:00 -0400305 struct mv_crqb *crqb;
306 dma_addr_t crqb_dma;
307 struct mv_crpb *crpb;
308 dma_addr_t crpb_dma;
309 struct mv_sg *sg_tbl;
310 dma_addr_t sg_tbl_dma;
Brett Russ31961942005-09-30 01:36:00 -0400311 u32 pp_flags;
Brett Russ20f733e2005-09-01 18:26:17 -0400312};
313
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500314struct mv_port_signal {
315 u32 amps;
316 u32 pre;
317};
318
Jeff Garzik47c2b672005-11-12 21:13:17 -0500319struct mv_host_priv;
320struct mv_hw_ops {
Jeff Garzik2a47ce02005-11-12 23:05:14 -0500321 void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio,
322 unsigned int port);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500323 void (*enable_leds)(struct mv_host_priv *hpriv, void __iomem *mmio);
324 void (*read_preamp)(struct mv_host_priv *hpriv, int idx,
325 void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500326 int (*reset_hc)(struct mv_host_priv *hpriv, void __iomem *mmio,
327 unsigned int n_hc);
Jeff Garzik522479f2005-11-12 22:14:02 -0500328 void (*reset_flash)(struct mv_host_priv *hpriv, void __iomem *mmio);
329 void (*reset_bus)(struct pci_dev *pdev, void __iomem *mmio);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500330};
331
Brett Russ20f733e2005-09-01 18:26:17 -0400332struct mv_host_priv {
Brett Russ31961942005-09-30 01:36:00 -0400333 u32 hp_flags;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -0500334 struct mv_port_signal signal[8];
Jeff Garzik47c2b672005-11-12 21:13:17 -0500335 const struct mv_hw_ops *ops;
Brett Russ20f733e2005-09-01 18:26:17 -0400336};
337
338static void mv_irq_clear(struct ata_port *ap);
339static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
340static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500341static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
342static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
Brett Russ20f733e2005-09-01 18:26:17 -0400343static void mv_phy_reset(struct ata_port *ap);
Jeff Garzik22374672005-11-17 10:59:48 -0500344static void __mv_phy_reset(struct ata_port *ap, int can_sleep);
Brett Russ31961942005-09-30 01:36:00 -0400345static int mv_port_start(struct ata_port *ap);
346static void mv_port_stop(struct ata_port *ap);
347static void mv_qc_prep(struct ata_queued_cmd *qc);
Jeff Garzike4e7b892006-01-31 12:18:41 -0500348static void mv_qc_prep_iie(struct ata_queued_cmd *qc);
Tejun Heo9a3d9eb2006-01-23 13:09:36 +0900349static unsigned int mv_qc_issue(struct ata_queued_cmd *qc);
David Howells7d12e782006-10-05 14:55:46 +0100350static irqreturn_t mv_interrupt(int irq, void *dev_instance);
Brett Russ31961942005-09-30 01:36:00 -0400351static void mv_eng_timeout(struct ata_port *ap);
Brett Russ20f733e2005-09-01 18:26:17 -0400352static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
353
Jeff Garzik2a47ce02005-11-12 23:05:14 -0500354static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
355 unsigned int port);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500356static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio);
357static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx,
358 void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500359static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
360 unsigned int n_hc);
Jeff Garzik522479f2005-11-12 22:14:02 -0500361static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
362static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500363
Jeff Garzik2a47ce02005-11-12 23:05:14 -0500364static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
365 unsigned int port);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500366static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio);
367static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
368 void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500369static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
370 unsigned int n_hc);
Jeff Garzik522479f2005-11-12 22:14:02 -0500371static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio);
372static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio);
Jeff Garzikc9d39132005-11-13 17:47:51 -0500373static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
374 unsigned int port_no);
375static void mv_stop_and_reset(struct ata_port *ap);
Jeff Garzik47c2b672005-11-12 21:13:17 -0500376
Jeff Garzik193515d2005-11-07 00:59:37 -0500377static struct scsi_host_template mv_sht = {
Brett Russ20f733e2005-09-01 18:26:17 -0400378 .module = THIS_MODULE,
379 .name = DRV_NAME,
380 .ioctl = ata_scsi_ioctl,
381 .queuecommand = ata_scsi_queuecmd,
Brett Russ31961942005-09-30 01:36:00 -0400382 .can_queue = MV_USE_Q_DEPTH,
Brett Russ20f733e2005-09-01 18:26:17 -0400383 .this_id = ATA_SHT_THIS_ID,
Jeff Garzikd88184f2007-02-26 01:26:06 -0500384 .sg_tablesize = MV_MAX_SG_CT,
Brett Russ20f733e2005-09-01 18:26:17 -0400385 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
386 .emulated = ATA_SHT_EMULATED,
Jeff Garzikd88184f2007-02-26 01:26:06 -0500387 .use_clustering = 1,
Brett Russ20f733e2005-09-01 18:26:17 -0400388 .proc_name = DRV_NAME,
389 .dma_boundary = MV_DMA_BOUNDARY,
390 .slave_configure = ata_scsi_slave_config,
Tejun Heoccf68c32006-05-31 18:28:09 +0900391 .slave_destroy = ata_scsi_slave_destroy,
Brett Russ20f733e2005-09-01 18:26:17 -0400392 .bios_param = ata_std_bios_param,
Brett Russ20f733e2005-09-01 18:26:17 -0400393};
394
Jeff Garzikc9d39132005-11-13 17:47:51 -0500395static const struct ata_port_operations mv5_ops = {
396 .port_disable = ata_port_disable,
397
398 .tf_load = ata_tf_load,
399 .tf_read = ata_tf_read,
400 .check_status = ata_check_status,
401 .exec_command = ata_exec_command,
402 .dev_select = ata_std_dev_select,
403
404 .phy_reset = mv_phy_reset,
405
406 .qc_prep = mv_qc_prep,
407 .qc_issue = mv_qc_issue,
Tejun Heo0d5ff562007-02-01 15:06:36 +0900408 .data_xfer = ata_data_xfer,
Jeff Garzikc9d39132005-11-13 17:47:51 -0500409
410 .eng_timeout = mv_eng_timeout,
411
412 .irq_handler = mv_interrupt,
413 .irq_clear = mv_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900414 .irq_on = ata_irq_on,
415 .irq_ack = ata_irq_ack,
Jeff Garzikc9d39132005-11-13 17:47:51 -0500416
417 .scr_read = mv5_scr_read,
418 .scr_write = mv5_scr_write,
419
420 .port_start = mv_port_start,
421 .port_stop = mv_port_stop,
Jeff Garzikc9d39132005-11-13 17:47:51 -0500422};
423
424static const struct ata_port_operations mv6_ops = {
Brett Russ20f733e2005-09-01 18:26:17 -0400425 .port_disable = ata_port_disable,
426
427 .tf_load = ata_tf_load,
428 .tf_read = ata_tf_read,
429 .check_status = ata_check_status,
430 .exec_command = ata_exec_command,
431 .dev_select = ata_std_dev_select,
432
433 .phy_reset = mv_phy_reset,
434
Brett Russ31961942005-09-30 01:36:00 -0400435 .qc_prep = mv_qc_prep,
436 .qc_issue = mv_qc_issue,
Tejun Heo0d5ff562007-02-01 15:06:36 +0900437 .data_xfer = ata_data_xfer,
Brett Russ20f733e2005-09-01 18:26:17 -0400438
Brett Russ31961942005-09-30 01:36:00 -0400439 .eng_timeout = mv_eng_timeout,
Brett Russ20f733e2005-09-01 18:26:17 -0400440
441 .irq_handler = mv_interrupt,
442 .irq_clear = mv_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900443 .irq_on = ata_irq_on,
444 .irq_ack = ata_irq_ack,
Brett Russ20f733e2005-09-01 18:26:17 -0400445
446 .scr_read = mv_scr_read,
447 .scr_write = mv_scr_write,
448
Brett Russ31961942005-09-30 01:36:00 -0400449 .port_start = mv_port_start,
450 .port_stop = mv_port_stop,
Brett Russ20f733e2005-09-01 18:26:17 -0400451};
452
Jeff Garzike4e7b892006-01-31 12:18:41 -0500453static const struct ata_port_operations mv_iie_ops = {
454 .port_disable = ata_port_disable,
455
456 .tf_load = ata_tf_load,
457 .tf_read = ata_tf_read,
458 .check_status = ata_check_status,
459 .exec_command = ata_exec_command,
460 .dev_select = ata_std_dev_select,
461
462 .phy_reset = mv_phy_reset,
463
464 .qc_prep = mv_qc_prep_iie,
465 .qc_issue = mv_qc_issue,
Tejun Heo0d5ff562007-02-01 15:06:36 +0900466 .data_xfer = ata_data_xfer,
Jeff Garzike4e7b892006-01-31 12:18:41 -0500467
468 .eng_timeout = mv_eng_timeout,
469
470 .irq_handler = mv_interrupt,
471 .irq_clear = mv_irq_clear,
Akira Iguchi246ce3b2007-01-26 16:27:58 +0900472 .irq_on = ata_irq_on,
473 .irq_ack = ata_irq_ack,
Jeff Garzike4e7b892006-01-31 12:18:41 -0500474
475 .scr_read = mv_scr_read,
476 .scr_write = mv_scr_write,
477
478 .port_start = mv_port_start,
479 .port_stop = mv_port_stop,
Jeff Garzike4e7b892006-01-31 12:18:41 -0500480};
481
Arjan van de Ven98ac62d2005-11-28 10:06:23 +0100482static const struct ata_port_info mv_port_info[] = {
Brett Russ20f733e2005-09-01 18:26:17 -0400483 { /* chip_504x */
484 .sht = &mv_sht,
Jeff Garzikcca39742006-08-24 03:19:22 -0400485 .flags = MV_COMMON_FLAGS,
Brett Russ31961942005-09-30 01:36:00 -0400486 .pio_mask = 0x1f, /* pio0-4 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500487 .udma_mask = 0x7f, /* udma0-6 */
488 .port_ops = &mv5_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400489 },
490 { /* chip_508x */
491 .sht = &mv_sht,
Jeff Garzikcca39742006-08-24 03:19:22 -0400492 .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC),
Brett Russ31961942005-09-30 01:36:00 -0400493 .pio_mask = 0x1f, /* pio0-4 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500494 .udma_mask = 0x7f, /* udma0-6 */
495 .port_ops = &mv5_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400496 },
Jeff Garzik47c2b672005-11-12 21:13:17 -0500497 { /* chip_5080 */
498 .sht = &mv_sht,
Jeff Garzikcca39742006-08-24 03:19:22 -0400499 .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC),
Jeff Garzik47c2b672005-11-12 21:13:17 -0500500 .pio_mask = 0x1f, /* pio0-4 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500501 .udma_mask = 0x7f, /* udma0-6 */
502 .port_ops = &mv5_ops,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500503 },
Brett Russ20f733e2005-09-01 18:26:17 -0400504 { /* chip_604x */
505 .sht = &mv_sht,
Jeff Garzikcca39742006-08-24 03:19:22 -0400506 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
Brett Russ31961942005-09-30 01:36:00 -0400507 .pio_mask = 0x1f, /* pio0-4 */
508 .udma_mask = 0x7f, /* udma0-6 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500509 .port_ops = &mv6_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400510 },
511 { /* chip_608x */
512 .sht = &mv_sht,
Jeff Garzikcca39742006-08-24 03:19:22 -0400513 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS |
Brett Russ31961942005-09-30 01:36:00 -0400514 MV_FLAG_DUAL_HC),
515 .pio_mask = 0x1f, /* pio0-4 */
516 .udma_mask = 0x7f, /* udma0-6 */
Jeff Garzikc9d39132005-11-13 17:47:51 -0500517 .port_ops = &mv6_ops,
Brett Russ20f733e2005-09-01 18:26:17 -0400518 },
Jeff Garzike4e7b892006-01-31 12:18:41 -0500519 { /* chip_6042 */
520 .sht = &mv_sht,
Jeff Garzikcca39742006-08-24 03:19:22 -0400521 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
Jeff Garzike4e7b892006-01-31 12:18:41 -0500522 .pio_mask = 0x1f, /* pio0-4 */
523 .udma_mask = 0x7f, /* udma0-6 */
524 .port_ops = &mv_iie_ops,
525 },
526 { /* chip_7042 */
527 .sht = &mv_sht,
Olof Johanssone93f09d2007-01-18 18:39:59 -0600528 .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS),
Jeff Garzike4e7b892006-01-31 12:18:41 -0500529 .pio_mask = 0x1f, /* pio0-4 */
530 .udma_mask = 0x7f, /* udma0-6 */
531 .port_ops = &mv_iie_ops,
532 },
Brett Russ20f733e2005-09-01 18:26:17 -0400533};
534
Jeff Garzik3b7d6972005-11-10 11:04:11 -0500535static const struct pci_device_id mv_pci_tbl[] = {
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400536 { PCI_VDEVICE(MARVELL, 0x5040), chip_504x },
537 { PCI_VDEVICE(MARVELL, 0x5041), chip_504x },
538 { PCI_VDEVICE(MARVELL, 0x5080), chip_5080 },
539 { PCI_VDEVICE(MARVELL, 0x5081), chip_508x },
Brett Russ20f733e2005-09-01 18:26:17 -0400540
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400541 { PCI_VDEVICE(MARVELL, 0x6040), chip_604x },
542 { PCI_VDEVICE(MARVELL, 0x6041), chip_604x },
543 { PCI_VDEVICE(MARVELL, 0x6042), chip_6042 },
544 { PCI_VDEVICE(MARVELL, 0x6080), chip_608x },
545 { PCI_VDEVICE(MARVELL, 0x6081), chip_608x },
Jeff Garzik29179532005-11-11 08:08:03 -0500546
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400547 { PCI_VDEVICE(ADAPTEC2, 0x0241), chip_604x },
548
Olof Johanssone93f09d2007-01-18 18:39:59 -0600549 { PCI_VDEVICE(TTI, 0x2310), chip_7042 },
550
Morrison, Tom6a3d5862007-03-06 02:38:10 -0800551 /* add Marvell 7042 support */
552 { PCI_VDEVICE(MARVELL, 0x7042), chip_7042 },
553
Jeff Garzik2d2744f2006-09-28 20:21:59 -0400554 { } /* terminate list */
Brett Russ20f733e2005-09-01 18:26:17 -0400555};
556
557static struct pci_driver mv_pci_driver = {
558 .name = DRV_NAME,
559 .id_table = mv_pci_tbl,
560 .probe = mv_init_one,
561 .remove = ata_pci_remove_one,
562};
563
Jeff Garzik47c2b672005-11-12 21:13:17 -0500564static const struct mv_hw_ops mv5xxx_ops = {
565 .phy_errata = mv5_phy_errata,
566 .enable_leds = mv5_enable_leds,
567 .read_preamp = mv5_read_preamp,
568 .reset_hc = mv5_reset_hc,
Jeff Garzik522479f2005-11-12 22:14:02 -0500569 .reset_flash = mv5_reset_flash,
570 .reset_bus = mv5_reset_bus,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500571};
572
573static const struct mv_hw_ops mv6xxx_ops = {
574 .phy_errata = mv6_phy_errata,
575 .enable_leds = mv6_enable_leds,
576 .read_preamp = mv6_read_preamp,
577 .reset_hc = mv6_reset_hc,
Jeff Garzik522479f2005-11-12 22:14:02 -0500578 .reset_flash = mv6_reset_flash,
579 .reset_bus = mv_reset_pci_bus,
Jeff Garzik47c2b672005-11-12 21:13:17 -0500580};
581
Brett Russ20f733e2005-09-01 18:26:17 -0400582/*
Jeff Garzikddef9bb2006-02-02 16:17:06 -0500583 * module options
584 */
585static int msi; /* Use PCI msi; either zero (off, default) or non-zero */
586
587
Jeff Garzikd88184f2007-02-26 01:26:06 -0500588/* move to PCI layer or libata core? */
589static int pci_go_64(struct pci_dev *pdev)
590{
591 int rc;
592
593 if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
594 rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
595 if (rc) {
596 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
597 if (rc) {
598 dev_printk(KERN_ERR, &pdev->dev,
599 "64-bit DMA enable failed\n");
600 return rc;
601 }
602 }
603 } else {
604 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
605 if (rc) {
606 dev_printk(KERN_ERR, &pdev->dev,
607 "32-bit DMA enable failed\n");
608 return rc;
609 }
610 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
611 if (rc) {
612 dev_printk(KERN_ERR, &pdev->dev,
613 "32-bit consistent DMA enable failed\n");
614 return rc;
615 }
616 }
617
618 return rc;
619}
620
Jeff Garzikddef9bb2006-02-02 16:17:06 -0500621/*
Brett Russ20f733e2005-09-01 18:26:17 -0400622 * Functions
623 */
624
625static inline void writelfl(unsigned long data, void __iomem *addr)
626{
627 writel(data, addr);
628 (void) readl(addr); /* flush to avoid PCI posted write */
629}
630
Brett Russ20f733e2005-09-01 18:26:17 -0400631static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc)
632{
633 return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ));
634}
635
Jeff Garzikc9d39132005-11-13 17:47:51 -0500636static inline unsigned int mv_hc_from_port(unsigned int port)
637{
638 return port >> MV_PORT_HC_SHIFT;
639}
640
641static inline unsigned int mv_hardport_from_port(unsigned int port)
642{
643 return port & MV_PORT_MASK;
644}
645
646static inline void __iomem *mv_hc_base_from_port(void __iomem *base,
647 unsigned int port)
648{
649 return mv_hc_base(base, mv_hc_from_port(port));
650}
651
Brett Russ20f733e2005-09-01 18:26:17 -0400652static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port)
653{
Jeff Garzikc9d39132005-11-13 17:47:51 -0500654 return mv_hc_base_from_port(base, port) +
Jeff Garzik8b260242005-11-12 12:32:50 -0500655 MV_SATAHC_ARBTR_REG_SZ +
Jeff Garzikc9d39132005-11-13 17:47:51 -0500656 (mv_hardport_from_port(port) * MV_PORT_REG_SZ);
Brett Russ20f733e2005-09-01 18:26:17 -0400657}
658
659static inline void __iomem *mv_ap_base(struct ata_port *ap)
660{
Tejun Heo0d5ff562007-02-01 15:06:36 +0900661 return mv_port_base(ap->host->iomap[MV_PRIMARY_BAR], ap->port_no);
Brett Russ20f733e2005-09-01 18:26:17 -0400662}
663
Jeff Garzikcca39742006-08-24 03:19:22 -0400664static inline int mv_get_hc_count(unsigned long port_flags)
Brett Russ20f733e2005-09-01 18:26:17 -0400665{
Jeff Garzikcca39742006-08-24 03:19:22 -0400666 return ((port_flags & MV_FLAG_DUAL_HC) ? 2 : 1);
Brett Russ20f733e2005-09-01 18:26:17 -0400667}
668
669static void mv_irq_clear(struct ata_port *ap)
670{
671}
672
Brett Russ05b308e2005-10-05 17:08:53 -0400673/**
674 * mv_start_dma - Enable eDMA engine
675 * @base: port base address
676 * @pp: port private data
677 *
Tejun Heobeec7db2006-02-11 19:11:13 +0900678 * Verify the local cache of the eDMA state is accurate with a
679 * WARN_ON.
Brett Russ05b308e2005-10-05 17:08:53 -0400680 *
681 * LOCKING:
682 * Inherited from caller.
683 */
Brett Russafb0edd2005-10-05 17:08:42 -0400684static void mv_start_dma(void __iomem *base, struct mv_port_priv *pp)
Brett Russ31961942005-09-30 01:36:00 -0400685{
Brett Russafb0edd2005-10-05 17:08:42 -0400686 if (!(MV_PP_FLAG_EDMA_EN & pp->pp_flags)) {
687 writelfl(EDMA_EN, base + EDMA_CMD_OFS);
688 pp->pp_flags |= MV_PP_FLAG_EDMA_EN;
689 }
Tejun Heobeec7db2006-02-11 19:11:13 +0900690 WARN_ON(!(EDMA_EN & readl(base + EDMA_CMD_OFS)));
Brett Russ31961942005-09-30 01:36:00 -0400691}
692
Brett Russ05b308e2005-10-05 17:08:53 -0400693/**
694 * mv_stop_dma - Disable eDMA engine
695 * @ap: ATA channel to manipulate
696 *
Tejun Heobeec7db2006-02-11 19:11:13 +0900697 * Verify the local cache of the eDMA state is accurate with a
698 * WARN_ON.
Brett Russ05b308e2005-10-05 17:08:53 -0400699 *
700 * LOCKING:
701 * Inherited from caller.
702 */
Brett Russ31961942005-09-30 01:36:00 -0400703static void mv_stop_dma(struct ata_port *ap)
704{
705 void __iomem *port_mmio = mv_ap_base(ap);
706 struct mv_port_priv *pp = ap->private_data;
Brett Russ31961942005-09-30 01:36:00 -0400707 u32 reg;
708 int i;
709
Brett Russafb0edd2005-10-05 17:08:42 -0400710 if (MV_PP_FLAG_EDMA_EN & pp->pp_flags) {
711 /* Disable EDMA if active. The disable bit auto clears.
Brett Russ31961942005-09-30 01:36:00 -0400712 */
Brett Russ31961942005-09-30 01:36:00 -0400713 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
714 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
Brett Russafb0edd2005-10-05 17:08:42 -0400715 } else {
Tejun Heobeec7db2006-02-11 19:11:13 +0900716 WARN_ON(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS));
Brett Russafb0edd2005-10-05 17:08:42 -0400717 }
Jeff Garzik8b260242005-11-12 12:32:50 -0500718
Brett Russ31961942005-09-30 01:36:00 -0400719 /* now properly wait for the eDMA to stop */
720 for (i = 1000; i > 0; i--) {
721 reg = readl(port_mmio + EDMA_CMD_OFS);
722 if (!(EDMA_EN & reg)) {
723 break;
724 }
725 udelay(100);
726 }
727
Brett Russ31961942005-09-30 01:36:00 -0400728 if (EDMA_EN & reg) {
Tejun Heof15a1da2006-05-15 20:57:56 +0900729 ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n");
Brett Russafb0edd2005-10-05 17:08:42 -0400730 /* FIXME: Consider doing a reset here to recover */
Brett Russ31961942005-09-30 01:36:00 -0400731 }
732}
733
Jeff Garzik8a70f8d2005-10-05 17:19:47 -0400734#ifdef ATA_DEBUG
Brett Russ31961942005-09-30 01:36:00 -0400735static void mv_dump_mem(void __iomem *start, unsigned bytes)
736{
Brett Russ31961942005-09-30 01:36:00 -0400737 int b, w;
738 for (b = 0; b < bytes; ) {
739 DPRINTK("%p: ", start + b);
740 for (w = 0; b < bytes && w < 4; w++) {
741 printk("%08x ",readl(start + b));
742 b += sizeof(u32);
743 }
744 printk("\n");
745 }
Brett Russ31961942005-09-30 01:36:00 -0400746}
Jeff Garzik8a70f8d2005-10-05 17:19:47 -0400747#endif
748
Brett Russ31961942005-09-30 01:36:00 -0400749static void mv_dump_pci_cfg(struct pci_dev *pdev, unsigned bytes)
750{
751#ifdef ATA_DEBUG
752 int b, w;
753 u32 dw;
754 for (b = 0; b < bytes; ) {
755 DPRINTK("%02x: ", b);
756 for (w = 0; b < bytes && w < 4; w++) {
757 (void) pci_read_config_dword(pdev,b,&dw);
758 printk("%08x ",dw);
759 b += sizeof(u32);
760 }
761 printk("\n");
762 }
763#endif
764}
765static void mv_dump_all_regs(void __iomem *mmio_base, int port,
766 struct pci_dev *pdev)
767{
768#ifdef ATA_DEBUG
Jeff Garzik8b260242005-11-12 12:32:50 -0500769 void __iomem *hc_base = mv_hc_base(mmio_base,
Brett Russ31961942005-09-30 01:36:00 -0400770 port >> MV_PORT_HC_SHIFT);
771 void __iomem *port_base;
772 int start_port, num_ports, p, start_hc, num_hcs, hc;
773
774 if (0 > port) {
775 start_hc = start_port = 0;
776 num_ports = 8; /* shld be benign for 4 port devs */
777 num_hcs = 2;
778 } else {
779 start_hc = port >> MV_PORT_HC_SHIFT;
780 start_port = port;
781 num_ports = num_hcs = 1;
782 }
Jeff Garzik8b260242005-11-12 12:32:50 -0500783 DPRINTK("All registers for port(s) %u-%u:\n", start_port,
Brett Russ31961942005-09-30 01:36:00 -0400784 num_ports > 1 ? num_ports - 1 : start_port);
785
786 if (NULL != pdev) {
787 DPRINTK("PCI config space regs:\n");
788 mv_dump_pci_cfg(pdev, 0x68);
789 }
790 DPRINTK("PCI regs:\n");
791 mv_dump_mem(mmio_base+0xc00, 0x3c);
792 mv_dump_mem(mmio_base+0xd00, 0x34);
793 mv_dump_mem(mmio_base+0xf00, 0x4);
794 mv_dump_mem(mmio_base+0x1d00, 0x6c);
795 for (hc = start_hc; hc < start_hc + num_hcs; hc++) {
Dan Alonid220c372006-04-10 23:20:22 -0700796 hc_base = mv_hc_base(mmio_base, hc);
Brett Russ31961942005-09-30 01:36:00 -0400797 DPRINTK("HC regs (HC %i):\n", hc);
798 mv_dump_mem(hc_base, 0x1c);
799 }
800 for (p = start_port; p < start_port + num_ports; p++) {
801 port_base = mv_port_base(mmio_base, p);
802 DPRINTK("EDMA regs (port %i):\n",p);
803 mv_dump_mem(port_base, 0x54);
804 DPRINTK("SATA regs (port %i):\n",p);
805 mv_dump_mem(port_base+0x300, 0x60);
806 }
807#endif
808}
809
Brett Russ20f733e2005-09-01 18:26:17 -0400810static unsigned int mv_scr_offset(unsigned int sc_reg_in)
811{
812 unsigned int ofs;
813
814 switch (sc_reg_in) {
815 case SCR_STATUS:
816 case SCR_CONTROL:
817 case SCR_ERROR:
818 ofs = SATA_STATUS_OFS + (sc_reg_in * sizeof(u32));
819 break;
820 case SCR_ACTIVE:
821 ofs = SATA_ACTIVE_OFS; /* active is not with the others */
822 break;
823 default:
824 ofs = 0xffffffffU;
825 break;
826 }
827 return ofs;
828}
829
830static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
831{
832 unsigned int ofs = mv_scr_offset(sc_reg_in);
833
Jeff Garzik35177262007-02-24 21:26:42 -0500834 if (0xffffffffU != ofs)
Brett Russ20f733e2005-09-01 18:26:17 -0400835 return readl(mv_ap_base(ap) + ofs);
Jeff Garzik35177262007-02-24 21:26:42 -0500836 else
Brett Russ20f733e2005-09-01 18:26:17 -0400837 return (u32) ofs;
Brett Russ20f733e2005-09-01 18:26:17 -0400838}
839
840static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
841{
842 unsigned int ofs = mv_scr_offset(sc_reg_in);
843
Jeff Garzik35177262007-02-24 21:26:42 -0500844 if (0xffffffffU != ofs)
Brett Russ20f733e2005-09-01 18:26:17 -0400845 writelfl(val, mv_ap_base(ap) + ofs);
Brett Russ20f733e2005-09-01 18:26:17 -0400846}
847
Jeff Garzike4e7b892006-01-31 12:18:41 -0500848static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio)
849{
850 u32 cfg = readl(port_mmio + EDMA_CFG_OFS);
851
852 /* set up non-NCQ EDMA configuration */
Jeff Garzike4e7b892006-01-31 12:18:41 -0500853 cfg &= ~(1 << 9); /* disable equeue */
854
Jeff Garzike728eab2007-02-25 02:53:41 -0500855 if (IS_GEN_I(hpriv)) {
856 cfg &= ~0x1f; /* clear queue depth */
Jeff Garzike4e7b892006-01-31 12:18:41 -0500857 cfg |= (1 << 8); /* enab config burst size mask */
Jeff Garzike728eab2007-02-25 02:53:41 -0500858 }
Jeff Garzike4e7b892006-01-31 12:18:41 -0500859
Jeff Garzike728eab2007-02-25 02:53:41 -0500860 else if (IS_GEN_II(hpriv)) {
861 cfg &= ~0x1f; /* clear queue depth */
Jeff Garzike4e7b892006-01-31 12:18:41 -0500862 cfg |= EDMA_CFG_RD_BRST_EXT | EDMA_CFG_WR_BUFF_LEN;
Jeff Garzike728eab2007-02-25 02:53:41 -0500863 cfg &= ~(EDMA_CFG_NCQ | EDMA_CFG_NCQ_GO_ON_ERR); /* clear NCQ */
864 }
Jeff Garzike4e7b892006-01-31 12:18:41 -0500865
866 else if (IS_GEN_IIE(hpriv)) {
Jeff Garzike728eab2007-02-25 02:53:41 -0500867 cfg |= (1 << 23); /* do not mask PM field in rx'd FIS */
868 cfg |= (1 << 22); /* enab 4-entry host queue cache */
Jeff Garzike4e7b892006-01-31 12:18:41 -0500869 cfg &= ~(1 << 19); /* dis 128-entry queue (for now?) */
870 cfg |= (1 << 18); /* enab early completion */
Jeff Garzike728eab2007-02-25 02:53:41 -0500871 cfg |= (1 << 17); /* enab cut-through (dis stor&forwrd) */
872 cfg &= ~(1 << 16); /* dis FIS-based switching (for now) */
873 cfg &= ~(EDMA_CFG_NCQ | EDMA_CFG_NCQ_GO_ON_ERR); /* clear NCQ */
Jeff Garzike4e7b892006-01-31 12:18:41 -0500874 }
875
876 writelfl(cfg, port_mmio + EDMA_CFG_OFS);
877}
878
Brett Russ05b308e2005-10-05 17:08:53 -0400879/**
880 * mv_port_start - Port specific init/start routine.
881 * @ap: ATA channel to manipulate
882 *
883 * Allocate and point to DMA memory, init port private memory,
884 * zero indices.
885 *
886 * LOCKING:
887 * Inherited from caller.
888 */
Brett Russ31961942005-09-30 01:36:00 -0400889static int mv_port_start(struct ata_port *ap)
890{
Jeff Garzikcca39742006-08-24 03:19:22 -0400891 struct device *dev = ap->host->dev;
892 struct mv_host_priv *hpriv = ap->host->private_data;
Brett Russ31961942005-09-30 01:36:00 -0400893 struct mv_port_priv *pp;
894 void __iomem *port_mmio = mv_ap_base(ap);
895 void *mem;
896 dma_addr_t mem_dma;
Tejun Heo24dc5f32007-01-20 16:00:28 +0900897 int rc;
Brett Russ31961942005-09-30 01:36:00 -0400898
Tejun Heo24dc5f32007-01-20 16:00:28 +0900899 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500900 if (!pp)
Tejun Heo24dc5f32007-01-20 16:00:28 +0900901 return -ENOMEM;
Brett Russ31961942005-09-30 01:36:00 -0400902
Tejun Heo24dc5f32007-01-20 16:00:28 +0900903 mem = dmam_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma,
904 GFP_KERNEL);
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500905 if (!mem)
Tejun Heo24dc5f32007-01-20 16:00:28 +0900906 return -ENOMEM;
Brett Russ31961942005-09-30 01:36:00 -0400907 memset(mem, 0, MV_PORT_PRIV_DMA_SZ);
908
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500909 rc = ata_pad_alloc(ap, dev);
910 if (rc)
Tejun Heo24dc5f32007-01-20 16:00:28 +0900911 return rc;
Jeff Garzik6037d6b2005-11-04 22:08:00 -0500912
Jeff Garzik8b260242005-11-12 12:32:50 -0500913 /* First item in chunk of DMA memory:
Brett Russ31961942005-09-30 01:36:00 -0400914 * 32-slot command request table (CRQB), 32 bytes each in size
915 */
916 pp->crqb = mem;
917 pp->crqb_dma = mem_dma;
918 mem += MV_CRQB_Q_SZ;
919 mem_dma += MV_CRQB_Q_SZ;
920
Jeff Garzik8b260242005-11-12 12:32:50 -0500921 /* Second item:
Brett Russ31961942005-09-30 01:36:00 -0400922 * 32-slot command response table (CRPB), 8 bytes each in size
923 */
924 pp->crpb = mem;
925 pp->crpb_dma = mem_dma;
926 mem += MV_CRPB_Q_SZ;
927 mem_dma += MV_CRPB_Q_SZ;
928
929 /* Third item:
930 * Table of scatter-gather descriptors (ePRD), 16 bytes each
931 */
932 pp->sg_tbl = mem;
933 pp->sg_tbl_dma = mem_dma;
934
Jeff Garzike4e7b892006-01-31 12:18:41 -0500935 mv_edma_cfg(hpriv, port_mmio);
Brett Russ31961942005-09-30 01:36:00 -0400936
937 writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS);
Jeff Garzik8b260242005-11-12 12:32:50 -0500938 writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK,
Brett Russ31961942005-09-30 01:36:00 -0400939 port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
940
Jeff Garzike4e7b892006-01-31 12:18:41 -0500941 if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
942 writelfl(pp->crqb_dma & 0xffffffff,
943 port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
944 else
945 writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS);
Brett Russ31961942005-09-30 01:36:00 -0400946
947 writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS);
Jeff Garzike4e7b892006-01-31 12:18:41 -0500948
949 if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0)
950 writelfl(pp->crpb_dma & 0xffffffff,
951 port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
952 else
953 writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS);
954
Jeff Garzik8b260242005-11-12 12:32:50 -0500955 writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK,
Brett Russ31961942005-09-30 01:36:00 -0400956 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
957
Brett Russ31961942005-09-30 01:36:00 -0400958 /* Don't turn on EDMA here...do it before DMA commands only. Else
959 * we'll be unable to send non-data, PIO, etc due to restricted access
960 * to shadow regs.
961 */
962 ap->private_data = pp;
963 return 0;
964}
965
Brett Russ05b308e2005-10-05 17:08:53 -0400966/**
967 * mv_port_stop - Port specific cleanup/stop routine.
968 * @ap: ATA channel to manipulate
969 *
970 * Stop DMA, cleanup port memory.
971 *
972 * LOCKING:
Jeff Garzikcca39742006-08-24 03:19:22 -0400973 * This routine uses the host lock to protect the DMA stop.
Brett Russ05b308e2005-10-05 17:08:53 -0400974 */
Brett Russ31961942005-09-30 01:36:00 -0400975static void mv_port_stop(struct ata_port *ap)
976{
Brett Russafb0edd2005-10-05 17:08:42 -0400977 unsigned long flags;
Brett Russ31961942005-09-30 01:36:00 -0400978
Jeff Garzikcca39742006-08-24 03:19:22 -0400979 spin_lock_irqsave(&ap->host->lock, flags);
Brett Russ31961942005-09-30 01:36:00 -0400980 mv_stop_dma(ap);
Jeff Garzikcca39742006-08-24 03:19:22 -0400981 spin_unlock_irqrestore(&ap->host->lock, flags);
Brett Russ31961942005-09-30 01:36:00 -0400982}
983
Brett Russ05b308e2005-10-05 17:08:53 -0400984/**
985 * mv_fill_sg - Fill out the Marvell ePRD (scatter gather) entries
986 * @qc: queued command whose SG list to source from
987 *
988 * Populate the SG list and mark the last entry.
989 *
990 * LOCKING:
991 * Inherited from caller.
992 */
Jeff Garzikd88184f2007-02-26 01:26:06 -0500993static unsigned int mv_fill_sg(struct ata_queued_cmd *qc)
Brett Russ31961942005-09-30 01:36:00 -0400994{
995 struct mv_port_priv *pp = qc->ap->private_data;
Jeff Garzikd88184f2007-02-26 01:26:06 -0500996 unsigned int n_sg = 0;
Jeff Garzik972c26b2005-10-18 22:14:54 -0400997 struct scatterlist *sg;
Jeff Garzikd88184f2007-02-26 01:26:06 -0500998 struct mv_sg *mv_sg;
Brett Russ31961942005-09-30 01:36:00 -0400999
Jeff Garzikd88184f2007-02-26 01:26:06 -05001000 mv_sg = pp->sg_tbl;
Jeff Garzik972c26b2005-10-18 22:14:54 -04001001 ata_for_each_sg(sg, qc) {
Jeff Garzikd88184f2007-02-26 01:26:06 -05001002 dma_addr_t addr = sg_dma_address(sg);
1003 u32 sg_len = sg_dma_len(sg);
Brett Russ31961942005-09-30 01:36:00 -04001004
Jeff Garzikd88184f2007-02-26 01:26:06 -05001005 mv_sg->addr = cpu_to_le32(addr & 0xffffffff);
1006 mv_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16);
1007 mv_sg->flags_size = cpu_to_le32(sg_len & 0xffff);
Brett Russ31961942005-09-30 01:36:00 -04001008
Jeff Garzikd88184f2007-02-26 01:26:06 -05001009 if (ata_sg_is_last(sg, qc))
1010 mv_sg->flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL);
Jeff Garzik972c26b2005-10-18 22:14:54 -04001011
Jeff Garzikd88184f2007-02-26 01:26:06 -05001012 mv_sg++;
1013 n_sg++;
Brett Russ31961942005-09-30 01:36:00 -04001014 }
Jeff Garzikd88184f2007-02-26 01:26:06 -05001015
1016 return n_sg;
Brett Russ31961942005-09-30 01:36:00 -04001017}
1018
Mark Lorda6432432006-05-19 16:36:36 -04001019static inline unsigned mv_inc_q_index(unsigned index)
Brett Russ31961942005-09-30 01:36:00 -04001020{
Mark Lorda6432432006-05-19 16:36:36 -04001021 return (index + 1) & MV_MAX_Q_DEPTH_MASK;
Brett Russ31961942005-09-30 01:36:00 -04001022}
1023
Mark Lorde1469872006-05-22 19:02:03 -04001024static inline void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last)
Brett Russ31961942005-09-30 01:36:00 -04001025{
Mark Lord559eeda2006-05-19 16:40:15 -04001026 u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS |
Brett Russ31961942005-09-30 01:36:00 -04001027 (last ? CRQB_CMD_LAST : 0);
Mark Lord559eeda2006-05-19 16:40:15 -04001028 *cmdw = cpu_to_le16(tmp);
Brett Russ31961942005-09-30 01:36:00 -04001029}
1030
Brett Russ05b308e2005-10-05 17:08:53 -04001031/**
1032 * mv_qc_prep - Host specific command preparation.
1033 * @qc: queued command to prepare
1034 *
1035 * This routine simply redirects to the general purpose routine
1036 * if command is not DMA. Else, it handles prep of the CRQB
1037 * (command request block), does some sanity checking, and calls
1038 * the SG load routine.
1039 *
1040 * LOCKING:
1041 * Inherited from caller.
1042 */
Brett Russ31961942005-09-30 01:36:00 -04001043static void mv_qc_prep(struct ata_queued_cmd *qc)
1044{
1045 struct ata_port *ap = qc->ap;
1046 struct mv_port_priv *pp = ap->private_data;
Mark Lorde1469872006-05-22 19:02:03 -04001047 __le16 *cw;
Brett Russ31961942005-09-30 01:36:00 -04001048 struct ata_taskfile *tf;
1049 u16 flags = 0;
Mark Lorda6432432006-05-19 16:36:36 -04001050 unsigned in_index;
Brett Russ31961942005-09-30 01:36:00 -04001051
Jeff Garzike4e7b892006-01-31 12:18:41 -05001052 if (ATA_PROT_DMA != qc->tf.protocol)
Brett Russ31961942005-09-30 01:36:00 -04001053 return;
Brett Russ20f733e2005-09-01 18:26:17 -04001054
Brett Russ31961942005-09-30 01:36:00 -04001055 /* Fill in command request block
1056 */
Jeff Garzike4e7b892006-01-31 12:18:41 -05001057 if (!(qc->tf.flags & ATA_TFLAG_WRITE))
Brett Russ31961942005-09-30 01:36:00 -04001058 flags |= CRQB_FLAG_READ;
Tejun Heobeec7db2006-02-11 19:11:13 +09001059 WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
Brett Russ31961942005-09-30 01:36:00 -04001060 flags |= qc->tag << CRQB_TAG_SHIFT;
1061
Mark Lorda6432432006-05-19 16:36:36 -04001062 /* get current queue index from hardware */
1063 in_index = (readl(mv_ap_base(ap) + EDMA_REQ_Q_IN_PTR_OFS)
1064 >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
Brett Russ31961942005-09-30 01:36:00 -04001065
Mark Lorda6432432006-05-19 16:36:36 -04001066 pp->crqb[in_index].sg_addr =
1067 cpu_to_le32(pp->sg_tbl_dma & 0xffffffff);
1068 pp->crqb[in_index].sg_addr_hi =
1069 cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16);
1070 pp->crqb[in_index].ctrl_flags = cpu_to_le16(flags);
1071
1072 cw = &pp->crqb[in_index].ata_cmd[0];
Brett Russ31961942005-09-30 01:36:00 -04001073 tf = &qc->tf;
1074
1075 /* Sadly, the CRQB cannot accomodate all registers--there are
1076 * only 11 bytes...so we must pick and choose required
1077 * registers based on the command. So, we drop feature and
1078 * hob_feature for [RW] DMA commands, but they are needed for
1079 * NCQ. NCQ will drop hob_nsect.
1080 */
1081 switch (tf->command) {
1082 case ATA_CMD_READ:
1083 case ATA_CMD_READ_EXT:
1084 case ATA_CMD_WRITE:
1085 case ATA_CMD_WRITE_EXT:
Jens Axboec15d85c2006-02-15 15:59:25 +01001086 case ATA_CMD_WRITE_FUA_EXT:
Brett Russ31961942005-09-30 01:36:00 -04001087 mv_crqb_pack_cmd(cw++, tf->hob_nsect, ATA_REG_NSECT, 0);
1088 break;
1089#ifdef LIBATA_NCQ /* FIXME: remove this line when NCQ added */
1090 case ATA_CMD_FPDMA_READ:
1091 case ATA_CMD_FPDMA_WRITE:
Jeff Garzik8b260242005-11-12 12:32:50 -05001092 mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0);
Brett Russ31961942005-09-30 01:36:00 -04001093 mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0);
1094 break;
1095#endif /* FIXME: remove this line when NCQ added */
1096 default:
1097 /* The only other commands EDMA supports in non-queued and
1098 * non-NCQ mode are: [RW] STREAM DMA and W DMA FUA EXT, none
1099 * of which are defined/used by Linux. If we get here, this
1100 * driver needs work.
1101 *
1102 * FIXME: modify libata to give qc_prep a return value and
1103 * return error here.
1104 */
1105 BUG_ON(tf->command);
1106 break;
1107 }
1108 mv_crqb_pack_cmd(cw++, tf->nsect, ATA_REG_NSECT, 0);
1109 mv_crqb_pack_cmd(cw++, tf->hob_lbal, ATA_REG_LBAL, 0);
1110 mv_crqb_pack_cmd(cw++, tf->lbal, ATA_REG_LBAL, 0);
1111 mv_crqb_pack_cmd(cw++, tf->hob_lbam, ATA_REG_LBAM, 0);
1112 mv_crqb_pack_cmd(cw++, tf->lbam, ATA_REG_LBAM, 0);
1113 mv_crqb_pack_cmd(cw++, tf->hob_lbah, ATA_REG_LBAH, 0);
1114 mv_crqb_pack_cmd(cw++, tf->lbah, ATA_REG_LBAH, 0);
1115 mv_crqb_pack_cmd(cw++, tf->device, ATA_REG_DEVICE, 0);
1116 mv_crqb_pack_cmd(cw++, tf->command, ATA_REG_CMD, 1); /* last */
1117
Jeff Garzike4e7b892006-01-31 12:18:41 -05001118 if (!(qc->flags & ATA_QCFLAG_DMAMAP))
Brett Russ31961942005-09-30 01:36:00 -04001119 return;
Jeff Garzike4e7b892006-01-31 12:18:41 -05001120 mv_fill_sg(qc);
1121}
1122
1123/**
1124 * mv_qc_prep_iie - Host specific command preparation.
1125 * @qc: queued command to prepare
1126 *
1127 * This routine simply redirects to the general purpose routine
1128 * if command is not DMA. Else, it handles prep of the CRQB
1129 * (command request block), does some sanity checking, and calls
1130 * the SG load routine.
1131 *
1132 * LOCKING:
1133 * Inherited from caller.
1134 */
1135static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
1136{
1137 struct ata_port *ap = qc->ap;
1138 struct mv_port_priv *pp = ap->private_data;
1139 struct mv_crqb_iie *crqb;
1140 struct ata_taskfile *tf;
Mark Lorda6432432006-05-19 16:36:36 -04001141 unsigned in_index;
Jeff Garzike4e7b892006-01-31 12:18:41 -05001142 u32 flags = 0;
1143
1144 if (ATA_PROT_DMA != qc->tf.protocol)
1145 return;
1146
Jeff Garzike4e7b892006-01-31 12:18:41 -05001147 /* Fill in Gen IIE command request block
1148 */
1149 if (!(qc->tf.flags & ATA_TFLAG_WRITE))
1150 flags |= CRQB_FLAG_READ;
1151
Tejun Heobeec7db2006-02-11 19:11:13 +09001152 WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
Jeff Garzike4e7b892006-01-31 12:18:41 -05001153 flags |= qc->tag << CRQB_TAG_SHIFT;
1154
Mark Lorda6432432006-05-19 16:36:36 -04001155 /* get current queue index from hardware */
1156 in_index = (readl(mv_ap_base(ap) + EDMA_REQ_Q_IN_PTR_OFS)
1157 >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
1158
1159 crqb = (struct mv_crqb_iie *) &pp->crqb[in_index];
Jeff Garzike4e7b892006-01-31 12:18:41 -05001160 crqb->addr = cpu_to_le32(pp->sg_tbl_dma & 0xffffffff);
1161 crqb->addr_hi = cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16);
1162 crqb->flags = cpu_to_le32(flags);
1163
1164 tf = &qc->tf;
1165 crqb->ata_cmd[0] = cpu_to_le32(
1166 (tf->command << 16) |
1167 (tf->feature << 24)
1168 );
1169 crqb->ata_cmd[1] = cpu_to_le32(
1170 (tf->lbal << 0) |
1171 (tf->lbam << 8) |
1172 (tf->lbah << 16) |
1173 (tf->device << 24)
1174 );
1175 crqb->ata_cmd[2] = cpu_to_le32(
1176 (tf->hob_lbal << 0) |
1177 (tf->hob_lbam << 8) |
1178 (tf->hob_lbah << 16) |
1179 (tf->hob_feature << 24)
1180 );
1181 crqb->ata_cmd[3] = cpu_to_le32(
1182 (tf->nsect << 0) |
1183 (tf->hob_nsect << 8)
1184 );
1185
1186 if (!(qc->flags & ATA_QCFLAG_DMAMAP))
1187 return;
Brett Russ31961942005-09-30 01:36:00 -04001188 mv_fill_sg(qc);
1189}
1190
Brett Russ05b308e2005-10-05 17:08:53 -04001191/**
1192 * mv_qc_issue - Initiate a command to the host
1193 * @qc: queued command to start
1194 *
1195 * This routine simply redirects to the general purpose routine
1196 * if command is not DMA. Else, it sanity checks our local
1197 * caches of the request producer/consumer indices then enables
1198 * DMA and bumps the request producer index.
1199 *
1200 * LOCKING:
1201 * Inherited from caller.
1202 */
Tejun Heo9a3d9eb2006-01-23 13:09:36 +09001203static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
Brett Russ31961942005-09-30 01:36:00 -04001204{
1205 void __iomem *port_mmio = mv_ap_base(qc->ap);
1206 struct mv_port_priv *pp = qc->ap->private_data;
Mark Lorda6432432006-05-19 16:36:36 -04001207 unsigned in_index;
Brett Russ31961942005-09-30 01:36:00 -04001208 u32 in_ptr;
1209
1210 if (ATA_PROT_DMA != qc->tf.protocol) {
1211 /* We're about to send a non-EDMA capable command to the
1212 * port. Turn off EDMA so there won't be problems accessing
1213 * shadow block, etc registers.
1214 */
1215 mv_stop_dma(qc->ap);
1216 return ata_qc_issue_prot(qc);
1217 }
1218
Mark Lorda6432432006-05-19 16:36:36 -04001219 in_ptr = readl(port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
1220 in_index = (in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
Brett Russ31961942005-09-30 01:36:00 -04001221
Brett Russ31961942005-09-30 01:36:00 -04001222 /* until we do queuing, the queue should be empty at this point */
Mark Lorda6432432006-05-19 16:36:36 -04001223 WARN_ON(in_index != ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS)
1224 >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK));
Brett Russ31961942005-09-30 01:36:00 -04001225
Mark Lorda6432432006-05-19 16:36:36 -04001226 in_index = mv_inc_q_index(in_index); /* now incr producer index */
Brett Russ31961942005-09-30 01:36:00 -04001227
Brett Russafb0edd2005-10-05 17:08:42 -04001228 mv_start_dma(port_mmio, pp);
Brett Russ31961942005-09-30 01:36:00 -04001229
1230 /* and write the request in pointer to kick the EDMA to life */
1231 in_ptr &= EDMA_REQ_Q_BASE_LO_MASK;
Mark Lorda6432432006-05-19 16:36:36 -04001232 in_ptr |= in_index << EDMA_REQ_Q_PTR_SHIFT;
Brett Russ31961942005-09-30 01:36:00 -04001233 writelfl(in_ptr, port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
1234
1235 return 0;
1236}
1237
Brett Russ05b308e2005-10-05 17:08:53 -04001238/**
1239 * mv_get_crpb_status - get status from most recently completed cmd
1240 * @ap: ATA channel to manipulate
1241 *
1242 * This routine is for use when the port is in DMA mode, when it
1243 * will be using the CRPB (command response block) method of
Tejun Heobeec7db2006-02-11 19:11:13 +09001244 * returning command completion information. We check indices
Brett Russ05b308e2005-10-05 17:08:53 -04001245 * are good, grab status, and bump the response consumer index to
1246 * prove that we're up to date.
1247 *
1248 * LOCKING:
1249 * Inherited from caller.
1250 */
Brett Russ31961942005-09-30 01:36:00 -04001251static u8 mv_get_crpb_status(struct ata_port *ap)
1252{
1253 void __iomem *port_mmio = mv_ap_base(ap);
1254 struct mv_port_priv *pp = ap->private_data;
Mark Lorda6432432006-05-19 16:36:36 -04001255 unsigned out_index;
Brett Russ31961942005-09-30 01:36:00 -04001256 u32 out_ptr;
Mark Lord806a6e72006-03-21 21:11:53 -05001257 u8 ata_status;
Brett Russ31961942005-09-30 01:36:00 -04001258
Mark Lorda6432432006-05-19 16:36:36 -04001259 out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1260 out_index = (out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK;
Brett Russ31961942005-09-30 01:36:00 -04001261
Mark Lorda6432432006-05-19 16:36:36 -04001262 ata_status = le16_to_cpu(pp->crpb[out_index].flags)
1263 >> CRPB_FLAG_STATUS_SHIFT;
Mark Lord806a6e72006-03-21 21:11:53 -05001264
Brett Russ31961942005-09-30 01:36:00 -04001265 /* increment our consumer index... */
Mark Lorda6432432006-05-19 16:36:36 -04001266 out_index = mv_inc_q_index(out_index);
Jeff Garzik8b260242005-11-12 12:32:50 -05001267
Brett Russ31961942005-09-30 01:36:00 -04001268 /* and, until we do NCQ, there should only be 1 CRPB waiting */
Mark Lorda6432432006-05-19 16:36:36 -04001269 WARN_ON(out_index != ((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS)
1270 >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK));
Brett Russ31961942005-09-30 01:36:00 -04001271
1272 /* write out our inc'd consumer index so EDMA knows we're caught up */
1273 out_ptr &= EDMA_RSP_Q_BASE_LO_MASK;
Mark Lorda6432432006-05-19 16:36:36 -04001274 out_ptr |= out_index << EDMA_RSP_Q_PTR_SHIFT;
Brett Russ31961942005-09-30 01:36:00 -04001275 writelfl(out_ptr, port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
1276
1277 /* Return ATA status register for completed CRPB */
Mark Lord806a6e72006-03-21 21:11:53 -05001278 return ata_status;
Brett Russ20f733e2005-09-01 18:26:17 -04001279}
1280
Brett Russ05b308e2005-10-05 17:08:53 -04001281/**
1282 * mv_err_intr - Handle error interrupts on the port
1283 * @ap: ATA channel to manipulate
Mark Lord9b358e32006-05-19 16:21:03 -04001284 * @reset_allowed: bool: 0 == don't trigger from reset here
Brett Russ05b308e2005-10-05 17:08:53 -04001285 *
1286 * In most cases, just clear the interrupt and move on. However,
1287 * some cases require an eDMA reset, which is done right before
1288 * the COMRESET in mv_phy_reset(). The SERR case requires a
1289 * clear of pending errors in the SATA SERROR register. Finally,
1290 * if the port disabled DMA, update our cached copy to match.
1291 *
1292 * LOCKING:
1293 * Inherited from caller.
1294 */
Mark Lord9b358e32006-05-19 16:21:03 -04001295static void mv_err_intr(struct ata_port *ap, int reset_allowed)
Brett Russ20f733e2005-09-01 18:26:17 -04001296{
Brett Russ31961942005-09-30 01:36:00 -04001297 void __iomem *port_mmio = mv_ap_base(ap);
Brett Russ20f733e2005-09-01 18:26:17 -04001298 u32 edma_err_cause, serr = 0;
1299
Brett Russ20f733e2005-09-01 18:26:17 -04001300 edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1301
1302 if (EDMA_ERR_SERR & edma_err_cause) {
Tejun Heo81952c52006-05-15 20:57:47 +09001303 sata_scr_read(ap, SCR_ERROR, &serr);
1304 sata_scr_write_flush(ap, SCR_ERROR, serr);
Brett Russ20f733e2005-09-01 18:26:17 -04001305 }
Brett Russafb0edd2005-10-05 17:08:42 -04001306 if (EDMA_ERR_SELF_DIS & edma_err_cause) {
1307 struct mv_port_priv *pp = ap->private_data;
1308 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
1309 }
1310 DPRINTK(KERN_ERR "ata%u: port error; EDMA err cause: 0x%08x "
Tejun Heo44877b42007-02-21 01:06:51 +09001311 "SERR: 0x%08x\n", ap->print_id, edma_err_cause, serr);
Brett Russ20f733e2005-09-01 18:26:17 -04001312
1313 /* Clear EDMA now that SERR cleanup done */
1314 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1315
1316 /* check for fatal here and recover if needed */
Mark Lord9b358e32006-05-19 16:21:03 -04001317 if (reset_allowed && (EDMA_ERR_FATAL & edma_err_cause))
Jeff Garzikc9d39132005-11-13 17:47:51 -05001318 mv_stop_and_reset(ap);
Brett Russ20f733e2005-09-01 18:26:17 -04001319}
1320
Brett Russ05b308e2005-10-05 17:08:53 -04001321/**
1322 * mv_host_intr - Handle all interrupts on the given host controller
Jeff Garzikcca39742006-08-24 03:19:22 -04001323 * @host: host specific structure
Brett Russ05b308e2005-10-05 17:08:53 -04001324 * @relevant: port error bits relevant to this host controller
1325 * @hc: which host controller we're to look at
1326 *
1327 * Read then write clear the HC interrupt status then walk each
1328 * port connected to the HC and see if it needs servicing. Port
1329 * success ints are reported in the HC interrupt status reg, the
1330 * port error ints are reported in the higher level main
1331 * interrupt status register and thus are passed in via the
1332 * 'relevant' argument.
1333 *
1334 * LOCKING:
1335 * Inherited from caller.
1336 */
Jeff Garzikcca39742006-08-24 03:19:22 -04001337static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc)
Brett Russ20f733e2005-09-01 18:26:17 -04001338{
Tejun Heo0d5ff562007-02-01 15:06:36 +09001339 void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
Brett Russ20f733e2005-09-01 18:26:17 -04001340 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
Brett Russ20f733e2005-09-01 18:26:17 -04001341 struct ata_queued_cmd *qc;
1342 u32 hc_irq_cause;
Brett Russ31961942005-09-30 01:36:00 -04001343 int shift, port, port0, hard_port, handled;
Jeff Garzika7dac442005-10-30 04:44:42 -05001344 unsigned int err_mask;
Brett Russ20f733e2005-09-01 18:26:17 -04001345
Jeff Garzik35177262007-02-24 21:26:42 -05001346 if (hc == 0)
Brett Russ20f733e2005-09-01 18:26:17 -04001347 port0 = 0;
Jeff Garzik35177262007-02-24 21:26:42 -05001348 else
Brett Russ20f733e2005-09-01 18:26:17 -04001349 port0 = MV_PORTS_PER_HC;
Brett Russ20f733e2005-09-01 18:26:17 -04001350
1351 /* we'll need the HC success int register in most cases */
1352 hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS);
Jeff Garzik35177262007-02-24 21:26:42 -05001353 if (hc_irq_cause)
Brett Russ31961942005-09-30 01:36:00 -04001354 writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001355
1356 VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n",
1357 hc,relevant,hc_irq_cause);
1358
1359 for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) {
Jeff Garzikcd85f6e2006-03-20 19:49:54 -05001360 u8 ata_status = 0;
Jeff Garzikcca39742006-08-24 03:19:22 -04001361 struct ata_port *ap = host->ports[port];
Mark Lord63af2a52006-03-29 09:50:31 -05001362 struct mv_port_priv *pp = ap->private_data;
Jeff Garzik55d8ca42006-03-29 19:43:31 -05001363
Mark Lorde857f142006-05-19 16:33:03 -04001364 hard_port = mv_hardport_from_port(port); /* range 0..3 */
Brett Russ31961942005-09-30 01:36:00 -04001365 handled = 0; /* ensure ata_status is set if handled++ */
Brett Russ20f733e2005-09-01 18:26:17 -04001366
Mark Lord63af2a52006-03-29 09:50:31 -05001367 /* Note that DEV_IRQ might happen spuriously during EDMA,
Mark Lorde857f142006-05-19 16:33:03 -04001368 * and should be ignored in such cases.
1369 * The cause of this is still under investigation.
Jeff Garzik8190bdb2006-05-24 01:53:39 -04001370 */
Mark Lord63af2a52006-03-29 09:50:31 -05001371 if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) {
1372 /* EDMA: check for response queue interrupt */
1373 if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) {
1374 ata_status = mv_get_crpb_status(ap);
1375 handled = 1;
1376 }
1377 } else {
1378 /* PIO: check for device (drive) interrupt */
1379 if ((DEV_IRQ << hard_port) & hc_irq_cause) {
Tejun Heo0d5ff562007-02-01 15:06:36 +09001380 ata_status = readb(ap->ioaddr.status_addr);
Mark Lord63af2a52006-03-29 09:50:31 -05001381 handled = 1;
Mark Lorde857f142006-05-19 16:33:03 -04001382 /* ignore spurious intr if drive still BUSY */
1383 if (ata_status & ATA_BUSY) {
1384 ata_status = 0;
1385 handled = 0;
1386 }
Mark Lord63af2a52006-03-29 09:50:31 -05001387 }
Brett Russ20f733e2005-09-01 18:26:17 -04001388 }
1389
Jeff Garzik029f5462006-04-02 10:30:40 -04001390 if (ap && (ap->flags & ATA_FLAG_DISABLED))
Jeff Garzika2c91a82005-11-17 05:44:44 -05001391 continue;
1392
Jeff Garzika7dac442005-10-30 04:44:42 -05001393 err_mask = ac_err_mask(ata_status);
1394
Brett Russ31961942005-09-30 01:36:00 -04001395 shift = port << 1; /* (port * 2) */
Brett Russ20f733e2005-09-01 18:26:17 -04001396 if (port >= MV_PORTS_PER_HC) {
1397 shift++; /* skip bit 8 in the HC Main IRQ reg */
1398 }
1399 if ((PORT0_ERR << shift) & relevant) {
Mark Lord9b358e32006-05-19 16:21:03 -04001400 mv_err_intr(ap, 1);
Jeff Garzika7dac442005-10-30 04:44:42 -05001401 err_mask |= AC_ERR_OTHER;
Mark Lord63af2a52006-03-29 09:50:31 -05001402 handled = 1;
Brett Russ20f733e2005-09-01 18:26:17 -04001403 }
Jeff Garzik8b260242005-11-12 12:32:50 -05001404
Mark Lord63af2a52006-03-29 09:50:31 -05001405 if (handled) {
Brett Russ20f733e2005-09-01 18:26:17 -04001406 qc = ata_qc_from_tag(ap, ap->active_tag);
Mark Lord63af2a52006-03-29 09:50:31 -05001407 if (qc && (qc->flags & ATA_QCFLAG_ACTIVE)) {
Brett Russ20f733e2005-09-01 18:26:17 -04001408 VPRINTK("port %u IRQ found for qc, "
1409 "ata_status 0x%x\n", port,ata_status);
Brett Russ20f733e2005-09-01 18:26:17 -04001410 /* mark qc status appropriately */
Jeff Garzik701db692005-12-06 04:52:48 -05001411 if (!(qc->tf.flags & ATA_TFLAG_POLLING)) {
Albert Leea22e2eb2005-12-05 15:38:02 +08001412 qc->err_mask |= err_mask;
1413 ata_qc_complete(qc);
1414 }
Brett Russ20f733e2005-09-01 18:26:17 -04001415 }
1416 }
1417 }
1418 VPRINTK("EXIT\n");
1419}
1420
Brett Russ05b308e2005-10-05 17:08:53 -04001421/**
Jeff Garzik8b260242005-11-12 12:32:50 -05001422 * mv_interrupt -
Brett Russ05b308e2005-10-05 17:08:53 -04001423 * @irq: unused
1424 * @dev_instance: private data; in this case the host structure
1425 * @regs: unused
1426 *
1427 * Read the read only register to determine if any host
1428 * controllers have pending interrupts. If so, call lower level
1429 * routine to handle. Also check for PCI errors which are only
1430 * reported here.
1431 *
Jeff Garzik8b260242005-11-12 12:32:50 -05001432 * LOCKING:
Jeff Garzikcca39742006-08-24 03:19:22 -04001433 * This routine holds the host lock while processing pending
Brett Russ05b308e2005-10-05 17:08:53 -04001434 * interrupts.
1435 */
David Howells7d12e782006-10-05 14:55:46 +01001436static irqreturn_t mv_interrupt(int irq, void *dev_instance)
Brett Russ20f733e2005-09-01 18:26:17 -04001437{
Jeff Garzikcca39742006-08-24 03:19:22 -04001438 struct ata_host *host = dev_instance;
Brett Russ20f733e2005-09-01 18:26:17 -04001439 unsigned int hc, handled = 0, n_hcs;
Tejun Heo0d5ff562007-02-01 15:06:36 +09001440 void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
Mark Lord615ab952006-05-19 16:24:56 -04001441 struct mv_host_priv *hpriv;
Brett Russ20f733e2005-09-01 18:26:17 -04001442 u32 irq_stat;
1443
Brett Russ20f733e2005-09-01 18:26:17 -04001444 irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001445
1446 /* check the cases where we either have nothing pending or have read
1447 * a bogus register value which can indicate HW removal or PCI fault
1448 */
Jeff Garzik35177262007-02-24 21:26:42 -05001449 if (!irq_stat || (0xffffffffU == irq_stat))
Brett Russ20f733e2005-09-01 18:26:17 -04001450 return IRQ_NONE;
Brett Russ20f733e2005-09-01 18:26:17 -04001451
Jeff Garzikcca39742006-08-24 03:19:22 -04001452 n_hcs = mv_get_hc_count(host->ports[0]->flags);
1453 spin_lock(&host->lock);
Brett Russ20f733e2005-09-01 18:26:17 -04001454
1455 for (hc = 0; hc < n_hcs; hc++) {
1456 u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT));
1457 if (relevant) {
Jeff Garzikcca39742006-08-24 03:19:22 -04001458 mv_host_intr(host, relevant, hc);
Brett Russ31961942005-09-30 01:36:00 -04001459 handled++;
Brett Russ20f733e2005-09-01 18:26:17 -04001460 }
1461 }
Mark Lord615ab952006-05-19 16:24:56 -04001462
Jeff Garzikcca39742006-08-24 03:19:22 -04001463 hpriv = host->private_data;
Mark Lord615ab952006-05-19 16:24:56 -04001464 if (IS_60XX(hpriv)) {
1465 /* deal with the interrupt coalescing bits */
1466 if (irq_stat & (TRAN_LO_DONE | TRAN_HI_DONE | PORTS_0_7_COAL_DONE)) {
1467 writelfl(0, mmio + MV_IRQ_COAL_CAUSE_LO);
1468 writelfl(0, mmio + MV_IRQ_COAL_CAUSE_HI);
1469 writelfl(0, mmio + MV_IRQ_COAL_CAUSE);
1470 }
1471 }
1472
Brett Russ20f733e2005-09-01 18:26:17 -04001473 if (PCI_ERR & irq_stat) {
Brett Russ31961942005-09-30 01:36:00 -04001474 printk(KERN_ERR DRV_NAME ": PCI ERROR; PCI IRQ cause=0x%08x\n",
1475 readl(mmio + PCI_IRQ_CAUSE_OFS));
Brett Russ20f733e2005-09-01 18:26:17 -04001476
Brett Russafb0edd2005-10-05 17:08:42 -04001477 DPRINTK("All regs @ PCI error\n");
Jeff Garzikcca39742006-08-24 03:19:22 -04001478 mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev));
Brett Russ31961942005-09-30 01:36:00 -04001479
1480 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS);
1481 handled++;
1482 }
Jeff Garzikcca39742006-08-24 03:19:22 -04001483 spin_unlock(&host->lock);
Brett Russ20f733e2005-09-01 18:26:17 -04001484
1485 return IRQ_RETVAL(handled);
1486}
1487
Jeff Garzikc9d39132005-11-13 17:47:51 -05001488static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port)
1489{
1490 void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port);
1491 unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL;
1492
1493 return hc_mmio + ofs;
1494}
1495
1496static unsigned int mv5_scr_offset(unsigned int sc_reg_in)
1497{
1498 unsigned int ofs;
1499
1500 switch (sc_reg_in) {
1501 case SCR_STATUS:
1502 case SCR_ERROR:
1503 case SCR_CONTROL:
1504 ofs = sc_reg_in * sizeof(u32);
1505 break;
1506 default:
1507 ofs = 0xffffffffU;
1508 break;
1509 }
1510 return ofs;
1511}
1512
1513static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
1514{
Tejun Heo0d5ff562007-02-01 15:06:36 +09001515 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
1516 void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
Jeff Garzikc9d39132005-11-13 17:47:51 -05001517 unsigned int ofs = mv5_scr_offset(sc_reg_in);
1518
1519 if (ofs != 0xffffffffU)
Tejun Heo0d5ff562007-02-01 15:06:36 +09001520 return readl(addr + ofs);
Jeff Garzikc9d39132005-11-13 17:47:51 -05001521 else
1522 return (u32) ofs;
1523}
1524
1525static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
1526{
Tejun Heo0d5ff562007-02-01 15:06:36 +09001527 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
1528 void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
Jeff Garzikc9d39132005-11-13 17:47:51 -05001529 unsigned int ofs = mv5_scr_offset(sc_reg_in);
1530
1531 if (ofs != 0xffffffffU)
Tejun Heo0d5ff562007-02-01 15:06:36 +09001532 writelfl(val, addr + ofs);
Jeff Garzikc9d39132005-11-13 17:47:51 -05001533}
1534
Jeff Garzik522479f2005-11-12 22:14:02 -05001535static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio)
1536{
1537 u8 rev_id;
1538 int early_5080;
1539
1540 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
1541
1542 early_5080 = (pdev->device == 0x5080) && (rev_id == 0);
1543
1544 if (!early_5080) {
1545 u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL);
1546 tmp |= (1 << 0);
1547 writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL);
1548 }
1549
1550 mv_reset_pci_bus(pdev, mmio);
1551}
1552
1553static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio)
1554{
1555 writel(0x0fcfffff, mmio + MV_FLASH_CTL);
1556}
1557
Jeff Garzik47c2b672005-11-12 21:13:17 -05001558static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx,
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001559 void __iomem *mmio)
1560{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001561 void __iomem *phy_mmio = mv5_phy_base(mmio, idx);
1562 u32 tmp;
1563
1564 tmp = readl(phy_mmio + MV5_PHY_MODE);
1565
1566 hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */
1567 hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001568}
1569
Jeff Garzik47c2b672005-11-12 21:13:17 -05001570static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio)
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001571{
Jeff Garzik522479f2005-11-12 22:14:02 -05001572 u32 tmp;
1573
1574 writel(0, mmio + MV_GPIO_PORT_CTL);
1575
1576 /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */
1577
1578 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL);
1579 tmp |= ~(1 << 0);
1580 writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL);
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001581}
1582
Jeff Garzik2a47ce02005-11-12 23:05:14 -05001583static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
1584 unsigned int port)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001585{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001586 void __iomem *phy_mmio = mv5_phy_base(mmio, port);
1587 const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5);
1588 u32 tmp;
1589 int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0);
1590
1591 if (fix_apm_sq) {
1592 tmp = readl(phy_mmio + MV5_LT_MODE);
1593 tmp |= (1 << 19);
1594 writel(tmp, phy_mmio + MV5_LT_MODE);
1595
1596 tmp = readl(phy_mmio + MV5_PHY_CTL);
1597 tmp &= ~0x3;
1598 tmp |= 0x1;
1599 writel(tmp, phy_mmio + MV5_PHY_CTL);
1600 }
1601
1602 tmp = readl(phy_mmio + MV5_PHY_MODE);
1603 tmp &= ~mask;
1604 tmp |= hpriv->signal[port].pre;
1605 tmp |= hpriv->signal[port].amps;
1606 writel(tmp, phy_mmio + MV5_PHY_MODE);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001607}
1608
Jeff Garzikc9d39132005-11-13 17:47:51 -05001609
1610#undef ZERO
1611#define ZERO(reg) writel(0, port_mmio + (reg))
1612static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio,
1613 unsigned int port)
Jeff Garzik47c2b672005-11-12 21:13:17 -05001614{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001615 void __iomem *port_mmio = mv_port_base(mmio, port);
1616
1617 writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS);
1618
1619 mv_channel_reset(hpriv, mmio, port);
1620
1621 ZERO(0x028); /* command */
1622 writel(0x11f, port_mmio + EDMA_CFG_OFS);
1623 ZERO(0x004); /* timer */
1624 ZERO(0x008); /* irq err cause */
1625 ZERO(0x00c); /* irq err mask */
1626 ZERO(0x010); /* rq bah */
1627 ZERO(0x014); /* rq inp */
1628 ZERO(0x018); /* rq outp */
1629 ZERO(0x01c); /* respq bah */
1630 ZERO(0x024); /* respq outp */
1631 ZERO(0x020); /* respq inp */
1632 ZERO(0x02c); /* test control */
1633 writel(0xbc, port_mmio + EDMA_IORDY_TMOUT);
1634}
1635#undef ZERO
1636
1637#define ZERO(reg) writel(0, hc_mmio + (reg))
1638static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
1639 unsigned int hc)
1640{
1641 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
1642 u32 tmp;
1643
1644 ZERO(0x00c);
1645 ZERO(0x010);
1646 ZERO(0x014);
1647 ZERO(0x018);
1648
1649 tmp = readl(hc_mmio + 0x20);
1650 tmp &= 0x1c1c1c1c;
1651 tmp |= 0x03030303;
1652 writel(tmp, hc_mmio + 0x20);
1653}
1654#undef ZERO
1655
1656static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
1657 unsigned int n_hc)
1658{
1659 unsigned int hc, port;
1660
1661 for (hc = 0; hc < n_hc; hc++) {
1662 for (port = 0; port < MV_PORTS_PER_HC; port++)
1663 mv5_reset_hc_port(hpriv, mmio,
1664 (hc * MV_PORTS_PER_HC) + port);
1665
1666 mv5_reset_one_hc(hpriv, mmio, hc);
1667 }
1668
1669 return 0;
Jeff Garzik47c2b672005-11-12 21:13:17 -05001670}
1671
Jeff Garzik101ffae2005-11-12 22:17:49 -05001672#undef ZERO
1673#define ZERO(reg) writel(0, mmio + (reg))
1674static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio)
1675{
1676 u32 tmp;
1677
1678 tmp = readl(mmio + MV_PCI_MODE);
1679 tmp &= 0xff00ffff;
1680 writel(tmp, mmio + MV_PCI_MODE);
1681
1682 ZERO(MV_PCI_DISC_TIMER);
1683 ZERO(MV_PCI_MSI_TRIGGER);
1684 writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT);
1685 ZERO(HC_MAIN_IRQ_MASK_OFS);
1686 ZERO(MV_PCI_SERR_MASK);
1687 ZERO(PCI_IRQ_CAUSE_OFS);
1688 ZERO(PCI_IRQ_MASK_OFS);
1689 ZERO(MV_PCI_ERR_LOW_ADDRESS);
1690 ZERO(MV_PCI_ERR_HIGH_ADDRESS);
1691 ZERO(MV_PCI_ERR_ATTRIBUTE);
1692 ZERO(MV_PCI_ERR_COMMAND);
1693}
1694#undef ZERO
1695
1696static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio)
1697{
1698 u32 tmp;
1699
1700 mv5_reset_flash(hpriv, mmio);
1701
1702 tmp = readl(mmio + MV_GPIO_PORT_CTL);
1703 tmp &= 0x3;
1704 tmp |= (1 << 5) | (1 << 6);
1705 writel(tmp, mmio + MV_GPIO_PORT_CTL);
1706}
1707
1708/**
1709 * mv6_reset_hc - Perform the 6xxx global soft reset
1710 * @mmio: base address of the HBA
1711 *
1712 * This routine only applies to 6xxx parts.
1713 *
1714 * LOCKING:
1715 * Inherited from caller.
1716 */
Jeff Garzikc9d39132005-11-13 17:47:51 -05001717static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio,
1718 unsigned int n_hc)
Jeff Garzik101ffae2005-11-12 22:17:49 -05001719{
1720 void __iomem *reg = mmio + PCI_MAIN_CMD_STS_OFS;
1721 int i, rc = 0;
1722 u32 t;
1723
1724 /* Following procedure defined in PCI "main command and status
1725 * register" table.
1726 */
1727 t = readl(reg);
1728 writel(t | STOP_PCI_MASTER, reg);
1729
1730 for (i = 0; i < 1000; i++) {
1731 udelay(1);
1732 t = readl(reg);
1733 if (PCI_MASTER_EMPTY & t) {
1734 break;
1735 }
1736 }
1737 if (!(PCI_MASTER_EMPTY & t)) {
1738 printk(KERN_ERR DRV_NAME ": PCI master won't flush\n");
1739 rc = 1;
1740 goto done;
1741 }
1742
1743 /* set reset */
1744 i = 5;
1745 do {
1746 writel(t | GLOB_SFT_RST, reg);
1747 t = readl(reg);
1748 udelay(1);
1749 } while (!(GLOB_SFT_RST & t) && (i-- > 0));
1750
1751 if (!(GLOB_SFT_RST & t)) {
1752 printk(KERN_ERR DRV_NAME ": can't set global reset\n");
1753 rc = 1;
1754 goto done;
1755 }
1756
1757 /* clear reset and *reenable the PCI master* (not mentioned in spec) */
1758 i = 5;
1759 do {
1760 writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg);
1761 t = readl(reg);
1762 udelay(1);
1763 } while ((GLOB_SFT_RST & t) && (i-- > 0));
1764
1765 if (GLOB_SFT_RST & t) {
1766 printk(KERN_ERR DRV_NAME ": can't clear global reset\n");
1767 rc = 1;
1768 }
1769done:
1770 return rc;
1771}
1772
Jeff Garzik47c2b672005-11-12 21:13:17 -05001773static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx,
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001774 void __iomem *mmio)
1775{
1776 void __iomem *port_mmio;
1777 u32 tmp;
1778
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001779 tmp = readl(mmio + MV_RESET_CFG);
1780 if ((tmp & (1 << 0)) == 0) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05001781 hpriv->signal[idx].amps = 0x7 << 8;
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001782 hpriv->signal[idx].pre = 0x1 << 5;
1783 return;
1784 }
1785
1786 port_mmio = mv_port_base(mmio, idx);
1787 tmp = readl(port_mmio + PHY_MODE2);
1788
1789 hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */
1790 hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */
1791}
1792
Jeff Garzik47c2b672005-11-12 21:13:17 -05001793static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio)
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001794{
Jeff Garzik47c2b672005-11-12 21:13:17 -05001795 writel(0x00000060, mmio + MV_GPIO_PORT_CTL);
Jeff Garzikba3fe8f2005-11-12 19:08:48 -05001796}
1797
Jeff Garzikc9d39132005-11-13 17:47:51 -05001798static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio,
Jeff Garzik2a47ce02005-11-12 23:05:14 -05001799 unsigned int port)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001800{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001801 void __iomem *port_mmio = mv_port_base(mmio, port);
1802
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001803 u32 hp_flags = hpriv->hp_flags;
Jeff Garzik47c2b672005-11-12 21:13:17 -05001804 int fix_phy_mode2 =
1805 hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001806 int fix_phy_mode4 =
Jeff Garzik47c2b672005-11-12 21:13:17 -05001807 hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0);
1808 u32 m2, tmp;
1809
1810 if (fix_phy_mode2) {
1811 m2 = readl(port_mmio + PHY_MODE2);
1812 m2 &= ~(1 << 16);
1813 m2 |= (1 << 31);
1814 writel(m2, port_mmio + PHY_MODE2);
1815
1816 udelay(200);
1817
1818 m2 = readl(port_mmio + PHY_MODE2);
1819 m2 &= ~((1 << 16) | (1 << 31));
1820 writel(m2, port_mmio + PHY_MODE2);
1821
1822 udelay(200);
1823 }
1824
1825 /* who knows what this magic does */
1826 tmp = readl(port_mmio + PHY_MODE3);
1827 tmp &= ~0x7F800000;
1828 tmp |= 0x2A800000;
1829 writel(tmp, port_mmio + PHY_MODE3);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001830
1831 if (fix_phy_mode4) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05001832 u32 m4;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001833
1834 m4 = readl(port_mmio + PHY_MODE4);
Jeff Garzik47c2b672005-11-12 21:13:17 -05001835
1836 if (hp_flags & MV_HP_ERRATA_60X1B2)
1837 tmp = readl(port_mmio + 0x310);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001838
1839 m4 = (m4 & ~(1 << 1)) | (1 << 0);
1840
1841 writel(m4, port_mmio + PHY_MODE4);
Jeff Garzik47c2b672005-11-12 21:13:17 -05001842
1843 if (hp_flags & MV_HP_ERRATA_60X1B2)
1844 writel(tmp, port_mmio + 0x310);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001845 }
1846
1847 /* Revert values of pre-emphasis and signal amps to the saved ones */
1848 m2 = readl(port_mmio + PHY_MODE2);
1849
1850 m2 &= ~MV_M2_PREAMP_MASK;
Jeff Garzik2a47ce02005-11-12 23:05:14 -05001851 m2 |= hpriv->signal[port].amps;
1852 m2 |= hpriv->signal[port].pre;
Jeff Garzik47c2b672005-11-12 21:13:17 -05001853 m2 &= ~(1 << 16);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001854
Jeff Garzike4e7b892006-01-31 12:18:41 -05001855 /* according to mvSata 3.6.1, some IIE values are fixed */
1856 if (IS_GEN_IIE(hpriv)) {
1857 m2 &= ~0xC30FF01F;
1858 m2 |= 0x0000900F;
1859 }
1860
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001861 writel(m2, port_mmio + PHY_MODE2);
1862}
1863
Jeff Garzikc9d39132005-11-13 17:47:51 -05001864static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
1865 unsigned int port_no)
Brett Russ20f733e2005-09-01 18:26:17 -04001866{
Jeff Garzikc9d39132005-11-13 17:47:51 -05001867 void __iomem *port_mmio = mv_port_base(mmio, port_no);
Brett Russ20f733e2005-09-01 18:26:17 -04001868
Brett Russ31961942005-09-30 01:36:00 -04001869 writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001870
1871 if (IS_60XX(hpriv)) {
1872 u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL);
Mark Lordeb46d682006-05-19 16:29:21 -04001873 ifctl |= (1 << 7); /* enable gen2i speed */
1874 ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001875 writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL);
1876 }
1877
Brett Russ20f733e2005-09-01 18:26:17 -04001878 udelay(25); /* allow reset propagation */
1879
1880 /* Spec never mentions clearing the bit. Marvell's driver does
1881 * clear the bit, however.
1882 */
Brett Russ31961942005-09-30 01:36:00 -04001883 writelfl(0, port_mmio + EDMA_CMD_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04001884
Jeff Garzikc9d39132005-11-13 17:47:51 -05001885 hpriv->ops->phy_errata(hpriv, mmio, port_no);
1886
1887 if (IS_50XX(hpriv))
1888 mdelay(1);
1889}
1890
1891static void mv_stop_and_reset(struct ata_port *ap)
1892{
Jeff Garzikcca39742006-08-24 03:19:22 -04001893 struct mv_host_priv *hpriv = ap->host->private_data;
Tejun Heo0d5ff562007-02-01 15:06:36 +09001894 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
Jeff Garzikc9d39132005-11-13 17:47:51 -05001895
1896 mv_stop_dma(ap);
1897
1898 mv_channel_reset(hpriv, mmio, ap->port_no);
1899
Jeff Garzik22374672005-11-17 10:59:48 -05001900 __mv_phy_reset(ap, 0);
1901}
1902
1903static inline void __msleep(unsigned int msec, int can_sleep)
1904{
1905 if (can_sleep)
1906 msleep(msec);
1907 else
1908 mdelay(msec);
Jeff Garzikc9d39132005-11-13 17:47:51 -05001909}
1910
1911/**
Jeff Garzik22374672005-11-17 10:59:48 -05001912 * __mv_phy_reset - Perform eDMA reset followed by COMRESET
Jeff Garzikc9d39132005-11-13 17:47:51 -05001913 * @ap: ATA channel to manipulate
1914 *
1915 * Part of this is taken from __sata_phy_reset and modified to
1916 * not sleep since this routine gets called from interrupt level.
1917 *
1918 * LOCKING:
1919 * Inherited from caller. This is coded to safe to call at
1920 * interrupt level, i.e. it does not sleep.
1921 */
Jeff Garzik22374672005-11-17 10:59:48 -05001922static void __mv_phy_reset(struct ata_port *ap, int can_sleep)
Jeff Garzikc9d39132005-11-13 17:47:51 -05001923{
1924 struct mv_port_priv *pp = ap->private_data;
Jeff Garzikcca39742006-08-24 03:19:22 -04001925 struct mv_host_priv *hpriv = ap->host->private_data;
Jeff Garzikc9d39132005-11-13 17:47:51 -05001926 void __iomem *port_mmio = mv_ap_base(ap);
1927 struct ata_taskfile tf;
1928 struct ata_device *dev = &ap->device[0];
1929 unsigned long timeout;
Jeff Garzik22374672005-11-17 10:59:48 -05001930 int retry = 5;
1931 u32 sstatus;
Jeff Garzikc9d39132005-11-13 17:47:51 -05001932
1933 VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05001934
Jeff Garzik095fec82005-11-12 09:50:49 -05001935 DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x "
Brett Russ31961942005-09-30 01:36:00 -04001936 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS),
1937 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL));
Brett Russ20f733e2005-09-01 18:26:17 -04001938
Jeff Garzik22374672005-11-17 10:59:48 -05001939 /* Issue COMRESET via SControl */
1940comreset_retry:
Tejun Heo81952c52006-05-15 20:57:47 +09001941 sata_scr_write_flush(ap, SCR_CONTROL, 0x301);
Jeff Garzik22374672005-11-17 10:59:48 -05001942 __msleep(1, can_sleep);
1943
Tejun Heo81952c52006-05-15 20:57:47 +09001944 sata_scr_write_flush(ap, SCR_CONTROL, 0x300);
Jeff Garzik22374672005-11-17 10:59:48 -05001945 __msleep(20, can_sleep);
1946
1947 timeout = jiffies + msecs_to_jiffies(200);
Brett Russ31961942005-09-30 01:36:00 -04001948 do {
Tejun Heo81952c52006-05-15 20:57:47 +09001949 sata_scr_read(ap, SCR_STATUS, &sstatus);
Andres Salomon62f1d0e2006-09-11 08:51:05 -04001950 if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0))
Brett Russ31961942005-09-30 01:36:00 -04001951 break;
Jeff Garzik22374672005-11-17 10:59:48 -05001952
1953 __msleep(1, can_sleep);
Brett Russ31961942005-09-30 01:36:00 -04001954 } while (time_before(jiffies, timeout));
Brett Russ20f733e2005-09-01 18:26:17 -04001955
Jeff Garzik22374672005-11-17 10:59:48 -05001956 /* work around errata */
1957 if (IS_60XX(hpriv) &&
1958 (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) &&
1959 (retry-- > 0))
1960 goto comreset_retry;
Jeff Garzik095fec82005-11-12 09:50:49 -05001961
1962 DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x "
Brett Russ31961942005-09-30 01:36:00 -04001963 "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS),
1964 mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL));
1965
Tejun Heo81952c52006-05-15 20:57:47 +09001966 if (ata_port_online(ap)) {
Brett Russ31961942005-09-30 01:36:00 -04001967 ata_port_probe(ap);
1968 } else {
Tejun Heo81952c52006-05-15 20:57:47 +09001969 sata_scr_read(ap, SCR_STATUS, &sstatus);
Tejun Heof15a1da2006-05-15 20:57:56 +09001970 ata_port_printk(ap, KERN_INFO,
1971 "no device found (phy stat %08x)\n", sstatus);
Brett Russ31961942005-09-30 01:36:00 -04001972 ata_port_disable(ap);
Brett Russ20f733e2005-09-01 18:26:17 -04001973 return;
1974 }
Brett Russ31961942005-09-30 01:36:00 -04001975 ap->cbl = ATA_CBL_SATA;
Brett Russ20f733e2005-09-01 18:26:17 -04001976
Jeff Garzik22374672005-11-17 10:59:48 -05001977 /* even after SStatus reflects that device is ready,
1978 * it seems to take a while for link to be fully
1979 * established (and thus Status no longer 0x80/0x7F),
1980 * so we poll a bit for that, here.
1981 */
1982 retry = 20;
1983 while (1) {
1984 u8 drv_stat = ata_check_status(ap);
1985 if ((drv_stat != 0x80) && (drv_stat != 0x7f))
1986 break;
1987 __msleep(500, can_sleep);
1988 if (retry-- <= 0)
1989 break;
1990 }
1991
Tejun Heo0d5ff562007-02-01 15:06:36 +09001992 tf.lbah = readb(ap->ioaddr.lbah_addr);
1993 tf.lbam = readb(ap->ioaddr.lbam_addr);
1994 tf.lbal = readb(ap->ioaddr.lbal_addr);
1995 tf.nsect = readb(ap->ioaddr.nsect_addr);
Brett Russ20f733e2005-09-01 18:26:17 -04001996
1997 dev->class = ata_dev_classify(&tf);
Tejun Heoe1211e32006-04-01 01:38:18 +09001998 if (!ata_dev_enabled(dev)) {
Brett Russ20f733e2005-09-01 18:26:17 -04001999 VPRINTK("Port disabled post-sig: No device present.\n");
2000 ata_port_disable(ap);
2001 }
Jeff Garzik095fec82005-11-12 09:50:49 -05002002
2003 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
2004
2005 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
2006
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002007 VPRINTK("EXIT\n");
Brett Russ20f733e2005-09-01 18:26:17 -04002008}
2009
Jeff Garzik22374672005-11-17 10:59:48 -05002010static void mv_phy_reset(struct ata_port *ap)
2011{
2012 __mv_phy_reset(ap, 1);
2013}
2014
Brett Russ05b308e2005-10-05 17:08:53 -04002015/**
2016 * mv_eng_timeout - Routine called by libata when SCSI times out I/O
2017 * @ap: ATA channel to manipulate
2018 *
2019 * Intent is to clear all pending error conditions, reset the
2020 * chip/bus, fail the command, and move on.
2021 *
2022 * LOCKING:
Jeff Garzikcca39742006-08-24 03:19:22 -04002023 * This routine holds the host lock while failing the command.
Brett Russ05b308e2005-10-05 17:08:53 -04002024 */
Brett Russ31961942005-09-30 01:36:00 -04002025static void mv_eng_timeout(struct ata_port *ap)
Brett Russ20f733e2005-09-01 18:26:17 -04002026{
Tejun Heo0d5ff562007-02-01 15:06:36 +09002027 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
Brett Russ31961942005-09-30 01:36:00 -04002028 struct ata_queued_cmd *qc;
Mark Lord2f9719b2006-06-07 12:53:29 -04002029 unsigned long flags;
Brett Russ31961942005-09-30 01:36:00 -04002030
Tejun Heof15a1da2006-05-15 20:57:56 +09002031 ata_port_printk(ap, KERN_ERR, "Entering mv_eng_timeout\n");
Brett Russ31961942005-09-30 01:36:00 -04002032 DPRINTK("All regs @ start of eng_timeout\n");
Tejun Heo0d5ff562007-02-01 15:06:36 +09002033 mv_dump_all_regs(mmio, ap->port_no, to_pci_dev(ap->host->dev));
Brett Russ31961942005-09-30 01:36:00 -04002034
2035 qc = ata_qc_from_tag(ap, ap->active_tag);
2036 printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n",
Tejun Heo0d5ff562007-02-01 15:06:36 +09002037 mmio, ap, qc, qc->scsicmd, &qc->scsicmd->cmnd);
Brett Russ31961942005-09-30 01:36:00 -04002038
Jeff Garzikcca39742006-08-24 03:19:22 -04002039 spin_lock_irqsave(&ap->host->lock, flags);
Mark Lord9b358e32006-05-19 16:21:03 -04002040 mv_err_intr(ap, 0);
Jeff Garzikc9d39132005-11-13 17:47:51 -05002041 mv_stop_and_reset(ap);
Jeff Garzikcca39742006-08-24 03:19:22 -04002042 spin_unlock_irqrestore(&ap->host->lock, flags);
Brett Russ31961942005-09-30 01:36:00 -04002043
Mark Lord9b358e32006-05-19 16:21:03 -04002044 WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE));
2045 if (qc->flags & ATA_QCFLAG_ACTIVE) {
2046 qc->err_mask |= AC_ERR_TIMEOUT;
2047 ata_eh_qc_complete(qc);
2048 }
Brett Russ31961942005-09-30 01:36:00 -04002049}
2050
Brett Russ05b308e2005-10-05 17:08:53 -04002051/**
2052 * mv_port_init - Perform some early initialization on a single port.
2053 * @port: libata data structure storing shadow register addresses
2054 * @port_mmio: base address of the port
2055 *
2056 * Initialize shadow register mmio addresses, clear outstanding
2057 * interrupts on the port, and unmask interrupts for the future
2058 * start of the port.
2059 *
2060 * LOCKING:
2061 * Inherited from caller.
2062 */
Brett Russ31961942005-09-30 01:36:00 -04002063static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio)
2064{
Tejun Heo0d5ff562007-02-01 15:06:36 +09002065 void __iomem *shd_base = port_mmio + SHD_BLK_OFS;
Brett Russ31961942005-09-30 01:36:00 -04002066 unsigned serr_ofs;
2067
Jeff Garzik8b260242005-11-12 12:32:50 -05002068 /* PIO related setup
Brett Russ31961942005-09-30 01:36:00 -04002069 */
2070 port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA);
Jeff Garzik8b260242005-11-12 12:32:50 -05002071 port->error_addr =
Brett Russ31961942005-09-30 01:36:00 -04002072 port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR);
2073 port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT);
2074 port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL);
2075 port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM);
2076 port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH);
2077 port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE);
Jeff Garzik8b260242005-11-12 12:32:50 -05002078 port->status_addr =
Brett Russ31961942005-09-30 01:36:00 -04002079 port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS);
2080 /* special case: control/altstatus doesn't have ATA_REG_ address */
2081 port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS;
2082
2083 /* unused: */
Randy Dunlap8d9db2d2007-02-16 01:40:06 -08002084 port->cmd_addr = port->bmdma_addr = port->scr_addr = NULL;
Brett Russ20f733e2005-09-01 18:26:17 -04002085
Brett Russ31961942005-09-30 01:36:00 -04002086 /* Clear any currently outstanding port interrupt conditions */
2087 serr_ofs = mv_scr_offset(SCR_ERROR);
2088 writelfl(readl(port_mmio + serr_ofs), port_mmio + serr_ofs);
2089 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
2090
Brett Russ20f733e2005-09-01 18:26:17 -04002091 /* unmask all EDMA error interrupts */
Brett Russ31961942005-09-30 01:36:00 -04002092 writelfl(~0, port_mmio + EDMA_ERR_IRQ_MASK_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04002093
Jeff Garzik8b260242005-11-12 12:32:50 -05002094 VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n",
Brett Russ31961942005-09-30 01:36:00 -04002095 readl(port_mmio + EDMA_CFG_OFS),
2096 readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS),
2097 readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS));
Brett Russ20f733e2005-09-01 18:26:17 -04002098}
2099
Jeff Garzik47c2b672005-11-12 21:13:17 -05002100static int mv_chip_id(struct pci_dev *pdev, struct mv_host_priv *hpriv,
Jeff Garzik522479f2005-11-12 22:14:02 -05002101 unsigned int board_idx)
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002102{
2103 u8 rev_id;
2104 u32 hp_flags = hpriv->hp_flags;
2105
2106 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
2107
2108 switch(board_idx) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05002109 case chip_5080:
2110 hpriv->ops = &mv5xxx_ops;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002111 hp_flags |= MV_HP_50XX;
2112
Jeff Garzik47c2b672005-11-12 21:13:17 -05002113 switch (rev_id) {
2114 case 0x1:
2115 hp_flags |= MV_HP_ERRATA_50XXB0;
2116 break;
2117 case 0x3:
2118 hp_flags |= MV_HP_ERRATA_50XXB2;
2119 break;
2120 default:
2121 dev_printk(KERN_WARNING, &pdev->dev,
2122 "Applying 50XXB2 workarounds to unknown rev\n");
2123 hp_flags |= MV_HP_ERRATA_50XXB2;
2124 break;
2125 }
2126 break;
2127
2128 case chip_504x:
2129 case chip_508x:
2130 hpriv->ops = &mv5xxx_ops;
2131 hp_flags |= MV_HP_50XX;
2132
2133 switch (rev_id) {
2134 case 0x0:
2135 hp_flags |= MV_HP_ERRATA_50XXB0;
2136 break;
2137 case 0x3:
2138 hp_flags |= MV_HP_ERRATA_50XXB2;
2139 break;
2140 default:
2141 dev_printk(KERN_WARNING, &pdev->dev,
2142 "Applying B2 workarounds to unknown rev\n");
2143 hp_flags |= MV_HP_ERRATA_50XXB2;
2144 break;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002145 }
2146 break;
2147
2148 case chip_604x:
2149 case chip_608x:
Jeff Garzik47c2b672005-11-12 21:13:17 -05002150 hpriv->ops = &mv6xxx_ops;
2151
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002152 switch (rev_id) {
Jeff Garzik47c2b672005-11-12 21:13:17 -05002153 case 0x7:
2154 hp_flags |= MV_HP_ERRATA_60X1B2;
2155 break;
2156 case 0x9:
2157 hp_flags |= MV_HP_ERRATA_60X1C0;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002158 break;
2159 default:
2160 dev_printk(KERN_WARNING, &pdev->dev,
Jeff Garzik47c2b672005-11-12 21:13:17 -05002161 "Applying B2 workarounds to unknown rev\n");
2162 hp_flags |= MV_HP_ERRATA_60X1B2;
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002163 break;
2164 }
2165 break;
2166
Jeff Garzike4e7b892006-01-31 12:18:41 -05002167 case chip_7042:
2168 case chip_6042:
2169 hpriv->ops = &mv6xxx_ops;
2170
2171 hp_flags |= MV_HP_GEN_IIE;
2172
2173 switch (rev_id) {
2174 case 0x0:
2175 hp_flags |= MV_HP_ERRATA_XX42A0;
2176 break;
2177 case 0x1:
2178 hp_flags |= MV_HP_ERRATA_60X1C0;
2179 break;
2180 default:
2181 dev_printk(KERN_WARNING, &pdev->dev,
2182 "Applying 60X1C0 workarounds to unknown rev\n");
2183 hp_flags |= MV_HP_ERRATA_60X1C0;
2184 break;
2185 }
2186 break;
2187
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002188 default:
2189 printk(KERN_ERR DRV_NAME ": BUG: invalid board index %u\n", board_idx);
2190 return 1;
2191 }
2192
2193 hpriv->hp_flags = hp_flags;
2194
2195 return 0;
2196}
2197
Brett Russ05b308e2005-10-05 17:08:53 -04002198/**
Jeff Garzik47c2b672005-11-12 21:13:17 -05002199 * mv_init_host - Perform some early initialization of the host.
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002200 * @pdev: host PCI device
Brett Russ05b308e2005-10-05 17:08:53 -04002201 * @probe_ent: early data struct representing the host
2202 *
2203 * If possible, do an early global reset of the host. Then do
2204 * our port init and clear/unmask all/relevant host interrupts.
2205 *
2206 * LOCKING:
2207 * Inherited from caller.
2208 */
Jeff Garzik47c2b672005-11-12 21:13:17 -05002209static int mv_init_host(struct pci_dev *pdev, struct ata_probe_ent *probe_ent,
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002210 unsigned int board_idx)
Brett Russ20f733e2005-09-01 18:26:17 -04002211{
2212 int rc = 0, n_hc, port, hc;
Tejun Heo0d5ff562007-02-01 15:06:36 +09002213 void __iomem *mmio = probe_ent->iomap[MV_PRIMARY_BAR];
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002214 struct mv_host_priv *hpriv = probe_ent->private_data;
2215
Jeff Garzik47c2b672005-11-12 21:13:17 -05002216 /* global interrupt mask */
2217 writel(0, mmio + HC_MAIN_IRQ_MASK_OFS);
2218
2219 rc = mv_chip_id(pdev, hpriv, board_idx);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002220 if (rc)
2221 goto done;
2222
Jeff Garzikcca39742006-08-24 03:19:22 -04002223 n_hc = mv_get_hc_count(probe_ent->port_flags);
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002224 probe_ent->n_ports = MV_PORTS_PER_HC * n_hc;
2225
Jeff Garzik47c2b672005-11-12 21:13:17 -05002226 for (port = 0; port < probe_ent->n_ports; port++)
2227 hpriv->ops->read_preamp(hpriv, port, mmio);
Brett Russ20f733e2005-09-01 18:26:17 -04002228
Jeff Garzikc9d39132005-11-13 17:47:51 -05002229 rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc);
Jeff Garzik47c2b672005-11-12 21:13:17 -05002230 if (rc)
Brett Russ20f733e2005-09-01 18:26:17 -04002231 goto done;
Brett Russ20f733e2005-09-01 18:26:17 -04002232
Jeff Garzik522479f2005-11-12 22:14:02 -05002233 hpriv->ops->reset_flash(hpriv, mmio);
2234 hpriv->ops->reset_bus(pdev, mmio);
Jeff Garzik47c2b672005-11-12 21:13:17 -05002235 hpriv->ops->enable_leds(hpriv, mmio);
Brett Russ20f733e2005-09-01 18:26:17 -04002236
2237 for (port = 0; port < probe_ent->n_ports; port++) {
Jeff Garzik2a47ce02005-11-12 23:05:14 -05002238 if (IS_60XX(hpriv)) {
Jeff Garzikc9d39132005-11-13 17:47:51 -05002239 void __iomem *port_mmio = mv_port_base(mmio, port);
2240
Jeff Garzik2a47ce02005-11-12 23:05:14 -05002241 u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL);
Mark Lordeb46d682006-05-19 16:29:21 -04002242 ifctl |= (1 << 7); /* enable gen2i speed */
2243 ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */
Jeff Garzik2a47ce02005-11-12 23:05:14 -05002244 writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL);
2245 }
2246
Jeff Garzikc9d39132005-11-13 17:47:51 -05002247 hpriv->ops->phy_errata(hpriv, mmio, port);
Jeff Garzik2a47ce02005-11-12 23:05:14 -05002248 }
2249
2250 for (port = 0; port < probe_ent->n_ports; port++) {
2251 void __iomem *port_mmio = mv_port_base(mmio, port);
Brett Russ31961942005-09-30 01:36:00 -04002252 mv_port_init(&probe_ent->port[port], port_mmio);
Brett Russ20f733e2005-09-01 18:26:17 -04002253 }
2254
2255 for (hc = 0; hc < n_hc; hc++) {
Brett Russ31961942005-09-30 01:36:00 -04002256 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
2257
2258 VPRINTK("HC%i: HC config=0x%08x HC IRQ cause "
2259 "(before clear)=0x%08x\n", hc,
2260 readl(hc_mmio + HC_CFG_OFS),
2261 readl(hc_mmio + HC_IRQ_CAUSE_OFS));
2262
2263 /* Clear any currently outstanding hc interrupt conditions */
2264 writelfl(0, hc_mmio + HC_IRQ_CAUSE_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04002265 }
2266
Brett Russ31961942005-09-30 01:36:00 -04002267 /* Clear any currently outstanding host interrupt conditions */
2268 writelfl(0, mmio + PCI_IRQ_CAUSE_OFS);
2269
2270 /* and unmask interrupt generation for host regs */
2271 writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS);
Jeff Garzikfb621e22007-02-25 04:19:45 -05002272
2273 if (IS_50XX(hpriv))
2274 writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS);
2275 else
2276 writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS);
Brett Russ20f733e2005-09-01 18:26:17 -04002277
2278 VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x "
Jeff Garzik8b260242005-11-12 12:32:50 -05002279 "PCI int cause/mask=0x%08x/0x%08x\n",
Brett Russ20f733e2005-09-01 18:26:17 -04002280 readl(mmio + HC_MAIN_IRQ_CAUSE_OFS),
2281 readl(mmio + HC_MAIN_IRQ_MASK_OFS),
2282 readl(mmio + PCI_IRQ_CAUSE_OFS),
2283 readl(mmio + PCI_IRQ_MASK_OFS));
Jeff Garzikbca1c4e2005-11-12 12:48:15 -05002284
Brett Russ31961942005-09-30 01:36:00 -04002285done:
Brett Russ20f733e2005-09-01 18:26:17 -04002286 return rc;
2287}
2288
Brett Russ05b308e2005-10-05 17:08:53 -04002289/**
2290 * mv_print_info - Dump key info to kernel log for perusal.
2291 * @probe_ent: early data struct representing the host
2292 *
2293 * FIXME: complete this.
2294 *
2295 * LOCKING:
2296 * Inherited from caller.
2297 */
Brett Russ31961942005-09-30 01:36:00 -04002298static void mv_print_info(struct ata_probe_ent *probe_ent)
2299{
2300 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
2301 struct mv_host_priv *hpriv = probe_ent->private_data;
2302 u8 rev_id, scc;
2303 const char *scc_s;
2304
2305 /* Use this to determine the HW stepping of the chip so we know
2306 * what errata to workaround
2307 */
2308 pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id);
2309
2310 pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &scc);
2311 if (scc == 0)
2312 scc_s = "SCSI";
2313 else if (scc == 0x01)
2314 scc_s = "RAID";
2315 else
2316 scc_s = "unknown";
2317
Jeff Garzika9524a72005-10-30 14:39:11 -05002318 dev_printk(KERN_INFO, &pdev->dev,
2319 "%u slots %u ports %s mode IRQ via %s\n",
Jeff Garzik8b260242005-11-12 12:32:50 -05002320 (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports,
Brett Russ31961942005-09-30 01:36:00 -04002321 scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx");
2322}
2323
Brett Russ05b308e2005-10-05 17:08:53 -04002324/**
2325 * mv_init_one - handle a positive probe of a Marvell host
2326 * @pdev: PCI device found
2327 * @ent: PCI device ID entry for the matched host
2328 *
2329 * LOCKING:
2330 * Inherited from caller.
2331 */
Brett Russ20f733e2005-09-01 18:26:17 -04002332static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2333{
2334 static int printed_version = 0;
Tejun Heo24dc5f32007-01-20 16:00:28 +09002335 struct device *dev = &pdev->dev;
2336 struct ata_probe_ent *probe_ent;
Brett Russ20f733e2005-09-01 18:26:17 -04002337 struct mv_host_priv *hpriv;
2338 unsigned int board_idx = (unsigned int)ent->driver_data;
Tejun Heo24dc5f32007-01-20 16:00:28 +09002339 int rc;
Brett Russ20f733e2005-09-01 18:26:17 -04002340
Jeff Garzika9524a72005-10-30 14:39:11 -05002341 if (!printed_version++)
2342 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
Brett Russ20f733e2005-09-01 18:26:17 -04002343
Tejun Heo24dc5f32007-01-20 16:00:28 +09002344 rc = pcim_enable_device(pdev);
2345 if (rc)
Brett Russ20f733e2005-09-01 18:26:17 -04002346 return rc;
Mark Lordeb46d682006-05-19 16:29:21 -04002347 pci_set_master(pdev);
Brett Russ20f733e2005-09-01 18:26:17 -04002348
Tejun Heo0d5ff562007-02-01 15:06:36 +09002349 rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME);
2350 if (rc == -EBUSY)
Tejun Heo24dc5f32007-01-20 16:00:28 +09002351 pcim_pin_device(pdev);
Tejun Heo0d5ff562007-02-01 15:06:36 +09002352 if (rc)
Tejun Heo24dc5f32007-01-20 16:00:28 +09002353 return rc;
Brett Russ20f733e2005-09-01 18:26:17 -04002354
Jeff Garzikd88184f2007-02-26 01:26:06 -05002355 rc = pci_go_64(pdev);
2356 if (rc)
2357 return rc;
2358
Tejun Heo24dc5f32007-01-20 16:00:28 +09002359 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
2360 if (probe_ent == NULL)
2361 return -ENOMEM;
Brett Russ20f733e2005-09-01 18:26:17 -04002362
Brett Russ20f733e2005-09-01 18:26:17 -04002363 probe_ent->dev = pci_dev_to_dev(pdev);
2364 INIT_LIST_HEAD(&probe_ent->node);
2365
Tejun Heo24dc5f32007-01-20 16:00:28 +09002366 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
2367 if (!hpriv)
2368 return -ENOMEM;
Brett Russ20f733e2005-09-01 18:26:17 -04002369
2370 probe_ent->sht = mv_port_info[board_idx].sht;
Jeff Garzikcca39742006-08-24 03:19:22 -04002371 probe_ent->port_flags = mv_port_info[board_idx].flags;
Brett Russ20f733e2005-09-01 18:26:17 -04002372 probe_ent->pio_mask = mv_port_info[board_idx].pio_mask;
2373 probe_ent->udma_mask = mv_port_info[board_idx].udma_mask;
2374 probe_ent->port_ops = mv_port_info[board_idx].port_ops;
2375
2376 probe_ent->irq = pdev->irq;
Thomas Gleixner1d6f3592006-07-01 19:29:42 -07002377 probe_ent->irq_flags = IRQF_SHARED;
Tejun Heo0d5ff562007-02-01 15:06:36 +09002378 probe_ent->iomap = pcim_iomap_table(pdev);
Brett Russ20f733e2005-09-01 18:26:17 -04002379 probe_ent->private_data = hpriv;
2380
2381 /* initialize adapter */
Jeff Garzik47c2b672005-11-12 21:13:17 -05002382 rc = mv_init_host(pdev, probe_ent, board_idx);
Tejun Heo24dc5f32007-01-20 16:00:28 +09002383 if (rc)
2384 return rc;
Brett Russ20f733e2005-09-01 18:26:17 -04002385
Brett Russ31961942005-09-30 01:36:00 -04002386 /* Enable interrupts */
Tejun Heo6a59dcf2007-02-24 15:12:31 +09002387 if (msi && pci_enable_msi(pdev))
Brett Russ31961942005-09-30 01:36:00 -04002388 pci_intx(pdev, 1);
Brett Russ20f733e2005-09-01 18:26:17 -04002389
Brett Russ31961942005-09-30 01:36:00 -04002390 mv_dump_pci_cfg(pdev, 0x68);
2391 mv_print_info(probe_ent);
Brett Russ20f733e2005-09-01 18:26:17 -04002392
Tejun Heo24dc5f32007-01-20 16:00:28 +09002393 if (ata_device_add(probe_ent) == 0)
2394 return -ENODEV;
Brett Russ31961942005-09-30 01:36:00 -04002395
Tejun Heo24dc5f32007-01-20 16:00:28 +09002396 devm_kfree(dev, probe_ent);
Brett Russ20f733e2005-09-01 18:26:17 -04002397 return 0;
Brett Russ20f733e2005-09-01 18:26:17 -04002398}
2399
2400static int __init mv_init(void)
2401{
Pavel Roskinb7887192006-08-10 18:13:18 +09002402 return pci_register_driver(&mv_pci_driver);
Brett Russ20f733e2005-09-01 18:26:17 -04002403}
2404
2405static void __exit mv_exit(void)
2406{
2407 pci_unregister_driver(&mv_pci_driver);
2408}
2409
2410MODULE_AUTHOR("Brett Russ");
2411MODULE_DESCRIPTION("SCSI low-level driver for Marvell SATA controllers");
2412MODULE_LICENSE("GPL");
2413MODULE_DEVICE_TABLE(pci, mv_pci_tbl);
2414MODULE_VERSION(DRV_VERSION);
2415
Jeff Garzikddef9bb2006-02-02 16:17:06 -05002416module_param(msi, int, 0444);
2417MODULE_PARM_DESC(msi, "Enable use of PCI MSI (0=off, 1=on)");
2418
Brett Russ20f733e2005-09-01 18:26:17 -04002419module_init(mv_init);
2420module_exit(mv_exit);