diff options
author | Hauke Mehrtens <hauke@hauke-m.de> | 2023-01-28 01:37:55 +0100 |
---|---|---|
committer | Hauke Mehrtens <hauke@hauke-m.de> | 2023-01-29 18:33:30 +0100 |
commit | d90adcaa60d2d3b0375ec00b20d39e8412480b06 (patch) | |
tree | aa0aa8253941c8744a0eab5a8c4b91b7cd694331 | |
parent | e1867d552f108f403725067c72ad2dc87535b935 (diff) | |
download | backports-d90adcaa60d2d3b0375ec00b20d39e8412480b06.tar.gz |
backports: Add usb_find_common_endpoints()
This is needed for ath9k.
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
-rw-r--r-- | backport/backport-include/linux/usb.h | 16 | ||||
-rw-r--r-- | backport/compat/Makefile | 1 | ||||
-rw-r--r-- | backport/compat/backport-4.12.c | 94 |
3 files changed, 111 insertions, 0 deletions
diff --git a/backport/backport-include/linux/usb.h b/backport/backport-include/linux/usb.h new file mode 100644 index 00000000..acb5b2ee --- /dev/null +++ b/backport/backport-include/linux/usb.h @@ -0,0 +1,16 @@ +#ifndef __BACKPORT_LINUX_USB_H +#define __BACKPORT_LINUX_USB_H +#include_next <linux/usb.h> +#include <linux/version.h> + +#if LINUX_VERSION_IS_LESS(4,12,0) +#define usb_find_common_endpoints LINUX_BACKPORT(usb_find_common_endpoints) +int __must_check +usb_find_common_endpoints(struct usb_host_interface *alt, + struct usb_endpoint_descriptor **bulk_in, + struct usb_endpoint_descriptor **bulk_out, + struct usb_endpoint_descriptor **int_in, + struct usb_endpoint_descriptor **int_out); +#endif /* < 4.12 */ + +#endif /* __BACKPORT_LINUX_USB_H */ diff --git a/backport/compat/Makefile b/backport/compat/Makefile index b9f1dee9..a1be9e83 100644 --- a/backport/compat/Makefile +++ b/backport/compat/Makefile @@ -13,6 +13,7 @@ compat-$(CPTCFG_KERNEL_4_7) += backport-4.7.o compat-$(CPTCFG_KERNEL_4_8) += backport-4.8.o compat-$(CPTCFG_KERNEL_4_10) += backport-4.10.o compat-$(CPTCFG_KERNEL_4_11) += backport-4.11.o +compat-$(CPTCFG_KERNEL_4_12) += backport-4.12.o compat-$(CPTCFG_KERNEL_4_18) += backport-4.18.o compat-$(CPTCFG_KERNEL_5_2) += backport-5.2.o backport-genetlink.o compat-$(CPTCFG_KERNEL_5_3) += backport-5.3.o diff --git a/backport/compat/backport-4.12.c b/backport/compat/backport-4.12.c new file mode 100644 index 00000000..1307a69e --- /dev/null +++ b/backport/compat/backport-4.12.c @@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/export.h> +#include <linux/usb.h> +#include <linux/usb/ch9.h> + +static bool match_endpoint(struct usb_endpoint_descriptor *epd, + struct usb_endpoint_descriptor **bulk_in, + struct usb_endpoint_descriptor **bulk_out, + struct usb_endpoint_descriptor **int_in, + struct usb_endpoint_descriptor **int_out) +{ + switch (usb_endpoint_type(epd)) { + case USB_ENDPOINT_XFER_BULK: + if (usb_endpoint_dir_in(epd)) { + if (bulk_in && !*bulk_in) { + *bulk_in = epd; + break; + } + } else { + if (bulk_out && !*bulk_out) { + *bulk_out = epd; + break; + } + } + + return false; + case USB_ENDPOINT_XFER_INT: + if (usb_endpoint_dir_in(epd)) { + if (int_in && !*int_in) { + *int_in = epd; + break; + } + } else { + if (int_out && !*int_out) { + *int_out = epd; + break; + } + } + + return false; + default: + return false; + } + + return (!bulk_in || *bulk_in) && (!bulk_out || *bulk_out) && + (!int_in || *int_in) && (!int_out || *int_out); +} + +/** + * usb_find_common_endpoints() -- look up common endpoint descriptors + * @alt: alternate setting to search + * @bulk_in: pointer to descriptor pointer, or NULL + * @bulk_out: pointer to descriptor pointer, or NULL + * @int_in: pointer to descriptor pointer, or NULL + * @int_out: pointer to descriptor pointer, or NULL + * + * Search the alternate setting's endpoint descriptors for the first bulk-in, + * bulk-out, interrupt-in and interrupt-out endpoints and return them in the + * provided pointers (unless they are NULL). + * + * If a requested endpoint is not found, the corresponding pointer is set to + * NULL. + * + * Return: Zero if all requested descriptors were found, or -ENXIO otherwise. + */ +int usb_find_common_endpoints(struct usb_host_interface *alt, + struct usb_endpoint_descriptor **bulk_in, + struct usb_endpoint_descriptor **bulk_out, + struct usb_endpoint_descriptor **int_in, + struct usb_endpoint_descriptor **int_out) +{ + struct usb_endpoint_descriptor *epd; + int i; + + if (bulk_in) + *bulk_in = NULL; + if (bulk_out) + *bulk_out = NULL; + if (int_in) + *int_in = NULL; + if (int_out) + *int_out = NULL; + + for (i = 0; i < alt->desc.bNumEndpoints; ++i) { + epd = &alt->endpoint[i].desc; + + if (match_endpoint(epd, bulk_in, bulk_out, int_in, int_out)) + return 0; + } + + return -ENXIO; +} +EXPORT_SYMBOL_GPL(usb_find_common_endpoints); |