Skip to contentSkip to conversation

pci_get_device, new driver model

RFClue William D Waddington 3 participants 7 messages Oct 7, 2005

lore
Share & tools
lore
#0 lore raw

CRAP, I think this one got sent when half written - sorry about that.

I'm missing something fundamental, and beg your indulgence. Read LDD 3, googled, and looked around in the code (but not in the right places...)

My current 2.6 drivers support multiple identical PCI boards per host. The init code spins on pci_find_device and assigns instance/minor numbers as boards are found. Load script insmods the driver, gets the major # from /proc/devices, and creates the /dev/ entries on the fly.

If I convert to pci_get_device, it looks like subsequent calls in the loop "put" the previously "gotten" device. I need the pci_dev struct to persist for later use (DMA, etc). Do I take an additional bump to the ref count for each board found before looping, and "put" each when the driver is unloaded?

If I just give in to the new driver model how/when do I associate instance/minor numbers with boards found? Is it ever possible for ordinary PCI boards to be (logically) removed and re-added w/out removing the driver? If so, how to maintain association between a particular board and minor number?

I don't have any control over the tools available on the user's target host.

Pointers to code supporting multiple boards per driver would be very helpful.

Not subscribed but lurking. Thanks,
Bill

Signature · 7 lines
--------------------------------------------
William D Waddington
Bainbridge Island, WA, USA
[email protected]
--------------------------------------------
"Even bugs...are unexpected signposts on
the long road of creativity..." - Ken Burtch
#1 lore raw
Quoted 5 lines · William D Waddington

If I convert to pci_get_device, it looks like subsequent calls in the loop "put" the previously "gotten" device. I need the pci_dev struct to persist for later use (DMA, etc). Do I take an additional bump to the ref count for each board found before looping, and "put" each when the driver is unloaded?

If you are saving the pci device point then yes you should. If you are using pci_module_init() and the hotplug interface instead then it may not be neccessary.

Quoted 5 lines

If I just give in to the new driver model how/when do I associate instance/minor numbers with boards found? Is it ever possible for ordinary PCI boards to be (logically) removed and re-added w/out removing the driver? If so, how to maintain association between a particular board and minor number?

Its up to you how you implement this. One requirement I suspect would be that the boards have unique serial numbers. Most drivers do not retain state if someone unplugs a board, moves it and plugs it back in. Instead they report the old device as "gone" and let user space sort it out

#2 lore raw
Quoted 9 lines · Alan Cox
Quoted 5 lines · William D Waddington

If I just give in to the new driver model how/when do I associate instance/minor numbers with boards found? Is it ever possible for ordinary PCI boards to be (logically) removed and re-added w/out removing the driver? If so, how to maintain association between a particular board and minor number?

Quoted 4 lines

Its up to you how you implement this. One requirement I suspect would be that the boards have unique serial numbers. Most drivers do not retain state if someone unplugs a board, moves it and plugs it back in. Instead they report the old device as "gone" and let user space sort it out

I don't have unique serial #s available, but my question wasn't clear.

Is it ever possible that the hotplug stuff will try to remove and re-add one (or all) of my boards when there _hasn't_ been a physical change or power cycle/reboot/driver reload/whatever.

As long as the driver gets reloaded following any logical or physical system change I will just go through the instance/minor assignment again. What I don't want is /dev/idr0 /dev/idr1 turning into /dev/idr2 /dev/idr3 because someone tickled the hotplug controls.

Still not quite clear how to assocuiate instance/minor #s with boards. Do I just keep a global counter and bump it each time probe (or init) gets called for each board? Hence my worry above.

Thanks for the quick reply.

Bill (not sure if this will thread OK)
--------------------------------------------
William D Waddington
Bainbridge Island, WA, USA
[email protected]
--------------------------------------------
"Even bugs...are unexpected signposts on
the long road of creativity..." - Ken Burtch

#3 lore raw
Quoted 3 lines · William D Waddington

Is it ever possible that the hotplug stuff will try to remove and re-add one (or all) of my boards when there _hasn't_ been a physical change or power cycle/reboot/driver reload/whatever.

Only if the user does it deliberately.

Quoted 3 lines

Still not quite clear how to assocuiate instance/minor #s with boards. Do I just keep a global counter and bump it each time probe (or init) gets called for each board? Hence my worry above.

It really is up to you. Most drivers just issue the first free minor number.

Alan

#4 lore raw
In reply to William D Waddington
Quoted 10 lines · William D Waddington

CRAP, I think this one got sent when half written - sorry about that.

I'm missing something fundamental, and beg your indulgence. Read LDD 3, googled, and looked around in the code (but not in the right places...)

My current 2.6 drivers support multiple identical PCI boards per host. The init code spins on pci_find_device and assigns instance/minor numbers as boards are found. Load script insmods the driver, gets the major # from /proc/devices, and creates the /dev/ entries on the fly.

Ick, don't do that.

Quoted 5 lines

If I convert to pci_get_device, it looks like subsequent calls in the loop "put" the previously "gotten" device. I need the pci_dev struct to persist for later use (DMA, etc). Do I take an additional bump to the ref count for each board found before looping, and "put" each when the driver is unloaded?

When you save the pointer off, you need to increment the count.

Quoted 2 lines

If I just give in to the new driver model how/when do I associate instance/minor numbers with boards found?

It doesn't matter. Use udev to handle your device naming for you, it can associate any type of name with any type of device you have, and you can do it by topology, location, serial number, or the phase of the moon.

Quoted 2 lines

Is it ever possible for ordinary PCI boards to be (logically) removed and re-added w/out removing the driver?

Yes, on hotplug pci systems. You can fake this out by testing with the fakephp driver if you don't have this kind of hardware.

Quoted 2 lines

If so, how to maintain association between a particular board and minor number?

Again, use udev, that's what it is there for.

Hope this helps,

greg k-h

#5 lore raw
Quoted 2 lines · Greg KH
Quoted 2 lines

If I just give in to the new driver model how/when do I associate instance/minor numbers with boards found?

Oh, and if you don't convert to the new driver model, your driver will just die a horrible death on pci hotplug systems, as it has no way to be notified that the device was removed.

thanks,

greg k-h

#6 lore raw
Quoted 5 lines · Greg KH
Quoted 2 lines · Greg KH
Quoted 2 lines

If I just give in to the new driver model how/when do I associate instance/minor numbers with boards found?

Oh, and if you don't convert to the new driver model,

And it's not "new" at all, it's been there since 2.3 days, so it's not like you haven't had enough warning...

thanks,

greg k-h