diff options
author | Jeff Garzik <jgarzik@pobox.com> | 2005-11-17 11:16:39 -0500 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-11-17 11:16:39 -0500 |
commit | 67cb6e842e7f1e534a5e0e8708a8779e33b60520 (patch) | |
tree | 1c887edd39fddb9016949976fea48f7ca22bae4b /drivers/scsi | |
parent | 8bb6030b62a70edc0cb8129338f83e9063aeaf92 (diff) | |
parent | a2c91a8819e315e9fd1aef3ff57badb6c1be3f80 (diff) |
Merge branch 'upstream-fixes'
Diffstat (limited to 'drivers/scsi')
-rw-r--r-- | drivers/scsi/Kconfig | 2 | ||||
-rw-r--r-- | drivers/scsi/libata-core.c | 32 | ||||
-rw-r--r-- | drivers/scsi/sata_mv.c | 991 |
3 files changed, 851 insertions, 174 deletions
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index 84c42c44e04d..20dd85a77813 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig | |||
@@ -497,7 +497,7 @@ config SCSI_ATA_PIIX | |||
497 | If unsure, say N. | 497 | If unsure, say N. |
498 | 498 | ||
499 | config SCSI_SATA_MV | 499 | config SCSI_SATA_MV |
500 | tristate "Marvell SATA support" | 500 | tristate "Marvell SATA support (HIGHLY EXPERIMENTAL)" |
501 | depends on SCSI_SATA && PCI && EXPERIMENTAL | 501 | depends on SCSI_SATA && PCI && EXPERIMENTAL |
502 | help | 502 | help |
503 | This option enables support for the Marvell Serial ATA family. | 503 | This option enables support for the Marvell Serial ATA family. |
diff --git a/drivers/scsi/libata-core.c b/drivers/scsi/libata-core.c index bb604dfbdef6..665ae79e1fd6 100644 --- a/drivers/scsi/libata-core.c +++ b/drivers/scsi/libata-core.c | |||
@@ -1046,6 +1046,30 @@ static unsigned int ata_pio_modes(const struct ata_device *adev) | |||
1046 | return modes; | 1046 | return modes; |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | static int ata_qc_wait_err(struct ata_queued_cmd *qc, | ||
1050 | struct completion *wait) | ||
1051 | { | ||
1052 | int rc = 0; | ||
1053 | |||
1054 | if (wait_for_completion_timeout(wait, 30 * HZ) < 1) { | ||
1055 | /* timeout handling */ | ||
1056 | unsigned int err_mask = ac_err_mask(ata_chk_status(qc->ap)); | ||
1057 | |||
1058 | if (!err_mask) { | ||
1059 | printk(KERN_WARNING "ata%u: slow completion (cmd %x)\n", | ||
1060 | qc->ap->id, qc->tf.command); | ||
1061 | } else { | ||
1062 | printk(KERN_WARNING "ata%u: qc timeout (cmd %x)\n", | ||
1063 | qc->ap->id, qc->tf.command); | ||
1064 | rc = -EIO; | ||
1065 | } | ||
1066 | |||
1067 | ata_qc_complete(qc, err_mask); | ||
1068 | } | ||
1069 | |||
1070 | return rc; | ||
1071 | } | ||
1072 | |||
1049 | /** | 1073 | /** |
1050 | * ata_dev_identify - obtain IDENTIFY x DEVICE page | 1074 | * ata_dev_identify - obtain IDENTIFY x DEVICE page |
1051 | * @ap: port on which device we wish to probe resides | 1075 | * @ap: port on which device we wish to probe resides |
@@ -1125,7 +1149,7 @@ retry: | |||
1125 | if (rc) | 1149 | if (rc) |
1126 | goto err_out; | 1150 | goto err_out; |
1127 | else | 1151 | else |
1128 | wait_for_completion(&wait); | 1152 | ata_qc_wait_err(qc, &wait); |
1129 | 1153 | ||
1130 | spin_lock_irqsave(&ap->host_set->lock, flags); | 1154 | spin_lock_irqsave(&ap->host_set->lock, flags); |
1131 | ap->ops->tf_read(ap, &qc->tf); | 1155 | ap->ops->tf_read(ap, &qc->tf); |
@@ -2269,7 +2293,7 @@ static void ata_dev_set_xfermode(struct ata_port *ap, struct ata_device *dev) | |||
2269 | if (rc) | 2293 | if (rc) |
2270 | ata_port_disable(ap); | 2294 | ata_port_disable(ap); |
2271 | else | 2295 | else |
2272 | wait_for_completion(&wait); | 2296 | ata_qc_wait_err(qc, &wait); |
2273 | 2297 | ||
2274 | DPRINTK("EXIT\n"); | 2298 | DPRINTK("EXIT\n"); |
2275 | } | 2299 | } |
@@ -2317,7 +2341,7 @@ static void ata_dev_reread_id(struct ata_port *ap, struct ata_device *dev) | |||
2317 | if (rc) | 2341 | if (rc) |
2318 | goto err_out; | 2342 | goto err_out; |
2319 | 2343 | ||
2320 | wait_for_completion(&wait); | 2344 | ata_qc_wait_err(qc, &wait); |
2321 | 2345 | ||
2322 | swap_buf_le16(dev->id, ATA_ID_WORDS); | 2346 | swap_buf_le16(dev->id, ATA_ID_WORDS); |
2323 | 2347 | ||
@@ -2373,7 +2397,7 @@ static void ata_dev_init_params(struct ata_port *ap, struct ata_device *dev) | |||
2373 | if (rc) | 2397 | if (rc) |
2374 | ata_port_disable(ap); | 2398 | ata_port_disable(ap); |
2375 | else | 2399 | else |
2376 | wait_for_completion(&wait); | 2400 | ata_qc_wait_err(qc, &wait); |
2377 | 2401 | ||
2378 | DPRINTK("EXIT\n"); | 2402 | DPRINTK("EXIT\n"); |
2379 | } | 2403 | } |
diff --git a/drivers/scsi/sata_mv.c b/drivers/scsi/sata_mv.c index 257c128f4aaa..ac184e60797e 100644 --- a/drivers/scsi/sata_mv.c +++ b/drivers/scsi/sata_mv.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * sata_mv.c - Marvell SATA support | 2 | * sata_mv.c - Marvell SATA support |
3 | * | 3 | * |
4 | * Copyright 2005: EMC Corporation, all rights reserved. | 4 | * Copyright 2005: EMC Corporation, all rights reserved. |
5 | * | 5 | * |
6 | * Please ALWAYS copy linux-ide@vger.kernel.org on emails. | 6 | * Please ALWAYS copy linux-ide@vger.kernel.org on emails. |
7 | * | 7 | * |
@@ -50,6 +50,9 @@ enum { | |||
50 | MV_PCI_REG_BASE = 0, | 50 | MV_PCI_REG_BASE = 0, |
51 | MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */ | 51 | MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */ |
52 | MV_SATAHC0_REG_BASE = 0x20000, | 52 | MV_SATAHC0_REG_BASE = 0x20000, |
53 | MV_FLASH_CTL = 0x1046c, | ||
54 | MV_GPIO_PORT_CTL = 0x104f0, | ||
55 | MV_RESET_CFG = 0x180d8, | ||
53 | 56 | ||
54 | MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ, | 57 | MV_PCI_REG_SZ = MV_MAJOR_REG_AREA_SZ, |
55 | MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ, | 58 | MV_SATAHC_REG_SZ = MV_MAJOR_REG_AREA_SZ, |
@@ -72,11 +75,6 @@ enum { | |||
72 | MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT), | 75 | MV_SG_TBL_SZ = (16 * MV_MAX_SG_CT), |
73 | MV_PORT_PRIV_DMA_SZ = (MV_CRQB_Q_SZ + MV_CRPB_Q_SZ + MV_SG_TBL_SZ), | 76 | MV_PORT_PRIV_DMA_SZ = (MV_CRQB_Q_SZ + MV_CRPB_Q_SZ + MV_SG_TBL_SZ), |
74 | 77 | ||
75 | /* Our DMA boundary is determined by an ePRD being unable to handle | ||
76 | * anything larger than 64KB | ||
77 | */ | ||
78 | MV_DMA_BOUNDARY = 0xffffU, | ||
79 | |||
80 | MV_PORTS_PER_HC = 4, | 78 | MV_PORTS_PER_HC = 4, |
81 | /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */ | 79 | /* == (port / MV_PORTS_PER_HC) to determine HC from 0-7 port */ |
82 | MV_PORT_HC_SHIFT = 2, | 80 | MV_PORT_HC_SHIFT = 2, |
@@ -86,16 +84,9 @@ enum { | |||
86 | /* Host Flags */ | 84 | /* Host Flags */ |
87 | MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ | 85 | MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ |
88 | MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */ | 86 | MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */ |
89 | MV_FLAG_GLBL_SFT_RST = (1 << 28), /* Global Soft Reset support */ | ||
90 | MV_COMMON_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | | 87 | MV_COMMON_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | |
91 | ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO), | 88 | ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO), |
92 | MV_6XXX_FLAGS = (MV_FLAG_IRQ_COALESCE | | 89 | MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE, |
93 | MV_FLAG_GLBL_SFT_RST), | ||
94 | |||
95 | chip_504x = 0, | ||
96 | chip_508x = 1, | ||
97 | chip_604x = 2, | ||
98 | chip_608x = 3, | ||
99 | 90 | ||
100 | CRQB_FLAG_READ = (1 << 0), | 91 | CRQB_FLAG_READ = (1 << 0), |
101 | CRQB_TAG_SHIFT = 1, | 92 | CRQB_TAG_SHIFT = 1, |
@@ -116,8 +107,19 @@ enum { | |||
116 | PCI_MASTER_EMPTY = (1 << 3), | 107 | PCI_MASTER_EMPTY = (1 << 3), |
117 | GLOB_SFT_RST = (1 << 4), | 108 | GLOB_SFT_RST = (1 << 4), |
118 | 109 | ||
119 | PCI_IRQ_CAUSE_OFS = 0x1d58, | 110 | MV_PCI_MODE = 0xd00, |
120 | PCI_IRQ_MASK_OFS = 0x1d5c, | 111 | MV_PCI_EXP_ROM_BAR_CTL = 0xd2c, |
112 | MV_PCI_DISC_TIMER = 0xd04, | ||
113 | MV_PCI_MSI_TRIGGER = 0xc38, | ||
114 | MV_PCI_SERR_MASK = 0xc28, | ||
115 | MV_PCI_XBAR_TMOUT = 0x1d04, | ||
116 | MV_PCI_ERR_LOW_ADDRESS = 0x1d40, | ||
117 | MV_PCI_ERR_HIGH_ADDRESS = 0x1d44, | ||
118 | MV_PCI_ERR_ATTRIBUTE = 0x1d48, | ||
119 | MV_PCI_ERR_COMMAND = 0x1d50, | ||
120 | |||
121 | PCI_IRQ_CAUSE_OFS = 0x1d58, | ||
122 | PCI_IRQ_MASK_OFS = 0x1d5c, | ||
121 | PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */ | 123 | PCI_UNMASK_ALL_IRQS = 0x7fffff, /* bits 22-0 */ |
122 | 124 | ||
123 | HC_MAIN_IRQ_CAUSE_OFS = 0x1d60, | 125 | HC_MAIN_IRQ_CAUSE_OFS = 0x1d60, |
@@ -134,7 +136,7 @@ enum { | |||
134 | SELF_INT = (1 << 23), | 136 | SELF_INT = (1 << 23), |
135 | TWSI_INT = (1 << 24), | 137 | TWSI_INT = (1 << 24), |
136 | HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */ | 138 | HC_MAIN_RSVD = (0x7f << 25), /* bits 31-25 */ |
137 | HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE | | 139 | HC_MAIN_MASKED_IRQS = (TRAN_LO_DONE | TRAN_HI_DONE | |
138 | PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT | | 140 | PORTS_0_7_COAL_DONE | GPIO_INT | TWSI_INT | |
139 | HC_MAIN_RSVD), | 141 | HC_MAIN_RSVD), |
140 | 142 | ||
@@ -153,6 +155,15 @@ enum { | |||
153 | /* SATA registers */ | 155 | /* SATA registers */ |
154 | SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */ | 156 | SATA_STATUS_OFS = 0x300, /* ctrl, err regs follow status */ |
155 | SATA_ACTIVE_OFS = 0x350, | 157 | SATA_ACTIVE_OFS = 0x350, |
158 | PHY_MODE3 = 0x310, | ||
159 | PHY_MODE4 = 0x314, | ||
160 | PHY_MODE2 = 0x330, | ||
161 | MV5_PHY_MODE = 0x74, | ||
162 | MV5_LT_MODE = 0x30, | ||
163 | MV5_PHY_CTL = 0x0C, | ||
164 | SATA_INTERFACE_CTL = 0x050, | ||
165 | |||
166 | MV_M2_PREAMP_MASK = 0x7e0, | ||
156 | 167 | ||
157 | /* Port registers */ | 168 | /* Port registers */ |
158 | EDMA_CFG_OFS = 0, | 169 | EDMA_CFG_OFS = 0, |
@@ -182,17 +193,16 @@ enum { | |||
182 | EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), | 193 | EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), |
183 | EDMA_ERR_LNK_DATA_TX = (0x1f << 26), | 194 | EDMA_ERR_LNK_DATA_TX = (0x1f << 26), |
184 | EDMA_ERR_TRANS_PROTO = (1 << 31), | 195 | EDMA_ERR_TRANS_PROTO = (1 << 31), |
185 | EDMA_ERR_FATAL = (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | | 196 | EDMA_ERR_FATAL = (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | |
186 | EDMA_ERR_DEV_DCON | EDMA_ERR_CRBQ_PAR | | 197 | EDMA_ERR_DEV_DCON | EDMA_ERR_CRBQ_PAR | |
187 | EDMA_ERR_CRPB_PAR | EDMA_ERR_INTRL_PAR | | 198 | EDMA_ERR_CRPB_PAR | EDMA_ERR_INTRL_PAR | |
188 | EDMA_ERR_IORDY | EDMA_ERR_LNK_CTRL_RX_2 | | 199 | EDMA_ERR_IORDY | EDMA_ERR_LNK_CTRL_RX_2 | |
189 | EDMA_ERR_LNK_DATA_RX | | 200 | EDMA_ERR_LNK_DATA_RX | |
190 | EDMA_ERR_LNK_DATA_TX | | 201 | EDMA_ERR_LNK_DATA_TX | |
191 | EDMA_ERR_TRANS_PROTO), | 202 | EDMA_ERR_TRANS_PROTO), |
192 | 203 | ||
193 | EDMA_REQ_Q_BASE_HI_OFS = 0x10, | 204 | EDMA_REQ_Q_BASE_HI_OFS = 0x10, |
194 | EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */ | 205 | EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */ |
195 | EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U, | ||
196 | 206 | ||
197 | EDMA_REQ_Q_OUT_PTR_OFS = 0x18, | 207 | EDMA_REQ_Q_OUT_PTR_OFS = 0x18, |
198 | EDMA_REQ_Q_PTR_SHIFT = 5, | 208 | EDMA_REQ_Q_PTR_SHIFT = 5, |
@@ -200,7 +210,6 @@ enum { | |||
200 | EDMA_RSP_Q_BASE_HI_OFS = 0x1c, | 210 | EDMA_RSP_Q_BASE_HI_OFS = 0x1c, |
201 | EDMA_RSP_Q_IN_PTR_OFS = 0x20, | 211 | EDMA_RSP_Q_IN_PTR_OFS = 0x20, |
202 | EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */ | 212 | EDMA_RSP_Q_OUT_PTR_OFS = 0x24, /* also contains BASE_LO */ |
203 | EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U, | ||
204 | EDMA_RSP_Q_PTR_SHIFT = 3, | 213 | EDMA_RSP_Q_PTR_SHIFT = 3, |
205 | 214 | ||
206 | EDMA_CMD_OFS = 0x28, | 215 | EDMA_CMD_OFS = 0x28, |
@@ -208,14 +217,44 @@ enum { | |||
208 | EDMA_DS = (1 << 1), | 217 | EDMA_DS = (1 << 1), |
209 | ATA_RST = (1 << 2), | 218 | ATA_RST = (1 << 2), |
210 | 219 | ||
220 | EDMA_IORDY_TMOUT = 0x34, | ||
221 | EDMA_ARB_CFG = 0x38, | ||
222 | |||
211 | /* Host private flags (hp_flags) */ | 223 | /* Host private flags (hp_flags) */ |
212 | MV_HP_FLAG_MSI = (1 << 0), | 224 | MV_HP_FLAG_MSI = (1 << 0), |
225 | MV_HP_ERRATA_50XXB0 = (1 << 1), | ||
226 | MV_HP_ERRATA_50XXB2 = (1 << 2), | ||
227 | MV_HP_ERRATA_60X1B2 = (1 << 3), | ||
228 | MV_HP_ERRATA_60X1C0 = (1 << 4), | ||
229 | MV_HP_50XX = (1 << 5), | ||
213 | 230 | ||
214 | /* Port private flags (pp_flags) */ | 231 | /* Port private flags (pp_flags) */ |
215 | MV_PP_FLAG_EDMA_EN = (1 << 0), | 232 | MV_PP_FLAG_EDMA_EN = (1 << 0), |
216 | MV_PP_FLAG_EDMA_DS_ACT = (1 << 1), | 233 | MV_PP_FLAG_EDMA_DS_ACT = (1 << 1), |
217 | }; | 234 | }; |
218 | 235 | ||
236 | #define IS_50XX(hpriv) ((hpriv)->hp_flags & MV_HP_50XX) | ||
237 | #define IS_60XX(hpriv) (((hpriv)->hp_flags & MV_HP_50XX) == 0) | ||
238 | |||
239 | enum { | ||
240 | /* Our DMA boundary is determined by an ePRD being unable to handle | ||
241 | * anything larger than 64KB | ||
242 | */ | ||
243 | MV_DMA_BOUNDARY = 0xffffU, | ||
244 | |||
245 | EDMA_REQ_Q_BASE_LO_MASK = 0xfffffc00U, | ||
246 | |||
247 | EDMA_RSP_Q_BASE_LO_MASK = 0xffffff00U, | ||
248 | }; | ||
249 | |||
250 | enum chip_type { | ||
251 | chip_504x, | ||
252 | chip_508x, | ||
253 | chip_5080, | ||
254 | chip_604x, | ||
255 | chip_608x, | ||
256 | }; | ||
257 | |||
219 | /* Command ReQuest Block: 32B */ | 258 | /* Command ReQuest Block: 32B */ |
220 | struct mv_crqb { | 259 | struct mv_crqb { |
221 | u32 sg_addr; | 260 | u32 sg_addr; |
@@ -252,14 +291,37 @@ struct mv_port_priv { | |||
252 | u32 pp_flags; | 291 | u32 pp_flags; |
253 | }; | 292 | }; |
254 | 293 | ||
294 | struct mv_port_signal { | ||
295 | u32 amps; | ||
296 | u32 pre; | ||
297 | }; | ||
298 | |||
299 | struct mv_host_priv; | ||
300 | struct mv_hw_ops { | ||
301 | void (*phy_errata)(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
302 | unsigned int port); | ||
303 | void (*enable_leds)(struct mv_host_priv *hpriv, void __iomem *mmio); | ||
304 | void (*read_preamp)(struct mv_host_priv *hpriv, int idx, | ||
305 | void __iomem *mmio); | ||
306 | int (*reset_hc)(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
307 | unsigned int n_hc); | ||
308 | void (*reset_flash)(struct mv_host_priv *hpriv, void __iomem *mmio); | ||
309 | void (*reset_bus)(struct pci_dev *pdev, void __iomem *mmio); | ||
310 | }; | ||
311 | |||
255 | struct mv_host_priv { | 312 | struct mv_host_priv { |
256 | u32 hp_flags; | 313 | u32 hp_flags; |
314 | struct mv_port_signal signal[8]; | ||
315 | const struct mv_hw_ops *ops; | ||
257 | }; | 316 | }; |
258 | 317 | ||
259 | static void mv_irq_clear(struct ata_port *ap); | 318 | static void mv_irq_clear(struct ata_port *ap); |
260 | static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in); | 319 | static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in); |
261 | static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); | 320 | static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); |
321 | static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in); | ||
322 | static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); | ||
262 | static void mv_phy_reset(struct ata_port *ap); | 323 | static void mv_phy_reset(struct ata_port *ap); |
324 | static void __mv_phy_reset(struct ata_port *ap, int can_sleep); | ||
263 | static void mv_host_stop(struct ata_host_set *host_set); | 325 | static void mv_host_stop(struct ata_host_set *host_set); |
264 | static int mv_port_start(struct ata_port *ap); | 326 | static int mv_port_start(struct ata_port *ap); |
265 | static void mv_port_stop(struct ata_port *ap); | 327 | static void mv_port_stop(struct ata_port *ap); |
@@ -270,6 +332,29 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance, | |||
270 | static void mv_eng_timeout(struct ata_port *ap); | 332 | static void mv_eng_timeout(struct ata_port *ap); |
271 | static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); | 333 | static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); |
272 | 334 | ||
335 | static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
336 | unsigned int port); | ||
337 | static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); | ||
338 | static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, | ||
339 | void __iomem *mmio); | ||
340 | static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
341 | unsigned int n_hc); | ||
342 | static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); | ||
343 | static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio); | ||
344 | |||
345 | static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
346 | unsigned int port); | ||
347 | static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio); | ||
348 | static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, | ||
349 | void __iomem *mmio); | ||
350 | static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
351 | unsigned int n_hc); | ||
352 | static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); | ||
353 | static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio); | ||
354 | static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
355 | unsigned int port_no); | ||
356 | static void mv_stop_and_reset(struct ata_port *ap); | ||
357 | |||
273 | static struct scsi_host_template mv_sht = { | 358 | static struct scsi_host_template mv_sht = { |
274 | .module = THIS_MODULE, | 359 | .module = THIS_MODULE, |
275 | .name = DRV_NAME, | 360 | .name = DRV_NAME, |
@@ -278,7 +363,7 @@ static struct scsi_host_template mv_sht = { | |||
278 | .eh_strategy_handler = ata_scsi_error, | 363 | .eh_strategy_handler = ata_scsi_error, |
279 | .can_queue = MV_USE_Q_DEPTH, | 364 | .can_queue = MV_USE_Q_DEPTH, |
280 | .this_id = ATA_SHT_THIS_ID, | 365 | .this_id = ATA_SHT_THIS_ID, |
281 | .sg_tablesize = MV_MAX_SG_CT, | 366 | .sg_tablesize = MV_MAX_SG_CT / 2, |
282 | .max_sectors = ATA_MAX_SECTORS, | 367 | .max_sectors = ATA_MAX_SECTORS, |
283 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, | 368 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, |
284 | .emulated = ATA_SHT_EMULATED, | 369 | .emulated = ATA_SHT_EMULATED, |
@@ -290,7 +375,34 @@ static struct scsi_host_template mv_sht = { | |||
290 | .ordered_flush = 1, | 375 | .ordered_flush = 1, |
291 | }; | 376 | }; |
292 | 377 | ||
293 | static const struct ata_port_operations mv_ops = { | 378 | static const struct ata_port_operations mv5_ops = { |
379 | .port_disable = ata_port_disable, | ||
380 | |||
381 | .tf_load = ata_tf_load, | ||
382 | .tf_read = ata_tf_read, | ||
383 | .check_status = ata_check_status, | ||
384 | .exec_command = ata_exec_command, | ||
385 | .dev_select = ata_std_dev_select, | ||
386 | |||
387 | .phy_reset = mv_phy_reset, | ||
388 | |||
389 | .qc_prep = mv_qc_prep, | ||
390 | .qc_issue = mv_qc_issue, | ||
391 | |||
392 | .eng_timeout = mv_eng_timeout, | ||
393 | |||
394 | .irq_handler = mv_interrupt, | ||
395 | .irq_clear = mv_irq_clear, | ||
396 | |||
397 | .scr_read = mv5_scr_read, | ||
398 | .scr_write = mv5_scr_write, | ||
399 | |||
400 | .port_start = mv_port_start, | ||
401 | .port_stop = mv_port_stop, | ||
402 | .host_stop = mv_host_stop, | ||
403 | }; | ||
404 | |||
405 | static const struct ata_port_operations mv6_ops = { | ||
294 | .port_disable = ata_port_disable, | 406 | .port_disable = ata_port_disable, |
295 | 407 | ||
296 | .tf_load = ata_tf_load, | 408 | .tf_load = ata_tf_load, |
@@ -322,37 +434,44 @@ static struct ata_port_info mv_port_info[] = { | |||
322 | .sht = &mv_sht, | 434 | .sht = &mv_sht, |
323 | .host_flags = MV_COMMON_FLAGS, | 435 | .host_flags = MV_COMMON_FLAGS, |
324 | .pio_mask = 0x1f, /* pio0-4 */ | 436 | .pio_mask = 0x1f, /* pio0-4 */ |
325 | .udma_mask = 0, /* 0x7f (udma0-6 disabled for now) */ | 437 | .udma_mask = 0x7f, /* udma0-6 */ |
326 | .port_ops = &mv_ops, | 438 | .port_ops = &mv5_ops, |
327 | }, | 439 | }, |
328 | { /* chip_508x */ | 440 | { /* chip_508x */ |
329 | .sht = &mv_sht, | 441 | .sht = &mv_sht, |
330 | .host_flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), | 442 | .host_flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), |
331 | .pio_mask = 0x1f, /* pio0-4 */ | 443 | .pio_mask = 0x1f, /* pio0-4 */ |
332 | .udma_mask = 0, /* 0x7f (udma0-6 disabled for now) */ | 444 | .udma_mask = 0x7f, /* udma0-6 */ |
333 | .port_ops = &mv_ops, | 445 | .port_ops = &mv5_ops, |
446 | }, | ||
447 | { /* chip_5080 */ | ||
448 | .sht = &mv_sht, | ||
449 | .host_flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), | ||
450 | .pio_mask = 0x1f, /* pio0-4 */ | ||
451 | .udma_mask = 0x7f, /* udma0-6 */ | ||
452 | .port_ops = &mv5_ops, | ||
334 | }, | 453 | }, |
335 | { /* chip_604x */ | 454 | { /* chip_604x */ |
336 | .sht = &mv_sht, | 455 | .sht = &mv_sht, |
337 | .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), | 456 | .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), |
338 | .pio_mask = 0x1f, /* pio0-4 */ | 457 | .pio_mask = 0x1f, /* pio0-4 */ |
339 | .udma_mask = 0x7f, /* udma0-6 */ | 458 | .udma_mask = 0x7f, /* udma0-6 */ |
340 | .port_ops = &mv_ops, | 459 | .port_ops = &mv6_ops, |
341 | }, | 460 | }, |
342 | { /* chip_608x */ | 461 | { /* chip_608x */ |
343 | .sht = &mv_sht, | 462 | .sht = &mv_sht, |
344 | .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS | | 463 | .host_flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS | |
345 | MV_FLAG_DUAL_HC), | 464 | MV_FLAG_DUAL_HC), |
346 | .pio_mask = 0x1f, /* pio0-4 */ | 465 | .pio_mask = 0x1f, /* pio0-4 */ |
347 | .udma_mask = 0x7f, /* udma0-6 */ | 466 | .udma_mask = 0x7f, /* udma0-6 */ |
348 | .port_ops = &mv_ops, | 467 | .port_ops = &mv6_ops, |
349 | }, | 468 | }, |
350 | }; | 469 | }; |
351 | 470 | ||
352 | static const struct pci_device_id mv_pci_tbl[] = { | 471 | static const struct pci_device_id mv_pci_tbl[] = { |
353 | {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5040), 0, 0, chip_504x}, | 472 | {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5040), 0, 0, chip_504x}, |
354 | {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5041), 0, 0, chip_504x}, | 473 | {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5041), 0, 0, chip_504x}, |
355 | {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5080), 0, 0, chip_508x}, | 474 | {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5080), 0, 0, chip_5080}, |
356 | {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5081), 0, 0, chip_508x}, | 475 | {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x5081), 0, 0, chip_508x}, |
357 | 476 | ||
358 | {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6040), 0, 0, chip_604x}, | 477 | {PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x6040), 0, 0, chip_604x}, |
@@ -371,6 +490,24 @@ static struct pci_driver mv_pci_driver = { | |||
371 | .remove = ata_pci_remove_one, | 490 | .remove = ata_pci_remove_one, |
372 | }; | 491 | }; |
373 | 492 | ||
493 | static const struct mv_hw_ops mv5xxx_ops = { | ||
494 | .phy_errata = mv5_phy_errata, | ||
495 | .enable_leds = mv5_enable_leds, | ||
496 | .read_preamp = mv5_read_preamp, | ||
497 | .reset_hc = mv5_reset_hc, | ||
498 | .reset_flash = mv5_reset_flash, | ||
499 | .reset_bus = mv5_reset_bus, | ||
500 | }; | ||
501 | |||
502 | static const struct mv_hw_ops mv6xxx_ops = { | ||
503 | .phy_errata = mv6_phy_errata, | ||
504 | .enable_leds = mv6_enable_leds, | ||
505 | .read_preamp = mv6_read_preamp, | ||
506 | .reset_hc = mv6_reset_hc, | ||
507 | .reset_flash = mv6_reset_flash, | ||
508 | .reset_bus = mv_reset_pci_bus, | ||
509 | }; | ||
510 | |||
374 | /* | 511 | /* |
375 | * Functions | 512 | * Functions |
376 | */ | 513 | */ |
@@ -386,11 +523,27 @@ static inline void __iomem *mv_hc_base(void __iomem *base, unsigned int hc) | |||
386 | return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ)); | 523 | return (base + MV_SATAHC0_REG_BASE + (hc * MV_SATAHC_REG_SZ)); |
387 | } | 524 | } |
388 | 525 | ||
526 | static inline unsigned int mv_hc_from_port(unsigned int port) | ||
527 | { | ||
528 | return port >> MV_PORT_HC_SHIFT; | ||
529 | } | ||
530 | |||
531 | static inline unsigned int mv_hardport_from_port(unsigned int port) | ||
532 | { | ||
533 | return port & MV_PORT_MASK; | ||
534 | } | ||
535 | |||
536 | static inline void __iomem *mv_hc_base_from_port(void __iomem *base, | ||
537 | unsigned int port) | ||
538 | { | ||
539 | return mv_hc_base(base, mv_hc_from_port(port)); | ||
540 | } | ||
541 | |||
389 | static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port) | 542 | static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port) |
390 | { | 543 | { |
391 | return (mv_hc_base(base, port >> MV_PORT_HC_SHIFT) + | 544 | return mv_hc_base_from_port(base, port) + |
392 | MV_SATAHC_ARBTR_REG_SZ + | 545 | MV_SATAHC_ARBTR_REG_SZ + |
393 | ((port & MV_PORT_MASK) * MV_PORT_REG_SZ)); | 546 | (mv_hardport_from_port(port) * MV_PORT_REG_SZ); |
394 | } | 547 | } |
395 | 548 | ||
396 | static inline void __iomem *mv_ap_base(struct ata_port *ap) | 549 | static inline void __iomem *mv_ap_base(struct ata_port *ap) |
@@ -398,9 +551,9 @@ static inline void __iomem *mv_ap_base(struct ata_port *ap) | |||
398 | return mv_port_base(ap->host_set->mmio_base, ap->port_no); | 551 | return mv_port_base(ap->host_set->mmio_base, ap->port_no); |
399 | } | 552 | } |
400 | 553 | ||
401 | static inline int mv_get_hc_count(unsigned long hp_flags) | 554 | static inline int mv_get_hc_count(unsigned long host_flags) |
402 | { | 555 | { |
403 | return ((hp_flags & MV_FLAG_DUAL_HC) ? 2 : 1); | 556 | return ((host_flags & MV_FLAG_DUAL_HC) ? 2 : 1); |
404 | } | 557 | } |
405 | 558 | ||
406 | static void mv_irq_clear(struct ata_port *ap) | 559 | static void mv_irq_clear(struct ata_port *ap) |
@@ -452,7 +605,7 @@ static void mv_stop_dma(struct ata_port *ap) | |||
452 | } else { | 605 | } else { |
453 | assert(!(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS))); | 606 | assert(!(EDMA_EN & readl(port_mmio + EDMA_CMD_OFS))); |
454 | } | 607 | } |
455 | 608 | ||
456 | /* now properly wait for the eDMA to stop */ | 609 | /* now properly wait for the eDMA to stop */ |
457 | for (i = 1000; i > 0; i--) { | 610 | for (i = 1000; i > 0; i--) { |
458 | reg = readl(port_mmio + EDMA_CMD_OFS); | 611 | reg = readl(port_mmio + EDMA_CMD_OFS); |
@@ -503,7 +656,7 @@ static void mv_dump_all_regs(void __iomem *mmio_base, int port, | |||
503 | struct pci_dev *pdev) | 656 | struct pci_dev *pdev) |
504 | { | 657 | { |
505 | #ifdef ATA_DEBUG | 658 | #ifdef ATA_DEBUG |
506 | void __iomem *hc_base = mv_hc_base(mmio_base, | 659 | void __iomem *hc_base = mv_hc_base(mmio_base, |
507 | port >> MV_PORT_HC_SHIFT); | 660 | port >> MV_PORT_HC_SHIFT); |
508 | void __iomem *port_base; | 661 | void __iomem *port_base; |
509 | int start_port, num_ports, p, start_hc, num_hcs, hc; | 662 | int start_port, num_ports, p, start_hc, num_hcs, hc; |
@@ -517,7 +670,7 @@ static void mv_dump_all_regs(void __iomem *mmio_base, int port, | |||
517 | start_port = port; | 670 | start_port = port; |
518 | num_ports = num_hcs = 1; | 671 | num_ports = num_hcs = 1; |
519 | } | 672 | } |
520 | DPRINTK("All registers for port(s) %u-%u:\n", start_port, | 673 | DPRINTK("All registers for port(s) %u-%u:\n", start_port, |
521 | num_ports > 1 ? num_ports - 1 : start_port); | 674 | num_ports > 1 ? num_ports - 1 : start_port); |
522 | 675 | ||
523 | if (NULL != pdev) { | 676 | if (NULL != pdev) { |
@@ -585,70 +738,6 @@ static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) | |||
585 | } | 738 | } |
586 | 739 | ||
587 | /** | 740 | /** |
588 | * mv_global_soft_reset - Perform the 6xxx global soft reset | ||
589 | * @mmio_base: base address of the HBA | ||
590 | * | ||
591 | * This routine only applies to 6xxx parts. | ||
592 | * | ||
593 | * LOCKING: | ||
594 | * Inherited from caller. | ||
595 | */ | ||
596 | static int mv_global_soft_reset(void __iomem *mmio_base) | ||
597 | { | ||
598 | void __iomem *reg = mmio_base + PCI_MAIN_CMD_STS_OFS; | ||
599 | int i, rc = 0; | ||
600 | u32 t; | ||
601 | |||
602 | /* Following procedure defined in PCI "main command and status | ||
603 | * register" table. | ||
604 | */ | ||
605 | t = readl(reg); | ||
606 | writel(t | STOP_PCI_MASTER, reg); | ||
607 | |||
608 | for (i = 0; i < 1000; i++) { | ||
609 | udelay(1); | ||
610 | t = readl(reg); | ||
611 | if (PCI_MASTER_EMPTY & t) { | ||
612 | break; | ||
613 | } | ||
614 | } | ||
615 | if (!(PCI_MASTER_EMPTY & t)) { | ||
616 | printk(KERN_ERR DRV_NAME ": PCI master won't flush\n"); | ||
617 | rc = 1; | ||
618 | goto done; | ||
619 | } | ||
620 | |||
621 | /* set reset */ | ||
622 | i = 5; | ||
623 | do { | ||
624 | writel(t | GLOB_SFT_RST, reg); | ||
625 | t = readl(reg); | ||
626 | udelay(1); | ||
627 | } while (!(GLOB_SFT_RST & t) && (i-- > 0)); | ||
628 | |||
629 | if (!(GLOB_SFT_RST & t)) { | ||
630 | printk(KERN_ERR DRV_NAME ": can't set global reset\n"); | ||
631 | rc = 1; | ||
632 | goto done; | ||
633 | } | ||
634 | |||
635 | /* clear reset and *reenable the PCI master* (not mentioned in spec) */ | ||
636 | i = 5; | ||
637 | do { | ||
638 | writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg); | ||
639 | t = readl(reg); | ||
640 | udelay(1); | ||
641 | } while ((GLOB_SFT_RST & t) && (i-- > 0)); | ||
642 | |||
643 | if (GLOB_SFT_RST & t) { | ||
644 | printk(KERN_ERR DRV_NAME ": can't clear global reset\n"); | ||
645 | rc = 1; | ||
646 | } | ||
647 | done: | ||
648 | return rc; | ||
649 | } | ||
650 | |||
651 | /** | ||
652 | * mv_host_stop - Host specific cleanup/stop routine. | 741 | * mv_host_stop - Host specific cleanup/stop routine. |
653 | * @host_set: host data structure | 742 | * @host_set: host data structure |
654 | * | 743 | * |
@@ -701,7 +790,7 @@ static int mv_port_start(struct ata_port *ap) | |||
701 | goto err_out; | 790 | goto err_out; |
702 | memset(pp, 0, sizeof(*pp)); | 791 | memset(pp, 0, sizeof(*pp)); |
703 | 792 | ||
704 | mem = dma_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma, | 793 | mem = dma_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma, |
705 | GFP_KERNEL); | 794 | GFP_KERNEL); |
706 | if (!mem) | 795 | if (!mem) |
707 | goto err_out_pp; | 796 | goto err_out_pp; |
@@ -711,7 +800,7 @@ static int mv_port_start(struct ata_port *ap) | |||
711 | if (rc) | 800 | if (rc) |
712 | goto err_out_priv; | 801 | goto err_out_priv; |
713 | 802 | ||
714 | /* First item in chunk of DMA memory: | 803 | /* First item in chunk of DMA memory: |
715 | * 32-slot command request table (CRQB), 32 bytes each in size | 804 | * 32-slot command request table (CRQB), 32 bytes each in size |
716 | */ | 805 | */ |
717 | pp->crqb = mem; | 806 | pp->crqb = mem; |
@@ -719,7 +808,7 @@ static int mv_port_start(struct ata_port *ap) | |||
719 | mem += MV_CRQB_Q_SZ; | 808 | mem += MV_CRQB_Q_SZ; |
720 | mem_dma += MV_CRQB_Q_SZ; | 809 | mem_dma += MV_CRQB_Q_SZ; |
721 | 810 | ||
722 | /* Second item: | 811 | /* Second item: |
723 | * 32-slot command response table (CRPB), 8 bytes each in size | 812 | * 32-slot command response table (CRPB), 8 bytes each in size |
724 | */ | 813 | */ |
725 | pp->crpb = mem; | 814 | pp->crpb = mem; |
@@ -733,18 +822,18 @@ static int mv_port_start(struct ata_port *ap) | |||
733 | pp->sg_tbl = mem; | 822 | pp->sg_tbl = mem; |
734 | pp->sg_tbl_dma = mem_dma; | 823 | pp->sg_tbl_dma = mem_dma; |
735 | 824 | ||
736 | writelfl(EDMA_CFG_Q_DEPTH | EDMA_CFG_RD_BRST_EXT | | 825 | writelfl(EDMA_CFG_Q_DEPTH | EDMA_CFG_RD_BRST_EXT | |
737 | EDMA_CFG_WR_BUFF_LEN, port_mmio + EDMA_CFG_OFS); | 826 | EDMA_CFG_WR_BUFF_LEN, port_mmio + EDMA_CFG_OFS); |
738 | 827 | ||
739 | writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); | 828 | writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); |
740 | writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK, | 829 | writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK, |
741 | port_mmio + EDMA_REQ_Q_IN_PTR_OFS); | 830 | port_mmio + EDMA_REQ_Q_IN_PTR_OFS); |
742 | 831 | ||
743 | writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); | 832 | writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); |
744 | writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS); | 833 | writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS); |
745 | 834 | ||
746 | writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS); | 835 | writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS); |
747 | writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK, | 836 | writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK, |
748 | port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); | 837 | port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); |
749 | 838 | ||
750 | pp->req_producer = pp->rsp_consumer = 0; | 839 | pp->req_producer = pp->rsp_consumer = 0; |
@@ -805,20 +894,30 @@ static void mv_fill_sg(struct ata_queued_cmd *qc) | |||
805 | struct scatterlist *sg; | 894 | struct scatterlist *sg; |
806 | 895 | ||
807 | ata_for_each_sg(sg, qc) { | 896 | ata_for_each_sg(sg, qc) { |
808 | u32 sg_len; | ||
809 | dma_addr_t addr; | 897 | dma_addr_t addr; |
898 | u32 sg_len, len, offset; | ||
810 | 899 | ||
811 | addr = sg_dma_address(sg); | 900 | addr = sg_dma_address(sg); |
812 | sg_len = sg_dma_len(sg); | 901 | sg_len = sg_dma_len(sg); |
813 | 902 | ||
814 | pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff); | 903 | while (sg_len) { |
815 | pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16); | 904 | offset = addr & MV_DMA_BOUNDARY; |
816 | assert(0 == (sg_len & ~MV_DMA_BOUNDARY)); | 905 | len = sg_len; |
817 | pp->sg_tbl[i].flags_size = cpu_to_le32(sg_len); | 906 | if ((offset + sg_len) > 0x10000) |
818 | if (ata_sg_is_last(sg, qc)) | 907 | len = 0x10000 - offset; |
819 | pp->sg_tbl[i].flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL); | 908 | |
909 | pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff); | ||
910 | pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16); | ||
911 | pp->sg_tbl[i].flags_size = cpu_to_le32(len); | ||
912 | |||
913 | sg_len -= len; | ||
914 | addr += len; | ||
915 | |||
916 | if (!sg_len && ata_sg_is_last(sg, qc)) | ||
917 | pp->sg_tbl[i].flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL); | ||
820 | 918 | ||
821 | i++; | 919 | i++; |
920 | } | ||
822 | } | 921 | } |
823 | } | 922 | } |
824 | 923 | ||
@@ -859,7 +958,7 @@ static void mv_qc_prep(struct ata_queued_cmd *qc) | |||
859 | } | 958 | } |
860 | 959 | ||
861 | /* the req producer index should be the same as we remember it */ | 960 | /* the req producer index should be the same as we remember it */ |
862 | assert(((readl(mv_ap_base(qc->ap) + EDMA_REQ_Q_IN_PTR_OFS) >> | 961 | assert(((readl(mv_ap_base(qc->ap) + EDMA_REQ_Q_IN_PTR_OFS) >> |
863 | EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == | 962 | EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == |
864 | pp->req_producer); | 963 | pp->req_producer); |
865 | 964 | ||
@@ -871,9 +970,9 @@ static void mv_qc_prep(struct ata_queued_cmd *qc) | |||
871 | assert(MV_MAX_Q_DEPTH > qc->tag); | 970 | assert(MV_MAX_Q_DEPTH > qc->tag); |
872 | flags |= qc->tag << CRQB_TAG_SHIFT; | 971 | flags |= qc->tag << CRQB_TAG_SHIFT; |
873 | 972 | ||
874 | pp->crqb[pp->req_producer].sg_addr = | 973 | pp->crqb[pp->req_producer].sg_addr = |
875 | cpu_to_le32(pp->sg_tbl_dma & 0xffffffff); | 974 | cpu_to_le32(pp->sg_tbl_dma & 0xffffffff); |
876 | pp->crqb[pp->req_producer].sg_addr_hi = | 975 | pp->crqb[pp->req_producer].sg_addr_hi = |
877 | cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16); | 976 | cpu_to_le32((pp->sg_tbl_dma >> 16) >> 16); |
878 | pp->crqb[pp->req_producer].ctrl_flags = cpu_to_le16(flags); | 977 | pp->crqb[pp->req_producer].ctrl_flags = cpu_to_le16(flags); |
879 | 978 | ||
@@ -896,7 +995,7 @@ static void mv_qc_prep(struct ata_queued_cmd *qc) | |||
896 | #ifdef LIBATA_NCQ /* FIXME: remove this line when NCQ added */ | 995 | #ifdef LIBATA_NCQ /* FIXME: remove this line when NCQ added */ |
897 | case ATA_CMD_FPDMA_READ: | 996 | case ATA_CMD_FPDMA_READ: |
898 | case ATA_CMD_FPDMA_WRITE: | 997 | case ATA_CMD_FPDMA_WRITE: |
899 | mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0); | 998 | mv_crqb_pack_cmd(cw++, tf->hob_feature, ATA_REG_FEATURE, 0); |
900 | mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0); | 999 | mv_crqb_pack_cmd(cw++, tf->feature, ATA_REG_FEATURE, 0); |
901 | break; | 1000 | break; |
902 | #endif /* FIXME: remove this line when NCQ added */ | 1001 | #endif /* FIXME: remove this line when NCQ added */ |
@@ -962,7 +1061,7 @@ static int mv_qc_issue(struct ata_queued_cmd *qc) | |||
962 | pp->req_producer); | 1061 | pp->req_producer); |
963 | /* until we do queuing, the queue should be empty at this point */ | 1062 | /* until we do queuing, the queue should be empty at this point */ |
964 | assert(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == | 1063 | assert(((in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == |
965 | ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) >> | 1064 | ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) >> |
966 | EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK)); | 1065 | EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK)); |
967 | 1066 | ||
968 | mv_inc_q_index(&pp->req_producer); /* now incr producer index */ | 1067 | mv_inc_q_index(&pp->req_producer); /* now incr producer index */ |
@@ -999,15 +1098,15 @@ static u8 mv_get_crpb_status(struct ata_port *ap) | |||
999 | out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); | 1098 | out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); |
1000 | 1099 | ||
1001 | /* the response consumer index should be the same as we remember it */ | 1100 | /* the response consumer index should be the same as we remember it */ |
1002 | assert(((out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == | 1101 | assert(((out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == |
1003 | pp->rsp_consumer); | 1102 | pp->rsp_consumer); |
1004 | 1103 | ||
1005 | /* increment our consumer index... */ | 1104 | /* increment our consumer index... */ |
1006 | pp->rsp_consumer = mv_inc_q_index(&pp->rsp_consumer); | 1105 | pp->rsp_consumer = mv_inc_q_index(&pp->rsp_consumer); |
1007 | 1106 | ||
1008 | /* and, until we do NCQ, there should only be 1 CRPB waiting */ | 1107 | /* and, until we do NCQ, there should only be 1 CRPB waiting */ |
1009 | assert(((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) >> | 1108 | assert(((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) >> |
1010 | EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == | 1109 | EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK) == |
1011 | pp->rsp_consumer); | 1110 | pp->rsp_consumer); |
1012 | 1111 | ||
1013 | /* write out our inc'd consumer index so EDMA knows we're caught up */ | 1112 | /* write out our inc'd consumer index so EDMA knows we're caught up */ |
@@ -1055,7 +1154,7 @@ static void mv_err_intr(struct ata_port *ap) | |||
1055 | 1154 | ||
1056 | /* check for fatal here and recover if needed */ | 1155 | /* check for fatal here and recover if needed */ |
1057 | if (EDMA_ERR_FATAL & edma_err_cause) { | 1156 | if (EDMA_ERR_FATAL & edma_err_cause) { |
1058 | mv_phy_reset(ap); | 1157 | mv_stop_and_reset(ap); |
1059 | } | 1158 | } |
1060 | } | 1159 | } |
1061 | 1160 | ||
@@ -1120,6 +1219,10 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant, | |||
1120 | handled++; | 1219 | handled++; |
1121 | } | 1220 | } |
1122 | 1221 | ||
1222 | if (ap && | ||
1223 | (ap->flags & (ATA_FLAG_PORT_DISABLED | ATA_FLAG_NOINTR))) | ||
1224 | continue; | ||
1225 | |||
1123 | err_mask = ac_err_mask(ata_status); | 1226 | err_mask = ac_err_mask(ata_status); |
1124 | 1227 | ||
1125 | shift = port << 1; /* (port * 2) */ | 1228 | shift = port << 1; /* (port * 2) */ |
@@ -1131,14 +1234,15 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant, | |||
1131 | err_mask |= AC_ERR_OTHER; | 1234 | err_mask |= AC_ERR_OTHER; |
1132 | handled++; | 1235 | handled++; |
1133 | } | 1236 | } |
1134 | 1237 | ||
1135 | if (handled && ap) { | 1238 | if (handled && ap) { |
1136 | qc = ata_qc_from_tag(ap, ap->active_tag); | 1239 | qc = ata_qc_from_tag(ap, ap->active_tag); |
1137 | if (NULL != qc) { | 1240 | if (NULL != qc) { |
1138 | VPRINTK("port %u IRQ found for qc, " | 1241 | VPRINTK("port %u IRQ found for qc, " |
1139 | "ata_status 0x%x\n", port,ata_status); | 1242 | "ata_status 0x%x\n", port,ata_status); |
1140 | /* mark qc status appropriately */ | 1243 | /* mark qc status appropriately */ |
1141 | ata_qc_complete(qc, err_mask); | 1244 | if (!(qc->tf.ctl & ATA_NIEN)) |
1245 | ata_qc_complete(qc, err_mask); | ||
1142 | } | 1246 | } |
1143 | } | 1247 | } |
1144 | } | 1248 | } |
@@ -1146,7 +1250,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant, | |||
1146 | } | 1250 | } |
1147 | 1251 | ||
1148 | /** | 1252 | /** |
1149 | * mv_interrupt - | 1253 | * mv_interrupt - |
1150 | * @irq: unused | 1254 | * @irq: unused |
1151 | * @dev_instance: private data; in this case the host structure | 1255 | * @dev_instance: private data; in this case the host structure |
1152 | * @regs: unused | 1256 | * @regs: unused |
@@ -1156,7 +1260,7 @@ static void mv_host_intr(struct ata_host_set *host_set, u32 relevant, | |||
1156 | * routine to handle. Also check for PCI errors which are only | 1260 | * routine to handle. Also check for PCI errors which are only |
1157 | * reported here. | 1261 | * reported here. |
1158 | * | 1262 | * |
1159 | * LOCKING: | 1263 | * LOCKING: |
1160 | * This routine holds the host_set lock while processing pending | 1264 | * This routine holds the host_set lock while processing pending |
1161 | * interrupts. | 1265 | * interrupts. |
1162 | */ | 1266 | */ |
@@ -1202,8 +1306,422 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance, | |||
1202 | return IRQ_RETVAL(handled); | 1306 | return IRQ_RETVAL(handled); |
1203 | } | 1307 | } |
1204 | 1308 | ||
1309 | static void __iomem *mv5_phy_base(void __iomem *mmio, unsigned int port) | ||
1310 | { | ||
1311 | void __iomem *hc_mmio = mv_hc_base_from_port(mmio, port); | ||
1312 | unsigned long ofs = (mv_hardport_from_port(port) + 1) * 0x100UL; | ||
1313 | |||
1314 | return hc_mmio + ofs; | ||
1315 | } | ||
1316 | |||
1317 | static unsigned int mv5_scr_offset(unsigned int sc_reg_in) | ||
1318 | { | ||
1319 | unsigned int ofs; | ||
1320 | |||
1321 | switch (sc_reg_in) { | ||
1322 | case SCR_STATUS: | ||
1323 | case SCR_ERROR: | ||
1324 | case SCR_CONTROL: | ||
1325 | ofs = sc_reg_in * sizeof(u32); | ||
1326 | break; | ||
1327 | default: | ||
1328 | ofs = 0xffffffffU; | ||
1329 | break; | ||
1330 | } | ||
1331 | return ofs; | ||
1332 | } | ||
1333 | |||
1334 | static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in) | ||
1335 | { | ||
1336 | void __iomem *mmio = mv5_phy_base(ap->host_set->mmio_base, ap->port_no); | ||
1337 | unsigned int ofs = mv5_scr_offset(sc_reg_in); | ||
1338 | |||
1339 | if (ofs != 0xffffffffU) | ||
1340 | return readl(mmio + ofs); | ||
1341 | else | ||
1342 | return (u32) ofs; | ||
1343 | } | ||
1344 | |||
1345 | static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) | ||
1346 | { | ||
1347 | void __iomem *mmio = mv5_phy_base(ap->host_set->mmio_base, ap->port_no); | ||
1348 | unsigned int ofs = mv5_scr_offset(sc_reg_in); | ||
1349 | |||
1350 | if (ofs != 0xffffffffU) | ||
1351 | writelfl(val, mmio + ofs); | ||
1352 | } | ||
1353 | |||
1354 | static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio) | ||
1355 | { | ||
1356 | u8 rev_id; | ||
1357 | int early_5080; | ||
1358 | |||
1359 | pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id); | ||
1360 | |||
1361 | early_5080 = (pdev->device == 0x5080) && (rev_id == 0); | ||
1362 | |||
1363 | if (!early_5080) { | ||
1364 | u32 tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); | ||
1365 | tmp |= (1 << 0); | ||
1366 | writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); | ||
1367 | } | ||
1368 | |||
1369 | mv_reset_pci_bus(pdev, mmio); | ||
1370 | } | ||
1371 | |||
1372 | static void mv5_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) | ||
1373 | { | ||
1374 | writel(0x0fcfffff, mmio + MV_FLASH_CTL); | ||
1375 | } | ||
1376 | |||
1377 | static void mv5_read_preamp(struct mv_host_priv *hpriv, int idx, | ||
1378 | void __iomem *mmio) | ||
1379 | { | ||
1380 | void __iomem *phy_mmio = mv5_phy_base(mmio, idx); | ||
1381 | u32 tmp; | ||
1382 | |||
1383 | tmp = readl(phy_mmio + MV5_PHY_MODE); | ||
1384 | |||
1385 | hpriv->signal[idx].pre = tmp & 0x1800; /* bits 12:11 */ | ||
1386 | hpriv->signal[idx].amps = tmp & 0xe0; /* bits 7:5 */ | ||
1387 | } | ||
1388 | |||
1389 | static void mv5_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) | ||
1390 | { | ||
1391 | u32 tmp; | ||
1392 | |||
1393 | writel(0, mmio + MV_GPIO_PORT_CTL); | ||
1394 | |||
1395 | /* FIXME: handle MV_HP_ERRATA_50XXB2 errata */ | ||
1396 | |||
1397 | tmp = readl(mmio + MV_PCI_EXP_ROM_BAR_CTL); | ||
1398 | tmp |= ~(1 << 0); | ||
1399 | writel(tmp, mmio + MV_PCI_EXP_ROM_BAR_CTL); | ||
1400 | } | ||
1401 | |||
1402 | static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
1403 | unsigned int port) | ||
1404 | { | ||
1405 | void __iomem *phy_mmio = mv5_phy_base(mmio, port); | ||
1406 | const u32 mask = (1<<12) | (1<<11) | (1<<7) | (1<<6) | (1<<5); | ||
1407 | u32 tmp; | ||
1408 | int fix_apm_sq = (hpriv->hp_flags & MV_HP_ERRATA_50XXB0); | ||
1409 | |||
1410 | if (fix_apm_sq) { | ||
1411 | tmp = readl(phy_mmio + MV5_LT_MODE); | ||
1412 | tmp |= (1 << 19); | ||
1413 | writel(tmp, phy_mmio + MV5_LT_MODE); | ||
1414 | |||
1415 | tmp = readl(phy_mmio + MV5_PHY_CTL); | ||
1416 | tmp &= ~0x3; | ||
1417 | tmp |= 0x1; | ||
1418 | writel(tmp, phy_mmio + MV5_PHY_CTL); | ||
1419 | } | ||
1420 | |||
1421 | tmp = readl(phy_mmio + MV5_PHY_MODE); | ||
1422 | tmp &= ~mask; | ||
1423 | tmp |= hpriv->signal[port].pre; | ||
1424 | tmp |= hpriv->signal[port].amps; | ||
1425 | writel(tmp, phy_mmio + MV5_PHY_MODE); | ||
1426 | } | ||
1427 | |||
1428 | |||
1429 | #undef ZERO | ||
1430 | #define ZERO(reg) writel(0, port_mmio + (reg)) | ||
1431 | static void mv5_reset_hc_port(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
1432 | unsigned int port) | ||
1433 | { | ||
1434 | void __iomem *port_mmio = mv_port_base(mmio, port); | ||
1435 | |||
1436 | writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); | ||
1437 | |||
1438 | mv_channel_reset(hpriv, mmio, port); | ||
1439 | |||
1440 | ZERO(0x028); /* command */ | ||
1441 | writel(0x11f, port_mmio + EDMA_CFG_OFS); | ||
1442 | ZERO(0x004); /* timer */ | ||
1443 | ZERO(0x008); /* irq err cause */ | ||
1444 | ZERO(0x00c); /* irq err mask */ | ||
1445 | ZERO(0x010); /* rq bah */ | ||
1446 | ZERO(0x014); /* rq inp */ | ||
1447 | ZERO(0x018); /* rq outp */ | ||
1448 | ZERO(0x01c); /* respq bah */ | ||
1449 | ZERO(0x024); /* respq outp */ | ||
1450 | ZERO(0x020); /* respq inp */ | ||
1451 | ZERO(0x02c); /* test control */ | ||
1452 | writel(0xbc, port_mmio + EDMA_IORDY_TMOUT); | ||
1453 | } | ||
1454 | #undef ZERO | ||
1455 | |||
1456 | #define ZERO(reg) writel(0, hc_mmio + (reg)) | ||
1457 | static void mv5_reset_one_hc(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
1458 | unsigned int hc) | ||
1459 | { | ||
1460 | void __iomem *hc_mmio = mv_hc_base(mmio, hc); | ||
1461 | u32 tmp; | ||
1462 | |||
1463 | ZERO(0x00c); | ||
1464 | ZERO(0x010); | ||
1465 | ZERO(0x014); | ||
1466 | ZERO(0x018); | ||
1467 | |||
1468 | tmp = readl(hc_mmio + 0x20); | ||
1469 | tmp &= 0x1c1c1c1c; | ||
1470 | tmp |= 0x03030303; | ||
1471 | writel(tmp, hc_mmio + 0x20); | ||
1472 | } | ||
1473 | #undef ZERO | ||
1474 | |||
1475 | static int mv5_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
1476 | unsigned int n_hc) | ||
1477 | { | ||
1478 | unsigned int hc, port; | ||
1479 | |||
1480 | for (hc = 0; hc < n_hc; hc++) { | ||
1481 | for (port = 0; port < MV_PORTS_PER_HC; port++) | ||
1482 | mv5_reset_hc_port(hpriv, mmio, | ||
1483 | (hc * MV_PORTS_PER_HC) + port); | ||
1484 | |||
1485 | mv5_reset_one_hc(hpriv, mmio, hc); | ||
1486 | } | ||
1487 | |||
1488 | return 0; | ||
1489 | } | ||
1490 | |||
1491 | #undef ZERO | ||
1492 | #define ZERO(reg) writel(0, mmio + (reg)) | ||
1493 | static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio) | ||
1494 | { | ||
1495 | u32 tmp; | ||
1496 | |||
1497 | tmp = readl(mmio + MV_PCI_MODE); | ||
1498 | tmp &= 0xff00ffff; | ||
1499 | writel(tmp, mmio + MV_PCI_MODE); | ||
1500 | |||
1501 | ZERO(MV_PCI_DISC_TIMER); | ||
1502 | ZERO(MV_PCI_MSI_TRIGGER); | ||
1503 | writel(0x000100ff, mmio + MV_PCI_XBAR_TMOUT); | ||
1504 | ZERO(HC_MAIN_IRQ_MASK_OFS); | ||
1505 | ZERO(MV_PCI_SERR_MASK); | ||
1506 | ZERO(PCI_IRQ_CAUSE_OFS); | ||
1507 | ZERO(PCI_IRQ_MASK_OFS); | ||
1508 | ZERO(MV_PCI_ERR_LOW_ADDRESS); | ||
1509 | ZERO(MV_PCI_ERR_HIGH_ADDRESS); | ||
1510 | ZERO(MV_PCI_ERR_ATTRIBUTE); | ||
1511 | ZERO(MV_PCI_ERR_COMMAND); | ||
1512 | } | ||
1513 | #undef ZERO | ||
1514 | |||
1515 | static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio) | ||
1516 | { | ||
1517 | u32 tmp; | ||
1518 | |||
1519 | mv5_reset_flash(hpriv, mmio); | ||
1520 | |||
1521 | tmp = readl(mmio + MV_GPIO_PORT_CTL); | ||
1522 | tmp &= 0x3; | ||
1523 | tmp |= (1 << 5) | (1 << 6); | ||
1524 | writel(tmp, mmio + MV_GPIO_PORT_CTL); | ||
1525 | } | ||
1526 | |||
1527 | /** | ||
1528 | * mv6_reset_hc - Perform the 6xxx global soft reset | ||
1529 | * @mmio: base address of the HBA | ||
1530 | * | ||
1531 | * This routine only applies to 6xxx parts. | ||
1532 | * | ||
1533 | * LOCKING: | ||
1534 | * Inherited from caller. | ||
1535 | */ | ||
1536 | static int mv6_reset_hc(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
1537 | unsigned int n_hc) | ||
1538 | { | ||
1539 | void __iomem *reg = mmio + PCI_MAIN_CMD_STS_OFS; | ||
1540 | int i, rc = 0; | ||
1541 | u32 t; | ||
1542 | |||
1543 | /* Following procedure defined in PCI "main command and status | ||
1544 | * register" table. | ||
1545 | */ | ||
1546 | t = readl(reg); | ||
1547 | writel(t | STOP_PCI_MASTER, reg); | ||
1548 | |||
1549 | for (i = 0; i < 1000; i++) { | ||
1550 | udelay(1); | ||
1551 | t = readl(reg); | ||
1552 | if (PCI_MASTER_EMPTY & t) { | ||
1553 | break; | ||
1554 | } | ||
1555 | } | ||
1556 | if (!(PCI_MASTER_EMPTY & t)) { | ||
1557 | printk(KERN_ERR DRV_NAME ": PCI master won't flush\n"); | ||
1558 | rc = 1; | ||
1559 | goto done; | ||
1560 | } | ||
1561 | |||
1562 | /* set reset */ | ||
1563 | i = 5; | ||
1564 | do { | ||
1565 | writel(t | GLOB_SFT_RST, reg); | ||
1566 | t = readl(reg); | ||
1567 | udelay(1); | ||
1568 | } while (!(GLOB_SFT_RST & t) && (i-- > 0)); | ||
1569 | |||
1570 | if (!(GLOB_SFT_RST & t)) { | ||
1571 | printk(KERN_ERR DRV_NAME ": can't set global reset\n"); | ||
1572 | rc = 1; | ||
1573 | goto done; | ||
1574 | } | ||
1575 | |||
1576 | /* clear reset and *reenable the PCI master* (not mentioned in spec) */ | ||
1577 | i = 5; | ||
1578 | do { | ||
1579 | writel(t & ~(GLOB_SFT_RST | STOP_PCI_MASTER), reg); | ||
1580 | t = readl(reg); | ||
1581 | udelay(1); | ||
1582 | } while ((GLOB_SFT_RST & t) && (i-- > 0)); | ||
1583 | |||
1584 | if (GLOB_SFT_RST & t) { | ||
1585 | printk(KERN_ERR DRV_NAME ": can't clear global reset\n"); | ||
1586 | rc = 1; | ||
1587 | } | ||
1588 | done: | ||
1589 | return rc; | ||
1590 | } | ||
1591 | |||
1592 | static void mv6_read_preamp(struct mv_host_priv *hpriv, int idx, | ||
1593 | void __iomem *mmio) | ||
1594 | { | ||
1595 | void __iomem *port_mmio; | ||
1596 | u32 tmp; | ||
1597 | |||
1598 | tmp = readl(mmio + MV_RESET_CFG); | ||
1599 | if ((tmp & (1 << 0)) == 0) { | ||
1600 | hpriv->signal[idx].amps = 0x7 << 8; | ||
1601 | hpriv->signal[idx].pre = 0x1 << 5; | ||
1602 | return; | ||
1603 | } | ||
1604 | |||
1605 | port_mmio = mv_port_base(mmio, idx); | ||
1606 | tmp = readl(port_mmio + PHY_MODE2); | ||
1607 | |||
1608 | hpriv->signal[idx].amps = tmp & 0x700; /* bits 10:8 */ | ||
1609 | hpriv->signal[idx].pre = tmp & 0xe0; /* bits 7:5 */ | ||
1610 | } | ||
1611 | |||
1612 | static void mv6_enable_leds(struct mv_host_priv *hpriv, void __iomem *mmio) | ||
1613 | { | ||
1614 | writel(0x00000060, mmio + MV_GPIO_PORT_CTL); | ||
1615 | } | ||
1616 | |||
1617 | static void mv6_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
1618 | unsigned int port) | ||
1619 | { | ||
1620 | void __iomem *port_mmio = mv_port_base(mmio, port); | ||
1621 | |||
1622 | u32 hp_flags = hpriv->hp_flags; | ||
1623 | int fix_phy_mode2 = | ||
1624 | hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); | ||
1625 | int fix_phy_mode4 = | ||
1626 | hp_flags & (MV_HP_ERRATA_60X1B2 | MV_HP_ERRATA_60X1C0); | ||
1627 | u32 m2, tmp; | ||
1628 | |||
1629 | if (fix_phy_mode2) { | ||
1630 | m2 = readl(port_mmio + PHY_MODE2); | ||
1631 | m2 &= ~(1 << 16); | ||
1632 | m2 |= (1 << 31); | ||
1633 | writel(m2, port_mmio + PHY_MODE2); | ||
1634 | |||
1635 | udelay(200); | ||
1636 | |||
1637 | m2 = readl(port_mmio + PHY_MODE2); | ||
1638 | m2 &= ~((1 << 16) | (1 << 31)); | ||
1639 | writel(m2, port_mmio + PHY_MODE2); | ||
1640 | |||
1641 | udelay(200); | ||
1642 | } | ||
1643 | |||
1644 | /* who knows what this magic does */ | ||
1645 | tmp = readl(port_mmio + PHY_MODE3); | ||
1646 | tmp &= ~0x7F800000; | ||
1647 | tmp |= 0x2A800000; | ||
1648 | writel(tmp, port_mmio + PHY_MODE3); | ||
1649 | |||
1650 | if (fix_phy_mode4) { | ||
1651 | u32 m4; | ||
1652 | |||
1653 | m4 = readl(port_mmio + PHY_MODE4); | ||
1654 | |||
1655 | if (hp_flags & MV_HP_ERRATA_60X1B2) | ||
1656 | tmp = readl(port_mmio + 0x310); | ||
1657 | |||
1658 | m4 = (m4 & ~(1 << 1)) | (1 << 0); | ||
1659 | |||
1660 | writel(m4, port_mmio + PHY_MODE4); | ||
1661 | |||
1662 | if (hp_flags & MV_HP_ERRATA_60X1B2) | ||
1663 | writel(tmp, port_mmio + 0x310); | ||
1664 | } | ||
1665 | |||
1666 | /* Revert values of pre-emphasis and signal amps to the saved ones */ | ||
1667 | m2 = readl(port_mmio + PHY_MODE2); | ||
1668 | |||
1669 | m2 &= ~MV_M2_PREAMP_MASK; | ||
1670 | m2 |= hpriv->signal[port].amps; | ||
1671 | m2 |= hpriv->signal[port].pre; | ||
1672 | m2 &= ~(1 << 16); | ||
1673 | |||
1674 | writel(m2, port_mmio + PHY_MODE2); | ||
1675 | } | ||
1676 | |||
1677 | static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, | ||
1678 | unsigned int port_no) | ||
1679 | { | ||
1680 | void __iomem *port_mmio = mv_port_base(mmio, port_no); | ||
1681 | |||
1682 | writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS); | ||
1683 | |||
1684 | if (IS_60XX(hpriv)) { | ||
1685 | u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); | ||
1686 | ifctl |= (1 << 12) | (1 << 7); | ||
1687 | writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL); | ||
1688 | } | ||
1689 | |||
1690 | udelay(25); /* allow reset propagation */ | ||
1691 | |||
1692 | /* Spec never mentions clearing the bit. Marvell's driver does | ||
1693 | * clear the bit, however. | ||
1694 | */ | ||
1695 | writelfl(0, port_mmio + EDMA_CMD_OFS); | ||
1696 | |||
1697 | hpriv->ops->phy_errata(hpriv, mmio, port_no); | ||
1698 | |||
1699 | if (IS_50XX(hpriv)) | ||
1700 | mdelay(1); | ||
1701 | } | ||
1702 | |||
1703 | static void mv_stop_and_reset(struct ata_port *ap) | ||
1704 | { | ||
1705 | struct mv_host_priv *hpriv = ap->host_set->private_data; | ||
1706 | void __iomem *mmio = ap->host_set->mmio_base; | ||
1707 | |||
1708 | mv_stop_dma(ap); | ||
1709 | |||
1710 | mv_channel_reset(hpriv, mmio, ap->port_no); | ||
1711 | |||
1712 | __mv_phy_reset(ap, 0); | ||
1713 | } | ||
1714 | |||
1715 | static inline void __msleep(unsigned int msec, int can_sleep) | ||
1716 | { | ||
1717 | if (can_sleep) | ||
1718 | msleep(msec); | ||
1719 | else | ||
1720 | mdelay(msec); | ||
1721 | } | ||
1722 | |||
1205 | /** | 1723 | /** |
1206 | * mv_phy_reset - Perform eDMA reset followed by COMRESET | 1724 | * __mv_phy_reset - Perform eDMA reset followed by COMRESET |
1207 | * @ap: ATA channel to manipulate | 1725 | * @ap: ATA channel to manipulate |
1208 | * | 1726 | * |
1209 | * Part of this is taken from __sata_phy_reset and modified to | 1727 | * Part of this is taken from __sata_phy_reset and modified to |
@@ -1213,41 +1731,47 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance, | |||
1213 | * Inherited from caller. This is coded to safe to call at | 1731 | * Inherited from caller. This is coded to safe to call at |
1214 | * interrupt level, i.e. it does not sleep. | 1732 | * interrupt level, i.e. it does not sleep. |
1215 | */ | 1733 | */ |
1216 | static void mv_phy_reset(struct ata_port *ap) | 1734 | static void __mv_phy_reset(struct ata_port *ap, int can_sleep) |
1217 | { | 1735 | { |
1736 | struct mv_port_priv *pp = ap->private_data; | ||
1737 | struct mv_host_priv *hpriv = ap->host_set->private_data; | ||
1218 | void __iomem *port_mmio = mv_ap_base(ap); | 1738 | void __iomem *port_mmio = mv_ap_base(ap); |
1219 | struct ata_taskfile tf; | 1739 | struct ata_taskfile tf; |
1220 | struct ata_device *dev = &ap->device[0]; | 1740 | struct ata_device *dev = &ap->device[0]; |
1221 | unsigned long timeout; | 1741 | unsigned long timeout; |
1742 | int retry = 5; | ||
1743 | u32 sstatus; | ||
1222 | 1744 | ||
1223 | VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio); | 1745 | VPRINTK("ENTER, port %u, mmio 0x%p\n", ap->port_no, port_mmio); |
1224 | 1746 | ||
1225 | mv_stop_dma(ap); | 1747 | DPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x " |
1226 | |||
1227 | writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS); | ||
1228 | udelay(25); /* allow reset propagation */ | ||
1229 | |||
1230 | /* Spec never mentions clearing the bit. Marvell's driver does | ||
1231 | * clear the bit, however. | ||
1232 | */ | ||
1233 | writelfl(0, port_mmio + EDMA_CMD_OFS); | ||
1234 | |||
1235 | VPRINTK("S-regs after ATA_RST: SStat 0x%08x SErr 0x%08x " | ||
1236 | "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), | 1748 | "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), |
1237 | mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); | 1749 | mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); |
1238 | 1750 | ||
1239 | /* proceed to init communications via the scr_control reg */ | 1751 | /* Issue COMRESET via SControl */ |
1752 | comreset_retry: | ||
1240 | scr_write_flush(ap, SCR_CONTROL, 0x301); | 1753 | scr_write_flush(ap, SCR_CONTROL, 0x301); |
1241 | mdelay(1); | 1754 | __msleep(1, can_sleep); |
1755 | |||
1242 | scr_write_flush(ap, SCR_CONTROL, 0x300); | 1756 | scr_write_flush(ap, SCR_CONTROL, 0x300); |
1243 | timeout = jiffies + (HZ * 1); | 1757 | __msleep(20, can_sleep); |
1758 | |||
1759 | timeout = jiffies + msecs_to_jiffies(200); | ||
1244 | do { | 1760 | do { |
1245 | mdelay(10); | 1761 | sstatus = scr_read(ap, SCR_STATUS) & 0x3; |
1246 | if ((scr_read(ap, SCR_STATUS) & 0xf) != 1) | 1762 | if ((sstatus == 3) || (sstatus == 0)) |
1247 | break; | 1763 | break; |
1764 | |||
1765 | __msleep(1, can_sleep); | ||
1248 | } while (time_before(jiffies, timeout)); | 1766 | } while (time_before(jiffies, timeout)); |
1249 | 1767 | ||
1250 | VPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x " | 1768 | /* work around errata */ |
1769 | if (IS_60XX(hpriv) && | ||
1770 | (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) && | ||
1771 | (retry-- > 0)) | ||
1772 | goto comreset_retry; | ||
1773 | |||
1774 | DPRINTK("S-regs after PHY wake: SStat 0x%08x SErr 0x%08x " | ||
1251 | "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), | 1775 | "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), |
1252 | mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); | 1776 | mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); |
1253 | 1777 | ||
@@ -1261,6 +1785,21 @@ static void mv_phy_reset(struct ata_port *ap) | |||
1261 | } | 1785 | } |
1262 | ap->cbl = ATA_CBL_SATA; | 1786 | ap->cbl = ATA_CBL_SATA; |
1263 | 1787 | ||
1788 | /* even after SStatus reflects that device is ready, | ||
1789 | * it seems to take a while for link to be fully | ||
1790 | * established (and thus Status no longer 0x80/0x7F), | ||
1791 | * so we poll a bit for that, here. | ||
1792 | */ | ||
1793 | retry = 20; | ||
1794 | while (1) { | ||
1795 | u8 drv_stat = ata_check_status(ap); | ||
1796 | if ((drv_stat != 0x80) && (drv_stat != 0x7f)) | ||
1797 | break; | ||
1798 | __msleep(500, can_sleep); | ||
1799 | if (retry-- <= 0) | ||
1800 | break; | ||
1801 | } | ||
1802 | |||
1264 | tf.lbah = readb((void __iomem *) ap->ioaddr.lbah_addr); | 1803 | tf.lbah = readb((void __iomem *) ap->ioaddr.lbah_addr); |
1265 | tf.lbam = readb((void __iomem *) ap->ioaddr.lbam_addr); | 1804 | tf.lbam = readb((void __iomem *) ap->ioaddr.lbam_addr); |
1266 | tf.lbal = readb((void __iomem *) ap->ioaddr.lbal_addr); | 1805 | tf.lbal = readb((void __iomem *) ap->ioaddr.lbal_addr); |
@@ -1271,9 +1810,19 @@ static void mv_phy_reset(struct ata_port *ap) | |||
1271 | VPRINTK("Port disabled post-sig: No device present.\n"); | 1810 | VPRINTK("Port disabled post-sig: No device present.\n"); |
1272 | ata_port_disable(ap); | 1811 | ata_port_disable(ap); |
1273 | } | 1812 | } |
1813 | |||
1814 | writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); | ||
1815 | |||
1816 | pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; | ||
1817 | |||
1274 | VPRINTK("EXIT\n"); | 1818 | VPRINTK("EXIT\n"); |
1275 | } | 1819 | } |
1276 | 1820 | ||
1821 | static void mv_phy_reset(struct ata_port *ap) | ||
1822 | { | ||
1823 | __mv_phy_reset(ap, 1); | ||
1824 | } | ||
1825 | |||
1277 | /** | 1826 | /** |
1278 | * mv_eng_timeout - Routine called by libata when SCSI times out I/O | 1827 | * mv_eng_timeout - Routine called by libata when SCSI times out I/O |
1279 | * @ap: ATA channel to manipulate | 1828 | * @ap: ATA channel to manipulate |
@@ -1291,16 +1840,16 @@ static void mv_eng_timeout(struct ata_port *ap) | |||
1291 | 1840 | ||
1292 | printk(KERN_ERR "ata%u: Entering mv_eng_timeout\n",ap->id); | 1841 | printk(KERN_ERR "ata%u: Entering mv_eng_timeout\n",ap->id); |
1293 | DPRINTK("All regs @ start of eng_timeout\n"); | 1842 | DPRINTK("All regs @ start of eng_timeout\n"); |
1294 | mv_dump_all_regs(ap->host_set->mmio_base, ap->port_no, | 1843 | mv_dump_all_regs(ap->host_set->mmio_base, ap->port_no, |
1295 | to_pci_dev(ap->host_set->dev)); | 1844 | to_pci_dev(ap->host_set->dev)); |
1296 | 1845 | ||
1297 | qc = ata_qc_from_tag(ap, ap->active_tag); | 1846 | qc = ata_qc_from_tag(ap, ap->active_tag); |
1298 | printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n", | 1847 | printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n", |
1299 | ap->host_set->mmio_base, ap, qc, qc->scsicmd, | 1848 | ap->host_set->mmio_base, ap, qc, qc->scsicmd, |
1300 | &qc->scsicmd->cmnd); | 1849 | &qc->scsicmd->cmnd); |
1301 | 1850 | ||
1302 | mv_err_intr(ap); | 1851 | mv_err_intr(ap); |
1303 | mv_phy_reset(ap); | 1852 | mv_stop_and_reset(ap); |
1304 | 1853 | ||
1305 | if (!qc) { | 1854 | if (!qc) { |
1306 | printk(KERN_ERR "ata%u: BUG: timeout without command\n", | 1855 | printk(KERN_ERR "ata%u: BUG: timeout without command\n", |
@@ -1336,17 +1885,17 @@ static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio) | |||
1336 | unsigned long shd_base = (unsigned long) port_mmio + SHD_BLK_OFS; | 1885 | unsigned long shd_base = (unsigned long) port_mmio + SHD_BLK_OFS; |
1337 | unsigned serr_ofs; | 1886 | unsigned serr_ofs; |
1338 | 1887 | ||
1339 | /* PIO related setup | 1888 | /* PIO related setup |
1340 | */ | 1889 | */ |
1341 | port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA); | 1890 | port->data_addr = shd_base + (sizeof(u32) * ATA_REG_DATA); |
1342 | port->error_addr = | 1891 | port->error_addr = |
1343 | port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR); | 1892 | port->feature_addr = shd_base + (sizeof(u32) * ATA_REG_ERR); |
1344 | port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT); | 1893 | port->nsect_addr = shd_base + (sizeof(u32) * ATA_REG_NSECT); |
1345 | port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL); | 1894 | port->lbal_addr = shd_base + (sizeof(u32) * ATA_REG_LBAL); |
1346 | port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM); | 1895 | port->lbam_addr = shd_base + (sizeof(u32) * ATA_REG_LBAM); |
1347 | port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH); | 1896 | port->lbah_addr = shd_base + (sizeof(u32) * ATA_REG_LBAH); |
1348 | port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE); | 1897 | port->device_addr = shd_base + (sizeof(u32) * ATA_REG_DEVICE); |
1349 | port->status_addr = | 1898 | port->status_addr = |
1350 | port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS); | 1899 | port->command_addr = shd_base + (sizeof(u32) * ATA_REG_STATUS); |
1351 | /* special case: control/altstatus doesn't have ATA_REG_ address */ | 1900 | /* special case: control/altstatus doesn't have ATA_REG_ address */ |
1352 | port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS; | 1901 | port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST_OFS; |
@@ -1362,14 +1911,92 @@ static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio) | |||
1362 | /* unmask all EDMA error interrupts */ | 1911 | /* unmask all EDMA error interrupts */ |
1363 | writelfl(~0, port_mmio + EDMA_ERR_IRQ_MASK_OFS); | 1912 | writelfl(~0, port_mmio + EDMA_ERR_IRQ_MASK_OFS); |
1364 | 1913 | ||
1365 | VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n", | 1914 | VPRINTK("EDMA cfg=0x%08x EDMA IRQ err cause/mask=0x%08x/0x%08x\n", |
1366 | readl(port_mmio + EDMA_CFG_OFS), | 1915 | readl(port_mmio + EDMA_CFG_OFS), |
1367 | readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS), | 1916 | readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS), |
1368 | readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS)); | 1917 | readl(port_mmio + EDMA_ERR_IRQ_MASK_OFS)); |
1369 | } | 1918 | } |
1370 | 1919 | ||
1920 | static int mv_chip_id(struct pci_dev *pdev, struct mv_host_priv *hpriv, | ||
1921 | unsigned int board_idx) | ||
1922 | { | ||
1923 | u8 rev_id; | ||
1924 | u32 hp_flags = hpriv->hp_flags; | ||
1925 | |||
1926 | pci_read_config_byte(pdev, PCI_REVISION_ID, &rev_id); | ||
1927 | |||
1928 | switch(board_idx) { | ||
1929 | case chip_5080: | ||
1930 | hpriv->ops = &mv5xxx_ops; | ||
1931 | hp_flags |= MV_HP_50XX; | ||
1932 | |||
1933 | switch (rev_id) { | ||
1934 | case 0x1: | ||
1935 | hp_flags |= MV_HP_ERRATA_50XXB0; | ||
1936 | break; | ||
1937 | case 0x3: | ||
1938 | hp_flags |= MV_HP_ERRATA_50XXB2; | ||
1939 | break; | ||
1940 | default: | ||
1941 | dev_printk(KERN_WARNING, &pdev->dev, | ||
1942 | "Applying 50XXB2 workarounds to unknown rev\n"); | ||
1943 | hp_flags |= MV_HP_ERRATA_50XXB2; | ||
1944 | break; | ||
1945 | } | ||
1946 | break; | ||
1947 | |||
1948 | case chip_504x: | ||
1949 | case chip_508x: | ||
1950 | hpriv->ops = &mv5xxx_ops; | ||
1951 | hp_flags |= MV_HP_50XX; | ||
1952 | |||
1953 | switch (rev_id) { | ||
1954 | case 0x0: | ||
1955 | hp_flags |= MV_HP_ERRATA_50XXB0; | ||
1956 | break; | ||
1957 | case 0x3: | ||
1958 | hp_flags |= MV_HP_ERRATA_50XXB2; | ||
1959 | break; | ||
1960 | default: | ||
1961 | dev_printk(KERN_WARNING, &pdev->dev, | ||
1962 | "Applying B2 workarounds to unknown rev\n"); | ||
1963 | hp_flags |= MV_HP_ERRATA_50XXB2; | ||
1964 | break; | ||
1965 | } | ||
1966 | break; | ||
1967 | |||
1968 | case chip_604x: | ||
1969 | case chip_608x: | ||
1970 | hpriv->ops = &mv6xxx_ops; | ||
1971 | |||
1972 | switch (rev_id) { | ||
1973 | case 0x7: | ||
1974 | hp_flags |= MV_HP_ERRATA_60X1B2; | ||
1975 | break; | ||
1976 | case 0x9: | ||
1977 | hp_flags |= MV_HP_ERRATA_60X1C0; | ||
1978 | break; | ||
1979 | default: | ||
1980 | dev_printk(KERN_WARNING, &pdev->dev, | ||
1981 | "Applying B2 workarounds to unknown rev\n"); | ||
1982 | hp_flags |= MV_HP_ERRATA_60X1B2; | ||
1983 | break; | ||
1984 | } | ||
1985 | break; | ||
1986 | |||
1987 | default: | ||
1988 | printk(KERN_ERR DRV_NAME ": BUG: invalid board index %u\n", board_idx); | ||
1989 | return 1; | ||
1990 | } | ||
1991 | |||
1992 | hpriv->hp_flags = hp_flags; | ||
1993 | |||
1994 | return 0; | ||
1995 | } | ||
1996 | |||
1371 | /** | 1997 | /** |
1372 | * mv_host_init - Perform some early initialization of the host. | 1998 | * mv_init_host - Perform some early initialization of the host. |
1999 | * @pdev: host PCI device | ||
1373 | * @probe_ent: early data struct representing the host | 2000 | * @probe_ent: early data struct representing the host |
1374 | * | 2001 | * |
1375 | * If possible, do an early global reset of the host. Then do | 2002 | * If possible, do an early global reset of the host. Then do |
@@ -1378,23 +2005,48 @@ static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio) | |||
1378 | * LOCKING: | 2005 | * LOCKING: |
1379 | * Inherited from caller. | 2006 | * Inherited from caller. |
1380 | */ | 2007 | */ |
1381 | static int mv_host_init(struct ata_probe_ent *probe_ent) | 2008 | static int mv_init_host(struct pci_dev *pdev, struct ata_probe_ent *probe_ent, |
2009 | unsigned int board_idx) | ||
1382 | { | 2010 | { |
1383 | int rc = 0, n_hc, port, hc; | 2011 | int rc = 0, n_hc, port, hc; |
1384 | void __iomem *mmio = probe_ent->mmio_base; | 2012 | void __iomem *mmio = probe_ent->mmio_base; |
1385 | void __iomem *port_mmio; | 2013 | struct mv_host_priv *hpriv = probe_ent->private_data; |
1386 | 2014 | ||
1387 | if ((MV_FLAG_GLBL_SFT_RST & probe_ent->host_flags) && | 2015 | /* global interrupt mask */ |
1388 | mv_global_soft_reset(probe_ent->mmio_base)) { | 2016 | writel(0, mmio + HC_MAIN_IRQ_MASK_OFS); |
1389 | rc = 1; | 2017 | |
2018 | rc = mv_chip_id(pdev, hpriv, board_idx); | ||
2019 | if (rc) | ||
1390 | goto done; | 2020 | goto done; |
1391 | } | ||
1392 | 2021 | ||
1393 | n_hc = mv_get_hc_count(probe_ent->host_flags); | 2022 | n_hc = mv_get_hc_count(probe_ent->host_flags); |
1394 | probe_ent->n_ports = MV_PORTS_PER_HC * n_hc; | 2023 | probe_ent->n_ports = MV_PORTS_PER_HC * n_hc; |
1395 | 2024 | ||
2025 | for (port = 0; port < probe_ent->n_ports; port++) | ||
2026 | hpriv->ops->read_preamp(hpriv, port, mmio); | ||
2027 | |||
2028 | rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc); | ||
2029 | if (rc) | ||
2030 | goto done; | ||
2031 | |||
2032 | hpriv->ops->reset_flash(hpriv, mmio); | ||
2033 | hpriv->ops->reset_bus(pdev, mmio); | ||
2034 | hpriv->ops->enable_leds(hpriv, mmio); | ||
2035 | |||
1396 | for (port = 0; port < probe_ent->n_ports; port++) { | 2036 | for (port = 0; port < probe_ent->n_ports; port++) { |
1397 | port_mmio = mv_port_base(mmio, port); | 2037 | if (IS_60XX(hpriv)) { |
2038 | void __iomem *port_mmio = mv_port_base(mmio, port); | ||
2039 | |||
2040 | u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); | ||
2041 | ifctl |= (1 << 12); | ||
2042 | writelfl(ifctl, port_mmio + SATA_INTERFACE_CTL); | ||
2043 | } | ||
2044 | |||
2045 | hpriv->ops->phy_errata(hpriv, mmio, port); | ||
2046 | } | ||
2047 | |||
2048 | for (port = 0; port < probe_ent->n_ports; port++) { | ||
2049 | void __iomem *port_mmio = mv_port_base(mmio, port); | ||
1398 | mv_port_init(&probe_ent->port[port], port_mmio); | 2050 | mv_port_init(&probe_ent->port[port], port_mmio); |
1399 | } | 2051 | } |
1400 | 2052 | ||
@@ -1418,11 +2070,12 @@ static int mv_host_init(struct ata_probe_ent *probe_ent) | |||
1418 | writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS); | 2070 | writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS); |
1419 | 2071 | ||
1420 | VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x " | 2072 | VPRINTK("HC MAIN IRQ cause/mask=0x%08x/0x%08x " |
1421 | "PCI int cause/mask=0x%08x/0x%08x\n", | 2073 | "PCI int cause/mask=0x%08x/0x%08x\n", |
1422 | readl(mmio + HC_MAIN_IRQ_CAUSE_OFS), | 2074 | readl(mmio + HC_MAIN_IRQ_CAUSE_OFS), |
1423 | readl(mmio + HC_MAIN_IRQ_MASK_OFS), | 2075 | readl(mmio + HC_MAIN_IRQ_MASK_OFS), |
1424 | readl(mmio + PCI_IRQ_CAUSE_OFS), | 2076 | readl(mmio + PCI_IRQ_CAUSE_OFS), |
1425 | readl(mmio + PCI_IRQ_MASK_OFS)); | 2077 | readl(mmio + PCI_IRQ_MASK_OFS)); |
2078 | |||
1426 | done: | 2079 | done: |
1427 | return rc; | 2080 | return rc; |
1428 | } | 2081 | } |
@@ -1458,7 +2111,7 @@ static void mv_print_info(struct ata_probe_ent *probe_ent) | |||
1458 | 2111 | ||
1459 | dev_printk(KERN_INFO, &pdev->dev, | 2112 | dev_printk(KERN_INFO, &pdev->dev, |
1460 | "%u slots %u ports %s mode IRQ via %s\n", | 2113 | "%u slots %u ports %s mode IRQ via %s\n", |
1461 | (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports, | 2114 | (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports, |
1462 | scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx"); | 2115 | scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx"); |
1463 | } | 2116 | } |
1464 | 2117 | ||
@@ -1528,7 +2181,7 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
1528 | probe_ent->private_data = hpriv; | 2181 | probe_ent->private_data = hpriv; |
1529 | 2182 | ||
1530 | /* initialize adapter */ | 2183 | /* initialize adapter */ |
1531 | rc = mv_host_init(probe_ent); | 2184 | rc = mv_init_host(pdev, probe_ent, board_idx); |
1532 | if (rc) { | 2185 | if (rc) { |
1533 | goto err_out_hpriv; | 2186 | goto err_out_hpriv; |
1534 | } | 2187 | } |