Skip to content

Commit 9a829cc

Browse files
htejunJeff Garzik
authored andcommitted
libata: convert ata_pci_init_native_mode() users to new init model
Convert drivers which use ata_pci_init_native_mode() to new init model. ata_pci_init_native_host() is used instead. sata_nv, sata_uli and sata_sis are in this category. Tested on nVidia Corporation CK804 Serial ATA Controller [10de:0054] in both BMDMA and ADMA mode. Signed-off-by: Tejun Heo <htejun@gmail.com> Signed-off-by: Jeff Garzik <jeff@garzik.org>
1 parent eca25dc commit 9a829cc

File tree

3 files changed

+80
-132
lines changed

3 files changed

+80
-132
lines changed

drivers/ata/sata_nv.c

Lines changed: 40 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,6 @@ static const struct ata_port_operations nv_generic_ops = {
369369
.error_handler = nv_error_handler,
370370
.post_internal_cmd = ata_bmdma_post_internal_cmd,
371371
.data_xfer = ata_data_xfer,
372-
.irq_handler = nv_generic_interrupt,
373372
.irq_clear = ata_bmdma_irq_clear,
374373
.irq_on = ata_irq_on,
375374
.irq_ack = ata_irq_ack,
@@ -396,7 +395,6 @@ static const struct ata_port_operations nv_nf2_ops = {
396395
.error_handler = nv_error_handler,
397396
.post_internal_cmd = ata_bmdma_post_internal_cmd,
398397
.data_xfer = ata_data_xfer,
399-
.irq_handler = nv_nf2_interrupt,
400398
.irq_clear = ata_bmdma_irq_clear,
401399
.irq_on = ata_irq_on,
402400
.irq_ack = ata_irq_ack,
@@ -423,7 +421,6 @@ static const struct ata_port_operations nv_ck804_ops = {
423421
.error_handler = nv_error_handler,
424422
.post_internal_cmd = ata_bmdma_post_internal_cmd,
425423
.data_xfer = ata_data_xfer,
426-
.irq_handler = nv_ck804_interrupt,
427424
.irq_clear = ata_bmdma_irq_clear,
428425
.irq_on = ata_irq_on,
429426
.irq_ack = ata_irq_ack,
@@ -452,7 +449,6 @@ static const struct ata_port_operations nv_adma_ops = {
452449
.error_handler = nv_adma_error_handler,
453450
.post_internal_cmd = nv_adma_post_internal_cmd,
454451
.data_xfer = ata_data_xfer,
455-
.irq_handler = nv_adma_interrupt,
456452
.irq_clear = nv_adma_irq_clear,
457453
.irq_on = ata_irq_on,
458454
.irq_ack = ata_irq_ack,
@@ -477,6 +473,7 @@ static struct ata_port_info nv_port_info[] = {
477473
.mwdma_mask = NV_MWDMA_MASK,
478474
.udma_mask = NV_UDMA_MASK,
479475
.port_ops = &nv_generic_ops,
476+
.irq_handler = nv_generic_interrupt,
480477
},
481478
/* nforce2/3 */
482479
{
@@ -487,6 +484,7 @@ static struct ata_port_info nv_port_info[] = {
487484
.mwdma_mask = NV_MWDMA_MASK,
488485
.udma_mask = NV_UDMA_MASK,
489486
.port_ops = &nv_nf2_ops,
487+
.irq_handler = nv_nf2_interrupt,
490488
},
491489
/* ck804 */
492490
{
@@ -497,6 +495,7 @@ static struct ata_port_info nv_port_info[] = {
497495
.mwdma_mask = NV_MWDMA_MASK,
498496
.udma_mask = NV_UDMA_MASK,
499497
.port_ops = &nv_ck804_ops,
498+
.irq_handler = nv_ck804_interrupt,
500499
},
501500
/* ADMA */
502501
{
@@ -508,6 +507,7 @@ static struct ata_port_info nv_port_info[] = {
508507
.mwdma_mask = NV_MWDMA_MASK,
509508
.udma_mask = NV_UDMA_MASK,
510509
.port_ops = &nv_adma_ops,
510+
.irq_handler = nv_adma_interrupt,
511511
},
512512
};
513513

@@ -1079,14 +1079,14 @@ static int nv_adma_port_resume(struct ata_port *ap)
10791079
}
10801080
#endif
10811081

1082-
static void nv_adma_setup_port(struct ata_probe_ent *probe_ent, unsigned int port)
1082+
static void nv_adma_setup_port(struct ata_port *ap)
10831083
{
1084-
void __iomem *mmio = probe_ent->iomap[NV_MMIO_BAR];
1085-
struct ata_ioports *ioport = &probe_ent->port[port];
1084+
void __iomem *mmio = ap->host->iomap[NV_MMIO_BAR];
1085+
struct ata_ioports *ioport = &ap->ioaddr;
10861086

10871087
VPRINTK("ENTER\n");
10881088

1089-
mmio += NV_ADMA_PORT + port * NV_ADMA_PORT_SIZE;
1089+
mmio += NV_ADMA_PORT + ap->port_no * NV_ADMA_PORT_SIZE;
10901090

10911091
ioport->cmd_addr = mmio;
10921092
ioport->data_addr = mmio + (ATA_REG_DATA * 4);
@@ -1103,9 +1103,9 @@ static void nv_adma_setup_port(struct ata_probe_ent *probe_ent, unsigned int por
11031103
ioport->ctl_addr = mmio + 0x20;
11041104
}
11051105

1106-
static int nv_adma_host_init(struct ata_probe_ent *probe_ent)
1106+
static int nv_adma_host_init(struct ata_host *host)
11071107
{
1108-
struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
1108+
struct pci_dev *pdev = to_pci_dev(host->dev);
11091109
unsigned int i;
11101110
u32 tmp32;
11111111

@@ -1120,8 +1120,8 @@ static int nv_adma_host_init(struct ata_probe_ent *probe_ent)
11201120

11211121
pci_write_config_dword(pdev, NV_MCP_SATA_CFG_20, tmp32);
11221122

1123-
for (i = 0; i < probe_ent->n_ports; i++)
1124-
nv_adma_setup_port(probe_ent, i);
1123+
for (i = 0; i < host->n_ports; i++)
1124+
nv_adma_setup_port(host->ports[i]);
11251125

11261126
return 0;
11271127
}
@@ -1480,14 +1480,13 @@ static void nv_adma_error_handler(struct ata_port *ap)
14801480
static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
14811481
{
14821482
static int printed_version = 0;
1483-
struct ata_port_info *ppi[2];
1484-
struct ata_probe_ent *probe_ent;
1483+
const struct ata_port_info *ppi[2];
1484+
struct ata_host *host;
14851485
struct nv_host_priv *hpriv;
14861486
int rc;
14871487
u32 bar;
14881488
void __iomem *base;
14891489
unsigned long type = ent->driver_data;
1490-
int mask_set = 0;
14911490

14921491
// Make sure this is a SATA controller by counting the number of bars
14931492
// (NVIDIA SATA controllers will always have six bars). Otherwise,
@@ -1503,50 +1502,38 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
15031502
if (rc)
15041503
return rc;
15051504

1506-
rc = pci_request_regions(pdev, DRV_NAME);
1507-
if (rc) {
1508-
pcim_pin_device(pdev);
1509-
return rc;
1510-
}
1511-
1512-
if(type >= CK804 && adma_enabled) {
1505+
/* determine type and allocate host */
1506+
if (type >= CK804 && adma_enabled) {
15131507
dev_printk(KERN_NOTICE, &pdev->dev, "Using ADMA mode\n");
15141508
type = ADMA;
1515-
if(!pci_set_dma_mask(pdev, DMA_64BIT_MASK) &&
1516-
!pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))
1517-
mask_set = 1;
1518-
}
1519-
1520-
if(!mask_set) {
1521-
rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
1522-
if (rc)
1523-
return rc;
1524-
rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
1525-
if (rc)
1526-
return rc;
15271509
}
15281510

1529-
rc = -ENOMEM;
1511+
ppi[0] = ppi[1] = &nv_port_info[type];
1512+
rc = ata_pci_prepare_native_host(pdev, ppi, 2, &host);
1513+
if (rc)
1514+
return rc;
15301515

15311516
hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
15321517
if (!hpriv)
15331518
return -ENOMEM;
1519+
hpriv->type = type;
1520+
host->private_data = hpriv;
15341521

1535-
ppi[0] = ppi[1] = &nv_port_info[type];
1536-
probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
1537-
if (!probe_ent)
1538-
return -ENOMEM;
1539-
1540-
if (!pcim_iomap(pdev, NV_MMIO_BAR, 0))
1541-
return -EIO;
1542-
probe_ent->iomap = pcim_iomap_table(pdev);
1522+
/* set 64bit dma masks, may fail */
1523+
if (type == ADMA) {
1524+
if (pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0)
1525+
pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
1526+
}
15431527

1544-
probe_ent->private_data = hpriv;
1545-
hpriv->type = type;
1528+
/* request and iomap NV_MMIO_BAR */
1529+
rc = pcim_iomap_regions(pdev, 1 << NV_MMIO_BAR, DRV_NAME);
1530+
if (rc)
1531+
return rc;
15461532

1547-
base = probe_ent->iomap[NV_MMIO_BAR];
1548-
probe_ent->port[0].scr_addr = base + NV_PORT0_SCR_REG_OFFSET;
1549-
probe_ent->port[1].scr_addr = base + NV_PORT1_SCR_REG_OFFSET;
1533+
/* configure SCR access */
1534+
base = host->iomap[NV_MMIO_BAR];
1535+
host->ports[0]->ioaddr.scr_addr = base + NV_PORT0_SCR_REG_OFFSET;
1536+
host->ports[1]->ioaddr.scr_addr = base + NV_PORT1_SCR_REG_OFFSET;
15501537

15511538
/* enable SATA space for CK804 */
15521539
if (type >= CK804) {
@@ -1557,20 +1544,16 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
15571544
pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
15581545
}
15591546

1560-
pci_set_master(pdev);
1561-
1547+
/* init ADMA */
15621548
if (type == ADMA) {
1563-
rc = nv_adma_host_init(probe_ent);
1549+
rc = nv_adma_host_init(host);
15641550
if (rc)
15651551
return rc;
15661552
}
15671553

1568-
rc = ata_device_add(probe_ent);
1569-
if (rc != NV_PORTS)
1570-
return -ENODEV;
1571-
1572-
devm_kfree(&pdev->dev, probe_ent);
1573-
return 0;
1554+
pci_set_master(pdev);
1555+
return ata_host_activate(host, pdev->irq, ppi[0]->irq_handler,
1556+
IRQF_SHARED, ppi[0]->sht);
15741557
}
15751558

15761559
static void nv_remove_one (struct pci_dev *pdev)

drivers/ata/sata_sis.c

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ static const struct ata_port_operations sis_ops = {
121121
.thaw = ata_bmdma_thaw,
122122
.error_handler = ata_bmdma_error_handler,
123123
.post_internal_cmd = ata_bmdma_post_internal_cmd,
124-
.irq_handler = ata_interrupt,
125124
.irq_clear = ata_bmdma_irq_clear,
126125
.irq_on = ata_irq_on,
127126
.irq_ack = ata_irq_ack,
@@ -131,7 +130,6 @@ static const struct ata_port_operations sis_ops = {
131130
};
132131

133132
static struct ata_port_info sis_port_info = {
134-
.sht = &sis_sht,
135133
.flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
136134
.pio_mask = 0x1f,
137135
.mwdma_mask = 0x7,
@@ -256,12 +254,13 @@ static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
256254
static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
257255
{
258256
static int printed_version;
259-
struct ata_probe_ent *probe_ent = NULL;
260-
int rc;
257+
struct ata_port_info pi = sis_port_info;
258+
const struct ata_port_info *ppi[2] = { &pi, &pi };
259+
struct ata_host *host;
261260
u32 genctl, val;
262-
struct ata_port_info pi = sis_port_info, *ppi[2] = { &pi, &pi };
263261
u8 pmr;
264262
u8 port2_start = 0x20;
263+
int rc;
265264

266265
if (!printed_version++)
267266
dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
@@ -270,19 +269,6 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
270269
if (rc)
271270
return rc;
272271

273-
rc = pci_request_regions(pdev, DRV_NAME);
274-
if (rc) {
275-
pcim_pin_device(pdev);
276-
return rc;
277-
}
278-
279-
rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
280-
if (rc)
281-
return rc;
282-
rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
283-
if (rc)
284-
return rc;
285-
286272
/* check and see if the SCRs are in IO space or PCI cfg space */
287273
pci_read_config_dword(pdev, SIS_GENCTL, &genctl);
288274
if ((genctl & GENCTL_IOMAPPED_SCR) == 0)
@@ -349,30 +335,26 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
349335
break;
350336
}
351337

352-
probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
353-
if (!probe_ent)
354-
return -ENOMEM;
338+
rc = ata_pci_prepare_native_host(pdev, ppi, 2, &host);
339+
if (rc)
340+
return rc;
355341

356-
if (!(probe_ent->port_flags & SIS_FLAG_CFGSCR)) {
342+
if (!(pi.flags & SIS_FLAG_CFGSCR)) {
357343
void __iomem *mmio;
358344

359-
mmio = pcim_iomap(pdev, SIS_SCR_PCI_BAR, 0);
360-
if (!mmio)
361-
return -ENOMEM;
345+
rc = pcim_iomap_regions(pdev, 1 << SIS_SCR_PCI_BAR, DRV_NAME);
346+
if (rc)
347+
return rc;
348+
mmio = host->iomap[SIS_SCR_PCI_BAR];
362349

363-
probe_ent->port[0].scr_addr = mmio;
364-
probe_ent->port[1].scr_addr = mmio + port2_start;
350+
host->ports[0]->ioaddr.scr_addr = mmio;
351+
host->ports[1]->ioaddr.scr_addr = mmio + port2_start;
365352
}
366353

367354
pci_set_master(pdev);
368355
pci_intx(pdev, 1);
369-
370-
if (!ata_device_add(probe_ent))
371-
return -EIO;
372-
373-
devm_kfree(&pdev->dev, probe_ent);
374-
return 0;
375-
356+
return ata_host_activate(host, pdev->irq, ata_interrupt, IRQF_SHARED,
357+
&sis_sht);
376358
}
377359

378360
static int __init sis_init(void)

0 commit comments

Comments
 (0)