2008-12-29 21:48:45

by Julia Lawall

[permalink] [raw]
Subject: [PATCH] include/linux: Move definitions from usb.h to usb/ch9.h

From: Julia Lawall <[email protected]>

The functions:

usb_endpoint_dir_in(epd)
usb_endpoint_dir_out(epd)
usb_endpoint_is_bulk_in(epd)
usb_endpoint_is_bulk_out(epd)
usb_endpoint_is_int_in(epd)
usb_endpoint_is_int_out(epd)
usb_endpoint_is_isoc_in(epd)
usb_endpoint_is_isoc_out(epd)
usb_endpoint_num(epd)
usb_endpoint_type(epd)
usb_endpoint_xfer_bulk(epd)
usb_endpoint_xfer_control(epd)
usb_endpoint_xfer_int(epd)
usb_endpoint_xfer_isoc(epd)

are moved from include/linux/usb.h to include/linux/usb/ch9.h.
include/linux/usb/ch9.h makes more sense for these functions because they
only depend on constants that are defined in this file.

Signed-off-by: Julia Lawall <[email protected]>

---
include/linux/usb.h | 180 ------------------------------------------------
include/linux/usb/ch9.h | 179 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 179 insertions(+), 180 deletions(-)

diff -u -p a/include/linux/usb.h b/include/linux/usb.h
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -641,186 +641,6 @@ static inline int usb_make_path(struct u

/*-------------------------------------------------------------------------*/

-/**
- * usb_endpoint_num - get the endpoint's number
- * @epd: endpoint to be checked
- *
- * Returns @epd's number: 0 to 15.
- */
-static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
-{
- return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
-}
-
-/**
- * usb_endpoint_type - get the endpoint's transfer type
- * @epd: endpoint to be checked
- *
- * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
- * to @epd's transfer type.
- */
-static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
-{
- return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
-}
-
-/**
- * usb_endpoint_dir_in - check if the endpoint has IN direction
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint is of type IN, otherwise it returns false.
- */
-static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
-{
- return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
-}
-
-/**
- * usb_endpoint_dir_out - check if the endpoint has OUT direction
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint is of type OUT, otherwise it returns false.
- */
-static inline int usb_endpoint_dir_out(
- const struct usb_endpoint_descriptor *epd)
-{
- return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
-}
-
-/**
- * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint is of type bulk, otherwise it returns false.
- */
-static inline int usb_endpoint_xfer_bulk(
- const struct usb_endpoint_descriptor *epd)
-{
- return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
- USB_ENDPOINT_XFER_BULK);
-}
-
-/**
- * usb_endpoint_xfer_control - check if the endpoint has control transfer type
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint is of type control, otherwise it returns false.
- */
-static inline int usb_endpoint_xfer_control(
- const struct usb_endpoint_descriptor *epd)
-{
- return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
- USB_ENDPOINT_XFER_CONTROL);
-}
-
-/**
- * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint is of type interrupt, otherwise it returns
- * false.
- */
-static inline int usb_endpoint_xfer_int(
- const struct usb_endpoint_descriptor *epd)
-{
- return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
- USB_ENDPOINT_XFER_INT);
-}
-
-/**
- * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint is of type isochronous, otherwise it returns
- * false.
- */
-static inline int usb_endpoint_xfer_isoc(
- const struct usb_endpoint_descriptor *epd)
-{
- return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
- USB_ENDPOINT_XFER_ISOC);
-}
-
-/**
- * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint has bulk transfer type and IN direction,
- * otherwise it returns false.
- */
-static inline int usb_endpoint_is_bulk_in(
- const struct usb_endpoint_descriptor *epd)
-{
- return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd));
-}
-
-/**
- * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint has bulk transfer type and OUT direction,
- * otherwise it returns false.
- */
-static inline int usb_endpoint_is_bulk_out(
- const struct usb_endpoint_descriptor *epd)
-{
- return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd));
-}
-
-/**
- * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint has interrupt transfer type and IN direction,
- * otherwise it returns false.
- */
-static inline int usb_endpoint_is_int_in(
- const struct usb_endpoint_descriptor *epd)
-{
- return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
-}
-
-/**
- * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint has interrupt transfer type and OUT direction,
- * otherwise it returns false.
- */
-static inline int usb_endpoint_is_int_out(
- const struct usb_endpoint_descriptor *epd)
-{
- return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd));
-}
-
-/**
- * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint has isochronous transfer type and IN direction,
- * otherwise it returns false.
- */
-static inline int usb_endpoint_is_isoc_in(
- const struct usb_endpoint_descriptor *epd)
-{
- return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd));
-}
-
-/**
- * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
- * @epd: endpoint to be checked
- *
- * Returns true if the endpoint has isochronous transfer type and OUT direction,
- * otherwise it returns false.
- */
-static inline int usb_endpoint_is_isoc_out(
- const struct usb_endpoint_descriptor *epd)
-{
- return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd));
-}
-
-/*-------------------------------------------------------------------------*/
-
#define USB_DEVICE_ID_MATCH_DEVICE \
(USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
#define USB_DEVICE_ID_MATCH_DEV_RANGE \
diff -u -p a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -353,6 +353,185 @@ struct usb_endpoint_descriptor {
#define USB_ENDPOINT_XFER_INT 3
#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80

+/*-------------------------------------------------------------------------*/
+
+/**
+ * usb_endpoint_num - get the endpoint's number
+ * @epd: endpoint to be checked
+ *
+ * Returns @epd's number: 0 to 15.
+ */
+static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
+{
+ return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
+}
+
+/**
+ * usb_endpoint_type - get the endpoint's transfer type
+ * @epd: endpoint to be checked
+ *
+ * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
+ * to @epd's transfer type.
+ */
+static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
+{
+ return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
+}
+
+/**
+ * usb_endpoint_dir_in - check if the endpoint has IN direction
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint is of type IN, otherwise it returns false.
+ */
+static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
+{
+ return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
+}
+
+/**
+ * usb_endpoint_dir_out - check if the endpoint has OUT direction
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint is of type OUT, otherwise it returns false.
+ */
+static inline int usb_endpoint_dir_out(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
+}
+
+/**
+ * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint is of type bulk, otherwise it returns false.
+ */
+static inline int usb_endpoint_xfer_bulk(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
+ USB_ENDPOINT_XFER_BULK);
+}
+
+/**
+ * usb_endpoint_xfer_control - check if the endpoint has control transfer type
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint is of type control, otherwise it returns false.
+ */
+static inline int usb_endpoint_xfer_control(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
+ USB_ENDPOINT_XFER_CONTROL);
+}
+
+/**
+ * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint is of type interrupt, otherwise it returns
+ * false.
+ */
+static inline int usb_endpoint_xfer_int(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
+ USB_ENDPOINT_XFER_INT);
+}
+
+/**
+ * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint is of type isochronous, otherwise it returns
+ * false.
+ */
+static inline int usb_endpoint_xfer_isoc(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
+ USB_ENDPOINT_XFER_ISOC);
+}
+
+/**
+ * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint has bulk transfer type and IN direction,
+ * otherwise it returns false.
+ */
+static inline int usb_endpoint_is_bulk_in(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd));
+}
+
+/**
+ * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint has bulk transfer type and OUT direction,
+ * otherwise it returns false.
+ */
+static inline int usb_endpoint_is_bulk_out(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd));
+}
+
+/**
+ * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint has interrupt transfer type and IN direction,
+ * otherwise it returns false.
+ */
+static inline int usb_endpoint_is_int_in(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
+}
+
+/**
+ * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint has interrupt transfer type and OUT direction,
+ * otherwise it returns false.
+ */
+static inline int usb_endpoint_is_int_out(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd));
+}
+
+/**
+ * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint has isochronous transfer type and IN direction,
+ * otherwise it returns false.
+ */
+static inline int usb_endpoint_is_isoc_in(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd));
+}
+
+/**
+ * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
+ * @epd: endpoint to be checked
+ *
+ * Returns true if the endpoint has isochronous transfer type and OUT direction,
+ * otherwise it returns false.
+ */
+static inline int usb_endpoint_is_isoc_out(
+ const struct usb_endpoint_descriptor *epd)
+{
+ return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd));
+}

/*-------------------------------------------------------------------------*/


2008-12-30 00:25:54

by David Brownell

[permalink] [raw]
Subject: Re: [PATCH] include/linux: Move definitions from usb.h to usb/ch9.h

On Monday 29 December 2008, Julia Lawall wrote:
> From: Julia Lawall <[email protected]>
>
> The functions:
>
> usb_endpoint_dir_in(epd)
> usb_endpoint_dir_out(epd)
> usb_endpoint_is_bulk_in(epd)
> usb_endpoint_is_bulk_out(epd)
> usb_endpoint_is_int_in(epd)
> usb_endpoint_is_int_out(epd)
> usb_endpoint_is_isoc_in(epd)
> usb_endpoint_is_isoc_out(epd)
> usb_endpoint_num(epd)
> usb_endpoint_type(epd)
> usb_endpoint_xfer_bulk(epd)
> usb_endpoint_xfer_control(epd)
> usb_endpoint_xfer_int(epd)
> usb_endpoint_xfer_isoc(epd)
>
> are moved from include/linux/usb.h to include/linux/usb/ch9.h.
> include/linux/usb/ch9.h makes more sense for these functions because they
> only depend on constants that are defined in this file.

... "constants and structures", to be a bit more exact. :)


>
> Signed-off-by: Julia Lawall <[email protected]>

Acked-by: David Brownell <[email protected]>

>
> ---
> include/linux/usb.h | 180 ------------------------------------------------
> include/linux/usb/ch9.h | 179 +++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 179 insertions(+), 180 deletions(-)
>
> diff -u -p a/include/linux/usb.h b/include/linux/usb.h
> --- a/include/linux/usb.h
> +++ b/include/linux/usb.h
> @@ -641,186 +641,6 @@ static inline int usb_make_path(struct u
>
> /*-------------------------------------------------------------------------*/
>
> -/**
> - * usb_endpoint_num - get the endpoint's number
> - * @epd: endpoint to be checked
> - *
> - * Returns @epd's number: 0 to 15.
> - */
> -static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
> -{
> - return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
> -}
> -
> -/**
> - * usb_endpoint_type - get the endpoint's transfer type
> - * @epd: endpoint to be checked
> - *
> - * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
> - * to @epd's transfer type.
> - */
> -static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
> -{
> - return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
> -}
> -
> -/**
> - * usb_endpoint_dir_in - check if the endpoint has IN direction
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint is of type IN, otherwise it returns false.
> - */
> -static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
> -{
> - return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
> -}
> -
> -/**
> - * usb_endpoint_dir_out - check if the endpoint has OUT direction
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint is of type OUT, otherwise it returns false.
> - */
> -static inline int usb_endpoint_dir_out(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
> -}
> -
> -/**
> - * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint is of type bulk, otherwise it returns false.
> - */
> -static inline int usb_endpoint_xfer_bulk(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
> - USB_ENDPOINT_XFER_BULK);
> -}
> -
> -/**
> - * usb_endpoint_xfer_control - check if the endpoint has control transfer type
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint is of type control, otherwise it returns false.
> - */
> -static inline int usb_endpoint_xfer_control(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
> - USB_ENDPOINT_XFER_CONTROL);
> -}
> -
> -/**
> - * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint is of type interrupt, otherwise it returns
> - * false.
> - */
> -static inline int usb_endpoint_xfer_int(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
> - USB_ENDPOINT_XFER_INT);
> -}
> -
> -/**
> - * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint is of type isochronous, otherwise it returns
> - * false.
> - */
> -static inline int usb_endpoint_xfer_isoc(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
> - USB_ENDPOINT_XFER_ISOC);
> -}
> -
> -/**
> - * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint has bulk transfer type and IN direction,
> - * otherwise it returns false.
> - */
> -static inline int usb_endpoint_is_bulk_in(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd));
> -}
> -
> -/**
> - * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint has bulk transfer type and OUT direction,
> - * otherwise it returns false.
> - */
> -static inline int usb_endpoint_is_bulk_out(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd));
> -}
> -
> -/**
> - * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint has interrupt transfer type and IN direction,
> - * otherwise it returns false.
> - */
> -static inline int usb_endpoint_is_int_in(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
> -}
> -
> -/**
> - * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint has interrupt transfer type and OUT direction,
> - * otherwise it returns false.
> - */
> -static inline int usb_endpoint_is_int_out(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd));
> -}
> -
> -/**
> - * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint has isochronous transfer type and IN direction,
> - * otherwise it returns false.
> - */
> -static inline int usb_endpoint_is_isoc_in(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd));
> -}
> -
> -/**
> - * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
> - * @epd: endpoint to be checked
> - *
> - * Returns true if the endpoint has isochronous transfer type and OUT direction,
> - * otherwise it returns false.
> - */
> -static inline int usb_endpoint_is_isoc_out(
> - const struct usb_endpoint_descriptor *epd)
> -{
> - return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd));
> -}
> -
> -/*-------------------------------------------------------------------------*/
> -
> #define USB_DEVICE_ID_MATCH_DEVICE \
> (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
> #define USB_DEVICE_ID_MATCH_DEV_RANGE \
> diff -u -p a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
> --- a/include/linux/usb/ch9.h
> +++ b/include/linux/usb/ch9.h
> @@ -353,6 +353,185 @@ struct usb_endpoint_descriptor {
> #define USB_ENDPOINT_XFER_INT 3
> #define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
>
> +/*-------------------------------------------------------------------------*/
> +
> +/**
> + * usb_endpoint_num - get the endpoint's number
> + * @epd: endpoint to be checked
> + *
> + * Returns @epd's number: 0 to 15.
> + */
> +static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
> +{
> + return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
> +}
> +
> +/**
> + * usb_endpoint_type - get the endpoint's transfer type
> + * @epd: endpoint to be checked
> + *
> + * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
> + * to @epd's transfer type.
> + */
> +static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
> +{
> + return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
> +}
> +
> +/**
> + * usb_endpoint_dir_in - check if the endpoint has IN direction
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint is of type IN, otherwise it returns false.
> + */
> +static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
> +{
> + return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
> +}
> +
> +/**
> + * usb_endpoint_dir_out - check if the endpoint has OUT direction
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint is of type OUT, otherwise it returns false.
> + */
> +static inline int usb_endpoint_dir_out(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
> +}
> +
> +/**
> + * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint is of type bulk, otherwise it returns false.
> + */
> +static inline int usb_endpoint_xfer_bulk(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
> + USB_ENDPOINT_XFER_BULK);
> +}
> +
> +/**
> + * usb_endpoint_xfer_control - check if the endpoint has control transfer type
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint is of type control, otherwise it returns false.
> + */
> +static inline int usb_endpoint_xfer_control(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
> + USB_ENDPOINT_XFER_CONTROL);
> +}
> +
> +/**
> + * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint is of type interrupt, otherwise it returns
> + * false.
> + */
> +static inline int usb_endpoint_xfer_int(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
> + USB_ENDPOINT_XFER_INT);
> +}
> +
> +/**
> + * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint is of type isochronous, otherwise it returns
> + * false.
> + */
> +static inline int usb_endpoint_xfer_isoc(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
> + USB_ENDPOINT_XFER_ISOC);
> +}
> +
> +/**
> + * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint has bulk transfer type and IN direction,
> + * otherwise it returns false.
> + */
> +static inline int usb_endpoint_is_bulk_in(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd));
> +}
> +
> +/**
> + * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint has bulk transfer type and OUT direction,
> + * otherwise it returns false.
> + */
> +static inline int usb_endpoint_is_bulk_out(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd));
> +}
> +
> +/**
> + * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint has interrupt transfer type and IN direction,
> + * otherwise it returns false.
> + */
> +static inline int usb_endpoint_is_int_in(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
> +}
> +
> +/**
> + * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint has interrupt transfer type and OUT direction,
> + * otherwise it returns false.
> + */
> +static inline int usb_endpoint_is_int_out(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd));
> +}
> +
> +/**
> + * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint has isochronous transfer type and IN direction,
> + * otherwise it returns false.
> + */
> +static inline int usb_endpoint_is_isoc_in(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd));
> +}
> +
> +/**
> + * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
> + * @epd: endpoint to be checked
> + *
> + * Returns true if the endpoint has isochronous transfer type and OUT direction,
> + * otherwise it returns false.
> + */
> +static inline int usb_endpoint_is_isoc_out(
> + const struct usb_endpoint_descriptor *epd)
> +{
> + return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd));
> +}
>
> /*-------------------------------------------------------------------------*/
>
>
>

2008-12-30 23:39:23

by Sarah Sharp

[permalink] [raw]
Subject: Re: [PATCH] include/linux: Move definitions from usb.h to usb/ch9.h

On Mon, Dec 29, 2008 at 10:48:19PM +0100, Julia Lawall wrote:
> From: Julia Lawall <[email protected]>
>
> The functions:
>
> usb_endpoint_dir_in(epd)
> usb_endpoint_dir_out(epd)
> usb_endpoint_is_bulk_in(epd)
> usb_endpoint_is_bulk_out(epd)
> usb_endpoint_is_int_in(epd)
> usb_endpoint_is_int_out(epd)
> usb_endpoint_is_isoc_in(epd)
> usb_endpoint_is_isoc_out(epd)
> usb_endpoint_num(epd)
> usb_endpoint_type(epd)
> usb_endpoint_xfer_bulk(epd)
> usb_endpoint_xfer_control(epd)
> usb_endpoint_xfer_int(epd)
> usb_endpoint_xfer_isoc(epd)
>
> are moved from include/linux/usb.h to include/linux/usb/ch9.h.
> include/linux/usb/ch9.h makes more sense for these functions because they
> only depend on constants that are defined in this file.

I thought the include/linux/usb/ch9.h was supposed to include values that are
defined in various USB specifications (starting with the protocol "chapter 9"
from the USB 1.1 bus specification). The constants (masks) used by these
functions aren't part of the standards, so why move these functions to
include/linux/usb/ch9.h? Was it confusing to find these functions, or do you
have an overall plan for these changes?

Sarah Sharp

2008-12-31 01:40:38

by David Brownell

[permalink] [raw]
Subject: Re: [PATCH] include/linux: Move definitions from usb.h to usb/ch9.h

On Tuesday 30 December 2008, Sarah Sharp wrote:
> I thought the include/linux/usb/ch9.h was supposed to include values that are
> defined in various USB specifications (starting with the protocol "chapter 9"
> from the USB 1.1 bus specification).

And not getting too far from "chapter 9" ... there are
a few things from the "common class spec", and constants
defining classes, but they're needed to interpret a lot
of descriptors.


> The constants (masks) used by these
> functions aren't part of the standards,

They are too! Bitfields and the values in those bitfields
are part of the endpoint descriptor definitions.

In protocol specs, data format definitions don't usually
define symbolic accessors for fields, or for individual
message structures. Those are part of a programming
language/environment binding.

This distinction is a Good Thing ... names used in assembly
might use Hungarian Notation to make up for the complete
lack of type checking; names in C would normally leave
type checking to the compiler; names in LISP would use
embedded "-" instead of embedded "_" or embedded "$" for
separators; and so on. No single set of names can work
everywhere; and even if it could, it would fight against
coding conventions in many organizations.


> so why move these functions to
> include/linux/usb/ch9.h? ?Was it confusing to find these functions, or do you
> have an overall plan for these changes?

You missed earlier mail on the topic. The basic issue is
that those symbols can (and should!) be used for peripheral
side support as well as host side support ... which means
they should never have been put into a host-only header.

- Dave

2009-01-02 02:02:16

by Sarah Sharp

[permalink] [raw]
Subject: Re: [PATCH] include/linux: Move definitions from usb.h to usb/ch9.h

On Tue, Dec 30, 2008 at 05:40:26PM -0800, David Brownell wrote:
> On Tuesday 30 December 2008, Sarah Sharp wrote:
> > so why move these functions to
> > include/linux/usb/ch9.h? ?Was it confusing to find these functions, or do you
> > have an overall plan for these changes?
>
> You missed earlier mail on the topic. The basic issue is
> that those symbols can (and should!) be used for peripheral
> side support as well as host side support ... which means
> they should never have been put into a host-only header.

Ah, I see. Thanks for the explanation. :)

Sarah