Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * This file holds USB constants and structures that are needed for
4 * USB device APIs. These are used by the USB device model, which is
5 * defined in chapter 9 of the USB 2.0 specification and in the
6 * Wireless USB 1.0 (spread around). Linux has several APIs in C that
7 * need these:
8 *
9 * - the host side Linux-USB kernel driver API;
10 * - the "usbfs" user space API; and
11 * - the Linux "gadget" device/peripheral side driver API.
12 *
13 * USB 2.0 adds an additional "On The Go" (OTG) mode, which lets systems
14 * act either as a USB host or as a USB device. That means the host and
15 * device side APIs benefit from working well together.
16 *
17 * There's also "Wireless USB", using low power short range radios for
18 * peripheral interconnection but otherwise building on the USB framework.
19 *
20 * Note all descriptors are declared '__attribute__((packed))' so that:
21 *
22 * [a] they never get padded, either internally (USB spec writers
23 * probably handled that) or externally;
24 *
25 * [b] so that accessing bigger-than-a-bytes fields will never
26 * generate bus errors on any platform, even when the location of
27 * its descriptor inside a bundle isn't "naturally aligned", and
28 *
29 * [c] for consistency, removing all doubt even when it appears to
30 * someone that the two other points are non-issues for that
31 * particular descriptor type.
32 */
33#ifndef __LINUX_USB_CH9_H
34#define __LINUX_USB_CH9_H
35
36#include <linux/device.h>
37#include <uapi/linux/usb/ch9.h>
38
39/* USB 3.2 SuperSpeed Plus phy signaling rate generation and lane count */
40
41enum usb_ssp_rate {
42 USB_SSP_GEN_UNKNOWN = 0,
43 USB_SSP_GEN_2x1,
44 USB_SSP_GEN_1x2,
45 USB_SSP_GEN_2x2,
46};
47
48/**
49 * usb_ep_type_string() - Returns human readable-name of the endpoint type.
50 * @ep_type: The endpoint type to return human-readable name for. If it's not
51 * any of the types: USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT},
52 * usually got by usb_endpoint_type(), the string 'unknown' will be returned.
53 */
54extern const char *usb_ep_type_string(int ep_type);
55
56/**
57 * usb_speed_string() - Returns human readable-name of the speed.
58 * @speed: The speed to return human-readable name for. If it's not
59 * any of the speeds defined in usb_device_speed enum, string for
60 * USB_SPEED_UNKNOWN will be returned.
61 */
62extern const char *usb_speed_string(enum usb_device_speed speed);
63
64/**
65 * usb_get_maximum_speed - Get maximum requested speed for a given USB
66 * controller.
67 * @dev: Pointer to the given USB controller device
68 *
69 * The function gets the maximum speed string from property "maximum-speed",
70 * and returns the corresponding enum usb_device_speed.
71 */
72extern enum usb_device_speed usb_get_maximum_speed(struct device *dev);
73
74/**
75 * usb_get_maximum_ssp_rate - Get the signaling rate generation and lane count
76 * of a SuperSpeed Plus capable device.
77 * @dev: Pointer to the given USB controller device
78 *
79 * If the string from "maximum-speed" property is super-speed-plus-genXxY where
80 * 'X' is the generation number and 'Y' is the number of lanes, then this
81 * function returns the corresponding enum usb_ssp_rate.
82 */
83extern enum usb_ssp_rate usb_get_maximum_ssp_rate(struct device *dev);
84
85/**
86 * usb_state_string - Returns human readable name for the state.
87 * @state: The state to return a human-readable name for. If it's not
88 * any of the states devices in usb_device_state_string enum,
89 * the string UNKNOWN will be returned.
90 */
91extern const char *usb_state_string(enum usb_device_state state);
92
93#ifdef CONFIG_TRACING
94/**
95 * usb_decode_ctrl - Returns human readable representation of control request.
96 * @str: buffer to return a human-readable representation of control request.
97 * This buffer should have about 200 bytes.
98 * @size: size of str buffer.
99 * @bRequestType: matches the USB bmRequestType field
100 * @bRequest: matches the USB bRequest field
101 * @wValue: matches the USB wValue field (CPU byte order)
102 * @wIndex: matches the USB wIndex field (CPU byte order)
103 * @wLength: matches the USB wLength field (CPU byte order)
104 *
105 * Function returns decoded, formatted and human-readable description of
106 * control request packet.
107 *
108 * The usage scenario for this is for tracepoints, so function as a return
109 * use the same value as in parameters. This approach allows to use this
110 * function in TP_printk
111 *
112 * Important: wValue, wIndex, wLength parameters before invoking this function
113 * should be processed by le16_to_cpu macro.
114 */
115extern const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType,
116 __u8 bRequest, __u16 wValue, __u16 wIndex,
117 __u16 wLength);
118#endif
119
120#endif /* __LINUX_USB_CH9_H */