20 #include <linux/kernel.h>
21 #include <linux/module.h>
23 #include <linux/pci.h>
28 #include <linux/device.h>
33 #define DRV_NAME "sata_sil24"
34 #define DRV_VERSION "1.1"
271 static const struct sil24_cerr_info {
272 unsigned int err_mask,
action;
274 } sil24_cerr_db[] = {
278 "device error via D2H FIS" },
280 "device error via SDB FIS" },
282 "error in data FIS" },
284 "failed to transmit command FIS" },
286 "protocol mismatch" },
288 "data directon mismatch" },
290 "ran out of SGEs while writing" },
292 "ran out of SGEs while reading" },
294 "invalid data directon for ATAPI CDB" },
296 "SGT not on qword boundary" },
298 "PCI target abort while fetching SGT" },
300 "PCI master abort while fetching SGT" },
302 "PCI parity error while fetching SGT" },
304 "PRB not on qword boundary" },
306 "PCI target abort while fetching PRB" },
308 "PCI master abort while fetching PRB" },
310 "PCI parity error while fetching PRB" },
312 "undefined error while transferring data" },
314 "PCI target abort while transferring data" },
316 "PCI master abort while transferring data" },
318 "PCI parity error while transferring data" },
320 "FIS received while sending service FIS" },
342 static void sil24_pmp_attach(
struct ata_port *ap);
343 static void sil24_pmp_detach(
struct ata_port *ap);
344 static void sil24_freeze(
struct ata_port *ap);
345 static void sil24_thaw(
struct ata_port *ap);
346 static int sil24_softreset(
struct ata_link *
link,
unsigned int *
class,
347 unsigned long deadline);
348 static int sil24_hardreset(
struct ata_link *
link,
unsigned int *
class,
349 unsigned long deadline);
350 static int sil24_pmp_hardreset(
struct ata_link *
link,
unsigned int *
class,
351 unsigned long deadline);
352 static void sil24_error_handler(
struct ata_port *ap);
354 static int sil24_port_start(
struct ata_port *ap);
357 static int sil24_pci_device_resume(
struct pci_dev *pdev);
358 static int sil24_port_resume(
struct ata_port *ap);
375 .id_table = sil24_pci_tbl,
376 .probe = sil24_init_one,
377 .remove = ata_pci_remove_one,
379 .suspend = ata_pci_device_suspend,
380 .resume = sil24_pci_device_resume,
394 .qc_defer = sil24_qc_defer,
395 .qc_prep = sil24_qc_prep,
396 .qc_issue = sil24_qc_issue,
397 .qc_fill_rtf = sil24_qc_fill_rtf,
399 .freeze = sil24_freeze,
401 .softreset = sil24_softreset,
402 .hardreset = sil24_hardreset,
403 .pmp_softreset = sil24_softreset,
404 .pmp_hardreset = sil24_pmp_hardreset,
405 .error_handler = sil24_error_handler,
406 .post_internal_cmd = sil24_post_internal_cmd,
407 .dev_config = sil24_dev_config,
409 .scr_read = sil24_scr_read,
410 .scr_write = sil24_scr_write,
411 .pmp_attach = sil24_pmp_attach,
412 .pmp_detach = sil24_pmp_detach,
414 .port_start = sil24_port_start,
416 .port_resume = sil24_port_resume,
420 static bool sata_sil24_msi;
428 #define SIL24_NPORTS2FLAG(nports) ((((unsigned)(nports) - 1) & 0x3) << 30)
429 #define SIL24_FLAG2NPORTS(flag) ((((flag) >> 30) & 0x3) + 1)
439 .port_ops = &sil24_ops,
447 .port_ops = &sil24_ops,
455 .port_ops = &sil24_ops,
459 static int sil24_tag(
int tag)
461 if (
unlikely(ata_tag_internal(tag)))
466 static unsigned long sil24_port_offset(
struct ata_port *ap)
488 void __iomem *port = sil24_port_base(ap);
497 static int sil24_scr_map[] = {
510 addr = scr_addr + sil24_scr_map[sc_reg] * 4;
511 *val =
readl(scr_addr + sil24_scr_map[sc_reg] * 4);
517 static int sil24_scr_write(
struct ata_link *link,
unsigned sc_reg,
u32 val)
523 addr = scr_addr + sil24_scr_map[sc_reg] * 4;
524 writel(val, scr_addr + sil24_scr_map[sc_reg] * 4);
530 static void sil24_config_port(
struct ata_port *ap)
532 void __iomem *port = sil24_port_base(ap);
555 static void sil24_config_pmp(
struct ata_port *ap,
int attached)
557 void __iomem *port = sil24_port_base(ap);
565 static void sil24_clear_pmp(
struct ata_port *ap)
567 void __iomem *port = sil24_port_base(ap);
580 static int sil24_init_port(
struct ata_port *ap)
582 void __iomem *port = sil24_port_base(ap);
587 if (sata_pmp_attached(ap))
605 static int sil24_exec_polled_cmd(
struct ata_port *ap,
int pmp,
608 unsigned long timeout_msec)
610 void __iomem *port = sil24_port_base(ap);
657 static int sil24_softreset(
struct ata_link *link,
unsigned int *
class,
658 unsigned long deadline)
661 int pmp = sata_srst_pmp(link);
662 unsigned long timeout_msec = 0;
670 if (sil24_init_port(ap)) {
671 reason =
"port not ready";
679 ata_tf_init(link->
device, &tf);
686 reason =
"SRST command error";
690 sil24_read_tf(ap, 0, &tf);
693 DPRINTK(
"EXIT, class=%u\n", *
class);
701 static int sil24_hardreset(
struct ata_link *link,
unsigned int *
class,
702 unsigned long deadline)
705 void __iomem *port = sil24_port_base(ap);
707 int did_port_rst = 0;
718 "controller in dubious state, performing PORT_RST\n");
727 sil24_config_port(ap);
751 reason =
"PHY debouncing failed";
758 reason =
"link not ready";
803 u8 prot = qc->
tf.protocol;
824 int is_excl = (ata_is_atapi(prot) ||
855 if (!ata_is_atapi(qc->
tf.protocol)) {
858 if (ata_is_data(qc->
tf.protocol)) {
861 if (ata_is_ncq(qc->
tf.protocol))
870 prb = &cb->
atapi.prb;
875 if (ata_is_data(qc->
tf.protocol)) {
887 sil24_fill_sg(qc, sge);
894 void __iomem *port = sil24_port_base(ap);
895 unsigned int tag = sil24_tag(qc->
tag);
919 static void sil24_pmp_attach(
struct ata_port *ap)
921 u32 *gscr = ap->
link.device->gscr;
923 sil24_config_pmp(ap, 1);
929 "disabling NCQ support due to sil24-mv4140 quirk\n");
934 static void sil24_pmp_detach(
struct ata_port *ap)
937 sil24_config_pmp(ap, 0);
942 static int sil24_pmp_hardreset(
struct ata_link *link,
unsigned int *
class,
943 unsigned long deadline)
947 rc = sil24_init_port(link->
ap);
949 ata_link_err(link,
"hardreset failed (port not ready)\n");
956 static void sil24_freeze(
struct ata_port *ap)
958 void __iomem *port = sil24_port_base(ap);
966 static void sil24_thaw(
struct ata_port *ap)
968 void __iomem *port = sil24_port_base(ap);
979 static void sil24_error_intr(
struct ata_port *ap)
981 void __iomem *port = sil24_port_base(ap);
986 int abort = 0, freeze = 0;
1006 ata_ehi_hotplugged(ehi);
1009 "PHY RDY changed" :
"device exchanged");
1022 const struct sil24_cerr_info *ci =
NULL;
1023 unsigned int err_mask = 0,
action = 0;
1043 if (sata_pmp_attached(ap)) {
1045 pmp = (context >> 5) & 0xf;
1047 if (pmp < ap->nr_pmp_links) {
1066 ci = &sil24_cerr_db[cerr];
1068 if (ci && ci->desc) {
1069 err_mask |= ci->err_mask;
1091 if (sata_pmp_attached(ap))
1106 static inline void sil24_host_intr(
struct ata_port *ap)
1108 void __iomem *port = sil24_port_base(ap);
1109 u32 slot_stat, qc_active;
1125 sil24_error_intr(ap);
1129 qc_active = slot_stat & ~HOST_SSTAT_ATTN;
1144 "spurious interrupt (slot_stat 0x%x active_tag %d sactive 0x%x)\n",
1145 slot_stat, ap->
link.active_tag, ap->
link.sactive);
1148 static irqreturn_t sil24_interrupt(
int irq,
void *dev_instance)
1152 unsigned handled = 0;
1158 if (status == 0xffffffff) {
1160 "PCI fault or device removal?\n");
1167 spin_lock(&host->
lock);
1169 for (i = 0; i < host->
n_ports; i++)
1170 if (status & (1 << i)) {
1171 sil24_host_intr(host->
ports[i]);
1175 spin_unlock(&host->
lock);
1180 static void sil24_error_handler(
struct ata_port *ap)
1184 if (sil24_init_port(ap))
1201 static int sil24_port_start(
struct ata_port *ap)
1224 ata_port_pbar_desc(ap,
SIL24_PORT_BAR, sil24_port_offset(ap),
"port");
1229 static void sil24_init_controller(
struct ata_host *host)
1242 for (i = 0; i < host->
n_ports; i++) {
1244 void __iomem *port = sil24_port_base(ap);
1256 PORT_CS_PORT_RST, 10, 100);
1257 if (tmp & PORT_CS_PORT_RST)
1259 "failed to clear port RST\n");
1263 sil24_config_port(ap);
1272 extern int __MARKER__sil24_cmd_block_is_sized_wrongly;
1282 __MARKER__sil24_cmd_block_is_sized_wrongly = 1;
1303 "Applying completion IRQ loss on PCI-X errata fix\n");
1317 rc = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64));
1319 rc = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
1322 "64-bit DMA enable failed\n");
1329 dev_err(&pdev->
dev,
"32-bit DMA enable failed\n");
1332 rc = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
1335 "32-bit consistent DMA enable failed\n");
1345 sil24_init_controller(host);
1347 if (sata_sil24_msi && !pci_enable_msi(pdev)) {
1358 static int sil24_pci_device_resume(
struct pci_dev *pdev)
1364 rc = ata_pci_device_do_resume(pdev);
1371 sil24_init_controller(host);
1373 ata_host_resume(host);
1378 static int sil24_port_resume(
struct ata_port *ap)