views:

322

answers:

1

A few months ago I had to write a small tool to program the eeprom of a rtl8139-card. It's basically the rtl8139-diag tool stripped down to read/write the eeprom.

This tool has to be extend to be able to program the eeprom of rtl8101-cards now. This was not a problem, as the interface to the eeprom is similar to the one of the rtl8139. Actually, the only difference is the contents of the eeprom-file.

What I want to implement is an auto-detection that checks, if the card at the given port-address is an rtl8139 or rtl8101 and selects the fitting eeprom-dump. I cannot determine the difference of these chips by reading out the eeprom as the cards to be programmed are 'virgin' and the eeprom-contents is basically 0xffff.

I noticed, that Linux always loads the fitting driver for these cards, regardless of the contents of the eeprom. So I think, that I just have to read the chip-id of the card.

How do I do that?

+3  A: 

I think you may find lspci or lspci -vv will help you. (You may need to be root.)

That is, if the PCI id is set in the card, and not determined from the eeprom, you should be able to use lspci to get the card's PCI id and determine which card you're working with.

The -n option will give you the raw numbers, which will probably be more helpful if you're scripting this.

Alternatively, you could read from /sys/devices/pci*/*/device and vendor to find those values.

retracile
That would be a solution, if I could change the environment calling the program (call lspci, regexp to get the chipid, call program with switch), but unfortunately I've to implement the auto-detection inside the tool.
flokra
Then read the `/sys` files from within the program. If that won't work, you need to explain the constraints more.
retracile
Thanks, that'll do it. I might have to scan all devices for their id and IO-Port, but that's ok.
flokra