All of lore.kernel.org
 help / color / mirror / Atom feed
* How to register a new "function" in configfs?
@ 2021-09-11  5:43 Ajay Garg
  2021-09-11 14:31 ` Michael Sweet
  0 siblings, 1 reply; 7+ messages in thread
From: Ajay Garg @ 2021-09-11  5:43 UTC (permalink / raw)
  To: linux-usb

Hi All.

As a first step, I have been able to load a gadget on configfs, which
binds to the function "gser" (thus loading up the usb_f_serial module
when the gadget mounts). Things work well till here.

Now, I have written a brand-new gadget-side device-driver, trying to
create a new function "gusb", via DECLARE_USB_FUNCTION_INIT.
However, now when I try to load the gadget for binding to "gusb", I
get the error that the function cannot be found.

Seems that firing up a new gadget-side driver, that registers a new
function via DECLARE_USB_FUNCTION_INIT, is not enough to make the new
function visible across the kernel.

Kindly let know what I am missing.
Will be grateful for pointers.


Thanks and Regards,
Ajay

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to register a new "function" in configfs?
  2021-09-11  5:43 How to register a new "function" in configfs? Ajay Garg
@ 2021-09-11 14:31 ` Michael Sweet
  2021-09-11 14:58   ` Ajay Garg
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Sweet @ 2021-09-11 14:31 UTC (permalink / raw)
  To: Ajay Garg; +Cc: linux-usb

Ajay,

Quick question (as someone who has been down this road), do you need to do a kernel driver or could you just use the functionfs support to implement everything in userspace?  I found that path to be much easier and less error-prone (and one of these days I'm going to be contributing some documentation changes to make some things clearer...) and I was able to get my IPP-USB implementation up and running very quickly.


> On Sep 11, 2021, at 1:43 AM, Ajay Garg <ajaygargnsit@gmail.com> wrote:
> 
> Hi All.
> 
> As a first step, I have been able to load a gadget on configfs, which
> binds to the function "gser" (thus loading up the usb_f_serial module
> when the gadget mounts). Things work well till here.
> 
> Now, I have written a brand-new gadget-side device-driver, trying to
> create a new function "gusb", via DECLARE_USB_FUNCTION_INIT.
> However, now when I try to load the gadget for binding to "gusb", I
> get the error that the function cannot be found.
> 
> Seems that firing up a new gadget-side driver, that registers a new
> function via DECLARE_USB_FUNCTION_INIT, is not enough to make the new
> function visible across the kernel.
> 
> Kindly let know what I am missing.
> Will be grateful for pointers.
> 
> 
> Thanks and Regards,
> Ajay
> 

________________________
Michael Sweet




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to register a new "function" in configfs?
  2021-09-11 14:31 ` Michael Sweet
@ 2021-09-11 14:58   ` Ajay Garg
  2021-09-15 14:54     ` Ajay Garg
       [not found]     ` <CAHP4M8W-z_L3r0kDbW943A6hm9y3gXzYJd=ZOpi+w9okS1zaaQ@mail.gmail.com>
  0 siblings, 2 replies; 7+ messages in thread
From: Ajay Garg @ 2021-09-11 14:58 UTC (permalink / raw)
  To: Michael Sweet; +Cc: linux-usb

Hi Michael,

Thanks for the reply.

I am a bit of old-school, and would prefer things in one place only
(in the kernel) :)
Thus :

a)
I wish to have all the endpoints configuration/management in the
kernel only (like done in drivers/usb/gadget/function/f_serial.c,
drivers/usb/gadget/function/u_serial.c).

b)
Only the attributes like vendorId/productId would be in configfs, to
help setup the device.

c)
No user-space management of kernel objects.


Either-way, I think that my issue of "function exposure" would remain
the same, irrespective of whether we use configfs for managing the
kernel-objects (please correct me if I am wrong).


Thanks again for your time, look forward to listening back !


Thanks and Regards,
Ajay

On Sat, Sep 11, 2021 at 8:01 PM Michael Sweet <msweet@msweet.org> wrote:
>
> Ajay,
>
> Quick question (as someone who has been down this road), do you need to do a kernel driver or could you just use the functionfs support to implement everything in userspace?  I found that path to be much easier and less error-prone (and one of these days I'm going to be contributing some documentation changes to make some things clearer...) and I was able to get my IPP-USB implementation up and running very quickly.
>
>
> > On Sep 11, 2021, at 1:43 AM, Ajay Garg <ajaygargnsit@gmail.com> wrote:
> >
> > Hi All.
> >
> > As a first step, I have been able to load a gadget on configfs, which
> > binds to the function "gser" (thus loading up the usb_f_serial module
> > when the gadget mounts). Things work well till here.
> >
> > Now, I have written a brand-new gadget-side device-driver, trying to
> > create a new function "gusb", via DECLARE_USB_FUNCTION_INIT.
> > However, now when I try to load the gadget for binding to "gusb", I
> > get the error that the function cannot be found.
> >
> > Seems that firing up a new gadget-side driver, that registers a new
> > function via DECLARE_USB_FUNCTION_INIT, is not enough to make the new
> > function visible across the kernel.
> >
> > Kindly let know what I am missing.
> > Will be grateful for pointers.
> >
> >
> > Thanks and Regards,
> > Ajay
> >
>
> ________________________
> Michael Sweet
>
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to register a new "function" in configfs?
  2021-09-11 14:58   ` Ajay Garg
@ 2021-09-15 14:54     ` Ajay Garg
       [not found]     ` <CAHP4M8W-z_L3r0kDbW943A6hm9y3gXzYJd=ZOpi+w9okS1zaaQ@mail.gmail.com>
  1 sibling, 0 replies; 7+ messages in thread
From: Ajay Garg @ 2021-09-15 14:54 UTC (permalink / raw)
  To: Michael Sweet; +Cc: linux-usb

Any pointers, please?

On Sat, Sep 11, 2021 at 8:28 PM Ajay Garg <ajaygargnsit@gmail.com> wrote:
>
> Hi Michael,
>
> Thanks for the reply.
>
> I am a bit of old-school, and would prefer things in one place only
> (in the kernel) :)
> Thus :
>
> a)
> I wish to have all the endpoints configuration/management in the
> kernel only (like done in drivers/usb/gadget/function/f_serial.c,
> drivers/usb/gadget/function/u_serial.c).
>
> b)
> Only the attributes like vendorId/productId would be in configfs, to
> help setup the device.
>
> c)
> No user-space management of kernel objects.
>
>
> Either-way, I think that my issue of "function exposure" would remain
> the same, irrespective of whether we use configfs for managing the
> kernel-objects (please correct me if I am wrong).
>
>
> Thanks again for your time, look forward to listening back !
>
>
> Thanks and Regards,
> Ajay
>
> On Sat, Sep 11, 2021 at 8:01 PM Michael Sweet <msweet@msweet.org> wrote:
> >
> > Ajay,
> >
> > Quick question (as someone who has been down this road), do you need to do a kernel driver or could you just use the functionfs support to implement everything in userspace?  I found that path to be much easier and less error-prone (and one of these days I'm going to be contributing some documentation changes to make some things clearer...) and I was able to get my IPP-USB implementation up and running very quickly.
> >
> >
> > > On Sep 11, 2021, at 1:43 AM, Ajay Garg <ajaygargnsit@gmail.com> wrote:
> > >
> > > Hi All.
> > >
> > > As a first step, I have been able to load a gadget on configfs, which
> > > binds to the function "gser" (thus loading up the usb_f_serial module
> > > when the gadget mounts). Things work well till here.
> > >
> > > Now, I have written a brand-new gadget-side device-driver, trying to
> > > create a new function "gusb", via DECLARE_USB_FUNCTION_INIT.
> > > However, now when I try to load the gadget for binding to "gusb", I
> > > get the error that the function cannot be found.
> > >
> > > Seems that firing up a new gadget-side driver, that registers a new
> > > function via DECLARE_USB_FUNCTION_INIT, is not enough to make the new
> > > function visible across the kernel.
> > >
> > > Kindly let know what I am missing.
> > > Will be grateful for pointers.
> > >
> > >
> > > Thanks and Regards,
> > > Ajay
> > >
> >
> > ________________________
> > Michael Sweet
> >
> >
> >

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to register a new "function" in configfs?
       [not found]     ` <CAHP4M8W-z_L3r0kDbW943A6hm9y3gXzYJd=ZOpi+w9okS1zaaQ@mail.gmail.com>
@ 2021-09-17 14:17       ` Michael Sweet
  2021-09-17 15:25         ` Ajay Garg
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Sweet @ 2021-09-17 14:17 UTC (permalink / raw)
  To: Ajay Garg; +Cc: linux-usb

Ajay,

It is really hard to help further without seeing source code...

I assume you've verified that your gadget driver module is loaded?

And in your code:

- Did you use the MODULE_LICENSE, MODULE_AUTHOR, and MODULE_DESCRIPTION macros to define your driver metadata?
- Did you use the module_init and module_exit macros?


> On Sep 15, 2021, at 9:51 AM, Ajay Garg <ajaygargnsit@gmail.com> wrote:
> 
> Any pointers, please?
> 
> On Sat, 11 Sep 2021, 20:28 Ajay Garg, <ajaygargnsit@gmail.com> wrote:
> Hi Michael,
> 
> Thanks for the reply.
> 
> I am a bit of old-school, and would prefer things in one place only
> (in the kernel) :)
> Thus :
> 
> a)
> I wish to have all the endpoints configuration/management in the
> kernel only (like done in drivers/usb/gadget/function/f_serial.c,
> drivers/usb/gadget/function/u_serial.c).
> 
> b)
> Only the attributes like vendorId/productId would be in configfs, to
> help setup the device.
> 
> c)
> No user-space management of kernel objects.
> 
> 
> Either-way, I think that my issue of "function exposure" would remain
> the same, irrespective of whether we use configfs for managing the
> kernel-objects (please correct me if I am wrong).
> 
> 
> Thanks again for your time, look forward to listening back !
> 
> 
> Thanks and Regards,
> Ajay
> 
> On Sat, Sep 11, 2021 at 8:01 PM Michael Sweet <msweet@msweet.org> wrote:
> >
> > Ajay,
> >
> > Quick question (as someone who has been down this road), do you need to do a kernel driver or could you just use the functionfs support to implement everything in userspace?  I found that path to be much easier and less error-prone (and one of these days I'm going to be contributing some documentation changes to make some things clearer...) and I was able to get my IPP-USB implementation up and running very quickly.
> >
> >
> > > On Sep 11, 2021, at 1:43 AM, Ajay Garg <ajaygargnsit@gmail.com> wrote:
> > >
> > > Hi All.
> > >
> > > As a first step, I have been able to load a gadget on configfs, which
> > > binds to the function "gser" (thus loading up the usb_f_serial module
> > > when the gadget mounts). Things work well till here.
> > >
> > > Now, I have written a brand-new gadget-side device-driver, trying to
> > > create a new function "gusb", via DECLARE_USB_FUNCTION_INIT.
> > > However, now when I try to load the gadget for binding to "gusb", I
> > > get the error that the function cannot be found.
> > >
> > > Seems that firing up a new gadget-side driver, that registers a new
> > > function via DECLARE_USB_FUNCTION_INIT, is not enough to make the new
> > > function visible across the kernel.
> > >
> > > Kindly let know what I am missing.
> > > Will be grateful for pointers.
> > >
> > >
> > > Thanks and Regards,
> > > Ajay
> > >
> >
> > ________________________
> > Michael Sweet
> >
> >
> >

________________________
Michael Sweet




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to register a new "function" in configfs?
  2021-09-17 14:17       ` Michael Sweet
@ 2021-09-17 15:25         ` Ajay Garg
  2021-09-18  7:30           ` Ajay Garg
  0 siblings, 1 reply; 7+ messages in thread
From: Ajay Garg @ 2021-09-17 15:25 UTC (permalink / raw)
  To: Michael Sweet; +Cc: linux-usb

Hi Michael, thanks for the reply.

My gadget-driver is actually an almost copy of
drivers/usb/gadget/function/f_serial.c, except that the above
TTY-layer has been removed. I wrote this driver for my learning, to
learn simply sending/receiving of bytes using a host-driver as the
peer.

This test-driver of mine loads/works/communicates fine if

* I load my test-driver, exposing *gser* function.
* I load the gadget using *gser* function.

However, if

* I change the exposed function to something like *ajaytest* in my test-driver.
* Then load the driver (successfully).
* Then try loading the gadget using *ajaytest* function, the gadget
fails to load, saying "Function not found".


Let me see if I can post my code, probably on github, for a better public-view.

On Fri, Sep 17, 2021 at 7:47 PM Michael Sweet <msweet@msweet.org> wrote:
>
> Ajay,
>
> It is really hard to help further without seeing source code...
>
> I assume you've verified that your gadget driver module is loaded?
>
> And in your code:
>
> - Did you use the MODULE_LICENSE, MODULE_AUTHOR, and MODULE_DESCRIPTION macros to define your driver metadata?
> - Did you use the module_init and module_exit macros?
>
>
> > On Sep 15, 2021, at 9:51 AM, Ajay Garg <ajaygargnsit@gmail.com> wrote:
> >
> > Any pointers, please?
> >
> > On Sat, 11 Sep 2021, 20:28 Ajay Garg, <ajaygargnsit@gmail.com> wrote:
> > Hi Michael,
> >
> > Thanks for the reply.
> >
> > I am a bit of old-school, and would prefer things in one place only
> > (in the kernel) :)
> > Thus :
> >
> > a)
> > I wish to have all the endpoints configuration/management in the
> > kernel only (like done in drivers/usb/gadget/function/f_serial.c,
> > drivers/usb/gadget/function/u_serial.c).
> >
> > b)
> > Only the attributes like vendorId/productId would be in configfs, to
> > help setup the device.
> >
> > c)
> > No user-space management of kernel objects.
> >
> >
> > Either-way, I think that my issue of "function exposure" would remain
> > the same, irrespective of whether we use configfs for managing the
> > kernel-objects (please correct me if I am wrong).
> >
> >
> > Thanks again for your time, look forward to listening back !
> >
> >
> > Thanks and Regards,
> > Ajay
> >
> > On Sat, Sep 11, 2021 at 8:01 PM Michael Sweet <msweet@msweet.org> wrote:
> > >
> > > Ajay,
> > >
> > > Quick question (as someone who has been down this road), do you need to do a kernel driver or could you just use the functionfs support to implement everything in userspace?  I found that path to be much easier and less error-prone (and one of these days I'm going to be contributing some documentation changes to make some things clearer...) and I was able to get my IPP-USB implementation up and running very quickly.
> > >
> > >
> > > > On Sep 11, 2021, at 1:43 AM, Ajay Garg <ajaygargnsit@gmail.com> wrote:
> > > >
> > > > Hi All.
> > > >
> > > > As a first step, I have been able to load a gadget on configfs, which
> > > > binds to the function "gser" (thus loading up the usb_f_serial module
> > > > when the gadget mounts). Things work well till here.
> > > >
> > > > Now, I have written a brand-new gadget-side device-driver, trying to
> > > > create a new function "gusb", via DECLARE_USB_FUNCTION_INIT.
> > > > However, now when I try to load the gadget for binding to "gusb", I
> > > > get the error that the function cannot be found.
> > > >
> > > > Seems that firing up a new gadget-side driver, that registers a new
> > > > function via DECLARE_USB_FUNCTION_INIT, is not enough to make the new
> > > > function visible across the kernel.
> > > >
> > > > Kindly let know what I am missing.
> > > > Will be grateful for pointers.
> > > >
> > > >
> > > > Thanks and Regards,
> > > > Ajay
> > > >
> > >
> > > ________________________
> > > Michael Sweet
> > >
> > >
> > >
>
> ________________________
> Michael Sweet
>
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to register a new "function" in configfs?
  2021-09-17 15:25         ` Ajay Garg
@ 2021-09-18  7:30           ` Ajay Garg
  0 siblings, 0 replies; 7+ messages in thread
From: Ajay Garg @ 2021-09-18  7:30 UTC (permalink / raw)
  To: Michael Sweet; +Cc: linux-usb

I just had a hunch, and I checked the libusbgx code.
There it was found that there are function-specific checks, and *gser*
works because it is present here.

All in all, I need to add my function *ajaytest* in libusbgx (which I
will do locally).

I am sorry for the noise, and thanks everyone (especially Michael for
taking his time out).


Thanks and Regards,
Ajay

On Fri, Sep 17, 2021 at 8:55 PM Ajay Garg <ajaygargnsit@gmail.com> wrote:
>
> Hi Michael, thanks for the reply.
>
> My gadget-driver is actually an almost copy of
> drivers/usb/gadget/function/f_serial.c, except that the above
> TTY-layer has been removed. I wrote this driver for my learning, to
> learn simply sending/receiving of bytes using a host-driver as the
> peer.
>
> This test-driver of mine loads/works/communicates fine if
>
> * I load my test-driver, exposing *gser* function.
> * I load the gadget using *gser* function.
>
> However, if
>
> * I change the exposed function to something like *ajaytest* in my test-driver.
> * Then load the driver (successfully).
> * Then try loading the gadget using *ajaytest* function, the gadget
> fails to load, saying "Function not found".
>
>
> Let me see if I can post my code, probably on github, for a better public-view.
>
> On Fri, Sep 17, 2021 at 7:47 PM Michael Sweet <msweet@msweet.org> wrote:
> >
> > Ajay,
> >
> > It is really hard to help further without seeing source code...
> >
> > I assume you've verified that your gadget driver module is loaded?
> >
> > And in your code:
> >
> > - Did you use the MODULE_LICENSE, MODULE_AUTHOR, and MODULE_DESCRIPTION macros to define your driver metadata?
> > - Did you use the module_init and module_exit macros?
> >
> >
> > > On Sep 15, 2021, at 9:51 AM, Ajay Garg <ajaygargnsit@gmail.com> wrote:
> > >
> > > Any pointers, please?
> > >
> > > On Sat, 11 Sep 2021, 20:28 Ajay Garg, <ajaygargnsit@gmail.com> wrote:
> > > Hi Michael,
> > >
> > > Thanks for the reply.
> > >
> > > I am a bit of old-school, and would prefer things in one place only
> > > (in the kernel) :)
> > > Thus :
> > >
> > > a)
> > > I wish to have all the endpoints configuration/management in the
> > > kernel only (like done in drivers/usb/gadget/function/f_serial.c,
> > > drivers/usb/gadget/function/u_serial.c).
> > >
> > > b)
> > > Only the attributes like vendorId/productId would be in configfs, to
> > > help setup the device.
> > >
> > > c)
> > > No user-space management of kernel objects.
> > >
> > >
> > > Either-way, I think that my issue of "function exposure" would remain
> > > the same, irrespective of whether we use configfs for managing the
> > > kernel-objects (please correct me if I am wrong).
> > >
> > >
> > > Thanks again for your time, look forward to listening back !
> > >
> > >
> > > Thanks and Regards,
> > > Ajay
> > >
> > > On Sat, Sep 11, 2021 at 8:01 PM Michael Sweet <msweet@msweet.org> wrote:
> > > >
> > > > Ajay,
> > > >
> > > > Quick question (as someone who has been down this road), do you need to do a kernel driver or could you just use the functionfs support to implement everything in userspace?  I found that path to be much easier and less error-prone (and one of these days I'm going to be contributing some documentation changes to make some things clearer...) and I was able to get my IPP-USB implementation up and running very quickly.
> > > >
> > > >
> > > > > On Sep 11, 2021, at 1:43 AM, Ajay Garg <ajaygargnsit@gmail.com> wrote:
> > > > >
> > > > > Hi All.
> > > > >
> > > > > As a first step, I have been able to load a gadget on configfs, which
> > > > > binds to the function "gser" (thus loading up the usb_f_serial module
> > > > > when the gadget mounts). Things work well till here.
> > > > >
> > > > > Now, I have written a brand-new gadget-side device-driver, trying to
> > > > > create a new function "gusb", via DECLARE_USB_FUNCTION_INIT.
> > > > > However, now when I try to load the gadget for binding to "gusb", I
> > > > > get the error that the function cannot be found.
> > > > >
> > > > > Seems that firing up a new gadget-side driver, that registers a new
> > > > > function via DECLARE_USB_FUNCTION_INIT, is not enough to make the new
> > > > > function visible across the kernel.
> > > > >
> > > > > Kindly let know what I am missing.
> > > > > Will be grateful for pointers.
> > > > >
> > > > >
> > > > > Thanks and Regards,
> > > > > Ajay
> > > > >
> > > >
> > > > ________________________
> > > > Michael Sweet
> > > >
> > > >
> > > >
> >
> > ________________________
> > Michael Sweet
> >
> >
> >

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-09-18  7:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-11  5:43 How to register a new "function" in configfs? Ajay Garg
2021-09-11 14:31 ` Michael Sweet
2021-09-11 14:58   ` Ajay Garg
2021-09-15 14:54     ` Ajay Garg
     [not found]     ` <CAHP4M8W-z_L3r0kDbW943A6hm9y3gXzYJd=ZOpi+w9okS1zaaQ@mail.gmail.com>
2021-09-17 14:17       ` Michael Sweet
2021-09-17 15:25         ` Ajay Garg
2021-09-18  7:30           ` Ajay Garg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.