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