18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/**
38c2ecf20Sopenharmony_ci * udc.c - Core UDC Framework
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2016 Intel Corporation
68c2ecf20Sopenharmony_ci * Author: Felipe Balbi <felipe.balbi@linux.intel.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#undef TRACE_SYSTEM
108c2ecf20Sopenharmony_ci#define TRACE_SYSTEM gadget
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#if !defined(__UDC_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
138c2ecf20Sopenharmony_ci#define __UDC_TRACE_H
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <linux/types.h>
168c2ecf20Sopenharmony_ci#include <linux/tracepoint.h>
178c2ecf20Sopenharmony_ci#include <asm/byteorder.h>
188c2ecf20Sopenharmony_ci#include <linux/usb/gadget.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciDECLARE_EVENT_CLASS(udc_log_gadget,
218c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
228c2ecf20Sopenharmony_ci	TP_ARGS(g, ret),
238c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
248c2ecf20Sopenharmony_ci		__field(enum usb_device_speed, speed)
258c2ecf20Sopenharmony_ci		__field(enum usb_device_speed, max_speed)
268c2ecf20Sopenharmony_ci		__field(enum usb_device_state, state)
278c2ecf20Sopenharmony_ci		__field(unsigned, mA)
288c2ecf20Sopenharmony_ci		__field(unsigned, sg_supported)
298c2ecf20Sopenharmony_ci		__field(unsigned, is_otg)
308c2ecf20Sopenharmony_ci		__field(unsigned, is_a_peripheral)
318c2ecf20Sopenharmony_ci		__field(unsigned, b_hnp_enable)
328c2ecf20Sopenharmony_ci		__field(unsigned, a_hnp_support)
338c2ecf20Sopenharmony_ci		__field(unsigned, hnp_polling_support)
348c2ecf20Sopenharmony_ci		__field(unsigned, host_request_flag)
358c2ecf20Sopenharmony_ci		__field(unsigned, quirk_ep_out_aligned_size)
368c2ecf20Sopenharmony_ci		__field(unsigned, quirk_altset_not_supp)
378c2ecf20Sopenharmony_ci		__field(unsigned, quirk_stall_not_supp)
388c2ecf20Sopenharmony_ci		__field(unsigned, quirk_zlp_not_supp)
398c2ecf20Sopenharmony_ci		__field(unsigned, is_selfpowered)
408c2ecf20Sopenharmony_ci		__field(unsigned, deactivated)
418c2ecf20Sopenharmony_ci		__field(unsigned, connected)
428c2ecf20Sopenharmony_ci		__field(int, ret)
438c2ecf20Sopenharmony_ci	),
448c2ecf20Sopenharmony_ci	TP_fast_assign(
458c2ecf20Sopenharmony_ci		__entry->speed = g->speed;
468c2ecf20Sopenharmony_ci		__entry->max_speed = g->max_speed;
478c2ecf20Sopenharmony_ci		__entry->state = g->state;
488c2ecf20Sopenharmony_ci		__entry->mA = g->mA;
498c2ecf20Sopenharmony_ci		__entry->sg_supported = g->sg_supported;
508c2ecf20Sopenharmony_ci		__entry->is_otg = g->is_otg;
518c2ecf20Sopenharmony_ci		__entry->is_a_peripheral = g->is_a_peripheral;
528c2ecf20Sopenharmony_ci		__entry->b_hnp_enable = g->b_hnp_enable;
538c2ecf20Sopenharmony_ci		__entry->a_hnp_support = g->a_hnp_support;
548c2ecf20Sopenharmony_ci		__entry->hnp_polling_support = g->hnp_polling_support;
558c2ecf20Sopenharmony_ci		__entry->host_request_flag = g->host_request_flag;
568c2ecf20Sopenharmony_ci		__entry->quirk_ep_out_aligned_size = g->quirk_ep_out_aligned_size;
578c2ecf20Sopenharmony_ci		__entry->quirk_altset_not_supp = g->quirk_altset_not_supp;
588c2ecf20Sopenharmony_ci		__entry->quirk_stall_not_supp = g->quirk_stall_not_supp;
598c2ecf20Sopenharmony_ci		__entry->quirk_zlp_not_supp = g->quirk_zlp_not_supp;
608c2ecf20Sopenharmony_ci		__entry->is_selfpowered = g->is_selfpowered;
618c2ecf20Sopenharmony_ci		__entry->deactivated = g->deactivated;
628c2ecf20Sopenharmony_ci		__entry->connected = g->connected;
638c2ecf20Sopenharmony_ci		__entry->ret = ret;
648c2ecf20Sopenharmony_ci	),
658c2ecf20Sopenharmony_ci	TP_printk("speed %d/%d state %d %dmA [%s%s%s%s%s%s%s%s%s%s%s%s%s%s] --> %d",
668c2ecf20Sopenharmony_ci		__entry->speed, __entry->max_speed, __entry->state, __entry->mA,
678c2ecf20Sopenharmony_ci		__entry->sg_supported ? "sg:" : "",
688c2ecf20Sopenharmony_ci		__entry->is_otg ? "OTG:" : "",
698c2ecf20Sopenharmony_ci		__entry->is_a_peripheral ? "a_peripheral:" : "",
708c2ecf20Sopenharmony_ci		__entry->b_hnp_enable ? "b_hnp:" : "",
718c2ecf20Sopenharmony_ci		__entry->a_hnp_support ? "a_hnp:" : "",
728c2ecf20Sopenharmony_ci		__entry->hnp_polling_support ? "hnp_poll:" : "",
738c2ecf20Sopenharmony_ci		__entry->host_request_flag ? "hostreq:" : "",
748c2ecf20Sopenharmony_ci		__entry->quirk_ep_out_aligned_size ? "out_aligned:" : "",
758c2ecf20Sopenharmony_ci		__entry->quirk_altset_not_supp ? "no_altset:" : "",
768c2ecf20Sopenharmony_ci		__entry->quirk_stall_not_supp ? "no_stall:" : "",
778c2ecf20Sopenharmony_ci		__entry->quirk_zlp_not_supp ? "no_zlp" : "",
788c2ecf20Sopenharmony_ci		__entry->is_selfpowered ? "self-powered:" : "bus-powered:",
798c2ecf20Sopenharmony_ci		__entry->deactivated ? "deactivated:" : "activated:",
808c2ecf20Sopenharmony_ci		__entry->connected ? "connected" : "disconnected",
818c2ecf20Sopenharmony_ci		__entry->ret)
828c2ecf20Sopenharmony_ci);
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_frame_number,
858c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
868c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
878c2ecf20Sopenharmony_ci);
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_wakeup,
908c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
918c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
928c2ecf20Sopenharmony_ci);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_set_selfpowered,
958c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
968c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
978c2ecf20Sopenharmony_ci);
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_clear_selfpowered,
1008c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
1018c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
1028c2ecf20Sopenharmony_ci);
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_vbus_connect,
1058c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
1068c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
1078c2ecf20Sopenharmony_ci);
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_vbus_draw,
1108c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
1118c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
1128c2ecf20Sopenharmony_ci);
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_vbus_disconnect,
1158c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
1168c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
1178c2ecf20Sopenharmony_ci);
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_connect,
1208c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
1218c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
1228c2ecf20Sopenharmony_ci);
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_disconnect,
1258c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
1268c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
1278c2ecf20Sopenharmony_ci);
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_deactivate,
1308c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
1318c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
1328c2ecf20Sopenharmony_ci);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_gadget, usb_gadget_activate,
1358c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_gadget *g, int ret),
1368c2ecf20Sopenharmony_ci	TP_ARGS(g, ret)
1378c2ecf20Sopenharmony_ci);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ciDECLARE_EVENT_CLASS(udc_log_ep,
1408c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, int ret),
1418c2ecf20Sopenharmony_ci	TP_ARGS(ep, ret),
1428c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
1438c2ecf20Sopenharmony_ci		__dynamic_array(char, name, UDC_TRACE_STR_MAX)
1448c2ecf20Sopenharmony_ci		__field(unsigned, maxpacket)
1458c2ecf20Sopenharmony_ci		__field(unsigned, maxpacket_limit)
1468c2ecf20Sopenharmony_ci		__field(unsigned, max_streams)
1478c2ecf20Sopenharmony_ci		__field(unsigned, mult)
1488c2ecf20Sopenharmony_ci		__field(unsigned, maxburst)
1498c2ecf20Sopenharmony_ci		__field(u8, address)
1508c2ecf20Sopenharmony_ci		__field(bool, claimed)
1518c2ecf20Sopenharmony_ci		__field(bool, enabled)
1528c2ecf20Sopenharmony_ci		__field(int, ret)
1538c2ecf20Sopenharmony_ci	),
1548c2ecf20Sopenharmony_ci	TP_fast_assign(
1558c2ecf20Sopenharmony_ci		snprintf(__get_str(name), UDC_TRACE_STR_MAX, "%s", ep->name);
1568c2ecf20Sopenharmony_ci		__entry->maxpacket = ep->maxpacket;
1578c2ecf20Sopenharmony_ci		__entry->maxpacket_limit = ep->maxpacket_limit;
1588c2ecf20Sopenharmony_ci		__entry->max_streams = ep->max_streams;
1598c2ecf20Sopenharmony_ci		__entry->mult = ep->mult;
1608c2ecf20Sopenharmony_ci		__entry->maxburst = ep->maxburst;
1618c2ecf20Sopenharmony_ci		__entry->address = ep->address,
1628c2ecf20Sopenharmony_ci		__entry->claimed = ep->claimed;
1638c2ecf20Sopenharmony_ci		__entry->enabled = ep->enabled;
1648c2ecf20Sopenharmony_ci		__entry->ret = ret;
1658c2ecf20Sopenharmony_ci	),
1668c2ecf20Sopenharmony_ci	TP_printk("%s: mps %d/%d streams %d mult %d burst %d addr %02x %s%s --> %d",
1678c2ecf20Sopenharmony_ci		__get_str(name), __entry->maxpacket, __entry->maxpacket_limit,
1688c2ecf20Sopenharmony_ci		__entry->max_streams, __entry->mult, __entry->maxburst,
1698c2ecf20Sopenharmony_ci		__entry->address, __entry->claimed ? "claimed:" : "released:",
1708c2ecf20Sopenharmony_ci		__entry->enabled ? "enabled" : "disabled", ret)
1718c2ecf20Sopenharmony_ci);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_ep, usb_ep_set_maxpacket_limit,
1748c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, int ret),
1758c2ecf20Sopenharmony_ci	TP_ARGS(ep, ret)
1768c2ecf20Sopenharmony_ci);
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_ep, usb_ep_enable,
1798c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, int ret),
1808c2ecf20Sopenharmony_ci	TP_ARGS(ep, ret)
1818c2ecf20Sopenharmony_ci);
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_ep, usb_ep_disable,
1848c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, int ret),
1858c2ecf20Sopenharmony_ci	TP_ARGS(ep, ret)
1868c2ecf20Sopenharmony_ci);
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_ep, usb_ep_set_halt,
1898c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, int ret),
1908c2ecf20Sopenharmony_ci	TP_ARGS(ep, ret)
1918c2ecf20Sopenharmony_ci);
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_ep, usb_ep_clear_halt,
1948c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, int ret),
1958c2ecf20Sopenharmony_ci	TP_ARGS(ep, ret)
1968c2ecf20Sopenharmony_ci);
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_ep, usb_ep_set_wedge,
1998c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, int ret),
2008c2ecf20Sopenharmony_ci	TP_ARGS(ep, ret)
2018c2ecf20Sopenharmony_ci);
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_ep, usb_ep_fifo_status,
2048c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, int ret),
2058c2ecf20Sopenharmony_ci	TP_ARGS(ep, ret)
2068c2ecf20Sopenharmony_ci);
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_ep, usb_ep_fifo_flush,
2098c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, int ret),
2108c2ecf20Sopenharmony_ci	TP_ARGS(ep, ret)
2118c2ecf20Sopenharmony_ci);
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ciDECLARE_EVENT_CLASS(udc_log_req,
2148c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret),
2158c2ecf20Sopenharmony_ci	TP_ARGS(ep, req, ret),
2168c2ecf20Sopenharmony_ci	TP_STRUCT__entry(
2178c2ecf20Sopenharmony_ci		__dynamic_array(char, name, UDC_TRACE_STR_MAX)
2188c2ecf20Sopenharmony_ci		__field(unsigned, length)
2198c2ecf20Sopenharmony_ci		__field(unsigned, actual)
2208c2ecf20Sopenharmony_ci		__field(unsigned, num_sgs)
2218c2ecf20Sopenharmony_ci		__field(unsigned, num_mapped_sgs)
2228c2ecf20Sopenharmony_ci		__field(unsigned, stream_id)
2238c2ecf20Sopenharmony_ci		__field(unsigned, no_interrupt)
2248c2ecf20Sopenharmony_ci		__field(unsigned, zero)
2258c2ecf20Sopenharmony_ci		__field(unsigned, short_not_ok)
2268c2ecf20Sopenharmony_ci		__field(int, status)
2278c2ecf20Sopenharmony_ci		__field(int, ret)
2288c2ecf20Sopenharmony_ci		__field(struct usb_request *, req)
2298c2ecf20Sopenharmony_ci	),
2308c2ecf20Sopenharmony_ci	TP_fast_assign(
2318c2ecf20Sopenharmony_ci		snprintf(__get_str(name), UDC_TRACE_STR_MAX, "%s", ep->name);
2328c2ecf20Sopenharmony_ci		__entry->length = req->length;
2338c2ecf20Sopenharmony_ci		__entry->actual = req->actual;
2348c2ecf20Sopenharmony_ci		__entry->num_sgs = req->num_sgs;
2358c2ecf20Sopenharmony_ci		__entry->num_mapped_sgs = req->num_mapped_sgs;
2368c2ecf20Sopenharmony_ci		__entry->stream_id = req->stream_id;
2378c2ecf20Sopenharmony_ci		__entry->no_interrupt = req->no_interrupt;
2388c2ecf20Sopenharmony_ci		__entry->zero = req->zero;
2398c2ecf20Sopenharmony_ci		__entry->short_not_ok = req->short_not_ok;
2408c2ecf20Sopenharmony_ci		__entry->status = req->status;
2418c2ecf20Sopenharmony_ci		__entry->ret = ret;
2428c2ecf20Sopenharmony_ci		__entry->req = req;
2438c2ecf20Sopenharmony_ci	),
2448c2ecf20Sopenharmony_ci	TP_printk("%s: req %p length %d/%d sgs %d/%d stream %d %s%s%s status %d --> %d",
2458c2ecf20Sopenharmony_ci		__get_str(name),__entry->req,  __entry->actual, __entry->length,
2468c2ecf20Sopenharmony_ci		__entry->num_mapped_sgs, __entry->num_sgs, __entry->stream_id,
2478c2ecf20Sopenharmony_ci		__entry->zero ? "Z" : "z",
2488c2ecf20Sopenharmony_ci		__entry->short_not_ok ? "S" : "s",
2498c2ecf20Sopenharmony_ci		__entry->no_interrupt ? "i" : "I",
2508c2ecf20Sopenharmony_ci		__entry->status, __entry->ret
2518c2ecf20Sopenharmony_ci	)
2528c2ecf20Sopenharmony_ci);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_req, usb_ep_alloc_request,
2558c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret),
2568c2ecf20Sopenharmony_ci	TP_ARGS(ep, req, ret)
2578c2ecf20Sopenharmony_ci);
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_req, usb_ep_free_request,
2608c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret),
2618c2ecf20Sopenharmony_ci	TP_ARGS(ep, req, ret)
2628c2ecf20Sopenharmony_ci);
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_req, usb_ep_queue,
2658c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret),
2668c2ecf20Sopenharmony_ci	TP_ARGS(ep, req, ret)
2678c2ecf20Sopenharmony_ci);
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_req, usb_ep_dequeue,
2708c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret),
2718c2ecf20Sopenharmony_ci	TP_ARGS(ep, req, ret)
2728c2ecf20Sopenharmony_ci);
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ciDEFINE_EVENT(udc_log_req, usb_gadget_giveback_request,
2758c2ecf20Sopenharmony_ci	TP_PROTO(struct usb_ep *ep, struct usb_request *req, int ret),
2768c2ecf20Sopenharmony_ci	TP_ARGS(ep, req, ret)
2778c2ecf20Sopenharmony_ci);
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci#endif /* __UDC_TRACE_H */
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci/* this part has to be here */
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci#undef TRACE_INCLUDE_PATH
2848c2ecf20Sopenharmony_ci#define TRACE_INCLUDE_PATH .
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci#undef TRACE_INCLUDE_FILE
2878c2ecf20Sopenharmony_ci#define TRACE_INCLUDE_FILE trace
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci#include <trace/define_trace.h>
290