patch for sysfs in the cyclades driver
Hi
I will have to study again the code I tried first (it was long ago), but the main problem was that due to that class be (somehow) derived from class_simple, I can one export using it the major and minor numbers for the device. Tosatti, maybe you can complete my answer with details, since it was you that advised me about this limitation. However, this was some time ago (kernel 2.6.7 was going to be released), and I didn't check how much sysfs for the tty drivers has changed since them. If I can attach this data (signalling states) to the port, it would be very preferable than attaching to the board as me and Scott are trying. Even because his advise about the possibility of my patch be overwritting one channel data with other's make a lot of sense and I will have to test it (I'm grateful for you, Scott).
Cheers :)
Germano
Quoted 5 lines · Scott
Quoted 5 lines
I know you have done work on USB serial drivers with devices with multiple ports...
Is there any way to create a file in sys that can point back to a port, and NOT the port's
parent (ie, the board) WITHOUT having to create a new kobject per port?
What's wrong with the kobject in /sys/class/tty/ which has one object per port? I think we might not be exporting that class_device structure, but I would not have a problem with doing that.
thanks,
greg k-h
Quoted 14 lines · Germano
Hi
I will have to study again the code I tried first (it was long ago), but the main problem was that due to that class be (somehow) derived from
class_simple, I can one export using it the major and minor numbers for the device. Tosatti, maybe you can complete my answer with details, since it was you that advised me about this limitation. However, this was some time ago (kernel 2.6.7 was going to be released), and I didn't check how much sysfs for the tty drivers has changed since them. If I can attach this data (signalling states) to the port, it would be very preferable than attaching to the board as me and Scott are trying. Even because his advise about the possibility of my patch be overwritting one channel data with other's make a lot of sense and I will have to test it (I'm grateful for you, Scott).
The problem was class_simple only contains the "dev" attribute. You can't add other attributes to it.
The correct thing should be to create "class_tty" with all necessary attributes (speed, data transferred, etc).
But thats not a v2.6 thing I believe.
I talked to Greg about this at the time and he agreed we need a "class_tty" type.
Quoted 12 lines
Cheers :)
GermanoQuoted 5 lines · Scott
Quoted 5 lines
I know you have done work on USB serial drivers with devices with multiple ports...
Is there any way to create a file in sys that can point back to a port, and NOT the port's
parent (ie, the board) WITHOUT having to create a new kobject per port?What's wrong with the kobject in
/sys/class/tty/which has one object per port? I think we might not be exporting thatclass_devicestructure, but I would not have a problem with doing that.
Marcelo> The problem was class_simple only contains the "dev" Marcelo> attribute. You can't add other attributes to it.
I believe, based on the comment in class_simple.c:
Any further sysfs files that might be required can be created using this pointer.
and the implementation in in drivers/scsi/st.c, that there's no problem adding attributes to a device in a simple class. You can just use class_set_devdata() on your class_device to set whatever context you need to get back to your internal structures, and then use class_device_create_file() to add the attributes.
I assume this is OK (since there is already one in-kernel driver doing it), but Greg, can you confirm that it's definitely OK for a driver to use class_set_devdata() on a class_device from class_simple_device_add()?
Thanks,
Roland
Quoted 13 lines · Roland Dreier
Marcelo> The problem was
class_simpleonly contains the "dev" Marcelo> attribute. You can't add other attributes to it.I believe, based on the comment in
class_simple.c:Any further sysfs files that might be required can be created using this pointer.
and the implementation in in
drivers/scsi/st.c, that there's no problem adding attributes to a device in a simple class. You can just useclass_set_devdata()on yourclass_deviceto set whatever context you need to get back to your internal structures, and then useclass_device_create_file()to add the attributes.
Quoted 3 lines
I assume this is OK (since there is already one in-kernel driver doing it), but Greg, can you confirm that it's definitely OK for a driver to use
class_set_devdata()on aclass_devicefromclass_simple_device_add()?
Hi Roland,
Oh thanks, I didnt knew the existance of such possibily.
I once asked here on the list:
---------
Hope this is not a FAQ.
I want to export some read-only attributes (statistics) from cyclades.c char driver to userspace via sysfs.
I can't figure out the right place to do it - I could create a class under /sys/class/cyclades for example, but that doesnt sound right since this is not a "class" of device, but a device itself.
Hooking the statistics into /sys/class/tty/ttyC$/ sounds reasonable, but its not possible it seems because "tty" is a class_simple class, which only implements the "dev" attribute.
------ Greg answer was:
For a driver only attribute, you want them to show up in the place for the driver (like under /sys/bus/pci/driver/MY_FOO_DRIVER/). To do that use the DRIVER_ATTR() and the driver_add_file() functions. For examples, see the other drivers that use these functions.
But I hope you are right - /sys/class/tty/tty$/
sounds the correct place for those files - I thought a "class_tty" class was required for new attributes.
Marcelo> ------ Greg answer was:
Greg> For a driver only attribute, you want them to show up in the Greg> place for the driver (like under
Greg> /sys/bus/pci/driver/MY_FOO_DRIVER/). To do that use the Greg> DRIVER_ATTR() and the driver_add_file() functions. For Greg> examples, see the other drivers that use these functions.
I think Greg may have misunderstood the question and told you how to expose per-driver attributes. But I think the attributes you want really are per-device and should be attached to the class_device, not the driver.
- Roland
Quoted 13 lines · Roland Dreier
Marcelo> The problem was
class_simpleonly contains the "dev" Marcelo> attribute. You can't add other attributes to it.I believe, based on the comment in
class_simple.c:Any further sysfs files that might be required can be created using this pointer.
and the implementation in in
drivers/scsi/st.c, that there's no problem adding attributes to a device in a simple class. You can just useclass_set_devdata()on yourclass_deviceto set whatever context you need to get back to your internal structures, and then useclass_device_create_file()to add the attributes.
Quoted 3 lines
I assume this is OK (since there is already one in-kernel driver doing it), but Greg, can you confirm that it's definitely OK for a driver to use
class_set_devdata()on aclass_devicefromclass_simple_device_add()?
Hm, I think that should be ok, but I'd make sure to test it before verifying that it really is :)
thanks,
greg k-h
Quoted 47 lines · Marcelo Tosatti
Quoted 13 lines · Roland Dreier
Marcelo> The problem was
class_simpleonly contains the "dev" Marcelo> attribute. You can't add other attributes to it.I believe, based on the comment in
class_simple.c:Any further sysfs files that might be required can be created using this pointer.
and the implementation in in
drivers/scsi/st.c, that there's no problem adding attributes to a device in a simple class. You can just useclass_set_devdata()on yourclass_deviceto set whatever context you need to get back to your internal structures, and then useclass_device_create_file()to add the attributes.Quoted 3 lines
I assume this is OK (since there is already one in-kernel driver doing it), but Greg, can you confirm that it's definitely OK for a driver to use
class_set_devdata()on aclass_devicefromclass_simple_device_add()?Hi Roland,
Oh thanks, I didnt knew the existance of such possibily.
I once asked here on the list:
---------
Hope this is not a FAQ.
I want to export some read-only attributes (statistics) from
cyclades.cchar driver to userspace via sysfs.I can't figure out the right place to do it - I could create a class under
/sys/class/cycladesfor example, but that doesnt sound right since this is not a "class" of device, but a device itself.Hooking the statistics into
/sys/class/tty/ttyC$/sounds reasonable, but its not possible it seems because "tty" is aclass_simpleclass, which only implements the "dev" attribute.------ Greg answer was:
For a driver only attribute, you want them to show up in the place for the driver (like under
/sys/bus/pci/driver/MY_FOO_DRIVER/). To do that use theDRIVER_ATTR()and thedriver_add_file()functions. For examples, see the other drivers that use these functions.
Quoted 3 lines
But I hope you are right -
/sys/class/tty/tty$/
sounds the correct place for those files - I thought a "class_tty" class was required for new attributes.
No, Roland is right, just use the class_device pointer you get back from the core when a tty device is created.
Right now we aren't saving the pointer anywhere (see tty_register_device() for where it is created.) Just add that to the proper tty_device structure, and you should be fine (yeah, it's going to be a pain, and you will quickly see why I didn't do that in the first place, but it is going to need to be changed eventually...)
Good luck,
greg k-h
Quoted 8 lines · Roland Dreier
Marcelo> ------ Greg answer was:
Greg> For a driver only attribute, you want them to show up in the Greg> place for the driver (like under
Greg>/sys/bus/pci/driver/MY_FOO_DRIVER/). To do that use the Greg>DRIVER_ATTR()and thedriver_add_file()functions. For Greg> examples, see the other drivers that use these functions.
Quoted 4 lines
I think Greg may have misunderstood the question and told you how to expose per-driver attributes. But I think the attributes you want really are per-device and should be attached to the
class_device, not the driver.
Heh, yes. Per-driver attributes go in the driver's directory. Per port attributes go in the port's directory. Simple as that :)
thanks,
greg k-h
Roland> I assume this is OK (since there is already one in-kernel Roland> driver doing it), but Greg, can you confirm that it's Roland> definitely OK for a driver to use class_set_devdata() on a Roland> class_device from class_simple_device_add()?
Greg> Hm, I think that should be ok, but I'd make sure to test it Greg> before verifying that it really is :)
Well class_simple.c definitely doesn't use class_data/class_set_devdata() now (and as I said drivers/scsi/st.c is using this on a class_simple device). The question is whether you can bless this situation as part of the API, or whether some time in the future class_simple might start using class_data.
- R.
Quoted 5 lines · Roland Dreier
Roland> I assume this is OK (since there is already one in-kernel Roland> driver doing it), but Greg, can you confirm that it's Roland> definitely OK for a driver to use
class_set_devdata()on a Roland>class_devicefromclass_simple_device_add()?
Quoted 8 lines
Greg> Hm, I think that should be ok, but I'd make sure to test it Greg> before verifying that it really is :)
Well
class_simple.cdefinitely doesn't use class_data/class_set_devdata() now (and as I saiddrivers/scsi/st.cis using this on aclass_simpledevice). The question is whether you can bless this situation as part of the API, or whether some time in the futureclass_simplemight start usingclass_data.
Hey, if it works today, great! If I, or someone else breaks this in the future, they they will have to deal with the issue then :)
In short, use it.
thanks,
greg k-h