From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Alan Stern <stern@rowland.harvard.edu>,
linux-media@vger.kernel.org,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-usb@vger.kernel.org, tglx@linutronix.de,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Takashi Iwai <tiwai@suse.de>
Subject: [RFC] usb: add usb_fill_iso_urb()
Date: Fri, 13 Jul 2018 11:01:02 +0300 [thread overview]
Message-ID: <23211374.K0HmdtcaYO@avalon> (raw)
Hi Sebastian,
Thank you for the patch.
On Friday, 13 July 2018 01:35:27 EEST Sebastian Andrzej Siewior wrote:
> Provide usb_fill_iso_urb() for the initialisation of isochronous URBs.
> We already have one of this helpers for control, bulk and interruptible
> URB types. This helps to keep the initialisation of the URB members in
> one place.
> Update the documentation by adding this to the available init functions
> and remove the suggestion to use the `_int_' helper which might provide
> wrong encoding for the `interval' member.
>
> This looks like it would cover most users nicely. The sound subsystem
> initialises the ->iso_frame_desc[].offset + length member (often) at a
> different location and I'm not sure ->interval will work always as
> expected. So we might need to overwrite those two in worst case.
>
> Some users also initialise ->iso_frame_desc[].actual_length but I don't
s/I don't/I don't think/ ?
> this is required since it is the return value.
>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> Documentation/driver-api/usb/URB.rst | 12 +++----
> include/linux/usb.h | 53 ++++++++++++++++++++++++++++
> 2 files changed, 59 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/driver-api/usb/URB.rst
> b/Documentation/driver-api/usb/URB.rst index 61a54da9fce9..20030b781519
> 100644
> --- a/Documentation/driver-api/usb/URB.rst
> +++ b/Documentation/driver-api/usb/URB.rst
> @@ -116,11 +116,11 @@ What has to be filled in?
>
> Depending on the type of transaction, there are some inline functions
> defined in ``linux/usb.h`` to simplify the initialization, such as
> -:c:func:`usb_fill_control_urb`, :c:func:`usb_fill_bulk_urb` and
> -:c:func:`usb_fill_int_urb`. In general, they need the usb device pointer,
> -the pipe (usual format from usb.h), the transfer buffer, the desired
> transfer -length, the completion handler, and its context. Take a look at
> the some -existing drivers to see how they're used.
> +:c:func:`usb_fill_control_urb`, :c:func:`usb_fill_bulk_urb`,
> +:c:func:`usb_fill_int_urb` and :c:func:`usb_fill_iso_urb`. In general,
> they +need the usb device pointer, the pipe (usual format from usb.h), the
> transfer +buffer, the desired transfer length, the completion handler, and
> its context. +Take a look at the some existing drivers to see how they're
> used.
>
> Flags:
>
> @@ -243,7 +243,7 @@ Besides the fields present on a bulk transfer, for ISO,
> you also also have to set ``urb->interval`` to say how often to make
> transfers; it's often one per frame (which is once every microframe for
> highspeed devices). The actual interval used will be a power of two that's
> no bigger than what -you specify. You can use the
> :c:func:`usb_fill_int_urb` macro to fill +you specify. You can use the
> :c:func:`usb_fill_iso_urb` macro to fill most ISO transfer fields.
>
> For ISO transfers you also have to fill a
> :c:type:`usb_iso_packet_descriptor` diff --git a/include/linux/usb.h
> b/include/linux/usb.h
> index 4cdd515a4385..74a3339041d6 100644
> --- a/include/linux/usb.h
> +++ b/include/linux/usb.h
> @@ -1697,6 +1697,59 @@ static inline void usb_fill_int_urb(struct urb *urb,
> urb->start_frame = -1;
> }
>
> +/**
> + * usb_fill_iso_urb - macro to help initialize an isochronous urb
Strictly speaking this isn't a macro, so I'd write "initializes an isochronous
urb"
> + * @urb: pointer to the urb to initialize.
> + * @dev: pointer to the struct usb_device for this urb.
> + * @pipe: the endpoint pipe
> + * @transfer_buffer: pointer to the transfer buffer
> + * @buffer_length: length of the transfer buffer
> + * @complete_fn: pointer to the usb_complete_t function
> + * @context: what to set the urb context to.
> + * @interval: what to set the urb interval to, encoded like
> + * the endpoint descriptor's bInterval value.
> + * @packets: number of ISO packets.
> + * @packet_size: size of each ISO packet.
> + *
> + * Initializes an isochronous urb with the proper information needed to
> submit
> + * it to a device.
> + *
> + * Note that isochronous endpoints use a logarithmic encoding of the
> endpoint
> + * interval, and express polling intervals in microframes (eight per
> + * millisecond) rather than in frames (one per millisecond).
> + */
> +static inline void usb_fill_iso_urb(struct urb *urb,
> + struct usb_device *dev,
> + unsigned int pipe,
> + void *transfer_buffer,
> + int buffer_length,
> + usb_complete_t complete_fn,
> + void *context,
> + int interval,
> + unsigned int packets,
> + unsigned int packet_size)
> +{
> + unsigned int i;
> +
> + urb->dev = dev;
> + urb->pipe = pipe;
> + urb->transfer_buffer = transfer_buffer;
> + urb->transfer_buffer_length = buffer_length;
> + urb->complete = complete_fn;
> + urb->context = context;
> +
> + interval = clamp(interval, 1, 16);
> + urb->interval = 1 << (interval - 1);
> + urb->start_frame = -1;
> +
> + urb->number_of_packets = packets;
> +
> + for (i = 0; i < packets; i++) {
> + urb->iso_frame_desc[i].offset = packet_size * i;
> + urb->iso_frame_desc[i].length = packet_size;
> + }
> +}
I think this should be moved to a .c file as the function is growing big, but
that's true of the other URB helpers as well, so it can be done later in a
separate patch.
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> extern void usb_init_urb(struct urb *urb);
> extern struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags);
> extern void usb_free_urb(struct urb *urb);
WARNING: multiple messages have this Message-ID (diff)
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Alan Stern <stern@rowland.harvard.edu>,
linux-media@vger.kernel.org,
Mauro Carvalho Chehab <mchehab@kernel.org>,
linux-usb@vger.kernel.org, tglx@linutronix.de,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Takashi Iwai <tiwai@suse.de>
Subject: Re: [PATCH RFC] usb: add usb_fill_iso_urb()
Date: Fri, 13 Jul 2018 11:01:02 +0300 [thread overview]
Message-ID: <23211374.K0HmdtcaYO@avalon> (raw)
In-Reply-To: <20180712223527.5nmxndignujo7smt@linutronix.de>
Hi Sebastian,
Thank you for the patch.
On Friday, 13 July 2018 01:35:27 EEST Sebastian Andrzej Siewior wrote:
> Provide usb_fill_iso_urb() for the initialisation of isochronous URBs.
> We already have one of this helpers for control, bulk and interruptible
> URB types. This helps to keep the initialisation of the URB members in
> one place.
> Update the documentation by adding this to the available init functions
> and remove the suggestion to use the `_int_' helper which might provide
> wrong encoding for the `interval' member.
>
> This looks like it would cover most users nicely. The sound subsystem
> initialises the ->iso_frame_desc[].offset + length member (often) at a
> different location and I'm not sure ->interval will work always as
> expected. So we might need to overwrite those two in worst case.
>
> Some users also initialise ->iso_frame_desc[].actual_length but I don't
s/I don't/I don't think/ ?
> this is required since it is the return value.
>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> Documentation/driver-api/usb/URB.rst | 12 +++----
> include/linux/usb.h | 53 ++++++++++++++++++++++++++++
> 2 files changed, 59 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/driver-api/usb/URB.rst
> b/Documentation/driver-api/usb/URB.rst index 61a54da9fce9..20030b781519
> 100644
> --- a/Documentation/driver-api/usb/URB.rst
> +++ b/Documentation/driver-api/usb/URB.rst
> @@ -116,11 +116,11 @@ What has to be filled in?
>
> Depending on the type of transaction, there are some inline functions
> defined in ``linux/usb.h`` to simplify the initialization, such as
> -:c:func:`usb_fill_control_urb`, :c:func:`usb_fill_bulk_urb` and
> -:c:func:`usb_fill_int_urb`. In general, they need the usb device pointer,
> -the pipe (usual format from usb.h), the transfer buffer, the desired
> transfer -length, the completion handler, and its context. Take a look at
> the some -existing drivers to see how they're used.
> +:c:func:`usb_fill_control_urb`, :c:func:`usb_fill_bulk_urb`,
> +:c:func:`usb_fill_int_urb` and :c:func:`usb_fill_iso_urb`. In general,
> they +need the usb device pointer, the pipe (usual format from usb.h), the
> transfer +buffer, the desired transfer length, the completion handler, and
> its context. +Take a look at the some existing drivers to see how they're
> used.
>
> Flags:
>
> @@ -243,7 +243,7 @@ Besides the fields present on a bulk transfer, for ISO,
> you also also have to set ``urb->interval`` to say how often to make
> transfers; it's often one per frame (which is once every microframe for
> highspeed devices). The actual interval used will be a power of two that's
> no bigger than what -you specify. You can use the
> :c:func:`usb_fill_int_urb` macro to fill +you specify. You can use the
> :c:func:`usb_fill_iso_urb` macro to fill most ISO transfer fields.
>
> For ISO transfers you also have to fill a
> :c:type:`usb_iso_packet_descriptor` diff --git a/include/linux/usb.h
> b/include/linux/usb.h
> index 4cdd515a4385..74a3339041d6 100644
> --- a/include/linux/usb.h
> +++ b/include/linux/usb.h
> @@ -1697,6 +1697,59 @@ static inline void usb_fill_int_urb(struct urb *urb,
> urb->start_frame = -1;
> }
>
> +/**
> + * usb_fill_iso_urb - macro to help initialize an isochronous urb
Strictly speaking this isn't a macro, so I'd write "initializes an isochronous
urb"
> + * @urb: pointer to the urb to initialize.
> + * @dev: pointer to the struct usb_device for this urb.
> + * @pipe: the endpoint pipe
> + * @transfer_buffer: pointer to the transfer buffer
> + * @buffer_length: length of the transfer buffer
> + * @complete_fn: pointer to the usb_complete_t function
> + * @context: what to set the urb context to.
> + * @interval: what to set the urb interval to, encoded like
> + * the endpoint descriptor's bInterval value.
> + * @packets: number of ISO packets.
> + * @packet_size: size of each ISO packet.
> + *
> + * Initializes an isochronous urb with the proper information needed to
> submit
> + * it to a device.
> + *
> + * Note that isochronous endpoints use a logarithmic encoding of the
> endpoint
> + * interval, and express polling intervals in microframes (eight per
> + * millisecond) rather than in frames (one per millisecond).
> + */
> +static inline void usb_fill_iso_urb(struct urb *urb,
> + struct usb_device *dev,
> + unsigned int pipe,
> + void *transfer_buffer,
> + int buffer_length,
> + usb_complete_t complete_fn,
> + void *context,
> + int interval,
> + unsigned int packets,
> + unsigned int packet_size)
> +{
> + unsigned int i;
> +
> + urb->dev = dev;
> + urb->pipe = pipe;
> + urb->transfer_buffer = transfer_buffer;
> + urb->transfer_buffer_length = buffer_length;
> + urb->complete = complete_fn;
> + urb->context = context;
> +
> + interval = clamp(interval, 1, 16);
> + urb->interval = 1 << (interval - 1);
> + urb->start_frame = -1;
> +
> + urb->number_of_packets = packets;
> +
> + for (i = 0; i < packets; i++) {
> + urb->iso_frame_desc[i].offset = packet_size * i;
> + urb->iso_frame_desc[i].length = packet_size;
> + }
> +}
I think this should be moved to a .c file as the function is growing big, but
that's true of the other URB helpers as well, so it can be done later in a
separate patch.
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> extern void usb_init_urb(struct urb *urb);
> extern struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags);
> extern void usb_free_urb(struct urb *urb);
--
Regards,
Laurent Pinchart
next reply other threads:[~2018-07-13 8:01 UTC|newest]
Thread overview: 100+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-13 8:01 Laurent Pinchart [this message]
2018-07-13 8:01 ` [PATCH RFC] usb: add usb_fill_iso_urb() Laurent Pinchart
-- strict thread matches above, loose matches on Subject: below --
2018-08-06 22:02 [RFC] " Sebastian Andrzej Siewior
2018-08-06 22:02 ` [PATCH RFC] " Sebastian Andrzej Siewior
2018-08-06 21:21 [RFC] " Laurent Pinchart
2018-08-06 21:21 ` [PATCH RFC] " Laurent Pinchart
2018-07-13 20:12 [RFC] " Alan Stern
2018-07-13 20:12 ` [PATCH RFC] " Alan Stern
2018-06-21 7:37 [22/27] media: ttusbir: use usb_fill_int_urb() Sebastian Andrzej Siewior
2018-06-21 7:37 ` [PATCH 22/27] " Sebastian Andrzej Siewior
2018-06-20 20:50 [22/27] " Sean Young
2018-06-20 20:50 ` [PATCH 22/27] " Sean Young
2018-06-20 16:49 USB: note that usb_fill_int_urb() can be used used for ISOC urbs Sebastian Andrzej Siewior
2018-06-20 16:49 ` [PATCH] " Sebastian Andrzej Siewior
2018-06-20 17:23 ` Alan Stern
2018-06-20 17:23 ` [PATCH] " Alan Stern
2018-07-12 22:35 ` [RFC] usb: add usb_fill_iso_urb() Sebastian Andrzej Siewior
2018-07-12 22:35 ` [PATCH RFC] " Sebastian Andrzej Siewior
2018-07-13 7:29 ` [RFC] " Greg Kroah-Hartman
2018-07-13 7:29 ` [PATCH RFC] " Greg Kroah-Hartman
2018-07-13 7:47 ` [RFC] " Sebastian Andrzej Siewior
2018-07-13 7:47 ` [PATCH RFC] " Sebastian Andrzej Siewior
2018-07-16 22:53 ` [RFC] " Sebastian Andrzej Siewior
2018-07-16 22:53 ` [PATCH RFC] " Sebastian Andrzej Siewior
2018-07-17 6:54 ` Clemens Ladisch
2018-07-17 6:54 ` Clemens Ladisch
2018-07-17 6:54 ` [RFC] " Clemens Ladisch
2018-06-20 16:21 USB: note that usb_fill_int_urb() can be used used for ISOC urbs Alan Stern
2018-06-20 16:21 ` [PATCH] " Alan Stern
2018-06-20 16:02 Sebastian Andrzej Siewior
2018-06-20 16:02 ` [PATCH] " Sebastian Andrzej Siewior
2018-06-20 15:40 [27/27,v2] media: uvcvideo: use usb_fill_int_urb() for the ->intarval value Alan Stern
2018-06-20 15:40 ` [PATCH 27/27 v2] " Alan Stern
2018-06-20 15:35 USB: note that usb_fill_int_urb() can be used used for ISOC urbs Alan Stern
2018-06-20 15:35 ` [PATCH] " Alan Stern
2018-06-20 15:21 [27/27,v2] media: uvcvideo: use usb_fill_int_urb() for the ->intarval value Sebastian Andrzej Siewior
2018-06-20 15:21 ` [PATCH 27/27 v2] " Sebastian Andrzej Siewior
2018-06-20 15:20 USB: note that usb_fill_int_urb() can be used used for ISOC urbs Sebastian Andrzej Siewior
2018-06-20 15:20 ` [PATCH] " Sebastian Andrzej Siewior
2018-06-20 14:14 [27/27] media: uvcvideo: use usb_fill_int_urb() Laurent Pinchart
2018-06-20 14:14 ` [PATCH 27/27] " Laurent Pinchart
2018-06-20 13:21 [27/27] " Sebastian Andrzej Siewior
2018-06-20 13:21 ` [PATCH 27/27] " Sebastian Andrzej Siewior
2018-06-20 11:55 [27/27] " Laurent Pinchart
2018-06-20 11:55 ` [PATCH 27/27] " Laurent Pinchart
2018-06-20 11:01 [27/27] " Sebastian Andrzej Siewior
2018-06-20 11:01 ` [PATCH 27/27] " Sebastian Andrzej Siewior
2018-06-20 11:01 [26/27] media: usbvision: " Sebastian Andrzej Siewior
2018-06-20 11:01 ` [PATCH 26/27] " Sebastian Andrzej Siewior
2018-06-20 11:01 [25/27] media: usbvision: remove time_in_irq Sebastian Andrzej Siewior
2018-06-20 11:01 ` [PATCH 25/27] " Sebastian Andrzej Siewior
2018-06-20 11:01 [24/27] media: usbtv: use usb_fill_int_urb() Sebastian Andrzej Siewior
2018-06-20 11:01 ` [PATCH 24/27] " Sebastian Andrzej Siewior
2018-06-20 11:01 [23/27] media: usbtv: use irqsave() in USB's complete callback Sebastian Andrzej Siewior
2018-06-20 11:01 ` [PATCH 23/27] " Sebastian Andrzej Siewior
2018-06-20 11:01 [22/27] media: ttusbir: use usb_fill_int_urb() Sebastian Andrzej Siewior
2018-06-20 11:01 ` [PATCH 22/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [21/27] media: ttusb-dec: " Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 21/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [20/27] media: ttusb-budget: " Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 20/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [19/27] media: tm6000: use irqsave() in USB's complete callback Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 19/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [18/27] media: stkwebcam: use usb_fill_int_urb() Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 18/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [17/27] media: stk1160: " Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 17/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [16/27] media: pwc: " Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 16/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [15/27] media: msi2500: " Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 15/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [14/27] media: gspca: sq930x: use GFP_KERNEL in sd_dq_callback() Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 14/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [13/27] media: gspca: konica: use usb_fill_int_urb() Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 13/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [12/27] media: gspca: gspca: use usb_fill_XXX_urb() Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 12/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [11/27] media: gspca: benq: use usb_fill_int_urb() Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 11/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [10/27] media: go7007: use irqsave() in USB's complete callback Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 10/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [09/27] media: em28xx-audio: use usb_fill_int_urb() Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 09/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [08/27] media: em28xx-audio: use irqsave() in USB's complete callback Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 08/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [07/27] media: em28xx-audio: use GFP_KERNEL for memory allocation during init Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 07/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [06/27] media: dvb_usb_v2: use usb_fill_int_urb() Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 06/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [05/27] media: dvb-usb: " Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 05/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [04/27] media: cx231xx: use irqsave() in USB's complete callback Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 04/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [03/27] media: cx231xx: use usb_fill_XXX_urb() Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 03/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [02/27] media: cpia2_usb: use usb_fill_int_urb() Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 02/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 [01/27] media: b2c2: " Sebastian Andrzej Siewior
2018-06-20 11:00 ` [PATCH 01/27] " Sebastian Andrzej Siewior
2018-06-20 11:00 medial: use irqsave() in URB completion + usb_fill_int_urb Sebastian Andrzej Siewior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=23211374.K0HmdtcaYO@avalon \
--to=laurent.pinchart@ideasonboard.com \
--cc=bigeasy@linutronix.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=tglx@linutronix.de \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.