Lines Matching +full:link +full:- +full:loss +full:- +full:low
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * sata_sil24.c - Driver for Silicon Image 3124/3132 SATA-2 controllers
17 #include <linux/dma-mapping.h>
57 SIL24_MAX_SGT = (PAGE_SIZE - SIL24_PRB_SZ)
113 PORT_CTRL_STAT = 0x1000, /* write: ctrl-set, read: stat */
114 PORT_CTRL_CLR = 0x1004, /* write: ctrl-clear */
115 PORT_IRQ_STAT = 0x1008, /* high: status, low: interrupt */
116 PORT_IRQ_ENABLE_SET = 0x1010, /* write: enable-set */
117 PORT_IRQ_ENABLE_CLR = 0x1014, /* write: enable-clear */
135 PORT_EXEC_DIAG = 0x1e00, /* 32bit exec diag * 16 (64 bytes, 0-10 used on 3124) */
136 PORT_PSD_DIAG = 0x1e40, /* 32bit psd diag * 16 (64 bytes, 0-8 used on 3124) */
149 PORT_CS_32BIT_ACTV = (1 << 10), /* 32-bit activation */
177 /* ENABLE_SET/CLR specific, intr steering - 2 bit field */
191 PORT_CERR_SGT_BOUNDARY = 16, /* PLD ecode 00 - SGT not on qword boundary */
192 PORT_CERR_SGT_TGTABRT = 17, /* PLD ecode 01 - target abort */
193 PORT_CERR_SGT_MSTABRT = 18, /* PLD ecode 10 - master abort */
194 PORT_CERR_SGT_PCIPERR = 19, /* PLD ecode 11 - PCI parity err while fetching SGT */
195 PORT_CERR_CMD_BOUNDARY = 24, /* ctrl[15:13] 001 - PRB not on qword boundary */
196 PORT_CERR_CMD_TGTABRT = 25, /* ctrl[15:13] 010 - target abort */
197 PORT_CERR_CMD_MSTABRT = 26, /* ctrl[15:13] 100 - master abort */
198 PORT_CERR_CMD_PCIPERR = 27, /* ctrl[15:13] 110 - PCI parity err while fetching PRB */
199 PORT_CERR_XFR_UNDEF = 32, /* PSD ecode 00 - undefined */
200 PORT_CERR_XFR_TGTABRT = 33, /* PSD ecode 01 - target abort */
201 PORT_CERR_XFR_MSTABRT = 34, /* PSD ecode 10 - master abort */
202 PORT_CERR_XFR_PCIPERR = 35, /* PSD ecode 11 - PCI prity err during transfer */
240 SIL24_FLAG_PCIX_IRQ_WOC = (1 << 24), /* IRQ loss errata on PCI-X */
314 * ap->private_data
326 static int sil24_scr_read(struct ata_link *link, unsigned sc_reg, u32 *val);
327 static int sil24_scr_write(struct ata_link *link, unsigned sc_reg, u32 val);
336 static int sil24_softreset(struct ata_link *link, unsigned int *class,
338 static int sil24_hardreset(struct ata_link *link, unsigned int *class,
340 static int sil24_pmp_hardreset(struct ata_link *link, unsigned int *class,
421 * Use bits 30-31 of port_flags to encode available port numbers.
424 #define SIL24_NPORTS2FLAG(nports) ((((unsigned)(nports) - 1) & 0x3) << 30)
464 return ap->port_no * PORT_REGS_SIZE; in sil24_port_offset()
469 return ap->host->iomap[SIL24_PORT_BAR] + sil24_port_offset(ap); in sil24_port_base()
474 void __iomem *port = sil24_port_base(dev->link->ap); in sil24_dev_config()
476 if (dev->cdb_len == 16) in sil24_dev_config()
489 memcpy_fromio(fis, prb->fis, sizeof(fis)); in sil24_read_tf()
500 static int sil24_scr_read(struct ata_link *link, unsigned sc_reg, u32 *val) in sil24_scr_read() argument
502 void __iomem *scr_addr = sil24_port_base(link->ap) + PORT_SCONTROL; in sil24_scr_read()
508 return -EINVAL; in sil24_scr_read()
511 static int sil24_scr_write(struct ata_link *link, unsigned sc_reg, u32 val) in sil24_scr_write() argument
513 void __iomem *scr_addr = sil24_port_base(link->ap) + PORT_SCONTROL; in sil24_scr_write()
519 return -EINVAL; in sil24_scr_write()
527 if (ap->flags & SIL24_FLAG_PCIX_IRQ_WOC) in sil24_config_port()
575 struct sil24_port_priv *pp = ap->private_data; in sil24_init_port()
589 pp->do_port_rst = 1; in sil24_init_port()
590 ap->link.eh_context.i.action |= ATA_EH_RESET; in sil24_init_port()
591 return -EIO; in sil24_init_port()
603 struct sil24_port_priv *pp = ap->private_data; in sil24_exec_polled_cmd()
604 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb; in sil24_exec_polled_cmd()
605 dma_addr_t paddr = pp->cmd_block_dma; in sil24_exec_polled_cmd()
609 prb->ctrl = cpu_to_le16(ctrl); in sil24_exec_polled_cmd()
610 ata_tf_to_fis(tf, pmp, is_cmd, prb->fis); in sil24_exec_polled_cmd()
638 rc = -EIO; in sil24_exec_polled_cmd()
640 rc = -EBUSY; in sil24_exec_polled_cmd()
649 static int sil24_softreset(struct ata_link *link, unsigned int *class, in sil24_softreset() argument
652 struct ata_port *ap = link->ap; in sil24_softreset()
653 int pmp = sata_srst_pmp(link); in sil24_softreset()
667 timeout_msec = jiffies_to_msecs(deadline - jiffies); in sil24_softreset()
669 ata_tf_init(link->device, &tf); /* doesn't really matter */ in sil24_softreset()
672 if (rc == -EBUSY) { in sil24_softreset()
686 ata_link_err(link, "softreset failed (%s)\n", reason); in sil24_softreset()
687 return -EIO; in sil24_softreset()
690 static int sil24_hardreset(struct ata_link *link, unsigned int *class, in sil24_hardreset() argument
693 struct ata_port *ap = link->ap; in sil24_hardreset()
695 struct sil24_port_priv *pp = ap->private_data; in sil24_hardreset()
705 if (pp->do_port_rst) { in sil24_hardreset()
717 sil24_config_pmp(ap, ap->nr_pmp_links); in sil24_hardreset()
719 pp->do_port_rst = 0; in sil24_hardreset()
724 sata_set_spd(link); in sil24_hardreset()
727 if (ata_link_online(link)) in sil24_hardreset()
738 rc = sata_link_debounce(link, sata_deb_timing_long, deadline); in sil24_hardreset()
745 if (ata_link_offline(link)) in sil24_hardreset()
747 reason = "link not ready"; in sil24_hardreset()
754 * for BSY clearance here. Tell libata to perform follow-up in sil24_hardreset()
757 return -EAGAIN; in sil24_hardreset()
761 pp->do_port_rst = 1; in sil24_hardreset()
765 ata_link_err(link, "hardreset failed (%s)\n", reason); in sil24_hardreset()
766 return -EIO; in sil24_hardreset()
776 for_each_sg(qc->sg, sg, qc->n_elem, si) { in sil24_fill_sg()
777 sge->addr = cpu_to_le64(sg_dma_address(sg)); in sil24_fill_sg()
778 sge->cnt = cpu_to_le32(sg_dma_len(sg)); in sil24_fill_sg()
779 sge->flags = 0; in sil24_fill_sg()
785 last_sge->flags = cpu_to_le32(SGE_TRM); in sil24_fill_sg()
790 struct ata_link *link = qc->dev->link; in sil24_qc_defer() local
791 struct ata_port *ap = link->ap; in sil24_qc_defer()
792 u8 prot = qc->tf.protocol; in sil24_qc_defer()
808 * - ATAPI commands which check the sense data in sil24_qc_defer()
809 * - Passthrough ATA commands which always have ATA_QCFLAG_RESULT_TF in sil24_qc_defer()
814 (qc->flags & ATA_QCFLAG_RESULT_TF)); in sil24_qc_defer()
816 if (unlikely(ap->excl_link)) { in sil24_qc_defer()
817 if (link == ap->excl_link) { in sil24_qc_defer()
818 if (ap->nr_active_links) in sil24_qc_defer()
820 qc->flags |= ATA_QCFLAG_CLEAR_EXCL; in sil24_qc_defer()
824 ap->excl_link = link; in sil24_qc_defer()
825 if (ap->nr_active_links) in sil24_qc_defer()
827 qc->flags |= ATA_QCFLAG_CLEAR_EXCL; in sil24_qc_defer()
835 struct ata_port *ap = qc->ap; in sil24_qc_prep()
836 struct sil24_port_priv *pp = ap->private_data; in sil24_qc_prep()
842 cb = &pp->cmd_block[sil24_tag(qc->hw_tag)]; in sil24_qc_prep()
844 if (!ata_is_atapi(qc->tf.protocol)) { in sil24_qc_prep()
845 prb = &cb->ata.prb; in sil24_qc_prep()
846 sge = cb->ata.sge; in sil24_qc_prep()
847 if (ata_is_data(qc->tf.protocol)) { in sil24_qc_prep()
850 if (ata_is_ncq(qc->tf.protocol)) in sil24_qc_prep()
852 if (qc->tf.flags & ATA_TFLAG_WRITE) in sil24_qc_prep()
856 prb->prot = cpu_to_le16(prot); in sil24_qc_prep()
859 prb = &cb->atapi.prb; in sil24_qc_prep()
860 sge = cb->atapi.sge; in sil24_qc_prep()
861 memset(cb->atapi.cdb, 0, sizeof(cb->atapi.cdb)); in sil24_qc_prep()
862 memcpy(cb->atapi.cdb, qc->cdb, qc->dev->cdb_len); in sil24_qc_prep()
864 if (ata_is_data(qc->tf.protocol)) { in sil24_qc_prep()
865 if (qc->tf.flags & ATA_TFLAG_WRITE) in sil24_qc_prep()
872 prb->ctrl = cpu_to_le16(ctrl); in sil24_qc_prep()
873 ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, prb->fis); in sil24_qc_prep()
875 if (qc->flags & ATA_QCFLAG_DMAMAP) in sil24_qc_prep()
883 struct ata_port *ap = qc->ap; in sil24_qc_issue()
884 struct sil24_port_priv *pp = ap->private_data; in sil24_qc_issue()
886 unsigned int tag = sil24_tag(qc->hw_tag); in sil24_qc_issue()
890 paddr = pp->cmd_block_dma + tag * sizeof(*pp->cmd_block); in sil24_qc_issue()
906 sil24_read_tf(qc->ap, qc->hw_tag, &qc->result_tf); in sil24_qc_fill_rtf()
911 u32 *gscr = ap->link.device->gscr; in sil24_pmp_attach()
919 "disabling NCQ support due to sil24-mv4140 quirk\n"); in sil24_pmp_attach()
920 ap->flags &= ~ATA_FLAG_NCQ; in sil24_pmp_attach()
929 ap->flags |= ATA_FLAG_NCQ; in sil24_pmp_detach()
932 static int sil24_pmp_hardreset(struct ata_link *link, unsigned int *class, in sil24_pmp_hardreset() argument
937 rc = sil24_init_port(link->ap); in sil24_pmp_hardreset()
939 ata_link_err(link, "hardreset failed (port not ready)\n"); in sil24_pmp_hardreset()
943 return sata_std_hardreset(link, class, deadline); in sil24_pmp_hardreset()
950 /* Port-wide IRQ mask in HOST_CTRL doesn't really work, clear in sil24_freeze()
972 struct sil24_port_priv *pp = ap->private_data; in sil24_error_intr()
974 struct ata_link *link; in sil24_error_intr() local
984 link = &ap->link; in sil24_error_intr()
985 ehi = &link->eh_info; in sil24_error_intr()
1004 ehi->err_mask |= AC_ERR_HSM; in sil24_error_intr()
1005 ehi->action |= ATA_EH_RESET; in sil24_error_intr()
1024 if (ap->nr_active_links >= 3) { in sil24_error_intr()
1025 ehi->err_mask |= AC_ERR_OTHER; in sil24_error_intr()
1026 ehi->action |= ATA_EH_RESET; in sil24_error_intr()
1028 pp->do_port_rst = 1; in sil24_error_intr()
1032 /* find out the offending link and qc */ in sil24_error_intr()
1037 if (pmp < ap->nr_pmp_links) { in sil24_error_intr()
1038 link = &ap->pmp_link[pmp]; in sil24_error_intr()
1039 ehi = &link->eh_info; in sil24_error_intr()
1040 qc = ata_qc_from_tag(ap, link->active_tag); in sil24_error_intr()
1051 qc = ata_qc_from_tag(ap, link->active_tag); in sil24_error_intr()
1058 if (ci && ci->desc) { in sil24_error_intr()
1059 err_mask |= ci->err_mask; in sil24_error_intr()
1060 action |= ci->action; in sil24_error_intr()
1063 ata_ehi_push_desc(ehi, "%s", ci->desc); in sil24_error_intr()
1074 qc->err_mask |= err_mask; in sil24_error_intr()
1076 ehi->err_mask |= err_mask; in sil24_error_intr()
1078 ehi->action |= action; in sil24_error_intr()
1090 ata_link_abort(qc->dev->link); in sil24_error_intr()
1109 if (ap->flags & SIL24_FLAG_PCIX_IRQ_WOC) in sil24_host_intr()
1124 struct ata_eh_info *ehi = &ap->link.eh_info; in sil24_host_intr()
1125 ehi->err_mask |= AC_ERR_HSM; in sil24_host_intr()
1126 ehi->action |= ATA_EH_RESET; in sil24_host_intr()
1132 if (!(ap->flags & SIL24_FLAG_PCIX_IRQ_WOC) && ata_ratelimit()) in sil24_host_intr()
1135 slot_stat, ap->link.active_tag, ap->link.sactive); in sil24_host_intr()
1141 void __iomem *host_base = host->iomap[SIL24_HOST_BAR]; in sil24_interrupt()
1149 dev_err(host->dev, "IRQ status == 0xffffffff, " in sil24_interrupt()
1157 spin_lock(&host->lock); in sil24_interrupt()
1159 for (i = 0; i < host->n_ports; i++) in sil24_interrupt()
1161 sil24_host_intr(host->ports[i]); in sil24_interrupt()
1165 spin_unlock(&host->lock); in sil24_interrupt()
1172 struct sil24_port_priv *pp = ap->private_data; in sil24_error_handler()
1179 pp->do_port_rst = 0; in sil24_error_handler()
1184 struct ata_port *ap = qc->ap; in sil24_post_internal_cmd()
1187 if ((qc->flags & ATA_QCFLAG_EH) && sil24_init_port(ap)) in sil24_post_internal_cmd()
1193 struct device *dev = ap->host->dev; in sil24_port_start()
1201 return -ENOMEM; in sil24_port_start()
1205 return -ENOMEM; in sil24_port_start()
1207 pp->cmd_block = cb; in sil24_port_start()
1208 pp->cmd_block_dma = cb_dma; in sil24_port_start()
1210 ap->private_data = pp; in sil24_port_start()
1212 ata_port_pbar_desc(ap, SIL24_HOST_BAR, -1, "host"); in sil24_port_start()
1220 void __iomem *host_base = host->iomap[SIL24_HOST_BAR]; in sil24_init_controller()
1231 for (i = 0; i < host->n_ports; i++) { in sil24_init_controller()
1232 struct ata_port *ap = host->ports[i]; in sil24_init_controller()
1247 dev_err(host->dev, in sil24_init_controller()
1262 struct ata_port_info pi = sil24_port_info[ent->driver_data]; in sil24_init_one()
1269 /* cause link error if sil24_cmd_block is sized wrongly */ in sil24_init_one()
1273 ata_print_version_once(&pdev->dev, DRV_VERSION); in sil24_init_one()
1287 /* apply workaround for completion IRQ loss on PCI-X errata */ in sil24_init_one()
1291 dev_info(&pdev->dev, in sil24_init_one()
1292 "Applying completion IRQ loss on PCI-X errata fix\n"); in sil24_init_one()
1298 host = ata_host_alloc_pinfo(&pdev->dev, ppi, in sil24_init_one()
1299 SIL24_FLAG2NPORTS(ppi[0]->flags)); in sil24_init_one()
1301 return -ENOMEM; in sil24_init_one()
1302 host->iomap = iomap; in sil24_init_one()
1305 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in sil24_init_one()
1307 dev_err(&pdev->dev, "DMA enable failed\n"); in sil24_init_one()
1312 * write throughput for pci-e variants. in sil24_init_one()
1319 dev_info(&pdev->dev, "Using MSI\n"); in sil24_init_one()
1324 return ata_host_activate(host, pdev->irq, sil24_interrupt, IRQF_SHARED, in sil24_init_one()
1332 void __iomem *host_base = host->iomap[SIL24_HOST_BAR]; in sil24_pci_device_resume()
1339 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) in sil24_pci_device_resume()
1353 sil24_config_pmp(ap, ap->nr_pmp_links); in sil24_port_resume()
1361 MODULE_DESCRIPTION("Silicon Image 3124/3132 SATA low-level driver");