diff options
Diffstat (limited to 'drivers/ata/sata_mv.c')
-rw-r--r-- | drivers/ata/sata_mv.c | 887 |
1 files changed, 568 insertions, 319 deletions
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index 3873b29c80d6..8a77a0ae83ad 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c | |||
@@ -29,11 +29,6 @@ | |||
29 | I distinctly remember a couple workarounds (one related to PCI-X) | 29 | I distinctly remember a couple workarounds (one related to PCI-X) |
30 | are still needed. | 30 | are still needed. |
31 | 31 | ||
32 | 2) Convert to LibATA new EH. Required for hotplug, NCQ, and sane | ||
33 | probing/error handling in general. MUST HAVE. | ||
34 | |||
35 | 3) Add hotplug support (easy, once new-EH support appears) | ||
36 | |||
37 | 4) Add NCQ support (easy to intermediate, once new-EH support appears) | 32 | 4) Add NCQ support (easy to intermediate, once new-EH support appears) |
38 | 33 | ||
39 | 5) Investigate problems with PCI Message Signalled Interrupts (MSI). | 34 | 5) Investigate problems with PCI Message Signalled Interrupts (MSI). |
@@ -108,8 +103,6 @@ enum { | |||
108 | MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */ | 103 | MV_SATAHC_ARBTR_REG_SZ = MV_MINOR_REG_AREA_SZ, /* arbiter */ |
109 | MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ, | 104 | MV_PORT_REG_SZ = MV_MINOR_REG_AREA_SZ, |
110 | 105 | ||
111 | MV_USE_Q_DEPTH = ATA_DEF_QUEUE, | ||
112 | |||
113 | MV_MAX_Q_DEPTH = 32, | 106 | MV_MAX_Q_DEPTH = 32, |
114 | MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1, | 107 | MV_MAX_Q_DEPTH_MASK = MV_MAX_Q_DEPTH - 1, |
115 | 108 | ||
@@ -133,18 +126,22 @@ enum { | |||
133 | /* Host Flags */ | 126 | /* Host Flags */ |
134 | MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ | 127 | MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ |
135 | MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */ | 128 | MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */ |
136 | MV_COMMON_FLAGS = (ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | | 129 | MV_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | |
137 | ATA_FLAG_SATA_RESET | ATA_FLAG_MMIO | | 130 | ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI | |
138 | ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING), | 131 | ATA_FLAG_PIO_POLLING, |
139 | MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE, | 132 | MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE, |
140 | 133 | ||
141 | CRQB_FLAG_READ = (1 << 0), | 134 | CRQB_FLAG_READ = (1 << 0), |
142 | CRQB_TAG_SHIFT = 1, | 135 | CRQB_TAG_SHIFT = 1, |
136 | CRQB_IOID_SHIFT = 6, /* CRQB Gen-II/IIE IO Id shift */ | ||
137 | CRQB_HOSTQ_SHIFT = 17, /* CRQB Gen-II/IIE HostQueTag shift */ | ||
143 | CRQB_CMD_ADDR_SHIFT = 8, | 138 | CRQB_CMD_ADDR_SHIFT = 8, |
144 | CRQB_CMD_CS = (0x2 << 11), | 139 | CRQB_CMD_CS = (0x2 << 11), |
145 | CRQB_CMD_LAST = (1 << 15), | 140 | CRQB_CMD_LAST = (1 << 15), |
146 | 141 | ||
147 | CRPB_FLAG_STATUS_SHIFT = 8, | 142 | CRPB_FLAG_STATUS_SHIFT = 8, |
143 | CRPB_IOID_SHIFT_6 = 5, /* CRPB Gen-II IO Id shift */ | ||
144 | CRPB_IOID_SHIFT_7 = 7, /* CRPB Gen-IIE IO Id shift */ | ||
148 | 145 | ||
149 | EPRD_FLAG_END_OF_TBL = (1 << 31), | 146 | EPRD_FLAG_END_OF_TBL = (1 << 31), |
150 | 147 | ||
@@ -236,8 +233,10 @@ enum { | |||
236 | EDMA_ERR_DEV_DCON = (1 << 3), | 233 | EDMA_ERR_DEV_DCON = (1 << 3), |
237 | EDMA_ERR_DEV_CON = (1 << 4), | 234 | EDMA_ERR_DEV_CON = (1 << 4), |
238 | EDMA_ERR_SERR = (1 << 5), | 235 | EDMA_ERR_SERR = (1 << 5), |
239 | EDMA_ERR_SELF_DIS = (1 << 7), | 236 | EDMA_ERR_SELF_DIS = (1 << 7), /* Gen II/IIE self-disable */ |
237 | EDMA_ERR_SELF_DIS_5 = (1 << 8), /* Gen I self-disable */ | ||
240 | EDMA_ERR_BIST_ASYNC = (1 << 8), | 238 | EDMA_ERR_BIST_ASYNC = (1 << 8), |
239 | EDMA_ERR_TRANS_IRQ_7 = (1 << 8), /* Gen IIE transprt layer irq */ | ||
241 | EDMA_ERR_CRBQ_PAR = (1 << 9), | 240 | EDMA_ERR_CRBQ_PAR = (1 << 9), |
242 | EDMA_ERR_CRPB_PAR = (1 << 10), | 241 | EDMA_ERR_CRPB_PAR = (1 << 10), |
243 | EDMA_ERR_INTRL_PAR = (1 << 11), | 242 | EDMA_ERR_INTRL_PAR = (1 << 11), |
@@ -248,13 +247,33 @@ enum { | |||
248 | EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), | 247 | EDMA_ERR_LNK_CTRL_TX = (0x1f << 21), |
249 | EDMA_ERR_LNK_DATA_TX = (0x1f << 26), | 248 | EDMA_ERR_LNK_DATA_TX = (0x1f << 26), |
250 | EDMA_ERR_TRANS_PROTO = (1 << 31), | 249 | EDMA_ERR_TRANS_PROTO = (1 << 31), |
251 | EDMA_ERR_FATAL = (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | | 250 | EDMA_ERR_OVERRUN_5 = (1 << 5), |
252 | EDMA_ERR_DEV_DCON | EDMA_ERR_CRBQ_PAR | | 251 | EDMA_ERR_UNDERRUN_5 = (1 << 6), |
253 | EDMA_ERR_CRPB_PAR | EDMA_ERR_INTRL_PAR | | 252 | EDMA_EH_FREEZE = EDMA_ERR_D_PAR | |
254 | EDMA_ERR_IORDY | EDMA_ERR_LNK_CTRL_RX_2 | | 253 | EDMA_ERR_PRD_PAR | |
255 | EDMA_ERR_LNK_DATA_RX | | 254 | EDMA_ERR_DEV_DCON | |
256 | EDMA_ERR_LNK_DATA_TX | | 255 | EDMA_ERR_DEV_CON | |
257 | EDMA_ERR_TRANS_PROTO), | 256 | EDMA_ERR_SERR | |
257 | EDMA_ERR_SELF_DIS | | ||
258 | EDMA_ERR_CRBQ_PAR | | ||
259 | EDMA_ERR_CRPB_PAR | | ||
260 | EDMA_ERR_INTRL_PAR | | ||
261 | EDMA_ERR_IORDY | | ||
262 | EDMA_ERR_LNK_CTRL_RX_2 | | ||
263 | EDMA_ERR_LNK_DATA_RX | | ||
264 | EDMA_ERR_LNK_DATA_TX | | ||
265 | EDMA_ERR_TRANS_PROTO, | ||
266 | EDMA_EH_FREEZE_5 = EDMA_ERR_D_PAR | | ||
267 | EDMA_ERR_PRD_PAR | | ||
268 | EDMA_ERR_DEV_DCON | | ||
269 | EDMA_ERR_DEV_CON | | ||
270 | EDMA_ERR_OVERRUN_5 | | ||
271 | EDMA_ERR_UNDERRUN_5 | | ||
272 | EDMA_ERR_SELF_DIS_5 | | ||
273 | EDMA_ERR_CRBQ_PAR | | ||
274 | EDMA_ERR_CRPB_PAR | | ||
275 | EDMA_ERR_INTRL_PAR | | ||
276 | EDMA_ERR_IORDY, | ||
258 | 277 | ||
259 | EDMA_REQ_Q_BASE_HI_OFS = 0x10, | 278 | EDMA_REQ_Q_BASE_HI_OFS = 0x10, |
260 | EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */ | 279 | EDMA_REQ_Q_IN_PTR_OFS = 0x14, /* also contains BASE_LO */ |
@@ -282,18 +301,18 @@ enum { | |||
282 | MV_HP_ERRATA_60X1B2 = (1 << 3), | 301 | MV_HP_ERRATA_60X1B2 = (1 << 3), |
283 | MV_HP_ERRATA_60X1C0 = (1 << 4), | 302 | MV_HP_ERRATA_60X1C0 = (1 << 4), |
284 | MV_HP_ERRATA_XX42A0 = (1 << 5), | 303 | MV_HP_ERRATA_XX42A0 = (1 << 5), |
285 | MV_HP_50XX = (1 << 6), | 304 | MV_HP_GEN_I = (1 << 6), |
286 | MV_HP_GEN_IIE = (1 << 7), | 305 | MV_HP_GEN_II = (1 << 7), |
306 | MV_HP_GEN_IIE = (1 << 8), | ||
287 | 307 | ||
288 | /* Port private flags (pp_flags) */ | 308 | /* Port private flags (pp_flags) */ |
289 | MV_PP_FLAG_EDMA_EN = (1 << 0), | 309 | MV_PP_FLAG_EDMA_EN = (1 << 0), |
290 | MV_PP_FLAG_EDMA_DS_ACT = (1 << 1), | 310 | MV_PP_FLAG_EDMA_DS_ACT = (1 << 1), |
311 | MV_PP_FLAG_HAD_A_RESET = (1 << 2), | ||
291 | }; | 312 | }; |
292 | 313 | ||
293 | #define IS_50XX(hpriv) ((hpriv)->hp_flags & MV_HP_50XX) | 314 | #define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I) |
294 | #define IS_60XX(hpriv) (((hpriv)->hp_flags & MV_HP_50XX) == 0) | 315 | #define IS_GEN_II(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_II) |
295 | #define IS_GEN_I(hpriv) IS_50XX(hpriv) | ||
296 | #define IS_GEN_II(hpriv) IS_60XX(hpriv) | ||
297 | #define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE) | 316 | #define IS_GEN_IIE(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_IIE) |
298 | 317 | ||
299 | enum { | 318 | enum { |
@@ -352,6 +371,10 @@ struct mv_port_priv { | |||
352 | dma_addr_t crpb_dma; | 371 | dma_addr_t crpb_dma; |
353 | struct mv_sg *sg_tbl; | 372 | struct mv_sg *sg_tbl; |
354 | dma_addr_t sg_tbl_dma; | 373 | dma_addr_t sg_tbl_dma; |
374 | |||
375 | unsigned int req_idx; | ||
376 | unsigned int resp_idx; | ||
377 | |||
355 | u32 pp_flags; | 378 | u32 pp_flags; |
356 | }; | 379 | }; |
357 | 380 | ||
@@ -384,14 +407,15 @@ static u32 mv_scr_read(struct ata_port *ap, unsigned int sc_reg_in); | |||
384 | static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); | 407 | static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); |
385 | static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in); | 408 | static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in); |
386 | static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); | 409 | static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); |
387 | static void mv_phy_reset(struct ata_port *ap); | ||
388 | static void __mv_phy_reset(struct ata_port *ap, int can_sleep); | ||
389 | static int mv_port_start(struct ata_port *ap); | 410 | static int mv_port_start(struct ata_port *ap); |
390 | static void mv_port_stop(struct ata_port *ap); | 411 | static void mv_port_stop(struct ata_port *ap); |
391 | static void mv_qc_prep(struct ata_queued_cmd *qc); | 412 | static void mv_qc_prep(struct ata_queued_cmd *qc); |
392 | static void mv_qc_prep_iie(struct ata_queued_cmd *qc); | 413 | static void mv_qc_prep_iie(struct ata_queued_cmd *qc); |
393 | static unsigned int mv_qc_issue(struct ata_queued_cmd *qc); | 414 | static unsigned int mv_qc_issue(struct ata_queued_cmd *qc); |
394 | static void mv_eng_timeout(struct ata_port *ap); | 415 | static void mv_error_handler(struct ata_port *ap); |
416 | static void mv_post_int_cmd(struct ata_queued_cmd *qc); | ||
417 | static void mv_eh_freeze(struct ata_port *ap); | ||
418 | static void mv_eh_thaw(struct ata_port *ap); | ||
395 | static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); | 419 | static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); |
396 | 420 | ||
397 | static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, | 421 | static void mv5_phy_errata(struct mv_host_priv *hpriv, void __iomem *mmio, |
@@ -415,14 +439,31 @@ static void mv6_reset_flash(struct mv_host_priv *hpriv, void __iomem *mmio); | |||
415 | static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio); | 439 | static void mv_reset_pci_bus(struct pci_dev *pdev, void __iomem *mmio); |
416 | static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, | 440 | static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, |
417 | unsigned int port_no); | 441 | unsigned int port_no); |
418 | static void mv_stop_and_reset(struct ata_port *ap); | ||
419 | 442 | ||
420 | static struct scsi_host_template mv_sht = { | 443 | static struct scsi_host_template mv5_sht = { |
444 | .module = THIS_MODULE, | ||
445 | .name = DRV_NAME, | ||
446 | .ioctl = ata_scsi_ioctl, | ||
447 | .queuecommand = ata_scsi_queuecmd, | ||
448 | .can_queue = ATA_DEF_QUEUE, | ||
449 | .this_id = ATA_SHT_THIS_ID, | ||
450 | .sg_tablesize = MV_MAX_SG_CT, | ||
451 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, | ||
452 | .emulated = ATA_SHT_EMULATED, | ||
453 | .use_clustering = 1, | ||
454 | .proc_name = DRV_NAME, | ||
455 | .dma_boundary = MV_DMA_BOUNDARY, | ||
456 | .slave_configure = ata_scsi_slave_config, | ||
457 | .slave_destroy = ata_scsi_slave_destroy, | ||
458 | .bios_param = ata_std_bios_param, | ||
459 | }; | ||
460 | |||
461 | static struct scsi_host_template mv6_sht = { | ||
421 | .module = THIS_MODULE, | 462 | .module = THIS_MODULE, |
422 | .name = DRV_NAME, | 463 | .name = DRV_NAME, |
423 | .ioctl = ata_scsi_ioctl, | 464 | .ioctl = ata_scsi_ioctl, |
424 | .queuecommand = ata_scsi_queuecmd, | 465 | .queuecommand = ata_scsi_queuecmd, |
425 | .can_queue = MV_USE_Q_DEPTH, | 466 | .can_queue = ATA_DEF_QUEUE, |
426 | .this_id = ATA_SHT_THIS_ID, | 467 | .this_id = ATA_SHT_THIS_ID, |
427 | .sg_tablesize = MV_MAX_SG_CT, | 468 | .sg_tablesize = MV_MAX_SG_CT, |
428 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, | 469 | .cmd_per_lun = ATA_SHT_CMD_PER_LUN, |
@@ -444,19 +485,21 @@ static const struct ata_port_operations mv5_ops = { | |||
444 | .exec_command = ata_exec_command, | 485 | .exec_command = ata_exec_command, |
445 | .dev_select = ata_std_dev_select, | 486 | .dev_select = ata_std_dev_select, |
446 | 487 | ||
447 | .phy_reset = mv_phy_reset, | ||
448 | .cable_detect = ata_cable_sata, | 488 | .cable_detect = ata_cable_sata, |
449 | 489 | ||
450 | .qc_prep = mv_qc_prep, | 490 | .qc_prep = mv_qc_prep, |
451 | .qc_issue = mv_qc_issue, | 491 | .qc_issue = mv_qc_issue, |
452 | .data_xfer = ata_data_xfer, | 492 | .data_xfer = ata_data_xfer, |
453 | 493 | ||
454 | .eng_timeout = mv_eng_timeout, | ||
455 | |||
456 | .irq_clear = mv_irq_clear, | 494 | .irq_clear = mv_irq_clear, |
457 | .irq_on = ata_irq_on, | 495 | .irq_on = ata_irq_on, |
458 | .irq_ack = ata_irq_ack, | 496 | .irq_ack = ata_irq_ack, |
459 | 497 | ||
498 | .error_handler = mv_error_handler, | ||
499 | .post_internal_cmd = mv_post_int_cmd, | ||
500 | .freeze = mv_eh_freeze, | ||
501 | .thaw = mv_eh_thaw, | ||
502 | |||
460 | .scr_read = mv5_scr_read, | 503 | .scr_read = mv5_scr_read, |
461 | .scr_write = mv5_scr_write, | 504 | .scr_write = mv5_scr_write, |
462 | 505 | ||
@@ -473,19 +516,21 @@ static const struct ata_port_operations mv6_ops = { | |||
473 | .exec_command = ata_exec_command, | 516 | .exec_command = ata_exec_command, |
474 | .dev_select = ata_std_dev_select, | 517 | .dev_select = ata_std_dev_select, |
475 | 518 | ||
476 | .phy_reset = mv_phy_reset, | ||
477 | .cable_detect = ata_cable_sata, | 519 | .cable_detect = ata_cable_sata, |
478 | 520 | ||
479 | .qc_prep = mv_qc_prep, | 521 | .qc_prep = mv_qc_prep, |
480 | .qc_issue = mv_qc_issue, | 522 | .qc_issue = mv_qc_issue, |
481 | .data_xfer = ata_data_xfer, | 523 | .data_xfer = ata_data_xfer, |
482 | 524 | ||
483 | .eng_timeout = mv_eng_timeout, | ||
484 | |||
485 | .irq_clear = mv_irq_clear, | 525 | .irq_clear = mv_irq_clear, |
486 | .irq_on = ata_irq_on, | 526 | .irq_on = ata_irq_on, |
487 | .irq_ack = ata_irq_ack, | 527 | .irq_ack = ata_irq_ack, |
488 | 528 | ||
529 | .error_handler = mv_error_handler, | ||
530 | .post_internal_cmd = mv_post_int_cmd, | ||
531 | .freeze = mv_eh_freeze, | ||
532 | .thaw = mv_eh_thaw, | ||
533 | |||
489 | .scr_read = mv_scr_read, | 534 | .scr_read = mv_scr_read, |
490 | .scr_write = mv_scr_write, | 535 | .scr_write = mv_scr_write, |
491 | 536 | ||
@@ -502,19 +547,21 @@ static const struct ata_port_operations mv_iie_ops = { | |||
502 | .exec_command = ata_exec_command, | 547 | .exec_command = ata_exec_command, |
503 | .dev_select = ata_std_dev_select, | 548 | .dev_select = ata_std_dev_select, |
504 | 549 | ||
505 | .phy_reset = mv_phy_reset, | ||
506 | .cable_detect = ata_cable_sata, | 550 | .cable_detect = ata_cable_sata, |
507 | 551 | ||
508 | .qc_prep = mv_qc_prep_iie, | 552 | .qc_prep = mv_qc_prep_iie, |
509 | .qc_issue = mv_qc_issue, | 553 | .qc_issue = mv_qc_issue, |
510 | .data_xfer = ata_data_xfer, | 554 | .data_xfer = ata_data_xfer, |
511 | 555 | ||
512 | .eng_timeout = mv_eng_timeout, | ||
513 | |||
514 | .irq_clear = mv_irq_clear, | 556 | .irq_clear = mv_irq_clear, |
515 | .irq_on = ata_irq_on, | 557 | .irq_on = ata_irq_on, |
516 | .irq_ack = ata_irq_ack, | 558 | .irq_ack = ata_irq_ack, |
517 | 559 | ||
560 | .error_handler = mv_error_handler, | ||
561 | .post_internal_cmd = mv_post_int_cmd, | ||
562 | .freeze = mv_eh_freeze, | ||
563 | .thaw = mv_eh_thaw, | ||
564 | |||
518 | .scr_read = mv_scr_read, | 565 | .scr_read = mv_scr_read, |
519 | .scr_write = mv_scr_write, | 566 | .scr_write = mv_scr_write, |
520 | 567 | ||
@@ -530,38 +577,38 @@ static const struct ata_port_info mv_port_info[] = { | |||
530 | .port_ops = &mv5_ops, | 577 | .port_ops = &mv5_ops, |
531 | }, | 578 | }, |
532 | { /* chip_508x */ | 579 | { /* chip_508x */ |
533 | .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), | 580 | .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC, |
534 | .pio_mask = 0x1f, /* pio0-4 */ | 581 | .pio_mask = 0x1f, /* pio0-4 */ |
535 | .udma_mask = ATA_UDMA6, | 582 | .udma_mask = ATA_UDMA6, |
536 | .port_ops = &mv5_ops, | 583 | .port_ops = &mv5_ops, |
537 | }, | 584 | }, |
538 | { /* chip_5080 */ | 585 | { /* chip_5080 */ |
539 | .flags = (MV_COMMON_FLAGS | MV_FLAG_DUAL_HC), | 586 | .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC, |
540 | .pio_mask = 0x1f, /* pio0-4 */ | 587 | .pio_mask = 0x1f, /* pio0-4 */ |
541 | .udma_mask = ATA_UDMA6, | 588 | .udma_mask = ATA_UDMA6, |
542 | .port_ops = &mv5_ops, | 589 | .port_ops = &mv5_ops, |
543 | }, | 590 | }, |
544 | { /* chip_604x */ | 591 | { /* chip_604x */ |
545 | .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), | 592 | .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS, |
546 | .pio_mask = 0x1f, /* pio0-4 */ | 593 | .pio_mask = 0x1f, /* pio0-4 */ |
547 | .udma_mask = ATA_UDMA6, | 594 | .udma_mask = ATA_UDMA6, |
548 | .port_ops = &mv6_ops, | 595 | .port_ops = &mv6_ops, |
549 | }, | 596 | }, |
550 | { /* chip_608x */ | 597 | { /* chip_608x */ |
551 | .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS | | 598 | .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | |
552 | MV_FLAG_DUAL_HC), | 599 | MV_FLAG_DUAL_HC, |
553 | .pio_mask = 0x1f, /* pio0-4 */ | 600 | .pio_mask = 0x1f, /* pio0-4 */ |
554 | .udma_mask = ATA_UDMA6, | 601 | .udma_mask = ATA_UDMA6, |
555 | .port_ops = &mv6_ops, | 602 | .port_ops = &mv6_ops, |
556 | }, | 603 | }, |
557 | { /* chip_6042 */ | 604 | { /* chip_6042 */ |
558 | .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), | 605 | .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS, |
559 | .pio_mask = 0x1f, /* pio0-4 */ | 606 | .pio_mask = 0x1f, /* pio0-4 */ |
560 | .udma_mask = ATA_UDMA6, | 607 | .udma_mask = ATA_UDMA6, |
561 | .port_ops = &mv_iie_ops, | 608 | .port_ops = &mv_iie_ops, |
562 | }, | 609 | }, |
563 | { /* chip_7042 */ | 610 | { /* chip_7042 */ |
564 | .flags = (MV_COMMON_FLAGS | MV_6XXX_FLAGS), | 611 | .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS, |
565 | .pio_mask = 0x1f, /* pio0-4 */ | 612 | .pio_mask = 0x1f, /* pio0-4 */ |
566 | .udma_mask = ATA_UDMA6, | 613 | .udma_mask = ATA_UDMA6, |
567 | .port_ops = &mv_iie_ops, | 614 | .port_ops = &mv_iie_ops, |
@@ -709,6 +756,46 @@ static void mv_irq_clear(struct ata_port *ap) | |||
709 | { | 756 | { |
710 | } | 757 | } |
711 | 758 | ||
759 | static void mv_set_edma_ptrs(void __iomem *port_mmio, | ||
760 | struct mv_host_priv *hpriv, | ||
761 | struct mv_port_priv *pp) | ||
762 | { | ||
763 | u32 index; | ||
764 | |||
765 | /* | ||
766 | * initialize request queue | ||
767 | */ | ||
768 | index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT; | ||
769 | |||
770 | WARN_ON(pp->crqb_dma & 0x3ff); | ||
771 | writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); | ||
772 | writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | index, | ||
773 | port_mmio + EDMA_REQ_Q_IN_PTR_OFS); | ||
774 | |||
775 | if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) | ||
776 | writelfl((pp->crqb_dma & 0xffffffff) | index, | ||
777 | port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); | ||
778 | else | ||
779 | writelfl(index, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); | ||
780 | |||
781 | /* | ||
782 | * initialize response queue | ||
783 | */ | ||
784 | index = (pp->resp_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_RSP_Q_PTR_SHIFT; | ||
785 | |||
786 | WARN_ON(pp->crpb_dma & 0xff); | ||
787 | writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS); | ||
788 | |||
789 | if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) | ||
790 | writelfl((pp->crpb_dma & 0xffffffff) | index, | ||
791 | port_mmio + EDMA_RSP_Q_IN_PTR_OFS); | ||
792 | else | ||
793 | writelfl(index, port_mmio + EDMA_RSP_Q_IN_PTR_OFS); | ||
794 | |||
795 | writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | index, | ||
796 | port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); | ||
797 | } | ||
798 | |||
712 | /** | 799 | /** |
713 | * mv_start_dma - Enable eDMA engine | 800 | * mv_start_dma - Enable eDMA engine |
714 | * @base: port base address | 801 | * @base: port base address |
@@ -720,9 +807,15 @@ static void mv_irq_clear(struct ata_port *ap) | |||
720 | * LOCKING: | 807 | * LOCKING: |
721 | * Inherited from caller. | 808 | * Inherited from caller. |
722 | */ | 809 | */ |
723 | static void mv_start_dma(void __iomem *base, struct mv_port_priv *pp) | 810 | static void mv_start_dma(void __iomem *base, struct mv_host_priv *hpriv, |
811 | struct mv_port_priv *pp) | ||
724 | { | 812 | { |
725 | if (!(MV_PP_FLAG_EDMA_EN & pp->pp_flags)) { | 813 | if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) { |
814 | /* clear EDMA event indicators, if any */ | ||
815 | writelfl(0, base + EDMA_ERR_IRQ_CAUSE_OFS); | ||
816 | |||
817 | mv_set_edma_ptrs(base, hpriv, pp); | ||
818 | |||
726 | writelfl(EDMA_EN, base + EDMA_CMD_OFS); | 819 | writelfl(EDMA_EN, base + EDMA_CMD_OFS); |
727 | pp->pp_flags |= MV_PP_FLAG_EDMA_EN; | 820 | pp->pp_flags |= MV_PP_FLAG_EDMA_EN; |
728 | } | 821 | } |
@@ -739,14 +832,14 @@ static void mv_start_dma(void __iomem *base, struct mv_port_priv *pp) | |||
739 | * LOCKING: | 832 | * LOCKING: |
740 | * Inherited from caller. | 833 | * Inherited from caller. |
741 | */ | 834 | */ |
742 | static void mv_stop_dma(struct ata_port *ap) | 835 | static int mv_stop_dma(struct ata_port *ap) |
743 | { | 836 | { |
744 | void __iomem *port_mmio = mv_ap_base(ap); | 837 | void __iomem *port_mmio = mv_ap_base(ap); |
745 | struct mv_port_priv *pp = ap->private_data; | 838 | struct mv_port_priv *pp = ap->private_data; |
746 | u32 reg; | 839 | u32 reg; |
747 | int i; | 840 | int i, err = 0; |
748 | 841 | ||
749 | if (MV_PP_FLAG_EDMA_EN & pp->pp_flags) { | 842 | if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { |
750 | /* Disable EDMA if active. The disable bit auto clears. | 843 | /* Disable EDMA if active. The disable bit auto clears. |
751 | */ | 844 | */ |
752 | writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); | 845 | writelfl(EDMA_DS, port_mmio + EDMA_CMD_OFS); |
@@ -758,16 +851,18 @@ static void mv_stop_dma(struct ata_port *ap) | |||
758 | /* now properly wait for the eDMA to stop */ | 851 | /* now properly wait for the eDMA to stop */ |
759 | for (i = 1000; i > 0; i--) { | 852 | for (i = 1000; i > 0; i--) { |
760 | reg = readl(port_mmio + EDMA_CMD_OFS); | 853 | reg = readl(port_mmio + EDMA_CMD_OFS); |
761 | if (!(EDMA_EN & reg)) { | 854 | if (!(reg & EDMA_EN)) |
762 | break; | 855 | break; |
763 | } | 856 | |
764 | udelay(100); | 857 | udelay(100); |
765 | } | 858 | } |
766 | 859 | ||
767 | if (EDMA_EN & reg) { | 860 | if (reg & EDMA_EN) { |
768 | ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n"); | 861 | ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n"); |
769 | /* FIXME: Consider doing a reset here to recover */ | 862 | err = -EIO; |
770 | } | 863 | } |
864 | |||
865 | return err; | ||
771 | } | 866 | } |
772 | 867 | ||
773 | #ifdef ATA_DEBUG | 868 | #ifdef ATA_DEBUG |
@@ -884,12 +979,13 @@ static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) | |||
884 | writelfl(val, mv_ap_base(ap) + ofs); | 979 | writelfl(val, mv_ap_base(ap) + ofs); |
885 | } | 980 | } |
886 | 981 | ||
887 | static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio) | 982 | static void mv_edma_cfg(struct ata_port *ap, struct mv_host_priv *hpriv, |
983 | void __iomem *port_mmio) | ||
888 | { | 984 | { |
889 | u32 cfg = readl(port_mmio + EDMA_CFG_OFS); | 985 | u32 cfg = readl(port_mmio + EDMA_CFG_OFS); |
890 | 986 | ||
891 | /* set up non-NCQ EDMA configuration */ | 987 | /* set up non-NCQ EDMA configuration */ |
892 | cfg &= ~(1 << 9); /* disable equeue */ | 988 | cfg &= ~(1 << 9); /* disable eQue */ |
893 | 989 | ||
894 | if (IS_GEN_I(hpriv)) { | 990 | if (IS_GEN_I(hpriv)) { |
895 | cfg &= ~0x1f; /* clear queue depth */ | 991 | cfg &= ~0x1f; /* clear queue depth */ |
@@ -909,7 +1005,7 @@ static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio) | |||
909 | cfg |= (1 << 18); /* enab early completion */ | 1005 | cfg |= (1 << 18); /* enab early completion */ |
910 | cfg |= (1 << 17); /* enab cut-through (dis stor&forwrd) */ | 1006 | cfg |= (1 << 17); /* enab cut-through (dis stor&forwrd) */ |
911 | cfg &= ~(1 << 16); /* dis FIS-based switching (for now) */ | 1007 | cfg &= ~(1 << 16); /* dis FIS-based switching (for now) */ |
912 | cfg &= ~(EDMA_CFG_NCQ | EDMA_CFG_NCQ_GO_ON_ERR); /* clear NCQ */ | 1008 | cfg &= ~(EDMA_CFG_NCQ); /* clear NCQ */ |
913 | } | 1009 | } |
914 | 1010 | ||
915 | writelfl(cfg, port_mmio + EDMA_CFG_OFS); | 1011 | writelfl(cfg, port_mmio + EDMA_CFG_OFS); |
@@ -971,28 +1067,9 @@ static int mv_port_start(struct ata_port *ap) | |||
971 | pp->sg_tbl = mem; | 1067 | pp->sg_tbl = mem; |
972 | pp->sg_tbl_dma = mem_dma; | 1068 | pp->sg_tbl_dma = mem_dma; |
973 | 1069 | ||
974 | mv_edma_cfg(hpriv, port_mmio); | 1070 | mv_edma_cfg(ap, hpriv, port_mmio); |
975 | 1071 | ||
976 | writel((pp->crqb_dma >> 16) >> 16, port_mmio + EDMA_REQ_Q_BASE_HI_OFS); | 1072 | mv_set_edma_ptrs(port_mmio, hpriv, pp); |
977 | writelfl(pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK, | ||
978 | port_mmio + EDMA_REQ_Q_IN_PTR_OFS); | ||
979 | |||
980 | if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) | ||
981 | writelfl(pp->crqb_dma & 0xffffffff, | ||
982 | port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); | ||
983 | else | ||
984 | writelfl(0, port_mmio + EDMA_REQ_Q_OUT_PTR_OFS); | ||
985 | |||
986 | writel((pp->crpb_dma >> 16) >> 16, port_mmio + EDMA_RSP_Q_BASE_HI_OFS); | ||
987 | |||
988 | if (hpriv->hp_flags & MV_HP_ERRATA_XX42A0) | ||
989 | writelfl(pp->crpb_dma & 0xffffffff, | ||
990 | port_mmio + EDMA_RSP_Q_IN_PTR_OFS); | ||
991 | else | ||
992 | writelfl(0, port_mmio + EDMA_RSP_Q_IN_PTR_OFS); | ||
993 | |||
994 | writelfl(pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK, | ||
995 | port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); | ||
996 | 1073 | ||
997 | /* Don't turn on EDMA here...do it before DMA commands only. Else | 1074 | /* Don't turn on EDMA here...do it before DMA commands only. Else |
998 | * we'll be unable to send non-data, PIO, etc due to restricted access | 1075 | * we'll be unable to send non-data, PIO, etc due to restricted access |
@@ -1055,11 +1132,6 @@ static unsigned int mv_fill_sg(struct ata_queued_cmd *qc) | |||
1055 | return n_sg; | 1132 | return n_sg; |
1056 | } | 1133 | } |
1057 | 1134 | ||
1058 | static inline unsigned mv_inc_q_index(unsigned index) | ||
1059 | { | ||
1060 | return (index + 1) & MV_MAX_Q_DEPTH_MASK; | ||
1061 | } | ||
1062 | |||
1063 | static inline void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last) | 1135 | static inline void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last) |
1064 | { | 1136 | { |
1065 | u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS | | 1137 | u16 tmp = data | (addr << CRQB_CMD_ADDR_SHIFT) | CRQB_CMD_CS | |
@@ -1088,7 +1160,7 @@ static void mv_qc_prep(struct ata_queued_cmd *qc) | |||
1088 | u16 flags = 0; | 1160 | u16 flags = 0; |
1089 | unsigned in_index; | 1161 | unsigned in_index; |
1090 | 1162 | ||
1091 | if (ATA_PROT_DMA != qc->tf.protocol) | 1163 | if (qc->tf.protocol != ATA_PROT_DMA) |
1092 | return; | 1164 | return; |
1093 | 1165 | ||
1094 | /* Fill in command request block | 1166 | /* Fill in command request block |
@@ -1097,10 +1169,10 @@ static void mv_qc_prep(struct ata_queued_cmd *qc) | |||
1097 | flags |= CRQB_FLAG_READ; | 1169 | flags |= CRQB_FLAG_READ; |
1098 | WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); | 1170 | WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); |
1099 | flags |= qc->tag << CRQB_TAG_SHIFT; | 1171 | flags |= qc->tag << CRQB_TAG_SHIFT; |
1172 | flags |= qc->tag << CRQB_IOID_SHIFT; /* 50xx appears to ignore this*/ | ||
1100 | 1173 | ||
1101 | /* get current queue index from hardware */ | 1174 | /* get current queue index from software */ |
1102 | in_index = (readl(mv_ap_base(ap) + EDMA_REQ_Q_IN_PTR_OFS) | 1175 | in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; |
1103 | >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; | ||
1104 | 1176 | ||
1105 | pp->crqb[in_index].sg_addr = | 1177 | pp->crqb[in_index].sg_addr = |
1106 | cpu_to_le32(pp->sg_tbl_dma & 0xffffffff); | 1178 | cpu_to_le32(pp->sg_tbl_dma & 0xffffffff); |
@@ -1180,7 +1252,7 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc) | |||
1180 | unsigned in_index; | 1252 | unsigned in_index; |
1181 | u32 flags = 0; | 1253 | u32 flags = 0; |
1182 | 1254 | ||
1183 | if (ATA_PROT_DMA != qc->tf.protocol) | 1255 | if (qc->tf.protocol != ATA_PROT_DMA) |
1184 | return; | 1256 | return; |
1185 | 1257 | ||
1186 | /* Fill in Gen IIE command request block | 1258 | /* Fill in Gen IIE command request block |
@@ -1190,10 +1262,11 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc) | |||
1190 | 1262 | ||
1191 | WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); | 1263 | WARN_ON(MV_MAX_Q_DEPTH <= qc->tag); |
1192 | flags |= qc->tag << CRQB_TAG_SHIFT; | 1264 | flags |= qc->tag << CRQB_TAG_SHIFT; |
1265 | flags |= qc->tag << CRQB_IOID_SHIFT; /* "I/O Id" is -really- | ||
1266 | what we use as our tag */ | ||
1193 | 1267 | ||
1194 | /* get current queue index from hardware */ | 1268 | /* get current queue index from software */ |
1195 | in_index = (readl(mv_ap_base(ap) + EDMA_REQ_Q_IN_PTR_OFS) | 1269 | in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; |
1196 | >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; | ||
1197 | 1270 | ||
1198 | crqb = (struct mv_crqb_iie *) &pp->crqb[in_index]; | 1271 | crqb = (struct mv_crqb_iie *) &pp->crqb[in_index]; |
1199 | crqb->addr = cpu_to_le32(pp->sg_tbl_dma & 0xffffffff); | 1272 | crqb->addr = cpu_to_le32(pp->sg_tbl_dma & 0xffffffff); |
@@ -1241,83 +1314,41 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc) | |||
1241 | */ | 1314 | */ |
1242 | static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) | 1315 | static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) |
1243 | { | 1316 | { |
1244 | void __iomem *port_mmio = mv_ap_base(qc->ap); | 1317 | struct ata_port *ap = qc->ap; |
1245 | struct mv_port_priv *pp = qc->ap->private_data; | 1318 | void __iomem *port_mmio = mv_ap_base(ap); |
1246 | unsigned in_index; | 1319 | struct mv_port_priv *pp = ap->private_data; |
1247 | u32 in_ptr; | 1320 | struct mv_host_priv *hpriv = ap->host->private_data; |
1321 | u32 in_index; | ||
1248 | 1322 | ||
1249 | if (ATA_PROT_DMA != qc->tf.protocol) { | 1323 | if (qc->tf.protocol != ATA_PROT_DMA) { |
1250 | /* We're about to send a non-EDMA capable command to the | 1324 | /* We're about to send a non-EDMA capable command to the |
1251 | * port. Turn off EDMA so there won't be problems accessing | 1325 | * port. Turn off EDMA so there won't be problems accessing |
1252 | * shadow block, etc registers. | 1326 | * shadow block, etc registers. |
1253 | */ | 1327 | */ |
1254 | mv_stop_dma(qc->ap); | 1328 | mv_stop_dma(ap); |
1255 | return ata_qc_issue_prot(qc); | 1329 | return ata_qc_issue_prot(qc); |
1256 | } | 1330 | } |
1257 | 1331 | ||
1258 | in_ptr = readl(port_mmio + EDMA_REQ_Q_IN_PTR_OFS); | 1332 | mv_start_dma(port_mmio, hpriv, pp); |
1259 | in_index = (in_ptr >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; | 1333 | |
1334 | in_index = pp->req_idx & MV_MAX_Q_DEPTH_MASK; | ||
1260 | 1335 | ||
1261 | /* until we do queuing, the queue should be empty at this point */ | 1336 | /* until we do queuing, the queue should be empty at this point */ |
1262 | WARN_ON(in_index != ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) | 1337 | WARN_ON(in_index != ((readl(port_mmio + EDMA_REQ_Q_OUT_PTR_OFS) |
1263 | >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK)); | 1338 | >> EDMA_REQ_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK)); |
1264 | 1339 | ||
1265 | in_index = mv_inc_q_index(in_index); /* now incr producer index */ | 1340 | pp->req_idx++; |
1266 | 1341 | ||
1267 | mv_start_dma(port_mmio, pp); | 1342 | in_index = (pp->req_idx & MV_MAX_Q_DEPTH_MASK) << EDMA_REQ_Q_PTR_SHIFT; |
1268 | 1343 | ||
1269 | /* and write the request in pointer to kick the EDMA to life */ | 1344 | /* and write the request in pointer to kick the EDMA to life */ |
1270 | in_ptr &= EDMA_REQ_Q_BASE_LO_MASK; | 1345 | writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index, |
1271 | in_ptr |= in_index << EDMA_REQ_Q_PTR_SHIFT; | 1346 | port_mmio + EDMA_REQ_Q_IN_PTR_OFS); |
1272 | writelfl(in_ptr, port_mmio + EDMA_REQ_Q_IN_PTR_OFS); | ||
1273 | 1347 | ||
1274 | return 0; | 1348 | return 0; |
1275 | } | 1349 | } |
1276 | 1350 | ||
1277 | /** | 1351 | /** |
1278 | * mv_get_crpb_status - get status from most recently completed cmd | ||
1279 | * @ap: ATA channel to manipulate | ||
1280 | * | ||
1281 | * This routine is for use when the port is in DMA mode, when it | ||
1282 | * will be using the CRPB (command response block) method of | ||
1283 | * returning command completion information. We check indices | ||
1284 | * are good, grab status, and bump the response consumer index to | ||
1285 | * prove that we're up to date. | ||
1286 | * | ||
1287 | * LOCKING: | ||
1288 | * Inherited from caller. | ||
1289 | */ | ||
1290 | static u8 mv_get_crpb_status(struct ata_port *ap) | ||
1291 | { | ||
1292 | void __iomem *port_mmio = mv_ap_base(ap); | ||
1293 | struct mv_port_priv *pp = ap->private_data; | ||
1294 | unsigned out_index; | ||
1295 | u32 out_ptr; | ||
1296 | u8 ata_status; | ||
1297 | |||
1298 | out_ptr = readl(port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); | ||
1299 | out_index = (out_ptr >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; | ||
1300 | |||
1301 | ata_status = le16_to_cpu(pp->crpb[out_index].flags) | ||
1302 | >> CRPB_FLAG_STATUS_SHIFT; | ||
1303 | |||
1304 | /* increment our consumer index... */ | ||
1305 | out_index = mv_inc_q_index(out_index); | ||
1306 | |||
1307 | /* and, until we do NCQ, there should only be 1 CRPB waiting */ | ||
1308 | WARN_ON(out_index != ((readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) | ||
1309 | >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK)); | ||
1310 | |||
1311 | /* write out our inc'd consumer index so EDMA knows we're caught up */ | ||
1312 | out_ptr &= EDMA_RSP_Q_BASE_LO_MASK; | ||
1313 | out_ptr |= out_index << EDMA_RSP_Q_PTR_SHIFT; | ||
1314 | writelfl(out_ptr, port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); | ||
1315 | |||
1316 | /* Return ATA status register for completed CRPB */ | ||
1317 | return ata_status; | ||
1318 | } | ||
1319 | |||
1320 | /** | ||
1321 | * mv_err_intr - Handle error interrupts on the port | 1352 | * mv_err_intr - Handle error interrupts on the port |
1322 | * @ap: ATA channel to manipulate | 1353 | * @ap: ATA channel to manipulate |
1323 | * @reset_allowed: bool: 0 == don't trigger from reset here | 1354 | * @reset_allowed: bool: 0 == don't trigger from reset here |
@@ -1331,30 +1362,191 @@ static u8 mv_get_crpb_status(struct ata_port *ap) | |||
1331 | * LOCKING: | 1362 | * LOCKING: |
1332 | * Inherited from caller. | 1363 | * Inherited from caller. |
1333 | */ | 1364 | */ |
1334 | static void mv_err_intr(struct ata_port *ap, int reset_allowed) | 1365 | static void mv_err_intr(struct ata_port *ap, struct ata_queued_cmd *qc) |
1335 | { | 1366 | { |
1336 | void __iomem *port_mmio = mv_ap_base(ap); | 1367 | void __iomem *port_mmio = mv_ap_base(ap); |
1337 | u32 edma_err_cause, serr = 0; | 1368 | u32 edma_err_cause, eh_freeze_mask, serr = 0; |
1369 | struct mv_port_priv *pp = ap->private_data; | ||
1370 | struct mv_host_priv *hpriv = ap->host->private_data; | ||
1371 | unsigned int edma_enabled = (pp->pp_flags & MV_PP_FLAG_EDMA_EN); | ||
1372 | unsigned int action = 0, err_mask = 0; | ||
1373 | struct ata_eh_info *ehi = &ap->eh_info; | ||
1338 | 1374 | ||
1339 | edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); | 1375 | ata_ehi_clear_desc(ehi); |
1340 | 1376 | ||
1341 | if (EDMA_ERR_SERR & edma_err_cause) { | 1377 | if (!edma_enabled) { |
1378 | /* just a guess: do we need to do this? should we | ||
1379 | * expand this, and do it in all cases? | ||
1380 | */ | ||
1342 | sata_scr_read(ap, SCR_ERROR, &serr); | 1381 | sata_scr_read(ap, SCR_ERROR, &serr); |
1343 | sata_scr_write_flush(ap, SCR_ERROR, serr); | 1382 | sata_scr_write_flush(ap, SCR_ERROR, serr); |
1344 | } | 1383 | } |
1345 | if (EDMA_ERR_SELF_DIS & edma_err_cause) { | 1384 | |
1346 | struct mv_port_priv *pp = ap->private_data; | 1385 | edma_err_cause = readl(port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); |
1347 | pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; | 1386 | |
1387 | ata_ehi_push_desc(ehi, "edma_err 0x%08x", edma_err_cause); | ||
1388 | |||
1389 | /* | ||
1390 | * all generations share these EDMA error cause bits | ||
1391 | */ | ||
1392 | |||
1393 | if (edma_err_cause & EDMA_ERR_DEV) | ||
1394 | err_mask |= AC_ERR_DEV; | ||
1395 | if (edma_err_cause & (EDMA_ERR_D_PAR | EDMA_ERR_PRD_PAR | | ||
1396 | EDMA_ERR_CRBQ_PAR | EDMA_ERR_CRPB_PAR | | ||
1397 | EDMA_ERR_INTRL_PAR)) { | ||
1398 | err_mask |= AC_ERR_ATA_BUS; | ||
1399 | action |= ATA_EH_HARDRESET; | ||
1400 | ata_ehi_push_desc(ehi, ", parity error"); | ||
1401 | } | ||
1402 | if (edma_err_cause & (EDMA_ERR_DEV_DCON | EDMA_ERR_DEV_CON)) { | ||
1403 | ata_ehi_hotplugged(ehi); | ||
1404 | ata_ehi_push_desc(ehi, edma_err_cause & EDMA_ERR_DEV_DCON ? | ||
1405 | ", dev disconnect" : ", dev connect"); | ||
1406 | } | ||
1407 | |||
1408 | if (IS_GEN_I(hpriv)) { | ||
1409 | eh_freeze_mask = EDMA_EH_FREEZE_5; | ||
1410 | |||
1411 | if (edma_err_cause & EDMA_ERR_SELF_DIS_5) { | ||
1412 | struct mv_port_priv *pp = ap->private_data; | ||
1413 | pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; | ||
1414 | ata_ehi_push_desc(ehi, ", EDMA self-disable"); | ||
1415 | } | ||
1416 | } else { | ||
1417 | eh_freeze_mask = EDMA_EH_FREEZE; | ||
1418 | |||
1419 | if (edma_err_cause & EDMA_ERR_SELF_DIS) { | ||
1420 | struct mv_port_priv *pp = ap->private_data; | ||
1421 | pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; | ||
1422 | ata_ehi_push_desc(ehi, ", EDMA self-disable"); | ||
1423 | } | ||
1424 | |||
1425 | if (edma_err_cause & EDMA_ERR_SERR) { | ||
1426 | sata_scr_read(ap, SCR_ERROR, &serr); | ||
1427 | sata_scr_write_flush(ap, SCR_ERROR, serr); | ||
1428 | err_mask = AC_ERR_ATA_BUS; | ||
1429 | action |= ATA_EH_HARDRESET; | ||
1430 | } | ||
1348 | } | 1431 | } |
1349 | DPRINTK(KERN_ERR "ata%u: port error; EDMA err cause: 0x%08x " | ||
1350 | "SERR: 0x%08x\n", ap->print_id, edma_err_cause, serr); | ||
1351 | 1432 | ||
1352 | /* Clear EDMA now that SERR cleanup done */ | 1433 | /* Clear EDMA now that SERR cleanup done */ |
1353 | writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); | 1434 | writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); |
1354 | 1435 | ||
1355 | /* check for fatal here and recover if needed */ | 1436 | if (!err_mask) { |
1356 | if (reset_allowed && (EDMA_ERR_FATAL & edma_err_cause)) | 1437 | err_mask = AC_ERR_OTHER; |
1357 | mv_stop_and_reset(ap); | 1438 | action |= ATA_EH_HARDRESET; |
1439 | } | ||
1440 | |||
1441 | ehi->serror |= serr; | ||
1442 | ehi->action |= action; | ||
1443 | |||
1444 | if (qc) | ||
1445 | qc->err_mask |= err_mask; | ||
1446 | else | ||
1447 | ehi->err_mask |= err_mask; | ||
1448 | |||
1449 | if (edma_err_cause & eh_freeze_mask) | ||
1450 | ata_port_freeze(ap); | ||
1451 | else | ||
1452 | ata_port_abort(ap); | ||
1453 | } | ||
1454 | |||
1455 | static void mv_intr_pio(struct ata_port *ap) | ||
1456 | { | ||
1457 | struct ata_queued_cmd *qc; | ||
1458 | u8 ata_status; | ||
1459 | |||
1460 | /* ignore spurious intr if drive still BUSY */ | ||
1461 | ata_status = readb(ap->ioaddr.status_addr); | ||
1462 | if (unlikely(ata_status & ATA_BUSY)) | ||
1463 | return; | ||
1464 | |||
1465 | /* get active ATA command */ | ||
1466 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
1467 | if (unlikely(!qc)) /* no active tag */ | ||
1468 | return; | ||
1469 | if (qc->tf.flags & ATA_TFLAG_POLLING) /* polling; we don't own qc */ | ||
1470 | return; | ||
1471 | |||
1472 | /* and finally, complete the ATA command */ | ||
1473 | qc->err_mask |= ac_err_mask(ata_status); | ||
1474 | ata_qc_complete(qc); | ||
1475 | } | ||
1476 | |||
1477 | static void mv_intr_edma(struct ata_port *ap) | ||
1478 | { | ||
1479 | void __iomem *port_mmio = mv_ap_base(ap); | ||
1480 | struct mv_host_priv *hpriv = ap->host->private_data; | ||
1481 | struct mv_port_priv *pp = ap->private_data; | ||
1482 | struct ata_queued_cmd *qc; | ||
1483 | u32 out_index, in_index; | ||
1484 | bool work_done = false; | ||
1485 | |||
1486 | /* get h/w response queue pointer */ | ||
1487 | in_index = (readl(port_mmio + EDMA_RSP_Q_IN_PTR_OFS) | ||
1488 | >> EDMA_RSP_Q_PTR_SHIFT) & MV_MAX_Q_DEPTH_MASK; | ||
1489 | |||
1490 | while (1) { | ||
1491 | u16 status; | ||
1492 | |||
1493 | /* get s/w response queue last-read pointer, and compare */ | ||
1494 | out_index = pp->resp_idx & MV_MAX_Q_DEPTH_MASK; | ||
1495 | if (in_index == out_index) | ||
1496 | break; | ||
1497 | |||
1498 | |||
1499 | /* 50xx: get active ATA command */ | ||
1500 | if (IS_GEN_I(hpriv)) | ||
1501 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
1502 | |||
1503 | /* 60xx: get active ATA command via tag, to enable support | ||
1504 | * for queueing. this works transparently for queued and | ||
1505 | * non-queued modes. | ||
1506 | */ | ||
1507 | else { | ||
1508 | unsigned int tag; | ||
1509 | |||
1510 | if (IS_GEN_II(hpriv)) | ||
1511 | tag = (le16_to_cpu(pp->crpb[out_index].id) | ||
1512 | >> CRPB_IOID_SHIFT_6) & 0x3f; | ||
1513 | else | ||
1514 | tag = (le16_to_cpu(pp->crpb[out_index].id) | ||
1515 | >> CRPB_IOID_SHIFT_7) & 0x3f; | ||
1516 | |||
1517 | qc = ata_qc_from_tag(ap, tag); | ||
1518 | } | ||
1519 | |||
1520 | /* lower 8 bits of status are EDMA_ERR_IRQ_CAUSE_OFS | ||
1521 | * bits (WARNING: might not necessarily be associated | ||
1522 | * with this command), which -should- be clear | ||
1523 | * if all is well | ||
1524 | */ | ||
1525 | status = le16_to_cpu(pp->crpb[out_index].flags); | ||
1526 | if (unlikely(status & 0xff)) { | ||
1527 | mv_err_intr(ap, qc); | ||
1528 | return; | ||
1529 | } | ||
1530 | |||
1531 | /* and finally, complete the ATA command */ | ||
1532 | if (qc) { | ||
1533 | qc->err_mask |= | ||
1534 | ac_err_mask(status >> CRPB_FLAG_STATUS_SHIFT); | ||
1535 | ata_qc_complete(qc); | ||
1536 | } | ||
1537 | |||
1538 | /* advance software response queue pointer, to | ||
1539 | * indicate (after the loop completes) to hardware | ||
1540 | * that we have consumed a response queue entry. | ||
1541 | */ | ||
1542 | work_done = true; | ||
1543 | pp->resp_idx++; | ||
1544 | } | ||
1545 | |||
1546 | if (work_done) | ||
1547 | writelfl((pp->crpb_dma & EDMA_RSP_Q_BASE_LO_MASK) | | ||
1548 | (out_index << EDMA_RSP_Q_PTR_SHIFT), | ||
1549 | port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); | ||
1358 | } | 1550 | } |
1359 | 1551 | ||
1360 | /** | 1552 | /** |
@@ -1377,10 +1569,8 @@ static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc) | |||
1377 | { | 1569 | { |
1378 | void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; | 1570 | void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; |
1379 | void __iomem *hc_mmio = mv_hc_base(mmio, hc); | 1571 | void __iomem *hc_mmio = mv_hc_base(mmio, hc); |
1380 | struct ata_queued_cmd *qc; | ||
1381 | u32 hc_irq_cause; | 1572 | u32 hc_irq_cause; |
1382 | int shift, port, port0, hard_port, handled; | 1573 | int port, port0; |
1383 | unsigned int err_mask; | ||
1384 | 1574 | ||
1385 | if (hc == 0) | 1575 | if (hc == 0) |
1386 | port0 = 0; | 1576 | port0 = 0; |
@@ -1389,79 +1579,95 @@ static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc) | |||
1389 | 1579 | ||
1390 | /* we'll need the HC success int register in most cases */ | 1580 | /* we'll need the HC success int register in most cases */ |
1391 | hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); | 1581 | hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); |
1392 | if (hc_irq_cause) | 1582 | if (!hc_irq_cause) |
1393 | writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); | 1583 | return; |
1584 | |||
1585 | writelfl(~hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); | ||
1394 | 1586 | ||
1395 | VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n", | 1587 | VPRINTK("ENTER, hc%u relevant=0x%08x HC IRQ cause=0x%08x\n", |
1396 | hc,relevant,hc_irq_cause); | 1588 | hc,relevant,hc_irq_cause); |
1397 | 1589 | ||
1398 | for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) { | 1590 | for (port = port0; port < port0 + MV_PORTS_PER_HC; port++) { |
1399 | u8 ata_status = 0; | ||
1400 | struct ata_port *ap = host->ports[port]; | 1591 | struct ata_port *ap = host->ports[port]; |
1401 | struct mv_port_priv *pp = ap->private_data; | 1592 | struct mv_port_priv *pp = ap->private_data; |
1593 | int have_err_bits, hard_port, shift; | ||
1594 | |||
1595 | if ((!ap) || (ap->flags & ATA_FLAG_DISABLED)) | ||
1596 | continue; | ||
1597 | |||
1598 | shift = port << 1; /* (port * 2) */ | ||
1599 | if (port >= MV_PORTS_PER_HC) { | ||
1600 | shift++; /* skip bit 8 in the HC Main IRQ reg */ | ||
1601 | } | ||
1602 | have_err_bits = ((PORT0_ERR << shift) & relevant); | ||
1603 | |||
1604 | if (unlikely(have_err_bits)) { | ||
1605 | struct ata_queued_cmd *qc; | ||
1606 | |||
1607 | qc = ata_qc_from_tag(ap, ap->active_tag); | ||
1608 | if (qc && (qc->tf.flags & ATA_TFLAG_POLLING)) | ||
1609 | continue; | ||
1610 | |||
1611 | mv_err_intr(ap, qc); | ||
1612 | continue; | ||
1613 | } | ||
1402 | 1614 | ||
1403 | hard_port = mv_hardport_from_port(port); /* range 0..3 */ | 1615 | hard_port = mv_hardport_from_port(port); /* range 0..3 */ |
1404 | handled = 0; /* ensure ata_status is set if handled++ */ | ||
1405 | 1616 | ||
1406 | /* Note that DEV_IRQ might happen spuriously during EDMA, | ||
1407 | * and should be ignored in such cases. | ||
1408 | * The cause of this is still under investigation. | ||
1409 | */ | ||
1410 | if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { | 1617 | if (pp->pp_flags & MV_PP_FLAG_EDMA_EN) { |
1411 | /* EDMA: check for response queue interrupt */ | 1618 | if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) |
1412 | if ((CRPB_DMA_DONE << hard_port) & hc_irq_cause) { | 1619 | mv_intr_edma(ap); |
1413 | ata_status = mv_get_crpb_status(ap); | ||
1414 | handled = 1; | ||
1415 | } | ||
1416 | } else { | 1620 | } else { |
1417 | /* PIO: check for device (drive) interrupt */ | 1621 | if ((DEV_IRQ << hard_port) & hc_irq_cause) |
1418 | if ((DEV_IRQ << hard_port) & hc_irq_cause) { | 1622 | mv_intr_pio(ap); |
1419 | ata_status = readb(ap->ioaddr.status_addr); | ||
1420 | handled = 1; | ||
1421 | /* ignore spurious intr if drive still BUSY */ | ||
1422 | if (ata_status & ATA_BUSY) { | ||
1423 | ata_status = 0; | ||
1424 | handled = 0; | ||
1425 | } | ||
1426 | } | ||
1427 | } | 1623 | } |
1624 | } | ||
1625 | VPRINTK("EXIT\n"); | ||
1626 | } | ||
1428 | 1627 | ||
1429 | if (ap && (ap->flags & ATA_FLAG_DISABLED)) | 1628 | static void mv_pci_error(struct ata_host *host, void __iomem *mmio) |
1430 | continue; | 1629 | { |
1630 | struct ata_port *ap; | ||
1631 | struct ata_queued_cmd *qc; | ||
1632 | struct ata_eh_info *ehi; | ||
1633 | unsigned int i, err_mask, printed = 0; | ||
1634 | u32 err_cause; | ||
1431 | 1635 | ||
1432 | err_mask = ac_err_mask(ata_status); | 1636 | err_cause = readl(mmio + PCI_IRQ_CAUSE_OFS); |
1433 | 1637 | ||
1434 | shift = port << 1; /* (port * 2) */ | 1638 | dev_printk(KERN_ERR, host->dev, "PCI ERROR; PCI IRQ cause=0x%08x\n", |
1435 | if (port >= MV_PORTS_PER_HC) { | 1639 | err_cause); |
1436 | shift++; /* skip bit 8 in the HC Main IRQ reg */ | 1640 | |
1437 | } | 1641 | DPRINTK("All regs @ PCI error\n"); |
1438 | if ((PORT0_ERR << shift) & relevant) { | 1642 | mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev)); |
1439 | mv_err_intr(ap, 1); | 1643 | |
1440 | err_mask |= AC_ERR_OTHER; | 1644 | writelfl(0, mmio + PCI_IRQ_CAUSE_OFS); |
1441 | handled = 1; | ||
1442 | } | ||
1443 | 1645 | ||
1444 | if (handled) { | 1646 | for (i = 0; i < host->n_ports; i++) { |
1647 | ap = host->ports[i]; | ||
1648 | if (!ata_port_offline(ap)) { | ||
1649 | ehi = &ap->eh_info; | ||
1650 | ata_ehi_clear_desc(ehi); | ||
1651 | if (!printed++) | ||
1652 | ata_ehi_push_desc(ehi, | ||
1653 | "PCI err cause 0x%08x", err_cause); | ||
1654 | err_mask = AC_ERR_HOST_BUS; | ||
1655 | ehi->action = ATA_EH_HARDRESET; | ||
1445 | qc = ata_qc_from_tag(ap, ap->active_tag); | 1656 | qc = ata_qc_from_tag(ap, ap->active_tag); |
1446 | if (qc && (qc->flags & ATA_QCFLAG_ACTIVE)) { | 1657 | if (qc) |
1447 | VPRINTK("port %u IRQ found for qc, " | 1658 | qc->err_mask |= err_mask; |
1448 | "ata_status 0x%x\n", port,ata_status); | 1659 | else |
1449 | /* mark qc status appropriately */ | 1660 | ehi->err_mask |= err_mask; |
1450 | if (!(qc->tf.flags & ATA_TFLAG_POLLING)) { | 1661 | |
1451 | qc->err_mask |= err_mask; | 1662 | ata_port_freeze(ap); |
1452 | ata_qc_complete(qc); | ||
1453 | } | ||
1454 | } | ||
1455 | } | 1663 | } |
1456 | } | 1664 | } |
1457 | VPRINTK("EXIT\n"); | ||
1458 | } | 1665 | } |
1459 | 1666 | ||
1460 | /** | 1667 | /** |
1461 | * mv_interrupt - | 1668 | * mv_interrupt - Main interrupt event handler |
1462 | * @irq: unused | 1669 | * @irq: unused |
1463 | * @dev_instance: private data; in this case the host structure | 1670 | * @dev_instance: private data; in this case the host structure |
1464 | * @regs: unused | ||
1465 | * | 1671 | * |
1466 | * Read the read only register to determine if any host | 1672 | * Read the read only register to determine if any host |
1467 | * controllers have pending interrupts. If so, call lower level | 1673 | * controllers have pending interrupts. If so, call lower level |
@@ -1477,7 +1683,6 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance) | |||
1477 | struct ata_host *host = dev_instance; | 1683 | struct ata_host *host = dev_instance; |
1478 | unsigned int hc, handled = 0, n_hcs; | 1684 | unsigned int hc, handled = 0, n_hcs; |
1479 | void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; | 1685 | void __iomem *mmio = host->iomap[MV_PRIMARY_BAR]; |
1480 | struct mv_host_priv *hpriv; | ||
1481 | u32 irq_stat; | 1686 | u32 irq_stat; |
1482 | 1687 | ||
1483 | irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS); | 1688 | irq_stat = readl(mmio + HC_MAIN_IRQ_CAUSE_OFS); |
@@ -1491,34 +1696,21 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance) | |||
1491 | n_hcs = mv_get_hc_count(host->ports[0]->flags); | 1696 | n_hcs = mv_get_hc_count(host->ports[0]->flags); |
1492 | spin_lock(&host->lock); | 1697 | spin_lock(&host->lock); |
1493 | 1698 | ||
1699 | if (unlikely(irq_stat & PCI_ERR)) { | ||
1700 | mv_pci_error(host, mmio); | ||
1701 | handled = 1; | ||
1702 | goto out_unlock; /* skip all other HC irq handling */ | ||
1703 | } | ||
1704 | |||
1494 | for (hc = 0; hc < n_hcs; hc++) { | 1705 | for (hc = 0; hc < n_hcs; hc++) { |
1495 | u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT)); | 1706 | u32 relevant = irq_stat & (HC0_IRQ_PEND << (hc * HC_SHIFT)); |
1496 | if (relevant) { | 1707 | if (relevant) { |
1497 | mv_host_intr(host, relevant, hc); | 1708 | mv_host_intr(host, relevant, hc); |
1498 | handled++; | 1709 | handled = 1; |
1499 | } | ||
1500 | } | ||
1501 | |||
1502 | hpriv = host->private_data; | ||
1503 | if (IS_60XX(hpriv)) { | ||
1504 | /* deal with the interrupt coalescing bits */ | ||
1505 | if (irq_stat & (TRAN_LO_DONE | TRAN_HI_DONE | PORTS_0_7_COAL_DONE)) { | ||
1506 | writelfl(0, mmio + MV_IRQ_COAL_CAUSE_LO); | ||
1507 | writelfl(0, mmio + MV_IRQ_COAL_CAUSE_HI); | ||
1508 | writelfl(0, mmio + MV_IRQ_COAL_CAUSE); | ||
1509 | } | 1710 | } |
1510 | } | 1711 | } |
1511 | 1712 | ||
1512 | if (PCI_ERR & irq_stat) { | 1713 | out_unlock: |
1513 | printk(KERN_ERR DRV_NAME ": PCI ERROR; PCI IRQ cause=0x%08x\n", | ||
1514 | readl(mmio + PCI_IRQ_CAUSE_OFS)); | ||
1515 | |||
1516 | DPRINTK("All regs @ PCI error\n"); | ||
1517 | mv_dump_all_regs(mmio, -1, to_pci_dev(host->dev)); | ||
1518 | |||
1519 | writelfl(0, mmio + PCI_IRQ_CAUSE_OFS); | ||
1520 | handled++; | ||
1521 | } | ||
1522 | spin_unlock(&host->lock); | 1714 | spin_unlock(&host->lock); |
1523 | 1715 | ||
1524 | return IRQ_RETVAL(handled); | 1716 | return IRQ_RETVAL(handled); |
@@ -1907,7 +2099,7 @@ static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, | |||
1907 | 2099 | ||
1908 | writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS); | 2100 | writelfl(ATA_RST, port_mmio + EDMA_CMD_OFS); |
1909 | 2101 | ||
1910 | if (IS_60XX(hpriv)) { | 2102 | if (IS_GEN_II(hpriv)) { |
1911 | u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); | 2103 | u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); |
1912 | ifctl |= (1 << 7); /* enable gen2i speed */ | 2104 | ifctl |= (1 << 7); /* enable gen2i speed */ |
1913 | ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ | 2105 | ifctl = (ifctl & 0xfff) | 0x9b1000; /* from chip spec */ |
@@ -1923,32 +2115,12 @@ static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio, | |||
1923 | 2115 | ||
1924 | hpriv->ops->phy_errata(hpriv, mmio, port_no); | 2116 | hpriv->ops->phy_errata(hpriv, mmio, port_no); |
1925 | 2117 | ||
1926 | if (IS_50XX(hpriv)) | 2118 | if (IS_GEN_I(hpriv)) |
1927 | mdelay(1); | 2119 | mdelay(1); |
1928 | } | 2120 | } |
1929 | 2121 | ||
1930 | static void mv_stop_and_reset(struct ata_port *ap) | ||
1931 | { | ||
1932 | struct mv_host_priv *hpriv = ap->host->private_data; | ||
1933 | void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; | ||
1934 | |||
1935 | mv_stop_dma(ap); | ||
1936 | |||
1937 | mv_channel_reset(hpriv, mmio, ap->port_no); | ||
1938 | |||
1939 | __mv_phy_reset(ap, 0); | ||
1940 | } | ||
1941 | |||
1942 | static inline void __msleep(unsigned int msec, int can_sleep) | ||
1943 | { | ||
1944 | if (can_sleep) | ||
1945 | msleep(msec); | ||
1946 | else | ||
1947 | mdelay(msec); | ||
1948 | } | ||
1949 | |||
1950 | /** | 2122 | /** |
1951 | * __mv_phy_reset - Perform eDMA reset followed by COMRESET | 2123 | * mv_phy_reset - Perform eDMA reset followed by COMRESET |
1952 | * @ap: ATA channel to manipulate | 2124 | * @ap: ATA channel to manipulate |
1953 | * | 2125 | * |
1954 | * Part of this is taken from __sata_phy_reset and modified to | 2126 | * Part of this is taken from __sata_phy_reset and modified to |
@@ -1958,14 +2130,12 @@ static inline void __msleep(unsigned int msec, int can_sleep) | |||
1958 | * Inherited from caller. This is coded to safe to call at | 2130 | * Inherited from caller. This is coded to safe to call at |
1959 | * interrupt level, i.e. it does not sleep. | 2131 | * interrupt level, i.e. it does not sleep. |
1960 | */ | 2132 | */ |
1961 | static void __mv_phy_reset(struct ata_port *ap, int can_sleep) | 2133 | static void mv_phy_reset(struct ata_port *ap, unsigned int *class, |
2134 | unsigned long deadline) | ||
1962 | { | 2135 | { |
1963 | struct mv_port_priv *pp = ap->private_data; | 2136 | struct mv_port_priv *pp = ap->private_data; |
1964 | struct mv_host_priv *hpriv = ap->host->private_data; | 2137 | struct mv_host_priv *hpriv = ap->host->private_data; |
1965 | void __iomem *port_mmio = mv_ap_base(ap); | 2138 | void __iomem *port_mmio = mv_ap_base(ap); |
1966 | struct ata_taskfile tf; | ||
1967 | struct ata_device *dev = &ap->device[0]; | ||
1968 | unsigned long timeout; | ||
1969 | int retry = 5; | 2139 | int retry = 5; |
1970 | u32 sstatus; | 2140 | u32 sstatus; |
1971 | 2141 | ||
@@ -1978,22 +2148,21 @@ static void __mv_phy_reset(struct ata_port *ap, int can_sleep) | |||
1978 | /* Issue COMRESET via SControl */ | 2148 | /* Issue COMRESET via SControl */ |
1979 | comreset_retry: | 2149 | comreset_retry: |
1980 | sata_scr_write_flush(ap, SCR_CONTROL, 0x301); | 2150 | sata_scr_write_flush(ap, SCR_CONTROL, 0x301); |
1981 | __msleep(1, can_sleep); | 2151 | msleep(1); |
1982 | 2152 | ||
1983 | sata_scr_write_flush(ap, SCR_CONTROL, 0x300); | 2153 | sata_scr_write_flush(ap, SCR_CONTROL, 0x300); |
1984 | __msleep(20, can_sleep); | 2154 | msleep(20); |
1985 | 2155 | ||
1986 | timeout = jiffies + msecs_to_jiffies(200); | ||
1987 | do { | 2156 | do { |
1988 | sata_scr_read(ap, SCR_STATUS, &sstatus); | 2157 | sata_scr_read(ap, SCR_STATUS, &sstatus); |
1989 | if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0)) | 2158 | if (((sstatus & 0x3) == 3) || ((sstatus & 0x3) == 0)) |
1990 | break; | 2159 | break; |
1991 | 2160 | ||
1992 | __msleep(1, can_sleep); | 2161 | msleep(1); |
1993 | } while (time_before(jiffies, timeout)); | 2162 | } while (time_before(jiffies, deadline)); |
1994 | 2163 | ||
1995 | /* work around errata */ | 2164 | /* work around errata */ |
1996 | if (IS_60XX(hpriv) && | 2165 | if (IS_GEN_II(hpriv) && |
1997 | (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) && | 2166 | (sstatus != 0x0) && (sstatus != 0x113) && (sstatus != 0x123) && |
1998 | (retry-- > 0)) | 2167 | (retry-- > 0)) |
1999 | goto comreset_retry; | 2168 | goto comreset_retry; |
@@ -2002,13 +2171,8 @@ comreset_retry: | |||
2002 | "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), | 2171 | "SCtrl 0x%08x\n", mv_scr_read(ap, SCR_STATUS), |
2003 | mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); | 2172 | mv_scr_read(ap, SCR_ERROR), mv_scr_read(ap, SCR_CONTROL)); |
2004 | 2173 | ||
2005 | if (ata_port_online(ap)) { | 2174 | if (ata_port_offline(ap)) { |
2006 | ata_port_probe(ap); | 2175 | *class = ATA_DEV_NONE; |
2007 | } else { | ||
2008 | sata_scr_read(ap, SCR_STATUS, &sstatus); | ||
2009 | ata_port_printk(ap, KERN_INFO, | ||
2010 | "no device found (phy stat %08x)\n", sstatus); | ||
2011 | ata_port_disable(ap); | ||
2012 | return; | 2176 | return; |
2013 | } | 2177 | } |
2014 | 2178 | ||
@@ -2022,68 +2186,152 @@ comreset_retry: | |||
2022 | u8 drv_stat = ata_check_status(ap); | 2186 | u8 drv_stat = ata_check_status(ap); |
2023 | if ((drv_stat != 0x80) && (drv_stat != 0x7f)) | 2187 | if ((drv_stat != 0x80) && (drv_stat != 0x7f)) |
2024 | break; | 2188 | break; |
2025 | __msleep(500, can_sleep); | 2189 | msleep(500); |
2026 | if (retry-- <= 0) | 2190 | if (retry-- <= 0) |
2027 | break; | 2191 | break; |
2192 | if (time_after(jiffies, deadline)) | ||
2193 | break; | ||
2028 | } | 2194 | } |
2029 | 2195 | ||
2030 | tf.lbah = readb(ap->ioaddr.lbah_addr); | 2196 | /* FIXME: if we passed the deadline, the following |
2031 | tf.lbam = readb(ap->ioaddr.lbam_addr); | 2197 | * code probably produces an invalid result |
2032 | tf.lbal = readb(ap->ioaddr.lbal_addr); | 2198 | */ |
2033 | tf.nsect = readb(ap->ioaddr.nsect_addr); | ||
2034 | 2199 | ||
2035 | dev->class = ata_dev_classify(&tf); | 2200 | /* finally, read device signature from TF registers */ |
2036 | if (!ata_dev_enabled(dev)) { | 2201 | *class = ata_dev_try_classify(ap, 0, NULL); |
2037 | VPRINTK("Port disabled post-sig: No device present.\n"); | ||
2038 | ata_port_disable(ap); | ||
2039 | } | ||
2040 | 2202 | ||
2041 | writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); | 2203 | writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); |
2042 | 2204 | ||
2043 | pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; | 2205 | WARN_ON(pp->pp_flags & MV_PP_FLAG_EDMA_EN); |
2044 | 2206 | ||
2045 | VPRINTK("EXIT\n"); | 2207 | VPRINTK("EXIT\n"); |
2046 | } | 2208 | } |
2047 | 2209 | ||
2048 | static void mv_phy_reset(struct ata_port *ap) | 2210 | static int mv_prereset(struct ata_port *ap, unsigned long deadline) |
2049 | { | 2211 | { |
2050 | __mv_phy_reset(ap, 1); | 2212 | struct mv_port_priv *pp = ap->private_data; |
2213 | struct ata_eh_context *ehc = &ap->eh_context; | ||
2214 | int rc; | ||
2215 | |||
2216 | rc = mv_stop_dma(ap); | ||
2217 | if (rc) | ||
2218 | ehc->i.action |= ATA_EH_HARDRESET; | ||
2219 | |||
2220 | if (!(pp->pp_flags & MV_PP_FLAG_HAD_A_RESET)) { | ||
2221 | pp->pp_flags |= MV_PP_FLAG_HAD_A_RESET; | ||
2222 | ehc->i.action |= ATA_EH_HARDRESET; | ||
2223 | } | ||
2224 | |||
2225 | /* if we're about to do hardreset, nothing more to do */ | ||
2226 | if (ehc->i.action & ATA_EH_HARDRESET) | ||
2227 | return 0; | ||
2228 | |||
2229 | if (ata_port_online(ap)) | ||
2230 | rc = ata_wait_ready(ap, deadline); | ||
2231 | else | ||
2232 | rc = -ENODEV; | ||
2233 | |||
2234 | return rc; | ||
2051 | } | 2235 | } |
2052 | 2236 | ||
2053 | /** | 2237 | static int mv_hardreset(struct ata_port *ap, unsigned int *class, |
2054 | * mv_eng_timeout - Routine called by libata when SCSI times out I/O | 2238 | unsigned long deadline) |
2055 | * @ap: ATA channel to manipulate | ||
2056 | * | ||
2057 | * Intent is to clear all pending error conditions, reset the | ||
2058 | * chip/bus, fail the command, and move on. | ||
2059 | * | ||
2060 | * LOCKING: | ||
2061 | * This routine holds the host lock while failing the command. | ||
2062 | */ | ||
2063 | static void mv_eng_timeout(struct ata_port *ap) | ||
2064 | { | 2239 | { |
2240 | struct mv_host_priv *hpriv = ap->host->private_data; | ||
2065 | void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; | 2241 | void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; |
2066 | struct ata_queued_cmd *qc; | ||
2067 | unsigned long flags; | ||
2068 | 2242 | ||
2069 | ata_port_printk(ap, KERN_ERR, "Entering mv_eng_timeout\n"); | 2243 | mv_stop_dma(ap); |
2070 | DPRINTK("All regs @ start of eng_timeout\n"); | ||
2071 | mv_dump_all_regs(mmio, ap->port_no, to_pci_dev(ap->host->dev)); | ||
2072 | 2244 | ||
2073 | qc = ata_qc_from_tag(ap, ap->active_tag); | 2245 | mv_channel_reset(hpriv, mmio, ap->port_no); |
2074 | printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n", | ||
2075 | mmio, ap, qc, qc->scsicmd, &qc->scsicmd->cmnd); | ||
2076 | 2246 | ||
2077 | spin_lock_irqsave(&ap->host->lock, flags); | 2247 | mv_phy_reset(ap, class, deadline); |
2078 | mv_err_intr(ap, 0); | 2248 | |
2079 | mv_stop_and_reset(ap); | 2249 | return 0; |
2080 | spin_unlock_irqrestore(&ap->host->lock, flags); | 2250 | } |
2251 | |||
2252 | static void mv_postreset(struct ata_port *ap, unsigned int *classes) | ||
2253 | { | ||
2254 | u32 serr; | ||
2255 | |||
2256 | /* print link status */ | ||
2257 | sata_print_link_status(ap); | ||
2258 | |||
2259 | /* clear SError */ | ||
2260 | sata_scr_read(ap, SCR_ERROR, &serr); | ||
2261 | sata_scr_write_flush(ap, SCR_ERROR, serr); | ||
2081 | 2262 | ||
2082 | WARN_ON(!(qc->flags & ATA_QCFLAG_ACTIVE)); | 2263 | /* bail out if no device is present */ |
2083 | if (qc->flags & ATA_QCFLAG_ACTIVE) { | 2264 | if (classes[0] == ATA_DEV_NONE && classes[1] == ATA_DEV_NONE) { |
2084 | qc->err_mask |= AC_ERR_TIMEOUT; | 2265 | DPRINTK("EXIT, no device\n"); |
2085 | ata_eh_qc_complete(qc); | 2266 | return; |
2086 | } | 2267 | } |
2268 | |||
2269 | /* set up device control */ | ||
2270 | iowrite8(ap->ctl, ap->ioaddr.ctl_addr); | ||
2271 | } | ||
2272 | |||
2273 | static void mv_error_handler(struct ata_port *ap) | ||
2274 | { | ||
2275 | ata_do_eh(ap, mv_prereset, ata_std_softreset, | ||
2276 | mv_hardreset, mv_postreset); | ||
2277 | } | ||
2278 | |||
2279 | static void mv_post_int_cmd(struct ata_queued_cmd *qc) | ||
2280 | { | ||
2281 | mv_stop_dma(qc->ap); | ||
2282 | } | ||
2283 | |||
2284 | static void mv_eh_freeze(struct ata_port *ap) | ||
2285 | { | ||
2286 | void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; | ||
2287 | unsigned int hc = (ap->port_no > 3) ? 1 : 0; | ||
2288 | u32 tmp, mask; | ||
2289 | unsigned int shift; | ||
2290 | |||
2291 | /* FIXME: handle coalescing completion events properly */ | ||
2292 | |||
2293 | shift = ap->port_no * 2; | ||
2294 | if (hc > 0) | ||
2295 | shift++; | ||
2296 | |||
2297 | mask = 0x3 << shift; | ||
2298 | |||
2299 | /* disable assertion of portN err, done events */ | ||
2300 | tmp = readl(mmio + HC_MAIN_IRQ_MASK_OFS); | ||
2301 | writelfl(tmp & ~mask, mmio + HC_MAIN_IRQ_MASK_OFS); | ||
2302 | } | ||
2303 | |||
2304 | static void mv_eh_thaw(struct ata_port *ap) | ||
2305 | { | ||
2306 | void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR]; | ||
2307 | unsigned int hc = (ap->port_no > 3) ? 1 : 0; | ||
2308 | void __iomem *hc_mmio = mv_hc_base(mmio, hc); | ||
2309 | void __iomem *port_mmio = mv_ap_base(ap); | ||
2310 | u32 tmp, mask, hc_irq_cause; | ||
2311 | unsigned int shift, hc_port_no = ap->port_no; | ||
2312 | |||
2313 | /* FIXME: handle coalescing completion events properly */ | ||
2314 | |||
2315 | shift = ap->port_no * 2; | ||
2316 | if (hc > 0) { | ||
2317 | shift++; | ||
2318 | hc_port_no -= 4; | ||
2319 | } | ||
2320 | |||
2321 | mask = 0x3 << shift; | ||
2322 | |||
2323 | /* clear EDMA errors on this port */ | ||
2324 | writel(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS); | ||
2325 | |||
2326 | /* clear pending irq events */ | ||
2327 | hc_irq_cause = readl(hc_mmio + HC_IRQ_CAUSE_OFS); | ||
2328 | hc_irq_cause &= ~(1 << hc_port_no); /* clear CRPB-done */ | ||
2329 | hc_irq_cause &= ~(1 << (hc_port_no + 8)); /* clear Device int */ | ||
2330 | writel(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS); | ||
2331 | |||
2332 | /* enable assertion of portN err, done events */ | ||
2333 | tmp = readl(mmio + HC_MAIN_IRQ_MASK_OFS); | ||
2334 | writelfl(tmp | mask, mmio + HC_MAIN_IRQ_MASK_OFS); | ||
2087 | } | 2335 | } |
2088 | 2336 | ||
2089 | /** | 2337 | /** |
@@ -2147,7 +2395,7 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx) | |||
2147 | switch(board_idx) { | 2395 | switch(board_idx) { |
2148 | case chip_5080: | 2396 | case chip_5080: |
2149 | hpriv->ops = &mv5xxx_ops; | 2397 | hpriv->ops = &mv5xxx_ops; |
2150 | hp_flags |= MV_HP_50XX; | 2398 | hp_flags |= MV_HP_GEN_I; |
2151 | 2399 | ||
2152 | switch (rev_id) { | 2400 | switch (rev_id) { |
2153 | case 0x1: | 2401 | case 0x1: |
@@ -2167,7 +2415,7 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx) | |||
2167 | case chip_504x: | 2415 | case chip_504x: |
2168 | case chip_508x: | 2416 | case chip_508x: |
2169 | hpriv->ops = &mv5xxx_ops; | 2417 | hpriv->ops = &mv5xxx_ops; |
2170 | hp_flags |= MV_HP_50XX; | 2418 | hp_flags |= MV_HP_GEN_I; |
2171 | 2419 | ||
2172 | switch (rev_id) { | 2420 | switch (rev_id) { |
2173 | case 0x0: | 2421 | case 0x0: |
@@ -2187,6 +2435,7 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx) | |||
2187 | case chip_604x: | 2435 | case chip_604x: |
2188 | case chip_608x: | 2436 | case chip_608x: |
2189 | hpriv->ops = &mv6xxx_ops; | 2437 | hpriv->ops = &mv6xxx_ops; |
2438 | hp_flags |= MV_HP_GEN_II; | ||
2190 | 2439 | ||
2191 | switch (rev_id) { | 2440 | switch (rev_id) { |
2192 | case 0x7: | 2441 | case 0x7: |
@@ -2206,7 +2455,6 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx) | |||
2206 | case chip_7042: | 2455 | case chip_7042: |
2207 | case chip_6042: | 2456 | case chip_6042: |
2208 | hpriv->ops = &mv6xxx_ops; | 2457 | hpriv->ops = &mv6xxx_ops; |
2209 | |||
2210 | hp_flags |= MV_HP_GEN_IIE; | 2458 | hp_flags |= MV_HP_GEN_IIE; |
2211 | 2459 | ||
2212 | switch (rev_id) { | 2460 | switch (rev_id) { |
@@ -2273,7 +2521,7 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx) | |||
2273 | hpriv->ops->enable_leds(hpriv, mmio); | 2521 | hpriv->ops->enable_leds(hpriv, mmio); |
2274 | 2522 | ||
2275 | for (port = 0; port < host->n_ports; port++) { | 2523 | for (port = 0; port < host->n_ports; port++) { |
2276 | if (IS_60XX(hpriv)) { | 2524 | if (IS_GEN_II(hpriv)) { |
2277 | void __iomem *port_mmio = mv_port_base(mmio, port); | 2525 | void __iomem *port_mmio = mv_port_base(mmio, port); |
2278 | 2526 | ||
2279 | u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); | 2527 | u32 ifctl = readl(port_mmio + SATA_INTERFACE_CTL); |
@@ -2308,7 +2556,7 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx) | |||
2308 | /* and unmask interrupt generation for host regs */ | 2556 | /* and unmask interrupt generation for host regs */ |
2309 | writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS); | 2557 | writelfl(PCI_UNMASK_ALL_IRQS, mmio + PCI_IRQ_MASK_OFS); |
2310 | 2558 | ||
2311 | if (IS_50XX(hpriv)) | 2559 | if (IS_GEN_I(hpriv)) |
2312 | writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS); | 2560 | writelfl(~HC_MAIN_MASKED_IRQS_5, mmio + HC_MAIN_IRQ_MASK_OFS); |
2313 | else | 2561 | else |
2314 | writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS); | 2562 | writelfl(~HC_MAIN_MASKED_IRQS, mmio + HC_MAIN_IRQ_MASK_OFS); |
@@ -2426,8 +2674,9 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
2426 | mv_print_info(host); | 2674 | mv_print_info(host); |
2427 | 2675 | ||
2428 | pci_set_master(pdev); | 2676 | pci_set_master(pdev); |
2677 | pci_set_mwi(pdev); | ||
2429 | return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED, | 2678 | return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED, |
2430 | &mv_sht); | 2679 | IS_GEN_I(hpriv) ? &mv5_sht : &mv6_sht); |
2431 | } | 2680 | } |
2432 | 2681 | ||
2433 | static int __init mv_init(void) | 2682 | static int __init mv_init(void) |