1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (c) 2018-2019 Hisilicon Limited. */
3 
4 /* This must be outside ifdef _HNS3_TRACE_H */
5 #undef TRACE_SYSTEM
6 #define TRACE_SYSTEM hns3
7 
8 #if !defined(_HNS3_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ)
9 #define _HNS3_TRACE_H_
10 
11 #include <linux/tracepoint.h>
12 
13 #define DESC_NR		(sizeof(struct hns3_desc) / sizeof(u32))
14 
15 DECLARE_EVENT_CLASS(hns3_skb_template,
16 	TP_PROTO(struct sk_buff *skb),
17 	TP_ARGS(skb),
18 
19 	TP_STRUCT__entry(
20 		__field(unsigned int, headlen)
21 		__field(unsigned int, len)
22 		__field(__u8, nr_frags)
23 		__field(__u8, ip_summed)
24 		__field(unsigned int, hdr_len)
25 		__field(unsigned short, gso_size)
26 		__field(unsigned short, gso_segs)
27 		__field(unsigned int, gso_type)
28 		__field(bool, fraglist)
29 		__array(__u32, size, MAX_SKB_FRAGS)
30 	),
31 
32 	TP_fast_assign(
33 		__entry->headlen = skb_headlen(skb);
34 		__entry->len = skb->len;
35 		__entry->nr_frags = skb_shinfo(skb)->nr_frags;
36 		__entry->gso_size = skb_shinfo(skb)->gso_size;
37 		__entry->gso_segs = skb_shinfo(skb)->gso_segs;
38 		__entry->gso_type = skb_shinfo(skb)->gso_type;
39 		__entry->hdr_len = skb->encapsulation ?
40 		skb_inner_transport_offset(skb) + inner_tcp_hdrlen(skb) :
41 		skb_transport_offset(skb) + tcp_hdrlen(skb);
42 		__entry->ip_summed = skb->ip_summed;
43 		__entry->fraglist = skb_has_frag_list(skb);
44 		hns3_shinfo_pack(skb_shinfo(skb), __entry->size);
45 	),
46 
47 	TP_printk(
48 		"len: %u, %u, %u, cs: %u, gso: %u, %u, %x, frag(%d %u): %s",
49 		__entry->headlen, __entry->len, __entry->hdr_len,
50 		__entry->ip_summed, __entry->gso_size, __entry->gso_segs,
51 		__entry->gso_type, __entry->fraglist, __entry->nr_frags,
52 		__print_array(__entry->size, MAX_SKB_FRAGS, sizeof(__u32))
53 	)
54 );
55 
56 DEFINE_EVENT(hns3_skb_template, hns3_over_max_bd,
57 	TP_PROTO(struct sk_buff *skb),
58 	TP_ARGS(skb));
59 
60 DEFINE_EVENT(hns3_skb_template, hns3_gro,
61 	TP_PROTO(struct sk_buff *skb),
62 	TP_ARGS(skb));
63 
64 DEFINE_EVENT(hns3_skb_template, hns3_tso,
65 	TP_PROTO(struct sk_buff *skb),
66 	TP_ARGS(skb));
67 
68 TRACE_EVENT(hns3_tx_desc,
69 	TP_PROTO(struct hns3_enet_ring *ring, int cur_ntu),
70 	TP_ARGS(ring, cur_ntu),
71 
72 	TP_STRUCT__entry(
73 		__field(int, index)
74 		__field(int, ntu)
75 		__field(int, ntc)
76 		__field(dma_addr_t, desc_dma)
77 		__array(u32, desc, DESC_NR)
78 		__string(devname, ring->tqp->handle->kinfo.netdev->name)
79 	),
80 
81 	TP_fast_assign(
82 		__entry->index = ring->tqp->tqp_index;
83 		__entry->ntu = ring->next_to_use;
84 		__entry->ntc = ring->next_to_clean;
85 		__entry->desc_dma = ring->desc_dma_addr,
86 		memcpy(__entry->desc, &ring->desc[cur_ntu],
87 		       sizeof(struct hns3_desc));
88 		__assign_str(devname, ring->tqp->handle->kinfo.netdev->name);
89 	),
90 
91 	TP_printk(
92 		"%s-%d-%d/%d desc(%pad): %s",
93 		__get_str(devname), __entry->index, __entry->ntu,
94 		__entry->ntc, &__entry->desc_dma,
95 		__print_array(__entry->desc, DESC_NR, sizeof(u32))
96 	)
97 );
98 
99 TRACE_EVENT(hns3_rx_desc,
100 	TP_PROTO(struct hns3_enet_ring *ring),
101 	TP_ARGS(ring),
102 
103 	TP_STRUCT__entry(
104 		__field(int, index)
105 		__field(int, ntu)
106 		__field(int, ntc)
107 		__field(dma_addr_t, desc_dma)
108 		__field(dma_addr_t, buf_dma)
109 		__array(u32, desc, DESC_NR)
110 		__string(devname, ring->tqp->handle->kinfo.netdev->name)
111 	),
112 
113 	TP_fast_assign(
114 		__entry->index = ring->tqp->tqp_index;
115 		__entry->ntu = ring->next_to_use;
116 		__entry->ntc = ring->next_to_clean;
117 		__entry->desc_dma = ring->desc_dma_addr;
118 		__entry->buf_dma = ring->desc_cb[ring->next_to_clean].dma;
119 		memcpy(__entry->desc, &ring->desc[ring->next_to_clean],
120 		       sizeof(struct hns3_desc));
121 		__assign_str(devname, ring->tqp->handle->kinfo.netdev->name);
122 	),
123 
124 	TP_printk(
125 		"%s-%d-%d/%d desc(%pad) buf(%pad): %s",
126 		__get_str(devname), __entry->index, __entry->ntu,
127 		__entry->ntc, &__entry->desc_dma, &__entry->buf_dma,
128 		__print_array(__entry->desc, DESC_NR, sizeof(u32))
129 	)
130 );
131 
132 #endif /* _HNS3_TRACE_H_ */
133 
134 /* This must be outside ifdef _HNS3_TRACE_H */
135 #undef TRACE_INCLUDE_PATH
136 #define TRACE_INCLUDE_PATH .
137 #undef TRACE_INCLUDE_FILE
138 #define TRACE_INCLUDE_FILE hns3_trace
139 #include <trace/define_trace.h>
140