Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Common USB debugging functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2010-2011 Texas Instruments Incorporated - https://www.ti.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Authors: Felipe Balbi <balbi@ti.com>,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *	    Sebastian Andrzej Siewior <bigeasy@linutronix.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/usb/ch9.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) static void usb_decode_get_status(__u8 bRequestType, __u16 wIndex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 				  __u16 wLength, char *str, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	switch (bRequestType & USB_RECIP_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	case USB_RECIP_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 		snprintf(str, size, "Get Device Status(Length = %d)", wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	case USB_RECIP_INTERFACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		snprintf(str, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 			 "Get Interface Status(Intf = %d, Length = %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 			 wIndex, wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	case USB_RECIP_ENDPOINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		snprintf(str, size, "Get Endpoint Status(ep%d%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 			 wIndex & ~USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 			 wIndex & USB_DIR_IN ? "in" : "out");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static const char *usb_decode_device_feature(u16 wValue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	switch (wValue) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	case USB_DEVICE_SELF_POWERED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		return "Self Powered";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	case USB_DEVICE_REMOTE_WAKEUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		return "Remote Wakeup";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	case USB_DEVICE_TEST_MODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		return "Test Mode";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	case USB_DEVICE_U1_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return "U1 Enable";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	case USB_DEVICE_U2_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return "U2 Enable";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	case USB_DEVICE_LTM_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		return "LTM Enable";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		return "UNKNOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static const char *usb_decode_test_mode(u16 wIndex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	switch (wIndex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	case USB_TEST_J:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		return ": TEST_J";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	case USB_TEST_K:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		return ": TEST_K";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	case USB_TEST_SE0_NAK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		return ": TEST_SE0_NAK";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	case USB_TEST_PACKET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return ": TEST_PACKET";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	case USB_TEST_FORCE_ENABLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return ": TEST_FORCE_EN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		return ": UNKNOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static void usb_decode_set_clear_feature(__u8 bRequestType,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 					 __u8 bRequest, __u16 wValue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 					 __u16 wIndex, char *str, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	switch (bRequestType & USB_RECIP_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	case USB_RECIP_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		snprintf(str, size, "%s Device Feature(%s%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			 bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			 usb_decode_device_feature(wValue),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			 wValue == USB_DEVICE_TEST_MODE ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			 usb_decode_test_mode(wIndex) : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	case USB_RECIP_INTERFACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		snprintf(str, size, "%s Interface Feature(%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			 bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			 wValue == USB_INTRF_FUNC_SUSPEND ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			 "Function Suspend" : "UNKNOWN");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	case USB_RECIP_ENDPOINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		snprintf(str, size, "%s Endpoint Feature(%s ep%d%s)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			 bRequest == USB_REQ_CLEAR_FEATURE ? "Clear" : "Set",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			 wValue == USB_ENDPOINT_HALT ? "Halt" : "UNKNOWN",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			 wIndex & ~USB_DIR_IN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			 wIndex & USB_DIR_IN ? "in" : "out");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static void usb_decode_set_address(__u16 wValue, char *str, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	snprintf(str, size, "Set Address(Addr = %02x)", wValue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static void usb_decode_get_set_descriptor(__u8 bRequestType, __u8 bRequest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 					  __u16 wValue, __u16 wIndex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 					  __u16 wLength, char *str, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	switch (wValue >> 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	case USB_DT_DEVICE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		s = "Device";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	case USB_DT_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		s = "Configuration";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	case USB_DT_STRING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		s = "String";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	case USB_DT_INTERFACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		s = "Interface";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	case USB_DT_ENDPOINT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		s = "Endpoint";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	case USB_DT_DEVICE_QUALIFIER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		s = "Device Qualifier";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	case USB_DT_OTHER_SPEED_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		s = "Other Speed Config";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	case USB_DT_INTERFACE_POWER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		s = "Interface Power";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	case USB_DT_OTG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		s = "OTG";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	case USB_DT_DEBUG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		s = "Debug";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	case USB_DT_INTERFACE_ASSOCIATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		s = "Interface Association";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	case USB_DT_BOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		s = "BOS";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	case USB_DT_DEVICE_CAPABILITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		s = "Device Capability";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	case USB_DT_PIPE_USAGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		s = "Pipe Usage";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	case USB_DT_SS_ENDPOINT_COMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		s = "SS Endpoint Companion";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	case USB_DT_SSP_ISOC_ENDPOINT_COMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		s = "SSP Isochronous Endpoint Companion";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		s = "UNKNOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	snprintf(str, size, "%s %s Descriptor(Index = %d, Length = %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		bRequest == USB_REQ_GET_DESCRIPTOR ? "Get" : "Set",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		s, wValue & 0xff, wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static void usb_decode_get_configuration(__u16 wLength, char *str, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	snprintf(str, size, "Get Configuration(Length = %d)", wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static void usb_decode_set_configuration(__u8 wValue, char *str, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	snprintf(str, size, "Set Configuration(Config = %d)", wValue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static void usb_decode_get_intf(__u16 wIndex, __u16 wLength, char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	snprintf(str, size, "Get Interface(Intf = %d, Length = %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		 wIndex, wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static void usb_decode_set_intf(__u8 wValue, __u16 wIndex, char *str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	snprintf(str, size, "Set Interface(Intf = %d, Alt.Setting = %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		 wIndex, wValue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static void usb_decode_synch_frame(__u16 wIndex, __u16 wLength,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 				   char *str, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	snprintf(str, size, "Synch Frame(Endpoint = %d, Length = %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		 wIndex, wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static void usb_decode_set_sel(__u16 wLength, char *str, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	snprintf(str, size, "Set SEL(Length = %d)", wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static void usb_decode_set_isoch_delay(__u8 wValue, char *str, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	snprintf(str, size, "Set Isochronous Delay(Delay = %d ns)", wValue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * usb_decode_ctrl - Returns human readable representation of control request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * @str: buffer to return a human-readable representation of control request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  *       This buffer should have about 200 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  * @size: size of str buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * @bRequestType: matches the USB bmRequestType field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * @bRequest: matches the USB bRequest field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * @wValue: matches the USB wValue field (CPU byte order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * @wIndex: matches the USB wIndex field (CPU byte order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * @wLength: matches the USB wLength field (CPU byte order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * Function returns decoded, formatted and human-readable description of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * control request packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  * The usage scenario for this is for tracepoints, so function as a return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  * use the same value as in parameters. This approach allows to use this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  * function in TP_printk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * Important: wValue, wIndex, wLength parameters before invoking this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  * should be processed by le16_to_cpu macro.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) const char *usb_decode_ctrl(char *str, size_t size, __u8 bRequestType,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			    __u8 bRequest, __u16 wValue, __u16 wIndex,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			    __u16 wLength)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	switch (bRequest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	case USB_REQ_GET_STATUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		usb_decode_get_status(bRequestType, wIndex, wLength, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	case USB_REQ_CLEAR_FEATURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	case USB_REQ_SET_FEATURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		usb_decode_set_clear_feature(bRequestType, bRequest, wValue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 					     wIndex, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	case USB_REQ_SET_ADDRESS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		usb_decode_set_address(wValue, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	case USB_REQ_GET_DESCRIPTOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	case USB_REQ_SET_DESCRIPTOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		usb_decode_get_set_descriptor(bRequestType, bRequest, wValue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 					      wIndex, wLength, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	case USB_REQ_GET_CONFIGURATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		usb_decode_get_configuration(wLength, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	case USB_REQ_SET_CONFIGURATION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		usb_decode_set_configuration(wValue, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	case USB_REQ_GET_INTERFACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		usb_decode_get_intf(wIndex, wLength, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	case USB_REQ_SET_INTERFACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		usb_decode_set_intf(wValue, wIndex, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	case USB_REQ_SYNCH_FRAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		usb_decode_synch_frame(wIndex, wLength, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	case USB_REQ_SET_SEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		usb_decode_set_sel(wLength, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	case USB_REQ_SET_ISOCH_DELAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		usb_decode_set_isoch_delay(wValue, str, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		snprintf(str, size, "%02x %02x %02x %02x %02x %02x %02x %02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			 bRequestType, bRequest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			 (u8)(cpu_to_le16(wValue) & 0xff),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			 (u8)(cpu_to_le16(wValue) >> 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			 (u8)(cpu_to_le16(wIndex) & 0xff),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			 (u8)(cpu_to_le16(wIndex) >> 8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			 (u8)(cpu_to_le16(wLength) & 0xff),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			 (u8)(cpu_to_le16(wLength) >> 8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	return str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) EXPORT_SYMBOL_GPL(usb_decode_ctrl);