Skip to content

Commit

Permalink
libata: stop overloading port_info->private_data
Browse files Browse the repository at this point in the history
port_info->private_data is currently used for two purposes - to record
private data about the port_info or to specify host->private_data to
use when allocating ata_host.

This overloading is confusing and counter-intuitive in that
port_info->private_data becomes host->private_data instead of
port->private_data.  In addition, port_info and host don't correspond
to each other 1-to-1.  Currently, the first non-NULL
port_info->private_data is used.

This patch makes port_info->private_data just be what it is -
private_data for the port_info where LLD can jot down extra info.
libata no longer sets host->private_data to the first non-NULL
port_info->private_data, @host_priv argument is added to
ata_pci_init_one() instead.  LLDs which use ata_pci_init_one() can use
this argument to pass in pointer to host private data.  LLDs which
don't should use init-register model anyway and can initialize
host->private_data directly.

Adding @host_priv instead of using init-register model for LLDs which
use ata_pci_init_one() is suggested by Alan Cox.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
  • Loading branch information
htejun authored and Jeff Garzik committed Apr 17, 2008
1 parent 1bd5b71 commit 887125e
Show file tree
Hide file tree
Showing 39 changed files with 79 additions and 145 deletions.
2 changes: 1 addition & 1 deletion drivers/ata/ata_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id
if (dev->vendor == PCI_VENDOR_ID_AL)
ata_pci_clear_simplex(dev);

return ata_pci_init_one(dev, ppi, &generic_sht);
return ata_pci_init_one(dev, ppi, &generic_sht, NULL);
}

static struct pci_device_id ata_generic[] = {
Expand Down
2 changes: 0 additions & 2 deletions drivers/ata/libata-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -6995,8 +6995,6 @@ struct ata_host *ata_host_alloc_pinfo(struct device *dev,

if (!host->ops && (pi->port_ops != &ata_dummy_port_ops))
host->ops = pi->port_ops;
if (!host->private_data && pi->private_data)
host->private_data = pi->private_data;
}

return host;
Expand Down
4 changes: 3 additions & 1 deletion drivers/ata/libata-sff.c
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ int ata_pci_activate_sff_host(struct ata_host *host,
* @pdev: Controller to be initialized
* @ppi: array of port_info, must be enough for two ports
* @sht: scsi_host_template to use when registering the host
* @host_priv: host private_data
*
* This is a helper function which can be called from a driver's
* xxx_init_one() probe function if the hardware uses traditional
Expand All @@ -848,7 +849,7 @@ int ata_pci_activate_sff_host(struct ata_host *host,
*/
int ata_pci_init_one(struct pci_dev *pdev,
const struct ata_port_info * const * ppi,
struct scsi_host_template *sht)
struct scsi_host_template *sht, void *host_priv)
{
struct device *dev = &pdev->dev;
const struct ata_port_info *pi = NULL;
Expand Down Expand Up @@ -882,6 +883,7 @@ int ata_pci_init_one(struct pci_dev *pdev,
rc = ata_pci_prepare_sff_host(pdev, ppi, &host);
if (rc)
goto out;
host->private_data = host_priv;

pci_set_master(pdev);
rc = ata_pci_activate_sff_host(host, ata_interrupt, sht);
Expand Down
18 changes: 2 additions & 16 deletions drivers/ata/pata_acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,6 @@ static int pacpi_cable_detect(struct ata_port *ap)
return ATA_CBL_PATA40;
}

/**
* pacpi_error_handler - Setup and error handler
* @ap: Port to handle
*
* LOCKING:
* None (inherited from caller).
*/

static void pacpi_error_handler(struct ata_port *ap)
{
ata_bmdma_drive_eh(ap, pacpi_pre_reset, ata_std_softreset, NULL,
ata_std_postreset);
}

/**
* pacpi_discover_modes - filter non ACPI modes
* @adev: ATA device
Expand Down Expand Up @@ -242,7 +228,7 @@ static struct ata_port_operations pacpi_ops = {
.mode_filter = pacpi_mode_filter,
.set_piomode = pacpi_set_piomode,
.set_dmamode = pacpi_set_dmamode,
.error_handler = pacpi_error_handler,
.prereset = pacpi_pre_reset,
.port_start = pacpi_port_start,
};

Expand Down Expand Up @@ -273,7 +259,7 @@ static int pacpi_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
.port_ops = &pacpi_ops,
};
const struct ata_port_info *ppi[] = { &info, NULL };
return ata_pci_init_one(pdev, ppi, &pacpi_sht);
return ata_pci_init_one(pdev, ppi, &pacpi_sht, NULL);
}

static const struct pci_device_id pacpi_pci_tbl[] = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_ali.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
ppi[0] = &info_20_udma;
pci_dev_put(isa_bridge);
}
return ata_pci_init_one(pdev, ppi, &ali_sht);
return ata_pci_init_one(pdev, ppi, &ali_sht, NULL);
}

#ifdef CONFIG_PM
Expand Down
27 changes: 7 additions & 20 deletions drivers/ata/pata_amd.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ static int amd_pre_reset(struct ata_link *link, unsigned long deadline)
return ata_std_prereset(link, deadline);
}

static void amd_error_handler(struct ata_port *ap)
{
ata_bmdma_drive_eh(ap, amd_pre_reset, ata_std_softreset, NULL,
ata_std_postreset);
}

static int amd_cable_detect(struct ata_port *ap)
{
static const u32 bitmask[2] = {0x03, 0x0C};
Expand Down Expand Up @@ -300,13 +294,6 @@ static int nv_pre_reset(struct ata_link *link, unsigned long deadline)
return ata_std_prereset(link, deadline);
}

static void nv_error_handler(struct ata_port *ap)
{
ata_bmdma_drive_eh(ap, nv_pre_reset,
ata_std_softreset, NULL,
ata_std_postreset);
}

/**
* nv100_set_piomode - set initial PIO mode data
* @ap: ATA interface
Expand Down Expand Up @@ -358,7 +345,7 @@ static struct scsi_host_template amd_sht = {

static const struct ata_port_operations amd_base_port_ops = {
.inherits = &ata_bmdma_port_ops,
.error_handler = amd_error_handler,
.prereset = amd_pre_reset,
};

static struct ata_port_operations amd33_port_ops = {
Expand Down Expand Up @@ -393,7 +380,7 @@ static const struct ata_port_operations nv_base_port_ops = {
.inherits = &ata_bmdma_port_ops,
.cable_detect = ata_cable_ignore,
.mode_filter = nv_mode_filter,
.error_handler = nv_error_handler,
.prereset = nv_pre_reset,
.host_stop = nv_host_stop,
};

Expand Down Expand Up @@ -483,10 +470,10 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
.port_ops = &amd100_port_ops
}
};
struct ata_port_info pi;
const struct ata_port_info *ppi[] = { &pi, NULL };
const struct ata_port_info *ppi[] = { NULL, NULL };
static int printed_version;
int type = id->driver_data;
void *hpriv = NULL;
u8 fifo;
int rc;

Expand All @@ -511,7 +498,7 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
/*
* Okay, type is determined now. Apply type-specific workarounds.
*/
pi = info[type];
ppi[0] = &info[type];

if (type < 3)
ata_pci_clear_simplex(pdev);
Expand All @@ -530,11 +517,11 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
u32 udma;

pci_read_config_dword(pdev, 0x60, &udma);
pi.private_data = (void *)(unsigned long)udma;
hpriv = (void *)(unsigned long)udma;
}

/* And fire it up */
return ata_pci_init_one(pdev, ppi, &amd_sht);
return ata_pci_init_one(pdev, ppi, &amd_sht, hpriv);
}

#ifdef CONFIG_PM
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_artop.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id)

BUG_ON(ppi[0] == NULL);

return ata_pci_init_one(pdev, ppi, &artop_sht);
return ata_pci_init_one(pdev, ppi, &artop_sht, NULL);
}

static const struct pci_device_id artop_pci_tbl[] = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_atiixp.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static int atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id)
.port_ops = &atiixp_port_ops
};
const struct ata_port_info *ppi[] = { &info, NULL };
return ata_pci_init_one(dev, ppi, &atiixp_sht);
return ata_pci_init_one(dev, ppi, &atiixp_sht, NULL);
}

static const struct pci_device_id atiixp[] = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_cmd640.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ static int cmd640_init_one(struct pci_dev *pdev, const struct pci_device_id *id)

cmd640_hardware_init(pdev);

return ata_pci_init_one(pdev, ppi, &cmd640_sht);
return ata_pci_init_one(pdev, ppi, &cmd640_sht, NULL);
}

#ifdef CONFIG_PM
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_cmd64x.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
pci_write_config_byte(pdev, UDIDETCR0, 0xF0);
#endif

return ata_pci_init_one(pdev, ppi, &cmd64x_sht);
return ata_pci_init_one(pdev, ppi, &cmd64x_sht, NULL);
}

#ifdef CONFIG_PM
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_cs5530.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ static int cs5530_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
ppi[1] = &info_palmax_secondary;

/* Now kick off ATA set up */
return ata_pci_init_one(pdev, ppi, &cs5530_sht);
return ata_pci_init_one(pdev, ppi, &cs5530_sht, NULL);
}

#ifdef CONFIG_PM
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_cs5535.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static int cs5535_init_one(struct pci_dev *dev, const struct pci_device_id *id)
rdmsr(ATAC_CH0D1_PIO, timings, dummy);
if (CS5535_BAD_PIO(timings))
wrmsr(ATAC_CH0D1_PIO, 0xF7F4F7F4UL, 0);
return ata_pci_init_one(dev, ppi, &cs5535_sht);
return ata_pci_init_one(dev, ppi, &cs5535_sht, NULL);
}

static const struct pci_device_id cs5535[] = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_cs5536.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static int cs5536_init_one(struct pci_dev *dev, const struct pci_device_id *id)
return -ENODEV;
}

return ata_pci_init_one(dev, ppi, &cs5536_sht);
return ata_pci_init_one(dev, ppi, &cs5536_sht, NULL);
}

static const struct pci_device_id cs5536[] = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_cypress.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static int cy82c693_init_one(struct pci_dev *pdev, const struct pci_device_id *i
if (PCI_FUNC(pdev->devfn) != 1)
return -ENODEV;

return ata_pci_init_one(pdev, ppi, &cy82c693_sht);
return ata_pci_init_one(pdev, ppi, &cy82c693_sht, NULL);
}

static const struct pci_device_id cy82c693[] = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/ata/pata_efar.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ static int efar_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
dev_printk(KERN_DEBUG, &pdev->dev,
"version " DRV_VERSION "\n");

return ata_pci_init_one(pdev, ppi, &efar_sht);
return ata_pci_init_one(pdev, ppi, &efar_sht, NULL);
}

static const struct pci_device_id efar_pci_tbl[] = {
Expand Down
12 changes: 6 additions & 6 deletions drivers/ata/pata_hpt366.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
.udma_mask = ATA_UDMA4,
.port_ops = &hpt366_port_ops
};
struct ata_port_info info = info_hpt366;
const struct ata_port_info *ppi[] = { &info, NULL };
const struct ata_port_info *ppi[] = { &info_hpt366, NULL };

void *hpriv = NULL;
u32 class_rev;
u32 reg1;
int rc;
Expand All @@ -383,17 +383,17 @@ static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
/* info_hpt366 is safe against re-entry so we can scribble on it */
switch((reg1 & 0x700) >> 8) {
case 5:
info.private_data = &hpt366_40;
hpriv = &hpt366_40;
break;
case 9:
info.private_data = &hpt366_25;
hpriv = &hpt366_25;
break;
default:
info.private_data = &hpt366_33;
hpriv = &hpt366_33;
break;
}
/* Now kick off ATA set up */
return ata_pci_init_one(dev, ppi, &hpt36x_sht);
return ata_pci_init_one(dev, ppi, &hpt36x_sht, hpriv);
}

#ifdef CONFIG_PM
Expand Down
33 changes: 14 additions & 19 deletions drivers/ata/pata_hpt37x.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,10 +831,8 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
};

static const int MHz[4] = { 33, 40, 50, 66 };
const struct ata_port_info *port;
void *private_data = NULL;
struct ata_port_info port_info;
const struct ata_port_info *ppi[] = { &port_info, NULL };
const struct ata_port_info *ppi[] = { NULL, NULL };

u8 irqmask;
u32 class_rev;
Expand Down Expand Up @@ -866,17 +864,17 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)

switch(class_rev) {
case 3:
port = &info_hpt370;
ppi[0] = &info_hpt370;
chip_table = &hpt370;
prefer_dpll = 0;
break;
case 4:
port = &info_hpt370a;
ppi[0] = &info_hpt370a;
chip_table = &hpt370a;
prefer_dpll = 0;
break;
case 5:
port = &info_hpt372;
ppi[0] = &info_hpt372;
chip_table = &hpt372;
break;
default:
Expand All @@ -889,21 +887,21 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
/* 372N if rev >= 2*/
if (class_rev >= 2)
return -ENODEV;
port = &info_hpt372;
ppi[0] = &info_hpt372;
chip_table = &hpt372a;
break;
case PCI_DEVICE_ID_TTI_HPT302:
/* 302N if rev > 1 */
if (class_rev > 1)
return -ENODEV;
port = &info_hpt372;
ppi[0] = &info_hpt372;
/* Check this */
chip_table = &hpt302;
break;
case PCI_DEVICE_ID_TTI_HPT371:
if (class_rev > 1)
return -ENODEV;
port = &info_hpt372;
ppi[0] = &info_hpt372;
chip_table = &hpt371;
/* Single channel device, master is not present
but the BIOS (or us for non x86) must mark it
Expand All @@ -914,7 +912,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
break;
case PCI_DEVICE_ID_TTI_HPT374:
chip_table = &hpt374;
port = &info_hpt374;
ppi[0] = &info_hpt374;
break;
default:
printk(KERN_ERR "pata_hpt37x: PCI table is bogus please report (%d).\n", dev->device);
Expand Down Expand Up @@ -993,7 +991,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
int dpll, adjust;

/* Compute DPLL */
dpll = (port->udma_mask & 0xC0) ? 3 : 2;
dpll = (ppi[0]->udma_mask & 0xC0) ? 3 : 2;

f_low = (MHz[clock_slot] * 48) / MHz[dpll];
f_high = f_low + 2;
Expand Down Expand Up @@ -1033,19 +1031,16 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
* about lack of UDMA133 support on lower clocks
*/

if (clock_slot < 2 && port == &info_hpt370)
port = &info_hpt370_33;
if (clock_slot < 2 && port == &info_hpt370a)
port = &info_hpt370a_33;
if (clock_slot < 2 && ppi[0] == &info_hpt370)
ppi[0] = &info_hpt370_33;
if (clock_slot < 2 && ppi[0] == &info_hpt370a)
ppi[0] = &info_hpt370a_33;
printk(KERN_INFO "pata_hpt37x: %s using %dMHz bus clock.\n",
chip_table->name, MHz[clock_slot]);
}

/* Now kick off ATA set up */
port_info = *port;
port_info.private_data = private_data;

return ata_pci_init_one(dev, ppi, &hpt37x_sht);
return ata_pci_init_one(dev, ppi, &hpt37x_sht, private_data);
}

static const struct pci_device_id hpt37x[] = {
Expand Down
Loading

0 comments on commit 887125e

Please sign in to comment.