aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ata/sata_nv.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ata/sata_nv.c')
-rw-r--r--drivers/ata/sata_nv.c86
1 files changed, 23 insertions, 63 deletions
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 246df22ecd05..18361a38aee7 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -363,8 +363,6 @@ static const struct ata_port_operations nv_generic_ops = {
363 .scr_read = nv_scr_read, 363 .scr_read = nv_scr_read,
364 .scr_write = nv_scr_write, 364 .scr_write = nv_scr_write,
365 .port_start = ata_port_start, 365 .port_start = ata_port_start,
366 .port_stop = ata_port_stop,
367 .host_stop = ata_pci_host_stop,
368}; 366};
369 367
370static const struct ata_port_operations nv_nf2_ops = { 368static const struct ata_port_operations nv_nf2_ops = {
@@ -390,8 +388,6 @@ static const struct ata_port_operations nv_nf2_ops = {
390 .scr_read = nv_scr_read, 388 .scr_read = nv_scr_read,
391 .scr_write = nv_scr_write, 389 .scr_write = nv_scr_write,
392 .port_start = ata_port_start, 390 .port_start = ata_port_start,
393 .port_stop = ata_port_stop,
394 .host_stop = ata_pci_host_stop,
395}; 391};
396 392
397static const struct ata_port_operations nv_ck804_ops = { 393static const struct ata_port_operations nv_ck804_ops = {
@@ -417,7 +413,6 @@ static const struct ata_port_operations nv_ck804_ops = {
417 .scr_read = nv_scr_read, 413 .scr_read = nv_scr_read,
418 .scr_write = nv_scr_write, 414 .scr_write = nv_scr_write,
419 .port_start = ata_port_start, 415 .port_start = ata_port_start,
420 .port_stop = ata_port_stop,
421 .host_stop = nv_ck804_host_stop, 416 .host_stop = nv_ck804_host_stop,
422}; 417};
423 418
@@ -928,11 +923,9 @@ static int nv_adma_port_start(struct ata_port *ap)
928 if (rc) 923 if (rc)
929 return rc; 924 return rc;
930 925
931 pp = kzalloc(sizeof(*pp), GFP_KERNEL); 926 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
932 if (!pp) { 927 if (!pp)
933 rc = -ENOMEM; 928 return -ENOMEM;
934 goto err_out;
935 }
936 929
937 mmio = ap->host->mmio_base + NV_ADMA_PORT + 930 mmio = ap->host->mmio_base + NV_ADMA_PORT +
938 ap->port_no * NV_ADMA_PORT_SIZE; 931 ap->port_no * NV_ADMA_PORT_SIZE;
@@ -941,13 +934,10 @@ static int nv_adma_port_start(struct ata_port *ap)
941 pp->notifier_clear_block = pp->gen_block + 934 pp->notifier_clear_block = pp->gen_block +
942 NV_ADMA_NOTIFIER_CLEAR + (4 * ap->port_no); 935 NV_ADMA_NOTIFIER_CLEAR + (4 * ap->port_no);
943 936
944 mem = dma_alloc_coherent(dev, NV_ADMA_PORT_PRIV_DMA_SZ, 937 mem = dmam_alloc_coherent(dev, NV_ADMA_PORT_PRIV_DMA_SZ,
945 &mem_dma, GFP_KERNEL); 938 &mem_dma, GFP_KERNEL);
946 939 if (!mem)
947 if (!mem) { 940 return -ENOMEM;
948 rc = -ENOMEM;
949 goto err_out_kfree;
950 }
951 memset(mem, 0, NV_ADMA_PORT_PRIV_DMA_SZ); 941 memset(mem, 0, NV_ADMA_PORT_PRIV_DMA_SZ);
952 942
953 /* 943 /*
@@ -993,28 +983,15 @@ static int nv_adma_port_start(struct ata_port *ap)
993 readl( mmio + NV_ADMA_CTL ); /* flush posted write */ 983 readl( mmio + NV_ADMA_CTL ); /* flush posted write */
994 984
995 return 0; 985 return 0;
996
997err_out_kfree:
998 kfree(pp);
999err_out:
1000 ata_port_stop(ap);
1001 return rc;
1002} 986}
1003 987
1004static void nv_adma_port_stop(struct ata_port *ap) 988static void nv_adma_port_stop(struct ata_port *ap)
1005{ 989{
1006 struct device *dev = ap->host->dev;
1007 struct nv_adma_port_priv *pp = ap->private_data; 990 struct nv_adma_port_priv *pp = ap->private_data;
1008 void __iomem *mmio = pp->ctl_block; 991 void __iomem *mmio = pp->ctl_block;
1009 992
1010 VPRINTK("ENTER\n"); 993 VPRINTK("ENTER\n");
1011
1012 writew(0, mmio + NV_ADMA_CTL); 994 writew(0, mmio + NV_ADMA_CTL);
1013
1014 ap->private_data = NULL;
1015 dma_free_coherent(dev, NV_ADMA_PORT_PRIV_DMA_SZ, pp->cpb, pp->cpb_dma);
1016 kfree(pp);
1017 ata_port_stop(ap);
1018} 995}
1019 996
1020static int nv_adma_port_suspend(struct ata_port *ap, pm_message_t mesg) 997static int nv_adma_port_suspend(struct ata_port *ap, pm_message_t mesg)
@@ -1433,7 +1410,6 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1433 struct ata_port_info *ppi[2]; 1410 struct ata_port_info *ppi[2];
1434 struct ata_probe_ent *probe_ent; 1411 struct ata_probe_ent *probe_ent;
1435 struct nv_host_priv *hpriv; 1412 struct nv_host_priv *hpriv;
1436 int pci_dev_busy = 0;
1437 int rc; 1413 int rc;
1438 u32 bar; 1414 u32 bar;
1439 unsigned long base; 1415 unsigned long base;
@@ -1450,14 +1426,14 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1450 if (!printed_version++) 1426 if (!printed_version++)
1451 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1427 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1452 1428
1453 rc = pci_enable_device(pdev); 1429 rc = pcim_enable_device(pdev);
1454 if (rc) 1430 if (rc)
1455 goto err_out; 1431 return rc;
1456 1432
1457 rc = pci_request_regions(pdev, DRV_NAME); 1433 rc = pci_request_regions(pdev, DRV_NAME);
1458 if (rc) { 1434 if (rc) {
1459 pci_dev_busy = 1; 1435 pcim_pin_device(pdev);
1460 goto err_out_disable; 1436 return rc;
1461 } 1437 }
1462 1438
1463 if(type >= CK804 && adma_enabled) { 1439 if(type >= CK804 && adma_enabled) {
@@ -1471,28 +1447,27 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1471 if(!mask_set) { 1447 if(!mask_set) {
1472 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 1448 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
1473 if (rc) 1449 if (rc)
1474 goto err_out_regions; 1450 return rc;
1475 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 1451 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
1476 if (rc) 1452 if (rc)
1477 goto err_out_regions; 1453 return rc;
1478 } 1454 }
1479 1455
1480 rc = -ENOMEM; 1456 rc = -ENOMEM;
1481 1457
1482 hpriv = kmalloc(sizeof(*hpriv), GFP_KERNEL); 1458 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
1483 if (!hpriv) 1459 if (!hpriv)
1484 goto err_out_regions; 1460 return -ENOMEM;
1485 1461
1486 ppi[0] = ppi[1] = &nv_port_info[type]; 1462 ppi[0] = ppi[1] = &nv_port_info[type];
1487 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 1463 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
1488 if (!probe_ent) 1464 if (!probe_ent)
1489 goto err_out_regions; 1465 return -ENOMEM;
1466
1467 probe_ent->mmio_base = pcim_iomap(pdev, 5, 0);
1468 if (!probe_ent->mmio_base)
1469 return -EIO;
1490 1470
1491 probe_ent->mmio_base = pci_iomap(pdev, 5, 0);
1492 if (!probe_ent->mmio_base) {
1493 rc = -EIO;
1494 goto err_out_free_ent;
1495 }
1496 probe_ent->private_data = hpriv; 1471 probe_ent->private_data = hpriv;
1497 hpriv->type = type; 1472 hpriv->type = type;
1498 1473
@@ -1515,28 +1490,15 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1515 if (type == ADMA) { 1490 if (type == ADMA) {
1516 rc = nv_adma_host_init(probe_ent); 1491 rc = nv_adma_host_init(probe_ent);
1517 if (rc) 1492 if (rc)
1518 goto err_out_iounmap; 1493 return rc;
1519 } 1494 }
1520 1495
1521 rc = ata_device_add(probe_ent); 1496 rc = ata_device_add(probe_ent);
1522 if (rc != NV_PORTS) 1497 if (rc != NV_PORTS)
1523 goto err_out_iounmap; 1498 return -ENODEV;
1524
1525 kfree(probe_ent);
1526 1499
1500 devm_kfree(&pdev->dev, probe_ent);
1527 return 0; 1501 return 0;
1528
1529err_out_iounmap:
1530 pci_iounmap(pdev, probe_ent->mmio_base);
1531err_out_free_ent:
1532 kfree(probe_ent);
1533err_out_regions:
1534 pci_release_regions(pdev);
1535err_out_disable:
1536 if (!pci_dev_busy)
1537 pci_disable_device(pdev);
1538err_out:
1539 return rc;
1540} 1502}
1541 1503
1542static void nv_remove_one (struct pci_dev *pdev) 1504static void nv_remove_one (struct pci_dev *pdev)
@@ -1602,8 +1564,6 @@ static void nv_ck804_host_stop(struct ata_host *host)
1602 pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval); 1564 pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
1603 regval &= ~NV_MCP_SATA_CFG_20_SATA_SPACE_EN; 1565 regval &= ~NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
1604 pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval); 1566 pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
1605
1606 ata_pci_host_stop(host);
1607} 1567}
1608 1568
1609static void nv_adma_host_stop(struct ata_host *host) 1569static void nv_adma_host_stop(struct ata_host *host)