1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/module.h>
19#include <linux/mempool.h>
20#include <linux/errno.h>
21#include <linux/spinlock.h>
22#include <linux/kallsyms.h>
23#include <linux/time.h>
24#include <linux/vmalloc.h>
25#include "fnic_io.h"
26#include "fnic.h"
27
28unsigned int trace_max_pages;
29static int fnic_max_trace_entries;
30
31static unsigned long fnic_trace_buf_p;
32static DEFINE_SPINLOCK(fnic_trace_lock);
33
34static fnic_trace_dbg_t fnic_trace_entries;
35int fnic_tracing_enabled = 1;
36
37
38
39static int fc_trace_max_entries;
40static unsigned long fnic_fc_ctlr_trace_buf_p;
41static fnic_trace_dbg_t fc_trace_entries;
42int fnic_fc_tracing_enabled = 1;
43int fnic_fc_trace_cleared = 1;
44static DEFINE_SPINLOCK(fnic_fc_trace_lock);
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59fnic_trace_data_t *fnic_trace_get_buf(void)
60{
61 unsigned long fnic_buf_head;
62 unsigned long flags;
63
64 spin_lock_irqsave(&fnic_trace_lock, flags);
65
66
67
68
69
70 fnic_buf_head =
71 fnic_trace_entries.page_offset[fnic_trace_entries.wr_idx];
72 fnic_trace_entries.wr_idx++;
73
74
75
76
77
78 if (fnic_trace_entries.wr_idx >= fnic_max_trace_entries)
79 fnic_trace_entries.wr_idx = 0;
80
81
82
83
84
85 if (fnic_trace_entries.wr_idx == fnic_trace_entries.rd_idx) {
86 fnic_trace_entries.rd_idx++;
87 if (fnic_trace_entries.rd_idx >= fnic_max_trace_entries)
88 fnic_trace_entries.rd_idx = 0;
89 }
90 spin_unlock_irqrestore(&fnic_trace_lock, flags);
91 return (fnic_trace_data_t *)fnic_buf_head;
92}
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107int fnic_get_trace_data(fnic_dbgfs_t *fnic_dbgfs_prt)
108{
109 int rd_idx;
110 int wr_idx;
111 int len = 0;
112 unsigned long flags;
113 char str[KSYM_SYMBOL_LEN];
114 struct timespec64 val;
115 fnic_trace_data_t *tbp;
116
117 spin_lock_irqsave(&fnic_trace_lock, flags);
118 rd_idx = fnic_trace_entries.rd_idx;
119 wr_idx = fnic_trace_entries.wr_idx;
120 if (wr_idx < rd_idx) {
121 while (1) {
122
123 tbp = (fnic_trace_data_t *)
124 fnic_trace_entries.page_offset[rd_idx];
125 if (!tbp) {
126 spin_unlock_irqrestore(&fnic_trace_lock, flags);
127 return 0;
128 }
129
130 if (sizeof(unsigned long) < 8) {
131 sprint_symbol(str, tbp->fnaddr.low);
132 jiffies_to_timespec64(tbp->timestamp.low, &val);
133 } else {
134 sprint_symbol(str, tbp->fnaddr.val);
135 jiffies_to_timespec64(tbp->timestamp.val, &val);
136 }
137
138
139
140
141 len += snprintf(fnic_dbgfs_prt->buffer + len,
142 (trace_max_pages * PAGE_SIZE * 3) - len,
143 "%16llu.%09lu %-50s %8x %8x %16llx %16llx "
144 "%16llx %16llx %16llx\n", (u64)val.tv_sec,
145 val.tv_nsec, str, tbp->host_no, tbp->tag,
146 tbp->data[0], tbp->data[1], tbp->data[2],
147 tbp->data[3], tbp->data[4]);
148 rd_idx++;
149
150
151
152
153 if (rd_idx > (fnic_max_trace_entries-1))
154 rd_idx = 0;
155
156
157
158
159 if (rd_idx == wr_idx)
160 break;
161 }
162 } else if (wr_idx > rd_idx) {
163 while (1) {
164
165 tbp = (fnic_trace_data_t *)
166 fnic_trace_entries.page_offset[rd_idx];
167 if (!tbp) {
168 spin_unlock_irqrestore(&fnic_trace_lock, flags);
169 return 0;
170 }
171
172 if (sizeof(unsigned long) < 8) {
173 sprint_symbol(str, tbp->fnaddr.low);
174 jiffies_to_timespec64(tbp->timestamp.low, &val);
175 } else {
176 sprint_symbol(str, tbp->fnaddr.val);
177 jiffies_to_timespec64(tbp->timestamp.val, &val);
178 }
179
180
181
182
183 len += snprintf(fnic_dbgfs_prt->buffer + len,
184 (trace_max_pages * PAGE_SIZE * 3) - len,
185 "%16llu.%09lu %-50s %8x %8x %16llx %16llx "
186 "%16llx %16llx %16llx\n", (u64)val.tv_sec,
187 val.tv_nsec, str, tbp->host_no, tbp->tag,
188 tbp->data[0], tbp->data[1], tbp->data[2],
189 tbp->data[3], tbp->data[4]);
190 rd_idx++;
191
192
193
194
195 if (rd_idx == wr_idx)
196 break;
197 }
198 }
199 spin_unlock_irqrestore(&fnic_trace_lock, flags);
200 return len;
201}
202
203
204
205
206
207
208
209
210
211
212
213
214
215int fnic_get_stats_data(struct stats_debug_info *debug,
216 struct fnic_stats *stats)
217{
218 int len = 0;
219 int buf_size = debug->buf_size;
220 struct timespec64 val1, val2;
221
222 ktime_get_real_ts64(&val1);
223 len = snprintf(debug->debug_buffer + len, buf_size - len,
224 "------------------------------------------\n"
225 "\t\tTime\n"
226 "------------------------------------------\n");
227
228 len += snprintf(debug->debug_buffer + len, buf_size - len,
229 "Current time : [%lld:%ld]\n"
230 "Last stats reset time: [%lld:%09ld]\n"
231 "Last stats read time: [%lld:%ld]\n"
232 "delta since last reset: [%lld:%ld]\n"
233 "delta since last read: [%lld:%ld]\n",
234 (s64)val1.tv_sec, val1.tv_nsec,
235 (s64)stats->stats_timestamps.last_reset_time.tv_sec,
236 stats->stats_timestamps.last_reset_time.tv_nsec,
237 (s64)stats->stats_timestamps.last_read_time.tv_sec,
238 stats->stats_timestamps.last_read_time.tv_nsec,
239 (s64)timespec64_sub(val1, stats->stats_timestamps.last_reset_time).tv_sec,
240 timespec64_sub(val1, stats->stats_timestamps.last_reset_time).tv_nsec,
241 (s64)timespec64_sub(val1, stats->stats_timestamps.last_read_time).tv_sec,
242 timespec64_sub(val1, stats->stats_timestamps.last_read_time).tv_nsec);
243
244 stats->stats_timestamps.last_read_time = val1;
245
246 len += snprintf(debug->debug_buffer + len, buf_size - len,
247 "------------------------------------------\n"
248 "\t\tIO Statistics\n"
249 "------------------------------------------\n");
250 len += snprintf(debug->debug_buffer + len, buf_size - len,
251 "Number of Active IOs: %lld\nMaximum Active IOs: %lld\n"
252 "Number of IOs: %lld\nNumber of IO Completions: %lld\n"
253 "Number of IO Failures: %lld\nNumber of IO NOT Found: %lld\n"
254 "Number of Memory alloc Failures: %lld\n"
255 "Number of IOREQ Null: %lld\n"
256 "Number of SCSI cmd pointer Null: %lld\n"
257
258 "\nIO completion times: \n"
259 " < 10 ms : %lld\n"
260 " 10 ms - 100 ms : %lld\n"
261 " 100 ms - 500 ms : %lld\n"
262 " 500 ms - 5 sec: %lld\n"
263 " 5 sec - 10 sec: %lld\n"
264 " 10 sec - 30 sec: %lld\n"
265 " > 30 sec: %lld\n",
266 (u64)atomic64_read(&stats->io_stats.active_ios),
267 (u64)atomic64_read(&stats->io_stats.max_active_ios),
268 (u64)atomic64_read(&stats->io_stats.num_ios),
269 (u64)atomic64_read(&stats->io_stats.io_completions),
270 (u64)atomic64_read(&stats->io_stats.io_failures),
271 (u64)atomic64_read(&stats->io_stats.io_not_found),
272 (u64)atomic64_read(&stats->io_stats.alloc_failures),
273 (u64)atomic64_read(&stats->io_stats.ioreq_null),
274 (u64)atomic64_read(&stats->io_stats.sc_null),
275 (u64)atomic64_read(&stats->io_stats.io_btw_0_to_10_msec),
276 (u64)atomic64_read(&stats->io_stats.io_btw_10_to_100_msec),
277 (u64)atomic64_read(&stats->io_stats.io_btw_100_to_500_msec),
278 (u64)atomic64_read(&stats->io_stats.io_btw_500_to_5000_msec),
279 (u64)atomic64_read(&stats->io_stats.io_btw_5000_to_10000_msec),
280 (u64)atomic64_read(&stats->io_stats.io_btw_10000_to_30000_msec),
281 (u64)atomic64_read(&stats->io_stats.io_greater_than_30000_msec));
282
283 len += snprintf(debug->debug_buffer + len, buf_size - len,
284 "\nCurrent Max IO time : %lld\n",
285 (u64)atomic64_read(&stats->io_stats.current_max_io_time));
286
287 len += snprintf(debug->debug_buffer + len, buf_size - len,
288 "\n------------------------------------------\n"
289 "\t\tAbort Statistics\n"
290 "------------------------------------------\n");
291
292 len += snprintf(debug->debug_buffer + len, buf_size - len,
293 "Number of Aborts: %lld\n"
294 "Number of Abort Failures: %lld\n"
295 "Number of Abort Driver Timeouts: %lld\n"
296 "Number of Abort FW Timeouts: %lld\n"
297 "Number of Abort IO NOT Found: %lld\n"
298
299 "Abort issued times: \n"
300 " < 6 sec : %lld\n"
301 " 6 sec - 20 sec : %lld\n"
302 " 20 sec - 30 sec : %lld\n"
303 " 30 sec - 40 sec : %lld\n"
304 " 40 sec - 50 sec : %lld\n"
305 " 50 sec - 60 sec : %lld\n"
306 " > 60 sec: %lld\n",
307
308 (u64)atomic64_read(&stats->abts_stats.aborts),
309 (u64)atomic64_read(&stats->abts_stats.abort_failures),
310 (u64)atomic64_read(&stats->abts_stats.abort_drv_timeouts),
311 (u64)atomic64_read(&stats->abts_stats.abort_fw_timeouts),
312 (u64)atomic64_read(&stats->abts_stats.abort_io_not_found),
313 (u64)atomic64_read(&stats->abts_stats.abort_issued_btw_0_to_6_sec),
314 (u64)atomic64_read(&stats->abts_stats.abort_issued_btw_6_to_20_sec),
315 (u64)atomic64_read(&stats->abts_stats.abort_issued_btw_20_to_30_sec),
316 (u64)atomic64_read(&stats->abts_stats.abort_issued_btw_30_to_40_sec),
317 (u64)atomic64_read(&stats->abts_stats.abort_issued_btw_40_to_50_sec),
318 (u64)atomic64_read(&stats->abts_stats.abort_issued_btw_50_to_60_sec),
319 (u64)atomic64_read(&stats->abts_stats.abort_issued_greater_than_60_sec));
320
321 len += snprintf(debug->debug_buffer + len, buf_size - len,
322 "\n------------------------------------------\n"
323 "\t\tTerminate Statistics\n"
324 "------------------------------------------\n");
325
326 len += snprintf(debug->debug_buffer + len, buf_size - len,
327 "Number of Terminates: %lld\n"
328 "Maximum Terminates: %lld\n"
329 "Number of Terminate Driver Timeouts: %lld\n"
330 "Number of Terminate FW Timeouts: %lld\n"
331 "Number of Terminate IO NOT Found: %lld\n"
332 "Number of Terminate Failures: %lld\n",
333 (u64)atomic64_read(&stats->term_stats.terminates),
334 (u64)atomic64_read(&stats->term_stats.max_terminates),
335 (u64)atomic64_read(&stats->term_stats.terminate_drv_timeouts),
336 (u64)atomic64_read(&stats->term_stats.terminate_fw_timeouts),
337 (u64)atomic64_read(&stats->term_stats.terminate_io_not_found),
338 (u64)atomic64_read(&stats->term_stats.terminate_failures));
339
340 len += snprintf(debug->debug_buffer + len, buf_size - len,
341 "\n------------------------------------------\n"
342 "\t\tReset Statistics\n"
343 "------------------------------------------\n");
344
345 len += snprintf(debug->debug_buffer + len, buf_size - len,
346 "Number of Device Resets: %lld\n"
347 "Number of Device Reset Failures: %lld\n"
348 "Number of Device Reset Aborts: %lld\n"
349 "Number of Device Reset Timeouts: %lld\n"
350 "Number of Device Reset Terminates: %lld\n"
351 "Number of FW Resets: %lld\n"
352 "Number of FW Reset Completions: %lld\n"
353 "Number of FW Reset Failures: %lld\n"
354 "Number of Fnic Reset: %lld\n"
355 "Number of Fnic Reset Completions: %lld\n"
356 "Number of Fnic Reset Failures: %lld\n",
357 (u64)atomic64_read(&stats->reset_stats.device_resets),
358 (u64)atomic64_read(&stats->reset_stats.device_reset_failures),
359 (u64)atomic64_read(&stats->reset_stats.device_reset_aborts),
360 (u64)atomic64_read(&stats->reset_stats.device_reset_timeouts),
361 (u64)atomic64_read(
362 &stats->reset_stats.device_reset_terminates),
363 (u64)atomic64_read(&stats->reset_stats.fw_resets),
364 (u64)atomic64_read(&stats->reset_stats.fw_reset_completions),
365 (u64)atomic64_read(&stats->reset_stats.fw_reset_failures),
366 (u64)atomic64_read(&stats->reset_stats.fnic_resets),
367 (u64)atomic64_read(
368 &stats->reset_stats.fnic_reset_completions),
369 (u64)atomic64_read(&stats->reset_stats.fnic_reset_failures));
370
371 len += snprintf(debug->debug_buffer + len, buf_size - len,
372 "\n------------------------------------------\n"
373 "\t\tFirmware Statistics\n"
374 "------------------------------------------\n");
375
376 len += snprintf(debug->debug_buffer + len, buf_size - len,
377 "Number of Active FW Requests %lld\n"
378 "Maximum FW Requests: %lld\n"
379 "Number of FW out of resources: %lld\n"
380 "Number of FW IO errors: %lld\n",
381 (u64)atomic64_read(&stats->fw_stats.active_fw_reqs),
382 (u64)atomic64_read(&stats->fw_stats.max_fw_reqs),
383 (u64)atomic64_read(&stats->fw_stats.fw_out_of_resources),
384 (u64)atomic64_read(&stats->fw_stats.io_fw_errs));
385
386 len += snprintf(debug->debug_buffer + len, buf_size - len,
387 "\n------------------------------------------\n"
388 "\t\tVlan Discovery Statistics\n"
389 "------------------------------------------\n");
390
391 len += snprintf(debug->debug_buffer + len, buf_size - len,
392 "Number of Vlan Discovery Requests Sent %lld\n"
393 "Vlan Response Received with no FCF VLAN ID: %lld\n"
394 "No solicitations recvd after vlan set, expiry count: %lld\n"
395 "Flogi rejects count: %lld\n",
396 (u64)atomic64_read(&stats->vlan_stats.vlan_disc_reqs),
397 (u64)atomic64_read(&stats->vlan_stats.resp_withno_vlanID),
398 (u64)atomic64_read(&stats->vlan_stats.sol_expiry_count),
399 (u64)atomic64_read(&stats->vlan_stats.flogi_rejects));
400
401 len += snprintf(debug->debug_buffer + len, buf_size - len,
402 "\n------------------------------------------\n"
403 "\t\tOther Important Statistics\n"
404 "------------------------------------------\n");
405
406 jiffies_to_timespec64(stats->misc_stats.last_isr_time, &val1);
407 jiffies_to_timespec64(stats->misc_stats.last_ack_time, &val2);
408
409 len += snprintf(debug->debug_buffer + len, buf_size - len,
410 "Last ISR time: %llu (%8llu.%09lu)\n"
411 "Last ACK time: %llu (%8llu.%09lu)\n"
412 "Number of ISRs: %lld\n"
413 "Maximum CQ Entries: %lld\n"
414 "Number of ACK index out of range: %lld\n"
415 "Number of data count mismatch: %lld\n"
416 "Number of FCPIO Timeouts: %lld\n"
417 "Number of FCPIO Aborted: %lld\n"
418 "Number of SGL Invalid: %lld\n"
419 "Number of Copy WQ Alloc Failures for ABTs: %lld\n"
420 "Number of Copy WQ Alloc Failures for Device Reset: %lld\n"
421 "Number of Copy WQ Alloc Failures for IOs: %lld\n"
422 "Number of no icmnd itmf Completions: %lld\n"
423 "Number of Check Conditions encountered: %lld\n"
424 "Number of QUEUE Fulls: %lld\n"
425 "Number of rport not ready: %lld\n"
426 "Number of receive frame errors: %lld\n",
427 (u64)stats->misc_stats.last_isr_time,
428 (s64)val1.tv_sec, val1.tv_nsec,
429 (u64)stats->misc_stats.last_ack_time,
430 (s64)val2.tv_sec, val2.tv_nsec,
431 (u64)atomic64_read(&stats->misc_stats.isr_count),
432 (u64)atomic64_read(&stats->misc_stats.max_cq_entries),
433 (u64)atomic64_read(&stats->misc_stats.ack_index_out_of_range),
434 (u64)atomic64_read(&stats->misc_stats.data_count_mismatch),
435 (u64)atomic64_read(&stats->misc_stats.fcpio_timeout),
436 (u64)atomic64_read(&stats->misc_stats.fcpio_aborted),
437 (u64)atomic64_read(&stats->misc_stats.sgl_invalid),
438 (u64)atomic64_read(
439 &stats->misc_stats.abts_cpwq_alloc_failures),
440 (u64)atomic64_read(
441 &stats->misc_stats.devrst_cpwq_alloc_failures),
442 (u64)atomic64_read(&stats->misc_stats.io_cpwq_alloc_failures),
443 (u64)atomic64_read(&stats->misc_stats.no_icmnd_itmf_cmpls),
444 (u64)atomic64_read(&stats->misc_stats.check_condition),
445 (u64)atomic64_read(&stats->misc_stats.queue_fulls),
446 (u64)atomic64_read(&stats->misc_stats.rport_not_ready),
447 (u64)atomic64_read(&stats->misc_stats.frame_errors));
448
449 return len;
450
451}
452
453
454
455
456
457
458
459
460
461int fnic_trace_buf_init(void)
462{
463 unsigned long fnic_buf_head;
464 int i;
465 int err = 0;
466
467 trace_max_pages = fnic_trace_max_pages;
468 fnic_max_trace_entries = (trace_max_pages * PAGE_SIZE)/
469 FNIC_ENTRY_SIZE_BYTES;
470
471 fnic_trace_buf_p = (unsigned long)vmalloc((trace_max_pages * PAGE_SIZE));
472 if (!fnic_trace_buf_p) {
473 printk(KERN_ERR PFX "Failed to allocate memory "
474 "for fnic_trace_buf_p\n");
475 err = -ENOMEM;
476 goto err_fnic_trace_buf_init;
477 }
478 memset((void *)fnic_trace_buf_p, 0, (trace_max_pages * PAGE_SIZE));
479
480 fnic_trace_entries.page_offset =
481 vmalloc(array_size(fnic_max_trace_entries,
482 sizeof(unsigned long)));
483 if (!fnic_trace_entries.page_offset) {
484 printk(KERN_ERR PFX "Failed to allocate memory for"
485 " page_offset\n");
486 if (fnic_trace_buf_p) {
487 vfree((void *)fnic_trace_buf_p);
488 fnic_trace_buf_p = 0;
489 }
490 err = -ENOMEM;
491 goto err_fnic_trace_buf_init;
492 }
493 memset((void *)fnic_trace_entries.page_offset, 0,
494 (fnic_max_trace_entries * sizeof(unsigned long)));
495 fnic_trace_entries.wr_idx = fnic_trace_entries.rd_idx = 0;
496 fnic_buf_head = fnic_trace_buf_p;
497
498
499
500
501
502
503 for (i = 0; i < fnic_max_trace_entries; i++) {
504 fnic_trace_entries.page_offset[i] = fnic_buf_head;
505 fnic_buf_head += FNIC_ENTRY_SIZE_BYTES;
506 }
507 err = fnic_trace_debugfs_init();
508 if (err < 0) {
509 pr_err("fnic: Failed to initialize debugfs for tracing\n");
510 goto err_fnic_trace_debugfs_init;
511 }
512 pr_info("fnic: Successfully Initialized Trace Buffer\n");
513 return err;
514err_fnic_trace_debugfs_init:
515 fnic_trace_free();
516err_fnic_trace_buf_init:
517 return err;
518}
519
520
521
522
523void fnic_trace_free(void)
524{
525 fnic_tracing_enabled = 0;
526 fnic_trace_debugfs_terminate();
527 if (fnic_trace_entries.page_offset) {
528 vfree((void *)fnic_trace_entries.page_offset);
529 fnic_trace_entries.page_offset = NULL;
530 }
531 if (fnic_trace_buf_p) {
532 vfree((void *)fnic_trace_buf_p);
533 fnic_trace_buf_p = 0;
534 }
535 printk(KERN_INFO PFX "Successfully Freed Trace Buffer\n");
536}
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551int fnic_fc_trace_init(void)
552{
553 unsigned long fc_trace_buf_head;
554 int err = 0;
555 int i;
556
557 fc_trace_max_entries = (fnic_fc_trace_max_pages * PAGE_SIZE)/
558 FC_TRC_SIZE_BYTES;
559 fnic_fc_ctlr_trace_buf_p =
560 (unsigned long)vmalloc(array_size(PAGE_SIZE,
561 fnic_fc_trace_max_pages));
562 if (!fnic_fc_ctlr_trace_buf_p) {
563 pr_err("fnic: Failed to allocate memory for "
564 "FC Control Trace Buf\n");
565 err = -ENOMEM;
566 goto err_fnic_fc_ctlr_trace_buf_init;
567 }
568
569 memset((void *)fnic_fc_ctlr_trace_buf_p, 0,
570 fnic_fc_trace_max_pages * PAGE_SIZE);
571
572
573 fc_trace_entries.page_offset =
574 vmalloc(array_size(fc_trace_max_entries,
575 sizeof(unsigned long)));
576 if (!fc_trace_entries.page_offset) {
577 pr_err("fnic:Failed to allocate memory for page_offset\n");
578 if (fnic_fc_ctlr_trace_buf_p) {
579 pr_err("fnic: Freeing FC Control Trace Buf\n");
580 vfree((void *)fnic_fc_ctlr_trace_buf_p);
581 fnic_fc_ctlr_trace_buf_p = 0;
582 }
583 err = -ENOMEM;
584 goto err_fnic_fc_ctlr_trace_buf_init;
585 }
586 memset((void *)fc_trace_entries.page_offset, 0,
587 (fc_trace_max_entries * sizeof(unsigned long)));
588
589 fc_trace_entries.rd_idx = fc_trace_entries.wr_idx = 0;
590 fc_trace_buf_head = fnic_fc_ctlr_trace_buf_p;
591
592
593
594
595
596 for (i = 0; i < fc_trace_max_entries; i++) {
597 fc_trace_entries.page_offset[i] = fc_trace_buf_head;
598 fc_trace_buf_head += FC_TRC_SIZE_BYTES;
599 }
600 err = fnic_fc_trace_debugfs_init();
601 if (err < 0) {
602 pr_err("fnic: Failed to initialize FC_CTLR tracing.\n");
603 goto err_fnic_fc_ctlr_trace_debugfs_init;
604 }
605 pr_info("fnic: Successfully Initialized FC_CTLR Trace Buffer\n");
606 return err;
607
608err_fnic_fc_ctlr_trace_debugfs_init:
609 fnic_fc_trace_free();
610err_fnic_fc_ctlr_trace_buf_init:
611 return err;
612}
613
614
615
616
617void fnic_fc_trace_free(void)
618{
619 fnic_fc_tracing_enabled = 0;
620 fnic_fc_trace_debugfs_terminate();
621 if (fc_trace_entries.page_offset) {
622 vfree((void *)fc_trace_entries.page_offset);
623 fc_trace_entries.page_offset = NULL;
624 }
625 if (fnic_fc_ctlr_trace_buf_p) {
626 vfree((void *)fnic_fc_ctlr_trace_buf_p);
627 fnic_fc_ctlr_trace_buf_p = 0;
628 }
629 pr_info("fnic:Successfully FC_CTLR Freed Trace Buffer\n");
630}
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649int fnic_fc_trace_set_data(u32 host_no, u8 frame_type,
650 char *frame, u32 fc_trc_frame_len)
651{
652 unsigned long flags;
653 struct fc_trace_hdr *fc_buf;
654 unsigned long eth_fcoe_hdr_len;
655 char *fc_trace;
656
657 if (fnic_fc_tracing_enabled == 0)
658 return 0;
659
660 spin_lock_irqsave(&fnic_fc_trace_lock, flags);
661
662 if (fnic_fc_trace_cleared == 1) {
663 fc_trace_entries.rd_idx = fc_trace_entries.wr_idx = 0;
664 pr_info("fnic: Resetting the read idx\n");
665 memset((void *)fnic_fc_ctlr_trace_buf_p, 0,
666 fnic_fc_trace_max_pages * PAGE_SIZE);
667 fnic_fc_trace_cleared = 0;
668 }
669
670 fc_buf = (struct fc_trace_hdr *)
671 fc_trace_entries.page_offset[fc_trace_entries.wr_idx];
672
673 fc_trace_entries.wr_idx++;
674
675 if (fc_trace_entries.wr_idx >= fc_trace_max_entries)
676 fc_trace_entries.wr_idx = 0;
677
678 if (fc_trace_entries.wr_idx == fc_trace_entries.rd_idx) {
679 fc_trace_entries.rd_idx++;
680 if (fc_trace_entries.rd_idx >= fc_trace_max_entries)
681 fc_trace_entries.rd_idx = 0;
682 }
683
684 ktime_get_real_ts64(&fc_buf->time_stamp);
685 fc_buf->host_no = host_no;
686 fc_buf->frame_type = frame_type;
687
688 fc_trace = (char *)FC_TRACE_ADDRESS(fc_buf);
689
690
691
692
693 if (frame_type == FNIC_FC_RECV) {
694 eth_fcoe_hdr_len = sizeof(struct ethhdr) +
695 sizeof(struct fcoe_hdr);
696 memset((char *)fc_trace, 0xff, eth_fcoe_hdr_len);
697
698 memcpy((char *)(fc_trace + eth_fcoe_hdr_len), (void *)frame,
699 min_t(u8, fc_trc_frame_len,
700 (u8)(FC_TRC_SIZE_BYTES - FC_TRC_HEADER_SIZE
701 - eth_fcoe_hdr_len)));
702 } else {
703 memcpy((char *)fc_trace, (void *)frame,
704 min_t(u8, fc_trc_frame_len,
705 (u8)(FC_TRC_SIZE_BYTES - FC_TRC_HEADER_SIZE)));
706 }
707
708
709 fc_buf->frame_len = fc_trc_frame_len;
710
711 spin_unlock_irqrestore(&fnic_fc_trace_lock, flags);
712 return 0;
713}
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729int fnic_fc_trace_get_data(fnic_dbgfs_t *fnic_dbgfs_prt, u8 rdata_flag)
730{
731 int rd_idx, wr_idx;
732 unsigned long flags;
733 int len = 0, j;
734 struct fc_trace_hdr *tdata;
735 char *fc_trace;
736
737 spin_lock_irqsave(&fnic_fc_trace_lock, flags);
738 if (fc_trace_entries.wr_idx == fc_trace_entries.rd_idx) {
739 spin_unlock_irqrestore(&fnic_fc_trace_lock, flags);
740 pr_info("fnic: Buffer is empty\n");
741 return 0;
742 }
743 rd_idx = fc_trace_entries.rd_idx;
744 wr_idx = fc_trace_entries.wr_idx;
745 if (rdata_flag == 0) {
746 len += snprintf(fnic_dbgfs_prt->buffer + len,
747 (fnic_fc_trace_max_pages * PAGE_SIZE * 3) - len,
748 "Time Stamp (UTC)\t\t"
749 "Host No: F Type: len: FCoE_FRAME:\n");
750 }
751
752 while (rd_idx != wr_idx) {
753 tdata = (struct fc_trace_hdr *)
754 fc_trace_entries.page_offset[rd_idx];
755 if (!tdata) {
756 pr_info("fnic: Rd data is NULL\n");
757 spin_unlock_irqrestore(&fnic_fc_trace_lock, flags);
758 return 0;
759 }
760 if (rdata_flag == 0) {
761 copy_and_format_trace_data(tdata,
762 fnic_dbgfs_prt, &len, rdata_flag);
763 } else {
764 fc_trace = (char *)tdata;
765 for (j = 0; j < FC_TRC_SIZE_BYTES; j++) {
766 len += snprintf(fnic_dbgfs_prt->buffer + len,
767 (fnic_fc_trace_max_pages * PAGE_SIZE * 3)
768 - len, "%02x", fc_trace[j] & 0xff);
769 }
770 len += snprintf(fnic_dbgfs_prt->buffer + len,
771 (fnic_fc_trace_max_pages * PAGE_SIZE * 3) - len,
772 "\n");
773 }
774 rd_idx++;
775 if (rd_idx > (fc_trace_max_entries - 1))
776 rd_idx = 0;
777 }
778
779 spin_unlock_irqrestore(&fnic_fc_trace_lock, flags);
780 return len;
781}
782
783
784
785
786
787
788
789
790
791
792
793
794
795void copy_and_format_trace_data(struct fc_trace_hdr *tdata,
796 fnic_dbgfs_t *fnic_dbgfs_prt, int *orig_len,
797 u8 rdata_flag)
798{
799 struct tm tm;
800 int j, i = 1, len;
801 char *fc_trace, *fmt;
802 int ethhdr_len = sizeof(struct ethhdr) - 1;
803 int fcoehdr_len = sizeof(struct fcoe_hdr);
804 int fchdr_len = sizeof(struct fc_frame_header);
805 int max_size = fnic_fc_trace_max_pages * PAGE_SIZE * 3;
806
807 tdata->frame_type = tdata->frame_type & 0x7F;
808
809 len = *orig_len;
810
811 time64_to_tm(tdata->time_stamp.tv_sec, 0, &tm);
812
813 fmt = "%02d:%02d:%04ld %02d:%02d:%02d.%09lu ns%8x %c%8x\t";
814 len += snprintf(fnic_dbgfs_prt->buffer + len,
815 max_size - len,
816 fmt,
817 tm.tm_mon + 1, tm.tm_mday, tm.tm_year + 1900,
818 tm.tm_hour, tm.tm_min, tm.tm_sec,
819 tdata->time_stamp.tv_nsec, tdata->host_no,
820 tdata->frame_type, tdata->frame_len);
821
822 fc_trace = (char *)FC_TRACE_ADDRESS(tdata);
823
824 for (j = 0; j < min_t(u8, tdata->frame_len,
825 (u8)(FC_TRC_SIZE_BYTES - FC_TRC_HEADER_SIZE)); j++) {
826 if (tdata->frame_type == FNIC_FC_LE) {
827 len += snprintf(fnic_dbgfs_prt->buffer + len,
828 max_size - len, "%c", fc_trace[j]);
829 } else {
830 len += snprintf(fnic_dbgfs_prt->buffer + len,
831 max_size - len, "%02x", fc_trace[j] & 0xff);
832 len += snprintf(fnic_dbgfs_prt->buffer + len,
833 max_size - len, " ");
834 if (j == ethhdr_len ||
835 j == ethhdr_len + fcoehdr_len ||
836 j == ethhdr_len + fcoehdr_len + fchdr_len ||
837 (i > 3 && j%fchdr_len == 0)) {
838 len += snprintf(fnic_dbgfs_prt->buffer
839 + len, max_size - len,
840 "\n\t\t\t\t\t\t\t\t");
841 i++;
842 }
843 }
844 }
845 len += snprintf(fnic_dbgfs_prt->buffer + len,
846 max_size - len, "\n");
847 *orig_len = len;
848}
849