Skip to contentSkip to conversation

finding pci_dev from scsi_device

DISCUSSION Herbert Rosmanith 2 participants 10 messages Jun 26, 2006

lore
Share & tools
lore
#0 lore raw

good day,

Could someone please tell me how to find the corresponding "struct pci_dev *" from a given "struct scsi_device *"?

I've been searching through structures/header files now for quite some time, but cannot find anything.

thanks in advance,
h.rosmanith

#1 lore raw
Quoted 7 lines · Herbert Rosmanith

good day,

Could someone please tell me how to find the corresponding "struct pci_dev *" from a given "struct scsi_device *"?

I've been searching through structures/header files now for quite some time, but cannot find anything.

looking at my isa bus scsi controller... I'd say that that is a really hard question that doesn't even always have an answer ;)

can you share with us what you want to do with this?

Greetings,
Arjan van de Ven

#2 lore raw
Quoted 8 lines
Quoted 5 lines

Could someone please tell me how to find the corresponding "struct pci_dev *" from a given "struct scsi_device *"?

I've been searching through structures/header files now for quite some time, but cannot find anything.

looking at my isa bus scsi controller... I'd say that that is a really hard question that doesn't even always have an answer ;)

umh, yes, but in this case, I'm sure I always have a pci_dev.

Quoted 1 line

can you share with us what you want to do with this?

I need the pci_dev to reconfigure ahci-controllers so that they look like having been initialised by BIOS at reboot time.

kind regards,
h.rosmanith

#3 lore raw
Quoted 5 lines
Quoted 2 lines

can you share with us what you want to do with this?

I need the pci_dev to reconfigure ahci-controllers so that they look like having been initialised by BIOS at reboot time.

isn't it better to do this in the ahci driver itself instead? it for sure will be orders of magnitude easier....

#4 lore raw
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

can you share with us what you want to do with this?

I need the pci_dev to reconfigure ahci-controllers so that they look like having been initialised by BIOS at reboot time.

isn't it better to do this in the ahci driver itself instead?

guess what I'm doing.

Quoted 1 line

it for sure will be orders of magnitude easier....

yes?

#5 lore raw
Quoted 6 lines · Herbert Rosmanith
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

can you share with us what you want to do with this?

I need the pci_dev to reconfigure ahci-controllers so that they look like having been initialised by BIOS at reboot time.

Quoted 7 lines
Quoted 1 line

isn't it better to do this in the ahci driver itself instead?

guess what I'm doing.

Quoted 1 line

it for sure will be orders of magnitude easier....

yes?

static int ahci_host_init(struct ata_probe_ent *probe_ent)

{
        struct ahci_host_priv *hpriv = probe_ent->private_data;
        struct pci_dev *pdev = to_pci_dev(probe_ent->dev);

as you can see, you can easily go from an ata_probe_ent to a pci device...

also.. you could just put your code into the remove hook... :)

#6 lore raw
Quoted 2 lines

also.. you could just put your code into the remove hook... :)

oh by the way, that's the reason why I need to find the pci-pointer myself. in our environment, the remove hook is never called.

kind regards,
h.rosmanith

#7 lore raw
In reply to Arjan van de Ven
Quoted 4 lines
        struct pci_dev *pdev = to_pci_dev(probe_ent->dev);

as you can see, you can easily go from an ata_probe_ent to a pci device...

just for the sake of completeness:

static int ahci_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) { struct pci_dev *pdev;

	pdev=to_pci_dev(((struct ata_port *)&scsidev->host->hostdata[0])->host_set->dev);

kind regards,
h.rosmanith

#8 lore raw
In reply to Arjan van de Ven
Quoted 2 lines

isn't it better to do this in the ahci driver itself instead? it for sure will be orders of magnitude easier....

drivers/scsi/ahci.c:

// XXX added herp
static int ahci_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg) {
...

For some reason, I have to use an ioctl to reconfigure the controller. This means that I don't have the "struct pci_dev *pdev" from ahci_init_one and ahci_remove_one.

I could store a pointer to pci_dev by extending "struct ahci_host_priv", but before doing this, I'm trying to figure out if there's a "correct" way of finding a pci_dev from a scsi_device.

Quoted 1 line

From the scsi_device, I know I can get a "struct ata_port", from there

a "struct Scsi_Host", a "struct ata_host_set" and even a generic "struct device *".

Now all that's missing is a pointer to "struct pci_dev". Is there a function to enumerate all "struct device", in that case I could compare "struct pci_dev -> dev", if the pointers match, I've found it.

kind regards,
h.rosmanith

#9 lore raw
Quoted 3 lines
Quoted 1 line

From the scsi_device, I know I can get a "struct ata_port", from there

a "struct Scsi_Host", a "struct ata_host_set" and even a generic "struct device *".

Arjan> static int ahci_host_init(struct ata_probe_ent *probe_ent) Arjan> {
Arjan> struct ahci_host_priv *hpriv = probe_ent->private_data;
Arjan> struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
Arjan>
Arjan> as you can see, you can easily go from an ata_probe_ent to a pci Arjan> device...

ah! that looks promising. looks like "to_pci_dev" is what I've been searching.

thanks, I'll try immediately :)

kind regards,
h.rosmanith